@astryx-vue/core 0.38.0 → 0.39.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 (248) hide show
  1. package/dist/AlertDialog/index.js +1 -1
  2. package/dist/{AlertDialog-BVTKz7re.js → AlertDialog-DnylRSpj.js} +3 -3
  3. package/dist/AppShell/index.js +1 -1
  4. package/dist/{AppShell-C2y8U6wp.js → AppShell-lv3WDlCi.js} +5 -5
  5. package/dist/AvatarGroup/index.d.ts +1 -1
  6. package/dist/Banner/index.d.ts +1 -1
  7. package/dist/Banner/index.js +1 -1
  8. package/dist/{Banner-NCI6aOKt.js → Banner-CqIYLEcx.js} +2 -2
  9. package/dist/BottomSheet/index.d.ts +1 -1
  10. package/dist/BottomSheet/index.js +2 -2
  11. package/dist/{BottomSheet-dgHDqtQg.js → BottomSheet-6W3izQzr.js} +1 -1
  12. package/dist/{BottomSheet-CFdGLVIF.js → BottomSheet-D37eNqz5.js} +2 -2
  13. package/dist/Breadcrumbs/index.js +2 -2
  14. package/dist/{Breadcrumbs-CwEfccnT.js → Breadcrumbs-BEzCPnoe.js} +2 -2
  15. package/dist/Button/index.js +1 -1
  16. package/dist/{Button-BZV5wL4j.js → Button-DGIfLwqj.js} +1 -1
  17. package/dist/ButtonGroup/index.d.ts +1 -1
  18. package/dist/Calendar/index.d.ts +1 -1
  19. package/dist/Calendar/index.js +1 -1
  20. package/dist/{Calendar-S5IjkDsY.js → Calendar-CfhOlgQJ.js} +1 -1
  21. package/dist/Carousel/index.d.ts +1 -1
  22. package/dist/Carousel/index.js +1 -1
  23. package/dist/{Carousel-CbOusMO0.js → Carousel-DmeW51vC.js} +2 -2
  24. package/dist/Chat/index.d.ts +1 -1
  25. package/dist/Chat/index.js +1 -1
  26. package/dist/{Chat-BrHbv7Ah.js → Chat-whrqE8Zj.js} +5 -5
  27. package/dist/CheckboxInput/index.d.ts +1 -1
  28. package/dist/CheckboxInput/index.js +1 -1
  29. package/dist/{CheckboxInput-CV8aHb9r.js → CheckboxInput-CHO4Jz0m.js} +3 -3
  30. package/dist/CheckboxList/index.d.ts +1 -1
  31. package/dist/CheckboxList/index.js +1 -1
  32. package/dist/{CheckboxListItem-SyF1JdT3.js → CheckboxListItem-C4dmrC_w.js} +3 -3
  33. package/dist/Citation/index.js +1 -1
  34. package/dist/{Citation-Ijf06x0V.js → Citation-DXMQVSi5.js} +1 -1
  35. package/dist/ClickableCard/index.d.ts +1 -1
  36. package/dist/Code/index.js +2 -2
  37. package/dist/{Code-BNOzyQX4.js → Code-D80SHrJx.js} +4 -3
  38. package/dist/{CodeBlock-DYXx_9Kj.js → CodeBlock-vhMVY90M.js} +3 -3
  39. package/dist/Collapsible/index.js +1 -1
  40. package/dist/{Collapsible-48Q1GfRw.js → Collapsible-CaKmR3yE.js} +3 -3
  41. package/dist/CommandPalette/index.js +1 -1
  42. package/dist/{CommandPalette-Ct70AcIK.js → CommandPalette-C-iXk7EB.js} +2 -2
  43. package/dist/ComplexSelector/index.d.ts +1 -1
  44. package/dist/ComplexSelector/index.js +1 -1
  45. package/dist/{ComplexSelector-NnPRhI6t.js → ComplexSelector-BsdtBmd0.js} +5 -5
  46. package/dist/{ComponentIcon-Dw4xQxg3.js → ComponentIcon-B67QcA-d.js} +2 -2
  47. package/dist/ContextMenu/index.d.ts +1 -1
  48. package/dist/ContextMenu/index.js +2 -2
  49. package/dist/{ContextMenu-C7m059d4.js → ContextMenu-GZkN9lf1.js} +6 -6
  50. package/dist/DateInput/index.d.ts +1 -1
  51. package/dist/DateInput/index.js +1 -1
  52. package/dist/{DateInput-D-NIlF5P.js → DateInput-Cb6eLrbU.js} +9 -9
  53. package/dist/DateRangeInput/index.d.ts +1 -1
  54. package/dist/DateRangeInput/index.js +1 -1
  55. package/dist/{DateRangeInput-BYl649eD.js → DateRangeInput-BUFeQYJ6.js} +6 -6
  56. package/dist/DateTimeInput/index.d.ts +1 -1
  57. package/dist/DateTimeInput/index.js +1 -1
  58. package/dist/{DateTimeInput-CBzae6EW.js → DateTimeInput-r-MOwLs4.js} +9 -9
  59. package/dist/Dialog/index.js +1 -1
  60. package/dist/{DialogHeader-DKt_lREy.js → DialogHeader-CPhEYbZ1.js} +1 -1
  61. package/dist/Drawer/index.d.ts +1 -1
  62. package/dist/Drawer/index.js +1 -1
  63. package/dist/{Drawer-D63qUfxP.js → Drawer-C0ntt2L9.js} +1 -1
  64. package/dist/DropdownMenu/index.js +2 -2
  65. package/dist/{DropdownMenu-BkTjcbtP.js → DropdownMenu-CSWLdtI4.js} +7 -7
  66. package/dist/Field/index.js +3 -3
  67. package/dist/{Field-DgtZ9Czv.js → Field-BYAHZ4s7.js} +2 -2
  68. package/dist/{FieldIcon-BU1ZWAuo.js → FieldIcon-C6A69-um.js} +1 -1
  69. package/dist/{FieldInfoTip-D4vkQb2F.js → FieldInfoTip-6IHEEEJL.js} +2 -2
  70. package/dist/{FieldLabel-DkElUlTP.js → FieldLabel-CHaeZROf.js} +2 -2
  71. package/dist/FieldStatus/index.js +1 -1
  72. package/dist/{FieldStatus-DmCWPT6U.js → FieldStatus-QjwGygl3.js} +1 -1
  73. package/dist/FileInput/index.js +1 -1
  74. package/dist/{FileInput-epZuREvN.js → FileInput-DD3DvIT0.js} +5 -5
  75. package/dist/HoverCard/index.d.ts +1 -1
  76. package/dist/Icon/index.js +2 -2
  77. package/dist/{Icon-Dk0jccgU.js → Icon-BUSj1-Th.js} +1 -1
  78. package/dist/{Icon-M1Rlknd0.js → Icon-CYXC4iYF.js} +1 -1
  79. package/dist/IconButton/index.js +1 -1
  80. package/dist/{IconButton-ddP2kBOE.js → IconButton-CzU-cz_H.js} +1 -1
  81. package/dist/Indicator/index.d.ts +2 -2
  82. package/dist/Indicator/index.js +1 -1
  83. package/dist/InfoTip/index.d.ts +1 -1
  84. package/dist/InfoTip/index.js +1 -1
  85. package/dist/{InfoTip-D2rbGvF9.js → InfoTip-Ckhg715K.js} +1 -1
  86. package/dist/{InputClearButton-pGsDJl26.js → InputClearButton-Btjd5Lnk.js} +2 -2
  87. package/dist/InputGroup/index.js +1 -1
  88. package/dist/{InputGroup-BIVCj2rq.js → InputGroup-C388xPHC.js} +1 -1
  89. package/dist/Layout/index.js +2 -2
  90. package/dist/{Layout-DIs9FbLS.js → Layout-DTSKNAzq.js} +1 -1
  91. package/dist/{LayoutPanel-DPueklAW.js → LayoutPanel-CH4HZGLR.js} +1 -1
  92. package/dist/Lightbox/index.js +1 -1
  93. package/dist/{Lightbox-CYFqIuYF.js → Lightbox-CQhmsbhy.js} +2 -2
  94. package/dist/Link/index.d.ts +1 -1
  95. package/dist/Link/index.js +1 -1
  96. package/dist/{Link-Bte02xvC.js → Link-BsmxrY3Y.js} +1 -1
  97. package/dist/List/index.js +1 -1
  98. package/dist/{ListItem-DyJ5nTUB.js → ListItem-BEc2EF1u.js} +1 -1
  99. package/dist/Markdown/index.d.ts +1 -1
  100. package/dist/Markdown/index.js +1 -1
  101. package/dist/{Markdown-DLOM7sua.js → Markdown-BkL2wt7F.js} +3 -3
  102. package/dist/{MediaTheme-CBkEmVe4.js → MediaTheme-BavxpAJt.js} +5 -77
  103. package/dist/MoreMenu/index.d.ts +1 -1
  104. package/dist/MoreMenu/index.js +1 -1
  105. package/dist/{MoreMenu-Dfw9RqEG.js → MoreMenu-pvuN9vfu.js} +4 -4
  106. package/dist/MultiSelector/index.d.ts +1 -1
  107. package/dist/MultiSelector/index.js +1 -1
  108. package/dist/{MultiSelector-670gfK2P.js → MultiSelector-sD97taHQ.js} +8 -8
  109. package/dist/{NavHeadingSurface-CyzeGig1.js → NavHeadingSurface-C3QJ64vm.js} +1 -1
  110. package/dist/NumberInput/index.d.ts +1 -1
  111. package/dist/NumberInput/index.js +1 -1
  112. package/dist/{NumberInput-CoozsQxb.js → NumberInput-B3Y_NOui.js} +6 -6
  113. package/dist/OverflowList/index.d.ts +1 -1
  114. package/dist/Overlay/index.d.ts +1 -1
  115. package/dist/Pagination/index.js +1 -1
  116. package/dist/{Pagination-HRiDkiv1.js → Pagination-BJKFuELz.js} +2 -2
  117. package/dist/{PickerWheel-BH7fotFp.js → PickerWheel-J5F_ecWb.js} +1 -1
  118. package/dist/Popover/index.d.ts +2 -2
  119. package/dist/Popover/index.js +1 -1
  120. package/dist/{Popover-CIfmPr2b.js → Popover-CVZnqsUy.js} +4 -4
  121. package/dist/PowerSearch/index.d.ts +1 -1
  122. package/dist/PowerSearch/index.js +1 -1
  123. package/dist/{PowerSearch-lZ7C-9_i.js → PowerSearch-BHTHVINR.js} +21 -21
  124. package/dist/Radio/index.d.ts +1 -1
  125. package/dist/Radio/index.js +1 -1
  126. package/dist/{RadioGroup-DE0vl44p.js → RadioGroup-CvMj98z_.js} +2 -2
  127. package/dist/RadioList/index.d.ts +1 -1
  128. package/dist/RadioList/index.js +1 -1
  129. package/dist/{RadioListItem-CMH7E4o4.js → RadioListItem-CptY2wdB.js} +1 -1
  130. package/dist/Resizable/index.js +1 -1
  131. package/dist/{ResizeHandle-IXhzcM0r.js → ResizeHandle-ruXeaXUT.js} +1 -1
  132. package/dist/ScrollableArea/index.d.ts +1 -1
  133. package/dist/SegmentedControl/index.js +1 -1
  134. package/dist/{SegmentedControl-DfQbw_Kx.js → SegmentedControl-DMxIY7uq.js} +1 -1
  135. package/dist/SelectableCard/index.d.ts +1 -1
  136. package/dist/Selector/index.d.ts +1 -1
  137. package/dist/Selector/index.js +1 -1
  138. package/dist/{Selector-BA_Br1PQ.js → Selector-DhKtSP71.js} +7 -7
  139. package/dist/SideNav/index.d.ts +1 -1
  140. package/dist/SideNav/index.js +2 -2
  141. package/dist/{SideNav-iTVaFVr8.js → SideNav-DOXNxEIp.js} +7 -7
  142. package/dist/Slider/index.js +1 -1
  143. package/dist/{Slider-Dd-7-KDB.js → Slider-D5GYcH4S.js} +1 -1
  144. package/dist/Spinner/index.js +1 -1
  145. package/dist/{Spinner-D1adu3uH.js → Spinner-lLOYfbOY.js} +1 -1
  146. package/dist/Stepper/index.d.ts +1 -1
  147. package/dist/Stepper/index.js +1 -1
  148. package/dist/{Stepper-2Pzjo2X6.js → Stepper-0ycdCwND.js} +1 -1
  149. package/dist/Switch/index.d.ts +1 -1
  150. package/dist/Switch/index.js +1 -1
  151. package/dist/{Switch-CDzpdofs.js → Switch-DDHf_9iJ.js} +2 -2
  152. package/dist/TabList/index.js +1 -1
  153. package/dist/{TabList-2WI0pFSQ.js → TabList-BnLUktgm.js} +1 -1
  154. package/dist/Table/index.d.ts +1 -1
  155. package/dist/Table/index.js +1 -1
  156. package/dist/{Table-Dv2v2Qn1.js → Table-B49mlc0R.js} +13 -13
  157. package/dist/TextArea/index.d.ts +1 -1
  158. package/dist/TextArea/index.js +1 -1
  159. package/dist/{TextArea-DVaMUVoM.js → TextArea-BSB5WIpK.js} +6 -6
  160. package/dist/TextInput/index.d.ts +1 -1
  161. package/dist/TextInput/index.js +1 -1
  162. package/dist/{TextInput-CuZ0_q-W.js → TextInput-Ck-6Mtbt.js} +6 -6
  163. package/dist/Theme/index.d.ts +3 -3
  164. package/dist/Theme/index.js +3 -3
  165. package/dist/{Theme-CwruhtLu.js → Theme-B_kAJHy2.js} +111 -23
  166. package/dist/Thumbnail/index.js +1 -1
  167. package/dist/{Thumbnail-DdWfJKHa.js → Thumbnail-Tg50Msul.js} +3 -3
  168. package/dist/{TimeField-BxM1p1iV.js → TimeField-CLD_j1tX.js} +7 -7
  169. package/dist/TimeInput/index.d.ts +1 -1
  170. package/dist/TimeInput/index.js +1 -1
  171. package/dist/{TimeInput-OazN0w6r.js → TimeInput-DuijuQMd.js} +2 -2
  172. package/dist/Timestamp/index.d.ts +1 -1
  173. package/dist/Timestamp/index.js +1 -1
  174. package/dist/{Timestamp-B6Ob-xlj.js → Timestamp-D8fyTuhk.js} +2 -2
  175. package/dist/Toast/index.js +1 -1
  176. package/dist/{Toast-CW2ML8tU.js → Toast-51l_F_YA.js} +4 -3
  177. package/dist/ToggleButton/index.d.ts +1 -1
  178. package/dist/ToggleButton/index.js +1 -1
  179. package/dist/{ToggleButton-8XAM4Mko.js → ToggleButton-_fEU63Nz.js} +1 -1
  180. package/dist/Token/index.d.ts +1 -1
  181. package/dist/Tokenizer/index.js +1 -1
  182. package/dist/{Tokenizer-OZbI0TqN.js → Tokenizer-wWybLovw.js} +9 -9
  183. package/dist/Toolbar/index.d.ts +1 -1
  184. package/dist/Tooltip/index.d.ts +1 -1
  185. package/dist/TopNav/index.d.ts +1 -1
  186. package/dist/TopNav/index.js +1 -1
  187. package/dist/{TopNav-Bea1f-4t.js → TopNav-GvK-XIRl.js} +3 -3
  188. package/dist/TreeList/index.js +1 -1
  189. package/dist/{TreeList-DEGpCrNi.js → TreeList-CfELZwbQ.js} +5 -5
  190. package/dist/Typeahead/index.js +2 -2
  191. package/dist/{Typeahead-BONCIm6m.js → Typeahead-DtNM4311.js} +5 -5
  192. package/dist/{accessibleName-YrrAARQX.js → accessibleName-CYV4uRm9.js} +3 -3
  193. package/dist/{adaptationTypes-D874ONPJ.d.ts → adaptationTypes-D5HrfPSt.d.ts} +9 -0
  194. package/dist/{assertOptions-Byu4Yqfg.js → assertOptions-BOwrrTT-.js} +1 -1
  195. package/dist/colorMode-DVs86FF2.js +49 -0
  196. package/dist/{compactDefinition-CMTR5KqU.d.ts → compactDefinition-BPg0hR8Q.d.ts} +1 -1
  197. package/dist/{compactDefinition-BeFUKEFg.js → compactDefinition-D32f2O_H.js} +1 -1
  198. package/dist/composables/index.d.ts +2 -2
  199. package/dist/composables/index.js +7 -7
  200. package/dist/{composables-BJfZbXeW.js → composables-D5840uKi.js} +1 -1
  201. package/dist/{context-DArta_KP.js → context-CLCiYDtY.js} +1 -1
  202. package/dist/context-CwV8eyUd.js +12 -0
  203. package/dist/contrast-B0fsdq4U.js +75 -0
  204. package/dist/{index-Pad9p8CU.d.ts → index-Ak1b0V24.d.ts} +1 -1
  205. package/dist/{index-BrY-v2wz.d.ts → index-Bk2SsmEu.d.ts} +3 -3
  206. package/dist/{index-BDZCJ9ri.d.ts → index-BuubzuE8.d.ts} +2 -2
  207. package/dist/{index-Dgl2rXqH.d.ts → index-BzaRSOA3.d.ts} +2 -1
  208. package/dist/index-CDZhxbEp.d.ts +44 -0
  209. package/dist/{index-CQi9WGWE.d.ts → index-CEdoNcHF.d.ts} +1 -1
  210. package/dist/{index-DkYOGpsC.d.ts → index-CTo75wH5.d.ts} +1 -1
  211. package/dist/{index-V6uruC4Z.d.ts → index-CqvIpZ-t.d.ts} +1 -1
  212. package/dist/{index-JE1HrzdJ.d.ts → index-DVX2jlTQ.d.ts} +2 -2
  213. package/dist/{index-DPhQZXYw.d.ts → index-DYabo8TI.d.ts} +1 -1
  214. package/dist/{index-BtqvPjAf.d.ts → index-DofC9Rll.d.ts} +1 -1
  215. package/dist/{index-CTASAiq2.d.ts → index-EyFu5eSZ.d.ts} +3 -3
  216. package/dist/{index-EUzmHHm6.d.ts → index-WBF_zxXX.d.ts} +2 -2
  217. package/dist/{index-DxFU2kv3.d.ts → index-ZXDolNI1.d.ts} +29 -29
  218. package/dist/index.d.ts +20 -18
  219. package/dist/index.js +85 -84
  220. package/dist/{landing-CwF_76em.js → landing-DjJvKu3c.js} +1 -1
  221. package/dist/{lazyBottomSheet-COX_Z3-V.js → lazyBottomSheet-DUPKYGf1.js} +1 -1
  222. package/dist/motionTokenDefaults-EFzpiAF5.js +38 -0
  223. package/dist/palette/index.d.ts +3 -0
  224. package/dist/palette/index.js +2 -0
  225. package/dist/palette-DlNBLR8U.js +2114 -0
  226. package/dist/{presentationHold-ZKixVLcz.js → presentationHold-Bjjux3fp.js} +1 -1
  227. package/dist/{reportChange-DuOzs-8h.js → reportChange-wIeU3q3y.js} +1 -1
  228. package/dist/{resizableChannel-6oZZNYYM.js → resizableChannel-b7iQNnCj.js} +2 -2
  229. package/dist/{themeTiming-Cv_hsTJU.js → themeTiming-DOf0j6SM.js} +2 -1
  230. package/dist/{tokenReferences-sKpv-7_O.js → tokenReferences-CdmofltU.js} +1 -38
  231. package/dist/{triggerVariant-DPuBmzpp.js → triggerVariant-CRQoD-4F.js} +1 -1
  232. package/dist/{types-D97oBk6c.d.ts → types-DTlpQo7j.d.ts} +1 -1
  233. package/dist/types-DypDQlbk.d.ts +176 -0
  234. package/dist/{useAnimatedLayout-CVYflMPG.js → useAnimatedLayout-CXjd5pjG.js} +1 -1
  235. package/dist/{useChatStreamScroll-3mJvbNtI.js → useChatStreamScroll-BQpGHGAr.js} +1 -1
  236. package/dist/{useHeldPresentation-CaIKTwUh.js → useHeldPresentation-0Z0Untra.js} +1 -1
  237. package/dist/{useIndicator-PFDBNOvX.js → useIndicator-Co1ERlg-.js} +2 -2
  238. package/dist/{useInputStatusIcon-CV8qfqzK.js → useInputStatusIcon-DJfhmCiH.js} +2 -2
  239. package/dist/{useMediaQuery-BzXGT1Aw.js → useMediaQuery-DKnSDG3S.js} +1 -1
  240. package/dist/{useMenuHover-DoBatZeD.js → useMenuHover-Dahcf3qo.js} +1 -1
  241. package/dist/{useMobileKeyboard-DOa93Ek2.js → useMobileKeyboard-Cibxl8ZC.js} +1 -1
  242. package/dist/{useResizable-9WyAIDnz.js → useResizable-CJQAV_tU.js} +1 -1
  243. package/dist/useResolvedColorMode-CyZjLvfj.js +159 -0
  244. package/dist/{useTypeaheadMenuConfig-DUZD3GqE.js → useTypeaheadMenuConfig-0glQWHQd.js} +1 -1
  245. package/package.json +5 -1
  246. package/dist/context-Cws_tXTr.js +0 -7
  247. package/dist/useResolvedColorMode-Df97_9w_.js +0 -78
  248. package/dist/{index-BqhgeAT4.d.ts → index-5FGt4HsB.d.ts} +1 -1
