@itwin/itwinui-react 3.0.3 → 3.0.5

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 (498) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/cjs/core/Alert/Alert.js +46 -106
  3. package/cjs/core/Avatar/Avatar.js +21 -58
  4. package/cjs/core/AvatarGroup/AvatarGroup.js +26 -64
  5. package/cjs/core/Backdrop/Backdrop.js +8 -16
  6. package/cjs/core/Badge/Badge.js +22 -39
  7. package/cjs/core/Breadcrumbs/Breadcrumbs.js +61 -138
  8. package/cjs/core/ButtonGroup/ButtonGroup.js +32 -68
  9. package/cjs/core/Buttons/Button.js +11 -57
  10. package/cjs/core/Buttons/DropdownButton.js +15 -49
  11. package/cjs/core/Buttons/IconButton.js +13 -53
  12. package/cjs/core/Buttons/IdeasButton.js +8 -20
  13. package/cjs/core/Buttons/SplitButton.js +43 -103
  14. package/cjs/core/Carousel/Carousel.js +54 -78
  15. package/cjs/core/Carousel/CarouselContext.js +4 -4
  16. package/cjs/core/Carousel/CarouselDot.js +12 -23
  17. package/cjs/core/Carousel/CarouselDotsList.js +92 -153
  18. package/cjs/core/Carousel/CarouselNavigation.js +41 -84
  19. package/cjs/core/Carousel/CarouselSlide.js +26 -49
  20. package/cjs/core/Carousel/CarouselSlider.js +47 -66
  21. package/cjs/core/Checkbox/Checkbox.js +32 -88
  22. package/cjs/core/ColorPicker/ColorBuilder.js +174 -292
  23. package/cjs/core/ColorPicker/ColorInputPanel.js +246 -411
  24. package/cjs/core/ColorPicker/ColorPalette.js +23 -47
  25. package/cjs/core/ColorPicker/ColorPicker.js +53 -87
  26. package/cjs/core/ColorPicker/ColorPickerContext.js +9 -11
  27. package/cjs/core/ColorPicker/ColorSwatch.js +15 -40
  28. package/cjs/core/ComboBox/ComboBox.js +280 -402
  29. package/cjs/core/ComboBox/ComboBoxEndIcon.js +12 -28
  30. package/cjs/core/ComboBox/ComboBoxInput.js +131 -207
  31. package/cjs/core/ComboBox/ComboBoxInputContainer.js +12 -35
  32. package/cjs/core/ComboBox/ComboBoxMenu.js +43 -87
  33. package/cjs/core/ComboBox/ComboBoxMenuItem.js +21 -73
  34. package/cjs/core/ComboBox/ComboBoxMultipleContainer.js +7 -13
  35. package/cjs/core/ComboBox/helpers.js +43 -47
  36. package/cjs/core/DatePicker/DatePicker.js +333 -569
  37. package/cjs/core/Dialog/Dialog.js +36 -65
  38. package/cjs/core/Dialog/DialogBackdrop.js +27 -47
  39. package/cjs/core/Dialog/DialogButtonBar.js +3 -3
  40. package/cjs/core/Dialog/DialogContent.js +18 -26
  41. package/cjs/core/Dialog/DialogContext.js +5 -5
  42. package/cjs/core/Dialog/DialogDragContext.js +8 -8
  43. package/cjs/core/Dialog/DialogMain.js +116 -183
  44. package/cjs/core/Dialog/DialogTitleBar.js +20 -67
  45. package/cjs/core/Dialog/DialogTitleBarTitle.js +3 -3
  46. package/cjs/core/Divider/Divider.js +8 -14
  47. package/cjs/core/DropdownMenu/DropdownMenu.js +46 -80
  48. package/cjs/core/ExpandableBlock/ExpandableBlock.js +101 -206
  49. package/cjs/core/Fieldset/Fieldset.js +14 -25
  50. package/cjs/core/FileUpload/FileEmptyCard.js +17 -43
  51. package/cjs/core/FileUpload/FileUpload.js +42 -88
  52. package/cjs/core/FileUpload/FileUploadCard.js +84 -169
  53. package/cjs/core/FileUpload/FileUploadTemplate.js +16 -51
  54. package/cjs/core/Flex/Flex.js +77 -93
  55. package/cjs/core/Footer/Footer.js +64 -103
  56. package/cjs/core/Footer/FooterItem.js +3 -3
  57. package/cjs/core/Footer/FooterList.js +3 -3
  58. package/cjs/core/Footer/FooterSeparator.js +5 -8
  59. package/cjs/core/Header/Header.js +22 -67
  60. package/cjs/core/Header/HeaderBasicButton.js +13 -24
  61. package/cjs/core/Header/HeaderBreadcrumbs.js +14 -38
  62. package/cjs/core/Header/HeaderButton.js +22 -76
  63. package/cjs/core/Header/HeaderDropdownButton.js +20 -48
  64. package/cjs/core/Header/HeaderLogo.js +11 -42
  65. package/cjs/core/Header/HeaderSplitButton.js +21 -66
  66. package/cjs/core/Icon/Icon.js +18 -32
  67. package/cjs/core/InformationPanel/InformationPanel.js +42 -77
  68. package/cjs/core/InformationPanel/InformationPanelBody.js +4 -6
  69. package/cjs/core/InformationPanel/InformationPanelContent.js +8 -20
  70. package/cjs/core/InformationPanel/InformationPanelHeader.js +14 -34
  71. package/cjs/core/InformationPanel/InformationPanelWrapper.js +4 -6
  72. package/cjs/core/Input/Input.js +10 -18
  73. package/cjs/core/InputGrid/InputGrid.js +8 -17
  74. package/cjs/core/InputGroup/InputGroup.js +25 -72
  75. package/cjs/core/InputWithDecorations/InputWithDecorations.js +23 -51
  76. package/cjs/core/Label/Label.js +11 -32
  77. package/cjs/core/LabeledInput/LabeledInput.js +20 -70
  78. package/cjs/core/LabeledSelect/LabeledSelect.js +28 -77
  79. package/cjs/core/LabeledTextarea/LabeledTextarea.js +7 -13
  80. package/cjs/core/LinkAction/LinkAction.js +3 -3
  81. package/cjs/core/List/List.js +3 -3
  82. package/cjs/core/List/ListItem.js +35 -55
  83. package/cjs/core/Menu/Menu.js +53 -66
  84. package/cjs/core/Menu/MenuDivider.js +4 -4
  85. package/cjs/core/Menu/MenuExtraContent.js +4 -4
  86. package/cjs/core/Menu/MenuItem.js +92 -168
  87. package/cjs/core/Menu/MenuItemSkeleton.js +19 -54
  88. package/cjs/core/Modal/Modal.js +11 -38
  89. package/cjs/core/Modal/ModalButtonBar.js +4 -7
  90. package/cjs/core/Modal/ModalContent.js +3 -3
  91. package/cjs/core/NonIdealState/ErrorPage.js +131 -187
  92. package/cjs/core/NonIdealState/NonIdealState.js +12 -77
  93. package/cjs/core/NotificationMarker/NotificationMarker.js +8 -29
  94. package/cjs/core/Overlay/Overlay.d.ts +20 -24
  95. package/cjs/core/Overlay/Overlay.js +50 -64
  96. package/cjs/core/Popover/Popover.js +87 -157
  97. package/cjs/core/ProgressIndicators/ProgressLinear.js +11 -49
  98. package/cjs/core/ProgressIndicators/ProgressRadial.js +19 -51
  99. package/cjs/core/Radio/Radio.js +12 -54
  100. package/cjs/core/RadioTiles/RadioTile.js +14 -80
  101. package/cjs/core/RadioTiles/RadioTileGroup.js +9 -16
  102. package/cjs/core/SearchBox/SearchBox.js +104 -221
  103. package/cjs/core/Select/Select.js +141 -282
  104. package/cjs/core/Select/SelectTag.js +9 -21
  105. package/cjs/core/Select/SelectTagContainer.js +14 -30
  106. package/cjs/core/SideNavigation/SideNavigation.js +29 -138
  107. package/cjs/core/SideNavigation/SidenavButton.js +8 -30
  108. package/cjs/core/SideNavigation/SidenavSubmenu.js +9 -23
  109. package/cjs/core/SideNavigation/SidenavSubmenuHeader.js +10 -29
  110. package/cjs/core/SkipToContentLink/SkipToContentLink.js +8 -20
  111. package/cjs/core/Slider/Slider.js +195 -376
  112. package/cjs/core/Slider/Thumb.js +57 -108
  113. package/cjs/core/Slider/Track.js +55 -83
  114. package/cjs/core/StatusMessage/StatusMessage.js +12 -34
  115. package/cjs/core/Stepper/Stepper.js +21 -80
  116. package/cjs/core/Stepper/StepperStep.js +36 -109
  117. package/cjs/core/Stepper/WorkflowDiagram.js +15 -38
  118. package/cjs/core/Stepper/WorkflowDiagramStep.js +11 -39
  119. package/cjs/core/Surface/Surface.js +54 -94
  120. package/cjs/core/Table/SubRowExpander.js +15 -37
  121. package/cjs/core/Table/Table.js +419 -763
  122. package/cjs/core/Table/TableCell.js +63 -113
  123. package/cjs/core/Table/TablePaginator.js +136 -312
  124. package/cjs/core/Table/TableRowMemoized.js +64 -137
  125. package/cjs/core/Table/actionHandlers/expandHandler.js +12 -12
  126. package/cjs/core/Table/actionHandlers/filterHandler.js +17 -25
  127. package/cjs/core/Table/actionHandlers/index.js +14 -56
  128. package/cjs/core/Table/actionHandlers/resizeHandler.js +13 -13
  129. package/cjs/core/Table/actionHandlers/selectHandler.js +98 -128
  130. package/cjs/core/Table/cells/DefaultCell.js +13 -48
  131. package/cjs/core/Table/cells/EditableCell.js +46 -75
  132. package/cjs/core/Table/cells/index.js +6 -16
  133. package/cjs/core/Table/columns/actionColumn.js +67 -97
  134. package/cjs/core/Table/columns/expanderColumn.js +32 -46
  135. package/cjs/core/Table/columns/index.js +11 -41
  136. package/cjs/core/Table/columns/selectionColumn.js +29 -57
  137. package/cjs/core/Table/filters/BaseFilter.js +13 -24
  138. package/cjs/core/Table/filters/DateRangeFilter/DatePickerInput.js +52 -120
  139. package/cjs/core/Table/filters/DateRangeFilter/DateRangeFilter.js +60 -120
  140. package/cjs/core/Table/filters/FilterButtonBar.js +16 -39
  141. package/cjs/core/Table/filters/FilterToggle.js +26 -62
  142. package/cjs/core/Table/filters/NumberRangeFilter/NumberRangeFilter.js +36 -58
  143. package/cjs/core/Table/filters/TextFilter/TextFilter.js +28 -40
  144. package/cjs/core/Table/filters/customFilterFunctions.js +14 -16
  145. package/cjs/core/Table/filters/defaultFilterFunctions.js +81 -86
  146. package/cjs/core/Table/filters/index.js +11 -35
  147. package/cjs/core/Table/filters/tableFilters.js +32 -44
  148. package/cjs/core/Table/filters/types.js +2 -2
  149. package/cjs/core/Table/hooks/index.js +19 -67
  150. package/cjs/core/Table/hooks/useColumnDragAndDrop.js +86 -101
  151. package/cjs/core/Table/hooks/useExpanderCell.js +25 -33
  152. package/cjs/core/Table/hooks/useResizeColumns.js +290 -362
  153. package/cjs/core/Table/hooks/useScrollToRow.js +38 -46
  154. package/cjs/core/Table/hooks/useSelectionCell.js +10 -17
  155. package/cjs/core/Table/hooks/useStickyColumns.js +62 -64
  156. package/cjs/core/Table/hooks/useSubRowFiltering.js +88 -95
  157. package/cjs/core/Table/hooks/useSubRowSelection.js +31 -32
  158. package/cjs/core/Table/index.js +18 -78
  159. package/cjs/core/Table/utils.js +40 -42
  160. package/cjs/core/Tabs/Tabs.d.ts +3 -5
  161. package/cjs/core/Tabs/Tabs.js +235 -422
  162. package/cjs/core/Tag/Tag.js +15 -42
  163. package/cjs/core/Tag/TagContainer.js +11 -23
  164. package/cjs/core/Textarea/Textarea.js +6 -11
  165. package/cjs/core/ThemeProvider/ThemeContext.js +4 -4
  166. package/cjs/core/ThemeProvider/ThemeProvider.js +52 -105
  167. package/cjs/core/Tile/Tile.js +230 -410
  168. package/cjs/core/TimePicker/TimePicker.js +234 -458
  169. package/cjs/core/Toast/Toast.js +107 -204
  170. package/cjs/core/Toast/Toaster.js +77 -103
  171. package/cjs/core/ToggleSwitch/ToggleSwitch.js +23 -66
  172. package/cjs/core/Tooltip/Tooltip.js +91 -137
  173. package/cjs/core/TransferList/TransferList.js +103 -177
  174. package/cjs/core/Tree/Tree.js +129 -204
  175. package/cjs/core/Tree/TreeContext.js +9 -9
  176. package/cjs/core/Tree/TreeNode.js +104 -207
  177. package/cjs/core/Tree/TreeNodeExpander.js +12 -26
  178. package/cjs/core/Typography/Anchor.js +3 -3
  179. package/cjs/core/Typography/Blockquote.js +10 -18
  180. package/cjs/core/Typography/Code.js +3 -3
  181. package/cjs/core/Typography/Kbd.js +21 -30
  182. package/cjs/core/Typography/Text.js +13 -26
  183. package/cjs/core/VisuallyHidden/VisuallyHidden.js +8 -14
  184. package/cjs/core/utils/color/ColorValue.js +453 -535
  185. package/cjs/core/utils/color/index.js +4 -4
  186. package/cjs/core/utils/components/AutoclearingHiddenLiveRegion.js +13 -20
  187. package/cjs/core/utils/components/Box.js +3 -3
  188. package/cjs/core/utils/components/ButtonBase.js +20 -38
  189. package/cjs/core/utils/components/FocusTrap.js +38 -47
  190. package/cjs/core/utils/components/InputContainer.js +19 -58
  191. package/cjs/core/utils/components/InputFlexContainer.js +8 -24
  192. package/cjs/core/utils/components/MiddleTextTruncation.js +22 -32
  193. package/cjs/core/utils/components/Portal.js +20 -22
  194. package/cjs/core/utils/components/Resizer.js +196 -253
  195. package/cjs/core/utils/components/VirtualScroll.js +223 -304
  196. package/cjs/core/utils/components/WithCSSTransition.js +32 -49
  197. package/cjs/core/utils/components/index.js +14 -14
  198. package/cjs/core/utils/functions/colors.js +22 -25
  199. package/cjs/core/utils/functions/date.js +10 -10
  200. package/cjs/core/utils/functions/dev.js +14 -13
  201. package/cjs/core/utils/functions/dom.js +17 -24
  202. package/cjs/core/utils/functions/focusable.js +17 -26
  203. package/cjs/core/utils/functions/import.js +23 -46
  204. package/cjs/core/utils/functions/index.js +13 -13
  205. package/cjs/core/utils/functions/numbers.js +9 -9
  206. package/cjs/core/utils/functions/polymorphic.js +30 -43
  207. package/cjs/core/utils/functions/react.js +24 -26
  208. package/cjs/core/utils/functions/supports.js +4 -5
  209. package/cjs/core/utils/hooks/index.js +17 -17
  210. package/cjs/core/utils/hooks/useContainerWidth.js +19 -26
  211. package/cjs/core/utils/hooks/useControlledState.js +12 -21
  212. package/cjs/core/utils/hooks/useDragAndDrop.js +87 -110
  213. package/cjs/core/utils/hooks/useEventListener.js +22 -22
  214. package/cjs/core/utils/hooks/useGlobals.js +27 -33
  215. package/cjs/core/utils/hooks/useId.js +8 -9
  216. package/cjs/core/utils/hooks/useIntersection.js +24 -30
  217. package/cjs/core/utils/hooks/useIsClient.js +9 -9
  218. package/cjs/core/utils/hooks/useIsomorphicLayoutEffect.js +5 -6
  219. package/cjs/core/utils/hooks/useLatestRef.js +9 -9
  220. package/cjs/core/utils/hooks/useMediaQuery.js +31 -31
  221. package/cjs/core/utils/hooks/useMergedRefs.js +16 -15
  222. package/cjs/core/utils/hooks/useOverflow.js +57 -70
  223. package/cjs/core/utils/hooks/useResizeObserver.js +17 -22
  224. package/cjs/core/utils/hooks/useSafeContext.js +9 -9
  225. package/cjs/core/utils/icons/StatusIconMap.js +12 -28
  226. package/cjs/core/utils/icons/Svg.js +3 -3
  227. package/cjs/core/utils/icons/SvgCalendar.js +7 -12
  228. package/cjs/core/utils/icons/SvgCaretDownSmall.js +7 -12
  229. package/cjs/core/utils/icons/SvgCaretRightSmall.js +7 -12
  230. package/cjs/core/utils/icons/SvgCaretUpSmall.js +7 -12
  231. package/cjs/core/utils/icons/SvgCheckmark.js +7 -10
  232. package/cjs/core/utils/icons/SvgCheckmarkSmall.js +7 -12
  233. package/cjs/core/utils/icons/SvgChevronLeft.js +7 -12
  234. package/cjs/core/utils/icons/SvgChevronLeftDouble.js +7 -12
  235. package/cjs/core/utils/icons/SvgChevronRight.js +7 -12
  236. package/cjs/core/utils/icons/SvgChevronRightDouble.js +7 -12
  237. package/cjs/core/utils/icons/SvgClose.js +7 -12
  238. package/cjs/core/utils/icons/SvgCloseSmall.js +7 -12
  239. package/cjs/core/utils/icons/SvgColumnManager.js +7 -12
  240. package/cjs/core/utils/icons/SvgDocument.js +7 -10
  241. package/cjs/core/utils/icons/SvgFilter.js +7 -10
  242. package/cjs/core/utils/icons/SvgFilterHollow.js +7 -12
  243. package/cjs/core/utils/icons/SvgImportantSmall.js +7 -12
  244. package/cjs/core/utils/icons/SvgInfoCircular.js +7 -12
  245. package/cjs/core/utils/icons/SvgMore.js +7 -12
  246. package/cjs/core/utils/icons/SvgMoreVertical.js +7 -12
  247. package/cjs/core/utils/icons/SvgNew.js +7 -12
  248. package/cjs/core/utils/icons/SvgSearch.js +7 -12
  249. package/cjs/core/utils/icons/SvgSmileyHappy.js +7 -12
  250. package/cjs/core/utils/icons/SvgSortDown.js +7 -12
  251. package/cjs/core/utils/icons/SvgSortUp.js +7 -12
  252. package/cjs/core/utils/icons/SvgStatusError.js +7 -12
  253. package/cjs/core/utils/icons/SvgStatusSuccess.js +7 -12
  254. package/cjs/core/utils/icons/SvgStatusWarning.js +7 -12
  255. package/cjs/core/utils/icons/SvgSwap.js +7 -12
  256. package/cjs/core/utils/icons/SvgUpload.js +7 -12
  257. package/cjs/core/utils/icons/index.js +34 -34
  258. package/cjs/core/utils/index.js +10 -10
  259. package/cjs/core/utils/props.js +2 -2
  260. package/cjs/core/utils/types.js +2 -2
  261. package/cjs/index.js +229 -949
  262. package/cjs/react-table/react-table.js +2 -2
  263. package/cjs/styles.js +412 -425
  264. package/esm/core/Alert/Alert.js +39 -106
  265. package/esm/core/Avatar/Avatar.js +14 -42
  266. package/esm/core/AvatarGroup/AvatarGroup.js +20 -58
  267. package/esm/core/Backdrop/Backdrop.js +2 -10
  268. package/esm/core/Badge/Badge.js +16 -31
  269. package/esm/core/Breadcrumbs/Breadcrumbs.js +55 -135
  270. package/esm/core/ButtonGroup/ButtonGroup.js +25 -61
  271. package/esm/core/Buttons/Button.js +5 -45
  272. package/esm/core/Buttons/DropdownButton.js +7 -37
  273. package/esm/core/Buttons/IconButton.js +5 -40
  274. package/esm/core/Buttons/IdeasButton.js +2 -12
  275. package/esm/core/Buttons/SplitButton.js +34 -101
  276. package/esm/core/Carousel/Carousel.js +43 -72
  277. package/esm/core/Carousel/CarouselDot.js +6 -17
  278. package/esm/core/Carousel/CarouselDotsList.js +85 -147
  279. package/esm/core/Carousel/CarouselNavigation.js +32 -68
  280. package/esm/core/Carousel/CarouselSlide.js +19 -41
  281. package/esm/core/Carousel/CarouselSlider.js +41 -65
  282. package/esm/core/Checkbox/Checkbox.js +25 -78
  283. package/esm/core/ColorPicker/ColorBuilder.js +167 -280
  284. package/esm/core/ColorPicker/ColorInputPanel.js +237 -395
  285. package/esm/core/ColorPicker/ColorPalette.js +14 -35
  286. package/esm/core/ColorPicker/ColorPicker.js +46 -79
  287. package/esm/core/ColorPicker/ColorPickerContext.js +5 -7
  288. package/esm/core/ColorPicker/ColorSwatch.js +7 -24
  289. package/esm/core/ComboBox/ComboBox.js +267 -396
  290. package/esm/core/ComboBox/ComboBoxEndIcon.js +5 -18
  291. package/esm/core/ComboBox/ComboBoxInput.js +125 -197
  292. package/esm/core/ComboBox/ComboBoxInputContainer.js +5 -20
  293. package/esm/core/ComboBox/ComboBoxMenu.js +37 -77
  294. package/esm/core/ComboBox/ComboBoxMenuItem.js +14 -61
  295. package/esm/core/ComboBox/ComboBoxMultipleContainer.js +2 -6
  296. package/esm/core/ComboBox/helpers.js +38 -38
  297. package/esm/core/DatePicker/DatePicker.js +326 -555
  298. package/esm/core/Dialog/Dialog.js +24 -53
  299. package/esm/core/Dialog/DialogBackdrop.js +19 -39
  300. package/esm/core/Dialog/DialogContent.js +12 -20
  301. package/esm/core/Dialog/DialogContext.js +1 -1
  302. package/esm/core/Dialog/DialogDragContext.js +4 -4
  303. package/esm/core/Dialog/DialogMain.js +107 -177
  304. package/esm/core/Dialog/DialogTitleBar.js +10 -45
  305. package/esm/core/Divider/Divider.js +2 -8
  306. package/esm/core/DropdownMenu/DropdownMenu.js +40 -75
  307. package/esm/core/ExpandableBlock/ExpandableBlock.js +92 -193
  308. package/esm/core/Fieldset/Fieldset.js +8 -19
  309. package/esm/core/FileUpload/FileEmptyCard.js +8 -19
  310. package/esm/core/FileUpload/FileUpload.js +36 -72
  311. package/esm/core/FileUpload/FileUploadCard.js +76 -153
  312. package/esm/core/FileUpload/FileUploadTemplate.js +9 -37
  313. package/esm/core/Flex/Flex.js +71 -87
  314. package/esm/core/Footer/Footer.js +55 -86
  315. package/esm/core/Footer/FooterSeparator.js +1 -1
  316. package/esm/core/Header/Header.js +14 -55
  317. package/esm/core/Header/HeaderBasicButton.js +7 -15
  318. package/esm/core/Header/HeaderBreadcrumbs.js +8 -32
  319. package/esm/core/Header/HeaderButton.js +14 -62
  320. package/esm/core/Header/HeaderDropdownButton.js +13 -42
  321. package/esm/core/Header/HeaderLogo.js +5 -36
  322. package/esm/core/Header/HeaderSplitButton.js +14 -61
  323. package/esm/core/Icon/Icon.js +12 -26
  324. package/esm/core/InformationPanel/InformationPanel.js +36 -71
  325. package/esm/core/InformationPanel/InformationPanelContent.js +3 -17
  326. package/esm/core/InformationPanel/InformationPanelHeader.js +8 -32
  327. package/esm/core/InformationPanel/InformationPanelWrapper.js +1 -3
  328. package/esm/core/Input/Input.js +4 -12
  329. package/esm/core/InputGrid/InputGrid.js +2 -11
  330. package/esm/core/InputGroup/InputGroup.js +16 -57
  331. package/esm/core/InputWithDecorations/InputWithDecorations.js +11 -42
  332. package/esm/core/Label/Label.js +5 -26
  333. package/esm/core/LabeledInput/LabeledInput.js +10 -63
  334. package/esm/core/LabeledSelect/LabeledSelect.js +18 -67
  335. package/esm/core/LabeledTextarea/LabeledTextarea.js +2 -8
  336. package/esm/core/List/ListItem.js +28 -46
  337. package/esm/core/Menu/Menu.js +48 -64
  338. package/esm/core/Menu/MenuDivider.js +1 -1
  339. package/esm/core/Menu/MenuExtraContent.js +1 -1
  340. package/esm/core/Menu/MenuItem.js +84 -164
  341. package/esm/core/Menu/MenuItemSkeleton.js +12 -43
  342. package/esm/core/Modal/Modal.js +6 -33
  343. package/esm/core/NonIdealState/ErrorPage.js +123 -173
  344. package/esm/core/NonIdealState/NonIdealState.js +6 -65
  345. package/esm/core/NotificationMarker/NotificationMarker.js +2 -20
  346. package/esm/core/Overlay/Overlay.d.ts +20 -24
  347. package/esm/core/Overlay/Overlay.js +45 -55
  348. package/esm/core/Popover/Popover.js +80 -172
  349. package/esm/core/ProgressIndicators/ProgressLinear.js +5 -40
  350. package/esm/core/ProgressIndicators/ProgressRadial.js +14 -40
  351. package/esm/core/Radio/Radio.js +6 -45
  352. package/esm/core/RadioTiles/RadioTile.js +8 -62
  353. package/esm/core/RadioTiles/RadioTileGroup.js +3 -10
  354. package/esm/core/SearchBox/SearchBox.js +97 -214
  355. package/esm/core/Select/Select.js +130 -271
  356. package/esm/core/Select/SelectTag.js +3 -15
  357. package/esm/core/Select/SelectTagContainer.js +7 -20
  358. package/esm/core/SideNavigation/SideNavigation.js +21 -118
  359. package/esm/core/SideNavigation/SidenavButton.js +2 -24
  360. package/esm/core/SideNavigation/SidenavSubmenu.js +3 -14
  361. package/esm/core/SideNavigation/SidenavSubmenuHeader.js +4 -20
  362. package/esm/core/SkipToContentLink/SkipToContentLink.js +2 -11
  363. package/esm/core/Slider/Slider.js +187 -340
  364. package/esm/core/Slider/Thumb.js +50 -97
  365. package/esm/core/Slider/Track.js +49 -74
  366. package/esm/core/StatusMessage/StatusMessage.js +5 -23
  367. package/esm/core/Stepper/Stepper.js +14 -70
  368. package/esm/core/Stepper/StepperStep.js +29 -92
  369. package/esm/core/Stepper/WorkflowDiagram.js +8 -21
  370. package/esm/core/Stepper/WorkflowDiagramStep.js +4 -22
  371. package/esm/core/Surface/Surface.js +48 -84
  372. package/esm/core/Table/SubRowExpander.js +9 -31
  373. package/esm/core/Table/Table.js +408 -763
  374. package/esm/core/Table/TableCell.js +53 -87
  375. package/esm/core/Table/TablePaginator.js +125 -306
  376. package/esm/core/Table/TableRowMemoized.js +58 -129
  377. package/esm/core/Table/actionHandlers/expandHandler.js +10 -10
  378. package/esm/core/Table/actionHandlers/filterHandler.js +15 -23
  379. package/esm/core/Table/actionHandlers/index.js +1 -5
  380. package/esm/core/Table/actionHandlers/resizeHandler.js +11 -11
  381. package/esm/core/Table/actionHandlers/selectHandler.js +95 -122
  382. package/esm/core/Table/cells/DefaultCell.js +7 -42
  383. package/esm/core/Table/cells/EditableCell.js +41 -70
  384. package/esm/core/Table/columns/actionColumn.js +55 -85
  385. package/esm/core/Table/columns/expanderColumn.js +25 -39
  386. package/esm/core/Table/columns/selectionColumn.js +23 -51
  387. package/esm/core/Table/filters/BaseFilter.js +7 -15
  388. package/esm/core/Table/filters/DateRangeFilter/DatePickerInput.js +42 -107
  389. package/esm/core/Table/filters/DateRangeFilter/DateRangeFilter.js +52 -110
  390. package/esm/core/Table/filters/FilterButtonBar.js +9 -28
  391. package/esm/core/Table/filters/FilterToggle.js +18 -51
  392. package/esm/core/Table/filters/NumberRangeFilter/NumberRangeFilter.js +28 -50
  393. package/esm/core/Table/filters/TextFilter/TextFilter.js +20 -32
  394. package/esm/core/Table/filters/customFilterFunctions.js +12 -14
  395. package/esm/core/Table/filters/defaultFilterFunctions.js +79 -84
  396. package/esm/core/Table/filters/tableFilters.js +25 -34
  397. package/esm/core/Table/hooks/useColumnDragAndDrop.js +81 -88
  398. package/esm/core/Table/hooks/useExpanderCell.js +20 -26
  399. package/esm/core/Table/hooks/useResizeColumns.js +287 -353
  400. package/esm/core/Table/hooks/useScrollToRow.js +34 -42
  401. package/esm/core/Table/hooks/useSelectionCell.js +6 -10
  402. package/esm/core/Table/hooks/useStickyColumns.js +59 -61
  403. package/esm/core/Table/hooks/useSubRowFiltering.js +83 -90
  404. package/esm/core/Table/hooks/useSubRowSelection.js +27 -28
  405. package/esm/core/Table/index.js +1 -5
  406. package/esm/core/Table/utils.js +38 -40
  407. package/esm/core/Tabs/Tabs.d.ts +3 -5
  408. package/esm/core/Tabs/Tabs.js +229 -406
  409. package/esm/core/Tag/Tag.js +8 -35
  410. package/esm/core/Tag/TagContainer.js +5 -17
  411. package/esm/core/Textarea/Textarea.js +1 -6
  412. package/esm/core/ThemeProvider/ThemeProvider.js +44 -101
  413. package/esm/core/Tile/Tile.js +218 -386
  414. package/esm/core/TimePicker/TimePicker.js +228 -448
  415. package/esm/core/Toast/Toast.js +99 -193
  416. package/esm/core/Toast/Toaster.js +69 -83
  417. package/esm/core/ToggleSwitch/ToggleSwitch.js +17 -60
  418. package/esm/core/Tooltip/Tooltip.js +86 -151
  419. package/esm/core/TransferList/TransferList.js +93 -157
  420. package/esm/core/Tree/Tree.js +122 -196
  421. package/esm/core/Tree/TreeContext.js +5 -5
  422. package/esm/core/Tree/TreeNode.js +96 -195
  423. package/esm/core/Tree/TreeNodeExpander.js +5 -16
  424. package/esm/core/Typography/Blockquote.js +4 -12
  425. package/esm/core/Typography/Kbd.js +15 -24
  426. package/esm/core/Typography/Text.js +7 -20
  427. package/esm/core/VisuallyHidden/VisuallyHidden.js +2 -8
  428. package/esm/core/utils/color/ColorValue.js +449 -524
  429. package/esm/core/utils/components/AutoclearingHiddenLiveRegion.js +7 -11
  430. package/esm/core/utils/components/ButtonBase.js +13 -31
  431. package/esm/core/utils/components/FocusTrap.js +32 -41
  432. package/esm/core/utils/components/InputContainer.js +11 -50
  433. package/esm/core/utils/components/InputFlexContainer.js +2 -15
  434. package/esm/core/utils/components/MiddleTextTruncation.js +17 -27
  435. package/esm/core/utils/components/Portal.js +12 -12
  436. package/esm/core/utils/components/Resizer.js +191 -249
  437. package/esm/core/utils/components/VirtualScroll.js +218 -297
  438. package/esm/core/utils/components/WithCSSTransition.js +26 -43
  439. package/esm/core/utils/functions/colors.js +19 -19
  440. package/esm/core/utils/functions/date.js +8 -8
  441. package/esm/core/utils/functions/dev.js +12 -11
  442. package/esm/core/utils/functions/dom.js +14 -17
  443. package/esm/core/utils/functions/focusable.js +15 -24
  444. package/esm/core/utils/functions/import.js +2 -4
  445. package/esm/core/utils/functions/numbers.js +7 -7
  446. package/esm/core/utils/functions/polymorphic.js +23 -32
  447. package/esm/core/utils/functions/react.js +19 -21
  448. package/esm/core/utils/functions/supports.js +1 -2
  449. package/esm/core/utils/hooks/useContainerWidth.js +13 -16
  450. package/esm/core/utils/hooks/useControlledState.js +8 -17
  451. package/esm/core/utils/hooks/useDragAndDrop.js +80 -99
  452. package/esm/core/utils/hooks/useEventListener.js +18 -18
  453. package/esm/core/utils/hooks/useGlobals.js +21 -27
  454. package/esm/core/utils/hooks/useId.js +3 -3
  455. package/esm/core/utils/hooks/useIntersection.js +19 -25
  456. package/esm/core/utils/hooks/useIsClient.js +5 -5
  457. package/esm/core/utils/hooks/useIsomorphicLayoutEffect.js +1 -2
  458. package/esm/core/utils/hooks/useLatestRef.js +5 -5
  459. package/esm/core/utils/hooks/useMediaQuery.js +25 -23
  460. package/esm/core/utils/hooks/useMergedRefs.js +12 -11
  461. package/esm/core/utils/hooks/useOverflow.js +51 -63
  462. package/esm/core/utils/hooks/useResizeObserver.js +12 -17
  463. package/esm/core/utils/hooks/useSafeContext.js +5 -5
  464. package/esm/core/utils/icons/StatusIconMap.js +4 -8
  465. package/esm/core/utils/icons/SvgCalendar.js +2 -7
  466. package/esm/core/utils/icons/SvgCaretDownSmall.js +2 -7
  467. package/esm/core/utils/icons/SvgCaretRightSmall.js +2 -7
  468. package/esm/core/utils/icons/SvgCaretUpSmall.js +2 -7
  469. package/esm/core/utils/icons/SvgCheckmark.js +2 -5
  470. package/esm/core/utils/icons/SvgCheckmarkSmall.js +2 -7
  471. package/esm/core/utils/icons/SvgChevronLeft.js +2 -7
  472. package/esm/core/utils/icons/SvgChevronLeftDouble.js +2 -7
  473. package/esm/core/utils/icons/SvgChevronRight.js +2 -7
  474. package/esm/core/utils/icons/SvgChevronRightDouble.js +2 -7
  475. package/esm/core/utils/icons/SvgClose.js +2 -7
  476. package/esm/core/utils/icons/SvgCloseSmall.js +2 -7
  477. package/esm/core/utils/icons/SvgColumnManager.js +2 -7
  478. package/esm/core/utils/icons/SvgDocument.js +2 -5
  479. package/esm/core/utils/icons/SvgFilter.js +2 -5
  480. package/esm/core/utils/icons/SvgFilterHollow.js +2 -7
  481. package/esm/core/utils/icons/SvgImportantSmall.js +2 -7
  482. package/esm/core/utils/icons/SvgInfoCircular.js +2 -7
  483. package/esm/core/utils/icons/SvgMore.js +2 -7
  484. package/esm/core/utils/icons/SvgMoreVertical.js +2 -7
  485. package/esm/core/utils/icons/SvgNew.js +2 -7
  486. package/esm/core/utils/icons/SvgSearch.js +2 -7
  487. package/esm/core/utils/icons/SvgSmileyHappy.js +2 -7
  488. package/esm/core/utils/icons/SvgSortDown.js +2 -7
  489. package/esm/core/utils/icons/SvgSortUp.js +2 -7
  490. package/esm/core/utils/icons/SvgStatusError.js +2 -7
  491. package/esm/core/utils/icons/SvgStatusSuccess.js +2 -7
  492. package/esm/core/utils/icons/SvgStatusWarning.js +2 -7
  493. package/esm/core/utils/icons/SvgSwap.js +2 -7
  494. package/esm/core/utils/icons/SvgUpload.js +2 -7
  495. package/esm/index.js +3 -21
  496. package/esm/styles.js +414 -425
  497. package/package.json +2 -2
  498. package/styles.css +6 -6
