@niibase/uniwind 1.6.4 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +71 -0
- package/dist/cli/index.cjs +91 -0
- package/dist/cli/index.mjs +84 -0
- package/dist/common/{css → bundler/artifacts/css}/index.js +1 -4
- package/dist/common/{css → bundler/artifacts/css}/themes.js +4 -1
- package/dist/common/{utils/buildDtsFile.js → bundler/artifacts/dts.js} +1 -2
- package/dist/common/bundler/cli/index.js +76 -0
- package/dist/common/bundler/config.js +75 -0
- package/dist/common/bundler/css-compiler/compileCSS.js +18 -0
- package/dist/common/bundler/css-compiler/compileNativeCSS.js +19 -0
- package/dist/common/bundler/css-compiler/compileTailwind.js +27 -0
- package/dist/common/bundler/css-compiler/compileWebCSS.js +15 -0
- package/dist/common/{vite → bundler/css-compiler}/index.js +4 -4
- package/dist/common/bundler/css-processor/addMetaToStylesTemplate.js +130 -0
- package/dist/common/bundler/css-processor/animation.js +112 -0
- package/dist/common/bundler/css-processor/color.js +66 -0
- package/dist/common/bundler/css-processor/css.js +510 -0
- package/dist/common/bundler/css-processor/functions.js +145 -0
- package/dist/common/bundler/css-processor/index.js +38 -0
- package/dist/common/bundler/css-processor/mq.js +87 -0
- package/dist/common/bundler/css-processor/processor.js +353 -0
- package/dist/common/bundler/css-processor/rn.js +356 -0
- package/dist/common/bundler/css-processor/serialize.js +86 -0
- package/dist/common/bundler/css-processor/types.js +1 -0
- package/dist/common/bundler/css-processor/units.js +55 -0
- package/dist/common/bundler/css-processor/utils.js +61 -0
- package/dist/common/bundler/css-processor/var.js +20 -0
- package/dist/common/{css-visitor → bundler/css-visitor}/rule-visitor.js +7 -7
- package/dist/common/{css-visitor → bundler/css-visitor}/visitor.js +5 -6
- package/dist/common/bundler/logger.js +44 -0
- package/dist/common/bundler/types.js +1 -0
- package/dist/common/common/consts.js +26 -2
- package/dist/common/components/web/rnw.js +2 -2
- package/dist/common/core/config/config.common.js +9 -9
- package/dist/common/core/config/config.js +2 -2
- package/dist/common/core/config/config.native.js +4 -8
- package/dist/common/core/listener.js +10 -10
- package/dist/common/core/native/native-utils.js +1 -8
- package/dist/common/core/native/parsers/textShadow.js +6 -18
- package/dist/common/core/native/parsers/transforms.js +1 -5
- package/dist/common/core/native/runtime.js +7 -3
- package/dist/common/core/native/store.js +22 -69
- package/dist/common/core/web/cssListener.js +2 -2
- package/dist/common/hoc/withUniwind.js +5 -5
- package/dist/common/hoc/withUniwind.native.js +5 -5
- package/dist/common/hooks/useCSSVariable/getVariableValue.native.js +4 -1
- package/dist/common/hooks/useCSSVariable/useCSSVariable.js +6 -2
- package/dist/common/hooks/useUniwind.js +2 -2
- package/dist/metro/index.cjs +40 -34
- package/dist/metro/index.d.ts +2 -0
- package/dist/metro/index.mjs +28 -22
- package/dist/metro/{metro-transformer.cjs → transformer.cjs} +316 -200
- package/dist/metro/{metro-transformer.mjs → transformer.mjs} +254 -138
- package/dist/module/{css → bundler/artifacts/css}/index.d.ts +1 -1
- package/dist/module/{css → bundler/artifacts/css}/index.js +1 -4
- package/dist/module/{css → bundler/artifacts/css}/themes.js +4 -1
- package/dist/module/{utils/buildDtsFile.js → bundler/artifacts/dts.js} +3 -4
- package/dist/module/bundler/cli/index.d.ts +2 -0
- package/dist/module/bundler/cli/index.js +81 -0
- package/dist/module/bundler/config.d.ts +17 -0
- package/dist/module/bundler/config.js +77 -0
- package/dist/module/bundler/css-compiler/compileCSS.d.ts +2 -0
- package/dist/module/bundler/css-compiler/compileCSS.js +11 -0
- package/dist/module/bundler/css-compiler/compileNativeCSS.d.ts +2 -0
- package/dist/module/bundler/css-compiler/compileNativeCSS.js +33 -0
- package/dist/module/bundler/css-compiler/compileTailwind.d.ts +2 -0
- package/dist/module/bundler/css-compiler/compileTailwind.js +22 -0
- package/dist/module/bundler/css-compiler/compileWebCSS.d.ts +2 -0
- package/dist/module/bundler/css-compiler/compileWebCSS.js +8 -0
- package/dist/module/bundler/css-compiler/index.d.ts +1 -0
- package/dist/module/bundler/css-compiler/index.js +1 -0
- package/dist/module/bundler/css-processor/addMetaToStylesTemplate.d.ts +3 -0
- package/dist/module/bundler/css-processor/addMetaToStylesTemplate.js +136 -0
- package/dist/module/bundler/css-processor/animation.d.ts +6 -0
- package/dist/module/bundler/css-processor/animation.js +112 -0
- package/dist/module/bundler/css-processor/color.d.ts +12 -0
- package/dist/module/bundler/css-processor/color.js +63 -0
- package/dist/module/bundler/css-processor/css.d.ts +23 -0
- package/dist/module/bundler/css-processor/css.js +566 -0
- package/dist/module/bundler/css-processor/functions.d.ts +12 -0
- package/dist/module/bundler/css-processor/functions.js +190 -0
- package/dist/module/bundler/css-processor/index.d.ts +3 -0
- package/dist/module/bundler/css-processor/index.js +3 -0
- package/dist/module/bundler/css-processor/mq.d.ts +12 -0
- package/dist/module/bundler/css-processor/mq.js +78 -0
- package/dist/module/bundler/css-processor/processor.d.ts +36 -0
- package/dist/module/bundler/css-processor/processor.js +336 -0
- package/dist/module/bundler/css-processor/rn.d.ts +10 -0
- package/dist/module/bundler/css-processor/rn.js +400 -0
- package/dist/module/bundler/css-processor/serialize.d.ts +2 -0
- package/dist/module/bundler/css-processor/serialize.js +101 -0
- package/dist/module/bundler/css-processor/types.d.ts +28 -0
- package/dist/module/bundler/css-processor/types.js +0 -0
- package/dist/module/bundler/css-processor/units.d.ts +10 -0
- package/dist/module/bundler/css-processor/units.js +48 -0
- package/dist/module/bundler/css-processor/utils.d.ts +23 -0
- package/dist/{shared/uniwind.PtWWxxnh.mjs → module/bundler/css-processor/utils.js} +12 -18
- package/dist/module/bundler/css-processor/var.d.ts +7 -0
- package/dist/module/bundler/css-processor/var.js +13 -0
- package/dist/module/{css-visitor → bundler/css-visitor}/function-visitor.d.ts +1 -1
- package/dist/module/{css-visitor → bundler/css-visitor}/rule-visitor.d.ts +4 -3
- package/dist/module/{css-visitor → bundler/css-visitor}/rule-visitor.js +7 -7
- package/dist/module/{css-visitor → bundler/css-visitor}/visitor.d.ts +3 -3
- package/dist/module/{css-visitor → bundler/css-visitor}/visitor.js +5 -6
- package/dist/module/bundler/logger.d.ts +12 -0
- package/dist/module/bundler/logger.js +37 -0
- package/dist/module/bundler/types.d.ts +15 -0
- package/dist/module/bundler/types.js +0 -0
- package/dist/module/common/consts.d.ts +21 -0
- package/dist/module/common/consts.js +24 -0
- package/dist/module/components/ScopedTheme/ScopedTheme.native.d.ts +1 -1
- package/dist/module/components/native/Pressable.d.ts +1 -1
- package/dist/module/components/native/TouchableHighlight.d.ts +1 -1
- package/dist/module/components/native/TouchableOpacity.d.ts +1 -1
- package/dist/module/components/native/useAccentColor.d.ts +1 -1
- package/dist/module/components/native/useStyle.d.ts +3 -3
- package/dist/module/components/react-native-gesture-handler/native/BaseButton.d.ts +1 -1
- package/dist/module/components/react-native-gesture-handler/native/BorderlessButton.d.ts +1 -1
- package/dist/module/components/react-native-gesture-handler/native/DrawerLayoutAndroid.d.ts +1 -1
- package/dist/module/components/react-native-gesture-handler/native/FlatList.d.ts +1 -1
- package/dist/module/components/react-native-gesture-handler/native/Pressable.d.ts +1 -1
- package/dist/module/components/react-native-gesture-handler/native/PureNativeButton.d.ts +1 -1
- package/dist/module/components/react-native-gesture-handler/native/RawButton.d.ts +1 -1
- package/dist/module/components/react-native-gesture-handler/native/RectButton.d.ts +1 -1
- package/dist/module/components/react-native-gesture-handler/native/RefreshControl.d.ts +1 -1
- package/dist/module/components/react-native-gesture-handler/native/ScrollView.d.ts +1 -1
- package/dist/module/components/react-native-gesture-handler/native/Switch.d.ts +1 -1
- package/dist/module/components/react-native-gesture-handler/native/Text.d.ts +4 -1
- package/dist/module/components/react-native-gesture-handler/native/TextInput.d.ts +1 -1
- package/dist/module/components/web/Pressable.d.ts +1 -1
- package/dist/module/components/web/TouchableHighlight.d.ts +1 -1
- package/dist/module/components/web/TouchableOpacity.d.ts +1 -1
- package/dist/module/components/web/rnw.js +1 -1
- package/dist/module/core/config/config.common.d.ts +6 -7
- package/dist/module/core/config/config.common.js +2 -2
- package/dist/module/core/config/config.d.ts +1 -1
- package/dist/module/core/config/config.js +1 -1
- package/dist/module/core/config/config.native.d.ts +2 -2
- package/dist/module/core/config/config.native.js +2 -6
- package/dist/module/core/listener.d.ts +1 -1
- package/dist/module/core/listener.js +1 -1
- package/dist/module/core/native/native-utils.d.ts +0 -1
- package/dist/module/core/native/native-utils.js +0 -6
- package/dist/module/core/native/parsers/textShadow.js +6 -18
- package/dist/module/core/native/parsers/transforms.js +1 -5
- package/dist/module/core/native/runtime.js +5 -1
- package/dist/module/core/native/store.d.ts +3 -3
- package/dist/module/core/native/store.js +22 -65
- package/dist/module/core/types.d.ts +12 -7
- package/dist/module/core/web/cssListener.js +1 -1
- package/dist/module/core/web/getWebStyles.d.ts +1 -1
- package/dist/module/hoc/types.d.ts +2 -2
- package/dist/module/hoc/withUniwind.d.ts +1 -1
- package/dist/module/hoc/withUniwind.js +5 -5
- package/dist/module/hoc/withUniwind.native.d.ts +1 -1
- package/dist/module/hoc/withUniwind.native.js +5 -5
- package/dist/module/hooks/useCSSVariable/getVariableValue.native.d.ts +1 -1
- package/dist/module/hooks/useCSSVariable/getVariableValue.native.js +4 -1
- package/dist/module/hooks/useCSSVariable/useCSSVariable.d.ts +1 -1
- package/dist/module/hooks/useCSSVariable/useCSSVariable.js +5 -1
- package/dist/module/hooks/useResolveClassNames.d.ts +1 -1
- package/dist/module/hooks/useUniwind.d.ts +1 -1
- package/dist/module/hooks/useUniwind.js +1 -1
- package/dist/module/index.d.ts +1 -2
- package/dist/shared/{uniwind.r2i22V6d.cjs → uniwind.BEqYiPBB.cjs} +319 -217
- package/dist/shared/uniwind.CFAAUZ2t.mjs +3 -0
- package/dist/shared/uniwind.DJ5M1Q4q.cjs +5 -0
- package/dist/shared/{uniwind.BGiqYvxb.mjs → uniwind.DgC4MT51.mjs} +312 -214
- package/dist/vite/index.cjs +82 -59
- package/dist/vite/index.mjs +80 -58
- package/package.json +37 -21
- package/src/{metro → bundler/adapters/metro}/index.d.ts +2 -0
- package/src/bundler/adapters/metro/index.ts +1 -0
- package/src/bundler/adapters/metro/metro.ts +67 -0
- package/src/{metro/metro-css-patches.ts → bundler/adapters/metro/patches.ts} +3 -2
- package/src/{metro → bundler/adapters/metro}/resolvers.ts +8 -8
- package/src/bundler/adapters/metro/transformer.ts +85 -0
- package/src/bundler/adapters/vite/vite.ts +148 -0
- package/src/{css → bundler/artifacts/css}/extraUtilities.ts +1 -1
- package/src/{css → bundler/artifacts/css}/index.ts +1 -5
- package/src/{css → bundler/artifacts/css}/themes.ts +7 -2
- package/src/{utils/buildDtsFile.ts → bundler/artifacts/dts.ts} +3 -4
- package/src/bundler/cli/index.ts +105 -0
- package/src/bundler/config.ts +94 -0
- package/src/bundler/css-compiler/compileCSS.ts +15 -0
- package/src/bundler/css-compiler/compileNativeCSS.ts +41 -0
- package/src/bundler/css-compiler/compileTailwind.ts +25 -0
- package/src/bundler/css-compiler/compileWebCSS.ts +10 -0
- package/src/bundler/css-compiler/index.ts +1 -0
- package/src/{metro → bundler/css-processor}/addMetaToStylesTemplate.ts +36 -17
- package/src/{metro/processor → bundler/css-processor}/animation.ts +4 -4
- package/src/{metro/processor → bundler/css-processor}/color.ts +5 -4
- package/src/{metro/processor → bundler/css-processor}/css.ts +19 -11
- package/src/{metro/processor → bundler/css-processor}/functions.ts +2 -2
- package/src/bundler/css-processor/index.ts +3 -0
- package/src/{metro/processor → bundler/css-processor}/mq.ts +4 -4
- package/src/{metro/processor → bundler/css-processor}/processor.ts +20 -18
- package/src/{metro/processor → bundler/css-processor}/rn.ts +96 -3
- package/src/{metro/utils → bundler/css-processor}/serialize.ts +2 -2
- package/src/{metro → bundler/css-processor}/types.ts +3 -17
- package/src/{metro/processor → bundler/css-processor}/units.ts +2 -2
- package/src/{metro/utils/common.ts → bundler/css-processor/utils.ts} +2 -5
- package/src/{metro/processor → bundler/css-processor}/var.ts +2 -2
- package/src/{css-visitor → bundler/css-visitor}/function-visitor.ts +1 -1
- package/src/{css-visitor → bundler/css-visitor}/rule-visitor.ts +8 -7
- package/src/{css-visitor → bundler/css-visitor}/visitor.ts +4 -3
- package/src/{metro → bundler}/logger.ts +4 -0
- package/src/bundler/types.ts +17 -0
- package/src/common/consts.ts +25 -0
- package/src/components/ScopedTheme/ScopedTheme.native.tsx +1 -1
- package/src/components/native/ActivityIndicator.tsx +2 -1
- package/src/components/native/Button.tsx +2 -1
- package/src/components/native/FlatList.tsx +2 -1
- package/src/components/native/Image.tsx +2 -1
- package/src/components/native/ImageBackground.tsx +2 -1
- package/src/components/native/InputAccessoryView.tsx +3 -2
- package/src/components/native/KeyboardAvoidingView.tsx +2 -1
- package/src/components/native/Modal.tsx +2 -1
- package/src/components/native/Pressable.tsx +1 -1
- package/src/components/native/RefreshControl.tsx +2 -1
- package/src/components/native/SafeAreaView.tsx +2 -1
- package/src/components/native/ScrollView.tsx +2 -1
- package/src/components/native/SectionList.tsx +2 -1
- package/src/components/native/Switch.tsx +3 -2
- package/src/components/native/Text.tsx +3 -2
- package/src/components/native/TextInput.tsx +3 -2
- package/src/components/native/TouchableHighlight.tsx +3 -2
- package/src/components/native/TouchableNativeFeedback.tsx +3 -2
- package/src/components/native/TouchableOpacity.tsx +3 -2
- package/src/components/native/TouchableWithoutFeedback.tsx +3 -2
- package/src/components/native/View.tsx +2 -1
- package/src/components/native/VirtualizedList.tsx +2 -1
- package/src/components/native/useAccentColor.ts +1 -1
- package/src/components/native/useStyle.ts +2 -2
- package/src/components/react-native-gesture-handler/native/BaseButton.tsx +1 -1
- package/src/components/react-native-gesture-handler/native/BorderlessButton.tsx +1 -1
- package/src/components/react-native-gesture-handler/native/DrawerLayoutAndroid.tsx +1 -1
- package/src/components/react-native-gesture-handler/native/FlatList.tsx +1 -1
- package/src/components/react-native-gesture-handler/native/GestureHandlerRootView.tsx +1 -1
- package/src/components/react-native-gesture-handler/native/Pressable.tsx +1 -1
- package/src/components/react-native-gesture-handler/native/PureNativeButton.tsx +1 -1
- package/src/components/react-native-gesture-handler/native/RawButton.tsx +1 -1
- package/src/components/react-native-gesture-handler/native/RectButton.tsx +1 -1
- package/src/components/react-native-gesture-handler/native/RefreshControl.tsx +1 -1
- package/src/components/react-native-gesture-handler/native/ScrollView.tsx +1 -1
- package/src/components/react-native-gesture-handler/native/Switch.tsx +2 -2
- package/src/components/react-native-gesture-handler/native/Text.tsx +2 -2
- package/src/components/react-native-gesture-handler/native/TextInput.tsx +2 -2
- package/src/components/react-native-gesture-handler/native/TouchableNativeFeedback.tsx +2 -2
- package/src/components/react-native-gesture-handler/native/TouchableOpacity.tsx +2 -2
- package/src/components/react-native-gesture-handler/native/TouchableWithoutFeedback.tsx +2 -2
- package/src/components/web/ActivityIndicator.tsx +2 -1
- package/src/components/web/Button.tsx +2 -1
- package/src/components/web/FlatList.tsx +2 -1
- package/src/components/web/Image.tsx +2 -1
- package/src/components/web/ImageBackground.tsx +2 -1
- package/src/components/web/KeyboardAvoidingView.tsx +2 -1
- package/src/components/web/Modal.tsx +2 -1
- package/src/components/web/Pressable.tsx +2 -1
- package/src/components/web/RefreshControl.tsx +2 -1
- package/src/components/web/SafeAreaView.tsx +2 -1
- package/src/components/web/ScrollView.tsx +2 -1
- package/src/components/web/SectionList.tsx +2 -1
- package/src/components/web/Switch.tsx +2 -1
- package/src/components/web/Text.tsx +2 -1
- package/src/components/web/TextInput.tsx +2 -1
- package/src/components/web/TouchableHighlight.tsx +2 -1
- package/src/components/web/TouchableOpacity.tsx +2 -1
- package/src/components/web/TouchableWithoutFeedback.tsx +2 -1
- package/src/components/web/View.tsx +2 -1
- package/src/components/web/VirtualizedList.tsx +2 -1
- package/src/components/web/rnw.ts +1 -1
- package/src/core/config/config.common.ts +11 -9
- package/src/core/config/config.native.ts +4 -8
- package/src/core/config/config.ts +2 -2
- package/src/core/listener.ts +1 -1
- package/src/core/native/native-utils.ts +0 -9
- package/src/core/native/parsers/textShadow.ts +6 -18
- package/src/core/native/parsers/transforms.ts +1 -5
- package/src/core/native/runtime.ts +6 -1
- package/src/core/native/store.ts +26 -69
- package/src/core/types.ts +13 -7
- package/src/core/web/cssListener.ts +1 -1
- package/src/core/web/getWebStyles.ts +1 -1
- package/src/hoc/types.ts +2 -2
- package/src/hoc/withUniwind.native.tsx +4 -3
- package/src/hoc/withUniwind.tsx +3 -2
- package/src/hooks/useCSSVariable/getVariableValue.native.ts +6 -3
- package/src/hooks/useCSSVariable/useCSSVariable.ts +8 -2
- package/src/hooks/useResolveClassNames.ts +1 -1
- package/src/hooks/useUniwind.ts +2 -2
- package/src/index.ts +1 -2
- package/dist/common/types.js +0 -28
- package/dist/common/utils/stringifyThemes.js +0 -8
- package/dist/common/vite/vite.js +0 -95
- package/dist/module/types.d.ts +0 -21
- package/dist/module/types.js +0 -22
- package/dist/module/utils/stringifyThemes.d.ts +0 -1
- package/dist/module/utils/stringifyThemes.js +0 -1
- package/dist/module/vite/index.d.ts +0 -9
- package/dist/module/vite/index.js +0 -1
- package/dist/module/vite/vite.d.ts +0 -8
- package/dist/module/vite/vite.js +0 -98
- package/dist/shared/uniwind.B5q8hBGv.cjs +0 -18
- package/dist/shared/uniwind.Cv73KtI-.cjs +0 -86
- package/dist/shared/uniwind.JSWK3vHl.mjs +0 -14
- package/src/metro/compileVirtual.ts +0 -85
- package/src/metro/index.ts +0 -1
- package/src/metro/injectThemes.ts +0 -23
- package/src/metro/metro-transformer.ts +0 -116
- package/src/metro/processor/index.ts +0 -1
- package/src/metro/utils/index.ts +0 -2
- package/src/metro/withUniwindConfig.ts +0 -61
- package/src/types.ts +0 -23
- package/src/utils/stringifyThemes.ts +0 -1
- package/src/vite/index.d.ts +0 -9
- package/src/vite/vite.ts +0 -113
- /package/dist/common/{css → bundler/artifacts/css}/extraUtilities.js +0 -0
- /package/dist/common/{css → bundler/artifacts/css}/insets.js +0 -0
- /package/dist/common/{css → bundler/artifacts/css}/overwrite.js +0 -0
- /package/dist/common/{css → bundler/artifacts/css}/variants.js +0 -0
- /package/dist/common/{css-visitor → bundler/css-visitor}/function-visitor.js +0 -0
- /package/dist/common/{css-visitor → bundler/css-visitor}/index.js +0 -0
- /package/dist/module/{css → bundler/artifacts/css}/extraUtilities.d.ts +0 -0
- /package/dist/module/{css → bundler/artifacts/css}/extraUtilities.js +0 -0
- /package/dist/module/{css → bundler/artifacts/css}/insets.d.ts +0 -0
- /package/dist/module/{css → bundler/artifacts/css}/insets.js +0 -0
- /package/dist/module/{css → bundler/artifacts/css}/overwrite.d.ts +0 -0
- /package/dist/module/{css → bundler/artifacts/css}/overwrite.js +0 -0
- /package/dist/module/{css → bundler/artifacts/css}/themes.d.ts +0 -0
- /package/dist/module/{css → bundler/artifacts/css}/variants.d.ts +0 -0
- /package/dist/module/{css → bundler/artifacts/css}/variants.js +0 -0
- /package/dist/module/{utils/buildDtsFile.d.ts → bundler/artifacts/dts.d.ts} +0 -0
- /package/dist/module/{css-visitor → bundler/css-visitor}/function-visitor.js +0 -0
- /package/dist/module/{css-visitor → bundler/css-visitor}/index.d.ts +0 -0
- /package/dist/module/{css-visitor → bundler/css-visitor}/index.js +0 -0
- /package/{dist/common → src/bundler/adapters}/vite/index.d.ts +0 -0
- /package/src/{vite → bundler/adapters/vite}/index.ts +0 -0
- /package/src/{css → bundler/artifacts/css}/insets.ts +0 -0
- /package/src/{css → bundler/artifacts/css}/overwrite.ts +0 -0
- /package/src/{css → bundler/artifacts/css}/variants.ts +0 -0
- /package/src/{css-visitor → bundler/css-visitor}/index.ts +0 -0
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { DEFAULT_SCREEN_HEIGHT, DEFAULT_SCREEN_WIDTH } from "@/common/consts";
|
|
2
|
+
import { isDefined } from "@/common/utils";
|
|
3
|
+
import { addMissingSpaces, pipe, removeKeys, toCamelCase } from "./utils.js";
|
|
4
|
+
const transitions = { overlay: '"overlayColor"' };
|
|
5
|
+
const cssToRNMap = {
|
|
6
|
+
backgroundSize: (value) => {
|
|
7
|
+
return {
|
|
8
|
+
resizeMode: value
|
|
9
|
+
};
|
|
10
|
+
},
|
|
11
|
+
transitionProperty: (value) => {
|
|
12
|
+
const properties = value.replace(/"/g, "").split(",").filter((token) => token !== "" && !token.startsWith("--")).map((token) => transitions[token.trim()] ?? `"${toCamelCase(token.trim())}"`);
|
|
13
|
+
if (properties.length === 1 && ['"allowDiscrete"', '"normal"'].includes(properties[0])) {
|
|
14
|
+
const behavior = properties[0] === '"allowDiscrete"' ? "allow-discrete" : "normal";
|
|
15
|
+
return {
|
|
16
|
+
transitionBehavior: `"${behavior}"`
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
transitionProperty: properties
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
transitionDuration: (value) => {
|
|
24
|
+
return {
|
|
25
|
+
transitionDuration: value.includes('""') ? value.replace(/""/g, ",") : value
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
transitionTimingFunction: (value) => {
|
|
29
|
+
return {
|
|
30
|
+
transitionTimingFunction: value.includes('""') ? value.replace(/""/g, ",") : value
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
animation: (value) => {
|
|
34
|
+
if (Array.isArray(value)) {
|
|
35
|
+
const result = {};
|
|
36
|
+
for (const [key, val] of value) {
|
|
37
|
+
if (val === '"none"') {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const keyName = toCamelCase(`animation-${key.replace(/^"|"$/g, "")}`);
|
|
41
|
+
if (key === "name") {
|
|
42
|
+
result[keyName] = typeof val === "string" ? val.split(",").map((v) => v.startsWith('"') ? v : `"${v}"`) : val;
|
|
43
|
+
} else {
|
|
44
|
+
result[keyName] = val;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
animationName: value
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
flex: (value) => {
|
|
54
|
+
if (typeof value === "object") {
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
flex: value
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
overflow: (value) => {
|
|
62
|
+
if (typeof value === "object") {
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
overflow: value
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
backdropFilter: () => ({}),
|
|
70
|
+
filter: (value) => ({
|
|
71
|
+
filter: value
|
|
72
|
+
}),
|
|
73
|
+
backgroundImage: (value) => ({
|
|
74
|
+
experimental_backgroundImage: value
|
|
75
|
+
}),
|
|
76
|
+
borderSpacing: () => ({}),
|
|
77
|
+
translate: (value) => {
|
|
78
|
+
if (typeof value === "object" && "x" in value && "y" in value) {
|
|
79
|
+
return {
|
|
80
|
+
translateX: value.x,
|
|
81
|
+
translateY: value.y
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (typeof value === "string") {
|
|
85
|
+
const [x, y] = value.split(" ");
|
|
86
|
+
return {
|
|
87
|
+
translateX: x,
|
|
88
|
+
translateY: y ?? x
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {};
|
|
92
|
+
},
|
|
93
|
+
rotate: (value) => {
|
|
94
|
+
if (typeof value === "object") {
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
rotate: value
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
scale: (value) => {
|
|
102
|
+
if (typeof value === "object") {
|
|
103
|
+
return {
|
|
104
|
+
scaleX: value.x,
|
|
105
|
+
scaleY: value.y,
|
|
106
|
+
scaleZ: value.z
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (typeof value === "string") {
|
|
110
|
+
const [x, y, z] = value.split(" ");
|
|
111
|
+
return {
|
|
112
|
+
scaleX: x,
|
|
113
|
+
scaleY: y,
|
|
114
|
+
scaleZ: z
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return {};
|
|
118
|
+
},
|
|
119
|
+
transform: (value) => {
|
|
120
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
121
|
+
return {
|
|
122
|
+
transform: value
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (typeof value === "object") {
|
|
126
|
+
return Object.keys(value).length === 0 ? { transform: [] } : value;
|
|
127
|
+
}
|
|
128
|
+
return {};
|
|
129
|
+
},
|
|
130
|
+
fontSize: (value) => {
|
|
131
|
+
return {
|
|
132
|
+
fontSize: value,
|
|
133
|
+
"--uniwind-em": value
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
borderInlineWidth: (value) => {
|
|
137
|
+
const borderWidth = typeof value === "object" ? Object.values(value)[0] : value;
|
|
138
|
+
return {
|
|
139
|
+
borderLeftWidth: borderWidth,
|
|
140
|
+
borderRightWidth: borderWidth
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
borderBlockWidth: (value) => {
|
|
144
|
+
const borderWidth = typeof value === "object" ? Object.values(value)[0] : value;
|
|
145
|
+
return {
|
|
146
|
+
borderTopWidth: borderWidth,
|
|
147
|
+
borderBottomWidth: borderWidth
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
borderInlineStyle: (value) => {
|
|
151
|
+
return {
|
|
152
|
+
borderStyle: value
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
borderBlockStyle: (value) => {
|
|
156
|
+
return {
|
|
157
|
+
borderStyle: value
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
borderStyle: (value) => {
|
|
161
|
+
const borderStyle = typeof value === "object" ? Object.values(value)[0] : value;
|
|
162
|
+
return {
|
|
163
|
+
borderStyle
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
transformOrigin: (value) => {
|
|
167
|
+
if (typeof value === "object") {
|
|
168
|
+
return {
|
|
169
|
+
transformOrigin: `${value.x} ${value.y}`
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
transformOrigin: value
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
fontVariantNumeric: (value) => ({
|
|
177
|
+
fontVariant: value
|
|
178
|
+
}),
|
|
179
|
+
display: (value) => {
|
|
180
|
+
if (value === '"box"') {
|
|
181
|
+
return {
|
|
182
|
+
display: '"flex"'
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
display: value
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const BORDER_WIDTH_KEYS = ["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"];
|
|
191
|
+
const BORDER_COLOR_KEYS = ["borderTopColor", "borderRightColor", "borderBottomColor", "borderLeftColor"];
|
|
192
|
+
const BORDER_RADIUS_KEYS = ["borderTopLeftRadius", "borderTopRightRadius", "borderBottomLeftRadius", "borderBottomRightRadius"];
|
|
193
|
+
const COMPONENT_RESPONSIVE_PROPS = /* @__PURE__ */ new Set([
|
|
194
|
+
"width",
|
|
195
|
+
"height",
|
|
196
|
+
"minWidth",
|
|
197
|
+
"maxWidth",
|
|
198
|
+
"minHeight",
|
|
199
|
+
"maxHeight",
|
|
200
|
+
"padding",
|
|
201
|
+
"paddingTop",
|
|
202
|
+
"paddingRight",
|
|
203
|
+
"paddingBottom",
|
|
204
|
+
"paddingLeft",
|
|
205
|
+
"paddingHorizontal",
|
|
206
|
+
"paddingVertical",
|
|
207
|
+
"paddingStart",
|
|
208
|
+
"paddingEnd",
|
|
209
|
+
"margin",
|
|
210
|
+
"marginTop",
|
|
211
|
+
"marginRight",
|
|
212
|
+
"marginBottom",
|
|
213
|
+
"marginLeft",
|
|
214
|
+
"marginHorizontal",
|
|
215
|
+
"marginVertical",
|
|
216
|
+
"marginStart",
|
|
217
|
+
"marginEnd",
|
|
218
|
+
"top",
|
|
219
|
+
"right",
|
|
220
|
+
"bottom",
|
|
221
|
+
"left",
|
|
222
|
+
"gap",
|
|
223
|
+
"rowGap",
|
|
224
|
+
"columnGap",
|
|
225
|
+
"borderWidth",
|
|
226
|
+
"borderTopWidth",
|
|
227
|
+
"borderRightWidth",
|
|
228
|
+
"borderBottomWidth",
|
|
229
|
+
"borderLeftWidth",
|
|
230
|
+
"borderStartWidth",
|
|
231
|
+
"borderEndWidth",
|
|
232
|
+
"borderRadius",
|
|
233
|
+
"borderTopLeftRadius",
|
|
234
|
+
"borderTopRightRadius",
|
|
235
|
+
"borderBottomLeftRadius",
|
|
236
|
+
"borderBottomRightRadius",
|
|
237
|
+
"borderTopStartRadius",
|
|
238
|
+
"borderTopEndRadius",
|
|
239
|
+
"borderBottomStartRadius",
|
|
240
|
+
"borderBottomEndRadius",
|
|
241
|
+
"flexBasis",
|
|
242
|
+
"translateX",
|
|
243
|
+
"translateY"
|
|
244
|
+
]);
|
|
245
|
+
export class RN {
|
|
246
|
+
constructor(Processor) {
|
|
247
|
+
this.Processor = Processor;
|
|
248
|
+
}
|
|
249
|
+
cssToRN(property, value) {
|
|
250
|
+
const transformedProperty = property.startsWith("--") ? property : pipe(property)(
|
|
251
|
+
toCamelCase,
|
|
252
|
+
(x) => {
|
|
253
|
+
if (x.includes("padding") || x.includes("margin")) {
|
|
254
|
+
return x.replace("InlineStart", "Start").replace("InlineEnd", "End").replace("Inline", "Horizontal").replace("Block", "Vertical");
|
|
255
|
+
}
|
|
256
|
+
if (x.includes("border")) {
|
|
257
|
+
return x.replace("InlineStart", "Start").replace("InlineEnd", "End");
|
|
258
|
+
}
|
|
259
|
+
return x;
|
|
260
|
+
}
|
|
261
|
+
);
|
|
262
|
+
const rn = this.transformProperty(
|
|
263
|
+
transformedProperty,
|
|
264
|
+
typeof value === "string" ? addMissingSpaces(value) : value
|
|
265
|
+
);
|
|
266
|
+
const joinedStyles = this.joinStyles(rn);
|
|
267
|
+
return Object.entries(joinedStyles).filter(([, value2]) => isDefined(value2)).map(([prop, val]) => [prop, this.makeResponsive(prop, val)]);
|
|
268
|
+
}
|
|
269
|
+
makeResponsive(property, value) {
|
|
270
|
+
const mode = this.Processor.bundlerConfig.polyfills?.responsive;
|
|
271
|
+
if (!mode) {
|
|
272
|
+
return value;
|
|
273
|
+
}
|
|
274
|
+
if (typeof value === "string") {
|
|
275
|
+
const rawValue = value.startsWith('"') && value.endsWith('"') ? value.slice(1, -1) : value;
|
|
276
|
+
if (rawValue.endsWith("%")) {
|
|
277
|
+
const numValue = parseFloat(rawValue);
|
|
278
|
+
if (!isNaN(numValue)) {
|
|
279
|
+
return `rt.makeResponsive(${numValue}, 100, true)`;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (typeof value !== "number") {
|
|
284
|
+
return value;
|
|
285
|
+
}
|
|
286
|
+
const isTextMode = mode === true || mode === "text";
|
|
287
|
+
const isComponentMode = mode === true || mode === "components";
|
|
288
|
+
if (isTextMode && (property === "fontSize" || property === "--uniwind-em")) {
|
|
289
|
+
return `rt.makeResponsive(${value}, ${DEFAULT_SCREEN_HEIGHT}, true)`;
|
|
290
|
+
}
|
|
291
|
+
if (isComponentMode && COMPONENT_RESPONSIVE_PROPS.has(property)) {
|
|
292
|
+
return `rt.makeResponsive(${value}, ${DEFAULT_SCREEN_WIDTH})`;
|
|
293
|
+
}
|
|
294
|
+
return value;
|
|
295
|
+
}
|
|
296
|
+
transformProperty(property, value) {
|
|
297
|
+
if (property in cssToRNMap) {
|
|
298
|
+
return cssToRNMap[property](value);
|
|
299
|
+
}
|
|
300
|
+
if (typeof value === "object") {
|
|
301
|
+
const transformed = this.transformObjectProperty(property, value);
|
|
302
|
+
if (transformed) {
|
|
303
|
+
return transformed;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
[property]: value
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
transformObjectProperty(property, value) {
|
|
311
|
+
const properties = Object.keys(value);
|
|
312
|
+
const propertyEnd = property.includes("border") ? property.split("border").at(-1) ?? "" : "";
|
|
313
|
+
const transformedProperty = property.replace(propertyEnd, "");
|
|
314
|
+
const isSpacing = property.includes("margin") || property.includes("padding");
|
|
315
|
+
const wrapProperty = (prop) => `${transformedProperty}${prop}${propertyEnd}`;
|
|
316
|
+
if (properties.every((property2) => ["row", "column"].includes(property2))) {
|
|
317
|
+
return {
|
|
318
|
+
rowGap: value.row,
|
|
319
|
+
columnGap: value.column
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
if (properties.every((property2) => ["start", "end"].includes(property2))) {
|
|
323
|
+
if (isSpacing && property.includes("Horizontal")) {
|
|
324
|
+
return {
|
|
325
|
+
[`${property.replace("Horizontal", "Left")}`]: value.start,
|
|
326
|
+
[`${property.replace("Horizontal", "Right")}`]: value.end
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
if (isSpacing && property.includes("Vertical")) {
|
|
330
|
+
return {
|
|
331
|
+
[`${property.replace("Vertical", "Top")}`]: value.start,
|
|
332
|
+
[`${property.replace("Vertical", "Bottom")}`]: value.end
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
[wrapProperty("Start")]: value.start,
|
|
337
|
+
[wrapProperty("End")]: value.end
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
if (properties.every((property2) => ["top", "right", "bottom", "left"].includes(property2))) {
|
|
341
|
+
if (transformedProperty === "inset") {
|
|
342
|
+
const isEverySideSame = properties.every((property2) => value[property2] === value.top);
|
|
343
|
+
return isEverySideSame ? { inset: value.top } : value;
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
[wrapProperty("Top")]: value.top,
|
|
347
|
+
[wrapProperty("Right")]: value.right,
|
|
348
|
+
[wrapProperty("Bottom")]: value.bottom,
|
|
349
|
+
[wrapProperty("Left")]: value.left
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
if (properties.every((property2) => ["topLeft", "topRight", "bottomRight", "bottomLeft"].includes(property2))) {
|
|
353
|
+
return {
|
|
354
|
+
[wrapProperty("TopLeft")]: value.topLeft,
|
|
355
|
+
[wrapProperty("TopRight")]: value.topRight,
|
|
356
|
+
[wrapProperty("BottomRight")]: value.bottomRight,
|
|
357
|
+
[wrapProperty("BottomLeft")]: value.bottomLeft
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
if (properties.every((property2) => ["style", "width", "color"].includes(property2))) {
|
|
361
|
+
return {
|
|
362
|
+
[wrapProperty("Style")]: value.style,
|
|
363
|
+
[wrapProperty("Width")]: value.width,
|
|
364
|
+
[wrapProperty("Color")]: value.color
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
// Used when they're multiple styles with the same value that could be joined
|
|
369
|
+
joinStyles(styles) {
|
|
370
|
+
const keys = Object.keys(styles);
|
|
371
|
+
if (BORDER_WIDTH_KEYS.every((key) => keys.includes(key))) {
|
|
372
|
+
const borderWidth = styles.borderTopWidth;
|
|
373
|
+
if (BORDER_WIDTH_KEYS.every((key) => styles[key] === borderWidth)) {
|
|
374
|
+
return {
|
|
375
|
+
...removeKeys(styles, BORDER_WIDTH_KEYS),
|
|
376
|
+
borderWidth
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (BORDER_COLOR_KEYS.every((key) => keys.includes(key))) {
|
|
381
|
+
const borderColor = styles.borderTopColor;
|
|
382
|
+
if (BORDER_COLOR_KEYS.every((key) => styles[key] === borderColor)) {
|
|
383
|
+
return {
|
|
384
|
+
...removeKeys(styles, BORDER_COLOR_KEYS),
|
|
385
|
+
borderColor
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (BORDER_RADIUS_KEYS.every((key) => keys.includes(key))) {
|
|
390
|
+
const borderRadius = styles.borderTopLeftRadius;
|
|
391
|
+
if (BORDER_RADIUS_KEYS.every((key) => styles[key] === borderRadius)) {
|
|
392
|
+
return {
|
|
393
|
+
...removeKeys(styles, BORDER_RADIUS_KEYS),
|
|
394
|
+
borderRadius
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return styles;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Logger } from "@/bundler/logger";
|
|
2
|
+
import { addMissingSpaces, isNumber, isValidJSValue, pipe, roundToPrecision, smartSplit } from "./utils.js";
|
|
3
|
+
const parseStringValue = (value) => {
|
|
4
|
+
if (isValidJSValue(value)) {
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
if (value.startsWith("function")) {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
const tokens = smartSplit(addMissingSpaces(value));
|
|
11
|
+
const parsedTokens = tokens.map((token) => {
|
|
12
|
+
if (token.startsWith('"')) {
|
|
13
|
+
return token.replace(/"/g, "");
|
|
14
|
+
}
|
|
15
|
+
if (/^[a-z]+$/i.test(token.replace(/,/g, ""))) {
|
|
16
|
+
return token;
|
|
17
|
+
}
|
|
18
|
+
if (isNumber(token)) {
|
|
19
|
+
return token;
|
|
20
|
+
}
|
|
21
|
+
const endsWithComma = token.endsWith(",");
|
|
22
|
+
const expr = endsWithComma ? token.slice(0, -1) : token;
|
|
23
|
+
if (!isValidJSValue(expr)) {
|
|
24
|
+
return token;
|
|
25
|
+
}
|
|
26
|
+
return [
|
|
27
|
+
"${",
|
|
28
|
+
expr,
|
|
29
|
+
"}",
|
|
30
|
+
endsWithComma ? "," : ""
|
|
31
|
+
].join("");
|
|
32
|
+
});
|
|
33
|
+
return [
|
|
34
|
+
"`",
|
|
35
|
+
parsedTokens.join(" "),
|
|
36
|
+
"`"
|
|
37
|
+
].join("");
|
|
38
|
+
};
|
|
39
|
+
export const serialize = (value) => {
|
|
40
|
+
const typeOfValue = typeof value;
|
|
41
|
+
switch (typeOfValue) {
|
|
42
|
+
case "string":
|
|
43
|
+
return parseStringValue(value);
|
|
44
|
+
case "symbol":
|
|
45
|
+
return String(value);
|
|
46
|
+
case "number":
|
|
47
|
+
case "bigint":
|
|
48
|
+
return String(roundToPrecision(value, 2));
|
|
49
|
+
case "boolean":
|
|
50
|
+
return value.toString();
|
|
51
|
+
case "object":
|
|
52
|
+
if (value === null) {
|
|
53
|
+
return "null";
|
|
54
|
+
}
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
return [
|
|
57
|
+
"[",
|
|
58
|
+
value.map(serialize).join(", "),
|
|
59
|
+
"]"
|
|
60
|
+
].join("");
|
|
61
|
+
}
|
|
62
|
+
return [
|
|
63
|
+
"{",
|
|
64
|
+
Object.entries(value).map(([key, val]) => {
|
|
65
|
+
const serializedKey = isNumber(key) ? key : `"${key}"`;
|
|
66
|
+
return `${serializedKey}: ${serialize(val)}`;
|
|
67
|
+
}).join(", "),
|
|
68
|
+
"}"
|
|
69
|
+
].join("");
|
|
70
|
+
case "undefined":
|
|
71
|
+
return "undefined";
|
|
72
|
+
case "function":
|
|
73
|
+
return "";
|
|
74
|
+
default:
|
|
75
|
+
typeOfValue;
|
|
76
|
+
return "";
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
export const serializeJSObject = (obj, serializer) => {
|
|
80
|
+
const serializedObject = pipe(obj)(
|
|
81
|
+
Object.entries,
|
|
82
|
+
(entries) => entries.map(([key, value]) => serializer(key, serialize(value))),
|
|
83
|
+
(serializedValues) => serializedValues.filter((serializedValue) => {
|
|
84
|
+
try {
|
|
85
|
+
new Function(`function validateJS() { const obj = ({ ${serializedValue} }) }`);
|
|
86
|
+
return true;
|
|
87
|
+
} catch {
|
|
88
|
+
Logger.error(`Failed to serialize ${serializedValue} as a valid JS object entry. Skipping.`);
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}),
|
|
92
|
+
(entries) => entries.join(","),
|
|
93
|
+
(result) => {
|
|
94
|
+
if (result === "") {
|
|
95
|
+
return "";
|
|
96
|
+
}
|
|
97
|
+
return `${result},`;
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
return serializedObject;
|
|
101
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ColorScheme, Orientation, Platform } from '@/common/consts';
|
|
2
|
+
import type { AbsoluteFontWeight, Declaration, GradientItemFor_DimensionPercentageFor_LengthValue, LineDirection, MathFunctionFor_DimensionPercentageFor_LengthValue, MathFunctionFor_Length, MediaFeatureValue, ParsedComponent, Token, TokenOrValue, UnresolvedColor } from 'lightningcss';
|
|
3
|
+
export type MediaQueryResolver = {
|
|
4
|
+
maxWidth: number | null;
|
|
5
|
+
minWidth: number | null;
|
|
6
|
+
platform: Platform | null;
|
|
7
|
+
rtl: boolean | null;
|
|
8
|
+
important: boolean;
|
|
9
|
+
importantProperties?: Array<string>;
|
|
10
|
+
colorScheme: ColorScheme | null;
|
|
11
|
+
theme: string | null;
|
|
12
|
+
orientation: Orientation | null;
|
|
13
|
+
disabled: boolean | null;
|
|
14
|
+
active: boolean | null;
|
|
15
|
+
focus: boolean | null;
|
|
16
|
+
dataAttributes: Record<string, string> | null;
|
|
17
|
+
};
|
|
18
|
+
type TakeArray<T> = T extends Array<any> ? T : never;
|
|
19
|
+
export type DeclarationValues = Declaration['value'] | TakeArray<Declaration['value']>[number] | TokenOrValue | Token | ParsedComponent | Array<TokenOrValue> | MediaFeatureValue | MathFunctionFor_DimensionPercentageFor_LengthValue | MathFunctionFor_Length | LineDirection | GradientItemFor_DimensionPercentageFor_LengthValue | AbsoluteFontWeight | UnresolvedColor;
|
|
20
|
+
export type DeclarationProperty = Declaration['property'];
|
|
21
|
+
export type ProcessMetaValues = {
|
|
22
|
+
className?: string | null;
|
|
23
|
+
};
|
|
24
|
+
export type AnimationFrame = [Array<string | number>, Array<Record<string, any>>];
|
|
25
|
+
export type StyleSheetTemplate = {
|
|
26
|
+
[K: string]: Array<MediaQueryResolver & Record<string, unknown>>;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DimensionPercentageFor_LengthValue, Length, LengthValue } from 'lightningcss';
|
|
2
|
+
import type { ProcessorBuilder } from './processor';
|
|
3
|
+
export declare class Units {
|
|
4
|
+
private readonly Processor;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
constructor(Processor: ProcessorBuilder);
|
|
7
|
+
processLength(length: LengthValue | DimensionPercentageFor_LengthValue | number): any;
|
|
8
|
+
processAnyLength(length: DimensionPercentageFor_LengthValue | Length | LengthValue): any;
|
|
9
|
+
replaceInfinity(value: any): any;
|
|
10
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Logger } from "../logger.js";
|
|
2
|
+
export class Units {
|
|
3
|
+
constructor(Processor) {
|
|
4
|
+
this.Processor = Processor;
|
|
5
|
+
}
|
|
6
|
+
logger = new Logger("Units");
|
|
7
|
+
processLength(length) {
|
|
8
|
+
if (typeof length === "number") {
|
|
9
|
+
return length;
|
|
10
|
+
}
|
|
11
|
+
if ("unit" in length) {
|
|
12
|
+
switch (length.unit) {
|
|
13
|
+
case "px":
|
|
14
|
+
return this.replaceInfinity(length.value);
|
|
15
|
+
case "vw":
|
|
16
|
+
return `rt.screen.width * ${length.value / 100}`;
|
|
17
|
+
case "vh":
|
|
18
|
+
return `rt.screen.height * ${length.value / 100}`;
|
|
19
|
+
case "rem":
|
|
20
|
+
return length.value * this.Processor.vars["--uniwind-em"];
|
|
21
|
+
case "em":
|
|
22
|
+
return `vars["--uniwind-em"]?.(vars) * ${length.value}`;
|
|
23
|
+
default:
|
|
24
|
+
this.logger.warn(`Unsupported unit - ${length.unit}`);
|
|
25
|
+
return length.value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return this.Processor.CSS.processValue(length);
|
|
29
|
+
}
|
|
30
|
+
processAnyLength(length) {
|
|
31
|
+
if ("type" in length) {
|
|
32
|
+
switch (length.type) {
|
|
33
|
+
case "value":
|
|
34
|
+
case "dimension":
|
|
35
|
+
return this.processLength(length.value);
|
|
36
|
+
case "percentage":
|
|
37
|
+
return `${length.value * 100}%`;
|
|
38
|
+
default:
|
|
39
|
+
this.logger.warn(`Unsupported length type - ${length.type}`);
|
|
40
|
+
return length.value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return this.processLength(length);
|
|
44
|
+
}
|
|
45
|
+
replaceInfinity(value) {
|
|
46
|
+
return value === Infinity ? 99999 : value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const toCamelCase: (str: string) => string;
|
|
2
|
+
type P<I, O> = (data: I) => O;
|
|
3
|
+
type PipeFns<T> = {
|
|
4
|
+
<A>(a: P<T, A>): A;
|
|
5
|
+
<A, B>(a: P<T, A>, b: P<A, B>): B;
|
|
6
|
+
<A, B, C>(a: P<T, A>, b: P<A, B>, c: P<B, C>): C;
|
|
7
|
+
<A, B, C, D>(a: P<T, A>, b: P<A, B>, c: P<B, C>, d: P<C, D>): D;
|
|
8
|
+
<A, B, C, D, E>(a: P<T, A>, b: P<A, B>, c: P<B, C>, d: P<C, D>, e: P<D, E>): E;
|
|
9
|
+
<A, B, C, D, E, F>(a: P<T, A>, b: P<A, B>, c: P<B, C>, d: P<C, D>, e: P<D, E>, f: P<E, F>): F;
|
|
10
|
+
<A, B, C, D, E, F, G>(a: P<T, A>, b: P<A, B>, c: P<B, C>, d: P<C, D>, e: P<D, E>, f: P<E, F>, g: P<F, G>): G;
|
|
11
|
+
<A, B, C, D, E, F, G, H>(a: P<T, A>, b: P<A, B>, c: P<B, C>, d: P<C, D>, e: P<D, E>, f: P<E, F>, g: P<F, G>, h: P<G, H>): H;
|
|
12
|
+
(...fns: Array<P<T, T>>): T;
|
|
13
|
+
};
|
|
14
|
+
export declare const pipe: <T>(data: T) => PipeFns<T>;
|
|
15
|
+
export declare const isNumber: (data: any) => boolean;
|
|
16
|
+
export declare const smartSplit: (str: string, separator?: string | RegExp) => string[];
|
|
17
|
+
export declare const addMissingSpaces: (str: string) => string;
|
|
18
|
+
export declare const isValidJSValue: (jsValueString: string) => boolean;
|
|
19
|
+
export declare const shouldBeSerialized: (value: string) => boolean;
|
|
20
|
+
export declare const roundToPrecision: (value: number, precision: number) => number;
|
|
21
|
+
export declare const deepEqual: <T>(a: T, b: T) => boolean;
|
|
22
|
+
export declare const removeKeys: <TObj extends Record<PropertyKey, any>, TKey extends keyof TObj>(obj: TObj, keysToRemove: Array<TKey>) => Omit<TObj, TKey>;
|
|
23
|
+
export {};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const pipe = (data) => ((...fns) => fns.reduce((acc, fn) => fn(acc), data));
|
|
5
|
-
const isNumber = (data) => {
|
|
1
|
+
export const toCamelCase = (str) => str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
2
|
+
export const pipe = (data) => ((...fns) => fns.reduce((acc, fn) => fn(acc), data));
|
|
3
|
+
export const isNumber = (data) => {
|
|
6
4
|
if (typeof data === "number") {
|
|
7
5
|
return true;
|
|
8
6
|
}
|
|
@@ -11,7 +9,7 @@ const isNumber = (data) => {
|
|
|
11
9
|
}
|
|
12
10
|
return false;
|
|
13
11
|
};
|
|
14
|
-
const smartSplit = (str, separator = " ") => {
|
|
12
|
+
export const smartSplit = (str, separator = " ") => {
|
|
15
13
|
const escaper = "&&&";
|
|
16
14
|
return pipe(str)(
|
|
17
15
|
(x) => x.replace(/\s\?\?\s/g, `${escaper}??${escaper}`),
|
|
@@ -20,16 +18,14 @@ const smartSplit = (str, separator = " ") => {
|
|
|
20
18
|
(x) => x.map((token) => token.replace(new RegExp(escaper, "g"), " "))
|
|
21
19
|
);
|
|
22
20
|
};
|
|
23
|
-
const addMissingSpaces = (str) => pipe(str)(
|
|
21
|
+
export const addMissingSpaces = (str) => pipe(str)(
|
|
24
22
|
(x) => x.trim(),
|
|
25
|
-
(x) => x.replace(/([^ {])this/g, "$1 this"),
|
|
26
23
|
(x) => x.replace(/\](?=\d)/g, "] "),
|
|
27
24
|
(x) => x.replace(/\](?=")/g, "] "),
|
|
28
|
-
(x) => x.replace(/\)(
|
|
25
|
+
(x) => x.replace(/\)(?=[^\s,])/g, ") "),
|
|
29
26
|
(x) => x.replace(/(?<!^)(?<!\s)"(?=\d)/g, '" ')
|
|
30
27
|
);
|
|
31
|
-
const
|
|
32
|
-
const isValidJSValue = (jsValueString) => {
|
|
28
|
+
export const isValidJSValue = (jsValueString) => {
|
|
33
29
|
try {
|
|
34
30
|
new Function(`const test = ${jsValueString}`);
|
|
35
31
|
return true;
|
|
@@ -37,13 +33,13 @@ const isValidJSValue = (jsValueString) => {
|
|
|
37
33
|
return false;
|
|
38
34
|
}
|
|
39
35
|
};
|
|
40
|
-
const shouldBeSerialized = (value) => {
|
|
36
|
+
export const shouldBeSerialized = (value) => {
|
|
41
37
|
if (value.includes("-")) {
|
|
42
38
|
return value.split("-").some(shouldBeSerialized);
|
|
43
39
|
}
|
|
44
40
|
return [
|
|
45
41
|
isNumber(value),
|
|
46
|
-
value.startsWith("
|
|
42
|
+
value.startsWith("vars["),
|
|
47
43
|
value.startsWith("rt."),
|
|
48
44
|
/[*/+-]/.test(value),
|
|
49
45
|
value.includes('"'),
|
|
@@ -52,8 +48,8 @@ const shouldBeSerialized = (value) => {
|
|
|
52
48
|
value === ")"
|
|
53
49
|
].some(Boolean);
|
|
54
50
|
};
|
|
55
|
-
const roundToPrecision = (value, precision) => parseFloat(value.toFixed(precision));
|
|
56
|
-
const deepEqual = (a, b) => {
|
|
51
|
+
export const roundToPrecision = (value, precision) => parseFloat(value.toFixed(precision));
|
|
52
|
+
export const deepEqual = (a, b) => {
|
|
57
53
|
if (Object.is(a, b)) {
|
|
58
54
|
return true;
|
|
59
55
|
}
|
|
@@ -66,8 +62,6 @@ const deepEqual = (a, b) => {
|
|
|
66
62
|
}
|
|
67
63
|
return keysA.every((key) => deepEqual(a[key], b[key]) && Object.prototype.hasOwnProperty.call(b, key));
|
|
68
64
|
};
|
|
69
|
-
const removeKeys = (obj, keysToRemove) => Object.fromEntries(
|
|
65
|
+
export const removeKeys = (obj, keysToRemove) => Object.fromEntries(
|
|
70
66
|
Object.entries(obj).filter(([key]) => !keysToRemove.includes(key))
|
|
71
67
|
);
|
|
72
|
-
|
|
73
|
-
export { isValidJSValue as a, addMissingSpaces as b, shouldBeSerialized as c, deepEqual as d, removeKeys as e, isNumber as i, name as n, pipe as p, roundToPrecision as r, smartSplit as s, toCamelCase as t, uniq as u };
|