react-native-unistyles 3.0.0-alpha.3 → 3.0.0-alpha.31
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +7 -0
- package/android/CMakeLists.txt +12 -21
- package/cxx/common/Constants.h +3 -0
- package/cxx/common/Helpers.h +118 -5
- package/cxx/core/HostStyle.cpp +12 -8
- package/cxx/core/HostStyle.h +4 -0
- package/cxx/core/StyleSheet.h +0 -2
- package/cxx/core/StyleSheetRegistry.cpp +10 -13
- package/cxx/core/StyleSheetRegistry.h +4 -4
- package/cxx/core/Unistyle.h +7 -10
- package/cxx/core/UnistyleData.h +23 -0
- package/cxx/core/UnistyleWrapper.h +61 -12
- package/cxx/core/UnistylesCommitHook.cpp +14 -15
- package/cxx/core/UnistylesCommitHook.h +6 -11
- package/cxx/core/UnistylesCommitShadowNode.h +13 -0
- package/cxx/core/UnistylesMountHook.cpp +28 -0
- package/cxx/core/UnistylesMountHook.h +25 -0
- package/cxx/core/UnistylesRegistry.cpp +104 -89
- package/cxx/core/UnistylesRegistry.h +16 -13
- package/cxx/core/UnistylesState.cpp +29 -11
- package/cxx/core/UnistylesState.h +5 -2
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +15 -13
- package/cxx/hybridObjects/HybridStyleSheet.cpp +136 -46
- package/cxx/hybridObjects/HybridStyleSheet.h +23 -5
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +51 -8
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +12 -1
- package/cxx/parser/Parser.cpp +236 -165
- package/cxx/parser/Parser.h +11 -14
- package/cxx/shadowTree/ShadowLeafUpdate.h +2 -1
- package/cxx/shadowTree/ShadowTrafficController.h +60 -0
- package/cxx/shadowTree/ShadowTreeManager.cpp +17 -17
- package/cxx/shadowTree/ShadowTreeManager.h +3 -2
- package/ios/Equatable.swift +2 -1
- package/ios/NativePlatform+ios.swift +21 -5
- package/ios/NativePlatform+keyboard.swift +83 -0
- package/ios/NativePlatformListener+ios.swift +36 -23
- package/ios/Unistyles.h +1 -0
- package/ios/UnistylesModuleOnLoad.h +13 -2
- package/ios/UnistylesModuleOnLoad.mm +9 -1
- package/lib/commonjs/core/createUnistylesComponent.js +18 -0
- package/lib/commonjs/core/createUnistylesComponent.js.map +1 -0
- package/lib/commonjs/core/createUnistylesComponent.native.js +46 -0
- package/lib/commonjs/core/createUnistylesComponent.native.js.map +1 -0
- package/lib/commonjs/core/index.js +27 -0
- package/lib/commonjs/core/index.js.map +1 -0
- package/lib/commonjs/core/useBreakpoint.js +22 -0
- package/lib/commonjs/core/useBreakpoint.js.map +1 -0
- package/lib/commonjs/core/useBreakpoint.native.js +24 -0
- package/lib/commonjs/core/useBreakpoint.native.js.map +1 -0
- package/lib/commonjs/core/useTheme.js +22 -0
- package/lib/commonjs/core/useTheme.js.map +1 -0
- package/lib/commonjs/core/useTheme.native.js +24 -0
- package/lib/commonjs/core/useTheme.native.js.map +1 -0
- package/lib/commonjs/global.js +3 -0
- package/lib/commonjs/index.js +23 -11
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mq.js +1 -4
- package/lib/commonjs/mq.js.map +2 -1
- package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +1 -0
- package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +2 -1
- package/lib/commonjs/specs/NativePlatform/index.js.map +1 -1
- package/lib/commonjs/specs/NavigtionBar/index.js +1 -1
- package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +7 -6
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/types.js +3 -0
- package/lib/commonjs/specs/StatusBar/index.js +1 -1
- package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/UnistylesStyleSheet.nitro.js +2 -4
- package/lib/commonjs/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js +1 -0
- package/lib/commonjs/specs/StyleSheet/index.js.map +2 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/commonjs/specs/index.js +7 -0
- package/lib/commonjs/specs/index.js.map +1 -1
- package/lib/commonjs/specs/index.web.js +1 -1
- package/lib/commonjs/specs/index.web.js.map +2 -1
- package/lib/commonjs/specs/types.js +10 -10
- package/lib/commonjs/specs/types.js.map +1 -0
- package/lib/commonjs/types/accessibility.js +1 -1
- package/lib/commonjs/types/accessibility.js.map +1 -0
- package/lib/commonjs/types/common.js +3 -0
- package/lib/commonjs/types/stylesheet.js.map +1 -1
- package/lib/commonjs/types/variants.js.map +1 -1
- package/lib/commonjs/web/convert/boxShadow.js +74 -0
- package/lib/commonjs/web/convert/boxShadow.js.map +2 -0
- package/lib/commonjs/web/convert/index.js +68 -0
- package/lib/commonjs/web/convert/index.js.map +2 -0
- package/lib/commonjs/web/convert/module.d.js +2 -0
- package/lib/commonjs/web/convert/module.d.js.map +1 -0
- package/lib/commonjs/web/convert/pseudo.js +10 -0
- package/lib/commonjs/web/convert/pseudo.js.map +2 -0
- package/lib/commonjs/web/convert/shadow.js +64 -0
- package/lib/commonjs/web/convert/shadow.js.map +1 -0
- package/lib/commonjs/web/convert/style.js +93 -0
- package/lib/commonjs/web/convert/style.js.map +2 -0
- package/lib/commonjs/web/convert/textShadow.js +73 -0
- package/lib/commonjs/web/convert/textShadow.js.map +1 -0
- package/lib/commonjs/web/convert/transform.js +72 -0
- package/lib/commonjs/web/convert/transform.js.map +2 -0
- package/lib/commonjs/web/convert/types.js +9 -0
- package/lib/commonjs/web/convert/types.js.map +1 -0
- package/lib/commonjs/web/convert/utils.js +54 -0
- package/lib/commonjs/web/convert/utils.js.map +2 -0
- package/lib/commonjs/web/create.js +48 -0
- package/lib/commonjs/web/create.js.map +1 -0
- package/lib/commonjs/web/index.js +60 -0
- package/lib/commonjs/web/index.js.map +1 -0
- package/lib/commonjs/web/listener.js +35 -0
- package/lib/commonjs/web/listener.js.map +1 -0
- package/lib/commonjs/web/mock.js +28 -0
- package/lib/commonjs/web/mock.js.map +1 -0
- package/lib/commonjs/web/mq.js +23 -0
- package/lib/commonjs/web/mq.js.map +1 -0
- package/lib/commonjs/web/registry.js +183 -0
- package/lib/commonjs/web/registry.js.map +2 -0
- package/lib/commonjs/web/runtime.js +167 -0
- package/lib/commonjs/web/runtime.js.map +2 -0
- package/lib/commonjs/web/shadowRegistry.js +114 -0
- package/lib/commonjs/web/shadowRegistry.js.map +2 -0
- package/lib/commonjs/web/state.js +69 -0
- package/lib/commonjs/web/state.js.map +2 -0
- package/lib/commonjs/web/utils/common.js +92 -0
- package/lib/commonjs/web/utils/common.js.map +1 -0
- package/lib/commonjs/web/utils/index.js +28 -0
- package/lib/commonjs/web/utils/index.js.map +1 -0
- package/lib/commonjs/web/utils/unistyle.js +82 -0
- package/lib/commonjs/web/utils/unistyle.js.map +2 -0
- package/lib/commonjs/web/variants/getVariants.js +39 -0
- package/lib/commonjs/web/variants/getVariants.js.map +2 -0
- package/lib/commonjs/web/variants/index.js +28 -0
- package/lib/commonjs/web/variants/index.js.map +1 -0
- package/lib/commonjs/web/variants/useVariants.js +58 -0
- package/lib/commonjs/web/variants/useVariants.js.map +2 -0
- package/lib/module/common.js.map +1 -1
- package/lib/module/core/createUnistylesComponent.js +12 -0
- package/lib/module/core/createUnistylesComponent.js.map +1 -0
- package/lib/module/core/createUnistylesComponent.native.js +39 -0
- package/lib/module/core/createUnistylesComponent.native.js.map +1 -0
- package/lib/module/core/index.js +6 -0
- package/lib/module/core/index.js.map +1 -0
- package/lib/module/core/useBreakpoint.js +17 -0
- package/lib/module/core/useBreakpoint.js.map +1 -0
- package/lib/module/core/useBreakpoint.native.js +19 -0
- package/lib/module/core/useBreakpoint.native.js.map +2 -0
- package/lib/module/core/useTheme.js +17 -0
- package/lib/module/core/useTheme.js.map +1 -0
- package/lib/module/core/useTheme.native.js +19 -0
- package/lib/module/core/useTheme.native.js.map +1 -0
- package/lib/module/global.js +1 -1
- package/lib/module/global.js.map +1 -0
- package/lib/module/index.js +1 -9
- package/lib/module/index.js.map +1 -1
- package/lib/module/mq.js +1 -4
- package/lib/module/mq.js.map +2 -1
- package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +1 -0
- package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +2 -1
- package/lib/module/specs/NavigtionBar/UnistylesNavigationBar.nitro.js.map +1 -1
- package/lib/module/specs/NavigtionBar/index.js +1 -1
- package/lib/module/specs/NavigtionBar/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/ShadowRegistry.nitro.js.map +1 -0
- package/lib/module/specs/ShadowRegistry/index.js +7 -6
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/types.js +2 -0
- package/lib/module/specs/ShadowRegistry/types.js.map +1 -1
- package/lib/module/specs/StatusBar/UnistylesStatusBar.nitro.js.map +1 -0
- package/lib/module/specs/StatusBar/index.js +1 -1
- package/lib/module/specs/StatusBar/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js +1 -1
- package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js +1 -0
- package/lib/module/specs/StyleSheet/index.js.map +2 -1
- package/lib/module/specs/UnistylesRuntime/UnistylesRuntime.nitro.js.map +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js.map +2 -1
- package/lib/module/specs/index.js +2 -1
- package/lib/module/specs/index.js.map +1 -1
- package/lib/module/specs/index.web.js +1 -1
- package/lib/module/specs/index.web.js.map +2 -1
- package/lib/module/specs/types.js.map +1 -0
- package/lib/module/types/accessibility.js +1 -1
- package/lib/module/types/accessibility.js.map +1 -0
- package/lib/module/types/breakpoints.js.map +1 -1
- package/lib/module/types/common.js +1 -1
- package/lib/module/types/common.js.map +1 -0
- package/lib/module/types/core.js.map +1 -0
- package/lib/module/types/index.js.map +2 -1
- package/lib/module/types/stylesheet.js.map +1 -1
- package/lib/module/types/variants.js.map +1 -0
- package/lib/module/web/convert/boxShadow.js +72 -0
- package/lib/module/web/convert/boxShadow.js.map +1 -0
- package/lib/module/web/convert/index.js +69 -0
- package/lib/module/web/convert/index.js.map +1 -0
- package/lib/module/web/convert/module.d.js +2 -0
- package/lib/module/web/convert/module.d.js.map +1 -0
- package/lib/module/web/convert/pseudo.js +5 -0
- package/lib/module/web/convert/pseudo.js.map +1 -0
- package/lib/module/web/convert/shadow.js +63 -0
- package/lib/module/web/convert/shadow.js.map +1 -0
- package/lib/module/web/convert/style.js +88 -0
- package/lib/module/web/convert/style.js.map +1 -0
- package/lib/module/web/convert/textShadow.js +65 -0
- package/lib/module/web/convert/textShadow.js.map +2 -0
- package/lib/module/web/convert/transform.js +67 -0
- package/lib/module/web/convert/transform.js.map +1 -0
- package/lib/module/web/convert/types.js +5 -0
- package/lib/module/web/convert/types.js.map +1 -0
- package/lib/module/web/convert/utils.js +42 -0
- package/lib/module/web/convert/utils.js.map +2 -0
- package/lib/module/web/create.js +39 -0
- package/lib/module/web/create.js.map +2 -0
- package/lib/module/web/index.js +25 -0
- package/lib/module/web/index.js.map +1 -0
- package/lib/module/web/listener.js +31 -0
- package/lib/module/web/listener.js.map +2 -0
- package/lib/module/web/mock.js +24 -0
- package/lib/module/web/mock.js.map +1 -0
- package/lib/module/web/mq.js +17 -0
- package/lib/module/web/mq.js.map +1 -0
- package/lib/module/web/registry.js +179 -0
- package/lib/module/web/registry.js.map +1 -0
- package/lib/module/web/runtime.js +163 -0
- package/lib/module/web/runtime.js.map +1 -0
- package/lib/module/web/shadowRegistry.js +118 -0
- package/lib/module/web/shadowRegistry.js.map +1 -0
- package/lib/module/web/state.js +65 -0
- package/lib/module/web/state.js.map +2 -0
- package/lib/module/web/utils/common.js +78 -0
- package/lib/module/web/utils/common.js.map +2 -0
- package/lib/module/web/utils/index.js +5 -0
- package/lib/module/web/utils/index.js.map +1 -0
- package/lib/module/web/utils/unistyle.js +69 -0
- package/lib/module/web/utils/unistyle.js.map +2 -0
- package/lib/module/web/variants/getVariants.js +34 -0
- package/lib/module/web/variants/getVariants.js.map +1 -0
- package/lib/module/web/variants/index.js +5 -0
- package/lib/module/web/variants/index.js.map +1 -0
- package/lib/module/web/variants/useVariants.js +53 -0
- package/lib/module/web/variants/useVariants.js.map +1 -0
- package/lib/typescript/src/core/createUnistylesComponent.d.ts +6 -0
- package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -0
- package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +6 -0
- package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +4 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -0
- package/lib/typescript/src/core/useBreakpoint.d.ts +2 -0
- package/lib/typescript/src/core/useBreakpoint.d.ts.map +1 -0
- package/lib/typescript/src/core/useBreakpoint.native.d.ts +2 -0
- package/lib/typescript/src/core/useBreakpoint.native.d.ts.map +1 -0
- package/lib/typescript/src/core/useTheme.d.ts +3 -0
- package/lib/typescript/src/core/useTheme.d.ts.map +1 -0
- package/lib/typescript/src/core/useTheme.native.d.ts +3 -0
- package/lib/typescript/src/core/useTheme.native.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +6 -2
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/NavigtionBar/index.d.ts +5 -0
- package/lib/typescript/src/specs/NavigtionBar/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +3 -3
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StatusBar/index.d.ts +5 -0
- package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts +3 -1
- package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +3 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +0 -1
- package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts +3 -1
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.d.ts +4 -2
- package/lib/typescript/src/specs/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.web.d.ts +1 -1
- package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +11 -11
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +1 -1
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +6 -4
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/types/variants.d.ts +4 -1
- package/lib/typescript/src/types/variants.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/boxShadow.d.ts +8 -0
- package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/index.d.ts +3 -0
- package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/pseudo.d.ts +6 -0
- package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/style.d.ts +2 -0
- package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/textShadow.d.ts +8 -0
- package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/transform.d.ts +4 -0
- package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
- package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
- package/lib/typescript/src/web/create.d.ts +1443 -0
- package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
- package/lib/typescript/src/web/index.d.ts +1459 -0
- package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
- package/lib/typescript/{web/listener → src/web}/listener.d.ts +3 -2
- package/lib/typescript/src/web/listener.d.ts.map +1 -0
- package/lib/typescript/src/web/mock.d.ts +5 -0
- package/lib/typescript/src/web/mock.d.ts.map +1 -0
- package/lib/typescript/src/web/mq.d.ts +8 -0
- package/lib/typescript/src/web/mq.d.ts.map +1 -0
- package/lib/typescript/src/web/registry.d.ts +28 -0
- package/lib/typescript/src/web/registry.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/runtime.d.ts +9 -9
- package/lib/typescript/src/web/runtime.d.ts.map +1 -0
- package/lib/typescript/src/web/shadowRegistry.d.ts +16 -0
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -0
- package/lib/typescript/src/web/state.d.ts +18 -0
- package/lib/typescript/src/web/state.d.ts.map +1 -0
- package/lib/typescript/{web/utils.d.ts → src/web/utils/common.d.ts} +8 -9
- package/lib/typescript/src/web/utils/common.d.ts.map +1 -0
- package/lib/typescript/src/web/utils/index.d.ts +3 -0
- package/lib/typescript/src/web/utils/index.d.ts.map +1 -0
- package/lib/typescript/src/web/utils/unistyle.d.ts +20 -0
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/index.d.ts +3 -0
- package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
- package/nitrogen/generated/android/c++/JColorScheme.hpp +1 -1
- package/nitrogen/generated/android/c++/JFunc_void.hpp +48 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency_.hpp +8 -8
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +31 -22
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +8 -3
- package/nitrogen/generated/android/c++/JOrientation.hpp +1 -1
- package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +4 -1
- package/nitrogen/generated/android/c++/JUnistylesNativeMiniRuntime.hpp +9 -7
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void.kt +45 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +25 -5
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +2 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistylesNativeMiniRuntime.kt +2 -1
- package/nitrogen/generated/android/unistyles+autolinking.cmake +13 -1
- package/nitrogen/generated/android/{UnistylesOnLoad.cpp → unistylesOnLoad.cpp} +4 -2
- package/nitrogen/generated/android/{UnistylesOnLoad.hpp → unistylesOnLoad.hpp} +1 -1
- package/nitrogen/generated/ios/Unistyles+autolinking.rb +5 -3
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.cpp +25 -0
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +53 -31
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +0 -29
- package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +7 -1
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +3 -13
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +167 -104
- package/nitrogen/generated/ios/swift/UnistyleDependency.swift +4 -0
- package/nitrogen/generated/ios/swift/UnistylesNativeMiniRuntime.swift +16 -5
- package/nitrogen/generated/shared/c++/ColorScheme.hpp +2 -2
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +5 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +2 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +10 -4
- package/nitrogen/generated/shared/c++/Orientation.hpp +2 -2
- package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -1
- package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +10 -9
- package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +9 -8
- package/package.json +18 -30
- package/plugin/common.js +12 -1
- package/plugin/index.js +110 -23
- package/plugin/ref.js +64 -13
- package/plugin/style.js +82 -22
- package/plugin/stylesheet.js +53 -3
- package/plugin/variants.js +33 -0
- package/src/common.js +4 -0
- package/src/core/createUnistylesComponent.js +6 -0
- package/src/core/createUnistylesComponent.native.js +31 -0
- package/src/core/createUnistylesComponent.native.tsx +44 -0
- package/src/core/createUnistylesComponent.tsx +10 -0
- package/src/core/index.js +3 -0
- package/src/core/index.ts +3 -0
- package/src/core/useBreakpoint.js +14 -0
- package/src/core/useBreakpoint.native.js +16 -0
- package/src/core/useBreakpoint.native.ts +21 -0
- package/src/core/useBreakpoint.ts +18 -0
- package/src/core/useTheme.js +14 -0
- package/src/core/useTheme.native.js +16 -0
- package/src/core/useTheme.native.ts +22 -0
- package/src/core/useTheme.ts +19 -0
- package/src/global.js +1 -0
- package/src/index.js +3 -0
- package/src/index.ts +2 -12
- package/src/mq.js +38 -0
- package/src/specs/NativePlatform/NativePlatform.nitro.js +19 -0
- package/src/specs/NativePlatform/NativePlatform.nitro.ts +7 -3
- package/src/specs/NativePlatform/index.js +1 -0
- package/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.js +1 -0
- package/src/specs/NavigtionBar/index.js +9 -0
- package/src/specs/NavigtionBar/index.ts +6 -1
- package/src/specs/ShadowRegistry/ShadowRegistry.nitro.js +1 -0
- package/src/specs/ShadowRegistry/index.js +26 -0
- package/src/specs/ShadowRegistry/index.ts +10 -9
- package/src/specs/ShadowRegistry/types.js +1 -0
- package/src/specs/StatusBar/UnistylesStatusBar.nitro.js +1 -0
- package/src/specs/StatusBar/index.js +25 -0
- package/src/specs/StatusBar/index.ts +6 -1
- package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.js +1 -0
- package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.ts +4 -1
- package/src/specs/StyleSheet/index.js +13 -0
- package/src/specs/StyleSheet/index.ts +6 -1
- package/src/specs/TurboUnistyles/NativeTurboUnistyles.js +2 -0
- package/src/specs/TurboUnistyles/index.js +1 -0
- package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.js +1 -0
- package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +0 -1
- package/src/specs/UnistylesRuntime/index.js +20 -0
- package/src/specs/UnistylesRuntime/index.ts +4 -2
- package/src/specs/index.js +8 -0
- package/src/specs/index.ts +6 -2
- package/src/specs/index.web.js +2 -0
- package/src/specs/index.web.ts +1 -1
- package/src/specs/types.js +17 -0
- package/src/types/accessibility.js +30 -0
- package/src/types/breakpoints.js +1 -0
- package/src/types/breakpoints.ts +25 -13
- package/src/types/common.js +1 -0
- package/src/types/core.js +1 -0
- package/src/types/index.js +1 -0
- package/src/types/index.ts +1 -1
- package/src/types/stylesheet.js +2 -0
- package/src/types/stylesheet.ts +7 -5
- package/src/types/variants.js +1 -0
- package/src/types/variants.ts +7 -1
- package/src/web/convert/boxShadow.js +59 -0
- package/{web → src/web}/convert/boxShadow.ts +14 -15
- package/src/web/convert/index.js +56 -0
- package/{web → src/web}/convert/index.ts +8 -15
- package/src/web/convert/pseudo.js +131 -0
- package/src/web/convert/pseudo.ts +137 -0
- package/src/web/convert/shadow.js +50 -0
- package/src/web/convert/style.js +137 -0
- package/{web → src/web}/convert/style.ts +61 -10
- package/src/web/convert/textShadow.js +56 -0
- package/{web → src/web}/convert/textShadow.ts +13 -14
- package/src/web/convert/transform.js +65 -0
- package/{web → src/web}/convert/transform.ts +7 -8
- package/src/web/convert/types.js +2 -0
- package/{web → src/web}/convert/types.ts +1 -1
- package/src/web/convert/utils.js +39 -0
- package/src/web/create.js +36 -0
- package/src/web/create.ts +47 -0
- package/src/web/index.js +22 -0
- package/{web → src/web}/index.ts +3 -2
- package/src/web/listener.js +26 -0
- package/{web/listener → src/web}/listener.ts +3 -3
- package/src/web/mock.js +21 -0
- package/{web → src/web}/mock.ts +2 -12
- package/src/web/mq.js +14 -0
- package/{web → src/web}/mq.ts +1 -3
- package/src/web/registry.js +165 -0
- package/src/web/registry.ts +236 -0
- package/src/web/runtime.js +160 -0
- package/{web → src/web}/runtime.ts +21 -18
- package/src/web/shadowRegistry.js +96 -0
- package/src/web/shadowRegistry.ts +121 -0
- package/src/web/state.js +68 -0
- package/src/web/state.ts +94 -0
- package/src/web/utils/common.js +79 -0
- package/{web/utils.ts → src/web/utils/common.ts} +48 -36
- package/src/web/utils/index.js +2 -0
- package/src/web/utils/index.ts +2 -0
- package/src/web/utils/unistyle.js +72 -0
- package/src/web/utils/unistyle.ts +104 -0
- package/src/web/variants/getVariants.js +26 -0
- package/src/web/variants/getVariants.ts +42 -0
- package/src/web/variants/index.js +2 -0
- package/src/web/variants/index.ts +2 -0
- package/src/web/variants/useVariants.js +50 -0
- package/src/web/variants/useVariants.ts +65 -0
- package/lib/typescript/example/App.d.ts +0 -4
- package/lib/typescript/example/App.d.ts.map +0 -1
- package/lib/typescript/example/unistyles.d.ts +0 -63
- package/lib/typescript/example/unistyles.d.ts.map +0 -1
- package/lib/typescript/expo-example/App.d.ts +0 -4
- package/lib/typescript/expo-example/App.d.ts.map +0 -1
- package/lib/typescript/expo-example/unistyles.d.ts +0 -63
- package/lib/typescript/expo-example/unistyles.d.ts.map +0 -1
- package/lib/typescript/web/convert/boxShadow.d.ts +0 -3
- package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/breakpoint.d.ts +0 -3
- package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
- package/lib/typescript/web/convert/index.d.ts +0 -4
- package/lib/typescript/web/convert/index.d.ts.map +0 -1
- package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/style.d.ts +0 -3
- package/lib/typescript/web/convert/style.d.ts.map +0 -1
- package/lib/typescript/web/convert/textShadow.d.ts +0 -3
- package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/transform.d.ts +0 -5
- package/lib/typescript/web/convert/transform.d.ts.map +0 -1
- package/lib/typescript/web/convert/types.d.ts.map +0 -1
- package/lib/typescript/web/convert/utils.d.ts.map +0 -1
- package/lib/typescript/web/create.d.ts +0 -2449
- package/lib/typescript/web/index.d.ts +0 -2464
- package/lib/typescript/web/listener/index.d.ts +0 -2
- package/lib/typescript/web/listener/index.d.ts.map +0 -1
- package/lib/typescript/web/listener/listener.d.ts.map +0 -1
- package/lib/typescript/web/mock.d.ts +0 -14
- package/lib/typescript/web/mock.d.ts.map +0 -1
- package/lib/typescript/web/mq.d.ts +0 -4
- package/lib/typescript/web/mq.d.ts.map +0 -1
- package/lib/typescript/web/pseudo.d.ts +0 -4
- package/lib/typescript/web/pseudo.d.ts.map +0 -1
- package/lib/typescript/web/registry.d.ts +0 -12
- package/lib/typescript/web/registry.d.ts.map +0 -1
- package/lib/typescript/web/runtime.d.ts.map +0 -1
- package/lib/typescript/web/state.d.ts +0 -24
- package/lib/typescript/web/state.d.ts.map +0 -1
- package/lib/typescript/web/useVariants.d.ts +0 -3
- package/lib/typescript/web/useVariants.d.ts.map +0 -1
- package/lib/typescript/web/utils.d.ts.map +0 -1
- package/plugin/__tests__/dependencies.spec.js +0 -360
- package/plugin/__tests__/ref.spec.js +0 -991
- package/plugin/__tests__/stylesheet.spec.js +0 -396
- package/web/convert/breakpoint.ts +0 -21
- package/web/create.ts +0 -102
- package/web/listener/index.ts +0 -1
- package/web/pseudo.ts +0 -11
- package/web/registry.ts +0 -41
- package/web/state.ts +0 -148
- package/web/useVariants.ts +0 -99
- /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
- /package/nitrogen/generated/android/{UnistylesOnLoad.kt → unistylesOnLoad.kt} +0 -0
- /package/{web → src/web}/convert/module.d.ts +0 -0
- /package/{web → src/web}/convert/shadow.ts +0 -0
- /package/{web → src/web}/convert/utils.ts +0 -0
@@ -0,0 +1,179 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
import { UnistylesRuntime } from './runtime';
|
4
|
+
import { extractMediaQueryValue, keyInObject, getMediaQuery, generateHash, extractUnistyleDependencies, deepMergeObjects } from './utils';
|
5
|
+
import { UnistylesListener } from './listener';
|
6
|
+
import { convertUnistyles } from './convert';
|
7
|
+
import { getVariants } from './variants';
|
8
|
+
class UnistylesRegistryBuilder {
|
9
|
+
stylesheets = new Map();
|
10
|
+
stylesCounter = new Map();
|
11
|
+
#styleTag = null;
|
12
|
+
disposeListenersMap = new Map();
|
13
|
+
dependenciesMap = new Map();
|
14
|
+
get styleTag() {
|
15
|
+
const tag = this.#styleTag;
|
16
|
+
if (!tag) {
|
17
|
+
const newTag = document.createElement('style');
|
18
|
+
newTag.id = 'unistyles-web';
|
19
|
+
this.#styleTag = newTag;
|
20
|
+
document.head.appendChild(newTag);
|
21
|
+
return newTag;
|
22
|
+
}
|
23
|
+
return tag;
|
24
|
+
}
|
25
|
+
getComputedStylesheet = stylesheet => {
|
26
|
+
if (typeof stylesheet !== 'function') {
|
27
|
+
return stylesheet;
|
28
|
+
}
|
29
|
+
const computedStylesheet = this.stylesheets.get(stylesheet);
|
30
|
+
if (computedStylesheet) {
|
31
|
+
return computedStylesheet;
|
32
|
+
}
|
33
|
+
const createdStylesheet = stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime);
|
34
|
+
const dependencies = Object.values(createdStylesheet).flatMap(value => extractUnistyleDependencies(value));
|
35
|
+
this.addDependenciesToStylesheet(stylesheet, dependencies);
|
36
|
+
this.stylesheets.set(stylesheet, createdStylesheet);
|
37
|
+
return createdStylesheet;
|
38
|
+
};
|
39
|
+
addDependenciesToStylesheet = (stylesheet, dependencies) => {
|
40
|
+
this.disposeListenersMap.get(stylesheet)?.();
|
41
|
+
const dependenciesMap = this.dependenciesMap.get(stylesheet) ?? new Set(dependencies);
|
42
|
+
dependencies.forEach(dependency => dependenciesMap.add(dependency));
|
43
|
+
const dispose = UnistylesListener.addListeners(Array.from(dependenciesMap), () => {
|
44
|
+
const newComputedStylesheet = stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime);
|
45
|
+
this.stylesheets.set(stylesheet, newComputedStylesheet);
|
46
|
+
});
|
47
|
+
this.dependenciesMap.set(stylesheet, dependenciesMap);
|
48
|
+
this.disposeListenersMap.set(stylesheet, dispose);
|
49
|
+
};
|
50
|
+
add = ({
|
51
|
+
key,
|
52
|
+
value,
|
53
|
+
stylesheet,
|
54
|
+
args,
|
55
|
+
variants
|
56
|
+
}) => {
|
57
|
+
const hash = generateHash(value);
|
58
|
+
const existingCounter = this.stylesCounter.get(hash);
|
59
|
+
if (!existingCounter || existingCounter.size === 0) {
|
60
|
+
const counter = new Set();
|
61
|
+
const dependencies = extractUnistyleDependencies(value);
|
62
|
+
counter.add(value);
|
63
|
+
this.stylesCounter.set(hash, counter);
|
64
|
+
this.applyStyles(hash, convertUnistyles(value));
|
65
|
+
UnistylesListener.addListeners(dependencies, async () => {
|
66
|
+
// Move this callback to the end of the event loop
|
67
|
+
await Promise.resolve();
|
68
|
+
const newComputedStyleSheet = this.getComputedStylesheet(stylesheet);
|
69
|
+
const newValue = newComputedStyleSheet[key];
|
70
|
+
const result = typeof newValue === 'function' ? newValue(...args) : newValue;
|
71
|
+
const {
|
72
|
+
variantsResult
|
73
|
+
} = Object.fromEntries(getVariants({
|
74
|
+
variantsResult: result
|
75
|
+
}, variants));
|
76
|
+
const resultWithVariants = deepMergeObjects(result, variantsResult ?? {});
|
77
|
+
this.applyStyles(hash, convertUnistyles(resultWithVariants));
|
78
|
+
});
|
79
|
+
return hash;
|
80
|
+
}
|
81
|
+
existingCounter.add(value);
|
82
|
+
return hash;
|
83
|
+
};
|
84
|
+
applyStyles = (hash, styles) => {
|
85
|
+
Object.entries(styles).forEach(([key, value]) => {
|
86
|
+
if (!this.styleTag.sheet) {
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
if (typeof value === 'object' && !key.startsWith('_')) {
|
90
|
+
const mediaQuery = getMediaQuery(key);
|
91
|
+
const cssRules = Array.from(this.styleTag.sheet.cssRules);
|
92
|
+
let queryRule = cssRules.find(rule => {
|
93
|
+
if (!(rule instanceof CSSMediaRule)) {
|
94
|
+
return false;
|
95
|
+
}
|
96
|
+
return rule.media.item(0)?.includes(mediaQuery);
|
97
|
+
}) ?? null;
|
98
|
+
if (!queryRule) {
|
99
|
+
const mediaQueryValue = extractMediaQueryValue(mediaQuery);
|
100
|
+
const ruleIndex = mediaQueryValue ? cssRules.reduce((acc, rule, ruleIndex) => {
|
101
|
+
if (!(rule instanceof CSSMediaRule)) {
|
102
|
+
return acc;
|
103
|
+
}
|
104
|
+
const ruleMediaQueryValue = extractMediaQueryValue(rule.conditionText);
|
105
|
+
if (ruleMediaQueryValue === undefined) {
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
return ruleMediaQueryValue > mediaQueryValue ? ruleIndex : acc;
|
109
|
+
}, cssRules.length) : undefined;
|
110
|
+
queryRule = this.styleTag.sheet.cssRules.item(this.styleTag.sheet.insertRule(`@media ${mediaQuery} {.${hash} {}}`, ruleIndex));
|
111
|
+
}
|
112
|
+
if (queryRule instanceof CSSMediaRule) {
|
113
|
+
Object.entries(value).forEach(([mqKey, mqValue]) => {
|
114
|
+
this.applyRule({
|
115
|
+
hash,
|
116
|
+
key: mqKey,
|
117
|
+
value: mqValue,
|
118
|
+
sheet: queryRule
|
119
|
+
});
|
120
|
+
});
|
121
|
+
}
|
122
|
+
return;
|
123
|
+
}
|
124
|
+
// Pseudo
|
125
|
+
if (typeof value === 'object') {
|
126
|
+
Object.entries(value).forEach(([pseudoKey, pseudoValue]) => {
|
127
|
+
this.applyRule({
|
128
|
+
hash: `${hash}${key.replace('_', ':')}`,
|
129
|
+
key: pseudoKey,
|
130
|
+
value: pseudoValue,
|
131
|
+
sheet: this.styleTag.sheet
|
132
|
+
});
|
133
|
+
});
|
134
|
+
return;
|
135
|
+
}
|
136
|
+
this.applyRule({
|
137
|
+
hash,
|
138
|
+
key,
|
139
|
+
value,
|
140
|
+
sheet: this.styleTag.sheet
|
141
|
+
});
|
142
|
+
});
|
143
|
+
};
|
144
|
+
applyRule = ({
|
145
|
+
hash,
|
146
|
+
key,
|
147
|
+
value,
|
148
|
+
sheet
|
149
|
+
}) => {
|
150
|
+
let rule = Array.from(sheet.cssRules).find(rule => {
|
151
|
+
if (!(rule instanceof CSSStyleRule)) {
|
152
|
+
return false;
|
153
|
+
}
|
154
|
+
// In unistyles pseudos are prefixed with ':' but in css some of them are prefixed with '::'
|
155
|
+
return rule.selectorText.replace('::', ':').includes(hash);
|
156
|
+
}) ?? null;
|
157
|
+
if (!rule) {
|
158
|
+
rule = sheet.cssRules.item(sheet.insertRule(`.${hash} {}`));
|
159
|
+
}
|
160
|
+
if (!(rule instanceof CSSStyleRule) || !keyInObject(rule.style, key)) {
|
161
|
+
return;
|
162
|
+
}
|
163
|
+
rule.style[key] = value;
|
164
|
+
};
|
165
|
+
remove = value => {
|
166
|
+
const hash = generateHash(value);
|
167
|
+
const existingStyles = this.stylesCounter.get(hash);
|
168
|
+
if (!existingStyles) {
|
169
|
+
return;
|
170
|
+
}
|
171
|
+
existingStyles.delete(value);
|
172
|
+
if (existingStyles.size === 0) {
|
173
|
+
const ruleIndex = Array.from(this.styleTag.sheet?.cssRules ?? []).findIndex(rule => rule.cssText.includes(`.${hash}`));
|
174
|
+
this.styleTag.sheet?.deleteRule(ruleIndex);
|
175
|
+
}
|
176
|
+
};
|
177
|
+
}
|
178
|
+
export const UnistylesRegistry = new UnistylesRegistryBuilder();
|
179
|
+
//# sourceMappingURL=registry.js.mapap
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["UnistylesRuntime","extractMediaQueryValue","keyInObject","getMediaQuery","generateHash","extractUnistyleDependencies","deepMergeObjects","UnistylesListener","convertUnistyles","getVariants","UnistylesRegistryBuilder","stylesheets","Map","stylesCounter","styleTag","disposeListenersMap","dependenciesMap","tag","newTag","document","createElement","id","head","appendChild","getComputedStylesheet","stylesheet","computedStylesheet","get","createdStylesheet","theme","miniRuntime","dependencies","Object","values","flatMap","value","addDependenciesToStylesheet","set","Set","forEach","dependency","add","dispose","addListeners","Array","from","newComputedStylesheet","key","args","variants","hash","existingCounter","size","counter","applyStyles","Promise","resolve","newComputedStyleSheet","newValue","result","variantsResult","fromEntries","resultWithVariants","styles","entries","sheet","startsWith","mediaQuery","cssRules","queryRule","find","rule","CSSMediaRule","media","item","includes","mediaQueryValue","ruleIndex","reduce","acc","ruleMediaQueryValue","conditionText","undefined","length","insertRule","mqKey","mqValue","applyRule","pseudoKey","pseudoValue","replace","CSSStyleRule","selectorText","style","remove","existingStyles","delete","findIndex","cssText","deleteRule","UnistylesRegistry"],"sourceRoot":"../../../src","sources":["web/registry.ts"],"mappings":";;AAEA,SAASA,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C;MAEtH,IAAI,CAACpC,QAAQ,CAACmD,KAAK,EAAEkC,UAAU,CAACtB,SAAS,CAAC;IAC9C;EACJ,CAAC;AACL;AAEA,OAAO,MAAMuB,iBAAiB,GAAG,IAAI1F,wBAAwB,CAAC,CAAC","ignoreList":[]}
|
@@ -0,0 +1,163 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
import { UnistyleDependency } from '../specs/NativePlatform';
|
4
|
+
import { ColorScheme, Orientation } from '../specs/types';
|
5
|
+
import { WebContentSizeCategory } from '../types';
|
6
|
+
import { UnistylesListener } from './listener';
|
7
|
+
import { NavigationBar, StatusBar } from './mock';
|
8
|
+
import { UnistylesState } from './state';
|
9
|
+
import { hexToRGBA, isServer, schemeToTheme } from './utils';
|
10
|
+
class UnistylesRuntimeBuilder {
|
11
|
+
lightMedia = this.getLightMedia();
|
12
|
+
darkMedia = this.getDarkMedia();
|
13
|
+
getLightMedia() {
|
14
|
+
if (isServer()) {
|
15
|
+
return null;
|
16
|
+
}
|
17
|
+
if (!this.lightMedia) {
|
18
|
+
this.lightMedia = window.matchMedia('(prefers-color-scheme: light)');
|
19
|
+
}
|
20
|
+
return this.lightMedia;
|
21
|
+
}
|
22
|
+
getDarkMedia() {
|
23
|
+
if (isServer()) {
|
24
|
+
return null;
|
25
|
+
}
|
26
|
+
if (!this.darkMedia) {
|
27
|
+
this.darkMedia = window.matchMedia('(prefers-color-scheme: dark)');
|
28
|
+
}
|
29
|
+
return this.darkMedia;
|
30
|
+
}
|
31
|
+
get colorScheme() {
|
32
|
+
switch (true) {
|
33
|
+
case this.getLightMedia()?.matches:
|
34
|
+
return ColorScheme.Light;
|
35
|
+
case this.getDarkMedia()?.matches:
|
36
|
+
return ColorScheme.Dark;
|
37
|
+
default:
|
38
|
+
return ColorScheme.Unspecified;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
get themeName() {
|
42
|
+
return UnistylesState.themeName;
|
43
|
+
}
|
44
|
+
get contentSizeCategory() {
|
45
|
+
return WebContentSizeCategory.Unspecified;
|
46
|
+
}
|
47
|
+
get breakpoint() {
|
48
|
+
return UnistylesState.breakpoint;
|
49
|
+
}
|
50
|
+
get orientation() {
|
51
|
+
if (isServer()) {
|
52
|
+
return Orientation.Portrait;
|
53
|
+
}
|
54
|
+
return screen.orientation.type.includes('portrait') ? Orientation.Portrait : Orientation.Landscape;
|
55
|
+
}
|
56
|
+
get theme() {
|
57
|
+
return this.getTheme(this.themeName);
|
58
|
+
}
|
59
|
+
get pixelRatio() {
|
60
|
+
return isServer() ? 1 : window.devicePixelRatio;
|
61
|
+
}
|
62
|
+
get screen() {
|
63
|
+
if (isServer()) {
|
64
|
+
return {
|
65
|
+
width: 0,
|
66
|
+
height: 0
|
67
|
+
};
|
68
|
+
}
|
69
|
+
return {
|
70
|
+
width: window.innerWidth,
|
71
|
+
height: window.innerHeight
|
72
|
+
};
|
73
|
+
}
|
74
|
+
get fontScale() {
|
75
|
+
return 1;
|
76
|
+
}
|
77
|
+
get insets() {
|
78
|
+
return {
|
79
|
+
top: 0,
|
80
|
+
bottom: 0,
|
81
|
+
left: 0,
|
82
|
+
right: 0,
|
83
|
+
ime: 0
|
84
|
+
};
|
85
|
+
}
|
86
|
+
get statusBar() {
|
87
|
+
return StatusBar;
|
88
|
+
}
|
89
|
+
get rtl() {
|
90
|
+
return isServer() ? true : document.documentElement.dir === 'rtl';
|
91
|
+
}
|
92
|
+
get hasAdaptiveThemes() {
|
93
|
+
return UnistylesState.hasAdaptiveThemes;
|
94
|
+
}
|
95
|
+
get navigationBar() {
|
96
|
+
return NavigationBar;
|
97
|
+
}
|
98
|
+
get miniRuntime() {
|
99
|
+
return {
|
100
|
+
colorScheme: this.colorScheme,
|
101
|
+
themeName: this.themeName,
|
102
|
+
contentSizeCategory: this.contentSizeCategory,
|
103
|
+
breakpoint: this.breakpoint,
|
104
|
+
isLandscape: this.orientation === Orientation.Landscape,
|
105
|
+
isPortrait: this.orientation === Orientation.Portrait,
|
106
|
+
pixelRatio: this.pixelRatio,
|
107
|
+
screen: this.screen,
|
108
|
+
fontScale: this.fontScale,
|
109
|
+
insets: this.insets,
|
110
|
+
statusBar: {
|
111
|
+
width: this.statusBar.width,
|
112
|
+
height: this.statusBar.height
|
113
|
+
},
|
114
|
+
navigationBar: {
|
115
|
+
width: this.navigationBar.width,
|
116
|
+
height: this.navigationBar.height
|
117
|
+
},
|
118
|
+
rtl: this.rtl,
|
119
|
+
hasAdaptiveThemes: this.hasAdaptiveThemes
|
120
|
+
};
|
121
|
+
}
|
122
|
+
setTheme = themeName => {
|
123
|
+
if (themeName === UnistylesRuntime.themeName) {
|
124
|
+
return;
|
125
|
+
}
|
126
|
+
UnistylesState.themeName = themeName;
|
127
|
+
UnistylesListener.emitChange(UnistyleDependency.Theme);
|
128
|
+
UnistylesListener.emitChange(UnistyleDependency.ThemeName);
|
129
|
+
};
|
130
|
+
setAdaptiveThemes = isEnabled => {
|
131
|
+
UnistylesState.hasAdaptiveThemes = isEnabled;
|
132
|
+
if (!isEnabled) {
|
133
|
+
return;
|
134
|
+
}
|
135
|
+
this.setTheme(schemeToTheme(UnistylesRuntime.colorScheme));
|
136
|
+
};
|
137
|
+
setRootViewBackgroundColor = (hex, alpha) => {
|
138
|
+
if (isServer()) {
|
139
|
+
return;
|
140
|
+
}
|
141
|
+
document.documentElement.style.backgroundColor = alpha ? hexToRGBA(hex, alpha) : hex;
|
142
|
+
};
|
143
|
+
setImmersiveMode = () => {};
|
144
|
+
updateTheme = (themeName, updater) => {
|
145
|
+
const oldTheme = UnistylesState.themes.get(themeName);
|
146
|
+
if (!oldTheme) {
|
147
|
+
throw new Error(`🦄 Theme "${themeName}" is not registered!`);
|
148
|
+
}
|
149
|
+
UnistylesState.themes.set(themeName, updater(oldTheme));
|
150
|
+
};
|
151
|
+
getTheme = (themeName = this.themeName) => {
|
152
|
+
if (!themeName) {
|
153
|
+
throw new Error('🦄 No theme selected!');
|
154
|
+
}
|
155
|
+
const theme = UnistylesState.themes.get(themeName);
|
156
|
+
if (!theme) {
|
157
|
+
throw new Error(`🦄 Theme "${this.themeName}" is not registered!`);
|
158
|
+
}
|
159
|
+
return theme;
|
160
|
+
};
|
161
|
+
}
|
162
|
+
export const UnistylesRuntime = new UnistylesRuntimeBuilder();
|
163
|
+
//# sourceMappingURL=runtime.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["UnistyleDependency","ColorScheme","Orientation","WebContentSizeCategory","UnistylesListener","NavigationBar","StatusBar","UnistylesState","hexToRGBA","isServer","schemeToTheme","UnistylesRuntimeBuilder","lightMedia","getLightMedia","darkMedia","getDarkMedia","window","matchMedia","colorScheme","matches","Light","Dark","Unspecified","themeName","contentSizeCategory","breakpoint","orientation","Portrait","screen","type","includes","Landscape","theme","getTheme","pixelRatio","devicePixelRatio","width","height","innerWidth","innerHeight","fontScale","insets","top","bottom","left","right","ime","statusBar","rtl","document","documentElement","dir","hasAdaptiveThemes","navigationBar","miniRuntime","isLandscape","isPortrait","setTheme","UnistylesRuntime","emitChange","Theme","ThemeName","setAdaptiveThemes","isEnabled","setRootViewBackgroundColor","hex","alpha","style","backgroundColor","setImmersiveMode","updateTheme","updater","oldTheme","themes","get","Error","set"],"sourceRoot":"../../../src","sources":["web/runtime.ts"],"mappings":";;AAAA,SAASA,kBAAkB,QAAQ,yBAAyB;AAC5D,SAASC,WAAW,EAAEC,WAAW,QAA0C,gBAAgB;AAE3F,SAASC,sBAAsB,QAAQ,UAAU;AACjD,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,aAAa,EAAEC,SAAS,QAAQ,QAAQ;AACjD,SAASC,cAAc,QAAQ,SAAS;AACxC,SAASC,SAAS,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,SAAS;AAE5D,MAAMC,uBAAuB,CAAC;EAC1BC,UAAU,GAAG,IAAI,CAACC,aAAa,CAAC,CAAC;EACjCC,SAAS,GAAG,IAAI,CAACC,YAAY,CAAC,CAAC;EAEvBF,aAAaA,CAAA,EAA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wC,QAAQ,CAACC,eAAe,CAACiB,KAAK,CAACC,eAAe,GAAGF,KAAK,GAAG1D,SAAS,CAACyD,GAAG,EAAEC,KAAK,CAAC,GAAGD,GAAG;EACxF,CAAC;EAEDI,gBAAgB,GAAGA,CAAA,KAAM,CAAC,CAAC;EAE3BC,WAAW,GAAGA,CAAC/C,SAAuB,EAAEgD,OAA6C,KAAK;IACtF,MAAMC,QAAQ,GAAGjE,cAAc,CAACkE,MAAM,CAACC,GAAG,CAACnD,SAAS,CAAC;IAErD,IAAI,CAACiD,QAAQ,EAAE;MACX,MAAM,IAAIG,KAAK,CAAC,aAAapD,SAAS,sBAAsB,CAAC;IACjE;IAEAhB,cAAc,CAACkE,MAAM,CAACG,GAAG,CAACrD,SAAS,EAAEgD,OAAO,CAACC,QAAQ,CAAC,CAAC;EAC3D,CAAC;EAEDvC,QAAQ,GAAGA,CAACV,SAAS,GAAG,IAAI,CAACA,SAAS,KAAK;IACvC,IAAI,CAACA,SAAS,EAAE;MACZ,MAAM,IAAIoD,KAAK,CAAC,uBAAuB,CAAC;IAC5C;IAEA,MAAM3C,KAAK,GAAGzB,cAAc,CAACkE,MAAM,CAACC,GAAG,CAACnD,SAAS,CAAC;IAElD,IAAI,CAACS,KAAK,EAAE;MACR,MAAM,IAAI2C,KAAK,CAAC,aAAa,IAAI,CAACpD,SAAS,sBAAsB,CAAC;IACtE;IAEA,OAAOS,KAAK;EAChB,CAAC;AACL;AAEA,OAAO,MAAM0B,gBAAgB,GAAG,IAAI/C,uBAAuB,CAAC,CAAC","ignoreList":[]}
|
@@ -0,0 +1,118 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
import { UnistylesRegistry } from './registry';
|
4
|
+
import { createDoubleMap, deepMergeObjects, equal, extractSecrets, extractUnistyleDependencies, isInDocument } from './utils';
|
5
|
+
import { getVariants } from './variants';
|
6
|
+
class UnistylesShadowRegistryBuilder {
|
7
|
+
// MOCKS
|
8
|
+
name = 'UnistylesShadowRegistry';
|
9
|
+
__type = 'web';
|
10
|
+
equals = () => true;
|
11
|
+
toString = () => 'UnistylesShadowRegistry';
|
12
|
+
dispose = () => {};
|
13
|
+
// END MOCKS
|
14
|
+
|
15
|
+
resultsMap = createDoubleMap();
|
16
|
+
classNamesMap = createDoubleMap();
|
17
|
+
add = (ref, _style, _variants, _args) => {
|
18
|
+
// Style is not provided
|
19
|
+
if (!_style) {
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
|
23
|
+
// Array of styles
|
24
|
+
if (Array.isArray(_style)) {
|
25
|
+
_style.forEach(style => this.add(ref, style, _variants, _args));
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
|
29
|
+
// Not a unistyle
|
30
|
+
if (!Object.keys(_style).some(key => key.startsWith('__uni__'))) {
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
|
34
|
+
// Ref is unmounted, remove style tags from the document
|
35
|
+
if (ref === null) {
|
36
|
+
const secrets = extractSecrets(_style);
|
37
|
+
secrets.forEach(({
|
38
|
+
__uni__refs,
|
39
|
+
__uni__key
|
40
|
+
}) => {
|
41
|
+
__uni__refs.forEach(ref => {
|
42
|
+
if (isInDocument(ref)) {
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
const oldResult = this.resultsMap.get(ref, __uni__key);
|
46
|
+
this.resultsMap.delete(ref, __uni__key);
|
47
|
+
this.classNamesMap.delete(ref, __uni__key);
|
48
|
+
if (oldResult) {
|
49
|
+
UnistylesRegistry.remove(oldResult);
|
50
|
+
}
|
51
|
+
});
|
52
|
+
});
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
|
56
|
+
// Ref is not an HTMLElement
|
57
|
+
if (!(ref instanceof HTMLElement)) {
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
extractSecrets(_style).forEach(secret => {
|
61
|
+
const {
|
62
|
+
__uni__key,
|
63
|
+
__uni__stylesheet,
|
64
|
+
__uni__variants,
|
65
|
+
__uni__args = [],
|
66
|
+
__uni__refs
|
67
|
+
} = secret;
|
68
|
+
const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet);
|
69
|
+
const style = newComputedStylesheet[__uni__key];
|
70
|
+
const args = _args ?? __uni__args;
|
71
|
+
const variants = _variants && Object.keys(_variants).length > 0 ? _variants : __uni__variants;
|
72
|
+
const result = typeof style === 'function' ? style(...args) : style;
|
73
|
+
const {
|
74
|
+
variantsResult
|
75
|
+
} = Object.fromEntries(getVariants({
|
76
|
+
variantsResult: result
|
77
|
+
}, variants));
|
78
|
+
const resultWithVariants = deepMergeObjects(result, variantsResult ?? {});
|
79
|
+
const oldResult = this.resultsMap.get(ref, __uni__key);
|
80
|
+
|
81
|
+
// If results are the same do nothing
|
82
|
+
if (equal(oldResult, resultWithVariants)) {
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
const oldClassNames = this.classNamesMap.get(ref, __uni__key);
|
86
|
+
|
87
|
+
// Remove old styles
|
88
|
+
if (oldResult) {
|
89
|
+
UnistylesRegistry.remove(oldResult);
|
90
|
+
}
|
91
|
+
|
92
|
+
// Remove old classnames from the ref
|
93
|
+
oldClassNames?.forEach(className => ref.classList.remove(className));
|
94
|
+
this.resultsMap.set(ref, __uni__key, resultWithVariants);
|
95
|
+
const className = UnistylesRegistry.add({
|
96
|
+
key: __uni__key,
|
97
|
+
args,
|
98
|
+
stylesheet: __uni__stylesheet,
|
99
|
+
value: resultWithVariants,
|
100
|
+
variants
|
101
|
+
});
|
102
|
+
const injectedClassNames = resultWithVariants?._web?._classNames ?? [];
|
103
|
+
const newClassNames = injectedClassNames.concat(className);
|
104
|
+
const dependencies = extractUnistyleDependencies(resultWithVariants);
|
105
|
+
if (typeof __uni__stylesheet === 'function') {
|
106
|
+
// Add dependencies from dynamic styles to stylesheet
|
107
|
+
UnistylesRegistry.addDependenciesToStylesheet(__uni__stylesheet, dependencies);
|
108
|
+
}
|
109
|
+
__uni__refs.add(ref);
|
110
|
+
this.classNamesMap.set(ref, __uni__key, newClassNames);
|
111
|
+
// Add new classnames to the ref
|
112
|
+
ref.classList.add(...newClassNames);
|
113
|
+
});
|
114
|
+
};
|
115
|
+
remove = () => {};
|
116
|
+
}
|
117
|
+
export const UnistylesShadowRegistry = new UnistylesShadowRegistryBuilder();
|
118
|
+
//# sourceMappingURL=shadowRegistry.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["UnistylesRegistry","createDoubleMap","deepMergeObjects","equal","extractSecrets","extractUnistyleDependencies","isInDocument","getVariants","UnistylesShadowRegistryBuilder","name","__type","equals","toString","dispose","resultsMap","classNamesMap","add","ref","_style","_variants","_args","Array","isArray","forEach","style","Object","keys","some","key","startsWith","secrets","__uni__refs","__uni__key","oldResult","get","delete","remove","HTMLElement","secret","__uni__stylesheet","__uni__variants","__uni__args","newComputedStylesheet","getComputedStylesheet","args","variants","length","result","variantsResult","fromEntries","resultWithVariants","oldClassNames","className","classList","set","stylesheet","value","injectedClassNames","_web","_classNames","newClassNames","concat","dependencies","addDependenciesToStylesheet","UnistylesShadowRegistry"],"sourceRoot":"../../../src","sources":["web/shadowRegistry.ts"],"mappings":";;AACA,SAASA,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,eAAe,EAAEC,gBAAgB,EAAEC,KAAK,EAAEC,cAAc,EAAEC,2BAA2B,EAAEC,YAAY,QAAQ,SAAS;AAC7H,SAASC,WAAW,QAAQ,YAAY;AAIxC,MAAMC,8BAA8B,CAAC;EACjC;EACAC,IAAI,GAAG,yBAAyB;EAChCC,MAAM,GAAG,KAAK;EACdC,MAAM,GAAGA,CAAA,KAAM,IAAI;EACnBC,QAAQ,GAAGA,CAAA,KAAM,yBAAyB;EAC1CC,OAAO,GAAGA,CAAA,KAAM,CAAC,CAAC;EAClB;;EAEQC,UAAU,GAAGb,eAAe,CAAuC,CAAC;EACpEc,aAAa,GAAGd,eAAe,CAAqC,CAAC;EAE7Ee,GAAG,GAAGA,CAACC,GAAQ,EAAEC,MAA6B,EAAEC,SAA+B,EAAEC,KAAkB,KAAK;IACpG;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,CAAC;MAExD,MAAME,SAAS,GAAGpD,iBAAiB,CAACgB,GAAG,CAAC;QACpCY,GAAG,EAAEI,UAAU;QACfY,IAAI;QACJW,UAAU,EAAEhB,iBAAiB;QAC7BiB,KAAK,EAAEN,kBAAkB;QACzBL;MACJ,CAAC,CAAC;MACF,MAAMY,kBAAiC,GAAGP,kBAAkB,EAAEQ,IAAI,EAAEC,WAAW,IAAI,EAAE;MACrF,MAAMC,aAAa,GAAGH,kBAAkB,CAACI,MAAM,CAACT,SAAS,CAAC;MAC1D,MAAMU,YAAY,GAAGzD,2BAA2B,CAAC6C,kBAAkB,CAAC;MAEpE,IAAI,OAAOX,iBAAiB,KAAK,UAAU,EAAE;QACzC;QACAvC,iBAAiB,CAAC+D,2BAA2B,CAACxB,iBAAiB,EAAEuB,YAAY,CAAC;MAClF;MAEA/B,WAAW,CAACf,GAAG,CAACC,GAAG,CAAC;MACpB,IAAI,CAACF,aAAa,CAACuC,GAAG,CAACrC,GAAG,EAAEe,UAAU,EAAE4B,aAAa,CAAC;MACtD;MACA3C,GAAG,CAACoC,SAAS,CAACrC,GAAG,CAAC,GAAG4C,aAAa,CAAC;IACvC,CAAC,CAAC;EACN,CAAC;EAEDxB,MAAM,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB;AAEA,OAAO,MAAM4B,uBAAuB,GAAG,IAAIxD,8BAA8B,CAAC,CAAC","ignoreList":[]}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
import { UnistylesRuntime } from './runtime';
|
4
|
+
import { isServer, schemeToTheme } from './utils';
|
5
|
+
import { UnistylesListener } from './listener';
|
6
|
+
import { UnistyleDependency } from '../specs/NativePlatform';
|
7
|
+
class UnistylesStateBuilder {
|
8
|
+
themes = new Map();
|
9
|
+
matchingBreakpoints = new Map();
|
10
|
+
get breakpoint() {
|
11
|
+
const [currentBreakpoint] = Array.from(this.matchingBreakpoints).reverse().find(([_key, value]) => value) ?? [];
|
12
|
+
return currentBreakpoint;
|
13
|
+
}
|
14
|
+
hasAdaptiveThemes = false;
|
15
|
+
init = config => {
|
16
|
+
this.initThemes(config.themes);
|
17
|
+
this.initBreakpoints(config.breakpoints);
|
18
|
+
this.initSettings(config.settings);
|
19
|
+
if (isServer()) {
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
UnistylesListener.initListeners();
|
23
|
+
};
|
24
|
+
initThemes = (themes = {}) => {
|
25
|
+
Object.entries(themes).forEach(([themeName, theme]) => {
|
26
|
+
this.themes.set(themeName, theme);
|
27
|
+
});
|
28
|
+
};
|
29
|
+
initSettings = settings => {
|
30
|
+
this.hasAdaptiveThemes = settings?.adaptiveThemes ?? false;
|
31
|
+
const themeNames = Array.from(this.themes.keys());
|
32
|
+
// Single theme + no settings
|
33
|
+
if (!settings?.adaptiveThemes && !settings?.initialTheme && themeNames.length === 1) {
|
34
|
+
this.themeName = themeNames[0];
|
35
|
+
return;
|
36
|
+
}
|
37
|
+
// No settings
|
38
|
+
if (!settings?.adaptiveThemes && !settings?.initialTheme) {
|
39
|
+
throw new Error('🦄 You need to specify either "initialTheme" or "adaptiveThemes" in your config');
|
40
|
+
}
|
41
|
+
// Adaptive themes
|
42
|
+
if (settings.adaptiveThemes) {
|
43
|
+
this.themeName = schemeToTheme(UnistylesRuntime.colorScheme);
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
// Initial theme
|
47
|
+
this.themeName = typeof settings.initialTheme === 'function' ? settings.initialTheme() : settings.initialTheme;
|
48
|
+
};
|
49
|
+
initBreakpoints = (breakpoints = {}) => {
|
50
|
+
this.breakpoints = breakpoints;
|
51
|
+
Object.entries(breakpoints).sort(([, a], [, b]) => a - b).forEach(([breakpoint, value]) => {
|
52
|
+
if (isServer()) {
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
const mediaQuery = window.matchMedia(`(min-width: ${value}px)`);
|
56
|
+
this.matchingBreakpoints.set(breakpoint, mediaQuery.matches);
|
57
|
+
mediaQuery.addEventListener('change', event => {
|
58
|
+
this.matchingBreakpoints.set(breakpoint, event.matches);
|
59
|
+
UnistylesListener.emitChange(UnistyleDependency.Breakpoints);
|
60
|
+
});
|
61
|
+
});
|
62
|
+
};
|
63
|
+
}
|
64
|
+
export const UnistylesState = new UnistylesStateBuilder();
|
65
|
+
//# sourceMappingURL=state.js.map.map
|
@@ -0,0 +1,2 @@
|
|
1
|
+
{"version":3,"names":["UnistylesRuntime","isServer","schemeToTheme","UnistylesListener","UnistyleDependency","UnistylesStateBuilder","themes","Map","matchingBreakpoints","breakpoint","currentBreakpoint","Array","from","reverse","find","_key","value","hasAdaptiveThemes","init","config","initThemes","initBreakpoints","breakpoints","initSettings","settings","initListeners","Object","entries","forEach","themeName","theme","set","adaptiveThemes","themeNames","keys","initialTheme","length","Error","colorScheme","sort","a","b","mediaQuery","window","matchMedia","matches","addEventListener","event","emitChange","Breakpoints","UnistylesState"],"sourceRoot":"../../../src","sources":["web/state.js"],"mappings":";;AAAA,SAASA,gBAAgB,QAAQ,WAAW;AAC5C,SAASC,QAAQ,EAAEC,aAAa,QAAQ,SAAS;AACjD,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,kBAAkB,QAAQ,yBAAyB;AAC5D,MAAMC,qBAAqB,CAAC;EACxBC,MAAM,GAAG,IAAIC,GAAG,CAAC,CAAC;EAElBC,mBAAmB,GAAG,IAAID,GAAG,CAAC,CAAC;EAC/B,IAAIE,UAAUA,CAAA,EAAG;IACb,MAAM,CAACC,iBAAiB,CAAC,GAAGC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACJ,mBAAmB,CAAC,CAC3DK,OAAO,CAAC,CAAC,CACTC,IAAI,CAAC,CAAC,CAACC,IAAI,EAAEC,KAAK,CAAC,KAAKA,KAAK,CAAC,IAAI,EAAE;IACzC,OAAON,iBAAiB;EAC5B;EAEAO,iBAAiB,GAAG,KAAK;EACzBC,IAAI,GAAIC,MAAM,IAAK;IACf,IAAI,CAACC,UAAU,CAACD,MAAM,CAACb,MAAM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,YAAY,CAAC,CAAC,GAAGX,QAAQ,CAACW,YAAY;EAClH,CAAC;EACDd,eAAe,GAAGA,CAACC,WAAW,GAAG,CAAC,CAAC,KAAK;IACpC,IAAI,CAACA,WAAW,GAAGA,WAAW;IAC9BI,MAAM,CAACC,OAAO,CAACL,WAAW,CAAC,CACtBiB,IAAI,CAAC,CAAC,GAAGC,CAAC,CAAC,EAAE,GAAGC,CAAC,CAAC,KAAKD,CAAC,GAAGC,CAAC,CAAC,CAC7Bb,OAAO,CAAC,CAAC,CAACnB,UAAU,EAAEO,KAAK,CAAC,KAAK;MAClC,IAAIf,QAAQ,CAAC,CAAC,EAAE;QACZ;MACJ;MACA,MAAMyC,UAAU,GAAGC,MAAM,CAACC,UAAU,CAAC,eAAe5B,KAAK,KAAK,CAAC;MAC/D,IAAI,CAACR,mBAAmB,CAACuB,GAAG,CAACtB,UAAU,EAAEiC,UAAU,CAACG,OAAO,CAAC;MAC5DH,UAAU,CAACI,gBAAgB,CAAC,QAAQ,EAAEC,KAAK,IAAI;QAC3C,IAAI,CAACvC,mBAAmB,CAACuB,GAAG,CAACtB,UAAU,EAAEsC,KAAK,CAACF,OAAO,CAAC;QACvD1C,iBAAiB,CAAC6C,UAAU,CAAC5C,kBAAkB,CAAC6C,WAAW,CAAC;MAChE,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC;AACL;AACA,OAAO,MAAMC,cAAc,GAAG,IAAI7C,qBAAqB,CAAC,CAAC","ignoreList":[]}
|
2
|
+
noreList":[]}
|
@@ -0,0 +1,78 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
export const reduceObject = (obj, reducer) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, reducer(value, key)]));
|
4
|
+
export const keyInObject = (obj, key) => key in obj;
|
5
|
+
export const isServer = () => typeof window === 'undefined';
|
6
|
+
/**
|
7
|
+
* Deeply merges properties of passed object
|
8
|
+
*/
|
9
|
+
export const deepMergeObjects = (...sources) => {
|
10
|
+
const target = {};
|
11
|
+
sources.forEach(source => {
|
12
|
+
Object.keys(source).forEach(key => {
|
13
|
+
const sourceValue = source[key];
|
14
|
+
const targetValue = target[key];
|
15
|
+
if (Object(sourceValue) == sourceValue && Object(targetValue) === targetValue) {
|
16
|
+
// @ts-expect-error - can't assign to generic
|
17
|
+
target[key] = deepMergeObjects(targetValue, sourceValue);
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
// @ts-expect-error - can't assign to generic
|
21
|
+
target[key] = sourceValue;
|
22
|
+
});
|
23
|
+
});
|
24
|
+
return target;
|
25
|
+
};
|
26
|
+
export const warn = message => console.warn(`🦄 [react-native-unistyles] ${message}`);
|
27
|
+
export const equal = (a, b) => {
|
28
|
+
if (Object.is(a, b)) {
|
29
|
+
return true;
|
30
|
+
}
|
31
|
+
if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) {
|
32
|
+
return false;
|
33
|
+
}
|
34
|
+
const keysA = Object.keys(a);
|
35
|
+
if (keysA.length !== Object.keys(b).length) {
|
36
|
+
return false;
|
37
|
+
}
|
38
|
+
return keysA.every(key => Object.is(a[key], b[key]) && Object.prototype.hasOwnProperty.call(b, key));
|
39
|
+
};
|
40
|
+
export const generateHash = value => {
|
41
|
+
const str = JSON.stringify(value);
|
42
|
+
let hasher = 5381;
|
43
|
+
let length = str.length;
|
44
|
+
while (length--) hasher = hasher * 33 ^ str.charCodeAt(length);
|
45
|
+
return `unistyles-${(hasher >>> 0).toString(36)}`;
|
46
|
+
};
|
47
|
+
export const createDoubleMap = () => {
|
48
|
+
const map = new Map();
|
49
|
+
return {
|
50
|
+
get: (key, secondKey) => {
|
51
|
+
const mapForKey = map.get(key);
|
52
|
+
if (!mapForKey) {
|
53
|
+
return undefined;
|
54
|
+
}
|
55
|
+
return mapForKey.get(secondKey);
|
56
|
+
},
|
57
|
+
set: (key, secondKey, value) => {
|
58
|
+
const mapForKey = map.get(key) ?? new Map();
|
59
|
+
map.set(key, mapForKey);
|
60
|
+
mapForKey.set(secondKey, value);
|
61
|
+
},
|
62
|
+
delete: (key, secondKey) => {
|
63
|
+
const mapForKey = map.get(key);
|
64
|
+
if (!mapForKey) {
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
mapForKey.delete(secondKey);
|
68
|
+
},
|
69
|
+
forEach: callback => {
|
70
|
+
map.forEach((mapForKey, key) => {
|
71
|
+
mapForKey.forEach((value, secondKey) => {
|
72
|
+
callback(key, secondKey, value);
|
73
|
+
});
|
74
|
+
});
|
75
|
+
}
|
76
|
+
};
|
77
|
+
};
|
78
|
+
//# sourceMappingURL=common.js.mapap
|
@@ -0,0 +1,2 @@
|
|
1
|
+
{"version":3,"names":["reduceObject","obj","reducer","Object","fromEntries","entries","map","key","value","keyInObject","isServer","window","deepMergeObjects","sources","target","forEach","source","keys","sourceValue","targetValue","warn","message","console","equal","a","b","is","keysA","length","every","prototype","hasOwnProperty","call","generateHash","str","JSON","stringify","hasher","charCodeAt","toString","createDoubleMap","Map","get","secondKey","mapForKey","undefined","set","delete","callback"],"sourceRoot":"../../../../src","sources":["web/utils/common.js"],"mappings":";;AAAA,OAAO,MAAMA,YAAY,GAAGA,CAACC,GAAG,EAAEC,OAAO,KAAKC,MAAM,CAACC,WAAW,CAACD,MAAM,CAACE,OAAO,CAACJ,GAAG,CAAC,CAACK,GAAG,CAAC,CAAC,CAACC,GAAG,EAAEC,KAAK,CAAC,KAAK,CAACD,GAAG,EAAEL,OAAO,CAACM,KAAK,EAAED,GAAG,CAAC,CAAC,CAAC,CAAC;AACvI,OAAO,MAAME,WAAW,GAAGA,CAACR,GAAG,EAAEM,GAAG,KAAKA,GAAG,IAAIN,GAAG;AACnD,OAAO,MAAMS,QAAQ,GAAGA,CAAA,KAAM,OAAOC,MAAM,KAAK,WAAW;AAC3D;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,GAAGA,CAAC,GAAGC,OAAO,KAAK;EAC5C,MAAMC,MAAM,GAAG,CAAC,CAAC;EACjBD,OAAO,CAACE,OAAO,CAACC,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