@@ -10,25 +10,19 @@ const scratchUInt32 = new Uint32Array(scratchBytes.buffer);
10
10
  * isRgbValue type guard.
11
11
  */
12
12
  export const isRgbColor = (value) => {
13
- return (
14
- typeof value !== 'string' && 'r' in value && 'g' in value && 'b' in value
15
- );
13
+ return (typeof value !== 'string' && 'r' in value && 'g' in value && 'b' in value);
16
14
  };
17
15
  /**
18
16
  * isHslValue type guard.
19
17
  */
20
18
  export const isHslColor = (value) => {
21
- return (
22
- typeof value !== 'string' && 'h' in value && 's' in value && 'l' in value
23
- );
19
+ return (typeof value !== 'string' && 'h' in value && 's' in value && 'l' in value);
24
20
  };
25
21
  /**
26
22
  * isHsvValue type guard.
27
23
  */
28
24
  export const isHsvColor = (value) => {
29
- return (
30
- typeof value !== 'string' && 'h' in value && 's' in value && 'v' in value
31
- );
25
+ return (typeof value !== 'string' && 'h' in value && 's' in value && 'v' in value);
32
26
  };
33
27
  /**
34
28
  * An immutable integer representation of a color.
@@ -42,543 +36,474 @@ export const isHsvColor = (value) => {
42
36
  * @public
43
37
  */
