@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,29 @@
|
|
|
1
|
+
import { useEffect, useReducer } from 'react'
|
|
2
|
+
import { UniwindListener } from '../core/listener'
|
|
3
|
+
import { UniwindStore } from '../core/native'
|
|
4
|
+
import { ComponentState, RNStyle } from '../core/types'
|
|
5
|
+
|
|
6
|
+
const emptyState = { styles: {} as RNStyle, dependencies: [] }
|
|
7
|
+
|
|
8
|
+
export const useResolveClassNames = (className: string, state?: ComponentState) => {
|
|
9
|
+
const [uniwindState, recreate] = useReducer(
|
|
10
|
+
() => className !== '' ? UniwindStore.getStyles(className, state) : emptyState,
|
|
11
|
+
className !== '' ? UniwindStore.getStyles(className, state) : emptyState,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (className !== '') {
|
|
16
|
+
recreate()
|
|
17
|
+
}
|
|
18
|
+
}, [className, state?.isDisabled, state?.isPressed, state?.isFocused])
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (uniwindState.dependencies.length > 0) {
|
|
22
|
+
const dispose = UniwindListener.subscribe(recreate, uniwindState.dependencies)
|
|
23
|
+
|
|
24
|
+
return dispose
|
|
25
|
+
}
|
|
26
|
+
}, [uniwindState.dependencies, className])
|
|
27
|
+
|
|
28
|
+
return uniwindState.styles
|
|
29
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useEffect, useReducer } from 'react'
|
|
2
|
+
import { RNStyle } from '../core/types'
|
|
3
|
+
import { CSSListener, getWebStyles } from '../core/web'
|
|
4
|
+
|
|
5
|
+
const emptyState = {} as RNStyle
|
|
6
|
+
|
|
7
|
+
export const useResolveClassNames = (className: string) => {
|
|
8
|
+
const [styles, recreate] = useReducer(
|
|
9
|
+
() => className !== '' ? getWebStyles(className) : emptyState,
|
|
10
|
+
className !== '' ? getWebStyles(className) : emptyState,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (className === '') {
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
recreate()
|
|
19
|
+
|
|
20
|
+
const dispose = CSSListener.subscribeToClassName(className, recreate)
|
|
21
|
+
|
|
22
|
+
return dispose
|
|
23
|
+
}, [className])
|
|
24
|
+
|
|
25
|
+
return styles
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { Uniwind } from '../core'
|
|
3
|
+
import { UniwindListener } from '../core/listener'
|
|
4
|
+
import { ThemeName } from '../core/types'
|
|
5
|
+
import { StyleDependency } from '../types'
|
|
6
|
+
|
|
7
|
+
export const useUniwind = () => {
|
|
8
|
+
const [theme, setTheme] = useState(Uniwind.currentTheme)
|
|
9
|
+
const [hasAdaptiveThemes, setHasAdaptiveThemes] = useState(Uniwind.hasAdaptiveThemes)
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const dispose = UniwindListener.subscribe(() => {
|
|
13
|
+
setTheme(Uniwind.currentTheme)
|
|
14
|
+
setHasAdaptiveThemes(Uniwind.hasAdaptiveThemes)
|
|
15
|
+
}, [StyleDependency.Theme, StyleDependency.AdaptiveThemes])
|
|
16
|
+
|
|
17
|
+
return () => {
|
|
18
|
+
dispose()
|
|
19
|
+
}
|
|
20
|
+
}, [])
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
theme: theme as ThemeName,
|
|
24
|
+
hasAdaptiveThemes,
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ComponentState } from '../core/types'
|
|
2
|
+
import { useResolveClassNames } from './useResolveClassNames.native'
|
|
3
|
+
|
|
4
|
+
export const useUniwindAccent = (className: string | undefined, state?: ComponentState) => {
|
|
5
|
+
const styles = useResolveClassNames(className ?? '', state)
|
|
6
|
+
|
|
7
|
+
return styles.accentColor
|
|
8
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { formatColor } from '../core/web/formatColor'
|
|
2
|
+
import { useResolveClassNames } from './useResolveClassNames'
|
|
3
|
+
|
|
4
|
+
export const useUniwindAccent = (className: string | undefined) => {
|
|
5
|
+
const styles = useResolveClassNames(className ?? '')
|
|
6
|
+
|
|
7
|
+
return styles.accentColor !== undefined
|
|
8
|
+
? formatColor(styles.accentColor)
|
|
9
|
+
: undefined
|
|
10
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { StyleDependency } from '../types'
|
|
2
|
+
import { ProcessorBuilder } from './processor'
|
|
3
|
+
import { Platform, StyleSheetTemplate } from './types'
|
|
4
|
+
import { isDefined, serialize, toCamelCase } from './utils'
|
|
5
|
+
|
|
6
|
+
const extractVarsFromString = (value: string) => {
|
|
7
|
+
const thisIndexes = [...value.matchAll(/this\[/g)].map(m => m.index)
|
|
8
|
+
|
|
9
|
+
return thisIndexes.map(index => {
|
|
10
|
+
const afterIndex = value.slice(index + 5)
|
|
11
|
+
const closingIndex = afterIndex.indexOf(']')
|
|
12
|
+
const varName = afterIndex.slice(0, closingIndex)
|
|
13
|
+
|
|
14
|
+
return varName.replace(/[`"\\]/g, '')
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const makeSafeForSerialization = (value: any) => {
|
|
19
|
+
if (value === null) {
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (typeof value === 'string') {
|
|
24
|
+
return `"${value}"`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return value
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const addMetaToStylesTemplate = (Processor: ProcessorBuilder, currentPlatform: Platform) => {
|
|
31
|
+
const stylesheetsEntries = Object.entries(Processor.stylesheets as StyleSheetTemplate)
|
|
32
|
+
.map(([className, stylesPerMediaQuery]) => {
|
|
33
|
+
const styles = stylesPerMediaQuery.map((style, index) => {
|
|
34
|
+
const {
|
|
35
|
+
platform,
|
|
36
|
+
rtl,
|
|
37
|
+
theme,
|
|
38
|
+
orientation,
|
|
39
|
+
minWidth,
|
|
40
|
+
maxWidth,
|
|
41
|
+
colorScheme,
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
43
|
+
important,
|
|
44
|
+
importantProperties,
|
|
45
|
+
active,
|
|
46
|
+
focus,
|
|
47
|
+
disabled,
|
|
48
|
+
...rest
|
|
49
|
+
} = style
|
|
50
|
+
|
|
51
|
+
const entries = Object.entries(rest)
|
|
52
|
+
.flatMap(([property, value]) => Processor.RN.cssToRN(property, value))
|
|
53
|
+
.map(([property, value]) => [`"${property}"`, `function() { return ${serialize(value)} }`])
|
|
54
|
+
|
|
55
|
+
if (platform && platform !== Platform.Native && platform !== currentPlatform) {
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (entries.length === 0) {
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const dependencies: Array<StyleDependency> = []
|
|
64
|
+
const stringifiedEntries = JSON.stringify(entries)
|
|
65
|
+
const usedVars = extractVarsFromString(stringifiedEntries)
|
|
66
|
+
const isUsingThemedVar = usedVars.some(usedVarName => {
|
|
67
|
+
return Object.values(Processor.scopedVars).some(scopedVars => {
|
|
68
|
+
const scopedVarsNames = Object.keys(scopedVars)
|
|
69
|
+
|
|
70
|
+
return scopedVarsNames.includes(usedVarName)
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
if (usedVars.length > 0) {
|
|
75
|
+
dependencies.push(StyleDependency.Variables)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (theme !== null || isUsingThemedVar || stringifiedEntries.includes('rt.lightDark')) {
|
|
79
|
+
dependencies.push(StyleDependency.Theme)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (orientation !== null) {
|
|
83
|
+
dependencies.push(StyleDependency.Orientation)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (rtl !== null) {
|
|
87
|
+
dependencies.push(StyleDependency.Rtl)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (
|
|
91
|
+
Number(minWidth) !== 0
|
|
92
|
+
|| Number(maxWidth) !== Number.MAX_VALUE
|
|
93
|
+
|| stringifiedEntries.includes('rt.screen')
|
|
94
|
+
) {
|
|
95
|
+
dependencies.push(StyleDependency.Dimensions)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (stringifiedEntries.includes('rt.insets')) {
|
|
99
|
+
dependencies.push(StyleDependency.Insets)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (stringifiedEntries.includes('rt.fontScale')) {
|
|
103
|
+
dependencies.push(StyleDependency.FontScale)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
entries,
|
|
108
|
+
minWidth,
|
|
109
|
+
maxWidth,
|
|
110
|
+
theme: makeSafeForSerialization(theme),
|
|
111
|
+
orientation: makeSafeForSerialization(orientation),
|
|
112
|
+
rtl,
|
|
113
|
+
colorScheme: makeSafeForSerialization(colorScheme),
|
|
114
|
+
native: platform !== null,
|
|
115
|
+
dependencies: dependencies.length > 0 ? dependencies : null,
|
|
116
|
+
index,
|
|
117
|
+
className: makeSafeForSerialization(className),
|
|
118
|
+
active,
|
|
119
|
+
focus,
|
|
120
|
+
disabled,
|
|
121
|
+
importantProperties: importantProperties
|
|
122
|
+
?.map(property => property.startsWith('--') ? property : toCamelCase)
|
|
123
|
+
.map(makeSafeForSerialization) ?? [],
|
|
124
|
+
complexity: [
|
|
125
|
+
minWidth !== 0,
|
|
126
|
+
theme !== null,
|
|
127
|
+
orientation !== null,
|
|
128
|
+
rtl !== null,
|
|
129
|
+
platform !== null,
|
|
130
|
+
active !== null,
|
|
131
|
+
focus !== null,
|
|
132
|
+
disabled !== null,
|
|
133
|
+
].filter(Boolean).length,
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
const filteredStyles = styles.filter(isDefined)
|
|
138
|
+
|
|
139
|
+
if (filteredStyles.length === 0) {
|
|
140
|
+
return null
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return [
|
|
144
|
+
className,
|
|
145
|
+
filteredStyles,
|
|
146
|
+
] as const
|
|
147
|
+
})
|
|
148
|
+
.filter(isDefined)
|
|
149
|
+
const stylesheets = Object.fromEntries(stylesheetsEntries) as Record<string, any>
|
|
150
|
+
|
|
151
|
+
return stylesheets
|
|
152
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { compile } from '@tailwindcss/node'
|
|
2
|
+
import { Scanner } from '@tailwindcss/oxide'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import { addMetaToStylesTemplate } from './addMetaToStylesTemplate'
|
|
5
|
+
import { Logger } from './logger'
|
|
6
|
+
import { polyfillWeb } from './polyfillWeb'
|
|
7
|
+
import { ProcessorBuilder } from './processor'
|
|
8
|
+
import { Platform, Polyfills } from './types'
|
|
9
|
+
import { serializeJSObject } from './utils'
|
|
10
|
+
|
|
11
|
+
type CompileVirtualConfig = {
|
|
12
|
+
cssPath: string
|
|
13
|
+
css: string
|
|
14
|
+
platform: Platform
|
|
15
|
+
themes: Array<string>
|
|
16
|
+
polyfills: Polyfills | undefined
|
|
17
|
+
debug: boolean | undefined
|
|
18
|
+
candidates?: Array<string>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const compileVirtual = async ({ css, cssPath, platform, themes, polyfills, debug, candidates }: CompileVirtualConfig) => {
|
|
22
|
+
const compiler = await compile(css, {
|
|
23
|
+
base: path.dirname(cssPath),
|
|
24
|
+
onDependency: () => void 0,
|
|
25
|
+
})
|
|
26
|
+
const scanner = new Scanner({
|
|
27
|
+
sources: [
|
|
28
|
+
...compiler.sources,
|
|
29
|
+
{
|
|
30
|
+
negated: false,
|
|
31
|
+
pattern: '**/*',
|
|
32
|
+
base: path.dirname(cssPath),
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
})
|
|
36
|
+
const tailwindCSS = compiler.build(candidates ?? scanner.scan())
|
|
37
|
+
|
|
38
|
+
if (platform === Platform.Web) {
|
|
39
|
+
return polyfillWeb(tailwindCSS)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const Processor = new ProcessorBuilder(themes, polyfills)
|
|
43
|
+
|
|
44
|
+
Logger.debug = debug === true
|
|
45
|
+
Processor.transform(tailwindCSS)
|
|
46
|
+
|
|
47
|
+
const stylesheet = serializeJSObject(
|
|
48
|
+
addMetaToStylesTemplate(Processor, platform),
|
|
49
|
+
(key, value) => `"${key}": ${value}`,
|
|
50
|
+
)
|
|
51
|
+
const vars = serializeJSObject(
|
|
52
|
+
Processor.vars,
|
|
53
|
+
(key, value) => `get "${key}"() { return ${value} }`,
|
|
54
|
+
)
|
|
55
|
+
const scopedVars = Object.fromEntries(
|
|
56
|
+
Object.entries(Processor.scopedVars)
|
|
57
|
+
.map(([scopedVarsName, scopedVars]) => [
|
|
58
|
+
scopedVarsName,
|
|
59
|
+
serializeJSObject(scopedVars, (key, value) => `get "${key}"() { return ${value} }`),
|
|
60
|
+
]),
|
|
61
|
+
)
|
|
62
|
+
const serializedScopedVars = Object.entries(scopedVars)
|
|
63
|
+
.map(([scopedVarsName, scopedVars]) => `"${scopedVarsName}": ({ ${scopedVars} }),`)
|
|
64
|
+
.join('')
|
|
65
|
+
const currentColorVar = `get currentColor() { return rt.colorScheme === 'dark' ? '#ffffff' : '#000000' },`
|
|
66
|
+
|
|
67
|
+
return [
|
|
68
|
+
'({',
|
|
69
|
+
`scopedVars: ({ ${serializedScopedVars} }),`,
|
|
70
|
+
`vars: ({ ${currentColorVar} ${vars} }),`,
|
|
71
|
+
`stylesheet: ({ ${stylesheet} }),`,
|
|
72
|
+
'})',
|
|
73
|
+
].join('')
|
|
74
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MetroConfig } from 'metro-config'
|
|
2
|
+
|
|
3
|
+
type Polyfills = {
|
|
4
|
+
rem?: number
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type UniwindConfig = {
|
|
8
|
+
cssEntryFile: string
|
|
9
|
+
extraThemes?: Array<string>
|
|
10
|
+
dtsFile?: string
|
|
11
|
+
polyfills?: Polyfills
|
|
12
|
+
debug?: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export declare function withUniwindConfig(config: MetroConfig, options: UniwindConfig): MetroConfig
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './withUniwindConfig'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { buildCSS } from '../css'
|
|
2
|
+
import { buildDtsFile } from '../utils/buildDtsFile'
|
|
3
|
+
import { stringifyThemes } from '../utils/stringifyThemes'
|
|
4
|
+
|
|
5
|
+
type InjectThemesConfig = {
|
|
6
|
+
themes: Array<string>
|
|
7
|
+
dtsPath?: string
|
|
8
|
+
input: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const injectThemes = async ({
|
|
12
|
+
themes,
|
|
13
|
+
dtsPath = 'uniwind-types.d.ts',
|
|
14
|
+
input,
|
|
15
|
+
}: InjectThemesConfig) => {
|
|
16
|
+
const stringifiedThemes = stringifyThemes(themes)
|
|
17
|
+
|
|
18
|
+
buildDtsFile(dtsPath, stringifiedThemes)
|
|
19
|
+
await buildCSS(themes, input)
|
|
20
|
+
|
|
21
|
+
// js generation
|
|
22
|
+
return stringifiedThemes
|
|
23
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
const red = '\x1b[91m'
|
|
4
|
+
const yellow = '\x1b[33m'
|
|
5
|
+
const blue = '\x1b[36m'
|
|
6
|
+
const reset = '\x1b[0m'
|
|
7
|
+
|
|
8
|
+
export class Logger {
|
|
9
|
+
static debug = false
|
|
10
|
+
|
|
11
|
+
constructor(private readonly name: string) {}
|
|
12
|
+
|
|
13
|
+
static log(message: string, meta = '') {
|
|
14
|
+
if (!Logger.debug) {
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
console.log(`${blue}Uniwind ${meta}- ${message}${reset}`)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static error(message: string, meta = '') {
|
|
22
|
+
console.log(`${red}Uniwind Error ${meta}- ${message}${reset}`)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static warn(message: string, meta = '') {
|
|
26
|
+
if (!Logger.debug) {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log(`${yellow}Uniwind Warning ${meta}- ${message}${reset}`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
log(message: string) {
|
|
34
|
+
Logger.log(message, `[${this.name} Processor] `)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
error(message: string) {
|
|
38
|
+
Logger.error(message, `[${this.name} Processor] `)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
warn(message: string) {
|
|
42
|
+
Logger.warn(message, `[${this.name} Processor] `)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Graph, Result as GraphResult } from '@expo/metro/metro/DeltaBundler/Graph'
|
|
2
|
+
import FileStoreBase from 'metro-cache/private/stores/FileStore'
|
|
3
|
+
import type { Options as GraphOptions } from 'metro/private/DeltaBundler/types'
|
|
4
|
+
import os from 'os'
|
|
5
|
+
import path from 'path'
|
|
6
|
+
|
|
7
|
+
class FileStore<T> extends FileStoreBase<T> {
|
|
8
|
+
async set(key: Buffer, value: any): Promise<void> {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
10
|
+
if (value?.output?.[0]?.data?.css?.skipCache) {
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return super.set(key, value)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const cacheStore = new FileStore<any>({
|
|
19
|
+
root: path.join(os.tmpdir(), 'metro-cache'),
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
interface TraverseDependencies {
|
|
23
|
+
(paths: readonly string[], options: GraphOptions<any>): Promise<GraphResult<any>>
|
|
24
|
+
__patched?: boolean
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const patchMetroGraphToSupportUncachedModules = () => {
|
|
28
|
+
const { Graph } = require('metro/private/DeltaBundler/Graph') as typeof import('metro/private/DeltaBundler/Graph')
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
31
|
+
const original_traverseDependencies = Graph.prototype.traverseDependencies as unknown as TraverseDependencies
|
|
32
|
+
|
|
33
|
+
if (original_traverseDependencies.__patched) {
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
original_traverseDependencies.__patched = true
|
|
38
|
+
|
|
39
|
+
function traverseDependencies(this: Graph, paths: Array<string>, options: GraphOptions<any>) {
|
|
40
|
+
this.dependencies.forEach(dependency => {
|
|
41
|
+
if (
|
|
42
|
+
dependency.output.find(file => file.data.css?.skipCache === true)
|
|
43
|
+
&& !paths.includes(dependency.path)
|
|
44
|
+
) {
|
|
45
|
+
// @ts-expect-error Hidden property
|
|
46
|
+
dependency.unstable_transformResultKey = `${dependency.unstable_transformResultKey}.`
|
|
47
|
+
paths.push(dependency.path)
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return original_traverseDependencies.call(this, paths, options)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// @ts-expect-error patch Graph traverseDependencies method
|
|
55
|
+
Graph.prototype.traverseDependencies = traverseDependencies
|
|
56
|
+
traverseDependencies.__patched = true
|
|
57
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import type { JsTransformerConfig, JsTransformOptions } from 'metro-transform-worker'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import { name } from '../../package.json'
|
|
5
|
+
import { compileVirtual } from './compileVirtual'
|
|
6
|
+
import { injectThemes } from './injectThemes'
|
|
7
|
+
import { Platform, UniwindConfig } from './types'
|
|
8
|
+
|
|
9
|
+
let worker: typeof import('metro-transform-worker')
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
try {
|
|
13
|
+
const { unstable_transformerPath } = require('@expo/metro-config') as typeof import('@expo/metro-config')
|
|
14
|
+
|
|
15
|
+
worker = require(unstable_transformerPath)
|
|
16
|
+
} catch {
|
|
17
|
+
worker = require('@expo/metro-config/build/transform-worker/transform-worker.js')
|
|
18
|
+
}
|
|
19
|
+
} catch {
|
|
20
|
+
worker = require('metro-transform-worker')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const transform = async (
|
|
24
|
+
config: JsTransformerConfig & {
|
|
25
|
+
uniwind: UniwindConfig
|
|
26
|
+
},
|
|
27
|
+
projectRoot: string,
|
|
28
|
+
filePath: string,
|
|
29
|
+
data: Buffer,
|
|
30
|
+
options: JsTransformOptions,
|
|
31
|
+
) => {
|
|
32
|
+
const isCss = options.type !== 'asset' && path.join(process.cwd(), config.uniwind.cssEntryFile) === path.join(process.cwd(), filePath)
|
|
33
|
+
|
|
34
|
+
if (filePath.endsWith('/components/web/metro-injected.js')) {
|
|
35
|
+
const cssPath = path.join(process.cwd(), config.uniwind.cssEntryFile)
|
|
36
|
+
const injectedThemesCode = await injectThemes({
|
|
37
|
+
input: cssPath,
|
|
38
|
+
themes: config.uniwind.themes,
|
|
39
|
+
dtsPath: config.uniwind.dtsFile,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
data = Buffer.from(
|
|
43
|
+
[
|
|
44
|
+
`import { Uniwind } from '${name}';`,
|
|
45
|
+
`Uniwind.__reinit(() => ({}), ${injectedThemesCode});`,
|
|
46
|
+
].join(''),
|
|
47
|
+
'utf-8',
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!isCss) {
|
|
52
|
+
return worker.transform(config, projectRoot, filePath, data, options)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const cssPath = path.join(process.cwd(), config.uniwind.cssEntryFile)
|
|
56
|
+
const injectedThemesCode = await injectThemes({
|
|
57
|
+
input: cssPath,
|
|
58
|
+
themes: config.uniwind.themes,
|
|
59
|
+
dtsPath: config.uniwind.dtsFile,
|
|
60
|
+
})
|
|
61
|
+
const css = fs.readFileSync(filePath, 'utf-8')
|
|
62
|
+
const platform = options.platform as Platform
|
|
63
|
+
const virtualCode = await compileVirtual({
|
|
64
|
+
css,
|
|
65
|
+
platform,
|
|
66
|
+
themes: config.uniwind.themes,
|
|
67
|
+
polyfills: config.uniwind.polyfills,
|
|
68
|
+
cssPath,
|
|
69
|
+
debug: config.uniwind.debug,
|
|
70
|
+
})
|
|
71
|
+
const isWeb = platform === Platform.Web
|
|
72
|
+
|
|
73
|
+
data = Buffer.from(
|
|
74
|
+
isWeb
|
|
75
|
+
? virtualCode
|
|
76
|
+
: [
|
|
77
|
+
`import { Uniwind } from '${name}';`,
|
|
78
|
+
`Uniwind.__reinit(rt => ${virtualCode}, ${injectedThemesCode});`,
|
|
79
|
+
].join(''),
|
|
80
|
+
'utf-8',
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
const transform: any = await worker.transform(
|
|
84
|
+
config,
|
|
85
|
+
projectRoot,
|
|
86
|
+
`${filePath}${isWeb ? '' : '.js'}`,
|
|
87
|
+
data,
|
|
88
|
+
options,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
transform.output[0].data.css ??= {}
|
|
92
|
+
transform.output[0].data.css.skipCache = true
|
|
93
|
+
|
|
94
|
+
if (!isWeb) {
|
|
95
|
+
transform.output[0].data.css.code = ''
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return transform
|
|
99
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { transform } from 'lightningcss'
|
|
2
|
+
import { processFunctions } from '../css/processFunctions'
|
|
3
|
+
|
|
4
|
+
export const polyfillWeb = (css: string) => {
|
|
5
|
+
const result = transform({
|
|
6
|
+
code: Buffer.from(css),
|
|
7
|
+
filename: 'uniwind.css',
|
|
8
|
+
visitor: {
|
|
9
|
+
Function: processFunctions,
|
|
10
|
+
},
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
return result.code.toString()
|
|
14
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Color as ColorType, converter, formatHex, formatHex8, parse } from 'culori'
|
|
2
|
+
import { CssColor, UnresolvedColor } from 'lightningcss'
|
|
3
|
+
import { Logger } from '../logger'
|
|
4
|
+
import { pipe } from '../utils'
|
|
5
|
+
import type { ProcessorBuilder } from './processor'
|
|
6
|
+
|
|
7
|
+
export class Color {
|
|
8
|
+
private toRgb = converter('rgb')
|
|
9
|
+
|
|
10
|
+
private readonly black = '#000000'
|
|
11
|
+
|
|
12
|
+
private readonly logger = new Logger('Color')
|
|
13
|
+
|
|
14
|
+
constructor(private readonly Processor: ProcessorBuilder) {}
|
|
15
|
+
|
|
16
|
+
processColor(color: CssColor | UnresolvedColor) {
|
|
17
|
+
if (typeof color === 'string') {
|
|
18
|
+
const parsed = parse(color)
|
|
19
|
+
|
|
20
|
+
if (parsed === undefined) {
|
|
21
|
+
this.logger.error(`Failed to convert color ${color}`)
|
|
22
|
+
|
|
23
|
+
return this.black
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return this.format(parsed)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
if (color.type === 'currentcolor') {
|
|
31
|
+
return 'this["currentColor"]'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (color.type === 'rgb' || color.type === 'srgb') {
|
|
35
|
+
const alpha = typeof color.alpha === 'number'
|
|
36
|
+
? color.alpha
|
|
37
|
+
: pipe(color.alpha)(
|
|
38
|
+
x => this.Processor.CSS.processValue(x),
|
|
39
|
+
Number,
|
|
40
|
+
x => isNaN(x) ? 1 : x,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
return this.format({
|
|
44
|
+
r: color.r / 255,
|
|
45
|
+
g: color.g / 255,
|
|
46
|
+
b: color.b / 255,
|
|
47
|
+
alpha,
|
|
48
|
+
mode: 'rgb',
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const result = this.toRgb({
|
|
53
|
+
mode: color.type,
|
|
54
|
+
...color,
|
|
55
|
+
} as ColorType)
|
|
56
|
+
|
|
57
|
+
return this.format(result)
|
|
58
|
+
} catch {
|
|
59
|
+
this.logger.error(`Failed to convert color ${JSON.stringify(color)}`)
|
|
60
|
+
|
|
61
|
+
return this.black
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
isColor(value: unknown): value is CssColor {
|
|
66
|
+
return typeof value === 'string' && parse(value) !== undefined
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private format(color: ColorType) {
|
|
70
|
+
if (color.alpha === 1 || color.alpha === undefined) {
|
|
71
|
+
return formatHex(color)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return formatHex8(color)
|
|
75
|
+
}
|
|
76
|
+
}
|