@octanejs/aria 0.0.40 → 0.0.41

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 (416) hide show
  1. package/LICENSE-APACHE-2.0 +201 -0
  2. package/README.md +20 -7
  3. package/UPSTREAM.md +108 -0
  4. package/package.json +10 -6
  5. package/src/calendar/useCalendar.tsx +36 -0
  6. package/src/calendar/useCalendarBase.tsx +142 -0
  7. package/src/calendar/useCalendarCell.tsx +416 -0
  8. package/src/calendar/useCalendarGrid.tsx +202 -0
  9. package/src/calendar/useCalendarHeading.tsx +85 -0
  10. package/src/calendar/useCalendarMonthPicker.tsx +92 -0
  11. package/src/calendar/useCalendarYearPicker.tsx +127 -0
  12. package/src/calendar/useRangeCalendar.tsx +121 -0
  13. package/src/calendar/utils.tsx +183 -0
  14. package/src/color/useColorArea.tsx +599 -0
  15. package/src/color/useColorAreaGradient.tsx +157 -0
  16. package/src/color/useColorChannelField.tsx +53 -0
  17. package/src/color/useColorField.tsx +170 -0
  18. package/src/color/useColorSlider.tsx +177 -0
  19. package/src/color/useColorSwatch.tsx +83 -0
  20. package/src/color/useColorWheel.tsx +401 -0
  21. package/src/compat/react.ts +111 -0
  22. package/src/components/Calendar.tsx +842 -0
  23. package/src/components/ColorArea.tsx +120 -0
  24. package/src/components/ColorField.tsx +304 -0
  25. package/src/components/ColorPicker.tsx +86 -0
  26. package/src/components/ColorSlider.tsx +144 -0
  27. package/src/components/ColorSwatch.tsx +72 -0
  28. package/src/components/ColorSwatchPicker.tsx +176 -0
  29. package/src/components/ColorThumb.tsx +140 -0
  30. package/src/components/ColorWheel.tsx +163 -0
  31. package/src/components/DateField.tsx +580 -0
  32. package/src/components/DatePicker.tsx +386 -0
  33. package/src/components/DropZone.tsx +181 -0
  34. package/src/components/FileTrigger.tsx +96 -0
  35. package/src/components/GridLayout.tsx +33 -0
  36. package/src/components/HiddenDateInput.tsx +169 -0
  37. package/src/components/TableLayout.tsx +39 -0
  38. package/src/components/Toast.tsx +336 -0
  39. package/src/components/Virtualizer.tsx +219 -0
  40. package/src/components/index.ts +257 -7
  41. package/src/components/useDragAndDrop.tsx +221 -0
  42. package/src/components/utils.ts +12 -89
  43. package/src/datepicker/useDateField.tsx +272 -0
  44. package/src/datepicker/useDatePicker.tsx +229 -0
  45. package/src/datepicker/useDatePickerGroup.tsx +147 -0
  46. package/src/datepicker/useDateRangePicker.tsx +288 -0
  47. package/src/datepicker/useDateSegment.tsx +439 -0
  48. package/src/datepicker/useDisplayNames.tsx +53 -0
  49. package/src/dnd/DragManager.tsx +718 -0
  50. package/src/dnd/DragPreview.tsx +100 -0
  51. package/src/dnd/DropTargetKeyboardNavigation.tsx +317 -0
  52. package/src/dnd/ListDropTargetDelegate.tsx +215 -0
  53. package/src/dnd/constants.tsx +93 -0
  54. package/src/dnd/useAutoScroll.tsx +116 -0
  55. package/src/dnd/useClipboard.tsx +160 -0
  56. package/src/dnd/useDrag.tsx +437 -0
  57. package/src/dnd/useDraggableCollection.tsx +35 -0
  58. package/src/dnd/useDraggableItem.tsx +168 -0
  59. package/src/dnd/useDrop.tsx +518 -0
  60. package/src/dnd/useDropIndicator.tsx +129 -0
  61. package/src/dnd/useDroppableCollection.tsx +808 -0
  62. package/src/dnd/useDroppableItem.tsx +99 -0
  63. package/src/dnd/useVirtualDrop.tsx +52 -0
  64. package/src/dnd/utils.tsx +430 -0
  65. package/src/intl/calendar/ar-AE.json +14 -0
  66. package/src/intl/calendar/bg-BG.json +14 -0
  67. package/src/intl/calendar/cs-CZ.json +14 -0
  68. package/src/intl/calendar/da-DK.json +14 -0
  69. package/src/intl/calendar/de-DE.json +14 -0
  70. package/src/intl/calendar/el-GR.json +14 -0
  71. package/src/intl/calendar/en-US.json +14 -0
  72. package/src/intl/calendar/es-ES.json +14 -0
  73. package/src/intl/calendar/et-EE.json +14 -0
  74. package/src/intl/calendar/fi-FI.json +14 -0
  75. package/src/intl/calendar/fr-FR.json +14 -0
  76. package/src/intl/calendar/he-IL.json +14 -0
  77. package/src/intl/calendar/hr-HR.json +14 -0
  78. package/src/intl/calendar/hu-HU.json +14 -0
  79. package/src/intl/calendar/index.ts +73 -0
  80. package/src/intl/calendar/it-IT.json +14 -0
  81. package/src/intl/calendar/ja-JP.json +14 -0
  82. package/src/intl/calendar/ko-KR.json +14 -0
  83. package/src/intl/calendar/lt-LT.json +14 -0
  84. package/src/intl/calendar/lv-LV.json +14 -0
  85. package/src/intl/calendar/nb-NO.json +14 -0
  86. package/src/intl/calendar/nl-NL.json +14 -0
  87. package/src/intl/calendar/pl-PL.json +14 -0
  88. package/src/intl/calendar/pt-BR.json +14 -0
  89. package/src/intl/calendar/pt-PT.json +14 -0
  90. package/src/intl/calendar/ro-RO.json +14 -0
  91. package/src/intl/calendar/ru-RU.json +14 -0
  92. package/src/intl/calendar/sk-SK.json +14 -0
  93. package/src/intl/calendar/sl-SI.json +14 -0
  94. package/src/intl/calendar/sr-SP.json +14 -0
  95. package/src/intl/calendar/sv-SE.json +14 -0
  96. package/src/intl/calendar/tr-TR.json +14 -0
  97. package/src/intl/calendar/uk-UA.json +14 -0
  98. package/src/intl/calendar/zh-CN.json +14 -0
  99. package/src/intl/calendar/zh-TW.json +14 -0
  100. package/src/intl/color/ar-AE.json +8 -0
  101. package/src/intl/color/bg-BG.json +8 -0
  102. package/src/intl/color/cs-CZ.json +8 -0
  103. package/src/intl/color/da-DK.json +8 -0
  104. package/src/intl/color/de-DE.json +8 -0
  105. package/src/intl/color/el-GR.json +8 -0
  106. package/src/intl/color/en-US.json +8 -0
  107. package/src/intl/color/es-ES.json +8 -0
  108. package/src/intl/color/et-EE.json +8 -0
  109. package/src/intl/color/fi-FI.json +8 -0
  110. package/src/intl/color/fr-FR.json +8 -0
  111. package/src/intl/color/he-IL.json +8 -0
  112. package/src/intl/color/hr-HR.json +8 -0
  113. package/src/intl/color/hu-HU.json +8 -0
  114. package/src/intl/color/index.ts +73 -0
  115. package/src/intl/color/it-IT.json +8 -0
  116. package/src/intl/color/ja-JP.json +8 -0
  117. package/src/intl/color/ko-KR.json +8 -0
  118. package/src/intl/color/lt-LT.json +8 -0
  119. package/src/intl/color/lv-LV.json +8 -0
  120. package/src/intl/color/nb-NO.json +8 -0
  121. package/src/intl/color/nl-NL.json +8 -0
  122. package/src/intl/color/pl-PL.json +8 -0
  123. package/src/intl/color/pt-BR.json +8 -0
  124. package/src/intl/color/pt-PT.json +8 -0
  125. package/src/intl/color/ro-RO.json +8 -0
  126. package/src/intl/color/ru-RU.json +8 -0
  127. package/src/intl/color/sk-SK.json +8 -0
  128. package/src/intl/color/sl-SI.json +8 -0
  129. package/src/intl/color/sr-SP.json +8 -0
  130. package/src/intl/color/sv-SE.json +8 -0
  131. package/src/intl/color/tr-TR.json +8 -0
  132. package/src/intl/color/uk-UA.json +8 -0
  133. package/src/intl/color/zh-CN.json +8 -0
  134. package/src/intl/color/zh-TW.json +8 -0
  135. package/src/intl/datepicker/ar-AE.json +18 -0
  136. package/src/intl/datepicker/bg-BG.json +18 -0
  137. package/src/intl/datepicker/cs-CZ.json +18 -0
  138. package/src/intl/datepicker/da-DK.json +18 -0
  139. package/src/intl/datepicker/de-DE.json +18 -0
  140. package/src/intl/datepicker/el-GR.json +18 -0
  141. package/src/intl/datepicker/en-US.json +18 -0
  142. package/src/intl/datepicker/es-ES.json +18 -0
  143. package/src/intl/datepicker/et-EE.json +18 -0
  144. package/src/intl/datepicker/fi-FI.json +18 -0
  145. package/src/intl/datepicker/fr-FR.json +18 -0
  146. package/src/intl/datepicker/he-IL.json +18 -0
  147. package/src/intl/datepicker/hr-HR.json +18 -0
  148. package/src/intl/datepicker/hu-HU.json +18 -0
  149. package/src/intl/datepicker/index.ts +73 -0
  150. package/src/intl/datepicker/it-IT.json +18 -0
  151. package/src/intl/datepicker/ja-JP.json +18 -0
  152. package/src/intl/datepicker/ko-KR.json +18 -0
  153. package/src/intl/datepicker/lt-LT.json +18 -0
  154. package/src/intl/datepicker/lv-LV.json +18 -0
  155. package/src/intl/datepicker/nb-NO.json +18 -0
  156. package/src/intl/datepicker/nl-NL.json +18 -0
  157. package/src/intl/datepicker/pl-PL.json +18 -0
  158. package/src/intl/datepicker/pt-BR.json +18 -0
  159. package/src/intl/datepicker/pt-PT.json +18 -0
  160. package/src/intl/datepicker/ro-RO.json +18 -0
  161. package/src/intl/datepicker/ru-RU.json +18 -0
  162. package/src/intl/datepicker/sk-SK.json +18 -0
  163. package/src/intl/datepicker/sl-SI.json +18 -0
  164. package/src/intl/datepicker/sr-SP.json +18 -0
  165. package/src/intl/datepicker/sv-SE.json +18 -0
  166. package/src/intl/datepicker/tr-TR.json +18 -0
  167. package/src/intl/datepicker/uk-UA.json +18 -0
  168. package/src/intl/datepicker/zh-CN.json +18 -0
  169. package/src/intl/datepicker/zh-TW.json +18 -0
  170. package/src/intl/dnd/ar-AE.json +29 -0
  171. package/src/intl/dnd/bg-BG.json +29 -0
  172. package/src/intl/dnd/cs-CZ.json +29 -0
  173. package/src/intl/dnd/da-DK.json +29 -0
  174. package/src/intl/dnd/de-DE.json +29 -0
  175. package/src/intl/dnd/el-GR.json +29 -0
  176. package/src/intl/dnd/en-US.json +29 -0
  177. package/src/intl/dnd/es-ES.json +29 -0
  178. package/src/intl/dnd/et-EE.json +29 -0
  179. package/src/intl/dnd/fi-FI.json +29 -0
  180. package/src/intl/dnd/fr-FR.json +29 -0
  181. package/src/intl/dnd/he-IL.json +29 -0
  182. package/src/intl/dnd/hr-HR.json +29 -0
  183. package/src/intl/dnd/hu-HU.json +29 -0
  184. package/src/intl/dnd/index.ts +73 -0
  185. package/src/intl/dnd/it-IT.json +29 -0
  186. package/src/intl/dnd/ja-JP.json +29 -0
  187. package/src/intl/dnd/ko-KR.json +29 -0
  188. package/src/intl/dnd/lt-LT.json +29 -0
  189. package/src/intl/dnd/lv-LV.json +29 -0
  190. package/src/intl/dnd/nb-NO.json +29 -0
  191. package/src/intl/dnd/nl-NL.json +29 -0
  192. package/src/intl/dnd/pl-PL.json +29 -0
  193. package/src/intl/dnd/pt-BR.json +29 -0
  194. package/src/intl/dnd/pt-PT.json +29 -0
  195. package/src/intl/dnd/ro-RO.json +29 -0
  196. package/src/intl/dnd/ru-RU.json +29 -0
  197. package/src/intl/dnd/sk-SK.json +29 -0
  198. package/src/intl/dnd/sl-SI.json +29 -0
  199. package/src/intl/dnd/sr-SP.json +29 -0
  200. package/src/intl/dnd/sv-SE.json +29 -0
  201. package/src/intl/dnd/tr-TR.json +29 -0
  202. package/src/intl/dnd/uk-UA.json +29 -0
  203. package/src/intl/dnd/zh-CN.json +29 -0
  204. package/src/intl/dnd/zh-TW.json +29 -0
  205. package/src/intl/react-aria-components/ar-AE.json +6 -0
  206. package/src/intl/react-aria-components/bg-BG.json +6 -0
  207. package/src/intl/react-aria-components/cs-CZ.json +6 -0
  208. package/src/intl/react-aria-components/da-DK.json +6 -0
  209. package/src/intl/react-aria-components/de-DE.json +6 -0
  210. package/src/intl/react-aria-components/el-GR.json +6 -0
  211. package/src/intl/react-aria-components/en-US.json +6 -0
  212. package/src/intl/react-aria-components/es-ES.json +6 -0
  213. package/src/intl/react-aria-components/et-EE.json +6 -0
  214. package/src/intl/react-aria-components/fi-FI.json +6 -0
  215. package/src/intl/react-aria-components/fr-FR.json +6 -0
  216. package/src/intl/react-aria-components/he-IL.json +6 -0
  217. package/src/intl/react-aria-components/hr-HR.json +6 -0
  218. package/src/intl/react-aria-components/hu-HU.json +6 -0
  219. package/src/intl/react-aria-components/index.ts +73 -0
  220. package/src/intl/react-aria-components/it-IT.json +6 -0
  221. package/src/intl/react-aria-components/ja-JP.json +6 -0
  222. package/src/intl/react-aria-components/ko-KR.json +6 -0
  223. package/src/intl/react-aria-components/lt-LT.json +6 -0
  224. package/src/intl/react-aria-components/lv-LV.json +6 -0
  225. package/src/intl/react-aria-components/nb-NO.json +6 -0
  226. package/src/intl/react-aria-components/nl-NL.json +6 -0
  227. package/src/intl/react-aria-components/pl-PL.json +6 -0
  228. package/src/intl/react-aria-components/pt-BR.json +6 -0
  229. package/src/intl/react-aria-components/pt-PT.json +6 -0
  230. package/src/intl/react-aria-components/ro-RO.json +6 -0
  231. package/src/intl/react-aria-components/ru-RU.json +6 -0
  232. package/src/intl/react-aria-components/sk-SK.json +6 -0
  233. package/src/intl/react-aria-components/sl-SI.json +6 -0
  234. package/src/intl/react-aria-components/sr-SP.json +6 -0
  235. package/src/intl/react-aria-components/sv-SE.json +6 -0
  236. package/src/intl/react-aria-components/tr-TR.json +6 -0
  237. package/src/intl/react-aria-components/uk-UA.json +6 -0
  238. package/src/intl/react-aria-components/zh-CN.json +6 -0
  239. package/src/intl/react-aria-components/zh-TW.json +6 -0
  240. package/src/intl/stately-color/ar-AE.json +39 -0
  241. package/src/intl/stately-color/bg-BG.json +39 -0
  242. package/src/intl/stately-color/cs-CZ.json +39 -0
  243. package/src/intl/stately-color/da-DK.json +39 -0
  244. package/src/intl/stately-color/de-DE.json +39 -0
  245. package/src/intl/stately-color/el-GR.json +39 -0
  246. package/src/intl/stately-color/en-US.json +39 -0
  247. package/src/intl/stately-color/es-ES.json +39 -0
  248. package/src/intl/stately-color/et-EE.json +39 -0
  249. package/src/intl/stately-color/fi-FI.json +39 -0
  250. package/src/intl/stately-color/fr-FR.json +39 -0
  251. package/src/intl/stately-color/he-IL.json +39 -0
  252. package/src/intl/stately-color/hr-HR.json +39 -0
  253. package/src/intl/stately-color/hu-HU.json +39 -0
  254. package/src/intl/stately-color/index.ts +73 -0
  255. package/src/intl/stately-color/it-IT.json +39 -0
  256. package/src/intl/stately-color/ja-JP.json +39 -0
  257. package/src/intl/stately-color/ko-KR.json +39 -0
  258. package/src/intl/stately-color/lt-LT.json +39 -0
  259. package/src/intl/stately-color/lv-LV.json +39 -0
  260. package/src/intl/stately-color/nb-NO.json +39 -0
  261. package/src/intl/stately-color/nl-NL.json +39 -0
  262. package/src/intl/stately-color/pl-PL.json +39 -0
  263. package/src/intl/stately-color/pt-BR.json +39 -0
  264. package/src/intl/stately-color/pt-PT.json +39 -0
  265. package/src/intl/stately-color/ro-RO.json +39 -0
  266. package/src/intl/stately-color/ru-RU.json +39 -0
  267. package/src/intl/stately-color/sk-SK.json +39 -0
  268. package/src/intl/stately-color/sl-SI.json +39 -0
  269. package/src/intl/stately-color/sr-SP.json +39 -0
  270. package/src/intl/stately-color/sv-SE.json +39 -0
  271. package/src/intl/stately-color/tr-TR.json +39 -0
  272. package/src/intl/stately-color/uk-UA.json +39 -0
  273. package/src/intl/stately-color/zh-CN.json +39 -0
  274. package/src/intl/stately-color/zh-TW.json +39 -0
  275. package/src/intl/toast/ar-AE.json +4 -0
  276. package/src/intl/toast/bg-BG.json +4 -0
  277. package/src/intl/toast/cs-CZ.json +4 -0
  278. package/src/intl/toast/da-DK.json +4 -0
  279. package/src/intl/toast/de-DE.json +4 -0
  280. package/src/intl/toast/el-GR.json +4 -0
  281. package/src/intl/toast/en-US.json +4 -0
  282. package/src/intl/toast/es-ES.json +4 -0
  283. package/src/intl/toast/et-EE.json +4 -0
  284. package/src/intl/toast/fi-FI.json +4 -0
  285. package/src/intl/toast/fr-FR.json +4 -0
  286. package/src/intl/toast/he-IL.json +4 -0
  287. package/src/intl/toast/hr-HR.json +4 -0
  288. package/src/intl/toast/hu-HU.json +4 -0
  289. package/src/intl/toast/index.ts +73 -0
  290. package/src/intl/toast/it-IT.json +4 -0
  291. package/src/intl/toast/ja-JP.json +4 -0
  292. package/src/intl/toast/ko-KR.json +4 -0
  293. package/src/intl/toast/lt-LT.json +4 -0
  294. package/src/intl/toast/lv-LV.json +4 -0
  295. package/src/intl/toast/nb-NO.json +4 -0
  296. package/src/intl/toast/nl-NL.json +4 -0
  297. package/src/intl/toast/pl-PL.json +4 -0
  298. package/src/intl/toast/pt-BR.json +4 -0
  299. package/src/intl/toast/pt-PT.json +4 -0
  300. package/src/intl/toast/ro-RO.json +4 -0
  301. package/src/intl/toast/ru-RU.json +4 -0
  302. package/src/intl/toast/sk-SK.json +4 -0
  303. package/src/intl/toast/sl-SI.json +4 -0
  304. package/src/intl/toast/sr-SP.json +4 -0
  305. package/src/intl/toast/sv-SE.json +4 -0
  306. package/src/intl/toast/tr-TR.json +4 -0
  307. package/src/intl/toast/uk-UA.json +4 -0
  308. package/src/intl/toast/zh-CN.json +4 -0
  309. package/src/intl/toast/zh-TW.json +4 -0
  310. package/src/landmark/useLandmark.tsx +569 -0
  311. package/src/stately/calendar/types.tsx +239 -0
  312. package/src/stately/calendar/useCalendarState.tsx +527 -0
  313. package/src/stately/calendar/useRangeCalendarState.tsx +323 -0
  314. package/src/stately/calendar/utils.tsx +175 -0
  315. package/src/stately/color/Color.tsx +889 -0
  316. package/src/stately/color/types.tsx +82 -0
  317. package/src/stately/color/useColor.tsx +30 -0
  318. package/src/stately/color/useColorAreaState.tsx +255 -0
  319. package/src/stately/color/useColorChannelFieldState.tsx +86 -0
  320. package/src/stately/color/useColorFieldState.tsx +220 -0
  321. package/src/stately/color/useColorPickerState.tsx +31 -0
  322. package/src/stately/color/useColorSliderState.tsx +143 -0
  323. package/src/stately/color/useColorWheelState.tsx +225 -0
  324. package/src/stately/data/useAsyncList.tsx +382 -0
  325. package/src/stately/data/useListData.tsx +447 -0
  326. package/src/stately/data/useTreeData.tsx +603 -0
  327. package/src/stately/datepicker/IncompleteDate.tsx +427 -0
  328. package/src/stately/datepicker/placeholders.tsx +116 -0
  329. package/src/stately/datepicker/types.tsx +169 -0
  330. package/src/stately/datepicker/useDateFieldState.tsx +564 -0
  331. package/src/stately/datepicker/useDatePickerState.tsx +244 -0
  332. package/src/stately/datepicker/useDateRangePickerState.tsx +397 -0
  333. package/src/stately/datepicker/useTimeFieldState.tsx +123 -0
  334. package/src/stately/datepicker/utils.tsx +316 -0
  335. package/src/stately/dnd/useDraggableCollectionState.tsx +191 -0
  336. package/src/stately/dnd/useDroppableCollectionState.tsx +288 -0
  337. package/src/stately/layout/GridLayout.tsx +449 -0
  338. package/src/stately/layout/ListLayout.tsx +872 -0
  339. package/src/stately/layout/TableLayout.tsx +793 -0
  340. package/src/stately/layout/WaterfallLayout.tsx +399 -0
  341. package/src/stately/toast/useToastState.tsx +219 -0
  342. package/src/stately/virtualizer/Layout.tsx +105 -0
  343. package/src/stately/virtualizer/LayoutInfo.tsx +127 -0
  344. package/src/stately/virtualizer/OverscanManager.tsx +56 -0
  345. package/src/stately/virtualizer/Point.tsx +47 -0
  346. package/src/stately/virtualizer/Rect.tsx +194 -0
  347. package/src/stately/virtualizer/ReusableView.tsx +101 -0
  348. package/src/stately/virtualizer/Size.tsx +48 -0
  349. package/src/stately/virtualizer/Virtualizer.tsx +408 -0
  350. package/src/stately/virtualizer/types.tsx +48 -0
  351. package/src/stately/virtualizer/useVirtualizerState.tsx +138 -0
  352. package/src/stately/virtualizer/utils.tsx +32 -0
  353. package/src/textfield/useTextField.ts +3 -0
  354. package/src/toast/useToast.tsx +105 -0
  355. package/src/toast/useToastRegion.tsx +223 -0
  356. package/src/upstream-exports/react-aria/I18nProvider.tsx +17 -0
  357. package/src/upstream-exports/react-aria/ListDropTargetDelegate.tsx +15 -0
  358. package/src/upstream-exports/react-aria/PortalProvider.tsx +19 -0
  359. package/src/upstream-exports/react-aria/SSRProvider.tsx +15 -0
  360. package/src/upstream-exports/react-aria/VisuallyHidden.tsx +15 -0
  361. package/src/upstream-exports/react-aria/filterDOMProps.tsx +3 -0
  362. package/src/upstream-exports/react-aria/mergeProps.tsx +14 -0
  363. package/src/upstream-exports/react-aria/private/dnd/DragManager.tsx +3 -0
  364. package/src/upstream-exports/react-aria/private/interactions/PressResponder.tsx +3 -0
  365. package/src/upstream-exports/react-aria/private/utils/isFocusable.tsx +3 -0
  366. package/src/upstream-exports/react-aria/private/utils/shadowdom/DOMFunctions.tsx +8 -0
  367. package/src/upstream-exports/react-aria/private/utils/useId.tsx +3 -0
  368. package/src/upstream-exports/react-aria/private/utils/useLabels.tsx +3 -0
  369. package/src/upstream-exports/react-aria/private/virtualizer/ScrollView.tsx +3 -0
  370. package/src/upstream-exports/react-aria/private/virtualizer/VirtualizerItem.tsx +3 -0
  371. package/src/upstream-exports/react-aria/useButton.tsx +22 -0
  372. package/src/upstream-exports/react-aria/useCalendar.tsx +37 -0
  373. package/src/upstream-exports/react-aria/useClipboard.tsx +23 -0
  374. package/src/upstream-exports/react-aria/useColorArea.tsx +19 -0
  375. package/src/upstream-exports/react-aria/useColorField.tsx +20 -0
  376. package/src/upstream-exports/react-aria/useColorSlider.tsx +19 -0
  377. package/src/upstream-exports/react-aria/useColorSwatch.tsx +15 -0
  378. package/src/upstream-exports/react-aria/useColorWheel.tsx +19 -0
  379. package/src/upstream-exports/react-aria/useDateField.tsx +23 -0
  380. package/src/upstream-exports/react-aria/useDatePicker.tsx +17 -0
  381. package/src/upstream-exports/react-aria/useDateRangePicker.tsx +24 -0
  382. package/src/upstream-exports/react-aria/useDraggableCollection.tsx +31 -0
  383. package/src/upstream-exports/react-aria/useDrop.tsx +33 -0
  384. package/src/upstream-exports/react-aria/useDroppableCollection.tsx +47 -0
  385. package/src/upstream-exports/react-aria/useFocusRing.tsx +16 -0
  386. package/src/upstream-exports/react-aria/useHover.tsx +17 -0
  387. package/src/upstream-exports/react-aria/useLocalizedStringFormatter.tsx +19 -0
  388. package/src/upstream-exports/react-aria/useObjectRef.tsx +14 -0
  389. package/src/upstream-exports/react-aria/useRangeCalendar.tsx +38 -0
  390. package/src/upstream-exports/react-aria/useTimeField.tsx +23 -0
  391. package/src/upstream-exports/react-aria/useToast.tsx +18 -0
  392. package/src/upstream-exports/react-stately/Color.tsx +23 -0
  393. package/src/upstream-exports/react-stately/private/form/useFormValidationState.tsx +11 -0
  394. package/src/upstream-exports/react-stately/useCalendarState.tsx +24 -0
  395. package/src/upstream-exports/react-stately/useColorAreaState.tsx +24 -0
  396. package/src/upstream-exports/react-stately/useColorFieldState.tsx +22 -0
  397. package/src/upstream-exports/react-stately/useColorPickerState.tsx +25 -0
  398. package/src/upstream-exports/react-stately/useColorSliderState.tsx +25 -0
  399. package/src/upstream-exports/react-stately/useColorWheelState.tsx +24 -0
  400. package/src/upstream-exports/react-stately/useDateFieldState.tsx +29 -0
  401. package/src/upstream-exports/react-stately/useDatePickerState.tsx +25 -0
  402. package/src/upstream-exports/react-stately/useDateRangePickerState.tsx +26 -0
  403. package/src/upstream-exports/react-stately/useDraggableCollectionState.tsx +19 -0
  404. package/src/upstream-exports/react-stately/useDroppableCollectionState.tsx +19 -0
  405. package/src/upstream-exports/react-stately/useRangeCalendarState.tsx +27 -0
  406. package/src/upstream-exports/react-stately/useTimeFieldState.tsx +26 -0
  407. package/src/upstream-exports/react-stately/useToastState.tsx +21 -0
  408. package/src/upstream-exports/react-stately/useVirtualizerState.tsx +22 -0
  409. package/src/utils/useLoadMore.tsx +89 -0
  410. package/src/virtualizer/ScrollView.tsx +401 -0
  411. package/src/virtualizer/Virtualizer.tsx +147 -0
  412. package/src/virtualizer/VirtualizerItem.tsx +108 -0
  413. package/src/virtualizer/useVirtualizerItem.tsx +57 -0
  414. package/src/virtualizer/utils.tsx +105 -0
  415. package/LICENSE +0 -21
  416. package/src/components/useDragAndDrop.ts +0 -164
