react-native-unistyles 3.0.0-beta.4 → 3.0.0-beta.6
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 +18 -3
- package/android/src/main/cxx/NativeUnistylesModule.cpp +2 -2
- package/android/src/main/cxx/NativeUnistylesModule.h +1 -1
- package/android/src/main/java/com/unistyles/NativePlatform+android.kt +1 -2
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +4 -0
- package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +2 -1
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +0 -4
- package/android/src/main/java/com/unistyles/UnistylesPackage.kt +6 -6
- package/components/native/ActivityIndicator/package.json +2 -1
- package/components/native/Animated/package.json +5 -0
- package/components/native/FlatList/package.json +2 -1
- package/components/native/Image/package.json +2 -1
- package/components/native/ImageBackground/package.json +2 -1
- package/components/native/KeyboardAvoidingView/package.json +2 -1
- package/components/native/NativeText/package.json +5 -0
- package/components/native/NativeView/package.json +5 -0
- package/components/native/Pressable/package.json +1 -1
- package/components/native/RefreshControl/package.json +2 -1
- package/components/native/ScrollView/package.json +2 -1
- package/components/native/SectionList/package.json +2 -1
- package/components/native/Switch/package.json +2 -1
- package/components/native/Text/package.json +2 -1
- package/components/native/TextInput/package.json +2 -1
- package/components/native/TouchableHighlight/package.json +2 -1
- package/components/native/TouchableOpacity/package.json +2 -1
- package/components/native/View/package.json +2 -1
- package/components/native/VirtualizedList/package.json +2 -1
- package/cxx/common/Constants.h +4 -4
- package/cxx/common/Helpers.h +1 -1
- package/cxx/core/HashGenerator.cpp +23 -0
- package/cxx/core/HashGenerator.h +13 -0
- package/cxx/core/HostUnistyle.cpp +83 -0
- package/cxx/core/HostUnistyle.h +27 -0
- package/cxx/core/RNStyle.h +18 -0
- package/cxx/core/Unistyle.h +13 -4
- package/cxx/core/UnistyleWrapper.h +92 -47
- package/cxx/core/UnistylesRegistry.cpp +40 -11
- package/cxx/core/UnistylesRegistry.h +5 -4
- package/cxx/hybridObjects/HybridNavigationBar.cpp +3 -3
- package/cxx/hybridObjects/HybridNavigationBar.h +2 -2
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +39 -45
- package/cxx/hybridObjects/HybridShadowRegistry.h +0 -10
- package/cxx/hybridObjects/HybridStatusBar.cpp +3 -3
- package/cxx/hybridObjects/HybridStatusBar.h +2 -2
- package/cxx/hybridObjects/HybridStyleSheet.cpp +52 -10
- package/cxx/hybridObjects/HybridStyleSheet.h +2 -1
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +15 -15
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -2
- package/cxx/parser/Parser.cpp +26 -27
- package/cxx/parser/Parser.h +2 -1
- package/ios/NativePlatform+ios.swift +21 -11
- package/ios/NativePlatform.swift +2 -2
- package/ios/UnistylesModuleOnLoad.h +4 -4
- package/ios/UnistylesModuleOnLoad.mm +5 -8
- package/lib/commonjs/components/ScopedTheme.js.map +1 -1
- package/lib/commonjs/components/index.js +0 -7
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/components/native/Animated.js +23 -0
- package/lib/commonjs/components/native/Animated.js.map +1 -0
- package/lib/commonjs/components/native/ImageBackground.js +47 -1
- package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
- package/lib/commonjs/components/native/ImageBackground.native.js +10 -0
- package/lib/commonjs/components/native/ImageBackground.native.js.map +1 -0
- package/lib/commonjs/components/native/NativeText.js +13 -0
- package/lib/commonjs/components/native/NativeText.js.map +1 -0
- package/lib/commonjs/components/native/NativeText.native.js +18 -0
- package/lib/commonjs/components/native/NativeText.native.js.map +1 -0
- package/lib/commonjs/components/native/NativeView.js +9 -0
- package/lib/commonjs/components/native/NativeView.js.map +1 -0
- package/lib/commonjs/components/native/NativeView.native.js +20 -0
- package/lib/commonjs/components/native/NativeView.native.js.map +1 -0
- package/lib/commonjs/components/native/Pressable.js +26 -51
- package/lib/commonjs/components/native/Pressable.js.map +1 -1
- package/lib/commonjs/components/native/Pressable.native.js +25 -9
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.js +33 -5
- package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.native.js +54 -0
- package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -0
- package/lib/commonjs/core/createUnistylesImageBackground.js +41 -15
- package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/commonjs/core/getClassname.js +23 -0
- package/lib/commonjs/core/getClassname.js.map +1 -0
- package/lib/commonjs/core/getClassname.native.js +9 -0
- package/lib/commonjs/core/getClassname.native.js.map +1 -0
- package/lib/commonjs/core/index.js +14 -7
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/core/passForwardRef.js +2 -2
- package/lib/commonjs/core/passForwardRef.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/index.js +13 -0
- package/lib/commonjs/core/useProxifiedUnistyles/index.js.map +1 -0
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js +22 -0
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -0
- package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js +26 -0
- package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js.map +1 -0
- package/lib/commonjs/core/useProxifiedUnistyles/types.js +6 -0
- package/lib/commonjs/core/useProxifiedUnistyles/types.js.map +1 -0
- package/lib/commonjs/core/{withUnistyles/useDependencies.js → useProxifiedUnistyles/useProxifiedUnistyles.js} +22 -22
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -0
- package/lib/commonjs/core/useUnistyles.js +19 -0
- package/lib/commonjs/core/useUnistyles.js.map +1 -0
- package/lib/commonjs/core/warn.js +16 -0
- package/lib/commonjs/core/warn.js.map +1 -0
- package/lib/commonjs/core/withUnistyles/withUnistyles.js +19 -55
- package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +32 -65
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/commonjs/index.js +23 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/server/getServerUnistyles.js +40 -0
- package/lib/commonjs/server/getServerUnistyles.js.map +1 -0
- package/lib/commonjs/server/hydrateServerUnistyles.js +17 -0
- package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -0
- package/lib/commonjs/server/index.js +34 -0
- package/lib/commonjs/server/index.js.map +1 -0
- package/lib/commonjs/server/resetServerUnistyles.js +16 -0
- package/lib/commonjs/server/resetServerUnistyles.js.map +1 -0
- package/lib/commonjs/server/types.js +8 -0
- package/lib/commonjs/server/types.js.map +1 -0
- package/lib/commonjs/server/useServerUnistyles.js +27 -0
- package/lib/commonjs/server/useServerUnistyles.js.map +1 -0
- package/lib/commonjs/specs/ShadowRegistry/index.js +6 -3
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/utils.js +19 -2
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/convert/object/filter.js +2 -2
- package/lib/commonjs/web/convert/object/filter.js.map +1 -1
- package/lib/commonjs/web/convert/style.js +4 -4
- package/lib/commonjs/web/convert/style.js.map +1 -1
- package/lib/commonjs/web/create.js +20 -15
- package/lib/commonjs/web/create.js.map +1 -1
- package/lib/commonjs/web/css/core.js +55 -0
- package/lib/commonjs/web/css/core.js.map +1 -0
- package/lib/commonjs/web/css/index.js +17 -0
- package/lib/commonjs/web/css/index.js.map +1 -0
- package/lib/commonjs/web/css/state.js +155 -0
- package/lib/commonjs/web/css/state.js.map +1 -0
- package/lib/commonjs/web/css/utils.js +47 -0
- package/lib/commonjs/web/css/utils.js.map +1 -0
- package/lib/commonjs/web/index.js +14 -18
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/commonjs/web/listener.js +9 -7
- package/lib/commonjs/web/listener.js.map +1 -1
- package/lib/commonjs/web/registry.js +44 -123
- package/lib/commonjs/web/registry.js.map +1 -1
- package/lib/commonjs/web/runtime.js +28 -21
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/commonjs/web/services.js +28 -0
- package/lib/commonjs/web/services.js.map +1 -0
- package/lib/commonjs/web/shadowRegistry.js +46 -93
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/state.js +39 -9
- package/lib/commonjs/web/state.js.map +1 -1
- package/lib/commonjs/web/types.js +6 -0
- package/lib/commonjs/web/types.js.map +1 -0
- package/lib/commonjs/web/utils/common.js +29 -9
- package/lib/commonjs/web/utils/common.js.map +1 -1
- package/lib/commonjs/web/utils/unistyle.js +32 -19
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/commonjs/web/variants.js +25 -27
- package/lib/commonjs/web/variants.js.map +1 -1
- package/lib/module/components/ScopedTheme.js.map +1 -1
- package/lib/module/components/index.js +0 -1
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/components/native/Animated.js +19 -0
- package/lib/module/components/native/Animated.js.map +1 -0
- package/lib/module/components/native/ImageBackground.js +47 -2
- package/lib/module/components/native/ImageBackground.js.map +1 -1
- package/lib/module/components/native/ImageBackground.native.js +6 -0
- package/lib/module/components/native/ImageBackground.native.js.map +1 -0
- package/lib/module/components/native/NativeText.js +4 -0
- package/lib/module/components/native/NativeText.js.map +1 -0
- package/lib/module/components/native/NativeText.native.js +15 -0
- package/lib/module/components/native/NativeText.native.js.map +1 -0
- package/lib/module/components/native/NativeView.js +5 -0
- package/lib/module/components/native/NativeView.js.map +1 -0
- package/lib/module/components/native/NativeView.native.js +17 -0
- package/lib/module/components/native/NativeView.native.js.map +1 -0
- package/lib/module/components/native/Pressable.js +27 -52
- package/lib/module/components/native/Pressable.js.map +1 -1
- package/lib/module/components/native/Pressable.native.js +26 -10
- package/lib/module/components/native/Pressable.native.js.map +1 -1
- package/lib/module/core/createUnistylesElement.js +33 -5
- package/lib/module/core/createUnistylesElement.js.map +1 -1
- package/lib/module/core/createUnistylesElement.native.js +47 -0
- package/lib/module/core/createUnistylesElement.native.js.map +1 -0
- package/lib/module/core/createUnistylesImageBackground.js +39 -14
- package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/module/core/getClassname.js +18 -0
- package/lib/module/core/getClassname.js.map +1 -0
- package/lib/module/core/getClassname.native.js +4 -0
- package/lib/module/core/getClassname.native.js.map +1 -0
- package/lib/module/core/index.js +2 -1
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/core/passForwardRef.js +2 -2
- package/lib/module/core/passForwardRef.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/index.js +4 -0
- package/lib/module/core/useProxifiedUnistyles/index.js.map +1 -0
- package/lib/module/core/useProxifiedUnistyles/listener.js +17 -0
- package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -0
- package/lib/module/core/useProxifiedUnistyles/listener.native.js +21 -0
- package/lib/module/core/useProxifiedUnistyles/listener.native.js.map +1 -0
- package/lib/module/core/useProxifiedUnistyles/types.js +4 -0
- package/lib/module/core/useProxifiedUnistyles/types.js.map +1 -0
- package/lib/module/core/{withUnistyles/useDependencies.js → useProxifiedUnistyles/useProxifiedUnistyles.js} +19 -19
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -0
- package/lib/module/core/useUnistyles.js +14 -0
- package/lib/module/core/useUnistyles.js.map +1 -0
- package/lib/module/core/warn.js +11 -0
- package/lib/module/core/warn.js.map +1 -0
- package/lib/module/core/withUnistyles/withUnistyles.js +19 -55
- package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js +33 -66
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/server/getServerUnistyles.js +34 -0
- package/lib/module/server/getServerUnistyles.js.map +1 -0
- package/lib/module/server/hydrateServerUnistyles.js +12 -0
- package/lib/module/server/hydrateServerUnistyles.js.map +1 -0
- package/lib/module/server/index.js +7 -0
- package/lib/module/server/index.js.map +1 -0
- package/lib/module/server/resetServerUnistyles.js +11 -0
- package/lib/module/server/resetServerUnistyles.js.map +1 -0
- package/lib/module/server/types.js +4 -0
- package/lib/module/server/types.js.map +1 -0
- package/lib/module/server/useServerUnistyles.js +22 -0
- package/lib/module/server/useServerUnistyles.js.map +1 -0
- package/lib/module/specs/ShadowRegistry/index.js +6 -3
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/utils.js +16 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/convert/object/filter.js +2 -2
- package/lib/module/web/convert/object/filter.js.map +1 -1
- package/lib/module/web/convert/style.js +4 -4
- package/lib/module/web/convert/style.js.map +1 -1
- package/lib/module/web/create.js +20 -15
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/css/core.js +50 -0
- package/lib/module/web/css/core.js.map +1 -0
- package/lib/module/web/css/index.js +4 -0
- package/lib/module/web/css/index.js.map +1 -0
- package/lib/module/web/css/state.js +150 -0
- package/lib/module/web/css/state.js.map +1 -0
- package/lib/module/web/css/utils.js +41 -0
- package/lib/module/web/css/utils.js.map +1 -0
- package/lib/module/web/index.js +10 -5
- package/lib/module/web/index.js.map +1 -1
- package/lib/module/web/listener.js +8 -7
- package/lib/module/web/listener.js.map +1 -1
- package/lib/module/web/registry.js +44 -124
- package/lib/module/web/registry.js.map +1 -1
- package/lib/module/web/runtime.js +27 -21
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/module/web/services.js +23 -0
- package/lib/module/web/services.js.map +1 -0
- package/lib/module/web/shadowRegistry.js +46 -94
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/state.js +39 -10
- package/lib/module/web/state.js.map +1 -1
- package/lib/module/web/types.js +4 -0
- package/lib/module/web/types.js.map +1 -0
- package/lib/module/web/utils/common.js +26 -7
- package/lib/module/web/utils/common.js.map +1 -1
- package/lib/module/web/utils/unistyle.js +31 -17
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/module/web/variants.js +25 -27
- package/lib/module/web/variants.js.map +1 -1
- package/lib/typescript/src/components/index.d.ts +0 -1
- package/lib/typescript/src/components/index.d.ts.map +1 -1
- package/lib/typescript/src/components/native/ActivityIndicator.d.ts +1 -1
- package/lib/typescript/src/components/native/ActivityIndicator.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Animated.d.ts +39 -0
- package/lib/typescript/src/components/native/Animated.d.ts.map +1 -0
- package/lib/typescript/src/components/native/FlatList.d.ts +1 -1
- package/lib/typescript/src/components/native/FlatList.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Image.d.ts +1 -1
- package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
- package/lib/typescript/src/components/native/ImageBackground.d.ts +1 -2
- package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/components/native/ImageBackground.native.d.ts +2 -0
- package/lib/typescript/src/components/native/ImageBackground.native.d.ts.map +1 -0
- package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts +1 -1
- package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts.map +1 -1
- package/lib/typescript/src/components/native/NativeText.d.ts +2 -0
- package/lib/typescript/src/components/native/NativeText.d.ts.map +1 -0
- package/lib/typescript/src/components/native/NativeText.native.d.ts +2 -0
- package/lib/typescript/src/components/native/NativeText.native.d.ts.map +1 -0
- package/lib/typescript/src/components/native/NativeView.d.ts +3 -0
- package/lib/typescript/src/components/native/NativeView.d.ts.map +1 -0
- package/lib/typescript/src/components/native/NativeView.native.d.ts +3 -0
- package/lib/typescript/src/components/native/NativeView.native.d.ts.map +1 -0
- package/lib/typescript/src/components/native/Pressable.d.ts +3 -2
- package/lib/typescript/src/components/native/Pressable.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
- package/lib/typescript/src/components/native/RefreshControl.d.ts +1 -1
- package/lib/typescript/src/components/native/RefreshControl.d.ts.map +1 -1
- package/lib/typescript/src/components/native/ScrollView.d.ts +1 -1
- package/lib/typescript/src/components/native/ScrollView.d.ts.map +1 -1
- package/lib/typescript/src/components/native/SectionList.d.ts +1 -1
- package/lib/typescript/src/components/native/SectionList.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Switch.d.ts +1 -1
- package/lib/typescript/src/components/native/Switch.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Text.d.ts +1 -1
- package/lib/typescript/src/components/native/Text.d.ts.map +1 -1
- package/lib/typescript/src/components/native/TextInput.d.ts +1 -1
- package/lib/typescript/src/components/native/TextInput.d.ts.map +1 -1
- package/lib/typescript/src/components/native/TouchableHighlight.d.ts +1 -1
- package/lib/typescript/src/components/native/TouchableHighlight.d.ts.map +1 -1
- package/lib/typescript/src/components/native/TouchableOpacity.d.ts +1 -1
- package/lib/typescript/src/components/native/TouchableOpacity.d.ts.map +1 -1
- package/lib/typescript/src/components/native/View.d.ts +1 -1
- package/lib/typescript/src/components/native/View.d.ts.map +1 -1
- package/lib/typescript/src/components/native/VirtualizedList.d.ts +1 -1
- package/lib/typescript/src/components/native/VirtualizedList.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.d.ts +1 -2
- package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.native.d.ts +2 -0
- package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -0
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts +2 -3
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/core/getClassname.d.ts +7 -0
- package/lib/typescript/src/core/getClassname.d.ts.map +1 -0
- package/lib/typescript/src/core/getClassname.native.d.ts +2 -0
- package/lib/typescript/src/core/getClassname.native.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +2 -1
- package/lib/typescript/src/core/index.d.ts.map +1 -1
- package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/index.d.ts +2 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/index.d.ts.map +1 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts +3 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts +3 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts +7 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts.map +1 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts +8 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/core/useUnistyles.d.ts +6 -0
- package/lib/typescript/src/core/useUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/core/warn.d.ts +3 -0
- package/lib/typescript/src/core/warn.d.ts.map +1 -0
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +0 -3
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +3 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/server/getServerUnistyles.d.ts +4 -0
- package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +8 -0
- package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/server/index.d.ts +5 -0
- package/lib/typescript/src/server/index.d.ts.map +1 -0
- package/lib/typescript/src/server/resetServerUnistyles.d.ts +2 -0
- package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/server/types.d.ts +5 -0
- package/lib/typescript/src/server/types.d.ts.map +1 -0
- package/lib/typescript/src/server/useServerUnistyles.d.ts +4 -0
- package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +0 -3
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +5 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +2 -0
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
- package/lib/typescript/src/web/create.d.ts.map +1 -1
- package/lib/typescript/src/web/css/core.d.ts +3 -0
- package/lib/typescript/src/web/css/core.d.ts.map +1 -0
- package/lib/typescript/src/web/css/index.d.ts +2 -0
- package/lib/typescript/src/web/css/index.d.ts.map +1 -0
- package/lib/typescript/src/web/css/state.d.ts +30 -0
- package/lib/typescript/src/web/css/state.d.ts.map +1 -0
- package/lib/typescript/src/web/css/utils.d.ts +4 -0
- package/lib/typescript/src/web/css/utils.d.ts.map +1 -0
- package/lib/typescript/src/web/index.d.ts +7 -1
- package/lib/typescript/src/web/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener.d.ts +4 -3
- package/lib/typescript/src/web/listener.d.ts.map +1 -1
- package/lib/typescript/src/web/registry.d.ts +11 -8
- package/lib/typescript/src/web/registry.d.ts.map +1 -1
- package/lib/typescript/src/web/runtime.d.ts +6 -4
- package/lib/typescript/src/web/runtime.d.ts.map +1 -1
- package/lib/typescript/src/web/services.d.ts +15 -0
- package/lib/typescript/src/web/services.d.ts.map +1 -0
- package/lib/typescript/src/web/shadowRegistry.d.ts +10 -13
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
- package/lib/typescript/src/web/state.d.ts +7 -3
- package/lib/typescript/src/web/state.d.ts.map +1 -1
- package/lib/typescript/src/web/types.d.ts +13 -0
- package/lib/typescript/src/web/types.d.ts.map +1 -0
- package/lib/typescript/src/web/utils/common.d.ts +2 -1
- package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts +5 -4
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
- package/lib/typescript/src/web/variants.d.ts +2 -2
- package/lib/typescript/src/web/variants.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JColorScheme.hpp +2 -1
- package/nitrogen/generated/android/c++/JDimensions.hpp +2 -1
- package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +36 -10
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +53 -19
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +5 -5
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JInsets.hpp +2 -1
- package/nitrogen/generated/android/c++/JOrientation.hpp +2 -1
- package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +2 -1
- package/nitrogen/generated/android/c++/JUnistylesNativeMiniRuntime.hpp +2 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/ColorScheme.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Dimensions.kt +10 -5
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +43 -14
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +43 -14
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +10 -10
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Insets.kt +13 -8
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Orientation.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistylesNativeMiniRuntime.kt +19 -14
- package/nitrogen/generated/android/unistyles+autolinking.cmake +4 -1
- package/nitrogen/generated/android/unistyles+autolinking.gradle +1 -1
- package/nitrogen/generated/android/unistylesOnLoad.cpp +7 -3
- package/nitrogen/generated/android/unistylesOnLoad.hpp +1 -1
- package/nitrogen/generated/ios/Unistyles+autolinking.rb +1 -1
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.cpp +21 -6
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +105 -27
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +5 -3
- package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +92 -33
- package/nitrogen/generated/ios/swift/ColorScheme.swift +1 -1
- package/nitrogen/generated/ios/swift/Dimensions.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_UnistylesNativeMiniRuntime.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +36 -23
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec_cxx.swift +327 -0
- package/nitrogen/generated/ios/swift/Insets.swift +1 -1
- package/nitrogen/generated/ios/swift/Orientation.swift +1 -1
- package/nitrogen/generated/ios/swift/UnistyleDependency.swift +1 -1
- package/nitrogen/generated/ios/swift/UnistylesNativeMiniRuntime.swift +1 -1
- package/nitrogen/generated/shared/c++/ColorScheme.hpp +1 -1
- package/nitrogen/generated/shared/c++/Dimensions.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/Insets.hpp +1 -1
- package/nitrogen/generated/shared/c++/Orientation.hpp +1 -1
- package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -2
- package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +1 -1
- package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +1 -1
- package/package.json +23 -14
- package/plugin/consts.js +63 -0
- package/plugin/exotic.js +54 -0
- package/plugin/import.js +1 -21
- package/plugin/index.d.ts +89 -0
- package/plugin/index.js +58 -96
- package/plugin/stylesheet.js +28 -1
- package/plugin/variants.js +49 -75
- package/src/components/ScopedTheme.tsx +1 -1
- package/src/components/index.ts +0 -1
- package/src/components/native/Animated.tsx +17 -0
- package/src/components/native/ImageBackground.native.tsx +4 -0
- package/src/components/native/ImageBackground.tsx +57 -2
- package/src/components/native/NativeText.native.tsx +12 -0
- package/src/components/native/NativeText.tsx +1 -0
- package/src/components/native/NativeView.native.tsx +13 -0
- package/src/components/native/NativeView.tsx +3 -0
- package/src/components/native/Pressable.native.tsx +32 -15
- package/src/components/native/Pressable.tsx +35 -69
- package/src/core/createUnistylesElement.native.tsx +51 -0
- package/src/core/createUnistylesElement.tsx +47 -8
- package/src/core/createUnistylesImageBackground.tsx +44 -18
- package/src/core/getClassname.native.ts +1 -0
- package/src/core/getClassname.ts +14 -0
- package/src/core/index.ts +2 -1
- package/src/core/passForwardRef.ts +1 -2
- package/src/core/useProxifiedUnistyles/index.ts +1 -0
- package/src/core/useProxifiedUnistyles/listener.native.ts +18 -0
- package/src/core/useProxifiedUnistyles/listener.ts +13 -0
- package/src/core/useProxifiedUnistyles/types.ts +7 -0
- package/src/core/{withUnistyles/useDependencies.ts → useProxifiedUnistyles/useProxifiedUnistyles.ts} +19 -26
- package/src/core/useUnistyles.ts +11 -0
- package/src/core/warn.ts +13 -0
- package/src/core/withUnistyles/withUnistyles.native.tsx +39 -68
- package/src/core/withUnistyles/withUnistyles.tsx +19 -56
- package/src/index.ts +3 -2
- package/src/server/getServerUnistyles.tsx +21 -0
- package/src/server/hydrateServerUnistyles.ts +17 -0
- package/src/server/index.ts +5 -0
- package/src/server/resetServerUnistyles.ts +9 -0
- package/src/server/types.ts +4 -0
- package/src/server/useServerUnistyles.tsx +22 -0
- package/src/specs/ShadowRegistry/index.ts +12 -9
- package/src/specs/StyleSheet/index.ts +6 -1
- package/src/utils.ts +32 -11
- package/src/web/convert/object/filter.ts +2 -2
- package/src/web/convert/style.ts +8 -7
- package/src/web/create.ts +23 -18
- package/src/web/css/core.ts +58 -0
- package/src/web/css/index.ts +1 -0
- package/src/web/css/state.ts +191 -0
- package/src/web/css/utils.ts +54 -0
- package/src/web/index.ts +18 -5
- package/src/web/listener.ts +8 -8
- package/src/web/registry.ts +47 -152
- package/src/web/runtime.ts +32 -22
- package/src/web/services.ts +28 -0
- package/src/web/shadowRegistry.ts +46 -104
- package/src/web/state.ts +46 -11
- package/src/web/types.ts +13 -0
- package/src/web/utils/common.ts +32 -8
- package/src/web/utils/unistyle.ts +46 -25
- package/src/web/variants.ts +27 -27
- package/cxx/core/HostStyle.cpp +0 -73
- package/cxx/core/HostStyle.h +0 -34
- package/lib/commonjs/components/Variants.js +0 -36
- package/lib/commonjs/components/Variants.js.map +0 -1
- package/lib/commonjs/core/createUnistylesComponent.js +0 -16
- package/lib/commonjs/core/createUnistylesComponent.js.map +0 -1
- package/lib/commonjs/core/withUnistyles/useDependencies.js.map +0 -1
- package/lib/module/components/Variants.js +0 -29
- package/lib/module/components/Variants.js.map +0 -1
- package/lib/module/core/createUnistylesComponent.js +0 -11
- package/lib/module/core/createUnistylesComponent.js.map +0 -1
- package/lib/module/core/withUnistyles/useDependencies.js.map +0 -1
- package/lib/typescript/src/components/Variants.d.ts +0 -7
- package/lib/typescript/src/components/Variants.d.ts.map +0 -1
- package/lib/typescript/src/core/createUnistylesComponent.d.ts +0 -14
- package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +0 -1
- package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts +0 -13
- package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts.map +0 -1
- package/nitrogen/generated/android/unistylesOnLoad.kt +0 -1
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +0 -314
- package/plugin/style.js +0 -168
- package/src/components/Variants.tsx +0 -30
- package/src/core/createUnistylesComponent.tsx +0 -14
package/src/web/registry.ts
CHANGED
@@ -1,42 +1,19 @@
|
|
1
1
|
import type { UnistylesTheme, UnistylesValues } from '../types'
|
2
2
|
import type { StyleSheet, StyleSheetWithSuperPowers } from '../types/stylesheet'
|
3
|
-
import {
|
4
|
-
import { extractMediaQueryValue, keyInObject, getMediaQuery, generateHash, extractUnistyleDependencies, error } from './utils'
|
5
|
-
import { UnistylesListener } from './listener'
|
6
|
-
import { convertUnistyles } from './convert'
|
3
|
+
import { generateHash, extractUnistyleDependencies, error } from './utils'
|
7
4
|
import type { UnistylesMiniRuntime, UnistyleDependency } from '../specs'
|
5
|
+
import { CSSState } from './css'
|
6
|
+
import type { UnistylesServices } from './types'
|
8
7
|
|
9
|
-
|
10
|
-
hash: string,
|
11
|
-
key: string,
|
12
|
-
value: any,
|
13
|
-
sheet: CSSStyleSheet | CSSMediaRule
|
14
|
-
}
|
15
|
-
|
16
|
-
type RemoveReadonlyStyleKeys<T extends string> = T extends 'length' | 'parentRule' ? never : T
|
17
|
-
|
18
|
-
class UnistylesRegistryBuilder {
|
8
|
+
export class UnistylesRegistry {
|
19
9
|
private readonly stylesheets = new Map<StyleSheetWithSuperPowers<StyleSheet>, StyleSheet>()
|
20
|
-
private readonly
|
21
|
-
|
10
|
+
private readonly stylesCache = new Set<string>()
|
11
|
+
private readonly stylesCounter = new Map<string, Set<HTMLElement>>()
|
22
12
|
private readonly disposeListenersMap = new Map<object, VoidFunction>()
|
23
13
|
private readonly dependenciesMap = new Map<StyleSheetWithSuperPowers<StyleSheet>, Set<UnistyleDependency>>()
|
14
|
+
readonly css = new CSSState()
|
24
15
|
|
25
|
-
private
|
26
|
-
const tag = this.#styleTag
|
27
|
-
|
28
|
-
if (!tag) {
|
29
|
-
const newTag = document.createElement('style')
|
30
|
-
|
31
|
-
newTag.id = 'unistyles-web'
|
32
|
-
this.#styleTag = newTag
|
33
|
-
document.head.appendChild(newTag)
|
34
|
-
|
35
|
-
return newTag
|
36
|
-
}
|
37
|
-
|
38
|
-
return tag
|
39
|
-
}
|
16
|
+
constructor(private services: UnistylesServices) {}
|
40
17
|
|
41
18
|
getComputedStylesheet = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, scopedThemeName?: UnistylesTheme) => {
|
42
19
|
if (typeof stylesheet !== 'function') {
|
@@ -44,13 +21,13 @@ class UnistylesRegistryBuilder {
|
|
44
21
|
}
|
45
22
|
|
46
23
|
if (scopedThemeName) {
|
47
|
-
const scopedTheme =
|
24
|
+
const scopedTheme = this.services.runtime.getTheme(scopedThemeName, this.services.state.CSSVars)
|
48
25
|
|
49
26
|
if (!scopedTheme) {
|
50
27
|
throw error(`Unistyles: You're trying to use scoped theme '${scopedThemeName}' but it wasn't registered.`)
|
51
28
|
}
|
52
29
|
|
53
|
-
return stylesheet(scopedTheme,
|
30
|
+
return stylesheet(scopedTheme, this.services.runtime.miniRuntime)
|
54
31
|
}
|
55
32
|
|
56
33
|
const computedStylesheet = this.stylesheets.get(stylesheet)
|
@@ -59,7 +36,8 @@ class UnistylesRegistryBuilder {
|
|
59
36
|
return computedStylesheet
|
60
37
|
}
|
61
38
|
|
62
|
-
const
|
39
|
+
const currentTheme = this.services.runtime.getTheme(this.services.runtime.themeName, this.services.state.CSSVars)
|
40
|
+
const createdStylesheet = stylesheet(currentTheme, this.services.runtime.miniRuntime)
|
63
41
|
const dependencies = Object.values(createdStylesheet).flatMap(value => extractUnistyleDependencies(value))
|
64
42
|
|
65
43
|
this.addDependenciesToStylesheet(stylesheet, dependencies)
|
@@ -75,8 +53,8 @@ class UnistylesRegistryBuilder {
|
|
75
53
|
|
76
54
|
dependencies.forEach(dependency => dependenciesMap.add(dependency))
|
77
55
|
|
78
|
-
const dispose =
|
79
|
-
const newComputedStylesheet = stylesheet(
|
56
|
+
const dispose = this.services.listener.addStylesheetListeners(Array.from(dependenciesMap), () => {
|
57
|
+
const newComputedStylesheet = stylesheet(this.services.runtime.theme, this.services.runtime.miniRuntime)
|
80
58
|
|
81
59
|
this.stylesheets.set(stylesheet, newComputedStylesheet)
|
82
60
|
})
|
@@ -85,140 +63,57 @@ class UnistylesRegistryBuilder {
|
|
85
63
|
this.disposeListenersMap.set(stylesheet, dispose)
|
86
64
|
}
|
87
65
|
|
88
|
-
|
89
|
-
const
|
90
|
-
const existingCounter = this.stylesCounter.get(hash)
|
91
|
-
|
92
|
-
if (!existingCounter || existingCounter.size === 0) {
|
93
|
-
const counter = new Set<UnistylesValues>()
|
94
|
-
|
95
|
-
counter.add(value)
|
96
|
-
this.stylesCounter.set(hash, counter)
|
97
|
-
this.applyStyles(hash, value)
|
98
|
-
|
99
|
-
return { hash, existingHash: false }
|
100
|
-
}
|
66
|
+
connect = (ref: HTMLElement, hash: string) => {
|
67
|
+
const stylesCounter = this.stylesCounter.get(hash) ?? new Set()
|
101
68
|
|
102
|
-
|
103
|
-
|
104
|
-
return { hash, existingHash: true }
|
69
|
+
stylesCounter.add(ref)
|
70
|
+
this.stylesCounter.set(hash, stylesCounter)
|
105
71
|
}
|
106
72
|
|
107
|
-
|
108
|
-
|
109
|
-
if (!this.styleTag.sheet) {
|
110
|
-
return
|
111
|
-
}
|
73
|
+
remove = (ref: HTMLElement, hash: string) => {
|
74
|
+
const stylesCounter = this.stylesCounter.get(hash) ?? new Set()
|
112
75
|
|
113
|
-
|
114
|
-
const mediaQuery = getMediaQuery(key)
|
115
|
-
const cssRules = Array.from(this.styleTag.sheet.cssRules)
|
116
|
-
let queryRule = cssRules.find(rule => {
|
117
|
-
if (!(rule instanceof CSSMediaRule)) {
|
118
|
-
return false
|
119
|
-
}
|
120
|
-
|
121
|
-
return rule.media.item(0)?.includes(mediaQuery)
|
122
|
-
}) ?? null
|
123
|
-
|
124
|
-
if (!queryRule) {
|
125
|
-
const mediaQueryValue = extractMediaQueryValue(mediaQuery)
|
126
|
-
const ruleIndex = mediaQueryValue
|
127
|
-
? cssRules.reduce<number | undefined>((acc, rule, ruleIndex) => {
|
128
|
-
if (!(rule instanceof CSSMediaRule)) {
|
129
|
-
return acc
|
130
|
-
}
|
131
|
-
|
132
|
-
const ruleMediaQueryValue = extractMediaQueryValue(rule.conditionText)
|
133
|
-
|
134
|
-
if (ruleMediaQueryValue === undefined) {
|
135
|
-
return
|
136
|
-
}
|
137
|
-
|
138
|
-
return ruleMediaQueryValue > mediaQueryValue ? ruleIndex : acc
|
139
|
-
}, cssRules.length)
|
140
|
-
: undefined
|
141
|
-
queryRule = this.styleTag.sheet.cssRules.item(this.styleTag.sheet.insertRule(`@media ${mediaQuery} {.${hash} {}}`, ruleIndex))
|
142
|
-
}
|
76
|
+
stylesCounter.delete(ref)
|
143
77
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
value: mqValue,
|
150
|
-
sheet: queryRule
|
151
|
-
})
|
152
|
-
})
|
78
|
+
if (stylesCounter.size === 0) {
|
79
|
+
// Move this to the end of the event loop so the element is removed from the DOM
|
80
|
+
Promise.resolve().then(() => {
|
81
|
+
if (document.querySelector(`.${hash}`)) {
|
82
|
+
return
|
153
83
|
}
|
154
84
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
// Pseudo
|
159
|
-
if (typeof value === 'object') {
|
160
|
-
Object.entries(value).forEach(([pseudoKey, pseudoValue]) => {
|
161
|
-
this.applyRule({
|
162
|
-
hash: `${hash}${key.replace('_', ':')}`,
|
163
|
-
key: pseudoKey,
|
164
|
-
value: pseudoValue,
|
165
|
-
sheet: this.styleTag.sheet as CSSStyleSheet
|
166
|
-
})
|
167
|
-
})
|
168
|
-
|
169
|
-
return
|
170
|
-
}
|
171
|
-
|
172
|
-
this.applyRule({
|
173
|
-
hash,
|
174
|
-
key,
|
175
|
-
value,
|
176
|
-
sheet: this.styleTag.sheet
|
85
|
+
this.css.remove(hash)
|
86
|
+
this.stylesCache.delete(hash)
|
177
87
|
})
|
178
|
-
})
|
179
|
-
}
|
180
88
|
|
181
|
-
|
182
|
-
let rule = Array.from(sheet.cssRules).find(rule => {
|
183
|
-
if (!(rule instanceof CSSStyleRule)) {
|
184
|
-
return false
|
185
|
-
}
|
186
|
-
|
187
|
-
// In unistyles pseudos are prefixed with ':' but in css some of them are prefixed with '::'
|
188
|
-
return rule.selectorText.replace('::', ':').includes(hash)
|
189
|
-
}) ?? null
|
190
|
-
|
191
|
-
if (!rule) {
|
192
|
-
rule = sheet.cssRules.item(sheet.insertRule(`.${hash} {}`))
|
89
|
+
return true
|
193
90
|
}
|
194
91
|
|
195
|
-
|
196
|
-
return
|
197
|
-
}
|
198
|
-
|
199
|
-
rule.style[key as RemoveReadonlyStyleKeys<typeof key>] = value
|
92
|
+
return false
|
200
93
|
}
|
201
94
|
|
202
|
-
|
95
|
+
add = (value: UnistylesValues) => {
|
203
96
|
const hash = generateHash(value)
|
204
|
-
const existingStyles = this.stylesCounter.get(hash)
|
205
97
|
|
206
|
-
if (!
|
207
|
-
|
208
|
-
|
98
|
+
if (!this.stylesCache.has(hash)) {
|
99
|
+
this.applyStyles(hash, value)
|
100
|
+
this.stylesCache.add(hash)
|
209
101
|
|
210
|
-
|
102
|
+
return { hash, existingHash: false }
|
103
|
+
}
|
211
104
|
|
212
|
-
|
213
|
-
|
105
|
+
return { hash, existingHash: true }
|
106
|
+
}
|
214
107
|
|
215
|
-
|
216
|
-
|
217
|
-
|
108
|
+
applyStyles = (hash: string, value: UnistylesValues) => {
|
109
|
+
this.css.add(hash, value)
|
110
|
+
}
|
218
111
|
|
219
|
-
|
220
|
-
|
112
|
+
reset = () => {
|
113
|
+
this.css.reset()
|
114
|
+
this.stylesCache.clear()
|
115
|
+
this.dependenciesMap.clear()
|
116
|
+
this.disposeListenersMap.clear()
|
117
|
+
this.stylesCounter.clear()
|
221
118
|
}
|
222
119
|
}
|
223
|
-
|
224
|
-
export const UnistylesRegistry = new UnistylesRegistryBuilder()
|
package/src/web/runtime.ts
CHANGED
@@ -2,16 +2,16 @@ import { UnistyleDependency } from '../specs/NativePlatform'
|
|
2
2
|
import { ColorScheme, Orientation, type AppTheme, type AppThemeName } from '../specs/types'
|
3
3
|
import type { UnistylesMiniRuntime } from '../specs/UnistylesRuntime'
|
4
4
|
import { WebContentSizeCategory } from '../types'
|
5
|
-
import { UnistylesListener } from './listener'
|
6
5
|
import { NavigationBar, StatusBar } from './mock'
|
7
6
|
import { error, isServer, schemeToTheme } from './utils'
|
7
|
+
import type { UnistylesServices } from './types'
|
8
8
|
|
9
|
-
|
10
|
-
import { UnistylesState } from './state'
|
11
|
-
|
12
|
-
class UnistylesRuntimeBuilder {
|
9
|
+
export class UnistylesRuntime {
|
13
10
|
lightMedia = this.getLightMedia()
|
14
11
|
darkMedia = this.getDarkMedia()
|
12
|
+
rootElement = isServer() ? null : document.querySelector(':root')
|
13
|
+
|
14
|
+
constructor(private services: UnistylesServices) {}
|
15
15
|
|
16
16
|
private getLightMedia(): MediaQueryList | null {
|
17
17
|
if (isServer()) {
|
@@ -49,11 +49,11 @@ class UnistylesRuntimeBuilder {
|
|
49
49
|
}
|
50
50
|
|
51
51
|
get themeName() {
|
52
|
-
if (
|
52
|
+
if (this.services.state.hasAdaptiveThemes) {
|
53
53
|
return schemeToTheme(this.colorScheme) as AppThemeName
|
54
54
|
}
|
55
55
|
|
56
|
-
return
|
56
|
+
return this.services.state.themeName
|
57
57
|
}
|
58
58
|
|
59
59
|
get contentSizeCategory() {
|
@@ -61,11 +61,11 @@ class UnistylesRuntimeBuilder {
|
|
61
61
|
}
|
62
62
|
|
63
63
|
get breakpoints() {
|
64
|
-
return
|
64
|
+
return this.services.state.breakpoints ?? {}
|
65
65
|
}
|
66
66
|
|
67
67
|
get breakpoint() {
|
68
|
-
return
|
68
|
+
return this.services.state.breakpoint
|
69
69
|
}
|
70
70
|
|
71
71
|
get orientation() {
|
@@ -121,7 +121,7 @@ class UnistylesRuntimeBuilder {
|
|
121
121
|
}
|
122
122
|
|
123
123
|
get hasAdaptiveThemes() {
|
124
|
-
return
|
124
|
+
return this.services.state.hasAdaptiveThemes
|
125
125
|
}
|
126
126
|
|
127
127
|
get navigationBar() {
|
@@ -158,23 +158,33 @@ class UnistylesRuntimeBuilder {
|
|
158
158
|
throw error(`You're trying to set theme to: '${themeName}', but adaptiveThemes are enabled.`)
|
159
159
|
}
|
160
160
|
|
161
|
-
if (themeName ===
|
161
|
+
if (themeName === this.themeName) {
|
162
162
|
return
|
163
163
|
}
|
164
164
|
|
165
|
-
|
166
|
-
|
167
|
-
|
165
|
+
const oldTheme = this.services.state.themeName
|
166
|
+
|
167
|
+
this.services.state.themeName = themeName
|
168
|
+
this.services.listener.emitChange(UnistyleDependency.Theme)
|
169
|
+
this.services.listener.emitChange(UnistyleDependency.ThemeName)
|
170
|
+
|
171
|
+
if (!isServer() && !this.services.state.hasAdaptiveThemes && this.services.state.CSSVars) {
|
172
|
+
this.rootElement?.classList.remove(oldTheme ?? '')
|
173
|
+
this.rootElement?.classList.add(themeName ?? '')
|
174
|
+
}
|
168
175
|
}
|
169
176
|
|
170
177
|
setAdaptiveThemes = (isEnabled: boolean) => {
|
171
|
-
|
178
|
+
this.services.state.hasAdaptiveThemes = isEnabled
|
172
179
|
|
173
180
|
if (!isEnabled) {
|
181
|
+
this.rootElement?.classList.add(this.themeName ?? '')
|
182
|
+
|
174
183
|
return
|
175
184
|
}
|
176
185
|
|
177
|
-
this.
|
186
|
+
this.rootElement?.classList.remove(this.themeName ?? '')
|
187
|
+
this.setTheme(schemeToTheme(this.colorScheme) as AppThemeName)
|
178
188
|
}
|
179
189
|
|
180
190
|
setRootViewBackgroundColor = (color: string) => {
|
@@ -188,17 +198,19 @@ class UnistylesRuntimeBuilder {
|
|
188
198
|
setImmersiveMode = () => {}
|
189
199
|
|
190
200
|
updateTheme = (themeName: AppThemeName, updater: (currentTheme: AppTheme) => AppTheme) => {
|
191
|
-
const oldTheme =
|
201
|
+
const oldTheme = this.services.state.themes.get(themeName)
|
192
202
|
|
193
203
|
if (!oldTheme) {
|
194
204
|
throw error(`Unistyles: You're trying to update theme "${themeName}" but it wasn't registered.`)
|
195
205
|
}
|
196
206
|
|
197
|
-
|
207
|
+
this.services.state.themes.set(themeName, updater(oldTheme))
|
198
208
|
}
|
199
209
|
|
200
|
-
getTheme = (themeName = this.themeName) => {
|
201
|
-
const theme =
|
210
|
+
getTheme = (themeName = this.themeName, CSSVars = false) => {
|
211
|
+
const theme = CSSVars
|
212
|
+
? this.services.state.cssThemes.get(themeName ?? '')
|
213
|
+
: this.services.state.themes.get(themeName ?? '')
|
202
214
|
|
203
215
|
if (!themeName || !theme) {
|
204
216
|
throw error(`You're trying to get theme "${themeName}" but it wasn't registered.`)
|
@@ -207,5 +219,3 @@ class UnistylesRuntimeBuilder {
|
|
207
219
|
return theme
|
208
220
|
}
|
209
221
|
}
|
210
|
-
|
211
|
-
export const UnistylesRuntime = new UnistylesRuntimeBuilder()
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { UnistylesListener } from './listener'
|
2
|
+
import { UnistylesRegistry } from './registry'
|
3
|
+
import { UnistylesRuntime } from './runtime'
|
4
|
+
import { UnistylesShadowRegistry } from './shadowRegistry'
|
5
|
+
import { UnistylesState } from './state'
|
6
|
+
|
7
|
+
export class UnistylesServices {
|
8
|
+
runtime: UnistylesRuntime
|
9
|
+
registry: UnistylesRegistry
|
10
|
+
shadowRegistry: UnistylesShadowRegistry
|
11
|
+
state: UnistylesState
|
12
|
+
listener: UnistylesListener
|
13
|
+
|
14
|
+
private services = {} as UnistylesServices
|
15
|
+
|
16
|
+
constructor() {
|
17
|
+
this.runtime = new UnistylesRuntime(this.services)
|
18
|
+
this.registry = new UnistylesRegistry(this.services)
|
19
|
+
this.shadowRegistry = new UnistylesShadowRegistry(this.services)
|
20
|
+
this.state = new UnistylesState(this.services)
|
21
|
+
this.listener = new UnistylesListener(this.services)
|
22
|
+
this.services.runtime = this.runtime
|
23
|
+
this.services.registry = this.registry
|
24
|
+
this.services.shadowRegistry = this.shadowRegistry
|
25
|
+
this.services.state = this.state
|
26
|
+
this.services.listener = this.listener
|
27
|
+
}
|
28
|
+
}
|
@@ -1,13 +1,11 @@
|
|
1
1
|
import type { UnistylesTheme, UnistylesValues } from '../types'
|
2
|
-
import { UnistylesListener } from './listener'
|
3
|
-
import { UnistylesRegistry } from './registry'
|
4
2
|
import { deepMergeObjects } from '../utils'
|
5
|
-
import {
|
3
|
+
import { extractSecrets, extractUnistyleDependencies } from './utils'
|
6
4
|
import { getVariants } from './variants'
|
5
|
+
import type { UnistylesServices } from './types'
|
6
|
+
import { UnistyleDependency } from '../specs'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
class UnistylesShadowRegistryBuilder {
|
8
|
+
export class UnistylesShadowRegistry {
|
11
9
|
// MOCKS
|
12
10
|
name = 'UnistylesShadowRegistry'
|
13
11
|
__type = 'web'
|
@@ -16,131 +14,68 @@ class UnistylesShadowRegistryBuilder {
|
|
16
14
|
dispose = () => {}
|
17
15
|
// END MOCKS
|
18
16
|
|
19
|
-
private resultsMap = new Map<HTMLElement, UnistylesValues>()
|
20
|
-
private classNamesMap = new Map<HTMLElement, Array<string>>()
|
21
|
-
private selectedVariants = new Map<string, string | boolean | undefined>()
|
22
17
|
private scopedTheme: UnistylesTheme | undefined = undefined
|
23
|
-
private disposeMap = new Map<
|
24
|
-
|
25
|
-
add = (ref: any, styles: Array<Style>) => {
|
26
|
-
// Styles are not provided
|
27
|
-
if (!styles || !Array.isArray(styles)) {
|
28
|
-
return
|
29
|
-
}
|
18
|
+
private disposeMap = new Map<string, VoidFunction>()
|
30
19
|
|
31
|
-
|
32
|
-
if (ref === null) {
|
33
|
-
styles.flat().forEach(style => {
|
34
|
-
extractSecrets(style)?.__uni__refs.forEach(ref => {
|
35
|
-
if (isInDocument(ref)) {
|
36
|
-
return
|
37
|
-
}
|
38
|
-
|
39
|
-
const oldResult = this.resultsMap.get(ref)
|
40
|
-
|
41
|
-
this.resultsMap.delete(ref)
|
42
|
-
this.classNamesMap.delete(ref)
|
43
|
-
this.disposeMap.get(ref)?.()
|
44
|
-
this.disposeMap.delete(ref)
|
45
|
-
|
46
|
-
if (oldResult) {
|
47
|
-
UnistylesRegistry.remove(oldResult)
|
48
|
-
}
|
49
|
-
})
|
50
|
-
})
|
20
|
+
constructor(private services: UnistylesServices) {}
|
51
21
|
|
22
|
+
add = (ref: any, hash?: string) => {
|
23
|
+
if (!(ref instanceof HTMLElement) || !hash) {
|
52
24
|
return
|
53
25
|
}
|
54
26
|
|
55
|
-
|
56
|
-
|
57
|
-
return
|
58
|
-
}
|
27
|
+
this.services.registry.connect(ref, hash)
|
28
|
+
}
|
59
29
|
|
30
|
+
addStyles = (unistyles: Array<UnistylesValues>) => {
|
60
31
|
const getParsedStyles = () => {
|
61
|
-
|
62
|
-
|
63
|
-
return []
|
64
|
-
}
|
65
|
-
|
66
|
-
const secrets = extractSecrets(unistyleStyle)
|
32
|
+
const allStyles = unistyles.map(unistyle => {
|
33
|
+
const secrets = extractSecrets(unistyle)
|
67
34
|
|
68
35
|
// Regular style
|
69
36
|
if (!secrets) {
|
70
|
-
return
|
37
|
+
return unistyle
|
71
38
|
}
|
72
39
|
|
73
|
-
const { __uni__key, __uni__stylesheet, __uni__args = [],
|
74
|
-
const newComputedStylesheet =
|
40
|
+
const { __uni__key, __uni__stylesheet, __uni__args = [], __uni_variants: variants } = secrets
|
41
|
+
const newComputedStylesheet = this.services.registry.getComputedStylesheet(__uni__stylesheet, scopedTheme)
|
75
42
|
const style = newComputedStylesheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
|
76
|
-
const args = __uni__args
|
77
43
|
const result = typeof style === 'function'
|
78
|
-
? style(...
|
44
|
+
? style(...__uni__args)
|
79
45
|
: style
|
80
|
-
const
|
81
|
-
const resultWithVariants = deepMergeObjects(result, variantsResult
|
46
|
+
const variantsResult = getVariants(result, variants)
|
47
|
+
const resultWithVariants = deepMergeObjects(result, variantsResult)
|
82
48
|
const dependencies = extractUnistyleDependencies(resultWithVariants)
|
83
49
|
|
84
50
|
if (typeof __uni__stylesheet === 'function') {
|
85
51
|
// Add dependencies from dynamic styles to stylesheet
|
86
|
-
|
52
|
+
this.services.registry.addDependenciesToStylesheet(__uni__stylesheet, dependencies)
|
87
53
|
}
|
88
54
|
|
89
|
-
__uni__refs.add(ref)
|
90
|
-
|
91
55
|
return resultWithVariants as UnistylesValues
|
92
56
|
})
|
57
|
+
|
58
|
+
return deepMergeObjects(...allStyles)
|
93
59
|
}
|
94
60
|
|
95
61
|
// Copy scoped theme to not use referenced value
|
96
|
-
const variants = this.getVariants()
|
97
62
|
const scopedTheme = this.scopedTheme
|
98
63
|
const parsedStyles = getParsedStyles()
|
99
|
-
const
|
100
|
-
const
|
101
|
-
|
102
|
-
|
103
|
-
|
64
|
+
const { hash, existingHash } = this.services.registry.add(parsedStyles)
|
65
|
+
const injectedClassNames = parsedStyles?._web?._classNames ?? []
|
66
|
+
const injectedClassName = Array.isArray(injectedClassNames) ? injectedClassNames.join(' ') : injectedClassNames
|
67
|
+
const dependencies = extractUnistyleDependencies(parsedStyles)
|
68
|
+
const filteredDependencies = this.services.state.CSSVars
|
69
|
+
? dependencies.filter(dependency => dependency !== UnistyleDependency.Theme)
|
70
|
+
: dependencies
|
71
|
+
|
72
|
+
if (!existingHash) {
|
73
|
+
this.disposeMap.set(hash, this.services.listener.addListeners(filteredDependencies, () => {
|
74
|
+
this.services.registry.applyStyles(hash, getParsedStyles())
|
75
|
+
}))
|
104
76
|
}
|
105
77
|
|
106
|
-
|
107
|
-
|
108
|
-
// Remove old styles
|
109
|
-
if (oldStyles) {
|
110
|
-
UnistylesRegistry.remove(oldStyles)
|
111
|
-
}
|
112
|
-
|
113
|
-
// Remove old classnames from the ref
|
114
|
-
oldClassNames?.forEach(className => ref.classList.remove(className))
|
115
|
-
this.resultsMap.set(ref, combinedStyles)
|
116
|
-
|
117
|
-
const { hash } = UnistylesRegistry.add(combinedStyles)
|
118
|
-
const injectedClassNames = combinedStyles?._web?._classNames ?? []
|
119
|
-
const newClassNames = (Array.isArray(injectedClassNames) ? injectedClassNames : [injectedClassNames]).concat(hash)
|
120
|
-
const dependencies = Array.from(new Set(parsedStyles.flatMap(style => extractUnistyleDependencies(style))))
|
121
|
-
|
122
|
-
this.disposeMap.get(ref)?.()
|
123
|
-
this.disposeMap.set(ref, UnistylesListener.addListeners(dependencies, () => {
|
124
|
-
UnistylesRegistry.applyStyles(hash, deepMergeObjects(...getParsedStyles()))
|
125
|
-
}))
|
126
|
-
this.classNamesMap.set(ref, newClassNames)
|
127
|
-
// Add new classnames to the ref
|
128
|
-
ref.classList.add(...newClassNames)
|
129
|
-
ref.removeAttribute('styles')
|
130
|
-
|
131
|
-
return newClassNames
|
132
|
-
}
|
133
|
-
|
134
|
-
selectVariants = (variants?: Record<string, string | boolean | undefined>) => {
|
135
|
-
if (!variants) {
|
136
|
-
this.selectedVariants.clear()
|
137
|
-
|
138
|
-
return
|
139
|
-
}
|
140
|
-
|
141
|
-
Object.entries(variants).forEach(([key, value]) => {
|
142
|
-
this.selectedVariants.set(key, value)
|
143
|
-
})
|
78
|
+
return { injectedClassName, hash }
|
144
79
|
}
|
145
80
|
|
146
81
|
setScopedTheme = (theme?: UnistylesTheme) => {
|
@@ -149,9 +84,16 @@ class UnistylesShadowRegistryBuilder {
|
|
149
84
|
|
150
85
|
getScopedTheme = () => this.scopedTheme
|
151
86
|
|
152
|
-
|
87
|
+
remove = (ref: any, hash?: string) => {
|
88
|
+
if (!(ref instanceof HTMLElement) || !hash) {
|
89
|
+
return
|
90
|
+
}
|
153
91
|
|
154
|
-
|
155
|
-
}
|
92
|
+
const removed = this.services.registry.remove(ref, hash)
|
156
93
|
|
157
|
-
|
94
|
+
if (removed) {
|
95
|
+
this.disposeMap.get(hash)?.()
|
96
|
+
this.disposeMap.delete(hash)
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|