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
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"generateId.d.ts","sourceRoot":"","sources":["../../../../src/utils/generateId.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,wBAAwB,QAAS,MAAM,SAAS,MAAM,KAAG,MAMrE,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"hash32.d.ts","sourceRoot":"","sources":["../../../../src/utils/hash32.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,iBAAiB,QAAS,MAAM,QAAQ,MAAM,WA+C1D,CAAA"}
|
@@ -1,7 +1,8 @@
|
|
1
|
-
export {
|
2
|
-
export
|
3
|
-
export {
|
4
|
-
export {
|
5
|
-
export {
|
6
|
-
export {
|
1
|
+
export { mq } from './mq';
|
2
|
+
export type { UnistylesParsedMq } from './mqParser';
|
3
|
+
export { getKeyForUnistylesMediaQuery, isWithinTheWidthAndHeight, isValidMq, parseMq, isUnistylesMq } from './mqParser';
|
4
|
+
export { getValueForBreakpoint } from './breakpoints';
|
5
|
+
export { proxifyFunction, parseStyle, isPlatformColor } from './styles';
|
6
|
+
export { withPlugins } from './withPlugins';
|
7
|
+
export { generateReactNativeWebId } from './generateId';
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAA;AACzB,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACvH,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA"}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import type { Nullable } from '../types';
|
2
|
+
import type { UnistylesBreakpoints } from '../global';
|
3
|
+
type MQValue = keyof UnistylesBreakpoints | number;
|
4
|
+
type MQHandler = {
|
5
|
+
only: {
|
6
|
+
width(wMin?: Nullable<MQValue>, wMax?: MQValue): symbol;
|
7
|
+
height(hMin?: Nullable<MQValue>, hMax?: MQValue): symbol;
|
8
|
+
};
|
9
|
+
width(wMin?: Nullable<MQValue>, wMax?: MQValue): {
|
10
|
+
and: {
|
11
|
+
height(hMin?: Nullable<MQValue>, hMax?: MQValue): symbol;
|
12
|
+
};
|
13
|
+
};
|
14
|
+
height(hMin?: Nullable<MQValue>, hMax?: MQValue): {
|
15
|
+
and: {
|
16
|
+
width(wMin?: Nullable<MQValue>, wMax?: MQValue): symbol;
|
17
|
+
};
|
18
|
+
};
|
19
|
+
};
|
20
|
+
/**
|
21
|
+
* Utility to create cross-platform media queries
|
22
|
+
* @returns - JavaScript symbol to be used in your stylesheet
|
23
|
+
*/
|
24
|
+
export declare const mq: MQHandler;
|
25
|
+
export {};
|
26
|
+
//# sourceMappingURL=mq.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mq.d.ts","sourceRoot":"","sources":["../../../../src/utils/mq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAGrD,KAAK,OAAO,GAAG,MAAM,oBAAoB,GAAG,MAAM,CAAA;AAElD,KAAK,SAAS,GAAG;IACb,IAAI,EAAE;QACF,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;QACxD,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;KAC5D,CAAC;IACF,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG;QAC7C,GAAG,EAAE;YACD,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;SAC3D,CAAA;KACJ,CAAC;IACF,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG;QAC9C,GAAG,EAAE;YACD,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;SAC1D,CAAA;KACJ,CAAA;CACJ,CAAA;AAcD;;;GAGG;AACH,eAAO,MAAM,EAAE,EAAE,SAiBhB,CAAA"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { Optional, RNValue, ScreenSize } from '../types';
|
2
|
+
type ParsedMqDimension = {
|
3
|
+
from: number;
|
4
|
+
to: number;
|
5
|
+
};
|
6
|
+
export type UnistylesParsedMq = {
|
7
|
+
width?: ParsedMqDimension;
|
8
|
+
height?: ParsedMqDimension;
|
9
|
+
};
|
10
|
+
export declare const parseMq: (mq: string) => UnistylesParsedMq;
|
11
|
+
export declare const isUnistylesMq: (mq: string) => boolean;
|
12
|
+
export declare const isValidMq: (parsedMq: UnistylesParsedMq) => boolean;
|
13
|
+
export declare const isWithinTheWidthAndHeight: (parsedMq: UnistylesParsedMq, screenSize: ScreenSize) => boolean;
|
14
|
+
export declare const getKeyForUnistylesMediaQuery: (mediaQueries: Array<[string, RNValue]>, screenSize: ScreenSize) => Optional<string>;
|
15
|
+
export {};
|
16
|
+
//# sourceMappingURL=mqParser.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mqParser.d.ts","sourceRoot":"","sources":["../../../../src/utils/mqParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAM7D,KAAK,iBAAiB,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC5B,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,MAAM,CAAC,EAAE,iBAAiB,CAAA;CAC7B,CAAA;AAED,eAAO,MAAM,OAAO,OAAQ,MAAM,KAAG,iBAcpC,CAAA;AAED,eAAO,MAAM,aAAa,OAAQ,MAAM,YAAgC,CAAA;AAExE,eAAO,MAAM,SAAS,aAAc,iBAAiB,YAgBpD,CAAA;AAED,eAAO,MAAM,yBAAyB,aAAc,iBAAiB,cAAc,UAAU,KAAG,OAgB/F,CAAA;AAcD,eAAO,MAAM,4BAA4B,iBAAkB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,cAAc,UAAU,KAAG,SAAS,MAAM,CAgB5H,CAAA"}
|
@@ -1,50 +1,5 @@
|
|
1
|
-
import type {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
* @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
|
6
|
-
*
|
7
|
-
* @param {Function} fn - The function to be proxified.
|
8
|
-
* @param {keyof B & string} breakpoint - The breakpoint name to check against.
|
9
|
-
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
10
|
-
* @param breakpointPairs - sorted pairs of breakpoints
|
11
|
-
*
|
12
|
-
* @returns {Function} Returns the proxified function
|
13
|
-
*
|
14
|
-
* @example
|
15
|
-
*
|
16
|
-
* const myFunction = () => ({ ':w[200]': 'value1', sm: 'value2' })
|
17
|
-
* const screenSize = { width: 250, height: 400 }
|
18
|
-
* const breakpoints = { sm: 300, md: 600 }
|
19
|
-
*
|
20
|
-
* const proxifiedFunction = proxifyFunction(myFunction, 'sm', screenSize, breakpoints)
|
21
|
-
* proxifiedFunction() // parsed style based on screenSize and breakpoints
|
22
|
-
*/
|
23
|
-
export declare const proxifyFunction: <B extends Breakpoints>(fn: Function, breakpoint: keyof B & string, screenSize: ScreenSize, breakpointPairs: SortedBreakpointEntries<B>) => Function;
|
24
|
-
/**
|
25
|
-
* Parses a style object to resolve custom media queries or breakpoints based on the provided screen size and breakpoints.
|
26
|
-
*
|
27
|
-
* 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),
|
28
|
-
* it is returned as-is. Otherwise, the function attempts to resolve the value based on the provided breakpoint, screen size, and defined breakpoints.
|
29
|
-
*
|
30
|
-
* @template T - The type of the style object.
|
31
|
-
* @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
|
32
|
-
*
|
33
|
-
* @param {CustomNamedStyles<T, B>} style - The style object to be parsed.
|
34
|
-
* @param {keyof B & string} breakpoint - The breakpoint name to check against.
|
35
|
-
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
36
|
-
* @param breakpointPairs - sorted pairs of breakpoints
|
37
|
-
*
|
38
|
-
* @returns {Record<string, string | number | Function>} Returns the parsed style object with resolved custom media queries or breakpoints.
|
39
|
-
*
|
40
|
-
* @example
|
41
|
-
*
|
42
|
-
* const style = { fontSize: { sm: '12px', md: '16px' } }
|
43
|
-
* const screenSize = { width: 300, height: 400 }
|
44
|
-
* const breakpoints = { xs: 0, sm: 300, md: 600 }
|
45
|
-
*
|
46
|
-
* const parsedStyle = parseStyle(style, 'sm', screenSize, breakpoints)
|
47
|
-
* // { fontSize: '12px' }
|
48
|
-
*/
|
49
|
-
export declare const parseStyle: <T, B extends Breakpoints>(style: CustomNamedStyles<T, B>, breakpoint: keyof B & string, screenSize: ScreenSize, breakpointPairs: SortedBreakpointEntries<B>) => T;
|
1
|
+
import type { Optional, RNStyle } from '../types';
|
2
|
+
export declare const proxifyFunction: (key: string, fn: Function, variant?: Record<string, Optional<string>>) => Function;
|
3
|
+
export declare const isPlatformColor: <T extends {}>(value: T) => boolean;
|
4
|
+
export declare const parseStyle: <T extends RNStyle>(style: T, variant?: Record<string, Optional<string>>, parseMediaQueries?: boolean) => T;
|
50
5
|
//# sourceMappingURL=styles.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAW,MAAM,UAAU,CAAA;AAK1D,eAAO,MAAM,eAAe,QACnB,MAAM,MACP,QAAQ,YACF,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC,CAAC,KAC3C,QAED,CAAA;AAEF,eAAO,MAAM,eAAe,8BAA6B,OAMxD,CAAA;AAED,eAAO,MAAM,UAAU,0CAEV,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC,CAAC,mCAmD9B,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"withPlugins.d.ts","sourceRoot":"","sources":["../../../../src/utils/withPlugins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAGvC,eAAO,MAAM,WAAW,QACf,MAAM,SACJ,OAAO,YAOT,CAAA"}
|
package/package.json
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-native-unistyles",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.3.0",
|
4
4
|
"description": "Level up your React Native StyleSheet",
|
5
5
|
"scripts": {
|
6
6
|
"test": "jest",
|
7
7
|
"test:coverage": "jest --coverage",
|
8
8
|
"tsc": "node_modules/typescript/bin/tsc --noEmit",
|
9
9
|
"lint": "eslint . --ext .ts,.tsx",
|
10
|
-
"clean": "del-cli lib",
|
11
10
|
"prepare": "husky install && bob build",
|
12
11
|
"precommit": "concurrently 'yarn tsc' 'yarn lint' 'yarn test'",
|
13
12
|
"release": "release-it"
|
@@ -20,13 +19,28 @@
|
|
20
19
|
"files": [
|
21
20
|
"src",
|
22
21
|
"lib",
|
22
|
+
"ios",
|
23
|
+
"android",
|
24
|
+
"cxx",
|
25
|
+
"react-native-unistyles.podspec",
|
26
|
+
"!lib/typescript/examples",
|
27
|
+
"!ios/build",
|
28
|
+
"!android/build",
|
29
|
+
"!android/gradle",
|
30
|
+
"!android/gradlew",
|
31
|
+
"!android/gradlew.bat",
|
32
|
+
"!android/local.properties",
|
23
33
|
"!**/*.spec.ts",
|
34
|
+
"!**/*.spec.tsx",
|
24
35
|
"!**/.*"
|
25
36
|
],
|
26
37
|
"keywords": [
|
27
38
|
"react-native",
|
28
39
|
"ios",
|
29
|
-
"android"
|
40
|
+
"android",
|
41
|
+
"react-native-macos",
|
42
|
+
"react-native-web",
|
43
|
+
"expo"
|
30
44
|
],
|
31
45
|
"repository": "https://github.com/jpudysz/react-native-unistyles",
|
32
46
|
"author": "Jacek Pudysz <jacekpudysz@gmail.com> (https://github.com/jpudysz)",
|
@@ -39,26 +53,24 @@
|
|
39
53
|
"registry": "https://registry.npmjs.org/"
|
40
54
|
},
|
41
55
|
"devDependencies": {
|
42
|
-
"@commitlint/config-conventional": "
|
56
|
+
"@commitlint/config-conventional": "18.4.3",
|
43
57
|
"@react-native/eslint-config": "0.74.0",
|
44
58
|
"@react-native/normalize-colors": "0.74.1",
|
45
|
-
"@release-it/conventional-changelog": "
|
59
|
+
"@release-it/conventional-changelog": "8.0.1",
|
46
60
|
"@testing-library/react-hooks": "8.0.1",
|
47
|
-
"@types/jest": "29.5.
|
48
|
-
"@types/react": "18.2.
|
49
|
-
"@
|
50
|
-
"@typescript-eslint/eslint-plugin": "6.
|
51
|
-
"@typescript-eslint/
|
52
|
-
"
|
53
|
-
"
|
54
|
-
"
|
55
|
-
"del-cli": "5.1.0",
|
56
|
-
"eslint": "8.51.0",
|
61
|
+
"@types/jest": "29.5.11",
|
62
|
+
"@types/react": "18.2.46",
|
63
|
+
"@typescript-eslint/eslint-plugin": "6.16.0",
|
64
|
+
"@typescript-eslint/eslint-plugin-tslint": "6.16.0",
|
65
|
+
"@typescript-eslint/parser": "6.16.0",
|
66
|
+
"commitlint": "18.4.3",
|
67
|
+
"concurrently": "8.2.2",
|
68
|
+
"eslint": "8.56.0",
|
57
69
|
"eslint-config-codemask": "1.1.7",
|
58
70
|
"eslint-plugin-functional": "6.0.0",
|
59
|
-
"eslint-plugin-import": "2.
|
60
|
-
"eslint-plugin-jsdoc": "46.
|
61
|
-
"eslint-plugin-jsx-a11y": "6.
|
71
|
+
"eslint-plugin-import": "2.29.1",
|
72
|
+
"eslint-plugin-jsdoc": "46.10.1",
|
73
|
+
"eslint-plugin-jsx-a11y": "6.8.0",
|
62
74
|
"eslint-plugin-nested-if": "1.0.0",
|
63
75
|
"eslint-plugin-no-else": "0.2.2",
|
64
76
|
"eslint-plugin-no-loops": "0.3.0",
|
@@ -68,26 +80,31 @@
|
|
68
80
|
"husky": "8.0.3",
|
69
81
|
"jest": "29.7.0",
|
70
82
|
"react": "18.2.0",
|
71
|
-
"react-native": "0.72.
|
72
|
-
"react-native-builder-bob": "0.23.
|
83
|
+
"react-native": "0.72.7",
|
84
|
+
"react-native-builder-bob": "0.23.2",
|
73
85
|
"react-native-web": "0.19.9",
|
74
86
|
"react-test-renderer": "18.2.0",
|
75
|
-
"release-it": "
|
76
|
-
"typescript": "5.
|
87
|
+
"release-it": "17.0.1",
|
88
|
+
"typescript": "5.3.3"
|
77
89
|
},
|
78
90
|
"peerDependencies": {
|
79
91
|
"@react-native/normalize-colors": "*",
|
80
92
|
"react": "*",
|
81
93
|
"react-native": "*",
|
94
|
+
"react-native-macos": "*",
|
82
95
|
"react-native-web": "*"
|
83
96
|
},
|
84
97
|
"peerDependenciesMeta": {
|
98
|
+
"react-native-macos": {
|
99
|
+
"optional": true
|
100
|
+
},
|
85
101
|
"react-native-web": {
|
86
102
|
"optional": true
|
87
103
|
}
|
88
104
|
},
|
89
105
|
"workspaces": [
|
90
106
|
"examples/expo",
|
107
|
+
"examples/macos",
|
91
108
|
"docs"
|
92
109
|
],
|
93
110
|
"packageManager": "yarn@3.6.1",
|
@@ -98,10 +115,13 @@
|
|
98
115
|
"preset": "react-native",
|
99
116
|
"modulePathIgnorePatterns": [
|
100
117
|
"<rootDir>/examples/expo/node_modules",
|
101
|
-
"<rootDir>/examples/
|
118
|
+
"<rootDir>/examples/macos/node_modules",
|
102
119
|
"<rootDir>/docs/node_modules",
|
103
120
|
"<rootDir>/lib/"
|
104
121
|
],
|
122
|
+
"testMatch": [
|
123
|
+
"**/*.spec.(ts|tsx)"
|
124
|
+
],
|
105
125
|
"coverageReporters": [
|
106
126
|
"html"
|
107
127
|
]
|
@@ -124,13 +144,14 @@
|
|
124
144
|
},
|
125
145
|
"plugins": {
|
126
146
|
"@release-it/conventional-changelog": {
|
127
|
-
"preset": "
|
147
|
+
"preset": "angular"
|
128
148
|
}
|
129
149
|
}
|
130
150
|
},
|
131
151
|
"eslintIgnore": [
|
132
152
|
"node_modules/",
|
133
|
-
"lib/"
|
153
|
+
"lib/",
|
154
|
+
"src/utils/hash32.ts"
|
134
155
|
],
|
135
156
|
"react-native-builder-bob": {
|
136
157
|
"source": "src",
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
4
|
+
|
5
|
+
Pod::Spec.new do |s|
|
6
|
+
s.name = package["name"]
|
7
|
+
s.version = package["version"]
|
8
|
+
s.summary = package["description"]
|
9
|
+
s.homepage = package["homepage"]
|
10
|
+
s.license = package["license"]
|
11
|
+
s.authors = package["author"]
|
12
|
+
|
13
|
+
s.platforms = { :ios => min_ios_version_supported, :osx => "10.14" }
|
14
|
+
s.source = { :git => package["repository"], :tag => "#{s.version}" }
|
15
|
+
|
16
|
+
s.source_files = [
|
17
|
+
"ios/**/*.{h,mm}",
|
18
|
+
"cxx/*.{h,cpp}"
|
19
|
+
]
|
20
|
+
|
21
|
+
install_modules_dependencies(s)
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import type { ScreenSize } from '../types'
|
2
|
+
|
3
|
+
const TEST_BREAKPOINTS = {
|
4
|
+
xs: 0,
|
5
|
+
sm: 300,
|
6
|
+
md: 500,
|
7
|
+
lg: 750,
|
8
|
+
xl: 1000
|
9
|
+
} as const
|
10
|
+
|
11
|
+
export const mockRuntime = (screenSize: ScreenSize) => ({
|
12
|
+
breakpoint: Object.entries(TEST_BREAKPOINTS)
|
13
|
+
.reverse()
|
14
|
+
.find(([, value]) => screenSize.width >= value)?.at(0),
|
15
|
+
orientation: screenSize.width > screenSize.height
|
16
|
+
? 'landscape'
|
17
|
+
: 'portrait',
|
18
|
+
screen: screenSize
|
19
|
+
})
|
20
|
+
|
21
|
+
export const mockRegistry = () => ({
|
22
|
+
sortedBreakpointPairs: Object.entries(TEST_BREAKPOINTS),
|
23
|
+
plugins: []
|
24
|
+
})
|
package/src/common.ts
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
import { Platform } from 'react-native'
|
2
|
+
|
3
|
+
export const warn = (message: string) => {
|
4
|
+
console.warn(`🦄 [react-native-unistyles]: ${message}`)
|
5
|
+
}
|
6
|
+
|
7
|
+
export const isWeb = Platform.OS === 'web'
|
8
|
+
export const isIOS = Platform.OS === 'ios'
|
9
|
+
export const isAndroid = Platform.OS === 'android'
|
10
|
+
export const isMobile = isIOS || isAndroid
|
11
|
+
export const isServer = typeof window === 'undefined'
|
12
|
+
|
13
|
+
export const ScreenOrientation = {
|
14
|
+
Landscape: 'landscape',
|
15
|
+
Portrait: 'portrait'
|
16
|
+
} as const
|
17
|
+
|
18
|
+
export enum IOSContentSizeCategory {
|
19
|
+
ExtraExtraExtraLarge = 'xxxLarge',
|
20
|
+
ExtraExtraLarge = 'xxLarge',
|
21
|
+
ExtraLarge = 'xLarge',
|
22
|
+
Large = 'Large',
|
23
|
+
Medium = 'Medium',
|
24
|
+
Small = 'Small',
|
25
|
+
ExtraSmall = 'xSmall',
|
26
|
+
Unspecified = 'unspecified'
|
27
|
+
}
|
28
|
+
|
29
|
+
export enum AndroidContentSizeCategory {
|
30
|
+
Small = 'Small',
|
31
|
+
Default = 'Default',
|
32
|
+
Large = 'Large',
|
33
|
+
ExtraLarge = 'ExtraLarge',
|
34
|
+
Huge = 'Huge'
|
35
|
+
}
|
36
|
+
|
37
|
+
export enum UnistylesEventType {
|
38
|
+
Theme = 'theme',
|
39
|
+
Layout = 'layout',
|
40
|
+
Plugin = 'plugin',
|
41
|
+
DynamicTypeSize = 'dynamicTypeSize'
|
42
|
+
}
|
43
|
+
|
44
|
+
export enum UnistylesError {
|
45
|
+
RuntimeUnavailable = 'Unistyles runtime is not available. Make sure you followed the installation instructions',
|
46
|
+
ThemeNotFound = 'You are trying to get a theme that is not registered with UnistylesRegistry',
|
47
|
+
ThemeNotRegistered = 'You are trying to set a theme that was not registered with UnistylesRegistry',
|
48
|
+
ThemeNotSelected = 'Your themes are registered, but you didn\'t select the initial theme',
|
49
|
+
ThemesCannotBeEmpty = 'You are trying to register empty themes object',
|
50
|
+
BreakpointsCannotBeEmpty = 'You are trying to register empty breakpoints object',
|
51
|
+
BreakpointsMustStartFromZero = 'You are trying to register breakpoints that don\'t start from 0',
|
52
|
+
InvalidPluginName = 'Plugin name can\'t start from reserved prefix __unistyles',
|
53
|
+
DuplicatePluginName = 'You are trying to register a plugin with a name that is already registered',
|
54
|
+
CantRemoveInternalPlugin = 'You are trying to remove an internal unistyles plugin'
|
55
|
+
}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
import type { UnistylesBridge, UnistylesConfig, UnistylesPlugin } from '../types'
|
2
|
+
import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
|
3
|
+
import { isWeb, UnistylesError } from '../common'
|
4
|
+
import { cssMediaQueriesPlugin, normalizeWebStylesPlugin } from '../plugins'
|
5
|
+
|
6
|
+
export class UnistyleRegistry {
|
7
|
+
public config: UnistylesConfig = {}
|
8
|
+
public plugins: Array<UnistylesPlugin> = isWeb
|
9
|
+
? [normalizeWebStylesPlugin]
|
10
|
+
: []
|
11
|
+
public themeNames: Array<keyof UnistylesThemes> = []
|
12
|
+
public themes: UnistylesThemes = {} as UnistylesThemes
|
13
|
+
public breakpoints: UnistylesBreakpoints = {} as UnistylesBreakpoints
|
14
|
+
public sortedBreakpointPairs: Array<[keyof UnistylesBreakpoints, UnistylesBreakpoints[keyof UnistylesBreakpoints]]> = []
|
15
|
+
|
16
|
+
constructor(private unistylesBridge: UnistylesBridge) {}
|
17
|
+
|
18
|
+
public addThemes = (themes: UnistylesThemes) => {
|
19
|
+
this.themes = themes
|
20
|
+
|
21
|
+
const keys = Object.keys(themes) as Array<keyof UnistylesThemes>
|
22
|
+
|
23
|
+
this.unistylesBridge.themes = keys
|
24
|
+
this.themeNames = keys
|
25
|
+
|
26
|
+
return {
|
27
|
+
addBreakpoints: this.addBreakpoints,
|
28
|
+
addConfig: this.addConfig
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
public addBreakpoints = (breakpoints: UnistylesBreakpoints) => {
|
33
|
+
this.breakpoints = breakpoints
|
34
|
+
this.unistylesBridge.useBreakpoints(breakpoints)
|
35
|
+
this.sortedBreakpointPairs = this.unistylesBridge.sortedBreakpointPairs
|
36
|
+
|
37
|
+
return {
|
38
|
+
addThemes: this.addThemes,
|
39
|
+
addConfig: this.addConfig
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
public addConfig = (config: UnistylesConfig) => {
|
44
|
+
this.config = config
|
45
|
+
|
46
|
+
if (config.adaptiveThemes) {
|
47
|
+
this.unistylesBridge.useAdaptiveThemes(config.adaptiveThemes)
|
48
|
+
}
|
49
|
+
|
50
|
+
if (config.plugins) {
|
51
|
+
config.plugins.forEach(plugin => this.addPlugin(plugin, false))
|
52
|
+
}
|
53
|
+
|
54
|
+
if (config.initialTheme) {
|
55
|
+
this.unistylesBridge.useTheme(config.initialTheme)
|
56
|
+
}
|
57
|
+
|
58
|
+
if (config.experimentalCSSMediaQueries) {
|
59
|
+
this.plugins = [cssMediaQueriesPlugin].concat(this.plugins)
|
60
|
+
this.unistylesBridge.addPlugin(cssMediaQueriesPlugin.name, false)
|
61
|
+
}
|
62
|
+
|
63
|
+
return {
|
64
|
+
addBreakpoints: this.addBreakpoints,
|
65
|
+
addThemes: this.addThemes
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
public getTheme = (forName: keyof UnistylesThemes) => {
|
70
|
+
if (this.themeNames.length === 0) {
|
71
|
+
return {} as UnistylesThemes[keyof UnistylesThemes]
|
72
|
+
}
|
73
|
+
|
74
|
+
if (this.hasTheme(forName)) {
|
75
|
+
return this.themes[forName]
|
76
|
+
}
|
77
|
+
|
78
|
+
if (this.unistylesBridge.themeName) {
|
79
|
+
throw new Error(UnistylesError.ThemeNotFound)
|
80
|
+
}
|
81
|
+
|
82
|
+
throw new Error(UnistylesError.ThemeNotSelected)
|
83
|
+
}
|
84
|
+
|
85
|
+
public addPlugin = (plugin: UnistylesPlugin, notify: boolean = true) => {
|
86
|
+
if (plugin.name.startsWith('__unistyles')) {
|
87
|
+
throw new Error(UnistylesError.InvalidPluginName)
|
88
|
+
}
|
89
|
+
|
90
|
+
if (this.plugins.some(({ name }) => name === plugin.name)) {
|
91
|
+
throw new Error(UnistylesError.DuplicatePluginName)
|
92
|
+
}
|
93
|
+
|
94
|
+
this.plugins = [plugin].concat(this.plugins)
|
95
|
+
this.unistylesBridge.addPlugin(plugin.name, notify)
|
96
|
+
}
|
97
|
+
|
98
|
+
public removePlugin = (plugin: UnistylesPlugin) => {
|
99
|
+
if (plugin.name.startsWith('__unistyles')) {
|
100
|
+
throw new Error(UnistylesError.CantRemoveInternalPlugin)
|
101
|
+
}
|
102
|
+
|
103
|
+
this.plugins = this.plugins.filter(({ name }) => name !== plugin.name)
|
104
|
+
this.unistylesBridge.removePlugin(plugin.name)
|
105
|
+
}
|
106
|
+
|
107
|
+
public hasTheme = (name: keyof UnistylesThemes) => name in this.themes
|
108
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { UnistylesModule } from './UnistylesModule'
|
2
|
+
import { UnistylesRuntime } from './UnistylesRuntime'
|
3
|
+
import { UnistyleRegistry } from './UnistyleRegistry'
|
4
|
+
import type { UnistylesBridge } from '../types'
|
5
|
+
import { UnistylesError, isWeb } from '../common'
|
6
|
+
|
7
|
+
class Unistyles {
|
8
|
+
private _runtime: UnistylesRuntime
|
9
|
+
private _registry: UnistyleRegistry
|
10
|
+
private _bridge: UnistylesBridge
|
11
|
+
|
12
|
+
constructor() {
|
13
|
+
const isInstalled = UnistylesModule?.install() ?? false
|
14
|
+
|
15
|
+
if (!isInstalled) {
|
16
|
+
throw new Error(UnistylesError.RuntimeUnavailable)
|
17
|
+
}
|
18
|
+
|
19
|
+
// @ts-ignore
|
20
|
+
// eslint-disable-next-line no-undef
|
21
|
+
this._bridge = (isWeb ? globalThis : global).__UNISTYLES__ as UnistylesBridge
|
22
|
+
this._registry = new UnistyleRegistry(this._bridge)
|
23
|
+
this._runtime = new UnistylesRuntime(this._bridge, this._registry)
|
24
|
+
}
|
25
|
+
|
26
|
+
public get registry() {
|
27
|
+
return this._registry
|
28
|
+
}
|
29
|
+
|
30
|
+
public get runtime() {
|
31
|
+
return this._runtime
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
export const unistyles = new Unistyles()
|