react-native-unistyles 1.1.6 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +1 -1
- package/README.md +30 -38
- package/android/CMakeLists.txt +27 -0
- package/android/build.gradle +75 -0
- package/android/src/main/cxx/cpp-adapter.cpp +132 -0
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +189 -0
- package/android/src/main/java/com/unistyles/UnistylesPackage.kt +18 -0
- package/cxx/UnistylesRuntime.cpp +318 -0
- package/cxx/UnistylesRuntime.h +74 -0
- package/ios/UnistylesHelpers.h +3 -0
- package/ios/UnistylesHelpers.mm +5 -0
- package/ios/UnistylesModule.h +16 -0
- package/ios/UnistylesModule.mm +138 -0
- package/ios/platform/Platform_iOS.h +21 -0
- package/ios/platform/Platform_iOS.mm +132 -0
- package/ios/platform/Platform_macOS.h +20 -0
- package/ios/platform/Platform_macOS.mm +83 -0
- package/lib/commonjs/common.js +60 -0
- package/lib/commonjs/common.js.map +1 -0
- package/lib/commonjs/core/UnistyleRegistry.js +94 -0
- package/lib/commonjs/core/UnistyleRegistry.js.map +1 -0
- package/lib/commonjs/core/Unistyles.js +32 -0
- package/lib/commonjs/core/Unistyles.js.map +1 -0
- package/lib/commonjs/core/UnistylesModule.js +197 -0
- package/lib/commonjs/core/UnistylesModule.js.map +1 -0
- package/lib/commonjs/core/UnistylesModule.native.js +9 -0
- package/lib/commonjs/core/UnistylesModule.native.js.map +1 -0
- package/lib/commonjs/core/UnistylesRuntime.js +140 -0
- package/lib/commonjs/core/UnistylesRuntime.js.map +1 -0
- package/lib/commonjs/core/index.js +13 -0
- package/lib/commonjs/core/index.js.map +1 -0
- package/lib/commonjs/createStyleSheet.js +14 -0
- package/lib/commonjs/createStyleSheet.js.map +1 -0
- package/lib/commonjs/global.js +2 -0
- package/lib/commonjs/global.js.map +1 -0
- package/lib/commonjs/hooks/index.js +24 -3
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useCSS.js +44 -0
- package/lib/commonjs/hooks/useCSS.js.map +1 -0
- package/lib/commonjs/hooks/useCSS.native.js +9 -0
- package/lib/commonjs/hooks/useCSS.native.js.map +1 -0
- package/lib/commonjs/hooks/useInitialTheme.js +17 -0
- package/lib/commonjs/hooks/useInitialTheme.js.map +1 -0
- package/lib/commonjs/hooks/useUnistyles.js +64 -0
- package/lib/commonjs/hooks/useUnistyles.js.map +1 -0
- package/lib/commonjs/hooks/useVariants.js +14 -0
- package/lib/commonjs/hooks/useVariants.js.map +1 -0
- package/lib/commonjs/index.js +63 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/normalizer/index.js +32 -0
- package/lib/commonjs/normalizer/index.js.map +1 -0
- package/lib/commonjs/normalizer/module.d.js.map +1 -0
- package/lib/commonjs/{utils/normalizeStyles.web.js → normalizer/normalizeStyle.js} +5 -5
- package/lib/commonjs/normalizer/normalizeStyle.js.map +1 -0
- package/lib/commonjs/{utils → normalizer}/normalizer.js +2 -3
- package/lib/commonjs/normalizer/normalizer.js.map +1 -0
- package/lib/commonjs/normalizer/normalizer.macos.js +3 -0
- package/lib/commonjs/normalizer/normalizer.macos.js.map +1 -0
- package/lib/commonjs/plugins/cssMediaQueriesPlugin.js +14 -0
- package/lib/commonjs/plugins/cssMediaQueriesPlugin.js.map +1 -0
- package/lib/commonjs/plugins/index.js +20 -0
- package/lib/commonjs/plugins/index.js.map +1 -0
- package/lib/commonjs/plugins/normalizeWebStylesPlugin.js +12 -0
- package/lib/commonjs/plugins/normalizeWebStylesPlugin.js.map +1 -0
- package/lib/commonjs/types/common.js +2 -0
- package/lib/{module/utils/module.d.js.map → commonjs/types/common.js.map} +1 -1
- package/lib/commonjs/types/index.js +11 -0
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/types/plugin.js +6 -0
- package/lib/commonjs/{utils/module.d.js.map → types/plugin.js.map} +1 -1
- package/lib/commonjs/types/stylesheet.js +6 -0
- package/lib/commonjs/types/{mediaQueries.js.map → stylesheet.js.map} +1 -1
- package/lib/commonjs/types/unistyles.js +6 -0
- package/lib/{module/types/mediaQueries.js.map → commonjs/types/unistyles.js.map} +1 -1
- package/lib/commonjs/types/variants.js +2 -0
- package/lib/commonjs/types/variants.js.map +1 -0
- package/lib/commonjs/useStyles.js +47 -0
- package/lib/commonjs/useStyles.js.map +1 -0
- package/lib/commonjs/utils/breakpoints.js +20 -122
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/cssMediaQuery.js +244 -0
- package/lib/commonjs/utils/cssMediaQuery.js.map +1 -0
- package/lib/commonjs/utils/generateId.js +15 -0
- package/lib/commonjs/utils/generateId.js.map +1 -0
- package/lib/commonjs/utils/hash32.js +43 -0
- package/lib/commonjs/utils/hash32.js.map +1 -0
- package/lib/commonjs/utils/index.js +22 -54
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/mq.js +38 -0
- package/lib/commonjs/utils/mq.js.map +1 -0
- package/lib/commonjs/utils/mqParser.js +89 -0
- package/lib/commonjs/utils/mqParser.js.map +1 -0
- package/lib/commonjs/utils/styles.js +52 -72
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/commonjs/utils/withPlugins.js +15 -0
- package/lib/commonjs/utils/withPlugins.js.map +1 -0
- package/lib/module/common.js +53 -0
- package/lib/module/common.js.map +1 -0
- package/lib/module/core/UnistyleRegistry.js +87 -0
- package/lib/module/core/UnistyleRegistry.js.map +1 -0
- package/lib/module/core/Unistyles.js +26 -0
- package/lib/module/core/Unistyles.js.map +1 -0
- package/lib/module/core/UnistylesModule.js +190 -0
- package/lib/module/core/UnistylesModule.js.map +1 -0
- package/lib/module/core/UnistylesModule.native.js +3 -0
- package/lib/module/core/UnistylesModule.native.js.map +1 -0
- package/lib/module/core/UnistylesRuntime.js +133 -0
- package/lib/module/core/UnistylesRuntime.js.map +1 -0
- package/lib/module/core/index.js +2 -0
- package/lib/module/core/index.js.map +1 -0
- package/lib/module/createStyleSheet.js +7 -0
- package/lib/module/createStyleSheet.js.map +1 -0
- package/lib/module/global.js +2 -0
- package/lib/module/global.js.map +1 -0
- package/lib/module/hooks/index.js +4 -1
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useCSS.js +37 -0
- package/lib/module/hooks/useCSS.js.map +1 -0
- package/lib/module/hooks/useCSS.native.js +2 -0
- package/lib/module/hooks/useCSS.native.js.map +1 -0
- package/lib/module/hooks/useInitialTheme.js +10 -0
- package/lib/module/hooks/useInitialTheme.js.map +1 -0
- package/lib/module/hooks/useUnistyles.js +57 -0
- package/lib/module/hooks/useUnistyles.js.map +1 -0
- package/lib/module/hooks/useVariants.js +7 -0
- package/lib/module/hooks/useVariants.js.map +1 -0
- package/lib/module/index.js +30 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/normalizer/index.js +3 -0
- package/lib/module/normalizer/index.js.map +1 -0
- package/lib/module/normalizer/module.d.js.map +1 -0
- package/lib/module/{utils/normalizeStyles.web.js → normalizer/normalizeStyle.js} +3 -3
- package/lib/module/normalizer/normalizeStyle.js.map +1 -0
- package/lib/module/{utils → normalizer}/normalizer.js +2 -3
- package/lib/module/normalizer/normalizer.js.map +1 -0
- package/lib/module/normalizer/normalizer.macos.js +2 -0
- package/lib/module/normalizer/normalizer.macos.js.map +1 -0
- package/lib/module/plugins/cssMediaQueriesPlugin.js +7 -0
- package/lib/module/plugins/cssMediaQueriesPlugin.js.map +1 -0
- package/lib/module/plugins/index.js +3 -0
- package/lib/module/plugins/index.js.map +1 -0
- package/lib/module/plugins/normalizeWebStylesPlugin.js +6 -0
- package/lib/module/plugins/normalizeWebStylesPlugin.js.map +1 -0
- package/lib/module/types/common.js +2 -0
- package/lib/module/types/common.js.map +1 -0
- package/lib/module/types/index.js +1 -0
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/types/plugin.js +2 -0
- package/lib/module/types/plugin.js.map +1 -0
- package/lib/module/types/stylesheet.js +2 -0
- package/lib/module/types/stylesheet.js.map +1 -0
- package/lib/module/types/unistyles.js +2 -0
- package/lib/module/types/unistyles.js.map +1 -0
- package/lib/module/types/variants.js +2 -0
- package/lib/module/types/variants.js.map +1 -0
- package/lib/module/useStyles.js +40 -0
- package/lib/module/useStyles.js.map +1 -0
- package/lib/module/utils/breakpoints.js +19 -120
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/cssMediaQuery.js +237 -0
- package/lib/module/utils/cssMediaQuery.js.map +1 -0
- package/lib/module/utils/generateId.js +7 -0
- package/lib/module/utils/generateId.js.map +1 -0
- package/lib/module/utils/hash32.js +36 -0
- package/lib/module/utils/hash32.js.map +1 -0
- package/lib/module/utils/index.js +6 -6
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/mq.js +32 -0
- package/lib/module/utils/mq.js.map +1 -0
- package/lib/module/utils/mqParser.js +78 -0
- package/lib/module/utils/mqParser.js.map +1 -0
- package/lib/module/utils/styles.js +50 -72
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/module/utils/withPlugins.js +8 -0
- package/lib/module/utils/withPlugins.js.map +1 -0
- package/lib/typescript/src/common.d.ts +46 -0
- package/lib/typescript/src/common.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistyleRegistry.d.ts +56 -0
- package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -0
- package/lib/typescript/src/core/Unistyles.d.ts +13 -0
- package/lib/typescript/src/core/Unistyles.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts +19 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesModule.native.d.ts +6 -0
- package/lib/typescript/src/core/UnistylesModule.native.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesRuntime.d.ts +81 -0
- package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +3 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -0
- package/lib/typescript/src/createStyleSheet.d.ts +8 -0
- package/lib/typescript/src/createStyleSheet.d.ts.map +1 -0
- package/lib/typescript/src/global.d.ts +7 -0
- package/lib/typescript/src/global.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +4 -1
- package/lib/typescript/src/hooks/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCSS.d.ts +3 -0
- package/lib/typescript/src/hooks/useCSS.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useCSS.native.d.ts +3 -0
- package/lib/typescript/src/hooks/useCSS.native.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useInitialTheme.d.ts +3 -0
- package/lib/typescript/src/hooks/useInitialTheme.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts +14 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useVariants.d.ts +3 -0
- package/lib/typescript/src/hooks/useVariants.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +76 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/normalizer/index.d.ts +3 -0
- package/lib/typescript/src/normalizer/index.d.ts.map +1 -0
- package/lib/typescript/src/normalizer/normalizeStyle.d.ts +3 -0
- package/lib/typescript/src/normalizer/normalizeStyle.d.ts.map +1 -0
- package/lib/typescript/src/normalizer/normalizer.d.ts.map +1 -0
- package/lib/typescript/src/normalizer/normalizer.macos.d.ts +1 -0
- package/lib/typescript/src/normalizer/normalizer.macos.d.ts.map +1 -0
- package/lib/typescript/src/plugins/cssMediaQueriesPlugin.d.ts +3 -0
- package/lib/typescript/src/plugins/cssMediaQueriesPlugin.d.ts.map +1 -0
- package/lib/typescript/src/plugins/index.d.ts +3 -0
- package/lib/typescript/src/plugins/index.d.ts.map +1 -0
- package/lib/typescript/src/plugins/normalizeWebStylesPlugin.d.ts +3 -0
- package/lib/typescript/src/plugins/normalizeWebStylesPlugin.d.ts.map +1 -0
- package/lib/typescript/src/types/breakpoints.d.ts +25 -16
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/common.d.ts +3 -0
- package/lib/typescript/src/types/common.d.ts.map +1 -0
- package/lib/typescript/src/types/core.d.ts +11 -25
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +7 -2
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/plugin.d.ts +7 -0
- package/lib/typescript/src/types/plugin.d.ts.map +1 -0
- package/lib/typescript/src/types/stylesheet.d.ts +40 -0
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -0
- package/lib/typescript/src/types/unistyles.d.ts +53 -0
- package/lib/typescript/src/types/unistyles.d.ts.map +1 -0
- package/lib/typescript/src/types/variants.d.ts +14 -0
- package/lib/typescript/src/types/variants.d.ts.map +1 -0
- package/lib/typescript/src/useStyles.d.ts +16 -0
- package/lib/typescript/src/useStyles.d.ts.map +1 -0
- package/lib/typescript/src/utils/breakpoints.d.ts +2 -62
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/utils/cssMediaQuery.d.ts +4 -0
- package/lib/typescript/src/utils/cssMediaQuery.d.ts.map +1 -0
- package/lib/typescript/src/utils/generateId.d.ts +2 -0
- package/lib/typescript/src/utils/generateId.d.ts.map +1 -0
- package/lib/typescript/src/utils/hash32.d.ts +2 -0
- package/lib/typescript/src/utils/hash32.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +7 -6
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/mq.d.ts +26 -0
- package/lib/typescript/src/utils/mq.d.ts.map +1 -0
- package/lib/typescript/src/utils/mqParser.d.ts +16 -0
- package/lib/typescript/src/utils/mqParser.d.ts.map +1 -0
- package/lib/typescript/src/utils/styles.d.ts +4 -49
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/lib/typescript/src/utils/withPlugins.d.ts +3 -0
- package/lib/typescript/src/utils/withPlugins.d.ts.map +1 -0
- package/package.json +46 -25
- package/react-native-unistyles.podspec +22 -0
- package/src/__tests__/mocks.ts +24 -0
- package/src/common.ts +55 -0
- package/src/core/UnistyleRegistry.ts +108 -0
- package/src/core/Unistyles.ts +35 -0
- package/src/core/UnistylesModule.native.ts +7 -0
- package/src/core/UnistylesModule.ts +230 -0
- package/src/core/UnistylesRuntime.ts +135 -0
- package/src/core/index.ts +2 -0
- package/src/createStyleSheet.ts +8 -0
- package/src/global.ts +6 -0
- package/src/hooks/index.ts +4 -1
- package/src/hooks/useCSS.native.ts +3 -0
- package/src/hooks/useCSS.ts +51 -0
- package/src/hooks/useInitialTheme.ts +11 -0
- package/src/hooks/useUnistyles.ts +64 -0
- package/src/hooks/useVariants.ts +10 -0
- package/src/index.ts +50 -2
- package/src/normalizer/index.ts +2 -0
- package/src/{utils/normalizeStyles.web.ts → normalizer/normalizeStyle.ts} +3 -3
- package/src/normalizer/normalizer.macos.ts +1 -0
- package/src/{utils → normalizer}/normalizer.ts +5 -4
- package/src/plugins/cssMediaQueriesPlugin.ts +8 -0
- package/src/plugins/index.ts +2 -0
- package/src/plugins/normalizeWebStylesPlugin.ts +7 -0
- package/src/types/breakpoints.ts +55 -27
- package/src/types/common.ts +2 -0
- package/src/types/core.ts +11 -36
- package/src/types/index.ts +12 -7
- package/src/types/plugin.ts +7 -0
- package/src/types/stylesheet.ts +49 -0
- package/src/types/unistyles.ts +63 -0
- package/src/types/variants.ts +19 -0
- package/src/useStyles.ts +60 -0
- package/src/utils/breakpoints.ts +28 -124
- package/src/utils/cssMediaQuery.ts +268 -0
- package/src/utils/generateId.ts +10 -0
- package/src/utils/hash32.ts +53 -0
- package/src/utils/index.ts +7 -13
- package/src/utils/mq.ts +57 -0
- package/src/utils/mqParser.ts +99 -0
- package/src/utils/styles.ts +62 -102
- package/src/utils/withPlugins.ts +13 -0
- package/lib/commonjs/UnistylesTheme.js +0 -21
- package/lib/commonjs/UnistylesTheme.js.map +0 -1
- package/lib/commonjs/createUnistyles.js +0 -57
- package/lib/commonjs/createUnistyles.js.map +0 -1
- package/lib/commonjs/hooks/useDimensions.js +0 -10
- package/lib/commonjs/hooks/useDimensions.js.map +0 -1
- package/lib/commonjs/hooks/useDimensions.web.js +0 -34
- package/lib/commonjs/hooks/useDimensions.web.js.map +0 -1
- package/lib/commonjs/types/mediaQueries.js +0 -2
- package/lib/commonjs/utils/common.js +0 -18
- package/lib/commonjs/utils/common.js.map +0 -1
- package/lib/commonjs/utils/mediaQueries.js +0 -189
- package/lib/commonjs/utils/mediaQueries.js.map +0 -1
- package/lib/commonjs/utils/normalizeStyles.js +0 -10
- package/lib/commonjs/utils/normalizeStyles.js.map +0 -1
- package/lib/commonjs/utils/normalizeStyles.web.js.map +0 -1
- package/lib/commonjs/utils/normalizer.js.map +0 -1
- package/lib/module/UnistylesTheme.js +0 -12
- package/lib/module/UnistylesTheme.js.map +0 -1
- package/lib/module/createUnistyles.js +0 -50
- package/lib/module/createUnistyles.js.map +0 -1
- package/lib/module/hooks/useDimensions.js +0 -3
- package/lib/module/hooks/useDimensions.js.map +0 -1
- package/lib/module/hooks/useDimensions.web.js +0 -27
- package/lib/module/hooks/useDimensions.web.js.map +0 -1
- package/lib/module/types/mediaQueries.js +0 -2
- package/lib/module/utils/common.js +0 -10
- package/lib/module/utils/common.js.map +0 -1
- package/lib/module/utils/mediaQueries.js +0 -176
- package/lib/module/utils/mediaQueries.js.map +0 -1
- package/lib/module/utils/normalizeStyles.js +0 -3
- package/lib/module/utils/normalizeStyles.js.map +0 -1
- package/lib/module/utils/normalizeStyles.web.js.map +0 -1
- package/lib/module/utils/normalizer.js.map +0 -1
- package/lib/typescript/examples/expo/src/App.d.ts +0 -3
- package/lib/typescript/examples/expo/src/App.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Extreme.d.ts +0 -7
- package/lib/typescript/examples/expo/src/examples/Extreme.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Memoization.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Memoization.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Minimal.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Minimal.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Theme.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Theme.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/index.d.ts +0 -8
- package/lib/typescript/examples/expo/src/examples/index.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/index.d.ts +0 -2
- package/lib/typescript/examples/expo/src/index.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts +0 -8
- package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/styles/index.d.ts +0 -46
- package/lib/typescript/examples/expo/src/styles/index.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/styles/theme.d.ts +0 -24
- package/lib/typescript/examples/expo/src/styles/theme.d.ts.map +0 -1
- package/lib/typescript/src/UnistylesTheme.d.ts +0 -9
- package/lib/typescript/src/UnistylesTheme.d.ts.map +0 -1
- package/lib/typescript/src/createUnistyles.d.ts +0 -10
- package/lib/typescript/src/createUnistyles.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useDimensions.d.ts +0 -3
- package/lib/typescript/src/hooks/useDimensions.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useDimensions.web.d.ts +0 -3
- package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +0 -1
- package/lib/typescript/src/types/mediaQueries.d.ts +0 -8
- package/lib/typescript/src/types/mediaQueries.d.ts.map +0 -1
- package/lib/typescript/src/utils/common.d.ts +0 -5
- package/lib/typescript/src/utils/common.d.ts.map +0 -1
- package/lib/typescript/src/utils/mediaQueries.d.ts +0 -130
- package/lib/typescript/src/utils/mediaQueries.d.ts.map +0 -1
- package/lib/typescript/src/utils/normalizeStyles.d.ts +0 -2
- package/lib/typescript/src/utils/normalizeStyles.d.ts.map +0 -1
- package/lib/typescript/src/utils/normalizeStyles.web.d.ts +0 -5
- package/lib/typescript/src/utils/normalizeStyles.web.d.ts.map +0 -1
- package/lib/typescript/src/utils/normalizer.d.ts.map +0 -1
- package/src/UnistylesTheme.tsx +0 -17
- package/src/__tests__/createUnistyles.spec.tsx +0 -192
- package/src/createUnistyles.ts +0 -70
- package/src/hooks/useDimensions.ts +0 -4
- package/src/hooks/useDimensions.web.ts +0 -34
- package/src/types/mediaQueries.ts +0 -10
- package/src/utils/common.ts +0 -12
- package/src/utils/mediaQueries.ts +0 -201
- package/src/utils/normalizeStyles.ts +0 -2
- /package/lib/commonjs/{utils → normalizer}/module.d.js +0 -0
- /package/lib/module/{utils → normalizer}/module.d.js +0 -0
- /package/lib/typescript/src/{utils → normalizer}/normalizer.d.ts +0 -0
- /package/src/{utils → normalizer}/module.d.ts +0 -0
package/src/types/breakpoints.ts
CHANGED
@@ -1,33 +1,61 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ColorValue, OpaqueColorValue } from 'react-native'
|
2
|
+
import type { UnistylesTheme } from '../types'
|
3
|
+
import type { BreakpointsOrMediaQueries, ToDeepUnistyles } from './stylesheet'
|
4
|
+
import type { TransformStyles } from './core'
|
2
5
|
|
3
|
-
|
4
|
-
|
6
|
+
type ExtractTransformArray<T> = T extends object
|
7
|
+
? { [K in keyof T]: ExtractBreakpoints<T[K]> }
|
8
|
+
: never
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
type ExtractBreakpoints<T> = T extends object
|
11
|
+
? keyof T extends BreakpointsOrMediaQueries
|
12
|
+
? T[keyof T]
|
13
|
+
: T extends Array<ToDeepUnistyles<TransformStyles>>
|
14
|
+
? Array<ExtractTransformArray<T[number]>>
|
15
|
+
: {
|
16
|
+
[K in keyof T]: ExtractBreakpoints<T[K]>
|
17
|
+
}
|
18
|
+
: T
|
10
19
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
? (...args: A) => ExtractBreakpoints<R, B>
|
22
|
-
: T[K] extends object
|
23
|
-
? ExtractBreakpoints<T[K], B>
|
20
|
+
type ParseNestedObject<T> = T extends (...args: infer A) => infer R
|
21
|
+
? (...args: A) => ParseNestedObject<R>
|
22
|
+
: T extends object
|
23
|
+
? T extends { variants: infer R }
|
24
|
+
? ParseVariants<FlattenVariants<R>> & ParseNestedObject<Omit<T, 'variants'>>
|
25
|
+
: {
|
26
|
+
[K in keyof T]: T[K] extends object
|
27
|
+
? T[K] extends OpaqueColorValue
|
28
|
+
? ColorValue
|
29
|
+
: ExtractBreakpoints<T[K]>
|
24
30
|
: T[K]
|
25
|
-
|
31
|
+
}
|
32
|
+
: T
|
26
33
|
|
27
|
-
|
28
|
-
?
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
type FlattenVariants<T> = T extends object
|
35
|
+
? {
|
36
|
+
[K in keyof T]: T[K] extends object
|
37
|
+
? {
|
38
|
+
[key in keyof T[K]]: T[K][key] extends object
|
39
|
+
? ParseNestedObject<T[K][key]>
|
40
|
+
: never
|
41
|
+
}
|
42
|
+
: never
|
43
|
+
}
|
44
|
+
: never
|
45
|
+
|
46
|
+
type ParseVariants<T> = T extends object
|
47
|
+
? T[keyof T] extends object
|
48
|
+
? UnionToIntersection<ParseVariants<T[keyof T]>>
|
33
49
|
: T
|
50
|
+
: T
|
51
|
+
|
52
|
+
type UnionToIntersection<U> =
|
53
|
+
(U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
|
54
|
+
|
55
|
+
type ParseStyleKeys<T> = T extends object
|
56
|
+
? { [K in keyof T]: ParseNestedObject<T[K]> }
|
57
|
+
: never
|
58
|
+
|
59
|
+
export type ReactNativeStyleSheet<T> = T extends (theme: UnistylesTheme) => infer R
|
60
|
+
? ParseStyleKeys<R>
|
61
|
+
: ParseStyleKeys<T>
|
package/src/types/core.ts
CHANGED
@@ -14,15 +14,14 @@ import type {
|
|
14
14
|
TranslateYTransform
|
15
15
|
} from 'react-native/Libraries/StyleSheet/StyleSheetTypes'
|
16
16
|
import type { ImageStyle, TextStyle, ViewStyle } from 'react-native'
|
17
|
-
import type {
|
18
|
-
import type { MediaQueries } from './mediaQueries'
|
17
|
+
import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
|
19
18
|
|
20
|
-
type ShadowOffset = {
|
19
|
+
export type ShadowOffset = {
|
21
20
|
width: number,
|
22
21
|
height: number
|
23
22
|
}
|
24
23
|
|
25
|
-
type TransformStyles =
|
24
|
+
export type TransformStyles =
|
26
25
|
& PerpectiveTransform
|
27
26
|
& RotateTransform
|
28
27
|
& RotateXTransform
|
@@ -37,37 +36,13 @@ type TransformStyles =
|
|
37
36
|
& SkewYTransform
|
38
37
|
& MatrixTransform
|
39
38
|
|
40
|
-
type
|
41
|
-
|
42
|
-
|
43
|
-
transform?: Array<DeepUniStyle<TransformStyles, B>>
|
44
|
-
}
|
45
|
-
|
46
|
-
type UniStyle<V, B> = {
|
47
|
-
[innerKey in keyof B]?: V
|
48
|
-
} | {
|
49
|
-
[innerKey in MediaQueries]?: V
|
50
|
-
} | V
|
51
|
-
|
52
|
-
type DeepUniStyle<T, B> = {
|
53
|
-
[K in keyof T]?: UniStyle<T[K], B>
|
39
|
+
export type ScreenSize = {
|
40
|
+
width: number,
|
41
|
+
height: number
|
54
42
|
}
|
55
43
|
|
56
|
-
|
57
|
-
type
|
58
|
-
|
59
|
-
type
|
60
|
-
type
|
61
|
-
type UnistyleImage<B> = DeepUniStyle<Omit<ImageStyle, NestedTypes>, B>
|
62
|
-
|
63
|
-
export type StaticStyles<B extends Breakpoints> =
|
64
|
-
| UnistyleView<B>
|
65
|
-
| UnistyleText<B>
|
66
|
-
| UnistyleImage<B>
|
67
|
-
& UnistyleNested<B>
|
68
|
-
|
69
|
-
export type CustomNamedStyles<T, B extends Breakpoints> = {
|
70
|
-
[K in keyof T]: T[K] extends (...args: infer A) => StaticStyles<B>
|
71
|
-
? (...args: A) => StaticStyles<B>
|
72
|
-
: StaticStyles<B>
|
73
|
-
}
|
44
|
+
export type RNStyle = ViewStyle & TextStyle & ImageStyle
|
45
|
+
export type RNValue = ViewStyle[keyof ViewStyle] | TextStyle[keyof TextStyle] | ImageStyle[keyof ImageStyle]
|
46
|
+
export type NestedStyle = Record<keyof UnistylesBreakpoints | symbol, RNValue>
|
47
|
+
export type NestedStylePairs = Array<[keyof UnistylesBreakpoints | symbol, RNValue]>
|
48
|
+
export type UnistylesTheme = UnistylesThemes[keyof UnistylesThemes]
|
package/src/types/index.ts
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
export * from './normalizer'
|
2
|
-
export
|
2
|
+
export * from './unistyles'
|
3
|
+
export type { Optional, Nullable } from './common'
|
3
4
|
export type {
|
5
|
+
NestedStylePairs,
|
6
|
+
UnistylesTheme,
|
4
7
|
ScreenSize,
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
} from './breakpoints'
|
8
|
+
NestedStyle,
|
9
|
+
RNValue,
|
10
|
+
RNStyle
|
11
|
+
} from './core'
|
12
|
+
export type { StyleSheetWithSuperPowers, StyleSheet, AllAvailableKeys } from './stylesheet'
|
13
|
+
export type { ReactNativeStyleSheet } from './breakpoints'
|
14
|
+
export type { ExtractVariantNames } from './variants'
|
15
|
+
export type { UnistylesPlugin } from './plugin'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import type { ImageStyle, TextStyle, ViewStyle } from 'react-native'
|
2
|
+
import type { ShadowOffset, TransformStyles, UnistylesTheme } from './core'
|
3
|
+
import type { UnistylesBreakpoints } from '../global'
|
4
|
+
|
5
|
+
// these props are treated differently to nest breakpoints and media queries
|
6
|
+
type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset'
|
7
|
+
|
8
|
+
type UnistyleView = Omit<ViewStyle, NestedKeys>
|
9
|
+
type UnistyleText = Omit<TextStyle, NestedKeys>
|
10
|
+
type UnistyleImage = Omit<ImageStyle, NestedKeys>
|
11
|
+
|
12
|
+
type UnistyleNestedStyles = {
|
13
|
+
shadowOffset?: ToDeepUnistyles<ShadowOffset>,
|
14
|
+
textShadowOffset?: ToDeepUnistyles<ShadowOffset>,
|
15
|
+
transform?: Array<ToDeepUnistyles<TransformStyles>>
|
16
|
+
}
|
17
|
+
|
18
|
+
type Variants = {
|
19
|
+
variants?: {
|
20
|
+
[variantName: string]: {
|
21
|
+
[variant: string]: Omit<UnistylesValues, 'variants'>
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
export type ToDeepUnistyles<T> = {
|
27
|
+
[K in keyof T]?: T[K] | {
|
28
|
+
[key in BreakpointsOrMediaQueries]?: T[K]
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
type AllAvailableStyles = UnistyleView & UnistyleText & UnistyleImage & UnistyleNestedStyles
|
33
|
+
|
34
|
+
export type AllAvailableKeys = keyof (UnistyleView & UnistyleText & UnistyleImage)
|
35
|
+
export type BreakpointsOrMediaQueries = keyof UnistylesBreakpoints | symbol
|
36
|
+
|
37
|
+
export type UnistylesValues = {
|
38
|
+
[propName in AllAvailableKeys]?: AllAvailableStyles[propName] | {
|
39
|
+
[key in BreakpointsOrMediaQueries]?: AllAvailableStyles[propName]
|
40
|
+
}
|
41
|
+
} & Variants & {
|
42
|
+
[propName in NestedKeys]?: UnistyleNestedStyles[propName]
|
43
|
+
}
|
44
|
+
|
45
|
+
export type StyleSheet = {
|
46
|
+
[styleName: string]: UnistylesValues | ((...args: any) => UnistylesValues)
|
47
|
+
}
|
48
|
+
|
49
|
+
export type StyleSheetWithSuperPowers = ((theme: UnistylesTheme) => StyleSheet) | StyleSheet
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import { UnistylesEventType, ScreenOrientation, IOSContentSizeCategory, AndroidContentSizeCategory } from '../common'
|
2
|
+
import type { UnistylesThemes, UnistylesBreakpoints } from '../global'
|
3
|
+
import type { ScreenSize } from './core'
|
4
|
+
import type { UnistylesPlugin } from './plugin'
|
5
|
+
|
6
|
+
export type ColorSchemeName = 'light' | 'dark' | 'unspecified'
|
7
|
+
|
8
|
+
export type UnistylesConfig = {
|
9
|
+
adaptiveThemes?: boolean,
|
10
|
+
initialTheme?: keyof UnistylesThemes,
|
11
|
+
plugins?: Array<UnistylesPlugin>,
|
12
|
+
experimentalCSSMediaQueries?: boolean
|
13
|
+
}
|
14
|
+
|
15
|
+
export type UnistylesBridge = {
|
16
|
+
// getters
|
17
|
+
screenWidth: number,
|
18
|
+
screenHeight: number,
|
19
|
+
enabledPlugins: Array<string>,
|
20
|
+
hasAdaptiveThemes: boolean,
|
21
|
+
themeName: keyof UnistylesThemes,
|
22
|
+
breakpoint: keyof UnistylesBreakpoints,
|
23
|
+
colorScheme: ColorSchemeName,
|
24
|
+
contentSizeCategory: IOSContentSizeCategory | AndroidContentSizeCategory,
|
25
|
+
sortedBreakpointPairs: Array<[keyof UnistylesBreakpoints, UnistylesBreakpoints[keyof UnistylesBreakpoints]]>,
|
26
|
+
|
27
|
+
// setters
|
28
|
+
themes: Array<keyof UnistylesThemes>,
|
29
|
+
useBreakpoints(breakpoints: UnistylesBreakpoints): void,
|
30
|
+
useTheme(name: keyof UnistylesThemes): void,
|
31
|
+
useAdaptiveThemes(enable: boolean): void,
|
32
|
+
addPlugin(pluginName: string, notify: boolean): void,
|
33
|
+
removePlugin(pluginName: string): void
|
34
|
+
}
|
35
|
+
|
36
|
+
export type UnistylesThemeEvent = {
|
37
|
+
type: UnistylesEventType.Theme,
|
38
|
+
payload: {
|
39
|
+
themeName: keyof UnistylesThemes
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
export type UnistylesMobileLayoutEvent = {
|
44
|
+
type: UnistylesEventType.Layout,
|
45
|
+
payload: {
|
46
|
+
screen: ScreenSize,
|
47
|
+
breakpoint: keyof UnistylesBreakpoints,
|
48
|
+
orientation: typeof ScreenOrientation[keyof typeof ScreenOrientation]
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
export type UnistylesPluginEvent = {
|
53
|
+
type: UnistylesEventType.Plugin
|
54
|
+
}
|
55
|
+
|
56
|
+
export type UnistylesDynamicTypeSizeEvent = {
|
57
|
+
type: UnistylesEventType.DynamicTypeSize,
|
58
|
+
payload: {
|
59
|
+
contentSizeCategory: IOSContentSizeCategory | AndroidContentSizeCategory
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
export type UnistylesEvents = UnistylesThemeEvent | UnistylesMobileLayoutEvent | UnistylesPluginEvent | UnistylesDynamicTypeSizeEvent
|
@@ -0,0 +1,19 @@
|
|
1
|
+
export type ExtractVariantNames<T> = T extends (...args: any) => infer R
|
2
|
+
? ExtractVariantKeys<R>
|
3
|
+
: ExtractVariantKeys<T>
|
4
|
+
|
5
|
+
type ExtractVariantKeys<T> = T extends object
|
6
|
+
? ExtractVariant<T[keyof T]>
|
7
|
+
: never
|
8
|
+
|
9
|
+
type ExtractSubVariantKeys<T> = T extends object
|
10
|
+
? keyof Omit<T, 'default'> | undefined
|
11
|
+
: never
|
12
|
+
|
13
|
+
type ExtractVariant<T> = T extends (...args: any) => infer R
|
14
|
+
? R extends { variants: infer V }
|
15
|
+
? { [key in keyof V]?: ExtractSubVariantKeys<V[key]> }
|
16
|
+
: never
|
17
|
+
: T extends { variants: infer V }
|
18
|
+
? { [key in keyof V]?: ExtractSubVariantKeys<V[key]> }
|
19
|
+
: never
|
package/src/useStyles.ts
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
import { useMemo } from 'react'
|
2
|
+
import { StyleSheet } from 'react-native'
|
3
|
+
import { parseStyle, proxifyFunction, withPlugins } from './utils'
|
4
|
+
import { useCSS, useUnistyles, useVariants } from './hooks'
|
5
|
+
import type { UnistylesBreakpoints } from './global'
|
6
|
+
import type { ExtractVariantNames, ReactNativeStyleSheet, StyleSheetWithSuperPowers, UnistylesTheme } from './types'
|
7
|
+
import { unistyles } from './core'
|
8
|
+
import { isWeb } from './common'
|
9
|
+
|
10
|
+
type ParsedStylesheet<ST extends StyleSheetWithSuperPowers> = {
|
11
|
+
theme: UnistylesTheme,
|
12
|
+
breakpoint: keyof UnistylesBreakpoints,
|
13
|
+
styles: ReactNativeStyleSheet<ST>
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Hook that enables all the features of Unistyles
|
18
|
+
* @param stylesheet - The stylesheet with superpowers to be used
|
19
|
+
* @param variantsMap - The map of variants to be used
|
20
|
+
* @returns - The theme, current breakpoint and RN compatible styles
|
21
|
+
*/
|
22
|
+
export const useStyles = <ST extends StyleSheetWithSuperPowers>(
|
23
|
+
stylesheet?: ST,
|
24
|
+
variantsMap?: ExtractVariantNames<typeof stylesheet>
|
25
|
+
): ParsedStylesheet<ST> => {
|
26
|
+
const { theme, layout, plugins } = useUnistyles()
|
27
|
+
const variants = useVariants(variantsMap)
|
28
|
+
const parsedStyles = useMemo(() => typeof stylesheet === 'function'
|
29
|
+
? stylesheet(theme)
|
30
|
+
: stylesheet, [theme, stylesheet, layout])
|
31
|
+
|
32
|
+
const dynamicStyleSheet = useMemo(() => Object
|
33
|
+
.entries(parsedStyles || {})
|
34
|
+
.reduce((acc, [key, value]) => {
|
35
|
+
if (typeof value === 'function') {
|
36
|
+
return {
|
37
|
+
...acc,
|
38
|
+
[key]: proxifyFunction(key, value, variants)
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
return StyleSheet.create({
|
43
|
+
...acc,
|
44
|
+
[key]: withPlugins(key, parseStyle(
|
45
|
+
value,
|
46
|
+
variants,
|
47
|
+
!isWeb || !unistyles.registry.config.experimentalCSSMediaQueries)
|
48
|
+
)
|
49
|
+
})
|
50
|
+
}, {}), [parsedStyles, variants, plugins]
|
51
|
+
)
|
52
|
+
|
53
|
+
useCSS(dynamicStyleSheet as ReactNativeStyleSheet<ST>)
|
54
|
+
|
55
|
+
return {
|
56
|
+
theme,
|
57
|
+
breakpoint: layout.breakpoint,
|
58
|
+
styles: dynamicStyleSheet as ReactNativeStyleSheet<ST>
|
59
|
+
}
|
60
|
+
}
|
package/src/utils/breakpoints.ts
CHANGED
@@ -1,140 +1,44 @@
|
|
1
|
-
import {
|
2
|
-
import type {
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
*
|
16
|
-
* @template B - An object type where keys are strings and values are numbers.
|
17
|
-
* @param {B} breakpoints - The breakpoints object to be sorted and validated.
|
18
|
-
* @returns {B} A new object with sorted and validated breakpoints.
|
19
|
-
*
|
20
|
-
* @example
|
21
|
-
* const input = { md: 768, lg: 1024, sm: 0 }
|
22
|
-
* sortAndValidateBreakpoints(input) // returns { sm: 0, md: 768, lg: 1024 }
|
23
|
-
*/
|
24
|
-
export const sortAndValidateBreakpoints = <B extends Breakpoints>(breakpoints: B): B => {
|
25
|
-
const sortedPairs = Object
|
26
|
-
.entries(breakpoints)
|
27
|
-
.sort((breakpoint1, breakpoint2) => {
|
28
|
-
const [, value1] = breakpoint1
|
29
|
-
const [, value2] = breakpoint2
|
30
|
-
|
31
|
-
return value1 - value2
|
32
|
-
})
|
33
|
-
|
34
|
-
const sortedBreakpoints = Object.freeze(Object.fromEntries(sortedPairs)) as B
|
35
|
-
const breakpointValues = Object.values(sortedBreakpoints)
|
36
|
-
const [firstBreakpoint] = breakpointValues
|
37
|
-
|
38
|
-
if (firstBreakpoint !== 0) {
|
39
|
-
throwError('first breakpoint must start with 0')
|
40
|
-
}
|
41
|
-
|
42
|
-
if (breakpointValues.length !== new Set(breakpointValues).size) {
|
43
|
-
throwError('breakpoint values are duplicated')
|
1
|
+
import { unistyles } from '../core'
|
2
|
+
import type { Optional, RNValue } from '../types'
|
3
|
+
import type { UnistylesBreakpoints } from '../global'
|
4
|
+
import { ScreenOrientation, isMobile } from '../common'
|
5
|
+
import { getKeyForUnistylesMediaQuery } from './mqParser'
|
6
|
+
|
7
|
+
export const getValueForBreakpoint = (value: Record<string, RNValue>): Optional<RNValue> => {
|
8
|
+
const customMediaQueryKey = getKeyForUnistylesMediaQuery(
|
9
|
+
Object.entries(value),
|
10
|
+
unistyles.runtime.screen
|
11
|
+
) as keyof typeof value
|
12
|
+
|
13
|
+
if (customMediaQueryKey) {
|
14
|
+
return value[customMediaQueryKey]
|
44
15
|
}
|
45
16
|
|
46
|
-
|
47
|
-
}
|
48
|
-
|
49
|
-
/**
|
50
|
-
* Determines the appropriate breakpoint key for a given screen width based on provided breakpoints.
|
51
|
-
*
|
52
|
-
* This function takes a screen width and an object of breakpoints. It returns the key of the breakpoint
|
53
|
-
* that the screen width falls into. The breakpoints are assumed to be sorted in ascending order.
|
54
|
-
*
|
55
|
-
* @template B - An object type where keys are strings and values are numbers representing screen widths.
|
56
|
-
* @param {number} width - The screen width to determine the breakpoint for.
|
57
|
-
* @param breakpointEntries - sorted pairs of breakpoints
|
58
|
-
* @returns {keyof B & string} The key of the breakpoint that the screen width falls into.
|
59
|
-
*
|
60
|
-
* @example
|
61
|
-
* const breakpoints = { sm: 0, md: 768, lg: 1024 }
|
62
|
-
* getBreakpointFromScreenWidth(800, breakpoints) // returns 'md'
|
63
|
-
*/
|
64
|
-
export const getBreakpointFromScreenWidth = <B extends Breakpoints>(width: number, breakpointEntries: SortedBreakpointEntries<B>): keyof B & string => {
|
65
|
-
const [key] = breakpointEntries
|
66
|
-
.find(([, value], index, otherBreakpoints) => {
|
67
|
-
const minVal = value
|
68
|
-
const maxVal = otherBreakpoints[index + 1]?.[1]
|
69
|
-
|
70
|
-
if (!maxVal) {
|
71
|
-
return true
|
72
|
-
}
|
73
|
-
|
74
|
-
return width >= minVal && width < maxVal
|
75
|
-
}) as [keyof B & string, number]
|
17
|
+
const hasBreakpoints = unistyles.registry.sortedBreakpointPairs.length > 0
|
76
18
|
|
77
|
-
|
78
|
-
|
19
|
+
if (!hasBreakpoints && isMobile && (ScreenOrientation.Landscape in value || ScreenOrientation.Portrait in value)) {
|
20
|
+
return value[unistyles.runtime.orientation]
|
21
|
+
}
|
79
22
|
|
80
|
-
|
81
|
-
* Retrieves the value associated with a given breakpoint or custom media query based on the provided screen size.
|
82
|
-
*
|
83
|
-
* The function first checks for custom media queries. If a matching custom media query is found, its associated value is returned.
|
84
|
-
* If no custom media query matches, the function then checks for a direct breakpoint match.
|
85
|
-
* If there's no direct breakpoint match, the function simulates CSS cascading to find the closest matching breakpoint.
|
86
|
-
*
|
87
|
-
* @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
|
88
|
-
*
|
89
|
-
* @param {Record<keyof B & string, string | number>} value - An object containing values associated with breakpoints or custom media queries.
|
90
|
-
* @param {keyof B & string} breakpoint - The breakpoint name to check against.
|
91
|
-
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
92
|
-
* @param breakpointPairs - sorted pairs of breakpoints
|
93
|
-
*
|
94
|
-
* @returns {string | number | undefined} Returns the value associated with the matching breakpoint or custom media query, or `undefined` if no match is found.
|
95
|
-
*
|
96
|
-
* @example
|
97
|
-
*
|
98
|
-
* const values = { ':w[200]': 'value1', sm: 'value2', md: 'value3' }
|
99
|
-
* const screenSize = { width: 250, height: 400 }
|
100
|
-
* const breakpoints = { sm: 300, md: 600, lg: 900 }
|
101
|
-
*
|
102
|
-
* getValueForBreakpoint(values, 'sm', screenSize, breakpoints); // 'value1'
|
103
|
-
*/
|
104
|
-
export const getValueForBreakpoint = <B extends Breakpoints>(
|
105
|
-
value: Record<keyof B & string, string | number | undefined>,
|
106
|
-
breakpoint: keyof B & string,
|
107
|
-
screenSize: ScreenSize,
|
108
|
-
breakpointPairs: SortedBreakpointEntries<B>
|
109
|
-
): string | number | undefined => {
|
110
|
-
// the highest priority is for custom media queries
|
111
|
-
const customMediaQueries = Object
|
112
|
-
.entries(value)
|
113
|
-
.filter(([key]) => isMediaQuery(key))
|
114
|
-
const customMediaQueryKey = getKeyForCustomMediaQuery(customMediaQueries, screenSize)
|
23
|
+
const breakpoint = unistyles.runtime.breakpoint
|
115
24
|
|
116
|
-
if (
|
117
|
-
return
|
25
|
+
if (!breakpoint) {
|
26
|
+
return undefined
|
118
27
|
}
|
119
28
|
|
120
|
-
|
121
|
-
const unifiedKey = breakpoint
|
122
|
-
const directBreakpoint = value[unifiedKey]
|
29
|
+
const directBreakpoint = value[breakpoint]
|
123
30
|
|
124
|
-
|
125
|
-
if (directBreakpoint || (unifiedKey in value)) {
|
31
|
+
if (directBreakpoint || (breakpoint in value)) {
|
126
32
|
return directBreakpoint
|
127
33
|
}
|
128
34
|
|
129
|
-
|
130
|
-
const
|
131
|
-
.findIndex(([key]) => key ===
|
35
|
+
const breakpointPairs = unistyles.registry.sortedBreakpointPairs
|
36
|
+
const currentBreakpointIndex = breakpointPairs
|
37
|
+
.findIndex(([key]) => key === breakpoint)
|
132
38
|
|
133
39
|
const availableBreakpoints = breakpointPairs
|
134
|
-
.filter(([key], index) => index <
|
40
|
+
.filter(([key], index) => index < currentBreakpointIndex && key in value)
|
135
41
|
.map(([key]) => key)
|
136
42
|
|
137
|
-
return
|
138
|
-
? value[availableBreakpoints[availableBreakpoints.length - 1] as keyof B & string]
|
139
|
-
: undefined
|
43
|
+
return value[availableBreakpoints[availableBreakpoints.length - 1] as keyof UnistylesBreakpoints & string]
|
140
44
|
}
|