@@ -0,0 +1,2114 @@
1
+ import { t as resolveTokenReferences } from "./tokenReferences-CdmofltU.js";
2
+ import { n as resolveLightDark } from "./colorMode-DVs86FF2.js";
3
+ import { r as parseColor$1 } from "./contrast-B0fsdq4U.js";
4
+ //#region src/palette/color.ts
5
+ function srgbToLinear(channel) {
6
+ const value = channel / 255;
7
+ return value <= .04045 ? value / 12.92 : ((value + .055) / 1.055) ** 2.4;
8
+ }
9
+ function linearToSrgb(channel) {
10
+ const value = channel <= .0031308 ? channel * 12.92 : 1.055 * channel ** (1 / 2.4) - .055;
11
+ return Math.round(Math.min(255, Math.max(0, value * 255)));
12
+ }
13
+ function hexToRgb(hex) {
14
+ const value = hex.replace("#", "");
15
+ const full = value.length === 3 ? value[0] + value[0] + value[1] + value[1] + value[2] + value[2] : value.slice(0, 6);
16
+ const numeric = Number.parseInt(full, 16);
17
+ return [
18
+ numeric >> 16 & 255,
19
+ numeric >> 8 & 255,
20
+ numeric & 255
21
+ ];
22
+ }
23
+ function rgbToHex(red, green, blue) {
24
+ return `#${[
25
+ red,
26
+ green,
27
+ blue
28
+ ].map((channel) => Math.round(Math.max(0, Math.min(255, channel))).toString(16).padStart(2, "0")).join("")}`;
29
+ }
30
+ function linearRgbToOklab(red, green, blue) {
31
+ const lRoot = Math.cbrt(.4122214708 * red + .5363325363 * green + .0514459929 * blue);
32
+ const mRoot = Math.cbrt(.2119034982 * red + .6806995451 * green + .1073969566 * blue);
33
+ const sRoot = Math.cbrt(.0883024619 * red + .2817188376 * green + .6299787005 * blue);
34
+ return [
35
+ .2104542553 * lRoot + .793617785 * mRoot - .0040720468 * sRoot,
36
+ 1.9779984951 * lRoot - 2.428592205 * mRoot + .4505937099 * sRoot,
37
+ .0259040371 * lRoot + .7827717662 * mRoot - .808675766 * sRoot
38
+ ];
39
+ }
40
+ function oklabToLinearRgb(lightness, a, b) {
41
+ const lRoot = lightness + .3963377774 * a + .2158037573 * b;
42
+ const mRoot = lightness - .1055613458 * a - .0638541728 * b;
43
+ const sRoot = lightness - .0894841775 * a - 1.291485548 * b;
44
+ const l = lRoot ** 3;
45
+ const m = mRoot ** 3;
46
+ const s = sRoot ** 3;
47
+ return [
48
+ 4.0767416621 * l - 3.3077115913 * m + .2309699292 * s,
49
+ -1.2684380046 * l + 2.6097574011 * m - .3413193965 * s,
50
+ -.0041960863 * l - .7034186147 * m + 1.707614701 * s
51
+ ];
52
+ }
53
+ function normalizeColor(input) {
54
+ const value = String(input).trim();
55
+ if (/^#?[0-9a-f]{3}$/i.test(value)) {
56
+ const hex = value.replace("#", "").toLowerCase();
57
+ return `#${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`;
58
+ }
59
+ if (/^#?[0-9a-f]{6}$/i.test(value)) return `#${value.replace("#", "").toLowerCase()}`;
60
+ throw new Error(`Invalid color: ${String(input)}`);
61
+ }
62
+ function hexToOklch(hex) {
63
+ const [red, green, blue] = hexToRgb(normalizeColor(hex));
64
+ const [lightness, a, b] = linearRgbToOklab(srgbToLinear(red), srgbToLinear(green), srgbToLinear(blue));
65
+ let hue = Math.atan2(b, a) * 180 / Math.PI;
66
+ if (hue < 0) hue += 360;
67
+ return {
68
+ L: lightness,
69
+ C: Math.sqrt(a * a + b * b),
70
+ H: hue
71
+ };
72
+ }
73
+ function oklchInGamut(lightness, chroma, hue) {
74
+ const radians = hue * Math.PI / 180;
75
+ const [red, green, blue] = oklabToLinearRgb(lightness, chroma * Math.cos(radians), chroma * Math.sin(radians));
76
+ return red >= -.001 && red <= 1.001 && green >= -.001 && green <= 1.001 && blue >= -.001 && blue <= 1.001;
77
+ }
78
+ function oklchToHex(lightness, chroma, hue) {
79
+ if (lightness <= 0) return "#000000";
80
+ if (lightness >= 1) return "#ffffff";
81
+ const radians = hue * Math.PI / 180;
82
+ const [red, green, blue] = oklabToLinearRgb(lightness, chroma * Math.cos(radians), chroma * Math.sin(radians));
83
+ return rgbToHex(linearToSrgb(Math.max(0, red)), linearToSrgb(Math.max(0, green)), linearToSrgb(Math.max(0, blue)));
84
+ }
85
+ function maxOklchChroma(hue, lightness) {
86
+ let low = 0;
87
+ let high = .4;
88
+ for (let index = 0; index < 20; index++) {
89
+ const middle = (low + high) / 2;
90
+ if (oklchInGamut(lightness, middle, hue)) low = middle;
91
+ else high = middle;
92
+ }
93
+ return low;
94
+ }
95
+ function oklchClampedHex(lightness, chroma, hue) {
96
+ if (oklchInGamut(lightness, chroma, hue)) return oklchToHex(lightness, chroma, hue);
97
+ return oklchToHex(lightness, maxOklchChroma(hue, lightness), hue);
98
+ }
99
+ function toneToOklabLightness(tone) {
100
+ if (tone <= 0) return 0;
101
+ if (tone >= 100) return 1;
102
+ const relative = tone > 8 ? ((tone + 16) / 116) ** 3 : tone / 903.3;
103
+ return Math.cbrt(relative);
104
+ }
105
+ function luminance(hex) {
106
+ const [red, green, blue] = hexToRgb(hex).map(srgbToLinear);
107
+ return .2126 * red + .7152 * green + .0722 * blue;
108
+ }
109
+ function oklabCoordinates(hex) {
110
+ const value = hexToOklch(hex);
111
+ const radians = value.H * Math.PI / 180;
112
+ return [
113
+ value.L,
114
+ value.C * Math.cos(radians),
115
+ value.C * Math.sin(radians)
116
+ ];
117
+ }
118
+ function oklabCoordinatesToHex(coordinates) {
119
+ const [lightness, a, b] = coordinates;
120
+ const chroma = Math.sqrt(a * a + b * b);
121
+ const hue = (Math.atan2(b, a) * 180 / Math.PI + 360) % 360;
122
+ return oklchClampedHex(Math.min(1, Math.max(0, lightness)), chroma, hue);
123
+ }
124
+ //#endregion
125
+ //#region src/palette/generatorRamp.ts
126
+ /**
127
+ * @param [chromaMultiplier] Share of its in-gamut chroma the stop
128
+ * keeps (see darkChromaMultiplier).
129
+ */
130
+ function generateCandidate(source, tone, mode, vibrancy, coordinateWithOtherFamilies, chromaMultiplier = 1, recipe = PALETTE_RECIPE) {
131
+ const adjustedTone = tone;
132
+ const adjustedHue = toneAdjustedHue(source.hue, adjustedTone);
133
+ let chroma = (coordinateWithOtherFamilies ? coordinatedChroma(source.chroma) : source.chroma) * vibrancyMultiplier(vibrancy) * hueBalanceFactor(adjustedHue) * highToneChromaFactor(adjustedHue, adjustedTone) * toneChromaEnvelope(adjustedTone) * (mode === "dark" ? DARK_CHROMA_FACTOR : 1);
134
+ const lightness = toneToOklabLightness(adjustedTone);
135
+ const maxChroma = maxOklchChroma(adjustedHue, lightness);
136
+ if (recipe === "astryx-oklch-v2" && !coordinateWithOtherFamilies) chroma *= grayFade(lightness);
137
+ if (recipe === "astryx-oklch-v2" && coordinateWithOtherFamilies && adjustedTone > 50) {
138
+ const shape = hueBalanceFactor(adjustedHue) * highToneChromaFactor(adjustedHue, adjustedTone) * toneChromaEnvelope(adjustedTone) * (mode === "dark" ? DARK_CHROMA_FACTOR : 1);
139
+ const share = smoothstep((MOST_VIVID_CHROMA * vibrancyMultiplier(50) * shape / Math.max(maxChroma, 1e-6) - V2_SHARED_FROM) / (2 - V2_SHARED_FROM));
140
+ if (share > 0) {
141
+ const most = MOST_VIVID_CHROMA * vibrancyMultiplier(100) * shape;
142
+ const shared = coordinatedChroma(source.chroma, recipe) * vibrancyMultiplier(vibrancy) * shape / most * maxChroma;
143
+ chroma = (1 - share) * Math.min(chroma, maxChroma) + share * shared;
144
+ }
145
+ }
146
+ return {
147
+ hex: oklchClampedHex(lightness, chromaMultiplier === 1 ? chroma : Math.min(chroma, maxChroma) * chromaMultiplier, adjustedHue),
148
+ gamutMapped: chroma > maxChroma + 1e-6
149
+ };
150
+ }
151
+ function perceptualDelta(colorA, colorB) {
152
+ const [lightnessA, aA, bA] = oklabCoordinates(colorA);
153
+ const [lightnessB, aB, bB] = oklabCoordinates(colorB);
154
+ return Math.sqrt((lightnessA - lightnessB) ** 2 + (aA - aB) ** 2 + (bA - bB) ** 2) * 100;
155
+ }
156
+ function interpolateColor(colorA, colorB, amount) {
157
+ const start = hexToOklch(colorA);
158
+ const end = hexToOklch(colorB);
159
+ return oklchClampedHex(start.L + (end.L - start.L) * amount, start.C + (end.C - start.C) * amount, interpolateHue(start.H, end.H, amount));
160
+ }
161
+ function applyAnchor(candidate, anchor) {
162
+ const target = normalizeColor(anchor.color);
163
+ let generatedColor = candidate;
164
+ if (anchor.policy === "exact") generatedColor = target;
165
+ else if (anchor.policy === "bounded") {
166
+ const tolerance = Number(anchor.maxDeltaE);
167
+ if (!Number.isFinite(tolerance) || tolerance < 0) throw new Error(`Bounded anchor at stop ${anchor.stop} requires a non-negative maxDeltaE.`);
168
+ if (perceptualDelta(candidate, target) > tolerance) {
169
+ let low = 0;
170
+ let high = 1;
171
+ for (let index = 0; index < 18; index++) {
172
+ const amount = (low + high) / 2;
173
+ if (perceptualDelta(interpolateColor(target, candidate, amount), target) <= tolerance) low = amount;
174
+ else high = amount;
175
+ }
176
+ generatedColor = interpolateColor(target, candidate, low);
177
+ }
178
+ } else if (anchor.policy === "flexible") generatedColor = interpolateColor(candidate, target, .35);
179
+ else throw new Error(`Unknown anchor policy: ${anchor.policy}`);
180
+ return {
181
+ ...anchor,
182
+ color: target,
183
+ generatedColor,
184
+ deltaE: perceptualDelta(generatedColor, target)
185
+ };
186
+ }
187
+ function smoothstep(amount) {
188
+ const value = clamp(amount, 0, 1);
189
+ return value * value * (3 - 2 * value);
190
+ }
191
+ function interpolateDelta(start, end, amount) {
192
+ return [
193
+ start[0] + (end[0] - start[0]) * amount,
194
+ start[1] + (end[1] - start[1]) * amount,
195
+ start[2] + (end[2] - start[2]) * amount
196
+ ];
197
+ }
198
+ function correctionAtStop(corrections, stop) {
199
+ const zero = [
200
+ 0,
201
+ 0,
202
+ 0
203
+ ];
204
+ if (corrections.length === 0) return zero;
205
+ const first = corrections[0];
206
+ if (stop <= first.stop) {
207
+ const boundary = Math.max(0, first.stop - 25);
208
+ if (stop <= boundary && boundary !== first.stop) return zero;
209
+ const amount = boundary === first.stop ? 1 : smoothstep((stop - boundary) / (first.stop - boundary));
210
+ return interpolateDelta(zero, first.delta, amount);
211
+ }
212
+ const last = corrections[corrections.length - 1];
213
+ if (stop >= last.stop) {
214
+ const boundary = Math.min(100, last.stop + 25);
215
+ if (stop >= boundary && boundary !== last.stop) return zero;
216
+ const amount = boundary === last.stop ? 1 : smoothstep((stop - last.stop) / (boundary - last.stop));
217
+ return interpolateDelta(last.delta, zero, amount);
218
+ }
219
+ const upperIndex = corrections.findIndex((item) => item.stop > stop);
220
+ const lower = corrections[upperIndex - 1];
221
+ const upper = corrections[upperIndex];
222
+ return interpolateDelta(lower.delta, upper.delta, smoothstep((stop - lower.stop) / (upper.stop - lower.stop)));
223
+ }
224
+ function applyAnchorCorrections(colors, stops, anchors) {
225
+ if (anchors.length === 0) return {
226
+ colors,
227
+ anchors: []
228
+ };
229
+ const corrections = anchors.map((anchor) => {
230
+ const candidate = colors[anchor.stop];
231
+ const result = applyAnchor(candidate, anchor);
232
+ const base = oklabCoordinates(candidate);
233
+ const target = oklabCoordinates(result.generatedColor);
234
+ const delta = [
235
+ target[0] - base[0],
236
+ target[1] - base[1],
237
+ target[2] - base[2]
238
+ ];
239
+ return {
240
+ stop: anchor.stop,
241
+ delta,
242
+ result
243
+ };
244
+ }).sort((a, b) => a.stop - b.stop);
245
+ const corrected = {};
246
+ for (const stop of stops) {
247
+ const base = oklabCoordinates(colors[stop]);
248
+ const delta = correctionAtStop(corrections, stop);
249
+ corrected[stop] = oklabCoordinatesToHex([
250
+ base[0] + delta[0],
251
+ base[1] + delta[1],
252
+ base[2] + delta[2]
253
+ ]);
254
+ }
255
+ for (const correction of corrections) corrected[correction.stop] = correction.result.generatedColor;
256
+ return {
257
+ colors: corrected,
258
+ anchors: corrections.map((correction) => correction.result)
259
+ };
260
+ }
261
+ function assertAnchorSet(anchors, stops) {
262
+ const seen = /* @__PURE__ */ new Set();
263
+ for (const anchor of anchors) {
264
+ const color = normalizeColor(anchor.color);
265
+ if (!["light", "dark"].includes(anchor.mode)) throw new Error(`Unknown anchor mode: ${anchor.mode}`);
266
+ if (!stops.includes(anchor.stop)) throw new Error(`Anchor stop ${anchor.stop} is not present in the requested stop layout.`);
267
+ if (anchor.stop === 0 && color !== "#000000" || anchor.stop === 100 && color !== "#ffffff") throw new Error(`Anchor stop ${anchor.stop} is reserved for exact ${anchor.stop === 0 ? "black" : "white"}; use an interior stop for a tinted endpoint.`);
268
+ const key = `${anchor.mode}:${anchor.stop}`;
269
+ if (seen.has(key)) throw new Error(`Duplicate anchor for ${anchor.mode} stop ${anchor.stop}.`);
270
+ seen.add(key);
271
+ }
272
+ }
273
+ function buildDiagnostics(colors, stops, sourceHue, gamutMappedStops, anchors) {
274
+ let monotonic = true;
275
+ let minimumAdjacentDeltaE = Number.POSITIVE_INFINITY;
276
+ let maximumAdjacentDeltaE = 0;
277
+ let maximumHueDrift = 0;
278
+ let hueIdentityRisk = null;
279
+ for (let index = 0; index < stops.length; index++) {
280
+ const color = colors[stops[index]];
281
+ const oklch = hexToOklch(color);
282
+ if (oklch.C >= .015) {
283
+ const drift = signedHueDelta(sourceHue, oklch.H);
284
+ maximumHueDrift = Math.max(maximumHueDrift, hueDistance(sourceHue, oklch.H));
285
+ if (sourceHue >= 230 && sourceHue < 285 && drift > 12) hueIdentityRisk = "blue-to-purple";
286
+ if (sourceHue >= 70 && sourceHue < 115 && drift < -12) hueIdentityRisk = "yellow-to-brown";
287
+ }
288
+ if (index === 0) continue;
289
+ const previous = colors[stops[index - 1]];
290
+ if (luminance(color) + 1e-6 < luminance(previous)) monotonic = false;
291
+ const adjacentDelta = perceptualDelta(previous, color);
292
+ minimumAdjacentDeltaE = Math.min(minimumAdjacentDeltaE, adjacentDelta);
293
+ maximumAdjacentDeltaE = Math.max(maximumAdjacentDeltaE, adjacentDelta);
294
+ }
295
+ return {
296
+ monotonic,
297
+ minimumAdjacentDeltaE: minimumAdjacentDeltaE === Number.POSITIVE_INFINITY ? 0 : minimumAdjacentDeltaE,
298
+ maximumAdjacentDeltaE,
299
+ maximumHueDrift,
300
+ hueIdentityRisk,
301
+ gamutMappedStops,
302
+ anchors
303
+ };
304
+ }
305
+ /**
306
+ * The share of its chroma a stop keeps under the request's
307
+ * `darkChromaTaper`: the edge multiplier through `throughStop`, a smoothstep
308
+ * back to 1 at `recoverAtStop`, and 1 from there on. Light ramps, neutral
309
+ * families, and the black and white endpoints keep all of it.
310
+ */
311
+ function darkChromaMultiplier(taper, family, mode, stop) {
312
+ if (!taper || mode !== "dark" || family.kind === "neutral") return 1;
313
+ if (stop <= 0 || stop >= 100 || stop >= taper.recoverAtStop) return 1;
314
+ const edge = Object.hasOwn(taper.familyMultipliers, family.id) ? taper.familyMultipliers[family.id] : taper.edgeMultiplier;
315
+ if (stop <= taper.throughStop) return edge;
316
+ const recovery = smoothstep((stop - taper.throughStop) / (taper.recoverAtStop - taper.throughStop));
317
+ return edge + (1 - edge) * recovery;
318
+ }
319
+ function generateRamp(request, family, mode) {
320
+ const seedHex = normalizeColor(family.seed);
321
+ const anchors = (family.anchors ?? []).filter((anchor) => anchor.mode === mode);
322
+ assertAnchorSet(family.anchors ?? [], request.stops);
323
+ const seed = family.kind === "neutral" ? neutralPolar(request.neutralProfile, seedHex) : colorToPolar(seedHex);
324
+ const colors = {};
325
+ const gamutMappedStops = [];
326
+ const diagnosticReference = generateCandidate(seed, 50, mode, request.vibrancy, family.kind !== "neutral", darkChromaMultiplier(request.darkChromaTaper, family, mode, 50), request.recipe).hex;
327
+ for (const stop of request.stops) {
328
+ const generated = generateCandidate(anchorPolarAtStop(seed, anchors, stop), stop, mode, request.vibrancy, family.kind !== "neutral", darkChromaMultiplier(request.darkChromaTaper, family, mode, stop), request.recipe);
329
+ colors[stop] = generated.hex;
330
+ if (generated.gamutMapped) gamutMappedStops.push(stop);
331
+ }
332
+ const corrected = applyAnchorCorrections(colors, request.stops, anchors);
333
+ const diagnostics = buildDiagnostics(corrected.colors, request.stops, hexToOklch(diagnosticReference).H, gamutMappedStops, corrected.anchors);
334
+ if (!diagnostics.monotonic) throw new Error(`${family.name} ${mode} ramp is not luminance-monotonic with the requested anchors.`);
335
+ return {
336
+ colors: corrected.colors,
337
+ diagnostics
338
+ };
339
+ }
340
+ //#endregion
341
+ //#region src/palette/generatorBase.ts
342
+ /** The recipe a request that names none runs: the first one. */
343
+ const PALETTE_RECIPE = "astryx-oklch-v1";
344
+ /**
345
+ * The recipe whose pale stops follow the vibrancy and the seed's own
346
+ * chroma: a stop whose gamut cannot hold the most vivid request gives every
347
+ * request the same share of it, and coordination never raises a seed's
348
+ * chroma. A request runs it by naming it.
349
+ */
350
+ const PALETTE_RECIPE_V2 = "astryx-oklch-v2";
351
+ /** Every recipe the generator runs. */
352
+ const PALETTE_RECIPES = Object.freeze([PALETTE_RECIPE, PALETTE_RECIPE_V2]);
353
+ const PALETTE_BLACK = "#000000";
354
+ const PALETTE_WHITE = "#ffffff";
355
+ const DEFAULT_21_STOPS = Object.freeze([
356
+ 0,
357
+ 5,
358
+ 10,
359
+ 15,
360
+ 20,
361
+ 25,
362
+ 30,
363
+ 35,
364
+ 40,
365
+ 45,
366
+ 50,
367
+ 55,
368
+ 60,
369
+ 65,
370
+ 70,
371
+ 75,
372
+ 80,
373
+ 85,
374
+ 90,
375
+ 95,
376
+ 100
377
+ ]);
378
+ const COMPACT_11_STOPS = Object.freeze([
379
+ 0,
380
+ 10,
381
+ 20,
382
+ 30,
383
+ 40,
384
+ 50,
385
+ 60,
386
+ 70,
387
+ 80,
388
+ 90,
389
+ 100
390
+ ]);
391
+ const DARK_CHROMA_FACTOR = .85;
392
+ const RESERVED_FAMILY_IDS = Object.freeze(["black", "white"]);
393
+ const NEUTRAL_PROFILES = [
394
+ "neutral-v1",
395
+ "warm-v1",
396
+ "cool-v1",
397
+ "custom"
398
+ ];
399
+ function clamp(value, minimum, maximum) {
400
+ return Math.min(maximum, Math.max(minimum, value));
401
+ }
402
+ function normalizeHue(hue) {
403
+ return (hue % 360 + 360) % 360;
404
+ }
405
+ function hueDistance(a, b) {
406
+ const difference = Math.abs(normalizeHue(a) - normalizeHue(b));
407
+ return Math.min(difference, 360 - difference);
408
+ }
409
+ function signedHueDelta(from, to) {
410
+ return (normalizeHue(to) - normalizeHue(from) + 540) % 360 - 180;
411
+ }
412
+ function interpolateHue(a, b, amount) {
413
+ return normalizeHue(a + ((b - a + 540) % 360 - 180) * amount);
414
+ }
415
+ function validateStops(stops) {
416
+ if (!Array.isArray(stops) || stops.length === 0) throw new Error("A palette requires at least one stop.");
417
+ for (const stop of stops) if (!Number.isFinite(stop) || stop < 0 || stop > 100) throw new Error(`Stop ${stop} must be a finite number from 0 to 100.`);
418
+ for (let index = 1; index < stops.length; index++) if (stops[index] <= stops[index - 1]) throw new Error("Stops must be unique and strictly increasing.");
419
+ return [...stops];
420
+ }
421
+ Object.freeze([
422
+ "recipe",
423
+ "vibrancy",
424
+ "neutralProfile",
425
+ "modeStrategy",
426
+ "darkChromaTaper",
427
+ "stops",
428
+ "families"
429
+ ]);
430
+ const DARK_CHROMA_TAPER_KEYS = Object.freeze([
431
+ "edgeMultiplier",
432
+ "throughStop",
433
+ "recoverAtStop",
434
+ "familyMultipliers"
435
+ ]);
436
+ Object.freeze([
437
+ "id",
438
+ "name",
439
+ "seed",
440
+ "kind",
441
+ "anchors"
442
+ ]);
443
+ Object.freeze([
444
+ "mode",
445
+ "stop",
446
+ "color",
447
+ "policy",
448
+ "maxDeltaE"
449
+ ]);
450
+ /**
451
+ * The modes a mode strategy generates.
452
+ */
453
+ function modesForStrategy(strategy) {
454
+ if (strategy === "light-only") return ["light"];
455
+ if (strategy === "dark-only") return ["dark"];
456
+ if (strategy === "light-and-dark") return ["light", "dark"];
457
+ throw new Error(`Unknown mode strategy: ${strategy}`);
458
+ }
459
+ function hueBalanceFactor(hue) {
460
+ const normalized = normalizeHue(hue);
461
+ if (normalized >= 70 && normalized < 115) return .94;
462
+ if (normalized >= 115 && normalized < 175) return .78;
463
+ if (normalized >= 175 && normalized < 230) return .82;
464
+ if (normalized >= 285 && normalized < 340) return .9;
465
+ return 1;
466
+ }
467
+ function highToneChromaFactor(hue, tone) {
468
+ if (tone <= 60) return 1;
469
+ const taper = smoothstep((tone - 60) / 35);
470
+ const normalized = normalizeHue(hue);
471
+ if (normalized >= 115 && normalized < 175) return 1 - .28 * taper;
472
+ if (normalized >= 175 && normalized < 200) return 1 - .4 * taper;
473
+ return 1;
474
+ }
475
+ function toneAdjustedHue(hue, tone) {
476
+ const normalized = normalizeHue(hue);
477
+ if (normalized < 40 || normalized >= 70 || tone >= 50) return normalized;
478
+ const darkening = clamp((50 - tone) / 40, 0, 1);
479
+ return normalizeHue(normalized - 8 * Math.sqrt(darkening));
480
+ }
481
+ function toneChromaEnvelope(tone) {
482
+ const normalized = clamp(tone / 100, 0, 1);
483
+ return .18 + .82 * Math.sqrt(Math.max(0, Math.sin(Math.PI * normalized)));
484
+ }
485
+ function vibrancyMultiplier(vibrancy) {
486
+ if (!Number.isFinite(vibrancy) || vibrancy < 0 || vibrancy > 100) throw new Error("Vibrancy must be a number from 0 to 100.");
487
+ if (vibrancy <= 25) return vibrancy / 25 * .72;
488
+ if (vibrancy <= 50) return .72 + (vibrancy - 25) / 25 * .28;
489
+ return 1 + (vibrancy - 50) * .0096;
490
+ }
491
+ /**
492
+ * A family's chroma drawn toward the shared one, so its families sit
493
+ * together. As v2 shares a narrow stop's gamut it is never raised above the
494
+ * seed's own, so a dusty seed stays dusty in its pale stops.
495
+ */
496
+ function coordinatedChroma(sourceChroma, recipe = PALETTE_RECIPE) {
497
+ const drawn = sourceChroma * .35 + .18 * .65;
498
+ return recipe === "astryx-oklch-v2" ? Math.min(sourceChroma, drawn) : drawn;
499
+ }
500
+ /**
501
+ * How narrow a stop's gamut is for v2 to share it: the most vivid seed at
502
+ * the default vibrancy asks this many times what the stop holds. From the
503
+ * first the stop starts to share its gamut in proportion; from the second
504
+ * it shares it wholly.
505
+ */
506
+ const V2_SHARED_FROM = 1.3;
507
+ /**
508
+ * The share of its chroma a v2 gray family keeps at a lightness. It keeps
509
+ * all of it up to GRAY_FADE_FROM. Above that the share falls linearly to
510
+ * GRAY_FADE_LEAST at GRAY_FADE_TO, as gray scales fade their tint toward
511
+ * white: a slate's palest grays keep about a sixth of its color.
512
+ * @param lightness OKLab lightness
513
+ */
514
+ function grayFade(lightness) {
515
+ const t = clamp((lightness - GRAY_FADE_FROM) / (GRAY_FADE_TO - GRAY_FADE_FROM), 0, 1);
516
+ return 1 - (1 - GRAY_FADE_LEAST) * t;
517
+ }
518
+ const GRAY_FADE_FROM = .7;
519
+ const GRAY_FADE_TO = .97;
520
+ const GRAY_FADE_LEAST = .28;
521
+ /** The chroma of the most vivid seed sRGB holds, as v2 coordinates it. */
522
+ const MOST_VIVID_CHROMA = coordinatedChroma(.32, PALETTE_RECIPE_V2);
523
+ function colorToPolar(color) {
524
+ const value = hexToOklch(color);
525
+ return {
526
+ lightness: value.L,
527
+ chroma: value.C,
528
+ hue: value.H
529
+ };
530
+ }
531
+ function neutralPolar(profile, seed) {
532
+ if (profile === "custom") return colorToPolar(seed);
533
+ const hue = profile === "warm-v1" ? 75 : profile === "cool-v1" ? 250 : 0;
534
+ if (![
535
+ "neutral-v1",
536
+ "warm-v1",
537
+ "cool-v1"
538
+ ].includes(profile)) throw new Error(`Unknown neutral profile: ${profile}`);
539
+ return {
540
+ lightness: .5,
541
+ chroma: profile === "neutral-v1" ? 0 : .018,
542
+ hue
543
+ };
544
+ }
545
+ function anchorPolarAtStop(seed, anchors, stop) {
546
+ if (anchors.length === 0) return seed;
547
+ const sorted = [...anchors].sort((a, b) => a.stop - b.stop);
548
+ const lower = [...sorted].reverse().find((anchor) => anchor.stop <= stop);
549
+ const upper = sorted.find((anchor) => anchor.stop >= stop);
550
+ if (!lower || !upper || lower.stop === upper.stop) return colorToPolar(normalizeColor((lower ?? upper ?? sorted[0]).color));
551
+ const start = colorToPolar(normalizeColor(lower.color));
552
+ const end = colorToPolar(normalizeColor(upper.color));
553
+ const amount = (stop - lower.stop) / (upper.stop - lower.stop);
554
+ return {
555
+ lightness: start.lightness + (end.lightness - start.lightness) * amount,
556
+ chroma: start.chroma + (end.chroma - start.chroma) * amount,
557
+ hue: interpolateHue(start.hue, end.hue, amount)
558
+ };
559
+ }
560
+ //#endregion
561
+ //#region src/palette/generatorRequest.ts
562
+ function nearestStop$1(stops, target) {
563
+ return stops.reduce((best, stop) => Math.abs(stop - target) < Math.abs(best - target) ? stop : best);
564
+ }
565
+ function buildCoordinationDiagnostics(request, families) {
566
+ const stop = nearestStop$1(request.stops, 50);
567
+ const chromaticIds = new Set(request.families.filter((family) => family.kind !== "neutral").map((family) => family.id));
568
+ return modesForStrategy(request.modeStrategy).map((mode) => {
569
+ const samples = families.filter((family) => chromaticIds.has(family.id) && family[mode]).map((family) => {
570
+ const ramp = family[mode];
571
+ if (!ramp) throw new Error(`Missing ${mode} ramp for ${family.id}.`);
572
+ const color = ramp.colors[stop];
573
+ return {
574
+ id: family.id,
575
+ name: family.name,
576
+ color,
577
+ chroma: hexToOklch(color).C
578
+ };
579
+ });
580
+ let closestFamilies = null;
581
+ let minimumFamilyDeltaE = Number.POSITIVE_INFINITY;
582
+ for (let index = 0; index < samples.length; index++) for (let next = index + 1; next < samples.length; next++) {
583
+ const delta = perceptualDelta(samples[index].color, samples[next].color);
584
+ if (delta < minimumFamilyDeltaE) {
585
+ minimumFamilyDeltaE = delta;
586
+ closestFamilies = [samples[index].name, samples[next].name];
587
+ }
588
+ }
589
+ const byChroma = [...samples].sort((a, b) => a.chroma - b.chroma);
590
+ const weakest = byChroma[0];
591
+ const strongest = byChroma[byChroma.length - 1];
592
+ return {
593
+ mode,
594
+ stop,
595
+ closestFamilies,
596
+ minimumFamilyDeltaE: minimumFamilyDeltaE === Number.POSITIVE_INFINITY ? null : minimumFamilyDeltaE,
597
+ strongestFamily: strongest?.name ?? null,
598
+ weakestFamily: weakest?.name ?? null,
599
+ chromaRatio: weakest && strongest && weakest.chroma > 1e-4 ? strongest.chroma / weakest.chroma : null
600
+ };
601
+ });
602
+ }
603
+ function assertMultiplier(value, label) {
604
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) throw new Error(`${label} must be a number from 0 to 1.`);
605
+ return value;
606
+ }
607
+ /**
608
+ * The request's dark chroma taper, checked against its stops and families,
609
+ * or undefined when the request has none. The receipt records the taper, so
610
+ * a field the taper does not read fails instead of changing nothing.
611
+ */
612
+ function normalizeDarkChromaTaper(taper, stops, families) {
613
+ if (taper == null) return;
614
+ if (typeof taper !== "object" || Array.isArray(taper)) throw new TypeError("darkChromaTaper must be an object.");
615
+ const fields = taper;
616
+ const unread = Object.keys(fields).filter((key) => !DARK_CHROMA_TAPER_KEYS.includes(key));
617
+ if (unread.length > 0) throw new Error(`darkChromaTaper does not read ${unread.join(", ")}; it reads ${DARK_CHROMA_TAPER_KEYS.join(", ")}.`);
618
+ const { edgeMultiplier, throughStop, recoverAtStop, familyMultipliers } = fields;
619
+ const edge = assertMultiplier(edgeMultiplier, "darkChromaTaper.edgeMultiplier");
620
+ if (typeof throughStop !== "number" || !stops.includes(throughStop)) throw new Error("darkChromaTaper.throughStop must be a stop in the requested stop layout.");
621
+ if (typeof recoverAtStop !== "number" || !stops.includes(recoverAtStop) || recoverAtStop <= throughStop) throw new Error("darkChromaTaper.recoverAtStop must be a stop in the requested stop layout after throughStop.");
622
+ if (familyMultipliers != null && (typeof familyMultipliers !== "object" || Array.isArray(familyMultipliers))) throw new Error("darkChromaTaper.familyMultipliers must be an object.");
623
+ const multipliers = {};
624
+ for (const [id, value] of Object.entries(familyMultipliers ?? {})) {
625
+ const family = families.find((candidate) => candidate.id === id);
626
+ if (!family) throw new Error(`darkChromaTaper.familyMultipliers names unknown family ${id}.`);
627
+ if (family.kind === "neutral") throw new Error(`darkChromaTaper.familyMultipliers names neutral family ${id}; the taper changes only chromatic families.`);
628
+ multipliers[id] = assertMultiplier(value, `darkChromaTaper.familyMultipliers.${id}`);
629
+ }
630
+ return {
631
+ edgeMultiplier: edge,
632
+ throughStop,
633
+ recoverAtStop,
634
+ familyMultipliers: multipliers
635
+ };
636
+ }
637
+ function normalizeGenerationRequest(input) {
638
+ if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("Palette generation config must be an object.");
639
+ const families = input.families;
640
+ if (!Array.isArray(families) || families.length === 0) throw new Error("Palette generation requires at least one family.");
641
+ const recipe = input.recipe ?? "astryx-oklch-v1";
642
+ if (!PALETTE_RECIPES.includes(recipe)) throw new Error(`Unknown palette recipe: ${input.recipe} (known: ${PALETTE_RECIPES.join(", ")}).`);
643
+ const modeStrategy = input.modeStrategy ?? "light-and-dark";
644
+ const modes = modesForStrategy(modeStrategy);
645
+ const stops = validateStops(input.stops ?? DEFAULT_21_STOPS);
646
+ const ids = /* @__PURE__ */ new Set();
647
+ const normalizedFamilies = families.map((family, index) => {
648
+ if (!family || typeof family !== "object" || Array.isArray(family)) throw new Error(`Family ${index} must be an object.`);
649
+ const id = `${family.id ?? ""}`.trim();
650
+ if (!/^[a-z][a-z0-9-]*$/.test(id)) throw new Error(`Family ${index} id must use lower-kebab-case characters.`);
651
+ if (RESERVED_FAMILY_IDS.includes(id)) throw new Error(`Family id ${id} is reserved for the standalone ${id} palette value.`);
652
+ if (ids.has(id)) throw new Error(`Duplicate family id: ${id}.`);
653
+ ids.add(id);
654
+ const kind = family.kind ?? "chromatic";
655
+ if (!["chromatic", "neutral"].includes(kind)) throw new Error(`Unknown family kind: ${kind}`);
656
+ if (family.anchors != null && !Array.isArray(family.anchors)) throw new Error(`Family ${id} anchors must be an array.`);
657
+ const anchors = (family.anchors ?? []).map((anchor, anchorIndex) => {
658
+ if (!anchor || typeof anchor !== "object" || Array.isArray(anchor)) throw new Error(`Family ${id} anchor ${anchorIndex} must be an object.`);
659
+ if (!["light", "dark"].includes(anchor.mode)) throw new Error(`Unknown anchor mode: ${anchor.mode}`);
660
+ if (!modes.includes(anchor.mode)) throw new Error(`Anchor mode ${anchor.mode} is not generated by mode strategy ${modeStrategy}.`);
661
+ if (!Number.isFinite(anchor.stop) || !stops.includes(anchor.stop)) throw new Error(`Anchor stop ${anchor.stop} is not present in the requested stop layout.`);
662
+ if (![
663
+ "exact",
664
+ "bounded",
665
+ "flexible"
666
+ ].includes(anchor.policy)) throw new Error(`Unknown anchor policy: ${anchor.policy}`);
667
+ const maxDeltaE = anchor.maxDeltaE;
668
+ if (anchor.policy === "bounded" && (typeof maxDeltaE !== "number" || !Number.isFinite(maxDeltaE) || maxDeltaE < 0)) throw new Error(`Bounded anchor at stop ${anchor.stop} requires a non-negative maxDeltaE.`);
669
+ if (anchor.policy !== "bounded" && maxDeltaE != null) throw new Error(`Anchor policy ${anchor.policy} does not accept maxDeltaE.`);
670
+ const color = normalizeColor(anchor.color);
671
+ if (anchor.stop === 0 && color !== "#000000" || anchor.stop === 100 && color !== "#ffffff") throw new Error(`Anchor stop ${anchor.stop} is reserved for exact ${anchor.stop === 0 ? "black" : "white"}; use an interior stop for a tinted endpoint.`);
672
+ return {
673
+ mode: anchor.mode,
674
+ stop: anchor.stop,
675
+ color,
676
+ policy: anchor.policy,
677
+ ...anchor.policy === "bounded" ? { maxDeltaE } : {}
678
+ };
679
+ });
680
+ return {
681
+ id,
682
+ name: `${family.name ?? id}`,
683
+ seed: normalizeColor(family.seed),
684
+ kind,
685
+ anchors
686
+ };
687
+ });
688
+ const neutralProfile = input.neutralProfile ?? "neutral-v1";
689
+ if (!NEUTRAL_PROFILES.includes(neutralProfile)) throw new Error(`Unknown neutral profile: ${neutralProfile}`);
690
+ const darkChromaTaper = normalizeDarkChromaTaper(input.darkChromaTaper, stops, normalizedFamilies);
691
+ const request = {
692
+ recipe,
693
+ vibrancy: input.vibrancy ?? 50,
694
+ neutralProfile,
695
+ modeStrategy,
696
+ ...darkChromaTaper ? { darkChromaTaper } : {},
697
+ stops,
698
+ families: normalizedFamilies
699
+ };
700
+ vibrancyMultiplier(request.vibrancy);
701
+ return request;
702
+ }
703
+ function generatePaletteSet(input) {
704
+ const request = normalizeGenerationRequest(input);
705
+ const families = [];
706
+ const errors = [];
707
+ for (const family of request.families) try {
708
+ const generated = {
709
+ id: family.id,
710
+ name: family.name,
711
+ seed: family.seed
712
+ };
713
+ for (const mode of modesForStrategy(request.modeStrategy)) generated[mode] = generateRamp(request, family, mode);
714
+ families.push(generated);
715
+ } catch (error) {
716
+ errors.push({
717
+ familyId: family.id,
718
+ message: error instanceof Error ? error.message : String(error)
719
+ });
720
+ }
721
+ return {
722
+ recipe: request.recipe,
723
+ status: "candidate",
724
+ request,
725
+ families,
726
+ coordination: buildCoordinationDiagnostics(request, families),
727
+ errors
728
+ };
729
+ }
730
+ /**
731
+ * Generate candidate palette data without reading or writing files.
732
+ */
733
+ function generateTonalPalette(input) {
734
+ const result = generatePaletteSet(input);
735
+ if (result.errors.length > 0) throw new Error(result.errors.map((error) => `${error.familyId}: ${error.message}`).join("\n"));
736
+ return {
737
+ schemaVersion: 1,
738
+ status: "candidate",
739
+ recipe: result.recipe,
740
+ black: PALETTE_BLACK,
741
+ white: PALETTE_WHITE,
742
+ stops: [...result.request.stops],
743
+ palette: Object.fromEntries(result.families.map((family) => [family.id, {
744
+ name: family.name,
745
+ ...family.light ? { light: family.light.colors } : {},
746
+ ...family.dark ? { dark: family.dark.colors } : {}
747
+ }]))
748
+ };
749
+ }
750
+ //#endregion
751
+ //#region src/palette/colorDefaults.ts
752
+ /**
753
+ * 调色板按它来量的那套默认颜色:没有主题时 Astryx 的颜色令牌,写成 `light-dark()`
754
+ * 和 `var()` 引用,名字用不带前缀的写法。`themePalette()` 拿它当底,
755
+ * 选出来的灰阶、状态色文字都以它为准。
756
+ */
757
+ const colorDefaults = {
758
+ "--color-accent": "light-dark(#0064E0, #0171E3)",
759
+ "--color-accent-muted": "light-dark(#0082FB33, #0082FB3F)",
760
+ "--color-on-accent": "light-dark(#FFFFFF, #FFFFFF)",
761
+ "--color-neutral": "light-dark(rgba(5, 54, 89, 0.1), rgba(223, 226, 229, 0.2))",
762
+ "--color-background-surface": "light-dark(#FFFFFF, #1F1F22)",
763
+ "--color-background-body": "light-dark(#F1F4F7, #111112)",
764
+ "--color-overlay": "light-dark(#01122866, #11111299)",
765
+ "--color-overlay-hover": "light-dark(#0536590C, #FFFFFF0C)",
766
+ "--color-overlay-pressed": "light-dark(#05365919, #FFFFFF19)",
767
+ "--color-background-muted": "light-dark(#0536590C, #1111127F)",
768
+ "--color-text-primary": "light-dark(#0A1317, #DFE2E5)",
769
+ "--color-text-secondary": "light-dark(#445564, #B0B5BB)",
770
+ "--color-text-disabled": "light-dark(#A4B0BC, #6F747C)",
771
+ "--color-text-accent": "light-dark(#0064E0, #3E9EFB)",
772
+ "--color-on-dark": "light-dark(#FFFFFF, #FFFFFF)",
773
+ "--color-on-light": "light-dark(#000000, #000000)",
774
+ "--color-icon-accent": "light-dark(#0064E0, #2694FE)",
775
+ "--color-icon-primary": "light-dark(#0A1317, #DFE2E5)",
776
+ "--color-icon-secondary": "light-dark(#4E606F, #AAAFB5)",
777
+ "--color-icon-disabled": "light-dark(#A4B0BC, #6F747C)",
778
+ "--color-background-card": "light-dark(#FFFFFF, #1F1F22)",
779
+ "--color-background-popover": "light-dark(#FFFFFF, #28292C)",
780
+ "--color-background-inverted": "light-dark(#0A1317, #FFFFFF)",
781
+ "--color-background-error-inverted": "light-dark(#AA071E, #E3193B)",
782
+ "--color-info": "light-dark(#0064E0, #0064E0)",
783
+ "--color-info-muted": "light-dark(#0082FB33, #0082FB3F)",
784
+ "--color-on-info": "light-dark(#FFFFFF, #FFFFFF)",
785
+ "--color-success": "light-dark(#0D8626, #0D8626)",
786
+ "--color-success-muted": "light-dark(#0B991F33, #0B991F3F)",
787
+ "--color-on-success": "light-dark(#FFFFFF, #FFFFFF)",
788
+ "--color-error": "light-dark(#E3193B, #F5394F)",
789
+ "--color-error-muted": "light-dark(#E3193B33, #F5394F3F)",
790
+ "--color-on-error": "light-dark(#FFFFFF, #0A1317)",
791
+ "--color-warning": "light-dark(#E9AF08, #F2C00B)",
792
+ "--color-warning-muted": "light-dark(#E2A40033, #E2A4003F)",
793
+ "--color-on-warning": "light-dark(#0A1317, #0A1317)",
794
+ "--color-text-info": "var(--color-text-blue)",
795
+ "--color-text-success": "var(--color-text-green)",
796
+ "--color-text-warning": "var(--color-text-yellow)",
797
+ "--color-text-error": "var(--color-text-red)",
798
+ "--color-icon-info": "var(--color-text-info)",
799
+ "--color-icon-success": "var(--color-text-success)",
800
+ "--color-icon-warning": "var(--color-text-warning)",
801
+ "--color-icon-error": "var(--color-text-error)",
802
+ "--color-border-info": "var(--color-text-info)",
803
+ "--color-border-success": "var(--color-text-success)",
804
+ "--color-border-warning": "var(--color-text-warning)",
805
+ "--color-border-error": "var(--color-text-error)",
806
+ "--color-on-info-muted": "var(--color-text-blue)",
807
+ "--color-on-success-muted": "var(--color-text-green)",
808
+ "--color-on-warning-muted": "var(--color-text-yellow)",
809
+ "--color-on-error-muted": "var(--color-text-red)",
810
+ "--color-border": "light-dark(#05365919, #F2F4F619)",
811
+ "--color-border-emphasized": "light-dark(#CCD3DB, #494D53)",
812
+ "--color-skeleton": "light-dark(#CCD3DB, #5A5E66)",
813
+ "--color-track": "light-dark(#CCD3DB, #5A5E66)",
814
+ "--color-shadow": "light-dark(rgba(5, 54, 89, 0.1), rgba(0, 0, 0, 0.3))",
815
+ "--color-tint-hover": "light-dark(black, white)",
816
+ "--color-background-blue": "light-dark(#0171E333, #0171E333)",
817
+ "--color-border-blue": "light-dark(#0064E0, #2694FE)",
818
+ "--color-icon-blue": "light-dark(#0064E0, #2694FE)",
819
+ "--color-text-blue": "light-dark(#042F97, #AFD7FF)",
820
+ "--color-background-cyan": "light-dark(#03A7D733, #03A7D733)",
821
+ "--color-border-cyan": "light-dark(#089DD0, #0171A4)",
822
+ "--color-icon-cyan": "light-dark(#00ACC1, #26C6DA)",
823
+ "--color-text-cyan": "light-dark(#014975, #A1EEF9)",
824
+ "--color-background-gray": "light-dark(#0A131733, #666A724C)",
825
+ "--color-border-gray": "light-dark(#647685, #748695)",
826
+ "--color-icon-gray": "light-dark(#4E606F, #AAAFB5)",
827
+ "--color-text-gray": "light-dark(#0A1317, #E7EAED)",
828
+ "--color-background-green": "light-dark(#24BB5E33, #24BB5E33)",
829
+ "--color-border-green": "light-dark(#0D8626, #0B991F)",
830
+ "--color-icon-green": "light-dark(#0D8626, #26A756)",
831
+ "--color-text-green": "light-dark(#09441F, #A5F690)",
832
+ "--color-background-orange": "light-dark(#F2790233, #F2790233)",
833
+ "--color-border-orange": "light-dark(#EB6E00, #B34A01)",
834
+ "--color-icon-orange": "light-dark(#E9690B, #FB8C00)",
835
+ "--color-text-orange": "light-dark(#6B2203, #FDB876)",
836
+ "--color-background-pink": "light-dark(#E638B333, #E638B333)",
837
+ "--color-border-pink": "light-dark(#F351C0, #C02294)",
838
+ "--color-icon-pink": "light-dark(#C2185B, #EC407A)",
839
+ "--color-text-pink": "light-dark(#650053, #FEADE3)",
840
+ "--color-background-purple": "light-dark(#7952FF33, #7952FF33)",
841
+ "--color-border-purple": "light-dark(#9081FF, #7340FE)",
842
+ "--color-icon-purple": "light-dark(#5B08D8, #7952FF)",
843
+ "--color-text-purple": "light-dark(#3E0697, #B3B0FE)",
844
+ "--color-background-red": "light-dark(#E3193B33, #E3193B33)",
845
+ "--color-border-red": "light-dark(#E3193B, #F5394F)",
846
+ "--color-icon-red": "light-dark(#D31130, #E3193B)",
847
+ "--color-text-red": "light-dark(#7B0210, #FFB2B8)",
848
+ "--color-background-teal": "light-dark(#0DB7AF33, #0DB7AF33)",
849
+ "--color-border-teal": "light-dark(#08A3A3, #08767D)",
850
+ "--color-icon-teal": "light-dark(#009688, #26A69A)",
851
+ "--color-text-teal": "light-dark(#083943, #40DCCD)",
852
+ "--color-background-yellow": "light-dark(#E2A40033, #E2A40033)",
853
+ "--color-border-yellow": "light-dark(#C58600, #B47700)",
854
+ "--color-icon-yellow": "light-dark(#FBC02D, #FFEE58)",
855
+ "--color-text-yellow": "light-dark(#753F07, #FBCE03)",
856
+ "--focus-outline-color": "var(--color-accent)"
857
+ };
858
+ /** 某个模式下每个默认颜色的具体值,`light-dark()` 和 `var()` 都已展开。 */
859
+ function resolveDefaultColors(mode) {
860
+ const picked = {};
861
+ for (const [token, value] of Object.entries(colorDefaults)) picked[token] = resolveLightDark(value, mode);
862
+ return resolveTokenReferences(picked);
863
+ }
864
+ //#endregion
865
+ //#region src/palette/mappingTables.ts
866
+ /**
867
+ * A palette config as the generator's request. The generator checks every
868
+ * field it reads, and refuses a config it cannot run.
869
+ */
870
+ function asRequest(config) {
871
+ return config;
872
+ }
873
+ /** A family's stops in a mode. */
874
+ function rampOf(candidate, id, m) {
875
+ return candidate.palette[id]?.[m] ?? {};
876
+ }
877
+ /** One block of a part's styles, or undefined. */
878
+ function partStyle(components, part, block) {
879
+ const blocks = components?.[part];
880
+ const style = blocks && typeof blocks === "object" ? blocks[block] : void 0;
881
+ return style && typeof style === "object" ? style : void 0;
882
+ }
883
+ /** The color settings. Each one is a palette family of the same id. */
884
+ const PALETTE_DIALS = Object.freeze([
885
+ "accent",
886
+ "neutral",
887
+ "success",
888
+ "warning",
889
+ "danger",
890
+ "info"
891
+ ]);
892
+ /** A record without inherited keys, so a key such as `constructor` reads nothing. */
893
+ function ownTable(table) {
894
+ const own = (value) => {
895
+ if (Array.isArray(value)) return value.map(own);
896
+ if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) return value;
897
+ const out = Object.create(null);
898
+ for (const [key, entry] of Object.entries(value)) out[key] = own(entry);
899
+ return out;
900
+ };
901
+ return own(table);
902
+ }
903
+ /** The Core token word of each status family. */
904
+ const STATUS_TOKEN = ownTable({
905
+ success: "success",
906
+ warning: "warning",
907
+ danger: "error",
908
+ info: "info"
909
+ });
910
+ /** The main token a color setting feeds: the exact-token escape hatch for it. */
911
+ function paletteToken(dial) {
912
+ return dial === "accent" ? "--color-accent" : dial === "neutral" ? "--color-background-surface" : `--color-${STATUS_TOKEN[dial]}`;
913
+ }
914
+ /** Text contrast and non-text contrast (fills, focus rings, icons). */
915
+ const TEXT = 4.5;
916
+ /**
917
+ * The official Neutral theme's color mapping: each token's stops,
918
+ * `[light, dark]`, with an opacity where it has one. A test keeps it equal
919
+ * to the Neutral theme's source.
920
+ */
921
+ const OFFICIAL_NEUTRAL_STOPS = ownTable({
922
+ "--color-background-body": [{ stop: 95 }, { stop: 10 }],
923
+ "--color-background-surface": [{ stop: 100 }, { stop: 15 }],
924
+ "--color-background-card": [{ stop: 100 }, { stop: 10 }],
925
+ "--color-background-popover": [{ stop: 100 }, { stop: 10 }],
926
+ "--color-background-muted": [{ stop: 95 }, { stop: 10 }],
927
+ "--color-text-primary": [{ stop: 0 }, { stop: 100 }],
928
+ "--color-text-secondary": [{ stop: 30 }, { stop: 65 }],
929
+ "--color-text-disabled": [{ stop: 60 }, { stop: 35 }],
930
+ "--color-icon-primary": [{ stop: 0 }, { stop: 100 }],
931
+ "--color-icon-secondary": [{ stop: 45 }, { stop: 65 }],
932
+ "--color-icon-disabled": [{ stop: 60 }, { stop: 35 }],
933
+ "--color-border-emphasized": [{ stop: 85 }, { stop: 35 }],
934
+ "--color-skeleton": [{ stop: 85 }, { stop: 35 }],
935
+ "--color-on-dark": [{ stop: 100 }, { stop: 100 }],
936
+ "--color-on-light": [{ stop: 5 }, { stop: 5 }],
937
+ "--color-border": [{
938
+ stop: 0,
939
+ alpha: "14"
940
+ }, {
941
+ stop: 100,
942
+ alpha: "1a"
943
+ }],
944
+ "--color-overlay-hover": [{
945
+ stop: 0,
946
+ alpha: "0d"
947
+ }, {
948
+ stop: 100,
949
+ alpha: "0d"
950
+ }],
951
+ "--color-overlay-pressed": [{
952
+ stop: 0,
953
+ alpha: "1a"
954
+ }, {
955
+ stop: 100,
956
+ alpha: "1a"
957
+ }],
958
+ "--color-text-info": [{ stop: 45 }, { stop: 80 }],
959
+ "--color-accent-muted": [{ stop: 85 }, { stop: 30 }],
960
+ "--color-info-muted": [{ stop: 85 }, {
961
+ stop: 75,
962
+ alpha: "3d"
963
+ }],
964
+ "--color-on-info-muted": [{ stop: 25 }, { stop: 80 }],
965
+ "--color-on-accent": [{ stop: 100 }, { stop: 5 }]
966
+ });
967
+ /** The parts whose secondary text the official Neutral theme lifts, `[part, block]`. */
968
+ const OFFICIAL_NEUTRAL_LIFTED = Object.freeze([
969
+ ["item", "selected"],
970
+ ["tree-list-item", "selected"],
971
+ ["file-input", "mode:dropzone"],
972
+ ["citation", "variant:number"],
973
+ ["segmented-control-item", "base"],
974
+ ["card", "variant:blue"],
975
+ ["card", "variant:cyan"],
976
+ ["card", "variant:green"],
977
+ ["card", "variant:orange"],
978
+ ["card", "variant:pink"],
979
+ ["card", "variant:purple"],
980
+ ["card", "variant:red"],
981
+ ["card", "variant:teal"],
982
+ ["card", "variant:yellow"]
983
+ ]);
984
+ /** A token's official `[light, dark]` stops. */
985
+ function officialStops(token) {
986
+ return (OFFICIAL_NEUTRAL_STOPS[token] ?? []).map((x) => x.stop);
987
+ }
988
+ /**
989
+ * The tokens the neutral color sets at the official theme's stops: the
990
+ * page background and the surfaces on it. A warm or cool gray so reaches
991
+ * the page as it reaches the cards. The inverted surface (tooltips,
992
+ * toasts) is the card surface of the other mode, inside the ramp (never
993
+ * the white or black end every ramp shares), so it carries the neutral
994
+ * color. A layout without one of these stops uses the nearest one it has.
995
+ */
996
+ const NEUTRAL_STOPS = ownTable({
997
+ ...Object.fromEntries([
998
+ "--color-background-body",
999
+ "--color-background-surface",
1000
+ "--color-background-card",
1001
+ "--color-background-popover",
1002
+ "--color-background-muted",
1003
+ "--color-text-primary",
1004
+ "--color-text-secondary",
1005
+ "--color-text-disabled",
1006
+ "--color-icon-primary",
1007
+ "--color-icon-secondary",
1008
+ "--color-icon-disabled",
1009
+ "--color-border-emphasized",
1010
+ "--color-skeleton",
1011
+ "--color-on-dark",
1012
+ "--color-on-light"
1013
+ ].map((t) => [t, officialStops(t)])),
1014
+ "--color-background-inverted": [...officialStops("--color-background-card")].reverse()
1015
+ });
1016
+ /** Neutral tokens whose shade stays inside the ramp, off its white and black ends. */
1017
+ const NEUTRAL_INSIDE = Object.freeze(["--color-background-inverted"]);
1018
+ /** Neutral tints: a stop with an opacity, `[[stop, alpha], [stop, alpha]]`. */
1019
+ const NEUTRAL_TINTS = ownTable(Object.fromEntries([
1020
+ "--color-border",
1021
+ "--color-overlay-hover",
1022
+ "--color-overlay-pressed"
1023
+ ].map((t) => [t, (OFFICIAL_NEUTRAL_STOPS[t] ?? []).map((x) => [x.stop, String(x.alpha)])])));
1024
+ const TEXT_STOP = officialStops("--color-text-info");
1025
+ const ACCENT_MUTED = officialStops("--color-accent-muted");
1026
+ const STATUS_MUTED = (OFFICIAL_NEUTRAL_STOPS["--color-info-muted"] ?? []).map((x, i) => i === 0 ? x.stop : [x.stop, String(x.alpha)]);
1027
+ const ON_MUTED = officialStops("--color-on-info-muted");
1028
+ /**
1029
+ * The parts whose secondary text the official Neutral theme lifts, with
1030
+ * the block it lifts it in and what the text sits on: the accent tint,
1031
+ * except under segmented-control labels, which sit on the translucent
1032
+ * neutral track (`--color-neutral`).
1033
+ */
1034
+ const LIFT_PARTS = OFFICIAL_NEUTRAL_LIFTED.map(([part, block]) => [
1035
+ part,
1036
+ block,
1037
+ liftGround(part, block)
1038
+ ]);
1039
+ /**
1040
+ * What a lifted block's secondary text sits on: a card's own fill for a
1041
+ * card colour (the card variant rule lifts it there), the translucent
1042
+ * neutral track under segmented-control labels, else the accent tint.
1043
+ */
1044
+ function liftGround(part, block) {
1045
+ if (part === "segmented-control-item") return "--color-neutral";
1046
+ const color = part === "card" ? /^variant:([\w-]+)$/.exec(block)?.[1] : null;
1047
+ return color ? `--color-background-${color}` : "--color-accent-muted";
1048
+ }
1049
+ /** What each lifted background is, and the parts on it, for notes. */
1050
+ const LIFT_GROUNDS = {
1051
+ "--color-accent-muted": {
1052
+ what: "the accent tint",
1053
+ parts: "selected items and rows, a dropzone, numbered citations"
1054
+ },
1055
+ "--color-neutral": {
1056
+ what: "the neutral track",
1057
+ parts: "segmented-control labels"
1058
+ },
1059
+ ...Object.fromEntries(LIFT_PARTS.filter(([part]) => part === "card").map(([, block, g]) => {
1060
+ const color = block.replace(/^variant:/, "");
1061
+ return [g, {
1062
+ what: `the ${color} card fill`,
1063
+ parts: `${color} cards`
1064
+ }];
1065
+ }))
1066
+ };
1067
+ const BORDER = [80, 65];
1068
+ /**
1069
+ * Text on a fill, from the neutral family as the official themes take it:
1070
+ * white (100) first in light, near-black (5) first in dark, and near-black
1071
+ * first in both modes on warning. Without a neutral color, black and white.
1072
+ */
1073
+ const [ON_LIGHT, ON_DARK] = officialStops("--color-on-accent");
1074
+ const ON_FILL = ownTable({
1075
+ light: [ON_LIGHT, ON_DARK],
1076
+ dark: [ON_DARK, ON_LIGHT]
1077
+ });
1078
+ /** Text on surfaces darkens in light mode and lightens in dark mode. */
1079
+ const TOWARD_CONTRAST = ownTable({
1080
+ light: -1,
1081
+ dark: 1
1082
+ });
1083
+ //#endregion
1084
+ //#region src/palette/mappingTools.ts
1085
+ /**
1086
+ * Below this OKLCH chroma a seed reads as gray: its family is generated as a
1087
+ * neutral, so no hue is invented for it in either mode.
1088
+ */
1089
+ const GRAY_CHROMA = .02;
1090
+ /** Whether a seed reads as gray. */
1091
+ function isGray(seed) {
1092
+ return hexToOklch(seed).C < GRAY_CHROMA;
1093
+ }
1094
+ /** Whether two values are one color. */
1095
+ function sameColor(a, b) {
1096
+ try {
1097
+ return normalizeColor(String(a)) === normalizeColor(String(b));
1098
+ } catch {
1099
+ return false;
1100
+ }
1101
+ }
1102
+ /** RGB channels (0–255) as a lowercase six-digit hex. */
1103
+ function hex(rgb) {
1104
+ return `#${rgb.slice(0, 3).map((x) => Math.round(Math.max(0, Math.min(255, x))).toString(16).padStart(2, "0")).join("")}`;
1105
+ }
1106
+ /** The WCAG contrast ratio of two RGB colors, each rounded to a hex first. */
1107
+ function ratio(a, b) {
1108
+ const [x, y] = [luminance(hex(a)), luminance(hex(b))].sort((p, q) => q - p);
1109
+ return (x + .05) / (y + .05);
1110
+ }
1111
+ /** A color drawn at `alpha` over `under`, as the opaque color the eye sees. */
1112
+ function compositeOver(over, alpha, under) {
1113
+ return over.map((c, i) => c * alpha + under[i] * (1 - alpha));
1114
+ }
1115
+ /** A ratio to two decimals. */
1116
+ const round = (r) => Math.round(r * 100) / 100;
1117
+ /** A stop as text: a layout may hold 16.666666666666668. */
1118
+ const shade = (s) => String(round(s));
1119
+ /**
1120
+ * The stop of a ramp whose shade is nearest a color, as the eye compares
1121
+ * them; never an end stop (pure black or white, which every ramp shares).
1122
+ * Null for a ramp with no inner stop.
1123
+ */
1124
+ function nearestShade(ramp, color) {
1125
+ const inner = Object.keys(ramp).filter((s) => Number(s) > 0 && Number(s) < 100);
1126
+ if (!inner.length) return null;
1127
+ return inner.reduce((best, s) => perceptualDelta(ramp[s], color) < perceptualDelta(ramp[best], color) ? s : best);
1128
+ }
1129
+ /** The stop of a layout nearest `n`; on a tie, the one nearer the middle. */
1130
+ function nearestStop(stops, n) {
1131
+ return stops.reduce((best, s) => {
1132
+ const d = Math.abs(s - n) - Math.abs(best - n);
1133
+ return d < 0 || d === 0 && Math.abs(s - 50) < Math.abs(best - 50) ? s : best;
1134
+ });
1135
+ }
1136
+ /**
1137
+ * The light stop nearest a seed color in the ramp the generator grows from
1138
+ * it. The official themes anchor a brand color there, exactly, so the fill
1139
+ * keeps the color as given. The end stops are pure black and white and
1140
+ * never hold an anchor.
1141
+ */
1142
+ function seedStop(seed, config, kind = "chromatic") {
1143
+ const { palette } = generateTonalPalette({
1144
+ ...config.stops ? { stops: config.stops } : {},
1145
+ ...config.vibrancy != null ? { vibrancy: config.vibrancy } : {},
1146
+ ...kind === "neutral" ? { neutralProfile: "custom" } : {},
1147
+ modeStrategy: "light-only",
1148
+ families: [{
1149
+ id: "seed",
1150
+ seed,
1151
+ kind
1152
+ }]
1153
+ });
1154
+ const ramp = palette.seed.light;
1155
+ return Number(nearestShade(ramp, seed));
1156
+ }
1157
+ /**
1158
+ * A gray ramp the generator grows from a gray of the theme (its secondary
1159
+ * text), for a mode: the grays of a theme whose palette has no neutral
1160
+ * family. Null when the seed does not grow.
1161
+ */
1162
+ function grownGrays(seed, m) {
1163
+ try {
1164
+ return generateTonalPalette({
1165
+ modeStrategy: m === "light" ? "light-only" : "dark-only",
1166
+ neutralProfile: "custom",
1167
+ families: [{
1168
+ id: "gray",
1169
+ seed,
1170
+ kind: "neutral"
1171
+ }]
1172
+ }).palette.gray[m] ?? null;
1173
+ } catch {
1174
+ return null;
1175
+ }
1176
+ }
1177
+ /** A text shade, named for a sentence. */
1178
+ function textName(r) {
1179
+ return r.family === "white" || r.family === "neutral" && r.stop >= 95 ? "white" : r.family === "black" || r.family === "neutral" && r.stop <= 10 ? "near-black" : `shade ${r.stop}`;
1180
+ }
1181
+ /**
1182
+ * Look-ups shared by the request planner and the mapping, on one
1183
+ * candidate: the nearest stop, a stop's color, the surfaces text and fills
1184
+ * sit on, the text that reads on a fill, and the theme's exact colors.
1185
+ */
1186
+ function paletteTools(candidate, context) {
1187
+ const { base, reader } = context;
1188
+ const { stops } = candidate;
1189
+ const parseColor = reader.rgb;
1190
+ const alphaOf = reader.alpha;
1191
+ const contrast = (a, b) => {
1192
+ const x = parseColor(a);
1193
+ const y = parseColor(b);
1194
+ if (!x || !y) throw new Error(`No contrast between "${a}" and "${b}".`);
1195
+ return ratio(x, y);
1196
+ };
1197
+ const at = (n) => nearestStop(stops, n);
1198
+ /** The stop nearest `n` off the white and black ends. */
1199
+ const atInside = (n) => nearestStop(stops.filter((s) => s > 0 && s < 100), n);
1200
+ const ref = (id, m, stop, alpha) => {
1201
+ const color = rampOf(candidate, id, m)[stop];
1202
+ return alpha ? {
1203
+ stop,
1204
+ color: `${color}${alpha}`,
1205
+ alpha
1206
+ } : {
1207
+ stop,
1208
+ color
1209
+ };
1210
+ };
1211
+ const neutral = Boolean(candidate.palette.neutral);
1212
+ /** The value a token is set to exactly in a mode, as written, or undefined. */
1213
+ const settingOf = (token, m) => context.settingOf?.(token, m);
1214
+ const colorIn = (value, m) => {
1215
+ if (value == null) return null;
1216
+ if (context.colorIn) return context.colorIn(value, m);
1217
+ const v = value.trim();
1218
+ return parseColor(v) ? v : null;
1219
+ };
1220
+ /** The exact opaque color a token is set to in a mode, or null. */
1221
+ const exactOf = (token, m) => {
1222
+ const v = colorIn(settingOf(token, m), m);
1223
+ const rgb = v == null ? null : parseColor(v);
1224
+ return rgb && v != null && alphaOf(v) >= 1 ? hex(rgb) : null;
1225
+ };
1226
+ /**
1227
+ * The exact color a token is set to in a mode, see-through or not, as
1228
+ * written; null when there is none or it is not a fixed color.
1229
+ */
1230
+ const rawOf = (token, m) => colorIn(settingOf(token, m), m);
1231
+ /**
1232
+ * Which column of a `[light, dark]` mapping a mode takes: the light one
1233
+ * on a light page and the dark one on a dark page, by the base theme's
1234
+ * page, the one its surfaces were made for.
1235
+ */
1236
+ const side = (m) => {
1237
+ const page = base?.[m]?.["--color-background-body"];
1238
+ const rgb = page ? parseColor(page) : null;
1239
+ if (!rgb || alphaOf(page) < 1) return m === "light" ? 0 : 1;
1240
+ return ratio(rgb, [
1241
+ 255,
1242
+ 255,
1243
+ 255
1244
+ ]) > ratio(rgb, [
1245
+ 0,
1246
+ 0,
1247
+ 0
1248
+ ]) ? 1 : 0;
1249
+ };
1250
+ /**
1251
+ * What text and fills sit on in a mode: the theme's exact surface
1252
+ * colors, else the neutral color's surfaces, else the base theme's; the
1253
+ * family's own surface stop when nothing else is known.
1254
+ */
1255
+ const surfaces = (m, id) => {
1256
+ const out = [];
1257
+ for (const n of [
1258
+ "--color-background-surface",
1259
+ "--color-background-body",
1260
+ "--color-background-card"
1261
+ ]) {
1262
+ const own = neutral && NEUTRAL_STOPS[n] ? ref("neutral", m, at(NEUTRAL_STOPS[n][side(m)])).color : null;
1263
+ const v = exactOf(n, m) ?? own ?? base?.[m]?.[n];
1264
+ const rgb = v ? parseColor(v) : null;
1265
+ if (v && rgb && alphaOf(v) >= 1) out.push([n, hex(rgb)]);
1266
+ }
1267
+ if (!out.length) {
1268
+ const s = at(NEUTRAL_STOPS["--color-background-surface"][side(m)]);
1269
+ out.push([`${id} shade ${s}`, ref(id, m, s).color]);
1270
+ }
1271
+ return out;
1272
+ };
1273
+ /** The text shades for a fill, preferred first. */
1274
+ const onChoices = (id, m) => (id === "warning" ? [5, 100] : ON_FILL[m]).map((s) => neutral ? {
1275
+ ...ref("neutral", m, at(s)),
1276
+ family: "neutral"
1277
+ } : s >= 50 ? {
1278
+ stop: 100,
1279
+ color: PALETTE_WHITE,
1280
+ family: "white"
1281
+ } : {
1282
+ stop: 0,
1283
+ color: PALETTE_BLACK,
1284
+ family: "black"
1285
+ });
1286
+ /**
1287
+ * The text on a fill: the preferred shade when it reads at 4.5:1, else
1288
+ * the one that reads better.
1289
+ */
1290
+ const onFor = (id, m, fill) => {
1291
+ const [a, b] = onChoices(id, m).map((on) => ({
1292
+ on,
1293
+ r: contrast(on.color, fill)
1294
+ }));
1295
+ let best = a.r >= 4.5 || a.r >= b.r ? a : b;
1296
+ const other = best === a ? b : a;
1297
+ if (best.r < 4.5) {
1298
+ const dark = contrast(best.on.color, PALETTE_WHITE) > contrast(fill, PALETTE_WHITE);
1299
+ const end = neutral ? {
1300
+ ...ref("neutral", m, at(dark ? 0 : 100)),
1301
+ family: "neutral"
1302
+ } : dark ? {
1303
+ stop: 0,
1304
+ color: PALETTE_BLACK,
1305
+ family: "black"
1306
+ } : {
1307
+ stop: 100,
1308
+ color: PALETTE_WHITE,
1309
+ family: "white"
1310
+ };
1311
+ const r = contrast(end.color, fill);
1312
+ if (r > best.r) best = {
1313
+ on: end,
1314
+ r
1315
+ };
1316
+ }
1317
+ return {
1318
+ on: best.on,
1319
+ r: best.r,
1320
+ other: other.on,
1321
+ otherR: other.r,
1322
+ first: a.on
1323
+ };
1324
+ };
1325
+ /** The lowest contrast of a color on the surfaces. */
1326
+ const page = (color, m, id) => Math.min(...surfaces(m, id).map(([, bg]) => contrast(color, bg)));
1327
+ /** A color as the eye sees it on the surface in a mode. */
1328
+ const solid = (color, m, id) => {
1329
+ const rgb = parseColor(color);
1330
+ const a = alphaOf(color);
1331
+ if (a >= 1) return hex(rgb);
1332
+ return hex(compositeOver(rgb, a, parseColor(surfaces(m, id)[0][1])));
1333
+ };
1334
+ /** A translucent stop drawn over each surface; an opaque stop as it is. */
1335
+ const over = (name, r, under) => {
1336
+ if (!r.alpha) return [[name, r.color]];
1337
+ const top = parseColor(r.color.slice(0, 7));
1338
+ const a = Number.parseInt(r.alpha, 16) / 255;
1339
+ return under.map(([n, bg]) => [`${name} over ${n}`, hex(compositeOver(top, a, parseColor(bg)))]);
1340
+ };
1341
+ return {
1342
+ stops,
1343
+ at,
1344
+ atInside,
1345
+ ref,
1346
+ exactOf,
1347
+ settingOf,
1348
+ rawOf,
1349
+ side,
1350
+ solid,
1351
+ surfaces,
1352
+ onFor,
1353
+ page,
1354
+ neutral,
1355
+ contrast,
1356
+ over,
1357
+ parseColor,
1358
+ alphaOf
1359
+ };
1360
+ }
1361
+ /**
1362
+ * A part-style value's light and dark halves: a `[light, dark]` pair, a
1363
+ * `light-dark()` value split at its top-level comma, or one value for
1364
+ * both; null for anything else.
1365
+ */
1366
+ function sides(v) {
1367
+ if (Array.isArray(v)) return v;
1368
+ if (typeof v !== "string") return null;
1369
+ const inner = /^light-dark\((.*)\)$/s.exec(v.trim())?.[1];
1370
+ return inner ? splitTopComma(inner) : [v, v];
1371
+ }
1372
+ /** Splits a CSS value at its top-level commas (outside brackets). */
1373
+ function splitTopComma(value) {
1374
+ const out = [];
1375
+ let depth = 0;
1376
+ let cur = "";
1377
+ for (const c of value) {
1378
+ if (c === "(") depth++;
1379
+ if (c === ")") depth--;
1380
+ if (depth === 0 && c === ",") {
1381
+ out.push(cur);
1382
+ cur = "";
1383
+ } else cur += c;
1384
+ }
1385
+ out.push(cur);
1386
+ return out;
1387
+ }
1388
+ //#endregion
1389
+ //#region src/palette/mapFamily.ts
1390
+ function mapFamily(s, f) {
1391
+ const { fills, context, t, stops, at, ref, rawOf, settingOf, side, solid, surfaces, contrast, over, parseColor, alphaOf, has, modes, checks, exact, unread, reports, put, each, pick } = s;
1392
+ const word = f.id === "accent" ? null : STATUS_TOKEN[f.id];
1393
+ const names = word ? {
1394
+ fill: `--color-${word}`,
1395
+ on: `--color-on-${word}`,
1396
+ text: `--color-text-${word}`,
1397
+ icon: `--color-icon-${word}`,
1398
+ muted: `--color-${word}-muted`,
1399
+ onMuted: `--color-on-${word}-muted`,
1400
+ border: `--color-border-${word}`,
1401
+ focus: null
1402
+ } : {
1403
+ fill: "--color-accent",
1404
+ on: "--color-on-accent",
1405
+ text: "--color-text-accent",
1406
+ icon: "--color-icon-accent",
1407
+ muted: "--color-accent-muted",
1408
+ onMuted: null,
1409
+ border: null,
1410
+ focus: "--focus-outline-color"
1411
+ };
1412
+ const plain = fills[f.id];
1413
+ const S = plain.stop;
1414
+ const fillWord = f.id;
1415
+ const exactFill = {};
1416
+ for (const m of modes) {
1417
+ const v = rawOf(names.fill, m);
1418
+ if (v) exactFill[m] = v;
1419
+ else if (settingOf(names.fill, m) != null) unread[names.fill] = String(settingOf(names.fill, m)).trim();
1420
+ }
1421
+ if (Object.keys(exactFill).length) exact[names.fill] = Object.fromEntries(Object.entries(exactFill).map(([m, v]) => {
1422
+ const written = (settingOf(names.fill, m) ?? "").trim();
1423
+ const rgb = parseColor(v);
1424
+ const color = rgb && alphaOf(v) >= 1 ? hex(rgb) : v;
1425
+ return [m, /var\(/i.test(written) ? `${written} = ${color}` : v];
1426
+ }));
1427
+ const fill = {};
1428
+ for (const m of modes) {
1429
+ if (m === "light" || plain.dark) {
1430
+ fill[m] = {
1431
+ ...ref(f.id, m, S),
1432
+ exact: true
1433
+ };
1434
+ continue;
1435
+ }
1436
+ const start = at(70);
1437
+ const found = [...stops].filter((s) => s > 0 && s < 100).sort((a, b) => Math.abs(a - start) - Math.abs(b - start) || b - a).find((s) => {
1438
+ const c = ref(f.id, m, s).color;
1439
+ return t.page(c, m, f.id) >= 3 && t.onFor(f.id, m, c).r >= 4.5;
1440
+ }) ?? start;
1441
+ fill[m] = ref(f.id, m, found);
1442
+ const near = [...stops].filter((s) => s > 0 && s < 100).sort((a, b) => Math.abs(a - S) - Math.abs(b - S) || b - a).find((s) => {
1443
+ const c = ref(f.id, m, s).color;
1444
+ return t.page(c, m, f.id) >= 3 && t.onFor(f.id, m, c).r >= 4.5;
1445
+ });
1446
+ const closer = near != null && Math.abs(near - S) < Math.abs(found - S) && context.setLine ? (() => {
1447
+ const c = ref(f.id, m, near).color;
1448
+ const o = t.onFor(f.id, m, c);
1449
+ return `; for a fill closer to your color in dark: ${context.setLine(names.fill, c, "dark")} (shade ${shade(near)}, the nearest that passes, with ${textName(o.on)} text at ${round(o.r)}:1)`;
1450
+ })() : "";
1451
+ if (reports(names.fill)) checks.push({
1452
+ token: names.fill,
1453
+ mode: m,
1454
+ stop: found,
1455
+ preferred: S,
1456
+ against: "the dark page and the text on it",
1457
+ ratio: plain.ratio,
1458
+ needs: TEXT,
1459
+ pass: true,
1460
+ note: `in dark, ${names.fill} is shade ${shade(found)}, not your exact color: ${plain.why}${found === start ? "" : `; shade ${shade(start)} does not pass either, so it is the nearest shade that does`}${closer}`
1461
+ });
1462
+ }
1463
+ put(names.fill, f.id, fill);
1464
+ const on = each((m) => {
1465
+ const used = exactFill[m] ?? fill[m].color;
1466
+ const o = t.onFor(fillWord, m, solid(used, m, f.id));
1467
+ const what = exactFill[m] ? `your exact ${names.fill} (${used}${alphaOf(used) < 1 ? `, as it shows: ${solid(used, m, f.id)}` : ""})` : `${names.fill} (shade ${shade(Number(fill[m]?.stop))})`;
1468
+ const moved = o.on !== o.first;
1469
+ if (reports(names.on)) checks.push({
1470
+ token: names.on,
1471
+ mode: m,
1472
+ stop: o.on.stop,
1473
+ preferred: o.first.stop,
1474
+ against: what,
1475
+ ratio: round(o.r),
1476
+ needs: TEXT,
1477
+ pass: o.r >= TEXT,
1478
+ ...o.r < 4.5 ? { note: `text on ${what} reads at only ${round(o.r)}:1 in ${m} with white or near-black text (needs ${TEXT}:1); the fill keeps your color: pick a lighter or darker ${f.id}, or set ${names.on} exactly` } : moved ? { note: `${names.on} uses ${textName(o.on)} text in ${m}, not ${textName(o.first)}, so it reads at ${round(o.r)}:1 on ${what}, where ${textName(o.other)} text reads at only ${round(o.otherR)}:1 (button and badge labels are normal-size text, which needs ${TEXT}:1); to keep ${textName(o.other)} text anyway, set ${names.on} exactly` } : {}
1479
+ });
1480
+ return o.on;
1481
+ });
1482
+ put(names.on, f.id, on);
1483
+ if (modes.includes("light") && has(names.fill)) {
1484
+ const used = exactFill.light ?? fill.light.color;
1485
+ const p = t.page(solid(used, "light", f.id), "light", f.id);
1486
+ let darker = null;
1487
+ const from = parseColor(solid(used, "light", f.id));
1488
+ for (let i = 1; from && i <= 100 && !darker; i++) {
1489
+ const c = hex(from.map((v) => Math.round(v * (1 - i / 100))));
1490
+ if (t.page(c, "light", f.id) >= 3) darker = c;
1491
+ }
1492
+ if (p < 3) checks.push({
1493
+ token: names.fill,
1494
+ mode: "light",
1495
+ stop: S,
1496
+ preferred: S,
1497
+ against: "the light page",
1498
+ ratio: round(p),
1499
+ needs: 3,
1500
+ pass: false,
1501
+ note: exactFill.light ? `in light, your exact ${names.fill} (${used}) stands out from the page at only ${round(p)}:1, and a fill needs 3:1, so its buttons and badges may not show: give it a darker color` : `in light, your exact ${f.id} stands out from the page at only ${round(p)}:1, and a fill needs 3:1, so ${names.fill} buttons and badges may not show: pick a darker ${f.id}`,
1502
+ ...darker ? { fix: exactFill.light ? {
1503
+ thing: names.fill,
1504
+ value: darker,
1505
+ mode: "light"
1506
+ } : {
1507
+ thing: f.id,
1508
+ value: darker
1509
+ } } : {}
1510
+ });
1511
+ }
1512
+ const muted = each((m) => {
1513
+ const i = side(m);
1514
+ const spec = word ? STATUS_MUTED[i] : ACCENT_MUTED[i];
1515
+ const [s, alpha] = Array.isArray(spec) ? spec : [spec, void 0];
1516
+ const usual = i === 0 ? 1 : -1;
1517
+ const order = [...stops].sort((a, b) => Math.abs(a - s) - Math.abs(b - s) || (Math.sign(b - a) === usual ? 1 : -1));
1518
+ const away = order.filter((x) => x !== fill[m]?.stop);
1519
+ return ref(f.id, m, away[0] ?? order[0], alpha);
1520
+ });
1521
+ put(names.muted, f.id, muted);
1522
+ /** The tint the theme really shows: an exact setting wins. */
1523
+ const mutedSeen = (m) => {
1524
+ const own = rawOf(names.muted, m);
1525
+ return own ? surfaces(m, f.id).map(([n, bg]) => [`your exact ${names.muted} over ${n}`, hex(compositeOver(parseColor(own), alphaOf(own), parseColor(bg)))]) : over(names.muted, muted[m], surfaces(m, f.id));
1526
+ };
1527
+ const text = each((m) => {
1528
+ const grounds = [...surfaces(m, f.id), ...mutedSeen(m)];
1529
+ const shown = exactFill[m] ? solid(exactFill[m], m, f.id) : null;
1530
+ const start = shown ? stops.reduce((x, y) => perceptualDelta(ref(f.id, m, y).color, shown) < perceptualDelta(ref(f.id, m, x).color, shown) ? y : x) : S;
1531
+ const own = shown ? {
1532
+ ...ref(f.id, m, start),
1533
+ color: shown
1534
+ } : fill[m]?.exact ? ref(f.id, m, S) : null;
1535
+ if (own) {
1536
+ const r = Math.min(...grounds.map(([, bg]) => contrast(own.color, bg)));
1537
+ if (r >= 4.5 && !shown) {
1538
+ if (reports(names.text)) checks.push({
1539
+ token: names.text,
1540
+ mode: m,
1541
+ stop: S,
1542
+ preferred: S,
1543
+ against: grounds.map(([n]) => n).join(", "),
1544
+ ratio: round(r),
1545
+ needs: TEXT,
1546
+ pass: true
1547
+ });
1548
+ return own;
1549
+ }
1550
+ const before = checks.length;
1551
+ const moved = pick(names.text, f.id, m, start, grounds, TEXT);
1552
+ if (r >= 4.5) return moved;
1553
+ const last = checks.length > before ? checks[checks.length - 1] : null;
1554
+ if (last && (moved.stop !== start || shown)) last.note = `${names.text} ${m}: your exact color (${own.color}) reads at only ${grounds.map(([n, bg]) => [n, contrast(own.color, bg)]).filter(([, x]) => x < TEXT).map(([n, x]) => `${round(x)}:1 on ${n}`).join(", ")} (text needs ${TEXT}:1), so ${f.id === "accent" ? "links and accent text" : `${f.id} text and icons`} use shade ${shade(moved.stop)} (${moved.color}), the nearest that reads; the fill keeps your color, and an exact ${names.text} keeps any color you give it`;
1555
+ return moved;
1556
+ }
1557
+ return pick(names.text, f.id, m, at(TEXT_STOP[side(m)]), grounds, TEXT);
1558
+ });
1559
+ put(names.text, f.id, text);
1560
+ put(names.icon, f.id, text);
1561
+ if (names.onMuted) {
1562
+ const onMuted = names.onMuted;
1563
+ put(onMuted, f.id, each((m) => pick(onMuted, f.id, m, at(ON_MUTED[side(m)]), mutedSeen(m), TEXT)));
1564
+ }
1565
+ if (names.border) put(names.border, f.id, each((m) => ref(f.id, m, at(BORDER[side(m)]))));
1566
+ if (names.focus && !Object.keys(exactFill).length) {
1567
+ const focus = names.focus;
1568
+ put(focus, f.id, each((m) => pick(focus, f.id, m, fill[m].stop, surfaces(m, f.id), 3)));
1569
+ }
1570
+ }
1571
+ //#endregion
1572
+ //#region src/palette/mapLift.ts
1573
+ function mapLift(s) {
1574
+ const { candidate, ref, rawOf, surfaces, contrast, parseColor, alphaOf, base, modes, tokens, checks, neutral } = s;
1575
+ const valueOf = (m, token) => {
1576
+ const v = rawOf(token, m) ?? tokens[token]?.[m].color ?? base?.[m]?.[token];
1577
+ return v && parseColor(v) ? v : null;
1578
+ };
1579
+ /** The secondary text a mode starts from. */
1580
+ const startText = (m) => {
1581
+ const v = tokens["--color-text-secondary"]?.[m].color ?? base?.[m]?.["--color-text-secondary"];
1582
+ const rgb = v ? parseColor(v) : null;
1583
+ return rgb ? hex(rgb) : null;
1584
+ };
1585
+ /** The gray ramp of a mode, and whether its shades are the palette's neutral ones. */
1586
+ const grays = (m) => {
1587
+ if (neutral) return {
1588
+ ramp: rampOf(candidate, "neutral", m),
1589
+ palette: true
1590
+ };
1591
+ const seed = startText(m);
1592
+ const ramp = seed ? grownGrays(seed, m) : null;
1593
+ return ramp ? {
1594
+ ramp,
1595
+ palette: false
1596
+ } : null;
1597
+ };
1598
+ /** A color drawn over each of `under`, as the eye sees it. */
1599
+ const drawn = (name, color, under) => {
1600
+ const top = parseColor(color);
1601
+ const a = alphaOf(color);
1602
+ return under.map(([n, c]) => [`${name} over ${n}`, hex(compositeOver(top, a, parseColor(c)))]);
1603
+ };
1604
+ const found = {};
1605
+ for (const ground of new Set(LIFT_PARTS.map(([, , g]) => g))) {
1606
+ const { what, parts } = LIFT_GROUNDS[ground];
1607
+ /**
1608
+ * The shade the base theme itself lifts this ground's text to in a
1609
+ * mode, when it gives one: the search starts there, so a change of
1610
+ * color moves it only when that shade no longer reads.
1611
+ */
1612
+ const baseLift = (m) => {
1613
+ for (const [part, block, g] of LIFT_PARTS) {
1614
+ if (g !== ground) continue;
1615
+ const v = partStyle(base?.components, part, block)?.["--color-text-secondary"];
1616
+ const c = sides(v)?.[m === "light" ? 0 : 1]?.trim();
1617
+ const rgb = c ? parseColor(c) : null;
1618
+ if (rgb) return hex(rgb);
1619
+ }
1620
+ return null;
1621
+ };
1622
+ const byMode = {};
1623
+ for (const m of modes) {
1624
+ const own = rawOf("--color-text-secondary", m);
1625
+ const literal = () => {
1626
+ byMode[m] = {
1627
+ stop: 0,
1628
+ color: own,
1629
+ family: "literal"
1630
+ };
1631
+ };
1632
+ const fillColor = valueOf(m, ground);
1633
+ const g = grays(m);
1634
+ const textColor = startText(m);
1635
+ if (!fillColor || !g || !textColor) {
1636
+ if (own) {
1637
+ literal();
1638
+ continue;
1639
+ }
1640
+ break;
1641
+ }
1642
+ const seen = drawn(what, fillColor, surfaces(m, "neutral"));
1643
+ const hover = valueOf(m, "--color-overlay-hover");
1644
+ const on = [...seen, ...hover && alphaOf(hover) > 0 ? drawn("a hover", hover, seen).map(([n, c]) => [n.replace(/^a hover over (.*)$/, "$1 under a hover"), c]) : []];
1645
+ const keys = Object.keys(g.ramp).map(Number).sort((a, b) => a - b);
1646
+ if (own && parseColor(own) && Math.min(...on.map(([, bg]) => contrast(own, bg))) >= 4.5) {
1647
+ literal();
1648
+ continue;
1649
+ }
1650
+ const ownRgb = own ? parseColor(own) : null;
1651
+ const from = (ownRgb ? hex(ownRgb) : null) ?? baseLift(m) ?? textColor;
1652
+ const start = keys.reduce((x, y) => perceptualDelta(g.ramp[y], from) < perceptualDelta(g.ramp[x], from) ? y : x);
1653
+ const scored = keys.sort((a, b) => Math.abs(a - start) - Math.abs(b - start) || (Math.sign(b - a) === TOWARD_CONTRAST[m] ? 1 : -1)).map((stop) => ({
1654
+ stop,
1655
+ r: Math.min(...on.map(([, bg]) => contrast(g.ramp[stop], bg)))
1656
+ }));
1657
+ const b = scored.find((x) => x.r >= 4.5) ?? scored.reduce((x, y) => y.r > x.r ? y : x);
1658
+ byMode[m] = g.palette ? ref("neutral", m, b.stop) : {
1659
+ stop: b.stop,
1660
+ color: g.ramp[b.stop],
1661
+ family: "literal"
1662
+ };
1663
+ const moved = hex(parseColor(g.ramp[b.stop])) !== from;
1664
+ if (b.r < 4.5 || moved) checks.push({
1665
+ token: "--color-text-secondary",
1666
+ mode: m,
1667
+ stop: b.stop,
1668
+ preferred: start,
1669
+ against: `${what} over the surfaces`,
1670
+ ratio: round(b.r),
1671
+ needs: TEXT,
1672
+ pass: b.r >= TEXT,
1673
+ dials: ["accent", "neutral"],
1674
+ note: b.r >= 4.5 ? `--color-text-secondary on ${parts} uses ${g.ramp[b.stop]} in ${m}, not ${from}, so it stays readable (${round(b.r)}:1) on ${what} and under a hover` : `--color-text-secondary on ${parts} reads at only ${round(b.r)}:1 in ${m} on ${what} even at ${g.ramp[b.stop]}, the most contrasting gray (needs ${TEXT}:1): pick another accent or neutral, or set --color-text-secondary on those parts exactly`
1675
+ });
1676
+ }
1677
+ if (modes.every((m) => byMode[m])) found[ground] = byMode;
1678
+ }
1679
+ return Object.keys(found).length ? found : null;
1680
+ }
1681
+ //#endregion
1682
+ //#region src/palette/mapNeutral.ts
1683
+ function mapNeutral(s) {
1684
+ const { at, atInside, ref, exactOf, side, surfaces, exact, put, each, pick, neutral } = s;
1685
+ if (neutral) {
1686
+ for (const [token, pair] of Object.entries(NEUTRAL_STOPS)) {
1687
+ if (token === "--color-text-secondary" || token === "--color-icon-secondary") continue;
1688
+ const shadeAt = NEUTRAL_INSIDE.includes(token) ? atInside : at;
1689
+ put(token, "neutral", each((m) => ref("neutral", m, shadeAt(pair[side(m)]))));
1690
+ }
1691
+ for (const [token, pair] of Object.entries(NEUTRAL_TINTS)) put(token, "neutral", each((m) => {
1692
+ const [s, a] = pair[side(m)];
1693
+ return ref("neutral", m, at(s), a);
1694
+ }));
1695
+ for (const [token, needs] of [["--color-text-secondary", TEXT], ["--color-icon-secondary", 3]]) put(token, "neutral", each((m) => pick(token, "neutral", m, at(NEUTRAL_STOPS[token][side(m)]), surfaces(m, "neutral"), needs)));
1696
+ const surface = paletteToken("neutral");
1697
+ const set = each((m) => exactOf(surface, m));
1698
+ if (Object.values(set).some(Boolean)) exact[surface] = Object.fromEntries(Object.entries(set).filter(([, v]) => v));
1699
+ }
1700
+ }
1701
+ //#endregion
1702
+ //#region src/palette/mapState.ts
1703
+ /**
1704
+ * The tools and result tables one palette mapping shares across its phases
1705
+ * (neutral, each color family, the lifted secondary text).
1706
+ */
1707
+ function createMapState(candidate, dials, fills, context) {
1708
+ const t = paletteTools(candidate, context);
1709
+ const { stops, at, atInside, ref, exactOf, rawOf, settingOf, side, solid, surfaces, contrast, over, parseColor, alphaOf } = t;
1710
+ const { base, has } = context;
1711
+ const modes = ["light", "dark"];
1712
+ const tokens = {};
1713
+ const checks = [];
1714
+ const exact = {};
1715
+ const unread = {};
1716
+ const setExactly = (k) => context.setExactly?.(k) ?? false;
1717
+ const reports = (k) => has(k) && !setExactly(k);
1718
+ /** Point a token at its stops. One mode's stop stands for both when only one is given. */
1719
+ const put = (token, id, refs) => {
1720
+ if (!has(token)) return;
1721
+ const one = refs[modes[0]];
1722
+ tokens[token] = {
1723
+ family: id,
1724
+ light: refs.light ?? one,
1725
+ dark: refs.dark ?? one
1726
+ };
1727
+ };
1728
+ const each = (fn) => Object.fromEntries(modes.map((m) => [m, fn(m)]));
1729
+ /**
1730
+ * The stop nearest `start` that reads at `needs` on every color in `on`,
1731
+ * searched both ways (the usual way first on a tie: darker in light,
1732
+ * lighter in dark); the most contrasting stop of all when none does.
1733
+ */
1734
+ const pick = (token, id, m, start, on, needs) => {
1735
+ const usual = TOWARD_CONTRAST[m];
1736
+ const order = [...stops].sort((a, b) => Math.abs(a - start) - Math.abs(b - start) || (Math.sign(b - a) === usual ? 1 : -1));
1737
+ const score = (stop) => {
1738
+ const c = ref(id, m, stop).color;
1739
+ return Math.min(...on.map(([, bg]) => contrast(c, bg)));
1740
+ };
1741
+ const scored = order.map((stop) => ({
1742
+ stop,
1743
+ r: score(stop)
1744
+ }));
1745
+ const b = scored.find((x) => x.r >= needs) ?? scored.reduce((x, y) => y.r > x.r ? y : x);
1746
+ if (reports(token)) checks.push({
1747
+ token,
1748
+ mode: m,
1749
+ stop: b.stop,
1750
+ preferred: start,
1751
+ against: on.map(([n]) => n).join(", "),
1752
+ ratio: round(b.r),
1753
+ needs,
1754
+ pass: b.r >= needs
1755
+ });
1756
+ return ref(id, m, b.stop);
1757
+ };
1758
+ return {
1759
+ candidate,
1760
+ dials,
1761
+ fills,
1762
+ context,
1763
+ t,
1764
+ stops,
1765
+ at,
1766
+ atInside,
1767
+ ref,
1768
+ exactOf,
1769
+ rawOf,
1770
+ settingOf,
1771
+ side,
1772
+ solid,
1773
+ surfaces,
1774
+ contrast,
1775
+ over,
1776
+ parseColor,
1777
+ alphaOf,
1778
+ base,
1779
+ has,
1780
+ modes,
1781
+ tokens,
1782
+ checks,
1783
+ exact,
1784
+ unread,
1785
+ setExactly,
1786
+ reports,
1787
+ put,
1788
+ each,
1789
+ pick,
1790
+ neutral: dials.find((f) => f.id === "neutral")
1791
+ };
1792
+ }
1793
+ //#endregion
1794
+ //#region src/palette/mappingPlan.ts
1795
+ /**
1796
+ * Whether the exact seed color works as the dark fill: text on it reads at
1797
+ * 4.5:1 and it stands out from the dark surfaces at 3:1. Why not otherwise.
1798
+ */
1799
+ function darkExact(t, id, seed) {
1800
+ const on = t.onFor(id, "dark", seed);
1801
+ if (on.r < 4.5) return {
1802
+ ok: false,
1803
+ ratio: round(on.r),
1804
+ why: `your exact color reads at only ${round(on.r)}:1 with any text shade, and text needs ${TEXT}:1`
1805
+ };
1806
+ const p = t.page(seed, "dark", id);
1807
+ if (p < 3) return {
1808
+ ok: false,
1809
+ ratio: round(p),
1810
+ why: `your exact color stands out from the dark page at only ${round(p)}:1, and a fill needs 3:1`
1811
+ };
1812
+ return {
1813
+ ok: true,
1814
+ ratio: round(on.r),
1815
+ why: ""
1816
+ };
1817
+ }
1818
+ /**
1819
+ * The family a color setting makes: its seed, a gray seed generated as a
1820
+ * neutral, and the seed's exact color anchored at its nearest light stop
1821
+ * (both modes for neutral). White or black as neutral holds no anchor:
1822
+ * they already end every ramp.
1823
+ */
1824
+ function dialFamily(dial, config, modes) {
1825
+ const neutral = dial.id === "neutral";
1826
+ const kind = neutral || isGray(dial.seed) ? "neutral" : void 0;
1827
+ const stop = seedStop(dial.seed, config, kind ?? "chromatic");
1828
+ const anchors = neutral && (sameColor(dial.seed, "#ffffff") || sameColor(dial.seed, "#000000")) ? [] : (neutral ? modes : modes.filter((m) => m === "light")).map((m) => ({
1829
+ mode: m,
1830
+ stop,
1831
+ color: dial.seed,
1832
+ policy: "exact"
1833
+ }));
1834
+ return {
1835
+ family: {
1836
+ id: dial.id,
1837
+ name: dial.id[0].toUpperCase() + dial.id.slice(1),
1838
+ seed: dial.seed,
1839
+ ...kind ? { kind } : {},
1840
+ ...anchors.length ? { anchors } : {}
1841
+ },
1842
+ stop
1843
+ };
1844
+ }
1845
+ /**
1846
+ * Anchors each accent and status seed in dark too where it reads there, as
1847
+ * the official themes anchor a brand color in both modes. Settles each
1848
+ * fill's `dark`, `why` and `ratio`; returns the families with the dark
1849
+ * anchors that the generator can hold, and the notes of any anchor of the
1850
+ * author's that one replaces.
1851
+ */
1852
+ function anchorDarkFills(config, dials, fills, context, replaced = () => {}) {
1853
+ const t = paletteTools(generateTonalPalette(asRequest(config)), context);
1854
+ const add = [];
1855
+ for (const [id, fill] of Object.entries(fills)) {
1856
+ const seed = dials.find((f) => f.id === id)?.seed;
1857
+ const check = darkExact(t, id, seed);
1858
+ Object.assign(fill, {
1859
+ why: check.why,
1860
+ ratio: check.ratio
1861
+ });
1862
+ if (check.ok) add.push(id);
1863
+ }
1864
+ const withDark = (id, cfg) => ({
1865
+ ...cfg,
1866
+ families: cfg.families.map((f) => {
1867
+ if (f?.id !== id) return f;
1868
+ const anchor = {
1869
+ mode: "dark",
1870
+ stop: fills[id].stop,
1871
+ color: f.seed,
1872
+ policy: "exact"
1873
+ };
1874
+ const own = f.anchors ?? [];
1875
+ const others = own.filter((a) => !(a.mode === "dark" && a.stop === anchor.stop));
1876
+ if (others.length < own.length) replaced(id, anchor.stop);
1877
+ return {
1878
+ ...f,
1879
+ anchors: [...others, anchor].sort((a, b) => a.mode === b.mode ? a.stop - b.stop : a.mode === "light" ? -1 : 1)
1880
+ };
1881
+ })
1882
+ });
1883
+ let next = config;
1884
+ for (const id of add) {
1885
+ const tried = withDark(id, next);
1886
+ try {
1887
+ generateTonalPalette(asRequest(tried));
1888
+ next = tried;
1889
+ fills[id].dark = true;
1890
+ } catch {
1891
+ fills[id].why = "the dark shades cannot hold your exact color and stay in order from dark to light";
1892
+ }
1893
+ }
1894
+ return next.families;
1895
+ }
1896
+ /** An accent or status fill at its seed's stop, before dark mode is settled. */
1897
+ function fillAt(stop) {
1898
+ return {
1899
+ stop,
1900
+ dark: false,
1901
+ why: "",
1902
+ ratio: 0
1903
+ };
1904
+ }
1905
+ /**
1906
+ * The generation request for color settings with no palette config of the
1907
+ * author's: one family per setting in setting order, each seed anchored
1908
+ * exactly, in dark too where it reads there. Null without a setting.
1909
+ */
1910
+ function planPaletteRequest(dials, options, context) {
1911
+ if (!dials.length) return null;
1912
+ const modes = ["light", "dark"];
1913
+ const config = {
1914
+ ...options.recipe ? { recipe: options.recipe } : {},
1915
+ ...options.vibrancy != null ? { vibrancy: options.vibrancy } : {},
1916
+ modeStrategy: "light-and-dark",
1917
+ families: []
1918
+ };
1919
+ const fills = {};
1920
+ for (const dial of dials) {
1921
+ const { family, stop } = dialFamily(dial, config, modes);
1922
+ if (dial.id !== "neutral") fills[dial.id] = fillAt(stop);
1923
+ config.families.push(family);
1924
+ }
1925
+ if (Object.keys(fills).length) config.families = anchorDarkFills(config, dials, fills, context);
1926
+ return {
1927
+ config,
1928
+ fills
1929
+ };
1930
+ }
1931
+ //#endregion
1932
+ //#region src/palette/mapping.ts
1933
+ /**
1934
+ * 把生成好的候选调色板映射到颜色令牌:每个令牌取哪一阶(亮、暗各一个),
1935
+ * 以及每次选择背后的对比度检查。分阶段做:中性色、各个颜色族、次要文字的提亮。
1936
+ */
1937
+ function mapPalette(candidate, dials, fills, context) {
1938
+ const state = createMapState(candidate, dials, fills, context);
1939
+ mapNeutral(state);
1940
+ for (const dial of dials) if (dial.id !== "neutral") mapFamily(state, dial);
1941
+ const lift = mapLift(state);
1942
+ return {
1943
+ tokens: state.tokens,
1944
+ contrast: state.checks.filter((c) => c.note !== ""),
1945
+ exact: state.exact,
1946
+ unread: state.unread,
1947
+ lift
1948
+ };
1949
+ }
1950
+ //#endregion
1951
+ //#region src/palette/themePalette.ts
1952
+ const INPUT_KEYS = Object.freeze([
1953
+ ...PALETTE_DIALS,
1954
+ "vibrancy",
1955
+ "recipe"
1956
+ ]);
1957
+ /**
1958
+ * 官方 Neutral 主题提亮次要文字的那些部位,按「上游部位/块」对到本库的主题目标。
1959
+ * 引用和分段控件标签的前景色在主题根上就已经代入,所以写它们自己的前景变量;
1960
+ * 树列表内容没有对应的主题目标,不在这里。
1961
+ */
1962
+ const LIFT_SPOTS = {
1963
+ "item/selected": {
1964
+ target: "item",
1965
+ key: "selected:true",
1966
+ property: "--color-text-secondary"
1967
+ },
1968
+ "file-input/mode:dropzone": {
1969
+ target: "file-input",
1970
+ key: "mode:dropzone",
1971
+ property: "--color-text-secondary"
1972
+ },
1973
+ "citation/variant:number": {
1974
+ target: "citation",
1975
+ key: "variant:number",
1976
+ property: "--citation-foreground"
1977
+ },
1978
+ "segmented-control-item/base": {
1979
+ target: "segmented-control-item",
1980
+ key: "base",
1981
+ property: "--segmented-control-item-foreground"
1982
+ },
1983
+ ...Object.fromEntries([
1984
+ "blue",
1985
+ "cyan",
1986
+ "green",
1987
+ "orange",
1988
+ "pink",
1989
+ "purple",
1990
+ "red",
1991
+ "teal",
1992
+ "yellow"
1993
+ ].map((color) => [`card/variant:${color}`, {
1994
+ target: "card",
1995
+ key: `variant:${color}`,
1996
+ property: "--color-text-secondary"
1997
+ }]))
1998
+ };
1999
+ /** 读一个固定颜色:十六进制、rgb()、rgba()、black、white 和 transparent。 */
2000
+ function parseColor(value) {
2001
+ const text = value.trim().toLowerCase();
2002
+ if (text === "black") return {
2003
+ r: 0,
2004
+ g: 0,
2005
+ b: 0,
2006
+ a: 1
2007
+ };
2008
+ if (text === "white") return {
2009
+ r: 255,
2010
+ g: 255,
2011
+ b: 255,
2012
+ a: 1
2013
+ };
2014
+ return parseColor$1(text);
2015
+ }
2016
+ const coreReader = {
2017
+ rgb: (value) => {
2018
+ const read = typeof value === "string" ? parseColor(value) : null;
2019
+ return read ? [
2020
+ read.r,
2021
+ read.g,
2022
+ read.b
2023
+ ] : null;
2024
+ },
2025
+ alpha: (value) => {
2026
+ if (typeof value !== "string") return 1;
2027
+ return parseColor(value)?.a ?? 1;
2028
+ }
2029
+ };
2030
+ /**
2031
+ * 默认颜色在每个模式下的值,调色板拿它当尺子。
2032
+ * 每次调用现读,入口不留状态,服务端和构建时跑出的结果一样。
2033
+ */
2034
+ function defaultBase() {
2035
+ return {
2036
+ light: resolveDefaultColors("light"),
2037
+ dark: resolveDefaultColors("dark"),
2038
+ components: {}
2039
+ };
2040
+ }
2041
+ /**
2042
+ * 用几个种子色生成主题的颜色。调色板按固定的配方生成,再映射到颜色令牌
2043
+ * (和命令行的主题编辑器映射的方式一样),以默认颜色为底。把结果交给
2044
+ * `defineTheme({ palette })`,主题自己写的 `tokens` 仍然逐个令牌优先。
2045
+ *
2046
+ * @example
2047
+ * ```ts
2048
+ * import { themePalette } from '@astryx-vue/core/palette'
2049
+ * import { defineTheme } from '@astryx-vue/core/Theme'
2050
+ *
2051
+ * export const acme = defineTheme({
2052
+ * name: 'acme',
2053
+ * palette: themePalette({ accent: '#5b3cc4', neutral: '#6b6b70' }),
2054
+ * })
2055
+ * ```
2056
+ */
2057
+ function themePalette(input) {
2058
+ if (!input || typeof input !== "object" || Array.isArray(input)) throw new TypeError("themePalette() takes an object of seed colors, such as {accent: \"#5b3cc4\"}.");
2059
+ const unknown = Object.keys(input).filter((key) => !INPUT_KEYS.includes(key));
2060
+ if (unknown.length) throw new TypeError(`themePalette(): ${unknown.map((key) => `"${key}"`).join(", ")} is not a palette key. It takes ${INPUT_KEYS.join(", ")}.`);
2061
+ const recipe = input.recipe ?? "astryx-oklch-v1";
2062
+ if (!PALETTE_RECIPES.includes(recipe)) throw new TypeError(`themePalette(): recipe "${String(input.recipe)}" is not a palette recipe. It takes ${PALETTE_RECIPES.join(", ")}.`);
2063
+ const { vibrancy } = input;
2064
+ if (vibrancy !== void 0 && (typeof vibrancy !== "number" || !Number.isInteger(vibrancy) || vibrancy < 0 || vibrancy > 100)) throw new TypeError(`themePalette(): vibrancy is a whole number from 0 to 100, got ${JSON.stringify(vibrancy)}.`);
2065
+ const dials = [];
2066
+ for (const id of PALETTE_DIALS) {
2067
+ const value = input[id];
2068
+ if (value === void 0) continue;
2069
+ const read = typeof value === "string" ? parseColor(value) : null;
2070
+ if (!read || read.a < 1) throw new TypeError(`themePalette(): ${id} is ${JSON.stringify(value)}, and a seed is one opaque color: a hex such as "#5b3cc4", rgb(), black or white.`);
2071
+ dials.push({
2072
+ id,
2073
+ seed: hex([
2074
+ read.r,
2075
+ read.g,
2076
+ read.b
2077
+ ])
2078
+ });
2079
+ }
2080
+ if (!dials.length) throw new TypeError(`themePalette() needs at least one seed color: ${PALETTE_DIALS.join(", ")}.`);
2081
+ const context = {
2082
+ base: defaultBase(),
2083
+ has: (token) => Object.hasOwn(colorDefaults, token),
2084
+ reader: coreReader
2085
+ };
2086
+ const plan = planPaletteRequest(dials, {
2087
+ recipe,
2088
+ vibrancy
2089
+ }, context);
2090
+ if (!plan) throw new TypeError("themePalette() needs at least one seed color.");
2091
+ const mapping = mapPalette(generateTonalPalette(plan.config), dials, plan.fills, context);
2092
+ const tokens = {};
2093
+ for (const [token, { light, dark }] of Object.entries(mapping.tokens)) tokens[token] = Object.freeze([light.color, dark.color]);
2094
+ const components = {};
2095
+ for (const [upstreamPart, upstreamBlock, ground] of LIFT_PARTS) {
2096
+ const lifted = mapping.lift?.[ground];
2097
+ const spot = LIFT_SPOTS[`${upstreamPart}/${upstreamBlock}`];
2098
+ if (!spot || !lifted?.light || !lifted.dark) continue;
2099
+ const blocks = components[spot.target] ?? {};
2100
+ components[spot.target] = blocks;
2101
+ blocks[spot.key] = Object.freeze({
2102
+ "@light": Object.freeze({ [spot.property]: lifted.light.color }),
2103
+ "@dark": Object.freeze({ [spot.property]: lifted.dark.color })
2104
+ });
2105
+ }
2106
+ return Object.freeze({
2107
+ kind: "theme-palette",
2108
+ recipe,
2109
+ tokens: Object.freeze(tokens),
2110
+ components: Object.freeze(Object.fromEntries(Object.entries(components).map(([part, blocks]) => [part, Object.freeze(blocks)])))
2111
+ });
2112
+ }
2113
+ //#endregion
2114
+ export { PALETTE_BLACK as a, PALETTE_RECIPE_V2 as c, DEFAULT_21_STOPS as i, PALETTE_WHITE as l, generateTonalPalette as n, PALETTE_RECIPE as o, COMPACT_11_STOPS as r, PALETTE_RECIPES as s, themePalette as t };