react-native-system-ui 0.0.6 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (366) hide show
  1. package/README.md +53 -30
  2. package/dist/cjs/components/action-sheet/ActionSheet.js +97 -105
  3. package/dist/cjs/components/action-sheet/tokens.js +16 -27
  4. package/dist/cjs/components/area/Area.js +54 -67
  5. package/dist/cjs/components/area/tokens.js +6 -3
  6. package/dist/cjs/components/avatar/Avatar.js +25 -23
  7. package/dist/cjs/components/badge/Badge.js +31 -31
  8. package/dist/cjs/components/badge/tokens.js +6 -8
  9. package/dist/cjs/components/button/Button.js +115 -151
  10. package/dist/cjs/components/button/ButtonGroup.js +8 -42
  11. package/dist/cjs/components/button/tokens.js +1 -8
  12. package/dist/cjs/components/calendar/Calendar.js +212 -223
  13. package/dist/cjs/components/calendar/tokens.js +3 -3
  14. package/dist/cjs/components/cascader/Cascader.js +177 -180
  15. package/dist/cjs/components/cascader/tokens.js +2 -2
  16. package/dist/cjs/components/cascader/useCascaderExtend.js +25 -29
  17. package/dist/cjs/components/cell/Cell.js +70 -83
  18. package/dist/cjs/components/cell/CellGroup.js +16 -29
  19. package/dist/cjs/components/checkbox/Checkbox.js +139 -132
  20. package/dist/cjs/components/checkbox/CheckboxGroup.js +4 -35
  21. package/dist/cjs/components/checkbox/tokens.js +7 -10
  22. package/dist/cjs/components/circle/Circle.js +25 -24
  23. package/dist/cjs/components/collapse/Collapse.js +75 -91
  24. package/dist/cjs/components/config-provider/ConfigProvider.js +16 -3
  25. package/dist/cjs/components/config-provider/DirectionContext.js +15 -0
  26. package/dist/cjs/components/config-provider/index.js +7 -0
  27. package/dist/cjs/components/config-provider/locale/en-US.js +32 -0
  28. package/dist/cjs/components/config-provider/locale/zh-CN.js +32 -0
  29. package/dist/cjs/components/config-provider/useDirection.js +16 -0
  30. package/dist/cjs/components/count-down/CountDown.js +20 -15
  31. package/dist/cjs/components/datetime-picker/DatetimePicker.js +61 -84
  32. package/dist/cjs/components/datetime-picker/tokens.js +14 -3
  33. package/dist/cjs/components/dialog/Dialog.js +153 -121
  34. package/dist/cjs/components/dialog/imperative.js +17 -30
  35. package/dist/cjs/components/divider/Divider.js +26 -28
  36. package/dist/cjs/components/empty/Empty.js +35 -39
  37. package/dist/cjs/components/error-boundary/ErrorBoundary.js +73 -0
  38. package/dist/cjs/components/error-boundary/index.js +19 -0
  39. package/dist/cjs/components/field/Field.js +109 -106
  40. package/dist/cjs/components/flex/Flex.js +18 -18
  41. package/dist/cjs/components/flex/FlexItem.js +26 -27
  42. package/dist/cjs/components/form/Form.js +142 -161
  43. package/dist/cjs/components/form/FormItem.js +69 -97
  44. package/dist/cjs/components/form/FormList.js +49 -37
  45. package/dist/cjs/components/form/tokens.js +6 -3
  46. package/dist/cjs/components/form/utils.js +15 -34
  47. package/dist/cjs/components/grid/Grid.js +30 -29
  48. package/dist/cjs/components/grid/GridItem.js +84 -85
  49. package/dist/cjs/components/image/Image.js +55 -59
  50. package/dist/cjs/components/image/tokens.js +2 -2
  51. package/dist/cjs/components/image-preview/ImagePreview.js +124 -112
  52. package/dist/cjs/components/image-preview/imperative.js +4 -13
  53. package/dist/cjs/components/index.js +13 -0
  54. package/dist/cjs/components/input/Input.js +30 -22
  55. package/dist/cjs/components/loading/Loading.js +14 -15
  56. package/dist/cjs/components/nav-bar/NavBar.js +68 -83
  57. package/dist/cjs/components/nav-bar/tokens.js +1 -9
  58. package/dist/cjs/components/notice-bar/NoticeBar.js +74 -77
  59. package/dist/cjs/components/notify/Notify.js +88 -84
  60. package/dist/cjs/components/notify/imperative.js +20 -43
  61. package/dist/cjs/components/notify/tokens.js +1 -11
  62. package/dist/cjs/components/number-keyboard/NumberKeyboard.js +187 -209
  63. package/dist/cjs/components/overlay/Overlay.js +37 -52
  64. package/dist/cjs/components/overlay/tokens.js +5 -3
  65. package/dist/cjs/components/password-input/PasswordInput.js +98 -79
  66. package/dist/cjs/components/picker/Picker.js +440 -421
  67. package/dist/cjs/components/picker/tokens.js +1 -1
  68. package/dist/cjs/components/popup/Popup.js +263 -293
  69. package/dist/cjs/components/portal/Portal.js +12 -29
  70. package/dist/cjs/components/portal/PortalHost.js +151 -234
  71. package/dist/cjs/components/progress/Progress.js +51 -48
  72. package/dist/cjs/components/radio/Radio.js +45 -42
  73. package/dist/cjs/components/radio/RadioGroup.js +8 -40
  74. package/dist/cjs/components/radio/tokens.js +7 -10
  75. package/dist/cjs/components/safe-area-view/SafeAreaView.js +22 -26
  76. package/dist/cjs/components/search/Search.js +51 -43
  77. package/dist/cjs/components/selector/Selector.js +14 -13
  78. package/dist/cjs/components/share-sheet/ShareSheet.js +160 -161
  79. package/dist/cjs/components/sidebar/Sidebar.js +39 -45
  80. package/dist/cjs/components/sidebar/SidebarContext.js +1 -2
  81. package/dist/cjs/components/sidebar/SidebarItem.js +13 -16
  82. package/dist/cjs/components/sidebar/tokens.js +1 -3
  83. package/dist/cjs/components/skeleton/Skeleton.js +30 -37
  84. package/dist/cjs/components/skeleton/tokens.js +1 -2
  85. package/dist/cjs/components/slider/Slider.js +156 -135
  86. package/dist/cjs/components/space/Space.js +46 -69
  87. package/dist/cjs/components/stepper/Stepper.js +177 -155
  88. package/dist/cjs/components/swiper/Swiper.js +251 -253
  89. package/dist/cjs/components/swiper/SwiperPagIndicator.js +25 -27
  90. package/dist/cjs/components/swiper/tokens.js +10 -3
  91. package/dist/cjs/components/switch/Switch.js +13 -15
  92. package/dist/cjs/components/tabbar/Tabbar.js +35 -27
  93. package/dist/cjs/components/tabbar/TabbarContext.js +1 -2
  94. package/dist/cjs/components/tabbar/TabbarItem.js +65 -68
  95. package/dist/cjs/components/tabs/Tabs.js +286 -313
  96. package/dist/cjs/components/tag/Tag.js +46 -37
  97. package/dist/cjs/components/toast/Toast.js +90 -90
  98. package/dist/cjs/components/toast/imperative.js +16 -41
  99. package/dist/cjs/components/typography/Typography.js +3 -5
  100. package/dist/cjs/components/water-mark/WaterMark.js +31 -29
  101. package/dist/cjs/design-system/ThemeProvider.js +5 -11
  102. package/dist/cjs/design-system/createComponentTokensHook.js +11 -13
  103. package/dist/cjs/design-system/presets.js +2 -3
  104. package/dist/cjs/design-system/tokens.js +2 -11
  105. package/dist/cjs/hooks/animation/index.js +25 -0
  106. package/dist/cjs/hooks/animation/useAnimatedTransition.js +72 -0
  107. package/dist/cjs/hooks/animation/useReducedMotion.js +75 -0
  108. package/dist/cjs/hooks/aria/useAriaListBox.js +8 -16
  109. package/dist/cjs/hooks/aria/useAriaOverlay.js +3 -3
  110. package/dist/cjs/hooks/aria/useAriaPress.js +8 -21
  111. package/dist/cjs/hooks/aria/useAriaToggle.js +3 -3
  112. package/dist/cjs/hooks/gesture/useGestureScroll.js +60 -61
  113. package/dist/cjs/hooks/index.js +12 -0
  114. package/dist/cjs/hooks/overlay/OverlayStackStore.js +49 -69
  115. package/dist/cjs/hooks/overlay/useOverlayStack.js +13 -19
  116. package/dist/cjs/hooks/useControllableValue.js +10 -21
  117. package/dist/cjs/hooks/useCountDown.js +14 -22
  118. package/dist/cjs/hooks/useHairline.js +17 -29
  119. package/dist/cjs/hooks/useSafeAreaPadding.js +1 -4
  120. package/dist/cjs/index.js +67 -1
  121. package/dist/cjs/platform/animation.js +10 -2
  122. package/dist/cjs/platform/measure.js +18 -36
  123. package/dist/cjs/utils/color.js +21 -35
  124. package/dist/cjs/utils/compare.js +7 -12
  125. package/dist/cjs/utils/createPlatformShadow.js +28 -39
  126. package/dist/cjs/utils/date.js +20 -50
  127. package/dist/cjs/utils/deepMerge.js +16 -26
  128. package/dist/cjs/utils/hairline.js +74 -71
  129. package/dist/cjs/utils/index.js +22 -0
  130. package/dist/cjs/utils/number.js +21 -29
  131. package/dist/cjs/utils/render.js +27 -0
  132. package/dist/cjs/utils/rtl.js +25 -0
  133. package/dist/cjs/utils/string.js +8 -25
  134. package/dist/es/components/action-sheet/ActionSheet.js +99 -107
  135. package/dist/es/components/action-sheet/tokens.js +16 -27
  136. package/dist/es/components/area/Area.js +55 -68
  137. package/dist/es/components/area/tokens.js +6 -3
  138. package/dist/es/components/avatar/Avatar.js +25 -23
  139. package/dist/es/components/avatar/index.js +1 -2
  140. package/dist/es/components/badge/Badge.js +33 -33
  141. package/dist/es/components/badge/tokens.js +6 -8
  142. package/dist/es/components/button/Button.js +116 -152
  143. package/dist/es/components/button/ButtonGroup.js +9 -43
  144. package/dist/es/components/button/tokens.js +2 -3
  145. package/dist/es/components/calendar/Calendar.js +214 -225
  146. package/dist/es/components/calendar/tokens.js +3 -3
  147. package/dist/es/components/cascader/Cascader.js +180 -183
  148. package/dist/es/components/cascader/tokens.js +2 -2
  149. package/dist/es/components/cascader/useCascaderExtend.js +25 -29
  150. package/dist/es/components/cell/Cell.js +71 -84
  151. package/dist/es/components/cell/CellGroup.js +16 -28
  152. package/dist/es/components/checkbox/Checkbox.js +140 -133
  153. package/dist/es/components/checkbox/CheckboxGroup.js +5 -36
  154. package/dist/es/components/checkbox/tokens.js +7 -10
  155. package/dist/es/components/circle/Circle.js +25 -23
  156. package/dist/es/components/collapse/Collapse.js +77 -92
  157. package/dist/es/components/config-provider/ConfigProvider.js +10 -3
  158. package/dist/es/components/config-provider/DirectionContext.js +2 -0
  159. package/dist/es/components/config-provider/index.js +1 -0
  160. package/dist/es/components/config-provider/locale/en-US.js +32 -0
  161. package/dist/es/components/config-provider/locale/zh-CN.js +32 -0
  162. package/dist/es/components/config-provider/useDirection.js +3 -0
  163. package/dist/es/components/count-down/CountDown.js +23 -18
  164. package/dist/es/components/datetime-picker/DatetimePicker.js +61 -84
  165. package/dist/es/components/datetime-picker/tokens.js +14 -3
  166. package/dist/es/components/dialog/Dialog.js +154 -121
  167. package/dist/es/components/dialog/imperative.js +17 -30
  168. package/dist/es/components/divider/Divider.js +28 -29
  169. package/dist/es/components/empty/Empty.js +36 -39
  170. package/dist/es/components/error-boundary/ErrorBoundary.js +61 -0
  171. package/dist/es/components/error-boundary/index.js +1 -0
  172. package/dist/es/components/field/Field.js +109 -106
  173. package/dist/es/components/flex/Flex.js +18 -17
  174. package/dist/es/components/flex/FlexItem.js +27 -27
  175. package/dist/es/components/form/Form.js +143 -162
  176. package/dist/es/components/form/FormItem.js +68 -95
  177. package/dist/es/components/form/FormList.js +49 -37
  178. package/dist/es/components/form/tokens.js +6 -3
  179. package/dist/es/components/form/utils.js +15 -34
  180. package/dist/es/components/grid/Grid.js +30 -28
  181. package/dist/es/components/grid/GridItem.js +84 -84
  182. package/dist/es/components/image/Image.js +58 -62
  183. package/dist/es/components/image/tokens.js +2 -2
  184. package/dist/es/components/image-preview/ImagePreview.js +124 -112
  185. package/dist/es/components/image-preview/imperative.js +4 -13
  186. package/dist/es/components/index.js +3 -1
  187. package/dist/es/components/input/Input.js +31 -23
  188. package/dist/es/components/loading/Loading.js +16 -16
  189. package/dist/es/components/nav-bar/NavBar.js +68 -83
  190. package/dist/es/components/nav-bar/tokens.js +1 -3
  191. package/dist/es/components/notice-bar/NoticeBar.js +74 -76
  192. package/dist/es/components/notify/Notify.js +92 -87
  193. package/dist/es/components/notify/imperative.js +21 -44
  194. package/dist/es/components/notify/tokens.js +1 -5
  195. package/dist/es/components/number-keyboard/NumberKeyboard.js +187 -209
  196. package/dist/es/components/overlay/Overlay.js +36 -51
  197. package/dist/es/components/overlay/tokens.js +5 -3
  198. package/dist/es/components/password-input/PasswordInput.js +98 -79
  199. package/dist/es/components/picker/Picker.js +440 -421
  200. package/dist/es/components/picker/tokens.js +1 -1
  201. package/dist/es/components/popup/Popup.js +263 -292
  202. package/dist/es/components/portal/Portal.js +13 -29
  203. package/dist/es/components/portal/PortalHost.js +152 -234
  204. package/dist/es/components/progress/Progress.js +51 -48
  205. package/dist/es/components/radio/Radio.js +47 -44
  206. package/dist/es/components/radio/RadioGroup.js +10 -41
  207. package/dist/es/components/radio/tokens.js +7 -10
  208. package/dist/es/components/safe-area-view/SafeAreaView.js +22 -25
  209. package/dist/es/components/search/Search.js +52 -44
  210. package/dist/es/components/selector/Selector.js +14 -13
  211. package/dist/es/components/share-sheet/ShareSheet.js +162 -163
  212. package/dist/es/components/sidebar/Sidebar.js +41 -47
  213. package/dist/es/components/sidebar/SidebarContext.js +1 -2
  214. package/dist/es/components/sidebar/SidebarItem.js +13 -15
  215. package/dist/es/components/sidebar/tokens.js +1 -3
  216. package/dist/es/components/skeleton/Skeleton.js +30 -37
  217. package/dist/es/components/skeleton/tokens.js +1 -2
  218. package/dist/es/components/slider/Slider.js +156 -134
  219. package/dist/es/components/space/Space.js +48 -71
  220. package/dist/es/components/stepper/Stepper.js +178 -156
  221. package/dist/es/components/swiper/Swiper.js +252 -254
  222. package/dist/es/components/swiper/SwiperPagIndicator.js +25 -27
  223. package/dist/es/components/swiper/tokens.js +10 -3
  224. package/dist/es/components/switch/Switch.js +13 -15
  225. package/dist/es/components/tabbar/Tabbar.js +36 -28
  226. package/dist/es/components/tabbar/TabbarContext.js +1 -2
  227. package/dist/es/components/tabbar/TabbarItem.js +66 -69
  228. package/dist/es/components/tabs/Tabs.js +286 -313
  229. package/dist/es/components/tag/Tag.js +49 -39
  230. package/dist/es/components/toast/Toast.js +93 -91
  231. package/dist/es/components/toast/imperative.js +16 -41
  232. package/dist/es/components/typography/Typography.js +3 -5
  233. package/dist/es/components/water-mark/WaterMark.js +32 -30
  234. package/dist/es/design-system/ThemeProvider.js +5 -11
  235. package/dist/es/design-system/createComponentTokensHook.js +11 -13
  236. package/dist/es/design-system/presets.js +2 -3
  237. package/dist/es/design-system/tokens.js +1 -9
  238. package/dist/es/hooks/animation/index.js +2 -0
  239. package/dist/es/hooks/animation/useAnimatedTransition.js +53 -0
  240. package/dist/es/hooks/animation/useReducedMotion.js +54 -0
  241. package/dist/es/hooks/aria/useAriaListBox.js +8 -16
  242. package/dist/es/hooks/aria/useAriaOverlay.js +3 -3
  243. package/dist/es/hooks/aria/useAriaPress.js +8 -21
  244. package/dist/es/hooks/aria/useAriaToggle.js +3 -3
  245. package/dist/es/hooks/gesture/useGestureScroll.js +60 -61
  246. package/dist/es/hooks/index.js +1 -0
  247. package/dist/es/hooks/overlay/OverlayStackStore.js +49 -69
  248. package/dist/es/hooks/overlay/useOverlayStack.js +13 -19
  249. package/dist/es/hooks/useControllableValue.js +10 -21
  250. package/dist/es/hooks/useCountDown.js +14 -22
  251. package/dist/es/hooks/useHairline.js +16 -28
  252. package/dist/es/hooks/useSafeAreaPadding.js +1 -4
  253. package/dist/es/index.js +8 -1
  254. package/dist/es/platform/animation.js +9 -1
  255. package/dist/es/platform/measure.js +18 -36
  256. package/dist/es/utils/color.js +21 -35
  257. package/dist/es/utils/compare.js +7 -12
  258. package/dist/es/utils/createPlatformShadow.js +28 -39
  259. package/dist/es/utils/date.js +20 -50
  260. package/dist/es/utils/deepMerge.js +16 -26
  261. package/dist/es/utils/hairline.js +73 -65
  262. package/dist/es/utils/index.js +2 -0
  263. package/dist/es/utils/number.js +21 -29
  264. package/dist/es/utils/render.js +7 -0
  265. package/dist/es/utils/rtl.js +17 -0
  266. package/dist/es/utils/string.js +8 -25
  267. package/dist/types/components/action-sheet/ActionSheet.d.ts +1 -1
  268. package/dist/types/components/area/Area.d.ts +1 -1
  269. package/dist/types/components/area/tokens.d.ts +4 -0
  270. package/dist/types/components/avatar/Avatar.d.ts +1 -1
  271. package/dist/types/components/avatar/index.d.ts +1 -2
  272. package/dist/types/components/badge/Badge.d.ts +1 -1
  273. package/dist/types/components/button/Button.d.ts +1 -1
  274. package/dist/types/components/button/index.d.ts +1 -1
  275. package/dist/types/components/calendar/Calendar.d.ts +1 -1
  276. package/dist/types/components/cascader/Cascader.d.ts +1 -1
  277. package/dist/types/components/cell/Cell.d.ts +1 -1
  278. package/dist/types/components/cell/CellGroup.d.ts +1 -1
  279. package/dist/types/components/cell/index.d.ts +2 -2
  280. package/dist/types/components/checkbox/Checkbox.d.ts +1 -1
  281. package/dist/types/components/circle/Circle.d.ts +1 -1
  282. package/dist/types/components/collapse/Collapse.d.ts +1 -2
  283. package/dist/types/components/config-provider/DirectionContext.d.ts +3 -0
  284. package/dist/types/components/config-provider/index.d.ts +2 -1
  285. package/dist/types/components/config-provider/locale/en-US.d.ts +32 -0
  286. package/dist/types/components/config-provider/locale/zh-CN.d.ts +32 -0
  287. package/dist/types/components/config-provider/useDirection.d.ts +1 -0
  288. package/dist/types/components/count-down/CountDown.d.ts +1 -1
  289. package/dist/types/components/datetime-picker/DatetimePicker.d.ts +1 -1
  290. package/dist/types/components/datetime-picker/tokens.d.ts +12 -0
  291. package/dist/types/components/dialog/Dialog.d.ts +1 -1
  292. package/dist/types/components/divider/Divider.d.ts +1 -1
  293. package/dist/types/components/empty/Empty.d.ts +1 -1
  294. package/dist/types/components/error-boundary/ErrorBoundary.d.ts +6 -0
  295. package/dist/types/components/error-boundary/index.d.ts +2 -0
  296. package/dist/types/components/field/Field.d.ts +1 -1
  297. package/dist/types/components/flex/Flex.d.ts +1 -1
  298. package/dist/types/components/flex/FlexItem.d.ts +1 -1
  299. package/dist/types/components/flex/index.d.ts +2 -2
  300. package/dist/types/components/form/Form.d.ts +1 -1
  301. package/dist/types/components/form/FormItem.d.ts +2 -1
  302. package/dist/types/components/form/index.d.ts +2 -2
  303. package/dist/types/components/form/tokens.d.ts +4 -0
  304. package/dist/types/components/grid/Grid.d.ts +1 -1
  305. package/dist/types/components/grid/GridItem.d.ts +1 -1
  306. package/dist/types/components/grid/index.d.ts +2 -2
  307. package/dist/types/components/image/Image.d.ts +1 -1
  308. package/dist/types/components/image-preview/ImagePreview.d.ts +1 -1
  309. package/dist/types/components/index.d.ts +4 -1
  310. package/dist/types/components/input/Input.d.ts +3 -3
  311. package/dist/types/components/loading/Loading.d.ts +1 -1
  312. package/dist/types/components/nav-bar/NavBar.d.ts +1 -1
  313. package/dist/types/components/notice-bar/NoticeBar.d.ts +1 -1
  314. package/dist/types/components/notify/Notify.d.ts +2 -2
  315. package/dist/types/components/notify/index.d.ts +1 -1
  316. package/dist/types/components/overlay/Overlay.d.ts +1 -5
  317. package/dist/types/components/overlay/tokens.d.ts +3 -0
  318. package/dist/types/components/password-input/PasswordInput.d.ts +1 -1
  319. package/dist/types/components/picker/Picker.d.ts +5 -5
  320. package/dist/types/components/popup/Popup.d.ts +3 -42
  321. package/dist/types/components/portal/Portal.d.ts +9 -6
  322. package/dist/types/components/portal/PortalHost.d.ts +1 -1
  323. package/dist/types/components/radio/RadioGroup.d.ts +1 -1
  324. package/dist/types/components/safe-area-view/SafeAreaView.d.ts +1 -1
  325. package/dist/types/components/search/Search.d.ts +1 -1
  326. package/dist/types/components/share-sheet/ShareSheet.d.ts +1 -1
  327. package/dist/types/components/sidebar/Sidebar.d.ts +1 -1
  328. package/dist/types/components/sidebar/SidebarContext.d.ts +1 -1
  329. package/dist/types/components/sidebar/SidebarItem.d.ts +1 -1
  330. package/dist/types/components/sidebar/index.d.ts +2 -2
  331. package/dist/types/components/skeleton/Skeleton.d.ts +1 -1
  332. package/dist/types/components/slider/Slider.d.ts +1 -1
  333. package/dist/types/components/stepper/Stepper.d.ts +1 -1
  334. package/dist/types/components/swiper/Swiper.d.ts +1 -1
  335. package/dist/types/components/swiper/index.d.ts +1 -1
  336. package/dist/types/components/swiper/tokens.d.ts +8 -0
  337. package/dist/types/components/tabbar/Tabbar.d.ts +2 -2
  338. package/dist/types/components/tabbar/TabbarContext.d.ts +1 -1
  339. package/dist/types/components/tabbar/TabbarItem.d.ts +2 -2
  340. package/dist/types/components/tabs/Tabs.d.ts +1 -1
  341. package/dist/types/components/tabs/index.d.ts +1 -1
  342. package/dist/types/components/tag/Tag.d.ts +1 -1
  343. package/dist/types/components/toast/Toast.d.ts +2 -2
  344. package/dist/types/components/toast/index.d.ts +1 -1
  345. package/dist/types/components/water-mark/WaterMark.d.ts +1 -1
  346. package/dist/types/design-system/tokens.d.ts +0 -1
  347. package/dist/types/hooks/animation/index.d.ts +3 -0
  348. package/dist/types/hooks/animation/useAnimatedTransition.d.ts +13 -0
  349. package/dist/types/hooks/animation/useReducedMotion.d.ts +3 -0
  350. package/dist/types/hooks/aria/useAriaOverlay.d.ts +1 -1
  351. package/dist/types/hooks/gesture/useGestureScroll.d.ts +11 -10
  352. package/dist/types/hooks/index.d.ts +1 -0
  353. package/dist/types/hooks/overlay/OverlayStackStore.d.ts +8 -8
  354. package/dist/types/hooks/useHairline.d.ts +1 -1
  355. package/dist/types/index.d.ts +5 -0
  356. package/dist/types/platform/animation.d.ts +8 -0
  357. package/dist/types/platform/measure.d.ts +1 -1
  358. package/dist/types/utils/compare.d.ts +1 -1
  359. package/dist/types/utils/createPlatformShadow.d.ts +2 -2
  360. package/dist/types/utils/date.d.ts +2 -2
  361. package/dist/types/utils/hairline.d.ts +5 -10
  362. package/dist/types/utils/index.d.ts +2 -0
  363. package/dist/types/utils/number.d.ts +2 -2
  364. package/dist/types/utils/render.d.ts +5 -0
  365. package/dist/types/utils/rtl.d.ts +5 -0
  366. package/package.json +10 -3
