react-native-unistyles 3.0.0-beta.1 → 3.0.0-beta.2
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/README.md +4 -4
- package/Unistyles.podspec +7 -1
- package/android/build.gradle +6 -0
- package/android/src/main/cxx/NativeUnistylesModule.cpp +2 -2
- package/cxx/common/Constants.h +2 -0
- package/cxx/core/HostStyle.cpp +12 -7
- package/cxx/core/HostStyle.h +5 -0
- package/cxx/core/UnistyleData.h +3 -3
- package/cxx/core/UnistyleWrapper.h +8 -8
- package/cxx/core/UnistylesRegistry.cpp +23 -30
- package/cxx/core/UnistylesRegistry.h +8 -2
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +108 -12
- package/cxx/hybridObjects/HybridShadowRegistry.h +21 -2
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +4 -0
- package/cxx/parser/Parser.cpp +182 -26
- package/cxx/parser/Parser.h +3 -1
- package/ios/UnistylesModuleOnLoad.mm +2 -2
- package/lib/commonjs/components/ScopedTheme.js +36 -0
- package/lib/commonjs/components/ScopedTheme.js.map +1 -0
- package/lib/commonjs/components/Variants.js +33 -0
- package/lib/commonjs/components/Variants.js.map +1 -0
- package/lib/commonjs/components/index.js +10 -3
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/components/native/ActivityIndicator.js +10 -0
- package/lib/commonjs/components/native/ActivityIndicator.js.map +1 -0
- package/lib/commonjs/components/native/FlatList.js +10 -0
- package/lib/commonjs/components/native/FlatList.js.map +1 -0
- package/lib/commonjs/components/native/Image.js +10 -0
- package/lib/commonjs/components/native/Image.js.map +1 -0
- package/lib/commonjs/components/native/ImageBackground.js +10 -0
- package/lib/commonjs/components/native/ImageBackground.js.map +1 -0
- package/lib/commonjs/components/native/KeyboardAvoidingView.js +10 -0
- package/lib/commonjs/components/native/KeyboardAvoidingView.js.map +1 -0
- package/lib/commonjs/components/{Pressable.web.js → native/Pressable.js} +26 -66
- package/lib/commonjs/components/native/Pressable.js.map +1 -0
- package/lib/commonjs/components/native/Pressable.native.js +48 -0
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -0
- package/lib/commonjs/components/native/RefreshControl.js +10 -0
- package/lib/commonjs/components/native/RefreshControl.js.map +1 -0
- package/lib/commonjs/components/native/ScrollView.js +10 -0
- package/lib/commonjs/components/native/ScrollView.js.map +1 -0
- package/lib/commonjs/components/native/SectionList.js +10 -0
- package/lib/commonjs/components/native/SectionList.js.map +1 -0
- package/lib/commonjs/components/native/Switch.js +10 -0
- package/lib/commonjs/components/native/Switch.js.map +1 -0
- package/lib/commonjs/components/native/Text.js +10 -0
- package/lib/commonjs/components/native/Text.js.map +1 -0
- package/lib/commonjs/components/native/TextInput.js +10 -0
- package/lib/commonjs/components/native/TextInput.js.map +1 -0
- package/lib/commonjs/components/native/TouchableHighlight.js +10 -0
- package/lib/commonjs/components/native/TouchableHighlight.js.map +1 -0
- package/lib/commonjs/components/native/TouchableOpacity.js +10 -0
- package/lib/commonjs/components/native/TouchableOpacity.js.map +1 -0
- package/lib/commonjs/components/native/View.js +10 -0
- package/lib/commonjs/components/native/View.js.map +1 -0
- package/lib/commonjs/components/native/VirtualizedList.js +10 -0
- package/lib/commonjs/components/native/VirtualizedList.js.map +1 -0
- package/lib/commonjs/core/createUnistylesComponent.js +5 -68
- package/lib/commonjs/core/createUnistylesComponent.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.js +16 -0
- package/lib/commonjs/core/createUnistylesElement.js.map +1 -0
- package/lib/commonjs/core/createUnistylesImageBackground.js +27 -0
- package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -0
- package/lib/commonjs/core/index.js +20 -6
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/core/passForwardRef.js +27 -0
- package/lib/commonjs/core/passForwardRef.js.map +1 -0
- package/lib/commonjs/core/withUnistyles/index.js +13 -0
- package/lib/commonjs/core/withUnistyles/index.js.map +1 -0
- package/lib/commonjs/core/withUnistyles/types.js +8 -0
- package/lib/commonjs/core/withUnistyles/types.js.map +1 -0
- package/lib/commonjs/core/withUnistyles/useDependencies.js +81 -0
- package/lib/commonjs/core/withUnistyles/useDependencies.js.map +1 -0
- package/lib/commonjs/core/withUnistyles/withUnistyles.js +88 -0
- package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -0
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +96 -0
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -0
- package/lib/commonjs/hooks/useMedia.js +17 -33
- package/lib/commonjs/hooks/useMedia.js.map +1 -1
- package/lib/commonjs/hooks/useMedia.native.js +60 -0
- package/lib/commonjs/hooks/useMedia.native.js.map +1 -0
- package/lib/commonjs/index.js +33 -16
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +3 -3
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/index.js +14 -40
- package/lib/commonjs/specs/index.js.map +1 -1
- package/lib/commonjs/specs/index.native.js +54 -0
- package/lib/commonjs/specs/index.native.js.map +1 -0
- package/lib/commonjs/web/create.js +12 -33
- package/lib/commonjs/web/create.js.map +1 -1
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/commonjs/web/registry.js +10 -3
- package/lib/commonjs/web/registry.js.map +1 -1
- package/lib/commonjs/web/runtime.js +3 -1
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +71 -64
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/utils/unistyle.js +3 -3
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/module/components/ScopedTheme.js +29 -0
- package/lib/module/components/ScopedTheme.js.map +1 -0
- package/lib/module/components/Variants.js +26 -0
- package/lib/module/components/Variants.js.map +1 -0
- package/lib/module/components/index.js +2 -1
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/components/native/ActivityIndicator.js +6 -0
- package/lib/module/components/native/ActivityIndicator.js.map +1 -0
- package/lib/module/components/native/FlatList.js +6 -0
- package/lib/module/components/native/FlatList.js.map +1 -0
- package/lib/module/components/native/Image.js +6 -0
- package/lib/module/components/native/Image.js.map +1 -0
- package/lib/module/components/native/ImageBackground.js +6 -0
- package/lib/module/components/native/ImageBackground.js.map +1 -0
- package/lib/module/components/native/KeyboardAvoidingView.js +6 -0
- package/lib/module/components/native/KeyboardAvoidingView.js.map +1 -0
- package/lib/module/components/native/Pressable.js +69 -0
- package/lib/module/components/native/Pressable.js.map +1 -0
- package/lib/module/components/native/Pressable.native.js +42 -0
- package/lib/module/components/native/Pressable.native.js.map +1 -0
- package/lib/module/components/native/RefreshControl.js +6 -0
- package/lib/module/components/native/RefreshControl.js.map +1 -0
- package/lib/module/components/native/ScrollView.js +6 -0
- package/lib/module/components/native/ScrollView.js.map +1 -0
- package/lib/module/components/native/SectionList.js +6 -0
- package/lib/module/components/native/SectionList.js.map +1 -0
- package/lib/module/components/native/Switch.js +6 -0
- package/lib/module/components/native/Switch.js.map +1 -0
- package/lib/module/components/native/Text.js +6 -0
- package/lib/module/components/native/Text.js.map +1 -0
- package/lib/module/components/native/TextInput.js +6 -0
- package/lib/module/components/native/TextInput.js.map +1 -0
- package/lib/module/components/native/TouchableHighlight.js +6 -0
- package/lib/module/components/native/TouchableHighlight.js.map +1 -0
- package/lib/module/components/native/TouchableOpacity.js +6 -0
- package/lib/module/components/native/TouchableOpacity.js.map +1 -0
- package/lib/module/components/native/View.js +6 -0
- package/lib/module/components/native/View.js.map +1 -0
- package/lib/module/components/native/VirtualizedList.js +6 -0
- package/lib/module/components/native/VirtualizedList.js.map +1 -0
- package/lib/module/core/createUnistylesComponent.js +5 -66
- package/lib/module/core/createUnistylesComponent.js.map +1 -1
- package/lib/module/core/createUnistylesElement.js +10 -0
- package/lib/module/core/createUnistylesElement.js.map +1 -0
- package/lib/module/core/createUnistylesImageBackground.js +21 -0
- package/lib/module/core/createUnistylesImageBackground.js.map +1 -0
- package/lib/module/core/index.js +4 -2
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/core/passForwardRef.js +22 -0
- package/lib/module/core/passForwardRef.js.map +1 -0
- package/lib/module/core/withUnistyles/index.js +4 -0
- package/lib/module/core/withUnistyles/index.js.map +1 -0
- package/lib/module/core/withUnistyles/types.js +4 -0
- package/lib/module/core/withUnistyles/types.js.map +1 -0
- package/lib/module/core/withUnistyles/useDependencies.js +75 -0
- package/lib/module/core/withUnistyles/useDependencies.js.map +1 -0
- package/lib/module/core/withUnistyles/withUnistyles.js +81 -0
- package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -0
- package/lib/module/core/withUnistyles/withUnistyles.native.js +89 -0
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -0
- package/lib/module/hooks/useMedia.js +19 -35
- package/lib/module/hooks/useMedia.js.map +1 -1
- package/lib/module/hooks/useMedia.native.js +55 -0
- package/lib/module/hooks/useMedia.native.js.map +1 -0
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +3 -3
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/index.js +2 -8
- package/lib/module/specs/index.js.map +1 -1
- package/lib/module/specs/index.native.js +11 -0
- package/lib/module/specs/index.native.js.map +1 -0
- package/lib/module/web/create.js +13 -34
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/index.js +1 -1
- package/lib/module/web/index.js.map +1 -1
- package/lib/module/web/registry.js +11 -4
- package/lib/module/web/registry.js.map +1 -1
- package/lib/module/web/runtime.js +3 -1
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +70 -63
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/utils/unistyle.js +1 -1
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/typescript/src/components/ScopedTheme.d.ts +8 -0
- package/lib/typescript/src/components/ScopedTheme.d.ts.map +1 -0
- package/lib/typescript/src/components/Variants.d.ts +7 -0
- package/lib/typescript/src/components/Variants.d.ts.map +1 -0
- package/lib/typescript/src/components/index.d.ts +2 -1
- package/lib/typescript/src/components/index.d.ts.map +1 -1
- package/lib/typescript/src/components/native/ActivityIndicator.d.ts +2 -0
- package/lib/typescript/src/components/native/ActivityIndicator.d.ts.map +1 -0
- package/lib/typescript/src/components/native/FlatList.d.ts +2 -0
- package/lib/typescript/src/components/native/FlatList.d.ts.map +1 -0
- package/lib/typescript/src/components/native/Image.d.ts +2 -0
- package/lib/typescript/src/components/native/Image.d.ts.map +1 -0
- package/lib/typescript/src/components/native/ImageBackground.d.ts +3 -0
- package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -0
- package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts +2 -0
- package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts.map +1 -0
- package/lib/typescript/src/components/{Pressable.web.d.ts → native/Pressable.d.ts} +3 -2
- package/lib/typescript/src/components/native/Pressable.d.ts.map +1 -0
- package/lib/typescript/src/components/{Pressable.d.ts → native/Pressable.native.d.ts} +1 -3
- package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -0
- package/lib/typescript/src/components/native/RefreshControl.d.ts +2 -0
- package/lib/typescript/src/components/native/RefreshControl.d.ts.map +1 -0
- package/lib/typescript/src/components/native/ScrollView.d.ts +2 -0
- package/lib/typescript/src/components/native/ScrollView.d.ts.map +1 -0
- package/lib/typescript/src/components/native/SectionList.d.ts +2 -0
- package/lib/typescript/src/components/native/SectionList.d.ts.map +1 -0
- package/lib/typescript/src/components/native/Switch.d.ts +2 -0
- package/lib/typescript/src/components/native/Switch.d.ts.map +1 -0
- package/lib/typescript/src/components/native/Text.d.ts +2 -0
- package/lib/typescript/src/components/native/Text.d.ts.map +1 -0
- package/lib/typescript/src/components/native/TextInput.d.ts +2 -0
- package/lib/typescript/src/components/native/TextInput.d.ts.map +1 -0
- package/lib/typescript/src/components/native/TouchableHighlight.d.ts +2 -0
- package/lib/typescript/src/components/native/TouchableHighlight.d.ts.map +1 -0
- package/lib/typescript/src/components/native/TouchableOpacity.d.ts +2 -0
- package/lib/typescript/src/components/native/TouchableOpacity.d.ts.map +1 -0
- package/lib/typescript/src/components/native/View.d.ts +2 -0
- package/lib/typescript/src/components/native/View.d.ts.map +1 -0
- package/lib/typescript/src/components/native/VirtualizedList.d.ts +2 -0
- package/lib/typescript/src/components/native/VirtualizedList.d.ts.map +1 -0
- package/lib/typescript/src/core/createUnistylesComponent.d.ts +9 -3
- package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.d.ts +3 -0
- package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -0
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts +4 -0
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +4 -2
- package/lib/typescript/src/core/index.d.ts.map +1 -1
- package/lib/typescript/src/core/passForwardRef.d.ts +3 -0
- package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -0
- package/lib/typescript/src/core/withUnistyles/index.d.ts +2 -0
- package/lib/typescript/src/core/withUnistyles/index.d.ts.map +1 -0
- package/lib/typescript/src/core/withUnistyles/types.d.ts +6 -0
- package/lib/typescript/src/core/withUnistyles/types.d.ts.map +1 -0
- package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts +13 -0
- package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts.map +1 -0
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +11 -0
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +8 -0
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useMedia.d.ts +1 -1
- package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useMedia.native.d.ts +6 -0
- package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +7 -2
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/types.d.ts +17 -0
- package/lib/typescript/src/specs/ShadowRegistry/types.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.d.ts +3 -11
- package/lib/typescript/src/specs/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.native.d.ts +12 -0
- package/lib/typescript/src/specs/index.native.d.ts.map +1 -0
- package/lib/typescript/src/web/create.d.ts +1 -1441
- package/lib/typescript/src/web/create.d.ts.map +1 -1
- package/lib/typescript/src/web/index.d.ts +2 -1441
- package/lib/typescript/src/web/index.d.ts.map +1 -1
- package/lib/typescript/src/web/registry.d.ts +2 -3
- package/lib/typescript/src/web/registry.d.ts.map +1 -1
- package/lib/typescript/src/web/runtime.d.ts.map +1 -1
- package/lib/typescript/src/web/shadowRegistry.d.ts +11 -3
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts +1 -2
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +3 -0
- package/package.json +4 -4
- package/plugin/common.js +4 -6
- package/plugin/import.js +63 -26
- package/plugin/index.js +48 -28
- package/plugin/ref.js +0 -234
- package/plugin/style.js +4 -317
- package/plugin/stylesheet.js +25 -10
- package/plugin/variants.js +54 -1
- package/src/components/ScopedTheme.tsx +32 -0
- package/src/components/Variants.tsx +29 -0
- package/src/components/index.ts +2 -1
- package/src/components/native/ActivityIndicator.tsx +4 -0
- package/src/components/native/FlatList.tsx +4 -0
- package/src/components/native/Image.tsx +4 -0
- package/src/components/native/ImageBackground.tsx +4 -0
- package/src/components/native/KeyboardAvoidingView.tsx +4 -0
- package/src/components/native/Pressable.native.tsx +55 -0
- package/src/components/native/Pressable.tsx +98 -0
- package/src/components/native/RefreshControl.tsx +4 -0
- package/src/components/native/ScrollView.tsx +4 -0
- package/src/components/native/SectionList.tsx +4 -0
- package/src/components/native/Switch.tsx +4 -0
- package/src/components/native/Text.tsx +4 -0
- package/src/components/native/TextInput.tsx +4 -0
- package/src/components/native/TouchableHighlight.tsx +4 -0
- package/src/components/native/TouchableOpacity.tsx +4 -0
- package/src/components/native/View.tsx +4 -0
- package/src/components/native/VirtualizedList.tsx +4 -0
- package/src/core/createUnistylesComponent.tsx +6 -76
- package/src/core/createUnistylesElement.tsx +9 -0
- package/src/core/createUnistylesImageBackground.tsx +24 -0
- package/src/core/index.ts +4 -2
- package/src/core/passForwardRef.ts +29 -0
- package/src/core/withUnistyles/index.ts +1 -0
- package/src/core/withUnistyles/types.ts +7 -0
- package/src/core/withUnistyles/useDependencies.ts +93 -0
- package/src/core/withUnistyles/withUnistyles.native.tsx +96 -0
- package/src/core/withUnistyles/withUnistyles.tsx +90 -0
- package/src/hooks/useMedia.native.ts +65 -0
- package/src/hooks/useMedia.ts +19 -36
- package/src/index.ts +2 -2
- package/src/specs/ShadowRegistry/index.ts +14 -5
- package/src/specs/ShadowRegistry/types.ts +18 -1
- package/src/specs/index.native.ts +27 -0
- package/src/specs/index.ts +3 -27
- package/src/web/create.ts +14 -32
- package/src/web/index.ts +3 -2
- package/src/web/registry.ts +15 -6
- package/src/web/runtime.ts +3 -1
- package/src/web/shadowRegistry.ts +66 -52
- package/src/web/utils/unistyle.ts +1 -2
- package/lib/commonjs/components/Pressable.js +0 -74
- package/lib/commonjs/components/Pressable.js.map +0 -1
- package/lib/commonjs/components/Pressable.web.js.map +0 -1
- package/lib/commonjs/core/createUnistylesComponent.native.js +0 -82
- package/lib/commonjs/core/createUnistylesComponent.native.js.map +0 -1
- package/lib/commonjs/core/getBoundArgs.js +0 -18
- package/lib/commonjs/core/getBoundArgs.js.map +0 -1
- package/lib/commonjs/core/getId.js +0 -9
- package/lib/commonjs/core/getId.js.map +0 -1
- package/lib/commonjs/hooks/useMedia.web.js +0 -43
- package/lib/commonjs/hooks/useMedia.web.js.map +0 -1
- package/lib/commonjs/specs/index.web.js +0 -17
- package/lib/commonjs/specs/index.web.js.map +0 -1
- package/lib/module/components/Pressable.js +0 -68
- package/lib/module/components/Pressable.js.map +0 -1
- package/lib/module/components/Pressable.web.js +0 -109
- package/lib/module/components/Pressable.web.js.map +0 -1
- package/lib/module/core/createUnistylesComponent.native.js +0 -75
- package/lib/module/core/createUnistylesComponent.native.js.map +0 -1
- package/lib/module/core/getBoundArgs.js +0 -13
- package/lib/module/core/getBoundArgs.js.map +0 -1
- package/lib/module/core/getId.js +0 -4
- package/lib/module/core/getId.js.map +0 -1
- package/lib/module/hooks/useMedia.web.js +0 -38
- package/lib/module/hooks/useMedia.web.js.map +0 -1
- package/lib/module/specs/index.web.js +0 -4
- package/lib/module/specs/index.web.js.map +0 -1
- package/lib/typescript/src/components/Pressable.d.ts.map +0 -1
- package/lib/typescript/src/components/Pressable.web.d.ts.map +0 -1
- package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +0 -8
- package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +0 -1
- package/lib/typescript/src/core/getBoundArgs.d.ts +0 -2
- package/lib/typescript/src/core/getBoundArgs.d.ts.map +0 -1
- package/lib/typescript/src/core/getId.d.ts +0 -2
- package/lib/typescript/src/core/getId.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useMedia.web.d.ts +0 -6
- package/lib/typescript/src/hooks/useMedia.web.d.ts.map +0 -1
- package/lib/typescript/src/specs/index.web.d.ts +0 -2
- package/lib/typescript/src/specs/index.web.d.ts.map +0 -1
- package/src/components/Pressable.tsx +0 -89
- package/src/components/Pressable.web.tsx +0 -129
- package/src/core/createUnistylesComponent.native.tsx +0 -83
- package/src/core/getBoundArgs.ts +0 -15
- package/src/core/getId.ts +0 -1
- package/src/hooks/useMedia.web.ts +0 -47
- package/src/specs/index.web.ts +0 -1
@@ -0,0 +1,96 @@
|
|
1
|
+
import React, { forwardRef, useEffect, useRef, type ComponentType } from 'react'
|
2
|
+
import { StyleSheet, UnistyleDependency } from '../../specs'
|
3
|
+
import type { PartialBy } from '../../types/common'
|
4
|
+
import { deepMergeObjects } from '../../utils'
|
5
|
+
import { SUPPORTED_STYLE_PROPS } from './types'
|
6
|
+
import type { Mappings, SupportedStyleProps } from './types'
|
7
|
+
import { useDependencies } from './useDependencies'
|
8
|
+
|
9
|
+
// @ts-expect-error
|
10
|
+
type GenericComponentProps<P> = ComponentProps<P>
|
11
|
+
// @ts-expect-error
|
12
|
+
type GenericComponentRef<T> = ComponentRef<T>
|
13
|
+
|
14
|
+
export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(Component: TComponent, mappings?: Mappings<TMappings>) => {
|
15
|
+
type TProps = GenericComponentProps<TComponent>
|
16
|
+
type PropsWithUnistyles = PartialBy<TProps, keyof TMappings | SupportedStyleProps> & {
|
17
|
+
uniProps?: Mappings<TProps>
|
18
|
+
}
|
19
|
+
|
20
|
+
return forwardRef<GenericComponentRef<TComponent>, PropsWithUnistyles>((props, ref) => {
|
21
|
+
const narrowedProps = props as PropsWithUnistyles
|
22
|
+
const stylesRef = useRef<Record<string, any>>({})
|
23
|
+
const isForcedRef = useRef(false)
|
24
|
+
const NativeComponent = Component as ComponentType
|
25
|
+
|
26
|
+
if (!isForcedRef.current) {
|
27
|
+
SUPPORTED_STYLE_PROPS.forEach(propName => {
|
28
|
+
if (narrowedProps?.[propName]) {
|
29
|
+
if (Array.isArray(narrowedProps[propName])) {
|
30
|
+
console.error(`🦄 Unistyles: withUnistyles requires ${propName} to be an object. Please check props for component: ${NativeComponent.displayName}`)
|
31
|
+
}
|
32
|
+
|
33
|
+
// @ts-expect-error - this is hidden from TS
|
34
|
+
if (props[propName].__unistyles_name && !props[propName].__proto__?.getStyle) {
|
35
|
+
console.error(`🦄 Unistyles: withUnistyles received style that is not bound. You likely used the spread operator on a Unistyle style. Please check props for component: ${NativeComponent.displayName}`)
|
36
|
+
}
|
37
|
+
|
38
|
+
stylesRef.current = {
|
39
|
+
...stylesRef.current,
|
40
|
+
[propName]: narrowedProps[propName]
|
41
|
+
}
|
42
|
+
}
|
43
|
+
})
|
44
|
+
}
|
45
|
+
|
46
|
+
const { mappingsCallback, addDependencies } = useDependencies(({ dependencies, updateTheme, updateRuntime }) => {
|
47
|
+
const listensToTheme = dependencies.includes(UnistyleDependency.Theme)
|
48
|
+
// @ts-expect-error - this is hidden from TS
|
49
|
+
const dispose = StyleSheet.addChangeListener(changedDependencies => {
|
50
|
+
if (listensToTheme && changedDependencies.includes(UnistyleDependency.Theme)) {
|
51
|
+
updateTheme()
|
52
|
+
}
|
53
|
+
|
54
|
+
if (changedDependencies.some((dependency: UnistyleDependency) => dependencies.includes(dependency))) {
|
55
|
+
SUPPORTED_STYLE_PROPS.forEach(propName => {
|
56
|
+
if (narrowedProps?.[propName]) {
|
57
|
+
stylesRef.current = {
|
58
|
+
...stylesRef.current,
|
59
|
+
// @ts-expect-error - this is hidden from TS
|
60
|
+
[propName]: props[propName].__proto__?.getStyle?.() || props[propName]
|
61
|
+
}
|
62
|
+
|
63
|
+
isForcedRef.current = true
|
64
|
+
}
|
65
|
+
})
|
66
|
+
|
67
|
+
updateRuntime()
|
68
|
+
}
|
69
|
+
})
|
70
|
+
|
71
|
+
return () => dispose()
|
72
|
+
})
|
73
|
+
|
74
|
+
useEffect(() => {
|
75
|
+
const styleDependencies = narrowedProps.style?.__proto__.uni__dependencies ?? [] as Array<UnistyleDependency>
|
76
|
+
const contentContainerStyleDependencies = narrowedProps.contentContainerStyle?.__proto__.uni__dependencies ?? [] as Array<UnistyleDependency>
|
77
|
+
|
78
|
+
addDependencies([...styleDependencies, ...contentContainerStyleDependencies])
|
79
|
+
}, [narrowedProps.style, narrowedProps.contentContainerStyle])
|
80
|
+
|
81
|
+
const mappingProps = mappings ? mappingsCallback(mappings) : {}
|
82
|
+
const unistyleProps = narrowedProps.uniProps ? mappingsCallback(narrowedProps.uniProps) : {}
|
83
|
+
const finalProps = deepMergeObjects<Record<string, any>>(mappingProps, unistyleProps, props)
|
84
|
+
|
85
|
+
// override with Unistyles styles
|
86
|
+
SUPPORTED_STYLE_PROPS.forEach(propName => {
|
87
|
+
if (finalProps[propName]) {
|
88
|
+
finalProps[propName] = stylesRef.current[propName]
|
89
|
+
}
|
90
|
+
})
|
91
|
+
|
92
|
+
isForcedRef.current = false
|
93
|
+
|
94
|
+
return <NativeComponent {...finalProps as TProps} ref={ref} />
|
95
|
+
})
|
96
|
+
}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import React, { useEffect, useState, type ComponentType, forwardRef, useRef, useMemo, type ComponentProps, type ComponentRef } from 'react'
|
2
|
+
import type { PartialBy } from '../../types/common'
|
3
|
+
import { UnistylesListener } from '../../web/listener'
|
4
|
+
import { UnistylesShadowRegistry } from '../../web'
|
5
|
+
import { equal } from '../../web/utils'
|
6
|
+
import { deepMergeObjects } from '../../utils'
|
7
|
+
import type { Mappings, SupportedStyleProps } from './types'
|
8
|
+
import { useDependencies } from './useDependencies'
|
9
|
+
import { UnistyleDependency } from '../../specs/NativePlatform'
|
10
|
+
import type { UnistylesValues } from '../../types'
|
11
|
+
|
12
|
+
const useShadowRegistry = (style?: Record<string, any>) => {
|
13
|
+
const [ref] = useState(document.createElement('div'))
|
14
|
+
const oldClassNames = useRef<Array<string>>([])
|
15
|
+
const classNames = useMemo(() => {
|
16
|
+
if (!style) {
|
17
|
+
return []
|
18
|
+
}
|
19
|
+
|
20
|
+
const newClassNames = UnistylesShadowRegistry.add(ref, [style]) ?? []
|
21
|
+
|
22
|
+
if (equal(oldClassNames.current, newClassNames)) {
|
23
|
+
return oldClassNames.current
|
24
|
+
}
|
25
|
+
|
26
|
+
oldClassNames.current = newClassNames
|
27
|
+
|
28
|
+
return newClassNames
|
29
|
+
}, [style])
|
30
|
+
|
31
|
+
useEffect(() => () => {
|
32
|
+
// Remove styles on unmount
|
33
|
+
if (style) {
|
34
|
+
UnistylesShadowRegistry.add(null, [style])
|
35
|
+
}
|
36
|
+
})
|
37
|
+
|
38
|
+
return classNames
|
39
|
+
}
|
40
|
+
|
41
|
+
// @ts-expect-error
|
42
|
+
type GenericComponentProps<T> = ComponentProps<T>
|
43
|
+
// @ts-expect-error
|
44
|
+
type GenericComponentRef<T> = ComponentRef<T>
|
45
|
+
|
46
|
+
export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(Component: TComponent, mappings?: Mappings<TMappings>) => {
|
47
|
+
type TProps = GenericComponentProps<TComponent>
|
48
|
+
type PropsWithUnistyles = PartialBy<TProps, keyof TMappings | SupportedStyleProps> & {
|
49
|
+
uniProps?: Mappings<TProps>
|
50
|
+
style?: UnistylesValues,
|
51
|
+
contentContainerStyle?: UnistylesValues
|
52
|
+
}
|
53
|
+
|
54
|
+
return forwardRef<GenericComponentRef<TComponent>, PropsWithUnistyles>((props, ref) => {
|
55
|
+
const narrowedProps = props as PropsWithUnistyles
|
56
|
+
const styleClassNames = useShadowRegistry(narrowedProps.style)
|
57
|
+
const contentContainerStyleClassNames = useShadowRegistry(narrowedProps.contentContainerStyle)
|
58
|
+
const { mappingsCallback } = useDependencies(({ dependencies, updateTheme, updateRuntime }) => {
|
59
|
+
const disposeTheme = UnistylesListener.addListeners(dependencies.filter(dependency => dependency === UnistyleDependency.Theme), updateTheme)
|
60
|
+
const disposeRuntime = UnistylesListener.addListeners(dependencies.filter(dependency => dependency !== UnistyleDependency.Theme), updateRuntime)
|
61
|
+
|
62
|
+
return () => {
|
63
|
+
disposeTheme()
|
64
|
+
disposeRuntime()
|
65
|
+
}
|
66
|
+
})
|
67
|
+
const mappingsProps = mappings ? mappingsCallback(mappings) : {}
|
68
|
+
const unistyleProps = narrowedProps.uniProps ? mappingsCallback(narrowedProps.uniProps) : {}
|
69
|
+
|
70
|
+
const combinedProps = {
|
71
|
+
...deepMergeObjects(mappingsProps, unistyleProps, props),
|
72
|
+
...narrowedProps.style ? {
|
73
|
+
style: {
|
74
|
+
$$css: true,
|
75
|
+
'unistyles': styleClassNames.join(' ')
|
76
|
+
},
|
77
|
+
} : {},
|
78
|
+
...narrowedProps.contentContainerStyle ? {
|
79
|
+
style: {
|
80
|
+
$$css: true,
|
81
|
+
'unistyles': contentContainerStyleClassNames.join(' ')
|
82
|
+
},
|
83
|
+
} : {},
|
84
|
+
} as any
|
85
|
+
|
86
|
+
const NativeComponent = Component as ComponentType
|
87
|
+
|
88
|
+
return <NativeComponent {...combinedProps} ref={ref} />
|
89
|
+
})
|
90
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import { useEffect, useLayoutEffect, useState } from 'react'
|
2
|
+
import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs'
|
3
|
+
import { isValidMq, parseMq, isUnistylesMq } from '../mq'
|
4
|
+
|
5
|
+
export const useMedia = (config: { mq: symbol }) => {
|
6
|
+
const computeIsVisible = (): boolean => {
|
7
|
+
const maybeMq = config.mq as unknown as string
|
8
|
+
|
9
|
+
if (!isUnistylesMq(maybeMq)) {
|
10
|
+
console.error(`🦄 Unistyles: Received invalid mq: ${maybeMq}`)
|
11
|
+
|
12
|
+
return false
|
13
|
+
}
|
14
|
+
|
15
|
+
const parsedMq = parseMq(maybeMq)
|
16
|
+
|
17
|
+
if (!isValidMq(parsedMq)) {
|
18
|
+
console.error(`🦄 Unistyles: Received invalid mq where min is greater than max: ${maybeMq}`)
|
19
|
+
|
20
|
+
return false
|
21
|
+
}
|
22
|
+
|
23
|
+
const { width, height } = UnistylesRuntime.screen
|
24
|
+
|
25
|
+
if (parsedMq.minWidth !== undefined && width < parsedMq.minWidth) {
|
26
|
+
return false
|
27
|
+
}
|
28
|
+
|
29
|
+
if (parsedMq.maxWidth !== undefined && width > parsedMq.maxWidth) {
|
30
|
+
return false
|
31
|
+
}
|
32
|
+
|
33
|
+
if (parsedMq.minHeight !== undefined && height < parsedMq.minHeight) {
|
34
|
+
return false
|
35
|
+
}
|
36
|
+
|
37
|
+
if (parsedMq.maxHeight !== undefined && height > parsedMq.maxHeight) {
|
38
|
+
return false
|
39
|
+
}
|
40
|
+
|
41
|
+
return true
|
42
|
+
}
|
43
|
+
const [isVisible, setIsVisible] = useState<boolean | null>(computeIsVisible())
|
44
|
+
|
45
|
+
useEffect(() => {
|
46
|
+
setIsVisible(computeIsVisible())
|
47
|
+
}, [config.mq])
|
48
|
+
|
49
|
+
useLayoutEffect(() => {
|
50
|
+
// @ts-expect-error - this is hidden from TS
|
51
|
+
const removeChangeListener = StyleSheet.addChangeListener((dependencies: Array<UnistyleDependency>) => {
|
52
|
+
if (dependencies.includes(UnistyleDependency.Breakpoints)) {
|
53
|
+
setIsVisible(computeIsVisible())
|
54
|
+
}
|
55
|
+
})
|
56
|
+
|
57
|
+
return () => {
|
58
|
+
removeChangeListener()
|
59
|
+
}
|
60
|
+
}, [config.mq])
|
61
|
+
|
62
|
+
return {
|
63
|
+
isVisible
|
64
|
+
}
|
65
|
+
}
|
package/src/hooks/useMedia.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import { useEffect,
|
2
|
-
import {
|
3
|
-
import { isValidMq, parseMq, isUnistylesMq } from '../mq'
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
2
|
+
import { isUnistylesMq, isValidMq, parseMq } from '../mq'
|
4
3
|
|
5
4
|
export const useMedia = (config: { mq: symbol }) => {
|
6
|
-
const
|
5
|
+
const disposeRef = useRef(() => {})
|
6
|
+
const [isVisible, setIsVisible] = useState(() => {
|
7
7
|
const maybeMq = config.mq as unknown as string
|
8
8
|
|
9
9
|
if (!isUnistylesMq(maybeMq)) {
|
@@ -20,43 +20,26 @@ export const useMedia = (config: { mq: symbol }) => {
|
|
20
20
|
return false
|
21
21
|
}
|
22
22
|
|
23
|
-
const {
|
23
|
+
const { minWidth, maxWidth, minHeight, maxHeight } = parsedMq
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
const mediaQuery = [
|
26
|
+
minWidth !== undefined ? `(min-width: ${minWidth}px)` : undefined,
|
27
|
+
maxWidth !== undefined ? `(max-width: ${maxWidth}px)` : undefined,
|
28
|
+
minHeight !== undefined ? `(min-height: ${minHeight}px)` : undefined,
|
29
|
+
maxHeight !== undefined ? `(max-height: ${maxHeight}px)` : undefined
|
30
|
+
].filter(Boolean).join(' and ')
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
}
|
32
|
+
const media = window.matchMedia(mediaQuery)
|
33
|
+
const handler = (event: MediaQueryListEvent) => setIsVisible(event.matches)
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
}
|
35
|
+
media.addEventListener('change', handler)
|
36
|
+
disposeRef.current = () => media.removeEventListener('change', handler)
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
}
|
40
|
-
|
41
|
-
return true
|
42
|
-
}
|
43
|
-
const [isVisible, setIsVisible] = useState<boolean | null>(computeIsVisible())
|
38
|
+
return media.matches
|
39
|
+
})
|
44
40
|
|
45
|
-
|
46
|
-
|
47
|
-
}, [config.mq])
|
48
|
-
|
49
|
-
useLayoutEffect(() => {
|
50
|
-
const removeChangeListener = (StyleSheet as UnistylesStyleSheet).addChangeListener(dependencies => {
|
51
|
-
if (dependencies.includes(UnistyleDependency.Breakpoints)) {
|
52
|
-
setIsVisible(computeIsVisible())
|
53
|
-
}
|
54
|
-
})
|
55
|
-
|
56
|
-
return () => {
|
57
|
-
removeChangeListener()
|
58
|
-
}
|
59
|
-
}, [config.mq])
|
41
|
+
// Unmount
|
42
|
+
useEffect(() => () => disposeRef.current(), [])
|
60
43
|
|
61
44
|
return {
|
62
45
|
isVisible
|
package/src/index.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
export * from './specs'
|
2
2
|
export { mq } from './mq'
|
3
3
|
export type { UnistylesThemes, UnistylesBreakpoints } from './global'
|
4
|
-
export { createUnistylesComponent,
|
4
|
+
export { createUnistylesComponent, withUnistyles } from './core'
|
5
5
|
export type { UnistylesVariants } from './types'
|
6
|
-
export
|
6
|
+
export { Display, Hide, Variants, ScopedTheme } from './components'
|
@@ -2,13 +2,19 @@ import { NitroModules } from 'react-native-nitro-modules'
|
|
2
2
|
import type { UnistylesShadowRegistry as UnistylesShadowRegistrySpec } from './ShadowRegistry.nitro'
|
3
3
|
import type { ShadowNode, Unistyle, ViewHandle } from './types'
|
4
4
|
|
5
|
+
type Variants = Record<string, string | boolean | undefined>
|
6
|
+
|
5
7
|
interface ShadowRegistry extends UnistylesShadowRegistrySpec {
|
6
8
|
// Babel API
|
7
|
-
add(handle?: ViewHandle, styles?: Array<Unistyle
|
9
|
+
add(handle?: ViewHandle, styles?: Array<Unistyle>): void,
|
8
10
|
remove(handle?: ViewHandle): void,
|
9
11
|
// JSI
|
10
|
-
link(node: ShadowNode, styles?: Array<Unistyle
|
11
|
-
unlink(node: ShadowNode): void
|
12
|
+
link(node: ShadowNode, styles?: Array<Unistyle>): void,
|
13
|
+
unlink(node: ShadowNode): void,
|
14
|
+
selectVariants(variants?: Variants): void,
|
15
|
+
setScopedTheme(themeName?: string): void,
|
16
|
+
getScopedTheme(): string | undefined,
|
17
|
+
getVariants(): Record<string, string | boolean | undefined> | undefined,
|
12
18
|
}
|
13
19
|
|
14
20
|
const HybridShadowRegistry = NitroModules.createHybridObject<ShadowRegistry>('UnistylesShadowRegistry')
|
@@ -17,6 +23,9 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
|
|
17
23
|
const node = handle?.__internalInstanceHandle?.stateNode?.node
|
18
24
|
?? handle?.getScrollResponder?.()?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node
|
19
25
|
?? handle?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node
|
26
|
+
?? handle?._viewRef?.__internalInstanceHandle?.stateNode?.node
|
27
|
+
?? handle?.viewRef?.current?.__internalInstanceHandle?.stateNode?.node
|
28
|
+
?? handle?._nativeRef?.__internalInstanceHandle?.stateNode?.node
|
20
29
|
|
21
30
|
if (!node) {
|
22
31
|
throw new Error(`Unistyles: Could not find shadow node for one of your components of type ${handle?.__internalInstanceHandle?.elementType ?? 'unknown'}`)
|
@@ -25,7 +34,7 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
|
|
25
34
|
return node
|
26
35
|
}
|
27
36
|
|
28
|
-
HybridShadowRegistry.add = (handle, styles
|
37
|
+
HybridShadowRegistry.add = (handle, styles) => {
|
29
38
|
// virtualized nodes can be null
|
30
39
|
if (!handle || !styles || !Array.isArray(styles)) {
|
31
40
|
return
|
@@ -36,7 +45,7 @@ HybridShadowRegistry.add = (handle, styles, variants, args, id) => {
|
|
36
45
|
.filter(style => !style?.initial?.updater)
|
37
46
|
.filter(Boolean)
|
38
47
|
|
39
|
-
HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles
|
48
|
+
HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles)
|
40
49
|
}
|
41
50
|
|
42
51
|
HybridShadowRegistry.remove = handle => {
|
@@ -22,7 +22,24 @@ export type ViewHandle = {
|
|
22
22
|
__internalInstanceHandle?: {
|
23
23
|
stateNode?: StateNode
|
24
24
|
}
|
25
|
-
})
|
25
|
+
}),
|
26
|
+
_viewRef?: {
|
27
|
+
__internalInstanceHandle?: {
|
28
|
+
stateNode?: StateNode
|
29
|
+
}
|
30
|
+
},
|
31
|
+
viewRef?: {
|
32
|
+
current?: {
|
33
|
+
__internalInstanceHandle?: {
|
34
|
+
stateNode?: StateNode
|
35
|
+
}
|
36
|
+
}
|
37
|
+
},
|
38
|
+
_nativeRef?: {
|
39
|
+
__internalInstanceHandle?: {
|
40
|
+
stateNode?: StateNode
|
41
|
+
}
|
42
|
+
}
|
26
43
|
}
|
27
44
|
|
28
45
|
export type Unistyle = {
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import './TurboUnistyles'
|
2
|
+
|
3
|
+
import { Runtime } from './UnistylesRuntime'
|
4
|
+
import { StyleSheet } from './StyleSheet'
|
5
|
+
import type { UnistylesStyleSheet } from './StyleSheet'
|
6
|
+
import { UnistylesShadowRegistry } from './ShadowRegistry'
|
7
|
+
import type { UnistylesMiniRuntime } from './UnistylesRuntime'
|
8
|
+
import { StatusBarStyle, ColorScheme, Orientation } from './types'
|
9
|
+
import { UnistyleDependency } from './NativePlatform'
|
10
|
+
|
11
|
+
export {
|
12
|
+
StatusBarStyle,
|
13
|
+
ColorScheme,
|
14
|
+
Orientation,
|
15
|
+
UnistyleDependency
|
16
|
+
}
|
17
|
+
|
18
|
+
export {
|
19
|
+
UnistylesShadowRegistry,
|
20
|
+
Runtime as UnistylesRuntime,
|
21
|
+
StyleSheet,
|
22
|
+
}
|
23
|
+
|
24
|
+
export type {
|
25
|
+
UnistylesMiniRuntime,
|
26
|
+
UnistylesStyleSheet
|
27
|
+
}
|
package/src/specs/index.ts
CHANGED
@@ -1,27 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
import { StyleSheet } from './StyleSheet'
|
5
|
-
import type { UnistylesStyleSheet } from './StyleSheet'
|
6
|
-
import { UnistylesShadowRegistry } from './ShadowRegistry'
|
7
|
-
import type { UnistylesMiniRuntime } from './UnistylesRuntime'
|
8
|
-
import { StatusBarStyle, ColorScheme, Orientation } from './types'
|
9
|
-
import { UnistyleDependency } from './NativePlatform'
|
10
|
-
|
11
|
-
export {
|
12
|
-
StatusBarStyle,
|
13
|
-
ColorScheme,
|
14
|
-
Orientation,
|
15
|
-
UnistyleDependency
|
16
|
-
}
|
17
|
-
|
18
|
-
export {
|
19
|
-
UnistylesShadowRegistry,
|
20
|
-
Runtime as UnistylesRuntime,
|
21
|
-
StyleSheet,
|
22
|
-
}
|
23
|
-
|
24
|
-
export type {
|
25
|
-
UnistylesMiniRuntime,
|
26
|
-
UnistylesStyleSheet
|
27
|
-
}
|
1
|
+
export * from '../web'
|
2
|
+
export type { UnistylesMiniRuntime } from './UnistylesRuntime'
|
3
|
+
export { UnistyleDependency } from './NativePlatform'
|
package/src/web/create.ts
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
import type { ReactNativeStyleSheet } from '../types'
|
2
1
|
import type { StyleSheetWithSuperPowers, StyleSheet } from '../types/stylesheet'
|
3
|
-
import { assignSecrets,
|
4
|
-
import { deepMergeObjects } from '../utils'
|
2
|
+
import { assignSecrets, error, removeInlineStyles } from './utils'
|
5
3
|
import { UnistylesRuntime } from './runtime'
|
6
|
-
import {
|
4
|
+
import { UnistylesShadowRegistry } from '../specs'
|
5
|
+
|
6
|
+
const useVariants = ['useVariants', (variants: Record<string, string | boolean>) => {
|
7
|
+
UnistylesShadowRegistry.selectVariants(variants)
|
8
|
+
}]
|
7
9
|
|
8
10
|
export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, id?: string) => {
|
9
11
|
if (!id) {
|
@@ -13,45 +15,25 @@ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, id?: s
|
|
13
15
|
const computedStylesheet = typeof stylesheet === 'function'
|
14
16
|
? stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime)
|
15
17
|
: stylesheet
|
16
|
-
const selectedVariants = new Map<string, any>()
|
17
18
|
|
18
|
-
const copyVariants = () => Object.fromEntries(selectedVariants.entries())
|
19
19
|
const addSecrets = (value: any, key: string, args?: Array<any>) => assignSecrets(value, {
|
20
20
|
__uni__key: key,
|
21
|
-
__uni__refs: new Set(),
|
22
21
|
__uni__stylesheet: stylesheet,
|
23
22
|
__uni__args: args,
|
24
|
-
|
23
|
+
__uni__refs: new Set()
|
25
24
|
})
|
26
25
|
|
27
|
-
const
|
28
|
-
const key = String(_key)
|
29
|
-
|
26
|
+
const styleSheetStyles = Object.entries(computedStylesheet).map(([key, value]) => {
|
30
27
|
if (typeof value === 'function') {
|
31
|
-
|
32
|
-
const result = value(...args)
|
33
|
-
const variants = Object.fromEntries(getVariants({ [key]: result } as ReactNativeStyleSheet<StyleSheet>, copyVariants()))
|
34
|
-
const resultWithVariants = deepMergeObjects(result, variants[key] ?? {})
|
28
|
+
return [key, (...args: Array<any>) => {
|
29
|
+
const result = removeInlineStyles(value(...args))
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
}
|
39
|
-
|
40
|
-
// Add secrets to dynamic styles function
|
41
|
-
return addSecrets(dynamicStyle, key)
|
31
|
+
return addSecrets(result, key, args)
|
32
|
+
}]
|
42
33
|
}
|
43
34
|
|
44
|
-
|
45
|
-
return addSecrets(getStyles(value), key)
|
46
|
-
}) as ReactNativeStyleSheet<StyleSheet>
|
47
|
-
|
48
|
-
// Inject useVariants hook to styles
|
49
|
-
Object.defineProperty(styles, 'useVariants', {
|
50
|
-
value: (variants: Record<string, string | boolean>) => {
|
51
|
-
Object.entries(variants).forEach(([key, value]) => selectedVariants.set(key, value))
|
52
|
-
},
|
53
|
-
configurable: false,
|
35
|
+
return [key, addSecrets(removeInlineStyles(value), key)]
|
54
36
|
})
|
55
37
|
|
56
|
-
return
|
38
|
+
return Object.fromEntries(styleSheetStyles.concat([useVariants]))
|
57
39
|
}
|
package/src/web/index.ts
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
import { create } from './create'
|
2
2
|
import { UnistylesState } from './state'
|
3
3
|
import { deepMergeObjects } from '../utils'
|
4
|
+
import type { CreateUnistylesStyleSheet } from '../types'
|
4
5
|
|
5
6
|
export const StyleSheet = {
|
6
7
|
configure: UnistylesState.init,
|
7
|
-
create,
|
8
|
+
create: create as CreateUnistylesStyleSheet,
|
8
9
|
absoluteFill: {
|
9
10
|
position: 'absolute',
|
10
11
|
left: 0,
|
@@ -21,7 +22,7 @@ export const StyleSheet = {
|
|
21
22
|
},
|
22
23
|
compose: (a: object, b: object) => deepMergeObjects(a, b),
|
23
24
|
flatten: (...styles: Array<object>) => deepMergeObjects(...styles),
|
24
|
-
hairlineWidth: 1
|
25
|
+
hairlineWidth: 1 as number
|
25
26
|
}
|
26
27
|
|
27
28
|
export { UnistylesRuntime } from './runtime'
|
package/src/web/registry.ts
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
import type { UnistylesTheme, UnistylesValues } from '../types'
|
2
2
|
import type { StyleSheet, StyleSheetWithSuperPowers } from '../types/stylesheet'
|
3
3
|
import { UnistylesRuntime } from './runtime'
|
4
|
-
import { extractMediaQueryValue, keyInObject, getMediaQuery, generateHash, extractUnistyleDependencies } from './utils'
|
4
|
+
import { extractMediaQueryValue, keyInObject, getMediaQuery, generateHash, extractUnistyleDependencies, error } from './utils'
|
5
5
|
import { UnistylesListener } from './listener'
|
6
6
|
import { convertUnistyles } from './convert'
|
7
|
-
import type { UnistyleDependency } from '../specs
|
8
|
-
import type { UnistylesMiniRuntime } from '../specs'
|
7
|
+
import type { UnistylesMiniRuntime, UnistyleDependency } from '../specs'
|
9
8
|
|
10
9
|
type ApplyRuleProps = {
|
11
10
|
hash: string,
|
@@ -39,11 +38,21 @@ class UnistylesRegistryBuilder {
|
|
39
38
|
return tag
|
40
39
|
}
|
41
40
|
|
42
|
-
getComputedStylesheet = (stylesheet: StyleSheetWithSuperPowers<StyleSheet
|
41
|
+
getComputedStylesheet = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, scopedThemeName?: UnistylesTheme) => {
|
43
42
|
if (typeof stylesheet !== 'function') {
|
44
43
|
return stylesheet
|
45
44
|
}
|
46
45
|
|
46
|
+
if (scopedThemeName) {
|
47
|
+
const scopedTheme = UnistylesRuntime.getTheme(scopedThemeName)
|
48
|
+
|
49
|
+
if (!scopedTheme) {
|
50
|
+
throw error(`Unistyles: You're trying to use scoped theme '${scopedThemeName}' but it wasn't registered.`)
|
51
|
+
}
|
52
|
+
|
53
|
+
return stylesheet(scopedTheme, UnistylesRuntime.miniRuntime)
|
54
|
+
}
|
55
|
+
|
47
56
|
const computedStylesheet = this.stylesheets.get(stylesheet)
|
48
57
|
|
49
58
|
if (computedStylesheet) {
|
@@ -85,7 +94,7 @@ class UnistylesRegistryBuilder {
|
|
85
94
|
|
86
95
|
counter.add(value)
|
87
96
|
this.stylesCounter.set(hash, counter)
|
88
|
-
this.applyStyles(hash,
|
97
|
+
this.applyStyles(hash, value)
|
89
98
|
|
90
99
|
return { hash, existingHash: false }
|
91
100
|
}
|
@@ -96,7 +105,7 @@ class UnistylesRegistryBuilder {
|
|
96
105
|
}
|
97
106
|
|
98
107
|
applyStyles = (hash: string, styles: Record<string, any>) => {
|
99
|
-
Object.entries(styles).forEach(([key, value]) => {
|
108
|
+
Object.entries(convertUnistyles(styles)).forEach(([key, value]) => {
|
100
109
|
if (!this.styleTag.sheet) {
|
101
110
|
return
|
102
111
|
}
|
package/src/web/runtime.ts
CHANGED
@@ -4,9 +4,11 @@ import type { UnistylesMiniRuntime } from '../specs/UnistylesRuntime'
|
|
4
4
|
import { WebContentSizeCategory } from '../types'
|
5
5
|
import { UnistylesListener } from './listener'
|
6
6
|
import { NavigationBar, StatusBar } from './mock'
|
7
|
-
import { UnistylesState } from './state'
|
8
7
|
import { error, isServer, schemeToTheme } from './utils'
|
9
8
|
|
9
|
+
// Keep this import here, otherwise circular dependency will occur and break the build
|
10
|
+
import { UnistylesState } from './state'
|
11
|
+
|
10
12
|
class UnistylesRuntimeBuilder {
|
11
13
|
lightMedia = this.getLightMedia()
|
12
14
|
darkMedia = this.getDarkMedia()
|