react-native-unistyles 3.0.0-rc.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/Unistyles.podspec +12 -1
- package/android/build.gradle +1 -1
- package/android/src/main/cxx/NativeUnistylesModule.cpp +5 -8
- package/android/src/main/cxx/NativeUnistylesModule.h +4 -4
- package/android/src/main/java/com/unistyles/NativePlatform+android.kt +1 -0
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +21 -9
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +8 -7
- package/cxx/core/UnistyleWrapper.h +4 -1
- package/cxx/core/UnistylesCommitShadowNode.h +0 -21
- package/cxx/core/UnistylesRegistry.cpp +52 -49
- package/cxx/core/UnistylesRegistry.h +2 -1
- package/cxx/core/UnistylesState.cpp +10 -0
- package/cxx/core/UnistylesState.h +3 -0
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +6 -1
- package/cxx/hybridObjects/HybridShadowRegistry.h +6 -0
- package/cxx/hybridObjects/HybridStyleSheet.cpp +13 -16
- package/cxx/hybridObjects/HybridStyleSheet.h +2 -7
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +17 -2
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
- package/cxx/parser/Parser.cpp +175 -110
- package/cxx/parser/Parser.h +1 -0
- package/cxx/shadowTree/ShadowTreeManager.cpp +36 -33
- package/cxx/shadowTree/ShadowTreeManager.h +0 -1
- package/get_rn_version.rb +28 -0
- package/ios/UnistylesModuleOnLoad.h +1 -5
- package/ios/UnistylesModuleOnLoad.mm +10 -13
- package/lib/commonjs/components/AdaptiveTheme.js +35 -0
- package/lib/commonjs/components/AdaptiveTheme.js.map +1 -0
- package/lib/commonjs/components/ApplyScopedTheme.js +19 -0
- package/lib/commonjs/components/ApplyScopedTheme.js.map +1 -0
- package/lib/commonjs/components/NamedTheme.js +31 -0
- package/lib/commonjs/components/NamedTheme.js.map +1 -0
- package/lib/commonjs/components/ScopedTheme.js +30 -21
- package/lib/commonjs/components/ScopedTheme.js.map +1 -1
- package/lib/commonjs/components/native/Image.js +1 -2
- package/lib/commonjs/components/native/Image.js.map +1 -1
- package/lib/commonjs/components/native/ImageBackground.js +1 -2
- package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
- package/lib/commonjs/components/native/Pressable.js +1 -2
- package/lib/commonjs/components/native/Pressable.js.map +1 -1
- package/lib/commonjs/components/native/Pressable.native.js +1 -2
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.js +5 -5
- package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.native.js +18 -31
- package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesImageBackground.js +6 -21
- package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/commonjs/core/getClassname.js +1 -2
- package/lib/commonjs/core/getClassname.js.map +1 -1
- package/lib/commonjs/core/parseBoxShadow.js +57 -0
- package/lib/commonjs/core/parseBoxShadow.js.map +1 -0
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js +2 -3
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js +2 -1
- package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -2
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.js +10 -5
- package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +10 -5
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/commonjs/index.js +6 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mocks.js +26 -2
- package/lib/commonjs/mocks.js.map +1 -1
- package/lib/commonjs/reanimated/index.js +7 -0
- package/lib/commonjs/reanimated/index.js.map +1 -1
- package/lib/commonjs/reanimated/variant/index.js +17 -0
- package/lib/commonjs/reanimated/variant/index.js.map +1 -0
- package/lib/commonjs/reanimated/variant/types.js +2 -0
- package/lib/commonjs/reanimated/variant/types.js.map +1 -0
- package/lib/commonjs/reanimated/variant/useAnimatedVariantColor.js +38 -0
- package/lib/commonjs/reanimated/variant/useAnimatedVariantColor.js.map +1 -0
- package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js +66 -0
- package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js.map +1 -0
- package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js +39 -0
- package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js.map +1 -0
- package/lib/commonjs/server/getServerUnistyles.js +1 -2
- package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/hydrateServerUnistyles.js +1 -2
- package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/resetServerUnistyles.js +1 -2
- package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +6 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js +3 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js +0 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/commonjs/utils.js +0 -3
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/convert/object/boxShadow.js.map +1 -1
- package/lib/commonjs/web/convert/pseudo.js +13 -3
- package/lib/commonjs/web/convert/pseudo.js.map +1 -1
- package/lib/commonjs/web/convert/utils.js +1 -0
- package/lib/commonjs/web/convert/utils.js.map +1 -1
- package/lib/commonjs/web/create.js +2 -3
- package/lib/commonjs/web/create.js.map +1 -1
- package/lib/commonjs/web/css/core.js +9 -2
- package/lib/commonjs/web/css/core.js.map +1 -1
- package/lib/commonjs/web/css/state.js +10 -7
- package/lib/commonjs/web/css/state.js.map +1 -1
- package/lib/commonjs/web/index.js +1 -2
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/commonjs/web/listener.js +4 -2
- package/lib/commonjs/web/listener.js.map +1 -1
- package/lib/commonjs/web/runtime.js +26 -2
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +5 -3
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/state.js +1 -10
- package/lib/commonjs/web/state.js.map +1 -1
- package/lib/commonjs/web/types.js.map +1 -1
- package/lib/commonjs/web/utils/createUnistylesRef.js +1 -2
- package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -1
- package/lib/commonjs/web/utils/unistyle.js +26 -4
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/module/components/AdaptiveTheme.js +29 -0
- package/lib/module/components/AdaptiveTheme.js.map +1 -0
- package/lib/module/components/ApplyScopedTheme.js +14 -0
- package/lib/module/components/ApplyScopedTheme.js.map +1 -0
- package/lib/module/components/NamedTheme.js +25 -0
- package/lib/module/components/NamedTheme.js.map +1 -0
- package/lib/module/components/ScopedTheme.js +30 -20
- package/lib/module/components/ScopedTheme.js.map +1 -1
- package/lib/module/core/createUnistylesElement.js +5 -5
- package/lib/module/core/createUnistylesElement.js.map +1 -1
- package/lib/module/core/createUnistylesElement.native.js +18 -30
- package/lib/module/core/createUnistylesElement.native.js.map +1 -1
- package/lib/module/core/createUnistylesImageBackground.js +5 -19
- package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/module/core/parseBoxShadow.js +52 -0
- package/lib/module/core/parseBoxShadow.js.map +1 -0
- package/lib/module/core/useProxifiedUnistyles/listener.js +1 -1
- package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/listener.native.js +2 -1
- package/lib/module/core/useProxifiedUnistyles/listener.native.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -2
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.js +9 -3
- package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js +9 -3
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/mocks.js +26 -2
- package/lib/module/mocks.js.map +1 -1
- package/lib/module/reanimated/index.js +1 -0
- package/lib/module/reanimated/index.js.map +1 -1
- package/lib/module/reanimated/variant/index.js +4 -0
- package/lib/module/reanimated/variant/index.js.map +1 -0
- package/lib/module/reanimated/variant/types.js +2 -0
- package/lib/module/reanimated/variant/types.js.map +1 -0
- package/lib/module/reanimated/variant/useAnimatedVariantColor.js +33 -0
- package/lib/module/reanimated/variant/useAnimatedVariantColor.js.map +1 -0
- package/lib/module/reanimated/variant/useUpdateVariantColor.js +61 -0
- package/lib/module/reanimated/variant/useUpdateVariantColor.js.map +1 -0
- package/lib/module/reanimated/variant/useUpdateVariantColor.native.js +34 -0
- package/lib/module/reanimated/variant/useUpdateVariantColor.native.js.map +1 -0
- package/lib/module/specs/ShadowRegistry/index.js +6 -1
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js +3 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js +0 -1
- package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/module/utils.js +0 -3
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/convert/object/boxShadow.js.map +1 -1
- package/lib/module/web/convert/pseudo.js +10 -2
- package/lib/module/web/convert/pseudo.js.map +1 -1
- package/lib/module/web/convert/utils.js +1 -0
- package/lib/module/web/convert/utils.js.map +1 -1
- package/lib/module/web/create.js +1 -1
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/css/core.js +9 -2
- package/lib/module/web/css/core.js.map +1 -1
- package/lib/module/web/css/state.js +10 -7
- package/lib/module/web/css/state.js.map +1 -1
- package/lib/module/web/listener.js +4 -2
- package/lib/module/web/listener.js.map +1 -1
- package/lib/module/web/runtime.js +27 -3
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +5 -3
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/state.js +1 -10
- package/lib/module/web/state.js.map +1 -1
- package/lib/module/web/types.js.map +1 -1
- package/lib/module/web/utils/unistyle.js +24 -3
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/typescript/plugin/src/consts.d.ts +17 -0
- package/lib/typescript/plugin/src/consts.d.ts.map +1 -0
- package/lib/typescript/repack-plugin/src/index.d.ts +18 -0
- package/lib/typescript/repack-plugin/src/index.d.ts.map +1 -0
- package/lib/typescript/repack-plugin/src/loader.d.ts +9 -0
- package/lib/typescript/repack-plugin/src/loader.d.ts.map +1 -0
- package/lib/typescript/src/components/AdaptiveTheme.d.ts +8 -0
- package/lib/typescript/src/components/AdaptiveTheme.d.ts.map +1 -0
- package/lib/typescript/src/components/ApplyScopedTheme.d.ts +7 -0
- package/lib/typescript/src/components/ApplyScopedTheme.d.ts.map +1 -0
- package/lib/typescript/src/components/NamedTheme.d.ts +10 -0
- package/lib/typescript/src/components/NamedTheme.d.ts.map +1 -0
- package/lib/typescript/src/components/ScopedTheme.d.ts +10 -0
- package/lib/typescript/src/components/ScopedTheme.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Animated.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.map +1 -1
- package/lib/typescript/src/core/parseBoxShadow.d.ts +11 -0
- package/lib/typescript/src/core/parseBoxShadow.d.ts.map +1 -0
- 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/types.d.ts +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/types.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/types.d.ts +3 -1
- package/lib/typescript/src/core/withUnistyles/types.d.ts.map +1 -1
- 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/hooks/useMedia.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/index.d.ts +1 -0
- package/lib/typescript/src/reanimated/index.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/variant/index.d.ts +2 -0
- package/lib/typescript/src/reanimated/variant/index.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/variant/types.d.ts +10 -0
- package/lib/typescript/src/reanimated/variant/types.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/variant/useAnimatedVariantColor.d.ts +3 -0
- package/lib/typescript/src/reanimated/variant/useAnimatedVariantColor.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts +6 -0
- package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts +6 -0
- package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts.map +1 -0
- package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/server/serialize.d.ts.map +1 -1
- package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +1 -0
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -0
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +2 -0
- package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts.map +1 -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.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 +6 -3
- 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 +2 -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/listener.d.ts +4 -2
- package/lib/typescript/src/web/listener.d.ts.map +1 -1
- package/lib/typescript/src/web/registry.d.ts.map +1 -1
- package/lib/typescript/src/web/runtime.d.ts +2 -0
- package/lib/typescript/src/web/runtime.d.ts.map +1 -1
- package/lib/typescript/src/web/shadowRegistry.d.ts +2 -0
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
- package/lib/typescript/src/web/state.d.ts.map +1 -1
- package/lib/typescript/src/web/types.d.ts +4 -1
- 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.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts +5 -1
- 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.map +1 -1
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +1 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +2 -0
- package/package.json +33 -23
- package/plugin/index.d.ts +6 -5
- package/plugin/index.js +11 -6
- package/repack-plugin/index.d.ts +19 -0
- package/repack-plugin/index.js +149 -0
- package/src/components/AdaptiveTheme.tsx +34 -0
- package/src/components/ApplyScopedTheme.tsx +17 -0
- package/src/components/NamedTheme.tsx +33 -0
- package/src/components/ScopedTheme.tsx +51 -24
- package/src/core/createUnistylesElement.native.tsx +21 -31
- package/src/core/createUnistylesElement.tsx +8 -6
- package/src/core/createUnistylesImageBackground.tsx +7 -22
- package/src/core/parseBoxShadow.ts +87 -0
- package/src/core/useProxifiedUnistyles/listener.native.ts +3 -1
- package/src/core/useProxifiedUnistyles/listener.ts +1 -1
- package/src/core/useProxifiedUnistyles/types.ts +1 -1
- package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +19 -2
- package/src/core/withUnistyles/types.ts +1 -1
- package/src/core/withUnistyles/withUnistyles.native.tsx +10 -3
- package/src/core/withUnistyles/withUnistyles.tsx +11 -8
- package/src/index.ts +8 -0
- package/src/mocks.ts +28 -2
- package/src/reanimated/index.ts +1 -0
- package/src/reanimated/variant/index.ts +1 -0
- package/src/reanimated/variant/types.ts +14 -0
- package/src/reanimated/variant/useAnimatedVariantColor.ts +38 -0
- package/src/reanimated/variant/useUpdateVariantColor.native.ts +38 -0
- package/src/reanimated/variant/useUpdateVariantColor.ts +81 -0
- package/src/specs/ShadowRegistry/index.ts +7 -1
- package/src/specs/StyleSheet/index.ts +5 -2
- package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +2 -0
- package/src/specs/UnistylesRuntime/index.ts +0 -1
- package/src/utils.ts +1 -3
- package/src/web/convert/object/boxShadow.ts +2 -2
- package/src/web/convert/pseudo.ts +23 -52
- package/src/web/convert/utils.ts +2 -1
- package/src/web/create.ts +1 -1
- package/src/web/css/core.ts +12 -2
- package/src/web/css/state.ts +10 -8
- package/src/web/listener.ts +10 -6
- package/src/web/runtime.ts +37 -3
- package/src/web/shadowRegistry.ts +5 -3
- package/src/web/state.ts +7 -17
- package/src/web/types.ts +4 -1
- package/src/web/utils/unistyle.ts +34 -4
- package/cxx/core/UnistylesCommitHook.cpp +0 -59
- package/cxx/core/UnistylesCommitHook.h +0 -27
- package/cxx/core/UnistylesMountHook.cpp +0 -26
- package/cxx/core/UnistylesMountHook.h +0 -24
- package/lib/module/package.json +0 -1
- /package/{web-only → web}/package.json +0 -0
package/src/utils.ts
CHANGED
@@ -35,10 +35,8 @@ export const copyComponentProperties = (Component: any, UnistylesComponent: any)
|
|
35
35
|
UnistylesComponent[key] = value
|
36
36
|
})
|
37
37
|
|
38
|
-
// Those are not enumerable, so we need to copy them manually
|
39
38
|
UnistylesComponent.displayName = Component.displayName
|
40
|
-
|
41
|
-
|
39
|
+
|
42
40
|
return UnistylesComponent
|
43
41
|
}
|
44
42
|
|
@@ -25,7 +25,7 @@ export const getBoxShadow = (boxShadow: Array<BoxShadowValue>) => {
|
|
25
25
|
const boxShadowStyle = Object.fromEntries(boxShadow.map(shadow => {
|
26
26
|
const [key] = Object.keys(shadow)
|
27
27
|
return [key, shadow[key as keyof BoxShadowValue]]
|
28
|
-
}))
|
28
|
+
})) as BoxShadowValue
|
29
29
|
|
30
30
|
return {
|
31
31
|
boxShadow: createBoxShadowValue(boxShadowStyle)
|
@@ -42,7 +42,7 @@ export const getBoxShadow = (boxShadow: Array<BoxShadowValue>) => {
|
|
42
42
|
}
|
43
43
|
|
44
44
|
return [key, value]
|
45
|
-
}))
|
45
|
+
})) as BoxShadowValue
|
46
46
|
|
47
47
|
return {
|
48
48
|
[breakpoint]: {
|
@@ -1,26 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
'_-moz-handler-blocked',
|
6
|
-
'_-moz-handler-crashed',
|
7
|
-
'_-moz-handler-disabled',
|
8
|
-
'_-moz-last-node',
|
9
|
-
'_-moz-loading',
|
10
|
-
'_-moz-locale-dir(ltr)',
|
11
|
-
'_-moz-locale-dir(rtl)',
|
12
|
-
'_-moz-only-whitespace',
|
13
|
-
'_-moz-submit-invalid',
|
14
|
-
'_-moz-suppressed',
|
15
|
-
'_-moz-user-disabled',
|
16
|
-
'_-moz-window-inactive',
|
1
|
+
// All non experimental pseudo clasess and elements
|
2
|
+
|
3
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes
|
4
|
+
const pseudoClasses = [
|
17
5
|
'_active',
|
18
6
|
'_any-link',
|
19
7
|
'_autofill',
|
20
|
-
'_blank',
|
21
8
|
'_buffering',
|
22
9
|
'_checked',
|
23
|
-
'_current',
|
24
10
|
'_default',
|
25
11
|
'_defined',
|
26
12
|
'_dir(',
|
@@ -33,8 +19,8 @@ export const pseudos = [
|
|
33
19
|
'_focus',
|
34
20
|
'_focus-visible',
|
35
21
|
'_focus-within',
|
36
|
-
'_fullscreen',
|
37
22
|
'_future',
|
23
|
+
'_has-slotted',
|
38
24
|
'_has(',
|
39
25
|
'_host',
|
40
26
|
'_host-context(',
|
@@ -49,7 +35,6 @@ export const pseudos = [
|
|
49
35
|
'_last-of-type',
|
50
36
|
'_left',
|
51
37
|
'_link',
|
52
|
-
'_local-link',
|
53
38
|
'_modal',
|
54
39
|
'_muted',
|
55
40
|
'_not(',
|
@@ -59,6 +44,7 @@ export const pseudos = [
|
|
59
44
|
'_nth-of-type(',
|
60
45
|
'_only-child',
|
61
46
|
'_only-of-type',
|
47
|
+
'_open',
|
62
48
|
'_optional',
|
63
49
|
'_out-of-range',
|
64
50
|
'_past',
|
@@ -71,45 +57,27 @@ export const pseudos = [
|
|
71
57
|
'_read-write',
|
72
58
|
'_required',
|
73
59
|
'_right',
|
60
|
+
'_root',
|
74
61
|
'_scope',
|
75
62
|
'_seeking',
|
76
63
|
'_stalled',
|
77
64
|
'_state(',
|
78
65
|
'_target',
|
79
|
-
'_target-within',
|
80
66
|
'_user-invalid',
|
81
67
|
'_user-valid',
|
82
68
|
'_valid',
|
83
69
|
'_visited',
|
84
70
|
'_volume-locked',
|
85
|
-
'_where
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
'_-moz-meter-bar',
|
91
|
-
'_-moz-progress-bar',
|
92
|
-
'_-moz-range-progress',
|
93
|
-
'_-moz-range-thumb',
|
94
|
-
'_-moz-range-track',
|
95
|
-
'_-webkit-inner-spin-button',
|
96
|
-
'_-webkit-meter-barDeprecated',
|
97
|
-
'_-webkit-meter-even-less-good-value',
|
98
|
-
'_-webkit-meter-inner-element',
|
99
|
-
'_-webkit-meter-optimum-value',
|
100
|
-
'_-webkit-meter-suboptimum-value',
|
101
|
-
'_-webkit-progress-bar',
|
102
|
-
'_-webkit-progress-inner-element',
|
103
|
-
'_-webkit-progress-value',
|
104
|
-
'_-webkit-scrollbar',
|
105
|
-
'_-webkit-search-cancel-button',
|
106
|
-
'_-webkit-search-results-button',
|
107
|
-
'_-webkit-slider-runnable-track',
|
108
|
-
'_-webkit-slider-thumb',
|
71
|
+
'_where',
|
72
|
+
] as const
|
73
|
+
|
74
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
|
75
|
+
const pseudoElements = [
|
109
76
|
'_after',
|
110
77
|
'_backdrop',
|
111
78
|
'_before',
|
112
79
|
'_cue',
|
80
|
+
'_details-content',
|
113
81
|
'_file-selector-button',
|
114
82
|
'_first-letter',
|
115
83
|
'_first-line',
|
@@ -123,15 +91,18 @@ export const pseudos = [
|
|
123
91
|
'_spelling-error',
|
124
92
|
'_target-text',
|
125
93
|
'_view-transition',
|
126
|
-
'_view-transition-group',
|
127
|
-
'_view-transition-image-pair',
|
128
|
-
'_view-transition-new',
|
129
|
-
'_view-transition-old',
|
94
|
+
'_view-transition-group(',
|
95
|
+
'_view-transition-image-pair(',
|
96
|
+
'_view-transition-new(',
|
97
|
+
'_view-transition-old(',
|
130
98
|
] as const
|
131
99
|
|
132
|
-
export const isPseudo = (selector: string) => pseudos.some(pseudo => selector.startsWith(pseudo))
|
133
|
-
|
134
100
|
type AddDynamicSelector<T extends string> = T extends `${infer U}(` ? `${U}(${string})` : T
|
135
101
|
|
136
|
-
export type Pseudo = AddDynamicSelector<typeof
|
102
|
+
export type Pseudo = AddDynamicSelector<(typeof pseudoClasses)[number] | (typeof pseudoElements)[number]>
|
103
|
+
|
104
|
+
export const isPseudoClass = (selector: string) => pseudoClasses.some(pseudo => selector.startsWith(pseudo))
|
105
|
+
|
106
|
+
export const isPseudoElement = (selector: string) => pseudoElements.some(pseudo => selector.startsWith(pseudo))
|
137
107
|
|
108
|
+
export const isPseudo = (selector: string) => isPseudoClass(selector) || isPseudoElement(selector)
|
package/src/web/convert/utils.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
// based on react-native-web normalizer
|
2
2
|
// https://github.com/necolas/react-native-web
|
3
|
+
/// <reference path="module.d.ts" />
|
3
4
|
import normalizeColors from '@react-native/normalize-colors'
|
4
5
|
import type { BoxShadowValue } from 'react-native'
|
5
6
|
import type { TransformStyles } from '../../types/core'
|
@@ -30,7 +31,7 @@ export const normalizeColor = (color: string, opacity = 1) => {
|
|
30
31
|
return color
|
31
32
|
}
|
32
33
|
|
33
|
-
const hex = integer.toString(16).padStart(8, '0')
|
34
|
+
const hex = integer.toString(16).padStart(8, '0') as string
|
34
35
|
|
35
36
|
if (hex.length === 8) {
|
36
37
|
const [r = 0, g = 0, b = 0, a = 1] = hex
|
package/src/web/create.ts
CHANGED
@@ -21,7 +21,7 @@ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, id?: s
|
|
21
21
|
__uni__key: key,
|
22
22
|
__uni__stylesheet: stylesheet,
|
23
23
|
__uni__args: args,
|
24
|
-
|
24
|
+
__stylesheetVariants: variants
|
25
25
|
})
|
26
26
|
|
27
27
|
const createStyleSheetStyles = (variants?: Variants) => {
|
package/src/web/css/core.ts
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
import { isPseudoClass } from '../convert/pseudo'
|
1
2
|
import { getMediaQuery } from '../utils'
|
2
3
|
import type { CSSState } from './state'
|
3
4
|
|
4
5
|
export const convertToCSS = (hash: string, value: Record<string, any>, state: CSSState) => {
|
5
6
|
Object.entries(value).forEach(([styleKey, styleValue]) => {
|
6
7
|
if (styleKey[0] === '_') {
|
7
|
-
const
|
8
|
+
const isStylePseudoClass = isPseudoClass(styleKey)
|
9
|
+
const pseudoClassName = `${hash}${isStylePseudoClass ? ':' : '::'}${styleKey.slice(1)}`
|
8
10
|
|
9
11
|
Object.entries(styleValue).forEach(([pseudoStyleKey, pseudoStyleValue]) => {
|
10
12
|
if (typeof pseudoStyleValue === 'object' && pseudoStyleValue !== null) {
|
@@ -34,8 +36,16 @@ export const convertToCSS = (hash: string, value: Record<string, any>, state: CS
|
|
34
36
|
}
|
35
37
|
|
36
38
|
if (typeof styleValue === 'object') {
|
37
|
-
const allBreakpoints = Object.keys(value)
|
38
39
|
Object.entries(styleValue).forEach(([breakpointStyleKey, breakpointStyleValue]) => {
|
40
|
+
const allBreakpoints = Object.entries(value)
|
41
|
+
.filter(([_, value]) => {
|
42
|
+
if (typeof value !== 'object' || value === null) {
|
43
|
+
return false
|
44
|
+
}
|
45
|
+
|
46
|
+
return breakpointStyleKey in value
|
47
|
+
})
|
48
|
+
.map(([key]) => key)
|
39
49
|
const mediaQuery = getMediaQuery(styleKey, allBreakpoints)
|
40
50
|
|
41
51
|
state.set({
|
package/src/web/css/state.ts
CHANGED
@@ -32,7 +32,7 @@ export class CSSState {
|
|
32
32
|
mainMap: MapType = new Map()
|
33
33
|
mqMap: MapType = new Map()
|
34
34
|
private styleTag: HTMLStyleElement | null = null
|
35
|
-
private
|
35
|
+
private themesCSS = new Map<string, string>()
|
36
36
|
|
37
37
|
constructor(private services: UnistylesServices) {
|
38
38
|
if (isServer()) {
|
@@ -62,7 +62,10 @@ export class CSSState {
|
|
62
62
|
|
63
63
|
add = (hash: string, values: UnistylesValues) => {
|
64
64
|
convertToCSS(hash, convertUnistyles(values, this.services.runtime), this)
|
65
|
+
this.recreate()
|
66
|
+
}
|
65
67
|
|
68
|
+
recreate = () => {
|
66
69
|
if (this.styleTag) {
|
67
70
|
this.styleTag.innerText = this.getStyles()
|
68
71
|
}
|
@@ -84,10 +87,10 @@ export class CSSState {
|
|
84
87
|
Object.entries(values).forEach(([key, value]) => convertToCSS(key, value))
|
85
88
|
|
86
89
|
if (theme === 'light' || theme === 'dark') {
|
87
|
-
this.
|
90
|
+
this.themesCSS.set(`media ${theme}`, `@media (prefers-color-scheme: ${theme}){:root{${themeVars}}}`)
|
88
91
|
}
|
89
92
|
|
90
|
-
this.
|
93
|
+
this.themesCSS.set(theme, `:root.${theme}{${themeVars}}`)
|
91
94
|
}
|
92
95
|
|
93
96
|
remove = (hash: string) => {
|
@@ -97,14 +100,13 @@ export class CSSState {
|
|
97
100
|
this.mqMap.forEach(styles => {
|
98
101
|
styles.delete(hash)
|
99
102
|
})
|
100
|
-
|
101
|
-
if (this.styleTag) {
|
102
|
-
this.styleTag.innerText = this.getStyles()
|
103
|
-
}
|
103
|
+
this.recreate()
|
104
104
|
}
|
105
105
|
|
106
106
|
getStyles = () => {
|
107
|
-
let styles = this.
|
107
|
+
let styles = Array.from(this.themesCSS.entries()).reduce((acc, [, themeCss]) => {
|
108
|
+
return acc + themeCss
|
109
|
+
}, '')
|
108
110
|
|
109
111
|
const generate = (mediaQuery: string, secondLevelMap: Map<string, Map<string, string>>) => {
|
110
112
|
if (mediaQuery) {
|
package/src/web/listener.ts
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
import { UnistyleDependency } from '../specs/NativePlatform'
|
2
2
|
import type { UnistylesServices } from './types'
|
3
3
|
|
4
|
+
type Listener = (dependency: UnistyleDependency) => void
|
5
|
+
|
4
6
|
export class UnistylesListener {
|
5
7
|
private isInitialized = false
|
6
|
-
private listeners = Array.from({ length: Object.keys(UnistyleDependency).length / 2 }, () => new Set<
|
7
|
-
private stylesheetListeners = Array.from({ length: Object.keys(UnistyleDependency).length / 2 }, () => new Set<
|
8
|
+
private listeners = Array.from({ length: Object.keys(UnistyleDependency).length / 2 }, () => new Set<Listener>())
|
9
|
+
private stylesheetListeners = Array.from({ length: Object.keys(UnistyleDependency).length / 2 }, () => new Set<Listener>())
|
8
10
|
|
9
11
|
constructor(private services: UnistylesServices) {}
|
10
12
|
|
11
13
|
emitChange = (dependency: UnistyleDependency) => {
|
12
|
-
this.stylesheetListeners[dependency]?.forEach(listener => listener())
|
13
|
-
this.listeners[dependency]?.forEach(listener => listener())
|
14
|
+
this.stylesheetListeners[dependency]?.forEach(listener => listener(dependency))
|
15
|
+
this.listeners[dependency]?.forEach(listener => listener(dependency))
|
14
16
|
}
|
15
17
|
|
16
18
|
initListeners = () => {
|
@@ -29,6 +31,7 @@ export class UnistylesListener {
|
|
29
31
|
|
30
32
|
if (this.services.runtime.hasAdaptiveThemes) {
|
31
33
|
this.emitChange(UnistyleDependency.Theme)
|
34
|
+
this.emitChange(UnistyleDependency.ThemeName)
|
32
35
|
}
|
33
36
|
})
|
34
37
|
this.services.runtime.lightMedia?.addEventListener('change', event => {
|
@@ -40,6 +43,7 @@ export class UnistylesListener {
|
|
40
43
|
|
41
44
|
if (this.services.runtime.hasAdaptiveThemes) {
|
42
45
|
this.emitChange(UnistyleDependency.Theme)
|
46
|
+
this.emitChange(UnistyleDependency.ThemeName)
|
43
47
|
}
|
44
48
|
})
|
45
49
|
|
@@ -47,7 +51,7 @@ export class UnistylesListener {
|
|
47
51
|
window.addEventListener('resize', () => this.emitChange(UnistyleDependency.Dimensions))
|
48
52
|
}
|
49
53
|
|
50
|
-
addListeners = (dependencies: Array<UnistyleDependency>, listener:
|
54
|
+
addListeners = (dependencies: Array<UnistyleDependency>, listener: Listener) => {
|
51
55
|
dependencies.forEach(dependency => this.listeners[dependency]?.add(listener))
|
52
56
|
|
53
57
|
return () => {
|
@@ -55,7 +59,7 @@ export class UnistylesListener {
|
|
55
59
|
}
|
56
60
|
}
|
57
61
|
|
58
|
-
addStylesheetListeners = (dependencies: Array<UnistyleDependency>, listener:
|
62
|
+
addStylesheetListeners = (dependencies: Array<UnistyleDependency>, listener: Listener) => {
|
59
63
|
dependencies.forEach(dependency => this.stylesheetListeners[dependency]?.add(listener))
|
60
64
|
|
61
65
|
return () => {
|
package/src/web/runtime.ts
CHANGED
@@ -4,7 +4,7 @@ import { type AppTheme, type AppThemeName, ColorScheme, Orientation } from '../s
|
|
4
4
|
import { type UnistylesTheme, WebContentSizeCategory } from '../types'
|
5
5
|
import { NavigationBar, StatusBar } from './mock'
|
6
6
|
import type { UnistylesServices } from './types'
|
7
|
-
import { error, isServer, schemeToTheme } from './utils'
|
7
|
+
import { convertTheme, error, isServer, schemeToTheme } from './utils'
|
8
8
|
|
9
9
|
export class UnistylesRuntime {
|
10
10
|
lightMedia = this.getLightMedia()
|
@@ -49,6 +49,12 @@ export class UnistylesRuntime {
|
|
49
49
|
}
|
50
50
|
|
51
51
|
get themeName() {
|
52
|
+
const scopedTheme = this.services.shadowRegistry.getScopedTheme()
|
53
|
+
|
54
|
+
if (scopedTheme) {
|
55
|
+
return scopedTheme
|
56
|
+
}
|
57
|
+
|
52
58
|
if (this.services.state.hasAdaptiveThemes) {
|
53
59
|
return schemeToTheme(this.colorScheme) as AppThemeName
|
54
60
|
}
|
@@ -76,6 +82,14 @@ export class UnistylesRuntime {
|
|
76
82
|
return screen.orientation.type.includes('portrait') ? Orientation.Portrait : Orientation.Landscape
|
77
83
|
}
|
78
84
|
|
85
|
+
get isLandscape() {
|
86
|
+
return this.orientation === Orientation.Landscape
|
87
|
+
}
|
88
|
+
|
89
|
+
get isPortrait() {
|
90
|
+
return this.orientation === Orientation.Portrait
|
91
|
+
}
|
92
|
+
|
79
93
|
get theme() {
|
80
94
|
return this.getTheme(this.themeName)
|
81
95
|
}
|
@@ -175,9 +189,14 @@ export class UnistylesRuntime {
|
|
175
189
|
}
|
176
190
|
|
177
191
|
setAdaptiveThemes = (isEnabled: boolean) => {
|
178
|
-
this.services.state.hasAdaptiveThemes
|
192
|
+
if (this.services.state.hasAdaptiveThemes === isEnabled) {
|
193
|
+
return
|
194
|
+
}
|
195
|
+
|
196
|
+
this.services.listener.emitChange(UnistyleDependency.AdaptiveThemes)
|
179
197
|
|
180
198
|
if (!isEnabled) {
|
199
|
+
this.services.state.hasAdaptiveThemes = isEnabled
|
181
200
|
this.rootElement?.classList.add(this.themeName ?? '')
|
182
201
|
|
183
202
|
return
|
@@ -185,6 +204,7 @@ export class UnistylesRuntime {
|
|
185
204
|
|
186
205
|
this.rootElement?.classList.remove(this.themeName ?? '')
|
187
206
|
this.setTheme(schemeToTheme(this.colorScheme) as AppThemeName)
|
207
|
+
this.services.state.hasAdaptiveThemes = isEnabled
|
188
208
|
}
|
189
209
|
|
190
210
|
setRootViewBackgroundColor = (color: string) => {
|
@@ -204,7 +224,21 @@ export class UnistylesRuntime {
|
|
204
224
|
throw error(`Unistyles: You're trying to update theme "${themeName}" but it wasn't registered.`)
|
205
225
|
}
|
206
226
|
|
207
|
-
|
227
|
+
const newTheme = updater(oldTheme)
|
228
|
+
|
229
|
+
this.services.state.themes.set(themeName, newTheme)
|
230
|
+
this.services.listener.emitChange(UnistyleDependency.Theme)
|
231
|
+
|
232
|
+
if (this.services.state.CSSVars) {
|
233
|
+
this.services.state.cssThemes.set(
|
234
|
+
themeName,
|
235
|
+
Object.fromEntries(Object.entries(newTheme).map(([key, value]) => {
|
236
|
+
return convertTheme(key, value)
|
237
|
+
})) as UnistylesTheme
|
238
|
+
)
|
239
|
+
this.services.registry.css.addTheme(themeName, newTheme)
|
240
|
+
this.services.registry.css.recreate()
|
241
|
+
}
|
208
242
|
}
|
209
243
|
|
210
244
|
getTheme = (themeName = this.themeName, CSSVars = false) => {
|
@@ -20,7 +20,7 @@ export class UnistylesShadowRegistry {
|
|
20
20
|
constructor(private services: UnistylesServices) {}
|
21
21
|
|
22
22
|
add = (ref: any, hash?: string) => {
|
23
|
-
if (!(ref instanceof HTMLElement) || !hash) {
|
23
|
+
if (isServer() || !(ref instanceof HTMLElement) || !hash) {
|
24
24
|
return
|
25
25
|
}
|
26
26
|
|
@@ -49,7 +49,7 @@ export class UnistylesShadowRegistry {
|
|
49
49
|
return {}
|
50
50
|
}
|
51
51
|
|
52
|
-
const { __uni__key, __uni__stylesheet, __uni__args = [],
|
52
|
+
const { __uni__key, __uni__stylesheet, __uni__args = [], __stylesheetVariants: variants } = secrets
|
53
53
|
const newComputedStylesheet = this.services.registry.getComputedStylesheet(__uni__stylesheet, scopedTheme)
|
54
54
|
const style = newComputedStylesheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
|
55
55
|
const result = typeof style === 'function'
|
@@ -94,7 +94,7 @@ export class UnistylesShadowRegistry {
|
|
94
94
|
? hash.replace(' > *', '')
|
95
95
|
: hash
|
96
96
|
|
97
|
-
return { injectedClassName, hash: hashClassname }
|
97
|
+
return { injectedClassName, hash: hashClassname, parsedStyles }
|
98
98
|
}
|
99
99
|
|
100
100
|
setScopedTheme = (theme?: UnistylesTheme) => {
|
@@ -118,4 +118,6 @@ export class UnistylesShadowRegistry {
|
|
118
118
|
this.disposeMap.delete(hash)
|
119
119
|
})
|
120
120
|
}
|
121
|
+
|
122
|
+
flush = () => {}
|
121
123
|
}
|
package/src/web/state.ts
CHANGED
@@ -5,7 +5,7 @@ import type { AppBreakpoint, AppTheme, AppThemeName } from '../specs/types'
|
|
5
5
|
import type { UnistylesTheme } from '../types'
|
6
6
|
import type { UnionToIntersection } from '../types'
|
7
7
|
import type { UnistylesServices } from './types'
|
8
|
-
import {
|
8
|
+
import { convertTheme, error, isServer, schemeToTheme } from './utils'
|
9
9
|
|
10
10
|
type UnistylesSettings = Partial<UnionToIntersection<Required<UnistylesConfig>['settings']>>
|
11
11
|
|
@@ -72,22 +72,12 @@ export class UnistylesState {
|
|
72
72
|
|
73
73
|
if (CSSVars) {
|
74
74
|
this.services.registry.css.addTheme(themeName, theme)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
return
|
79
|
-
}
|
80
|
-
|
81
|
-
if (typeof value === 'string') {
|
82
|
-
return [key, `var(${prev}-${hyphenate(key)})`]
|
83
|
-
}
|
84
|
-
|
85
|
-
return [key, value]
|
86
|
-
}
|
87
|
-
|
88
|
-
this.cssThemes.set(themeName, Object.fromEntries(Object.entries(theme).map(([key, value]) => {
|
89
|
-
return convertTheme(key, value)
|
90
|
-
})) as UnistylesTheme)
|
75
|
+
this.cssThemes.set(
|
76
|
+
themeName,
|
77
|
+
Object.fromEntries(Object.entries(theme).map(([key, value]) => {
|
78
|
+
return convertTheme(key, value)
|
79
|
+
})) as UnistylesTheme
|
80
|
+
)
|
91
81
|
}
|
92
82
|
})
|
93
83
|
}
|
package/src/web/types.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import type { UnistylesValues } from '../types'
|
1
2
|
import type { UnistylesListener } from './listener'
|
2
3
|
import type { UnistylesRegistry } from './registry'
|
3
4
|
import type { UnistylesRuntime } from './runtime'
|
@@ -15,4 +16,6 @@ export type UnistylesServices = {
|
|
15
16
|
export const UNI_GENERATED_KEYS = ['$$css', 'hash', 'injectedClassName'] as const
|
16
17
|
export type UniGeneratedKey = typeof UNI_GENERATED_KEYS[number]
|
17
18
|
|
18
|
-
export type UniGeneratedStyle = Record<UniGeneratedKey, string>
|
19
|
+
export type UniGeneratedStyle = Record<UniGeneratedKey, string> & {
|
20
|
+
parsedStyles?: UnistylesValues
|
21
|
+
}
|
@@ -3,10 +3,11 @@ import type { UnistylesBreakpoints } from '../../global'
|
|
3
3
|
import type { UnistyleDependency } from '../../specs/NativePlatform/NativePlatform.nitro'
|
4
4
|
import { ColorScheme, Orientation } from '../../specs/types'
|
5
5
|
import type { StyleSheet, StyleSheetWithSuperPowers, UnistylesValues } from '../../types/stylesheet'
|
6
|
-
import { isUnistylesMq, parseMq } from '../../utils'
|
6
|
+
import { isDefined, isUnistylesMq, parseMq } from '../../utils'
|
7
|
+
import type { UnistylesRuntime } from '../runtime'
|
7
8
|
import * as unistyles from '../services'
|
8
9
|
import { UNI_GENERATED_KEYS, type UniGeneratedKey, type UniGeneratedStyle } from '../types'
|
9
|
-
import { keyInObject, reduceObject } from './common'
|
10
|
+
import { hyphenate, keyInObject, reduceObject } from './common'
|
10
11
|
|
11
12
|
export const schemeToTheme = (scheme: ColorScheme) => {
|
12
13
|
switch (scheme) {
|
@@ -22,7 +23,7 @@ export type UnistyleSecrets = {
|
|
22
23
|
__uni__stylesheet: StyleSheetWithSuperPowers<StyleSheet>,
|
23
24
|
__uni__key: string,
|
24
25
|
__uni__args?: Array<any>,
|
25
|
-
|
26
|
+
__stylesheetVariants: Record<string, string | boolean | undefined>
|
26
27
|
}
|
27
28
|
|
28
29
|
export const assignSecrets = <T>(object: T, secrets: UnistyleSecrets) => {
|
@@ -142,5 +143,34 @@ export const checkForAnimated = (value: any): boolean => {
|
|
142
143
|
}
|
143
144
|
|
144
145
|
export const isGeneratedUnistyle = (value: Record<string, any>): value is UniGeneratedStyle => {
|
145
|
-
|
146
|
+
const keys = Object.keys(value)
|
147
|
+
|
148
|
+
return keys.length > 0 && keys.every(key => UNI_GENERATED_KEYS.includes(key as UniGeneratedKey))
|
149
|
+
}
|
150
|
+
|
151
|
+
export const convertTheme = (key: string, value: any, prev = '-'): [string, any] => {
|
152
|
+
if (typeof value === 'object' && value !== null) {
|
153
|
+
return [key, Object.fromEntries(Object.entries(value).map(([nestedKey, nestedValue]) => convertTheme(nestedKey, nestedValue, `${prev}-${key}`)))]
|
154
|
+
}
|
155
|
+
|
156
|
+
if (typeof value === 'string') {
|
157
|
+
return [key, `var(${prev}-${hyphenate(key)})`]
|
158
|
+
}
|
159
|
+
|
160
|
+
return [key, value]
|
161
|
+
}
|
162
|
+
|
163
|
+
export const getClosestBreakpointValue = <T>(runtime: UnistylesRuntime, values: Partial<Record<keyof UnistylesBreakpoints, T>>) => {
|
164
|
+
const breakpoints = runtime.breakpoints
|
165
|
+
const breakpointValues = Object.entries(values)
|
166
|
+
// Filter out non-breakpoint values
|
167
|
+
.filter((pair): pair is [keyof UnistylesBreakpoints, T] => pair[0] in breakpoints)
|
168
|
+
// Sort in descending order
|
169
|
+
.sort(([a], [b]) => (breakpoints[b] ?? 0) - (breakpoints[a] ?? 0))
|
170
|
+
// Get breakpoint value with highest priority
|
171
|
+
const [_, currentBreakpointValue] = breakpointValues.find(
|
172
|
+
([key]) => isDefined(runtime.breakpoint) && (breakpoints[key] ?? 0) <= (breakpoints[runtime.breakpoint] ?? 0)
|
173
|
+
) ?? []
|
174
|
+
|
175
|
+
return currentBreakpointValue
|
146
176
|
}
|
@@ -1,59 +0,0 @@
|
|
1
|
-
#include "UnistylesCommitHook.h"
|
2
|
-
|
3
|
-
using namespace margelo::nitro::unistyles;
|
4
|
-
using namespace facebook::react;
|
5
|
-
|
6
|
-
core::UnistylesCommitHook::~UnistylesCommitHook() noexcept {
|
7
|
-
_uiManager->unregisterCommitHook(*this);
|
8
|
-
}
|
9
|
-
|
10
|
-
void core::UnistylesCommitHook::commitHookWasRegistered(const UIManager &uiManager) noexcept {}
|
11
|
-
void core::UnistylesCommitHook::commitHookWasUnregistered(const UIManager &uiManager) noexcept {}
|
12
|
-
|
13
|
-
RootShadowNode::Unshared core::UnistylesCommitHook::shadowTreeWillCommit(
|
14
|
-
const ShadowTree &shadowTree,
|
15
|
-
const RootShadowNode::Shared &oldRootShadowNode,
|
16
|
-
const RootShadowNode::Unshared &newRootShadowNode
|
17
|
-
) noexcept {
|
18
|
-
RootShadowNode::Unshared rootNode = newRootShadowNode;
|
19
|
-
auto unistylesRootNode = std::reinterpret_pointer_cast<core::UnistylesCommitShadowNode>(newRootShadowNode);
|
20
|
-
|
21
|
-
// this is Unistyles commit, we don't need to override it
|
22
|
-
if (unistylesRootNode->hasUnistylesCommitTrait()) {
|
23
|
-
unistylesRootNode->removeUnistylesCommitTrait();
|
24
|
-
unistylesRootNode->addUnistylesMountTrait();
|
25
|
-
|
26
|
-
return newRootShadowNode;
|
27
|
-
}
|
28
|
-
|
29
|
-
auto& registry = core::UnistylesRegistry::get();
|
30
|
-
|
31
|
-
if (registry.trafficController.shouldStop()) {
|
32
|
-
registry.trafficController.resumeUnistylesTraffic();
|
33
|
-
|
34
|
-
return newRootShadowNode;
|
35
|
-
}
|
36
|
-
|
37
|
-
// this is React Native / Reanimated commit
|
38
|
-
// merge Unistyles updates before it completes
|
39
|
-
|
40
|
-
return registry.trafficController.withLock([&](){
|
41
|
-
auto& shadowLeafUpdates = registry.trafficController.getUpdates();
|
42
|
-
|
43
|
-
// oops, no updates from Unistyles yet, skip it!
|
44
|
-
if (shadowLeafUpdates.size() == 0) {
|
45
|
-
return newRootShadowNode;
|
46
|
-
}
|
47
|
-
|
48
|
-
auto affectedNodes = shadow::ShadowTreeManager::findAffectedNodes(*rootNode, shadowLeafUpdates);
|
49
|
-
|
50
|
-
registry.trafficController.stopUnistylesTraffic();
|
51
|
-
|
52
|
-
// we have few updates, so merge it
|
53
|
-
return std::static_pointer_cast<RootShadowNode>(shadow::ShadowTreeManager::cloneShadowTree(
|
54
|
-
*rootNode,
|
55
|
-
shadowLeafUpdates,
|
56
|
-
affectedNodes
|
57
|
-
));
|
58
|
-
});
|
59
|
-
}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
#pragma once
|
2
|
-
|
3
|
-
#include <react/renderer/uimanager/UIManager.h>
|
4
|
-
#include <react/renderer/uimanager/UIManagerCommitHook.h>
|
5
|
-
#include "ShadowTreeManager.h"
|
6
|
-
#include "ShadowTrafficController.h"
|
7
|
-
|
8
|
-
namespace margelo::nitro::unistyles::core {
|
9
|
-
|
10
|
-
using namespace facebook::react;
|
11
|
-
|
12
|
-
struct UnistylesCommitHook : public UIManagerCommitHook {
|
13
|
-
UnistylesCommitHook(std::shared_ptr<UIManager> uiManager) : _uiManager{uiManager} {
|
14
|
-
_uiManager->registerCommitHook(*this);
|
15
|
-
}
|
16
|
-
|
17
|
-
~UnistylesCommitHook() noexcept override;
|
18
|
-
|
19
|
-
void commitHookWasRegistered(const UIManager &uiManager) noexcept override;
|
20
|
-
void commitHookWasUnregistered(const UIManager &uiManager) noexcept override;
|
21
|
-
RootShadowNode::Unshared shadowTreeWillCommit(const ShadowTree &shadowTree, const RootShadowNode::Shared &oldRootShadowNode, const RootShadowNode::Unshared &newRootShadowNode) noexcept override;
|
22
|
-
|
23
|
-
private:
|
24
|
-
std::shared_ptr<UIManager> _uiManager;
|
25
|
-
};
|
26
|
-
|
27
|
-
}
|