react-native-unistyles 1.3.0 → 1.4.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 +38 -30
- package/lib/commonjs/UnistylesTheme.js +21 -0
- package/lib/commonjs/UnistylesTheme.js.map +1 -0
- package/lib/commonjs/createUnistyles.js +57 -0
- package/lib/commonjs/createUnistyles.js.map +1 -0
- package/lib/commonjs/hooks/index.js +3 -24
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useDimensions.js +10 -0
- package/lib/commonjs/hooks/useDimensions.js.map +1 -0
- package/lib/commonjs/hooks/useDimensions.web.js +34 -0
- package/lib/commonjs/hooks/useDimensions.web.js.map +1 -0
- package/lib/commonjs/index.js +6 -63
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/index.js +0 -11
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/types/mediaQueries.js +2 -0
- package/lib/commonjs/types/{unistyles.js.map → mediaQueries.js.map} +1 -1
- package/lib/commonjs/utils/breakpoints.js +122 -20
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/common.js +20 -0
- package/lib/commonjs/utils/common.js.map +1 -0
- package/lib/commonjs/utils/index.js +54 -22
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/mediaQueries.js +189 -0
- package/lib/commonjs/utils/mediaQueries.js.map +1 -0
- package/lib/{module/types/common.js.map → commonjs/utils/module.d.js.map} +1 -1
- package/lib/commonjs/utils/normalizeStyles.js +10 -0
- package/lib/commonjs/utils/normalizeStyles.js.map +1 -0
- package/lib/commonjs/{normalizer/normalizeStyle.js → utils/normalizeStyles.web.js} +5 -5
- package/lib/commonjs/utils/normalizeStyles.web.js.map +1 -0
- package/lib/commonjs/{normalizer → utils}/normalizer.js +3 -2
- package/lib/commonjs/utils/normalizer.js.map +1 -0
- package/lib/commonjs/utils/styles.js +72 -45
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/module/UnistylesTheme.js +12 -0
- package/lib/module/UnistylesTheme.js.map +1 -0
- package/lib/module/createUnistyles.js +50 -0
- package/lib/module/createUnistyles.js.map +1 -0
- package/lib/module/hooks/index.js +1 -4
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useDimensions.js +3 -0
- package/lib/module/hooks/useDimensions.js.map +1 -0
- package/lib/module/hooks/useDimensions.web.js +27 -0
- package/lib/module/hooks/useDimensions.web.js.map +1 -0
- package/lib/module/index.js +2 -30
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/index.js +0 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/types/mediaQueries.js +2 -0
- package/lib/{commonjs/types/stylesheet.js.map → module/types/mediaQueries.js.map} +1 -1
- package/lib/module/utils/breakpoints.js +120 -19
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/common.js +12 -0
- package/lib/module/utils/common.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/mediaQueries.js +176 -0
- package/lib/module/utils/mediaQueries.js.map +1 -0
- package/lib/{commonjs/types/variants.js.map → module/utils/module.d.js.map} +1 -1
- package/lib/module/utils/normalizeStyles.js +3 -0
- package/lib/module/utils/normalizeStyles.js.map +1 -0
- package/lib/module/{normalizer/normalizeStyle.js → utils/normalizeStyles.web.js} +3 -3
- package/lib/module/utils/normalizeStyles.web.js.map +1 -0
- package/lib/module/{normalizer → utils}/normalizer.js +3 -2
- package/lib/module/utils/normalizer.js.map +1 -0
- package/lib/module/utils/styles.js +72 -44
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/typescript/examples/expo/src/App.d.ts +3 -0
- package/lib/typescript/examples/expo/src/App.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts +3 -0
- package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts +3 -0
- package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/examples/Extreme.d.ts +7 -0
- package/lib/typescript/examples/expo/src/examples/Extreme.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts +3 -0
- package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/examples/Memoization.d.ts +3 -0
- package/lib/typescript/examples/expo/src/examples/Memoization.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/examples/Minimal.d.ts +3 -0
- package/lib/typescript/examples/expo/src/examples/Minimal.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts +3 -0
- package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/examples/PlatformColors.d.ts +3 -0
- package/lib/typescript/examples/expo/src/examples/PlatformColors.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/examples/Theme.d.ts +3 -0
- package/lib/typescript/examples/expo/src/examples/Theme.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/examples/index.d.ts +9 -0
- package/lib/typescript/examples/expo/src/examples/index.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/index.d.ts +2 -0
- package/lib/typescript/examples/expo/src/index.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts +8 -0
- package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/styles/index.d.ts +46 -0
- package/lib/typescript/examples/expo/src/styles/index.d.ts.map +1 -0
- package/lib/typescript/examples/expo/src/styles/theme.d.ts +24 -0
- package/lib/typescript/examples/expo/src/styles/theme.d.ts.map +1 -0
- package/lib/typescript/src/UnistylesTheme.d.ts +9 -0
- package/lib/typescript/src/UnistylesTheme.d.ts.map +1 -0
- package/lib/typescript/src/createUnistyles.d.ts +10 -0
- package/lib/typescript/src/createUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +1 -4
- package/lib/typescript/src/hooks/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useDimensions.d.ts +3 -0
- package/lib/typescript/src/hooks/useDimensions.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useDimensions.web.d.ts +3 -0
- package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -76
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +17 -25
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/core.d.ts +25 -11
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +2 -7
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/mediaQueries.d.ts +8 -0
- package/lib/typescript/src/types/mediaQueries.d.ts.map +1 -0
- package/lib/typescript/src/utils/breakpoints.d.ts +62 -2
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/utils/common.d.ts +7 -0
- package/lib/typescript/src/utils/common.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +6 -7
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/mediaQueries.d.ts +130 -0
- package/lib/typescript/src/utils/mediaQueries.d.ts.map +1 -0
- package/lib/typescript/src/utils/normalizeStyles.d.ts +2 -0
- package/lib/typescript/src/utils/normalizeStyles.d.ts.map +1 -0
- package/lib/typescript/src/utils/normalizeStyles.web.d.ts +5 -0
- package/lib/typescript/src/utils/normalizeStyles.web.d.ts.map +1 -0
- package/lib/typescript/src/utils/normalizer.d.ts.map +1 -0
- package/lib/typescript/src/utils/styles.d.ts +49 -3
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/package.json +25 -46
- package/src/UnistylesTheme.tsx +17 -0
- package/src/__tests__/createUnistyles.spec.tsx +192 -0
- package/src/createUnistyles.ts +70 -0
- package/src/hooks/index.ts +1 -4
- package/src/hooks/useDimensions.ts +4 -0
- package/src/hooks/useDimensions.web.ts +34 -0
- package/src/index.ts +2 -50
- package/src/types/breakpoints.ts +33 -58
- package/src/types/core.ts +36 -11
- package/src/types/index.ts +7 -12
- package/src/types/mediaQueries.ts +10 -0
- package/src/utils/breakpoints.ts +124 -28
- package/src/utils/common.ts +14 -0
- package/src/utils/index.ts +13 -7
- package/src/utils/mediaQueries.ts +201 -0
- package/src/utils/normalizeStyles.ts +2 -0
- package/src/{normalizer/normalizeStyle.ts → utils/normalizeStyles.web.ts} +3 -3
- package/src/{normalizer → utils}/normalizer.ts +4 -5
- package/src/utils/styles.ts +102 -54
- package/android/CMakeLists.txt +0 -27
- package/android/build.gradle +0 -75
- package/android/src/main/cxx/cpp-adapter.cpp +0 -132
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +0 -189
- package/android/src/main/java/com/unistyles/UnistylesPackage.kt +0 -18
- package/cxx/UnistylesRuntime.cpp +0 -318
- package/cxx/UnistylesRuntime.h +0 -74
- package/ios/UnistylesHelpers.h +0 -3
- package/ios/UnistylesHelpers.mm +0 -5
- package/ios/UnistylesModule.h +0 -16
- package/ios/UnistylesModule.mm +0 -138
- package/ios/platform/Platform_iOS.h +0 -21
- package/ios/platform/Platform_iOS.mm +0 -132
- package/ios/platform/Platform_macOS.h +0 -20
- package/ios/platform/Platform_macOS.mm +0 -83
- package/lib/commonjs/common.js +0 -60
- package/lib/commonjs/common.js.map +0 -1
- package/lib/commonjs/core/UnistyleRegistry.js +0 -94
- package/lib/commonjs/core/UnistyleRegistry.js.map +0 -1
- package/lib/commonjs/core/Unistyles.js +0 -32
- package/lib/commonjs/core/Unistyles.js.map +0 -1
- package/lib/commonjs/core/UnistylesModule.js +0 -197
- package/lib/commonjs/core/UnistylesModule.js.map +0 -1
- package/lib/commonjs/core/UnistylesModule.native.js +0 -9
- package/lib/commonjs/core/UnistylesModule.native.js.map +0 -1
- package/lib/commonjs/core/UnistylesRuntime.js +0 -140
- package/lib/commonjs/core/UnistylesRuntime.js.map +0 -1
- package/lib/commonjs/core/index.js +0 -13
- package/lib/commonjs/core/index.js.map +0 -1
- package/lib/commonjs/createStyleSheet.js +0 -14
- package/lib/commonjs/createStyleSheet.js.map +0 -1
- package/lib/commonjs/global.js +0 -2
- package/lib/commonjs/global.js.map +0 -1
- package/lib/commonjs/hooks/useCSS.js +0 -44
- package/lib/commonjs/hooks/useCSS.js.map +0 -1
- package/lib/commonjs/hooks/useCSS.native.js +0 -9
- package/lib/commonjs/hooks/useCSS.native.js.map +0 -1
- package/lib/commonjs/hooks/useInitialTheme.js +0 -17
- package/lib/commonjs/hooks/useInitialTheme.js.map +0 -1
- package/lib/commonjs/hooks/useUnistyles.js +0 -64
- package/lib/commonjs/hooks/useUnistyles.js.map +0 -1
- package/lib/commonjs/hooks/useVariants.js +0 -14
- package/lib/commonjs/hooks/useVariants.js.map +0 -1
- package/lib/commonjs/normalizer/index.js +0 -32
- package/lib/commonjs/normalizer/index.js.map +0 -1
- package/lib/commonjs/normalizer/module.d.js.map +0 -1
- package/lib/commonjs/normalizer/normalizeStyle.js.map +0 -1
- package/lib/commonjs/normalizer/normalizer.js.map +0 -1
- package/lib/commonjs/normalizer/normalizer.macos.js +0 -3
- package/lib/commonjs/normalizer/normalizer.macos.js.map +0 -1
- package/lib/commonjs/plugins/cssMediaQueriesPlugin.js +0 -14
- package/lib/commonjs/plugins/cssMediaQueriesPlugin.js.map +0 -1
- package/lib/commonjs/plugins/index.js +0 -20
- package/lib/commonjs/plugins/index.js.map +0 -1
- package/lib/commonjs/plugins/normalizeWebStylesPlugin.js +0 -12
- package/lib/commonjs/plugins/normalizeWebStylesPlugin.js.map +0 -1
- package/lib/commonjs/types/common.js +0 -2
- package/lib/commonjs/types/common.js.map +0 -1
- package/lib/commonjs/types/plugin.js +0 -6
- package/lib/commonjs/types/plugin.js.map +0 -1
- package/lib/commonjs/types/stylesheet.js +0 -6
- package/lib/commonjs/types/unistyles.js +0 -6
- package/lib/commonjs/types/variants.js +0 -2
- package/lib/commonjs/useStyles.js +0 -47
- package/lib/commonjs/useStyles.js.map +0 -1
- package/lib/commonjs/utils/cssMediaQuery.js +0 -244
- package/lib/commonjs/utils/cssMediaQuery.js.map +0 -1
- package/lib/commonjs/utils/generateId.js +0 -15
- package/lib/commonjs/utils/generateId.js.map +0 -1
- package/lib/commonjs/utils/hash32.js +0 -43
- package/lib/commonjs/utils/hash32.js.map +0 -1
- package/lib/commonjs/utils/mq.js +0 -38
- package/lib/commonjs/utils/mq.js.map +0 -1
- package/lib/commonjs/utils/mqParser.js +0 -89
- package/lib/commonjs/utils/mqParser.js.map +0 -1
- package/lib/commonjs/utils/withPlugins.js +0 -15
- package/lib/commonjs/utils/withPlugins.js.map +0 -1
- package/lib/module/common.js +0 -53
- package/lib/module/common.js.map +0 -1
- package/lib/module/core/UnistyleRegistry.js +0 -87
- package/lib/module/core/UnistyleRegistry.js.map +0 -1
- package/lib/module/core/Unistyles.js +0 -26
- package/lib/module/core/Unistyles.js.map +0 -1
- package/lib/module/core/UnistylesModule.js +0 -190
- package/lib/module/core/UnistylesModule.js.map +0 -1
- package/lib/module/core/UnistylesModule.native.js +0 -3
- package/lib/module/core/UnistylesModule.native.js.map +0 -1
- package/lib/module/core/UnistylesRuntime.js +0 -133
- package/lib/module/core/UnistylesRuntime.js.map +0 -1
- package/lib/module/core/index.js +0 -2
- package/lib/module/core/index.js.map +0 -1
- package/lib/module/createStyleSheet.js +0 -7
- package/lib/module/createStyleSheet.js.map +0 -1
- package/lib/module/global.js +0 -2
- package/lib/module/global.js.map +0 -1
- package/lib/module/hooks/useCSS.js +0 -37
- package/lib/module/hooks/useCSS.js.map +0 -1
- package/lib/module/hooks/useCSS.native.js +0 -2
- package/lib/module/hooks/useCSS.native.js.map +0 -1
- package/lib/module/hooks/useInitialTheme.js +0 -10
- package/lib/module/hooks/useInitialTheme.js.map +0 -1
- package/lib/module/hooks/useUnistyles.js +0 -57
- package/lib/module/hooks/useUnistyles.js.map +0 -1
- package/lib/module/hooks/useVariants.js +0 -7
- package/lib/module/hooks/useVariants.js.map +0 -1
- package/lib/module/normalizer/index.js +0 -3
- package/lib/module/normalizer/index.js.map +0 -1
- package/lib/module/normalizer/module.d.js.map +0 -1
- package/lib/module/normalizer/normalizeStyle.js.map +0 -1
- package/lib/module/normalizer/normalizer.js.map +0 -1
- package/lib/module/normalizer/normalizer.macos.js +0 -2
- package/lib/module/normalizer/normalizer.macos.js.map +0 -1
- package/lib/module/plugins/cssMediaQueriesPlugin.js +0 -7
- package/lib/module/plugins/cssMediaQueriesPlugin.js.map +0 -1
- package/lib/module/plugins/index.js +0 -3
- package/lib/module/plugins/index.js.map +0 -1
- package/lib/module/plugins/normalizeWebStylesPlugin.js +0 -6
- package/lib/module/plugins/normalizeWebStylesPlugin.js.map +0 -1
- package/lib/module/types/common.js +0 -2
- package/lib/module/types/plugin.js +0 -2
- package/lib/module/types/plugin.js.map +0 -1
- package/lib/module/types/stylesheet.js +0 -2
- package/lib/module/types/stylesheet.js.map +0 -1
- package/lib/module/types/unistyles.js +0 -2
- package/lib/module/types/unistyles.js.map +0 -1
- package/lib/module/types/variants.js +0 -2
- package/lib/module/types/variants.js.map +0 -1
- package/lib/module/useStyles.js +0 -40
- package/lib/module/useStyles.js.map +0 -1
- package/lib/module/utils/cssMediaQuery.js +0 -237
- package/lib/module/utils/cssMediaQuery.js.map +0 -1
- package/lib/module/utils/generateId.js +0 -7
- package/lib/module/utils/generateId.js.map +0 -1
- package/lib/module/utils/hash32.js +0 -36
- package/lib/module/utils/hash32.js.map +0 -1
- package/lib/module/utils/mq.js +0 -32
- package/lib/module/utils/mq.js.map +0 -1
- package/lib/module/utils/mqParser.js +0 -78
- package/lib/module/utils/mqParser.js.map +0 -1
- package/lib/module/utils/withPlugins.js +0 -8
- package/lib/module/utils/withPlugins.js.map +0 -1
- package/lib/typescript/src/common.d.ts +0 -46
- package/lib/typescript/src/common.d.ts.map +0 -1
- package/lib/typescript/src/core/UnistyleRegistry.d.ts +0 -56
- package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +0 -1
- package/lib/typescript/src/core/Unistyles.d.ts +0 -13
- package/lib/typescript/src/core/Unistyles.d.ts.map +0 -1
- package/lib/typescript/src/core/UnistylesModule.d.ts +0 -19
- package/lib/typescript/src/core/UnistylesModule.d.ts.map +0 -1
- package/lib/typescript/src/core/UnistylesModule.native.d.ts +0 -6
- package/lib/typescript/src/core/UnistylesModule.native.d.ts.map +0 -1
- package/lib/typescript/src/core/UnistylesRuntime.d.ts +0 -81
- package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +0 -1
- package/lib/typescript/src/core/index.d.ts +0 -3
- package/lib/typescript/src/core/index.d.ts.map +0 -1
- package/lib/typescript/src/createStyleSheet.d.ts +0 -8
- package/lib/typescript/src/createStyleSheet.d.ts.map +0 -1
- package/lib/typescript/src/global.d.ts +0 -7
- package/lib/typescript/src/global.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useCSS.d.ts +0 -3
- package/lib/typescript/src/hooks/useCSS.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useCSS.native.d.ts +0 -3
- package/lib/typescript/src/hooks/useCSS.native.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useInitialTheme.d.ts +0 -3
- package/lib/typescript/src/hooks/useInitialTheme.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useUnistyles.d.ts +0 -14
- package/lib/typescript/src/hooks/useUnistyles.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useVariants.d.ts +0 -3
- package/lib/typescript/src/hooks/useVariants.d.ts.map +0 -1
- package/lib/typescript/src/normalizer/index.d.ts +0 -3
- package/lib/typescript/src/normalizer/index.d.ts.map +0 -1
- package/lib/typescript/src/normalizer/normalizeStyle.d.ts +0 -3
- package/lib/typescript/src/normalizer/normalizeStyle.d.ts.map +0 -1
- package/lib/typescript/src/normalizer/normalizer.d.ts.map +0 -1
- package/lib/typescript/src/normalizer/normalizer.macos.d.ts +0 -1
- package/lib/typescript/src/normalizer/normalizer.macos.d.ts.map +0 -1
- package/lib/typescript/src/plugins/cssMediaQueriesPlugin.d.ts +0 -3
- package/lib/typescript/src/plugins/cssMediaQueriesPlugin.d.ts.map +0 -1
- package/lib/typescript/src/plugins/index.d.ts +0 -3
- package/lib/typescript/src/plugins/index.d.ts.map +0 -1
- package/lib/typescript/src/plugins/normalizeWebStylesPlugin.d.ts +0 -3
- package/lib/typescript/src/plugins/normalizeWebStylesPlugin.d.ts.map +0 -1
- package/lib/typescript/src/types/common.d.ts +0 -3
- package/lib/typescript/src/types/common.d.ts.map +0 -1
- package/lib/typescript/src/types/plugin.d.ts +0 -7
- package/lib/typescript/src/types/plugin.d.ts.map +0 -1
- package/lib/typescript/src/types/stylesheet.d.ts +0 -40
- package/lib/typescript/src/types/stylesheet.d.ts.map +0 -1
- package/lib/typescript/src/types/unistyles.d.ts +0 -53
- package/lib/typescript/src/types/unistyles.d.ts.map +0 -1
- package/lib/typescript/src/types/variants.d.ts +0 -14
- package/lib/typescript/src/types/variants.d.ts.map +0 -1
- package/lib/typescript/src/useStyles.d.ts +0 -16
- package/lib/typescript/src/useStyles.d.ts.map +0 -1
- package/lib/typescript/src/utils/cssMediaQuery.d.ts +0 -4
- package/lib/typescript/src/utils/cssMediaQuery.d.ts.map +0 -1
- package/lib/typescript/src/utils/generateId.d.ts +0 -2
- package/lib/typescript/src/utils/generateId.d.ts.map +0 -1
- package/lib/typescript/src/utils/hash32.d.ts +0 -2
- package/lib/typescript/src/utils/hash32.d.ts.map +0 -1
- package/lib/typescript/src/utils/mq.d.ts +0 -26
- package/lib/typescript/src/utils/mq.d.ts.map +0 -1
- package/lib/typescript/src/utils/mqParser.d.ts +0 -16
- package/lib/typescript/src/utils/mqParser.d.ts.map +0 -1
- package/lib/typescript/src/utils/withPlugins.d.ts +0 -3
- package/lib/typescript/src/utils/withPlugins.d.ts.map +0 -1
- package/react-native-unistyles.podspec +0 -22
- package/src/__tests__/mocks.ts +0 -24
- package/src/common.ts +0 -55
- package/src/core/UnistyleRegistry.ts +0 -108
- package/src/core/Unistyles.ts +0 -35
- package/src/core/UnistylesModule.native.ts +0 -7
- package/src/core/UnistylesModule.ts +0 -230
- package/src/core/UnistylesRuntime.ts +0 -135
- package/src/core/index.ts +0 -2
- package/src/createStyleSheet.ts +0 -8
- package/src/global.ts +0 -6
- package/src/hooks/useCSS.native.ts +0 -3
- package/src/hooks/useCSS.ts +0 -51
- package/src/hooks/useInitialTheme.ts +0 -11
- package/src/hooks/useUnistyles.ts +0 -64
- package/src/hooks/useVariants.ts +0 -10
- package/src/normalizer/index.ts +0 -2
- package/src/normalizer/normalizer.macos.ts +0 -1
- package/src/plugins/cssMediaQueriesPlugin.ts +0 -8
- package/src/plugins/index.ts +0 -2
- package/src/plugins/normalizeWebStylesPlugin.ts +0 -7
- package/src/types/common.ts +0 -2
- package/src/types/plugin.ts +0 -7
- package/src/types/stylesheet.ts +0 -49
- package/src/types/unistyles.ts +0 -63
- package/src/types/variants.ts +0 -19
- package/src/useStyles.ts +0 -60
- package/src/utils/cssMediaQuery.ts +0 -268
- package/src/utils/generateId.ts +0 -10
- package/src/utils/hash32.ts +0 -53
- package/src/utils/mq.ts +0 -57
- package/src/utils/mqParser.ts +0 -99
- package/src/utils/withPlugins.ts +0 -13
- /package/lib/commonjs/{normalizer → utils}/module.d.js +0 -0
- /package/lib/module/{normalizer → utils}/module.d.js +0 -0
- /package/lib/typescript/src/{normalizer → utils}/normalizer.d.ts +0 -0
- /package/src/{normalizer → utils}/module.d.ts +0 -0
package/src/utils/breakpoints.ts
CHANGED
@@ -1,44 +1,140 @@
|
|
1
|
-
import {
|
2
|
-
import type {
|
3
|
-
import
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
1
|
+
import { throwError } from './common'
|
2
|
+
import type { Breakpoints, ScreenSize, SortedBreakpointEntries } from '../types'
|
3
|
+
import { getKeyForCustomMediaQuery, isMediaQuery } from './mediaQueries'
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Sorts the breakpoints object based on its numeric values in ascending order and validates them.
|
7
|
+
*
|
8
|
+
* This function takes an object where keys represent breakpoint names and values are numeric.
|
9
|
+
* It returns a new object with the same keys but sorted based on their corresponding numeric values.
|
10
|
+
* Additionally, it validates that:
|
11
|
+
* 1. The first breakpoint starts with a value of 0.
|
12
|
+
* 2. No duplicate breakpoint values exist.
|
13
|
+
*
|
14
|
+
* If the validation fails, appropriate error messages are logged to the console.
|
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
|
+
})
|
16
33
|
|
17
|
-
const
|
34
|
+
const sortedBreakpoints = Object.freeze(Object.fromEntries(sortedPairs)) as B
|
35
|
+
const breakpointValues = Object.values(sortedBreakpoints)
|
36
|
+
const [firstBreakpoint] = breakpointValues
|
18
37
|
|
19
|
-
if (
|
20
|
-
|
38
|
+
if (firstBreakpoint !== 0) {
|
39
|
+
throwError('first breakpoint must start with 0')
|
21
40
|
}
|
22
41
|
|
23
|
-
|
42
|
+
if (breakpointValues.length !== new Set(breakpointValues).size) {
|
43
|
+
throwError('breakpoint values are duplicated')
|
44
|
+
}
|
45
|
+
|
46
|
+
return sortedBreakpoints
|
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
|
+
}
|
24
73
|
|
25
|
-
|
26
|
-
|
74
|
+
return width >= minVal && width < maxVal
|
75
|
+
}) as [keyof B & string, number]
|
76
|
+
|
77
|
+
return key
|
78
|
+
}
|
79
|
+
|
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)
|
115
|
+
|
116
|
+
if (customMediaQueryKey && customMediaQueryKey in value) {
|
117
|
+
return value[customMediaQueryKey]
|
27
118
|
}
|
28
119
|
|
29
|
-
|
120
|
+
// if no custom media query, or didn't match, proceed with defined breakpoints
|
121
|
+
const unifiedKey = breakpoint
|
122
|
+
const directBreakpoint = value[unifiedKey]
|
30
123
|
|
31
|
-
if
|
124
|
+
// if there is a direct key like 'sm' or 'md', or value for this key exists but its undefined
|
125
|
+
if (directBreakpoint || (unifiedKey in value)) {
|
32
126
|
return directBreakpoint
|
33
127
|
}
|
34
128
|
|
35
|
-
|
36
|
-
const
|
37
|
-
.findIndex(([key]) => key ===
|
129
|
+
// there is no direct hit for breakpoint nor media-query, so let's simulate CSS cascading
|
130
|
+
const currentBreakpoint = breakpointPairs
|
131
|
+
.findIndex(([key]) => key === unifiedKey)
|
38
132
|
|
39
133
|
const availableBreakpoints = breakpointPairs
|
40
|
-
.filter(([key], index) => index <
|
134
|
+
.filter(([key], index) => index < currentBreakpoint && key && key in value)
|
41
135
|
.map(([key]) => key)
|
42
136
|
|
43
|
-
return
|
137
|
+
return breakpointPairs.length > 0
|
138
|
+
? value[availableBreakpoints[availableBreakpoints.length - 1] as keyof B & string]
|
139
|
+
: undefined
|
44
140
|
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { Platform } from 'react-native'
|
2
|
+
|
3
|
+
export const throwError = (message: string) => {
|
4
|
+
throw new Error(`🦄 [react-native-unistyles]: ${message}`)
|
5
|
+
}
|
6
|
+
|
7
|
+
export const warn = (message: string) => {
|
8
|
+
console.warn(`🦄 [react-native-unistyles]: ${message}`)
|
9
|
+
}
|
10
|
+
|
11
|
+
export const isWeb = Platform.OS === 'web'
|
12
|
+
export const isIOS = Platform.OS === 'ios'
|
13
|
+
export const isAndroid = Platform.OS === 'android'
|
14
|
+
export const isServer = typeof window === 'undefined'
|
package/src/utils/index.ts
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
-
export {
|
2
|
-
export
|
3
|
-
export {
|
4
|
-
export {
|
5
|
-
export {
|
6
|
-
export {
|
7
|
-
|
1
|
+
export { normalizeStyles } from './normalizeStyles'
|
2
|
+
export * from './normalizer'
|
3
|
+
export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForBreakpoint } from './breakpoints'
|
4
|
+
export { proxifyFunction, parseStyle } from './styles'
|
5
|
+
export { isServer } from './common'
|
6
|
+
export {
|
7
|
+
extractValues,
|
8
|
+
getKeyForCustomMediaQuery,
|
9
|
+
isMediaQuery,
|
10
|
+
isWithinTheHeight,
|
11
|
+
isWithinTheWidth,
|
12
|
+
isWithinTheWidthAndHeight
|
13
|
+
} from './mediaQueries'
|
@@ -0,0 +1,201 @@
|
|
1
|
+
import type { ScreenSize } from '../types'
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Extracts numeric values from a coded string.
|
5
|
+
*
|
6
|
+
* The function is designed to process strings that have a format like "w[100,200]" or "h[300]".
|
7
|
+
* It removes characters 'w', 'h', '[', and ']' from the input string and then extracts the numbers.
|
8
|
+
*
|
9
|
+
* @param {string} codedValue - The input string to extract values from.
|
10
|
+
* @returns {Array<number>} An array of extracted numbers. Can contain one or two numbers based on the input format.
|
11
|
+
*
|
12
|
+
* @example
|
13
|
+
* extractValues("w[100,200]") // returns [100, 200]
|
14
|
+
* extractValues("h[300]") // returns [300]
|
15
|
+
* extractValues("h[,300]") // returns [0,300]
|
16
|
+
* extractValues("h[100,]") // returns [100]
|
17
|
+
*/
|
18
|
+
export const extractValues = (codedValue: string): Array<number> => {
|
19
|
+
const [lh, rh] = codedValue
|
20
|
+
.replace(/[wh[\]]/g, '')
|
21
|
+
.split(',')
|
22
|
+
|
23
|
+
return rh
|
24
|
+
? [Number(lh), Number(rh)]
|
25
|
+
: [Number(lh)]
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Determines if the given screen size matches the specified breakpoint query.
|
30
|
+
*
|
31
|
+
* The function checks if the screen size (width and/or height) falls within the range
|
32
|
+
* specified by the breakpoint query. The query can specify width (using 'w'), height (using 'h'),
|
33
|
+
* or both.
|
34
|
+
*
|
35
|
+
* @param {string} query - The breakpoint query string. Examples: 'w[100,200]', 'h[300]', 'w[100,200]h[300,400]'.
|
36
|
+
* @param {ScreenSize} screenSize - The screen size to check against the breakpoint query.
|
37
|
+
* @returns {boolean} True if the screen size matches the breakpoint query, false otherwise.
|
38
|
+
*
|
39
|
+
* @example
|
40
|
+
* const screenSize = { width: 150, height: 350 }
|
41
|
+
* isWithinBreakpoint('w[100,200]', screenSize) // returns true
|
42
|
+
* isWithinBreakpoint('h[400]', screenSize) // returns false
|
43
|
+
*/
|
44
|
+
export const isWithinBreakpoint = (query: string, screenSize: ScreenSize): boolean => {
|
45
|
+
if (query.includes('w') && query.includes('h')) {
|
46
|
+
return isWithinTheWidthAndHeight(query, screenSize)
|
47
|
+
}
|
48
|
+
|
49
|
+
if (query.charAt(0) === 'w') {
|
50
|
+
return isWithinTheWidth(query, screenSize.width)
|
51
|
+
}
|
52
|
+
|
53
|
+
if (query.charAt(0) === 'h') {
|
54
|
+
return isWithinTheHeight(query, screenSize.height)
|
55
|
+
}
|
56
|
+
|
57
|
+
return false
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Determines if the given width matches the specified width range in the query.
|
62
|
+
*
|
63
|
+
* The function checks if the provided width falls within the range specified by the query.
|
64
|
+
* The query specifies a width range using a format like 'w[100,200]'. If only one value is provided,
|
65
|
+
* it's treated as a minimum width.
|
66
|
+
*
|
67
|
+
* @param {string} query - The width query string. Examples: 'w[100,200]' or 'w[100]'.
|
68
|
+
* @param {number} width - The width to check against the query.
|
69
|
+
* @returns {boolean} True if the width matches the query range, false otherwise.
|
70
|
+
*
|
71
|
+
* @example
|
72
|
+
* isWithinTheWidth('w[100,200]', 150) // returns true
|
73
|
+
* isWithinTheWidth('w[100]', 50) // returns false
|
74
|
+
* isWithinTheWidth('w[100]', 150) // returns true
|
75
|
+
*/
|
76
|
+
export const isWithinTheWidth = (query: string, width: number): boolean => {
|
77
|
+
const [minWidth, maxWidth] = extractValues(query) as [number, number | undefined]
|
78
|
+
|
79
|
+
if (maxWidth && width >= minWidth && width <= maxWidth) {
|
80
|
+
return true
|
81
|
+
}
|
82
|
+
|
83
|
+
return !maxWidth && width >= minWidth
|
84
|
+
}
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Determines if the given height matches the specified height range in the query.
|
88
|
+
*
|
89
|
+
* The function checks if the provided height falls within the range specified by the query.
|
90
|
+
* The query specifies a height range using a format like 'h[100,200]'. If only one value is provided,
|
91
|
+
* it's treated as a minimum height.
|
92
|
+
*
|
93
|
+
* @param {string} query - The height query string. Examples: 'h[100,200]' or 'h[100]'.
|
94
|
+
* @param {number} height - The height to check against the query.
|
95
|
+
* @returns {boolean} True if the height matches the query range, false otherwise.
|
96
|
+
*
|
97
|
+
* @example
|
98
|
+
* isWithinTheHeight('h[100,200]', 150) // returns true
|
99
|
+
* isWithinTheHeight('h[100]', 50) // returns false
|
100
|
+
* isWithinTheHeight('h[100]', 150) // returns true
|
101
|
+
*/
|
102
|
+
export const isWithinTheHeight = (query: string, height: number): boolean => {
|
103
|
+
const [minHeight, maxHeight] = extractValues(query) as [number, number | undefined]
|
104
|
+
|
105
|
+
if (maxHeight && height >= minHeight && height <= maxHeight) {
|
106
|
+
return true
|
107
|
+
}
|
108
|
+
|
109
|
+
return !maxHeight && height >= minHeight
|
110
|
+
}
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Determines if the given screen size matches both the specified width and height ranges in the query.
|
114
|
+
*
|
115
|
+
* The function checks if the provided screen size (both width and height) falls within the ranges
|
116
|
+
* specified by the query. The query can specify both width and height using a format like 'w[100,200]:h[300,400]'.
|
117
|
+
*
|
118
|
+
* @param {string} query - The combined width and height query string. Example: 'w[100,200]:h[300,400]'.
|
119
|
+
* @param {ScreenSize} screenSize - The screen size to check against the query.
|
120
|
+
* @returns {boolean} True if the screen size matches both the width and height ranges in the query, false otherwise.
|
121
|
+
*
|
122
|
+
* @example
|
123
|
+
* const screenSize = { width: 150, height: 350 }
|
124
|
+
* isWithinTheWidthAndHeight('w[100,200]:h[300,400]', screenSize) // returns true
|
125
|
+
* isWithinTheWidthAndHeight('w[100,200]:h[400,500]', screenSize) // returns false
|
126
|
+
*/
|
127
|
+
export const isWithinTheWidthAndHeight = (query: string, screenSize: ScreenSize): boolean => {
|
128
|
+
const result = query
|
129
|
+
.split(':')
|
130
|
+
.filter(Boolean)
|
131
|
+
.map(q => isWithinBreakpoint(q, screenSize))
|
132
|
+
.filter(Boolean)
|
133
|
+
|
134
|
+
return result.length === 2
|
135
|
+
}
|
136
|
+
|
137
|
+
/**
|
138
|
+
* Checks if the given query string is a valid custom media query.
|
139
|
+
*
|
140
|
+
* The valid custom media query formats include:
|
141
|
+
* - :w[200]
|
142
|
+
* - :w[0, 200]
|
143
|
+
* - :w[, 300]
|
144
|
+
* - :h[200]
|
145
|
+
* - :h[0, 500]
|
146
|
+
* - :h[,200]
|
147
|
+
* - :w[100, 300]:h[200,500]
|
148
|
+
* - :h[200,500]:w[100, 300]
|
149
|
+
*
|
150
|
+
* @param {string} query - The query string to be checked.
|
151
|
+
* @returns {boolean} Returns `true` if the query is a valid custom media query, otherwise `false`.
|
152
|
+
* @example
|
153
|
+
*
|
154
|
+
* isMediaQuery(':w[200]') // true
|
155
|
+
* isMediaQuery(':w100]') // false
|
156
|
+
*/
|
157
|
+
export const isMediaQuery = (query: string): boolean => {
|
158
|
+
const regex = /^(?:(:w\[\d*(?:,\s?\d+)?])?(:h\[\d*(?:,\s?\d+)?])?|(:h\[\d*(?:,\s?\d+)?])?(:w\[\d*(?:,\s?\d+)?])?)$/
|
159
|
+
|
160
|
+
return query.length > 0 && regex.test(query)
|
161
|
+
}
|
162
|
+
|
163
|
+
/**
|
164
|
+
* Retrieves the first matching custom media query key based on the provided screen size.
|
165
|
+
*
|
166
|
+
* The function processes an array of media queries and returns the first query that matches
|
167
|
+
* the given screen size. The media queries can be in formats like:
|
168
|
+
* - w[200]
|
169
|
+
* - w[0, 200]
|
170
|
+
* - w[, 300]
|
171
|
+
* - h[200]
|
172
|
+
* - h[0, 500]
|
173
|
+
* - h[,200]
|
174
|
+
* - w[100, 300]:h[200,500]
|
175
|
+
* - h[200,500]:w[100, 300]
|
176
|
+
*
|
177
|
+
* @param {Array<[string, string | number]>} mediaQueries - An array of tuples containing media query keys and associated values.
|
178
|
+
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
179
|
+
* @returns {string | undefined} Returns the first matching media query key or `undefined` if no match is found.
|
180
|
+
* @example
|
181
|
+
*
|
182
|
+
* const queries = [[':w[200]', 'value1'], [':h[300,500]', 'value2']]
|
183
|
+
* const size = { width: 250, height: 400 }
|
184
|
+
* getKeyForCustomMediaQuery(queries, size) // ':w[200]
|
185
|
+
*/
|
186
|
+
export const getKeyForCustomMediaQuery = (mediaQueries: Array<[string, string | number | undefined]>, screenSize: ScreenSize): string | undefined => {
|
187
|
+
const [matchedQuery] = mediaQueries
|
188
|
+
.flatMap(([key]) => {
|
189
|
+
if (key.includes('w') && key.includes('h')) {
|
190
|
+
return isWithinBreakpoint(key, screenSize) ? key : undefined
|
191
|
+
}
|
192
|
+
|
193
|
+
return key
|
194
|
+
.split(':')
|
195
|
+
.filter(Boolean)
|
196
|
+
.map(query => isWithinBreakpoint(query, screenSize) ? key : undefined)
|
197
|
+
})
|
198
|
+
.filter(Boolean)
|
199
|
+
|
200
|
+
return matchedQuery
|
201
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
|
+
import { warn } from './common'
|
1
2
|
import { preprocessor } from './normalizer'
|
2
|
-
import {
|
3
|
-
import type { NormalizedBoxShadow, NormalizedTextShadow, BoxShadow, TextShadow, RNStyle } from '../types'
|
3
|
+
import type { NormalizedBoxShadow, NormalizedTextShadow, BoxShadow, TextShadow, Transforms } from '../types'
|
4
4
|
|
5
5
|
const normalizeBoxShadow = <T extends BoxShadow>(style: T): NormalizedBoxShadow => {
|
6
6
|
const requiredBoxShadowProperties = [
|
@@ -55,7 +55,7 @@ const normalizeTextShadow = <T extends TextShadow>(style: T): NormalizedTextShad
|
|
55
55
|
}
|
56
56
|
}
|
57
57
|
|
58
|
-
export const
|
58
|
+
export const normalizeStyles = <T extends BoxShadow | TextShadow | { transform: Transforms }>(style: T): T => {
|
59
59
|
const normalizedTransform = ('transform' in style && Array.isArray(style.transform))
|
60
60
|
? { transform: preprocessor.createTransformValue(style.transform) }
|
61
61
|
: {}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
// based on react-native-web normalizer
|
2
2
|
// https://github.com/necolas/react-native-web
|
3
3
|
import normalizeColors from '@react-native/normalize-colors'
|
4
|
-
import type { TextShadow, Transforms, BoxShadow
|
4
|
+
import type { TextShadow, Transforms, BoxShadow } from '../types'
|
5
5
|
|
6
6
|
type Preprocessor = {
|
7
7
|
createTextShadowValue(style: TextShadow): string,
|
@@ -15,9 +15,9 @@ export const normalizeColor = (color: string, opacity: number = 1) => {
|
|
15
15
|
return color
|
16
16
|
}
|
17
17
|
|
18
|
-
const integer = normalizeColors(color) as
|
18
|
+
const integer = normalizeColors(color) as number | null
|
19
19
|
|
20
|
-
// If the
|
20
|
+
// If the colour is an unknown format, the return value is null
|
21
21
|
if (integer === null) {
|
22
22
|
return color
|
23
23
|
}
|
@@ -37,8 +37,7 @@ export const normalizeColor = (color: string, opacity: number = 1) => {
|
|
37
37
|
}
|
38
38
|
|
39
39
|
export const normalizeNumericValue = (value: number) => value ? `${value}px` : value
|
40
|
-
|
41
|
-
const normalizeTransform = <T>(key: string, value: T) => {
|
40
|
+
const normalizeTransform = (key: string, value: number | string) => {
|
42
41
|
if (key.includes('scale')) {
|
43
42
|
return value
|
44
43
|
}
|
package/src/utils/styles.ts
CHANGED
@@ -1,14 +1,36 @@
|
|
1
|
-
import type {
|
1
|
+
import type { Breakpoints, CustomNamedStyles, ScreenSize, SortedBreakpointEntries } from '../types'
|
2
2
|
import { getValueForBreakpoint } from './breakpoints'
|
3
|
-
import {
|
4
|
-
import {
|
3
|
+
import { normalizeStyles } from './normalizeStyles'
|
4
|
+
import { isAndroid, isIOS, isWeb } from './common'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
/**
|
7
|
+
* Proxies a function to parse its return value for custom media queries or breakpoints.
|
8
|
+
*
|
9
|
+
* @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
|
10
|
+
*
|
11
|
+
* @param {Function} fn - The function to be proxified.
|
12
|
+
* @param {keyof B & string} breakpoint - The breakpoint name to check against.
|
13
|
+
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
14
|
+
* @param breakpointPairs - sorted pairs of breakpoints
|
15
|
+
*
|
16
|
+
* @returns {Function} Returns the proxified function
|
17
|
+
*
|
18
|
+
* @example
|
19
|
+
*
|
20
|
+
* const myFunction = () => ({ ':w[200]': 'value1', sm: 'value2' })
|
21
|
+
* const screenSize = { width: 250, height: 400 }
|
22
|
+
* const breakpoints = { sm: 300, md: 600 }
|
23
|
+
*
|
24
|
+
* const proxifiedFunction = proxifyFunction(myFunction, 'sm', screenSize, breakpoints)
|
25
|
+
* proxifiedFunction() // parsed style based on screenSize and breakpoints
|
26
|
+
*/
|
27
|
+
export const proxifyFunction = <B extends Breakpoints>(
|
28
|
+
fn: Function, breakpoint: keyof B & string,
|
29
|
+
screenSize: ScreenSize,
|
30
|
+
breakpointPairs: SortedBreakpointEntries<B>
|
10
31
|
): Function => new Proxy(fn, {
|
11
|
-
apply: (target, thisArg, argumentsList) =>
|
32
|
+
apply: (target, thisArg, argumentsList) =>
|
33
|
+
parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize, breakpointPairs)
|
12
34
|
})
|
13
35
|
|
14
36
|
export const isPlatformColor = <T extends {}>(value: T): boolean => {
|
@@ -19,57 +41,83 @@ export const isPlatformColor = <T extends {}>(value: T): boolean => {
|
|
19
41
|
return isAndroid && 'resource_paths' in value && typeof value.resource_paths === 'object'
|
20
42
|
}
|
21
43
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
44
|
+
/**
|
45
|
+
* Parses a style object to resolve custom media queries or breakpoints based on the provided screen size and breakpoints.
|
46
|
+
*
|
47
|
+
* The function processes each key-value pair in the style object. If the value is a function or a valid style (not an object or a 'transform' key),
|
48
|
+
* it is returned as-is. Otherwise, the function attempts to resolve the value based on the provided breakpoint, screen size, and defined breakpoints.
|
49
|
+
*
|
50
|
+
* @template T - The type of the style object.
|
51
|
+
* @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
|
52
|
+
*
|
53
|
+
* @param {CustomNamedStyles<T, B>} style - The style object to be parsed.
|
54
|
+
* @param {keyof B & string} breakpoint - The breakpoint name to check against.
|
55
|
+
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
56
|
+
* @param breakpointPairs - sorted pairs of breakpoints
|
57
|
+
*
|
58
|
+
* @returns {Record<string, string | number | Function>} Returns the parsed style object with resolved custom media queries or breakpoints.
|
59
|
+
*
|
60
|
+
* @example
|
61
|
+
*
|
62
|
+
* const style = { fontSize: { sm: '12px', md: '16px' } }
|
63
|
+
* const screenSize = { width: 300, height: 400 }
|
64
|
+
* const breakpoints = { xs: 0, sm: 300, md: 600 }
|
65
|
+
*
|
66
|
+
* const parsedStyle = parseStyle(style, 'sm', screenSize, breakpoints)
|
67
|
+
* // { fontSize: '12px' }
|
68
|
+
*/
|
69
|
+
export const parseStyle = <T, B extends Breakpoints>(
|
70
|
+
style: CustomNamedStyles<T, B>,
|
71
|
+
breakpoint: keyof B & string,
|
72
|
+
screenSize: ScreenSize,
|
73
|
+
breakpointPairs: SortedBreakpointEntries<B>
|
74
|
+
): T => {
|
75
|
+
const entries = Object.entries(style || {}) as [[
|
76
|
+
keyof T,
|
77
|
+
CustomNamedStyles<T, B> | Record<keyof B & string, string | number | undefined>]
|
78
|
+
]
|
32
79
|
|
33
|
-
|
34
|
-
|
80
|
+
const parsedStyles = Object
|
81
|
+
.fromEntries(entries
|
82
|
+
.map(([key, value]) => {
|
83
|
+
const hasNestedProperties = key === 'shadowOffset' || key === 'textShadowOffset'
|
35
84
|
|
36
|
-
|
37
|
-
|
38
|
-
|
85
|
+
if (hasNestedProperties) {
|
86
|
+
return [
|
87
|
+
key,
|
88
|
+
parseStyle(value as CustomNamedStyles<T, B>, breakpoint, screenSize, breakpointPairs)
|
89
|
+
]
|
90
|
+
}
|
39
91
|
|
40
|
-
|
41
|
-
}
|
92
|
+
const isTransform = key === 'transform'
|
42
93
|
|
43
|
-
|
44
|
-
|
45
|
-
|
94
|
+
if (isTransform && Array.isArray(value)) {
|
95
|
+
return [
|
96
|
+
key,
|
97
|
+
value.map(value => parseStyle(value, breakpoint, screenSize, breakpointPairs))
|
98
|
+
]
|
99
|
+
}
|
46
100
|
|
47
|
-
|
48
|
-
|
101
|
+
const isDynamicFunction = typeof value === 'function'
|
102
|
+
const isValidStyle = typeof value !== 'object' || isPlatformColor(value)
|
49
103
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
...(Object
|
54
|
-
.keys(value) as Array<keyof typeof value>)
|
55
|
-
.reduce((acc, key) => ({
|
56
|
-
...acc,
|
57
|
-
// this will parse the styles of the selected variant (or default if it is undefined), if selected variant has no styles then it will fallback to default styles
|
58
|
-
...parseStyle((value)[key][variant[key as keyof typeof variant] || 'default'] ?? (value)[key].default ?? {})
|
59
|
-
}), {})
|
60
|
-
}
|
61
|
-
}
|
104
|
+
if (isDynamicFunction || isValidStyle) {
|
105
|
+
return [key, value]
|
106
|
+
}
|
62
107
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
108
|
+
return [
|
109
|
+
key,
|
110
|
+
getValueForBreakpoint<B>(
|
111
|
+
value as Record<keyof B & string, string | number | undefined>,
|
112
|
+
breakpoint,
|
113
|
+
screenSize,
|
114
|
+
breakpointPairs
|
115
|
+
)
|
116
|
+
]
|
117
|
+
})
|
118
|
+
)
|
70
119
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
}, {} as T)
|
120
|
+
return isWeb
|
121
|
+
? normalizeStyles(parsedStyles)
|
122
|
+
: parsedStyles
|
123
|
+
}
|
package/android/CMakeLists.txt
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
cmake_minimum_required(VERSION 3.9.0)
|
2
|
-
|
3
|
-
project(unistyles)
|
4
|
-
|
5
|
-
add_library(unistyles
|
6
|
-
SHARED
|
7
|
-
../cxx/UnistylesRuntime.cpp
|
8
|
-
./src/main/cxx/cpp-adapter.cpp
|
9
|
-
)
|
10
|
-
|
11
|
-
include_directories(
|
12
|
-
../cxx
|
13
|
-
)
|
14
|
-
|
15
|
-
set_target_properties(unistyles PROPERTIES
|
16
|
-
CXX_STANDARD 17
|
17
|
-
CXX_STANDARD_REQUIRED ON
|
18
|
-
CXX_EXTENSIONS OFF
|
19
|
-
POSITION_INDEPENDENT_CODE ON
|
20
|
-
)
|
21
|
-
|
22
|
-
find_package(ReactAndroid REQUIRED CONFIG)
|
23
|
-
|
24
|
-
target_link_libraries(unistyles
|
25
|
-
ReactAndroid::jsi
|
26
|
-
android
|
27
|
-
)
|