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

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