@astryxdesign/core 0.7.17-canary.gffd1fc0 → 0.7.17

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 (950) hide show
  1. package/CHANGELOG.md +334 -0
  2. package/README.md +26 -9
  3. package/dist/AlertDialog/AlertDialog.d.ts +1 -1
  4. package/dist/AlertDialog/AlertDialog.d.ts.map +1 -1
  5. package/dist/AlertDialog/AlertDialog.js +6 -8
  6. package/dist/AppShell/AppShell.d.ts +7 -3
  7. package/dist/AppShell/AppShell.d.ts.map +1 -1
  8. package/dist/AppShell/AppShell.js +74 -36
  9. package/dist/AppShell/unreadWidthPoint.d.ts +29 -0
  10. package/dist/AppShell/unreadWidthPoint.d.ts.map +1 -0
  11. package/dist/AppShell/unreadWidthPoint.js +134 -0
  12. package/dist/AvatarGroup/AvatarGroupOverflow.d.ts +1 -1
  13. package/dist/AvatarGroup/AvatarGroupOverflow.d.ts.map +1 -1
  14. package/dist/AvatarGroup/AvatarGroupOverflow.js +5 -1
  15. package/dist/Badge/Badge.d.ts.map +1 -1
  16. package/dist/Badge/Badge.js +2 -2
  17. package/dist/Banner/Banner.d.ts +6 -4
  18. package/dist/Banner/Banner.d.ts.map +1 -1
  19. package/dist/Banner/Banner.js +32 -29
  20. package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
  21. package/dist/BottomSheet/BottomSheet.js +3 -1
  22. package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
  23. package/dist/BottomSheet/BottomSheetPanel.js +11 -7
  24. package/dist/BottomSheet/BottomSheetSwitcher.d.ts.map +1 -1
  25. package/dist/BottomSheet/BottomSheetSwitcher.js +57 -2
  26. package/dist/BottomSheet/BottomSheetSwitcherContext.d.ts +5 -0
  27. package/dist/BottomSheet/BottomSheetSwitcherContext.d.ts.map +1 -1
  28. package/dist/BottomSheet/bottomSheetStack.d.ts.map +1 -1
  29. package/dist/BottomSheet/bottomSheetStack.js +6 -14
  30. package/dist/Breadcrumbs/BreadcrumbItem.d.ts.map +1 -1
  31. package/dist/Breadcrumbs/BreadcrumbItem.js +12 -1
  32. package/dist/Button/Button.d.ts.map +1 -1
  33. package/dist/Button/Button.js +45 -7
  34. package/dist/Calendar/Calendar.js +8 -2
  35. package/dist/Calendar/styles.d.ts +10 -6
  36. package/dist/Calendar/styles.d.ts.map +1 -1
  37. package/dist/Calendar/styles.js +7 -3
  38. package/dist/Card/Card.d.ts.map +1 -1
  39. package/dist/Card/Card.js +23 -4
  40. package/dist/Chat/ChatComposer.d.ts +1 -1
  41. package/dist/Chat/ChatComposer.d.ts.map +1 -1
  42. package/dist/Chat/ChatComposer.js +4 -4
  43. package/dist/Chat/ChatComposerDrawer.d.ts.map +1 -1
  44. package/dist/Chat/ChatComposerDrawer.js +8 -4
  45. package/dist/Chat/ChatDictationButton.d.ts.map +1 -1
  46. package/dist/Chat/ChatDictationButton.js +7 -0
  47. package/dist/Chat/ChatPastedTextToken.d.ts.map +1 -1
  48. package/dist/Chat/ChatPastedTextToken.js +3 -9
  49. package/dist/Chat/ChatSendButton.d.ts.map +1 -1
  50. package/dist/Chat/ChatSendButton.js +3 -0
  51. package/dist/Chat/ChatSystemMessage.d.ts.map +1 -1
  52. package/dist/Chat/ChatSystemMessage.js +1 -0
  53. package/dist/Chat/ChatToolCalls.d.ts.map +1 -1
  54. package/dist/Chat/ChatToolCalls.js +8 -0
  55. package/dist/Chat/pastedTextLabel.d.ts +4 -0
  56. package/dist/Chat/pastedTextLabel.d.ts.map +1 -0
  57. package/dist/Chat/pastedTextLabel.js +21 -0
  58. package/dist/Chat/useChatPasteAsToken.d.ts.map +1 -1
  59. package/dist/Chat/useChatPasteAsToken.js +8 -8
  60. package/dist/Chat/useTriggerMenu.d.ts.map +1 -1
  61. package/dist/Chat/useTriggerMenu.js +3 -3
  62. package/dist/CheckboxInput/CheckboxInput.d.ts +2 -1
  63. package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
  64. package/dist/CheckboxInput/CheckboxInput.js +69 -18
  65. package/dist/Citation/Citation.d.ts.map +1 -1
  66. package/dist/Citation/Citation.js +8 -1
  67. package/dist/Code/Code.d.ts.map +1 -1
  68. package/dist/Code/Code.js +5 -1
  69. package/dist/CodeBlock/CodeBlock.d.ts.map +1 -1
  70. package/dist/CodeBlock/CodeBlock.js +39 -12
  71. package/dist/CodeBlock/highlightRanges.d.ts.map +1 -1
  72. package/dist/CodeBlock/highlightRanges.js +6 -5
  73. package/dist/Collapsible/Collapsible.d.ts.map +1 -1
  74. package/dist/Collapsible/Collapsible.js +2 -0
  75. package/dist/CommandPalette/CommandPaletteItem.d.ts.map +1 -1
  76. package/dist/CommandPalette/CommandPaletteItem.js +1 -0
  77. package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
  78. package/dist/ComplexSelector/ComplexSelector.js +8 -1
  79. package/dist/ContextMenu/ContextMenu.d.ts.map +1 -1
  80. package/dist/ContextMenu/ContextMenu.js +32 -5
  81. package/dist/DateInput/MonthScroller.d.ts.map +1 -1
  82. package/dist/DateInput/MonthScroller.js +1 -0
  83. package/dist/DateInput/PickerWheel.d.ts.map +1 -1
  84. package/dist/DateInput/PickerWheel.js +3 -2
  85. package/dist/DateInput/TouchDateField.d.ts.map +1 -1
  86. package/dist/DateInput/TouchDateField.js +2 -1
  87. package/dist/DateInput/Wheel.d.ts.map +1 -1
  88. package/dist/DateInput/Wheel.js +8 -8
  89. package/dist/DateInput/usePointerDragScroll.d.ts.map +1 -1
  90. package/dist/DateInput/usePointerDragScroll.js +5 -2
  91. package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
  92. package/dist/DateRangeInput/DateRangeInput.js +7 -0
  93. package/dist/DateTimeInput/TouchDateTimeField.d.ts.map +1 -1
  94. package/dist/DateTimeInput/TouchDateTimeField.js +2 -1
  95. package/dist/DateTimeInput/nativePickerSegmentStyles.d.ts +2 -2
  96. package/dist/Dialog/Dialog.d.ts.map +1 -1
  97. package/dist/Dialog/Dialog.js +104 -18
  98. package/dist/Dialog/DialogContext.d.ts +5 -4
  99. package/dist/Dialog/DialogContext.d.ts.map +1 -1
  100. package/dist/Dialog/DialogHeader.d.ts.map +1 -1
  101. package/dist/Dialog/DialogHeader.js +38 -12
  102. package/dist/Drawer/DrawerHeader.d.ts.map +1 -1
  103. package/dist/Drawer/DrawerHeader.js +23 -8
  104. package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
  105. package/dist/DropdownMenu/DropdownMenu.js +23 -17
  106. package/dist/DropdownMenu/DropdownMenuCheckboxItem.d.ts.map +1 -1
  107. package/dist/DropdownMenu/DropdownMenuCheckboxItem.js +3 -3
  108. package/dist/DropdownMenu/DropdownMenuItem.d.ts.map +1 -1
  109. package/dist/DropdownMenu/DropdownMenuItem.js +3 -2
  110. package/dist/DropdownMenu/DropdownMenuRadioItem.d.ts.map +1 -1
  111. package/dist/DropdownMenu/DropdownMenuRadioItem.js +3 -3
  112. package/dist/DropdownMenu/DropdownMenuSubMenu.d.ts.map +1 -1
  113. package/dist/DropdownMenu/DropdownMenuSubMenu.js +19 -2
  114. package/dist/DropdownMenu/lazyMenuBottomSheet.d.ts +6 -3
  115. package/dist/DropdownMenu/lazyMenuBottomSheet.d.ts.map +1 -1
  116. package/dist/DropdownMenu/lazyMenuBottomSheet.js +31 -7
  117. package/dist/DropdownMenu/menuRowCorners.stylex.d.ts +24 -0
  118. package/dist/DropdownMenu/menuRowCorners.stylex.d.ts.map +1 -0
  119. package/dist/DropdownMenu/menuRowCorners.stylex.js +29 -0
  120. package/dist/EmptyState/EmptyState.d.ts.map +1 -1
  121. package/dist/EmptyState/EmptyState.js +2 -2
  122. package/dist/Field/FieldLabel.d.ts.map +1 -1
  123. package/dist/Field/FieldLabel.js +2 -2
  124. package/dist/Field/inputDisabledFocus.d.ts +4 -0
  125. package/dist/Field/inputDisabledFocus.d.ts.map +1 -1
  126. package/dist/Field/inputDisabledFocus.js +5 -0
  127. package/dist/Field/inputStyles.stylex.d.ts +31 -4
  128. package/dist/Field/inputStyles.stylex.d.ts.map +1 -1
  129. package/dist/Field/inputStyles.stylex.js +30 -5
  130. package/dist/Grid/Grid.d.ts +2 -1
  131. package/dist/Grid/Grid.d.ts.map +1 -1
  132. package/dist/Grid/Grid.js +5 -2
  133. package/dist/Heading/Heading.d.ts +1 -1
  134. package/dist/Heading/Heading.d.ts.map +1 -1
  135. package/dist/Heading/Heading.js +15 -1
  136. package/dist/Icon/Icon.d.ts +1 -1
  137. package/dist/Icon/Icon.d.ts.map +1 -1
  138. package/dist/Icon/Icon.js +32 -2
  139. package/dist/Indicator/CheckboxIndicator.d.ts.map +1 -1
  140. package/dist/Indicator/CheckboxIndicator.js +12 -6
  141. package/dist/Indicator/RadioIndicator.d.ts.map +1 -1
  142. package/dist/Indicator/RadioIndicator.js +18 -4
  143. package/dist/Indicator/indicatorRegistry.d.ts +3 -26
  144. package/dist/Indicator/indicatorRegistry.d.ts.map +1 -1
  145. package/dist/Indicator/indicatorRegistry.js +2 -11
  146. package/dist/Indicator/themeIndicators.d.ts +15 -0
  147. package/dist/Indicator/themeIndicators.d.ts.map +1 -0
  148. package/dist/Indicator/themeIndicators.js +21 -0
  149. package/dist/Indicator/types.d.ts +14 -0
  150. package/dist/Indicator/types.d.ts.map +1 -1
  151. package/dist/Indicator/useThemeIndicator.d.ts +3 -0
  152. package/dist/Indicator/useThemeIndicator.d.ts.map +1 -0
  153. package/dist/Indicator/useThemeIndicator.js +19 -0
  154. package/dist/Item/Item.d.ts +6 -2
  155. package/dist/Item/Item.d.ts.map +1 -1
  156. package/dist/Item/Item.js +30 -2
  157. package/dist/Kbd/Kbd.d.ts.map +1 -1
  158. package/dist/Kbd/Kbd.js +9 -2
  159. package/dist/Layer/layerExitCopy.d.ts.map +1 -1
  160. package/dist/Layer/layerExitCopy.js +1 -1
  161. package/dist/Layer/layerSlideRules.d.ts +23 -15
  162. package/dist/Layer/layerSlideRules.d.ts.map +1 -1
  163. package/dist/Layer/layerSlideRules.js +54 -54
  164. package/dist/Layer/useLayer.d.ts +41 -29
  165. package/dist/Layer/useLayer.d.ts.map +1 -1
  166. package/dist/Layer/useLayer.js +199 -126
  167. package/dist/Layer/useLayerKeyboardClearance.d.ts +5 -5
  168. package/dist/Layer/useLayerKeyboardClearance.d.ts.map +1 -1
  169. package/dist/Layer/useLayerKeyboardClearance.js +5 -5
  170. package/dist/Layout/LayoutContainerContext.d.ts +4 -0
  171. package/dist/Layout/LayoutContainerContext.d.ts.map +1 -0
  172. package/dist/Layout/LayoutContainerContext.js +20 -0
  173. package/dist/Layout/LayoutContainerScope.d.ts +15 -0
  174. package/dist/Layout/LayoutContainerScope.d.ts.map +1 -0
  175. package/dist/Layout/LayoutContainerScope.js +23 -0
  176. package/dist/Layout/LayoutContent.d.ts +2 -1
  177. package/dist/Layout/LayoutContent.d.ts.map +1 -1
  178. package/dist/Layout/LayoutContent.js +7 -2
  179. package/dist/Layout/LayoutFooter.d.ts.map +1 -1
  180. package/dist/Layout/LayoutFooter.js +5 -1
  181. package/dist/Layout/LayoutHeader.d.ts.map +1 -1
  182. package/dist/Layout/LayoutHeader.js +5 -1
  183. package/dist/Layout/containerCorners.stylex.d.ts +15 -7
  184. package/dist/Layout/containerCorners.stylex.d.ts.map +1 -1
  185. package/dist/Layout/containerCorners.stylex.js +16 -7
  186. package/dist/Lightbox/Lightbox.d.ts.map +1 -1
  187. package/dist/Lightbox/Lightbox.js +324 -6
  188. package/dist/Link/Link.d.ts.map +1 -1
  189. package/dist/Link/Link.js +1 -1
  190. package/dist/List/List.d.ts.map +1 -1
  191. package/dist/List/List.js +14 -6
  192. package/dist/List/ListContext.d.ts +38 -1
  193. package/dist/List/ListContext.d.ts.map +1 -1
  194. package/dist/List/ListContext.js +50 -2
  195. package/dist/List/ListItem.js +2 -2
  196. package/dist/Markdown/Markdown.d.ts.map +1 -1
  197. package/dist/Markdown/Markdown.js +85 -96
  198. package/dist/Markdown/plugins/HeadingLinksRenderer.d.ts.map +1 -1
  199. package/dist/Markdown/plugins/HeadingLinksRenderer.js +12 -5
  200. package/dist/Markdown/plugins/protocol.js +3 -3
  201. package/dist/MetadataList/MetadataListItem.d.ts.map +1 -1
  202. package/dist/MetadataList/MetadataListItem.js +11 -3
  203. package/dist/MobileNav/MobileNav.d.ts +1 -1
  204. package/dist/MobileNav/MobileNav.d.ts.map +1 -1
  205. package/dist/MobileNav/MobileNav.js +6 -3
  206. package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
  207. package/dist/MultiSelector/MultiSelector.js +33 -9
  208. package/dist/NavMenu/NavHeadingMenu.d.ts.map +1 -1
  209. package/dist/NavMenu/NavHeadingMenu.js +5 -2
  210. package/dist/NavMenu/NavHeadingMenuItem.d.ts.map +1 -1
  211. package/dist/NavMenu/NavHeadingMenuItem.js +1 -0
  212. package/dist/NavMenu/NavMenuContext.d.ts +7 -0
  213. package/dist/NavMenu/NavMenuContext.d.ts.map +1 -1
  214. package/dist/NavMenu/NavMenuContext.js +9 -0
  215. package/dist/NumberInput/NumberInput.d.ts.map +1 -1
  216. package/dist/NumberInput/NumberInput.js +8 -2
  217. package/dist/Outline/Outline.d.ts +7 -3
  218. package/dist/Outline/Outline.d.ts.map +1 -1
  219. package/dist/Outline/Outline.js +11 -3
  220. package/dist/Outline/useScrollSpy.d.ts +1 -1
  221. package/dist/Outline/useScrollSpy.d.ts.map +1 -1
  222. package/dist/Outline/useScrollSpy.js +6 -2
  223. package/dist/OverflowList/OverflowList.d.ts.map +1 -1
  224. package/dist/OverflowList/OverflowList.js +51 -25
  225. package/dist/Pagination/Pagination.d.ts.map +1 -1
  226. package/dist/Pagination/Pagination.js +33 -13
  227. package/dist/Popover/Popover.d.ts.map +1 -1
  228. package/dist/Popover/Popover.js +5 -1
  229. package/dist/Popover/popoverAnchor.d.ts +11 -0
  230. package/dist/Popover/popoverAnchor.d.ts.map +1 -0
  231. package/dist/Popover/popoverAnchor.js +33 -0
  232. package/dist/Popover/usePopover.d.ts +20 -3
  233. package/dist/Popover/usePopover.d.ts.map +1 -1
  234. package/dist/Popover/usePopover.js +110 -10
  235. package/dist/PowerSearch/PowerSearch.d.ts +1 -0
  236. package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
  237. package/dist/PowerSearch/PowerSearch.js +46 -9
  238. package/dist/PowerSearch/PowerSearchEditPopover.d.ts.map +1 -1
  239. package/dist/PowerSearch/PowerSearchEditPopover.js +1 -1
  240. package/dist/PowerSearch/PowerSearchFilterEditor.d.ts.map +1 -1
  241. package/dist/PowerSearch/PowerSearchFilterEditor.js +7 -1
  242. package/dist/PowerSearch/PowerSearchToken.d.ts.map +1 -1
  243. package/dist/PowerSearch/PowerSearchToken.js +7 -0
  244. package/dist/PowerSearch/PowerSearchValueEditor.d.ts +2 -4
  245. package/dist/PowerSearch/PowerSearchValueEditor.d.ts.map +1 -1
  246. package/dist/PowerSearch/PowerSearchValueEditor.js +6 -13
  247. package/dist/ProgressBar/ProgressBar.d.ts +5 -4
  248. package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
  249. package/dist/ProgressBar/ProgressBar.js +26 -26
  250. package/dist/RadioList/RadioList.d.ts.map +1 -1
  251. package/dist/RadioList/RadioList.js +51 -0
  252. package/dist/RadioList/RadioListItem.d.ts.map +1 -1
  253. package/dist/RadioList/RadioListItem.js +1 -1
  254. package/dist/Resizable/ResizeHandle.d.ts +1 -1
  255. package/dist/Resizable/ResizeHandle.d.ts.map +1 -1
  256. package/dist/Resizable/ResizeHandle.js +1 -1
  257. package/dist/Resizable/resizableModel.d.ts +45 -3
  258. package/dist/Resizable/resizableModel.d.ts.map +1 -1
  259. package/dist/Resizable/resizableModel.js +91 -3
  260. package/dist/Resizable/resizeGesture.d.ts +3 -0
  261. package/dist/Resizable/resizeGesture.d.ts.map +1 -1
  262. package/dist/Resizable/resizeGesture.js +6 -0
  263. package/dist/Resizable/useResizable.d.ts +1 -33
  264. package/dist/Resizable/useResizable.d.ts.map +1 -1
  265. package/dist/Resizable/useResizable.js +8 -72
  266. package/dist/SegmentedControl/SegmentedControlItem.d.ts.map +1 -1
  267. package/dist/SegmentedControl/SegmentedControlItem.js +1 -0
  268. package/dist/SegmentedControl/useSegmentedTouchTracking.d.ts +27 -5
  269. package/dist/SegmentedControl/useSegmentedTouchTracking.d.ts.map +1 -1
  270. package/dist/SegmentedControl/useSegmentedTouchTracking.js +70 -8
  271. package/dist/Selector/Selector.d.ts.map +1 -1
  272. package/dist/Selector/Selector.js +34 -14
  273. package/dist/Selector/hooks.d.ts +5 -0
  274. package/dist/Selector/hooks.d.ts.map +1 -1
  275. package/dist/Selector/hooks.js +72 -16
  276. package/dist/Selector/useSelectorPresentation.d.ts.map +1 -1
  277. package/dist/Selector/useSelectorPresentation.js +9 -3
  278. package/dist/SideNav/SideNavHeading.d.ts.map +1 -1
  279. package/dist/SideNav/SideNavHeading.js +18 -5
  280. package/dist/Slider/Slider.d.ts.map +1 -1
  281. package/dist/Slider/Slider.js +2 -2
  282. package/dist/Spinner/Spinner.d.ts.map +1 -1
  283. package/dist/Spinner/Spinner.js +47 -33
  284. package/dist/Stepper/Step.d.ts.map +1 -1
  285. package/dist/Stepper/Step.js +21 -12
  286. package/dist/Swipe/useSwipeAction.js +3 -3
  287. package/dist/Switch/Switch.d.ts.map +1 -1
  288. package/dist/Switch/Switch.js +64 -46
  289. package/dist/Switch/useSwitchTouch.d.ts +22 -1
  290. package/dist/Switch/useSwitchTouch.d.ts.map +1 -1
  291. package/dist/Switch/useSwitchTouch.js +54 -3
  292. package/dist/TabList/Tab.d.ts.map +1 -1
  293. package/dist/TabList/Tab.js +3 -3
  294. package/dist/Table/BaseTable.d.ts.map +1 -1
  295. package/dist/Table/BaseTable.js +37 -18
  296. package/dist/Table/Table.d.ts +4 -3
  297. package/dist/Table/Table.d.ts.map +1 -1
  298. package/dist/Table/Table.js +32 -14
  299. package/dist/Table/TableBody.d.ts.map +1 -1
  300. package/dist/Table/TableBody.js +5 -1
  301. package/dist/Table/TableCell.d.ts.map +1 -1
  302. package/dist/Table/TableCell.js +6 -0
  303. package/dist/Table/TableHeaderCell.d.ts +1 -1
  304. package/dist/Table/TableHeaderCell.d.ts.map +1 -1
  305. package/dist/Table/TableHeaderCell.js +42 -9
  306. package/dist/Table/TableRow.d.ts.map +1 -1
  307. package/dist/Table/TableRow.js +9 -1
  308. package/dist/Table/TableRowPlacementContext.d.ts +18 -0
  309. package/dist/Table/TableRowPlacementContext.d.ts.map +1 -0
  310. package/dist/Table/TableRowPlacementContext.js +41 -0
  311. package/dist/Table/TableSelectionToolbar.d.ts.map +1 -1
  312. package/dist/Table/TableSelectionToolbar.js +7 -0
  313. package/dist/Table/columnUtils.d.ts +5 -0
  314. package/dist/Table/columnUtils.d.ts.map +1 -1
  315. package/dist/Table/columnUtils.js +9 -1
  316. package/dist/Table/plugins/rowIndex/useTableRowIndex.d.ts.map +1 -1
  317. package/dist/Table/plugins/rowIndex/useTableRowIndex.js +2 -2
  318. package/dist/Table/plugins/sortable/useTableSortable.d.ts.map +1 -1
  319. package/dist/Table/plugins/sortable/useTableSortable.js +8 -3
  320. package/dist/Table/plugins/sortable/useTableSortableState.d.ts.map +1 -1
  321. package/dist/Table/plugins/sortable/useTableSortableState.js +10 -6
  322. package/dist/Table/plugins/stickyColumns/useTableStickyColumns.d.ts.map +1 -1
  323. package/dist/Table/plugins/stickyColumns/useTableStickyColumns.js +5 -1
  324. package/dist/Table/plugins/tree/useTableTreeData.d.ts.map +1 -1
  325. package/dist/Table/plugins/tree/useTableTreeData.js +76 -15
  326. package/dist/Table/table.stylex.d.ts +31 -5
  327. package/dist/Table/table.stylex.d.ts.map +1 -1
  328. package/dist/Table/table.stylex.js +33 -5
  329. package/dist/Table/types.d.ts +3 -1
  330. package/dist/Table/types.d.ts.map +1 -1
  331. package/dist/Text/TruncationTooltip.d.ts +35 -1
  332. package/dist/Text/TruncationTooltip.d.ts.map +1 -1
  333. package/dist/Text/TruncationTooltip.js +115 -0
  334. package/dist/Text/text.stylex.d.ts +2 -2
  335. package/dist/Text/useTruncation.d.ts.map +1 -1
  336. package/dist/Text/useTruncation.js +23 -4
  337. package/dist/TextArea/TextArea.d.ts.map +1 -1
  338. package/dist/TextArea/TextArea.js +15 -1
  339. package/dist/TextInput/TextInput.d.ts +9 -3
  340. package/dist/TextInput/TextInput.d.ts.map +1 -1
  341. package/dist/TextInput/TextInput.js +19 -18
  342. package/dist/Thumbnail/Thumbnail.d.ts.map +1 -1
  343. package/dist/Thumbnail/Thumbnail.js +13 -4
  344. package/dist/Timer/Timer.d.ts.map +1 -1
  345. package/dist/Timer/Timer.js +10 -7
  346. package/dist/Timestamp/Timestamp.d.ts.map +1 -1
  347. package/dist/Timestamp/Timestamp.js +55 -4
  348. package/dist/Toast/Toast.d.ts +1 -6
  349. package/dist/Toast/Toast.d.ts.map +1 -1
  350. package/dist/Toast/Toast.js +77 -44
  351. package/dist/Toast/ToastViewport.d.ts.map +1 -1
  352. package/dist/Toast/ToastViewport.js +48 -21
  353. package/dist/Toast/types.d.ts +8 -0
  354. package/dist/Toast/types.d.ts.map +1 -1
  355. package/dist/Toast/useToast.d.ts.map +1 -1
  356. package/dist/Toast/useToast.js +14 -7
  357. package/dist/ToggleButton/ToggleButton.d.ts.map +1 -1
  358. package/dist/ToggleButton/ToggleButton.js +14 -9
  359. package/dist/Token/Token.d.ts +1 -1
  360. package/dist/Token/Token.d.ts.map +1 -1
  361. package/dist/Token/Token.js +6 -2
  362. package/dist/Tokenizer/Tokenizer.d.ts +2 -2
  363. package/dist/Tokenizer/Tokenizer.d.ts.map +1 -1
  364. package/dist/Tokenizer/Tokenizer.js +102 -62
  365. package/dist/Toolbar/Toolbar.d.ts.map +1 -1
  366. package/dist/Toolbar/Toolbar.js +33 -5
  367. package/dist/Tooltip/Tooltip.d.ts +12 -1
  368. package/dist/Tooltip/Tooltip.d.ts.map +1 -1
  369. package/dist/Tooltip/Tooltip.js +31 -1
  370. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  371. package/dist/Tooltip/useTooltip.js +20 -1
  372. package/dist/TopNav/TopNav.d.ts.map +1 -1
  373. package/dist/TopNav/TopNav.js +24 -8
  374. package/dist/TopNav/TopNavContext.d.ts +13 -0
  375. package/dist/TopNav/TopNavContext.d.ts.map +1 -1
  376. package/dist/TopNav/TopNavContext.js +27 -1
  377. package/dist/TopNav/TopNavHeading.d.ts.map +1 -1
  378. package/dist/TopNav/TopNavHeading.js +21 -9
  379. package/dist/TopNav/TopNavMegaMenu.d.ts.map +1 -1
  380. package/dist/TopNav/TopNavMegaMenu.js +25 -17
  381. package/dist/TopNav/TopNavMegaMenuFeaturedCard.d.ts.map +1 -1
  382. package/dist/TopNav/TopNavMegaMenuFeaturedCard.js +13 -2
  383. package/dist/TopNav/TopNavMegaMenuItem.d.ts +9 -1
  384. package/dist/TopNav/TopNavMegaMenuItem.d.ts.map +1 -1
  385. package/dist/TopNav/TopNavMegaMenuItem.js +14 -2
  386. package/dist/TopNav/TopNavMenu.d.ts +8 -0
  387. package/dist/TopNav/TopNavMenu.d.ts.map +1 -1
  388. package/dist/TopNav/TopNavMenu.js +20 -5
  389. package/dist/TopNav/TopNavRenderContext.d.ts +13 -0
  390. package/dist/TopNav/TopNavRenderContext.d.ts.map +1 -1
  391. package/dist/TopNav/TopNavRenderContext.js +24 -9
  392. package/dist/TreeList/TreeList.d.ts.map +1 -1
  393. package/dist/TreeList/TreeList.js +7 -1
  394. package/dist/TreeList/TreeListItem.d.ts.map +1 -1
  395. package/dist/TreeList/TreeListItem.js +20 -2
  396. package/dist/Typeahead/BaseTypeahead.d.ts.map +1 -1
  397. package/dist/Typeahead/BaseTypeahead.js +2 -1
  398. package/dist/Typeahead/Typeahead.d.ts.map +1 -1
  399. package/dist/Typeahead/Typeahead.js +24 -9
  400. package/dist/Typeahead/TypeaheadItem.d.ts.map +1 -1
  401. package/dist/Typeahead/TypeaheadItem.js +7 -0
  402. package/dist/astryx.css +215 -56
  403. package/dist/gestures/GestureHost.d.ts +7 -0
  404. package/dist/gestures/GestureHost.d.ts.map +1 -1
  405. package/dist/gestures/GestureHost.js +37 -0
  406. package/dist/hooks/anchoredHint.d.ts.map +1 -1
  407. package/dist/hooks/anchoredHint.js +0 -1
  408. package/dist/hooks/computeOverflow.d.ts.map +1 -1
  409. package/dist/hooks/computeOverflow.js +7 -0
  410. package/dist/hooks/focusableSelector.d.ts +16 -9
  411. package/dist/hooks/focusableSelector.d.ts.map +1 -1
  412. package/dist/hooks/focusableSelector.js +53 -2
  413. package/dist/hooks/scrollEdgeFade.d.ts +34 -0
  414. package/dist/hooks/scrollEdgeFade.d.ts.map +1 -0
  415. package/dist/hooks/scrollEdgeFade.js +173 -0
  416. package/dist/hooks/statusButtonPress.d.ts +15 -0
  417. package/dist/hooks/statusButtonPress.d.ts.map +1 -0
  418. package/dist/hooks/statusButtonPress.js +19 -0
  419. package/dist/hooks/useAnnounce.d.ts.map +1 -1
  420. package/dist/hooks/useAnnounce.js +2 -1
  421. package/dist/hooks/useFocusTrap.d.ts +26 -16
  422. package/dist/hooks/useFocusTrap.d.ts.map +1 -1
  423. package/dist/hooks/useFocusTrap.js +75 -112
  424. package/dist/hooks/useGroupPressTracking.d.ts +1 -1
  425. package/dist/hooks/useGroupPressTracking.js +1 -1
  426. package/dist/hooks/useOverflow.d.ts +25 -2
  427. package/dist/hooks/useOverflow.d.ts.map +1 -1
  428. package/dist/hooks/useOverflow.js +137 -8
  429. package/dist/hooks/useResolvedRequired.d.ts +27 -0
  430. package/dist/hooks/useResolvedRequired.d.ts.map +1 -1
  431. package/dist/hooks/useResolvedRequired.js +30 -1
  432. package/dist/hooks/useTreeFocus.d.ts.map +1 -1
  433. package/dist/hooks/useTreeFocus.js +4 -2
  434. package/dist/hooks/useTypeahead.d.ts.map +1 -1
  435. package/dist/hooks/useTypeahead.js +8 -8
  436. package/dist/i18n/InternationalizationContext.d.ts +13 -6
  437. package/dist/i18n/InternationalizationContext.d.ts.map +1 -1
  438. package/dist/i18n/InternationalizationContext.js +11 -6
  439. package/dist/i18n/InternationalizationProvider.d.ts.map +1 -1
  440. package/dist/i18n/InternationalizationProvider.js +7 -0
  441. package/dist/i18n/defaultTranslator.d.ts +17 -0
  442. package/dist/i18n/defaultTranslator.d.ts.map +1 -0
  443. package/dist/i18n/defaultTranslator.js +18 -0
  444. package/dist/i18n/firstStrongDirection.d.ts +3 -2
  445. package/dist/i18n/firstStrongDirection.d.ts.map +1 -1
  446. package/dist/i18n/firstStrongDirection.js +50 -12
  447. package/dist/i18n/generated-english/Chat/ChatPastedTextToken.generated.d.ts.map +1 -1
  448. package/dist/i18n/generated-english/Chat/ChatPastedTextToken.generated.js +1 -2
  449. package/dist/i18n/generated-english/Chat/pastedTextLabel.generated.d.ts +8 -0
  450. package/dist/i18n/generated-english/Chat/pastedTextLabel.generated.d.ts.map +1 -0
  451. package/dist/i18n/generated-english/Chat/pastedTextLabel.generated.js +12 -0
  452. package/dist/i18n/generated-english/Chat/useTriggerMenu.generated.d.ts.map +1 -1
  453. package/dist/i18n/generated-english/Chat/useTriggerMenu.generated.js +1 -0
  454. package/dist/i18n/generated-english/CodeBlock/CodeBlock.generated.d.ts.map +1 -1
  455. package/dist/i18n/generated-english/CodeBlock/CodeBlock.generated.js +2 -1
  456. package/dist/i18n/generated-english/Markdown/plugins/HeadingLinksRenderer.generated.d.ts.map +1 -1
  457. package/dist/i18n/generated-english/Markdown/plugins/HeadingLinksRenderer.generated.js +2 -1
  458. package/dist/i18n/generated-english/MultiSelector/MultiSelector.generated.d.ts.map +1 -1
  459. package/dist/i18n/generated-english/MultiSelector/MultiSelector.generated.js +1 -0
  460. package/dist/i18n/generated-english/Slider/Slider.generated.d.ts.map +1 -1
  461. package/dist/i18n/generated-english/Slider/Slider.generated.js +2 -1
  462. package/dist/i18n/generated-english/TextArea/TextArea.generated.d.ts.map +1 -1
  463. package/dist/i18n/generated-english/TextArea/TextArea.generated.js +1 -0
  464. package/dist/i18n/generated-english/TextInput/TextInput.generated.d.ts.map +1 -1
  465. package/dist/i18n/generated-english/TextInput/TextInput.generated.js +1 -0
  466. package/dist/i18n/generated-english/Timestamp/Timestamp.generated.d.ts.map +1 -1
  467. package/dist/i18n/generated-english/Timestamp/Timestamp.generated.js +2 -1
  468. package/dist/i18n/generated-english/Tokenizer/Tokenizer.generated.d.ts.map +1 -1
  469. package/dist/i18n/generated-english/Tokenizer/Tokenizer.generated.js +1 -0
  470. package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
  471. package/dist/i18n/generated-locales/en.generated.js +9 -0
  472. package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
  473. package/dist/i18n/generated-locales/pseudo.generated.js +9 -0
  474. package/dist/i18n/publicContext.d.ts.map +1 -1
  475. package/dist/i18n/publicContext.js +4 -2
  476. package/dist/i18n/translatingContext.d.ts +2 -0
  477. package/dist/i18n/translatingContext.d.ts.map +1 -0
  478. package/dist/i18n/translatingContext.js +25 -0
  479. package/dist/i18n/useComponentTranslator.d.ts.map +1 -1
  480. package/dist/i18n/useComponentTranslator.js +3 -2
  481. package/dist/i18n/useListFormatter.d.ts.map +1 -1
  482. package/dist/i18n/useListFormatter.js +3 -2
  483. package/dist/i18n/useTranslator.d.ts.map +1 -1
  484. package/dist/i18n/useTranslator.js +3 -2
  485. package/dist/internal/touch.d.ts +2 -0
  486. package/dist/internal/touch.d.ts.map +1 -1
  487. package/dist/internal/touch.js +5 -1
  488. package/dist/keyboard/keyboardHeight.d.ts +34 -3
  489. package/dist/keyboard/keyboardHeight.d.ts.map +1 -1
  490. package/dist/keyboard/keyboardHeight.js +101 -24
  491. package/dist/keyboard/keyboardTarget.d.ts +19 -16
  492. package/dist/keyboard/keyboardTarget.d.ts.map +1 -1
  493. package/dist/keyboard/keyboardTarget.js +529 -72
  494. package/dist/keyboard/useMobileKeyboard.d.ts.map +1 -1
  495. package/dist/keyboard/useMobileKeyboard.js +1 -8
  496. package/dist/palette/color.d.ts +23 -0
  497. package/dist/palette/color.d.ts.map +1 -0
  498. package/dist/palette/color.js +126 -0
  499. package/dist/palette/generator.d.ts +69 -0
  500. package/dist/palette/generator.d.ts.map +1 -0
  501. package/dist/palette/generator.js +778 -0
  502. package/dist/palette/index.d.ts +12 -0
  503. package/dist/palette/index.d.ts.map +1 -0
  504. package/dist/palette/index.js +13 -0
  505. package/dist/palette/mapping.d.ts +319 -0
  506. package/dist/palette/mapping.d.ts.map +1 -0
  507. package/dist/palette/mapping.js +1312 -0
  508. package/dist/palette/themePalette.d.ts +20 -0
  509. package/dist/palette/themePalette.d.ts.map +1 -0
  510. package/dist/palette/themePalette.js +145 -0
  511. package/dist/palette/types.d.ts +178 -0
  512. package/dist/palette/types.d.ts.map +1 -0
  513. package/dist/palette/types.js +1 -0
  514. package/dist/privateAttributes/mediaDarkPage.d.ts +5 -0
  515. package/dist/privateAttributes/mediaDarkPage.d.ts.map +1 -0
  516. package/dist/privateAttributes/mediaDarkPage.js +27 -0
  517. package/dist/privateAttributes/pressGroupItem.stylex.d.ts +2 -1
  518. package/dist/privateAttributes/pressGroupItem.stylex.d.ts.map +1 -1
  519. package/dist/privateAttributes/pressGroupItem.stylex.js +2 -1
  520. package/dist/privateAttributes/scheme.d.ts +10 -0
  521. package/dist/privateAttributes/scheme.d.ts.map +1 -0
  522. package/dist/privateAttributes/scheme.js +34 -0
  523. package/dist/privateAttributes/travelling.stylex.d.ts.map +1 -1
  524. package/dist/privateAttributes/travelling.stylex.js +2 -2
  525. package/dist/theme/MediaDarkPage.d.ts +18 -0
  526. package/dist/theme/MediaDarkPage.d.ts.map +1 -0
  527. package/dist/theme/MediaDarkPage.js +35 -0
  528. package/dist/theme/MediaTheme.d.ts.map +1 -1
  529. package/dist/theme/MediaTheme.js +9 -1
  530. package/dist/theme/Theme.d.ts.map +1 -1
  531. package/dist/theme/Theme.js +99 -31
  532. package/dist/theme/defineTheme.d.ts +31 -6
  533. package/dist/theme/defineTheme.d.ts.map +1 -1
  534. package/dist/theme/defineTheme.js +65 -29
  535. package/dist/theme/derivedVarRegistry.d.ts +19 -0
  536. package/dist/theme/derivedVarRegistry.d.ts.map +1 -1
  537. package/dist/theme/derivedVarRegistry.js +49 -4
  538. package/dist/theme/expandRadiusScale.d.ts +1 -2
  539. package/dist/theme/expandRadiusScale.d.ts.map +1 -1
  540. package/dist/theme/expandRadiusScale.js +1 -5
  541. package/dist/theme/generateThemeRules.d.ts +10 -3
  542. package/dist/theme/generateThemeRules.d.ts.map +1 -1
  543. package/dist/theme/generateThemeRules.js +310 -207
  544. package/dist/theme/index.d.ts +2 -1
  545. package/dist/theme/index.d.ts.map +1 -1
  546. package/dist/theme/index.js +2 -1
  547. package/dist/theme/invertedSurfaceSide.d.ts +17 -0
  548. package/dist/theme/invertedSurfaceSide.d.ts.map +1 -0
  549. package/dist/theme/invertedSurfaceSide.js +47 -0
  550. package/dist/theme/resolveThemeValues.d.ts +5 -2
  551. package/dist/theme/resolveThemeValues.d.ts.map +1 -1
  552. package/dist/theme/resolveThemeValues.js +7 -1
  553. package/dist/theme/statusRoleDefaults.d.ts +43 -0
  554. package/dist/theme/statusRoleDefaults.d.ts.map +1 -0
  555. package/dist/theme/statusRoleDefaults.js +196 -0
  556. package/dist/theme/statusRoleDerivation.d.ts +4 -0
  557. package/dist/theme/statusRoleDerivation.d.ts.map +1 -1
  558. package/dist/theme/statusRoleDerivation.js +3 -1
  559. package/dist/theme/syntax/SyntaxTheme.d.ts.map +1 -1
  560. package/dist/theme/syntax/SyntaxTheme.js +7 -0
  561. package/dist/theme/themeAdaptations.d.ts +24 -1
  562. package/dist/theme/themeAdaptations.d.ts.map +1 -1
  563. package/dist/theme/themeAdaptations.js +48 -5
  564. package/dist/theme/tokenDefaults.d.ts +3 -0
  565. package/dist/theme/tokenDefaults.d.ts.map +1 -0
  566. package/dist/theme/tokenDefaults.js +30 -0
  567. package/dist/theme/tokenValues.d.ts +26 -0
  568. package/dist/theme/tokenValues.d.ts.map +1 -0
  569. package/dist/theme/tokenValues.js +180 -0
  570. package/dist/theme/tokens.d.ts +3 -2
  571. package/dist/theme/tokens.d.ts.map +1 -1
  572. package/dist/theme/tokens.js +7 -161
  573. package/dist/theme/tokens.stylex.d.ts +4 -4
  574. package/dist/theme/tokens.stylex.d.ts.map +1 -1
  575. package/dist/theme/tokens.stylex.js +7 -5
  576. package/dist/theme/useTheme.d.ts +40 -3
  577. package/dist/theme/useTheme.d.ts.map +1 -1
  578. package/dist/theme/useTheme.js +137 -32
  579. package/dist/utils/devWarning.d.ts +17 -0
  580. package/dist/utils/devWarning.d.ts.map +1 -1
  581. package/dist/utils/devWarning.js +20 -0
  582. package/dist/utils/focusOutline.stylex.d.ts.map +1 -1
  583. package/dist/utils/focusOutline.stylex.js +7 -4
  584. package/dist/utils/focusReturn.d.ts +110 -0
  585. package/dist/utils/focusReturn.d.ts.map +1 -1
  586. package/dist/utils/focusReturn.js +418 -12
  587. package/dist/utils/hitArea.d.ts +28 -0
  588. package/dist/utils/hitArea.d.ts.map +1 -1
  589. package/dist/utils/hitArea.js +52 -18
  590. package/dist/utils/inputStream.d.ts +27 -0
  591. package/dist/utils/inputStream.d.ts.map +1 -1
  592. package/dist/utils/inputStream.js +72 -5
  593. package/dist/utils/nodeType.d.ts +2 -0
  594. package/dist/utils/nodeType.d.ts.map +1 -1
  595. package/dist/utils/nodeType.js +10 -0
  596. package/dist/utils/timeFormat.d.ts +14 -4
  597. package/dist/utils/timeFormat.d.ts.map +1 -1
  598. package/dist/utils/timeFormat.js +42 -4
  599. package/dist/utils/touchPresentation.d.ts +2 -2
  600. package/dist/utils/touchPresentation.d.ts.map +1 -1
  601. package/dist/utils/touchPresentation.js +10 -7
  602. package/dist/utils/touchPresentation.stylex.d.ts +4 -3
  603. package/dist/utils/touchPresentation.stylex.d.ts.map +1 -1
  604. package/dist/utils/touchPresentation.stylex.js +3 -3
  605. package/dist/utils/touchQueries.d.ts +3 -2
  606. package/dist/utils/touchQueries.d.ts.map +1 -1
  607. package/dist/utils/touchQueries.js +3 -2
  608. package/dist/utils/typeaheadMatch.d.ts +13 -0
  609. package/dist/utils/typeaheadMatch.d.ts.map +1 -1
  610. package/dist/utils/typeaheadMatch.js +15 -1
  611. package/dist/virtualization/useInlineListWindow.d.ts.map +1 -1
  612. package/dist/virtualization/useInlineListWindow.js +38 -22
  613. package/locales/en.json +36 -0
  614. package/locales/pseudo.json +27 -0
  615. package/package.json +10 -5
  616. package/scripts/agent-doc-state.mjs +71 -4
  617. package/src/AlertDialog/AlertDialog.doc.mjs +5 -1
  618. package/src/AlertDialog/AlertDialog.tsx +34 -7
  619. package/src/AppShell/AppShell.doc.mjs +22 -0
  620. package/src/AppShell/AppShell.tsx +112 -65
  621. package/src/AppShell/unreadWidthPoint.ts +162 -0
  622. package/src/AvatarGroup/AvatarGroupOverflow.tsx +6 -1
  623. package/src/Badge/Badge.tsx +5 -2
  624. package/src/Banner/Banner.doc.mjs +15 -0
  625. package/src/Banner/Banner.tsx +56 -45
  626. package/src/BottomSheet/BottomSheet.doc.mjs +6 -3
  627. package/src/BottomSheet/BottomSheet.tsx +3 -0
  628. package/src/BottomSheet/BottomSheetPanel.tsx +15 -7
  629. package/src/BottomSheet/BottomSheetSwitcher.tsx +73 -1
  630. package/src/BottomSheet/BottomSheetSwitcherContext.ts +5 -0
  631. package/src/BottomSheet/bottomSheetStack.ts +6 -14
  632. package/src/Breadcrumbs/BreadcrumbItem.tsx +14 -1
  633. package/src/Button/Button.doc.mjs +9 -3
  634. package/src/Button/Button.tsx +65 -11
  635. package/src/Calendar/Calendar.doc.mjs +16 -0
  636. package/src/Calendar/Calendar.tsx +32 -20
  637. package/src/Calendar/styles.ts +12 -3
  638. package/src/Card/Card.doc.mjs +2 -2
  639. package/src/Card/Card.tsx +22 -3
  640. package/src/Chat/Chat.doc.mjs +1 -1
  641. package/src/Chat/ChatComposer.doc.mjs +3 -3
  642. package/src/Chat/ChatComposer.tsx +11 -5
  643. package/src/Chat/ChatComposerDrawer.tsx +11 -7
  644. package/src/Chat/ChatDictationButton.tsx +12 -0
  645. package/src/Chat/ChatMessageBubble.tsx +2 -2
  646. package/src/Chat/ChatPastedTextToken.tsx +3 -9
  647. package/src/Chat/ChatSendButton.tsx +5 -0
  648. package/src/Chat/ChatSystemMessage.tsx +1 -0
  649. package/src/Chat/ChatToolCalls.tsx +16 -0
  650. package/src/Chat/pastedTextLabel.ts +23 -0
  651. package/src/Chat/useChatPasteAsToken.ts +9 -8
  652. package/src/Chat/useTriggerMenu.tsx +4 -1
  653. package/src/CheckboxInput/CheckboxInput.doc.mjs +20 -0
  654. package/src/CheckboxInput/CheckboxInput.tsx +83 -26
  655. package/src/CheckboxList/CheckboxList.doc.mjs +15 -0
  656. package/src/CheckboxList/CheckboxListItem.doc.mjs +3 -3
  657. package/src/Citation/Citation.tsx +16 -1
  658. package/src/Code/Code.tsx +3 -0
  659. package/src/CodeBlock/CodeBlock.doc.mjs +7 -0
  660. package/src/CodeBlock/CodeBlock.tsx +60 -13
  661. package/src/CodeBlock/highlightRanges.ts +7 -5
  662. package/src/Collapsible/Collapsible.tsx +2 -0
  663. package/src/CommandPalette/CommandPaletteItem.tsx +1 -0
  664. package/src/ComplexSelector/ComplexSelector.doc.mjs +30 -2
  665. package/src/ComplexSelector/ComplexSelector.tsx +19 -1
  666. package/src/ContextMenu/ContextMenu.doc.mjs +5 -1
  667. package/src/ContextMenu/ContextMenu.tsx +44 -5
  668. package/src/ContextMenu/ContextMenuItem.doc.mjs +55 -5
  669. package/src/DateInput/MonthScroller.tsx +1 -0
  670. package/src/DateInput/PickerWheel.tsx +1 -0
  671. package/src/DateInput/TouchDateField.tsx +2 -0
  672. package/src/DateInput/Wheel.tsx +1 -0
  673. package/src/DateInput/usePointerDragScroll.ts +6 -2
  674. package/src/DateRangeInput/DateRangeInput.tsx +16 -0
  675. package/src/DateTimeInput/TouchDateTimeField.tsx +2 -0
  676. package/src/Dialog/Dialog.doc.mjs +11 -1
  677. package/src/Dialog/Dialog.tsx +116 -19
  678. package/src/Dialog/DialogContext.ts +5 -4
  679. package/src/Dialog/DialogHeader.tsx +50 -12
  680. package/src/Drawer/DrawerHeader.tsx +31 -6
  681. package/src/DropdownMenu/DropdownMenu.doc.mjs +20 -1
  682. package/src/DropdownMenu/DropdownMenu.tsx +29 -22
  683. package/src/DropdownMenu/DropdownMenuCheckboxItem.doc.mjs +4 -4
  684. package/src/DropdownMenu/DropdownMenuCheckboxItem.tsx +3 -2
  685. package/src/DropdownMenu/DropdownMenuItem.doc.mjs +5 -5
  686. package/src/DropdownMenu/DropdownMenuItem.tsx +3 -1
  687. package/src/DropdownMenu/DropdownMenuRadioItem.doc.mjs +4 -4
  688. package/src/DropdownMenu/DropdownMenuRadioItem.tsx +3 -2
  689. package/src/DropdownMenu/DropdownMenuSubMenu.doc.mjs +3 -3
  690. package/src/DropdownMenu/DropdownMenuSubMenu.tsx +23 -1
  691. package/src/DropdownMenu/lazyMenuBottomSheet.ts +37 -9
  692. package/src/DropdownMenu/menuRowCorners.stylex.ts +40 -0
  693. package/src/EmptyState/EmptyState.tsx +2 -0
  694. package/src/Field/Field.doc.mjs +1 -1
  695. package/src/Field/FieldLabel.doc.mjs +3 -3
  696. package/src/Field/FieldLabel.tsx +9 -2
  697. package/src/Field/inputDisabledFocus.ts +18 -0
  698. package/src/Field/inputStyles.stylex.ts +52 -1
  699. package/src/Grid/Grid.doc.mjs +6 -3
  700. package/src/Grid/Grid.tsx +5 -2
  701. package/src/Heading/Heading.tsx +24 -1
  702. package/src/Icon/Icon.doc.mjs +1 -1
  703. package/src/Icon/Icon.tsx +40 -2
  704. package/src/Indicator/CheckboxIndicator.tsx +11 -6
  705. package/src/Indicator/Indicator.doc.mjs +1 -1
  706. package/src/Indicator/RadioIndicator.tsx +31 -4
  707. package/src/Indicator/indicatorRegistry.ts +7 -23
  708. package/src/Indicator/themeIndicators.ts +29 -0
  709. package/src/Indicator/types.ts +14 -0
  710. package/src/Indicator/useThemeIndicator.ts +24 -0
  711. package/src/Item/Item.doc.mjs +3 -3
  712. package/src/Item/Item.tsx +48 -7
  713. package/src/Kbd/Kbd.doc.mjs +6 -2
  714. package/src/Kbd/Kbd.tsx +16 -1
  715. package/src/Layer/layerExitCopy.ts +0 -1
  716. package/src/Layer/layerSlideRules.ts +62 -74
  717. package/src/Layer/useLayer.doc.mjs +2 -2
  718. package/src/Layer/useLayer.tsx +293 -137
  719. package/src/Layer/useLayerKeyboardClearance.ts +9 -12
  720. package/src/Layout/Layout.doc.mjs +3 -3
  721. package/src/Layout/LayoutContainerContext.ts +27 -0
  722. package/src/Layout/LayoutContainerScope.tsx +32 -0
  723. package/src/Layout/LayoutContent.tsx +5 -2
  724. package/src/Layout/LayoutFooter.tsx +3 -1
  725. package/src/Layout/LayoutHeader.tsx +3 -1
  726. package/src/Layout/containerCorners.stylex.ts +44 -7
  727. package/src/Lightbox/Lightbox.tsx +460 -8
  728. package/src/Link/Link.doc.mjs +18 -0
  729. package/src/Link/Link.tsx +3 -1
  730. package/src/List/List.tsx +14 -2
  731. package/src/List/ListContext.tsx +60 -1
  732. package/src/List/ListItem.doc.mjs +11 -9
  733. package/src/List/ListItem.tsx +4 -4
  734. package/src/Markdown/Markdown.doc.mjs +1 -1
  735. package/src/Markdown/Markdown.tsx +189 -190
  736. package/src/Markdown/plugins/HeadingLinksRenderer.tsx +14 -4
  737. package/src/Markdown/plugins/protocol.ts +3 -3
  738. package/src/MetadataList/MetadataListItem.tsx +18 -3
  739. package/src/MobileNav/MobileNav.doc.mjs +134 -52
  740. package/src/MobileNav/MobileNav.tsx +13 -9
  741. package/src/MultiSelector/MultiSelector.doc.mjs +2 -2
  742. package/src/MultiSelector/MultiSelector.tsx +51 -8
  743. package/src/NavMenu/NavHeadingMenu.tsx +5 -1
  744. package/src/NavMenu/NavHeadingMenuItem.tsx +1 -0
  745. package/src/NavMenu/NavMenu.doc.mjs +105 -2
  746. package/src/NavMenu/NavMenuContext.tsx +13 -0
  747. package/src/NumberInput/NumberInput.doc.mjs +12 -10
  748. package/src/NumberInput/NumberInput.tsx +19 -11
  749. package/src/Outline/Outline.doc.mjs +26 -8
  750. package/src/Outline/Outline.tsx +35 -5
  751. package/src/Outline/useScrollSpy.ts +8 -3
  752. package/src/OverflowList/OverflowList.doc.mjs +15 -0
  753. package/src/OverflowList/OverflowList.tsx +62 -26
  754. package/src/Pagination/Pagination.doc.mjs +12 -0
  755. package/src/Pagination/Pagination.tsx +40 -6
  756. package/src/Popover/Popover.doc.mjs +10 -0
  757. package/src/Popover/Popover.tsx +8 -4
  758. package/src/Popover/popoverAnchor.ts +47 -0
  759. package/src/Popover/usePopover.doc.mjs +16 -2
  760. package/src/Popover/usePopover.tsx +152 -16
  761. package/src/PowerSearch/PowerSearch.doc.mjs +8 -8
  762. package/src/PowerSearch/PowerSearch.tsx +65 -12
  763. package/src/PowerSearch/PowerSearchEditPopover.tsx +1 -0
  764. package/src/PowerSearch/PowerSearchFilterEditor.tsx +12 -0
  765. package/src/PowerSearch/PowerSearchToken.tsx +12 -0
  766. package/src/PowerSearch/PowerSearchValueEditor.tsx +14 -19
  767. package/src/ProgressBar/ProgressBar.doc.mjs +2 -2
  768. package/src/ProgressBar/ProgressBar.tsx +44 -30
  769. package/src/RadioList/RadioList.tsx +63 -0
  770. package/src/RadioList/RadioListItem.tsx +4 -1
  771. package/src/Resizable/ResizeHandle.tsx +2 -3
  772. package/src/Resizable/resizableModel.ts +105 -3
  773. package/src/Resizable/resizeGesture.ts +14 -0
  774. package/src/Resizable/useResizable.ts +14 -75
  775. package/src/SegmentedControl/SegmentedControlItem.tsx +1 -0
  776. package/src/SegmentedControl/useSegmentedTouchTracking.ts +76 -12
  777. package/src/Selector/Selector.doc.mjs +34 -7
  778. package/src/Selector/Selector.tsx +55 -25
  779. package/src/Selector/SelectorOption.doc.mjs +5 -5
  780. package/src/Selector/hooks.ts +92 -17
  781. package/src/Selector/useSelectorPresentation.ts +18 -3
  782. package/src/SideNav/SideNavHeading.tsx +15 -4
  783. package/src/SideNav/SideNavItem.doc.mjs +10 -10
  784. package/src/Slider/Slider.tsx +4 -1
  785. package/src/Spinner/Spinner.tsx +56 -41
  786. package/src/Stepper/Step.tsx +18 -3
  787. package/src/Stepper/Stepper.doc.mjs +14 -2
  788. package/src/Swipe/useSwipeAction.ts +3 -3
  789. package/src/Switch/Switch.doc.mjs +61 -5
  790. package/src/Switch/Switch.tsx +72 -35
  791. package/src/Switch/useSwitchTouch.ts +68 -3
  792. package/src/TabList/Tab.tsx +6 -0
  793. package/src/Table/BaseTable.tsx +73 -35
  794. package/src/Table/Table.doc.mjs +109 -5
  795. package/src/Table/Table.tsx +42 -17
  796. package/src/Table/TableBody.tsx +10 -1
  797. package/src/Table/TableCell.tsx +6 -0
  798. package/src/Table/TableHeaderCell.tsx +52 -7
  799. package/src/Table/TableRow.tsx +8 -1
  800. package/src/Table/TableRowPlacementContext.ts +58 -0
  801. package/src/Table/TableSelectionToolbar.tsx +12 -0
  802. package/src/Table/columnUtils.ts +9 -1
  803. package/src/Table/plugins/columnSettings/useTableColumnSettingsState.doc.mjs +1 -1
  804. package/src/Table/plugins/rowIndex/useTableRowIndex.tsx +1 -0
  805. package/src/Table/plugins/sortable/useTableSortable.tsx +15 -2
  806. package/src/Table/plugins/sortable/useTableSortableState.doc.mjs +5 -5
  807. package/src/Table/plugins/sortable/useTableSortableState.tsx +15 -8
  808. package/src/Table/plugins/stickyColumns/useTableStickyColumns.tsx +8 -0
  809. package/src/Table/plugins/tree/useTableTreeData.tsx +90 -14
  810. package/src/Table/table.stylex.ts +44 -5
  811. package/src/Table/types.ts +3 -1
  812. package/src/Table/useTableColumnResize.doc.mjs +3 -3
  813. package/src/Table/useTableColumnSettings.doc.mjs +3 -3
  814. package/src/Table/useTableFilterState.doc.mjs +6 -3
  815. package/src/Table/useTableFiltering.doc.mjs +71 -4
  816. package/src/Table/useTableInfiniteScroll.doc.mjs +2 -2
  817. package/src/Table/useTablePagination.doc.mjs +24 -3
  818. package/src/Table/useTableSelection.doc.mjs +30 -6
  819. package/src/Table/useTableSelectionState.doc.mjs +30 -2
  820. package/src/Table/useTableSortable.doc.mjs +104 -17
  821. package/src/Table/useTableStickyColumns.doc.mjs +3 -3
  822. package/src/Table/useTableTreeData.doc.mjs +2 -2
  823. package/src/Text/Heading.doc.mjs +2 -2
  824. package/src/Text/Text.doc.mjs +1 -1
  825. package/src/Text/TruncationTooltip.tsx +168 -1
  826. package/src/Text/useTruncation.ts +20 -4
  827. package/src/TextArea/TextArea.doc.mjs +5 -5
  828. package/src/TextArea/TextArea.tsx +20 -1
  829. package/src/TextInput/TextInput.doc.mjs +5 -5
  830. package/src/TextInput/TextInput.tsx +23 -18
  831. package/src/Thumbnail/Thumbnail.tsx +2 -1
  832. package/src/Timer/Timer.tsx +21 -6
  833. package/src/Timestamp/Timestamp.tsx +67 -4
  834. package/src/Toast/Toast.doc.mjs +15 -5
  835. package/src/Toast/Toast.tsx +83 -62
  836. package/src/Toast/ToastViewport.tsx +62 -23
  837. package/src/Toast/types.ts +8 -0
  838. package/src/Toast/useToast.doc.mjs +80 -15
  839. package/src/Toast/useToast.tsx +18 -7
  840. package/src/ToggleButton/ToggleButton.doc.mjs +1 -1
  841. package/src/ToggleButton/ToggleButton.tsx +25 -2
  842. package/src/Token/Token.tsx +5 -1
  843. package/src/Tokenizer/Tokenizer.doc.mjs +15 -3
  844. package/src/Tokenizer/Tokenizer.tsx +130 -75
  845. package/src/Toolbar/Toolbar.tsx +55 -4
  846. package/src/Tooltip/Tooltip.tsx +34 -0
  847. package/src/Tooltip/useTooltip.tsx +26 -0
  848. package/src/TopNav/TopNav.doc.mjs +1 -1
  849. package/src/TopNav/TopNav.tsx +13 -3
  850. package/src/TopNav/TopNavContext.ts +31 -1
  851. package/src/TopNav/TopNavHeading.tsx +22 -9
  852. package/src/TopNav/TopNavMegaMenu.tsx +27 -18
  853. package/src/TopNav/TopNavMegaMenuFeaturedCard.tsx +14 -2
  854. package/src/TopNav/TopNavMegaMenuItem.doc.mjs +26 -5
  855. package/src/TopNav/TopNavMegaMenuItem.tsx +26 -2
  856. package/src/TopNav/TopNavMenu.doc.mjs +19 -8
  857. package/src/TopNav/TopNavMenu.tsx +34 -2
  858. package/src/TopNav/TopNavRenderContext.ts +30 -9
  859. package/src/TreeList/TreeList.tsx +12 -0
  860. package/src/TreeList/TreeListItem.tsx +26 -5
  861. package/src/Typeahead/BaseTypeahead.doc.mjs +6 -0
  862. package/src/Typeahead/BaseTypeahead.tsx +2 -0
  863. package/src/Typeahead/Typeahead.doc.mjs +15 -2
  864. package/src/Typeahead/Typeahead.tsx +37 -13
  865. package/src/Typeahead/TypeaheadItem.tsx +12 -0
  866. package/src/gestures/GestureHost.ts +34 -0
  867. package/src/gestures/README.md +9 -6
  868. package/src/hooks/anchoredHint.tsx +1 -2
  869. package/src/hooks/computeOverflow.ts +10 -0
  870. package/src/hooks/focusableSelector.ts +59 -2
  871. package/src/hooks/scrollEdgeFade.ts +129 -0
  872. package/src/hooks/statusButtonPress.ts +26 -0
  873. package/src/hooks/useAnnounce.ts +2 -1
  874. package/src/hooks/useFocusTrap.ts +110 -141
  875. package/src/hooks/useGroupPressTracking.ts +1 -1
  876. package/src/hooks/useOverflow.ts +227 -13
  877. package/src/hooks/useResolvedRequired.ts +50 -1
  878. package/src/hooks/useTreeFocus.ts +8 -4
  879. package/src/hooks/useTypeahead.ts +12 -10
  880. package/src/i18n/InternationalizationContext.ts +16 -7
  881. package/src/i18n/InternationalizationProvider.doc.mjs +1 -1
  882. package/src/i18n/InternationalizationProvider.tsx +12 -0
  883. package/src/i18n/defaultTranslator.ts +25 -0
  884. package/src/i18n/firstStrongDirection.ts +54 -13
  885. package/src/i18n/generated-english/Chat/ChatPastedTextToken.generated.ts +1 -2
  886. package/src/i18n/generated-english/Chat/pastedTextLabel.generated.ts +13 -0
  887. package/src/i18n/generated-english/Chat/useTriggerMenu.generated.ts +1 -0
  888. package/src/i18n/generated-english/CodeBlock/CodeBlock.generated.ts +2 -1
  889. package/src/i18n/generated-english/Markdown/plugins/HeadingLinksRenderer.generated.ts +2 -1
  890. package/src/i18n/generated-english/MultiSelector/MultiSelector.generated.ts +1 -0
  891. package/src/i18n/generated-english/Slider/Slider.generated.ts +2 -1
  892. package/src/i18n/generated-english/TextArea/TextArea.generated.ts +1 -0
  893. package/src/i18n/generated-english/TextInput/TextInput.generated.ts +1 -0
  894. package/src/i18n/generated-english/Timestamp/Timestamp.generated.ts +2 -1
  895. package/src/i18n/generated-english/Tokenizer/Tokenizer.generated.ts +1 -0
  896. package/src/i18n/generated-locales/en.generated.ts +11 -0
  897. package/src/i18n/generated-locales/pseudo.generated.ts +11 -0
  898. package/src/i18n/publicContext.ts +4 -2
  899. package/src/i18n/translatingContext.ts +28 -0
  900. package/src/i18n/useComponentTranslator.ts +3 -2
  901. package/src/i18n/useListFormatter.ts +3 -2
  902. package/src/i18n/useTranslator.ts +3 -2
  903. package/src/internal/touch.ts +7 -0
  904. package/src/keyboard/README.md +58 -16
  905. package/src/keyboard/keyboardHeight.ts +138 -26
  906. package/src/keyboard/keyboardTarget.ts +667 -71
  907. package/src/keyboard/useMobileKeyboard.ts +1 -7
  908. package/src/palette/color.ts +205 -0
  909. package/src/palette/generator.ts +1134 -0
  910. package/src/palette/index.ts +35 -0
  911. package/src/palette/mapping.ts +1630 -0
  912. package/src/palette/themePalette.ts +175 -0
  913. package/src/palette/types.ts +194 -0
  914. package/src/privateAttributes/mediaDarkPage.ts +27 -0
  915. package/src/privateAttributes/pressGroupItem.stylex.ts +2 -1
  916. package/src/privateAttributes/scheme.ts +37 -0
  917. package/src/privateAttributes/travelling.stylex.ts +6 -4
  918. package/src/reset.css +1 -1
  919. package/src/theme/MediaDarkPage.tsx +41 -0
  920. package/src/theme/MediaTheme.tsx +8 -1
  921. package/src/theme/Theme.doc.mjs +4 -4
  922. package/src/theme/Theme.tsx +140 -35
  923. package/src/theme/defineTheme.ts +103 -40
  924. package/src/theme/derivedVarRegistry.ts +61 -4
  925. package/src/theme/expandRadiusScale.ts +1 -5
  926. package/src/theme/generateThemeRules.ts +398 -342
  927. package/src/theme/index.ts +2 -4
  928. package/src/theme/invertedSurfaceSide.ts +65 -0
  929. package/src/theme/resolveThemeValues.ts +8 -2
  930. package/src/theme/statusRoleDefaults.ts +330 -0
  931. package/src/theme/statusRoleDerivation.ts +2 -1
  932. package/src/theme/syntax/SyntaxTheme.tsx +12 -0
  933. package/src/theme/themeAdaptations.ts +53 -5
  934. package/src/theme/tokenDefaults.ts +44 -0
  935. package/src/theme/tokenValues.ts +193 -0
  936. package/src/theme/tokens.stylex.ts +7 -5
  937. package/src/theme/tokens.ts +14 -176
  938. package/src/theme/useTheme.ts +164 -35
  939. package/src/utils/devWarning.ts +24 -0
  940. package/src/utils/focusOutline.stylex.ts +7 -4
  941. package/src/utils/focusReturn.ts +578 -16
  942. package/src/utils/hitArea.ts +70 -33
  943. package/src/utils/inputStream.ts +81 -5
  944. package/src/utils/nodeType.ts +10 -0
  945. package/src/utils/timeFormat.ts +54 -4
  946. package/src/utils/touchPresentation.stylex.ts +7 -6
  947. package/src/utils/touchPresentation.ts +10 -7
  948. package/src/utils/touchQueries.ts +3 -2
  949. package/src/utils/typeaheadMatch.ts +20 -1
  950. package/src/virtualization/useInlineListWindow.ts +57 -33
