@niibase/uniwind 1.0.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/LICENSE +20 -0
- package/dist/common/components/index.js +314 -0
- package/dist/common/components/native/ActivityIndicator.js +21 -0
- package/dist/common/components/native/Button.js +18 -0
- package/dist/common/components/native/FlatList.js +30 -0
- package/dist/common/components/native/Image.js +21 -0
- package/dist/common/components/native/ImageBackground.js +23 -0
- package/dist/common/components/native/InputAccessoryView.js +21 -0
- package/dist/common/components/native/KeyboardAvoidingView.js +20 -0
- package/dist/common/components/native/Modal.js +21 -0
- package/dist/common/components/native/Pressable.js +29 -0
- package/dist/common/components/native/RefreshControl.js +27 -0
- package/dist/common/components/native/SafeAreaView.js +18 -0
- package/dist/common/components/native/ScrollView.js +23 -0
- package/dist/common/components/native/SectionList.js +27 -0
- package/dist/common/components/native/Switch.js +32 -0
- package/dist/common/components/native/Text.js +36 -0
- package/dist/common/components/native/TextInput.js +53 -0
- package/dist/common/components/native/TouchableHighlight.js +35 -0
- package/dist/common/components/native/TouchableNativeFeedback.js +32 -0
- package/dist/common/components/native/TouchableOpacity.js +32 -0
- package/dist/common/components/native/TouchableWithoutFeedback.js +32 -0
- package/dist/common/components/native/View.js +18 -0
- package/dist/common/components/native/VirtualizedList.js +27 -0
- package/dist/common/components/native/useStyle.js +29 -0
- package/dist/common/components/utils.js +18 -0
- package/dist/common/components/web/ActivityIndicator.js +20 -0
- package/dist/common/components/web/Button.js +18 -0
- package/dist/common/components/web/FlatList.js +22 -0
- package/dist/common/components/web/Image.js +20 -0
- package/dist/common/components/web/ImageBackground.js +21 -0
- package/dist/common/components/web/KeyboardAvoidingView.js +18 -0
- package/dist/common/components/web/Modal.js +17 -0
- package/dist/common/components/web/Pressable.js +17 -0
- package/dist/common/components/web/RefreshControl.js +17 -0
- package/dist/common/components/web/SafeAreaView.js +17 -0
- package/dist/common/components/web/ScrollView.js +18 -0
- package/dist/common/components/web/SectionList.js +20 -0
- package/dist/common/components/web/Switch.js +26 -0
- package/dist/common/components/web/Text.js +17 -0
- package/dist/common/components/web/TextInput.js +17 -0
- package/dist/common/components/web/TouchableHighlight.js +20 -0
- package/dist/common/components/web/TouchableNativeFeedback.js +13 -0
- package/dist/common/components/web/TouchableOpacity.js +17 -0
- package/dist/common/components/web/TouchableWithoutFeedback.js +17 -0
- package/dist/common/components/web/View.js +17 -0
- package/dist/common/components/web/VirtualizedList.js +20 -0
- package/dist/common/components/web/index.js +187 -0
- package/dist/common/components/web/metro-injected.js +1 -0
- package/dist/common/components/web/rnw.js +42 -0
- package/dist/common/core/config/config.common.js +80 -0
- package/dist/common/core/config/config.js +51 -0
- package/dist/common/core/config/config.native.js +67 -0
- package/dist/common/core/config/index.js +16 -0
- package/dist/common/core/index.js +16 -0
- package/dist/common/core/listener.js +51 -0
- package/dist/common/core/logger.js +18 -0
- package/dist/common/core/native/index.js +27 -0
- package/dist/common/core/native/native-utils.js +36 -0
- package/dist/common/core/native/parsers/boxShadow.js +10 -0
- package/dist/common/core/native/parsers/fontVariant.js +8 -0
- package/dist/common/core/native/parsers/gradient.js +31 -0
- package/dist/common/core/native/parsers/index.js +60 -0
- package/dist/common/core/native/parsers/textShadow.js +39 -0
- package/dist/common/core/native/parsers/transforms.js +44 -0
- package/dist/common/core/native/runtime.js +34 -0
- package/dist/common/core/native/store.js +181 -0
- package/dist/common/core/types.js +1 -0
- package/dist/common/core/web/cssListener.js +146 -0
- package/dist/common/core/web/formatColor.js +15 -0
- package/dist/common/core/web/getWebStyles.js +51 -0
- package/dist/common/core/web/index.js +49 -0
- package/dist/common/core/web/parseCSSValue.js +15 -0
- package/dist/common/css/index.js +26 -0
- package/dist/common/css/insets.js +64 -0
- package/dist/common/css/processFunctions.js +54 -0
- package/dist/common/css/themes.js +95 -0
- package/dist/common/css/variants.js +16 -0
- package/dist/common/hoc/index.js +16 -0
- package/dist/common/hoc/types.js +1 -0
- package/dist/common/hoc/withUniwind.js +95 -0
- package/dist/common/hoc/withUniwind.native.js +106 -0
- package/dist/common/hoc/withUniwindUtils.js +16 -0
- package/dist/common/hooks/index.js +49 -0
- package/dist/common/hooks/useCSSVariable/getVariableValue.js +19 -0
- package/dist/common/hooks/useCSSVariable/getVariableValue.native.js +9 -0
- package/dist/common/hooks/useCSSVariable/index.js +16 -0
- package/dist/common/hooks/useCSSVariable/useCSSVariable.js +58 -0
- package/dist/common/hooks/useResolveClassNames.js +22 -0
- package/dist/common/hooks/useResolveClassNames.native.js +29 -0
- package/dist/common/hooks/useUniwind.js +28 -0
- package/dist/common/hooks/useUniwindAccent.js +13 -0
- package/dist/common/hooks/useUniwindAccent.native.js +12 -0
- package/dist/common/index.js +38 -0
- package/dist/common/types.js +28 -0
- package/dist/common/utils/buildDtsFile.js +18 -0
- package/dist/common/utils/stringifyThemes.js +8 -0
- package/dist/common/vite/index.d.ts +9 -0
- package/dist/common/vite/index.js +16 -0
- package/dist/common/vite/vite.js +72 -0
- package/dist/metro/index.cjs +166 -0
- package/dist/metro/index.d.ts +15 -0
- package/dist/metro/index.mjs +158 -0
- package/dist/metro/metro-transformer.cjs +1565 -0
- package/dist/metro/metro-transformer.mjs +1558 -0
- package/dist/module/components/index.d.ts +0 -0
- package/dist/module/components/index.js +312 -0
- package/dist/module/components/native/ActivityIndicator.d.ts +3 -0
- package/dist/module/components/native/ActivityIndicator.js +18 -0
- package/dist/module/components/native/Button.d.ts +3 -0
- package/dist/module/components/native/Button.js +15 -0
- package/dist/module/components/native/FlatList.d.ts +3 -0
- package/dist/module/components/native/FlatList.js +27 -0
- package/dist/module/components/native/Image.d.ts +3 -0
- package/dist/module/components/native/Image.js +18 -0
- package/dist/module/components/native/ImageBackground.d.ts +3 -0
- package/dist/module/components/native/ImageBackground.js +20 -0
- package/dist/module/components/native/InputAccessoryView.d.ts +3 -0
- package/dist/module/components/native/InputAccessoryView.js +21 -0
- package/dist/module/components/native/KeyboardAvoidingView.d.ts +3 -0
- package/dist/module/components/native/KeyboardAvoidingView.js +17 -0
- package/dist/module/components/native/Modal.d.ts +3 -0
- package/dist/module/components/native/Modal.js +18 -0
- package/dist/module/components/native/Pressable.d.ts +3 -0
- package/dist/module/components/native/Pressable.js +29 -0
- package/dist/module/components/native/RefreshControl.d.ts +3 -0
- package/dist/module/components/native/RefreshControl.js +24 -0
- package/dist/module/components/native/SafeAreaView.d.ts +3 -0
- package/dist/module/components/native/SafeAreaView.js +15 -0
- package/dist/module/components/native/ScrollView.d.ts +3 -0
- package/dist/module/components/native/ScrollView.js +20 -0
- package/dist/module/components/native/SectionList.d.ts +3 -0
- package/dist/module/components/native/SectionList.js +24 -0
- package/dist/module/components/native/Switch.d.ts +3 -0
- package/dist/module/components/native/Switch.js +26 -0
- package/dist/module/components/native/Text.d.ts +3 -0
- package/dist/module/components/native/Text.js +33 -0
- package/dist/module/components/native/TextInput.d.ts +3 -0
- package/dist/module/components/native/TextInput.js +50 -0
- package/dist/module/components/native/TouchableHighlight.d.ts +3 -0
- package/dist/module/components/native/TouchableHighlight.js +32 -0
- package/dist/module/components/native/TouchableNativeFeedback.d.ts +3 -0
- package/dist/module/components/native/TouchableNativeFeedback.js +29 -0
- package/dist/module/components/native/TouchableOpacity.d.ts +3 -0
- package/dist/module/components/native/TouchableOpacity.js +29 -0
- package/dist/module/components/native/TouchableWithoutFeedback.d.ts +3 -0
- package/dist/module/components/native/TouchableWithoutFeedback.js +29 -0
- package/dist/module/components/native/View.d.ts +3 -0
- package/dist/module/components/native/View.js +15 -0
- package/dist/module/components/native/VirtualizedList.d.ts +3 -0
- package/dist/module/components/native/VirtualizedList.js +24 -0
- package/dist/module/components/native/useStyle.d.ts +2 -0
- package/dist/module/components/native/useStyle.js +22 -0
- package/dist/module/components/utils.d.ts +1 -0
- package/dist/module/components/utils.js +11 -0
- package/dist/module/components/web/ActivityIndicator.d.ts +3 -0
- package/dist/module/components/web/ActivityIndicator.js +17 -0
- package/dist/module/components/web/Button.d.ts +3 -0
- package/dist/module/components/web/Button.js +15 -0
- package/dist/module/components/web/FlatList.d.ts +3 -0
- package/dist/module/components/web/FlatList.js +19 -0
- package/dist/module/components/web/Image.d.ts +3 -0
- package/dist/module/components/web/Image.js +17 -0
- package/dist/module/components/web/ImageBackground.d.ts +3 -0
- package/dist/module/components/web/ImageBackground.js +18 -0
- package/dist/module/components/web/KeyboardAvoidingView.d.ts +3 -0
- package/dist/module/components/web/KeyboardAvoidingView.js +15 -0
- package/dist/module/components/web/Modal.d.ts +3 -0
- package/dist/module/components/web/Modal.js +14 -0
- package/dist/module/components/web/Pressable.d.ts +3 -0
- package/dist/module/components/web/Pressable.js +14 -0
- package/dist/module/components/web/RefreshControl.d.ts +3 -0
- package/dist/module/components/web/RefreshControl.js +14 -0
- package/dist/module/components/web/SafeAreaView.d.ts +3 -0
- package/dist/module/components/web/SafeAreaView.js +14 -0
- package/dist/module/components/web/ScrollView.d.ts +3 -0
- package/dist/module/components/web/ScrollView.js +15 -0
- package/dist/module/components/web/SectionList.d.ts +3 -0
- package/dist/module/components/web/SectionList.js +17 -0
- package/dist/module/components/web/Switch.d.ts +3 -0
- package/dist/module/components/web/Switch.js +20 -0
- package/dist/module/components/web/Text.d.ts +3 -0
- package/dist/module/components/web/Text.js +14 -0
- package/dist/module/components/web/TextInput.d.ts +3 -0
- package/dist/module/components/web/TextInput.js +14 -0
- package/dist/module/components/web/TouchableHighlight.d.ts +3 -0
- package/dist/module/components/web/TouchableHighlight.js +17 -0
- package/dist/module/components/web/TouchableNativeFeedback.d.ts +2 -0
- package/dist/module/components/web/TouchableNativeFeedback.js +2 -0
- package/dist/module/components/web/TouchableOpacity.d.ts +3 -0
- package/dist/module/components/web/TouchableOpacity.js +14 -0
- package/dist/module/components/web/TouchableWithoutFeedback.d.ts +3 -0
- package/dist/module/components/web/TouchableWithoutFeedback.js +14 -0
- package/dist/module/components/web/View.d.ts +3 -0
- package/dist/module/components/web/View.js +14 -0
- package/dist/module/components/web/VirtualizedList.d.ts +3 -0
- package/dist/module/components/web/VirtualizedList.js +17 -0
- package/dist/module/components/web/index.d.ts +22 -0
- package/dist/module/components/web/index.js +22 -0
- package/dist/module/components/web/metro-injected.d.ts +0 -0
- package/dist/module/components/web/metro-injected.js +0 -0
- package/dist/module/components/web/rnw.d.ts +2 -0
- package/dist/module/components/web/rnw.js +35 -0
- package/dist/module/core/config/config.common.d.ts +18 -0
- package/dist/module/core/config/config.common.js +74 -0
- package/dist/module/core/config/config.d.ts +11 -0
- package/dist/module/core/config/config.js +48 -0
- package/dist/module/core/config/config.native.d.ts +12 -0
- package/dist/module/core/config/config.native.js +61 -0
- package/dist/module/core/config/index.d.ts +1 -0
- package/dist/module/core/config/index.js +1 -0
- package/dist/module/core/index.d.ts +1 -0
- package/dist/module/core/index.js +1 -0
- package/dist/module/core/listener.d.ts +12 -0
- package/dist/module/core/listener.js +45 -0
- package/dist/module/core/logger.d.ts +5 -0
- package/dist/module/core/logger.js +11 -0
- package/dist/module/core/native/index.d.ts +2 -0
- package/dist/module/core/native/index.js +2 -0
- package/dist/module/core/native/native-utils.d.ts +4 -0
- package/dist/module/core/native/native-utils.js +27 -0
- package/dist/module/core/native/parsers/boxShadow.d.ts +1 -0
- package/dist/module/core/native/parsers/boxShadow.js +3 -0
- package/dist/module/core/native/parsers/fontVariant.d.ts +1 -0
- package/dist/module/core/native/parsers/fontVariant.js +1 -0
- package/dist/module/core/native/parsers/gradient.d.ts +8 -0
- package/dist/module/core/native/parsers/gradient.js +26 -0
- package/dist/module/core/native/parsers/index.d.ts +5 -0
- package/dist/module/core/native/parsers/index.js +5 -0
- package/dist/module/core/native/parsers/textShadow.d.ts +1 -0
- package/dist/module/core/native/parsers/textShadow.js +32 -0
- package/dist/module/core/native/parsers/transforms.d.ts +1 -0
- package/dist/module/core/native/parsers/transforms.js +48 -0
- package/dist/module/core/native/runtime.d.ts +2 -0
- package/dist/module/core/native/runtime.js +28 -0
- package/dist/module/core/native/store.d.ts +19 -0
- package/dist/module/core/native/store.js +172 -0
- package/dist/module/core/types.d.ts +73 -0
- package/dist/module/core/types.js +0 -0
- package/dist/module/core/web/cssListener.d.ts +19 -0
- package/dist/module/core/web/cssListener.js +137 -0
- package/dist/module/core/web/formatColor.d.ts +1 -0
- package/dist/module/core/web/formatColor.js +8 -0
- package/dist/module/core/web/getWebStyles.d.ts +2 -0
- package/dist/module/core/web/getWebStyles.js +49 -0
- package/dist/module/core/web/index.d.ts +4 -0
- package/dist/module/core/web/index.js +4 -0
- package/dist/module/core/web/parseCSSValue.d.ts +1 -0
- package/dist/module/core/web/parseCSSValue.js +8 -0
- package/dist/module/css/index.d.ts +1 -0
- package/dist/module/css/index.js +25 -0
- package/dist/module/css/insets.d.ts +1 -0
- package/dist/module/css/insets.js +63 -0
- package/dist/module/css/processFunctions.d.ts +2 -0
- package/dist/module/css/processFunctions.js +36 -0
- package/dist/module/css/themes.d.ts +1 -0
- package/dist/module/css/themes.js +97 -0
- package/dist/module/css/variants.d.ts +1 -0
- package/dist/module/css/variants.js +9 -0
- package/dist/module/hoc/index.d.ts +1 -0
- package/dist/module/hoc/index.js +1 -0
- package/dist/module/hoc/types.d.ts +27 -0
- package/dist/module/hoc/types.js +0 -0
- package/dist/module/hoc/withUniwind.d.ts +2 -0
- package/dist/module/hoc/withUniwind.js +76 -0
- package/dist/module/hoc/withUniwind.native.d.ts +2 -0
- package/dist/module/hoc/withUniwind.native.js +81 -0
- package/dist/module/hoc/withUniwindUtils.d.ts +5 -0
- package/dist/module/hoc/withUniwindUtils.js +5 -0
- package/dist/module/hooks/index.d.ts +4 -0
- package/dist/module/hooks/index.js +4 -0
- package/dist/module/hooks/useCSSVariable/getVariableValue.d.ts +1 -0
- package/dist/module/hooks/useCSSVariable/getVariableValue.js +12 -0
- package/dist/module/hooks/useCSSVariable/getVariableValue.native.d.ts +1 -0
- package/dist/module/hooks/useCSSVariable/getVariableValue.native.js +2 -0
- package/dist/module/hooks/useCSSVariable/index.d.ts +1 -0
- package/dist/module/hooks/useCSSVariable/index.js +1 -0
- package/dist/module/hooks/useCSSVariable/useCSSVariable.d.ts +13 -0
- package/dist/module/hooks/useCSSVariable/useCSSVariable.js +56 -0
- package/dist/module/hooks/useResolveClassNames.d.ts +2 -0
- package/dist/module/hooks/useResolveClassNames.js +18 -0
- package/dist/module/hooks/useResolveClassNames.native.d.ts +2 -0
- package/dist/module/hooks/useResolveClassNames.native.js +22 -0
- package/dist/module/hooks/useUniwind.d.ts +5 -0
- package/dist/module/hooks/useUniwind.js +21 -0
- package/dist/module/hooks/useUniwindAccent.d.ts +1 -0
- package/dist/module/hooks/useUniwindAccent.js +6 -0
- package/dist/module/hooks/useUniwindAccent.native.d.ts +2 -0
- package/dist/module/hooks/useUniwindAccent.native.js +5 -0
- package/dist/module/index.d.ts +5 -0
- package/dist/module/index.js +3 -0
- package/dist/module/types.d.ts +21 -0
- package/dist/module/types.js +22 -0
- package/dist/module/utils/buildDtsFile.d.ts +1 -0
- package/dist/module/utils/buildDtsFile.js +22 -0
- package/dist/module/utils/stringifyThemes.d.ts +1 -0
- package/dist/module/utils/stringifyThemes.js +1 -0
- package/dist/module/vite/index.d.ts +9 -0
- package/dist/module/vite/index.js +1 -0
- package/dist/module/vite/vite.d.ts +8 -0
- package/dist/module/vite/vite.js +73 -0
- package/dist/shared/uniwind.BZIuaszw.cjs +11 -0
- package/dist/shared/uniwind.BgZDHdUR.cjs +81 -0
- package/dist/shared/uniwind.Bt3kqZo6.mjs +290 -0
- package/dist/shared/uniwind.CyoRUwOj.mjs +9 -0
- package/dist/shared/uniwind.D3fvrgEG.mjs +68 -0
- package/dist/shared/uniwind.D_6s2EM-.cjs +301 -0
- package/dist/vite/index.cjs +80 -0
- package/dist/vite/index.d.ts +9 -0
- package/dist/vite/index.mjs +74 -0
- package/metro/package.json +3 -0
- package/package.json +106 -0
- package/readme.md +71 -0
- package/src/components/index.ts +313 -0
- package/src/components/native/ActivityIndicator.tsx +19 -0
- package/src/components/native/Button.tsx +16 -0
- package/src/components/native/FlatList.tsx +28 -0
- package/src/components/native/Image.tsx +19 -0
- package/src/components/native/ImageBackground.tsx +21 -0
- package/src/components/native/InputAccessoryView.tsx +23 -0
- package/src/components/native/KeyboardAvoidingView.tsx +18 -0
- package/src/components/native/Modal.tsx +19 -0
- package/src/components/native/Pressable.tsx +31 -0
- package/src/components/native/RefreshControl.tsx +25 -0
- package/src/components/native/SafeAreaView.tsx +16 -0
- package/src/components/native/ScrollView.tsx +21 -0
- package/src/components/native/SectionList.tsx +25 -0
- package/src/components/native/Switch.tsx +28 -0
- package/src/components/native/Text.tsx +39 -0
- package/src/components/native/TextInput.tsx +52 -0
- package/src/components/native/TouchableHighlight.tsx +34 -0
- package/src/components/native/TouchableNativeFeedback.tsx +31 -0
- package/src/components/native/TouchableOpacity.tsx +31 -0
- package/src/components/native/TouchableWithoutFeedback.tsx +31 -0
- package/src/components/native/View.tsx +16 -0
- package/src/components/native/VirtualizedList.tsx +25 -0
- package/src/components/native/useStyle.ts +33 -0
- package/src/components/utils.ts +16 -0
- package/src/components/web/ActivityIndicator.tsx +18 -0
- package/src/components/web/Button.tsx +16 -0
- package/src/components/web/FlatList.tsx +20 -0
- package/src/components/web/Image.tsx +18 -0
- package/src/components/web/ImageBackground.tsx +19 -0
- package/src/components/web/KeyboardAvoidingView.tsx +15 -0
- package/src/components/web/Modal.tsx +14 -0
- package/src/components/web/Pressable.tsx +14 -0
- package/src/components/web/RefreshControl.tsx +14 -0
- package/src/components/web/SafeAreaView.tsx +14 -0
- package/src/components/web/ScrollView.tsx +15 -0
- package/src/components/web/SectionList.tsx +17 -0
- package/src/components/web/Switch.tsx +21 -0
- package/src/components/web/Text.tsx +14 -0
- package/src/components/web/TextInput.tsx +14 -0
- package/src/components/web/TouchableHighlight.tsx +18 -0
- package/src/components/web/TouchableNativeFeedback.tsx +2 -0
- package/src/components/web/TouchableOpacity.tsx +14 -0
- package/src/components/web/TouchableWithoutFeedback.tsx +14 -0
- package/src/components/web/View.tsx +14 -0
- package/src/components/web/VirtualizedList.tsx +17 -0
- package/src/components/web/index.ts +22 -0
- package/src/components/web/metro-injected.ts +1 -0
- package/src/components/web/rnw.ts +52 -0
- package/src/core/config/config.common.ts +98 -0
- package/src/core/config/config.native.ts +79 -0
- package/src/core/config/config.ts +64 -0
- package/src/core/config/index.ts +1 -0
- package/src/core/index.ts +1 -0
- package/src/core/listener.ts +59 -0
- package/src/core/logger.ts +15 -0
- package/src/core/native/index.ts +2 -0
- package/src/core/native/native-utils.ts +41 -0
- package/src/core/native/parsers/boxShadow.ts +7 -0
- package/src/core/native/parsers/fontVariant.ts +3 -0
- package/src/core/native/parsers/gradient.ts +39 -0
- package/src/core/native/parsers/index.ts +5 -0
- package/src/core/native/parsers/textShadow.ts +37 -0
- package/src/core/native/parsers/transforms.ts +64 -0
- package/src/core/native/runtime.ts +32 -0
- package/src/core/native/store.ts +238 -0
- package/src/core/types.ts +92 -0
- package/src/core/web/cssListener.ts +185 -0
- package/src/core/web/formatColor.ts +13 -0
- package/src/core/web/getWebStyles.ts +76 -0
- package/src/core/web/index.ts +4 -0
- package/src/core/web/parseCSSValue.ts +10 -0
- package/src/css/index.ts +32 -0
- package/src/css/insets.ts +73 -0
- package/src/css/processFunctions.ts +39 -0
- package/src/css/themes.ts +130 -0
- package/src/css/variants.ts +11 -0
- package/src/hoc/index.ts +1 -0
- package/src/hoc/types.ts +45 -0
- package/src/hoc/withUniwind.native.tsx +118 -0
- package/src/hoc/withUniwind.tsx +115 -0
- package/src/hoc/withUniwindUtils.ts +10 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useCSSVariable/getVariableValue.native.ts +3 -0
- package/src/hooks/useCSSVariable/getVariableValue.ts +19 -0
- package/src/hooks/useCSSVariable/index.ts +1 -0
- package/src/hooks/useCSSVariable/useCSSVariable.ts +89 -0
- package/src/hooks/useResolveClassNames.native.ts +29 -0
- package/src/hooks/useResolveClassNames.ts +26 -0
- package/src/hooks/useUniwind.ts +26 -0
- package/src/hooks/useUniwindAccent.native.ts +8 -0
- package/src/hooks/useUniwindAccent.ts +10 -0
- package/src/index.ts +5 -0
- package/src/metro/addMetaToStylesTemplate.ts +152 -0
- package/src/metro/compileVirtual.ts +74 -0
- package/src/metro/index.d.ts +15 -0
- package/src/metro/index.ts +1 -0
- package/src/metro/injectThemes.ts +23 -0
- package/src/metro/logger.ts +44 -0
- package/src/metro/metro-css-patches.ts +57 -0
- package/src/metro/metro-transformer.ts +99 -0
- package/src/metro/polyfillWeb.ts +14 -0
- package/src/metro/processor/color.ts +76 -0
- package/src/metro/processor/css.ts +541 -0
- package/src/metro/processor/functions.ts +199 -0
- package/src/metro/processor/index.ts +1 -0
- package/src/metro/processor/mq.ts +82 -0
- package/src/metro/processor/processor.ts +249 -0
- package/src/metro/processor/rn.ts +277 -0
- package/src/metro/processor/units.ts +58 -0
- package/src/metro/processor/var.ts +18 -0
- package/src/metro/resolvers.ts +101 -0
- package/src/metro/types.ts +74 -0
- package/src/metro/utils/common.ts +103 -0
- package/src/metro/utils/index.ts +2 -0
- package/src/metro/utils/serialize.ts +116 -0
- package/src/metro/withUniwindConfig.ts +60 -0
- package/src/types.ts +24 -0
- package/src/utils/buildDtsFile.ts +27 -0
- package/src/utils/stringifyThemes.ts +1 -0
- package/src/vite/index.d.ts +9 -0
- package/src/vite/index.ts +1 -0
- package/src/vite/vite.ts +86 -0
- package/types.d.ts +109 -0
- package/uniwind.css +262 -0
- package/vite/package.json +3 -0
|
@@ -0,0 +1,1565 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const common = require('../shared/uniwind.BgZDHdUR.cjs');
|
|
6
|
+
const node = require('@tailwindcss/node');
|
|
7
|
+
const oxide = require('@tailwindcss/oxide');
|
|
8
|
+
const types = require('../shared/uniwind.BZIuaszw.cjs');
|
|
9
|
+
const stringifyThemes = require('../shared/uniwind.D_6s2EM-.cjs');
|
|
10
|
+
const lightningcss = require('lightningcss');
|
|
11
|
+
const culori = require('culori');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
14
|
+
|
|
15
|
+
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
16
|
+
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
17
|
+
|
|
18
|
+
const parseStringValue = (value) => {
|
|
19
|
+
if (common.isValidJSValue(value)) {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
if (value.startsWith("function")) {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
const tokens = common.smartSplit(common.addMissingSpaces(value));
|
|
26
|
+
const parsedTokens = tokens.map((token) => {
|
|
27
|
+
if (token.startsWith('"')) {
|
|
28
|
+
return token.replace(/"/g, "");
|
|
29
|
+
}
|
|
30
|
+
if (/^[a-z]+$/i.test(token.replace(/,/g, ""))) {
|
|
31
|
+
return token;
|
|
32
|
+
}
|
|
33
|
+
if (common.isNumber(token)) {
|
|
34
|
+
return token;
|
|
35
|
+
}
|
|
36
|
+
const endsWithComma = token.endsWith(",");
|
|
37
|
+
return [
|
|
38
|
+
"${",
|
|
39
|
+
endsWithComma ? token.slice(0, -1) : token,
|
|
40
|
+
"}",
|
|
41
|
+
endsWithComma ? "," : ""
|
|
42
|
+
].join("");
|
|
43
|
+
});
|
|
44
|
+
return [
|
|
45
|
+
"`",
|
|
46
|
+
parsedTokens.join(" "),
|
|
47
|
+
"`"
|
|
48
|
+
].join("");
|
|
49
|
+
};
|
|
50
|
+
const serialize = (value) => {
|
|
51
|
+
const typeOfValue = typeof value;
|
|
52
|
+
switch (typeOfValue) {
|
|
53
|
+
case "string":
|
|
54
|
+
return parseStringValue(value);
|
|
55
|
+
case "symbol":
|
|
56
|
+
return String(value);
|
|
57
|
+
case "number":
|
|
58
|
+
case "bigint":
|
|
59
|
+
return String(common.roundToPrecision(value, 2));
|
|
60
|
+
case "boolean":
|
|
61
|
+
return value.toString();
|
|
62
|
+
case "object":
|
|
63
|
+
if (value === null) {
|
|
64
|
+
return "null";
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(value)) {
|
|
67
|
+
return [
|
|
68
|
+
"[",
|
|
69
|
+
value.map(serialize).join(", "),
|
|
70
|
+
"]"
|
|
71
|
+
].join("");
|
|
72
|
+
}
|
|
73
|
+
return [
|
|
74
|
+
"{",
|
|
75
|
+
Object.entries(value).map(([key, val]) => {
|
|
76
|
+
const serializedKey = common.isNumber(key) ? key : `"${key}"`;
|
|
77
|
+
return `${serializedKey}: ${serialize(val)}`;
|
|
78
|
+
}).join(", "),
|
|
79
|
+
"}"
|
|
80
|
+
].join("");
|
|
81
|
+
case "undefined":
|
|
82
|
+
return "undefined";
|
|
83
|
+
case "function":
|
|
84
|
+
return "";
|
|
85
|
+
default:
|
|
86
|
+
return "";
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const serializeJSObject = (obj, serializer) => {
|
|
90
|
+
const serializedObject = common.pipe(obj)(
|
|
91
|
+
Object.entries,
|
|
92
|
+
(entries) => entries.map(([key, value]) => serializer(key, serialize(value))),
|
|
93
|
+
(entries) => entries.join(","),
|
|
94
|
+
(result) => {
|
|
95
|
+
if (result === "") {
|
|
96
|
+
return "";
|
|
97
|
+
}
|
|
98
|
+
return `${result},`;
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
try {
|
|
102
|
+
new Function(`function validateJS() { const obj = ({ ${serializedObject} }) }`);
|
|
103
|
+
} catch {
|
|
104
|
+
stringifyThemes.Logger.error("Failed to serialize javascript object");
|
|
105
|
+
return "";
|
|
106
|
+
}
|
|
107
|
+
return serializedObject;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
var StyleDependency = /* @__PURE__ */ ((StyleDependency2) => {
|
|
111
|
+
StyleDependency2[StyleDependency2["ColorScheme"] = 1] = "ColorScheme";
|
|
112
|
+
StyleDependency2[StyleDependency2["Theme"] = 2] = "Theme";
|
|
113
|
+
StyleDependency2[StyleDependency2["Dimensions"] = 3] = "Dimensions";
|
|
114
|
+
StyleDependency2[StyleDependency2["Orientation"] = 4] = "Orientation";
|
|
115
|
+
StyleDependency2[StyleDependency2["Insets"] = 5] = "Insets";
|
|
116
|
+
StyleDependency2[StyleDependency2["FontScale"] = 6] = "FontScale";
|
|
117
|
+
StyleDependency2[StyleDependency2["Rtl"] = 7] = "Rtl";
|
|
118
|
+
StyleDependency2[StyleDependency2["AdaptiveThemes"] = 8] = "AdaptiveThemes";
|
|
119
|
+
StyleDependency2[StyleDependency2["Variables"] = 9] = "Variables";
|
|
120
|
+
return StyleDependency2;
|
|
121
|
+
})(StyleDependency || {});
|
|
122
|
+
|
|
123
|
+
const extractVarsFromString = (value) => {
|
|
124
|
+
const thisIndexes = [...value.matchAll(/this\[/g)].map((m) => m.index);
|
|
125
|
+
return thisIndexes.map((index) => {
|
|
126
|
+
const afterIndex = value.slice(index + 5);
|
|
127
|
+
const closingIndex = afterIndex.indexOf("]");
|
|
128
|
+
const varName = afterIndex.slice(0, closingIndex);
|
|
129
|
+
return varName.replace(/[`"\\]/g, "");
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
const makeSafeForSerialization = (value) => {
|
|
133
|
+
if (value === null) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
if (typeof value === "string") {
|
|
137
|
+
return `"${value}"`;
|
|
138
|
+
}
|
|
139
|
+
return value;
|
|
140
|
+
};
|
|
141
|
+
const addMetaToStylesTemplate = (Processor, currentPlatform) => {
|
|
142
|
+
const stylesheetsEntries = Object.entries(Processor.stylesheets).map(([className, stylesPerMediaQuery]) => {
|
|
143
|
+
const styles = stylesPerMediaQuery.map((style, index) => {
|
|
144
|
+
const {
|
|
145
|
+
platform,
|
|
146
|
+
rtl,
|
|
147
|
+
theme,
|
|
148
|
+
orientation,
|
|
149
|
+
minWidth,
|
|
150
|
+
maxWidth,
|
|
151
|
+
colorScheme,
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
153
|
+
important,
|
|
154
|
+
importantProperties,
|
|
155
|
+
active,
|
|
156
|
+
focus,
|
|
157
|
+
disabled,
|
|
158
|
+
...rest
|
|
159
|
+
} = style;
|
|
160
|
+
const entries = Object.entries(rest).flatMap(([property, value]) => Processor.RN.cssToRN(property, value)).map(([property, value]) => [`"${property}"`, `function() { return ${serialize(value)} }`]);
|
|
161
|
+
if (platform && platform !== types.Platform.Native && platform !== currentPlatform) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
if (entries.length === 0) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
const dependencies = [];
|
|
168
|
+
const stringifiedEntries = JSON.stringify(entries);
|
|
169
|
+
const usedVars = extractVarsFromString(stringifiedEntries);
|
|
170
|
+
const isUsingThemedVar = usedVars.some((usedVarName) => {
|
|
171
|
+
return Object.values(Processor.scopedVars).some((scopedVars) => {
|
|
172
|
+
const scopedVarsNames = Object.keys(scopedVars);
|
|
173
|
+
return scopedVarsNames.includes(usedVarName);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
if (usedVars.length > 0) {
|
|
177
|
+
dependencies.push(StyleDependency.Variables);
|
|
178
|
+
}
|
|
179
|
+
if (theme !== null || isUsingThemedVar || stringifiedEntries.includes("rt.lightDark")) {
|
|
180
|
+
dependencies.push(StyleDependency.Theme);
|
|
181
|
+
}
|
|
182
|
+
if (orientation !== null) {
|
|
183
|
+
dependencies.push(StyleDependency.Orientation);
|
|
184
|
+
}
|
|
185
|
+
if (rtl !== null) {
|
|
186
|
+
dependencies.push(StyleDependency.Rtl);
|
|
187
|
+
}
|
|
188
|
+
if (Number(minWidth) !== 0 || Number(maxWidth) !== Number.MAX_VALUE || stringifiedEntries.includes("rt.screen")) {
|
|
189
|
+
dependencies.push(StyleDependency.Dimensions);
|
|
190
|
+
}
|
|
191
|
+
if (stringifiedEntries.includes("rt.insets")) {
|
|
192
|
+
dependencies.push(StyleDependency.Insets);
|
|
193
|
+
}
|
|
194
|
+
if (stringifiedEntries.includes("rt.fontScale")) {
|
|
195
|
+
dependencies.push(StyleDependency.FontScale);
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
entries,
|
|
199
|
+
minWidth,
|
|
200
|
+
maxWidth,
|
|
201
|
+
theme: makeSafeForSerialization(theme),
|
|
202
|
+
orientation: makeSafeForSerialization(orientation),
|
|
203
|
+
rtl,
|
|
204
|
+
colorScheme: makeSafeForSerialization(colorScheme),
|
|
205
|
+
native: platform !== null,
|
|
206
|
+
dependencies: dependencies.length > 0 ? dependencies : null,
|
|
207
|
+
index,
|
|
208
|
+
className: makeSafeForSerialization(className),
|
|
209
|
+
active,
|
|
210
|
+
focus,
|
|
211
|
+
disabled,
|
|
212
|
+
importantProperties: importantProperties?.map((property) => property.startsWith("--") ? property : common.toCamelCase).map(makeSafeForSerialization) ?? [],
|
|
213
|
+
complexity: [
|
|
214
|
+
minWidth !== 0,
|
|
215
|
+
theme !== null,
|
|
216
|
+
orientation !== null,
|
|
217
|
+
rtl !== null,
|
|
218
|
+
platform !== null,
|
|
219
|
+
active !== null,
|
|
220
|
+
focus !== null,
|
|
221
|
+
disabled !== null
|
|
222
|
+
].filter(Boolean).length
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
const filteredStyles = styles.filter(common.isDefined);
|
|
226
|
+
if (filteredStyles.length === 0) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
return [
|
|
230
|
+
className,
|
|
231
|
+
filteredStyles
|
|
232
|
+
];
|
|
233
|
+
}).filter(common.isDefined);
|
|
234
|
+
const stylesheets = Object.fromEntries(stylesheetsEntries);
|
|
235
|
+
return stylesheets;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const polyfillWeb = (css) => {
|
|
239
|
+
const result = lightningcss.transform({
|
|
240
|
+
code: Buffer.from(css),
|
|
241
|
+
filename: "uniwind.css",
|
|
242
|
+
visitor: {
|
|
243
|
+
Function: stringifyThemes.processFunctions
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
return result.code.toString();
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
class Color {
|
|
250
|
+
constructor(Processor) {
|
|
251
|
+
this.Processor = Processor;
|
|
252
|
+
}
|
|
253
|
+
toRgb = culori.converter("rgb");
|
|
254
|
+
black = "#000000";
|
|
255
|
+
logger = new stringifyThemes.Logger("Color");
|
|
256
|
+
processColor(color) {
|
|
257
|
+
if (typeof color === "string") {
|
|
258
|
+
const parsed = culori.parse(color);
|
|
259
|
+
if (parsed === void 0) {
|
|
260
|
+
this.logger.error(`Failed to convert color ${color}`);
|
|
261
|
+
return this.black;
|
|
262
|
+
}
|
|
263
|
+
return this.format(parsed);
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
if (color.type === "currentcolor") {
|
|
267
|
+
return 'this["currentColor"]';
|
|
268
|
+
}
|
|
269
|
+
if (color.type === "rgb" || color.type === "srgb") {
|
|
270
|
+
const alpha = typeof color.alpha === "number" ? color.alpha : common.pipe(color.alpha)(
|
|
271
|
+
(x) => this.Processor.CSS.processValue(x),
|
|
272
|
+
Number,
|
|
273
|
+
(x) => isNaN(x) ? 1 : x
|
|
274
|
+
);
|
|
275
|
+
return this.format({
|
|
276
|
+
r: color.r / 255,
|
|
277
|
+
g: color.g / 255,
|
|
278
|
+
b: color.b / 255,
|
|
279
|
+
alpha,
|
|
280
|
+
mode: "rgb"
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
const result = this.toRgb({
|
|
284
|
+
mode: color.type,
|
|
285
|
+
...color
|
|
286
|
+
});
|
|
287
|
+
return this.format(result);
|
|
288
|
+
} catch {
|
|
289
|
+
this.logger.error(`Failed to convert color ${JSON.stringify(color)}`);
|
|
290
|
+
return this.black;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
isColor(value) {
|
|
294
|
+
return typeof value === "string" && culori.parse(value) !== void 0;
|
|
295
|
+
}
|
|
296
|
+
format(color) {
|
|
297
|
+
if (color.alpha === 1 || color.alpha === void 0) {
|
|
298
|
+
return culori.formatHex(color);
|
|
299
|
+
}
|
|
300
|
+
return culori.formatHex8(color);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
class CSS {
|
|
305
|
+
constructor(Processor) {
|
|
306
|
+
this.Processor = Processor;
|
|
307
|
+
}
|
|
308
|
+
logger = new stringifyThemes.Logger("CSS");
|
|
309
|
+
processValue(declarationValue) {
|
|
310
|
+
const processedValue = this.getProcessedValue(declarationValue);
|
|
311
|
+
if (typeof processedValue === "string") {
|
|
312
|
+
return this.makeSafeForSerialization(processedValue);
|
|
313
|
+
}
|
|
314
|
+
if (Array.isArray(processedValue)) {
|
|
315
|
+
return processedValue.map((value) => {
|
|
316
|
+
if (typeof value === "string") {
|
|
317
|
+
return this.makeSafeForSerialization(value);
|
|
318
|
+
}
|
|
319
|
+
return value;
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
if (typeof processedValue === "object" && processedValue !== null) {
|
|
323
|
+
return Object.fromEntries(
|
|
324
|
+
Object.entries(processedValue).map(([key, value]) => {
|
|
325
|
+
if (typeof value === "string") {
|
|
326
|
+
return [
|
|
327
|
+
key,
|
|
328
|
+
this.makeSafeForSerialization(value)
|
|
329
|
+
];
|
|
330
|
+
}
|
|
331
|
+
return [
|
|
332
|
+
key,
|
|
333
|
+
value
|
|
334
|
+
];
|
|
335
|
+
})
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
return processedValue;
|
|
339
|
+
}
|
|
340
|
+
getProcessedValue(declarationValue) {
|
|
341
|
+
if (typeof declarationValue !== "object") {
|
|
342
|
+
return declarationValue;
|
|
343
|
+
}
|
|
344
|
+
if ("type" in declarationValue) {
|
|
345
|
+
switch (declarationValue.type) {
|
|
346
|
+
case "function":
|
|
347
|
+
return this.Processor.Functions.processFunction(declarationValue.value);
|
|
348
|
+
case "var":
|
|
349
|
+
return this.Processor.Var.processVar(declarationValue.value);
|
|
350
|
+
case "number":
|
|
351
|
+
return declarationValue.value;
|
|
352
|
+
case "token":
|
|
353
|
+
return this.processValue(declarationValue.value);
|
|
354
|
+
case "length":
|
|
355
|
+
return this.Processor.Units.processAnyLength(declarationValue.value);
|
|
356
|
+
case "color":
|
|
357
|
+
return this.Processor.Color.processColor(declarationValue.value);
|
|
358
|
+
case "integer":
|
|
359
|
+
return declarationValue.value;
|
|
360
|
+
case "comma":
|
|
361
|
+
return ", ";
|
|
362
|
+
case "dimension":
|
|
363
|
+
case "value":
|
|
364
|
+
case "length-percentage":
|
|
365
|
+
return this.Processor.Units.processLength(declarationValue.value);
|
|
366
|
+
case "translate": {
|
|
367
|
+
const [translateX, translateY] = declarationValue.value.map((x) => this.processValue(x));
|
|
368
|
+
return [
|
|
369
|
+
{
|
|
370
|
+
translateX
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
translateY
|
|
374
|
+
}
|
|
375
|
+
];
|
|
376
|
+
}
|
|
377
|
+
case "translateX":
|
|
378
|
+
return {
|
|
379
|
+
translateX: this.Processor.Units.processLength(declarationValue.value)
|
|
380
|
+
};
|
|
381
|
+
case "translateY":
|
|
382
|
+
return {
|
|
383
|
+
translateY: this.Processor.Units.processLength(declarationValue.value)
|
|
384
|
+
};
|
|
385
|
+
case "translateZ": {
|
|
386
|
+
return {
|
|
387
|
+
translateZ: this.processValue(declarationValue.value)
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
case "rotate":
|
|
391
|
+
return {
|
|
392
|
+
rotate: `${declarationValue.value.value}${declarationValue.value.type}`
|
|
393
|
+
};
|
|
394
|
+
case "rotateX":
|
|
395
|
+
return {
|
|
396
|
+
rotateX: `${declarationValue.value.value}${declarationValue.value.type}`
|
|
397
|
+
};
|
|
398
|
+
case "rotateY":
|
|
399
|
+
return {
|
|
400
|
+
rotateY: `${declarationValue.value.value}${declarationValue.value.type}`
|
|
401
|
+
};
|
|
402
|
+
case "rotateZ":
|
|
403
|
+
return {
|
|
404
|
+
rotateZ: `${declarationValue.value.value}${declarationValue.value.type}`
|
|
405
|
+
};
|
|
406
|
+
case "scale": {
|
|
407
|
+
const [scaleX, scaleY] = declarationValue.value.map((x) => this.processValue(x));
|
|
408
|
+
if (scaleX === scaleY) {
|
|
409
|
+
return {
|
|
410
|
+
scale: scaleX
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
return [
|
|
414
|
+
{
|
|
415
|
+
scaleX
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
scaleY
|
|
419
|
+
}
|
|
420
|
+
];
|
|
421
|
+
}
|
|
422
|
+
case "scaleX":
|
|
423
|
+
return {
|
|
424
|
+
scaleX: this.processValue(declarationValue.value)
|
|
425
|
+
};
|
|
426
|
+
case "scaleY":
|
|
427
|
+
return {
|
|
428
|
+
scaleY: this.processValue(declarationValue.value)
|
|
429
|
+
};
|
|
430
|
+
case "scaleZ":
|
|
431
|
+
return {
|
|
432
|
+
scaleZ: this.processValue(declarationValue.value)
|
|
433
|
+
};
|
|
434
|
+
case "percentage":
|
|
435
|
+
return `${declarationValue.value * 100}%`;
|
|
436
|
+
case "token-list":
|
|
437
|
+
return declarationValue.value.reduce((acc, token) => {
|
|
438
|
+
const tokenValue = this.processValue(token);
|
|
439
|
+
return acc + tokenValue;
|
|
440
|
+
}, "");
|
|
441
|
+
case "rgb":
|
|
442
|
+
case "oklab":
|
|
443
|
+
case "oklch":
|
|
444
|
+
case "hsl":
|
|
445
|
+
case "hwb":
|
|
446
|
+
case "lab":
|
|
447
|
+
case "lch":
|
|
448
|
+
case "srgb":
|
|
449
|
+
return this.Processor.Color.processColor(declarationValue);
|
|
450
|
+
case "delim":
|
|
451
|
+
return ` ${declarationValue.value} `;
|
|
452
|
+
case "ident":
|
|
453
|
+
if (this.Processor.Color.isColor(declarationValue.value)) {
|
|
454
|
+
return this.Processor.Color.processColor(declarationValue.value);
|
|
455
|
+
}
|
|
456
|
+
if (declarationValue.value === "currentcolor") {
|
|
457
|
+
return 'this["currentColor"]';
|
|
458
|
+
}
|
|
459
|
+
return declarationValue.value;
|
|
460
|
+
case "env":
|
|
461
|
+
if (declarationValue.value.name.type === "ua" && declarationValue.value.name.value.startsWith("safe-area-inset-")) {
|
|
462
|
+
const inset = declarationValue.value.name.value.replace("safe-area-inset-", "");
|
|
463
|
+
return `rt.insets.${inset}`;
|
|
464
|
+
}
|
|
465
|
+
this.logUnsupported(`Unsupported env value - ${JSON.stringify(declarationValue.value)}`);
|
|
466
|
+
return void 0;
|
|
467
|
+
case "time": {
|
|
468
|
+
const unit = declarationValue.value.type === "milliseconds" ? "ms" : "s";
|
|
469
|
+
return `${declarationValue.value.value}${unit}`;
|
|
470
|
+
}
|
|
471
|
+
case "cubic-bezier": {
|
|
472
|
+
const bezier = [
|
|
473
|
+
declarationValue.x1,
|
|
474
|
+
declarationValue.y1,
|
|
475
|
+
declarationValue.x2,
|
|
476
|
+
declarationValue.y2
|
|
477
|
+
];
|
|
478
|
+
return `rt.cubicBezier(${bezier.join(",")})`;
|
|
479
|
+
}
|
|
480
|
+
case "seconds":
|
|
481
|
+
return `${declarationValue.value}s`;
|
|
482
|
+
case "milliseconds":
|
|
483
|
+
return `${declarationValue.value}ms`;
|
|
484
|
+
case "pair":
|
|
485
|
+
return declarationValue.inside.type;
|
|
486
|
+
case "currentcolor":
|
|
487
|
+
return 'this["currentColor"]';
|
|
488
|
+
case "calc":
|
|
489
|
+
return this.Processor.Functions.processCalc(declarationValue.value);
|
|
490
|
+
case "min":
|
|
491
|
+
case "max":
|
|
492
|
+
case "abs":
|
|
493
|
+
return this.Processor.Functions.processMathFunction(declarationValue.type, declarationValue.value);
|
|
494
|
+
case "keyword":
|
|
495
|
+
if ("value" in declarationValue) {
|
|
496
|
+
return declarationValue.value;
|
|
497
|
+
}
|
|
498
|
+
this.logUnsupported(`Unsupported keyword value - ${JSON.stringify(declarationValue)}`);
|
|
499
|
+
return void 0;
|
|
500
|
+
case "min-max":
|
|
501
|
+
case "track-breadth":
|
|
502
|
+
return declarationValue.type;
|
|
503
|
+
case "explicit":
|
|
504
|
+
return `${this.processValue(declarationValue.width)} ${this.processValue(declarationValue.height)}`;
|
|
505
|
+
case "angle":
|
|
506
|
+
return `${declarationValue.value.value}${declarationValue.value.type}`;
|
|
507
|
+
case "gradient":
|
|
508
|
+
if (declarationValue.value.type === "linear") {
|
|
509
|
+
const direction = String(this.processValue(declarationValue.value.direction));
|
|
510
|
+
return [
|
|
511
|
+
direction.includes("deg") ? direction : `to ${direction}`,
|
|
512
|
+
...declarationValue.value.items.map((item) => this.processValue(item))
|
|
513
|
+
].join(", ");
|
|
514
|
+
}
|
|
515
|
+
return void 0;
|
|
516
|
+
case "color-stop":
|
|
517
|
+
return [
|
|
518
|
+
this.Processor.Color.processColor(declarationValue.color),
|
|
519
|
+
declarationValue.position ? this.processValue(declarationValue.position) : null
|
|
520
|
+
].filter(common.isDefined).join(" ");
|
|
521
|
+
case "side":
|
|
522
|
+
return declarationValue.side;
|
|
523
|
+
case "absolute":
|
|
524
|
+
if ("value" in declarationValue) {
|
|
525
|
+
return typeof declarationValue.value === "string" ? declarationValue.value : this.processValue(declarationValue.value);
|
|
526
|
+
}
|
|
527
|
+
return declarationValue.type;
|
|
528
|
+
case "hash":
|
|
529
|
+
return `#${declarationValue.value}`;
|
|
530
|
+
case "line-style":
|
|
531
|
+
return declarationValue.value;
|
|
532
|
+
case "parenthesis-block":
|
|
533
|
+
return "(";
|
|
534
|
+
case "close-parenthesis":
|
|
535
|
+
return ")";
|
|
536
|
+
case "light-dark":
|
|
537
|
+
return `rt.lightDark( ${this.processValue(declarationValue.light)}, ${this.processValue(declarationValue.dark)} )`;
|
|
538
|
+
case "unresolved-color":
|
|
539
|
+
return this.getProcessedValue(declarationValue.value);
|
|
540
|
+
case "track-list":
|
|
541
|
+
case "sticky":
|
|
542
|
+
case "fit-content":
|
|
543
|
+
case "shape":
|
|
544
|
+
return void 0;
|
|
545
|
+
case "weight":
|
|
546
|
+
case "horizontal":
|
|
547
|
+
case "vertical":
|
|
548
|
+
case "white-space":
|
|
549
|
+
case "string":
|
|
550
|
+
case "self-position":
|
|
551
|
+
case "content-distribution":
|
|
552
|
+
case "content-position":
|
|
553
|
+
return declarationValue.value;
|
|
554
|
+
case "baseline-position":
|
|
555
|
+
return "baseline";
|
|
556
|
+
default:
|
|
557
|
+
if (Object.keys(declarationValue).length === 1) {
|
|
558
|
+
return declarationValue.type;
|
|
559
|
+
}
|
|
560
|
+
this.logUnsupported(`Unsupported value type - ${JSON.stringify(declarationValue.type)}`);
|
|
561
|
+
return void 0;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if ("top" in declarationValue) {
|
|
565
|
+
return {
|
|
566
|
+
top: this.processValue(declarationValue.top),
|
|
567
|
+
right: this.processValue(declarationValue.right),
|
|
568
|
+
bottom: this.processValue(declarationValue.bottom),
|
|
569
|
+
left: this.processValue(declarationValue.left)
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
if ("topLeft" in declarationValue) {
|
|
573
|
+
return {
|
|
574
|
+
topLeft: this.processValue(declarationValue.topLeft),
|
|
575
|
+
topRight: this.processValue(declarationValue.topRight),
|
|
576
|
+
bottomLeft: this.processValue(declarationValue.bottomLeft),
|
|
577
|
+
bottomRight: this.processValue(declarationValue.bottomRight)
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
if ("grow" in declarationValue) {
|
|
581
|
+
return {
|
|
582
|
+
flexGrow: declarationValue.grow,
|
|
583
|
+
flexShrink: declarationValue.shrink,
|
|
584
|
+
flexBasis: this.processValue(declarationValue.basis)
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
if (Array.isArray(declarationValue)) {
|
|
588
|
+
if (declarationValue.length === 1) {
|
|
589
|
+
return this.processValue(declarationValue[0]);
|
|
590
|
+
}
|
|
591
|
+
return this.addComaBetweenTokens(declarationValue).reduce((acc, value, index, array) => {
|
|
592
|
+
if (typeof value === "object") {
|
|
593
|
+
const nextValue = array.at(index + 1);
|
|
594
|
+
if (common.deepEqual(value, nextValue)) {
|
|
595
|
+
return acc;
|
|
596
|
+
}
|
|
597
|
+
const result = this.processValue(value);
|
|
598
|
+
return acc === "" && typeof result === "number" ? result : acc + result;
|
|
599
|
+
}
|
|
600
|
+
return acc + value;
|
|
601
|
+
}, "");
|
|
602
|
+
}
|
|
603
|
+
if ("property" in declarationValue) {
|
|
604
|
+
const property = typeof declarationValue.property === "string" ? declarationValue.property : declarationValue.property.property;
|
|
605
|
+
return `${property},`;
|
|
606
|
+
}
|
|
607
|
+
if ("case" in declarationValue) {
|
|
608
|
+
return declarationValue.case;
|
|
609
|
+
}
|
|
610
|
+
if ("angle" in declarationValue) {
|
|
611
|
+
const angles = common.pipe([
|
|
612
|
+
["rotateX", declarationValue.x * declarationValue.angle.value],
|
|
613
|
+
["rotateY", declarationValue.y * declarationValue.angle.value],
|
|
614
|
+
["rotateZ", declarationValue.z * declarationValue.angle.value]
|
|
615
|
+
])(
|
|
616
|
+
(x) => x.filter(([, value]) => value !== 0),
|
|
617
|
+
(x) => x.map(([key, value]) => [key, `${value}${declarationValue.angle.type}`]),
|
|
618
|
+
Object.fromEntries
|
|
619
|
+
);
|
|
620
|
+
return angles;
|
|
621
|
+
}
|
|
622
|
+
if (this.isOverflow(declarationValue)) {
|
|
623
|
+
if (declarationValue.x === declarationValue.y) {
|
|
624
|
+
return {
|
|
625
|
+
overflow: declarationValue.x
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
return {
|
|
629
|
+
overflowX: declarationValue.x,
|
|
630
|
+
overflowY: declarationValue.y
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
if ("auto" in declarationValue) {
|
|
634
|
+
return declarationValue.ratio ? `${declarationValue.ratio[0]}/${declarationValue.ratio[1]}` : "auto";
|
|
635
|
+
}
|
|
636
|
+
if ("x" in declarationValue && "y" in declarationValue) {
|
|
637
|
+
return {
|
|
638
|
+
x: this.processValue(declarationValue.x),
|
|
639
|
+
y: this.processValue(declarationValue.y)
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
if ("xOffset" in declarationValue) {
|
|
643
|
+
return [
|
|
644
|
+
"inset" in declarationValue && declarationValue.inset ? "inset" : void 0,
|
|
645
|
+
this.processValue(declarationValue.xOffset),
|
|
646
|
+
this.processValue(declarationValue.yOffset),
|
|
647
|
+
this.processValue(declarationValue.blur),
|
|
648
|
+
this.processValue(declarationValue.spread),
|
|
649
|
+
this.processValue(declarationValue.color)
|
|
650
|
+
].filter(common.isDefined).join(" ");
|
|
651
|
+
}
|
|
652
|
+
if ("blockStart" in declarationValue) {
|
|
653
|
+
const startValue = this.processValue(declarationValue.blockStart);
|
|
654
|
+
const endValue = this.processValue(declarationValue.blockEnd);
|
|
655
|
+
return {
|
|
656
|
+
start: startValue,
|
|
657
|
+
end: endValue
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
if ("inlineStart" in declarationValue) {
|
|
661
|
+
const startValue = this.processValue(declarationValue.inlineStart);
|
|
662
|
+
const endValue = this.processValue(declarationValue.inlineEnd);
|
|
663
|
+
return {
|
|
664
|
+
start: startValue,
|
|
665
|
+
end: endValue
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
if ("start" in declarationValue) {
|
|
669
|
+
const startValue = this.processValue(declarationValue.start);
|
|
670
|
+
const endValue = this.processValue(declarationValue.end);
|
|
671
|
+
return {
|
|
672
|
+
start: startValue,
|
|
673
|
+
end: endValue
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
if ("row" in declarationValue) {
|
|
677
|
+
return {
|
|
678
|
+
row: this.processValue(declarationValue.row),
|
|
679
|
+
column: this.processValue(declarationValue.column)
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
if ("keyword" in declarationValue) {
|
|
683
|
+
return declarationValue.keyword === "auto" || declarationValue.keyword === "pointer" ? declarationValue.keyword : "auto";
|
|
684
|
+
}
|
|
685
|
+
if ("style" in declarationValue && "width" in declarationValue) {
|
|
686
|
+
return {
|
|
687
|
+
style: this.processValue(declarationValue.style),
|
|
688
|
+
width: declarationValue.width.type === "length" ? this.processValue(declarationValue.width.value) : void 0,
|
|
689
|
+
color: this.Processor.Color.processColor(declarationValue.color)
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
if ("duration" in declarationValue) {
|
|
693
|
+
return [
|
|
694
|
+
this.processValue(declarationValue.name),
|
|
695
|
+
this.processValue(declarationValue.duration),
|
|
696
|
+
this.processValue(declarationValue.timingFunction),
|
|
697
|
+
this.processValue(declarationValue.delay),
|
|
698
|
+
this.processValue(declarationValue.iterationCount),
|
|
699
|
+
declarationValue.direction,
|
|
700
|
+
declarationValue.fillMode,
|
|
701
|
+
declarationValue.playState,
|
|
702
|
+
this.processValue(declarationValue.timeline)
|
|
703
|
+
].filter(Boolean).join(" ");
|
|
704
|
+
}
|
|
705
|
+
this.logUnsupported(`Unsupported value - ${JSON.stringify(declarationValue)}`);
|
|
706
|
+
return void 0;
|
|
707
|
+
}
|
|
708
|
+
isOverflow(value) {
|
|
709
|
+
return typeof value === "object" && "x" in value && ["hidden", "visible"].includes(value.x);
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Between some tokens there isn't a comma but it should be.
|
|
713
|
+
* For example this applies to Array of shadows
|
|
714
|
+
*/
|
|
715
|
+
addComaBetweenTokens(values) {
|
|
716
|
+
return values.reduce((acc, value, index, array) => {
|
|
717
|
+
const next = array.at(index + 1);
|
|
718
|
+
acc.push(value);
|
|
719
|
+
if (next === void 0) {
|
|
720
|
+
return acc;
|
|
721
|
+
}
|
|
722
|
+
if (typeof next === "object" && "type" in next && next.type === "token" && next.value.type === "comma") {
|
|
723
|
+
return acc;
|
|
724
|
+
}
|
|
725
|
+
if (!(typeof value === "object" && "xOffset" in value && "blur" in value)) {
|
|
726
|
+
return acc;
|
|
727
|
+
}
|
|
728
|
+
acc.push({
|
|
729
|
+
type: "token",
|
|
730
|
+
value: {
|
|
731
|
+
type: "comma"
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
return acc;
|
|
735
|
+
}, []);
|
|
736
|
+
}
|
|
737
|
+
logUnsupported(message) {
|
|
738
|
+
this.logger.warn(
|
|
739
|
+
[
|
|
740
|
+
message,
|
|
741
|
+
this.Processor.meta.className !== void 0 ? `for className ${this.Processor.meta.className}` : null
|
|
742
|
+
].filter(Boolean).join(" ")
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
makeSafeForSerialization(value) {
|
|
746
|
+
if (common.shouldBeSerialized(value)) {
|
|
747
|
+
return value;
|
|
748
|
+
}
|
|
749
|
+
if (value.endsWith("%")) {
|
|
750
|
+
return `"${common.roundToPrecision(parseFloat(value), 2)}%"`;
|
|
751
|
+
}
|
|
752
|
+
return `"${value}"`;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
class Functions {
|
|
757
|
+
constructor(Processor) {
|
|
758
|
+
this.Processor = Processor;
|
|
759
|
+
}
|
|
760
|
+
logger = new stringifyThemes.Logger("Functions");
|
|
761
|
+
processCalc(calc) {
|
|
762
|
+
switch (calc.type) {
|
|
763
|
+
case "sum": {
|
|
764
|
+
const sum = calc.value.map((x) => this.processCalc(x)).join(" + ");
|
|
765
|
+
return this.tryEval(sum);
|
|
766
|
+
}
|
|
767
|
+
case "value":
|
|
768
|
+
return this.Processor.CSS.processValue(calc.value);
|
|
769
|
+
case "function":
|
|
770
|
+
return this.Processor.CSS.processValue(calc.value);
|
|
771
|
+
case "number":
|
|
772
|
+
return String(calc.value);
|
|
773
|
+
default:
|
|
774
|
+
this.logger.warn(`Unsupported calc type - ${calc.type}`);
|
|
775
|
+
return "";
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
processFunction(fn) {
|
|
779
|
+
if (typeof fn !== "object") {
|
|
780
|
+
this.logger.warn(`Unsupported function - ${fn}`);
|
|
781
|
+
return fn;
|
|
782
|
+
}
|
|
783
|
+
if (fn.name === "calc") {
|
|
784
|
+
const calc = this.Processor.CSS.processValue(fn.arguments);
|
|
785
|
+
return common.pipe(calc)(
|
|
786
|
+
String,
|
|
787
|
+
(x) => this.Processor.Functions.tryEval(x)
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
if (fn.name === "cubic-bezier") {
|
|
791
|
+
const cubicArguments = common.pipe(this.Processor.CSS.processValue(fn.arguments))(
|
|
792
|
+
String,
|
|
793
|
+
(x) => x.replace(/,\s/g, ",")
|
|
794
|
+
);
|
|
795
|
+
return `rt.cubicBezier(${cubicArguments})`;
|
|
796
|
+
}
|
|
797
|
+
if (fn.name === "max") {
|
|
798
|
+
return `Math.max(${this.Processor.CSS.processValue(fn.arguments)})`;
|
|
799
|
+
}
|
|
800
|
+
if (fn.name === "linear-gradient") {
|
|
801
|
+
return this.Processor.CSS.processValue(fn.arguments);
|
|
802
|
+
}
|
|
803
|
+
if (fn.name === "color-mix") {
|
|
804
|
+
return this.processColorMix(fn);
|
|
805
|
+
}
|
|
806
|
+
if ([
|
|
807
|
+
"rgb",
|
|
808
|
+
"oklab",
|
|
809
|
+
"oklch",
|
|
810
|
+
"hsl",
|
|
811
|
+
"hwb",
|
|
812
|
+
"lab",
|
|
813
|
+
"lch",
|
|
814
|
+
"srgb"
|
|
815
|
+
].includes(fn.name)) {
|
|
816
|
+
const color = `${fn.name}(${this.Processor.CSS.processValue(fn.arguments)})`;
|
|
817
|
+
return this.Processor.Color.processColor(color);
|
|
818
|
+
}
|
|
819
|
+
if ([
|
|
820
|
+
"blur",
|
|
821
|
+
"brightness",
|
|
822
|
+
"contrast",
|
|
823
|
+
"grayscale",
|
|
824
|
+
"hue-rotate",
|
|
825
|
+
"invert",
|
|
826
|
+
"opacity",
|
|
827
|
+
"saturate",
|
|
828
|
+
"sepia",
|
|
829
|
+
"conic-gradient",
|
|
830
|
+
"radial-gradient"
|
|
831
|
+
].includes(fn.name)) {
|
|
832
|
+
return '""';
|
|
833
|
+
}
|
|
834
|
+
if (["skewX", "skewY"].includes(fn.name)) {
|
|
835
|
+
return `"${fn.name}(${this.Processor.CSS.processValue(fn.arguments).replace(/"/g, "")})"`;
|
|
836
|
+
}
|
|
837
|
+
if (fn.name === "hairlineWidth") {
|
|
838
|
+
return "rt.hairlineWidth";
|
|
839
|
+
}
|
|
840
|
+
if (fn.name === "pixelRatio") {
|
|
841
|
+
return `rt.pixelRatio(${this.Processor.CSS.processValue(fn.arguments)})`;
|
|
842
|
+
}
|
|
843
|
+
if (fn.name === "fontScale") {
|
|
844
|
+
return `rt.fontScale(${this.Processor.CSS.processValue(fn.arguments)})`;
|
|
845
|
+
}
|
|
846
|
+
if (fn.name === "drop-shadow") {
|
|
847
|
+
return void 0;
|
|
848
|
+
}
|
|
849
|
+
this.logger.warn(`Unsupported function - ${fn.name}`);
|
|
850
|
+
return fn.name;
|
|
851
|
+
}
|
|
852
|
+
processMathFunction(name, value) {
|
|
853
|
+
if (!Array.isArray(value)) {
|
|
854
|
+
return `Math.${name}(${this.processCalc(value)})`;
|
|
855
|
+
}
|
|
856
|
+
const values = value.map((x) => this.processCalc(x)).join(" , ");
|
|
857
|
+
return `Math.${name}(${values})`;
|
|
858
|
+
}
|
|
859
|
+
tryEval(value) {
|
|
860
|
+
const units = Array.from(
|
|
861
|
+
value.replace(/"/g, "").match(/(?<![A-Za-z-])(?:%|deg|rad|grad|turn)(?=\s|$)/g) ?? []
|
|
862
|
+
);
|
|
863
|
+
if (units.length === 0) {
|
|
864
|
+
return value;
|
|
865
|
+
}
|
|
866
|
+
if (new Set(units).size !== 1) {
|
|
867
|
+
this.logger.error(`Invalid calc, you can't mix multiple units`);
|
|
868
|
+
return value;
|
|
869
|
+
}
|
|
870
|
+
if (units.includes("%") && value.includes("+")) {
|
|
871
|
+
this.logger.error(`Invalid calc, you can't mix % with other units`);
|
|
872
|
+
return value;
|
|
873
|
+
}
|
|
874
|
+
const unit = units.at(0) ?? "";
|
|
875
|
+
try {
|
|
876
|
+
const numericValue = value.replace(/"/g, "").replace(new RegExp(unit, "g"), "");
|
|
877
|
+
return new Function(`return ${numericValue} + '${unit}'`)();
|
|
878
|
+
} catch {
|
|
879
|
+
this.logger.error(`Invalid calc ${value}`);
|
|
880
|
+
return value;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
processColorMix(fn) {
|
|
884
|
+
const tokens = fn.arguments.map(
|
|
885
|
+
(arg) => common.pipe(arg)(
|
|
886
|
+
(x) => this.Processor.CSS.processValue(x),
|
|
887
|
+
String,
|
|
888
|
+
(x) => x.trim()
|
|
889
|
+
)
|
|
890
|
+
).filter((token) => !["", ",", "in", "srgb", "rgb", "hsl", "hwb", "lab", "lch", "oklab", "oklch"].includes(token.replace(/"/g, "")));
|
|
891
|
+
return `rt.colorMix(${tokens.join(", ")})`;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
class MQ {
|
|
896
|
+
constructor(Processor) {
|
|
897
|
+
this.Processor = Processor;
|
|
898
|
+
}
|
|
899
|
+
processMediaQueries(mediaQueries) {
|
|
900
|
+
const mq = this.getInitialMediaQueryResolver();
|
|
901
|
+
mediaQueries.forEach((mediaQuery) => {
|
|
902
|
+
const { condition, mediaType } = mediaQuery;
|
|
903
|
+
if ([types.Platform.Android, types.Platform.iOS, types.Platform.Native].includes(mediaType)) {
|
|
904
|
+
mq.platform = mediaType;
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
if (condition?.type !== "feature") {
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
if (condition.value.type === "range") {
|
|
911
|
+
this.processWidthMediaQuery(condition.value, mq);
|
|
912
|
+
}
|
|
913
|
+
if (condition.value.type === "plain") {
|
|
914
|
+
this.processPlainMediaQuery(condition.value, mq);
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
return mq;
|
|
918
|
+
}
|
|
919
|
+
processWidthMediaQuery(query, mq) {
|
|
920
|
+
const { operator, value } = query;
|
|
921
|
+
const result = this.Processor.CSS.processValue(value);
|
|
922
|
+
if (operator === "greater-than-equal" || operator === "greater-than") {
|
|
923
|
+
mq.minWidth = result;
|
|
924
|
+
}
|
|
925
|
+
if (operator === "less-than-equal" || operator === "less-than") {
|
|
926
|
+
mq.maxWidth = result;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
processPlainMediaQuery(query, mq) {
|
|
930
|
+
const { value, name } = query;
|
|
931
|
+
switch (name) {
|
|
932
|
+
case "orientation":
|
|
933
|
+
mq.orientation = value.value;
|
|
934
|
+
break;
|
|
935
|
+
case "prefers-color-scheme":
|
|
936
|
+
mq.colorScheme = value.value;
|
|
937
|
+
break;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
getInitialMediaQueryResolver() {
|
|
941
|
+
return {
|
|
942
|
+
minWidth: 0,
|
|
943
|
+
maxWidth: Number.MAX_VALUE,
|
|
944
|
+
platform: null,
|
|
945
|
+
rtl: null,
|
|
946
|
+
important: false,
|
|
947
|
+
colorScheme: null,
|
|
948
|
+
orientation: null,
|
|
949
|
+
theme: null,
|
|
950
|
+
active: null,
|
|
951
|
+
focus: null,
|
|
952
|
+
disabled: null
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
const cssToRNMap = {
|
|
958
|
+
backgroundSize: (value) => {
|
|
959
|
+
return {
|
|
960
|
+
resizeMode: value
|
|
961
|
+
};
|
|
962
|
+
},
|
|
963
|
+
transitionProperty: (value) => {
|
|
964
|
+
return {
|
|
965
|
+
transitionProperty: value.replace(/"/g, "").split(",").filter((token) => token !== "" && !token.startsWith("--")).map((token) => `"${common.toCamelCase(token)}"`)
|
|
966
|
+
};
|
|
967
|
+
},
|
|
968
|
+
flex: (value) => {
|
|
969
|
+
if (typeof value === "object") {
|
|
970
|
+
return value;
|
|
971
|
+
}
|
|
972
|
+
return {
|
|
973
|
+
flex: value
|
|
974
|
+
};
|
|
975
|
+
},
|
|
976
|
+
overflow: (value) => {
|
|
977
|
+
if (typeof value === "object") {
|
|
978
|
+
return value;
|
|
979
|
+
}
|
|
980
|
+
return {
|
|
981
|
+
overflow: value
|
|
982
|
+
};
|
|
983
|
+
},
|
|
984
|
+
backdropFilter: () => ({}),
|
|
985
|
+
backgroundImage: (value) => ({
|
|
986
|
+
experimental_backgroundImage: value
|
|
987
|
+
}),
|
|
988
|
+
borderSpacing: () => ({}),
|
|
989
|
+
translate: (value) => {
|
|
990
|
+
if (typeof value === "object" && "x" in value && "y" in value) {
|
|
991
|
+
return {
|
|
992
|
+
translateX: value.x,
|
|
993
|
+
translateY: value.y
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
if (typeof value === "string") {
|
|
997
|
+
const [x, y] = value.split(" ");
|
|
998
|
+
return {
|
|
999
|
+
translateX: x,
|
|
1000
|
+
translateY: y ?? x
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
return {};
|
|
1004
|
+
},
|
|
1005
|
+
rotate: (value) => {
|
|
1006
|
+
if (typeof value === "object") {
|
|
1007
|
+
return value;
|
|
1008
|
+
}
|
|
1009
|
+
return {
|
|
1010
|
+
rotate: value
|
|
1011
|
+
};
|
|
1012
|
+
},
|
|
1013
|
+
scale: (value) => {
|
|
1014
|
+
if (typeof value === "object") {
|
|
1015
|
+
return {
|
|
1016
|
+
scaleX: value.x,
|
|
1017
|
+
scaleY: value.y,
|
|
1018
|
+
scaleZ: value.z
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
if (typeof value === "string") {
|
|
1022
|
+
const [x, y, z] = value.split(" ");
|
|
1023
|
+
return {
|
|
1024
|
+
scaleX: x,
|
|
1025
|
+
scaleY: y,
|
|
1026
|
+
scaleZ: z
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
return {};
|
|
1030
|
+
},
|
|
1031
|
+
transform: (value) => {
|
|
1032
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
1033
|
+
return {
|
|
1034
|
+
transform: value
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
if (typeof value === "object") {
|
|
1038
|
+
return Object.keys(value).length === 0 ? { transform: [] } : value;
|
|
1039
|
+
}
|
|
1040
|
+
return {};
|
|
1041
|
+
},
|
|
1042
|
+
fontSize: (value) => {
|
|
1043
|
+
return {
|
|
1044
|
+
fontSize: value,
|
|
1045
|
+
"--uniwind-em": value
|
|
1046
|
+
};
|
|
1047
|
+
},
|
|
1048
|
+
borderInlineWidth: (value) => {
|
|
1049
|
+
const borderWidth = typeof value === "object" ? Object.values(value)[0] : value;
|
|
1050
|
+
return {
|
|
1051
|
+
borderLeftWidth: borderWidth,
|
|
1052
|
+
borderRightWidth: borderWidth
|
|
1053
|
+
};
|
|
1054
|
+
},
|
|
1055
|
+
borderBlockWidth: (value) => {
|
|
1056
|
+
const borderWidth = typeof value === "object" ? Object.values(value)[0] : value;
|
|
1057
|
+
return {
|
|
1058
|
+
borderTopWidth: borderWidth,
|
|
1059
|
+
borderBottomWidth: borderWidth
|
|
1060
|
+
};
|
|
1061
|
+
},
|
|
1062
|
+
borderInlineStyle: (value) => {
|
|
1063
|
+
return {
|
|
1064
|
+
borderStyle: value
|
|
1065
|
+
};
|
|
1066
|
+
},
|
|
1067
|
+
borderBlockStyle: (value) => {
|
|
1068
|
+
return {
|
|
1069
|
+
borderStyle: value
|
|
1070
|
+
};
|
|
1071
|
+
},
|
|
1072
|
+
borderStyle: (value) => {
|
|
1073
|
+
const borderStyle = typeof value === "object" ? Object.values(value)[0] : value;
|
|
1074
|
+
return {
|
|
1075
|
+
borderStyle
|
|
1076
|
+
};
|
|
1077
|
+
},
|
|
1078
|
+
transformOrigin: (value) => {
|
|
1079
|
+
if (typeof value === "object") {
|
|
1080
|
+
return {
|
|
1081
|
+
transformOrigin: `${value.x} ${value.y}`
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
return {
|
|
1085
|
+
transformOrigin: value
|
|
1086
|
+
};
|
|
1087
|
+
},
|
|
1088
|
+
fontVariantNumeric: (value) => ({
|
|
1089
|
+
fontVariant: value
|
|
1090
|
+
})
|
|
1091
|
+
};
|
|
1092
|
+
class RN {
|
|
1093
|
+
constructor(Processor) {
|
|
1094
|
+
this.Processor = Processor;
|
|
1095
|
+
}
|
|
1096
|
+
cssToRN(property, value) {
|
|
1097
|
+
const transformedProperty = property.startsWith("--") ? property : common.pipe(property)(
|
|
1098
|
+
common.toCamelCase,
|
|
1099
|
+
(x) => {
|
|
1100
|
+
if (x.includes("padding") || x.includes("margin")) {
|
|
1101
|
+
return x.replace("Inline", "Horizontal").replace("Block", "Vertical");
|
|
1102
|
+
}
|
|
1103
|
+
return x;
|
|
1104
|
+
}
|
|
1105
|
+
);
|
|
1106
|
+
const rn = this.transformProperty(
|
|
1107
|
+
transformedProperty,
|
|
1108
|
+
typeof value === "string" ? common.addMissingSpaces(value) : value
|
|
1109
|
+
);
|
|
1110
|
+
return Object.entries(rn).filter(([, value2]) => common.isDefined(value2));
|
|
1111
|
+
}
|
|
1112
|
+
transformProperty(property, value) {
|
|
1113
|
+
if (property in cssToRNMap) {
|
|
1114
|
+
return cssToRNMap[property](value);
|
|
1115
|
+
}
|
|
1116
|
+
if (typeof value === "object") {
|
|
1117
|
+
const transformed = this.transformObjectProperty(property, value);
|
|
1118
|
+
if (transformed) {
|
|
1119
|
+
return transformed;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
return {
|
|
1123
|
+
[property]: value
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
transformObjectProperty(property, value) {
|
|
1127
|
+
const properties = Object.keys(value);
|
|
1128
|
+
const propertyEnd = property.includes("border") ? property.split("border").at(-1) ?? "" : "";
|
|
1129
|
+
const transformedProperty = property.replace(propertyEnd, "");
|
|
1130
|
+
const isSpacing = property.includes("margin") || property.includes("padding");
|
|
1131
|
+
const wrapProperty = (prop) => `${transformedProperty}${prop}${propertyEnd}`;
|
|
1132
|
+
if (properties.every((property2) => ["row", "column"].includes(property2))) {
|
|
1133
|
+
return {
|
|
1134
|
+
rowGap: value.row,
|
|
1135
|
+
columnGap: value.column
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
if (properties.every((property2) => ["start", "end"].includes(property2))) {
|
|
1139
|
+
if (isSpacing && property.includes("Horizontal")) {
|
|
1140
|
+
return {
|
|
1141
|
+
[`${property.replace("Horizontal", "Left")}`]: value.start,
|
|
1142
|
+
[`${property.replace("Horizontal", "Right")}`]: value.end
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
if (isSpacing && property.includes("Vertical")) {
|
|
1146
|
+
return {
|
|
1147
|
+
[`${property.replace("Vertical", "Top")}`]: value.start,
|
|
1148
|
+
[`${property.replace("Vertical", "Bottom")}`]: value.end
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
return {
|
|
1152
|
+
[wrapProperty("Start")]: value.start,
|
|
1153
|
+
[wrapProperty("End")]: value.end
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
if (properties.every((property2) => ["top", "right", "bottom", "left"].includes(property2))) {
|
|
1157
|
+
return {
|
|
1158
|
+
[wrapProperty("Top")]: value.top,
|
|
1159
|
+
[wrapProperty("Right")]: value.right,
|
|
1160
|
+
[wrapProperty("Bottom")]: value.bottom,
|
|
1161
|
+
[wrapProperty("Left")]: value.left
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
if (properties.every((property2) => ["topLeft", "topRight", "bottomRight", "bottomLeft"].includes(property2))) {
|
|
1165
|
+
return {
|
|
1166
|
+
[wrapProperty("TopLeft")]: value.topLeft,
|
|
1167
|
+
[wrapProperty("TopRight")]: value.topRight,
|
|
1168
|
+
[wrapProperty("BottomRight")]: value.bottomRight,
|
|
1169
|
+
[wrapProperty("BottomLeft")]: value.bottomLeft
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
if (properties.every((property2) => ["style", "width", "color"].includes(property2))) {
|
|
1173
|
+
return {
|
|
1174
|
+
[wrapProperty("Style")]: value.style,
|
|
1175
|
+
[wrapProperty("Width")]: value.width,
|
|
1176
|
+
[wrapProperty("Color")]: value.color
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
class Units {
|
|
1183
|
+
constructor(Processor) {
|
|
1184
|
+
this.Processor = Processor;
|
|
1185
|
+
}
|
|
1186
|
+
logger = new stringifyThemes.Logger("Units");
|
|
1187
|
+
processLength(length) {
|
|
1188
|
+
if (typeof length === "number") {
|
|
1189
|
+
return length;
|
|
1190
|
+
}
|
|
1191
|
+
if ("unit" in length) {
|
|
1192
|
+
switch (length.unit) {
|
|
1193
|
+
case "px":
|
|
1194
|
+
return this.replaceInfinity(length.value);
|
|
1195
|
+
case "vw":
|
|
1196
|
+
return `rt.screen.width * ${length.value / 100}`;
|
|
1197
|
+
case "vh":
|
|
1198
|
+
return `rt.screen.height * ${length.value / 100}`;
|
|
1199
|
+
case "rem":
|
|
1200
|
+
return length.value * this.Processor.vars["--uniwind-em"];
|
|
1201
|
+
case "em":
|
|
1202
|
+
return `this[\`--uniwind-em\`] * ${length.value}`;
|
|
1203
|
+
default:
|
|
1204
|
+
this.logger.warn(`Unsupported unit - ${length.unit}`);
|
|
1205
|
+
return length.value;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
return this.Processor.CSS.processValue(length);
|
|
1209
|
+
}
|
|
1210
|
+
processAnyLength(length) {
|
|
1211
|
+
if ("type" in length) {
|
|
1212
|
+
switch (length.type) {
|
|
1213
|
+
case "value":
|
|
1214
|
+
case "dimension":
|
|
1215
|
+
return this.processLength(length.value);
|
|
1216
|
+
case "percentage":
|
|
1217
|
+
return `${length.value * 100}%`;
|
|
1218
|
+
default:
|
|
1219
|
+
this.logger.warn(`Unsupported length type - ${length.type}`);
|
|
1220
|
+
return length.value;
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
return this.processLength(length);
|
|
1224
|
+
}
|
|
1225
|
+
replaceInfinity(value) {
|
|
1226
|
+
return value === Infinity ? 99999 : value;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
class Var {
|
|
1231
|
+
constructor(Processor) {
|
|
1232
|
+
this.Processor = Processor;
|
|
1233
|
+
}
|
|
1234
|
+
processVar(variable) {
|
|
1235
|
+
const value = `this[\`${variable.name.ident}\`]`;
|
|
1236
|
+
if (!variable.fallback || variable.fallback.length === 0) {
|
|
1237
|
+
return value;
|
|
1238
|
+
}
|
|
1239
|
+
const fallback = this.Processor.CSS.processValue(variable.fallback);
|
|
1240
|
+
return `${value} ?? ${fallback}`;
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
class ProcessorBuilder {
|
|
1245
|
+
constructor(themes, polyfills) {
|
|
1246
|
+
this.themes = themes;
|
|
1247
|
+
this.polyfills = polyfills;
|
|
1248
|
+
this.vars["--uniwind-em"] = polyfills?.rem ?? 16;
|
|
1249
|
+
}
|
|
1250
|
+
stylesheets = {};
|
|
1251
|
+
vars = {};
|
|
1252
|
+
scopedVars = {};
|
|
1253
|
+
CSS = new CSS(this);
|
|
1254
|
+
RN = new RN(this);
|
|
1255
|
+
Var = new Var(this);
|
|
1256
|
+
MQ = new MQ(this);
|
|
1257
|
+
Color = new Color(this);
|
|
1258
|
+
Units = new Units(this);
|
|
1259
|
+
Functions = new Functions(this);
|
|
1260
|
+
meta = {};
|
|
1261
|
+
declarationConfig = this.getDeclarationConfig();
|
|
1262
|
+
transform(css) {
|
|
1263
|
+
lightningcss.transform({
|
|
1264
|
+
filename: "tailwind.css",
|
|
1265
|
+
code: Buffer.from(css),
|
|
1266
|
+
visitor: {
|
|
1267
|
+
StyleSheet: (styleSheet) => styleSheet.rules.forEach((rule) => {
|
|
1268
|
+
this.declarationConfig = this.getDeclarationConfig();
|
|
1269
|
+
this.parseRuleRec(rule);
|
|
1270
|
+
})
|
|
1271
|
+
}
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
getDeclarationConfig() {
|
|
1275
|
+
return {
|
|
1276
|
+
className: null,
|
|
1277
|
+
rtl: null,
|
|
1278
|
+
mediaQueries: [],
|
|
1279
|
+
root: false,
|
|
1280
|
+
theme: null,
|
|
1281
|
+
active: null,
|
|
1282
|
+
focus: null,
|
|
1283
|
+
disabled: null
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
addDeclaration(declaration, important = false) {
|
|
1287
|
+
const isVar = this.declarationConfig.root || this.declarationConfig.className === null;
|
|
1288
|
+
const mq = this.MQ.processMediaQueries(this.declarationConfig.mediaQueries);
|
|
1289
|
+
const style = (() => {
|
|
1290
|
+
if (!isVar) {
|
|
1291
|
+
return this.stylesheets[this.declarationConfig.className]?.at(-1);
|
|
1292
|
+
}
|
|
1293
|
+
if (mq.platform !== null) {
|
|
1294
|
+
const platformKey = `__uniwind-platform-${mq.platform}`;
|
|
1295
|
+
this.scopedVars[platformKey] ??= {};
|
|
1296
|
+
return this.scopedVars[platformKey];
|
|
1297
|
+
}
|
|
1298
|
+
if (this.declarationConfig.theme === null) {
|
|
1299
|
+
return this.vars;
|
|
1300
|
+
}
|
|
1301
|
+
const themeKey = `__uniwind-theme-${this.declarationConfig.theme}`;
|
|
1302
|
+
this.scopedVars[themeKey] ??= {};
|
|
1303
|
+
return this.scopedVars[themeKey];
|
|
1304
|
+
})();
|
|
1305
|
+
if (!isVar) {
|
|
1306
|
+
Object.assign(style, mq);
|
|
1307
|
+
style.importantProperties ??= [];
|
|
1308
|
+
style.rtl = this.declarationConfig.rtl;
|
|
1309
|
+
style.theme = mq.colorScheme ?? this.declarationConfig.theme;
|
|
1310
|
+
style.active = this.declarationConfig.active;
|
|
1311
|
+
style.focus = this.declarationConfig.focus;
|
|
1312
|
+
style.disabled = this.declarationConfig.disabled;
|
|
1313
|
+
this.meta.className = this.declarationConfig.className;
|
|
1314
|
+
}
|
|
1315
|
+
if (declaration.property === "unparsed") {
|
|
1316
|
+
style[declaration.value.propertyId.property] = this.CSS.processValue(declaration.value.value);
|
|
1317
|
+
if (!isVar && important) {
|
|
1318
|
+
style.importantProperties.push(declaration.value.propertyId.property);
|
|
1319
|
+
}
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
if (declaration.property === "custom") {
|
|
1323
|
+
style[declaration.value.name] = this.CSS.processValue(declaration.value.value);
|
|
1324
|
+
if (!isVar && important) {
|
|
1325
|
+
style.importantProperties.push(declaration.value.name);
|
|
1326
|
+
}
|
|
1327
|
+
return;
|
|
1328
|
+
}
|
|
1329
|
+
style[declaration.property] = this.CSS.processValue(declaration.value);
|
|
1330
|
+
if (!isVar && important) {
|
|
1331
|
+
style.importantProperties.push(declaration.property);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
parseRuleRec(rule) {
|
|
1335
|
+
if (this.declarationConfig.className !== null) {
|
|
1336
|
+
const lastStyle = this.stylesheets[this.declarationConfig.className]?.at(-1);
|
|
1337
|
+
if (lastStyle !== void 0 && Object.keys(lastStyle).length > 0) {
|
|
1338
|
+
this.stylesheets[this.declarationConfig.className]?.push({});
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
if (rule.type === "style") {
|
|
1342
|
+
rule.value.selectors.forEach((selector) => {
|
|
1343
|
+
const [maybeClassNameSelector] = selector;
|
|
1344
|
+
const newClassName = maybeClassNameSelector?.type === "class" ? maybeClassNameSelector.name : void 0;
|
|
1345
|
+
if (newClassName !== void 0) {
|
|
1346
|
+
this.declarationConfig.className = newClassName;
|
|
1347
|
+
this.stylesheets[newClassName] ??= [];
|
|
1348
|
+
this.stylesheets[newClassName].push({});
|
|
1349
|
+
rule.value.declarations?.declarations?.forEach((declaration) => this.addDeclaration(declaration));
|
|
1350
|
+
rule.value.declarations?.importantDeclarations?.forEach((declaration) => this.addDeclaration(declaration, true));
|
|
1351
|
+
rule.value.rules?.forEach((rule2) => this.parseRuleRec(rule2));
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
let rtl = null;
|
|
1355
|
+
let theme = null;
|
|
1356
|
+
let active = null;
|
|
1357
|
+
let focus = null;
|
|
1358
|
+
let disabled = null;
|
|
1359
|
+
selector.forEach((selector2) => {
|
|
1360
|
+
if (selector2.type === "pseudo-class" && selector2.kind === "where") {
|
|
1361
|
+
selector2.selectors.forEach((selector3) => {
|
|
1362
|
+
selector3.forEach((selector4) => {
|
|
1363
|
+
if (selector4.type === "class" && this.themes.includes(selector4.name)) {
|
|
1364
|
+
theme = selector4.name;
|
|
1365
|
+
}
|
|
1366
|
+
if (selector4.type === "pseudo-class" && selector4.kind === "dir") {
|
|
1367
|
+
rtl = selector4.direction === "rtl";
|
|
1368
|
+
}
|
|
1369
|
+
});
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
if (selector2.type === "pseudo-class" && selector2.kind === "active") {
|
|
1373
|
+
active = true;
|
|
1374
|
+
}
|
|
1375
|
+
if (selector2.type === "pseudo-class" && selector2.kind === "focus") {
|
|
1376
|
+
focus = true;
|
|
1377
|
+
}
|
|
1378
|
+
if (selector2.type === "pseudo-class" && selector2.kind === "disabled") {
|
|
1379
|
+
disabled = true;
|
|
1380
|
+
}
|
|
1381
|
+
});
|
|
1382
|
+
if ([rtl, theme, active, focus, disabled].some(Boolean)) {
|
|
1383
|
+
this.declarationConfig.rtl = rtl;
|
|
1384
|
+
this.declarationConfig.theme = theme;
|
|
1385
|
+
this.declarationConfig.active = active;
|
|
1386
|
+
this.declarationConfig.focus = focus;
|
|
1387
|
+
this.declarationConfig.disabled = disabled;
|
|
1388
|
+
rule.value.declarations?.declarations?.forEach((declaration) => this.addDeclaration(declaration));
|
|
1389
|
+
rule.value.declarations?.importantDeclarations?.forEach((declaration) => this.addDeclaration(declaration, true));
|
|
1390
|
+
rule.value.rules?.forEach((rule2) => this.parseRuleRec(rule2));
|
|
1391
|
+
this.declarationConfig.rtl = null;
|
|
1392
|
+
this.declarationConfig.theme = null;
|
|
1393
|
+
this.declarationConfig.active = null;
|
|
1394
|
+
this.declarationConfig.focus = null;
|
|
1395
|
+
this.declarationConfig.disabled = null;
|
|
1396
|
+
return;
|
|
1397
|
+
}
|
|
1398
|
+
selector.forEach((selectorToken) => {
|
|
1399
|
+
if (selectorToken.type === "pseudo-class" && selectorToken.kind === "root") {
|
|
1400
|
+
this.declarationConfig.root = true;
|
|
1401
|
+
rule.value.declarations?.declarations?.forEach((declaration) => this.addDeclaration(declaration));
|
|
1402
|
+
rule.value.declarations?.importantDeclarations?.forEach((declaration) => this.addDeclaration(declaration, true));
|
|
1403
|
+
rule.value.rules?.forEach((rule2) => this.parseRuleRec(rule2));
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
});
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
if (rule.type === "supports") {
|
|
1410
|
+
rule.value.rules.forEach((rule2) => this.parseRuleRec(rule2));
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
if (rule.type === "media") {
|
|
1414
|
+
const { mediaQueries } = rule.value.query;
|
|
1415
|
+
this.declarationConfig.mediaQueries.push(...mediaQueries);
|
|
1416
|
+
rule.value.rules.forEach((rule2) => {
|
|
1417
|
+
this.parseRuleRec(rule2);
|
|
1418
|
+
this.declarationConfig = this.getDeclarationConfig();
|
|
1419
|
+
});
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
if (rule.type === "layer-block") {
|
|
1423
|
+
rule.value.rules.forEach((rule2) => this.parseRuleRec(rule2));
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
if (rule.type === "nested-declarations") {
|
|
1427
|
+
rule.value.declarations.declarations?.forEach((declaration) => this.addDeclaration(declaration));
|
|
1428
|
+
rule.value.declarations.importantDeclarations?.forEach((declaration) => this.addDeclaration(declaration, true));
|
|
1429
|
+
return;
|
|
1430
|
+
}
|
|
1431
|
+
if (rule.type === "property" && rule.value.initialValue) {
|
|
1432
|
+
this.vars[rule.value.name] = this.CSS.processValue(rule.value.initialValue);
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
const compileVirtual = async ({ css, cssPath, platform, themes, polyfills, debug, candidates }) => {
|
|
1438
|
+
const compiler = await node.compile(css, {
|
|
1439
|
+
base: path__default.dirname(cssPath),
|
|
1440
|
+
onDependency: () => void 0
|
|
1441
|
+
});
|
|
1442
|
+
const scanner = new oxide.Scanner({
|
|
1443
|
+
sources: [
|
|
1444
|
+
...compiler.sources,
|
|
1445
|
+
{
|
|
1446
|
+
negated: false,
|
|
1447
|
+
pattern: "**/*",
|
|
1448
|
+
base: path__default.dirname(cssPath)
|
|
1449
|
+
}
|
|
1450
|
+
]
|
|
1451
|
+
});
|
|
1452
|
+
const tailwindCSS = compiler.build(candidates ?? scanner.scan());
|
|
1453
|
+
if (platform === types.Platform.Web) {
|
|
1454
|
+
return polyfillWeb(tailwindCSS);
|
|
1455
|
+
}
|
|
1456
|
+
const Processor = new ProcessorBuilder(themes, polyfills);
|
|
1457
|
+
stringifyThemes.Logger.debug = debug === true;
|
|
1458
|
+
Processor.transform(tailwindCSS);
|
|
1459
|
+
const stylesheet = serializeJSObject(
|
|
1460
|
+
addMetaToStylesTemplate(Processor, platform),
|
|
1461
|
+
(key, value) => `"${key}": ${value}`
|
|
1462
|
+
);
|
|
1463
|
+
const vars = serializeJSObject(
|
|
1464
|
+
Processor.vars,
|
|
1465
|
+
(key, value) => `get "${key}"() { return ${value} }`
|
|
1466
|
+
);
|
|
1467
|
+
const scopedVars = Object.fromEntries(
|
|
1468
|
+
Object.entries(Processor.scopedVars).map(([scopedVarsName, scopedVars2]) => [
|
|
1469
|
+
scopedVarsName,
|
|
1470
|
+
serializeJSObject(scopedVars2, (key, value) => `get "${key}"() { return ${value} }`)
|
|
1471
|
+
])
|
|
1472
|
+
);
|
|
1473
|
+
const serializedScopedVars = Object.entries(scopedVars).map(([scopedVarsName, scopedVars2]) => `"${scopedVarsName}": ({ ${scopedVars2} }),`).join("");
|
|
1474
|
+
const currentColorVar = `get currentColor() { return rt.colorScheme === 'dark' ? '#ffffff' : '#000000' },`;
|
|
1475
|
+
return [
|
|
1476
|
+
"({",
|
|
1477
|
+
`scopedVars: ({ ${serializedScopedVars} }),`,
|
|
1478
|
+
`vars: ({ ${currentColorVar} ${vars} }),`,
|
|
1479
|
+
`stylesheet: ({ ${stylesheet} }),`,
|
|
1480
|
+
"})"
|
|
1481
|
+
].join("");
|
|
1482
|
+
};
|
|
1483
|
+
|
|
1484
|
+
const injectThemes = async ({
|
|
1485
|
+
themes,
|
|
1486
|
+
dtsPath = "uniwind-types.d.ts",
|
|
1487
|
+
input
|
|
1488
|
+
}) => {
|
|
1489
|
+
const stringifiedThemes = stringifyThemes.stringifyThemes(themes);
|
|
1490
|
+
stringifyThemes.buildDtsFile(dtsPath, stringifiedThemes);
|
|
1491
|
+
await stringifyThemes.buildCSS(themes, input);
|
|
1492
|
+
return stringifiedThemes;
|
|
1493
|
+
};
|
|
1494
|
+
|
|
1495
|
+
let worker;
|
|
1496
|
+
try {
|
|
1497
|
+
try {
|
|
1498
|
+
const { unstable_transformerPath } = require("@expo/metro-config");
|
|
1499
|
+
worker = require(unstable_transformerPath);
|
|
1500
|
+
} catch {
|
|
1501
|
+
worker = require("@expo/metro-config/build/transform-worker/transform-worker.js");
|
|
1502
|
+
}
|
|
1503
|
+
} catch {
|
|
1504
|
+
worker = require("metro-transform-worker");
|
|
1505
|
+
}
|
|
1506
|
+
const transform = async (config, projectRoot, filePath, data, options) => {
|
|
1507
|
+
const isCss = options.type !== "asset" && path__default.join(process.cwd(), config.uniwind.cssEntryFile) === path__default.join(process.cwd(), filePath);
|
|
1508
|
+
if (filePath.endsWith("/components/web/metro-injected.js")) {
|
|
1509
|
+
const cssPath2 = path__default.join(process.cwd(), config.uniwind.cssEntryFile);
|
|
1510
|
+
const injectedThemesCode2 = await injectThemes({
|
|
1511
|
+
input: cssPath2,
|
|
1512
|
+
themes: config.uniwind.themes,
|
|
1513
|
+
dtsPath: config.uniwind.dtsFile
|
|
1514
|
+
});
|
|
1515
|
+
data = Buffer.from(
|
|
1516
|
+
[
|
|
1517
|
+
`import { Uniwind } from '${common.name}';`,
|
|
1518
|
+
`Uniwind.__reinit(() => ({}), ${injectedThemesCode2});`
|
|
1519
|
+
].join(""),
|
|
1520
|
+
"utf-8"
|
|
1521
|
+
);
|
|
1522
|
+
}
|
|
1523
|
+
if (!isCss) {
|
|
1524
|
+
return worker.transform(config, projectRoot, filePath, data, options);
|
|
1525
|
+
}
|
|
1526
|
+
const cssPath = path__default.join(process.cwd(), config.uniwind.cssEntryFile);
|
|
1527
|
+
const injectedThemesCode = await injectThemes({
|
|
1528
|
+
input: cssPath,
|
|
1529
|
+
themes: config.uniwind.themes,
|
|
1530
|
+
dtsPath: config.uniwind.dtsFile
|
|
1531
|
+
});
|
|
1532
|
+
const css = fs__default.readFileSync(filePath, "utf-8");
|
|
1533
|
+
const platform = options.platform;
|
|
1534
|
+
const virtualCode = await compileVirtual({
|
|
1535
|
+
css,
|
|
1536
|
+
platform,
|
|
1537
|
+
themes: config.uniwind.themes,
|
|
1538
|
+
polyfills: config.uniwind.polyfills,
|
|
1539
|
+
cssPath,
|
|
1540
|
+
debug: config.uniwind.debug
|
|
1541
|
+
});
|
|
1542
|
+
const isWeb = platform === types.Platform.Web;
|
|
1543
|
+
data = Buffer.from(
|
|
1544
|
+
isWeb ? virtualCode : [
|
|
1545
|
+
`import { Uniwind } from '${common.name}';`,
|
|
1546
|
+
`Uniwind.__reinit(rt => ${virtualCode}, ${injectedThemesCode});`
|
|
1547
|
+
].join(""),
|
|
1548
|
+
"utf-8"
|
|
1549
|
+
);
|
|
1550
|
+
const transform2 = await worker.transform(
|
|
1551
|
+
config,
|
|
1552
|
+
projectRoot,
|
|
1553
|
+
`${filePath}${isWeb ? "" : ".js"}`,
|
|
1554
|
+
data,
|
|
1555
|
+
options
|
|
1556
|
+
);
|
|
1557
|
+
transform2.output[0].data.css ??= {};
|
|
1558
|
+
transform2.output[0].data.css.skipCache = true;
|
|
1559
|
+
if (!isWeb) {
|
|
1560
|
+
transform2.output[0].data.css.code = "";
|
|
1561
|
+
}
|
|
1562
|
+
return transform2;
|
|
1563
|
+
};
|
|
1564
|
+
|
|
1565
|
+
exports.transform = transform;
|