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/plugin/exotic.js
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
function handleExoticImport(t, path, state, exoticImport) {
|
2
|
-
const specifiers = path.node.specifiers
|
3
|
-
const source = path.node.source
|
4
|
-
|
5
|
-
if (path.node.importKind !== 'value') {
|
6
|
-
return
|
7
|
-
}
|
8
|
-
|
9
|
-
specifiers.forEach(specifier => {
|
10
|
-
for (const rule of exoticImport.imports) {
|
11
|
-
const hasMatchingImportType = (!rule.isDefault && t.isImportSpecifier(specifier)) || (rule.isDefault && t.isImportDefaultSpecifier(specifier))
|
12
|
-
const hasMatchingImportName = rule.isDefault || (!rule.isDefault && rule.name === specifier.local.name)
|
13
|
-
const hasMatchingPath = rule.path === source.value
|
14
|
-
|
15
|
-
if (!hasMatchingImportType || !hasMatchingImportName || !hasMatchingPath) {
|
16
|
-
continue
|
17
|
-
}
|
18
|
-
|
19
|
-
if (t.isImportDefaultSpecifier(specifier)) {
|
20
|
-
const newImport = t.importDeclaration(
|
21
|
-
[t.importDefaultSpecifier(t.identifier(specifier.local.name))],
|
22
|
-
t.stringLiteral(state.opts.isLocal
|
23
|
-
? state.file.opts.filename.split('react-native-unistyles').at(0).concat(`react-native-unistyles/components/native/${rule.mapTo}`)
|
24
|
-
: `react-native-unistyles/components/native/${rule.mapTo}`
|
25
|
-
)
|
26
|
-
)
|
27
|
-
|
28
|
-
path.replaceWith(newImport)
|
29
|
-
} else {
|
30
|
-
const newImport = t.importDeclaration(
|
31
|
-
[t.importSpecifier(t.identifier(rule.mapTo), t.identifier(rule.mapTo))],
|
32
|
-
t.stringLiteral(state.opts.isLocal
|
33
|
-
? state.file.opts.filename.split('react-native-unistyles').at(0).concat(`react-native-unistyles/components/native/${rule.mapTo}`)
|
34
|
-
: `react-native-unistyles/components/native/${rule.mapTo}`
|
35
|
-
)
|
36
|
-
)
|
37
|
-
|
38
|
-
path.node.specifiers = specifiers.filter(s => s !== specifier)
|
39
|
-
|
40
|
-
if (path.node.specifiers.length === 0) {
|
41
|
-
path.replaceWith(newImport)
|
42
|
-
} else {
|
43
|
-
path.insertBefore(newImport)
|
44
|
-
}
|
45
|
-
}
|
46
|
-
|
47
|
-
return
|
48
|
-
}
|
49
|
-
})
|
50
|
-
}
|
51
|
-
|
52
|
-
module.exports = {
|
53
|
-
handleExoticImport
|
54
|
-
}
|
package/plugin/import.js
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
/** @param {import('./index').UnistylesPluginPass} state */
|
2
|
-
function addUnistylesImport(t, path, state) {
|
3
|
-
const localNames = Object.keys(state.reactNativeImports)
|
4
|
-
const names = Object.values(state.reactNativeImports)
|
5
|
-
const pairs = Object.entries(state.reactNativeImports)
|
6
|
-
const nodesToRemove = []
|
7
|
-
|
8
|
-
// remove rn-imports
|
9
|
-
path.node.body.forEach(node => {
|
10
|
-
// user might have multiple imports like import type, import
|
11
|
-
if (t.isImportDeclaration(node) && node.source.value === 'react-native') {
|
12
|
-
node.specifiers = node.specifiers.filter(specifier => !localNames.some(name => name === specifier.local.name))
|
13
|
-
|
14
|
-
if (node.specifiers.length === 0) {
|
15
|
-
nodesToRemove.push(node)
|
16
|
-
}
|
17
|
-
}
|
18
|
-
})
|
19
|
-
|
20
|
-
// remove RNWeb imports
|
21
|
-
names.forEach(name => {
|
22
|
-
const rnWebImport = path.node.body.find(node => t.isImportDeclaration(node) && node.source.value === `react-native-web/dist/exports/${name}`)
|
23
|
-
|
24
|
-
if (rnWebImport) {
|
25
|
-
rnWebImport.specifiers = []
|
26
|
-
}
|
27
|
-
})
|
28
|
-
|
29
|
-
// import components from react-native-unistyles
|
30
|
-
pairs.forEach(([localName, name]) => {
|
31
|
-
const newImport = t.importDeclaration(
|
32
|
-
[t.importSpecifier(t.identifier(localName), t.identifier(name))],
|
33
|
-
t.stringLiteral(state.opts.isLocal
|
34
|
-
? state.file.opts.filename.split('react-native-unistyles').at(0).concat(`react-native-unistyles/src/components/native/${name}`)
|
35
|
-
: `react-native-unistyles/components/native/${name}`
|
36
|
-
)
|
37
|
-
)
|
38
|
-
|
39
|
-
path.node.body.unshift(newImport)
|
40
|
-
})
|
41
|
-
|
42
|
-
// cleanup
|
43
|
-
nodesToRemove.forEach(node => path.node.body.splice(path.node.body.indexOf(node), 1))
|
44
|
-
}
|
45
|
-
|
46
|
-
const isInsideNodeModules = state => state.file.opts.filename.includes('node_modules')
|
47
|
-
|
48
|
-
module.exports = {
|
49
|
-
isInsideNodeModules,
|
50
|
-
addUnistylesImport
|
51
|
-
}
|
package/plugin/ref.js
DELETED
package/plugin/stylesheet.js
DELETED
@@ -1,565 +0,0 @@
|
|
1
|
-
const UnistyleDependency = {
|
2
|
-
Theme: 0,
|
3
|
-
ThemeName: 1,
|
4
|
-
AdaptiveThemes: 2,
|
5
|
-
Breakpoints: 3,
|
6
|
-
Variants: 4,
|
7
|
-
ColorScheme: 5,
|
8
|
-
Dimensions: 6,
|
9
|
-
Orientation: 7,
|
10
|
-
ContentSizeCategory: 8,
|
11
|
-
Insets: 9,
|
12
|
-
PixelRatio: 10,
|
13
|
-
FontScale: 11,
|
14
|
-
StatusBar: 12,
|
15
|
-
NavigationBar: 13,
|
16
|
-
Ime: 14
|
17
|
-
}
|
18
|
-
|
19
|
-
function stringToUniqueId(str) {
|
20
|
-
let hash = 0
|
21
|
-
|
22
|
-
for (let i = 0; i < str.length; i++) {
|
23
|
-
hash = (hash << 5) - hash + str.charCodeAt(i)
|
24
|
-
hash |= 0
|
25
|
-
}
|
26
|
-
|
27
|
-
const absHash = Math.abs(hash)
|
28
|
-
|
29
|
-
return absHash % 1000000000
|
30
|
-
}
|
31
|
-
|
32
|
-
function isUnistylesStyleSheet(t, path, state) {
|
33
|
-
const callee = path.get('callee')
|
34
|
-
|
35
|
-
return (
|
36
|
-
t.isMemberExpression(callee.node) &&
|
37
|
-
callee.node.property.name === 'create' &&
|
38
|
-
t.isIdentifier(callee.node.object) &&
|
39
|
-
callee.node.object.name === state.file.styleSheetLocalName
|
40
|
-
)
|
41
|
-
}
|
42
|
-
|
43
|
-
function isKindOfStyleSheet(t, path, state) {
|
44
|
-
if (!state.file.forceProcessing && !state.file.hasUnistylesImport) {
|
45
|
-
return false
|
46
|
-
}
|
47
|
-
|
48
|
-
const callee = path.get('callee')
|
49
|
-
|
50
|
-
return (
|
51
|
-
t.isMemberExpression(callee.node) &&
|
52
|
-
callee.node.property.name === 'create' &&
|
53
|
-
t.isIdentifier(callee.node.object)
|
54
|
-
)
|
55
|
-
}
|
56
|
-
|
57
|
-
function addStyleSheetTag(t, path, state) {
|
58
|
-
const callee = path.get('callee')
|
59
|
-
const uniqueId = stringToUniqueId(state.filename.replace(state.cwd, '')) + ++state.file.tagNumber
|
60
|
-
|
61
|
-
callee.container.arguments.push(t.numericLiteral(uniqueId))
|
62
|
-
}
|
63
|
-
|
64
|
-
const getProperty = (t, property) => {
|
65
|
-
if (!property) {
|
66
|
-
return undefined
|
67
|
-
}
|
68
|
-
|
69
|
-
if (t.isIdentifier(property)) {
|
70
|
-
return {
|
71
|
-
properties: [property.name]
|
72
|
-
}
|
73
|
-
}
|
74
|
-
|
75
|
-
if (t.isObjectPattern(property)) {
|
76
|
-
const matchingProperties = property.properties.flatMap(p => getProperty(t, p))
|
77
|
-
|
78
|
-
return {
|
79
|
-
properties: matchingProperties.flatMap(properties => properties.properties)
|
80
|
-
}
|
81
|
-
}
|
82
|
-
|
83
|
-
if (t.isObjectProperty(property) && t.isIdentifier(property.value)) {
|
84
|
-
return {
|
85
|
-
properties: [property.key.name]
|
86
|
-
}
|
87
|
-
}
|
88
|
-
|
89
|
-
if (t.isObjectProperty(property) && t.isObjectPattern(property.value)) {
|
90
|
-
const matchingProperties = property.value.properties.flatMap(p => getProperty(t, p))
|
91
|
-
|
92
|
-
return {
|
93
|
-
parent: property.key.name,
|
94
|
-
properties: matchingProperties.flatMap(properties => properties.properties)
|
95
|
-
}
|
96
|
-
}
|
97
|
-
|
98
|
-
return undefined
|
99
|
-
}
|
100
|
-
|
101
|
-
function getStylesDependenciesFromObject(t, path) {
|
102
|
-
const detectedStylesWithVariants = new Set()
|
103
|
-
const stylesheet = path.node.arguments[0]
|
104
|
-
|
105
|
-
stylesheet.properties.forEach(property => {
|
106
|
-
if (!t.isIdentifier(property.key)) {
|
107
|
-
return
|
108
|
-
}
|
109
|
-
|
110
|
-
if (t.isObjectProperty(property)) {
|
111
|
-
if(t.isObjectExpression(property.value)) {
|
112
|
-
property.value.properties.forEach(innerProp => {
|
113
|
-
if (t.isIdentifier(innerProp.key) && innerProp.key.name === 'variants') {
|
114
|
-
detectedStylesWithVariants.add({
|
115
|
-
label: 'variants',
|
116
|
-
key: property.key.name
|
117
|
-
})
|
118
|
-
}
|
119
|
-
})
|
120
|
-
|
121
|
-
}
|
122
|
-
}
|
123
|
-
|
124
|
-
if (t.isArrowFunctionExpression(property.value)) {
|
125
|
-
if(t.isObjectExpression(property.value.body)) {
|
126
|
-
property.value.body.properties.forEach(innerProp => {
|
127
|
-
if (t.isIdentifier(innerProp.key) && innerProp.key.name === 'variants') {
|
128
|
-
detectedStylesWithVariants.add({
|
129
|
-
label: 'variants',
|
130
|
-
key: property.key.name
|
131
|
-
})
|
132
|
-
}
|
133
|
-
})
|
134
|
-
|
135
|
-
}
|
136
|
-
}
|
137
|
-
})
|
138
|
-
|
139
|
-
const variants = Array.from(detectedStylesWithVariants)
|
140
|
-
|
141
|
-
return variants.reduce((acc, { key, label }) => {
|
142
|
-
if (acc[key]) {
|
143
|
-
return {
|
144
|
-
...acc,
|
145
|
-
[key]: [
|
146
|
-
...acc[key],
|
147
|
-
label
|
148
|
-
]
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
|
-
return {
|
153
|
-
...acc,
|
154
|
-
[key]: [label]
|
155
|
-
}
|
156
|
-
}, {})
|
157
|
-
}
|
158
|
-
|
159
|
-
function getStylesDependenciesFromFunction(t, path) {
|
160
|
-
const funcPath = path.get('arguments.0')
|
161
|
-
|
162
|
-
if (!funcPath) {
|
163
|
-
return
|
164
|
-
}
|
165
|
-
|
166
|
-
const params = funcPath.node.params
|
167
|
-
const [themeParam, rtParam] = params
|
168
|
-
|
169
|
-
let themeNames = []
|
170
|
-
|
171
|
-
// destructured theme object
|
172
|
-
if (themeParam && themeParam.type === 'ObjectPattern') {
|
173
|
-
// If destructured, collect all property names
|
174
|
-
for (const prop of themeParam.properties) {
|
175
|
-
themeNames.push(getProperty(t, prop))
|
176
|
-
}
|
177
|
-
}
|
178
|
-
|
179
|
-
// user used 'theme' without destructuring
|
180
|
-
if (themeParam && themeParam.type === 'Identifier') {
|
181
|
-
themeNames.push({
|
182
|
-
properties: [themeParam.name]
|
183
|
-
})
|
184
|
-
}
|
185
|
-
|
186
|
-
let rtNames = []
|
187
|
-
|
188
|
-
// destructured rt object
|
189
|
-
if (rtParam && rtParam.type === 'ObjectPattern') {
|
190
|
-
// If destructured, collect all property names
|
191
|
-
for (const prop of rtParam.properties) {
|
192
|
-
rtNames.push(getProperty(t, prop))
|
193
|
-
}
|
194
|
-
}
|
195
|
-
|
196
|
-
// user used 'rt' without destructuring
|
197
|
-
if (rtParam && rtParam.type === 'Identifier') {
|
198
|
-
rtNames.push({
|
199
|
-
properties: [rtParam.name]
|
200
|
-
})
|
201
|
-
}
|
202
|
-
|
203
|
-
// get returned object or return statement from StyleSheet.create function
|
204
|
-
let returnedObjectPath = null
|
205
|
-
|
206
|
-
if (funcPath.get('body').isObjectExpression()) {
|
207
|
-
returnedObjectPath = funcPath.get('body')
|
208
|
-
} else {
|
209
|
-
funcPath.traverse({
|
210
|
-
ReturnStatement(retPath) {
|
211
|
-
if (!returnedObjectPath && retPath.get('argument').isObjectExpression()) {
|
212
|
-
returnedObjectPath = retPath.get('argument')
|
213
|
-
}
|
214
|
-
}
|
215
|
-
})
|
216
|
-
}
|
217
|
-
|
218
|
-
if (!returnedObjectPath) {
|
219
|
-
// there is no returned object
|
220
|
-
// abort
|
221
|
-
|
222
|
-
return
|
223
|
-
}
|
224
|
-
|
225
|
-
const detectedStylesWithVariants = new Set()
|
226
|
-
|
227
|
-
// detect variants via Scope
|
228
|
-
returnedObjectPath.get('properties').forEach(propPath => {
|
229
|
-
// get style name
|
230
|
-
const stylePath = propPath.get('key')
|
231
|
-
|
232
|
-
if (!stylePath.isIdentifier()) {
|
233
|
-
return
|
234
|
-
}
|
235
|
-
|
236
|
-
const styleKey = stylePath.node.name
|
237
|
-
|
238
|
-
const valuePath = propPath.get('value')
|
239
|
-
|
240
|
-
if (valuePath.isObjectExpression()) {
|
241
|
-
const hasVariants = valuePath.get('properties').some(innerProp => {
|
242
|
-
const innerKey = innerProp.get('key')
|
243
|
-
|
244
|
-
return innerKey.isIdentifier() && innerKey.node.name === 'variants'
|
245
|
-
})
|
246
|
-
|
247
|
-
if (hasVariants) {
|
248
|
-
detectedStylesWithVariants.add({
|
249
|
-
label: 'variants',
|
250
|
-
key: styleKey
|
251
|
-
})
|
252
|
-
}
|
253
|
-
}
|
254
|
-
|
255
|
-
if (valuePath.isArrowFunctionExpression()) {
|
256
|
-
if(t.isObjectExpression(valuePath.node.body)) {
|
257
|
-
const hasVariants = valuePath.node.body.properties.some(innerProp => {
|
258
|
-
|
259
|
-
return t.isIdentifier(innerProp.key) && innerProp.key.name === 'variants'
|
260
|
-
})
|
261
|
-
|
262
|
-
if (hasVariants) {
|
263
|
-
detectedStylesWithVariants.add({
|
264
|
-
label: 'variants',
|
265
|
-
key: styleKey
|
266
|
-
})
|
267
|
-
}
|
268
|
-
}
|
269
|
-
}
|
270
|
-
})
|
271
|
-
|
272
|
-
const detectedStylesWithTheme = new Set()
|
273
|
-
|
274
|
-
// detect theme dependencies via Scope
|
275
|
-
themeNames.forEach(({ properties }) => {
|
276
|
-
properties.forEach(property => {
|
277
|
-
const binding = funcPath.scope.getBinding(property)
|
278
|
-
|
279
|
-
if (!binding) {
|
280
|
-
return
|
281
|
-
}
|
282
|
-
|
283
|
-
binding.referencePaths.forEach(refPath => {
|
284
|
-
// find key of the style that we are referring to
|
285
|
-
const containerProp = refPath
|
286
|
-
.findParent(parent => parent.isObjectProperty() && parent.parentPath === returnedObjectPath)
|
287
|
-
|
288
|
-
if (!containerProp) {
|
289
|
-
return
|
290
|
-
}
|
291
|
-
|
292
|
-
const keyNode = containerProp.get('key')
|
293
|
-
const styleKey = keyNode.isIdentifier()
|
294
|
-
? keyNode.node.name
|
295
|
-
: keyNode.isLiteral()
|
296
|
-
? keyNode.node.value
|
297
|
-
: null
|
298
|
-
|
299
|
-
if (styleKey) {
|
300
|
-
detectedStylesWithTheme.add({
|
301
|
-
label: 'theme',
|
302
|
-
key: styleKey
|
303
|
-
})
|
304
|
-
}
|
305
|
-
})
|
306
|
-
})
|
307
|
-
})
|
308
|
-
|
309
|
-
const detectedStylesWithRt = new Set()
|
310
|
-
const localRtName = t.isIdentifier(rtParam)
|
311
|
-
? rtParam.name
|
312
|
-
: undefined
|
313
|
-
|
314
|
-
// detect rt dependencies via Scope
|
315
|
-
rtNames.forEach(({ properties, parent }) => {
|
316
|
-
properties.forEach(property => {
|
317
|
-
const rtBinding = funcPath.scope.getBinding(property)
|
318
|
-
|
319
|
-
if (!rtBinding) {
|
320
|
-
return
|
321
|
-
}
|
322
|
-
|
323
|
-
const isValidDependency = Boolean(toUnistylesDependency(property))
|
324
|
-
|
325
|
-
let validRtName = property
|
326
|
-
|
327
|
-
// user used nested destructing, find out parent key
|
328
|
-
if (!isValidDependency && (!localRtName || (localRtName && localRtName !== property))) {
|
329
|
-
if (!parent) {
|
330
|
-
return
|
331
|
-
}
|
332
|
-
|
333
|
-
if (!Boolean(toUnistylesDependency(parent))) {
|
334
|
-
return
|
335
|
-
}
|
336
|
-
|
337
|
-
validRtName = parent
|
338
|
-
}
|
339
|
-
|
340
|
-
rtBinding.referencePaths.forEach(refPath => {
|
341
|
-
// to detect rt dependencies we need to get parameter not rt itself
|
342
|
-
// eg. rt.screen.width -> screen
|
343
|
-
// rt.insets.top -> insets
|
344
|
-
// special case: rt.insets.ime -> ime
|
345
|
-
|
346
|
-
let usedLabel = validRtName
|
347
|
-
|
348
|
-
if (refPath.parentPath.isMemberExpression() && refPath.parentPath.get('object') === refPath) {
|
349
|
-
const memberExpr = refPath.parentPath
|
350
|
-
const propPath = memberExpr.get('property')
|
351
|
-
|
352
|
-
if (propPath.isIdentifier()) {
|
353
|
-
if (localRtName) {
|
354
|
-
usedLabel = propPath.node.name
|
355
|
-
}
|
356
|
-
|
357
|
-
if (
|
358
|
-
usedLabel === 'insets' &&
|
359
|
-
memberExpr.parentPath.isMemberExpression() &&
|
360
|
-
memberExpr.parentPath.get('object') === memberExpr
|
361
|
-
) {
|
362
|
-
const secondPropPath = memberExpr.parentPath.get('property')
|
363
|
-
|
364
|
-
if (secondPropPath.isIdentifier() && secondPropPath.node.name === 'ime') {
|
365
|
-
usedLabel = 'ime'
|
366
|
-
}
|
367
|
-
}
|
368
|
-
}
|
369
|
-
}
|
370
|
-
|
371
|
-
// find key of the style that we are referring to
|
372
|
-
const containerProp = refPath
|
373
|
-
.findParent(parent => parent.isObjectProperty() && parent.parentPath === returnedObjectPath)
|
374
|
-
|
375
|
-
if (!containerProp) {
|
376
|
-
return
|
377
|
-
}
|
378
|
-
|
379
|
-
const keyNode = containerProp.get('key')
|
380
|
-
const styleKey = keyNode.isIdentifier()
|
381
|
-
? keyNode.node.name
|
382
|
-
: keyNode.isLiteral()
|
383
|
-
? keyNode.node.value
|
384
|
-
: null
|
385
|
-
|
386
|
-
if (styleKey) {
|
387
|
-
detectedStylesWithRt.add({
|
388
|
-
label: usedLabel,
|
389
|
-
key: styleKey
|
390
|
-
})
|
391
|
-
}
|
392
|
-
})
|
393
|
-
})
|
394
|
-
})
|
395
|
-
|
396
|
-
const variants = Array.from(detectedStylesWithVariants)
|
397
|
-
const theme = Array.from(detectedStylesWithTheme)
|
398
|
-
const rt = Array.from(detectedStylesWithRt)
|
399
|
-
|
400
|
-
return theme
|
401
|
-
.concat(rt)
|
402
|
-
.concat(variants)
|
403
|
-
.reduce((acc, { key, label }) => {
|
404
|
-
if (acc[key]) {
|
405
|
-
return {
|
406
|
-
...acc,
|
407
|
-
[key]: [
|
408
|
-
...acc[key],
|
409
|
-
label
|
410
|
-
]
|
411
|
-
}
|
412
|
-
}
|
413
|
-
|
414
|
-
return {
|
415
|
-
...acc,
|
416
|
-
[key]: [label]
|
417
|
-
}
|
418
|
-
}, {})
|
419
|
-
}
|
420
|
-
|
421
|
-
function toUnistylesDependency(dependency) {
|
422
|
-
switch (dependency) {
|
423
|
-
case 'theme': {
|
424
|
-
return UnistyleDependency.Theme
|
425
|
-
}
|
426
|
-
case 'themeName': {
|
427
|
-
return UnistyleDependency.ThemeName
|
428
|
-
}
|
429
|
-
case 'adaptiveThemes': {
|
430
|
-
return UnistyleDependency.AdaptiveThemes
|
431
|
-
}
|
432
|
-
case 'breakpoint': {
|
433
|
-
return UnistyleDependency.Breakpoints
|
434
|
-
}
|
435
|
-
case 'colorScheme': {
|
436
|
-
return UnistyleDependency.ColorScheme
|
437
|
-
}
|
438
|
-
case 'screen': {
|
439
|
-
return UnistyleDependency.Dimensions
|
440
|
-
}
|
441
|
-
case 'isPortrait':
|
442
|
-
case 'isLandscape': {
|
443
|
-
return UnistyleDependency.Orientation
|
444
|
-
}
|
445
|
-
case 'contentSizeCategory': {
|
446
|
-
return UnistyleDependency.ContentSizeCategory
|
447
|
-
}
|
448
|
-
case 'ime': {
|
449
|
-
return UnistyleDependency.Ime
|
450
|
-
}
|
451
|
-
case 'insets': {
|
452
|
-
return UnistyleDependency.Insets
|
453
|
-
}
|
454
|
-
case 'pixelRatio': {
|
455
|
-
return UnistyleDependency.PixelRatio
|
456
|
-
}
|
457
|
-
case 'fontScale': {
|
458
|
-
return UnistyleDependency.FontScale
|
459
|
-
}
|
460
|
-
case 'statusBar': {
|
461
|
-
return UnistyleDependency.StatusBar
|
462
|
-
}
|
463
|
-
case 'navigationBar': {
|
464
|
-
return UnistyleDependency.NavigationBar
|
465
|
-
}
|
466
|
-
case 'variants': {
|
467
|
-
return UnistyleDependency.Variants
|
468
|
-
}
|
469
|
-
|
470
|
-
// breakpoints are too complex and are handled by C++
|
471
|
-
}
|
472
|
-
}
|
473
|
-
|
474
|
-
function getReturnStatementsFromBody(t, node, results = []) {
|
475
|
-
if (t.isReturnStatement(node)) {
|
476
|
-
results.push(node)
|
477
|
-
}
|
478
|
-
|
479
|
-
if (t.isBlockStatement(node)) {
|
480
|
-
node.body.forEach(child => getReturnStatementsFromBody(t, child, results))
|
481
|
-
}
|
482
|
-
|
483
|
-
if (t.isIfStatement(node)) {
|
484
|
-
getReturnStatementsFromBody(t, node.consequent, results)
|
485
|
-
|
486
|
-
if (node.alternate) {
|
487
|
-
getReturnStatementsFromBody(t, node.alternate, results)
|
488
|
-
}
|
489
|
-
}
|
490
|
-
|
491
|
-
return results
|
492
|
-
}
|
493
|
-
|
494
|
-
function addDependencies(t, state, styleName, unistyle, detectedDependencies) {
|
495
|
-
const debugMessage = deps => {
|
496
|
-
if (state.opts.debug) {
|
497
|
-
const mappedDeps = deps
|
498
|
-
.map(dep => Object.keys(UnistyleDependency).find(key => UnistyleDependency[key] === dep))
|
499
|
-
.join(', ')
|
500
|
-
|
501
|
-
console.log(`${state.filename.replace(`${state.file.opts.root}/`, '')}: styles.${styleName}: [${mappedDeps}]`)
|
502
|
-
}
|
503
|
-
}
|
504
|
-
|
505
|
-
const styleDependencies = detectedDependencies.map(toUnistylesDependency)
|
506
|
-
|
507
|
-
// add metadata about dependencies
|
508
|
-
if (styleDependencies.length > 0) {
|
509
|
-
const uniqueDependencies = Array.from(new Set(styleDependencies))
|
510
|
-
|
511
|
-
debugMessage(uniqueDependencies)
|
512
|
-
|
513
|
-
let targets = []
|
514
|
-
|
515
|
-
if (t.isArrowFunctionExpression(unistyle.value) || t.isFunctionExpression(unistyle.value)) {
|
516
|
-
if (t.isObjectExpression(unistyle.value.body)) {
|
517
|
-
targets.push(unistyle.value.body)
|
518
|
-
}
|
519
|
-
|
520
|
-
if (t.isBlockStatement(unistyle.value.body)) {
|
521
|
-
targets = getReturnStatementsFromBody(t, unistyle.value.body)
|
522
|
-
.map(node => {
|
523
|
-
if (t.isIdentifier(node.argument)) {
|
524
|
-
node.argument = t.objectExpression([
|
525
|
-
t.spreadElement(node.argument)
|
526
|
-
])
|
527
|
-
}
|
528
|
-
|
529
|
-
return node.argument
|
530
|
-
})
|
531
|
-
}
|
532
|
-
}
|
533
|
-
|
534
|
-
if (t.isObjectExpression(unistyle.value)) {
|
535
|
-
targets.push(unistyle.value)
|
536
|
-
}
|
537
|
-
|
538
|
-
if (t.isMemberExpression(unistyle.value)) {
|
539
|
-
// convert to object
|
540
|
-
unistyle.value = t.objectExpression([t.spreadElement(unistyle.value)])
|
541
|
-
|
542
|
-
targets.push(unistyle.value)
|
543
|
-
}
|
544
|
-
|
545
|
-
if (targets.length > 0) {
|
546
|
-
targets.forEach(target => {
|
547
|
-
target.properties.push(
|
548
|
-
t.objectProperty(
|
549
|
-
t.identifier('uni__dependencies'),
|
550
|
-
t.arrayExpression(uniqueDependencies.map(dep => t.numericLiteral(dep)))
|
551
|
-
)
|
552
|
-
)
|
553
|
-
})
|
554
|
-
}
|
555
|
-
}
|
556
|
-
}
|
557
|
-
|
558
|
-
module.exports = {
|
559
|
-
isUnistylesStyleSheet,
|
560
|
-
addDependencies,
|
561
|
-
addStyleSheetTag,
|
562
|
-
getStylesDependenciesFromObject,
|
563
|
-
getStylesDependenciesFromFunction,
|
564
|
-
isKindOfStyleSheet
|
565
|
-
}
|