@qoretechnologies/reqore 0.78.6-pr.715.gdfefa70 → 0.78.7-pr.717.gae33bdc

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 (366) hide show
  1. package/.claude/CLAUDE.md +14 -0
  2. package/dist/components/Accordion/index.d.ts.map +1 -1
  3. package/dist/components/Accordion/index.js +73 -23
  4. package/dist/components/Accordion/index.js.map +1 -1
  5. package/dist/components/Breadcrumbs/index.d.ts.map +1 -1
  6. package/dist/components/Breadcrumbs/index.js +344 -44
  7. package/dist/components/Breadcrumbs/index.js.map +1 -1
  8. package/dist/components/Breadcrumbs/item.d.ts.map +1 -1
  9. package/dist/components/Breadcrumbs/item.js +6 -2
  10. package/dist/components/Breadcrumbs/item.js.map +1 -1
  11. package/dist/components/Bubble/index.d.ts.map +1 -1
  12. package/dist/components/Bubble/index.js +20 -43
  13. package/dist/components/Bubble/index.js.map +1 -1
  14. package/dist/components/Button/index.d.ts +75 -0
  15. package/dist/components/Button/index.d.ts.map +1 -1
  16. package/dist/components/Button/index.js +324 -110
  17. package/dist/components/Button/index.js.map +1 -1
  18. package/dist/components/ButtonRail/index.d.ts.map +1 -1
  19. package/dist/components/ButtonRail/index.js +3 -2
  20. package/dist/components/ButtonRail/index.js.map +1 -1
  21. package/dist/components/Callout/index.d.ts +4 -3
  22. package/dist/components/Callout/index.d.ts.map +1 -1
  23. package/dist/components/Callout/index.js +78 -27
  24. package/dist/components/Callout/index.js.map +1 -1
  25. package/dist/components/Checkbox/index.d.ts.map +1 -1
  26. package/dist/components/Checkbox/index.js +120 -44
  27. package/dist/components/Checkbox/index.js.map +1 -1
  28. package/dist/components/Collapse/index.d.ts.map +1 -1
  29. package/dist/components/Collapse/index.js +7 -36
  30. package/dist/components/Collapse/index.js.map +1 -1
  31. package/dist/components/CollapsibleContent/index.d.ts.map +1 -1
  32. package/dist/components/CollapsibleContent/index.js +11 -39
  33. package/dist/components/CollapsibleContent/index.js.map +1 -1
  34. package/dist/components/Collection/index.js +3 -3
  35. package/dist/components/Collection/index.js.map +1 -1
  36. package/dist/components/Collection/item.d.ts.map +1 -1
  37. package/dist/components/Collection/item.js +4 -4
  38. package/dist/components/Collection/item.js.map +1 -1
  39. package/dist/components/Columns/column.d.ts.map +1 -1
  40. package/dist/components/Columns/column.js +6 -35
  41. package/dist/components/Columns/column.js.map +1 -1
  42. package/dist/components/Columns/index.d.ts.map +1 -1
  43. package/dist/components/Columns/index.js +3 -35
  44. package/dist/components/Columns/index.js.map +1 -1
  45. package/dist/components/Comment/index.js +8 -8
  46. package/dist/components/Comment/index.js.map +1 -1
  47. package/dist/components/CommentFeed/index.js +2 -2
  48. package/dist/components/CommentFeed/index.js.map +1 -1
  49. package/dist/components/Content/index.d.ts.map +1 -1
  50. package/dist/components/Content/index.js +3 -35
  51. package/dist/components/Content/index.js.map +1 -1
  52. package/dist/components/Content/wrapper.js +2 -2
  53. package/dist/components/Content/wrapper.js.map +1 -1
  54. package/dist/components/ControlGroup/index.d.ts.map +1 -1
  55. package/dist/components/ControlGroup/index.js +52 -19
  56. package/dist/components/ControlGroup/index.js.map +1 -1
  57. package/dist/components/ControlGroup/item.d.ts.map +1 -1
  58. package/dist/components/ControlGroup/item.js +35 -6
  59. package/dist/components/ControlGroup/item.js.map +1 -1
  60. package/dist/components/DataView/index.d.ts.map +1 -1
  61. package/dist/components/DataView/index.js +35 -65
  62. package/dist/components/DataView/index.js.map +1 -1
  63. package/dist/components/DatePicker/index.d.ts.map +1 -1
  64. package/dist/components/DatePicker/index.js +40 -8
  65. package/dist/components/DatePicker/index.js.map +1 -1
  66. package/dist/components/DescriptionList/index.d.ts.map +1 -1
  67. package/dist/components/DescriptionList/index.js +36 -42
  68. package/dist/components/DescriptionList/index.js.map +1 -1
  69. package/dist/components/Drawer/backdrop.d.ts.map +1 -1
  70. package/dist/components/Drawer/backdrop.js +35 -6
  71. package/dist/components/Drawer/backdrop.js.map +1 -1
  72. package/dist/components/Drawer/index.d.ts.map +1 -1
  73. package/dist/components/Drawer/index.js +77 -66
  74. package/dist/components/Drawer/index.js.map +1 -1
  75. package/dist/components/Dropdown/index.d.ts.map +1 -1
  76. package/dist/components/Dropdown/index.js +3 -1
  77. package/dist/components/Dropdown/index.js.map +1 -1
  78. package/dist/components/Dropdown/list.d.ts.map +1 -1
  79. package/dist/components/Dropdown/list.js +90 -19
  80. package/dist/components/Dropdown/list.js.map +1 -1
  81. package/dist/components/Effect/index.d.ts +37 -6
  82. package/dist/components/Effect/index.d.ts.map +1 -1
  83. package/dist/components/Effect/index.js +216 -49
  84. package/dist/components/Effect/index.js.map +1 -1
  85. package/dist/components/EntityRow/index.d.ts +19 -1
  86. package/dist/components/EntityRow/index.d.ts.map +1 -1
  87. package/dist/components/EntityRow/index.js +139 -44
  88. package/dist/components/EntityRow/index.js.map +1 -1
  89. package/dist/components/FadeScroller/index.d.ts.map +1 -1
  90. package/dist/components/FadeScroller/index.js +14 -64
  91. package/dist/components/FadeScroller/index.js.map +1 -1
  92. package/dist/components/FeatureCard/index.d.ts +7 -1
  93. package/dist/components/FeatureCard/index.d.ts.map +1 -1
  94. package/dist/components/FeatureCard/index.js +82 -27
  95. package/dist/components/FeatureCard/index.js.map +1 -1
  96. package/dist/components/Header/index.d.ts.map +1 -1
  97. package/dist/components/Header/index.js +8 -5
  98. package/dist/components/Header/index.js.map +1 -1
  99. package/dist/components/Icon/index.d.ts.map +1 -1
  100. package/dist/components/Icon/index.js +39 -19
  101. package/dist/components/Icon/index.js.map +1 -1
  102. package/dist/components/IconPicker/index.js +2 -2
  103. package/dist/components/IconPicker/index.js.map +1 -1
  104. package/dist/components/Input/index.d.ts +44 -1
  105. package/dist/components/Input/index.d.ts.map +1 -1
  106. package/dist/components/Input/index.js +96 -30
  107. package/dist/components/Input/index.js.map +1 -1
  108. package/dist/components/InputClearButton/index.d.ts +7 -2
  109. package/dist/components/InputClearButton/index.d.ts.map +1 -1
  110. package/dist/components/InputClearButton/index.js +47 -8
  111. package/dist/components/InputClearButton/index.js.map +1 -1
  112. package/dist/components/InternalPopover/index.d.ts.map +1 -1
  113. package/dist/components/InternalPopover/index.js +56 -19
  114. package/dist/components/InternalPopover/index.js.map +1 -1
  115. package/dist/components/KeyboardShortcut/index.js +3 -3
  116. package/dist/components/KeyboardShortcut/index.js.map +1 -1
  117. package/dist/components/Layout/content.js +2 -2
  118. package/dist/components/Layout/content.js.map +1 -1
  119. package/dist/components/Layout/index.d.ts.map +1 -1
  120. package/dist/components/Layout/index.js +3 -35
  121. package/dist/components/Layout/index.js.map +1 -1
  122. package/dist/components/Link/index.d.ts.map +1 -1
  123. package/dist/components/Link/index.js +12 -39
  124. package/dist/components/Link/index.js.map +1 -1
  125. package/dist/components/Menu/divider.d.ts.map +1 -1
  126. package/dist/components/Menu/divider.js +11 -6
  127. package/dist/components/Menu/divider.js.map +1 -1
  128. package/dist/components/Menu/index.d.ts.map +1 -1
  129. package/dist/components/Menu/index.js +40 -22
  130. package/dist/components/Menu/index.js.map +1 -1
  131. package/dist/components/Menu/item.d.ts.map +1 -1
  132. package/dist/components/Menu/item.js +35 -5
  133. package/dist/components/Menu/item.js.map +1 -1
  134. package/dist/components/Menu/section.d.ts.map +1 -1
  135. package/dist/components/Menu/section.js +11 -6
  136. package/dist/components/Menu/section.js.map +1 -1
  137. package/dist/components/Message/index.d.ts.map +1 -1
  138. package/dist/components/Message/index.js +20 -4
  139. package/dist/components/Message/index.js.map +1 -1
  140. package/dist/components/NavRail/index.d.ts +2 -0
  141. package/dist/components/NavRail/index.d.ts.map +1 -1
  142. package/dist/components/NavRail/index.js +136 -46
  143. package/dist/components/NavRail/index.js.map +1 -1
  144. package/dist/components/Navbar/divider.d.ts.map +1 -1
  145. package/dist/components/Navbar/divider.js +35 -6
  146. package/dist/components/Navbar/divider.js.map +1 -1
  147. package/dist/components/Navbar/group.js +3 -3
  148. package/dist/components/Navbar/group.js.map +1 -1
  149. package/dist/components/Navbar/index.js +3 -3
  150. package/dist/components/Navbar/index.js.map +1 -1
  151. package/dist/components/Navbar/item.js +3 -3
  152. package/dist/components/Navbar/item.js.map +1 -1
  153. package/dist/components/Notifications/index.d.ts.map +1 -1
  154. package/dist/components/Notifications/index.js +6 -35
  155. package/dist/components/Notifications/index.js.map +1 -1
  156. package/dist/components/Notifications/notification.d.ts +6 -2
  157. package/dist/components/Notifications/notification.d.ts.map +1 -1
  158. package/dist/components/Notifications/notification.js +95 -60
  159. package/dist/components/Notifications/notification.js.map +1 -1
  160. package/dist/components/Notifications/styles.d.ts +20 -0
  161. package/dist/components/Notifications/styles.d.ts.map +1 -1
  162. package/dist/components/Notifications/styles.js +45 -17
  163. package/dist/components/Notifications/styles.js.map +1 -1
  164. package/dist/components/Paging/index.d.ts.map +1 -1
  165. package/dist/components/Paging/index.js +19 -19
  166. package/dist/components/Paging/index.js.map +1 -1
  167. package/dist/components/Panel/index.d.ts +15 -0
  168. package/dist/components/Panel/index.d.ts.map +1 -1
  169. package/dist/components/Panel/index.js +513 -202
  170. package/dist/components/Panel/index.js.map +1 -1
  171. package/dist/components/Paragraph/index.d.ts +6 -0
  172. package/dist/components/Paragraph/index.d.ts.map +1 -1
  173. package/dist/components/Paragraph/index.js +65 -13
  174. package/dist/components/Paragraph/index.js.map +1 -1
  175. package/dist/components/Popover/index.d.ts +8 -0
  176. package/dist/components/Popover/index.d.ts.map +1 -1
  177. package/dist/components/Popover/index.js +169 -21
  178. package/dist/components/Popover/index.js.map +1 -1
  179. package/dist/components/Progress/index.d.ts.map +1 -1
  180. package/dist/components/Progress/index.js +11 -43
  181. package/dist/components/Progress/index.js.map +1 -1
  182. package/dist/components/Rating/index.d.ts.map +1 -1
  183. package/dist/components/Rating/index.js +33 -47
  184. package/dist/components/Rating/index.js.map +1 -1
  185. package/dist/components/RichTextEditor/index.d.ts.map +1 -1
  186. package/dist/components/RichTextEditor/index.js +130 -52
  187. package/dist/components/RichTextEditor/index.js.map +1 -1
  188. package/dist/components/RowActionsMenu/index.d.ts +80 -0
  189. package/dist/components/RowActionsMenu/index.d.ts.map +1 -0
  190. package/dist/components/RowActionsMenu/index.js +182 -0
  191. package/dist/components/RowActionsMenu/index.js.map +1 -0
  192. package/dist/components/SegmentedControl/index.d.ts.map +1 -1
  193. package/dist/components/SegmentedControl/index.js +92 -77
  194. package/dist/components/SegmentedControl/index.js.map +1 -1
  195. package/dist/components/Select/valuePreview.js +2 -2
  196. package/dist/components/Select/valuePreview.js.map +1 -1
  197. package/dist/components/SeverityRow/index.d.ts +20 -1
  198. package/dist/components/SeverityRow/index.d.ts.map +1 -1
  199. package/dist/components/SeverityRow/index.js +58 -15
  200. package/dist/components/SeverityRow/index.js.map +1 -1
  201. package/dist/components/Skeleton/index.d.ts.map +1 -1
  202. package/dist/components/Skeleton/index.js +6 -35
  203. package/dist/components/Skeleton/index.js.map +1 -1
  204. package/dist/components/Slider/index.js +9 -9
  205. package/dist/components/Slider/index.js.map +1 -1
  206. package/dist/components/Spacer/index.js +7 -7
  207. package/dist/components/Spacer/index.js.map +1 -1
  208. package/dist/components/Span/index.d.ts.map +1 -1
  209. package/dist/components/Span/index.js +43 -11
  210. package/dist/components/Span/index.js.map +1 -1
  211. package/dist/components/StackedBar/index.d.ts.map +1 -1
  212. package/dist/components/StackedBar/index.js +48 -47
  213. package/dist/components/StackedBar/index.js.map +1 -1
  214. package/dist/components/Statistic/index.d.ts +0 -8
  215. package/dist/components/Statistic/index.d.ts.map +1 -1
  216. package/dist/components/Statistic/index.js +44 -45
  217. package/dist/components/Statistic/index.js.map +1 -1
  218. package/dist/components/Table/body.d.ts.map +1 -1
  219. package/dist/components/Table/body.js +12 -44
  220. package/dist/components/Table/body.js.map +1 -1
  221. package/dist/components/Table/cell.d.ts.map +1 -1
  222. package/dist/components/Table/cell.js +76 -52
  223. package/dist/components/Table/cell.js.map +1 -1
  224. package/dist/components/Table/header.d.ts.map +1 -1
  225. package/dist/components/Table/header.js +15 -12
  226. package/dist/components/Table/header.js.map +1 -1
  227. package/dist/components/Table/headerCell.d.ts.map +1 -1
  228. package/dist/components/Table/headerCell.js +8 -38
  229. package/dist/components/Table/headerCell.js.map +1 -1
  230. package/dist/components/Table/helpers.d.ts +20 -0
  231. package/dist/components/Table/helpers.d.ts.map +1 -1
  232. package/dist/components/Table/helpers.js +52 -1
  233. package/dist/components/Table/helpers.js.map +1 -1
  234. package/dist/components/Table/index.d.ts +57 -2
  235. package/dist/components/Table/index.d.ts.map +1 -1
  236. package/dist/components/Table/index.js +154 -59
  237. package/dist/components/Table/index.js.map +1 -1
  238. package/dist/components/Table/row.d.ts +3 -1
  239. package/dist/components/Table/row.d.ts.map +1 -1
  240. package/dist/components/Table/row.js +44 -13
  241. package/dist/components/Table/row.js.map +1 -1
  242. package/dist/components/Table/scrollbar.js +3 -3
  243. package/dist/components/Table/scrollbar.js.map +1 -1
  244. package/dist/components/Tabs/content.js +2 -2
  245. package/dist/components/Tabs/content.js.map +1 -1
  246. package/dist/components/Tabs/index.js +3 -3
  247. package/dist/components/Tabs/index.js.map +1 -1
  248. package/dist/components/Tabs/item.d.ts.map +1 -1
  249. package/dist/components/Tabs/item.js +8 -6
  250. package/dist/components/Tabs/item.js.map +1 -1
  251. package/dist/components/Tabs/list.d.ts.map +1 -1
  252. package/dist/components/Tabs/list.js +6 -4
  253. package/dist/components/Tabs/list.js.map +1 -1
  254. package/dist/components/Tag/group.d.ts.map +1 -1
  255. package/dist/components/Tag/group.js +3 -35
  256. package/dist/components/Tag/group.js.map +1 -1
  257. package/dist/components/Tag/index.d.ts +77 -3
  258. package/dist/components/Tag/index.d.ts.map +1 -1
  259. package/dist/components/Tag/index.js +315 -83
  260. package/dist/components/Tag/index.js.map +1 -1
  261. package/dist/components/Testimonial/index.d.ts +6 -1
  262. package/dist/components/Testimonial/index.d.ts.map +1 -1
  263. package/dist/components/Testimonial/index.js +59 -23
  264. package/dist/components/Testimonial/index.js.map +1 -1
  265. package/dist/components/Textarea/index.d.ts +16 -0
  266. package/dist/components/Textarea/index.d.ts.map +1 -1
  267. package/dist/components/Textarea/index.js +178 -33
  268. package/dist/components/Textarea/index.js.map +1 -1
  269. package/dist/components/Tier/group.d.ts.map +1 -1
  270. package/dist/components/Tier/group.js +9 -8
  271. package/dist/components/Tier/group.js.map +1 -1
  272. package/dist/components/Tier/index.d.ts +5 -0
  273. package/dist/components/Tier/index.d.ts.map +1 -1
  274. package/dist/components/Tier/index.js +14 -10
  275. package/dist/components/Tier/index.js.map +1 -1
  276. package/dist/components/Timeline/index.d.ts +2 -0
  277. package/dist/components/Timeline/index.d.ts.map +1 -1
  278. package/dist/components/Timeline/index.js +73 -28
  279. package/dist/components/Timeline/index.js.map +1 -1
  280. package/dist/components/TooltipComponent/index.d.ts.map +1 -1
  281. package/dist/components/TooltipComponent/index.js +6 -7
  282. package/dist/components/TooltipComponent/index.js.map +1 -1
  283. package/dist/components/Tree/index.d.ts.map +1 -1
  284. package/dist/components/Tree/index.js +27 -23
  285. package/dist/components/Tree/index.js.map +1 -1
  286. package/dist/components/Tree/modal.d.ts.map +1 -1
  287. package/dist/components/Tree/modal.js +3 -1
  288. package/dist/components/Tree/modal.js.map +1 -1
  289. package/dist/constants/sizes.d.ts +5 -0
  290. package/dist/constants/sizes.d.ts.map +1 -1
  291. package/dist/constants/sizes.js +6 -1
  292. package/dist/constants/sizes.js.map +1 -1
  293. package/dist/constants/theme.d.ts +0 -21
  294. package/dist/constants/theme.d.ts.map +1 -1
  295. package/dist/constants/theme.js.map +1 -1
  296. package/dist/containers/ReqoreProvider.d.ts.map +1 -1
  297. package/dist/containers/ReqoreProvider.js +27 -13
  298. package/dist/containers/ReqoreProvider.js.map +1 -1
  299. package/dist/containers/UIProvider.d.ts +10 -0
  300. package/dist/containers/UIProvider.d.ts.map +1 -1
  301. package/dist/containers/UIProvider.js +34 -36
  302. package/dist/containers/UIProvider.js.map +1 -1
  303. package/dist/context/SurfaceContext.d.ts +18 -0
  304. package/dist/context/SurfaceContext.d.ts.map +1 -0
  305. package/dist/context/SurfaceContext.js +39 -0
  306. package/dist/context/SurfaceContext.js.map +1 -0
  307. package/dist/helpers/colors.d.ts +183 -11
  308. package/dist/helpers/colors.d.ts.map +1 -1
  309. package/dist/helpers/colors.js +736 -100
  310. package/dist/helpers/colors.js.map +1 -1
  311. package/dist/helpers/hoveringPointer.d.ts +54 -0
  312. package/dist/helpers/hoveringPointer.d.ts.map +1 -0
  313. package/dist/helpers/hoveringPointer.js +66 -0
  314. package/dist/helpers/hoveringPointer.js.map +1 -0
  315. package/dist/helpers/iconProps.d.ts +14 -0
  316. package/dist/helpers/iconProps.d.ts.map +1 -0
  317. package/dist/helpers/iconProps.js +33 -0
  318. package/dist/helpers/iconProps.js.map +1 -0
  319. package/dist/helpers/styled.d.ts +39 -26
  320. package/dist/helpers/styled.d.ts.map +1 -1
  321. package/dist/helpers/styled.js +156 -4
  322. package/dist/helpers/styled.js.map +1 -1
  323. package/dist/helpers/surface.d.ts +31 -0
  324. package/dist/helpers/surface.d.ts.map +1 -0
  325. package/dist/helpers/surface.js +87 -0
  326. package/dist/helpers/surface.js.map +1 -0
  327. package/dist/hooks/useAutoFocus.d.ts.map +1 -1
  328. package/dist/hooks/useAutoFocus.js +11 -1
  329. package/dist/hooks/useAutoFocus.js.map +1 -1
  330. package/dist/hooks/useCloneThroughFragments.d.ts.map +1 -1
  331. package/dist/hooks/useCloneThroughFragments.js +51 -18
  332. package/dist/hooks/useCloneThroughFragments.js.map +1 -1
  333. package/dist/hooks/useCombinedRefs.d.ts +16 -6
  334. package/dist/hooks/useCombinedRefs.d.ts.map +1 -1
  335. package/dist/hooks/useCombinedRefs.js +34 -27
  336. package/dist/hooks/useCombinedRefs.js.map +1 -1
  337. package/dist/hooks/useDragToScroll.d.ts +58 -0
  338. package/dist/hooks/useDragToScroll.d.ts.map +1 -0
  339. package/dist/hooks/useDragToScroll.js +262 -0
  340. package/dist/hooks/useDragToScroll.js.map +1 -0
  341. package/dist/hooks/useDrawnSurface.d.ts +38 -0
  342. package/dist/hooks/useDrawnSurface.d.ts.map +1 -0
  343. package/dist/hooks/useDrawnSurface.js +48 -0
  344. package/dist/hooks/useDrawnSurface.js.map +1 -0
  345. package/dist/hooks/useMarqueeOnHover.d.ts.map +1 -1
  346. package/dist/hooks/useMarqueeOnHover.js +10 -0
  347. package/dist/hooks/useMarqueeOnHover.js.map +1 -1
  348. package/dist/hooks/usePaging.d.ts +9 -4
  349. package/dist/hooks/usePaging.d.ts.map +1 -1
  350. package/dist/hooks/usePaging.js +21 -32
  351. package/dist/hooks/usePaging.js.map +1 -1
  352. package/dist/hooks/usePointerDrag.d.ts.map +1 -1
  353. package/dist/hooks/usePointerDrag.js +13 -3
  354. package/dist/hooks/usePointerDrag.js.map +1 -1
  355. package/dist/hooks/useReqoreMedia.d.ts +22 -7
  356. package/dist/hooks/useReqoreMedia.d.ts.map +1 -1
  357. package/dist/hooks/useReqoreMedia.js +33 -9
  358. package/dist/hooks/useReqoreMedia.js.map +1 -1
  359. package/dist/index.d.ts +6 -0
  360. package/dist/index.d.ts.map +1 -1
  361. package/dist/index.js +11 -3
  362. package/dist/index.js.map +1 -1
  363. package/dist/styles.js +6 -6
  364. package/dist/styles.js.map +1 -1
  365. package/package.json +3 -4
  366. package/vitest.config.ts +115 -31