@@ -0,0 +1,1630 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file mapping.ts
5
+ * @input Palette seeds (accent, neutral, status colors), a generated
6
+ * candidate, the base theme's resolved colors, and optional exact settings
7
+ * @output The generation request for the seeds, and each color token's stop
8
+ * in light and dark with the contrast checks behind each choice
9
+ * @position The palette-to-token mapping for a palette made from color
10
+ * settings. `themePalette()` runs it, and the CLI theme editor runs its
11
+ * generated copy
12
+ */
13
+
14
+ import {hexToOklch, luminance, normalizeColor} from './color';
15
+ import {
16
+ PALETTE_BLACK,
17
+ PALETTE_WHITE,
18
+ generateTonalPalette,
19
+ perceptualDelta,
20
+ } from './generator';
21
+ import type {TonalPaletteCandidate, TonalPaletteGenerationInput} from './types';
22
+
23
+ export type PaletteMode = 'light' | 'dark';
24
+ type ColorTriple = [number, number, number];
25
+
26
+ /** One token pointed at a palette stop in one mode. */
27
+ export interface StopRef {
28
+ stop: number;
29
+ /** The stop's color, with `alpha` appended when set. */
30
+ color: string;
31
+ /** Two hex digits of opacity. */
32
+ alpha?: string;
33
+ /** The family the stop is from when it is not the token's own: `neutral` for text on a fill, `black` or `white` for the palette's own ends, `literal` for a color outside the palette. */
34
+ family?: string;
35
+ /** The stop holds the seed's exact color (an exact anchor). */
36
+ exact?: boolean;
37
+ }
38
+
39
+ /** One contrast check behind a stop choice. */
40
+ export interface ContrastCheck {
41
+ token: string;
42
+ mode: PaletteMode;
43
+ stop: number;
44
+ /** The stop the mapping starts from. */
45
+ preferred: number;
46
+ /** What it was measured on. */
47
+ against: string;
48
+ /** The lowest ratio over everything it was measured on. */
49
+ ratio: number;
50
+ needs: number;
51
+ pass: boolean;
52
+ /** The whole sentence to report, when the check is not a plain stop move. */
53
+ note?: string;
54
+ /** The color settings whose notes report it, when its token belongs to none of them. */
55
+ dials?: string[];
56
+ /** The nearest setting that passes it, when one does: a darker exact color for a pale fill. */
57
+ fix?: {thing: string; value: string; mode?: PaletteMode};
58
+ }
59
+
60
+ /** How the stop of an accent or status color's exact fill was settled. */
61
+ export interface PaletteFill {
62
+ stop: number;
63
+ dark: boolean;
64
+ why: string;
65
+ ratio: number;
66
+ }
67
+
68
+ /** Reads a fixed CSS color: its RGB (0–255) and its opacity (0–1). */
69
+ export interface PaletteColorReader {
70
+ rgb(value: unknown): ColorTriple | null;
71
+ alpha(value: unknown): number;
72
+ }
73
+
74
+ /** The resolved colors the mapping measures against, per mode. */
75
+ export interface PaletteBase {
76
+ light: Record<string, string>;
77
+ dark: Record<string, string>;
78
+ /** Part styles, which may lift secondary text on some parts. */
79
+ components?: Record<string, unknown>;
80
+ }
81
+
82
+ /** What the mapping reads around the palette. */
83
+ export interface PaletteMappingContext {
84
+ base?: PaletteBase;
85
+ /** Whether a token exists, so the mapping sets it. */
86
+ has: (token: string) => boolean;
87
+ reader: PaletteColorReader;
88
+ /** The value a token is set to exactly in a mode, as written. */
89
+ settingOf?: (token: string, mode: PaletteMode) => string | undefined;
90
+ /** The fixed color a written value gives in a mode, or null. */
91
+ colorIn?: (value: string, mode: PaletteMode) => string | null;
92
+ /** Whether a token is set exactly in any mode. */
93
+ setExactly?: (token: string) => boolean;
94
+ /** The line that sets a value, for a note that offers one; without it, the note offers none. */
95
+ setLine?: (thing: string, value: string, mode?: PaletteMode) => string;
96
+ }
97
+
98
+ /** One color setting: a palette family of the same id. */
99
+ export interface PaletteDial {
100
+ id: string;
101
+ seed: string;
102
+ }
103
+
104
+ /** A family of a palette config: the generator's family input, and any key of the author's. */
105
+ export interface ConfigFamily {
106
+ id?: unknown;
107
+ seed?: unknown;
108
+ anchors?: {mode: string; stop: number; [key: string]: unknown}[];
109
+ [key: string]: unknown;
110
+ }
111
+
112
+ /** A palette config: the generator's request, and any key of the author's. */
113
+ export interface PaletteConfig {
114
+ families: ConfigFamily[];
115
+ [key: string]: unknown;
116
+ }
117
+
118
+ /**
119
+ * A palette config as the generator's request. The generator checks every
120
+ * field it reads, and refuses a config it cannot run.
121
+ */
122
+ const asRequest = (config: PaletteConfig): TonalPaletteGenerationInput =>
123
+ config as unknown as TonalPaletteGenerationInput;
124
+
125
+ /** A family's stops in a mode. */
126
+ const rampOf = (
127
+ candidate: TonalPaletteCandidate,
128
+ id: string,
129
+ m: PaletteMode,
130
+ ): Record<string | number, string> => candidate.palette[id]?.[m] ?? {};
131
+
132
+ /** One block of a part's styles, or undefined. */
133
+ function partStyle(
134
+ components: Record<string, unknown> | undefined,
135
+ part: string,
136
+ block: string,
137
+ ): Record<string, unknown> | undefined {
138
+ const blocks = components?.[part];
139
+ const style =
140
+ blocks && typeof blocks === 'object'
141
+ ? (blocks as Record<string, unknown>)[block]
142
+ : undefined;
143
+ return style && typeof style === 'object'
144
+ ? (style as Record<string, unknown>)
145
+ : undefined;
146
+ }
147
+
148
+ /** The token mapping of a palette. */
149
+ export interface PaletteMapping {
150
+ tokens: Record<string, {family: string; light: StopRef; dark: StopRef}>;
151
+ contrast: ContrastCheck[];
152
+ /** Main tokens set exactly, per mode: the color's fill gives way to them. */
153
+ exact: Record<string, Partial<Record<PaletteMode, string>>>;
154
+ /** Main tokens set exactly to a value that is not one readable color in some mode, as written. */
155
+ unread: Record<string, string>;
156
+ /** Lifted secondary text per background token of LIFT_PARTS, per mode; null without one. */
157
+ lift: Record<string, Partial<Record<PaletteMode, StopRef>>> | null;
158
+ }
159
+
160
+ /** The color settings. Each one is a palette family of the same id. */
161
+ export const PALETTE_DIALS = Object.freeze([
162
+ 'accent',
163
+ 'neutral',
164
+ 'success',
165
+ 'warning',
166
+ 'danger',
167
+ 'info',
168
+ ]);
169
+
170
+ /** The generator's vibrancy when the theme sets none. */
171
+ export const VIBRANCY_DEFAULT = 50;
172
+
173
+ /** A value a mapping table holds. */
174
+ type TableEntry = object | string | number | boolean | null | undefined;
175
+
176
+ /** A record without inherited keys, so a key such as `constructor` reads nothing. */
177
+ function ownTable<T extends object>(table: T): T {
178
+ const own = (value: TableEntry): TableEntry => {
179
+ if (Array.isArray(value)) {
180
+ return value.map(own);
181
+ }
182
+ if (
183
+ !value ||
184
+ typeof value !== 'object' ||
185
+ Object.getPrototypeOf(value) !== Object.prototype
186
+ ) {
187
+ return value;
188
+ }
189
+ const out: Record<string, TableEntry> = Object.create(null);
190
+ for (const [key, entry] of Object.entries(
191
+ value as Record<string, TableEntry>,
192
+ )) {
193
+ out[key] = own(entry);
194
+ }
195
+ return out;
196
+ };
197
+ return own(table) as T;
198
+ }
199
+
200
+ /** The Core token word of each status family. */
201
+ export const STATUS_TOKEN: Record<string, string> = ownTable({
202
+ success: 'success',
203
+ warning: 'warning',
204
+ danger: 'error',
205
+ info: 'info',
206
+ });
207
+
208
+ /** The main token a color setting feeds: the exact-token escape hatch for it. */
209
+ export const paletteToken = (dial: string): string =>
210
+ dial === 'accent'
211
+ ? '--color-accent'
212
+ : dial === 'neutral'
213
+ ? '--color-background-surface'
214
+ : `--color-${STATUS_TOKEN[dial]}`;
215
+
216
+ /** Text contrast and non-text contrast (fills, focus rings, icons). */
217
+ export const TEXT = 4.5;
218
+ export const NON_TEXT = 3;
219
+
220
+ /**
221
+ * The official Neutral theme's color mapping: each token's stops,
222
+ * `[light, dark]`, with an opacity where it has one. A test keeps it equal
223
+ * to the Neutral theme's source.
224
+ */
225
+ export const OFFICIAL_NEUTRAL_STOPS: Readonly<
226
+ Record<string, ReadonlyArray<{stop: number; alpha?: string}>>
227
+ > = ownTable({
228
+ '--color-background-body': [{stop: 95}, {stop: 10}],
229
+ '--color-background-surface': [{stop: 100}, {stop: 15}],
230
+ '--color-background-card': [{stop: 100}, {stop: 10}],
231
+ '--color-background-popover': [{stop: 100}, {stop: 10}],
232
+ '--color-background-muted': [{stop: 95}, {stop: 10}],
233
+ '--color-text-primary': [{stop: 0}, {stop: 100}],
234
+ '--color-text-secondary': [{stop: 30}, {stop: 65}],
235
+ '--color-text-disabled': [{stop: 60}, {stop: 35}],
236
+ '--color-icon-primary': [{stop: 0}, {stop: 100}],
237
+ '--color-icon-secondary': [{stop: 45}, {stop: 65}],
238
+ '--color-icon-disabled': [{stop: 60}, {stop: 35}],
239
+ '--color-border-emphasized': [{stop: 85}, {stop: 35}],
240
+ '--color-skeleton': [{stop: 85}, {stop: 35}],
241
+ '--color-on-dark': [{stop: 100}, {stop: 100}],
242
+ '--color-on-light': [{stop: 5}, {stop: 5}],
243
+ '--color-border': [
244
+ {stop: 0, alpha: '14'},
245
+ {stop: 100, alpha: '1a'},
246
+ ],
247
+ '--color-overlay-hover': [
248
+ {stop: 0, alpha: '0d'},
249
+ {stop: 100, alpha: '0d'},
250
+ ],
251
+ '--color-overlay-pressed': [
252
+ {stop: 0, alpha: '1a'},
253
+ {stop: 100, alpha: '1a'},
254
+ ],
255
+ '--color-text-info': [{stop: 45}, {stop: 80}],
256
+ '--color-accent-muted': [{stop: 85}, {stop: 30}],
257
+ '--color-info-muted': [{stop: 85}, {stop: 75, alpha: '3d'}],
258
+ '--color-on-info-muted': [{stop: 25}, {stop: 80}],
259
+ '--color-on-accent': [{stop: 100}, {stop: 5}],
260
+ });
261
+
262
+ /** The parts whose secondary text the official Neutral theme lifts, `[part, block]`. */
263
+ export const OFFICIAL_NEUTRAL_LIFTED: ReadonlyArray<readonly [string, string]> =
264
+ Object.freeze([
265
+ ['item', 'selected'],
266
+ ['tree-list-item', 'selected'],
267
+ ['file-input', 'mode:dropzone'],
268
+ ['citation', 'variant:number'],
269
+ ['segmented-control-item', 'base'],
270
+ ['card', 'variant:blue'],
271
+ ['card', 'variant:cyan'],
272
+ ['card', 'variant:green'],
273
+ ['card', 'variant:orange'],
274
+ ['card', 'variant:pink'],
275
+ ['card', 'variant:purple'],
276
+ ['card', 'variant:red'],
277
+ ['card', 'variant:teal'],
278
+ ['card', 'variant:yellow'],
279
+ ] as const);
280
+
281
+ /** A token's official `[light, dark]` stops. */
282
+ const officialStops = (token: string): [number, number] =>
283
+ (OFFICIAL_NEUTRAL_STOPS[token] ?? []).map(x => x.stop) as [number, number];
284
+
285
+ /**
286
+ * The tokens the neutral color sets at the official theme's stops: the
287
+ * page background and the surfaces on it. A warm or cool gray so reaches
288
+ * the page as it reaches the cards. The inverted surface (tooltips,
289
+ * toasts) is the card surface of the other mode, inside the ramp (never
290
+ * the white or black end every ramp shares), so it carries the neutral
291
+ * color. A layout without one of these stops uses the nearest one it has.
292
+ */
293
+ export const NEUTRAL_STOPS: Record<string, [number, number]> = ownTable({
294
+ ...Object.fromEntries(
295
+ [
296
+ '--color-background-body',
297
+ '--color-background-surface',
298
+ '--color-background-card',
299
+ '--color-background-popover',
300
+ '--color-background-muted',
301
+ '--color-text-primary',
302
+ '--color-text-secondary',
303
+ '--color-text-disabled',
304
+ '--color-icon-primary',
305
+ '--color-icon-secondary',
306
+ '--color-icon-disabled',
307
+ '--color-border-emphasized',
308
+ '--color-skeleton',
309
+ '--color-on-dark',
310
+ '--color-on-light',
311
+ ].map(t => [t, officialStops(t)]),
312
+ ),
313
+ '--color-background-inverted': [
314
+ ...officialStops('--color-background-card'),
315
+ ].reverse() as [number, number],
316
+ });
317
+ /** Neutral tokens whose shade stays inside the ramp, off its white and black ends. */
318
+ export const NEUTRAL_INSIDE: ReadonlyArray<string> = Object.freeze([
319
+ '--color-background-inverted',
320
+ ]);
321
+ /** Neutral tints: a stop with an opacity, `[[stop, alpha], [stop, alpha]]`. */
322
+ export const NEUTRAL_TINTS: Record<
323
+ string,
324
+ [[number, string], [number, string]]
325
+ > = ownTable(
326
+ Object.fromEntries(
327
+ ['--color-border', '--color-overlay-hover', '--color-overlay-pressed'].map(
328
+ t => [
329
+ t,
330
+ (OFFICIAL_NEUTRAL_STOPS[t] ?? []).map((x): [number, string] => [
331
+ x.stop,
332
+ String(x.alpha),
333
+ ]) as [[number, string], [number, string]],
334
+ ],
335
+ ),
336
+ ),
337
+ );
338
+ /**
339
+ * Accent and status stops, `[light, dark]`, as the official Neutral theme
340
+ * maps its accent tint and its status families (info stands for them). The
341
+ * dark fill starts at 70 when the exact color does not read in dark. A
342
+ * status tint is translucent in dark (`[stop, alpha]`).
343
+ */
344
+ export const DARK_FILL = 70;
345
+ export const TEXT_STOP = officialStops('--color-text-info');
346
+ export const ACCENT_MUTED = officialStops('--color-accent-muted');
347
+ export const STATUS_MUTED = (
348
+ OFFICIAL_NEUTRAL_STOPS['--color-info-muted'] ?? []
349
+ ).map((x, i) => (i === 0 ? x.stop : [x.stop, String(x.alpha)])) as [
350
+ number,
351
+ [number, string],
352
+ ];
353
+ export const ON_MUTED = officialStops('--color-on-info-muted');
354
+ /**
355
+ * The parts whose secondary text the official Neutral theme lifts, with
356
+ * the block it lifts it in and what the text sits on: the accent tint,
357
+ * except under segmented-control labels, which sit on the translucent
358
+ * neutral track (`--color-neutral`).
359
+ */
360
+ export const LIFT_PARTS: ReadonlyArray<[string, string, string]> =
361
+ OFFICIAL_NEUTRAL_LIFTED.map(([part, block]) => [
362
+ part,
363
+ block,
364
+ liftGround(part, block),
365
+ ]);
366
+ /**
367
+ * What a lifted block's secondary text sits on: a card's own fill for a
368
+ * card colour (the card variant rule lifts it there), the translucent
369
+ * neutral track under segmented-control labels, else the accent tint.
370
+ */
371
+ function liftGround(part: string, block: string): string {
372
+ if (part === 'segmented-control-item') {
373
+ return '--color-neutral';
374
+ }
375
+ const color = part === 'card' ? /^variant:([\w-]+)$/.exec(block)?.[1] : null;
376
+ return color ? `--color-background-${color}` : '--color-accent-muted';
377
+ }
378
+ /** What each lifted background is, and the parts on it, for notes. */
379
+ export const LIFT_GROUNDS: Record<string, {what: string; parts: string}> = {
380
+ '--color-accent-muted': {
381
+ what: 'the accent tint',
382
+ parts: 'selected items and rows, a dropzone, numbered citations',
383
+ },
384
+ '--color-neutral': {
385
+ what: 'the neutral track',
386
+ parts: 'segmented-control labels',
387
+ },
388
+ ...Object.fromEntries(
389
+ LIFT_PARTS.filter(([part]) => part === 'card').map(([, block, g]) => {
390
+ const color = block.replace(/^variant:/, '');
391
+ return [g, {what: `the ${color} card fill`, parts: `${color} cards`}];
392
+ }),
393
+ ),
394
+ };
395
+ export const BORDER: [number, number] = [80, 65];
396
+ /**
397
+ * Text on a fill, from the neutral family as the official themes take it:
398
+ * white (100) first in light, near-black (5) first in dark, and near-black
399
+ * first in both modes on warning. Without a neutral color, black and white.
400
+ */
401
+ const [ON_LIGHT, ON_DARK] = officialStops('--color-on-accent');
402
+ export const ON_FILL: Record<PaletteMode, [number, number]> = ownTable({
403
+ light: [ON_LIGHT, ON_DARK],
404
+ dark: [ON_DARK, ON_LIGHT],
405
+ });
406
+ /** Text on surfaces darkens in light mode and lightens in dark mode. */
407
+ export const TOWARD_CONTRAST: Record<PaletteMode, 1 | -1> = ownTable({
408
+ light: -1,
409
+ dark: 1,
410
+ });
411
+
412
+ /**
413
+ * Below this OKLCH chroma a seed reads as gray: its family is generated as a
414
+ * neutral, so no hue is invented for it in either mode.
415
+ */
416
+ const GRAY_CHROMA = 0.02;
417
+
418
+ /** Whether a seed reads as gray. */
419
+ export const isGray = (seed: string): boolean =>
420
+ hexToOklch(seed).C < GRAY_CHROMA;
421
+
422
+ /** Whether two values are one color. */
423
+ export function sameColor(a: unknown, b: unknown): boolean {
424
+ try {
425
+ return normalizeColor(String(a)) === normalizeColor(String(b));
426
+ } catch {
427
+ return false;
428
+ }
429
+ }
430
+
431
+ /** RGB channels (0–255) as a lowercase six-digit hex. */
432
+ export const hex = (rgb: ReadonlyArray<number>): string =>
433
+ `#${rgb
434
+ .slice(0, 3)
435
+ .map(x =>
436
+ Math.round(Math.max(0, Math.min(255, x)))
437
+ .toString(16)
438
+ .padStart(2, '0'),
439
+ )
440
+ .join('')}`;
441
+
442
+ /** The WCAG contrast ratio of two RGB colors, each rounded to a hex first. */
443
+ export function ratio(
444
+ a: ReadonlyArray<number>,
445
+ b: ReadonlyArray<number>,
446
+ ): number {
447
+ const [x, y] = [luminance(hex(a)), luminance(hex(b))].sort((p, q) => q - p);
448
+ return (x + 0.05) / (y + 0.05);
449
+ }
450
+
451
+ /** A color drawn at `alpha` over `under`, as the opaque color the eye sees. */
452
+ export function compositeOver(
453
+ over: ReadonlyArray<number>,
454
+ alpha: number,
455
+ under: ReadonlyArray<number>,
456
+ ): ColorTriple {
457
+ return over.map((c, i) => c * alpha + under[i] * (1 - alpha)) as ColorTriple;
458
+ }
459
+
460
+ /** A ratio to two decimals. */
461
+ export const round = (r: number): number => Math.round(r * 100) / 100;
462
+
463
+ /** A stop as text: a layout may hold 16.666666666666668. */
464
+ export const shade = (s: number): string => String(round(s));
465
+
466
+ /**
467
+ * The stop of a ramp whose shade is nearest a color, as the eye compares
468
+ * them; never an end stop (pure black or white, which every ramp shares).
469
+ * Null for a ramp with no inner stop.
470
+ */
471
+ export function nearestShade(
472
+ ramp: Record<string | number, string>,
473
+ color: string,
474
+ ): string | null {
475
+ const inner = Object.keys(ramp).filter(s => Number(s) > 0 && Number(s) < 100);
476
+ if (!inner.length) {
477
+ return null;
478
+ }
479
+ return inner.reduce((best, s) =>
480
+ perceptualDelta(ramp[s], color) < perceptualDelta(ramp[best], color)
481
+ ? s
482
+ : best,
483
+ );
484
+ }
485
+
486
+ /** The stop of a layout nearest `n`; on a tie, the one nearer the middle. */
487
+ export function nearestStop(stops: ReadonlyArray<number>, n: number): number {
488
+ return stops.reduce((best, s) => {
489
+ const d = Math.abs(s - n) - Math.abs(best - n);
490
+ return d < 0 || (d === 0 && Math.abs(s - 50) < Math.abs(best - 50))
491
+ ? s
492
+ : best;
493
+ });
494
+ }
495
+
496
+ /**
497
+ * The light stop nearest a seed color in the ramp the generator grows from
498
+ * it. The official themes anchor a brand color there, exactly, so the fill
499
+ * keeps the color as given. The end stops are pure black and white and
500
+ * never hold an anchor.
501
+ */
502
+ export function seedStop(
503
+ seed: string,
504
+ config: {stops?: number[]; vibrancy?: number},
505
+ kind: 'chromatic' | 'neutral' = 'chromatic',
506
+ ): number {
507
+ const {palette} = generateTonalPalette({
508
+ ...(config.stops ? {stops: config.stops} : {}),
509
+ ...(config.vibrancy != null ? {vibrancy: config.vibrancy} : {}),
510
+ ...(kind === 'neutral' ? {neutralProfile: 'custom'} : {}),
511
+ modeStrategy: 'light-only',
512
+ families: [{id: 'seed', seed, kind}],
513
+ });
514
+ const ramp = palette.seed.light as Record<number, string>;
515
+ return Number(nearestShade(ramp, seed));
516
+ }
517
+
518
+ /**
519
+ * A gray ramp the generator grows from a gray of the theme (its secondary
520
+ * text), for a mode: the grays of a theme whose palette has no neutral
521
+ * family. Null when the seed does not grow.
522
+ */
523
+ export function grownGrays(
524
+ seed: string,
525
+ m: PaletteMode,
526
+ ): Record<string, string> | null {
527
+ try {
528
+ const g = generateTonalPalette({
529
+ modeStrategy: m === 'light' ? 'light-only' : 'dark-only',
530
+ neutralProfile: 'custom',
531
+ families: [{id: 'gray', seed, kind: 'neutral'}],
532
+ });
533
+ return g.palette.gray[m] ?? null;
534
+ } catch {
535
+ return null;
536
+ }
537
+ }
538
+
539
+ /** A text shade, named for a sentence. */
540
+ export const textName = (r: StopRef): string =>
541
+ r.family === 'white' || (r.family === 'neutral' && r.stop >= 95)
542
+ ? 'white'
543
+ : r.family === 'black' || (r.family === 'neutral' && r.stop <= 10)
544
+ ? 'near-black'
545
+ : `shade ${r.stop}`;
546
+
547
+ /**
548
+ * Look-ups shared by the request planner and the mapping, on one
549
+ * candidate: the nearest stop, a stop's color, the surfaces text and fills
550
+ * sit on, the text that reads on a fill, and the theme's exact colors.
551
+ */
552
+ export function paletteTools(
553
+ candidate: TonalPaletteCandidate,
554
+ context: PaletteMappingContext,
555
+ ) {
556
+ const {base, reader} = context;
557
+ const {stops} = candidate;
558
+ const parseColor = reader.rgb;
559
+ const alphaOf = reader.alpha;
560
+ const contrast = (a: string, b: string): number => {
561
+ const x = parseColor(a);
562
+ const y = parseColor(b);
563
+ if (!x || !y) {
564
+ throw new Error(`No contrast between "${a}" and "${b}".`);
565
+ }
566
+ return ratio(x, y);
567
+ };
568
+ const at = (n: number): number => nearestStop(stops, n);
569
+ /** The stop nearest `n` off the white and black ends. */
570
+ const atInside = (n: number): number =>
571
+ nearestStop(
572
+ stops.filter(s => s > 0 && s < 100),
573
+ n,
574
+ );
575
+ const ref = (
576
+ id: string,
577
+ m: PaletteMode,
578
+ stop: number,
579
+ alpha?: string,
580
+ ): StopRef => {
581
+ const color = rampOf(candidate, id, m)[stop];
582
+ return alpha ? {stop, color: `${color}${alpha}`, alpha} : {stop, color};
583
+ };
584
+ const neutral = Boolean(candidate.palette.neutral);
585
+ /** The value a token is set to exactly in a mode, as written, or undefined. */
586
+ const settingOf = (token: string, m: PaletteMode): string | undefined =>
587
+ context.settingOf?.(token, m);
588
+ const colorIn = (
589
+ value: string | undefined,
590
+ m: PaletteMode,
591
+ ): string | null => {
592
+ if (value == null) {
593
+ return null;
594
+ }
595
+ if (context.colorIn) {
596
+ return context.colorIn(value, m);
597
+ }
598
+ // (Without a reader of its own, a value is a color when it is one.)
599
+ const v = value.trim();
600
+ return parseColor(v) ? v : null;
601
+ };
602
+ /** The exact opaque color a token is set to in a mode, or null. */
603
+ const exactOf = (token: string, m: PaletteMode): string | null => {
604
+ const v = colorIn(settingOf(token, m), m);
605
+ const rgb = v == null ? null : parseColor(v);
606
+ return rgb && v != null && alphaOf(v) >= 1 ? hex(rgb) : null;
607
+ };
608
+ /**
609
+ * The exact color a token is set to in a mode, see-through or not, as
610
+ * written; null when there is none or it is not a fixed color.
611
+ */
612
+ const rawOf = (token: string, m: PaletteMode): string | null =>
613
+ colorIn(settingOf(token, m), m);
614
+ /**
615
+ * Which column of a `[light, dark]` mapping a mode takes: the light one
616
+ * on a light page and the dark one on a dark page, by the base theme's
617
+ * page, the one its surfaces were made for.
618
+ */
619
+ const side = (m: PaletteMode): 0 | 1 => {
620
+ const page = base?.[m]?.['--color-background-body'];
621
+ const rgb = page ? parseColor(page) : null;
622
+ if (!rgb || alphaOf(page) < 1) {
623
+ return m === 'light' ? 0 : 1;
624
+ }
625
+ return ratio(rgb, [255, 255, 255]) > ratio(rgb, [0, 0, 0]) ? 1 : 0;
626
+ };
627
+ /**
628
+ * What text and fills sit on in a mode: the theme's exact surface
629
+ * colors, else the neutral color's surfaces, else the base theme's; the
630
+ * family's own surface stop when nothing else is known.
631
+ */
632
+ const surfaces = (m: PaletteMode, id: string): [string, string][] => {
633
+ const out: [string, string][] = [];
634
+ for (const n of [
635
+ '--color-background-surface',
636
+ '--color-background-body',
637
+ '--color-background-card',
638
+ ]) {
639
+ const own =
640
+ neutral && NEUTRAL_STOPS[n]
641
+ ? ref('neutral', m, at(NEUTRAL_STOPS[n][side(m)])).color
642
+ : null;
643
+ const v = exactOf(n, m) ?? own ?? base?.[m]?.[n];
644
+ const rgb = v ? parseColor(v) : null;
645
+ if (v && rgb && alphaOf(v) >= 1) {
646
+ out.push([n, hex(rgb)]);
647
+ }
648
+ }
649
+ if (!out.length) {
650
+ const s = at(NEUTRAL_STOPS['--color-background-surface'][side(m)]);
651
+ out.push([`${id} shade ${s}`, ref(id, m, s).color]);
652
+ }
653
+ return out;
654
+ };
655
+ /** The text shades for a fill, preferred first. */
656
+ const onChoices = (id: string, m: PaletteMode): StopRef[] =>
657
+ (id === 'warning' ? [5, 100] : ON_FILL[m]).map(s =>
658
+ neutral
659
+ ? {...ref('neutral', m, at(s)), family: 'neutral'}
660
+ : s >= 50
661
+ ? {stop: 100, color: PALETTE_WHITE, family: 'white'}
662
+ : {stop: 0, color: PALETTE_BLACK, family: 'black'},
663
+ );
664
+ /**
665
+ * The text on a fill: the preferred shade when it reads at 4.5:1, else
666
+ * the one that reads better.
667
+ */
668
+ const onFor = (id: string, m: PaletteMode, fill: string) => {
669
+ const [a, b] = onChoices(id, m).map(on => ({
670
+ on,
671
+ r: contrast(on.color, fill),
672
+ }));
673
+ let best = a.r >= TEXT || a.r >= b.r ? a : b;
674
+ const other = best === a ? b : a;
675
+ // Neither reads: the end of the gray ramp on the better side (black
676
+ // past near-black, white past near-white) when it reads better, so the
677
+ // text picked is never one a darker or lighter gray would beat.
678
+ if (best.r < TEXT) {
679
+ const dark =
680
+ contrast(best.on.color, PALETTE_WHITE) > contrast(fill, PALETTE_WHITE);
681
+ const end: StopRef = neutral
682
+ ? {...ref('neutral', m, at(dark ? 0 : 100)), family: 'neutral'}
683
+ : dark
684
+ ? {stop: 0, color: PALETTE_BLACK, family: 'black'}
685
+ : {stop: 100, color: PALETTE_WHITE, family: 'white'};
686
+ const r = contrast(end.color, fill);
687
+ if (r > best.r) {
688
+ best = {on: end, r};
689
+ }
690
+ }
691
+ return {
692
+ on: best.on,
693
+ r: best.r,
694
+ other: other.on,
695
+ otherR: other.r,
696
+ first: a.on,
697
+ };
698
+ };
699
+ /** The lowest contrast of a color on the surfaces. */
700
+ const page = (color: string, m: PaletteMode, id: string): number =>
701
+ Math.min(...surfaces(m, id).map(([, bg]) => contrast(color, bg)));
702
+ /** A color as the eye sees it on the surface in a mode. */
703
+ const solid = (color: string, m: PaletteMode, id: string): string => {
704
+ const rgb = parseColor(color) as ColorTriple;
705
+ const a = alphaOf(color);
706
+ if (a >= 1) {
707
+ return hex(rgb);
708
+ }
709
+ const under = parseColor(surfaces(m, id)[0][1]) as ColorTriple;
710
+ return hex(compositeOver(rgb, a, under));
711
+ };
712
+ /** A translucent stop drawn over each surface; an opaque stop as it is. */
713
+ const over = (
714
+ name: string,
715
+ r: StopRef,
716
+ under: [string, string][],
717
+ ): [string, string][] => {
718
+ if (!r.alpha) {
719
+ return [[name, r.color]];
720
+ }
721
+ const top = parseColor(r.color.slice(0, 7)) as ColorTriple;
722
+ const a = parseInt(r.alpha, 16) / 255;
723
+ return under.map(([n, bg]) => [
724
+ `${name} over ${n}`,
725
+ hex(compositeOver(top, a, parseColor(bg) as ColorTriple)),
726
+ ]);
727
+ };
728
+ return {
729
+ stops,
730
+ at,
731
+ atInside,
732
+ ref,
733
+ exactOf,
734
+ settingOf,
735
+ rawOf,
736
+ side,
737
+ solid,
738
+ surfaces,
739
+ onFor,
740
+ page,
741
+ neutral,
742
+ contrast,
743
+ over,
744
+ parseColor,
745
+ alphaOf,
746
+ };
747
+ }
748
+
749
+ export type PaletteTools = ReturnType<typeof paletteTools>;
750
+
751
+ /**
752
+ * Whether the exact seed color works as the dark fill: text on it reads at
753
+ * 4.5:1 and it stands out from the dark surfaces at 3:1. Why not otherwise.
754
+ */
755
+ export function darkExact(
756
+ t: PaletteTools,
757
+ id: string,
758
+ seed: string,
759
+ ): {ok: boolean; ratio: number; why: string} {
760
+ const on = t.onFor(id, 'dark', seed);
761
+ if (on.r < TEXT) {
762
+ return {
763
+ ok: false,
764
+ ratio: round(on.r),
765
+ why: `your exact color reads at only ${round(on.r)}:1 with any text shade, and text needs ${TEXT}:1`,
766
+ };
767
+ }
768
+ const p = t.page(seed, 'dark', id);
769
+ if (p < NON_TEXT) {
770
+ return {
771
+ ok: false,
772
+ ratio: round(p),
773
+ why: `your exact color stands out from the dark page at only ${round(p)}:1, and a fill needs ${NON_TEXT}:1`,
774
+ };
775
+ }
776
+ return {ok: true, ratio: round(on.r), why: ''};
777
+ }
778
+
779
+ /** One family of a request, with its exact seed anchors. */
780
+ export type PaletteRequestFamily = {
781
+ id: string;
782
+ name: string;
783
+ seed: string;
784
+ kind?: 'neutral';
785
+ anchors?: {
786
+ mode: PaletteMode;
787
+ stop: number;
788
+ color: string;
789
+ policy: 'exact';
790
+ }[];
791
+ };
792
+
793
+ /**
794
+ * The family a color setting makes: its seed, a gray seed generated as a
795
+ * neutral, and the seed's exact color anchored at its nearest light stop
796
+ * (both modes for neutral). White or black as neutral holds no anchor:
797
+ * they already end every ramp.
798
+ */
799
+ export function dialFamily(
800
+ dial: PaletteDial,
801
+ config: {stops?: number[]; vibrancy?: number},
802
+ modes: ReadonlyArray<PaletteMode>,
803
+ ): {family: PaletteRequestFamily; stop: number} {
804
+ const neutral = dial.id === 'neutral';
805
+ const kind = neutral || isGray(dial.seed) ? 'neutral' : undefined;
806
+ const stop = seedStop(dial.seed, config, kind ?? 'chromatic');
807
+ const ends =
808
+ neutral &&
809
+ (sameColor(dial.seed, PALETTE_WHITE) ||
810
+ sameColor(dial.seed, PALETTE_BLACK));
811
+ const anchors = ends
812
+ ? []
813
+ : (neutral ? modes : modes.filter(m => m === 'light')).map(m => ({
814
+ mode: m,
815
+ stop,
816
+ color: dial.seed,
817
+ policy: 'exact' as const,
818
+ }));
819
+ return {
820
+ family: {
821
+ id: dial.id,
822
+ name: dial.id[0].toUpperCase() + dial.id.slice(1),
823
+ seed: dial.seed,
824
+ ...(kind ? {kind} : {}),
825
+ ...(anchors.length ? {anchors} : {}),
826
+ },
827
+ stop,
828
+ };
829
+ }
830
+
831
+ /**
832
+ * Anchors each accent and status seed in dark too where it reads there, as
833
+ * the official themes anchor a brand color in both modes. Settles each
834
+ * fill's `dark`, `why` and `ratio`; returns the families with the dark
835
+ * anchors that the generator can hold, and the notes of any anchor of the
836
+ * author's that one replaces.
837
+ */
838
+ export function anchorDarkFills(
839
+ config: PaletteConfig,
840
+ dials: ReadonlyArray<PaletteDial>,
841
+ fills: Record<string, PaletteFill>,
842
+ context: PaletteMappingContext,
843
+ replaced: (id: string, stop: number) => void = () => {},
844
+ ): ConfigFamily[] {
845
+ const t = paletteTools(generateTonalPalette(asRequest(config)), context);
846
+ const add: string[] = [];
847
+ for (const [id, fill] of Object.entries(fills)) {
848
+ const seed = dials.find(f => f.id === id)?.seed as string;
849
+ const check = darkExact(t, id, seed);
850
+ Object.assign(fill, {why: check.why, ratio: check.ratio});
851
+ if (check.ok) {
852
+ add.push(id);
853
+ }
854
+ }
855
+ const withDark = (id: string, cfg: typeof config): typeof config => ({
856
+ ...cfg,
857
+ families: cfg.families.map(f => {
858
+ if (f?.id !== id) {
859
+ return f;
860
+ }
861
+ const anchor = {
862
+ mode: 'dark',
863
+ stop: fills[id].stop,
864
+ color: f.seed,
865
+ policy: 'exact',
866
+ };
867
+ const own: {mode: string; stop: number}[] = f.anchors ?? [];
868
+ const others = own.filter(
869
+ a => !(a.mode === 'dark' && a.stop === anchor.stop),
870
+ );
871
+ if (others.length < own.length) {
872
+ replaced(id, anchor.stop);
873
+ }
874
+ return {
875
+ ...f,
876
+ anchors: [...others, anchor].sort((a, b) =>
877
+ a.mode === b.mode ? a.stop - b.stop : a.mode === 'light' ? -1 : 1,
878
+ ),
879
+ };
880
+ }),
881
+ });
882
+ let next = config;
883
+ for (const id of add) {
884
+ const tried = withDark(id, next);
885
+ try {
886
+ generateTonalPalette(asRequest(tried));
887
+ next = tried;
888
+ fills[id].dark = true;
889
+ } catch {
890
+ fills[id].why =
891
+ 'the dark shades cannot hold your exact color and stay in order from dark to light';
892
+ }
893
+ }
894
+ return next.families;
895
+ }
896
+
897
+ /** An accent or status fill at its seed's stop, before dark mode is settled. */
898
+ export const fillAt = (stop: number): PaletteFill => ({
899
+ stop,
900
+ dark: false,
901
+ why: '',
902
+ ratio: 0,
903
+ });
904
+
905
+ /** What `planPaletteRequest` settles for a set of color settings. */
906
+ export interface PalettePlan {
907
+ config: {
908
+ recipe?: string;
909
+ vibrancy?: number;
910
+ modeStrategy: 'light-and-dark';
911
+ families: ConfigFamily[];
912
+ };
913
+ fills: Record<string, PaletteFill>;
914
+ }
915
+
916
+ /**
917
+ * The generation request for color settings with no palette config of the
918
+ * author's: one family per setting in setting order, each seed anchored
919
+ * exactly, in dark too where it reads there. Null without a setting.
920
+ */
921
+ export function planPaletteRequest(
922
+ dials: ReadonlyArray<PaletteDial>,
923
+ options: {recipe?: string; vibrancy?: number},
924
+ context: PaletteMappingContext,
925
+ ): PalettePlan | null {
926
+ if (!dials.length) {
927
+ return null;
928
+ }
929
+ const modes: PaletteMode[] = ['light', 'dark'];
930
+ const config: PalettePlan['config'] = {
931
+ ...(options.recipe ? {recipe: options.recipe} : {}),
932
+ ...(options.vibrancy != null ? {vibrancy: options.vibrancy} : {}),
933
+ modeStrategy: 'light-and-dark',
934
+ families: [],
935
+ };
936
+ const fills: Record<string, PaletteFill> = {};
937
+ for (const dial of dials) {
938
+ const {family, stop} = dialFamily(dial, config, modes);
939
+ if (dial.id !== 'neutral') {
940
+ fills[dial.id] = fillAt(stop);
941
+ }
942
+ config.families.push(family);
943
+ }
944
+ if (Object.keys(fills).length) {
945
+ config.families = anchorDarkFills(config, dials, fills, context);
946
+ }
947
+ return {config, fills};
948
+ }
949
+
950
+ /**
951
+ * The token mapping of a generated palette: each color token's stop in
952
+ * light and dark, as the official Neutral theme maps its families, with the
953
+ * contrast checks behind each choice.
954
+ */
955
+ export function mapPalette(
956
+ candidate: TonalPaletteCandidate,
957
+ dials: ReadonlyArray<PaletteDial>,
958
+ fills: Record<string, PaletteFill>,
959
+ context: PaletteMappingContext,
960
+ ): PaletteMapping {
961
+ const t = paletteTools(candidate, context);
962
+ const {
963
+ stops,
964
+ at,
965
+ atInside,
966
+ ref,
967
+ exactOf,
968
+ rawOf,
969
+ settingOf,
970
+ side,
971
+ solid,
972
+ surfaces,
973
+ contrast,
974
+ over,
975
+ parseColor,
976
+ alphaOf,
977
+ } = t;
978
+ const {base, has} = context;
979
+ // Both halves, for a one-mode theme too.
980
+ const modes: PaletteMode[] = ['light', 'dark'];
981
+ const tokens: PaletteMapping['tokens'] = {};
982
+ const checks: ContrastCheck[] = [];
983
+ const exact: PaletteMapping['exact'] = {};
984
+ const unread: Record<string, string> = {};
985
+ const setExactly = (k: string): boolean => context.setExactly?.(k) ?? false;
986
+ const reports = (k: string): boolean => has(k) && !setExactly(k);
987
+ /** Point a token at its stops. One mode's stop stands for both when only one is given. */
988
+ const put = (
989
+ token: string,
990
+ id: string,
991
+ refs: Partial<Record<PaletteMode, StopRef>>,
992
+ ): void => {
993
+ if (!has(token)) {
994
+ return;
995
+ }
996
+ const one = refs[modes[0]] as StopRef;
997
+ tokens[token] = {
998
+ family: id,
999
+ light: refs.light ?? one,
1000
+ dark: refs.dark ?? one,
1001
+ };
1002
+ };
1003
+ const each = <T>(
1004
+ fn: (m: PaletteMode) => T,
1005
+ ): Partial<Record<PaletteMode, T>> =>
1006
+ Object.fromEntries(modes.map(m => [m, fn(m)]));
1007
+ /**
1008
+ * The stop nearest `start` that reads at `needs` on every color in `on`,
1009
+ * searched both ways (the usual way first on a tie: darker in light,
1010
+ * lighter in dark); the most contrasting stop of all when none does.
1011
+ */
1012
+ const pick = (
1013
+ token: string,
1014
+ id: string,
1015
+ m: PaletteMode,
1016
+ start: number,
1017
+ on: [string, string][],
1018
+ needs: number,
1019
+ ): StopRef => {
1020
+ const usual = TOWARD_CONTRAST[m];
1021
+ const order = [...stops].sort(
1022
+ (a, b) =>
1023
+ Math.abs(a - start) - Math.abs(b - start) ||
1024
+ (Math.sign(b - a) === usual ? 1 : -1),
1025
+ );
1026
+ const score = (stop: number): number => {
1027
+ const c = ref(id, m, stop).color;
1028
+ return Math.min(...on.map(([, bg]) => contrast(c, bg)));
1029
+ };
1030
+ const scored = order.map(stop => ({stop, r: score(stop)}));
1031
+ const b =
1032
+ scored.find(x => x.r >= needs) ??
1033
+ scored.reduce((x, y) => (y.r > x.r ? y : x));
1034
+ if (reports(token)) {
1035
+ checks.push({
1036
+ token,
1037
+ mode: m,
1038
+ stop: b.stop,
1039
+ preferred: start,
1040
+ against: on.map(([n]) => n).join(', '),
1041
+ ratio: round(b.r),
1042
+ needs,
1043
+ pass: b.r >= needs,
1044
+ });
1045
+ }
1046
+ return ref(id, m, b.stop);
1047
+ };
1048
+
1049
+ const neutral = dials.find(f => f.id === 'neutral');
1050
+ if (neutral) {
1051
+ for (const [token, pair] of Object.entries(NEUTRAL_STOPS)) {
1052
+ if (
1053
+ token === '--color-text-secondary' ||
1054
+ token === '--color-icon-secondary'
1055
+ ) {
1056
+ continue;
1057
+ }
1058
+ const shadeAt = NEUTRAL_INSIDE.includes(token) ? atInside : at;
1059
+ put(
1060
+ token,
1061
+ 'neutral',
1062
+ each(m => ref('neutral', m, shadeAt(pair[side(m)]))),
1063
+ );
1064
+ }
1065
+ for (const [token, pair] of Object.entries(NEUTRAL_TINTS)) {
1066
+ put(
1067
+ token,
1068
+ 'neutral',
1069
+ each(m => {
1070
+ const [s, a] = pair[side(m)];
1071
+ return ref('neutral', m, at(s), a);
1072
+ }),
1073
+ );
1074
+ }
1075
+ for (const [token, needs] of [
1076
+ ['--color-text-secondary', TEXT],
1077
+ ['--color-icon-secondary', NON_TEXT],
1078
+ ] as const) {
1079
+ put(
1080
+ token,
1081
+ 'neutral',
1082
+ each(m =>
1083
+ pick(
1084
+ token,
1085
+ 'neutral',
1086
+ m,
1087
+ at(NEUTRAL_STOPS[token][side(m)]),
1088
+ surfaces(m, 'neutral'),
1089
+ needs,
1090
+ ),
1091
+ ),
1092
+ );
1093
+ }
1094
+ const surface = paletteToken('neutral');
1095
+ const set = each(m => exactOf(surface, m));
1096
+ if (Object.values(set).some(Boolean)) {
1097
+ exact[surface] = Object.fromEntries(
1098
+ Object.entries(set).filter(([, v]) => v),
1099
+ );
1100
+ }
1101
+ }
1102
+
1103
+ for (const f of dials) {
1104
+ if (f.id === 'neutral') {
1105
+ continue;
1106
+ }
1107
+ const word = f.id === 'accent' ? null : STATUS_TOKEN[f.id];
1108
+ const names = word
1109
+ ? {
1110
+ fill: `--color-${word}`,
1111
+ on: `--color-on-${word}`,
1112
+ text: `--color-text-${word}`,
1113
+ icon: `--color-icon-${word}`,
1114
+ muted: `--color-${word}-muted`,
1115
+ onMuted: `--color-on-${word}-muted` as string | null,
1116
+ border: `--color-border-${word}` as string | null,
1117
+ focus: null as string | null,
1118
+ }
1119
+ : {
1120
+ fill: '--color-accent',
1121
+ on: '--color-on-accent',
1122
+ text: '--color-text-accent',
1123
+ icon: '--color-icon-accent',
1124
+ muted: '--color-accent-muted',
1125
+ onMuted: null as string | null,
1126
+ border: null as string | null,
1127
+ focus: '--focus-outline-color' as string | null,
1128
+ };
1129
+ const plain = fills[f.id];
1130
+ const S = plain.stop;
1131
+ const fillWord = f.id;
1132
+ const exactFill: Partial<Record<PaletteMode, string>> = {};
1133
+ for (const m of modes) {
1134
+ const v = rawOf(names.fill, m);
1135
+ if (v) {
1136
+ exactFill[m] = v;
1137
+ } else if (settingOf(names.fill, m) != null) {
1138
+ unread[names.fill] = String(settingOf(names.fill, m)).trim();
1139
+ }
1140
+ }
1141
+ if (Object.keys(exactFill).length) {
1142
+ exact[names.fill] = Object.fromEntries(
1143
+ Object.entries(exactFill).map(([m, v]) => {
1144
+ // A var() is named with the color it reads, so the note says
1145
+ // which color the text was picked for.
1146
+ const written = (
1147
+ settingOf(names.fill, m as PaletteMode) ?? ''
1148
+ ).trim();
1149
+ const rgb = parseColor(v);
1150
+ const color = rgb && alphaOf(v) >= 1 ? hex(rgb) : v;
1151
+ return [m, /var\(/i.test(written) ? `${written} = ${color}` : v];
1152
+ }),
1153
+ );
1154
+ }
1155
+
1156
+ const fill: Partial<Record<PaletteMode, StopRef>> = {};
1157
+ for (const m of modes) {
1158
+ if (m === 'light' || plain.dark) {
1159
+ fill[m] = {...ref(f.id, m, S), exact: true};
1160
+ continue;
1161
+ }
1162
+ // The dark fill when the exact color does not read there: shade 70,
1163
+ // else the shade nearest 70 that passes, else 70.
1164
+ const start = at(DARK_FILL);
1165
+ const order = [...stops]
1166
+ .filter(s => s > 0 && s < 100)
1167
+ .sort((a, b) => Math.abs(a - start) - Math.abs(b - start) || b - a);
1168
+ const found =
1169
+ order.find(s => {
1170
+ const c = ref(f.id, m, s).color;
1171
+ return (
1172
+ t.page(c, m, f.id) >= NON_TEXT && t.onFor(f.id, m, c).r >= TEXT
1173
+ );
1174
+ }) ?? start;
1175
+ fill[m] = ref(f.id, m, found);
1176
+ // The shade nearest your color that passes, offered as the theme's
1177
+ // own dark fill when it is closer to your color than the one used.
1178
+ const near = [...stops]
1179
+ .filter(s => s > 0 && s < 100)
1180
+ .sort((a, b) => Math.abs(a - S) - Math.abs(b - S) || b - a)
1181
+ .find(s => {
1182
+ const c = ref(f.id, m, s).color;
1183
+ return (
1184
+ t.page(c, m, f.id) >= NON_TEXT && t.onFor(f.id, m, c).r >= TEXT
1185
+ );
1186
+ });
1187
+ const closer =
1188
+ near != null &&
1189
+ Math.abs(near - S) < Math.abs(found - S) &&
1190
+ context.setLine
1191
+ ? (() => {
1192
+ const c = ref(f.id, m, near).color;
1193
+ const o = t.onFor(f.id, m, c);
1194
+ 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)`;
1195
+ })()
1196
+ : '';
1197
+ if (reports(names.fill)) {
1198
+ checks.push({
1199
+ token: names.fill,
1200
+ mode: m,
1201
+ stop: found,
1202
+ preferred: S,
1203
+ against: 'the dark page and the text on it',
1204
+ ratio: plain.ratio,
1205
+ needs: TEXT,
1206
+ pass: true,
1207
+ 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}`,
1208
+ });
1209
+ }
1210
+ }
1211
+ put(names.fill, f.id, fill);
1212
+
1213
+ // Text on the fill reads on the fill the theme really uses: the exact
1214
+ // token setting when there is one. The exact color never moves; the
1215
+ // text changes instead.
1216
+ const on = each(m => {
1217
+ const used = exactFill[m] ?? (fill[m] as StopRef).color;
1218
+ // A see-through exact fill is measured as it shows on the surface.
1219
+ const o = t.onFor(fillWord, m, solid(used, m, f.id));
1220
+ const what = exactFill[m]
1221
+ ? `your exact ${names.fill} (${used}${alphaOf(used) < 1 ? `, as it shows: ${solid(used, m, f.id)}` : ''})`
1222
+ : `${names.fill} (shade ${shade(Number(fill[m]?.stop))})`;
1223
+ const moved = o.on !== o.first;
1224
+ if (reports(names.on)) {
1225
+ checks.push({
1226
+ token: names.on,
1227
+ mode: m,
1228
+ stop: o.on.stop,
1229
+ preferred: o.first.stop,
1230
+ against: what,
1231
+ ratio: round(o.r),
1232
+ needs: TEXT,
1233
+ pass: o.r >= TEXT,
1234
+ ...(o.r < TEXT
1235
+ ? {
1236
+ 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`,
1237
+ }
1238
+ : moved
1239
+ ? {
1240
+ 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`,
1241
+ }
1242
+ : {}),
1243
+ });
1244
+ }
1245
+ return o.on;
1246
+ });
1247
+ put(names.on, f.id, on);
1248
+
1249
+ // A pale fill in light can disappear into the page: say so, and keep
1250
+ // the exact color, the setting's or the token's.
1251
+ if (modes.includes('light') && has(names.fill)) {
1252
+ const used = exactFill.light ?? (fill.light as StopRef).color;
1253
+ const p = t.page(solid(used, 'light', f.id), 'light', f.id);
1254
+ // The nearest darker color that stands out from the light page.
1255
+ let darker: string | null = null;
1256
+ const from = parseColor(solid(used, 'light', f.id));
1257
+ for (let i = 1; from && i <= 100 && !darker; i++) {
1258
+ const c = hex(from.map(v => Math.round(v * (1 - i / 100))));
1259
+ if (t.page(c, 'light', f.id) >= NON_TEXT) {
1260
+ darker = c;
1261
+ }
1262
+ }
1263
+ if (p < NON_TEXT) {
1264
+ checks.push({
1265
+ token: names.fill,
1266
+ mode: 'light',
1267
+ stop: S,
1268
+ preferred: S,
1269
+ against: 'the light page',
1270
+ ratio: round(p),
1271
+ needs: NON_TEXT,
1272
+ pass: false,
1273
+ note: exactFill.light
1274
+ ? `in light, your exact ${names.fill} (${used}) stands out from the page at only ${round(p)}:1, and a fill needs ${NON_TEXT}:1, so its buttons and badges may not show: give it a darker color`
1275
+ : `in light, your exact ${f.id} stands out from the page at only ${round(p)}:1, and a fill needs ${NON_TEXT}:1, so ${names.fill} buttons and badges may not show: pick a darker ${f.id}`,
1276
+ ...(darker
1277
+ ? {
1278
+ fix: exactFill.light
1279
+ ? {thing: names.fill, value: darker, mode: 'light' as const}
1280
+ : {thing: f.id, value: darker},
1281
+ }
1282
+ : {}),
1283
+ });
1284
+ }
1285
+ }
1286
+
1287
+ // The tint: the official stop, never the fill's own shade, see-through
1288
+ // or not.
1289
+ const muted = each(m => {
1290
+ const i = side(m);
1291
+ const spec = word ? STATUS_MUTED[i] : ACCENT_MUTED[i];
1292
+ const [s, alpha] = Array.isArray(spec) ? spec : [spec, undefined];
1293
+ // Nearest the official stop first, both ways; on a tie (a layout
1294
+ // without that stop) lighter first in light, darker in dark.
1295
+ const usual = i === 0 ? 1 : -1;
1296
+ const order = [...stops].sort(
1297
+ (a, b) =>
1298
+ Math.abs(a - s) - Math.abs(b - s) ||
1299
+ (Math.sign(b - a) === usual ? 1 : -1),
1300
+ );
1301
+ const away = order.filter(x => x !== fill[m]?.stop);
1302
+ return ref(f.id, m, away[0] ?? order[0], alpha);
1303
+ });
1304
+ put(names.muted, f.id, muted);
1305
+ /** The tint the theme really shows: an exact setting wins. */
1306
+ const mutedSeen = (m: PaletteMode): [string, string][] => {
1307
+ const own = rawOf(names.muted, m);
1308
+ return own
1309
+ ? surfaces(m, f.id).map(([n, bg]) => [
1310
+ `your exact ${names.muted} over ${n}`,
1311
+ hex(
1312
+ compositeOver(
1313
+ parseColor(own) as ColorTriple,
1314
+ alphaOf(own),
1315
+ parseColor(bg) as ColorTriple,
1316
+ ),
1317
+ ),
1318
+ ])
1319
+ : over(names.muted, muted[m] as StopRef, surfaces(m, f.id));
1320
+ };
1321
+
1322
+ // Accent text and icons are the color given where it reads on what
1323
+ // they sit on (the surfaces and the tint), in each mode its fill is
1324
+ // the exact color; only where it does not do they move, to the nearest
1325
+ // shade that reads, and the check says so.
1326
+ const text = each(m => {
1327
+ const grounds = [...surfaces(m, f.id), ...mutedSeen(m)];
1328
+ // The fill the theme really shows in this mode: an exact token
1329
+ // setting of it, else the setting's own color at its shade. The text
1330
+ // starts from that color's nearest shade.
1331
+ const shown = exactFill[m] ? solid(exactFill[m], m, f.id) : null;
1332
+ const start = shown
1333
+ ? stops.reduce((x, y) =>
1334
+ perceptualDelta(ref(f.id, m, y).color, shown) <
1335
+ perceptualDelta(ref(f.id, m, x).color, shown)
1336
+ ? y
1337
+ : x,
1338
+ )
1339
+ : S;
1340
+ const own = shown
1341
+ ? {...ref(f.id, m, start), color: shown}
1342
+ : fill[m]?.exact
1343
+ ? ref(f.id, m, S)
1344
+ : null;
1345
+ if (own) {
1346
+ const r = Math.min(...grounds.map(([, bg]) => contrast(own.color, bg)));
1347
+ if (r >= TEXT && !shown) {
1348
+ if (reports(names.text)) {
1349
+ checks.push({
1350
+ token: names.text,
1351
+ mode: m,
1352
+ stop: S,
1353
+ preferred: S,
1354
+ against: grounds.map(([n]) => n).join(', '),
1355
+ ratio: round(r),
1356
+ needs: TEXT,
1357
+ pass: true,
1358
+ });
1359
+ }
1360
+ return own;
1361
+ }
1362
+ const before = checks.length;
1363
+ const moved = pick(names.text, f.id, m, start, grounds, TEXT);
1364
+ if (r >= TEXT) {
1365
+ return moved;
1366
+ }
1367
+ const last = checks.length > before ? checks[checks.length - 1] : null;
1368
+ if (last && (moved.stop !== start || shown)) {
1369
+ last.note = `${names.text} ${m}: your exact color (${own.color}) reads at only ${grounds
1370
+ .map(([n, bg]): [string, number] => [n, contrast(own.color, bg)])
1371
+ .filter(([, x]) => x < TEXT)
1372
+ .map(([n, x]) => `${round(x)}:1 on ${n}`)
1373
+ .join(
1374
+ ', ',
1375
+ )} (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`;
1376
+ }
1377
+ return moved;
1378
+ }
1379
+ return pick(names.text, f.id, m, at(TEXT_STOP[side(m)]), grounds, TEXT);
1380
+ });
1381
+ put(names.text, f.id, text);
1382
+ put(names.icon, f.id, text);
1383
+ if (names.onMuted) {
1384
+ const onMuted = names.onMuted;
1385
+ put(
1386
+ onMuted,
1387
+ f.id,
1388
+ each(m =>
1389
+ pick(onMuted, f.id, m, at(ON_MUTED[side(m)]), mutedSeen(m), TEXT),
1390
+ ),
1391
+ );
1392
+ }
1393
+ if (names.border) {
1394
+ put(
1395
+ names.border,
1396
+ f.id,
1397
+ each(m => ref(f.id, m, at(BORDER[side(m)]))),
1398
+ );
1399
+ }
1400
+ // The focus ring follows the fill; with an exact fill it keeps
1401
+ // following that (Core's ring reads --color-accent).
1402
+ if (names.focus && !Object.keys(exactFill).length) {
1403
+ const focus = names.focus;
1404
+ put(
1405
+ focus,
1406
+ f.id,
1407
+ each(m =>
1408
+ pick(
1409
+ focus,
1410
+ f.id,
1411
+ m,
1412
+ (fill[m] as StopRef).stop,
1413
+ surfaces(m, f.id),
1414
+ NON_TEXT,
1415
+ ),
1416
+ ),
1417
+ );
1418
+ }
1419
+ }
1420
+
1421
+ // Secondary text on the parts the official Neutral theme lifts it on
1422
+ // (LIFT_PARTS), lifted the same way: for each background (the accent
1423
+ // tint, the neutral track), the gray shade nearest the secondary text's
1424
+ // own that reads at 4.5:1 on it and on it under a hover, over every
1425
+ // surface. The grays are the neutral color's, else a gray ramp grown
1426
+ // from the base theme's own secondary text. A mode where the theme sets
1427
+ // secondary text exactly takes that value instead, as written.
1428
+ let lift: PaletteMapping['lift'] = null;
1429
+ {
1430
+ const valueOf = (m: PaletteMode, token: string): string | null => {
1431
+ const v =
1432
+ rawOf(token, m) ?? tokens[token]?.[m].color ?? base?.[m]?.[token];
1433
+ return v && parseColor(v) ? v : null;
1434
+ };
1435
+ /** The secondary text a mode starts from. */
1436
+ const startText = (m: PaletteMode): string | null => {
1437
+ const v =
1438
+ tokens['--color-text-secondary']?.[m].color ??
1439
+ base?.[m]?.['--color-text-secondary'];
1440
+ const rgb = v ? parseColor(v) : null;
1441
+ return rgb ? hex(rgb) : null;
1442
+ };
1443
+ /** The gray ramp of a mode, and whether its shades are the palette's neutral ones. */
1444
+ const grays = (
1445
+ m: PaletteMode,
1446
+ ): {ramp: Record<string, string>; palette: boolean} | null => {
1447
+ if (neutral) {
1448
+ return {
1449
+ ramp: rampOf(candidate, 'neutral', m),
1450
+ palette: true,
1451
+ };
1452
+ }
1453
+ const seed = startText(m);
1454
+ const ramp = seed ? grownGrays(seed, m) : null;
1455
+ return ramp ? {ramp, palette: false} : null;
1456
+ };
1457
+ /** A color drawn over each of `under`, as the eye sees it. */
1458
+ const drawn = (
1459
+ name: string,
1460
+ color: string,
1461
+ under: [string, string][],
1462
+ ): [string, string][] => {
1463
+ const top = parseColor(color) as ColorTriple;
1464
+ const a = alphaOf(color);
1465
+ return under.map(([n, c]) => [
1466
+ `${name} over ${n}`,
1467
+ hex(compositeOver(top, a, parseColor(c) as ColorTriple)),
1468
+ ]);
1469
+ };
1470
+ const found: Record<string, Partial<Record<PaletteMode, StopRef>>> = {};
1471
+ for (const ground of new Set(LIFT_PARTS.map(([, , g]) => g))) {
1472
+ const {what, parts} = LIFT_GROUNDS[ground];
1473
+ /**
1474
+ * The shade the base theme itself lifts this ground's text to in a
1475
+ * mode, when it gives one: the search starts there, so a change of
1476
+ * color moves it only when that shade no longer reads.
1477
+ */
1478
+ const baseLift = (m: PaletteMode): string | null => {
1479
+ for (const [part, block, g] of LIFT_PARTS) {
1480
+ if (g !== ground) {
1481
+ continue;
1482
+ }
1483
+ const v = partStyle(base?.components, part, block)?.[
1484
+ '--color-text-secondary'
1485
+ ];
1486
+ const pair = sides(v);
1487
+ const c = pair?.[m === 'light' ? 0 : 1]?.trim();
1488
+ const rgb = c ? parseColor(c) : null;
1489
+ if (rgb) {
1490
+ return hex(rgb);
1491
+ }
1492
+ }
1493
+ return null;
1494
+ };
1495
+ const byMode: Partial<Record<PaletteMode, StopRef>> = {};
1496
+ for (const m of modes) {
1497
+ const own = rawOf('--color-text-secondary', m);
1498
+ const literal = (): void => {
1499
+ byMode[m] = {stop: 0, color: own as string, family: 'literal'};
1500
+ };
1501
+ const fillColor = valueOf(m, ground);
1502
+ const g = grays(m);
1503
+ const textColor = startText(m);
1504
+ if (!fillColor || !g || !textColor) {
1505
+ if (own) {
1506
+ literal();
1507
+ continue;
1508
+ }
1509
+ break;
1510
+ }
1511
+ const seen = drawn(what, fillColor, surfaces(m, 'neutral'));
1512
+ const hover = valueOf(m, '--color-overlay-hover');
1513
+ const on: [string, string][] = [
1514
+ ...seen,
1515
+ ...(hover && alphaOf(hover) > 0
1516
+ ? drawn('a hover', hover, seen).map(([n, c]): [string, string] => [
1517
+ n.replace(/^a hover over (.*)$/, '$1 under a hover'),
1518
+ c,
1519
+ ])
1520
+ : []),
1521
+ ];
1522
+ const keys = Object.keys(g.ramp)
1523
+ .map(Number)
1524
+ .sort((a, b) => a - b);
1525
+ if (
1526
+ own &&
1527
+ parseColor(own) &&
1528
+ Math.min(...on.map(([, bg]) => contrast(own, bg))) >= TEXT
1529
+ ) {
1530
+ literal();
1531
+ continue;
1532
+ }
1533
+ const ownRgb = own ? parseColor(own) : null;
1534
+ const from = (ownRgb ? hex(ownRgb) : null) ?? baseLift(m) ?? textColor;
1535
+ const start = keys.reduce((x, y) =>
1536
+ perceptualDelta(g.ramp[y], from) < perceptualDelta(g.ramp[x], from)
1537
+ ? y
1538
+ : x,
1539
+ );
1540
+ const scored = keys
1541
+ .sort(
1542
+ (a, b) =>
1543
+ Math.abs(a - start) - Math.abs(b - start) ||
1544
+ (Math.sign(b - a) === TOWARD_CONTRAST[m] ? 1 : -1),
1545
+ )
1546
+ .map(stop => ({
1547
+ stop,
1548
+ r: Math.min(...on.map(([, bg]) => contrast(g.ramp[stop], bg))),
1549
+ }));
1550
+ const b =
1551
+ scored.find(x => x.r >= TEXT) ??
1552
+ scored.reduce((x, y) => (y.r > x.r ? y : x));
1553
+ byMode[m] = g.palette
1554
+ ? ref('neutral', m, b.stop)
1555
+ : {stop: b.stop, color: g.ramp[b.stop], family: 'literal'};
1556
+ const moved = hex(parseColor(g.ramp[b.stop]) as ColorTriple) !== from;
1557
+ if (b.r < TEXT || moved) {
1558
+ checks.push({
1559
+ token: '--color-text-secondary',
1560
+ mode: m,
1561
+ stop: b.stop,
1562
+ preferred: start,
1563
+ against: `${what} over the surfaces`,
1564
+ ratio: round(b.r),
1565
+ needs: TEXT,
1566
+ pass: b.r >= TEXT,
1567
+ dials: ['accent', 'neutral'],
1568
+ note:
1569
+ b.r >= TEXT
1570
+ ? `--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`
1571
+ : `--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`,
1572
+ });
1573
+ }
1574
+ }
1575
+ if (modes.every(m => byMode[m])) {
1576
+ found[ground] = byMode;
1577
+ }
1578
+ }
1579
+ if (Object.keys(found).length) {
1580
+ lift = found;
1581
+ }
1582
+ }
1583
+
1584
+ return {
1585
+ tokens,
1586
+ contrast: checks.filter(c => c.note !== ''),
1587
+ exact,
1588
+ unread,
1589
+ lift,
1590
+ };
1591
+ }
1592
+
1593
+ /**
1594
+ * A part-style value's light and dark halves: a `[light, dark]` pair, a
1595
+ * `light-dark()` value split at its top-level comma, or one value for
1596
+ * both; null for anything else.
1597
+ */
1598
+ function sides(v: unknown): string[] | null {
1599
+ if (Array.isArray(v)) {
1600
+ return v as string[];
1601
+ }
1602
+ if (typeof v !== 'string') {
1603
+ return null;
1604
+ }
1605
+ const inner = /^light-dark\((.*)\)$/s.exec(v.trim())?.[1];
1606
+ return inner ? splitTopComma(inner) : [v, v];
1607
+ }
1608
+
1609
+ /** Splits a CSS value at its top-level commas (outside brackets). */
1610
+ export function splitTopComma(value: string): string[] {
1611
+ const out: string[] = [];
1612
+ let depth = 0;
1613
+ let cur = '';
1614
+ for (const c of value) {
1615
+ if (c === '(') {
1616
+ depth++;
1617
+ }
1618
+ if (c === ')') {
1619
+ depth--;
1620
+ }
1621
+ if (depth === 0 && c === ',') {
1622
+ out.push(cur);
1623
+ cur = '';
1624
+ } else {
1625
+ cur += c;
1626
+ }
1627
+ }
1628
+ out.push(cur);
1629
+ return out;
1630
+ }