44
38
  export class ColorValue {
45
- constructor(tbgr, hue) {
46
- scratchUInt32[0] = tbgr; // Force to be a 32-bit unsigned integer
47
- this._tbgr = scratchUInt32[0];
48
- this._hue = hue;
49
- }
50
- /**
51
- * Create a new ColorValue.
52
- * @param val value to use.
53
- *
54
- * If a string, must be in one of the following forms:
55
- * *"rgb(255,0,0)"*
56
- * *"rgba(255,0,0,.2)"*
57
- * *"rgb(100%,0%,0%)"*
58
- * *"hsl(120,50%,50%)"*
59
- * *"#rrggbb"*
60
- */
61
- static create(val) {
62
- if (!val) {
63
- return ColorValue.fromTbgr(0);
39
+ constructor(tbgr, hue) {
40
+ scratchUInt32[0] = tbgr; // Force to be a 32-bit unsigned integer
41
+ this._tbgr = scratchUInt32[0];
42
+ this._hue = hue;
64
43
  }
65
- if (isRgbColor(val)) {
66
- return ColorValue.fromRGB(val);
44
+ /**
45
+ * Create a new ColorValue.
46
+ * @param val value to use.
47
+ *
48
+ * If a string, must be in one of the following forms:
49
+ * *"rgb(255,0,0)"*
50
+ * *"rgba(255,0,0,.2)"*
51
+ * *"rgb(100%,0%,0%)"*
52
+ * *"hsl(120,50%,50%)"*
53
+ * *"#rrggbb"*
54
+ */
55
+ static create(val) {
56
+ if (!val) {
57
+ return ColorValue.fromTbgr(0);
58
+ }
59
+ if (isRgbColor(val)) {
60
+ return ColorValue.fromRGB(val);
61
+ }
62
+ if (isHslColor(val)) {
63
+ return ColorValue.fromHSL(val);
64
+ }
65
+ if (isHsvColor(val)) {
66
+ return ColorValue.fromHSV(val);
67
+ }
68
+ if (typeof val === 'string') {
69
+ return ColorValue.fromString(val, ColorValue.fromTbgr(0));
70
+ }
71
+ return ColorValue.fromTbgr(0);
67
72
  }
68
- if (isHslColor(val)) {
69
- return ColorValue.fromHSL(val);
73
+ /**
74
+ * Convert this ColorValue to an unsigned 32 bit integer representing the 0xTTBBGGRR value
75
+ */
76
+ toTbgr() {
77
+ return this._tbgr;
70
78
  }
71
- if (isHsvColor(val)) {
72
- return ColorValue.fromHSV(val);
79
+ /**
80
+ * Create a ColorValue from its 0xTTBBGGRR representation.
81
+ */
82
+ static fromTbgr(tbgr) {
83
+ return new ColorValue(tbgr);
73
84
  }
74
- if (typeof val === 'string') {
75
- return ColorValue.fromString(val, ColorValue.fromTbgr(0));
85
+ /**
86
+ * Create a ColorValue from Red, Green, Blue, Transparency values. All inputs should be integers between 0-255.
87
+ */
88
+ static fromRgbt(red, green, blue, transparency) {
89
+ return this.fromTbgr(this.computeTbgrFromComponents(red, green, blue, transparency));
76
90
  }
77
- return ColorValue.fromTbgr(0);
78
- }
79
- /**
80
- * Convert this ColorValue to an unsigned 32 bit integer representing the 0xTTBBGGRR value
81
- */
82
- toTbgr() {
83
- return this._tbgr;
84
- }
85
- /**
86
- * Create a ColorValue from its 0xTTBBGGRR representation.
87
- */
88
- static fromTbgr(tbgr) {
89
- return new ColorValue(tbgr);
90
- }
91
- /**
92
- * Create a ColorValue from Red, Green, Blue, Transparency values. All inputs should be integers between 0-255.
93
- */
94
- static fromRgbt(red, green, blue, transparency) {
95
- return this.fromTbgr(
96
- this.computeTbgrFromComponents(red, green, blue, transparency),
97
- );
98
- }
99
- /**
100
- * Compute the 0xTTBBGGRR value corresponding to the specified Red, Green, Blue, Transparency components.
101
- * All inputs should be integers between 0-255.
102
- */
103
- static computeTbgrFromComponents(red, green, blue, transparency) {
104
- scratchBytes[0] = red;
105
- scratchBytes[1] = green;
106
- scratchBytes[2] = blue;
107
- scratchBytes[3] = transparency || 0;
108
- return scratchUInt32[0];
109
- }
110
- /**
111
- * Create a ColorValue from a string representation. The following representations are supported:
112
- * *"rgb(255,0,0)"*
113
- * *"rgba(255,0,0,.2)"*
114
- * *"rgb(100%,0%,0%)"*
115
- * *"hsl(120,50%,50%)"*
116
- * *"#rrggbb"*
117
- * NOTE: If defaultColorIfNotParsed is not defined and string is invalid then error is thrown.
118
- * This allows component builders to know if they received bad input from user.
119
- */
120
- static fromString(val, defaultColorIfNotParsed) {
121
- const [tbgr, hue] = this.computeTbgrFromString(
122
- val,
123
- defaultColorIfNotParsed?.toTbgr(),
124
- );
125
- return new ColorValue(tbgr, hue);
126
- }
127
- /** Create a ColorValue from hue, saturation, lightness values. */
128
- static fromHSL(hsl) {
129
- const alpha = hsl.a ?? 1;
130
- return new ColorValue(
131
- this.computeTbgrFromHSL(
132
- hsl.h / 360,
133
- hsl.s / 100,
134
- hsl.l / 100,
135
- Math.round((1 - alpha) * 255),
136
- ),
137
- hsl.h,
138
- );
139
- }
140
- /** Create a ColorValue from an RgbColor */
141
- static fromRGB(rgb) {
142
- const alpha = rgb.a ?? 1;
143
- return ColorValue.fromRgbt(
144
- rgb.r,
145
- rgb.g,
146
- rgb.b,
147
- Math.round((1 - alpha) * 255),
148
- );
149
- }
150
- /**
151
- * Create a ColorValue from an HsvColor
152
- */
153
- static fromHSV(hsv) {
154
- const alpha = hsv.a ?? 1;
155
- const transparency = Math.round((1 - alpha) * 255);
156
- // Check for simple case first.
157
- if (!hsv.s || hsv.h === -1) {
158
- // hue must be undefined, have no color only white
159
- const white = 0xff & Math.floor((255.0 * hsv.v) / 100.0 + 0.5 + 3.0e-14);
160
- return ColorValue.fromRgbt(white, white, white, 0);
91
+ /**
92
+ * Compute the 0xTTBBGGRR value corresponding to the specified Red, Green, Blue, Transparency components.
93
+ * All inputs should be integers between 0-255.
94
+ */
95
+ static computeTbgrFromComponents(red, green, blue, transparency) {
96
+ scratchBytes[0] = red;
97
+ scratchBytes[1] = green;
98
+ scratchBytes[2] = blue;
99
+ scratchBytes[3] = transparency || 0;
100
+ return scratchUInt32[0];
161
101
  }
162
- let dhue = hsv.h,
163
- dsaturation = hsv.s,
164
- dvalue = hsv.v;
165
- if (dhue === 360) {
166
- dhue = 0.0;
102
+ /**
103
+ * Create a ColorValue from a string representation. The following representations are supported:
104
+ * *"rgb(255,0,0)"*
105
+ * *"rgba(255,0,0,.2)"*
106
+ * *"rgb(100%,0%,0%)"*
107
+ * *"hsl(120,50%,50%)"*
108
+ * *"#rrggbb"*
109
+ * NOTE: If defaultColorIfNotParsed is not defined and string is invalid then error is thrown.
110
+ * This allows component builders to know if they received bad input from user.
111
+ */
112
+ static fromString(val, defaultColorIfNotParsed) {
113
+ const [tbgr, hue] = this.computeTbgrFromString(val, defaultColorIfNotParsed?.toTbgr());
114
+ return new ColorValue(tbgr, hue);
167
115
  }
168
- dhue /= 60; // hue is now [0..6]
169
- const hueIntpart = Math.floor(dhue); // convert double -> int
170
- const hueFractpart = dhue - hueIntpart;
171
- dvalue /= 100;
172
- dsaturation /= 100;
173
- const p = 0xff & Math.floor(dvalue * (1.0 - dsaturation) * 255.0 + 0.5);
174
- const q =
175
- 0xff &
176
- Math.floor(dvalue * (1.0 - dsaturation * hueFractpart) * 255.0 + 0.5);
177
- const t =
178
- 0xff &
179
- Math.floor(
180
- dvalue * (1.0 - dsaturation * (1.0 - hueFractpart)) * 255.0 + 0.5,
181
- );
182
- const v = 0xff & Math.floor(dvalue * 255 + 0.5);
183
- let r = 0,
184
- b = 0,
185
- g = 0;
186
- switch (hueIntpart) {
187
- case 0:
188
- r = v;
189
- g = t;
190
- b = p;
191
- break; // reddish
192
- case 1:
193
- (r = q), (g = v);
194
- b = p;
195
- break; // yellowish
196
- case 2:
197
- (r = p), (g = v);
198
- b = t;
199
- break; // greenish
200
- case 3:
201
- (r = p), (g = q);
202
- b = v;
203
- break; // cyanish
204
- case 4:
205
- (r = t), (g = p);
206
- b = v;
207
- break; // bluish
208
- case 5:
209
- (r = v), (g = p);
210
- b = q;
211
- break; // magenta-ish
116
+ /** Create a ColorValue from hue, saturation, lightness values. */
117
+ static fromHSL(hsl) {
118
+ const alpha = hsl.a ?? 1;
119
+ return new ColorValue(this.computeTbgrFromHSL(hsl.h / 360, hsl.s / 100, hsl.l / 100, Math.round((1 - alpha) * 255)), hsl.h);
212
120
  }
213
- return new ColorValue(
214
- ColorValue.computeTbgrFromComponents(r, g, b, transparency),
215
- hsv.h,
216
- );
217
- }
218
- /**
219
- * Compute the 0xTTBBGGRR value corresponding to a string representation of a color. The following representations are supported:
220
- * *"rgb(255,0,0)"*
221
- * *"rgba(255,0,0,.2)"*
222
- * *"rgb(100%,0%,0%)"*
223
- * *"hsl(120,50%,50%)"*
224
- * *"#rrggbb"*
225
- */
226
- static computeTbgrFromString(val, defaultColorIfNotParsed) {
227
- val = val.toLowerCase();
228
- let m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(val);
229
- if (m) {
230
- // rgb / hsl
231
- let color;
232
- const name = m[1];
233
- const components = m[2];
234
- const hasPercent = (str) => str[str.length - 1] === '%';
235
- const floatOrPercent = (str) => {
236
- const v = parseFloat(str);
237
- return 255 * getBoundedValue(hasPercent(str) ? v / 100 : v, 0, 1);
238
- };
239
- const intOrPercent = (str) => {
240
- const v = hasPercent(str)
241
- ? (parseFloat(str) / 100) * 255
242
- : parseInt(str, 10);
243
- return getBoundedValue(v, 0, 255);
244
- };
245
- switch (name) {
246
- case 'rgb':
247
- case 'rgba':
248
- color =
249
- /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(
250
- components,
251
- );
252
- if (color) {
253
- // rgb(255,0,0) rgba(255,0,0,0.5)
254
- return [
255
- this.computeTbgrFromComponents(
256
- intOrPercent(color[1]),
257
- intOrPercent(color[2]),
258
- intOrPercent(color[3]),
259
- typeof color[4] === 'string'
260
- ? 255 - floatOrPercent(color[4])
261
- : 0,
262
- ),
263
- undefined,
264
- ];
265
- }
266
- break;
267
- case 'hsl':
268
- case 'hsla':
269
- color =
270
- /^(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(
271
- components,
272
- );
273
- if (color) {
274
- // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
275
- const h = parseFloat(color[1]);
276
- const s = parseInt(color[2], 10) / 100;
277
- const l = parseInt(color[3], 10) / 100;
278
- const t =
279
- typeof color[4] === 'string' ? 255 - floatOrPercent(color[4]) : 0;
280
- return [this.computeTbgrFromHSL(h / 360, s, l, t), h];
281
- }
282
- break;
283
- }
284
- // eslint-disable-next-line no-cond-assign
285
- } else if ((m = /^\#([A-Fa-f\d]+)$/.exec(val))) {
286
- // hex color
287
- const hex = m[1];
288
- const size = hex.length;
289
- if (size === 3) {
290
- // #ff0
291
- return [
292
- this.computeTbgrFromComponents(
293
- parseInt(hex.charAt(0) + hex.charAt(0), 16),
294
- parseInt(hex.charAt(1) + hex.charAt(1), 16),
295
- parseInt(hex.charAt(2) + hex.charAt(2), 16),
296
- 0,
297
- ),
298
- undefined,
299
- ];
300
- }
301
- if (size === 6) {
302
- // #ff0000
303
- return [
304
- this.computeTbgrFromComponents(
305
- parseInt(hex.charAt(0) + hex.charAt(1), 16),
306
- parseInt(hex.charAt(2) + hex.charAt(3), 16),
307
- parseInt(hex.charAt(4) + hex.charAt(5), 16),
308
- 0,
309
- ),
310
- undefined,
311
- ];
312
- }
313
- if (size === 8) {
314
- // #ff0000ff
315
- return [
316
- this.computeTbgrFromComponents(
317
- parseInt(hex.charAt(0) + hex.charAt(1), 16),
318
- parseInt(hex.charAt(2) + hex.charAt(3), 16),
319
- parseInt(hex.charAt(4) + hex.charAt(5), 16),
320
- 255 - parseInt(hex.charAt(6) + hex.charAt(7), 16),
321
- ),
322
- undefined,
323
- ];
324
- }
121
+ /** Create a ColorValue from an RgbColor */
122
+ static fromRGB(rgb) {
123
+ const alpha = rgb.a ?? 1;
124
+ return ColorValue.fromRgbt(rgb.r, rgb.g, rgb.b, Math.round((1 - alpha) * 255));
325
125
  }
326
- if (defaultColorIfNotParsed) {
327
- return [defaultColorIfNotParsed, undefined];
126
+ /**
127
+ * Create a ColorValue from an HsvColor
128
+ */
129
+ static fromHSV(hsv) {
130
+ const alpha = hsv.a ?? 1;
131
+ const transparency = Math.round((1 - alpha) * 255);
132
+ // Check for simple case first.
133
+ if (!hsv.s || hsv.h === -1) {
134
+ // hue must be undefined, have no color only white
135
+ const white = 0xff & Math.floor((255.0 * hsv.v) / 100.0 + 0.5 + 3.0e-14);
136
+ return ColorValue.fromRgbt(white, white, white, 0);
137
+ }
138
+ let dhue = hsv.h, dsaturation = hsv.s, dvalue = hsv.v;
139
+ if (dhue === 360) {
140
+ dhue = 0.0;
141
+ }
142
+ dhue /= 60; // hue is now [0..6]
143
+ const hueIntpart = Math.floor(dhue); // convert double -> int
144
+ const hueFractpart = dhue - hueIntpart;
145
+ dvalue /= 100;
146
+ dsaturation /= 100;
147
+ const p = 0xff & Math.floor(dvalue * (1.0 - dsaturation) * 255.0 + 0.5);
148
+ const q = 0xff &
149
+ Math.floor(dvalue * (1.0 - dsaturation * hueFractpart) * 255.0 + 0.5);
150
+ const t = 0xff &
151
+ Math.floor(dvalue * (1.0 - dsaturation * (1.0 - hueFractpart)) * 255.0 + 0.5);
152
+ const v = 0xff & Math.floor(dvalue * 255 + 0.5);
153
+ let r = 0, b = 0, g = 0;
154
+ switch (hueIntpart) {
155
+ case 0:
156
+ r = v;
157
+ g = t;
158
+ b = p;
159
+ break; // reddish
160
+ case 1:
161
+ (r = q), (g = v);
162
+ b = p;
163
+ break; // yellowish
164
+ case 2:
165
+ (r = p), (g = v);
166
+ b = t;
167
+ break; // greenish
168
+ case 3:
169
+ (r = p), (g = q);
170
+ b = v;
171
+ break; // cyanish
172
+ case 4:
173
+ (r = t), (g = p);
174
+ b = v;
175
+ break; // bluish
176
+ case 5:
177
+ (r = v), (g = p);
178
+ b = q;
179
+ break; // magenta-ish
180
+ }
181
+ return new ColorValue(ColorValue.computeTbgrFromComponents(r, g, b, transparency), hsv.h);
328
182
  }
329
- throw new Error('unable to parse string into ColorValue');
330
- }
331
- /**
332
- * Get the r,g,b,t values encoded in an 0xTTBBGGRR value. Values will be integers between 0-255.
333
- */
334
- static getColors(tbgr) {
335
- scratchUInt32[0] = tbgr;
336
- return {
337
- b: scratchBytes[2],
338
- g: scratchBytes[1],
339
- r: scratchBytes[0],
340
- t: scratchBytes[3],
341
- };
342
- }
343
- /**
344
- * Get the RGB value of the 0xTTBBGGRR color as a number in 0xRRGGBB or 0xRRGGBBAA format
345
- */
346
- getRgb(includeAlpha) {
347
- scratchUInt32[0] = this._tbgr;
348
- if (includeAlpha) {
349
- return (
350
- (scratchBytes[0] << 24) +
351
- (scratchBytes[1] << 16) +
352
- (scratchBytes[2] << 8) +
353
- (255 - scratchBytes[3])
354
- );
183
+ /**
184
+ * Compute the 0xTTBBGGRR value corresponding to a string representation of a color. The following representations are supported:
185
+ * *"rgb(255,0,0)"*
186
+ * *"rgba(255,0,0,.2)"*
187
+ * *"rgb(100%,0%,0%)"*
188
+ * *"hsl(120,50%,50%)"*
189
+ * *"#rrggbb"*
190
+ */
191
+ static computeTbgrFromString(val, defaultColorIfNotParsed) {
192
+ val = val.toLowerCase();
193
+ let m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(val);
194
+ if (m) {
195
+ // rgb / hsl
196
+ let color;
197
+ const name = m[1];
198
+ const components = m[2];
199
+ const hasPercent = (str) => str[str.length - 1] === '%';
200
+ const floatOrPercent = (str) => {
201
+ const v = parseFloat(str);
202
+ return 255 * getBoundedValue(hasPercent(str) ? v / 100 : v, 0, 1);
203
+ };
204
+ const intOrPercent = (str) => {
205
+ const v = hasPercent(str)
206
+ ? (parseFloat(str) / 100) * 255
207
+ : parseInt(str, 10);
208
+ return getBoundedValue(v, 0, 255);
209
+ };
210
+ switch (name) {
211
+ case 'rgb':
212
+ case 'rgba':
213
+ color =
214
+ /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components);
215
+ if (color) {
216
+ // rgb(255,0,0) rgba(255,0,0,0.5)
217
+ return [
218
+ this.computeTbgrFromComponents(intOrPercent(color[1]), intOrPercent(color[2]), intOrPercent(color[3]), typeof color[4] === 'string'
219
+ ? 255 - floatOrPercent(color[4])
220
+ : 0),
221
+ undefined,
222
+ ];
223
+ }
224
+ break;
225
+ case 'hsl':
226
+ case 'hsla':
227
+ color =
228
+ /^(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components);
229
+ if (color) {
230
+ // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
231
+ const h = parseFloat(color[1]);
232
+ const s = parseInt(color[2], 10) / 100;
233
+ const l = parseInt(color[3], 10) / 100;
234
+ const t = typeof color[4] === 'string' ? 255 - floatOrPercent(color[4]) : 0;
235
+ return [this.computeTbgrFromHSL(h / 360, s, l, t), h];
236
+ }
237
+ break;
238
+ }
239
+ // eslint-disable-next-line no-cond-assign
240
+ }
241
+ else if ((m = /^\#([A-Fa-f\d]+)$/.exec(val))) {
242
+ // hex color
243
+ const hex = m[1];
244
+ const size = hex.length;
245
+ if (size === 3) {
246
+ // #ff0
247
+ return [
248
+ this.computeTbgrFromComponents(parseInt(hex.charAt(0) + hex.charAt(0), 16), parseInt(hex.charAt(1) + hex.charAt(1), 16), parseInt(hex.charAt(2) + hex.charAt(2), 16), 0),
249
+ undefined,
250
+ ];
251
+ }
252
+ if (size === 6) {
253
+ // #ff0000
254
+ return [
255
+ this.computeTbgrFromComponents(parseInt(hex.charAt(0) + hex.charAt(1), 16), parseInt(hex.charAt(2) + hex.charAt(3), 16), parseInt(hex.charAt(4) + hex.charAt(5), 16), 0),
256
+ undefined,
257
+ ];
258
+ }
259
+ if (size === 8) {
260
+ // #ff0000ff
261
+ return [
262
+ this.computeTbgrFromComponents(parseInt(hex.charAt(0) + hex.charAt(1), 16), parseInt(hex.charAt(2) + hex.charAt(3), 16), parseInt(hex.charAt(4) + hex.charAt(5), 16), 255 - parseInt(hex.charAt(6) + hex.charAt(7), 16)),
263
+ undefined,
264
+ ];
265
+ }
266
+ }
267
+ if (defaultColorIfNotParsed) {
268
+ return [defaultColorIfNotParsed, undefined];
269
+ }
270
+ throw new Error('unable to parse string into ColorValue');
355
271
  }
356
- return (scratchBytes[0] << 16) + (scratchBytes[1] << 8) + scratchBytes[2];
357
- }
358
- /**
359
- * Get the alpha value for this ColorDef. Will be between 0-255
360
- */
361
- getAlpha() {
362
- return ColorValue.getAlpha(this._tbgr);
363
- }
364
- /**
365
- * Extract the alpha value from a 0xTTBBGGRR color.
366
- */
367
- static getAlpha(tbgr) {
368
- scratchUInt32[0] = tbgr;
369
- return 255 - scratchBytes[3];
370
- }
371
- /**
372
- * Convert this ColorValue to a string in the form "#rrggbb" or "#rrggbbaa" where values are hex digits of the respective colors
373
- */
374
- toHexString(includeAlpha) {
375
- if (includeAlpha) {
376
- let value = this.getRgb(includeAlpha);
377
- if (value < 0) {
378
- value = 0xffffffff + value + 1;
379
- }
380
- return `#${`00000000${value.toString(16)}`.slice(-8)}`;
272
+ /**
273
+ * Get the r,g,b,t values encoded in an 0xTTBBGGRR value. Values will be integers between 0-255.
274
+ */
275
+ static getColors(tbgr) {
276
+ scratchUInt32[0] = tbgr;
277
+ return {
278
+ b: scratchBytes[2],
279
+ g: scratchBytes[1],
280
+ r: scratchBytes[0],
281
+ t: scratchBytes[3],
282
+ };
381
283
  }
382
- return `#${`000000${this.getRgb().toString(16)}`.slice(-6)}`;
383
- }
384
- /**
385
- * Compute the 0xTTBBGGRR color corresponding to the specified hue, saturation, lightness values.
386
- */
387
- static computeTbgrFromHSL(
284
+ /**
285
+ * Get the RGB value of the 0xTTBBGGRR color as a number in 0xRRGGBB or 0xRRGGBBAA format
286
+ */
287
+ getRgb(includeAlpha) {
288
+ scratchUInt32[0] = this._tbgr;
289
+ if (includeAlpha) {
290
+ return ((scratchBytes[0] << 24) +
291
+ (scratchBytes[1] << 16) +
292
+ (scratchBytes[2] << 8) +
293
+ (255 - scratchBytes[3]));
294
+ }
295
+ return (scratchBytes[0] << 16) + (scratchBytes[1] << 8) + scratchBytes[2];
296
+ }
297
+ /**
298
+ * Get the alpha value for this ColorDef. Will be between 0-255
299
+ */
300
+ getAlpha() {
301
+ return ColorValue.getAlpha(this._tbgr);
302
+ }
303
+ /**
304
+ * Extract the alpha value from a 0xTTBBGGRR color.
305
+ */
306
+ static getAlpha(tbgr) {
307
+ scratchUInt32[0] = tbgr;
308
+ return 255 - scratchBytes[3];
309
+ }
310
+ /**
311
+ * Convert this ColorValue to a string in the form "#rrggbb" or "#rrggbbaa" where values are hex digits of the respective colors
312
+ */
313
+ toHexString(includeAlpha) {
314
+ if (includeAlpha) {
315
+ let value = this.getRgb(includeAlpha);
316
+ if (value < 0) {
317
+ value = 0xffffffff + value + 1;
318
+ }
319
+ return `#${`00000000${value.toString(16)}`.slice(-8)}`;
320
+ }
321
+ return `#${`000000${this.getRgb().toString(16)}`.slice(-6)}`;
322
+ }
323
+ /**
324
+ * Compute the 0xTTBBGGRR color corresponding to the specified hue, saturation, lightness values.
325
+ */
326
+ static computeTbgrFromHSL(
388
327
  /** 0-1 */
389
- h,
328
+ h,
390
329
  /** 0-1 */
391
- s,
330
+ s,
392
331
  /** 0-1 */
393
- l,
394
- transparency = 0,
395
- ) {
396
- const torgb = (p1, q1, t) => {
397
- if (t < 0) {
398
- t += 1;
399
- }
400
- if (t > 1) {
401
- t -= 1;
402
- }
403
- if (t < 1 / 6) {
404
- return p1 + (q1 - p1) * 6 * t;
405
- }
406
- if (t < 1 / 2) {
407
- return q1;
408
- }
409
- if (t < 2 / 3) {
410
- return p1 + (q1 - p1) * 6 * (2 / 3 - t);
411
- }
412
- return p1;
413
- };
414
- const hue2rgb = (p1, q1, t) => Math.round(torgb(p1, q1, t) * 255);
415
- const modulo = (n, m) => ((n % m) + m) % m;
416
- // h,s,l ranges are in 0.0 - 1.0
417
- h = modulo(h, 1);
418
- s = getBoundedValue(s, 0, 1);
419
- l = getBoundedValue(l, 0, 1);
420
- if (s === 0) {
421
- l *= 255;
422
- return this.computeTbgrFromComponents(l, l, l, transparency);
332
+ l, transparency = 0) {
333
+ const torgb = (p1, q1, t) => {
334
+ if (t < 0) {
335
+ t += 1;
336
+ }
337
+ if (t > 1) {
338
+ t -= 1;
339
+ }
340
+ if (t < 1 / 6) {
341
+ return p1 + (q1 - p1) * 6 * t;
342
+ }
343
+ if (t < 1 / 2) {
344
+ return q1;
345
+ }
346
+ if (t < 2 / 3) {
347
+ return p1 + (q1 - p1) * 6 * (2 / 3 - t);
348
+ }
349
+ return p1;
350
+ };
351
+ const hue2rgb = (p1, q1, t) => Math.round(torgb(p1, q1, t) * 255);
352
+ const modulo = (n, m) => ((n % m) + m) % m;
353
+ // h,s,l ranges are in 0.0 - 1.0
354
+ h = modulo(h, 1);
355
+ s = getBoundedValue(s, 0, 1);
356
+ l = getBoundedValue(l, 0, 1);
357
+ if (s === 0) {
358
+ l *= 255;
359
+ return this.computeTbgrFromComponents(l, l, l, transparency);
360
+ }
361
+ const p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
362
+ const q = 2 * l - p;
363
+ return this.computeTbgrFromComponents(hue2rgb(q, p, h + 1 / 3), hue2rgb(q, p, h), hue2rgb(q, p, h - 1 / 3), transparency);
364
+ }
365
+ /**
366
+ * Return HslColor from this ColorValue
367
+ */
368
+ toHslColor() {
369
+ return {
370
+ ...ColorValue.toHsl(this._tbgr),
371
+ ...(this._hue != undefined && { h: this._hue }),
372
+ };
373
+ }
374
+ /** Create an HslColor from this ColorValue */
375
+ static toHsl(tbgr) {
376
+ const { r, g, b } = ColorValue.getColors(tbgr);
377
+ const red = r / 255;
378
+ const green = g / 255;
379
+ const blue = b / 255;
380
+ const cMin = Math.min(red, green, blue);
381
+ const cMax = Math.max(red, green, blue);
382
+ const delta = cMax - cMin;
383
+ let hue = 0;
384
+ let saturation = 0;
385
+ if (0 === delta) {
386
+ hue = 0;
387
+ }
388
+ else if (red === cMax) {
389
+ hue = ((green - blue) / delta) % 6;
390
+ }
391
+ else if (green === cMax) {
392
+ hue = (blue - red) / delta + 2;
393
+ }
394
+ else {
395
+ hue = (red - green) / delta + 4;
396
+ }
397
+ hue = Math.round(hue * 60);
398
+ if (hue < 0) {
399
+ hue += 360;
400
+ }
401
+ let lightness = (cMax + cMin) / 2;
402
+ saturation = 0 === delta ? 0 : delta / (1 - Math.abs(2 * lightness - 1));
403
+ // round values to 1 decimal place
404
+ saturation = Number((saturation * 100).toFixed(1));
405
+ lightness = Number((lightness * 100).toFixed(1));
406
+ return {
407
+ h: hue,
408
+ s: saturation,
409
+ l: lightness,
410
+ a: this.getAlpha(tbgr) / 255,
411
+ };
423
412
  }
424
- const p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
425
- const q = 2 * l - p;
426
- return this.computeTbgrFromComponents(
427
- hue2rgb(q, p, h + 1 / 3),
428
- hue2rgb(q, p, h),
429
- hue2rgb(q, p, h - 1 / 3),
430
- transparency,
431
- );
432
- }
433
- /**
434
- * Return HslColor from this ColorValue
435
- */
436
- toHslColor() {
437
- return {
438
- ...ColorValue.toHsl(this._tbgr),
439
- ...(this._hue != undefined && { h: this._hue }),
440
- };
441
- }
442
- /** Create an HslColor from this ColorValue */
443
- static toHsl(tbgr) {
444
- const { r, g, b } = ColorValue.getColors(tbgr);
445
- const red = r / 255;
446
- const green = g / 255;
447
- const blue = b / 255;
448
- const cMin = Math.min(red, green, blue);
449
- const cMax = Math.max(red, green, blue);
450
- const delta = cMax - cMin;
451
- let hue = 0;
452
- let saturation = 0;
453
- if (0 === delta) {
454
- hue = 0;
455
- } else if (red === cMax) {
456
- hue = ((green - blue) / delta) % 6;
457
- } else if (green === cMax) {
458
- hue = (blue - red) / delta + 2;
459
- } else {
460
- hue = (red - green) / delta + 4;
413
+ /**
414
+ * Create an RgbColor from this ColorValue
415
+ */
416
+ toRgbColor() {
417
+ const { r, g, b } = ColorValue.getColors(this._tbgr);
418
+ return { r, g, b, a: this.getAlpha() / 255 };
461
419
  }
462
- hue = Math.round(hue * 60);
463
- if (hue < 0) {
464
- hue += 360;
420
+ /**
421
+ * Return HsvColor from this ColorValue
422
+ */
423
+ toHsvColor() {
424
+ return {
425
+ ...ColorValue.toHsv(this._tbgr),
426
+ ...(this._hue != undefined && { h: this._hue }),
427
+ };
465
428
  }
466
- let lightness = (cMax + cMin) / 2;
467
- saturation = 0 === delta ? 0 : delta / (1 - Math.abs(2 * lightness - 1));
468
- // round values to 1 decimal place
469
- saturation = Number((saturation * 100).toFixed(1));
470
- lightness = Number((lightness * 100).toFixed(1));
471
- return {
472
- h: hue,
473
- s: saturation,
474
- l: lightness,
475
- a: this.getAlpha(tbgr) / 255,
476
- };
477
- }
478
- /**
479
- * Create an RgbColor from this ColorValue
480
- */
481
- toRgbColor() {
482
- const { r, g, b } = ColorValue.getColors(this._tbgr);
483
- return { r, g, b, a: this.getAlpha() / 255 };
484
- }
485
- /**
486
- * Return HsvColor from this ColorValue
487
- */
488
- toHsvColor() {
489
- return {
490
- ...ColorValue.toHsv(this._tbgr),
491
- ...(this._hue != undefined && { h: this._hue }),
492
- };
493
- }
494
- /**
495
- * Create an HsvColor from this ColorValue
496
- */
497
- static toHsv(tbgr) {
498
- const { r, g, b } = ColorValue.getColors(tbgr);
499
- const red = r / 255;
500
- const green = g / 255;
501
- const blue = b / 255;
502
- const cMin = Math.min(red, green, blue);
503
- const cMax = Math.max(red, green, blue);
504
- const delta = cMax - cMin;
505
- let hue = 0;
506
- if (0 === delta) {
507
- hue = 0;
508
- } else if (red === cMax) {
509
- hue = ((green - blue) / delta) % 6;
510
- } else if (green === cMax) {
511
- hue = (blue - red) / delta + 2;
512
- } else {
513
- hue = (red - green) / delta + 4;
429
+ /**
430
+ * Create an HsvColor from this ColorValue
431
+ */
432
+ static toHsv(tbgr) {
433
+ const { r, g, b } = ColorValue.getColors(tbgr);
434
+ const red = r / 255;
435
+ const green = g / 255;
436
+ const blue = b / 255;
437
+ const cMin = Math.min(red, green, blue);
438
+ const cMax = Math.max(red, green, blue);
439
+ const delta = cMax - cMin;
440
+ let hue = 0;
441
+ if (0 === delta) {
442
+ hue = 0;
443
+ }
444
+ else if (red === cMax) {
445
+ hue = ((green - blue) / delta) % 6;
446
+ }
447
+ else if (green === cMax) {
448
+ hue = (blue - red) / delta + 2;
449
+ }
450
+ else {
451
+ hue = (red - green) / delta + 4;
452
+ }
453
+ hue = Math.round(hue * 60);
454
+ if (hue < 0) {
455
+ hue += 360;
456
+ }
457
+ let brightness = cMax;
458
+ let saturation = cMax === 0 ? 0 : delta / cMax;
459
+ // round values to 1 decimal place
460
+ saturation = Number((saturation * 100).toFixed(1));
461
+ brightness = Number((brightness * 100).toFixed(1));
462
+ return {
463
+ h: hue,
464
+ s: saturation,
465
+ v: brightness,
466
+ a: this.getAlpha(tbgr) / 255,
467
+ };
514
468
  }
515
- hue = Math.round(hue * 60);
516
- if (hue < 0) {
517
- hue += 360;
469
+ /** True if the value of this ColorValue is the same as another ColorValue. */
470
+ equals(other) {
471
+ return this._tbgr === other._tbgr;
518
472
  }
519
- let brightness = cMax;
520
- let saturation = cMax === 0 ? 0 : delta / cMax;
521
- // round values to 1 decimal place
522
- saturation = Number((saturation * 100).toFixed(1));
523
- brightness = Number((brightness * 100).toFixed(1));
524
- return {
525
- h: hue,
526
- s: saturation,
527
- v: brightness,
528
- a: this.getAlpha(tbgr) / 255,
529
- };
530
- }
531
- /** True if the value of this ColorValue is the same as another ColorValue. */
532
- equals(other) {
533
- return this._tbgr === other._tbgr;
534
- }
535
- static getFormattedColorNumber(value, precision = 1) {
536
- if (0 === precision) {
537
- Math.round(value).toString();
473
+ static getFormattedColorNumber(value, precision = 1) {
474
+ if (0 === precision) {
475
+ Math.round(value).toString();
476
+ }
477
+ return Number(value.toFixed(precision)).toString();
538
478
  }
539
- return Number(value.toFixed(precision)).toString();
540
- }
541
- /** Convert the 0xTTBBGGRR color to a string of the form "rgba(r,g,b,a)" where the color components are specified in decimal and the alpha component is a fraction. */
542
- toRgbString(includeAlpha) {
543
- const rgb = this.toRgbColor();
544
- const rgbString = `${rgb.r}, ${rgb.g}, ${rgb.b}`;
545
- if (includeAlpha) {
546
- const alpha = rgb.a ?? 1;
547
- return `rgba(${rgbString}, ${ColorValue.getFormattedColorNumber(
548
- alpha,
549
- 2,
550
- )})`;
479
+ /** Convert the 0xTTBBGGRR color to a string of the form "rgba(r,g,b,a)" where the color components are specified in decimal and the alpha component is a fraction. */
480
+ toRgbString(includeAlpha) {
481
+ const rgb = this.toRgbColor();
482
+ const rgbString = `${rgb.r}, ${rgb.g}, ${rgb.b}`;
483
+ if (includeAlpha) {
484
+ const alpha = rgb.a ?? 1;
485
+ return `rgba(${rgbString}, ${ColorValue.getFormattedColorNumber(alpha, 2)})`;
486
+ }
487
+ return `rgb(${rgbString})`;
551
488
  }
552
- return `rgb(${rgbString})`;
553
- }
554
- /** Convert this ColorValue to a string in the form "hsl(h,s,l) or hsla(h,s,l,a)" - i.e hsl(120,50%,50%). */
555
- toHslString(includeAlpha) {
556
- const hsl = this.toHslColor();
557
- const hslString = `${ColorValue.getFormattedColorNumber(
558
- this._hue ?? hsl.h,
559
- )}, ${ColorValue.getFormattedColorNumber(
560
- hsl.s,
561
- )}%, ${ColorValue.getFormattedColorNumber(hsl.l)}%`;
562
- if (includeAlpha) {
563
- const alpha = hsl.a ?? 1;
564
- return `hsla(${hslString}, ${ColorValue.getFormattedColorNumber(
565
- alpha,
566
- 2,
567
- )})`;
489
+ /** Convert this ColorValue to a string in the form "hsl(h,s,l) or hsla(h,s,l,a)" - i.e hsl(120,50%,50%). */
490
+ toHslString(includeAlpha) {
491
+ const hsl = this.toHslColor();
492
+ const hslString = `${ColorValue.getFormattedColorNumber(this._hue ?? hsl.h)}, ${ColorValue.getFormattedColorNumber(hsl.s)}%, ${ColorValue.getFormattedColorNumber(hsl.l)}%`;
493
+ if (includeAlpha) {
494
+ const alpha = hsl.a ?? 1;
495
+ return `hsla(${hslString}, ${ColorValue.getFormattedColorNumber(alpha, 2)})`;
496
+ }
497
+ return `hsl(${hslString})`;
568
498
  }
569
- return `hsl(${hslString})`;
570
- }
571
- /** Convert this ColorValue to a string in the form "hsv(h,s,v) or hsva(h,s,v,a)" - i.e hsv(120,50%,50%). */
572
- toHsvString(includeAlpha) {
573
- const hsv = this.toHsvColor();
574
- const hsvString = `${this._hue ?? hsv.h}, ${hsv.s}%, ${hsv.v}%`;
575
- if (includeAlpha) {
576
- const alpha = hsv.a ?? 1;
577
- return `hsva(${hsvString}, ${ColorValue.getFormattedColorNumber(
578
- alpha,
579
- 2,
580
- )})`;
499
+ /** Convert this ColorValue to a string in the form "hsv(h,s,v) or hsva(h,s,v,a)" - i.e hsv(120,50%,50%). */
500
+ toHsvString(includeAlpha) {
501
+ const hsv = this.toHsvColor();
502
+ const hsvString = `${this._hue ?? hsv.h}, ${hsv.s}%, ${hsv.v}%`;
503
+ if (includeAlpha) {
504
+ const alpha = hsv.a ?? 1;
505
+ return `hsva(${hsvString}, ${ColorValue.getFormattedColorNumber(alpha, 2)})`;
506
+ }
507
+ return `hsv(${hsvString})`;
581
508
  }
582
- return `hsv(${hsvString})`;
583
- }
584
509
  }