@@ -1,10 +1,84 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
2
22
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGradientMix = exports.getNthGradientColor = exports.buildGradientColorsFromString = exports.createEffectGradient = exports.getColorFromMaybeString = exports.getPanelHairlineColor = exports.getPanelBackgroundColor = exports.getThemePanelSurface = exports.getMainBackgroundColor = exports.getNotificationIntent = exports.mergeThemes = exports.buildTheme = exports.isValidSixCharHex = exports.getColorByBgColor = exports.getReadableAccentColor = exports.getOpaqueColor = exports.changeDarkness = exports.changeLightness = exports.getMainColor = exports.shouldDarken = exports.RGBAToHexA = exports.hexAToRGBA = exports.getRGBAFromHex = exports.percentToHexAlpha = exports.isAchromatic = exports.getReadableColorFrom = exports.getReadableColor = void 0;
23
+ exports.getGradientColorList = exports.getGradientMix = exports.getNthGradientColor = exports.buildGradientColorsFromString = exports.createEffectGradient = exports.getColorFromMaybeString = exports.getMainBackgroundColor = exports.getNotificationIntent = exports.mergeThemes = exports.buildTheme = exports.isValidSixCharHex = exports.getColorByBgColor = exports.getReadableThemeColor = exports.getReadableTextColor = exports.getReadableIntentColor = exports.getThemeSurfaces = exports.getThemeSurface = exports.getReadableIconLook = exports.getReadableAccentColorOn = exports.getReadableAccentColor = exports.getOpaqueColor = exports.changeDarkness = exports.changeLightness = exports.getMainColor = exports.shouldDarken = exports.RGBAToHexA = exports.hexAToRGBA = exports.getRGBAFromHex = exports.percentToHexAlpha = exports.isAchromatic = exports.getReadableColorFrom = exports.getReadableTextOn = exports.getReadableFadedColor = exports.getReadableGroupOpacity = exports.getReadableAlpha = exports.getReadableColorOn = exports.getContrastRatio = exports.fadeColor = exports.getDrawnColor = exports.getSaturatedTint = exports.getColorAtAlpha = exports.isReadableColor = exports.LARGE_BOLD_TEXT_PX = exports.READABLE_ICON_CONTRAST = exports.READABLE_TEXT_CONTRAST = exports.getReadableColor = exports.getThemeColorKey = exports.cacheKey = exports.createColorCache = void 0;
4
24
  var lodash_1 = require("lodash");