@@ -1,94 +1,78 @@
1
1
  import { BackHandler, Platform } from 'react-native';
2
2
  import { setBodyScrollLocked } from '../../platform';
3
3
  import { isNumber } from '../../utils';
4
- const DEFAULT_BASE_Z_INDEX = 1000;
5
- const DEFAULT_Z_INDEX_STEP = 2;
6
4
  export class OverlayStackStore {
7
5
  listeners = new Set();
8
6
  entries = [];
9
7
  keySeed = 0;
10
- constructor(baseZIndex = DEFAULT_BASE_Z_INDEX, zIndexStep = DEFAULT_Z_INDEX_STEP) {
11
- this.baseZIndex = baseZIndex;
12
- this.zIndexStep = zIndexStep;
8
+ constructor(baseZ = 1000, zStep = 2) {
9
+ this.baseZ = baseZ;
10
+ this.zStep = zStep;
13
11
  }
14
- subscribe = listener => {
15
- this.listeners.add(listener);
12
+ subscribe = l => {
13
+ this.listeners.add(l);
16
14
  return () => {
17
- this.listeners.delete(listener);
15
+ this.listeners.delete(l);
18
16
  };
19
17
  };
20
18
  getSnapshot = () => this.entries;
21
- mount = options => {
22
- const key = ++this.keySeed;
19
+ peek = () => this.entries[this.entries.length - 1];
20
+ size = () => this.entries.length;
21
+ getBaseZIndex = () => this.baseZ;
22
+ mount = o => {
23
23
  const entry = {
24
- key,
25
- zIndex: this.resolveZIndex(options.zIndex),
26
- onClose: options.onClose,
27
- closeOnBack: options.closeOnBack,
28
- lockScroll: options.lockScroll,
29
- type: options.type,
30
- meta: options.meta
24
+ key: ++this.keySeed,
25
+ zIndex: this.resolveZ(o.zIndex),
26
+ onClose: o.onClose,
27
+ closeOnBack: o.closeOnBack,
28
+ lockScroll: o.lockScroll,
29
+ type: o.type,
30
+ meta: o.meta
31
31
  };
32
32
  this.entries = [...this.entries, entry];
33
33
  this.emit();
34
34
  return entry;
35
35
  };
36
- update = (key, options) => {
37
- const index = this.entries.findIndex(item => item.key === key);
38
- if (index === -1) return undefined;
39
- const prev = this.entries[index];
36
+ update = (key, o) => {
37
+ const i = this.entries.findIndex(e => e.key === key);
38
+ if (i === -1) return undefined;
40
39
  const next = {
41
- ...prev,
42
- ...options,
43
- zIndex: isNumber(options.zIndex) ? this.resolveZIndex(options.zIndex) : prev.zIndex
40
+ ...this.entries[i],
41
+ ...o,
42
+ zIndex: isNumber(o.zIndex) ? this.resolveZ(o.zIndex) : this.entries[i].zIndex
44
43
  };
45
- this.entries = [...this.entries.slice(0, index), next, ...this.entries.slice(index + 1)];
44
+ this.entries = [...this.entries.slice(0, i), next, ...this.entries.slice(i + 1)];
46
45
  this.emit();
47
46
  return next;
48
47
  };
49
48
  unmount = key => {
50
- const next = this.entries.filter(entry => entry.key !== key);
51
- if (next.length === this.entries.length) {
52
- return;
49
+ const next = this.entries.filter(e => e.key !== key);
50
+ if (next.length !== this.entries.length) {
51
+ this.entries = next;
52
+ this.emit();
53
53
  }
54
- this.entries = next;
55
- this.emit();
56
54
  };
57
- peek = () => this.entries[this.entries.length - 1];
58
- size = () => this.entries.length;
59
- getBaseZIndex = () => this.baseZIndex;
60
- resolveZIndex = provided => {
61
- if (isNumber(provided)) {
62
- if (!Number.isFinite(provided) || provided < 0) {
63
- return this.baseZIndex;
64
- }
65
- return provided >= this.baseZIndex ? provided : this.baseZIndex + provided;
66
- }
55
+ resolveZ = v => {
56
+ if (isNumber(v)) return !Number.isFinite(v) || v < 0 ? this.baseZ : v >= this.baseZ ? v : this.baseZ + v;
67
57
  const top = this.peek();
68
- if (!top) {
69
- return this.baseZIndex;
70
- }
71
- return top.zIndex + this.zIndexStep;
58
+ return top ? top.zIndex + this.zStep : this.baseZ;
72
59
  };
73
60
  emit = () => {
74
- this.listeners.forEach(listener => {
75
- listener();
76
- });
61
+ this.listeners.forEach(l => l());
77
62
  };
78
63
  }
79
64
  export const overlayStackStore = new OverlayStackStore();
80
- let backHandlerSubscription = null;
81
- const syncBackHandler = () => {
65
+ let backSub = null;
66
+ const syncBack = () => {
82
67
  if (Platform.OS === 'web') return;
83
68
  const entries = overlayStackStore.getSnapshot();
84
- const hasClosable = entries.some(entry => entry.closeOnBack && entry.onClose);
85
- if (hasClosable && !backHandlerSubscription && BackHandler?.addEventListener) {
86
- backHandlerSubscription = BackHandler.addEventListener('hardwareBackPress', () => {
87
- const currentEntries = overlayStackStore.getSnapshot();
88
- for (let i = currentEntries.length - 1; i >= 0; i -= 1) {
89
- const entry = currentEntries[i];
90
- if (entry.closeOnBack && entry.onClose) {
91
- entry.onClose();
69
+ const has = entries.some(e => e.closeOnBack && e.onClose);
70
+ if (has && !backSub && BackHandler?.addEventListener) {
71
+ backSub = BackHandler.addEventListener('hardwareBackPress', () => {
72
+ const cur = overlayStackStore.getSnapshot();
73
+ for (let i = cur.length - 1; i >= 0; i--) {
74
+ if (cur[i].closeOnBack && cur[i].onClose) {
75
+ cur[i].onClose();
92
76
  return true;
93
77
  }
94
78
  }
@@ -96,18 +80,14 @@ const syncBackHandler = () => {
96
80
  });
97
81
  return;
98
82
  }
99
- if (!hasClosable && backHandlerSubscription) {
100
- backHandlerSubscription.remove();
101
- backHandlerSubscription = null;
83
+ if (!has && backSub) {
84
+ backSub.remove();
85
+ backSub = null;
102
86
  }
103
87
  };
104
- const syncScrollLock = () => {
105
- const shouldLock = overlayStackStore.getSnapshot().some(entry => entry.lockScroll);
106
- setBodyScrollLocked(shouldLock);
107
- };
108
- const handleStoreChange = () => {
109
- syncBackHandler();
110
- syncScrollLock();
88
+ const onChange = () => {
89
+ syncBack();
90
+ setBodyScrollLocked(overlayStackStore.getSnapshot().some(e => e.lockScroll));
111
91
  };
112
- overlayStackStore.subscribe(handleStoreChange);
113
- handleStoreChange();
92
+ overlayStackStore.subscribe(onChange);
93
+ onChange();
@@ -1,17 +1,15 @@
1
1
  import { useEffect, useRef, useSyncExternalStore } from 'react';
2
2
  import { overlayStackStore } from './OverlayStackStore';
3
- const useOverlayEntries = () => useSyncExternalStore(overlayStackStore.subscribe, overlayStackStore.getSnapshot, overlayStackStore.getSnapshot);
3
+ const useEntries = () => useSyncExternalStore(overlayStackStore.subscribe, overlayStackStore.getSnapshot, overlayStackStore.getSnapshot);
4
4
  export const useOverlayStack = ({
5
5
  visible,
6
6
  ...options
7
7
  }) => {
8
- const entries = useOverlayEntries();
8
+ const entries = useEntries();
9
9
  const entryRef = useRef(null);
10
- const optionsRef = useRef(options);
11
- if (optionsRef.current.onClose !== options.onClose || optionsRef.current.closeOnBack !== options.closeOnBack || optionsRef.current.lockScroll !== options.lockScroll || optionsRef.current.zIndex !== options.zIndex || optionsRef.current.type !== options.type || optionsRef.current.meta !== options.meta) {
12
- optionsRef.current = options;
13
- }
14
- const stableOptions = optionsRef.current;
10
+ const optRef = useRef(options);
11
+ if (optRef.current.onClose !== options.onClose || optRef.current.closeOnBack !== options.closeOnBack || optRef.current.lockScroll !== options.lockScroll || optRef.current.zIndex !== options.zIndex || optRef.current.type !== options.type || optRef.current.meta !== options.meta) optRef.current = options;
12
+ const opts = optRef.current;
15
13
  useEffect(() => {
16
14
  if (!visible) {
17
15
  if (entryRef.current) {
@@ -20,8 +18,7 @@ export const useOverlayStack = ({
20
18
  }
21
19
  return;
22
20
  }
23
- const entry = overlayStackStore.mount(stableOptions);
24
- entryRef.current = entry;
21
+ entryRef.current = overlayStackStore.mount(opts);
25
22
  return () => {
26
23
  if (entryRef.current) {
27
24
  overlayStackStore.unmount(entryRef.current.key);
@@ -30,17 +27,14 @@ export const useOverlayStack = ({
30
27
  };
31
28
  }, [visible]);
32
29
  useEffect(() => {
33
- if (!visible || !entryRef.current) {
34
- return;
35
- }
36
- overlayStackStore.update(entryRef.current.key, stableOptions);
37
- }, [stableOptions, visible]);
38
- const current = entryRef.current;
39
- const snapshotEntry = current ? entries.find(entry => entry.key === current.key) : undefined;
30
+ if (visible && entryRef.current) overlayStackStore.update(entryRef.current.key, opts);
31
+ }, [opts, visible]);
32
+ const cur = entryRef.current;
33
+ const snap = cur ? entries.find(e => e.key === cur.key) : undefined;
40
34
  const top = entries[entries.length - 1];
41
35
  return {
42
- entryKey: snapshotEntry?.key ?? null,
43
- zIndex: snapshotEntry?.zIndex ?? stableOptions.zIndex,
44
- isTopMost: !!snapshotEntry && !!top && top.key === snapshotEntry.key
36
+ entryKey: snap?.key ?? null,
37
+ zIndex: snap?.zIndex ?? opts.zIndex,
38
+ isTopMost: !!snap && !!top && top.key === snap.key
45
39
  };
46
40
  };
@@ -8,33 +8,22 @@ function useControllableValue(props = {}, options = {}) {
8
8
  valuePropName = 'value',
9
9
  trigger = 'onChange'
10
10
  } = options;
11
- const propsRecord = props;
11
+ const p = props;
12
12
  const isControlled = hasProp(props, valuePropName);
13
- const value = propsRecord[valuePropName];
13
+ const value = p[valuePropName];
14
14
  const [internalValue, setInternalValue] = useState(() => {
15
- if (isControlled) {
16
- return value;
17
- }
18
- if (hasProp(props, defaultValuePropName)) {
19
- return propsRecord[defaultValuePropName];
20
- }
15
+ if (isControlled) return value;
16
+ if (hasProp(props, defaultValuePropName)) return p[defaultValuePropName];
21
17
  return defaultValue;
22
18
  });
23
- const mergedValue = isControlled ? value : internalValue;
24
- const handlerRef = useRef(propsRecord[trigger]);
19
+ const handlerRef = useRef(p[trigger]);
25
20
  useEffect(() => {
26
- handlerRef.current = propsRecord[trigger];
21
+ handlerRef.current = p[trigger];
27
22
  }, [props, trigger]);
28
- const triggerChange = useCallback((nextValue, ...args) => {
29
- if (!isControlled) {
30
- setInternalValue(nextValue);
31
- }
32
- const handler = handlerRef.current;
33
- if (isFunction(handler)) {
34
- ;
35
- handler(nextValue, ...args);
36
- }
23
+ const triggerChange = useCallback((next, ...args) => {
24
+ if (!isControlled) setInternalValue(next);
25
+ if (isFunction(handlerRef.current)) handlerRef.current(next, ...args);
37
26
  }, [isControlled]);
38
- return [mergedValue, triggerChange];
27
+ return [isControlled ? value : internalValue, triggerChange];
39
28
  }
40
29
  export default useControllableValue;
@@ -1,19 +1,14 @@
1
1
  import { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import { isNumber } from '../utils/validate';
3
3
  const parseTime = time => {
4
- const total = Math.max(time, 0);
5
- const days = Math.floor(total / (24 * 60 * 60 * 1000));
6
- const hours = Math.floor(total % (24 * 60 * 60 * 1000) / (60 * 60 * 1000));
7
- const minutes = Math.floor(total % (60 * 60 * 1000) / (60 * 1000));
8
- const seconds = Math.floor(total % (60 * 1000) / 1000);
9
- const milliseconds = total % 1000;
4
+ const t = Math.max(time, 0);
10
5
  return {
11
- total,
12
- days,
13
- hours,
14
- minutes,
15
- seconds,
16
- milliseconds
6
+ total: t,
7
+ days: Math.floor(t / 86400000),
8
+ hours: Math.floor(t % 86400000 / 3600000),
9
+ minutes: Math.floor(t % 3600000 / 60000),
10
+ seconds: Math.floor(t % 60000 / 1000),
11
+ milliseconds: t % 1000
17
12
  };
18
13
  };
19
14
  const useCountDown = options => {
@@ -24,11 +19,11 @@ const useCountDown = options => {
24
19
  onFinish
25
20
  } = options;
26
21
  const timeRef = useRef(time);
27
- const millisecondRef = useRef(millisecond);
22
+ const msRef = useRef(millisecond);
28
23
  const onChangeRef = useRef(onChange);
29
24
  const onFinishRef = useRef(onFinish);
30
25
  timeRef.current = time;
31
- millisecondRef.current = millisecond;
26
+ msRef.current = millisecond;
32
27
  onChangeRef.current = onChange;
33
28
  onFinishRef.current = onFinish;
34
29
  const remainRef = useRef(Math.max(0, time));
@@ -59,10 +54,7 @@ const useCountDown = options => {
59
54
  const remain = Math.max(endTimeRef.current - Date.now(), 0);
60
55
  update(remain);
61
56
  if (remain <= 0) return;
62
- const delay = millisecondRef.current ? Math.max(1, Math.min(30, remain)) : Math.max(1, Math.min(remain, remain % 1000 + 1));
63
- timerRef.current = setTimeout(() => {
64
- tick();
65
- }, delay);
57
+ timerRef.current = setTimeout(tick, msRef.current ? Math.max(1, Math.min(30, remain)) : Math.max(1, Math.min(remain, remain % 1000 + 1)));
66
58
  }, [clearTimer, update]);
67
59
  const start = useCallback(() => {
68
60
  if (countingRef.current || remainRef.current <= 0) return;
@@ -78,10 +70,10 @@ const useCountDown = options => {
78
70
  }, [clearTimer]);
79
71
  const reset = useCallback(newTime => {
80
72
  pause();
81
- const next = Math.max(0, isNumber(newTime) ? newTime : timeRef.current);
82
- remainRef.current = next;
83
- endTimeRef.current = Date.now() + next;
84
- setCurrent(parseTime(next));
73
+ const n = Math.max(0, isNumber(newTime) ? newTime : timeRef.current);
74
+ remainRef.current = n;
75
+ endTimeRef.current = Date.now() + n;
76
+ setCurrent(parseTime(n));
85
77
  }, [pause]);
86
78
  useEffect(() => () => clearTimer(), [clearTimer]);
87
79
  return {
@@ -8,31 +8,19 @@ export const useHairline = ({
8
8
  color,
9
9
  width,
10
10
  defaultPaddingHorizontal = 0
11
- }) => {
12
- return useMemo(() => {
13
- if (!show) return null;
14
- const flattened = StyleSheet.flatten(containerStyle);
15
- const paddingHorizontal = isNumber(flattened?.paddingHorizontal) ? flattened.paddingHorizontal : undefined;
16
- const resolveInset = (primary, secondary) => isNumber(primary) ? primary : isNumber(secondary) ? secondary : isNumber(paddingHorizontal) ? paddingHorizontal : defaultPaddingHorizontal;
17
- const resolvedPadding = {
18
- left: resolveInset(flattened?.paddingLeft, flattened?.paddingStart),
19
- right: resolveInset(flattened?.paddingRight, flattened?.paddingEnd)
20
- };
21
- return /*#__PURE__*/React.createElement(View, {
22
- style: [styles.hairline, createHairlineView({
23
- position: 'bottom',
24
- color,
25
- left: resolvedPadding.left,
26
- right: resolvedPadding.right,
27
- enabled: width > 0,
28
- width
29
- })]
30
- });
31
- }, [show, containerStyle, color, width, defaultPaddingHorizontal]);
32
- };
33
- const styles = StyleSheet.create({
34
- hairline: {
35
- position: 'absolute',
36
- bottom: 0
37
- }
38
- });
11
+ }) => useMemo(() => {
12
+ if (!show) return null;
13
+ const f = StyleSheet.flatten(containerStyle);
14
+ const ph = isNumber(f?.paddingHorizontal) ? f.paddingHorizontal : undefined;
15
+ const r = (a, b) => isNumber(a) ? a : isNumber(b) ? b : isNumber(ph) ? ph : defaultPaddingHorizontal;
16
+ return /*#__PURE__*/React.createElement(View, {
17
+ style: createHairlineView({
18
+ position: 'bottom',
19
+ color,
20
+ left: r(f?.paddingLeft, f?.paddingStart),
21
+ right: r(f?.paddingRight, f?.paddingEnd),
22
+ enabled: width > 0,
23
+ width
24
+ })
25
+ });
26
+ }, [show, containerStyle, color, width, defaultPaddingHorizontal]);
@@ -3,10 +3,7 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
3
3
  export function useSafeAreaPadding(min) {
4
4
  const insets = useSafeAreaInsets();
5
5
  if (Platform.OS === 'web') {
6
- const t = min?.top ?? 0,
7
- b = min?.bottom ?? 0,
8
- l = min?.left ?? 0,
9
- r = min?.right ?? 0;
6
+ const [t, b, l, r] = [min?.top ?? 0, min?.bottom ?? 0, min?.left ?? 0, min?.right ?? 0];
10
7
  return {
11
8
  paddingTop: `max(env(safe-area-inset-top, 0px), ${t}px)`,
12
9
  paddingBottom: `max(env(safe-area-inset-bottom, 0px), ${b}px)`,
package/dist/es/index.js CHANGED
@@ -1,4 +1,11 @@
1
1
  export * from './components';
2
2
  export * from './design-system';
3
3
  export * from './hooks';
4
- export {};
4
+ // Utilities
5
+ export { flipStyle, rtlRow } from './utils/rtl';
6
+ export { deepMerge } from './utils/deepMerge';
7
+ export { createPlatformShadow } from './utils/createPlatformShadow';
8
+
9
+ // Platform helpers
10
+ export { nativeDriverEnabled } from './platform/animation';
11
+ export { isWeb, isIOS, isAndroid } from './platform/runtime';
@@ -1,2 +1,10 @@
1
1
  import { Platform } from 'react-native';
2
- export const nativeDriverEnabled = Platform.OS !== 'web';
2
+ export const nativeDriverEnabled = Platform.OS !== 'web';
3
+ export const defaultAnimationConfig = {
4
+ useNativeDriver: nativeDriverEnabled,
5
+ isInteraction: false
6
+ };
7
+ export const hardwareAccelerationProps = {
8
+ renderToHardwareTextureAndroid: Platform.OS === 'android',
9
+ shouldRasterizeIOS: Platform.OS === 'ios'
10
+ };
@@ -1,48 +1,30 @@
1
1
  import { isFunction } from '../utils/validate';
2
- export const measureInWindow = (node, callback) => {
2
+ const toRect = (x, y, w, h) => [x, y, w, h].every(Number.isFinite) ? {
3
+ x: x,
4
+ y: y,
5
+ width: w,
6
+ height: h
7
+ } : null;
8
+ export const measureInWindow = (node, cb) => {
3
9
  if (!node) {
4
- callback(null);
10
+ cb(null);
5
11
  return;
6
12
  }
7
13
  try {
8
- const maybeMeasureNode = node;
9
- if (isFunction(maybeMeasureNode.measureInWindow)) {
10
- maybeMeasureNode.measureInWindow((x, y, width, height) => {
11
- if (![x, y, width, height].every(Number.isFinite)) {
12
- callback(null);
13
- return;
14
- }
15
- callback({
16
- x,
17
- y,
18
- width,
19
- height
20
- });
21
- });
14
+ const mn = node;
15
+ if (isFunction(mn.measureInWindow)) {
16
+ mn.measureInWindow((x, y, w, h) => cb(toRect(x, y, w, h)));
22
17
  return;
23
18
  }
24
- const maybeDomNode = node;
25
- if (isFunction(maybeDomNode.getBoundingClientRect)) {
26
- const rect = maybeDomNode.getBoundingClientRect();
27
- const x = rect?.left;
28
- const y = rect?.top;
29
- const width = rect?.width;
30
- const height = rect?.height;
31
- if (![x, y, width, height].every(Number.isFinite)) {
32
- callback(null);
33
- return;
34
- }
35
- callback({
36
- x: x,
37
- y: y,
38
- width: width,
39
- height: height
40
- });
19
+ const dn = node;
20
+ if (isFunction(dn.getBoundingClientRect)) {
21
+ const r = dn.getBoundingClientRect();
22
+ cb(toRect(r?.left, r?.top, r?.width, r?.height));
41
23
  return;
42
24
  }
43
- } catch (_error) {
44
- callback(null);
25
+ } catch {
26
+ cb(null);
45
27
  return;
46
28
  }
47
- callback(null);
29
+ cb(null);
48
30
  };
@@ -1,42 +1,28 @@
1
1
  import { clamp01 } from './number';
2
- const hexRegex = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
2
+ const HEX_RE = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
3
3
  export const hexToRgb = input => {
4
- if (!hexRegex.test(input)) return null;
5
- const normalized = input.length === 4 ? `#${input[1]}${input[1]}${input[2]}${input[2]}${input[3]}${input[3]}` : input;
6
- const intVal = parseInt(normalized.slice(1), 16);
7
- const r = intVal >> 16 & 255;
8
- const g = intVal >> 8 & 255;
9
- const b = intVal & 255;
10
- return [r, g, b];
4
+ if (!HEX_RE.test(input)) return null;
5
+ const h = input.length === 4 ? `#${input[1]}${input[1]}${input[2]}${input[2]}${input[3]}${input[3]}` : input;
6
+ const v = parseInt(h.slice(1), 16);
7
+ return [v >> 16 & 255, v >> 8 & 255, v & 255];
11
8
  };
12
- const parseRgbChannels = input => {
13
- const match = input.match(/^rgba?\(([^)]*)\)$/i);
14
- if (!match) return null;
15
- const parts = match[1].split(',').map(part => part.trim()).slice(0, 3);
16
- const numeric = parts.map(value => Number(value));
17
- if (!numeric.every(channel => Number.isFinite(channel))) return null;
18
- return [numeric[0], numeric[1], numeric[2]];
9
+ const parseRgb = input => {
10
+ const m = input.match(/^rgba?\(([^)]*)\)$/i);
11
+ if (!m) return null;
12
+ const n = m[1].split(',').map(s => Number(s.trim()));
13
+ return n.length >= 3 && n.every(Number.isFinite) ? [n[0], n[1], n[2]] : null;
19
14
  };
20
15
  export const withAlpha = (color, alpha) => {
21
- const clamped = clamp01(alpha);
22
- const trimmed = color?.trim?.() ?? '';
23
- if (!trimmed) return color;
24
- if (trimmed.startsWith('#')) {
25
- const rgb = hexToRgb(trimmed);
26
- return rgb ? `rgba(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, ${clamped})` : color;
16
+ const a = clamp01(alpha);
17
+ const t = color?.trim?.() ?? '';
18
+ if (!t) return color;
19
+ if (t.startsWith('#')) {
20
+ const rgb = hexToRgb(t);
21
+ return rgb ? `rgba(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, ${a})` : color;
27
22
  }
28
- const rgb = parseRgbChannels(trimmed);
29
- if (rgb) return `rgba(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, ${clamped})`;
30
- return trimmed;
23
+ const rgb = parseRgb(t);
24
+ return rgb ? `rgba(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, ${a})` : t;
31
25
  };
32
- export const ensureRgba = (color, alpha) => {
33
- const trimmed = color.trim().toLowerCase();
34
- if (trimmed.startsWith('rgba')) return color;
35
- return withAlpha(color, alpha);
36
- };
37
- const gradientColorRegex = /(#[0-9a-fA-F]{3,8}|rgba?\([^)]*\)|hsla?\([^)]*\))/i;
38
- export const extractFirstColorToken = input => {
39
- if (!input) return undefined;
40
- const match = input.match(gradientColorRegex);
41
- return match ? match[0] : undefined;
42
- };
26
+ export const ensureRgba = (color, alpha) => color.trim().toLowerCase().startsWith('rgba') ? color : withAlpha(color, alpha);
27
+ const GRADIENT_RE = /(#[0-9a-fA-F]{3,8}|rgba?\([^)]*\)|hsla?\([^)]*\))/i;
28
+ export const extractFirstColorToken = input => input ? input.match(GRADIENT_RE)?.[0] : undefined;
@@ -1,18 +1,13 @@
1
1
  export const shallowEqualArray = (a = [], b = []) => {
2
2
  if (a.length !== b.length) return false;
3
- for (let i = 0; i < a.length; i += 1) {
4
- if (a[i] !== b[i]) return false;
5
- }
3
+ for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
6
4
  return true;
7
5
  };
8
- export const shallowEqualObject = (prev, next) => {
9
- if (prev === next) return true;
10
- if (!prev || !next) return false;
11
- const prevKeys = Object.keys(prev);
12
- const nextKeys = Object.keys(next);
13
- if (prevKeys.length !== nextKeys.length) return false;
14
- for (const key of prevKeys) {
15
- if (prev[key] !== next[key]) return false;
16
- }
6
+ export const shallowEqualObject = (a, b) => {
7
+ if (a === b) return true;
8
+ if (!a || !b) return false;
9
+ const ak = Object.keys(a);
10
+ if (ak.length !== Object.keys(b).length) return false;
11
+ for (const k of ak) if (a[k] !== b[k]) return false;
17
12
  return true;
18
13
  };