@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 @@
|
|
|
1
|
+
export declare const parseCSSValue: (value: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const buildCSS: (themes: Array<string>, input: string) => Promise<void>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { generateCSSForInsets } from "./insets.js";
|
|
4
|
+
import { generateCSSForThemes } from "./themes.js";
|
|
5
|
+
import { generateCSSForVariants } from "./variants.js";
|
|
6
|
+
const dirname = typeof __dirname !== "undefined" ? __dirname : import.meta.dirname;
|
|
7
|
+
export const buildCSS = async (themes, input) => {
|
|
8
|
+
const variants = generateCSSForVariants();
|
|
9
|
+
const insets = generateCSSForInsets();
|
|
10
|
+
const themesCSS = await generateCSSForThemes(themes, input);
|
|
11
|
+
const cssFilePath = path.join(dirname, "../../uniwind.css");
|
|
12
|
+
const oldCSSFile = fs.existsSync(cssFilePath) ? fs.readFileSync(cssFilePath, "utf-8") : "";
|
|
13
|
+
const newCssFile = [
|
|
14
|
+
variants,
|
|
15
|
+
insets,
|
|
16
|
+
themesCSS
|
|
17
|
+
].join("\n");
|
|
18
|
+
if (oldCSSFile === newCssFile) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
fs.writeFileSync(
|
|
22
|
+
cssFilePath,
|
|
23
|
+
newCssFile
|
|
24
|
+
);
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateCSSForInsets: () => string;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const types = ["m", "p"];
|
|
2
|
+
const sides = ["", "x", "y", "t", "b", "l", "r"];
|
|
3
|
+
const spacing = "--spacing(--value(integer))";
|
|
4
|
+
const length = "--value([length])";
|
|
5
|
+
export const generateCSSForInsets = () => {
|
|
6
|
+
let css = `@utility h-screen-safe {
|
|
7
|
+
height: calc(100vh - (env(safe-area-inset-top) + env(safe-area-inset-bottom)));
|
|
8
|
+
}
|
|
9
|
+
`;
|
|
10
|
+
const getInsetsForSide = (side) => {
|
|
11
|
+
switch (side) {
|
|
12
|
+
case "t":
|
|
13
|
+
return ["top"];
|
|
14
|
+
case "b":
|
|
15
|
+
return ["bottom"];
|
|
16
|
+
case "l":
|
|
17
|
+
return ["left"];
|
|
18
|
+
case "r":
|
|
19
|
+
return ["right"];
|
|
20
|
+
case "x":
|
|
21
|
+
return ["left", "right"];
|
|
22
|
+
case "y":
|
|
23
|
+
return ["top", "bottom"];
|
|
24
|
+
default:
|
|
25
|
+
return ["top", "bottom", "left", "right"];
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
types.forEach((type) => {
|
|
29
|
+
sides.forEach((side) => {
|
|
30
|
+
const styleName = type === "m" ? "margin" : "padding";
|
|
31
|
+
const insets = getInsetsForSide(side);
|
|
32
|
+
const styles = insets.map((inset) => `${styleName}-${inset}: env(safe-area-inset-${inset});`);
|
|
33
|
+
const safeStyles = styles.flatMap((style) => {
|
|
34
|
+
const styleWithoutSemicolon = style.replace(";", "");
|
|
35
|
+
return [
|
|
36
|
+
styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: max(${env}, ${spacing});`),
|
|
37
|
+
styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: max(${env}, ${length});`)
|
|
38
|
+
];
|
|
39
|
+
});
|
|
40
|
+
const safeOffsetStyles = styles.flatMap((style) => {
|
|
41
|
+
const styleWithoutSemicolon = style.replace(";", "");
|
|
42
|
+
return [
|
|
43
|
+
styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: calc(${env} + ${spacing});`),
|
|
44
|
+
styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: calc(${env} + ${length});`)
|
|
45
|
+
];
|
|
46
|
+
});
|
|
47
|
+
css += `
|
|
48
|
+
@utility ${type}${side}-safe {
|
|
49
|
+
${styles.join("\n ")}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@utility ${type}${side}-safe-or-* {
|
|
53
|
+
${safeStyles.join("\n ")}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@utility ${type}${side}-safe-offset-* {
|
|
57
|
+
${safeOffsetStyles.join("\n ")}
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
return css.replaceAll(" ", "").trim() + "\n";
|
|
63
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const ONE_PX = {
|
|
2
|
+
type: "token",
|
|
3
|
+
value: { type: "dimension", unit: "px", value: 1 }
|
|
4
|
+
};
|
|
5
|
+
export const processFunctions = {
|
|
6
|
+
pixelRatio: (fn) => {
|
|
7
|
+
return {
|
|
8
|
+
type: "function",
|
|
9
|
+
value: {
|
|
10
|
+
name: "calc",
|
|
11
|
+
arguments: [
|
|
12
|
+
fn.arguments.at(0) ?? ONE_PX,
|
|
13
|
+
{ type: "token", value: { type: "delim", value: "*" } },
|
|
14
|
+
ONE_PX
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
fontScale: (fn) => {
|
|
20
|
+
return {
|
|
21
|
+
type: "function",
|
|
22
|
+
value: {
|
|
23
|
+
name: "calc",
|
|
24
|
+
arguments: [
|
|
25
|
+
fn.arguments.at(0) ?? ONE_PX,
|
|
26
|
+
{ type: "token", value: { type: "delim", value: "*" } },
|
|
27
|
+
{
|
|
28
|
+
type: "token",
|
|
29
|
+
value: { type: "dimension", value: 1, unit: "rem" }
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
hairlineWidth: () => ONE_PX
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateCSSForThemes: (themes: Array<string>, input: string) => Promise<string>;
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
const readFileSafe = (filePath) => {
|
|
7
|
+
try {
|
|
8
|
+
return fs.readFileSync(filePath, "utf-8");
|
|
9
|
+
} catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const isExcludedDependency = (url) => [
|
|
14
|
+
url.includes("node_modules/tailwindcss"),
|
|
15
|
+
url.includes("node_modules/@tailwindcss"),
|
|
16
|
+
url.includes("node_modules/uniwind")
|
|
17
|
+
].some(Boolean);
|
|
18
|
+
export const generateCSSForThemes = async (themes, input) => {
|
|
19
|
+
const themesVariables = Object.fromEntries(themes.map((theme) => [theme, /* @__PURE__ */ new Set()]));
|
|
20
|
+
const findVariantsRec = async (cssPath) => {
|
|
21
|
+
const css = readFileSafe(cssPath);
|
|
22
|
+
if (css === null) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const { dependencies } = transform({
|
|
26
|
+
code: Buffer.from(css),
|
|
27
|
+
filename: "uniwind.css",
|
|
28
|
+
analyzeDependencies: true,
|
|
29
|
+
visitor: {
|
|
30
|
+
Rule: (rule) => {
|
|
31
|
+
if (rule.type === "unknown" && rule.value.name === "variant") {
|
|
32
|
+
const [firstPrelude] = rule.value.prelude;
|
|
33
|
+
if (firstPrelude?.type !== "token" || firstPrelude.value.type !== "ident" || !themes.includes(firstPrelude.value.value)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const theme = firstPrelude.value.value;
|
|
37
|
+
rule.value.block?.forEach((block) => {
|
|
38
|
+
if (block.type === "dashed-ident") {
|
|
39
|
+
themesVariables[theme]?.add(block.value);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
if (!Array.isArray(dependencies)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const importUrls = /* @__PURE__ */ new Set();
|
|
50
|
+
const importsCSS = dependencies.filter((dependency) => {
|
|
51
|
+
if (dependency.url.startsWith(".")) {
|
|
52
|
+
importUrls.add(path.resolve(path.dirname(cssPath), dependency.url));
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return !isExcludedDependency(dependency.url);
|
|
56
|
+
}).map((dependency) => `@import "${dependency.url}";`).join("\n");
|
|
57
|
+
await compile(importsCSS, {
|
|
58
|
+
base: path.resolve(path.dirname(cssPath)),
|
|
59
|
+
onDependency: (dependency) => {
|
|
60
|
+
if (isExcludedDependency(dependency)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
importUrls.add(dependency);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
for (const filePath of importUrls) {
|
|
67
|
+
await findVariantsRec(filePath);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
await findVariantsRec(input);
|
|
71
|
+
let hasErrors = false;
|
|
72
|
+
const hasVariables = Object.values(themesVariables).some((variables) => variables.size > 0);
|
|
73
|
+
Object.values(themesVariables).forEach((variables) => {
|
|
74
|
+
Object.entries(themesVariables).forEach(([checkedTheme, checkedVariables]) => {
|
|
75
|
+
variables.forEach((variable) => {
|
|
76
|
+
if (!checkedVariables.has(variable)) {
|
|
77
|
+
Logger.error(`Theme ${checkedTheme} is missing variable ${variable}`);
|
|
78
|
+
hasErrors = true;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
if (hasErrors) {
|
|
84
|
+
Logger.error("All themes must have the same variables");
|
|
85
|
+
}
|
|
86
|
+
const variablesCSS = hasVariables ? [
|
|
87
|
+
"",
|
|
88
|
+
"@theme {",
|
|
89
|
+
...Array.from(Object.values(themesVariables).at(0) ?? []).map((variable) => ` ${variable}: unset;`),
|
|
90
|
+
"}"
|
|
91
|
+
] : [];
|
|
92
|
+
const uniwindCSS = [
|
|
93
|
+
...themes.map((theme) => `@custom-variant ${theme} (&:where(.${theme}, .${theme} *));`),
|
|
94
|
+
...variablesCSS
|
|
95
|
+
].join("\n");
|
|
96
|
+
return uniwindCSS;
|
|
97
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateCSSForVariants: () => string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const variants = ["ios", "android", "web", "native"];
|
|
2
|
+
export const generateCSSForVariants = () => {
|
|
3
|
+
let css = "";
|
|
4
|
+
variants.forEach((variant) => {
|
|
5
|
+
css += `@custom-variant ${variant} (${variant === "web" ? "html &" : `@media ${variant}`});
|
|
6
|
+
`;
|
|
7
|
+
});
|
|
8
|
+
return css;
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './withUniwind';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./withUniwind.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ComponentProps, ComponentPropsWithRef } from 'react';
|
|
2
|
+
import { RNStyle } from '../core/types';
|
|
3
|
+
export type AnyObject = Record<PropertyKey, any>;
|
|
4
|
+
type StyleToClass<K extends PropertyKey> = K extends 'style' ? 'className' : K extends `${infer StyleProp}Style` ? `${StyleProp}ClassName` : never;
|
|
5
|
+
type ColorPropToClass<K extends PropertyKey> = K extends 'color' ? 'colorClassName' : K extends `${string}Color` | `${string}color${string}` ? `${K}ClassName` : never;
|
|
6
|
+
export type ApplyUniwind<TProps extends AnyObject> = {
|
|
7
|
+
[K in keyof TProps as StyleToClass<K>]?: string;
|
|
8
|
+
} & {
|
|
9
|
+
[K in keyof TProps as ColorPropToClass<K>]?: string;
|
|
10
|
+
} & TProps;
|
|
11
|
+
export type ApplyUniwindOptions<TProps extends AnyObject, TOptions extends {
|
|
12
|
+
[K in keyof TProps]?: OptionMapping;
|
|
13
|
+
}> = {
|
|
14
|
+
[K in keyof TOptions as TOptions[K] extends undefined ? never : TOptions[K]['fromClassName']]?: string;
|
|
15
|
+
} & TProps;
|
|
16
|
+
export type Component<T extends AnyObject = AnyObject> = React.JSXElementConstructor<T>;
|
|
17
|
+
export type OptionMapping = {
|
|
18
|
+
fromClassName: string;
|
|
19
|
+
styleProperty?: keyof RNStyle;
|
|
20
|
+
};
|
|
21
|
+
export type WithUniwind = {
|
|
22
|
+
<TComponent extends Component<any>>(Component: TComponent): (props: ApplyUniwind<ComponentPropsWithRef<TComponent>> & {}) => React.ReactNode;
|
|
23
|
+
<TComponent extends Component<any>, const TOptions extends {
|
|
24
|
+
[K in keyof ComponentProps<TComponent>]?: OptionMapping;
|
|
25
|
+
}>(Component: TComponent, options: TOptions): (props: ApplyUniwindOptions<ComponentPropsWithRef<TComponent>, TOptions> & {}) => React.ReactNode;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useReducer } from "react";
|
|
3
|
+
import { CSSListener, formatColor, getWebStyles } from "../core/web/index.js";
|
|
4
|
+
import { classToColor, classToStyle, isClassProperty, isColorClassProperty, isStyleProperty } from "./withUniwindUtils.js";
|
|
5
|
+
export const withUniwind = (Component2, options) => options ? withManualUniwind(Component2, options) : withAutoUniwind(Component2);
|
|
6
|
+
const withAutoUniwind = (Component2) => (props) => {
|
|
7
|
+
const { classNames, generatedProps } = Object.entries(props).reduce((acc, [propName, propValue]) => {
|
|
8
|
+
if (isColorClassProperty(propName)) {
|
|
9
|
+
const colorProp = classToColor(propName);
|
|
10
|
+
if (props[colorProp] !== void 0) {
|
|
11
|
+
return acc;
|
|
12
|
+
}
|
|
13
|
+
const className = propValue;
|
|
14
|
+
const color = getWebStyles(className).accentColor;
|
|
15
|
+
acc.generatedProps[colorProp] = color !== void 0 ? formatColor(color) : void 0;
|
|
16
|
+
acc.classNames += `${className} `;
|
|
17
|
+
return acc;
|
|
18
|
+
}
|
|
19
|
+
if (isClassProperty(propName)) {
|
|
20
|
+
const styleProp = classToStyle(propName);
|
|
21
|
+
acc.generatedProps[styleProp] ??= [];
|
|
22
|
+
acc.generatedProps[styleProp][0] = { $$css: true, tailwind: propValue };
|
|
23
|
+
return acc;
|
|
24
|
+
}
|
|
25
|
+
if (isStyleProperty(propName)) {
|
|
26
|
+
acc.generatedProps[propName] ??= [];
|
|
27
|
+
acc.generatedProps[propName][1] = propValue;
|
|
28
|
+
return acc;
|
|
29
|
+
}
|
|
30
|
+
return acc;
|
|
31
|
+
}, { generatedProps: {}, classNames: "" });
|
|
32
|
+
const [, rerender] = useReducer(() => ({}), {});
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const dispose = CSSListener.subscribeToClassName(classNames, rerender);
|
|
35
|
+
return dispose;
|
|
36
|
+
}, [classNames]);
|
|
37
|
+
return /* @__PURE__ */ jsx(
|
|
38
|
+
Component2,
|
|
39
|
+
{
|
|
40
|
+
...props,
|
|
41
|
+
...generatedProps
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
const withManualUniwind = (Component2, options) => (props) => {
|
|
46
|
+
const { generatedProps, classNames } = Object.entries(options).reduce((acc, [propName, option]) => {
|
|
47
|
+
const className = props[option.fromClassName];
|
|
48
|
+
if (className === void 0) {
|
|
49
|
+
return acc;
|
|
50
|
+
}
|
|
51
|
+
if (option.styleProperty !== void 0) {
|
|
52
|
+
if (props[propName] !== void 0) {
|
|
53
|
+
return acc;
|
|
54
|
+
}
|
|
55
|
+
const value = getWebStyles(className)[option.styleProperty];
|
|
56
|
+
const transformedValue = value !== void 0 && option.styleProperty.toLowerCase().includes("color") ? formatColor(value) : value;
|
|
57
|
+
acc.classNames += `${className} `;
|
|
58
|
+
acc.generatedProps[propName] = transformedValue;
|
|
59
|
+
return acc;
|
|
60
|
+
}
|
|
61
|
+
acc.generatedProps[propName] = [{ $$css: true, tailwind: className }, props[propName]];
|
|
62
|
+
return acc;
|
|
63
|
+
}, { generatedProps: {}, classNames: "" });
|
|
64
|
+
const [, rerender] = useReducer(() => ({}), {});
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const dispose = CSSListener.subscribeToClassName(classNames, rerender);
|
|
67
|
+
return dispose;
|
|
68
|
+
}, [classNames]);
|
|
69
|
+
return /* @__PURE__ */ jsx(
|
|
70
|
+
Component2,
|
|
71
|
+
{
|
|
72
|
+
...props,
|
|
73
|
+
...generatedProps
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useReducer } from "react";
|
|
3
|
+
import { UniwindListener } from "../core/listener.js";
|
|
4
|
+
import { UniwindStore } from "../core/native/index.js";
|
|
5
|
+
import { classToColor, classToStyle, isClassProperty, isColorClassProperty, isStyleProperty } from "./withUniwindUtils.js";
|
|
6
|
+
export const withUniwind = (Component2, options) => options ? withManualUniwind(Component2, options) : withAutoUniwind(Component2);
|
|
7
|
+
const withAutoUniwind = (Component2) => (props) => {
|
|
8
|
+
const { dependencies, generatedProps } = Object.entries(props).reduce((acc, [propName, propValue]) => {
|
|
9
|
+
if (isColorClassProperty(propName)) {
|
|
10
|
+
const colorProp = classToColor(propName);
|
|
11
|
+
if (props[colorProp] !== void 0) {
|
|
12
|
+
return acc;
|
|
13
|
+
}
|
|
14
|
+
const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(propValue);
|
|
15
|
+
acc.dependencies.push(...dependencies2);
|
|
16
|
+
acc.generatedProps[colorProp] = styles.accentColor;
|
|
17
|
+
return acc;
|
|
18
|
+
}
|
|
19
|
+
if (isClassProperty(propName)) {
|
|
20
|
+
const styleProp = classToStyle(propName);
|
|
21
|
+
const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(propValue);
|
|
22
|
+
acc.dependencies.push(...dependencies2);
|
|
23
|
+
acc.generatedProps[styleProp] ??= [];
|
|
24
|
+
acc.generatedProps[styleProp][0] = styles;
|
|
25
|
+
return acc;
|
|
26
|
+
}
|
|
27
|
+
if (isStyleProperty(propName)) {
|
|
28
|
+
acc.generatedProps[propName] ??= [];
|
|
29
|
+
acc.generatedProps[propName][1] = propValue;
|
|
30
|
+
return acc;
|
|
31
|
+
}
|
|
32
|
+
return acc;
|
|
33
|
+
}, { generatedProps: {}, dependencies: [] });
|
|
34
|
+
const deps = Array.from(new Set(dependencies));
|
|
35
|
+
const [, rerender] = useReducer(() => ({}), {});
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const dispose = UniwindListener.subscribe(rerender, deps);
|
|
38
|
+
return dispose;
|
|
39
|
+
}, [deps]);
|
|
40
|
+
return /* @__PURE__ */ jsx(
|
|
41
|
+
Component2,
|
|
42
|
+
{
|
|
43
|
+
...props,
|
|
44
|
+
...generatedProps
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
const withManualUniwind = (Component2, options) => (props) => {
|
|
49
|
+
const { generatedProps, dependencies } = Object.entries(options).reduce((acc, [propName, option]) => {
|
|
50
|
+
const className = props[option.fromClassName];
|
|
51
|
+
if (className === void 0) {
|
|
52
|
+
return acc;
|
|
53
|
+
}
|
|
54
|
+
if (option.styleProperty !== void 0) {
|
|
55
|
+
if (props[propName] !== void 0) {
|
|
56
|
+
return acc;
|
|
57
|
+
}
|
|
58
|
+
const { styles: styles2, dependencies: dependencies3 } = UniwindStore.getStyles(className);
|
|
59
|
+
acc.generatedProps[propName] = styles2[option.styleProperty];
|
|
60
|
+
acc.dependencies.push(...dependencies3);
|
|
61
|
+
return acc;
|
|
62
|
+
}
|
|
63
|
+
const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(className);
|
|
64
|
+
acc.generatedProps[propName] = styles;
|
|
65
|
+
acc.dependencies.push(...dependencies2);
|
|
66
|
+
return acc;
|
|
67
|
+
}, { generatedProps: {}, dependencies: [] });
|
|
68
|
+
const deps = Array.from(new Set(dependencies));
|
|
69
|
+
const [, rerender] = useReducer(() => ({}), {});
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
const dispose = UniwindListener.subscribe(rerender, deps);
|
|
72
|
+
return dispose;
|
|
73
|
+
}, [deps]);
|
|
74
|
+
return /* @__PURE__ */ jsx(
|
|
75
|
+
Component2,
|
|
76
|
+
{
|
|
77
|
+
...props,
|
|
78
|
+
...generatedProps
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const classToStyle: (className: string) => string;
|
|
2
|
+
export declare const classToColor: (className: string) => string;
|
|
3
|
+
export declare const isColorClassProperty: (prop: string) => boolean;
|
|
4
|
+
export declare const isClassProperty: (prop: string) => boolean;
|
|
5
|
+
export declare const isStyleProperty: (prop: string) => boolean;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const classToStyle = (className) => className === "className" ? "style" : className.replace("ClassName", "Style");
|
|
2
|
+
export const classToColor = (className) => className.replace("ClassName", "");
|
|
3
|
+
export const isColorClassProperty = (prop) => prop.toLowerCase().includes("color") && prop.endsWith("ClassName");
|
|
4
|
+
export const isClassProperty = (prop) => prop === "className" || prop.endsWith("ClassName");
|
|
5
|
+
export const isStyleProperty = (prop) => prop === "style" || prop.endsWith("Style");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getVariableValue: (name: string) => string | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { parseCSSValue } from "../../core/web/index.js";
|
|
2
|
+
const documentStyles = typeof document !== "undefined" ? window.getComputedStyle(document.documentElement) : null;
|
|
3
|
+
export const getVariableValue = (name) => {
|
|
4
|
+
if (!documentStyles) {
|
|
5
|
+
return void 0;
|
|
6
|
+
}
|
|
7
|
+
const value = documentStyles.getPropertyValue(name).trim();
|
|
8
|
+
if (value === "") {
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
return parseCSSValue(value);
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getVariableValue: (name: string) => unknown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useCSSVariable';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useCSSVariable.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type IsGenericNumber<T> = T & 0 extends -1 ? false : true;
|
|
2
|
+
type CreateArray<N extends number, Value, TAcc extends Array<Value> = []> = TAcc['length'] extends N ? TAcc : CreateArray<N, Value, [...TAcc, Value]>;
|
|
3
|
+
type UseCSSVariable = {
|
|
4
|
+
(name: string): string | number | undefined;
|
|
5
|
+
<const T extends Array<string>>(names: T): IsGenericNumber<T['length']> extends true ? Array<string | number | undefined> : CreateArray<T['length'], string | number | undefined>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A hook that returns the value of a CSS variable.
|
|
9
|
+
* @param name Name / Array of names of the CSS variable.
|
|
10
|
+
* @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)
|
|
11
|
+
*/
|
|
12
|
+
export declare const useCSSVariable: UseCSSVariable;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { UniwindListener } from "../../core/listener.js";
|
|
3
|
+
import { Logger } from "../../core/logger.js";
|
|
4
|
+
import { StyleDependency } from "../../types.js";
|
|
5
|
+
import { getVariableValue } from "./getVariableValue.js";
|
|
6
|
+
const getValue = (name) => Array.isArray(name) ? name.map(getVariableValue) : getVariableValue(name);
|
|
7
|
+
const arrayEquals = (a, b) => {
|
|
8
|
+
if (a.length !== b.length) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return a.every((value, index) => value === b[index]);
|
|
12
|
+
};
|
|
13
|
+
let warned = false;
|
|
14
|
+
const logDevError = (name) => {
|
|
15
|
+
warned = true;
|
|
16
|
+
Logger.warn(
|
|
17
|
+
`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`
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
export const useCSSVariable = (name) => {
|
|
21
|
+
const [value, setValue] = useState(getValue(name));
|
|
22
|
+
const nameRef = useRef(name);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (Array.isArray(name) && Array.isArray(nameRef.current)) {
|
|
25
|
+
if (arrayEquals(name, nameRef.current)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
setValue(getValue(name));
|
|
29
|
+
nameRef.current = name;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (name !== nameRef.current) {
|
|
33
|
+
setValue(getValue(name));
|
|
34
|
+
nameRef.current = name;
|
|
35
|
+
}
|
|
36
|
+
}, [name]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const updateValue = () => setValue(getValue(nameRef.current));
|
|
39
|
+
const dispose = UniwindListener.subscribe(
|
|
40
|
+
updateValue,
|
|
41
|
+
[StyleDependency.Theme, StyleDependency.Variables]
|
|
42
|
+
);
|
|
43
|
+
return dispose;
|
|
44
|
+
}, []);
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
value.forEach((val, index) => {
|
|
47
|
+
if (val === void 0 && __DEV__ && !warned) {
|
|
48
|
+
logDevError(name[index] ?? "");
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (value === void 0 && __DEV__ && !warned) {
|
|
53
|
+
logDevError(name);
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useEffect, useReducer } from "react";
|
|
2
|
+
import { CSSListener, getWebStyles } from "../core/web/index.js";
|
|
3
|
+
const emptyState = {};
|
|
4
|
+
export const useResolveClassNames = (className) => {
|
|
5
|
+
const [styles, recreate] = useReducer(
|
|
6
|
+
() => className !== "" ? getWebStyles(className) : emptyState,
|
|
7
|
+
className !== "" ? getWebStyles(className) : emptyState
|
|
8
|
+
);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (className === "") {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
recreate();
|
|
14
|
+
const dispose = CSSListener.subscribeToClassName(className, recreate);
|
|
15
|
+
return dispose;
|
|
16
|
+
}, [className]);
|
|
17
|
+
return styles;
|
|
18
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useEffect, useReducer } from "react";
|
|
2
|
+
import { UniwindListener } from "../core/listener.js";
|
|
3
|
+
import { UniwindStore } from "../core/native/index.js";
|
|
4
|
+
const emptyState = { styles: {}, dependencies: [] };
|
|
5
|
+
export const useResolveClassNames = (className, state) => {
|
|
6
|
+
const [uniwindState, recreate] = useReducer(
|
|
7
|
+
() => className !== "" ? UniwindStore.getStyles(className, state) : emptyState,
|
|
8
|
+
className !== "" ? UniwindStore.getStyles(className, state) : emptyState
|
|
9
|
+
);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (className !== "") {
|
|
12
|
+
recreate();
|
|
13
|
+
}
|
|
14
|
+
}, [className, state?.isDisabled, state?.isPressed, state?.isFocused]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (uniwindState.dependencies.length > 0) {
|
|
17
|
+
const dispose = UniwindListener.subscribe(recreate, uniwindState.dependencies);
|
|
18
|
+
return dispose;
|
|
19
|
+
}
|
|
20
|
+
}, [uniwindState.dependencies, className]);
|
|
21
|
+
return uniwindState.styles;
|
|
22
|
+
};
|