@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,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { UniwindBundlerConfig } from "@/bundler/config";
|
|
3
|
+
import { Logger } from "@/bundler/logger";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import path from "path";
|
|
6
|
+
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const cssArtifactPath = path.resolve(dirname, "../../uniwind.css");
|
|
8
|
+
const printHelp = () => {
|
|
9
|
+
console.log([
|
|
10
|
+
"Usage: uniwind generate-artifacts --css <file> [--theme <name>...] [--dts <file>]",
|
|
11
|
+
"",
|
|
12
|
+
"Options:",
|
|
13
|
+
" --css <file> CSS entry file path, e.g. ./global.css",
|
|
14
|
+
" --theme <name> Extra theme name. Can be passed multiple times",
|
|
15
|
+
" --dts <file> Generated TypeScript declarations path",
|
|
16
|
+
" --help Show help"
|
|
17
|
+
].join("\n"));
|
|
18
|
+
};
|
|
19
|
+
const readValue = (args, index, flag) => {
|
|
20
|
+
const value = args[index + 1];
|
|
21
|
+
if (value === void 0 || value.startsWith("--")) {
|
|
22
|
+
throw new Error(`Uniwind: ${flag} requires a value`);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
const parseGenerateArtifactsArgs = (args) => {
|
|
27
|
+
const parsed = {
|
|
28
|
+
extraThemes: []
|
|
29
|
+
};
|
|
30
|
+
for (let index = 0; index < args.length; index++) {
|
|
31
|
+
const arg = args[index];
|
|
32
|
+
switch (arg) {
|
|
33
|
+
case "--css":
|
|
34
|
+
parsed.cssEntryFile = readValue(args, index, arg);
|
|
35
|
+
index++;
|
|
36
|
+
break;
|
|
37
|
+
case "--theme":
|
|
38
|
+
parsed.extraThemes.push(readValue(args, index, arg));
|
|
39
|
+
index++;
|
|
40
|
+
break;
|
|
41
|
+
case "--dts":
|
|
42
|
+
parsed.dtsFile = readValue(args, index, arg);
|
|
43
|
+
index++;
|
|
44
|
+
break;
|
|
45
|
+
case "--help":
|
|
46
|
+
printHelp();
|
|
47
|
+
process.exit(0);
|
|
48
|
+
default:
|
|
49
|
+
throw new Error(`Uniwind: Unknown option ${arg}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return parsed;
|
|
53
|
+
};
|
|
54
|
+
const generateArtifacts = async (args) => {
|
|
55
|
+
const parsed = parseGenerateArtifactsArgs(args);
|
|
56
|
+
const bundlerConfig = UniwindBundlerConfig.fromCliConfig({
|
|
57
|
+
cssEntryFile: parsed.cssEntryFile,
|
|
58
|
+
dtsFile: parsed.dtsFile,
|
|
59
|
+
extraThemes: parsed.extraThemes
|
|
60
|
+
});
|
|
61
|
+
await bundlerConfig.generateArtifacts(cssArtifactPath);
|
|
62
|
+
Logger.info("Artifacts generated");
|
|
63
|
+
};
|
|
64
|
+
const main = async () => {
|
|
65
|
+
const [command, ...args] = process.argv.slice(2);
|
|
66
|
+
if (command === "--help" || command === void 0) {
|
|
67
|
+
printHelp();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
switch (command) {
|
|
71
|
+
case "generate-artifacts":
|
|
72
|
+
await generateArtifacts(args);
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
throw new Error(`Uniwind: Unknown command ${command}`);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
main().catch((error) => {
|
|
79
|
+
console.error(error instanceof Error ? error.message : error);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { UniwindConfig, UniwindMetroConfig } from '@/bundler/types';
|
|
2
|
+
import { Platform } from '@/common/consts';
|
|
3
|
+
export declare class UniwindBundlerConfig {
|
|
4
|
+
private readonly config;
|
|
5
|
+
readonly platform: Platform;
|
|
6
|
+
static fromMetroConfig(config: UniwindMetroConfig, platform?: string | null): UniwindBundlerConfig;
|
|
7
|
+
static fromViteConfig(config: UniwindConfig): UniwindBundlerConfig;
|
|
8
|
+
static fromCliConfig(config: UniwindConfig): UniwindBundlerConfig;
|
|
9
|
+
constructor(config: UniwindMetroConfig, platform: Platform);
|
|
10
|
+
get cssPath(): any;
|
|
11
|
+
get themes(): any[];
|
|
12
|
+
get cssVisitor(): any;
|
|
13
|
+
get polyfills(): any;
|
|
14
|
+
get stringifiedThemes(): string;
|
|
15
|
+
toMetroConfig(): UniwindMetroConfig;
|
|
16
|
+
generateArtifacts(cssArtifactPath: string): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { buildCSS } from "@/bundler/artifacts/css";
|
|
2
|
+
import { buildDtsFile } from "@/bundler/artifacts/dts";
|
|
3
|
+
import { UniwindCSSVisitor } from "@/bundler/css-visitor";
|
|
4
|
+
import { Platform } from "@/common/consts";
|
|
5
|
+
import { isDefined } from "@/common/utils";
|
|
6
|
+
import path from "path";
|
|
7
|
+
export class UniwindBundlerConfig {
|
|
8
|
+
constructor(config, platform) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.platform = platform;
|
|
11
|
+
}
|
|
12
|
+
static fromMetroConfig(config, platform) {
|
|
13
|
+
const getPlatform = () => {
|
|
14
|
+
if (!isDefined(platform)) {
|
|
15
|
+
return Platform.Native;
|
|
16
|
+
}
|
|
17
|
+
if (!config.isTV) {
|
|
18
|
+
return platform;
|
|
19
|
+
}
|
|
20
|
+
if (platform === Platform.Android) {
|
|
21
|
+
return Platform.AndroidTV;
|
|
22
|
+
}
|
|
23
|
+
if (platform === Platform.iOS) {
|
|
24
|
+
return Platform.AppleTV;
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`Platform ${platform} not supported`);
|
|
27
|
+
};
|
|
28
|
+
if (typeof config === "undefined") {
|
|
29
|
+
throw new Error("Uniwind: You need to pass second parameter to withUniwindConfig");
|
|
30
|
+
}
|
|
31
|
+
if (typeof config.cssEntryFile === "undefined") {
|
|
32
|
+
throw new Error(
|
|
33
|
+
'Uniwind: You need to pass css css entry file to withUniwindConfig, e.g. withUniwindConfig(config, { cssEntryFile: "./global.css" })'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return new UniwindBundlerConfig(config, getPlatform());
|
|
37
|
+
}
|
|
38
|
+
static fromViteConfig(config) {
|
|
39
|
+
return new UniwindBundlerConfig(config, Platform.Web);
|
|
40
|
+
}
|
|
41
|
+
static fromCliConfig(config) {
|
|
42
|
+
if (typeof config.cssEntryFile === "undefined") {
|
|
43
|
+
throw new Error(
|
|
44
|
+
"Uniwind: You need to pass css entry file, e.g. uniwind generate-artifacts --css ./global.css. Run uniwind generate-artifacts --help for usage."
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return new UniwindBundlerConfig(config, Platform.Web);
|
|
48
|
+
}
|
|
49
|
+
get cssPath() {
|
|
50
|
+
return path.join(process.cwd(), this.config.cssEntryFile);
|
|
51
|
+
}
|
|
52
|
+
get themes() {
|
|
53
|
+
return Array.from(
|
|
54
|
+
/* @__PURE__ */ new Set([
|
|
55
|
+
"light",
|
|
56
|
+
"dark",
|
|
57
|
+
...this.config.extraThemes ?? []
|
|
58
|
+
])
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
get cssVisitor() {
|
|
62
|
+
return new UniwindCSSVisitor(this);
|
|
63
|
+
}
|
|
64
|
+
get polyfills() {
|
|
65
|
+
return this.config.polyfills;
|
|
66
|
+
}
|
|
67
|
+
get stringifiedThemes() {
|
|
68
|
+
return `[${this.themes.map((theme) => `'${theme}'`).join(", ")}]`;
|
|
69
|
+
}
|
|
70
|
+
toMetroConfig() {
|
|
71
|
+
return this.config;
|
|
72
|
+
}
|
|
73
|
+
async generateArtifacts(cssArtifactPath) {
|
|
74
|
+
await buildCSS(this.themes, this.config.cssEntryFile, cssArtifactPath);
|
|
75
|
+
buildDtsFile(this.config.dtsFile ?? "uniwind-types.d.ts", this.stringifiedThemes);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Platform } from "@/common/consts";
|
|
2
|
+
import { compileNativeCSS } from "./compileNativeCSS.js";
|
|
3
|
+
import { compileTailwind } from "./compileTailwind.js";
|
|
4
|
+
import { compileWebCSS } from "./compileWebCSS.js";
|
|
5
|
+
export const compileCSS = async (bundlerConfig) => {
|
|
6
|
+
const tailwindCSS = await compileTailwind(bundlerConfig);
|
|
7
|
+
if (bundlerConfig.platform === Platform.Web) {
|
|
8
|
+
return compileWebCSS(bundlerConfig, tailwindCSS);
|
|
9
|
+
}
|
|
10
|
+
return compileNativeCSS(bundlerConfig, tailwindCSS);
|
|
11
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { addMetaToStylesTemplate, ProcessorBuilder, serializeJSObject } from "../css-processor/index.js";
|
|
2
|
+
export const compileNativeCSS = (bundlerConfig, tailwindCSS) => {
|
|
3
|
+
const Processor = new ProcessorBuilder(bundlerConfig);
|
|
4
|
+
Processor.transform(tailwindCSS);
|
|
5
|
+
const stylesheet = serializeJSObject(
|
|
6
|
+
addMetaToStylesTemplate(Processor, bundlerConfig.platform),
|
|
7
|
+
(key, value) => `"${key}": ${value}`
|
|
8
|
+
);
|
|
9
|
+
const vars = serializeJSObject(
|
|
10
|
+
Processor.vars,
|
|
11
|
+
(key, value) => `"${key}": vars => ${value}`
|
|
12
|
+
);
|
|
13
|
+
const keyframes = serializeJSObject(
|
|
14
|
+
Processor.keyframes,
|
|
15
|
+
(key, value) => `get "${key}"() { return ${value} }`
|
|
16
|
+
);
|
|
17
|
+
const scopedVars = Object.fromEntries(
|
|
18
|
+
Object.entries(Processor.scopedVars).map(([scopedVarsName, scopedVars2]) => [
|
|
19
|
+
scopedVarsName,
|
|
20
|
+
serializeJSObject(scopedVars2, (key, value) => `"${key}": vars => ${value}`)
|
|
21
|
+
])
|
|
22
|
+
);
|
|
23
|
+
const serializedScopedVars = Object.entries(scopedVars).map(([scopedVarsName, scopedVars2]) => `"${scopedVarsName}": ({ ${scopedVars2} }),`).join("");
|
|
24
|
+
const currentColorVar = `currentColor: () => rt.colorScheme === 'dark' ? '#ffffff' : '#000000',`;
|
|
25
|
+
return [
|
|
26
|
+
"({",
|
|
27
|
+
`scopedVars: ({ ${serializedScopedVars} }),`,
|
|
28
|
+
`vars: ({ ${currentColorVar} ${vars} }),`,
|
|
29
|
+
`stylesheet: ({ ${stylesheet} }),`,
|
|
30
|
+
`keyframes: ({ ${keyframes} }),`,
|
|
31
|
+
"})"
|
|
32
|
+
].join("");
|
|
33
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { compile } from "@tailwindcss/node";
|
|
2
|
+
import { Scanner } from "@tailwindcss/oxide";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
export const compileTailwind = async (bundlerConfig) => {
|
|
6
|
+
const css = await fs.promises.readFile(bundlerConfig.cssPath, "utf-8");
|
|
7
|
+
const compiler = await compile(css, {
|
|
8
|
+
base: path.dirname(bundlerConfig.cssPath),
|
|
9
|
+
onDependency: () => void 0
|
|
10
|
+
});
|
|
11
|
+
const scanner = new Scanner({
|
|
12
|
+
sources: [
|
|
13
|
+
...compiler.sources,
|
|
14
|
+
{
|
|
15
|
+
negated: false,
|
|
16
|
+
pattern: "**/*",
|
|
17
|
+
base: path.dirname(bundlerConfig.cssPath)
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
});
|
|
21
|
+
return compiler.build(scanner.scan());
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './compileCSS';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./compileCSS.js";
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Platform, StyleDependency } from "@/common/consts";
|
|
2
|
+
import { isDefined } from "@/common/utils";
|
|
3
|
+
import { serialize } from "./serialize.js";
|
|
4
|
+
import { toCamelCase } from "./utils.js";
|
|
5
|
+
const extractVarsFromString = (value) => {
|
|
6
|
+
const varsIndexes = [...value.matchAll(/vars\[/g)].map((m) => m.index);
|
|
7
|
+
return varsIndexes.map((index) => {
|
|
8
|
+
const afterIndex = value.slice(index + 5);
|
|
9
|
+
const closingIndex = afterIndex.indexOf("]");
|
|
10
|
+
const varName = afterIndex.slice(0, closingIndex);
|
|
11
|
+
return varName.replace(/[`"\\]/g, "");
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
const makeSafeForSerialization = (value) => {
|
|
15
|
+
if (value === null) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
if (typeof value === "string") {
|
|
19
|
+
return `"${value}"`;
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
const hasThemedVarDependency = (varName, Processor, visited = /* @__PURE__ */ new Set()) => {
|
|
24
|
+
if (visited.has(varName)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
visited.add(varName);
|
|
28
|
+
const isScopedVar = Object.values(Processor.scopedVars).some((scopedVars) => varName in scopedVars);
|
|
29
|
+
if (isScopedVar) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
const globalVarValue = Processor.vars[varName];
|
|
33
|
+
if (typeof globalVarValue !== "string") {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return extractVarsFromString(globalVarValue).some((usedVarName) => {
|
|
37
|
+
return hasThemedVarDependency(usedVarName, Processor, visited);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
export const addMetaToStylesTemplate = (Processor, currentPlatform) => {
|
|
41
|
+
const stylesheetsEntries = Object.entries(Processor.stylesheets).map(([className, stylesPerMediaQuery]) => {
|
|
42
|
+
const styles = stylesPerMediaQuery.map((style, index) => {
|
|
43
|
+
const {
|
|
44
|
+
platform,
|
|
45
|
+
rtl,
|
|
46
|
+
theme,
|
|
47
|
+
orientation,
|
|
48
|
+
minWidth,
|
|
49
|
+
maxWidth,
|
|
50
|
+
colorScheme,
|
|
51
|
+
important: _,
|
|
52
|
+
importantProperties,
|
|
53
|
+
active,
|
|
54
|
+
focus,
|
|
55
|
+
disabled,
|
|
56
|
+
dataAttributes,
|
|
57
|
+
...rest
|
|
58
|
+
} = style;
|
|
59
|
+
const entries = Object.entries(rest).flatMap(([property, value]) => Processor.RN.cssToRN(property, value)).map(([property, value]) => [`"${property}"`, `function(vars) { return ${serialize(value)} }`]);
|
|
60
|
+
if (platform) {
|
|
61
|
+
const isTV = currentPlatform === Platform.AndroidTV || currentPlatform === Platform.AppleTV;
|
|
62
|
+
const commonPlatform = isTV ? Platform.TV : Platform.Native;
|
|
63
|
+
if (platform !== commonPlatform && platform !== currentPlatform) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (entries.length === 0) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const dependencies = [];
|
|
71
|
+
const stringifiedEntries = JSON.stringify(entries);
|
|
72
|
+
const usedVars = extractVarsFromString(stringifiedEntries);
|
|
73
|
+
const isUsingThemedVar = usedVars.some((usedVarName) => hasThemedVarDependency(usedVarName, Processor));
|
|
74
|
+
if (usedVars.length > 0) {
|
|
75
|
+
dependencies.push(StyleDependency.Variables);
|
|
76
|
+
}
|
|
77
|
+
if (theme !== null || isUsingThemedVar || stringifiedEntries.includes("rt.lightDark")) {
|
|
78
|
+
dependencies.push(StyleDependency.Theme);
|
|
79
|
+
}
|
|
80
|
+
if (orientation !== null) {
|
|
81
|
+
dependencies.push(StyleDependency.Orientation);
|
|
82
|
+
}
|
|
83
|
+
if (rtl !== null) {
|
|
84
|
+
dependencies.push(StyleDependency.Rtl);
|
|
85
|
+
}
|
|
86
|
+
if (Number(minWidth) !== 0 || Number(maxWidth) !== Number.MAX_VALUE || stringifiedEntries.includes("rt.makeResponsive") || stringifiedEntries.includes("rt.screen")) {
|
|
87
|
+
dependencies.push(StyleDependency.Dimensions);
|
|
88
|
+
}
|
|
89
|
+
if (stringifiedEntries.includes("rt.insets")) {
|
|
90
|
+
dependencies.push(StyleDependency.Insets);
|
|
91
|
+
}
|
|
92
|
+
if (stringifiedEntries.includes("rt.fontScale")) {
|
|
93
|
+
dependencies.push(StyleDependency.FontScale);
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
entries,
|
|
97
|
+
minWidth,
|
|
98
|
+
maxWidth,
|
|
99
|
+
theme: makeSafeForSerialization(theme),
|
|
100
|
+
orientation: makeSafeForSerialization(orientation),
|
|
101
|
+
rtl,
|
|
102
|
+
colorScheme: makeSafeForSerialization(colorScheme),
|
|
103
|
+
native: platform !== null,
|
|
104
|
+
dependencies: dependencies.length > 0 ? dependencies : null,
|
|
105
|
+
index,
|
|
106
|
+
className: makeSafeForSerialization(className),
|
|
107
|
+
active,
|
|
108
|
+
focus,
|
|
109
|
+
disabled,
|
|
110
|
+
importantProperties: importantProperties?.map((property) => property.startsWith("--") ? property : toCamelCase(property)).map(makeSafeForSerialization) ?? [],
|
|
111
|
+
dataAttributes,
|
|
112
|
+
complexity: [
|
|
113
|
+
minWidth !== 0,
|
|
114
|
+
theme !== null,
|
|
115
|
+
orientation !== null,
|
|
116
|
+
rtl !== null,
|
|
117
|
+
platform !== null,
|
|
118
|
+
active !== null,
|
|
119
|
+
focus !== null,
|
|
120
|
+
disabled !== null,
|
|
121
|
+
dataAttributes !== null
|
|
122
|
+
].filter(Boolean).length
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
const filteredStyles = styles.filter(isDefined);
|
|
126
|
+
if (filteredStyles.length === 0) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
return [
|
|
130
|
+
className,
|
|
131
|
+
filteredStyles
|
|
132
|
+
];
|
|
133
|
+
}).filter(isDefined);
|
|
134
|
+
const stylesheets = Object.fromEntries(stylesheetsEntries);
|
|
135
|
+
return stylesheets;
|
|
136
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TokenOrValue } from 'lightningcss';
|
|
2
|
+
import type { DeclarationValues } from './types';
|
|
3
|
+
type GetProcessedValue = (value: DeclarationValues) => any;
|
|
4
|
+
export declare const getProcessedVarAnimation: (declarationValue: string, styles: Record<string, any>, updateVar: (value: string) => void) => void;
|
|
5
|
+
export declare const getProcessedAnimation: (declarationValue: Array<TokenOrValue>, getProcessedValue: GetProcessedValue) => any;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { toCamelCase } from "./utils.js";
|
|
2
|
+
const STATIC_TIMING_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
3
|
+
"linear",
|
|
4
|
+
"ease",
|
|
5
|
+
"ease-in",
|
|
6
|
+
"ease-out",
|
|
7
|
+
"ease-in-out",
|
|
8
|
+
"step-start",
|
|
9
|
+
"step-end"
|
|
10
|
+
]);
|
|
11
|
+
const DIRECTION_VALUES = /* @__PURE__ */ new Set(["normal", "reverse", "alternate", "alternate-reverse"]);
|
|
12
|
+
const FILL_MODE_VALUES = /* @__PURE__ */ new Set(["none", "forwards", "backwards", "both"]);
|
|
13
|
+
const PLAY_STATE_VALUES = /* @__PURE__ */ new Set(["running", "paused"]);
|
|
14
|
+
const isTimeString = (x) => {
|
|
15
|
+
if (typeof x === "number") return true;
|
|
16
|
+
return typeof x === "string" && /^-?\d*(?:\.\d+)?(?:e[+-]?\d+)?(ms|s)$/.test(x.trim());
|
|
17
|
+
};
|
|
18
|
+
const isTimingFunctionCustom = (x) => {
|
|
19
|
+
if (typeof x !== "string") return false;
|
|
20
|
+
return x.startsWith("rt.cubicBezier(") || x.startsWith("rt.steps(") || x.startsWith("rt.linear(");
|
|
21
|
+
};
|
|
22
|
+
export const getProcessedVarAnimation = (declarationValue, styles, updateVar) => {
|
|
23
|
+
const tokens = declarationValue.replace(/\)/g, ") ").split(" ");
|
|
24
|
+
let duration = false;
|
|
25
|
+
for (const unprocessedToken of tokens) {
|
|
26
|
+
const token = unprocessedToken.replace(/^"|"$/g, "");
|
|
27
|
+
if (isTimeString(token) && !duration) {
|
|
28
|
+
styles["animation-duration"] = unprocessedToken;
|
|
29
|
+
duration = true;
|
|
30
|
+
} else if (isTimeString(token) && duration) {
|
|
31
|
+
styles["animation-delay"] = unprocessedToken;
|
|
32
|
+
} else if (STATIC_TIMING_FUNCTIONS.has(token)) {
|
|
33
|
+
styles["animation-timing-function"] = unprocessedToken;
|
|
34
|
+
} else if (isTimingFunctionCustom(token)) {
|
|
35
|
+
styles["animation-timing-function"] = unprocessedToken;
|
|
36
|
+
} else if (token === "infinite" || /^\d+$/.test(token)) {
|
|
37
|
+
styles["animation-iteration-count"] = unprocessedToken;
|
|
38
|
+
} else if (DIRECTION_VALUES.has(token)) {
|
|
39
|
+
styles["animation-direction"] = unprocessedToken;
|
|
40
|
+
} else if (FILL_MODE_VALUES.has(token)) {
|
|
41
|
+
styles["animation-fill-mode"] = unprocessedToken;
|
|
42
|
+
} else if (PLAY_STATE_VALUES.has(token)) {
|
|
43
|
+
styles["animation-play-state"] = unprocessedToken;
|
|
44
|
+
} else {
|
|
45
|
+
updateVar(`"${token}"`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const parseValues = (tokens, getProcessedValue) => {
|
|
50
|
+
const groups = [];
|
|
51
|
+
let group = [];
|
|
52
|
+
for (const token of tokens) {
|
|
53
|
+
if (token.type === "token" && token.value.type === "delim" && token.value.value === "|") {
|
|
54
|
+
if (group.length > 0) {
|
|
55
|
+
groups.push(group);
|
|
56
|
+
group = [];
|
|
57
|
+
}
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
group.push(token);
|
|
61
|
+
}
|
|
62
|
+
if (group.length > 0) {
|
|
63
|
+
groups.push(group);
|
|
64
|
+
}
|
|
65
|
+
const values = groups.map((groupTokens) => tokensToText(groupTokens, getProcessedValue));
|
|
66
|
+
return values.length > 1 ? values : values[0];
|
|
67
|
+
};
|
|
68
|
+
const tokensToText = (tokens, getProcessedValue) => {
|
|
69
|
+
return tokens.map((token) => {
|
|
70
|
+
const value = getProcessedValue(token);
|
|
71
|
+
if (typeof value === "string") {
|
|
72
|
+
return /^"[^"]+"$/.test(value) ? value : `"${value}"`;
|
|
73
|
+
}
|
|
74
|
+
return value;
|
|
75
|
+
}).join(" ").trim();
|
|
76
|
+
};
|
|
77
|
+
export const getProcessedAnimation = (declarationValue, getProcessedValue) => {
|
|
78
|
+
const segments = [];
|
|
79
|
+
const result = [];
|
|
80
|
+
let current = [];
|
|
81
|
+
for (const token of declarationValue) {
|
|
82
|
+
if (token.type === "var") {
|
|
83
|
+
return getProcessedValue(token);
|
|
84
|
+
}
|
|
85
|
+
if (token.type === "token" && token.value.type === "comma") {
|
|
86
|
+
if (current.length > 0) {
|
|
87
|
+
segments.push(current);
|
|
88
|
+
current = [];
|
|
89
|
+
}
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
current.push(token);
|
|
93
|
+
}
|
|
94
|
+
if (current.length > 0) {
|
|
95
|
+
segments.push(current);
|
|
96
|
+
}
|
|
97
|
+
for (const segment of segments) {
|
|
98
|
+
const colonIndex = segment.findIndex((token) => token.type === "token" && token.value.type === "colon");
|
|
99
|
+
if (colonIndex === -1) {
|
|
100
|
+
const nameValue = parseValues(segment, getProcessedValue);
|
|
101
|
+
result.push(["name", Array.isArray(nameValue) ? nameValue : [nameValue]]);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const keyTokens = segment.slice(0, colonIndex);
|
|
105
|
+
const valueTokens = segment.slice(colonIndex + 1);
|
|
106
|
+
const rawKey = tokensToText(keyTokens, getProcessedValue);
|
|
107
|
+
const value = parseValues(valueTokens, getProcessedValue);
|
|
108
|
+
const key = toCamelCase(rawKey);
|
|
109
|
+
result.push([key, value]);
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CssColor, UnresolvedColor } from 'lightningcss';
|
|
2
|
+
import type { ProcessorBuilder } from './processor';
|
|
3
|
+
export declare class Color {
|
|
4
|
+
private readonly Processor;
|
|
5
|
+
private toRgb;
|
|
6
|
+
private readonly black;
|
|
7
|
+
private readonly logger;
|
|
8
|
+
constructor(Processor: ProcessorBuilder);
|
|
9
|
+
processColor(color: CssColor | UnresolvedColor): string;
|
|
10
|
+
isColor(value: unknown): value is CssColor;
|
|
11
|
+
private format;
|
|
12
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { converter, formatHex, formatHex8, parse } from "culori";
|
|
2
|
+
import { Logger } from "../logger.js";
|
|
3
|
+
import { pipe } from "./utils.js";
|
|
4
|
+
export class Color {
|
|
5
|
+
constructor(Processor) {
|
|
6
|
+
this.Processor = Processor;
|
|
7
|
+
}
|
|
8
|
+
toRgb = converter("rgb");
|
|
9
|
+
black = "#000000";
|
|
10
|
+
logger = new Logger("Color");
|
|
11
|
+
processColor(color) {
|
|
12
|
+
if (typeof color === "string") {
|
|
13
|
+
const parsed = parse(color);
|
|
14
|
+
if (parsed === void 0) {
|
|
15
|
+
const colorFunction = color.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/)?.[1];
|
|
16
|
+
if (colorFunction === void 0) {
|
|
17
|
+
this.logger.error(`Failed to convert color ${color}`);
|
|
18
|
+
return this.black;
|
|
19
|
+
}
|
|
20
|
+
const colorValue = color.replace(colorFunction, "").slice(1, -1);
|
|
21
|
+
return `rt.parseColor("${colorFunction}", ${colorValue})`;
|
|
22
|
+
}
|
|
23
|
+
return this.format(parsed);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
if (color.type === "currentcolor") {
|
|
27
|
+
return 'vars["currentColor"]?.(vars)';
|
|
28
|
+
}
|
|
29
|
+
if (color.type === "rgb" || color.type === "srgb") {
|
|
30
|
+
const alpha = typeof color.alpha === "number" ? color.alpha : pipe(color.alpha)(
|
|
31
|
+
(x) => this.Processor.CSS.processValue(x),
|
|
32
|
+
Number,
|
|
33
|
+
(x) => isNaN(x) ? 1 : x
|
|
34
|
+
);
|
|
35
|
+
return this.format({
|
|
36
|
+
r: color.r / 255,
|
|
37
|
+
g: color.g / 255,
|
|
38
|
+
b: color.b / 255,
|
|
39
|
+
alpha,
|
|
40
|
+
mode: "rgb"
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const colorType = color.type === "display-p3" ? "p3" : color.type;
|
|
44
|
+
const result = this.toRgb({
|
|
45
|
+
mode: colorType,
|
|
46
|
+
...color
|
|
47
|
+
});
|
|
48
|
+
return this.format(result);
|
|
49
|
+
} catch {
|
|
50
|
+
this.logger.error(`Failed to convert color ${JSON.stringify(color)}`);
|
|
51
|
+
return this.black;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
isColor(value) {
|
|
55
|
+
return typeof value === "string" && parse(value) !== void 0;
|
|
56
|
+
}
|
|
57
|
+
format(color) {
|
|
58
|
+
if (color.alpha === 1 || color.alpha === void 0) {
|
|
59
|
+
return formatHex(color);
|
|
60
|
+
}
|
|
61
|
+
return formatHex8(color);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Animation, TokenOrValue } from 'lightningcss';
|
|
2
|
+
import type { ProcessorBuilder } from './processor';
|
|
3
|
+
import type { DeclarationProperty, DeclarationValues } from './types';
|
|
4
|
+
export declare class CSS {
|
|
5
|
+
private readonly Processor;
|
|
6
|
+
private readonly logger;
|
|
7
|
+
constructor(Processor: ProcessorBuilder);
|
|
8
|
+
processValue(declarationValue: DeclarationValues, declarationProperty?: DeclarationProperty): any;
|
|
9
|
+
processAnimation(declarationValue: Array<TokenOrValue | Animation>): any;
|
|
10
|
+
processAnimationVar(declarationValue: string, styles: Record<string, string>, updateVar: (value: string) => void): void;
|
|
11
|
+
private processFilters;
|
|
12
|
+
private getProcessedValue;
|
|
13
|
+
private static readonly TRANSFORM_TYPES;
|
|
14
|
+
private isTransformArray;
|
|
15
|
+
private isOverflow;
|
|
16
|
+
/**
|
|
17
|
+
* Between some tokens there isn't a comma but it should be.
|
|
18
|
+
* For example this applies to Array of shadows
|
|
19
|
+
*/
|
|
20
|
+
private addComaBetweenTokens;
|
|
21
|
+
private logUnsupported;
|
|
22
|
+
private makeSafeForSerialization;
|
|
23
|
+
}
|