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.
- package/README.md +53 -30
- package/dist/cjs/components/action-sheet/ActionSheet.js +97 -105
- package/dist/cjs/components/action-sheet/tokens.js +16 -27
- package/dist/cjs/components/area/Area.js +54 -67
- package/dist/cjs/components/area/tokens.js +6 -3
- package/dist/cjs/components/avatar/Avatar.js +25 -23
- package/dist/cjs/components/badge/Badge.js +31 -31
- package/dist/cjs/components/badge/tokens.js +6 -8
- package/dist/cjs/components/button/Button.js +115 -151
- package/dist/cjs/components/button/ButtonGroup.js +8 -42
- package/dist/cjs/components/button/tokens.js +1 -8
- package/dist/cjs/components/calendar/Calendar.js +212 -223
- package/dist/cjs/components/calendar/tokens.js +3 -3
- package/dist/cjs/components/cascader/Cascader.js +177 -180
- package/dist/cjs/components/cascader/tokens.js +2 -2
- package/dist/cjs/components/cascader/useCascaderExtend.js +25 -29
- package/dist/cjs/components/cell/Cell.js +70 -83
- package/dist/cjs/components/cell/CellGroup.js +16 -29
- package/dist/cjs/components/checkbox/Checkbox.js +139 -132
- package/dist/cjs/components/checkbox/CheckboxGroup.js +4 -35
- package/dist/cjs/components/checkbox/tokens.js +7 -10
- package/dist/cjs/components/circle/Circle.js +25 -24
- package/dist/cjs/components/collapse/Collapse.js +75 -91
- package/dist/cjs/components/config-provider/ConfigProvider.js +16 -3
- package/dist/cjs/components/config-provider/DirectionContext.js +15 -0
- package/dist/cjs/components/config-provider/index.js +7 -0
- package/dist/cjs/components/config-provider/locale/en-US.js +32 -0
- package/dist/cjs/components/config-provider/locale/zh-CN.js +32 -0
- package/dist/cjs/components/config-provider/useDirection.js +16 -0
- package/dist/cjs/components/count-down/CountDown.js +20 -15
- package/dist/cjs/components/datetime-picker/DatetimePicker.js +61 -84
- package/dist/cjs/components/datetime-picker/tokens.js +14 -3
- package/dist/cjs/components/dialog/Dialog.js +153 -121
- package/dist/cjs/components/dialog/imperative.js +17 -30
- package/dist/cjs/components/divider/Divider.js +26 -28
- package/dist/cjs/components/empty/Empty.js +35 -39
- package/dist/cjs/components/error-boundary/ErrorBoundary.js +73 -0
- package/dist/cjs/components/error-boundary/index.js +19 -0
- package/dist/cjs/components/field/Field.js +109 -106
- package/dist/cjs/components/flex/Flex.js +18 -18
- package/dist/cjs/components/flex/FlexItem.js +26 -27
- package/dist/cjs/components/form/Form.js +142 -161
- package/dist/cjs/components/form/FormItem.js +69 -97
- package/dist/cjs/components/form/FormList.js +49 -37
- package/dist/cjs/components/form/tokens.js +6 -3
- package/dist/cjs/components/form/utils.js +15 -34
- package/dist/cjs/components/grid/Grid.js +30 -29
- package/dist/cjs/components/grid/GridItem.js +84 -85
- package/dist/cjs/components/image/Image.js +55 -59
- package/dist/cjs/components/image/tokens.js +2 -2
- package/dist/cjs/components/image-preview/ImagePreview.js +124 -112
- package/dist/cjs/components/image-preview/imperative.js +4 -13
- package/dist/cjs/components/index.js +13 -0
- package/dist/cjs/components/input/Input.js +30 -22
- package/dist/cjs/components/loading/Loading.js +14 -15
- package/dist/cjs/components/nav-bar/NavBar.js +68 -83
- package/dist/cjs/components/nav-bar/tokens.js +1 -9
- package/dist/cjs/components/notice-bar/NoticeBar.js +74 -77
- package/dist/cjs/components/notify/Notify.js +88 -84
- package/dist/cjs/components/notify/imperative.js +20 -43
- package/dist/cjs/components/notify/tokens.js +1 -11
- package/dist/cjs/components/number-keyboard/NumberKeyboard.js +187 -209
- package/dist/cjs/components/overlay/Overlay.js +37 -52
- package/dist/cjs/components/overlay/tokens.js +5 -3
- package/dist/cjs/components/password-input/PasswordInput.js +98 -79
- package/dist/cjs/components/picker/Picker.js +440 -421
- package/dist/cjs/components/picker/tokens.js +1 -1
- package/dist/cjs/components/popup/Popup.js +263 -293
- package/dist/cjs/components/portal/Portal.js +12 -29
- package/dist/cjs/components/portal/PortalHost.js +151 -234
- package/dist/cjs/components/progress/Progress.js +51 -48
- package/dist/cjs/components/radio/Radio.js +45 -42
- package/dist/cjs/components/radio/RadioGroup.js +8 -40
- package/dist/cjs/components/radio/tokens.js +7 -10
- package/dist/cjs/components/safe-area-view/SafeAreaView.js +22 -26
- package/dist/cjs/components/search/Search.js +51 -43
- package/dist/cjs/components/selector/Selector.js +14 -13
- package/dist/cjs/components/share-sheet/ShareSheet.js +160 -161
- package/dist/cjs/components/sidebar/Sidebar.js +39 -45
- package/dist/cjs/components/sidebar/SidebarContext.js +1 -2
- package/dist/cjs/components/sidebar/SidebarItem.js +13 -16
- package/dist/cjs/components/sidebar/tokens.js +1 -3
- package/dist/cjs/components/skeleton/Skeleton.js +30 -37
- package/dist/cjs/components/skeleton/tokens.js +1 -2
- package/dist/cjs/components/slider/Slider.js +156 -135
- package/dist/cjs/components/space/Space.js +46 -69
- package/dist/cjs/components/stepper/Stepper.js +177 -155
- package/dist/cjs/components/swiper/Swiper.js +251 -253
- package/dist/cjs/components/swiper/SwiperPagIndicator.js +25 -27
- package/dist/cjs/components/swiper/tokens.js +10 -3
- package/dist/cjs/components/switch/Switch.js +13 -15
- package/dist/cjs/components/tabbar/Tabbar.js +35 -27
- package/dist/cjs/components/tabbar/TabbarContext.js +1 -2
- package/dist/cjs/components/tabbar/TabbarItem.js +65 -68
- package/dist/cjs/components/tabs/Tabs.js +286 -313
- package/dist/cjs/components/tag/Tag.js +46 -37
- package/dist/cjs/components/toast/Toast.js +90 -90
- package/dist/cjs/components/toast/imperative.js +16 -41
- package/dist/cjs/components/typography/Typography.js +3 -5
- package/dist/cjs/components/water-mark/WaterMark.js +31 -29
- package/dist/cjs/design-system/ThemeProvider.js +5 -11
- package/dist/cjs/design-system/createComponentTokensHook.js +11 -13
- package/dist/cjs/design-system/presets.js +2 -3
- package/dist/cjs/design-system/tokens.js +2 -11
- package/dist/cjs/hooks/animation/index.js +25 -0
- package/dist/cjs/hooks/animation/useAnimatedTransition.js +72 -0
- package/dist/cjs/hooks/animation/useReducedMotion.js +75 -0
- package/dist/cjs/hooks/aria/useAriaListBox.js +8 -16
- package/dist/cjs/hooks/aria/useAriaOverlay.js +3 -3
- package/dist/cjs/hooks/aria/useAriaPress.js +8 -21
- package/dist/cjs/hooks/aria/useAriaToggle.js +3 -3
- package/dist/cjs/hooks/gesture/useGestureScroll.js +60 -61
- package/dist/cjs/hooks/index.js +12 -0
- package/dist/cjs/hooks/overlay/OverlayStackStore.js +49 -69
- package/dist/cjs/hooks/overlay/useOverlayStack.js +13 -19
- package/dist/cjs/hooks/useControllableValue.js +10 -21
- package/dist/cjs/hooks/useCountDown.js +14 -22
- package/dist/cjs/hooks/useHairline.js +17 -29
- package/dist/cjs/hooks/useSafeAreaPadding.js +1 -4
- package/dist/cjs/index.js +67 -1
- package/dist/cjs/platform/animation.js +10 -2
- package/dist/cjs/platform/measure.js +18 -36
- package/dist/cjs/utils/color.js +21 -35
- package/dist/cjs/utils/compare.js +7 -12
- package/dist/cjs/utils/createPlatformShadow.js +28 -39
- package/dist/cjs/utils/date.js +20 -50
- package/dist/cjs/utils/deepMerge.js +16 -26
- package/dist/cjs/utils/hairline.js +74 -71
- package/dist/cjs/utils/index.js +22 -0
- package/dist/cjs/utils/number.js +21 -29
- package/dist/cjs/utils/render.js +27 -0
- package/dist/cjs/utils/rtl.js +25 -0
- package/dist/cjs/utils/string.js +8 -25
- package/dist/es/components/action-sheet/ActionSheet.js +99 -107
- package/dist/es/components/action-sheet/tokens.js +16 -27
- package/dist/es/components/area/Area.js +55 -68
- package/dist/es/components/area/tokens.js +6 -3
- package/dist/es/components/avatar/Avatar.js +25 -23
- package/dist/es/components/avatar/index.js +1 -2
- package/dist/es/components/badge/Badge.js +33 -33
- package/dist/es/components/badge/tokens.js +6 -8
- package/dist/es/components/button/Button.js +116 -152
- package/dist/es/components/button/ButtonGroup.js +9 -43
- package/dist/es/components/button/tokens.js +2 -3
- package/dist/es/components/calendar/Calendar.js +214 -225
- package/dist/es/components/calendar/tokens.js +3 -3
- package/dist/es/components/cascader/Cascader.js +180 -183
- package/dist/es/components/cascader/tokens.js +2 -2
- package/dist/es/components/cascader/useCascaderExtend.js +25 -29
- package/dist/es/components/cell/Cell.js +71 -84
- package/dist/es/components/cell/CellGroup.js +16 -28
- package/dist/es/components/checkbox/Checkbox.js +140 -133
- package/dist/es/components/checkbox/CheckboxGroup.js +5 -36
- package/dist/es/components/checkbox/tokens.js +7 -10
- package/dist/es/components/circle/Circle.js +25 -23
- package/dist/es/components/collapse/Collapse.js +77 -92
- package/dist/es/components/config-provider/ConfigProvider.js +10 -3
- package/dist/es/components/config-provider/DirectionContext.js +2 -0
- package/dist/es/components/config-provider/index.js +1 -0
- package/dist/es/components/config-provider/locale/en-US.js +32 -0
- package/dist/es/components/config-provider/locale/zh-CN.js +32 -0
- package/dist/es/components/config-provider/useDirection.js +3 -0
- package/dist/es/components/count-down/CountDown.js +23 -18
- package/dist/es/components/datetime-picker/DatetimePicker.js +61 -84
- package/dist/es/components/datetime-picker/tokens.js +14 -3
- package/dist/es/components/dialog/Dialog.js +154 -121
- package/dist/es/components/dialog/imperative.js +17 -30
- package/dist/es/components/divider/Divider.js +28 -29
- package/dist/es/components/empty/Empty.js +36 -39
- package/dist/es/components/error-boundary/ErrorBoundary.js +61 -0
- package/dist/es/components/error-boundary/index.js +1 -0
- package/dist/es/components/field/Field.js +109 -106
- package/dist/es/components/flex/Flex.js +18 -17
- package/dist/es/components/flex/FlexItem.js +27 -27
- package/dist/es/components/form/Form.js +143 -162
- package/dist/es/components/form/FormItem.js +68 -95
- package/dist/es/components/form/FormList.js +49 -37
- package/dist/es/components/form/tokens.js +6 -3
- package/dist/es/components/form/utils.js +15 -34
- package/dist/es/components/grid/Grid.js +30 -28
- package/dist/es/components/grid/GridItem.js +84 -84
- package/dist/es/components/image/Image.js +58 -62
- package/dist/es/components/image/tokens.js +2 -2
- package/dist/es/components/image-preview/ImagePreview.js +124 -112
- package/dist/es/components/image-preview/imperative.js +4 -13
- package/dist/es/components/index.js +3 -1
- package/dist/es/components/input/Input.js +31 -23
- package/dist/es/components/loading/Loading.js +16 -16
- package/dist/es/components/nav-bar/NavBar.js +68 -83
- package/dist/es/components/nav-bar/tokens.js +1 -3
- package/dist/es/components/notice-bar/NoticeBar.js +74 -76
- package/dist/es/components/notify/Notify.js +92 -87
- package/dist/es/components/notify/imperative.js +21 -44
- package/dist/es/components/notify/tokens.js +1 -5
- package/dist/es/components/number-keyboard/NumberKeyboard.js +187 -209
- package/dist/es/components/overlay/Overlay.js +36 -51
- package/dist/es/components/overlay/tokens.js +5 -3
- package/dist/es/components/password-input/PasswordInput.js +98 -79
- package/dist/es/components/picker/Picker.js +440 -421
- package/dist/es/components/picker/tokens.js +1 -1
- package/dist/es/components/popup/Popup.js +263 -292
- package/dist/es/components/portal/Portal.js +13 -29
- package/dist/es/components/portal/PortalHost.js +152 -234
- package/dist/es/components/progress/Progress.js +51 -48
- package/dist/es/components/radio/Radio.js +47 -44
- package/dist/es/components/radio/RadioGroup.js +10 -41
- package/dist/es/components/radio/tokens.js +7 -10
- package/dist/es/components/safe-area-view/SafeAreaView.js +22 -25
- package/dist/es/components/search/Search.js +52 -44
- package/dist/es/components/selector/Selector.js +14 -13
- package/dist/es/components/share-sheet/ShareSheet.js +162 -163
- package/dist/es/components/sidebar/Sidebar.js +41 -47
- package/dist/es/components/sidebar/SidebarContext.js +1 -2
- package/dist/es/components/sidebar/SidebarItem.js +13 -15
- package/dist/es/components/sidebar/tokens.js +1 -3
- package/dist/es/components/skeleton/Skeleton.js +30 -37
- package/dist/es/components/skeleton/tokens.js +1 -2
- package/dist/es/components/slider/Slider.js +156 -134
- package/dist/es/components/space/Space.js +48 -71
- package/dist/es/components/stepper/Stepper.js +178 -156
- package/dist/es/components/swiper/Swiper.js +252 -254
- package/dist/es/components/swiper/SwiperPagIndicator.js +25 -27
- package/dist/es/components/swiper/tokens.js +10 -3
- package/dist/es/components/switch/Switch.js +13 -15
- package/dist/es/components/tabbar/Tabbar.js +36 -28
- package/dist/es/components/tabbar/TabbarContext.js +1 -2
- package/dist/es/components/tabbar/TabbarItem.js +66 -69
- package/dist/es/components/tabs/Tabs.js +286 -313
- package/dist/es/components/tag/Tag.js +49 -39
- package/dist/es/components/toast/Toast.js +93 -91
- package/dist/es/components/toast/imperative.js +16 -41
- package/dist/es/components/typography/Typography.js +3 -5
- package/dist/es/components/water-mark/WaterMark.js +32 -30
- package/dist/es/design-system/ThemeProvider.js +5 -11
- package/dist/es/design-system/createComponentTokensHook.js +11 -13
- package/dist/es/design-system/presets.js +2 -3
- package/dist/es/design-system/tokens.js +1 -9
- package/dist/es/hooks/animation/index.js +2 -0
- package/dist/es/hooks/animation/useAnimatedTransition.js +53 -0
- package/dist/es/hooks/animation/useReducedMotion.js +54 -0
- package/dist/es/hooks/aria/useAriaListBox.js +8 -16
- package/dist/es/hooks/aria/useAriaOverlay.js +3 -3
- package/dist/es/hooks/aria/useAriaPress.js +8 -21
- package/dist/es/hooks/aria/useAriaToggle.js +3 -3
- package/dist/es/hooks/gesture/useGestureScroll.js +60 -61
- package/dist/es/hooks/index.js +1 -0
- package/dist/es/hooks/overlay/OverlayStackStore.js +49 -69
- package/dist/es/hooks/overlay/useOverlayStack.js +13 -19
- package/dist/es/hooks/useControllableValue.js +10 -21
- package/dist/es/hooks/useCountDown.js +14 -22
- package/dist/es/hooks/useHairline.js +16 -28
- package/dist/es/hooks/useSafeAreaPadding.js +1 -4
- package/dist/es/index.js +8 -1
- package/dist/es/platform/animation.js +9 -1
- package/dist/es/platform/measure.js +18 -36
- package/dist/es/utils/color.js +21 -35
- package/dist/es/utils/compare.js +7 -12
- package/dist/es/utils/createPlatformShadow.js +28 -39
- package/dist/es/utils/date.js +20 -50
- package/dist/es/utils/deepMerge.js +16 -26
- package/dist/es/utils/hairline.js +73 -65
- package/dist/es/utils/index.js +2 -0
- package/dist/es/utils/number.js +21 -29
- package/dist/es/utils/render.js +7 -0
- package/dist/es/utils/rtl.js +17 -0
- package/dist/es/utils/string.js +8 -25
- package/dist/types/components/action-sheet/ActionSheet.d.ts +1 -1
- package/dist/types/components/area/Area.d.ts +1 -1
- package/dist/types/components/area/tokens.d.ts +4 -0
- package/dist/types/components/avatar/Avatar.d.ts +1 -1
- package/dist/types/components/avatar/index.d.ts +1 -2
- package/dist/types/components/badge/Badge.d.ts +1 -1
- package/dist/types/components/button/Button.d.ts +1 -1
- package/dist/types/components/button/index.d.ts +1 -1
- package/dist/types/components/calendar/Calendar.d.ts +1 -1
- package/dist/types/components/cascader/Cascader.d.ts +1 -1
- package/dist/types/components/cell/Cell.d.ts +1 -1
- package/dist/types/components/cell/CellGroup.d.ts +1 -1
- package/dist/types/components/cell/index.d.ts +2 -2
- package/dist/types/components/checkbox/Checkbox.d.ts +1 -1
- package/dist/types/components/circle/Circle.d.ts +1 -1
- package/dist/types/components/collapse/Collapse.d.ts +1 -2
- package/dist/types/components/config-provider/DirectionContext.d.ts +3 -0
- package/dist/types/components/config-provider/index.d.ts +2 -1
- package/dist/types/components/config-provider/locale/en-US.d.ts +32 -0
- package/dist/types/components/config-provider/locale/zh-CN.d.ts +32 -0
- package/dist/types/components/config-provider/useDirection.d.ts +1 -0
- package/dist/types/components/count-down/CountDown.d.ts +1 -1
- package/dist/types/components/datetime-picker/DatetimePicker.d.ts +1 -1
- package/dist/types/components/datetime-picker/tokens.d.ts +12 -0
- package/dist/types/components/dialog/Dialog.d.ts +1 -1
- package/dist/types/components/divider/Divider.d.ts +1 -1
- package/dist/types/components/empty/Empty.d.ts +1 -1
- package/dist/types/components/error-boundary/ErrorBoundary.d.ts +6 -0
- package/dist/types/components/error-boundary/index.d.ts +2 -0
- package/dist/types/components/field/Field.d.ts +1 -1
- package/dist/types/components/flex/Flex.d.ts +1 -1
- package/dist/types/components/flex/FlexItem.d.ts +1 -1
- package/dist/types/components/flex/index.d.ts +2 -2
- package/dist/types/components/form/Form.d.ts +1 -1
- package/dist/types/components/form/FormItem.d.ts +2 -1
- package/dist/types/components/form/index.d.ts +2 -2
- package/dist/types/components/form/tokens.d.ts +4 -0
- package/dist/types/components/grid/Grid.d.ts +1 -1
- package/dist/types/components/grid/GridItem.d.ts +1 -1
- package/dist/types/components/grid/index.d.ts +2 -2
- package/dist/types/components/image/Image.d.ts +1 -1
- package/dist/types/components/image-preview/ImagePreview.d.ts +1 -1
- package/dist/types/components/index.d.ts +4 -1
- package/dist/types/components/input/Input.d.ts +3 -3
- package/dist/types/components/loading/Loading.d.ts +1 -1
- package/dist/types/components/nav-bar/NavBar.d.ts +1 -1
- package/dist/types/components/notice-bar/NoticeBar.d.ts +1 -1
- package/dist/types/components/notify/Notify.d.ts +2 -2
- package/dist/types/components/notify/index.d.ts +1 -1
- package/dist/types/components/overlay/Overlay.d.ts +1 -5
- package/dist/types/components/overlay/tokens.d.ts +3 -0
- package/dist/types/components/password-input/PasswordInput.d.ts +1 -1
- package/dist/types/components/picker/Picker.d.ts +5 -5
- package/dist/types/components/popup/Popup.d.ts +3 -42
- package/dist/types/components/portal/Portal.d.ts +9 -6
- package/dist/types/components/portal/PortalHost.d.ts +1 -1
- package/dist/types/components/radio/RadioGroup.d.ts +1 -1
- package/dist/types/components/safe-area-view/SafeAreaView.d.ts +1 -1
- package/dist/types/components/search/Search.d.ts +1 -1
- package/dist/types/components/share-sheet/ShareSheet.d.ts +1 -1
- package/dist/types/components/sidebar/Sidebar.d.ts +1 -1
- package/dist/types/components/sidebar/SidebarContext.d.ts +1 -1
- package/dist/types/components/sidebar/SidebarItem.d.ts +1 -1
- package/dist/types/components/sidebar/index.d.ts +2 -2
- package/dist/types/components/skeleton/Skeleton.d.ts +1 -1
- package/dist/types/components/slider/Slider.d.ts +1 -1
- package/dist/types/components/stepper/Stepper.d.ts +1 -1
- package/dist/types/components/swiper/Swiper.d.ts +1 -1
- package/dist/types/components/swiper/index.d.ts +1 -1
- package/dist/types/components/swiper/tokens.d.ts +8 -0
- package/dist/types/components/tabbar/Tabbar.d.ts +2 -2
- package/dist/types/components/tabbar/TabbarContext.d.ts +1 -1
- package/dist/types/components/tabbar/TabbarItem.d.ts +2 -2
- package/dist/types/components/tabs/Tabs.d.ts +1 -1
- package/dist/types/components/tabs/index.d.ts +1 -1
- package/dist/types/components/tag/Tag.d.ts +1 -1
- package/dist/types/components/toast/Toast.d.ts +2 -2
- package/dist/types/components/toast/index.d.ts +1 -1
- package/dist/types/components/water-mark/WaterMark.d.ts +1 -1
- package/dist/types/design-system/tokens.d.ts +0 -1
- package/dist/types/hooks/animation/index.d.ts +3 -0
- package/dist/types/hooks/animation/useAnimatedTransition.d.ts +13 -0
- package/dist/types/hooks/animation/useReducedMotion.d.ts +3 -0
- package/dist/types/hooks/aria/useAriaOverlay.d.ts +1 -1
- package/dist/types/hooks/gesture/useGestureScroll.d.ts +11 -10
- package/dist/types/hooks/index.d.ts +1 -0
- package/dist/types/hooks/overlay/OverlayStackStore.d.ts +8 -8
- package/dist/types/hooks/useHairline.d.ts +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/platform/animation.d.ts +8 -0
- package/dist/types/platform/measure.d.ts +1 -1
- package/dist/types/utils/compare.d.ts +1 -1
- package/dist/types/utils/createPlatformShadow.d.ts +2 -2
- package/dist/types/utils/date.d.ts +2 -2
- package/dist/types/utils/hairline.d.ts +5 -10
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/number.d.ts +2 -2
- package/dist/types/utils/render.d.ts +5 -0
- package/dist/types/utils/rtl.d.ts +5 -0
- 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(
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
8
|
+
constructor(baseZ = 1000, zStep = 2) {
|
|
9
|
+
this.baseZ = baseZ;
|
|
10
|
+
this.zStep = zStep;
|
|
13
11
|
}
|
|
14
|
-
subscribe =
|
|
15
|
-
this.listeners.add(
|
|
12
|
+
subscribe = l => {
|
|
13
|
+
this.listeners.add(l);
|
|
16
14
|
return () => {
|
|
17
|
-
this.listeners.delete(
|
|
15
|
+
this.listeners.delete(l);
|
|
18
16
|
};
|
|
19
17
|
};
|
|
20
18
|
getSnapshot = () => this.entries;
|
|
21
|
-
|
|
22
|
-
|
|
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.
|
|
26
|
-
onClose:
|
|
27
|
-
closeOnBack:
|
|
28
|
-
lockScroll:
|
|
29
|
-
type:
|
|
30
|
-
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,
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
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
|
-
...
|
|
42
|
-
...
|
|
43
|
-
zIndex: isNumber(
|
|
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,
|
|
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(
|
|
51
|
-
if (next.length
|
|
52
|
-
|
|
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
|
-
|
|
58
|
-
|
|
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
|
-
|
|
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(
|
|
75
|
-
listener();
|
|
76
|
-
});
|
|
61
|
+
this.listeners.forEach(l => l());
|
|
77
62
|
};
|
|
78
63
|
}
|
|
79
64
|
export const overlayStackStore = new OverlayStackStore();
|
|
80
|
-
let
|
|
81
|
-
const
|
|
65
|
+
let backSub = null;
|
|
66
|
+
const syncBack = () => {
|
|
82
67
|
if (Platform.OS === 'web') return;
|
|
83
68
|
const entries = overlayStackStore.getSnapshot();
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
for (let i =
|
|
89
|
-
|
|
90
|
-
|
|
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 (!
|
|
100
|
-
|
|
101
|
-
|
|
83
|
+
if (!has && backSub) {
|
|
84
|
+
backSub.remove();
|
|
85
|
+
backSub = null;
|
|
102
86
|
}
|
|
103
87
|
};
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
setBodyScrollLocked(
|
|
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(
|
|
113
|
-
|
|
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
|
|
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 =
|
|
8
|
+
const entries = useEntries();
|
|
9
9
|
const entryRef = useRef(null);
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
12
|
-
|
|
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
|
-
|
|
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 (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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:
|
|
43
|
-
zIndex:
|
|
44
|
-
isTopMost: !!
|
|
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
|
|
11
|
+
const p = props;
|
|
12
12
|
const isControlled = hasProp(props, valuePropName);
|
|
13
|
-
const value =
|
|
13
|
+
const value = p[valuePropName];
|
|
14
14
|
const [internalValue, setInternalValue] = useState(() => {
|
|
15
|
-
if (isControlled)
|
|
16
|
-
|
|
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
|
|
24
|
-
const handlerRef = useRef(propsRecord[trigger]);
|
|
19
|
+
const handlerRef = useRef(p[trigger]);
|
|
25
20
|
useEffect(() => {
|
|
26
|
-
handlerRef.current =
|
|
21
|
+
handlerRef.current = p[trigger];
|
|
27
22
|
}, [props, trigger]);
|
|
28
|
-
const triggerChange = useCallback((
|
|
29
|
-
if (!isControlled)
|
|
30
|
-
|
|
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 [
|
|
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
|
|
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
|
|
22
|
+
const msRef = useRef(millisecond);
|
|
28
23
|
const onChangeRef = useRef(onChange);
|
|
29
24
|
const onFinishRef = useRef(onFinish);
|
|
30
25
|
timeRef.current = time;
|
|
31
|
-
|
|
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
|
-
|
|
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
|
|
82
|
-
remainRef.current =
|
|
83
|
-
endTimeRef.current = Date.now() +
|
|
84
|
-
setCurrent(parseTime(
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
10
|
+
cb(null);
|
|
5
11
|
return;
|
|
6
12
|
}
|
|
7
13
|
try {
|
|
8
|
-
const
|
|
9
|
-
if (isFunction(
|
|
10
|
-
|
|
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
|
|
25
|
-
if (isFunction(
|
|
26
|
-
const
|
|
27
|
-
|
|
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
|
|
44
|
-
|
|
25
|
+
} catch {
|
|
26
|
+
cb(null);
|
|
45
27
|
return;
|
|
46
28
|
}
|
|
47
|
-
|
|
29
|
+
cb(null);
|
|
48
30
|
};
|
package/dist/es/utils/color.js
CHANGED
|
@@ -1,42 +1,28 @@
|
|
|
1
1
|
import { clamp01 } from './number';
|
|
2
|
-
const
|
|
2
|
+
const HEX_RE = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
3
3
|
export const hexToRgb = input => {
|
|
4
|
-
if (!
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
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
|
|
13
|
-
const
|
|
14
|
-
if (!
|
|
15
|
-
const
|
|
16
|
-
|
|
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
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
24
|
-
if (
|
|
25
|
-
const rgb = hexToRgb(
|
|
26
|
-
return rgb ? `rgba(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, ${
|
|
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 =
|
|
29
|
-
|
|
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
|
-
|
|
34
|
-
|
|
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;
|
package/dist/es/utils/compare.js
CHANGED
|
@@ -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
|
|
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 = (
|
|
9
|
-
if (
|
|
10
|
-
if (!
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
if (
|
|
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
|
};
|