@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,73 @@
|
|
|
1
|
+
const types = ['m', 'p'] as const
|
|
2
|
+
const sides = ['', 'x', 'y', 't', 'b', 'l', 'r'] as const
|
|
3
|
+
const spacing = '--spacing(--value(integer))'
|
|
4
|
+
const length = '--value([length])'
|
|
5
|
+
|
|
6
|
+
type Side = (typeof sides)[number]
|
|
7
|
+
|
|
8
|
+
export const generateCSSForInsets = () => {
|
|
9
|
+
let css = `@utility h-screen-safe {
|
|
10
|
+
height: calc(100vh - (env(safe-area-inset-top) + env(safe-area-inset-bottom)));
|
|
11
|
+
}\n`
|
|
12
|
+
|
|
13
|
+
const getInsetsForSide = (side: Side) => {
|
|
14
|
+
switch (side) {
|
|
15
|
+
case 't':
|
|
16
|
+
return ['top']
|
|
17
|
+
case 'b':
|
|
18
|
+
return ['bottom']
|
|
19
|
+
case 'l':
|
|
20
|
+
return ['left']
|
|
21
|
+
case 'r':
|
|
22
|
+
return ['right']
|
|
23
|
+
case 'x':
|
|
24
|
+
return ['left', 'right']
|
|
25
|
+
case 'y':
|
|
26
|
+
return ['top', 'bottom']
|
|
27
|
+
default:
|
|
28
|
+
return ['top', 'bottom', 'left', 'right']
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
types.forEach(type => {
|
|
33
|
+
sides.forEach(side => {
|
|
34
|
+
const styleName = type === 'm' ? 'margin' : 'padding'
|
|
35
|
+
const insets = getInsetsForSide(side)
|
|
36
|
+
const styles = insets.map(inset => `${styleName}-${inset}: env(safe-area-inset-${inset});`)
|
|
37
|
+
const safeStyles = styles.flatMap(style => {
|
|
38
|
+
const styleWithoutSemicolon = style.replace(';', '')
|
|
39
|
+
|
|
40
|
+
return [
|
|
41
|
+
styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: max(${env}, ${spacing});`),
|
|
42
|
+
styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: max(${env}, ${length});`),
|
|
43
|
+
]
|
|
44
|
+
})
|
|
45
|
+
const safeOffsetStyles = styles.flatMap(style => {
|
|
46
|
+
const styleWithoutSemicolon = style.replace(';', '')
|
|
47
|
+
|
|
48
|
+
return [
|
|
49
|
+
styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: calc(${env} + ${spacing});`),
|
|
50
|
+
styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: calc(${env} + ${length});`),
|
|
51
|
+
]
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
css += `
|
|
55
|
+
@utility ${type}${side}-safe {
|
|
56
|
+
${styles.join('\n ')}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@utility ${type}${side}-safe-or-* {
|
|
60
|
+
${safeStyles.join('\n ')}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@utility ${type}${side}-safe-offset-* {
|
|
64
|
+
${safeOffsetStyles.join('\n ')}
|
|
65
|
+
}
|
|
66
|
+
`
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
// Remove all 8 spaces groups
|
|
71
|
+
// eslint-disable-next-line prefer-template
|
|
72
|
+
return css.replaceAll(' ', '').trim() + '\n'
|
|
73
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CustomAtRules, TokenOrValue, Visitor } from 'lightningcss'
|
|
2
|
+
|
|
3
|
+
const ONE_PX = {
|
|
4
|
+
type: 'token',
|
|
5
|
+
value: { type: 'dimension', unit: 'px', value: 1 },
|
|
6
|
+
} satisfies TokenOrValue
|
|
7
|
+
|
|
8
|
+
export const processFunctions: Visitor<CustomAtRules>['Function'] = {
|
|
9
|
+
pixelRatio: (fn) => {
|
|
10
|
+
return {
|
|
11
|
+
type: 'function',
|
|
12
|
+
value: {
|
|
13
|
+
name: 'calc',
|
|
14
|
+
arguments: [
|
|
15
|
+
fn.arguments.at(0) ?? ONE_PX,
|
|
16
|
+
{ type: 'token', value: { type: 'delim', value: '*' } },
|
|
17
|
+
ONE_PX,
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
} satisfies TokenOrValue
|
|
21
|
+
},
|
|
22
|
+
fontScale: (fn) => {
|
|
23
|
+
return {
|
|
24
|
+
type: 'function',
|
|
25
|
+
value: {
|
|
26
|
+
name: 'calc',
|
|
27
|
+
arguments: [
|
|
28
|
+
fn.arguments.at(0) ?? ONE_PX,
|
|
29
|
+
{ type: 'token', value: { type: 'delim', value: '*' } },
|
|
30
|
+
{
|
|
31
|
+
type: 'token',
|
|
32
|
+
value: { type: 'dimension', value: 1, unit: 'rem' },
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
} satisfies TokenOrValue
|
|
37
|
+
},
|
|
38
|
+
hairlineWidth: () => ONE_PX,
|
|
39
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { compile } from '@tailwindcss/node'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import { transform } from 'lightningcss'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import { Logger } from '../metro/logger'
|
|
6
|
+
|
|
7
|
+
const readFileSafe = (filePath: string) => {
|
|
8
|
+
try {
|
|
9
|
+
return fs.readFileSync(filePath, 'utf-8')
|
|
10
|
+
} catch {
|
|
11
|
+
return null
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const isExcludedDependency = (url: string) =>
|
|
16
|
+
[
|
|
17
|
+
url.includes('node_modules/tailwindcss'),
|
|
18
|
+
url.includes('node_modules/@tailwindcss'),
|
|
19
|
+
url.includes('node_modules/uniwind'),
|
|
20
|
+
].some(Boolean)
|
|
21
|
+
|
|
22
|
+
export const generateCSSForThemes = async (themes: Array<string>, input: string) => {
|
|
23
|
+
// css generation
|
|
24
|
+
const themesVariables = Object.fromEntries(themes.map(theme => [theme, new Set<string>()]))
|
|
25
|
+
|
|
26
|
+
const findVariantsRec = async (cssPath: string) => {
|
|
27
|
+
const css = readFileSafe(cssPath)
|
|
28
|
+
|
|
29
|
+
if (css === null) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const { dependencies } = transform({
|
|
34
|
+
code: Buffer.from(css),
|
|
35
|
+
filename: 'uniwind.css',
|
|
36
|
+
analyzeDependencies: true,
|
|
37
|
+
visitor: {
|
|
38
|
+
Rule: rule => {
|
|
39
|
+
if (rule.type === 'unknown' && rule.value.name === 'variant') {
|
|
40
|
+
const [firstPrelude] = rule.value.prelude
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
firstPrelude?.type !== 'token'
|
|
44
|
+
|| firstPrelude.value.type !== 'ident'
|
|
45
|
+
|| !themes.includes(firstPrelude.value.value)
|
|
46
|
+
) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const theme = firstPrelude.value.value
|
|
51
|
+
|
|
52
|
+
rule.value.block?.forEach(block => {
|
|
53
|
+
if (block.type === 'dashed-ident') {
|
|
54
|
+
themesVariables[theme]?.add(block.value)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
if (!Array.isArray(dependencies)) {
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const importUrls = new Set<string>()
|
|
67
|
+
const importsCSS = dependencies
|
|
68
|
+
.filter(dependency => {
|
|
69
|
+
if (dependency.url.startsWith('.')) {
|
|
70
|
+
importUrls.add(path.resolve(path.dirname(cssPath), dependency.url))
|
|
71
|
+
|
|
72
|
+
return false
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return !isExcludedDependency(dependency.url)
|
|
76
|
+
})
|
|
77
|
+
.map(dependency => `@import "${dependency.url}";`).join('\n')
|
|
78
|
+
|
|
79
|
+
await compile(importsCSS, {
|
|
80
|
+
base: path.resolve(path.dirname(cssPath)),
|
|
81
|
+
onDependency: dependency => {
|
|
82
|
+
if (isExcludedDependency(dependency)) {
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
importUrls.add(dependency)
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
for (const filePath of importUrls) {
|
|
91
|
+
await findVariantsRec(filePath)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
await findVariantsRec(input)
|
|
96
|
+
|
|
97
|
+
// Check if all themes have the same variables
|
|
98
|
+
let hasErrors = false as boolean
|
|
99
|
+
const hasVariables = Object.values(themesVariables).some(variables => variables.size > 0)
|
|
100
|
+
|
|
101
|
+
Object.values(themesVariables).forEach(variables => {
|
|
102
|
+
Object.entries(themesVariables).forEach(([checkedTheme, checkedVariables]) => {
|
|
103
|
+
variables.forEach(variable => {
|
|
104
|
+
if (!checkedVariables.has(variable)) {
|
|
105
|
+
Logger.error(`Theme ${checkedTheme} is missing variable ${variable}`)
|
|
106
|
+
hasErrors = true
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
if (hasErrors) {
|
|
113
|
+
Logger.error('All themes must have the same variables')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const variablesCSS = hasVariables
|
|
117
|
+
? [
|
|
118
|
+
'',
|
|
119
|
+
'@theme {',
|
|
120
|
+
...Array.from(Object.values(themesVariables).at(0) ?? []).map(variable => ` ${variable}: unset;`),
|
|
121
|
+
'}',
|
|
122
|
+
]
|
|
123
|
+
: []
|
|
124
|
+
const uniwindCSS = [
|
|
125
|
+
...themes.map(theme => `@custom-variant ${theme} (&:where(.${theme}, .${theme} *));`),
|
|
126
|
+
...variablesCSS,
|
|
127
|
+
].join('\n')
|
|
128
|
+
|
|
129
|
+
return uniwindCSS
|
|
130
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const variants = ['ios', 'android', 'web', 'native']
|
|
2
|
+
|
|
3
|
+
export const generateCSSForVariants = () => {
|
|
4
|
+
let css = ''
|
|
5
|
+
|
|
6
|
+
variants.forEach(variant => {
|
|
7
|
+
css += `@custom-variant ${variant} (${variant === 'web' ? 'html &' : `@media ${variant}`});\n`
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
return css
|
|
11
|
+
}
|
package/src/hoc/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './withUniwind'
|
package/src/hoc/types.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ComponentProps, ComponentPropsWithRef } from 'react'
|
|
2
|
+
import { RNStyle } from '../core/types'
|
|
3
|
+
|
|
4
|
+
export type AnyObject = Record<PropertyKey, any>
|
|
5
|
+
|
|
6
|
+
type StyleToClass<K extends PropertyKey> = K extends 'style' ? 'className'
|
|
7
|
+
: K extends `${infer StyleProp}Style` ? `${StyleProp}ClassName`
|
|
8
|
+
: never
|
|
9
|
+
|
|
10
|
+
type ColorPropToClass<K extends PropertyKey> = K extends 'color' ? 'colorClassName'
|
|
11
|
+
: K extends `${string}Color` | `${string}color${string}` ? `${K}ClassName`
|
|
12
|
+
: never
|
|
13
|
+
|
|
14
|
+
export type ApplyUniwind<TProps extends AnyObject> =
|
|
15
|
+
& {
|
|
16
|
+
[K in keyof TProps as StyleToClass<K>]?: string
|
|
17
|
+
}
|
|
18
|
+
& {
|
|
19
|
+
[K in keyof TProps as ColorPropToClass<K>]?: string
|
|
20
|
+
}
|
|
21
|
+
& TProps
|
|
22
|
+
|
|
23
|
+
export type ApplyUniwindOptions<TProps extends AnyObject, TOptions extends { [K in keyof TProps]?: OptionMapping }> =
|
|
24
|
+
& {
|
|
25
|
+
// @ts-expect-error TS isn't smart enough to infer this
|
|
26
|
+
[K in keyof TOptions as TOptions[K] extends undefined ? never : TOptions[K]['fromClassName']]?: string
|
|
27
|
+
}
|
|
28
|
+
& TProps
|
|
29
|
+
|
|
30
|
+
export type Component<T extends AnyObject = AnyObject> = React.JSXElementConstructor<T>
|
|
31
|
+
|
|
32
|
+
export type OptionMapping = {
|
|
33
|
+
fromClassName: string
|
|
34
|
+
styleProperty?: keyof RNStyle
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type WithUniwind = {
|
|
38
|
+
// Auto mapping
|
|
39
|
+
<TComponent extends Component<any>>(Component: TComponent): (props: ApplyUniwind<ComponentPropsWithRef<TComponent>> & {}) => React.ReactNode
|
|
40
|
+
// Manual mapping
|
|
41
|
+
<TComponent extends Component<any>, const TOptions extends { [K in keyof ComponentProps<TComponent>]?: OptionMapping }>(
|
|
42
|
+
Component: TComponent,
|
|
43
|
+
options: TOptions,
|
|
44
|
+
): (props: ApplyUniwindOptions<ComponentPropsWithRef<TComponent>, TOptions> & {}) => React.ReactNode
|
|
45
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { ComponentProps, useEffect, useReducer } from 'react'
|
|
2
|
+
import { UniwindListener } from '../core/listener'
|
|
3
|
+
import { UniwindStore } from '../core/native'
|
|
4
|
+
import { StyleDependency } from '../types'
|
|
5
|
+
import { AnyObject, Component, OptionMapping, WithUniwind } from './types'
|
|
6
|
+
import { classToColor, classToStyle, isClassProperty, isColorClassProperty, isStyleProperty } from './withUniwindUtils'
|
|
7
|
+
|
|
8
|
+
export const withUniwind: WithUniwind = <
|
|
9
|
+
TComponent extends Component,
|
|
10
|
+
TOptions extends Record<keyof ComponentProps<TComponent>, OptionMapping>,
|
|
11
|
+
>(
|
|
12
|
+
Component: TComponent,
|
|
13
|
+
options?: TOptions,
|
|
14
|
+
) => options
|
|
15
|
+
? withManualUniwind(Component, options)
|
|
16
|
+
: withAutoUniwind(Component)
|
|
17
|
+
|
|
18
|
+
const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject) => {
|
|
19
|
+
const { dependencies, generatedProps } = Object.entries(props).reduce((acc, [propName, propValue]) => {
|
|
20
|
+
if (isColorClassProperty(propName)) {
|
|
21
|
+
const colorProp = classToColor(propName)
|
|
22
|
+
|
|
23
|
+
if (props[colorProp] !== undefined) {
|
|
24
|
+
return acc
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const { styles, dependencies } = UniwindStore.getStyles(propValue)
|
|
28
|
+
|
|
29
|
+
acc.dependencies.push(...dependencies)
|
|
30
|
+
acc.generatedProps[colorProp] = styles.accentColor
|
|
31
|
+
|
|
32
|
+
return acc
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (isClassProperty(propName)) {
|
|
36
|
+
const styleProp = classToStyle(propName)
|
|
37
|
+
const { styles, dependencies } = UniwindStore.getStyles(propValue)
|
|
38
|
+
|
|
39
|
+
acc.dependencies.push(...dependencies)
|
|
40
|
+
acc.generatedProps[styleProp] ??= []
|
|
41
|
+
acc.generatedProps[styleProp][0] = styles
|
|
42
|
+
|
|
43
|
+
return acc
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (isStyleProperty(propName)) {
|
|
47
|
+
acc.generatedProps[propName] ??= []
|
|
48
|
+
acc.generatedProps[propName][1] = propValue
|
|
49
|
+
|
|
50
|
+
return acc
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return acc
|
|
54
|
+
}, { generatedProps: {} as AnyObject, dependencies: [] as Array<StyleDependency> })
|
|
55
|
+
|
|
56
|
+
const deps = Array.from(new Set(dependencies))
|
|
57
|
+
const [, rerender] = useReducer(() => ({}), {})
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
const dispose = UniwindListener.subscribe(rerender, deps)
|
|
61
|
+
|
|
62
|
+
return dispose
|
|
63
|
+
}, [deps])
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<Component
|
|
67
|
+
{...props}
|
|
68
|
+
{...generatedProps}
|
|
69
|
+
/>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const withManualUniwind = (Component: Component<AnyObject>, options: Record<PropertyKey, OptionMapping>) => (props: AnyObject) => {
|
|
74
|
+
const { generatedProps, dependencies } = Object.entries(options).reduce((acc, [propName, option]) => {
|
|
75
|
+
const className = props[option.fromClassName]
|
|
76
|
+
|
|
77
|
+
if (className === undefined) {
|
|
78
|
+
return acc
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (option.styleProperty !== undefined) {
|
|
82
|
+
// If the prop is already defined, we don't want to override it
|
|
83
|
+
if (props[propName] !== undefined) {
|
|
84
|
+
return acc
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const { styles, dependencies } = UniwindStore.getStyles(className)
|
|
88
|
+
|
|
89
|
+
acc.generatedProps[propName] = styles[option.styleProperty]
|
|
90
|
+
acc.dependencies.push(...dependencies)
|
|
91
|
+
|
|
92
|
+
return acc
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const { styles, dependencies } = UniwindStore.getStyles(className)
|
|
96
|
+
|
|
97
|
+
acc.generatedProps[propName] = styles
|
|
98
|
+
acc.dependencies.push(...dependencies)
|
|
99
|
+
|
|
100
|
+
return acc
|
|
101
|
+
}, { generatedProps: {} as AnyObject, dependencies: [] as Array<StyleDependency> })
|
|
102
|
+
|
|
103
|
+
const deps = Array.from(new Set(dependencies))
|
|
104
|
+
const [, rerender] = useReducer(() => ({}), {})
|
|
105
|
+
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
const dispose = UniwindListener.subscribe(rerender, deps)
|
|
108
|
+
|
|
109
|
+
return dispose
|
|
110
|
+
}, [deps])
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<Component
|
|
114
|
+
{...props}
|
|
115
|
+
{...generatedProps}
|
|
116
|
+
/>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { ComponentProps, useEffect, useReducer } from 'react'
|
|
2
|
+
import { CSSListener, formatColor, getWebStyles } from '../core/web'
|
|
3
|
+
import { AnyObject, Component, OptionMapping, WithUniwind } from './types'
|
|
4
|
+
import { classToColor, classToStyle, isClassProperty, isColorClassProperty, isStyleProperty } from './withUniwindUtils'
|
|
5
|
+
|
|
6
|
+
export const withUniwind: WithUniwind = <
|
|
7
|
+
TComponent extends Component,
|
|
8
|
+
TOptions extends Record<keyof ComponentProps<TComponent>, OptionMapping>,
|
|
9
|
+
>(
|
|
10
|
+
Component: TComponent,
|
|
11
|
+
options?: TOptions,
|
|
12
|
+
) => options
|
|
13
|
+
? withManualUniwind(Component, options)
|
|
14
|
+
: withAutoUniwind(Component)
|
|
15
|
+
|
|
16
|
+
const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject) => {
|
|
17
|
+
const { classNames, generatedProps } = Object.entries(props).reduce((acc, [propName, propValue]) => {
|
|
18
|
+
if (isColorClassProperty(propName)) {
|
|
19
|
+
const colorProp = classToColor(propName)
|
|
20
|
+
|
|
21
|
+
if (props[colorProp] !== undefined) {
|
|
22
|
+
return acc
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const className = propValue
|
|
26
|
+
const color = getWebStyles(className).accentColor
|
|
27
|
+
|
|
28
|
+
acc.generatedProps[colorProp] = color !== undefined
|
|
29
|
+
? formatColor(color)
|
|
30
|
+
: undefined
|
|
31
|
+
acc.classNames += `${className} `
|
|
32
|
+
|
|
33
|
+
return acc
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (isClassProperty(propName)) {
|
|
37
|
+
const styleProp = classToStyle(propName)
|
|
38
|
+
|
|
39
|
+
acc.generatedProps[styleProp] ??= []
|
|
40
|
+
acc.generatedProps[styleProp][0] = { $$css: true, tailwind: propValue }
|
|
41
|
+
|
|
42
|
+
return acc
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (isStyleProperty(propName)) {
|
|
46
|
+
acc.generatedProps[propName] ??= []
|
|
47
|
+
acc.generatedProps[propName][1] = propValue
|
|
48
|
+
|
|
49
|
+
return acc
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return acc
|
|
53
|
+
}, { generatedProps: {} as AnyObject, classNames: '' })
|
|
54
|
+
|
|
55
|
+
const [, rerender] = useReducer(() => ({}), {})
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
const dispose = CSSListener.subscribeToClassName(classNames, rerender)
|
|
59
|
+
|
|
60
|
+
return dispose
|
|
61
|
+
}, [classNames])
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Component
|
|
65
|
+
{...props}
|
|
66
|
+
{...generatedProps}
|
|
67
|
+
/>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const withManualUniwind = (Component: Component<AnyObject>, options: Record<PropertyKey, OptionMapping>) => (props: AnyObject) => {
|
|
72
|
+
const { generatedProps, classNames } = Object.entries(options).reduce((acc, [propName, option]) => {
|
|
73
|
+
const className = props[option.fromClassName]
|
|
74
|
+
|
|
75
|
+
if (className === undefined) {
|
|
76
|
+
return acc
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (option.styleProperty !== undefined) {
|
|
80
|
+
// If the prop is already defined, we don't want to override it
|
|
81
|
+
if (props[propName] !== undefined) {
|
|
82
|
+
return acc
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const value = getWebStyles(className)[option.styleProperty]
|
|
86
|
+
const transformedValue = value !== undefined && option.styleProperty.toLowerCase().includes('color')
|
|
87
|
+
? formatColor(value as string)
|
|
88
|
+
: value
|
|
89
|
+
|
|
90
|
+
acc.classNames += `${className} `
|
|
91
|
+
acc.generatedProps[propName] = transformedValue
|
|
92
|
+
|
|
93
|
+
return acc
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
acc.generatedProps[propName] = [{ $$css: true, tailwind: className }, props[propName]]
|
|
97
|
+
|
|
98
|
+
return acc
|
|
99
|
+
}, { generatedProps: {} as AnyObject, classNames: '' })
|
|
100
|
+
|
|
101
|
+
const [, rerender] = useReducer(() => ({}), {})
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
const dispose = CSSListener.subscribeToClassName(classNames, rerender)
|
|
105
|
+
|
|
106
|
+
return dispose
|
|
107
|
+
}, [classNames])
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<Component
|
|
111
|
+
{...props}
|
|
112
|
+
{...generatedProps}
|
|
113
|
+
/>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const classToStyle = (className: string) =>
|
|
2
|
+
className === 'className'
|
|
3
|
+
? 'style'
|
|
4
|
+
: className.replace('ClassName', 'Style')
|
|
5
|
+
|
|
6
|
+
export const classToColor = (className: string) => className.replace('ClassName', '')
|
|
7
|
+
|
|
8
|
+
export const isColorClassProperty = (prop: string) => prop.toLowerCase().includes('color') && prop.endsWith('ClassName')
|
|
9
|
+
export const isClassProperty = (prop: string) => prop === 'className' || prop.endsWith('ClassName')
|
|
10
|
+
export const isStyleProperty = (prop: string) => prop === 'style' || prop.endsWith('Style')
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { parseCSSValue } from '../../core/web'
|
|
2
|
+
|
|
3
|
+
const documentStyles = typeof document !== 'undefined'
|
|
4
|
+
? window.getComputedStyle(document.documentElement)
|
|
5
|
+
: null
|
|
6
|
+
|
|
7
|
+
export const getVariableValue = (name: string) => {
|
|
8
|
+
if (!documentStyles) {
|
|
9
|
+
return undefined
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const value = documentStyles.getPropertyValue(name).trim()
|
|
13
|
+
|
|
14
|
+
if (value === '') {
|
|
15
|
+
return undefined
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return parseCSSValue(value)
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useCSSVariable'
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
import { UniwindListener } from '../../core/listener'
|
|
3
|
+
import { Logger } from '../../core/logger'
|
|
4
|
+
import { StyleDependency } from '../../types'
|
|
5
|
+
import { getVariableValue } from './getVariableValue'
|
|
6
|
+
|
|
7
|
+
const getValue = (name: string | Array<string>) =>
|
|
8
|
+
Array.isArray(name)
|
|
9
|
+
? name.map(getVariableValue)
|
|
10
|
+
: getVariableValue(name)
|
|
11
|
+
|
|
12
|
+
const arrayEquals = <T>(a: Array<T>, b: Array<T>) => {
|
|
13
|
+
if (a.length !== b.length) {
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return a.every((value, index) => value === b[index])
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let warned = false
|
|
21
|
+
|
|
22
|
+
const logDevError = (name: string) => {
|
|
23
|
+
warned = true
|
|
24
|
+
Logger.warn(
|
|
25
|
+
`We couldn't find your variable ${name}. Make sure it's used at least once in your className, or define it in a static theme as described in the docs: https://docs.uniwind.dev/api/use-css-variable`,
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type IsGenericNumber<T> = T & 0 extends -1 ? false : true
|
|
30
|
+
type CreateArray<N extends number, Value, TAcc extends Array<Value> = []> = TAcc['length'] extends N ? TAcc : CreateArray<N, Value, [...TAcc, Value]>
|
|
31
|
+
|
|
32
|
+
type UseCSSVariable = {
|
|
33
|
+
(name: string): string | number | undefined
|
|
34
|
+
<const T extends Array<string>>(
|
|
35
|
+
names: T,
|
|
36
|
+
): IsGenericNumber<T['length']> extends true ? Array<string | number | undefined> : CreateArray<T['length'], string | number | undefined>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A hook that returns the value of a CSS variable.
|
|
41
|
+
* @param name Name / Array of names of the CSS variable.
|
|
42
|
+
* @returns Value / Values of the CSS variable. On web it is always a string (1rem, #ff0000, etc.), but on native it can be a string or a number (16px, #ff0000)
|
|
43
|
+
*/
|
|
44
|
+
export const useCSSVariable: UseCSSVariable = (name: string | Array<string>) => {
|
|
45
|
+
const [value, setValue] = useState(getValue(name))
|
|
46
|
+
const nameRef = useRef(name)
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (Array.isArray(name) && Array.isArray(nameRef.current)) {
|
|
50
|
+
if (arrayEquals(name, nameRef.current)) {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
setValue(getValue(name))
|
|
55
|
+
nameRef.current = name
|
|
56
|
+
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (name !== nameRef.current) {
|
|
61
|
+
setValue(getValue(name))
|
|
62
|
+
nameRef.current = name
|
|
63
|
+
}
|
|
64
|
+
}, [name])
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const updateValue = () => setValue(getValue(nameRef.current))
|
|
68
|
+
const dispose = UniwindListener.subscribe(
|
|
69
|
+
updateValue,
|
|
70
|
+
[StyleDependency.Theme, StyleDependency.Variables],
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
return dispose
|
|
74
|
+
}, [])
|
|
75
|
+
|
|
76
|
+
if (Array.isArray(value)) {
|
|
77
|
+
value.forEach((val, index) => {
|
|
78
|
+
if (val === undefined && __DEV__ && !warned) {
|
|
79
|
+
logDevError(name[index] ?? '')
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (value === undefined && __DEV__ && !warned) {
|
|
85
|
+
logDevError(name as string)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return value as never
|
|
89
|
+
}
|