react-native-unistyles 3.0.0-beta.7 → 3.0.0-experimental-2025051401
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 +41 -19
- package/Unistyles.podspec +1 -0
- package/android/CMakeLists.txt +2 -1
- package/android/src/main/cxx/NativeUnistylesModule.cpp +3 -7
- package/android/src/main/cxx/NativeUnistylesModule.h +0 -4
- package/android/src/main/java/com/unistyles/NativePlatform+android.kt +5 -1
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +11 -4
- package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +1 -1
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +1 -7
- package/components/native/ActivityIndicator/package.json +1 -0
- package/components/native/Animated/package.json +1 -0
- package/components/native/FlatList/package.json +1 -0
- package/components/native/Image/package.json +2 -1
- package/components/native/ImageBackground/package.json +1 -0
- package/components/native/KeyboardAvoidingView/package.json +1 -0
- package/components/native/NativeText/package.json +1 -0
- package/components/native/NativeView/package.json +1 -0
- package/components/native/Pressable/package.json +1 -0
- package/components/native/RefreshControl/package.json +1 -0
- package/components/native/ScrollView/package.json +1 -0
- package/components/native/SectionList/package.json +1 -0
- package/components/native/Switch/package.json +1 -0
- package/components/native/Text/package.json +1 -0
- package/components/native/TextInput/package.json +1 -0
- package/components/native/TouchableHighlight/package.json +1 -0
- package/components/native/TouchableOpacity/package.json +1 -0
- package/components/native/View/package.json +1 -0
- package/components/native/VirtualizedList/package.json +1 -0
- package/cxx/common/Helpers.h +89 -0
- package/cxx/core/HostUnistyle.cpp +14 -5
- package/cxx/core/StyleSheet.h +1 -1
- package/cxx/core/UnistyleWrapper.h +1 -1
- package/cxx/core/UnistylesCommitShadowNode.h +0 -21
- package/cxx/core/UnistylesRegistry.cpp +74 -69
- package/cxx/core/UnistylesRegistry.h +1 -1
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +2 -5
- package/cxx/hybridObjects/HybridStyleSheet.cpp +10 -19
- package/cxx/hybridObjects/HybridStyleSheet.h +3 -8
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +5 -1
- package/cxx/parser/Parser.cpp +200 -89
- package/cxx/parser/Parser.h +1 -1
- package/cxx/shadowTree/ShadowTrafficController.h +13 -9
- package/cxx/shadowTree/ShadowTreeManager.cpp +64 -59
- package/cxx/shadowTree/ShadowTreeManager.h +0 -1
- package/ios/NativePlatform+ios.swift +1 -1
- package/ios/NativePlatformListener+ios.swift +12 -7
- package/ios/UnistylesModuleOnLoad.h +1 -5
- package/ios/UnistylesModuleOnLoad.mm +5 -13
- package/lib/commonjs/components/native/Image.js +27 -1
- package/lib/commonjs/components/native/Image.js.map +1 -1
- package/lib/commonjs/components/native/Image.native.js +10 -0
- package/lib/commonjs/components/native/Image.native.js.map +1 -0
- package/lib/commonjs/components/native/ImageBackground.js +21 -36
- package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
- package/lib/commonjs/components/native/Pressable.native.js +16 -2
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.js +17 -21
- package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.native.js +7 -1
- package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesImageBackground.js +10 -4
- package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/commonjs/core/getClassname.js +11 -5
- package/lib/commonjs/core/getClassname.js.map +1 -1
- package/lib/commonjs/core/passForwardRef.js +3 -5
- package/lib/commonjs/core/passForwardRef.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js +5 -3
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +15 -2
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.js +14 -5
- package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +14 -7
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/commonjs/hooks/useMedia.js +4 -4
- package/lib/commonjs/hooks/useMedia.js.map +1 -1
- package/lib/commonjs/hooks/useMedia.native.js +4 -4
- package/lib/commonjs/hooks/useMedia.native.js.map +1 -1
- package/lib/commonjs/mocks.js +203 -0
- package/lib/commonjs/mocks.js.map +1 -0
- package/lib/commonjs/mq.js +1 -23
- package/lib/commonjs/mq.js.map +1 -1
- package/lib/commonjs/reanimated/index.js +13 -0
- package/lib/commonjs/reanimated/index.js.map +1 -0
- package/lib/commonjs/reanimated/useAnimatedTheme.js +22 -0
- package/lib/commonjs/reanimated/useAnimatedTheme.js.map +1 -0
- package/lib/commonjs/reanimated/useAnimatedTheme.native.js +24 -0
- package/lib/commonjs/reanimated/useAnimatedTheme.native.js.map +1 -0
- package/lib/commonjs/server/getServerUnistyles.js +9 -4
- package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/hydrateServerUnistyles.js +4 -2
- package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/resetServerUnistyles.js +4 -2
- package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/serialize.js +24 -0
- package/lib/commonjs/server/serialize.js.map +1 -0
- package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +1 -0
- package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/utils.js +23 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/convert/index.js +4 -7
- package/lib/commonjs/web/convert/index.js.map +1 -1
- package/lib/commonjs/web/convert/object/filter.js +7 -8
- package/lib/commonjs/web/convert/object/filter.js.map +1 -1
- package/lib/commonjs/web/create.js +10 -2
- package/lib/commonjs/web/create.js.map +1 -1
- package/lib/commonjs/web/css/core.js +2 -2
- package/lib/commonjs/web/css/core.js.map +1 -1
- package/lib/commonjs/web/css/state.js +6 -3
- package/lib/commonjs/web/css/state.js.map +1 -1
- package/lib/commonjs/web/index.js +7 -12
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/commonjs/web/registry.js +11 -9
- package/lib/commonjs/web/registry.js.map +1 -1
- package/lib/commonjs/web/runtime.js +5 -1
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/commonjs/web/services.js +7 -2
- package/lib/commonjs/web/services.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +27 -10
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/state.js +11 -2
- package/lib/commonjs/web/state.js.map +1 -1
- package/lib/commonjs/web/types.js +2 -0
- package/lib/commonjs/web/types.js.map +1 -1
- package/lib/commonjs/web/utils/createUnistylesRef.js +31 -0
- package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -0
- package/lib/commonjs/web/utils/unistyle.js +40 -14
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/commonjs/web-only/getWebProps.js +19 -0
- package/lib/commonjs/web-only/getWebProps.js.map +1 -0
- package/lib/commonjs/web-only/index.js +13 -0
- package/lib/commonjs/web-only/index.js.map +1 -0
- package/lib/module/components/native/Image.js +26 -2
- package/lib/module/components/native/Image.js.map +1 -1
- package/lib/module/components/native/Image.native.js +6 -0
- package/lib/module/components/native/Image.native.js.map +1 -0
- package/lib/module/components/native/ImageBackground.js +22 -37
- package/lib/module/components/native/ImageBackground.js.map +1 -1
- package/lib/module/components/native/Pressable.native.js +16 -2
- package/lib/module/components/native/Pressable.native.js.map +1 -1
- package/lib/module/core/createUnistylesElement.js +17 -21
- package/lib/module/core/createUnistylesElement.js.map +1 -1
- package/lib/module/core/createUnistylesElement.native.js +7 -1
- package/lib/module/core/createUnistylesElement.native.js.map +1 -1
- package/lib/module/core/createUnistylesImageBackground.js +10 -4
- package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/module/core/getClassname.js +9 -5
- package/lib/module/core/getClassname.js.map +1 -1
- package/lib/module/core/passForwardRef.js +3 -5
- package/lib/module/core/passForwardRef.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/listener.js +3 -3
- package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +15 -2
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.js +14 -5
- package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js +14 -7
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/module/hooks/useMedia.js +1 -1
- package/lib/module/hooks/useMedia.js.map +1 -1
- package/lib/module/hooks/useMedia.native.js +1 -1
- package/lib/module/hooks/useMedia.native.js.map +1 -1
- package/lib/module/mocks.js +201 -0
- package/lib/module/mocks.js.map +1 -0
- package/lib/module/mq.js +0 -19
- package/lib/module/mq.js.map +1 -1
- package/lib/module/reanimated/index.js +4 -0
- package/lib/module/reanimated/index.js.map +1 -0
- package/lib/module/reanimated/useAnimatedTheme.js +17 -0
- package/lib/module/reanimated/useAnimatedTheme.js.map +1 -0
- package/lib/module/reanimated/useAnimatedTheme.native.js +19 -0
- package/lib/module/reanimated/useAnimatedTheme.native.js.map +1 -0
- package/lib/module/server/getServerUnistyles.js +7 -4
- package/lib/module/server/getServerUnistyles.js.map +1 -1
- package/lib/module/server/hydrateServerUnistyles.js +2 -2
- package/lib/module/server/hydrateServerUnistyles.js.map +1 -1
- package/lib/module/server/resetServerUnistyles.js +2 -2
- package/lib/module/server/resetServerUnistyles.js.map +1 -1
- package/lib/module/server/serialize.js +19 -0
- package/lib/module/server/serialize.js.map +1 -0
- package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +1 -0
- package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +2 -2
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/utils.js +19 -0
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/convert/index.js +4 -7
- package/lib/module/web/convert/index.js.map +1 -1
- package/lib/module/web/convert/object/filter.js +3 -4
- package/lib/module/web/convert/object/filter.js.map +1 -1
- package/lib/module/web/create.js +9 -3
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/css/core.js +2 -2
- package/lib/module/web/css/core.js.map +1 -1
- package/lib/module/web/css/state.js +6 -3
- package/lib/module/web/css/state.js.map +1 -1
- package/lib/module/web/index.js +4 -10
- package/lib/module/web/index.js.map +1 -1
- package/lib/module/web/registry.js +11 -9
- package/lib/module/web/registry.js.map +1 -1
- package/lib/module/web/runtime.js +5 -1
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/module/web/services.js +7 -1
- package/lib/module/web/services.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +27 -10
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/state.js +11 -2
- package/lib/module/web/state.js.map +1 -1
- package/lib/module/web/types.js +1 -1
- package/lib/module/web/types.js.map +1 -1
- package/lib/module/web/utils/createUnistylesRef.js +24 -0
- package/lib/module/web/utils/createUnistylesRef.js.map +1 -0
- package/lib/module/web/utils/unistyle.js +32 -10
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/module/web-only/getWebProps.js +14 -0
- package/lib/module/web-only/getWebProps.js.map +1 -0
- package/lib/module/web-only/index.js +4 -0
- package/lib/module/web-only/index.js.map +1 -0
- package/lib/typescript/src/components/native/Animated.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Image.native.d.ts +2 -0
- package/lib/typescript/src/components/native/Image.native.d.ts.map +1 -0
- package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/core/getClassname.d.ts +5 -5
- package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
- package/lib/typescript/src/core/passForwardRef.d.ts +1 -1
- package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/core/warn.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +1 -3
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -1
- package/lib/typescript/src/mocks.d.ts +2 -0
- package/lib/typescript/src/mocks.d.ts.map +1 -0
- package/lib/typescript/src/mq.d.ts +0 -8
- package/lib/typescript/src/mq.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/index.d.ts +2 -0
- package/lib/typescript/src/reanimated/index.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts +4 -0
- package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts +4 -0
- package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts.map +1 -0
- package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +0 -1
- package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/server/serialize.d.ts +2 -0
- package/lib/typescript/src/server/serialize.d.ts.map +1 -0
- package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +2 -1
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
- package/lib/typescript/src/types/common.d.ts +0 -1
- package/lib/typescript/src/types/common.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +8 -0
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/index.d.ts +2 -1
- package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/object/filter.d.ts +2 -1
- package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/shadow/textShadow.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/utils.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.map +1 -1
- package/lib/typescript/src/web/css/state.d.ts +4 -1
- package/lib/typescript/src/web/css/state.d.ts.map +1 -1
- package/lib/typescript/src/web/css/utils.d.ts.map +1 -1
- package/lib/typescript/src/web/index.d.ts +0 -5
- package/lib/typescript/src/web/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener.d.ts.map +1 -1
- package/lib/typescript/src/web/registry.d.ts +2 -2
- 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/services.d.ts +6 -1
- package/lib/typescript/src/web/services.d.ts.map +1 -1
- package/lib/typescript/src/web/shadowRegistry.d.ts +2 -2
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
- package/lib/typescript/src/web/state.d.ts +2 -0
- package/lib/typescript/src/web/state.d.ts.map +1 -1
- package/lib/typescript/src/web/types.d.ts +3 -0
- package/lib/typescript/src/web/types.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/createUnistylesRef.d.ts +11 -0
- package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -0
- package/lib/typescript/src/web/utils/unistyle.d.ts +5 -2
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
- package/lib/typescript/src/web/variants.d.ts.map +1 -1
- package/lib/typescript/src/web-only/getWebProps.d.ts +7 -0
- package/lib/typescript/src/web-only/getWebProps.d.ts.map +1 -0
- package/lib/typescript/src/web-only/index.d.ts +2 -0
- package/lib/typescript/src/web-only/index.d.ts.map +1 -0
- package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +2 -2
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +2 -2
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +19 -19
- package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +3 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +7 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +7 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +22 -22
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +2 -1
- package/nitrogen/generated/android/unistyles+autolinking.cmake +16 -0
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +0 -1
- package/nitrogen/generated/ios/swift/UnistyleDependency.swift +4 -0
- package/nitrogen/generated/shared/c++/Dimensions.hpp +1 -0
- package/nitrogen/generated/shared/c++/Insets.hpp +1 -0
- package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -1
- package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +1 -0
- package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +1 -0
- package/package.json +77 -33
- package/plugin/index.d.ts +51 -18
- package/plugin/index.js +878 -177
- package/reanimated/package.json +6 -0
- package/server/package.json +6 -0
- package/src/components/native/Image.native.tsx +4 -0
- package/src/components/native/Image.tsx +36 -3
- package/src/components/native/ImageBackground.tsx +20 -36
- package/src/components/native/Pressable.native.tsx +25 -2
- package/src/core/createUnistylesElement.native.tsx +13 -2
- package/src/core/createUnistylesElement.tsx +26 -27
- package/src/core/createUnistylesImageBackground.tsx +16 -5
- package/src/core/getClassname.ts +16 -5
- package/src/core/passForwardRef.ts +5 -5
- package/src/core/useProxifiedUnistyles/listener.ts +3 -3
- package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +18 -1
- package/src/core/withUnistyles/withUnistyles.native.tsx +42 -17
- package/src/core/withUnistyles/withUnistyles.tsx +23 -6
- package/src/hooks/useMedia.native.ts +1 -1
- package/src/hooks/useMedia.ts +1 -1
- package/src/mocks.ts +217 -0
- package/src/mq.ts +0 -24
- package/src/reanimated/index.ts +1 -0
- package/src/reanimated/useAnimatedTheme.native.ts +21 -0
- package/src/reanimated/useAnimatedTheme.ts +19 -0
- package/src/server/getServerUnistyles.tsx +15 -10
- package/src/server/hydrateServerUnistyles.ts +3 -2
- package/src/server/resetServerUnistyles.ts +4 -3
- package/src/server/serialize.ts +20 -0
- package/src/specs/NativePlatform/NativePlatform.nitro.ts +2 -1
- package/src/specs/ShadowRegistry/index.ts +2 -2
- package/src/types/common.ts +0 -1
- package/src/types/stylesheet.ts +1 -1
- package/src/utils.ts +25 -0
- package/src/web/convert/index.ts +5 -7
- package/src/web/convert/object/filter.ts +4 -4
- package/src/web/create.ts +10 -3
- package/src/web/css/core.ts +2 -2
- package/src/web/css/state.ts +5 -3
- package/src/web/index.ts +4 -16
- package/src/web/registry.ts +20 -11
- package/src/web/runtime.ts +6 -2
- package/src/web/services.ts +14 -1
- package/src/web/shadowRegistry.ts +35 -13
- package/src/web/state.ts +14 -2
- package/src/web/types.ts +9 -4
- package/src/web/utils/createUnistylesRef.ts +33 -0
- package/src/web/utils/unistyle.ts +55 -23
- package/src/web-only/getWebProps.ts +18 -0
- package/src/web-only/index.ts +2 -0
- package/web/package.json +6 -0
- package/cxx/core/UnistylesCommitHook.cpp +0 -49
- package/cxx/core/UnistylesCommitHook.h +0 -27
- package/cxx/core/UnistylesMountHook.cpp +0 -28
- package/cxx/core/UnistylesMountHook.h +0 -27
- package/lib/module/package.json +0 -1
- package/plugin/consts.js +0 -63
- package/plugin/exotic.js +0 -54
- package/plugin/import.js +0 -51
- package/plugin/ref.js +0 -11
- package/plugin/stylesheet.js +0 -565
- package/plugin/variants.js +0 -66
- /package/cxx/common/{Constants.h → UnistylesConstants.h} +0 -0
package/src/mocks.ts
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
import type { UnistylesBreakpoints, UnistylesThemes } from './global'
|
2
|
+
import type { UnistylesNavigationBar } from './specs/NavigtionBar'
|
3
|
+
import type { UnistylesStatusBar } from './specs/StatusBar'
|
4
|
+
import type { UnistylesConfig, UnistylesStyleSheet } from './specs/StyleSheet'
|
5
|
+
import type { UnistylesRuntimePrivate } from './specs/UnistylesRuntime'
|
6
|
+
import type { ColorScheme, Orientation } from './specs/types'
|
7
|
+
import type { IOSContentSizeCategory, UnistylesTheme } from './types'
|
8
|
+
|
9
|
+
type Registry = {
|
10
|
+
themes: UnistylesThemes
|
11
|
+
breakpoints: UnistylesBreakpoints
|
12
|
+
}
|
13
|
+
|
14
|
+
jest.mock('react-native-nitro-modules', () => ({
|
15
|
+
NitroModules: {
|
16
|
+
createHybridObject: () => ({
|
17
|
+
add: () => {},
|
18
|
+
init: () => {},
|
19
|
+
createHybridStatusBar: () => ({
|
20
|
+
setStyle: () => {},
|
21
|
+
}),
|
22
|
+
createHybridNavigationBar: () => {},
|
23
|
+
})
|
24
|
+
}
|
25
|
+
}))
|
26
|
+
|
27
|
+
jest.mock('react-native-unistyles', () => {
|
28
|
+
const React = require('react')
|
29
|
+
const _REGISTRY: Registry = {
|
30
|
+
themes: {},
|
31
|
+
breakpoints: {}
|
32
|
+
}
|
33
|
+
const miniRuntime = {
|
34
|
+
themeName: undefined,
|
35
|
+
breakpoint: undefined,
|
36
|
+
hasAdaptiveThemes: false,
|
37
|
+
colorScheme: 'unspecified' as ColorScheme,
|
38
|
+
contentSizeCategory: 'Medium' as IOSContentSizeCategory,
|
39
|
+
insets: {
|
40
|
+
top: 0,
|
41
|
+
left: 0,
|
42
|
+
right: 0,
|
43
|
+
bottom: 0,
|
44
|
+
ime: 0
|
45
|
+
},
|
46
|
+
pixelRatio: 1,
|
47
|
+
fontScale: 1,
|
48
|
+
rtl: false,
|
49
|
+
isLandscape: false,
|
50
|
+
isPortrait: true,
|
51
|
+
navigationBar: {
|
52
|
+
width: 0,
|
53
|
+
height: 0
|
54
|
+
},
|
55
|
+
screen: {
|
56
|
+
width: 0,
|
57
|
+
height: 0
|
58
|
+
},
|
59
|
+
statusBar: {
|
60
|
+
width: 0,
|
61
|
+
height: 0
|
62
|
+
}
|
63
|
+
}
|
64
|
+
const unistylesRuntime = {
|
65
|
+
colorScheme: 'unspecified' as ColorScheme,
|
66
|
+
contentSizeCategory: 'Medium' as IOSContentSizeCategory,
|
67
|
+
orientation: 'portrait' as Orientation,
|
68
|
+
breakpoints: {},
|
69
|
+
dispose: () => { },
|
70
|
+
equals: () => false,
|
71
|
+
name: 'UnistylesRuntimeMock',
|
72
|
+
miniRuntime: miniRuntime,
|
73
|
+
statusBar: {
|
74
|
+
height: 0,
|
75
|
+
width: 0,
|
76
|
+
name: 'StatusBarMock',
|
77
|
+
equals: () => false,
|
78
|
+
setHidden: () => { },
|
79
|
+
setStyle: () => { }
|
80
|
+
},
|
81
|
+
navigationBar: {
|
82
|
+
height: 0,
|
83
|
+
width: 0,
|
84
|
+
name: 'NavigationBarMock',
|
85
|
+
equals: () => false,
|
86
|
+
setHidden: () => { },
|
87
|
+
dispose: () => { }
|
88
|
+
},
|
89
|
+
fontScale: 1,
|
90
|
+
hasAdaptiveThemes: false,
|
91
|
+
pixelRatio: 0,
|
92
|
+
rtl: false,
|
93
|
+
getTheme: () => {
|
94
|
+
return {} as UnistylesTheme
|
95
|
+
},
|
96
|
+
setTheme: () => {},
|
97
|
+
updateTheme: () => {},
|
98
|
+
setRootViewBackgroundColor: () => {},
|
99
|
+
_setRootViewBackgroundColor: () => {},
|
100
|
+
createHybridStatusBar: () => {
|
101
|
+
return {} as UnistylesStatusBar
|
102
|
+
},
|
103
|
+
createHybridNavigationBar: () => {
|
104
|
+
return {} as UnistylesNavigationBar
|
105
|
+
},
|
106
|
+
setAdaptiveThemes: () => {},
|
107
|
+
setImmersiveMode: () => {},
|
108
|
+
insets: {
|
109
|
+
top: 0,
|
110
|
+
left: 0,
|
111
|
+
right: 0,
|
112
|
+
bottom: 0,
|
113
|
+
ime: 0
|
114
|
+
},
|
115
|
+
screen: {
|
116
|
+
width: 0,
|
117
|
+
height: 0
|
118
|
+
},
|
119
|
+
breakpoint: undefined
|
120
|
+
} satisfies UnistylesRuntimePrivate
|
121
|
+
|
122
|
+
return {
|
123
|
+
Hide: () => null,
|
124
|
+
Display: () => null,
|
125
|
+
ScopedTheme: () => null,
|
126
|
+
withUnistyles: <TComponent,>(Component: TComponent, mapper?: (theme: UnistylesTheme, runtime: typeof miniRuntime) => TComponent) => (props: any) =>
|
127
|
+
React.createElement(Component, {
|
128
|
+
...mapper?.((Object.values(_REGISTRY.themes).at(0) ?? {}) as UnistylesTheme, miniRuntime),
|
129
|
+
...props
|
130
|
+
}),
|
131
|
+
mq: {
|
132
|
+
only: {
|
133
|
+
width: () => ({
|
134
|
+
and: {
|
135
|
+
height: () => ({})
|
136
|
+
}
|
137
|
+
}),
|
138
|
+
height: () => ({
|
139
|
+
and: {
|
140
|
+
width: () => ({})
|
141
|
+
}
|
142
|
+
})
|
143
|
+
},
|
144
|
+
width: () => ({
|
145
|
+
and: {
|
146
|
+
height: () => ({})
|
147
|
+
}
|
148
|
+
}),
|
149
|
+
height: () => ({
|
150
|
+
and: {
|
151
|
+
width: () => ({})
|
152
|
+
}
|
153
|
+
})
|
154
|
+
},
|
155
|
+
useUnistyles: () => ({
|
156
|
+
theme: Object.values(_REGISTRY.themes).at(0) ?? {},
|
157
|
+
rt: unistylesRuntime
|
158
|
+
}),
|
159
|
+
StyleSheet: {
|
160
|
+
absoluteFillObject: {
|
161
|
+
position: 'absolute',
|
162
|
+
left: 0,
|
163
|
+
right: 0,
|
164
|
+
top: 0,
|
165
|
+
bottom: 0
|
166
|
+
},
|
167
|
+
absoluteFill: {
|
168
|
+
position: 'absolute',
|
169
|
+
left: 0,
|
170
|
+
right: 0,
|
171
|
+
top: 0,
|
172
|
+
bottom: 0
|
173
|
+
} as unknown as UnistylesStyleSheet['absoluteFill'],
|
174
|
+
compose: (styles: any) => {
|
175
|
+
return styles
|
176
|
+
},
|
177
|
+
flatten: (styles: any) => {
|
178
|
+
return styles
|
179
|
+
},
|
180
|
+
create: (styles: any) => {
|
181
|
+
if (typeof styles === 'function') {
|
182
|
+
return {
|
183
|
+
...styles(Object.values(_REGISTRY.themes).at(0) ?? {}, miniRuntime),
|
184
|
+
useVariants: () => {}
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
return {
|
189
|
+
...styles,
|
190
|
+
useVariants: () => {}
|
191
|
+
}
|
192
|
+
},
|
193
|
+
configure: (config: UnistylesConfig) => {
|
194
|
+
if (config.breakpoints) {
|
195
|
+
_REGISTRY.breakpoints = config.breakpoints
|
196
|
+
}
|
197
|
+
|
198
|
+
if (config.themes) {
|
199
|
+
_REGISTRY.themes = config.themes
|
200
|
+
}
|
201
|
+
},
|
202
|
+
jsMethods: {
|
203
|
+
processColor: () => null
|
204
|
+
},
|
205
|
+
hairlineWidth: 1,
|
206
|
+
unid: -1,
|
207
|
+
addChangeListener: () => () => {},
|
208
|
+
init: () => {},
|
209
|
+
name: 'StyleSheetMock',
|
210
|
+
dispose: () => {},
|
211
|
+
equals: () => false
|
212
|
+
} satisfies UnistylesStyleSheet,
|
213
|
+
UnistylesRuntime: unistylesRuntime
|
214
|
+
}
|
215
|
+
})
|
216
|
+
|
217
|
+
|
package/src/mq.ts
CHANGED
@@ -2,10 +2,6 @@ import type { UnistylesBreakpoints } from './global'
|
|
2
2
|
import { UnistylesRuntime } from './specs'
|
3
3
|
import type { Nullable } from './types'
|
4
4
|
|
5
|
-
const IS_UNISTYLES_REGEX = /:([hw])\[(\d+)(?:,\s*(\d+|Infinity))?]/
|
6
|
-
const UNISTYLES_WIDTH_REGEX = /:(w)\[(\d+)(?:,\s*(\d+|Infinity))?]/
|
7
|
-
const UNISTYLES_HEIGHT_REGEX = /:(h)\[(\d+)(?:,\s*(\d+|Infinity))?]/
|
8
|
-
|
9
5
|
type MQValue = keyof UnistylesBreakpoints | number
|
10
6
|
|
11
7
|
type MQHandler = {
|
@@ -62,23 +58,3 @@ export const mq: MQHandler = {
|
|
62
58
|
})
|
63
59
|
}
|
64
60
|
|
65
|
-
export const parseMq = (mq: string) => {
|
66
|
-
const [, width, fromW, toW] = UNISTYLES_WIDTH_REGEX.exec(mq) || []
|
67
|
-
const [, height, fromH, toH] = UNISTYLES_HEIGHT_REGEX.exec(mq) || []
|
68
|
-
|
69
|
-
return {
|
70
|
-
minWidth: !width || fromW === 'Infinity' ? undefined : Number(fromW),
|
71
|
-
maxWidth: !width || toW === 'Infinity' ? undefined : Number(toW),
|
72
|
-
minHeight: !height || fromH === 'Infinity' ? undefined : Number(fromH),
|
73
|
-
maxHeight: !height || toH === 'Infinity' ? undefined : Number(toH),
|
74
|
-
}
|
75
|
-
}
|
76
|
-
|
77
|
-
export const isUnistylesMq = (mq: string) => IS_UNISTYLES_REGEX.test(mq)
|
78
|
-
|
79
|
-
export const isValidMq = (parsedMQ: ReturnType<typeof parseMq>) => {
|
80
|
-
const isWidthValid = parsedMQ.minWidth === undefined || parsedMQ.maxWidth === undefined || parsedMQ.minWidth <= parsedMQ.maxWidth
|
81
|
-
const isHeightValid = parsedMQ.minHeight === undefined || parsedMQ.maxHeight === undefined || parsedMQ.minHeight <= parsedMQ.maxHeight
|
82
|
-
|
83
|
-
return isWidthValid && isHeightValid
|
84
|
-
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export { useAnimatedTheme } from './useAnimatedTheme'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { useEffect } from 'react'
|
2
|
+
import { type SharedValue, useSharedValue } from 'react-native-reanimated'
|
3
|
+
import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs'
|
4
|
+
import type { UnistylesTheme } from '../types'
|
5
|
+
|
6
|
+
export const useAnimatedTheme = () => {
|
7
|
+
const theme = useSharedValue(UnistylesRuntime.getTheme())
|
8
|
+
|
9
|
+
useEffect(() => {
|
10
|
+
// @ts-ignore this is hidden from TS
|
11
|
+
const dispose = StyleSheet.addChangeListener(changedDependencies => {
|
12
|
+
if (changedDependencies.includes(UnistyleDependency.Theme)) {
|
13
|
+
theme.set(UnistylesRuntime.getTheme())
|
14
|
+
}
|
15
|
+
})
|
16
|
+
|
17
|
+
return () => dispose()
|
18
|
+
}, [])
|
19
|
+
|
20
|
+
return theme as SharedValue<UnistylesTheme>
|
21
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { useEffect } from 'react'
|
2
|
+
import { type SharedValue, useSharedValue } from 'react-native-reanimated'
|
3
|
+
import { UnistyleDependency, UnistylesRuntime } from '../specs'
|
4
|
+
import type { UnistylesTheme } from '../types'
|
5
|
+
import { services } from '../web/services'
|
6
|
+
|
7
|
+
export const useAnimatedTheme = () => {
|
8
|
+
const theme = useSharedValue(UnistylesRuntime.getTheme())
|
9
|
+
|
10
|
+
useEffect(() => {
|
11
|
+
const dispose = services.listener.addListeners([UnistyleDependency.Theme], () => theme.set(UnistylesRuntime.getTheme()))
|
12
|
+
|
13
|
+
return () => {
|
14
|
+
dispose()
|
15
|
+
}
|
16
|
+
}, [])
|
17
|
+
|
18
|
+
return theme as SharedValue<UnistylesTheme>
|
19
|
+
}
|
@@ -1,21 +1,26 @@
|
|
1
1
|
import React from 'react'
|
2
2
|
import { StyleSheet } from 'react-native'
|
3
|
-
import
|
3
|
+
import * as unistyles from '../web/services'
|
4
4
|
import { error, isServer } from '../web/utils'
|
5
|
+
import { serialize } from './serialize'
|
5
6
|
import { DefaultServerUnistylesSettings, type ServerUnistylesSettings } from './types'
|
6
7
|
|
7
8
|
export const getServerUnistyles = ({ includeRNWStyles = true }: ServerUnistylesSettings = DefaultServerUnistylesSettings) => {
|
8
9
|
if (!isServer()) {
|
9
10
|
throw error('Server styles should only be read on the server')
|
10
11
|
}
|
12
|
+
|
11
13
|
// @ts-ignore
|
12
14
|
const rnwStyle: string | null = includeRNWStyles ? (StyleSheet?.getSheet().textContent ?? '') : null
|
13
|
-
const css =
|
14
|
-
const state =
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
15
|
+
const css = unistyles.services.registry.css.getStyles()
|
16
|
+
const state = unistyles.services.registry.css.getState()
|
17
|
+
|
18
|
+
return (
|
19
|
+
<>
|
20
|
+
{rnwStyle && <style id='rnw-style'>{rnwStyle}</style>}
|
21
|
+
<style id='unistyles-web'>{css}</style>
|
22
|
+
{/* biome-ignore lint/security/noDangerouslySetInnerHtml: Needs the json quotes to be unescaped */}
|
23
|
+
<script id='unistyles-script' defer dangerouslySetInnerHTML={{ __html: `window.__UNISTYLES_STATE__ = ${serialize(state)}`}} />
|
24
|
+
</>
|
25
|
+
)
|
26
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import
|
1
|
+
import * as unistyles from '../web/services'
|
2
2
|
import { error, isServer } from '../web/utils'
|
3
3
|
|
4
4
|
declare global {
|
@@ -12,6 +12,7 @@ export const hydrateServerUnistyles = () => {
|
|
12
12
|
if (isServer()) {
|
13
13
|
throw error('Server styles should only be hydrated on the client')
|
14
14
|
}
|
15
|
-
|
15
|
+
|
16
|
+
unistyles.services.registry.css.hydrate(window.__UNISTYLES_STATE__)
|
16
17
|
document.querySelector('#unistyles-script')?.remove()
|
17
18
|
}
|
@@ -1,9 +1,10 @@
|
|
1
|
-
import
|
1
|
+
import * as unistyles from '../web/services'
|
2
2
|
import { error, isServer } from '../web/utils'
|
3
3
|
|
4
4
|
export const resetServerUnistyles = () => {
|
5
5
|
if (!isServer()) {
|
6
6
|
throw error('Server styles should only be reset on the server')
|
7
7
|
}
|
8
|
-
|
9
|
-
|
8
|
+
|
9
|
+
unistyles.services.registry.reset()
|
10
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
export const serialize = (value: any): string => {
|
2
|
+
switch (typeof value) {
|
3
|
+
case 'function':
|
4
|
+
return value.toString()
|
5
|
+
case 'object':
|
6
|
+
if (Array.isArray(value)) {
|
7
|
+
return `[${value.map(serialize).join(',')}]`
|
8
|
+
}
|
9
|
+
|
10
|
+
if (value === null) {
|
11
|
+
return 'null'
|
12
|
+
}
|
13
|
+
|
14
|
+
return `{${Object.entries(value)
|
15
|
+
.map(([key, value]) => `'${key}':${serialize(value)}`)
|
16
|
+
.join(',')}}`
|
17
|
+
default:
|
18
|
+
return JSON.stringify(value)
|
19
|
+
}
|
20
|
+
}
|
@@ -40,11 +40,11 @@ HybridShadowRegistry.add = (handle, styles) => {
|
|
40
40
|
? styles.flat()
|
41
41
|
: [styles]
|
42
42
|
|
43
|
-
// filter
|
43
|
+
// filter styles that are undefined or with no keys
|
44
44
|
const filteredStyles = stylesArray
|
45
|
-
.filter(style => !style?.initial?.updater)
|
46
45
|
.filter(style => style && Object.keys(style).length > 0)
|
47
46
|
.flat()
|
47
|
+
.filter(Boolean)
|
48
48
|
|
49
49
|
if (filteredStyles.length > 0) {
|
50
50
|
HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles)
|
package/src/types/common.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
export type Optional<T> = T | undefined
|
2
2
|
export type Nullable<T> = T | null
|
3
3
|
export type SafeReturnType<T> = T extends (...args: any) => infer R ? R : T
|
4
|
-
export type PartialBy<T, K> = Omit<T, K & keyof T> & Partial<Pick<T, K & keyof T>>
|
5
4
|
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
|
package/src/types/stylesheet.ts
CHANGED
@@ -62,7 +62,7 @@ export type UnistylesValues = FlatUnistylesValues & {
|
|
62
62
|
} & VariantsAndCompoundVariants & {
|
63
63
|
[propName in NestedKeys]?: UnistyleNestedStyles[propName]
|
64
64
|
} & {
|
65
|
-
_web?: CSSProperties & CustomClassName & {
|
65
|
+
_web?: ToDeepUnistyles<CSSProperties> & CustomClassName & {
|
66
66
|
[propName in Pseudo]?: ToDeepUnistyles<CSSProperties>
|
67
67
|
}
|
68
68
|
}
|
package/src/utils.ts
CHANGED
@@ -41,3 +41,28 @@ export const copyComponentProperties = (Component: any, UnistylesComponent: any)
|
|
41
41
|
|
42
42
|
return UnistylesComponent
|
43
43
|
}
|
44
|
+
|
45
|
+
const IS_UNISTYLES_REGEX = /:([hw])\[(\d+)(?:,\s*(\d+|Infinity))?]/
|
46
|
+
const UNISTYLES_WIDTH_REGEX = /:(w)\[(\d+)(?:,\s*(\d+|Infinity))?]/
|
47
|
+
const UNISTYLES_HEIGHT_REGEX = /:(h)\[(\d+)(?:,\s*(\d+|Infinity))?]/
|
48
|
+
|
49
|
+
export const isUnistylesMq = (mq: string) => IS_UNISTYLES_REGEX.test(mq)
|
50
|
+
|
51
|
+
export const parseMq = (mq: string) => {
|
52
|
+
const [, width, fromW, toW] = UNISTYLES_WIDTH_REGEX.exec(mq) || []
|
53
|
+
const [, height, fromH, toH] = UNISTYLES_HEIGHT_REGEX.exec(mq) || []
|
54
|
+
|
55
|
+
return {
|
56
|
+
minWidth: !width || fromW === 'Infinity' ? undefined : Number(fromW),
|
57
|
+
maxWidth: !width || toW === 'Infinity' ? undefined : Number(toW),
|
58
|
+
minHeight: !height || fromH === 'Infinity' ? undefined : Number(fromH),
|
59
|
+
maxHeight: !height || toH === 'Infinity' ? undefined : Number(toH),
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
export const isValidMq = (parsedMQ: ReturnType<typeof parseMq>) => {
|
64
|
+
const isWidthValid = parsedMQ.minWidth === undefined || parsedMQ.maxWidth === undefined || parsedMQ.minWidth <= parsedMQ.maxWidth
|
65
|
+
const isHeightValid = parsedMQ.minHeight === undefined || parsedMQ.maxHeight === undefined || parsedMQ.minHeight <= parsedMQ.maxHeight
|
66
|
+
|
67
|
+
return isWidthValid && isHeightValid
|
68
|
+
}
|
package/src/web/convert/index.ts
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
import type { UnistylesValues } from '../../types'
|
2
2
|
import { deepMergeObjects } from '../../utils'
|
3
|
+
import type { UnistylesRuntime } from '../runtime'
|
3
4
|
import { getBoxShadow, getFilterStyle, getTransformStyle } from './object'
|
4
5
|
import { isPseudo } from './pseudo'
|
5
6
|
import { getBoxShadowStyle, getTextShadowStyle } from './shadow'
|
6
7
|
import { getStyle } from './style'
|
7
8
|
import { isBoxShadow, isFilter, isShadow, isTextShadow, isTransform } from './utils'
|
8
9
|
|
9
|
-
export const convertUnistyles = (value: UnistylesValues) => {
|
10
|
+
export const convertUnistyles = (value: UnistylesValues, runtime: UnistylesRuntime) => {
|
10
11
|
// Flag to mark if textShadow is already created
|
11
12
|
let hasTextShadow = false
|
12
13
|
// Flag to mark if boxShadow is already created
|
13
14
|
let hasShadow = false
|
14
15
|
|
15
|
-
const stylesArray = Object.entries({
|
16
|
-
...value,
|
17
|
-
...value._web
|
18
|
-
}).flatMap(([unistylesKey, unistylesValue]) => {
|
16
|
+
const stylesArray = Object.entries(value).flatMap(([unistylesKey, unistylesValue]) => {
|
19
17
|
// Keys to omit
|
20
18
|
if (['_classNames', '_web', 'variants', 'compoundVariants', 'uni__dependencies'].includes(unistylesKey) || unistylesKey.startsWith('unistyles_')) {
|
21
19
|
return []
|
@@ -23,7 +21,7 @@ export const convertUnistyles = (value: UnistylesValues) => {
|
|
23
21
|
|
24
22
|
// Pseudo classes :hover, :before etc.
|
25
23
|
if (isPseudo(unistylesKey)) {
|
26
|
-
const flattenValues = convertUnistyles(unistylesValue as UnistylesValues)
|
24
|
+
const flattenValues = convertUnistyles(unistylesValue as UnistylesValues, runtime)
|
27
25
|
|
28
26
|
return { [unistylesKey]: flattenValues }
|
29
27
|
}
|
@@ -51,7 +49,7 @@ export const convertUnistyles = (value: UnistylesValues) => {
|
|
51
49
|
}
|
52
50
|
|
53
51
|
if (isFilter(unistylesKey, unistylesValue)) {
|
54
|
-
return getFilterStyle(unistylesValue)
|
52
|
+
return getFilterStyle(unistylesValue, runtime)
|
55
53
|
}
|
56
54
|
|
57
55
|
if (isBoxShadow(unistylesKey, unistylesValue)) {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { DropShadowValue } from 'react-native'
|
2
|
-
import { isUnistylesMq } from '../../../
|
3
|
-
import {
|
2
|
+
import { isUnistylesMq } from '../../../utils'
|
3
|
+
import type { UnistylesRuntime } from '../../runtime'
|
4
4
|
import { hyphenate } from '../../utils'
|
5
5
|
import type { Filters } from '../types'
|
6
6
|
import { normalizeColor, normalizeNumericValue } from '../utils'
|
@@ -12,7 +12,7 @@ const getDropShadowStyle = (dropShadow: DropShadowValue) => {
|
|
12
12
|
return `${normalizeColor(String(color))} ${normalizeNumericValue(offsetX)} ${normalizeNumericValue(offsetY)} ${normalizeNumericValue(standardDeviation)}`
|
13
13
|
}
|
14
14
|
|
15
|
-
export const getFilterStyle = (filters: Array<Filters
|
15
|
+
export const getFilterStyle = (filters: Array<Filters>, runtime: UnistylesRuntime) => {
|
16
16
|
const restFilters = filters.filter(filter => Object.keys(filter)[0] !== 'dropShadow')
|
17
17
|
const dropShadow = (() => {
|
18
18
|
const dropShadowValue = filters.find(filter => Object.keys(filter)[0] === 'dropShadow')?.dropShadow as Record<string, any>
|
@@ -21,7 +21,7 @@ export const getFilterStyle = (filters: Array<Filters>) => {
|
|
21
21
|
return []
|
22
22
|
}
|
23
23
|
|
24
|
-
const breakpoints = Object.keys(dropShadowValue).filter(key => Object.keys(
|
24
|
+
const breakpoints = Object.keys(dropShadowValue).filter(key => Object.keys(runtime.breakpoints).includes(key) || isUnistylesMq(key))
|
25
25
|
const breakpointsDropShadow = Object.fromEntries(breakpoints.map(breakpoint => [breakpoint, getDropShadowStyle(dropShadowValue[breakpoint])]))
|
26
26
|
|
27
27
|
if (breakpoints.length === 0) {
|
package/src/web/create.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { StyleSheet, StyleSheetWithSuperPowers } from '../types/stylesheet'
|
2
|
-
import
|
3
|
-
import { assignSecrets, error, removeInlineStyles } from './utils'
|
2
|
+
import * as unistyles from './services'
|
3
|
+
import { assignSecrets, error, isServer, removeInlineStyles } from './utils'
|
4
4
|
|
5
5
|
type Variants = Record<string, string | boolean | undefined>
|
6
6
|
|
@@ -9,7 +9,14 @@ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, id?: s
|
|
9
9
|
throw error('Unistyles is not initialized correctly. Please add babel plugin to your babel config.')
|
10
10
|
}
|
11
11
|
|
12
|
-
|
12
|
+
// For SSR
|
13
|
+
if (!unistyles.services.state.isInitialized && !isServer()) {
|
14
|
+
const config = window?.__UNISTYLES_STATE__?.config
|
15
|
+
|
16
|
+
config && unistyles.services.state.init(config)
|
17
|
+
}
|
18
|
+
|
19
|
+
const computedStylesheet = unistyles.services.registry.getComputedStylesheet(stylesheet)
|
13
20
|
const addSecrets = (value: any, key: string, args = undefined as Array<any> | undefined, variants = {} as Variants) => assignSecrets(value, {
|
14
21
|
__uni__key: key,
|
15
22
|
__uni__stylesheet: stylesheet,
|
package/src/web/css/core.ts
CHANGED
@@ -8,7 +8,7 @@ export const convertToCSS = (hash: string, value: Record<string, any>, state: CS
|
|
8
8
|
|
9
9
|
Object.entries(styleValue).forEach(([pseudoStyleKey, pseudoStyleValue]) => {
|
10
10
|
if (typeof pseudoStyleValue === 'object' && pseudoStyleValue !== null) {
|
11
|
-
const allBreakpoints = Object.keys(
|
11
|
+
const allBreakpoints = Object.keys(styleValue)
|
12
12
|
Object.entries(pseudoStyleValue).forEach(([breakpointStyleKey, breakpointStyleValue]) => {
|
13
13
|
const mediaQuery = getMediaQuery(pseudoStyleKey, allBreakpoints)
|
14
14
|
|
@@ -34,7 +34,7 @@ export const convertToCSS = (hash: string, value: Record<string, any>, state: CS
|
|
34
34
|
}
|
35
35
|
|
36
36
|
if (typeof styleValue === 'object') {
|
37
|
-
const allBreakpoints = Object.keys(
|
37
|
+
const allBreakpoints = Object.keys(value)
|
38
38
|
Object.entries(styleValue).forEach(([breakpointStyleKey, breakpointStyleValue]) => {
|
39
39
|
const mediaQuery = getMediaQuery(styleKey, allBreakpoints)
|
40
40
|
|
package/src/web/css/state.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { UnistylesValues } from '../../types'
|
2
2
|
import { convertUnistyles } from '../convert'
|
3
|
+
import type { UnistylesServices } from '../types'
|
3
4
|
import { hyphenate, isServer } from '../utils'
|
4
5
|
import { convertToCSS } from './core'
|
5
6
|
|
@@ -33,7 +34,7 @@ export class CSSState {
|
|
33
34
|
private styleTag: HTMLStyleElement | null = null
|
34
35
|
private CSS = ''
|
35
36
|
|
36
|
-
constructor() {
|
37
|
+
constructor(private services: UnistylesServices) {
|
37
38
|
if (isServer()) {
|
38
39
|
return
|
39
40
|
}
|
@@ -60,7 +61,7 @@ export class CSSState {
|
|
60
61
|
}
|
61
62
|
|
62
63
|
add = (hash: string, values: UnistylesValues) => {
|
63
|
-
convertToCSS(hash, convertUnistyles(values), this)
|
64
|
+
convertToCSS(hash, convertUnistyles(values, this.services.runtime), this)
|
64
65
|
|
65
66
|
if (this.styleTag) {
|
66
67
|
this.styleTag.innerText = this.getStyles()
|
@@ -159,8 +160,9 @@ export class CSSState {
|
|
159
160
|
|
160
161
|
const mainState = getState(this.mainMap)
|
161
162
|
const mqState = getState(this.mqMap)
|
163
|
+
const config = this.services.state.getConfig()
|
162
164
|
|
163
|
-
return { mainState, mqState }
|
165
|
+
return { mainState, mqState, config }
|
164
166
|
}
|
165
167
|
|
166
168
|
hydrate = ({ mainState, mqState }: ReturnType<typeof this.getState>) => {
|
package/src/web/index.ts
CHANGED
@@ -3,22 +3,10 @@ import type { StyleSheet as NativeStyleSheet } from '../specs/StyleSheet'
|
|
3
3
|
import type { Runtime as NativeUnistylesRuntime } from '../specs/UnistylesRuntime'
|
4
4
|
import { deepMergeObjects } from '../utils'
|
5
5
|
import { create } from './create'
|
6
|
-
import
|
7
|
-
import { isServer } from './utils'
|
6
|
+
import * as unistyles from './services'
|
8
7
|
|
9
|
-
declare global {
|
10
|
-
// @ts-ignore
|
11
|
-
var __unistyles__: UnistylesServices
|
12
|
-
}
|
13
|
-
|
14
|
-
if (isServer() && !globalThis.__unistyles__) {
|
15
|
-
// @ts-ignore
|
16
|
-
globalThis.__unistyles__ = new UnistylesServices()
|
17
|
-
}
|
18
|
-
|
19
|
-
export const UnistylesWeb = isServer() ? globalThis.__unistyles__ : new UnistylesServices()
|
20
8
|
export const StyleSheet = {
|
21
|
-
configure:
|
9
|
+
configure: unistyles.services.state.init,
|
22
10
|
create: create,
|
23
11
|
absoluteFill: {
|
24
12
|
position: 'absolute',
|
@@ -39,8 +27,8 @@ export const StyleSheet = {
|
|
39
27
|
hairlineWidth: 1
|
40
28
|
} as unknown as typeof NativeStyleSheet
|
41
29
|
|
42
|
-
export const UnistylesRuntime =
|
43
|
-
export const UnistylesShadowRegistry =
|
30
|
+
export const UnistylesRuntime = unistyles.services.runtime as unknown as typeof NativeUnistylesRuntime
|
31
|
+
export const UnistylesShadowRegistry = unistyles.services.shadowRegistry as unknown as typeof NativeUnistylesShadowRegistry
|
44
32
|
|
45
33
|
export * from './mock'
|
46
34
|
|