@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,85 @@
|
|
|
1
|
+
import { UniwindBundlerConfig } from '@/bundler/config'
|
|
2
|
+
import { compileCSS } from '@/bundler/css-compiler'
|
|
3
|
+
import type { UniwindMetroConfig } from '@/bundler/types'
|
|
4
|
+
import { Platform } from '@/common/consts'
|
|
5
|
+
import type * as ExpoMetroConfig from '@expo/metro-config'
|
|
6
|
+
import type * as MetroTransformWorker from 'metro-transform-worker'
|
|
7
|
+
import type { JsTransformerConfig, JsTransformOptions } from 'metro-transform-worker'
|
|
8
|
+
import path from 'path'
|
|
9
|
+
import { name as UNIWIND_PACKAGE_NAME } from '../../../../package.json'
|
|
10
|
+
|
|
11
|
+
const cssArtifactPath = path.resolve(__dirname, '../../uniwind.css')
|
|
12
|
+
|
|
13
|
+
let worker: typeof MetroTransformWorker
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
try {
|
|
17
|
+
const { unstable_transformerPath } = require('@expo/metro-config') as typeof ExpoMetroConfig
|
|
18
|
+
|
|
19
|
+
worker = require(unstable_transformerPath)
|
|
20
|
+
} catch {
|
|
21
|
+
worker = require('@expo/metro-config/build/transform-worker/transform-worker.js')
|
|
22
|
+
}
|
|
23
|
+
} catch {
|
|
24
|
+
worker = require('metro-transform-worker')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const transform = async (
|
|
28
|
+
config: JsTransformerConfig & {
|
|
29
|
+
uniwind: UniwindMetroConfig
|
|
30
|
+
},
|
|
31
|
+
projectRoot: string,
|
|
32
|
+
filePath: string,
|
|
33
|
+
data: Buffer,
|
|
34
|
+
options: JsTransformOptions,
|
|
35
|
+
) => {
|
|
36
|
+
const isCss = options.type !== 'asset' && path.join(process.cwd(), config.uniwind.cssEntryFile) === path.join(projectRoot, filePath)
|
|
37
|
+
|
|
38
|
+
if (filePath.endsWith('/components/web/metro-injected.js')) {
|
|
39
|
+
const bundlerConfig = UniwindBundlerConfig.fromMetroConfig(config.uniwind, Platform.Web)
|
|
40
|
+
|
|
41
|
+
data = Buffer.from(
|
|
42
|
+
[
|
|
43
|
+
`import { Uniwind } from '${UNIWIND_PACKAGE_NAME}';`,
|
|
44
|
+
`Uniwind.__reinit(() => ({}), ${bundlerConfig.stringifiedThemes});`,
|
|
45
|
+
].join(''),
|
|
46
|
+
'utf-8',
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!isCss) {
|
|
51
|
+
return worker.transform(config, projectRoot, filePath, data, options)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const bundlerConfig = UniwindBundlerConfig.fromMetroConfig(config.uniwind, options.platform)
|
|
55
|
+
await bundlerConfig.generateArtifacts(cssArtifactPath)
|
|
56
|
+
const virtualCode = await compileCSS(bundlerConfig)
|
|
57
|
+
const isWeb = bundlerConfig.platform === Platform.Web
|
|
58
|
+
|
|
59
|
+
data = Buffer.from(
|
|
60
|
+
isWeb
|
|
61
|
+
? virtualCode
|
|
62
|
+
: [
|
|
63
|
+
`const { Uniwind } = require('${UNIWIND_PACKAGE_NAME}');`,
|
|
64
|
+
`Uniwind.__reinit(rt => ${virtualCode}, ${bundlerConfig.stringifiedThemes});`,
|
|
65
|
+
].join(''),
|
|
66
|
+
'utf-8',
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
const transform: any = await worker.transform(
|
|
70
|
+
config,
|
|
71
|
+
projectRoot,
|
|
72
|
+
`${filePath}${isWeb ? '' : '.js'}`,
|
|
73
|
+
data,
|
|
74
|
+
options,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
transform.output[0].data.css ??= {}
|
|
78
|
+
transform.output[0].data.css.skipCache = true
|
|
79
|
+
|
|
80
|
+
if (!isWeb) {
|
|
81
|
+
transform.output[0].data.css.code = ''
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return transform
|
|
85
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { normalizePath } from '@tailwindcss/node'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import type { PluginContext } from 'rollup'
|
|
5
|
+
import type { Plugin, UserConfig } from 'vite'
|
|
6
|
+
import { name as UNIWIND_PACKAGE_NAME } from '../../../../package.json'
|
|
7
|
+
|
|
8
|
+
import { UniwindBundlerConfig } from '@/bundler/config'
|
|
9
|
+
import type { UniwindConfig } from '@/bundler/types'
|
|
10
|
+
|
|
11
|
+
const dirname = typeof __dirname !== 'undefined' ? __dirname : import.meta.dirname
|
|
12
|
+
const componentPath = path.resolve(
|
|
13
|
+
dirname,
|
|
14
|
+
'../module/components/web/index.js',
|
|
15
|
+
)
|
|
16
|
+
const styleSheetPath = path.resolve(
|
|
17
|
+
dirname,
|
|
18
|
+
'../module/components/web/createOrderedCSSStyleSheet.js',
|
|
19
|
+
)
|
|
20
|
+
const cssArtifactPath = path.resolve(dirname, '../../uniwind.css')
|
|
21
|
+
const require = createRequire(import.meta.url)
|
|
22
|
+
const viteVersion = require('vite/package.json').version as string
|
|
23
|
+
|
|
24
|
+
const isVite8 = Number(viteVersion.split('.')[0]) >= 8
|
|
25
|
+
|
|
26
|
+
type EsbuildResolveArgs = {
|
|
27
|
+
path: string
|
|
28
|
+
importer: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type EsbuildBuild = {
|
|
32
|
+
onResolve: (
|
|
33
|
+
options: { filter: RegExp },
|
|
34
|
+
callback: (args: EsbuildResolveArgs) => { path: string } | undefined,
|
|
35
|
+
) => void
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const resolveOrderedCSSStyleSheet = (source: string, importer: string | undefined) => {
|
|
39
|
+
const normalizedSource = normalizePath(source)
|
|
40
|
+
const isTarget = source === './createOrderedCSSStyleSheet'
|
|
41
|
+
|| normalizedSource.endsWith('react-native-web/dist/exports/StyleSheet/dom/createOrderedCSSStyleSheet.js')
|
|
42
|
+
|
|
43
|
+
if (isTarget && importer !== undefined && normalizePath(importer).includes('react-native-web/dist/exports/StyleSheet')) {
|
|
44
|
+
return styleSheetPath
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const vite8OptimizeDeps = {
|
|
49
|
+
exclude: [UNIWIND_PACKAGE_NAME, 'react-native'],
|
|
50
|
+
rolldownOptions: {
|
|
51
|
+
plugins: [{
|
|
52
|
+
name: 'uniwind-rolldown-plugin',
|
|
53
|
+
resolveId: resolveOrderedCSSStyleSheet,
|
|
54
|
+
}],
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const vite7OptimizeDeps = {
|
|
59
|
+
exclude: [UNIWIND_PACKAGE_NAME, 'react-native'],
|
|
60
|
+
esbuildOptions: {
|
|
61
|
+
plugins: [{
|
|
62
|
+
name: 'uniwind-esbuild-plugin',
|
|
63
|
+
setup: (build: EsbuildBuild) => {
|
|
64
|
+
build.onResolve(
|
|
65
|
+
{ filter: /^\.\/createOrderedCSSStyleSheet$/ },
|
|
66
|
+
args => {
|
|
67
|
+
const resolved = resolveOrderedCSSStyleSheet(args.path, args.importer)
|
|
68
|
+
|
|
69
|
+
if (resolved !== undefined) {
|
|
70
|
+
return { path: resolved }
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
)
|
|
74
|
+
},
|
|
75
|
+
}],
|
|
76
|
+
},
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const vite8Resolve = {
|
|
80
|
+
alias: [{
|
|
81
|
+
find: /^react-native$/,
|
|
82
|
+
replacement: componentPath,
|
|
83
|
+
customResolver: {
|
|
84
|
+
resolveId(this: PluginContext, _: string, importer: string | undefined) {
|
|
85
|
+
if (importer !== undefined && normalizePath(importer).includes(`${UNIWIND_PACKAGE_NAME}/dist`)) {
|
|
86
|
+
return this.resolve('react-native-web', importer, { skipSelf: true })
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return componentPath
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
}],
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const vite7Resolve = {
|
|
96
|
+
alias: [{
|
|
97
|
+
find: /^react-native$/,
|
|
98
|
+
replacement: componentPath,
|
|
99
|
+
customResolver: {
|
|
100
|
+
resolveId(this: PluginContext, _: string, importer: string | undefined) {
|
|
101
|
+
// Check if import comes from uniwind
|
|
102
|
+
if (importer !== undefined && normalizePath(importer).includes(`${UNIWIND_PACKAGE_NAME}/dist`)) {
|
|
103
|
+
return this.resolve('react-native-web')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return componentPath
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
}],
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export const uniwind = (config: UniwindConfig): Plugin => {
|
|
113
|
+
const bundlerConfig = UniwindBundlerConfig.fromViteConfig(config)
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
name: 'uniwind',
|
|
117
|
+
enforce: 'pre',
|
|
118
|
+
resolveId: (source, importer) => {
|
|
119
|
+
return resolveOrderedCSSStyleSheet(source, importer)
|
|
120
|
+
},
|
|
121
|
+
config: () =>
|
|
122
|
+
({
|
|
123
|
+
css: {
|
|
124
|
+
transformer: 'lightningcss',
|
|
125
|
+
lightningcss: {
|
|
126
|
+
visitor: bundlerConfig.cssVisitor,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
optimizeDeps: isVite8 ? vite8OptimizeDeps : vite7OptimizeDeps,
|
|
130
|
+
resolve: isVite8 ? vite8Resolve : vite7Resolve,
|
|
131
|
+
}) as unknown as UserConfig,
|
|
132
|
+
transform: (code, id) => {
|
|
133
|
+
const normalizedId = normalizePath(id)
|
|
134
|
+
|
|
135
|
+
if (normalizedId.includes(`${UNIWIND_PACKAGE_NAME}/dist`) && normalizedId.includes('config/config.js')) {
|
|
136
|
+
return {
|
|
137
|
+
code: `${code}\n;Uniwind.__reinit(() => ({}), ${bundlerConfig.stringifiedThemes})`,
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
buildStart: async () => {
|
|
142
|
+
await bundlerConfig.generateArtifacts(cssArtifactPath)
|
|
143
|
+
},
|
|
144
|
+
generateBundle: async () => {
|
|
145
|
+
await bundlerConfig.generateArtifacts(cssArtifactPath)
|
|
146
|
+
},
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
|
-
import path from 'path'
|
|
3
2
|
import { EXTRA_UTILITIES_CSS } from './extraUtilities'
|
|
4
3
|
import { INSETS_CSS } from './insets'
|
|
5
4
|
import { OVERWRITE_CSS } from './overwrite'
|
|
6
5
|
import { generateCSSForThemes } from './themes'
|
|
7
6
|
import { VARIANTS_CSS } from './variants'
|
|
8
7
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
export const buildCSS = async (themes: Array<string>, input: string) => {
|
|
8
|
+
export const buildCSS = async (themes: Array<string>, input: string, cssFilePath: string) => {
|
|
12
9
|
const themesCSS = await generateCSSForThemes(themes, input)
|
|
13
|
-
const cssFilePath = path.join(dirname, '../../uniwind.css')
|
|
14
10
|
const oldCSSFile = fs.existsSync(cssFilePath)
|
|
15
11
|
? fs.readFileSync(cssFilePath, 'utf-8')
|
|
16
12
|
: ''
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { Logger } from '@/bundler/logger'
|
|
1
2
|
import { compile } from '@tailwindcss/node'
|
|
2
3
|
import fs from 'fs'
|
|
3
4
|
import { transform } from 'lightningcss'
|
|
5
|
+
import type { ImportDependency } from 'lightningcss'
|
|
4
6
|
import path from 'path'
|
|
5
|
-
import { Logger } from '../metro/logger'
|
|
6
7
|
|
|
7
8
|
const readFileSafe = (filePath: string) => {
|
|
8
9
|
try {
|
|
@@ -66,7 +67,11 @@ export const generateCSSForThemes = async (themes: Array<string>, input: string)
|
|
|
66
67
|
|
|
67
68
|
const importUrls = new Set<string>()
|
|
68
69
|
const importsCSS = dependencies
|
|
69
|
-
.filter(dependency => {
|
|
70
|
+
.filter((dependency): dependency is ImportDependency => {
|
|
71
|
+
if (dependency.type !== 'import') {
|
|
72
|
+
return false
|
|
73
|
+
}
|
|
74
|
+
|
|
70
75
|
if (dependency.url.startsWith('.')) {
|
|
71
76
|
importUrls.add(path.resolve(path.dirname(cssPath), dependency.url))
|
|
72
77
|
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
|
-
import { name } from '../../package.json'
|
|
3
2
|
|
|
4
3
|
export const buildDtsFile = (dtsPath: string, stringifiedThemes: string) => {
|
|
5
4
|
const oldDtsContent = fs.existsSync(dtsPath)
|
|
6
5
|
? fs.readFileSync(dtsPath, 'utf-8')
|
|
7
6
|
: ''
|
|
8
7
|
const dtsContent = [
|
|
9
|
-
`// NOTE: This file is generated by
|
|
10
|
-
`/// <reference types="
|
|
8
|
+
`// NOTE: This file is generated by uniwind and it should not be edited manually.`,
|
|
9
|
+
`/// <reference types="uniwind/types" />`,
|
|
11
10
|
'',
|
|
12
|
-
`declare module '
|
|
11
|
+
`declare module 'uniwind' {`,
|
|
13
12
|
` export interface UniwindConfig {`,
|
|
14
13
|
` themes: readonly ${stringifiedThemes}`,
|
|
15
14
|
` }`,
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { UniwindBundlerConfig } from '@/bundler/config'
|
|
4
|
+
import { Logger } from '@/bundler/logger'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
import path from 'path'
|
|
7
|
+
|
|
8
|
+
const dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
9
|
+
const cssArtifactPath = path.resolve(dirname, '../../uniwind.css')
|
|
10
|
+
|
|
11
|
+
type GenerateArtifactsArgs = {
|
|
12
|
+
cssEntryFile?: string
|
|
13
|
+
dtsFile?: string
|
|
14
|
+
extraThemes: Array<string>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const printHelp = () => {
|
|
18
|
+
console.log([
|
|
19
|
+
'Usage: uniwind generate-artifacts --css <file> [--theme <name>...] [--dts <file>]',
|
|
20
|
+
'',
|
|
21
|
+
'Options:',
|
|
22
|
+
' --css <file> CSS entry file path, e.g. ./global.css',
|
|
23
|
+
' --theme <name> Extra theme name. Can be passed multiple times',
|
|
24
|
+
' --dts <file> Generated TypeScript declarations path',
|
|
25
|
+
' --help Show help',
|
|
26
|
+
].join('\n'))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const readValue = (args: Array<string>, index: number, flag: string) => {
|
|
30
|
+
const value = args[index + 1]
|
|
31
|
+
|
|
32
|
+
if (value === undefined || value.startsWith('--')) {
|
|
33
|
+
throw new Error(`Uniwind: ${flag} requires a value`)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return value
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const parseGenerateArtifactsArgs = (args: Array<string>): GenerateArtifactsArgs => {
|
|
40
|
+
const parsed: GenerateArtifactsArgs = {
|
|
41
|
+
extraThemes: [],
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (let index = 0; index < args.length; index++) {
|
|
45
|
+
const arg = args[index]
|
|
46
|
+
|
|
47
|
+
switch (arg) {
|
|
48
|
+
case '--css':
|
|
49
|
+
parsed.cssEntryFile = readValue(args, index, arg)
|
|
50
|
+
index++
|
|
51
|
+
break
|
|
52
|
+
case '--theme':
|
|
53
|
+
parsed.extraThemes.push(readValue(args, index, arg))
|
|
54
|
+
index++
|
|
55
|
+
break
|
|
56
|
+
case '--dts':
|
|
57
|
+
parsed.dtsFile = readValue(args, index, arg)
|
|
58
|
+
index++
|
|
59
|
+
break
|
|
60
|
+
case '--help':
|
|
61
|
+
printHelp()
|
|
62
|
+
process.exit(0)
|
|
63
|
+
default:
|
|
64
|
+
throw new Error(`Uniwind: Unknown option ${arg}`)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return parsed
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const generateArtifacts = async (args: Array<string>) => {
|
|
72
|
+
const parsed = parseGenerateArtifactsArgs(args)
|
|
73
|
+
const bundlerConfig = UniwindBundlerConfig.fromCliConfig({
|
|
74
|
+
cssEntryFile: parsed.cssEntryFile!,
|
|
75
|
+
dtsFile: parsed.dtsFile,
|
|
76
|
+
extraThemes: parsed.extraThemes,
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
await bundlerConfig.generateArtifacts(cssArtifactPath)
|
|
80
|
+
Logger.info('Artifacts generated')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const main = async () => {
|
|
84
|
+
const [command, ...args] = process.argv.slice(2)
|
|
85
|
+
|
|
86
|
+
if (command === '--help' || command === undefined) {
|
|
87
|
+
printHelp()
|
|
88
|
+
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
switch (command) {
|
|
93
|
+
case 'generate-artifacts':
|
|
94
|
+
await generateArtifacts(args)
|
|
95
|
+
|
|
96
|
+
break
|
|
97
|
+
default:
|
|
98
|
+
throw new Error(`Uniwind: Unknown command ${command}`)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
main().catch(error => {
|
|
103
|
+
console.error(error instanceof Error ? error.message : error)
|
|
104
|
+
process.exit(1)
|
|
105
|
+
})
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { buildCSS } from '@/bundler/artifacts/css'
|
|
2
|
+
import { buildDtsFile } from '@/bundler/artifacts/dts'
|
|
3
|
+
import { UniwindCSSVisitor } from '@/bundler/css-visitor'
|
|
4
|
+
import type { UniwindConfig, UniwindMetroConfig } from '@/bundler/types'
|
|
5
|
+
import { Platform } from '@/common/consts'
|
|
6
|
+
import { isDefined } from '@/common/utils'
|
|
7
|
+
import path from 'path'
|
|
8
|
+
|
|
9
|
+
export class UniwindBundlerConfig {
|
|
10
|
+
static fromMetroConfig(config: UniwindMetroConfig, platform?: string | null) {
|
|
11
|
+
const getPlatform = () => {
|
|
12
|
+
if (!isDefined(platform)) {
|
|
13
|
+
return Platform.Native
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!config.isTV) {
|
|
17
|
+
return platform as Platform
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (platform === Platform.Android) {
|
|
21
|
+
return Platform.AndroidTV
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (platform === Platform.iOS) {
|
|
25
|
+
return Platform.AppleTV
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
throw new Error(`Platform ${platform} not supported`)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (typeof config === 'undefined') {
|
|
32
|
+
throw new Error('Uniwind: You need to pass second parameter to withUniwindConfig')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (typeof config.cssEntryFile === 'undefined') {
|
|
36
|
+
throw new Error(
|
|
37
|
+
'Uniwind: You need to pass css css entry file to withUniwindConfig, e.g. withUniwindConfig(config, { cssEntryFile: "./global.css" })',
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return new UniwindBundlerConfig(config, getPlatform())
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static fromViteConfig(config: UniwindConfig) {
|
|
45
|
+
return new UniwindBundlerConfig(config, Platform.Web)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static fromCliConfig(config: UniwindConfig) {
|
|
49
|
+
if (typeof config.cssEntryFile === 'undefined') {
|
|
50
|
+
throw new Error(
|
|
51
|
+
'Uniwind: You need to pass css entry file, e.g. uniwind generate-artifacts --css ./global.css. Run uniwind generate-artifacts --help for usage.',
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return new UniwindBundlerConfig(config, Platform.Web)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
constructor(private readonly config: UniwindMetroConfig, readonly platform: Platform) {}
|
|
59
|
+
|
|
60
|
+
get cssPath() {
|
|
61
|
+
return path.join(process.cwd(), this.config.cssEntryFile)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get themes() {
|
|
65
|
+
return Array.from(
|
|
66
|
+
new Set([
|
|
67
|
+
'light',
|
|
68
|
+
'dark',
|
|
69
|
+
...this.config.extraThemes ?? [],
|
|
70
|
+
]),
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get cssVisitor() {
|
|
75
|
+
return new UniwindCSSVisitor(this)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get polyfills() {
|
|
79
|
+
return this.config.polyfills
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get stringifiedThemes() {
|
|
83
|
+
return `[${this.themes.map((theme) => `'${theme}'`).join(', ')}]`
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
toMetroConfig() {
|
|
87
|
+
return this.config
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async generateArtifacts(cssArtifactPath: string) {
|
|
91
|
+
await buildCSS(this.themes, this.config.cssEntryFile, cssArtifactPath)
|
|
92
|
+
buildDtsFile(this.config.dtsFile ?? 'uniwind-types.d.ts', this.stringifiedThemes)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Platform } from '@/common/consts'
|
|
2
|
+
import type { UniwindBundlerConfig } from '../config'
|
|
3
|
+
import { compileNativeCSS } from './compileNativeCSS'
|
|
4
|
+
import { compileTailwind } from './compileTailwind'
|
|
5
|
+
import { compileWebCSS } from './compileWebCSS'
|
|
6
|
+
|
|
7
|
+
export const compileCSS = async (bundlerConfig: UniwindBundlerConfig) => {
|
|
8
|
+
const tailwindCSS = await compileTailwind(bundlerConfig)
|
|
9
|
+
|
|
10
|
+
if (bundlerConfig.platform === Platform.Web) {
|
|
11
|
+
return compileWebCSS(bundlerConfig, tailwindCSS)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return compileNativeCSS(bundlerConfig, tailwindCSS)
|
|
15
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { UniwindBundlerConfig } from '../config'
|
|
2
|
+
import { addMetaToStylesTemplate, ProcessorBuilder, serializeJSObject } from '../css-processor'
|
|
3
|
+
|
|
4
|
+
export const compileNativeCSS = (bundlerConfig: UniwindBundlerConfig, tailwindCSS: string) => {
|
|
5
|
+
const Processor = new ProcessorBuilder(bundlerConfig)
|
|
6
|
+
|
|
7
|
+
Processor.transform(tailwindCSS)
|
|
8
|
+
|
|
9
|
+
const stylesheet = serializeJSObject(
|
|
10
|
+
addMetaToStylesTemplate(Processor, bundlerConfig.platform),
|
|
11
|
+
(key, value) => `"${key}": ${value}`,
|
|
12
|
+
)
|
|
13
|
+
const vars = serializeJSObject(
|
|
14
|
+
Processor.vars,
|
|
15
|
+
(key, value) => `"${key}": vars => ${value}`,
|
|
16
|
+
)
|
|
17
|
+
const keyframes = serializeJSObject(
|
|
18
|
+
Processor.keyframes,
|
|
19
|
+
(key, value) => `get "${key}"() { return ${value} }`,
|
|
20
|
+
)
|
|
21
|
+
const scopedVars = Object.fromEntries(
|
|
22
|
+
Object.entries(Processor.scopedVars)
|
|
23
|
+
.map(([scopedVarsName, scopedVars]) => [
|
|
24
|
+
scopedVarsName,
|
|
25
|
+
serializeJSObject(scopedVars, (key, value) => `"${key}": vars => ${value}`),
|
|
26
|
+
]),
|
|
27
|
+
)
|
|
28
|
+
const serializedScopedVars = Object.entries(scopedVars)
|
|
29
|
+
.map(([scopedVarsName, scopedVars]) => `"${scopedVarsName}": ({ ${scopedVars} }),`)
|
|
30
|
+
.join('')
|
|
31
|
+
const currentColorVar = `currentColor: () => rt.colorScheme === 'dark' ? '#ffffff' : '#000000',`
|
|
32
|
+
|
|
33
|
+
return [
|
|
34
|
+
'({',
|
|
35
|
+
`scopedVars: ({ ${serializedScopedVars} }),`,
|
|
36
|
+
`vars: ({ ${currentColorVar} ${vars} }),`,
|
|
37
|
+
`stylesheet: ({ ${stylesheet} }),`,
|
|
38
|
+
`keyframes: ({ ${keyframes} }),`,
|
|
39
|
+
'})',
|
|
40
|
+
].join('')
|
|
41
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { compile } from '@tailwindcss/node'
|
|
2
|
+
import { Scanner } from '@tailwindcss/oxide'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import type { UniwindBundlerConfig } from '../config'
|
|
6
|
+
|
|
7
|
+
export const compileTailwind = async (bundlerConfig: UniwindBundlerConfig) => {
|
|
8
|
+
const css = await fs.promises.readFile(bundlerConfig.cssPath, 'utf-8')
|
|
9
|
+
const compiler = await compile(css, {
|
|
10
|
+
base: path.dirname(bundlerConfig.cssPath),
|
|
11
|
+
onDependency: () => void 0,
|
|
12
|
+
})
|
|
13
|
+
const scanner = new Scanner({
|
|
14
|
+
sources: [
|
|
15
|
+
...compiler.sources,
|
|
16
|
+
{
|
|
17
|
+
negated: false,
|
|
18
|
+
pattern: '**/*',
|
|
19
|
+
base: path.dirname(bundlerConfig.cssPath),
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
return compiler.build(scanner.scan())
|
|
25
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { transform } from 'lightningcss'
|
|
2
|
+
import type { UniwindBundlerConfig } from '../config'
|
|
3
|
+
|
|
4
|
+
export const compileWebCSS = (bundlerConfig: UniwindBundlerConfig, tailwindCSS: string) => {
|
|
5
|
+
return transform({
|
|
6
|
+
code: Buffer.from(tailwindCSS),
|
|
7
|
+
filename: 'uniwind.css',
|
|
8
|
+
visitor: bundlerConfig.cssVisitor,
|
|
9
|
+
}).code.toString()
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './compileCSS'
|