5
25
  var polished_1 = require("polished");
6
26
  var colors_1 = require("../constants/colors");
7
27
  var theme_1 = require("../constants/theme");
28
+ /**
29
+ * How many results each cached helper keeps. The color maths runs while components render - a button works out its
30
+ * text, its hover and its icons from what it is drawn on, a gradient each of its colors - and a page draws the same
31
+ * few colors over and over (a table of 500 buttons in one theme), so each helper remembers its last results. A
32
+ * page that keeps meeting new colors only ever holds this many: the one used least recently goes first.
33
+ */
34
+ var COLOR_CACHE_SIZE = 2000;
35
+ /**
36
+ * A helper's memory of its results (see `COLOR_CACHE_SIZE`): `remember(key, compute)`. Also for a component's
37
+ * color work that is a function of its key alone (an effect's gradient pass): not part of the package's API.
38
+ */
39
+ var createColorCache = function () {
40
+ var results = new Map();
41
+ return function (key, compute) {
42
+ if (results.has(key)) {
43
+ var result_1 = results.get(key);
44
+ // the most recently used goes to the end, so the oldest is the first one out
45
+ results.delete(key);
46
+ results.set(key, result_1);
47
+ return result_1;
48
+ }
49
+ var result = compute();
50
+ results.set(key, result);
51
+ if (results.size > COLOR_CACHE_SIZE) {
52
+ results.delete(results.keys().next().value);
53
+ }
54
+ return result;
55
+ };
56
+ };
57
+ exports.createColorCache = createColorCache;
58
+ /** One key for any list of a helper's arguments (colors, numbers, flags, lists of colors). */
59
+ var cacheKey = function () {
60
+ var parts = [];
61
+ for (var _i = 0; _i < arguments.length; _i++) {
62
+ parts[_i] = arguments[_i];
63
+ }
64
+ return parts.map(function (part) { return (Array.isArray(part) ? part.join(',') : String(part)); }).join('|');
65
+ };
66
+ exports.cacheKey = cacheKey;
67
+ var intentKeys = new WeakMap();
68
+ /**
69
+ * What of a theme the helpers that take one read: its main, the main it was made from, and its intents. The
70
+ * intents are written out once per intents object.
71
+ */
72
+ var getThemeColorKey = function (theme) {
73
+ var intents = theme.intents;
74
+ var key = intents ? intentKeys.get(intents) : '';
75
+ if (key === undefined) {
76
+ key = JSON.stringify(intents);
77
+ intentKeys.set(intents, key);
78
+ }
79
+ return "".concat(theme.main, "|").concat(theme.originalMain, "|").concat(key);
80
+ };
81
+ exports.getThemeColorKey = getThemeColorKey;
8
82
  var getReadableColor = function (theme, ifLight, ifDark, dimmed, fallback) {
9
83
  var _a, _b;
10
84
  if ((_a = theme.text) === null || _a === void 0 ? void 0 : _a.color) {
@@ -16,16 +90,338 @@ var getReadableColor = function (theme, ifLight, ifDark, dimmed, fallback) {
16
90
  }
17
91
  var shouldDim = ((_b = theme.text) === null || _b === void 0 ? void 0 : _b.dim) && dimmed;
18
92
  var from = fallback || theme.main;
19
- return (0, exports.getReadableColorFrom)(from, shouldDim, ifLight, ifDark);
93
+ // a translucent color (a theme made from the muted intent, say) is drawn over the theme it was made from
94
+ return (0, exports.getReadableColorFrom)(from, shouldDim, ifLight, ifDark, theme.originalMain);
20
95
  };
21
96
  exports.getReadableColor = getReadableColor;
22
- var getReadableColorFrom = function (from, dim, ifLight, ifDark) {
23
- var returnIfLight = ifLight || (0, polished_1.lighten)(dim ? 0.05 : 0, colors_1.Colors.DARK);
24
- var returnIfDark = ifDark || (0, polished_1.darken)(dim ? 0.05 : 0, colors_1.Colors.LIGHT);
25
- var fixedColor = (0, exports.hexAToRGBA)(from);
26
- return (0, polished_1.readableColor)(fixedColor, returnIfLight, returnIfDark, false);
97
+ /**
98
+ * How far text has to stand out from what it is drawn on (WCAG 2.1 AA, 1.4.3): 4.5:1.
99
+ */
100
+ exports.READABLE_TEXT_CONTRAST = 4.5;
101
+ /**
102
+ * How far an icon (or any other graphic a control needs to be understood) and large text have to stand out from
103
+ * what they are drawn on (WCAG 2.1 AA, 1.4.11 and 1.4.3): 3:1.
104
+ */
105
+ exports.READABLE_ICON_CONTRAST = 3;
106
+ /** The least size (px) from which bold text is large in WCAG's sense (14pt), and needs to stand out by 3:1 only. */
107
+ exports.LARGE_BOLD_TEXT_PX = 18.66;
108
+ var rememberParts = (0, exports.createColorCache)();
109
+ /**
110
+ * The red, green, blue and alpha of a color - any a browser and polished both read: a hex of 3, 4, 6 or 8 digits,
111
+ * `rgb()`, `rgba()`, `hsl()`, a named color. Undefined for one they do not (a CSS variable, `currentColor`, a
112
+ * typo), which is the caller's to draw as it is: the helpers below leave such a color alone instead of throwing
113
+ * while a component renders. `'transparent'` is black at no alpha: it draws nothing.
114
+ */
115
+ var parseColor = function (color) {
116
+ if (typeof color !== 'string' || !color) {
117
+ return undefined;
118
+ }
119
+ return rememberParts(color, function () {
120
+ var _a;
121
+ if (color === 'transparent') {
122
+ return { red: 0, green: 0, blue: 0, alpha: 0 };
123
+ }
124
+ try {
125
+ var parsed = (0, polished_1.parseToRgb)(color);
126
+ return {
127
+ red: parsed.red,
128
+ green: parsed.green,
129
+ blue: parsed.blue,
130
+ alpha: (_a = parsed.alpha) !== null && _a !== void 0 ? _a : 1,
131
+ };
132
+ }
133
+ catch (_b) {
134
+ return undefined;
135
+ }
136
+ });
137
+ };
138
+ /** Whether the helpers can read `color` (see `parseColor`). */
139
+ var isReadableColor = function (color) { return !!parseColor(color); };
140
+ exports.isReadableColor = isReadableColor;
141
+ /** Whether `color` is a color drawn opaque, which text can be read on. */
142
+ var isOpaque = function (color) { var _a; return ((_a = parseColor(color)) === null || _a === void 0 ? void 0 : _a.alpha) === 1; };
143
+ var toHexColor = function (_a) {
144
+ var red = _a.red, green = _a.green, blue = _a.blue;
145
+ return "#".concat([red, green, blue]
146
+ .map(function (part) {
147
+ return Math.round(Math.min(255, Math.max(0, part)))
148
+ .toString(16)
149
+ .padStart(2, '0');
150
+ })
151
+ .join(''));
152
+ };
153
+ var rememberAlphaColor = (0, exports.createColorCache)();
154
+ /**
155
+ * `color` at `alpha`, as polished's `rgba(color, alpha)` writes it. A color it cannot read (a CSS variable,
156
+ * `currentColor`) is drawn as given, not thrown on: at an alpha below 1, mixed with nothing by the browser
157
+ * (`color-mix(in srgb, var(--brand) 20%, transparent)`), so a wash of it is still a wash and not the solid color
158
+ * the text on it is written in.
159
+ */
160
+ var getColorAtAlpha = function (color, alpha) {
161
+ if (typeof color !== 'string' || !color) {
162
+ return color;
163
+ }
164
+ return rememberAlphaColor((0, exports.cacheKey)(color, alpha), function () {
165
+ if (parseColor(color)) {
166
+ return (0, polished_1.rgba)(color, alpha);
167
+ }
168
+ return alpha >= 1
169
+ ? color
170
+ : "color-mix(in srgb, ".concat(color, " ").concat(Math.round(Math.max(0, alpha) * 1000) / 10, "%, transparent)");
171
+ });
172
+ };
173
+ exports.getColorAtAlpha = getColorAtAlpha;
174
+ var rememberTint = (0, exports.createColorCache)();
175
+ /**
176
+ * `color` tinted toward white by `amount` and fully saturated: the light shade of it an outlined control (a minimal
177
+ * button, a minimal tag) starts its text from, before it is made to read (`getReadableAccentColorOn`). A translucent
178
+ * color is its own hue drawn opaque; one it cannot read is as it is.
179
+ */
180
+ var getSaturatedTint = function (color, amount) {
181
+ var drawn = (0, exports.getDrawnColor)(color);
182
+ if (!isOpaque(drawn)) {
183
+ return drawn;
184
+ }
185
+ return rememberTint((0, exports.cacheKey)(drawn, amount), function () {
186
+ return (0, exports.getOpaqueColor)((0, polished_1.saturate)(1, (0, polished_1.tint)(amount, drawn)));
187
+ });
188
+ };
189
+ exports.getSaturatedTint = getSaturatedTint;
190
+ var rememberDrawn = (0, exports.createColorCache)();
191
+ /**
192
+ * `color` as it is drawn over `under`: a translucent color blended into what is under it, the way the browser
193
+ * draws it, and an opaque one as it is. Without `under` (or over one it cannot read), a translucent color counts as
194
+ * its own hue drawn opaque. An opaque six-digit hex - except for a color that draws nothing there
195
+ * (`'transparent'` with nothing under it) or one it cannot read (a CSS variable), which comes back as it is given.
196
+ */
197
+ var getDrawnColor = function (color, under) {
198
+ return rememberDrawn((0, exports.cacheKey)(color, under), function () {
199
+ var top = parseColor(color);
200
+ if (!top) {
201
+ return color;
202
+ }
203
+ var bottom = top.alpha < 1 && under ? parseColor((0, exports.getDrawnColor)(under)) : undefined;
204
+ if (!bottom || bottom.alpha < 1) {
205
+ // nothing under it that can be read: its own hue, if it draws anything at all
206
+ return top.alpha > 0 ? toHexColor(top) : color;
207
+ }
208
+ var blend = function (above, below) { return above * top.alpha + below * (1 - top.alpha); };
209
+ return toHexColor({
210
+ red: blend(top.red, bottom.red),
211
+ green: blend(top.green, bottom.green),
212
+ blue: blend(top.blue, bottom.blue),
213
+ alpha: 1,
214
+ });
215
+ });
216
+ };
217
+ exports.getDrawnColor = getDrawnColor;
218
+ /**
219
+ * `color` at `opacity` of the alpha it already has: a translucent color (a theme made from the muted intent) drawn
220
+ * at a panel's opacity stays as translucent, and more. `rgba(color, opacity)` replaced its alpha, so a panel in the
221
+ * muted intent's near-white drawn at 19% was drawn near-white and opaque. A color it cannot read is as it is.
222
+ */
223
+ var fadeColor = function (color, opacity) {
224
+ var parts = parseColor(color);
225
+ if (!parts) {
226
+ return color;
227
+ }
228
+ return (0, polished_1.rgba)(parts.red, parts.green, parts.blue, parts.alpha * opacity);
229
+ };
230
+ exports.fadeColor = fadeColor;
231
+ /**
232
+ * The WCAG relative luminance of an opaque color, not rounded: polished's `getLuminance` rounds to three decimals,
233
+ * which moves a ratio near a threshold across it (`#595959` on black is 2.998:1, not 3).
234
+ */
235
+ var getRelativeLuminance = function (_a) {
236
+ var red = _a.red, green = _a.green, blue = _a.blue;
237
+ var linear = function (channel) {
238
+ var value = channel / 255;
239
+ return value <= 0.03928 ? value / 12.92 : Math.pow(((value + 0.055) / 1.055), 2.4);
240
+ };
241
+ return 0.2126 * linear(red) + 0.7152 * linear(green) + 0.0722 * linear(blue);
242
+ };
243
+ var rememberContrast = (0, exports.createColorCache)();
244
+ /**
245
+ * The WCAG contrast ratio of two colors, each drawn opaque: from 1 to 21, not rounded. NaN when either cannot be
246
+ * read or draws nothing (a CSS variable, `'transparent'`): there is no telling how far it stands out.
247
+ */
248
+ var getContrastRatio = function (first, second) {
249
+ return rememberContrast((0, exports.cacheKey)(first, second), function () {
250
+ var one = parseColor((0, exports.getDrawnColor)(first));
251
+ var other = parseColor((0, exports.getDrawnColor)(second));
252
+ if (!one || !other || one.alpha < 1 || other.alpha < 1) {
253
+ return NaN;
254
+ }
255
+ var _a = [getRelativeLuminance(one), getRelativeLuminance(other)].sort(function (a, b) { return b - a; }), lighter = _a[0], darker = _a[1];
256
+ return (lighter + 0.05) / (darker + 0.05);
257
+ });
258
+ };
259
+ exports.getContrastRatio = getContrastRatio;
260
+ /** The worst contrast `color` has with any of `backgrounds`. */
261
+ var getWorstContrast = function (color, backgrounds) {
262
+ return Math.min.apply(Math, backgrounds.map(function (background) { return (0, exports.getContrastRatio)(color, background); }));
263
+ };
264
+ /** Of `colors`, as each is drawn over `under`, those text can be read on: opaque, and colors the helpers read. */
265
+ var getReadableSurfaces = function (colors, under) {
266
+ return colors.map(function (color) { return (0, exports.getDrawnColor)(color, under); }).filter(function (color) { return isOpaque(color); });
267
+ };
268
+ // the theme's text colors, a shade softer (`dim`)
269
+ var DIM_ON_LIGHT = (0, polished_1.lighten)(0.05, colors_1.Colors.DARK);
270
+ var DIM_ON_DARK = (0, polished_1.darken)(0.05, colors_1.Colors.LIGHT);
271
+ var rememberReadableOn = (0, exports.createColorCache)();
272
+ /**
273
+ * The text color that reads on every one of `backgrounds` (each drawn over `under` when it is translucent - the
274
+ * colors of a gradient, or a single surface): of the text colors for a light and for a dark background (`ifLight`,
275
+ * `ifDark`; black and white, a shade softer when `dim`), the one that stands out more. When even that one does not
276
+ * reach 4.5:1, a color the caller gave stays theirs (the better of their pair); the default shades give way to pure
277
+ * black or white, whichever stands out more: a dimmed shade is a nicety, being read is not. A background it cannot
278
+ * read is left out; with none left, the text for a dark background (Reqore's default theme).
279
+ */
280
+ var getReadableColorOn = function (backgrounds, dim, ifLight, ifDark, under) {
281
+ return rememberReadableOn((0, exports.cacheKey)(backgrounds, dim, ifLight, ifDark, under), function () {
282
+ var surfaces = getReadableSurfaces(backgrounds, under);
283
+ var onLight = ifLight || (dim ? DIM_ON_LIGHT : colors_1.Colors.DARK);
284
+ var onDark = ifDark || (dim ? DIM_ON_DARK : colors_1.Colors.LIGHT);
285
+ if (!surfaces.length) {
286
+ return onDark;
287
+ }
288
+ var preferred = getWorstContrast(onLight, surfaces) >= getWorstContrast(onDark, surfaces) ? onLight : onDark;
289
+ if (getWorstContrast(preferred, surfaces) >= exports.READABLE_TEXT_CONTRAST ||
290
+ (preferred === onLight ? !!ifLight : !!ifDark)) {
291
+ return preferred;
292
+ }
293
+ return getWorstContrast(colors_1.Colors.DARK, surfaces) >= getWorstContrast(colors_1.Colors.LIGHT, surfaces)
294
+ ? colors_1.Colors.DARK
295
+ : colors_1.Colors.LIGHT;
296
+ });
297
+ };
298
+ exports.getReadableColorOn = getReadableColorOn;
299
+ /** The contrast of `color` (its red, green and blue), drawn at `alpha` over the opaque `background`, with it. */
300
+ var getContrastAtAlpha = function (_a, background, alpha) {
301
+ var red = _a.red, green = _a.green, blue = _a.blue;
302
+ return (0, exports.getContrastRatio)((0, exports.getDrawnColor)((0, polished_1.rgba)(red, green, blue, alpha), background), background);
303
+ };
304
+ /** How far past the ratio `getReadableAlpha` aims: see there. */
305
+ var READABLE_ALPHA_MARGIN = 0.1;
306
+ /**
307
+ * The least alpha (or opacity), from `alpha` up, at which `color` drawn over `background` (each of them, for a list)
308
+ * still stands out from it by `minContrast`: secondary text or an icon fades only as far as it can and still be read.
309
+ * `alpha` itself when it already reads; 1 when even the full color does not, which is for whoever chose that color to
310
+ * fix. A color or a background it cannot read (none given, a CSS variable) leaves `alpha` as it is: there is no
311
+ * telling how far it stands out.
312
+ */
313
+ var getReadableAlpha = function (color, background, alpha, minContrast) {
314
+ if (minContrast === void 0) { minContrast = exports.READABLE_TEXT_CONTRAST; }
315
+ return Math.max.apply(Math, __spreadArray([alpha], (Array.isArray(background) ? background : [background]).map(function (each) {
316
+ return getReadableAlphaOn(color, each, alpha, minContrast);
317
+ }), false));
318
+ };
319
+ exports.getReadableAlpha = getReadableAlpha;
320
+ /**
321
+ * The least alpha from `from` up to 1 at which `reads` holds, to a hundredth, rounded up: `reads` holds at 1 and not
322
+ * at `from`. The range in which it starts to hold is halved until it is less than half a hundredth wide.
323
+ */
324
+ var leastReadingAlpha = function (from, reads) {
325
+ var low = from;
326
+ var high = 1;
327
+ while (high - low > 0.005) {
328
+ var middle = (low + high) / 2;
329
+ if (reads(middle)) {
330
+ high = middle;
331
+ }
332
+ else {
333
+ low = middle;
334
+ }
335
+ }
336
+ return Math.min(1, Math.ceil(high * 100) / 100);
337
+ };
338
+ var rememberAlpha = (0, exports.createColorCache)();
339
+ var getReadableAlphaOn = function (color, background, alpha, ratio) {
340
+ return rememberAlpha((0, exports.cacheKey)(color, background, alpha, ratio), function () {
341
+ var parts = parseColor(color);
342
+ var surface = (0, exports.getDrawnColor)(background);
343
+ if (alpha >= 1 || !parts || !isOpaque(surface)) {
344
+ return alpha;
345
+ }
346
+ // A browser blends a translucent color a shade differently (an alpha of 255ths, its own rounding): an alpha
347
+ // that just reaches the ratio here can fall a hair short on the page, so it aims a little past it.
348
+ var minContrast = ratio + READABLE_ALPHA_MARGIN;
349
+ if (getContrastAtAlpha(parts, surface, alpha) >= minContrast) {
350
+ return alpha;
351
+ }
352
+ if (getContrastAtAlpha(parts, surface, 1) < minContrast) {
353
+ return 1;
354
+ }
355
+ return leastReadingAlpha(alpha, function (at) { return getContrastAtAlpha(parts, surface, at) >= minContrast; });
356
+ });
357
+ };
358
+ /**
359
+ * How far a group drawn as a whole (`opacity` on it: an idle rail resting dim) can be faded over `under` and every
360
+ * one of `marks` in it still stand out from what it is drawn on by `minContrast`: `opacity`, or as little more as
361
+ * it takes. Faded, a mark and what it is on both fade into `under`, so they draw closer together.
362
+ */
363
+ var getReadableGroupOpacity = function (marks, under, opacity, minContrast) {
364
+ if (minContrast === void 0) { minContrast = exports.READABLE_TEXT_CONTRAST; }
365
+ var page = (0, exports.getDrawnColor)(under);
366
+ // aims a little past the ratio, as getReadableAlpha does: the browser blends a shade differently
367
+ var target = minContrast + READABLE_ALPHA_MARGIN;
368
+ // a mark, or what it is on, that cannot be read (a CSS variable) cannot be measured: it is left out
369
+ var drawn = marks
370
+ .map(function (_a) {
371
+ var color = _a.color, alpha = _a.alpha, on = _a.on;
372
+ var fill = (0, exports.getDrawnColor)(on);
373
+ return { fill: fill, mark: (0, exports.getDrawnColor)((0, exports.fadeColor)(color, alpha), fill) };
374
+ })
375
+ .filter(function (_a) {
376
+ var fill = _a.fill, mark = _a.mark;
377
+ return isOpaque(fill) && isOpaque(mark);
378
+ });
379
+ if (!isOpaque(page) || !drawn.length) {
380
+ return opacity;
381
+ }
382
+ var reads = function (at) {
383
+ return drawn.every(function (_a) {
384
+ var fill = _a.fill, mark = _a.mark;
385
+ return (0, exports.getContrastRatio)((0, exports.getDrawnColor)((0, polished_1.rgba)(mark, at), page), (0, exports.getDrawnColor)((0, polished_1.rgba)(fill, at), page)) >=
386
+ target;
387
+ });
388
+ };
389
+ if (opacity >= 1 || reads(opacity)) {
390
+ return opacity;
391
+ }
392
+ if (!reads(1)) {
393
+ return 1;
394
+ }
395
+ return leastReadingAlpha(opacity, reads);
396
+ };
397
+ exports.getReadableGroupOpacity = getReadableGroupOpacity;
398
+ /** `color` at `alpha`, or at as much more as it needs to stand out from `background` (`getReadableAlpha`). */
399
+ var getReadableFadedColor = function (color, background, alpha, minContrast) {
400
+ if (minContrast === void 0) { minContrast = exports.READABLE_TEXT_CONTRAST; }
401
+ return isOpaque((0, exports.getDrawnColor)(color))
402
+ ? (0, polished_1.rgba)((0, exports.getDrawnColor)(color), (0, exports.getReadableAlpha)(color, background, alpha, minContrast))
403
+ : color;
404
+ };
405
+ exports.getReadableFadedColor = getReadableFadedColor;
406
+ /**
407
+ * A theme's text color on every one of `backgrounds` (what a component is drawn in - each color of its gradient):
408
+ * the theme's own text color when it names one, else the one that reads on all of them (`getReadableColorOn`),
409
+ * dimmed when the theme dims its text.
410
+ */
411
+ var getReadableTextOn = function (theme, backgrounds, dimmed) {
412
+ var _a, _b;
413
+ if (dimmed === void 0) { dimmed = true; }
414
+ return ((_a = theme.text) === null || _a === void 0 ? void 0 : _a.color)
415
+ ? (0, exports.getReadableColor)(theme, undefined, undefined, dimmed)
416
+ : (0, exports.getReadableColorOn)(backgrounds, !!((_b = theme.text) === null || _b === void 0 ? void 0 : _b.dim) && dimmed);
27
417
  };
418
+ exports.getReadableTextOn = getReadableTextOn;
419
+ /**
420
+ * The text color that reads on `from` (drawn over `under` when it is translucent): see `getReadableColorOn`.
421
+ */
422
+ var getReadableColorFrom = function (from, dim, ifLight, ifDark, under) { return (0, exports.getReadableColorOn)([from], dim, ifLight, ifDark, under); };
28
423
  exports.getReadableColorFrom = getReadableColorFrom;
424
+ /** Whether `color` is a gray (black and white included); false for one it cannot read. */
29
425
  var isAchromatic = function (color) {
30
426
  var fixedColor = (0, exports.getRGBAFromHex)(color);
31
427
  return fixedColor.r === fixedColor.g && fixedColor.g === fixedColor.b;
@@ -38,31 +434,59 @@ var percentToHexAlpha = function (p) {
38
434
  return hexValue.padStart(2, '0').toUpperCase(); // format with leading 0 and upper case characters
39
435
  };
40
436
  exports.percentToHexAlpha = percentToHexAlpha;
437
+ /** A hex color of 3, 4, 6 or 8 digits: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`. */
438
+ var HEX_COLOR = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
439
+ /**
440
+ * A hex color in its long form, as CSS reads a short one - each digit doubled: `#fdc` is `#ffddcc`, `#f00a` is
441
+ * `#ff0000aa`. A long one, or anything that is not a hex color, as it is.
442
+ */
443
+ var expandHexColor = function (color) {
444
+ return HEX_COLOR.test(color) && color.length <= 5
445
+ ? "#".concat(Array.from(color.slice(1), function (digit) { return digit + digit; }).join(''))
446
+ : color;
447
+ };
448
+ var NO_RGBA = { r: NaN, g: NaN, b: NaN, a: NaN };
449
+ /**
450
+ * The red, green, blue (0-255) and alpha (0-1) of a color: a hex of 3, 4, 6 or 8 digits, `rgb()`/`rgba()`, or any
451
+ * other color polished reads (`hsl()`, a named one). NaN in each for one it cannot read (a CSS variable).
452
+ *
453
+ * A short hex is each of its digits doubled (`#fdc` is `#ffddcc`). It was repeated (`#fdcfdc`, another hue), and
454
+ * polished writes the colors it works out short wherever it can, so a readable shade made from one of them took
455
+ * the wrong hue: a minimal button in `#ff5500` had lilac text instead of peach.
456
+ */
41
457
  var getRGBAFromHex = function (color) {
42
- var hexColor = color;
458
+ if (typeof color !== 'string') {
459
+ return NO_RGBA;
460
+ }
43
461
  // If this is already an rgba color, we need to convert it to hex
44
- if (color.startsWith('rgba')) {
45
- hexColor = (0, exports.RGBAToHexA)(color);
462
+ var hexColor = expandHexColor(color.startsWith('rgba') ? (0, exports.RGBAToHexA)(color) : color);
463
+ if (!HEX_COLOR.test(hexColor)) {
464
+ var parts = parseColor(color);
465
+ return parts ? { r: parts.red, g: parts.green, b: parts.blue, a: parts.alpha } : NO_RGBA;
46
466
  }
47
- var colorWithAlpha = hexColor.length === 4 ? hexColor + hexColor.slice(1, 4) : hexColor;
48
- var r = parseInt(colorWithAlpha.slice(1, 3), 16);
49
- var g = parseInt(colorWithAlpha.slice(3, 5), 16);
50
- var b = parseInt(colorWithAlpha.slice(5, 7), 16);
51
- var a = parseInt(colorWithAlpha.slice(7, 9) || 'ff', 16) / 255;
467
+ var r = parseInt(hexColor.slice(1, 3), 16);
468
+ var g = parseInt(hexColor.slice(3, 5), 16);
469
+ var b = parseInt(hexColor.slice(5, 7), 16);
470
+ var a = parseInt(hexColor.slice(7, 9) || 'ff', 16) / 255;
52
471
  return { r: r, g: g, b: b, a: a };
53
472
  };
54
473
  exports.getRGBAFromHex = getRGBAFromHex;
474
+ /** `hex` as `rgba(r, g, b, a)`; an `rgb()`/`rgba()` color, and one it cannot read, as it is. */
55
475
  var hexAToRGBA = function (hex) {
56
476
  // Check if this color is already in rgba format
57
- if (hex.startsWith('rgb')) {
477
+ if (typeof hex !== 'string' || hex.startsWith('rgb')) {
58
478
  return hex;
59
479
  }
60
480
  var _a = (0, exports.getRGBAFromHex)(hex), r = _a.r, g = _a.g, b = _a.b, a = _a.a;
481
+ if (Number.isNaN(r)) {
482
+ return hex;
483
+ }
61
484
  return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(a.toFixed(2), ")");
62
485
  };
63
486
  exports.hexAToRGBA = hexAToRGBA;
64
487
  var RGBAToHexA = function (rgba, forceRemoveAlpha) {
65
488
  if (forceRemoveAlpha === void 0) { forceRemoveAlpha = false; }
489
+ // a hex already, of any length (`#f00a` too, which the parse below would write as `#NaN`)
66
490
  if ((0, exports.isValidSixCharHex)(rgba)) {
67
491
  return rgba;
68
492
  }
@@ -78,41 +502,50 @@ var RGBAToHexA = function (rgba, forceRemoveAlpha) {
78
502
  .join('')); // Puts the array to togehter to a string
79
503
  };
80
504
  exports.RGBAToHexA = RGBAToHexA;
505
+ /** Whether `mainColor` is light (a lighter shade of it is made darker); false for one it cannot read. */
81
506
  var shouldDarken = function (mainColor) {
82
- return (0, polished_1.getLuminance)((0, exports.hexAToRGBA)(mainColor)) > 0.2;
507
+ return (0, exports.isReadableColor)(mainColor) && (0, polished_1.getLuminance)((0, exports.hexAToRGBA)(mainColor)) > 0.2;
83
508
  };
84
509
  exports.shouldDarken = shouldDarken;
85
510
  var getMainColor = function (theme, component) { var _a; return ((_a = theme[component]) === null || _a === void 0 ? void 0 : _a.main) || theme.main; };
86
511
  exports.getMainColor = getMainColor;
87
512
  //export const changeBasedOnContrast = (color: string, lightness?: number): string =>
88
- var changeLightness = function (color, lightness) {
89
- var fixedColor = (0, exports.hexAToRGBA)(color);
90
- return lightness
91
- ? (0, exports.shouldDarken)(fixedColor)
513
+ var rememberLightness = (0, exports.createColorCache)();
514
+ /**
515
+ * `color` moved by `lightness` away from what it is (`towardContrast`: a light color darker, a dark one lighter)
516
+ * or toward it. A color it cannot read is as it is.
517
+ */
518
+ var shiftLightness = function (color, lightness, towardContrast) {
519
+ if (!lightness || !(0, exports.isReadableColor)(color)) {
520
+ return color;
521
+ }
522
+ return rememberLightness((0, exports.cacheKey)(color, lightness, towardContrast), function () {
523
+ var fixedColor = (0, exports.hexAToRGBA)(color);
524
+ return ((0, exports.shouldDarken)(fixedColor) === towardContrast
92
525
  ? (0, polished_1.darken)(lightness, fixedColor)
93
- : (0, polished_1.lighten)(lightness, fixedColor)
94
- : color;
526
+ : (0, polished_1.lighten)(lightness, fixedColor));
527
+ });
528
+ };
529
+ var changeLightness = function (color, lightness) {
530
+ return shiftLightness(color, lightness, true);
95
531
  };
96
532
  exports.changeLightness = changeLightness;
97
533
  var changeDarkness = function (color, lightness) {
98
- var fixedColor = (0, exports.hexAToRGBA)(color);
99
- return lightness
100
- ? (0, exports.shouldDarken)(fixedColor)
101
- ? (0, polished_1.lighten)(lightness, fixedColor)
102
- : (0, polished_1.darken)(lightness, fixedColor)
103
- : color;
534
+ return shiftLightness(color, lightness, false);
104
535
  };
105
536
  exports.changeDarkness = changeDarkness;
106
537
  /**
107
538
  * The colour without its alpha channel, as a six-digit hex: `#e6e6e630` → `#e6e6e6`,
108
539
  * `rgba(10, 102, 64, 0.5)` → `#0a6640`. For colour maths that needs the hue a colour
109
540
  * is drawn in rather than how faintly it is drawn (Reqore's muted intent, for one, is
110
- * an eight-digit hex).
541
+ * an eight-digit hex). A color it cannot read (a CSS variable) is as it is.
111
542
  */
112
543
  var getOpaqueColor = function (color) {
113
544
  var _a = (0, exports.getRGBAFromHex)(color), r = _a.r, g = _a.g, b = _a.b;
114
- var toHex = function (value) { return value.toString(16).padStart(2, '0'); };
115
- return "#".concat(toHex(r)).concat(toHex(g)).concat(toHex(b));
545
+ if (Number.isNaN(r)) {
546
+ return color;
547
+ }
548
+ return toHexColor({ red: r, green: g, blue: b, alpha: 1 });
116
549
  };
117
550
  exports.getOpaqueColor = getOpaqueColor;
118
551
  /**
@@ -126,26 +559,140 @@ exports.getOpaqueColor = getOpaqueColor;
126
559
  * ends at white or black, which always can.
127
560
  */
128
561
  var getReadableAccentColor = function (color, background, minContrast) {
129
- if (minContrast === void 0) { minContrast = 4.5; }
130
- var surface = (0, exports.getOpaqueColor)(background);
131
- var onLight = (0, exports.shouldDarken)(surface);
132
- var accent = (0, exports.getOpaqueColor)(color);
133
- // 25 steps of 4% lightness cover the whole range, so the loop always ends.
134
- for (var step = 0; step < 25 && (0, polished_1.getContrast)(accent, surface) < minContrast; step++) {
135
- accent = (onLight ? (0, polished_1.darken)(0.04, accent) : (0, polished_1.lighten)(0.04, accent));
136
- }
137
- return accent;
562
+ if (minContrast === void 0) { minContrast = exports.READABLE_TEXT_CONTRAST; }
563
+ return (0, exports.getReadableAccentColorOn)(color, [background], minContrast);
138
564
  };
139
565
  exports.getReadableAccentColor = getReadableAccentColor;
566
+ var rememberAccent = (0, exports.createColorCache)();
567
+ /**
568
+ * `color` in the shade that stands out by `minContrast` from every one of `backgrounds` (see
569
+ * `getReadableAccentColor`): moved toward whichever of white and black stands out more from the worst of them, until
570
+ * it stands out from all of them - or is that white or black, when nothing does. Always a six-digit hex; a color it
571
+ * cannot read is as it is, and a background it cannot read is left out.
572
+ */
573
+ var getReadableAccentColorOn = function (color, backgrounds, minContrast) {
574
+ if (minContrast === void 0) { minContrast = exports.READABLE_TEXT_CONTRAST; }
575
+ var start = (0, exports.getOpaqueColor)(color);
576
+ if (!isOpaque(start)) {
577
+ return start;
578
+ }
579
+ return rememberAccent((0, exports.cacheKey)(start, backgrounds, minContrast), function () {
580
+ var surfaces = backgrounds
581
+ .map(function (background) { return (0, exports.getOpaqueColor)(background); })
582
+ .filter(function (surface) { return isOpaque(surface); });
583
+ var worst = function (candidate) {
584
+ return Math.min.apply(Math, surfaces.map(function (surface) { return (0, exports.getContrastRatio)(candidate, surface); }));
585
+ };
586
+ var lighter = worst(colors_1.Colors.LIGHT) >= worst(colors_1.Colors.DARK);
587
+ var accent = start;
588
+ // 25 steps of 4% lightness cover the whole range, so the loop always ends.
589
+ for (var step = 0; step < 25 && surfaces.length && worst(accent) < minContrast; step++) {
590
+ accent = (lighter ? (0, polished_1.lighten)(0.04, accent) : (0, polished_1.darken)(0.04, accent));
591
+ }
592
+ // polished writes a color short where it can (`#fff`): the long form, for whoever adds an alpha to it
593
+ return (0, exports.getOpaqueColor)(accent);
594
+ });
595
+ };
596
+ exports.getReadableAccentColorOn = getReadableAccentColorOn;
597
+ /**
598
+ * How a control draws an icon on `backgrounds` (what it is drawn on: one color, or each it may be) beside its `text`:
599
+ * in its own `color` or else in the text color it inherits; at `opacity`, or as much more as it needs to stand out
600
+ * by 3:1. A theme's color (an intent, the theme's main, a shade of one) is drawn in the shade of it that stands
601
+ * out by 3:1; any other color (an explicit hex) as it is given, as a standalone `ReqoreIcon` draws it. `color` is
602
+ * undefined when the icon inherits the text color.
603
+ */
604
+ var getReadableIconLook = function (theme, backgrounds, text, opacity, color) {
605
+ if (opacity === void 0) { opacity = 1; }
606
+ var iconColor = color
607
+ ? (0, exports.getReadableThemeColor)(theme, color, exports.READABLE_ICON_CONTRAST, undefined, backgrounds)
608
+ : undefined;
609
+ return {
610
+ color: iconColor,
611
+ opacity: (0, exports.getReadableAlpha)(iconColor !== null && iconColor !== void 0 ? iconColor : text, backgrounds, opacity, exports.READABLE_ICON_CONTRAST),
612
+ };
613
+ };
614
+ exports.getReadableIconLook = getReadableIconLook;
615
+ /**
616
+ * What a component is drawn on: `surface`, when a component around it has said (`useReqoreSurface`), or else the
617
+ * surface of the theme it was picked in - the layout's, the theme's main a step lighter (`getMainBackgroundColor`).
618
+ * One color: the first of a gradient's (`getThemeSurfaces` gives every one).
619
+ */
620
+ var getThemeSurface = function (theme, surface) { return (0, exports.getThemeSurfaces)(theme, surface)[0]; };
621
+ exports.getThemeSurface = getThemeSurface;
622
+ /**
623
+ * Every color a component is drawn on (see `getThemeSurface`): each of a gradient's, or the one. A color that draws
624
+ * nothing (`'transparent'`) or that cannot be read (a CSS variable) is no surface to read on and is left out; with
625
+ * none left, the theme's.
626
+ */
627
+ var getThemeSurfaces = function (theme, surface) {
628
+ var given = getReadableSurfaces(Array.isArray(surface) ? surface : surface ? [surface] : []);
629
+ return given.length
630
+ ? given
631
+ : [(0, exports.getDrawnColor)((0, exports.changeLightness)(theme.originalMain || theme.main, 0.02))];
632
+ };
633
+ exports.getThemeSurfaces = getThemeSurfaces;
634
+ var rememberIntentColor = (0, exports.createColorCache)();
635
+ var rememberThemeColor = (0, exports.createColorCache)();
636
+ /**
637
+ * Text (or an icon, at `minContrast` 3) in an intent's color on what it is drawn on (`surface`, or the theme's: see
638
+ * `getThemeSurface`): the intent in the shade that stands out there - a warning stays orange, an orange light enough
639
+ * to read on a dark theme. A translucent intent (muted) is drawn over that surface first.
640
+ */
641
+ var getReadableIntentColor = function (theme, intent, minContrast, surface) {
642
+ if (minContrast === void 0) { minContrast = exports.READABLE_TEXT_CONTRAST; }
643
+ return rememberIntentColor((0, exports.cacheKey)((0, exports.getThemeColorKey)(theme), intent, minContrast, surface), function () {
644
+ var unders = (0, exports.getThemeSurfaces)(theme, surface);
645
+ return (0, exports.getReadableAccentColorOn)((0, exports.getDrawnColor)(theme.intents[intent] || unders[0], unders[0]), unders, minContrast);
646
+ });
647
+ };
648
+ exports.getReadableIntentColor = getReadableIntentColor;
649
+ /**
650
+ * The color a span, a paragraph or a link writes its text in: an intent in a shade of it that reads on what the text
651
+ * is drawn on (`surface`, or the theme's), else the theme's text color, else what it inherits.
652
+ */
653
+ var getReadableTextColor = function (theme, intent, surface) {
654
+ var _a;
655
+ return intent
656
+ ? (0, exports.getReadableIntentColor)(theme, intent, undefined, surface)
657
+ : ((_a = theme.text) === null || _a === void 0 ? void 0 : _a.color) || 'inherit';
658
+ };
659
+ exports.getReadableTextColor = getReadableTextColor;
660
+ /**
661
+ * A theme's color - an intent, the theme's main, a shade of one ('info', 'success:lighten:5') - in the shade of it
662
+ * that stands out by `minContrast` from what it is drawn on: `backgrounds` when they are known (a tag's fill, each
663
+ * color of a gradient), else `surface` or the theme's (`getThemeSurface`). The theme picks the hue, not how faint
664
+ * it is. Any other color is as it is given.
665
+ */
666
+ var getReadableThemeColor = function (theme, color, minContrast, surface, backgrounds) {
667
+ var _a;
668
+ if (minContrast === void 0) { minContrast = exports.READABLE_TEXT_CONTRAST; }
669
+ var resolved = (0, exports.getColorFromMaybeString)(theme, color);
670
+ var base = typeof color === 'string' ? color.split(':')[0] : undefined;
671
+ if (!resolved || !base || (base !== 'main' && !((_a = theme.intents) === null || _a === void 0 ? void 0 : _a[base]))) {
672
+ return resolved;
673
+ }
674
+ return rememberThemeColor((0, exports.cacheKey)(resolved, minContrast, (backgrounds === null || backgrounds === void 0 ? void 0 : backgrounds.length) ? backgrounds : '', surface, theme.originalMain, theme.main), function () {
675
+ var under = (backgrounds === null || backgrounds === void 0 ? void 0 : backgrounds.length) ? backgrounds : (0, exports.getThemeSurfaces)(theme, surface);
676
+ return (0, exports.getReadableAccentColorOn)((0, exports.getDrawnColor)(resolved, under[0]), under, minContrast);
677
+ });
678
+ };
679
+ exports.getReadableThemeColor = getReadableThemeColor;
680
+ /**
681
+ * Black or white for a background, by its value in the long form (a short hex, `#fff`, was read as the number
682
+ * `0xfff`: white text on white). Empty for no background; white for one it cannot read.
683
+ */
140
684
  var getColorByBgColor = function (bgColor) {
141
685
  if (!bgColor) {
142
686
  return '';
143
687
  }
144
- return parseInt(bgColor.replace('#', ''), 16) > 0xffffff / 2 ? '#000000' : '#ffffff';
688
+ return parseInt((0, exports.getOpaqueColor)(bgColor).replace('#', ''), 16) > 0xffffff / 2
689
+ ? '#000000'
690
+ : '#ffffff';
145
691
  };
146
692
  exports.getColorByBgColor = getColorByBgColor;
693
+ /** A hex color of 3, 4, 6 or 8 digits (the name is older than the rule): one CSS and the helpers read. */
147
694
  var isValidSixCharHex = function (hex) {
148
- return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8})$/.test(hex);
695
+ return typeof hex === 'string' && HEX_COLOR.test(hex);
149
696
  };
150
697
  exports.isValidSixCharHex = isValidSixCharHex;
151
698
  var buildTheme = function (theme) {
@@ -212,56 +759,67 @@ var getMainBackgroundColor = function (theme) {
212
759
  };
213
760
  exports.getMainBackgroundColor = getMainBackgroundColor;
214
761
  /**
215
- * The `theme.panel` surface and hairline — for a component whose own surface is NOT customised.
216
- * A `customTheme` with a `main`, an intent, or an inherited custom theme moves `theme.main` away
217
- * from `theme.originalMain` (see `mergeThemes`); such a component keeps its derived colours.
762
+ * Whether `color` is one CSS draws though Reqore has no name for it: a color function (`var(--brand)`, `hsl()`,
763
+ * `color-mix()`), `currentColor`, or a color polished reads (a named one, `red`).
218
764
  */
219
- var getThemePanelSurface = function (theme) {
220
- return theme.panel && (!theme.originalMain || theme.main === theme.originalMain)
221
- ? theme.panel
222
- : undefined;
765
+ var isCssColor = function (color) {
766
+ return color.includes('(') || /^currentcolor$/i.test(color) || (0, exports.isReadableColor)(color);
223
767
  };
224
- exports.getThemePanelSurface = getThemePanelSurface;
225
- /** The surface a panel or panel-like container paints: `theme.panel.main`, or derived from `main`. */
226
- var getPanelBackgroundColor = function (theme) { var _a, _b; return (_b = (_a = (0, exports.getThemePanelSurface)(theme)) === null || _a === void 0 ? void 0 : _a.main) !== null && _b !== void 0 ? _b : (0, exports.changeDarkness)((0, exports.getMainBackgroundColor)(theme), 0.03); };
227
- exports.getPanelBackgroundColor = getPanelBackgroundColor;
228
- /** The neutral 1px edge of a panel or panel-like container: `theme.panel.border`, or derived. */
229
- var getPanelHairlineColor = function (theme) { var _a, _b; return (_b = (_a = (0, exports.getThemePanelSurface)(theme)) === null || _a === void 0 ? void 0 : _a.border) !== null && _b !== void 0 ? _b : (0, exports.changeLightness)((0, exports.getMainBackgroundColor)(theme), 0.08); };
230
- exports.getPanelHairlineColor = getPanelHairlineColor;
768
+ var rememberColor = (0, exports.createColorCache)();
769
+ /**
770
+ * The color `color` names: an intent, the theme's main (`main`, or nothing before the first colon), a hex (a short
771
+ * one with an alpha, `#f00a`, in its long form), or `transparent` (the theme's original main), lightened or
772
+ * darkened by a number of steps and drawn at an alpha (`info:lighten:2:0.5`). A color CSS draws but Reqore has no
773
+ * name for (`red`, `var(--brand)`, `currentColor`) is as it is given, and so is a color that cannot be lightened (an
774
+ * intent that is a CSS variable); a name nothing knows is undefined.
775
+ */
231
776
  var getColorFromMaybeString = function (theme, color) {
232
- if (!color) {
777
+ var _a;
778
+ if (!color || typeof color !== 'string') {
233
779
  return undefined;
234
780
  }
235
781
  if (color.startsWith('rgba')) {
236
782
  return (0, exports.RGBAToHexA)(color);
237
783
  }
238
- var _a = color.split(':'), providedColor = _a[0], shading = _a[1], _b = _a[2], multiplier = _b === void 0 ? 1 : _b, _c = _a[3], alpha = _c === void 0 ? 1 : _c;
784
+ var _b = color.split(':'), providedColor = _b[0], shading = _b[1], _c = _b[2], multiplier = _c === void 0 ? 1 : _c, _d = _b[3], alpha = _d === void 0 ? 1 : _d;
239
785
  if (providedColor === 'transparent') {
240
786
  return theme.originalMain;
241
787
  }
242
- // First we need to get the actual color
243
- var _color;
244
- if (!providedColor || providedColor === 'main') {
245
- _color = theme.main;
246
- }
247
- if (theme.intents[providedColor]) {
248
- _color = theme.intents[providedColor];
249
- }
250
- if ((0, exports.isValidSixCharHex)(providedColor)) {
251
- _color = providedColor;
252
- }
253
- if (shading) {
254
- if (shading === 'lighten') {
255
- _color = (0, polished_1.lighten)(0.033 * multiplier, _color);
788
+ return rememberColor((0, exports.cacheKey)(color, theme.main, theme.originalMain, (_a = theme.intents) === null || _a === void 0 ? void 0 : _a[providedColor]), function () {
789
+ var _a;
790
+ // First we need to get the actual color
791
+ var _color;
792
+ if (!providedColor || providedColor === 'main') {
793
+ _color = theme.main;
256
794
  }
257
- else if (shading === 'darken') {
258
- _color = (0, polished_1.darken)(0.033 * multiplier, _color);
795
+ if ((_a = theme.intents) === null || _a === void 0 ? void 0 : _a[providedColor]) {
796
+ _color = theme.intents[providedColor];
259
797
  }
260
- }
261
- if (_color && _color.length === 7 && alpha < 1) {
262
- _color = (0, exports.RGBAToHexA)((0, polished_1.transparentize)(1 - alpha, _color));
263
- }
264
- return _color;
798
+ if (HEX_COLOR.test(providedColor)) {
799
+ // a short hex with an alpha (`#f00a`) in its long form; any other hex as it is
800
+ _color = (providedColor.length === 5 ? expandHexColor(providedColor) : providedColor);
801
+ }
802
+ else if (!_color && providedColor && isCssColor(providedColor)) {
803
+ _color = providedColor;
804
+ }
805
+ // a color that cannot be read (a CSS variable) cannot be shaded either: it is drawn as it is
806
+ if (!(0, exports.isReadableColor)(_color)) {
807
+ return _color;
808
+ }
809
+ if (shading) {
810
+ if (shading === 'lighten') {
811
+ _color = (0, polished_1.lighten)(0.033 * multiplier, _color);
812
+ }
813
+ else if (shading === 'darken') {
814
+ _color = (0, polished_1.darken)(0.033 * multiplier, _color);
815
+ }
816
+ }
817
+ // an opaque hex (polished writes a short one where it can) drawn at an alpha
818
+ if ((_color.length === 7 || _color.length === 4) && alpha < 1) {
819
+ _color = (0, exports.RGBAToHexA)((0, polished_1.transparentize)(1 - alpha, _color));
820
+ }
821
+ return _color;
822
+ });
265
823
  };
266
824
  exports.getColorFromMaybeString = getColorFromMaybeString;
267
825
  var createEffectGradient = function (theme, colors, lighten, minimal, active, transparent) {
@@ -271,36 +829,82 @@ var createEffectGradient = function (theme, colors, lighten, minimal, active, tr
271
829
  if (!colors) {
272
830
  throw new Error('You need to provide colors');
273
831
  }
274
- if (typeof colors === 'string') {
275
- _colors = (0, exports.buildGradientColorsFromString)(theme, colors);
276
- }
277
- else {
278
- _colors = colors;
279
- }
280
- return (0, lodash_1.reduce)(_colors, function (colorsString, color, percentage) {
281
- return "".concat(colorsString, ", ").concat(transparent
282
- ? active
283
- ? theme.originalMain
284
- : (0, exports.changeLightness)(theme.originalMain, lighten)
285
- : minimal
286
- ? (0, polished_1.rgba)((0, exports.changeLightness)((0, exports.getColorFromMaybeString)(theme, color), lighten), 0.25)
287
- : (0, exports.changeLightness)((0, exports.getColorFromMaybeString)(theme, color), lighten), " ").concat(percentage, "%");
288
- }, '');
832
+ return rememberEffectGradient((0, exports.cacheKey)((0, exports.getThemeColorKey)(theme), typeof colors === 'string' ? colors : JSON.stringify(colors), lighten, minimal, active, transparent), function () {
833
+ if (typeof colors === 'string') {
834
+ _colors = (0, exports.buildGradientColorsFromString)(theme, colors);
835
+ }
836
+ else {
837
+ _colors = colors;
838
+ }
839
+ return (0, lodash_1.reduce)(_colors, function (colorsString, color, percentage) {
840
+ // a color nothing knows draws nothing, rather than an `undefined` that drops the whole gradient
841
+ var stop = (0, exports.getColorFromMaybeString)(theme, color) || 'transparent';
842
+ return "".concat(colorsString, ", ").concat(transparent
843
+ ? active
844
+ ? theme.originalMain
845
+ : (0, exports.changeLightness)(theme.originalMain, lighten)
846
+ : minimal
847
+ ? (0, exports.getColorAtAlpha)((0, exports.changeLightness)(stop, lighten), 0.25)
848
+ : (0, exports.changeLightness)(stop, lighten), " ").concat(percentage, "%");
849
+ }, '');
850
+ });
289
851
  };
290
852
  exports.createEffectGradient = createEffectGradient;
853
+ var rememberEffectGradient = (0, exports.createColorCache)();
854
+ var rememberGradientColors = (0, exports.createColorCache)();
855
+ /**
856
+ * A gradient made from one color (`'info'`, `'#0776cb'`): see `buildGradientShades`. A color it cannot read (a CSS
857
+ * variable) is the gradient's both ends.
858
+ */
291
859
  var buildGradientColorsFromString = function (theme, colorString) {
292
860
  if (!colorString) {
293
861
  throw new Error('You need to provide a color or intent');
294
862
  }
295
863
  var finalColor = (0, exports.getColorFromMaybeString)(theme, colorString);
296
- var colorFrom = (0, exports.getColorFromMaybeString)(theme, "".concat(finalColor, ":lighten:5:1"));
297
- var colorTo = (0, exports.getColorFromMaybeString)(theme, "".concat(finalColor, ":darken:5:1"));
864
+ if (!(0, exports.isReadableColor)(finalColor)) {
865
+ return { 0: finalColor, 100: finalColor };
866
+ }
867
+ // the shades depend only on the color: a copy, so a caller that changes it changes nobody else's
868
+ return __assign({}, rememberGradientColors(finalColor, function () { return buildGradientShades(theme, finalColor); }));
869
+ };
870
+ exports.buildGradientColorsFromString = buildGradientColorsFromString;
871
+ var buildGradientShades = function (theme, finalColor) {
872
+ /* A lighter and a darker shade of the color, each as far as five steps from it - but only as far as the text
873
+ that reads on the color still reads on the shade: a gradient made from one color is a color text is put on,
874
+ and a blue lightened past where white reads on it was white text on a light blue at one end. */
875
+ var text = (0, exports.getReadableColorOn)([finalColor]);
876
+ // read at rest and a step lighter, as the effect draws it hovered or pressed
877
+ var readsOn = function (shade) {
878
+ return (0, exports.getContrastRatio)(text, shade) >= exports.READABLE_TEXT_CONTRAST &&
879
+ (0, exports.getContrastRatio)(text, (0, exports.changeLightness)(shade, 0.05)) >= exports.READABLE_TEXT_CONTRAST;
880
+ };
881
+ var getShade = function (shading) {
882
+ for (var steps = 5; steps > 0; steps--) {
883
+ var shade = (0, exports.getColorFromMaybeString)(theme, "".concat(finalColor, ":").concat(shading, ":").concat(steps, ":1"));
884
+ if (readsOn(shade)) {
885
+ return shade;
886
+ }
887
+ }
888
+ if (readsOn(finalColor)) {
889
+ return finalColor;
890
+ }
891
+ // the color itself does not read once lightened: as little the other way as it takes
892
+ var opposite = shading === 'lighten' ? 'darken' : 'lighten';
893
+ for (var steps = 1; steps <= 5; steps++) {
894
+ var shade = (0, exports.getColorFromMaybeString)(theme, "".concat(finalColor, ":").concat(opposite, ":").concat(steps, ":1"));
895
+ if (readsOn(shade)) {
896
+ return shade;
897
+ }
898
+ }
899
+ return finalColor;
900
+ };
901
+ var colorFrom = getShade('lighten');
902
+ var colorTo = getShade('darken');
298
903
  return {
299
904
  0: colorFrom,
300
905
  100: colorTo,
301
906
  };
302
907
  };
303
- exports.buildGradientColorsFromString = buildGradientColorsFromString;
304
908
  var getNthGradientColor = function (theme, colors, nth) {
305
909
  if (nth === void 0) { nth = 1; }
306
910
  var _colors = typeof colors === 'string' ? (0, exports.buildGradientColorsFromString)(theme, colors) : colors;
@@ -310,7 +914,16 @@ var getNthGradientColor = function (theme, colors, nth) {
310
914
  return undefined;
311
915
  };
312
916
  exports.getNthGradientColor = getNthGradientColor;
917
+ var rememberGradientMix = (0, exports.createColorCache)();
313
918
  var getGradientMix = function (theme, colors, fallback) {
919
+ if (!colors) {
920
+ return fallback;
921
+ }
922
+ return rememberGradientMix((0, exports.cacheKey)((0, exports.getThemeColorKey)(theme), typeof colors === 'string' ? colors : JSON.stringify(colors), fallback), function () { return mixGradient(theme, colors, fallback); });
923
+ };
924
+ exports.getGradientMix = getGradientMix;
925
+ /** The middle of a gradient, the mix of its first and last colors: see `getGradientMix`. */
926
+ var mixGradient = function (theme, colors, fallback) {
314
927
  var _colors = typeof colors === 'string' ? (0, exports.buildGradientColorsFromString)(theme, colors) : colors;
315
928
  if (!_colors) {
316
929
  return fallback;
@@ -318,7 +931,30 @@ var getGradientMix = function (theme, colors, fallback) {
318
931
  // If there are more than 2 colors, we can't mix them, so we get the first and last color
319
932
  var gradientColor1 = (0, exports.getNthGradientColor)(theme, _colors);
320
933
  var gradientColor2 = (0, exports.getNthGradientColor)(theme, _colors, (0, lodash_1.size)(_colors));
321
- return (0, exports.RGBAToHexA)((0, polished_1.mix)(0.5, gradientColor1 === '#00000000' ? theme.main : gradientColor1, gradientColor2 === '#00000000' ? theme.main : gradientColor2));
934
+ var first = gradientColor1 === '#00000000' ? theme.main : gradientColor1;
935
+ var last = gradientColor2 === '#00000000' ? theme.main : gradientColor2;
936
+ // colors it cannot read (a CSS variable) cannot be mixed: the first that can be, or the fallback
937
+ if (!(0, exports.isReadableColor)(first) || !(0, exports.isReadableColor)(last)) {
938
+ return [first, last].find(function (color) { return (0, exports.isReadableColor)(color); }) || fallback || first;
939
+ }
940
+ return (0, exports.RGBAToHexA)((0, polished_1.mix)(0.5, first, last));
322
941
  };
323
- exports.getGradientMix = getGradientMix;
942
+ var rememberGradientList = (0, exports.createColorCache)();
943
+ /**
944
+ * Each color a gradient is drawn in, as given (a translucent one stays translucent): what text on the gradient has
945
+ * to stand out from, every one of them.
946
+ */
947
+ var getGradientColorList = function (theme, colors) {
948
+ if (!colors) {
949
+ return [];
950
+ }
951
+ // a copy: a caller that changes the list changes nobody else's
952
+ return __spreadArray([], rememberGradientList((0, exports.cacheKey)((0, exports.getThemeColorKey)(theme), typeof colors === 'string' ? colors : JSON.stringify(colors)), function () {
953
+ var _colors = typeof colors === 'string' ? (0, exports.buildGradientColorsFromString)(theme, colors) : colors;
954
+ return Object.values(_colors)
955
+ .map(function (color) { return (0, exports.getColorFromMaybeString)(theme, color); })
956
+ .filter(function (color) { return !!color; });
957
+ }), true);
958
+ };
959
+ exports.getGradientColorList = getGradientColorList;
324
960
  //# sourceMappingURL=colors.js.map