@@ -0,0 +1,889 @@
1
+ /** @jsxImportSource octane */
2
+ // Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-stately/src/color/Color.ts).
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ import { clamp, toFixedNumber } from '../utils/number';
16
+ import {
17
+ ColorAxes,
18
+ ColorChannel,
19
+ ColorChannelRange,
20
+ ColorFormat,
21
+ ColorSpace,
22
+ Color as IColor,
23
+ } from './types';
24
+ import intlMessages from '../../intl/stately-color/index';
25
+ import { LocalizedStringDictionary, LocalizedStringFormatter } from '@internationalized/string';
26
+ import { NumberFormatter } from '@internationalized/number';
27
+
28
+ let dictionary = new LocalizedStringDictionary(intlMessages);
29
+
30
+ /** Parses a color from a string value. Throws an error if the string could not be parsed. */
31
+ export function parseColor(value: string): IColor {
32
+ let res = RGBColor.parse(value) || HSBColor.parse(value) || HSLColor.parse(value);
33
+ if (res) {
34
+ return res;
35
+ }
36
+
37
+ throw new Error('Invalid color value: ' + value);
38
+ }
39
+
40
+ export function normalizeColor(v: string | IColor): IColor {
41
+ if (typeof v === 'string') {
42
+ return parseColor(v);
43
+ } else {
44
+ return v;
45
+ }
46
+ }
47
+
48
+ /** Returns a list of color channels for a given color space. */
49
+ export function getColorChannels(
50
+ colorSpace: ColorSpace,
51
+ ): [ColorChannel, ColorChannel, ColorChannel] {
52
+ switch (colorSpace) {
53
+ case 'rgb':
54
+ return RGBColor.colorChannels;
55
+ case 'hsl':
56
+ return HSLColor.colorChannels;
57
+ case 'hsb':
58
+ return HSBColor.colorChannels;
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Returns the hue value normalized to the range of 0 to 360.
64
+ */
65
+ export function normalizeHue(hue: number): number {
66
+ if (hue === 360) {
67
+ return hue;
68
+ }
69
+
70
+ return ((hue % 360) + 360) % 360;
71
+ }
72
+
73
+ // Lightness threshold between orange and brown.
74
+ const ORANGE_LIGHTNESS_THRESHOLD = 0.68;
75
+ // Lightness threshold between pure yellow and "yellow green".
76
+ const YELLOW_GREEN_LIGHTNESS_THRESHOLD = 0.85;
77
+ // The maximum lightness considered to be "dark".
78
+ const MAX_DARK_LIGHTNESS = 0.55;
79
+ // The chroma threshold between gray and color.
80
+ const GRAY_THRESHOLD = 0.001;
81
+ const OKLCH_HUES: [number, string][] = [
82
+ [0, 'pink'],
83
+ [15, 'red'],
84
+ [48, 'orange'],
85
+ [94, 'yellow'],
86
+ [135, 'green'],
87
+ [175, 'cyan'],
88
+ [264, 'blue'],
89
+ [284, 'purple'],
90
+ [320, 'magenta'],
91
+ [349, 'pink'],
92
+ ];
93
+
94
+ abstract class Color implements IColor {
95
+ abstract toFormat(format: ColorFormat): IColor;
96
+ abstract toString(format: ColorFormat | 'css'): string;
97
+ abstract clone(): IColor;
98
+ abstract getChannelRange(channel: ColorChannel): ColorChannelRange;
99
+ abstract getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions;
100
+ abstract formatChannelValue(channel: ColorChannel, locale: string): string;
101
+
102
+ toHexInt(): number {
103
+ return this.toFormat('rgb').toHexInt();
104
+ }
105
+
106
+ getChannelValue(channel: ColorChannel): number {
107
+ if (channel in this) {
108
+ return (this as any)[channel];
109
+ }
110
+
111
+ throw new Error('Unsupported color channel: ' + channel);
112
+ }
113
+
114
+ withChannelValue(channel: ColorChannel, value: number): IColor {
115
+ if (channel in this) {
116
+ let x = this.clone();
117
+ (x as any)[channel] = value;
118
+ return x;
119
+ }
120
+
121
+ throw new Error('Unsupported color channel: ' + channel);
122
+ }
123
+
124
+ getChannelName(channel: ColorChannel, locale: string) {
125
+ let strings =
126
+ LocalizedStringDictionary.getGlobalDictionaryForPackage('@react-stately/color') || dictionary;
127
+ return strings.getStringForLocale(channel, locale) as string;
128
+ }
129
+
130
+ abstract getColorSpace(): ColorSpace;
131
+
132
+ getColorSpaceAxes(xyChannels: { xChannel?: ColorChannel; yChannel?: ColorChannel }): ColorAxes {
133
+ let { xChannel, yChannel } = xyChannels;
134
+ let xCh = xChannel || this.getColorChannels().find((c) => c !== yChannel)!;
135
+ let yCh = yChannel || this.getColorChannels().find((c) => c !== xCh)!;
136
+ let zCh = this.getColorChannels().find((c) => c !== xCh && c !== yCh)!;
137
+
138
+ return { xChannel: xCh, yChannel: yCh, zChannel: zCh };
139
+ }
140
+
141
+ abstract getColorChannels(): [ColorChannel, ColorChannel, ColorChannel];
142
+
143
+ getColorName(locale: string): string {
144
+ // Convert to oklch color space, which has perceptually uniform lightness across all hues.
145
+ let [l, c, h] = toOKLCH(this);
146
+
147
+ let strings =
148
+ LocalizedStringDictionary.getGlobalDictionaryForPackage('@react-stately/color') || dictionary;
149
+ if (l > 0.999) {
150
+ return strings.getStringForLocale('white', locale) as string;
151
+ }
152
+
153
+ if (l < 0.001) {
154
+ return strings.getStringForLocale('black', locale) as string;
155
+ }
156
+
157
+ let hue: string;
158
+ [hue, l] = this.getOklchHue(l, c, h, locale);
159
+
160
+ let lightness = '';
161
+ let chroma = '';
162
+ if (c <= 0.1 && c >= GRAY_THRESHOLD) {
163
+ if (l >= 0.7) {
164
+ chroma = 'pale';
165
+ } else {
166
+ chroma = 'grayish';
167
+ }
168
+ } else if (c >= 0.15) {
169
+ chroma = 'vibrant';
170
+ }
171
+
172
+ if (l < 0.3) {
173
+ lightness = 'very dark';
174
+ } else if (l < MAX_DARK_LIGHTNESS) {
175
+ lightness = 'dark';
176
+ } else if (l < 0.7) {
177
+ // none
178
+ } else if (l < 0.85) {
179
+ lightness = 'light';
180
+ } else {
181
+ lightness = 'very light';
182
+ }
183
+
184
+ if (chroma) {
185
+ chroma = strings.getStringForLocale(chroma, locale) as string;
186
+ }
187
+
188
+ if (lightness) {
189
+ lightness = strings.getStringForLocale(lightness, locale) as string;
190
+ }
191
+
192
+ let alpha = this.getChannelValue('alpha');
193
+ let formatter = new LocalizedStringFormatter(locale, strings);
194
+ if (alpha < 1) {
195
+ let percentTransparent = new NumberFormatter(locale, { style: 'percent' }).format(1 - alpha);
196
+ return formatter
197
+ .format('transparentColorName', {
198
+ lightness,
199
+ chroma,
200
+ hue,
201
+ percentTransparent,
202
+ })
203
+ .replace(/\s+/g, ' ')
204
+ .trim();
205
+ } else {
206
+ return formatter
207
+ .format('colorName', {
208
+ lightness,
209
+ chroma,
210
+ hue,
211
+ })
212
+ .replace(/\s+/g, ' ')
213
+ .trim();
214
+ }
215
+ }
216
+
217
+ private getOklchHue(l: number, c: number, h: number, locale: string): [string, number] {
218
+ let strings =
219
+ LocalizedStringDictionary.getGlobalDictionaryForPackage('@react-stately/color') || dictionary;
220
+ if (c < GRAY_THRESHOLD) {
221
+ return [strings.getStringForLocale('gray', locale) as string, l];
222
+ }
223
+
224
+ for (let i = 0; i < OKLCH_HUES.length; i++) {
225
+ let [hue, hueName] = OKLCH_HUES[i];
226
+ let [nextHue, nextHueName] = OKLCH_HUES[i + 1] || [360, 'pink'];
227
+ if (h >= hue && h < nextHue) {
228
+ // Split orange hue into brown/orange depending on lightness.
229
+ if (hueName === 'orange') {
230
+ if (l < ORANGE_LIGHTNESS_THRESHOLD) {
231
+ hueName = 'brown';
232
+ } else {
233
+ // Adjust lightness.
234
+ l = l - ORANGE_LIGHTNESS_THRESHOLD + MAX_DARK_LIGHTNESS;
235
+ }
236
+ }
237
+
238
+ // If the hue is at least halfway to the next hue, add the next hue name as well.
239
+ if (h > hue + (nextHue - hue) / 2 && hueName !== nextHueName) {
240
+ hueName = `${hueName} ${nextHueName}`;
241
+ } else if (hueName === 'yellow' && l < YELLOW_GREEN_LIGHTNESS_THRESHOLD) {
242
+ // Yellow shifts toward green at lower lightnesses.
243
+ hueName = 'yellow green';
244
+ }
245
+
246
+ let name = (strings.getStringForLocale(hueName, locale) as string).toLocaleLowerCase(
247
+ locale,
248
+ );
249
+ return [name, l];
250
+ }
251
+ }
252
+
253
+ throw new Error('Unexpected hue');
254
+ }
255
+
256
+ getHueName(locale: string): string {
257
+ let [l, c, h] = toOKLCH(this);
258
+ let [name] = this.getOklchHue(l, c, h, locale);
259
+ return name;
260
+ }
261
+ }
262
+
263
+ class RGBColor extends Color {
264
+ private red: number;
265
+ private green: number;
266
+ private blue: number;
267
+ private alpha: number;
268
+
269
+ constructor(red: number, green: number, blue: number, alpha: number) {
270
+ super();
271
+ this.red = red;
272
+ this.green = green;
273
+ this.blue = blue;
274
+ this.alpha = alpha;
275
+ }
276
+
277
+ static parse(value: string) {
278
+ let colors: Array<number | undefined> = [];
279
+ // matching #rgb, #rgba, #rrggbb, #rrggbbaa
280
+ if (/^#[\da-f]+$/i.test(value) && [4, 5, 7, 9].includes(value.length)) {
281
+ const values = (value.length < 6 ? value.replace(/[^#]/gi, '$&$&') : value)
282
+ .slice(1)
283
+ .split('');
284
+ while (values.length > 0) {
285
+ colors.push(parseInt(values.splice(0, 2).join(''), 16));
286
+ }
287
+ colors[3] = colors[3] !== undefined ? colors[3] / 255 : undefined;
288
+ }
289
+
290
+ // matching rgb(rrr, ggg, bbb), rgba(rrr, ggg, bbb, 0.a)
291
+ const match = value.match(/^rgba?\((.*)\)$/);
292
+ if (match?.[1]) {
293
+ colors = match[1].split(',').map((value) => Number(value.trim()));
294
+ colors = colors.map((num, i) => {
295
+ return clamp(num ?? 0, 0, i < 3 ? 255 : 1);
296
+ });
297
+ }
298
+ if (colors[0] === undefined || colors[1] === undefined || colors[2] === undefined) {
299
+ return undefined;
300
+ }
301
+
302
+ return colors.length < 3
303
+ ? undefined
304
+ : new RGBColor(colors[0], colors[1], colors[2], colors[3] ?? 1);
305
+ }
306
+
307
+ toString(format: ColorFormat | 'css' = 'css') {
308
+ switch (format) {
309
+ case 'hex':
310
+ return (
311
+ '#' +
312
+ (
313
+ this.red.toString(16).padStart(2, '0') +
314
+ this.green.toString(16).padStart(2, '0') +
315
+ this.blue.toString(16).padStart(2, '0')
316
+ ).toUpperCase()
317
+ );
318
+ case 'hexa':
319
+ return (
320
+ '#' +
321
+ (
322
+ this.red.toString(16).padStart(2, '0') +
323
+ this.green.toString(16).padStart(2, '0') +
324
+ this.blue.toString(16).padStart(2, '0') +
325
+ Math.round(this.alpha * 255)
326
+ .toString(16)
327
+ .padStart(2, '0')
328
+ ).toUpperCase()
329
+ );
330
+ case 'rgb':
331
+ return `rgb(${this.red}, ${this.green}, ${this.blue})`;
332
+ case 'css':
333
+ case 'rgba':
334
+ return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;
335
+ default:
336
+ return this.toFormat(format).toString(format);
337
+ }
338
+ }
339
+
340
+ toFormat(format: ColorFormat): IColor {
341
+ switch (format) {
342
+ case 'hex':
343
+ case 'hexa':
344
+ case 'rgb':
345
+ case 'rgba':
346
+ return this;
347
+ case 'hsb':
348
+ case 'hsba':
349
+ return this.toHSB();
350
+ case 'hsl':
351
+ case 'hsla':
352
+ return this.toHSL();
353
+ default:
354
+ throw new Error('Unsupported color conversion: rgb -> ' + format);
355
+ }
356
+ }
357
+
358
+ toHexInt(): number {
359
+ return (this.red << 16) | (this.green << 8) | this.blue;
360
+ }
361
+
362
+ /**
363
+ * Converts an RGB color value to HSB.
364
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.
365
+ *
366
+ * @returns An HSBColor object.
367
+ */
368
+ private toHSB(): IColor {
369
+ const red = this.red / 255;
370
+ const green = this.green / 255;
371
+ const blue = this.blue / 255;
372
+ const min = Math.min(red, green, blue);
373
+ const brightness = Math.max(red, green, blue);
374
+ const chroma = brightness - min;
375
+ const saturation = brightness === 0 ? 0 : chroma / brightness;
376
+ let hue = 0; // achromatic
377
+
378
+ if (chroma !== 0) {
379
+ switch (brightness) {
380
+ case red:
381
+ hue = (green - blue) / chroma + (green < blue ? 6 : 0);
382
+ break;
383
+ case green:
384
+ hue = (blue - red) / chroma + 2;
385
+ break;
386
+ case blue:
387
+ hue = (red - green) / chroma + 4;
388
+ break;
389
+ }
390
+
391
+ hue /= 6;
392
+ }
393
+
394
+ return new HSBColor(
395
+ toFixedNumber(hue * 360, 2),
396
+ toFixedNumber(saturation * 100, 2),
397
+ toFixedNumber(brightness * 100, 2),
398
+ this.alpha,
399
+ );
400
+ }
401
+
402
+ /**
403
+ * Converts an RGB color value to HSL.
404
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.
405
+ *
406
+ * @returns An HSLColor object.
407
+ */
408
+ private toHSL(): IColor {
409
+ const red = this.red / 255;
410
+ const green = this.green / 255;
411
+ const blue = this.blue / 255;
412
+ const min = Math.min(red, green, blue);
413
+ const max = Math.max(red, green, blue);
414
+ const lightness = (max + min) / 2;
415
+ const chroma = max - min;
416
+ let hue: number;
417
+ let saturation: number;
418
+
419
+ if (chroma === 0) {
420
+ hue = saturation = 0; // achromatic
421
+ } else {
422
+ saturation = chroma / (lightness < 0.5 ? max + min : 2 - max - min);
423
+
424
+ switch (max) {
425
+ case red:
426
+ hue = (green - blue) / chroma + (green < blue ? 6 : 0);
427
+ break;
428
+ case green:
429
+ hue = (blue - red) / chroma + 2;
430
+ break;
431
+ case blue:
432
+ default:
433
+ hue = (red - green) / chroma + 4;
434
+ break;
435
+ }
436
+
437
+ hue /= 6;
438
+ }
439
+
440
+ return new HSLColor(
441
+ toFixedNumber(hue * 360, 2),
442
+ toFixedNumber(saturation * 100, 2),
443
+ toFixedNumber(lightness * 100, 2),
444
+ this.alpha,
445
+ );
446
+ }
447
+
448
+ clone(): IColor {
449
+ return new RGBColor(this.red, this.green, this.blue, this.alpha);
450
+ }
451
+
452
+ getChannelRange(channel: ColorChannel): ColorChannelRange {
453
+ switch (channel) {
454
+ case 'red':
455
+ case 'green':
456
+ case 'blue':
457
+ return { minValue: 0x0, maxValue: 0xff, step: 0x1, pageSize: 0x11 };
458
+ case 'alpha':
459
+ return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 };
460
+ default:
461
+ throw new Error('Unknown color channel: ' + channel);
462
+ }
463
+ }
464
+
465
+ getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions {
466
+ switch (channel) {
467
+ case 'red':
468
+ case 'green':
469
+ case 'blue':
470
+ return { style: 'decimal' };
471
+ case 'alpha':
472
+ return { style: 'percent' };
473
+ default:
474
+ throw new Error('Unknown color channel: ' + channel);
475
+ }
476
+ }
477
+
478
+ formatChannelValue(channel: ColorChannel, locale: string) {
479
+ let options = this.getChannelFormatOptions(channel);
480
+ let value = this.getChannelValue(channel);
481
+ return new NumberFormatter(locale, options).format(value);
482
+ }
483
+
484
+ getColorSpace(): ColorSpace {
485
+ return 'rgb';
486
+ }
487
+
488
+ static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = ['red', 'green', 'blue'];
489
+ getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {
490
+ return RGBColor.colorChannels;
491
+ }
492
+ }
493
+
494
+ // X = <negative/positive number with/without decimal places>
495
+ // before/after a comma, 0 or more whitespaces are allowed
496
+ // - hsb(X, X%, X%)
497
+ // - hsba(X, X%, X%, X)
498
+ const HSB_REGEX =
499
+ /hsb\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%)\)|hsba\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d(.\d+)?)\)/;
500
+
501
+ class HSBColor extends Color {
502
+ private hue: number;
503
+ private saturation: number;
504
+ private brightness: number;
505
+ private alpha: number;
506
+
507
+ constructor(hue: number, saturation: number, brightness: number, alpha: number) {
508
+ super();
509
+ this.hue = hue;
510
+ this.saturation = saturation;
511
+ this.brightness = brightness;
512
+ this.alpha = alpha;
513
+ }
514
+
515
+ static parse(value: string): HSBColor | void {
516
+ let m: RegExpMatchArray | null;
517
+ if ((m = value.match(HSB_REGEX))) {
518
+ const [h, s, b, a] = (m[1] ?? m[2]).split(',').map((n) => Number(n.trim().replace('%', '')));
519
+ return new HSBColor(normalizeHue(h), clamp(s, 0, 100), clamp(b, 0, 100), clamp(a ?? 1, 0, 1));
520
+ }
521
+ }
522
+
523
+ toString(format: ColorFormat | 'css' = 'css') {
524
+ switch (format) {
525
+ case 'css':
526
+ return this.toHSL().toString('css');
527
+ case 'hex':
528
+ return this.toRGB().toString('hex');
529
+ case 'hexa':
530
+ return this.toRGB().toString('hexa');
531
+ case 'hsb':
532
+ return `hsb(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%)`;
533
+ case 'hsba':
534
+ return `hsba(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%, ${this.alpha})`;
535
+ default:
536
+ return this.toFormat(format).toString(format);
537
+ }
538
+ }
539
+
540
+ toFormat(format: ColorFormat): IColor {
541
+ switch (format) {
542
+ case 'hsb':
543
+ case 'hsba':
544
+ return this;
545
+ case 'hsl':
546
+ case 'hsla':
547
+ return this.toHSL();
548
+ case 'rgb':
549
+ case 'rgba':
550
+ return this.toRGB();
551
+ default:
552
+ throw new Error('Unsupported color conversion: hsb -> ' + format);
553
+ }
554
+ }
555
+
556
+ /**
557
+ * Converts a HSB color to HSL.
558
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
559
+ *
560
+ * @returns An HSLColor object.
561
+ */
562
+ private toHSL(): IColor {
563
+ let saturation = this.saturation / 100;
564
+ let brightness = this.brightness / 100;
565
+ let lightness = brightness * (1 - saturation / 2);
566
+ saturation =
567
+ lightness === 0 || lightness === 1
568
+ ? 0
569
+ : (brightness - lightness) / Math.min(lightness, 1 - lightness);
570
+
571
+ return new HSLColor(
572
+ toFixedNumber(this.hue, 2),
573
+ toFixedNumber(saturation * 100, 2),
574
+ toFixedNumber(lightness * 100, 2),
575
+ this.alpha,
576
+ );
577
+ }
578
+
579
+ /**
580
+ * Converts a HSV color value to RGB. Conversion formula adapted from
581
+ * https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
582
+ *
583
+ * @returns An RGBColor object.
584
+ */
585
+ private toRGB(): IColor {
586
+ let hue = this.hue;
587
+ let saturation = this.saturation / 100;
588
+ let brightness = this.brightness / 100;
589
+ let fn = (n: number, k = (n + hue / 60) % 6) =>
590
+ brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0);
591
+ return new RGBColor(
592
+ Math.round(fn(5) * 255),
593
+ Math.round(fn(3) * 255),
594
+ Math.round(fn(1) * 255),
595
+ this.alpha,
596
+ );
597
+ }
598
+
599
+ clone(): IColor {
600
+ return new HSBColor(this.hue, this.saturation, this.brightness, this.alpha);
601
+ }
602
+
603
+ getChannelRange(channel: ColorChannel): ColorChannelRange {
604
+ switch (channel) {
605
+ case 'hue':
606
+ return { minValue: 0, maxValue: 360, step: 1, pageSize: 15 };
607
+ case 'saturation':
608
+ case 'brightness':
609
+ return { minValue: 0, maxValue: 100, step: 1, pageSize: 10 };
610
+ case 'alpha':
611
+ return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 };
612
+ default:
613
+ throw new Error('Unknown color channel: ' + channel);
614
+ }
615
+ }
616
+
617
+ getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions {
618
+ switch (channel) {
619
+ case 'hue':
620
+ return { style: 'unit', unit: 'degree', unitDisplay: 'narrow' };
621
+ case 'saturation':
622
+ case 'brightness':
623
+ case 'alpha':
624
+ return { style: 'percent' };
625
+ default:
626
+ throw new Error('Unknown color channel: ' + channel);
627
+ }
628
+ }
629
+
630
+ formatChannelValue(channel: ColorChannel, locale: string) {
631
+ let options = this.getChannelFormatOptions(channel);
632
+ let value = this.getChannelValue(channel);
633
+ if (channel === 'saturation' || channel === 'brightness') {
634
+ value /= 100;
635
+ }
636
+ return new NumberFormatter(locale, options).format(value);
637
+ }
638
+
639
+ getColorSpace(): ColorSpace {
640
+ return 'hsb';
641
+ }
642
+
643
+ static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = [
644
+ 'hue',
645
+ 'saturation',
646
+ 'brightness',
647
+ ];
648
+ getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {
649
+ return HSBColor.colorChannels;
650
+ }
651
+ }
652
+
653
+ // X = <negative/positive number with/without decimal places>
654
+ // before/after a comma, 0 or more whitespaces are allowed
655
+ // - hsl(X, X%, X%)
656
+ // - hsla(X, X%, X%, X)
657
+ const HSL_REGEX =
658
+ /hsl\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%)\)|hsla\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d(.\d+)?)\)/;
659
+
660
+ class HSLColor extends Color {
661
+ private hue: number;
662
+ private saturation: number;
663
+ private lightness: number;
664
+ private alpha: number;
665
+
666
+ constructor(hue: number, saturation: number, lightness: number, alpha: number) {
667
+ super();
668
+ this.hue = hue;
669
+ this.saturation = saturation;
670
+ this.lightness = lightness;
671
+ this.alpha = alpha;
672
+ }
673
+
674
+ static parse(value: string): HSLColor | void {
675
+ let m: RegExpMatchArray | null;
676
+ if ((m = value.match(HSL_REGEX))) {
677
+ const [h, s, l, a] = (m[1] ?? m[2]).split(',').map((n) => Number(n.trim().replace('%', '')));
678
+ return new HSLColor(normalizeHue(h), clamp(s, 0, 100), clamp(l, 0, 100), clamp(a ?? 1, 0, 1));
679
+ }
680
+ }
681
+
682
+ toString(format: ColorFormat | 'css' = 'css') {
683
+ switch (format) {
684
+ case 'hex':
685
+ return this.toRGB().toString('hex');
686
+ case 'hexa':
687
+ return this.toRGB().toString('hexa');
688
+ case 'hsl':
689
+ return `hsl(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.lightness, 2)}%)`;
690
+ case 'css':
691
+ case 'hsla':
692
+ return `hsla(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.lightness, 2)}%, ${this.alpha})`;
693
+ default:
694
+ return this.toFormat(format).toString(format);
695
+ }
696
+ }
697
+ toFormat(format: ColorFormat): IColor {
698
+ switch (format) {
699
+ case 'hsl':
700
+ case 'hsla':
701
+ return this;
702
+ case 'hsb':
703
+ case 'hsba':
704
+ return this.toHSB();
705
+ case 'rgb':
706
+ case 'rgba':
707
+ return this.toRGB();
708
+ default:
709
+ throw new Error('Unsupported color conversion: hsl -> ' + format);
710
+ }
711
+ }
712
+
713
+ /**
714
+ * Converts a HSL color to HSB.
715
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV.
716
+ *
717
+ * @returns An HSBColor object.
718
+ */
719
+ private toHSB(): IColor {
720
+ let saturation = this.saturation / 100;
721
+ let lightness = this.lightness / 100;
722
+ let brightness = lightness + saturation * Math.min(lightness, 1 - lightness);
723
+ saturation = brightness === 0 ? 0 : 2 * (1 - lightness / brightness);
724
+ return new HSBColor(
725
+ toFixedNumber(this.hue, 2),
726
+ toFixedNumber(saturation * 100, 2),
727
+ toFixedNumber(brightness * 100, 2),
728
+ this.alpha,
729
+ );
730
+ }
731
+
732
+ /**
733
+ * Converts a HSL color to RGB. Conversion formula adapted from
734
+ * https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative.
735
+ *
736
+ * @returns An RGBColor object.
737
+ */
738
+ private toRGB(): IColor {
739
+ let hue = this.hue;
740
+ let saturation = this.saturation / 100;
741
+ let lightness = this.lightness / 100;
742
+ let a = saturation * Math.min(lightness, 1 - lightness);
743
+ let fn = (n: number, k = (n + hue / 30) % 12) =>
744
+ lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
745
+ return new RGBColor(
746
+ Math.round(fn(0) * 255),
747
+ Math.round(fn(8) * 255),
748
+ Math.round(fn(4) * 255),
749
+ this.alpha,
750
+ );
751
+ }
752
+
753
+ clone(): IColor {
754
+ return new HSLColor(this.hue, this.saturation, this.lightness, this.alpha);
755
+ }
756
+
757
+ getChannelRange(channel: ColorChannel): ColorChannelRange {
758
+ switch (channel) {
759
+ case 'hue':
760
+ return { minValue: 0, maxValue: 360, step: 1, pageSize: 15 };
761
+ case 'saturation':
762
+ case 'lightness':
763
+ return { minValue: 0, maxValue: 100, step: 1, pageSize: 10 };
764
+ case 'alpha':
765
+ return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 };
766
+ default:
767
+ throw new Error('Unknown color channel: ' + channel);
768
+ }
769
+ }
770
+
771
+ getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions {
772
+ switch (channel) {
773
+ case 'hue':
774
+ return { style: 'unit', unit: 'degree', unitDisplay: 'narrow' };
775
+ case 'saturation':
776
+ case 'lightness':
777
+ case 'alpha':
778
+ return { style: 'percent' };
779
+ default:
780
+ throw new Error('Unknown color channel: ' + channel);
781
+ }
782
+ }
783
+
784
+ formatChannelValue(channel: ColorChannel, locale: string) {
785
+ let options = this.getChannelFormatOptions(channel);
786
+ let value = this.getChannelValue(channel);
787
+ if (channel === 'saturation' || channel === 'lightness') {
788
+ value /= 100;
789
+ }
790
+ return new NumberFormatter(locale, options).format(value);
791
+ }
792
+
793
+ getColorSpace(): ColorSpace {
794
+ return 'hsl';
795
+ }
796
+
797
+ static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = [
798
+ 'hue',
799
+ 'saturation',
800
+ 'lightness',
801
+ ];
802
+ getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {
803
+ return HSLColor.colorChannels;
804
+ }
805
+ }
806
+
807
+ // https://www.w3.org/TR/css-color-4/#color-conversion-code
808
+ function toOKLCH(color: Color) {
809
+ let rgb = color.toFormat('rgb');
810
+ let red = rgb.getChannelValue('red') / 255;
811
+ let green = rgb.getChannelValue('green') / 255;
812
+ let blue = rgb.getChannelValue('blue') / 255;
813
+ [red, green, blue] = lin_sRGB(red, green, blue);
814
+ let [x, y, z] = lin_sRGB_to_XYZ(red, green, blue);
815
+ let [l, a, b] = XYZ_to_OKLab(x, y, z);
816
+ return OKLab_to_OKLCH(l, a, b);
817
+ }
818
+
819
+ function OKLab_to_OKLCH(l: number, a: number, b: number): [number, number, number] {
820
+ var hue = (Math.atan2(b, a) * 180) / Math.PI;
821
+ return [
822
+ l,
823
+ Math.sqrt(a ** 2 + b ** 2), // Chroma
824
+ hue >= 0 ? hue : hue + 360, // Hue, in degrees [0 to 360)
825
+ ];
826
+ }
827
+
828
+ function lin_sRGB(r: number, g: number, b: number): [number, number, number] {
829
+ // convert an array of sRGB values
830
+ // where in-gamut values are in the range [0 - 1]
831
+ // to linear light (un-companded) form.
832
+ // https://en.wikipedia.org/wiki/SRGB
833
+ // Extended transfer function:
834
+ // for negative values, linear portion is extended on reflection of axis,
835
+ // then reflected power function is used.
836
+ return [lin_sRGB_component(r), lin_sRGB_component(g), lin_sRGB_component(b)];
837
+ }
838
+
839
+ function lin_sRGB_component(val: number) {
840
+ let sign = val < 0 ? -1 : 1;
841
+ let abs = Math.abs(val);
842
+
843
+ if (abs <= 0.04045) {
844
+ return val / 12.92;
845
+ }
846
+
847
+ return sign * Math.pow((abs + 0.055) / 1.055, 2.4);
848
+ }
849
+
850
+ function lin_sRGB_to_XYZ(r: number, g: number, b: number) {
851
+ // convert an array of linear-light sRGB values to CIE XYZ
852
+ // using sRGB's own white, D65 (no chromatic adaptation)
853
+ const M = [
854
+ 506752 / 1228815,
855
+ 87881 / 245763,
856
+ 12673 / 70218,
857
+ 87098 / 409605,
858
+ 175762 / 245763,
859
+ 12673 / 175545,
860
+ 7918 / 409605,
861
+ 87881 / 737289,
862
+ 1001167 / 1053270,
863
+ ];
864
+ return multiplyMatrix(M, r, g, b);
865
+ }
866
+
867
+ function XYZ_to_OKLab(x: number, y: number, z: number) {
868
+ // Given XYZ relative to D65, convert to OKLab
869
+ const XYZtoLMS = [
870
+ 0.819022437996703, 0.3619062600528904, -0.1288737815209879, 0.0329836539323885,
871
+ 0.9292868615863434, 0.0361446663506424, 0.0481771893596242, 0.2642395317527308,
872
+ 0.6335478284694309,
873
+ ];
874
+ const LMStoOKLab = [
875
+ 0.210454268309314, 0.7936177747023054, -0.0040720430116193, 1.9779985324311684,
876
+ -2.4285922420485799, 0.450593709617411, 0.0259040424655478, 0.7827717124575296,
877
+ -0.8086757549230774,
878
+ ];
879
+
880
+ let [a, b, c] = multiplyMatrix(XYZtoLMS, x, y, z);
881
+ return multiplyMatrix(LMStoOKLab, Math.cbrt(a), Math.cbrt(b), Math.cbrt(c));
882
+ }
883
+
884
+ function multiplyMatrix(m: number[], x: number, y: number, z: number): [number, number, number] {
885
+ let a = m[0] * x + m[1] * y + m[2] * z;
886
+ let b = m[3] * x + m[4] * y + m[5] * z;
887
+ let c = m[6] * x + m[7] * y + m[8] * z;
888
+ return [a, b, c];
889
+ }