react-native-unistyles 3.0.0-alpha.4 → 3.0.0-alpha.41
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +7 -0
- package/Unistyles.podspec +1 -1
- package/android/CMakeLists.txt +22 -45
- package/android/build.gradle +16 -5
- package/android/src/main/cxx/NativeUnistylesModule.cpp +71 -0
- package/android/src/main/cxx/NativeUnistylesModule.h +42 -0
- package/android/src/main/cxx/cpp-adapter.cpp +8 -86
- package/android/src/main/java/com/unistyles/Equatable.kt +61 -0
- package/android/src/main/java/com/unistyles/NativePlatform+android.kt +294 -0
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +152 -0
- package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +59 -0
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +51 -0
- package/android/src/main/java/com/unistyles/UnistylesPackage.kt +16 -14
- package/cxx/NativePlatform.h +11 -0
- package/cxx/common/Constants.h +4 -0
- package/cxx/common/Helpers.h +140 -5
- package/cxx/core/HostStyle.cpp +10 -6
- package/cxx/core/HostStyle.h +4 -0
- package/cxx/core/StyleSheet.h +0 -2
- package/cxx/core/StyleSheetRegistry.cpp +9 -17
- package/cxx/core/StyleSheetRegistry.h +3 -4
- package/cxx/core/Unistyle.h +8 -11
- package/cxx/core/UnistyleData.h +24 -0
- package/cxx/core/UnistyleWrapper.h +108 -13
- 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 +27 -0
- package/cxx/core/UnistylesRegistry.cpp +123 -83
- package/cxx/core/UnistylesRegistry.h +16 -14
- package/cxx/core/UnistylesState.cpp +29 -8
- package/cxx/core/UnistylesState.h +5 -2
- package/cxx/hybridObjects/HybridNavigationBar.cpp +0 -4
- package/cxx/hybridObjects/HybridNavigationBar.h +3 -4
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +19 -11
- package/cxx/hybridObjects/HybridStatusBar.cpp +0 -4
- package/cxx/hybridObjects/HybridStatusBar.h +3 -4
- package/cxx/hybridObjects/HybridStyleSheet.cpp +154 -23
- package/cxx/hybridObjects/HybridStyleSheet.h +27 -5
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +96 -14
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +19 -3
- package/cxx/parser/Parser.cpp +249 -177
- package/cxx/parser/Parser.h +12 -15
- package/cxx/shadowTree/ShadowLeafUpdate.h +3 -1
- package/cxx/shadowTree/ShadowTrafficController.h +71 -0
- package/cxx/shadowTree/ShadowTreeManager.cpp +28 -19
- package/cxx/shadowTree/ShadowTreeManager.h +3 -2
- package/ios/Equatable.swift +2 -1
- package/ios/Extensions.swift +3 -1
- package/ios/NativePlatform+ios.swift +34 -9
- package/ios/NativePlatform+keyboard.swift +83 -0
- package/ios/NativePlatformListener+ios.swift +36 -24
- package/ios/Unistyles.h +1 -0
- package/ios/UnistylesModuleOnLoad.h +8 -2
- package/ios/UnistylesModuleOnLoad.mm +9 -1
- package/lib/commonjs/components/Display.js +18 -0
- package/lib/commonjs/components/Display.js.map +1 -0
- package/lib/commonjs/components/Hide.js +18 -0
- package/lib/commonjs/components/Hide.js.map +1 -0
- package/lib/commonjs/components/index.js +20 -0
- package/lib/commonjs/components/index.js.map +1 -0
- package/lib/commonjs/components/useMedia.js +59 -0
- package/lib/commonjs/components/useMedia.js.map +1 -0
- package/lib/commonjs/components/useMedia.web.js +43 -0
- package/lib/commonjs/components/useMedia.web.js.map +1 -0
- package/lib/commonjs/core/createUnistylesComponent.js +79 -0
- package/lib/commonjs/core/createUnistylesComponent.js.map +1 -0
- package/lib/commonjs/core/createUnistylesComponent.native.js +82 -0
- package/lib/commonjs/core/createUnistylesComponent.native.js.map +1 -0
- package/lib/commonjs/core/index.js +13 -0
- package/lib/commonjs/core/index.js.map +1 -0
- package/lib/commonjs/index.js +21 -11
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mq.js +25 -12
- package/lib/commonjs/mq.js.map +1 -1
- 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/NavigtionBar/index.js +0 -15
- package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +10 -6
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StatusBar/index.js +0 -5
- package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js +1 -0
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js +1 -3
- 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/types/stylesheet.js.map +1 -1
- package/lib/commonjs/utils.js +26 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/commonjs/web/convert/index.js +79 -0
- package/lib/commonjs/web/convert/index.js.map +1 -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/object/boxShadow.js +59 -0
- package/lib/commonjs/web/convert/object/boxShadow.js.map +1 -0
- package/lib/commonjs/web/convert/object/filter.js +42 -0
- package/lib/commonjs/web/convert/object/filter.js.map +1 -0
- package/lib/commonjs/web/convert/object/index.js +39 -0
- package/lib/commonjs/web/convert/object/index.js.map +1 -0
- package/lib/commonjs/web/convert/object/objectStyle.js +56 -0
- package/lib/commonjs/web/convert/object/objectStyle.js.map +1 -0
- package/lib/commonjs/web/convert/object/transform.js +27 -0
- package/lib/commonjs/web/convert/object/transform.js.map +1 -0
- package/lib/commonjs/web/convert/pseudo.js +10 -0
- package/lib/commonjs/web/convert/pseudo.js.map +1 -0
- package/lib/commonjs/web/convert/shadow/boxShadow.js +62 -0
- package/lib/commonjs/web/convert/shadow/boxShadow.js.map +1 -0
- package/lib/commonjs/web/convert/shadow/getShadowBreakpoints.js +38 -0
- package/lib/commonjs/web/convert/shadow/getShadowBreakpoints.js.map +1 -0
- package/lib/commonjs/web/convert/shadow/index.js +28 -0
- package/lib/commonjs/web/convert/shadow/index.js.map +1 -0
- package/lib/commonjs/web/convert/shadow/textShadow.js +59 -0
- package/lib/commonjs/web/convert/shadow/textShadow.js.map +1 -0
- package/lib/commonjs/web/convert/style.js +93 -0
- package/lib/commonjs/web/convert/style.js.map +1 -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 +59 -0
- package/lib/commonjs/web/convert/utils.js.map +1 -0
- package/lib/commonjs/web/create.js +49 -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 +61 -0
- package/lib/commonjs/web/listener.js.map +1 -0
- package/lib/commonjs/web/mock.js +27 -0
- package/lib/commonjs/web/mock.js.map +1 -0
- package/lib/commonjs/web/registry.js +172 -0
- package/lib/commonjs/web/registry.js.map +1 -0
- package/lib/commonjs/web/runtime.js +173 -0
- package/lib/commonjs/web/runtime.js.map +1 -0
- package/lib/commonjs/web/shadowRegistry.js +142 -0
- package/lib/commonjs/web/shadowRegistry.js.map +1 -0
- package/lib/commonjs/web/state.js +73 -0
- package/lib/commonjs/web/state.js.map +1 -0
- package/lib/commonjs/web/utils/common.js +39 -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 +85 -0
- package/lib/commonjs/web/utils/unistyle.js.map +1 -0
- package/lib/commonjs/web/variants/getVariants.js +39 -0
- package/lib/commonjs/web/variants/getVariants.js.map +1 -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 +59 -0
- package/lib/commonjs/web/variants/useVariants.js.map +1 -0
- package/lib/module/components/Display.js +13 -0
- package/lib/module/components/Display.js.map +1 -0
- package/lib/module/components/Hide.js +13 -0
- package/lib/module/components/Hide.js.map +1 -0
- package/lib/module/components/index.js +5 -0
- package/lib/module/components/index.js.map +1 -0
- package/lib/module/components/useMedia.js +54 -0
- package/lib/module/components/useMedia.js.map +1 -0
- package/lib/module/components/useMedia.web.js +38 -0
- package/lib/module/components/useMedia.web.js.map +1 -0
- package/lib/module/core/createUnistylesComponent.js +72 -0
- package/lib/module/core/createUnistylesComponent.js.map +1 -0
- package/lib/module/core/createUnistylesComponent.native.js +75 -0
- package/lib/module/core/createUnistylesComponent.native.js.map +1 -0
- package/lib/module/core/index.js +4 -0
- package/lib/module/core/index.js.map +1 -0
- package/lib/module/index.js +2 -9
- package/lib/module/index.js.map +1 -1
- package/lib/module/mq.js +21 -11
- package/lib/module/mq.js.map +1 -1
- 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/NavigtionBar/index.js +0 -10
- package/lib/module/specs/NavigtionBar/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +10 -6
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StatusBar/index.js +1 -6
- package/lib/module/specs/StatusBar/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js +1 -0
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js +1 -3
- package/lib/module/specs/UnistylesRuntime/index.js.map +1 -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 +1 -1
- package/lib/module/types/stylesheet.js.map +1 -1
- package/lib/module/utils.js +21 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/module/web/convert/index.js +74 -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/object/boxShadow.js +54 -0
- package/lib/module/web/convert/object/boxShadow.js.map +1 -0
- package/lib/module/web/convert/object/filter.js +37 -0
- package/lib/module/web/convert/object/filter.js.map +1 -0
- package/lib/module/web/convert/object/index.js +6 -0
- package/lib/module/web/convert/object/index.js.map +1 -0
- package/lib/module/web/convert/object/objectStyle.js +51 -0
- package/lib/module/web/convert/object/objectStyle.js.map +1 -0
- package/lib/module/web/convert/object/transform.js +22 -0
- package/lib/module/web/convert/object/transform.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/boxShadow.js +57 -0
- package/lib/module/web/convert/shadow/boxShadow.js.map +1 -0
- package/lib/module/web/convert/shadow/getShadowBreakpoints.js +33 -0
- package/lib/module/web/convert/shadow/getShadowBreakpoints.js.map +1 -0
- package/lib/module/web/convert/shadow/index.js +5 -0
- package/lib/module/web/convert/shadow/index.js.map +1 -0
- package/lib/module/web/convert/shadow/textShadow.js +54 -0
- package/lib/module/web/convert/shadow/textShadow.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/types.js +5 -0
- package/lib/module/web/convert/types.js.map +1 -0
- package/lib/module/web/convert/utils.js +45 -0
- package/lib/module/web/convert/utils.js.map +1 -0
- package/lib/module/web/create.js +44 -0
- package/lib/module/web/create.js.map +1 -0
- package/lib/module/web/index.js +26 -0
- package/lib/module/web/index.js.map +1 -0
- package/lib/module/web/listener.js +57 -0
- package/lib/module/web/listener.js.map +1 -0
- package/lib/module/web/mock.js +23 -0
- package/lib/module/web/mock.js.map +1 -0
- package/lib/module/web/registry.js +168 -0
- package/lib/module/web/registry.js.map +1 -0
- package/lib/module/web/runtime.js +169 -0
- package/lib/module/web/runtime.js.map +1 -0
- package/lib/module/web/shadowRegistry.js +138 -0
- package/lib/module/web/shadowRegistry.js.map +1 -0
- package/lib/module/web/state.js +69 -0
- package/lib/module/web/state.js.map +1 -0
- package/lib/module/web/utils/common.js +28 -0
- package/lib/module/web/utils/common.js.map +1 -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 +72 -0
- package/lib/module/web/utils/unistyle.js.map +1 -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 +54 -0
- package/lib/module/web/variants/useVariants.js.map +1 -0
- package/lib/typescript/src/components/Display.d.ts +7 -0
- package/lib/typescript/src/components/Display.d.ts.map +1 -0
- package/lib/typescript/src/components/Hide.d.ts +7 -0
- package/lib/typescript/src/components/Hide.d.ts.map +1 -0
- package/lib/typescript/src/components/index.d.ts +3 -0
- package/lib/typescript/src/components/index.d.ts.map +1 -0
- package/lib/typescript/src/components/useMedia.d.ts +6 -0
- package/lib/typescript/src/components/useMedia.d.ts.map +1 -0
- package/lib/typescript/src/components/useMedia.web.d.ts +6 -0
- package/lib/typescript/src/components/useMedia.web.d.ts.map +1 -0
- package/lib/typescript/src/core/createUnistylesComponent.d.ts +8 -0
- package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -0
- package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +8 -0
- package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +2 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/mq.d.ts +8 -0
- package/lib/typescript/src/mq.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +7 -5
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.d.ts +0 -1
- package/lib/typescript/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/NavigtionBar/index.d.ts +1 -10
- package/lib/typescript/src/specs/NavigtionBar/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +4 -4
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/types.d.ts +3 -0
- package/lib/typescript/src/specs/ShadowRegistry/types.d.ts.map +1 -1
- package/lib/typescript/src/specs/StatusBar/UnistylesStatusBar.nitro.d.ts +0 -1
- package/lib/typescript/src/specs/StatusBar/UnistylesStatusBar.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/StatusBar/index.d.ts +2 -4
- 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 +1 -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/common.d.ts +1 -0
- package/lib/typescript/src/types/common.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/utils.d.ts +2 -0
- package/lib/typescript/src/utils.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/object/boxShadow.d.ts +9 -0
- package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/object/filter.d.ts +3 -0
- package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/object/index.d.ts +4 -0
- package/lib/typescript/src/web/convert/object/index.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/object/objectStyle.d.ts +5 -0
- package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/object/transform.d.ts +3 -0
- package/lib/typescript/src/web/convert/object/transform.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/boxShadow.d.ts +8 -0
- package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts +2 -0
- package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/shadow/index.d.ts +3 -0
- package/lib/typescript/src/web/convert/shadow/index.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/shadow/textShadow.d.ts +8 -0
- package/lib/typescript/src/web/convert/shadow/textShadow.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/{web → src/web}/convert/types.d.ts +8 -2
- package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/utils.d.ts +12 -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 +5 -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/registry.d.ts +24 -0
- package/lib/typescript/src/web/registry.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/runtime.d.ts +11 -10
- package/lib/typescript/src/web/runtime.d.ts.map +1 -0
- package/lib/typescript/src/web/shadowRegistry.d.ts +17 -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/src/web/utils/common.d.ts +8 -0
- 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_UnistylesNativeMiniRuntime.hpp +57 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +69 -0
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +35 -34
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +15 -6
- 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/Dimensions.kt +1 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/{Func_void_std__vector_UnistyleDependency_.kt → Func_void_UnistylesNativeMiniRuntime.kt} +6 -5
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +46 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +25 -13
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Insets.kt +1 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +2 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistylesNativeMiniRuntime.kt +3 -1
- package/nitrogen/generated/android/unistyles+autolinking.cmake +13 -1
- package/nitrogen/generated/android/unistyles+autolinking.gradle +2 -0
- package/nitrogen/generated/android/{UnistylesOnLoad.cpp → unistylesOnLoad.cpp} +6 -4
- package/nitrogen/generated/android/{UnistylesOnLoad.hpp → unistylesOnLoad.hpp} +1 -1
- package/nitrogen/generated/ios/Unistyles+autolinking.rb +6 -4
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.cpp +25 -0
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +73 -38
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +1 -30
- package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +8 -8
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +4 -16
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +156 -115
- 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 -2
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +6 -3
- package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.cpp +0 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +3 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +5 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.cpp +0 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +3 -1
- 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 +20 -30
- package/plugin/common.js +31 -3
- package/plugin/index.js +107 -18
- package/plugin/ref.js +140 -14
- package/plugin/style.js +208 -22
- package/plugin/stylesheet.js +53 -3
- package/plugin/variants.js +33 -0
- package/src/components/Display.tsx +12 -0
- package/src/components/Hide.tsx +12 -0
- package/src/components/index.ts +2 -0
- package/src/components/useMedia.ts +64 -0
- package/src/components/useMedia.web.ts +47 -0
- package/src/core/createUnistylesComponent.native.tsx +83 -0
- package/src/core/createUnistylesComponent.tsx +84 -0
- package/src/core/index.ts +1 -0
- package/src/index.ts +3 -12
- package/src/mq.ts +27 -9
- package/src/specs/NativePlatform/NativePlatform.nitro.ts +7 -5
- package/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.ts +0 -1
- package/src/specs/NavigtionBar/index.ts +1 -25
- package/src/specs/ShadowRegistry/index.ts +16 -10
- package/src/specs/ShadowRegistry/types.ts +4 -1
- package/src/specs/StatusBar/UnistylesStatusBar.nitro.ts +0 -1
- package/src/specs/StatusBar/index.ts +2 -12
- package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.ts +4 -1
- package/src/specs/StyleSheet/index.ts +6 -1
- package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +1 -1
- package/src/specs/UnistylesRuntime/index.ts +5 -4
- package/src/specs/index.ts +6 -2
- package/src/specs/index.web.ts +1 -1
- package/src/types/breakpoints.ts +25 -13
- package/src/types/common.ts +1 -0
- package/src/types/index.ts +1 -1
- package/src/types/stylesheet.ts +7 -5
- package/src/types/variants.ts +7 -1
- package/src/utils.ts +22 -0
- package/{web → src/web}/convert/index.ts +25 -25
- package/src/web/convert/object/boxShadow.ts +55 -0
- package/src/web/convert/object/filter.ts +39 -0
- package/src/web/convert/object/index.ts +3 -0
- package/src/web/convert/object/objectStyle.ts +69 -0
- package/src/web/convert/object/transform.ts +24 -0
- package/src/web/convert/pseudo.ts +137 -0
- package/src/web/convert/shadow/boxShadow.ts +50 -0
- package/src/web/convert/shadow/getShadowBreakpoints.ts +34 -0
- package/src/web/convert/shadow/index.ts +2 -0
- package/src/web/convert/shadow/textShadow.ts +48 -0
- package/{web → src/web}/convert/style.ts +61 -10
- package/{web → src/web}/convert/types.ts +9 -2
- package/{web → src/web}/convert/utils.ts +11 -5
- package/src/web/create.ts +48 -0
- package/{web → src/web}/index.ts +4 -3
- package/src/web/listener.ts +63 -0
- package/{web → src/web}/mock.ts +3 -14
- package/src/web/registry.ts +215 -0
- package/{web → src/web}/runtime.ts +32 -21
- package/src/web/shadowRegistry.ts +145 -0
- package/src/web/state.ts +94 -0
- package/src/web/utils/common.ts +45 -0
- package/src/web/utils/index.ts +2 -0
- package/src/web/utils/unistyle.ts +108 -0
- package/src/web/variants/getVariants.ts +42 -0
- package/src/web/variants/index.ts +2 -0
- package/src/web/variants/useVariants.ts +65 -0
- package/android/src/main/cxx/helpers.cpp +0 -105
- package/android/src/main/cxx/helpers.h +0 -16
- package/android/src/main/cxx/platform.cpp +0 -170
- package/android/src/main/cxx/platform.h +0 -20
- 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 +0 -2
- 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 +0 -8
- 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 +0 -18
- package/lib/typescript/web/utils.d.ts.map +0 -1
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency_.hpp +0 -60
- 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/boxShadow.ts +0 -72
- package/web/convert/breakpoint.ts +0 -21
- package/web/convert/shadow.ts +0 -68
- package/web/convert/textShadow.ts +0 -69
- package/web/convert/transform.ts +0 -89
- package/web/create.ts +0 -102
- package/web/listener/index.ts +0 -1
- package/web/listener/listener.ts +0 -33
- package/web/mq.ts +0 -19
- 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/web/utils.ts +0 -95
- /package/nitrogen/generated/android/{UnistylesOnLoad.kt → unistylesOnLoad.kt} +0 -0
- /package/{web → src/web}/convert/module.d.ts +0 -0
package/web/convert/transform.ts
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
import { media } from 'typestyle'
|
2
|
-
import type { NestedCSSProperties } from 'typestyle/lib/types'
|
3
|
-
import { deepMergeObjects, keyInObject } from '../utils'
|
4
|
-
import { normalizeNumericValue } from './utils'
|
5
|
-
import { convertBreakpoint } from './breakpoint'
|
6
|
-
|
7
|
-
type Transforms = Array<Record<string, any>>
|
8
|
-
|
9
|
-
const normalizeTransform = (key: string, value: any) => {
|
10
|
-
if (key.includes('scale')) {
|
11
|
-
return value
|
12
|
-
}
|
13
|
-
|
14
|
-
if (typeof value === 'number') {
|
15
|
-
return normalizeNumericValue(value)
|
16
|
-
}
|
17
|
-
|
18
|
-
return value
|
19
|
-
}
|
20
|
-
|
21
|
-
const createTransformValue = (transforms: Transforms) => transforms
|
22
|
-
.map(transform => {
|
23
|
-
const [key] = Object.keys(transform)
|
24
|
-
|
25
|
-
if (!key) {
|
26
|
-
return undefined
|
27
|
-
}
|
28
|
-
|
29
|
-
const value = transform[key]
|
30
|
-
|
31
|
-
switch(key) {
|
32
|
-
case 'matrix':
|
33
|
-
case 'matrix3d':
|
34
|
-
return `${key}(${(value as Array<number>).join(',')})`
|
35
|
-
default:
|
36
|
-
return `${key}(${normalizeTransform(key, value)})`
|
37
|
-
}
|
38
|
-
})
|
39
|
-
.filter(Boolean)
|
40
|
-
.join(' ')
|
41
|
-
|
42
|
-
export const getTransformStyle = (transforms: Transforms): NestedCSSProperties => {
|
43
|
-
const breakpoints = new Set<string>()
|
44
|
-
const normalTransforms: Transforms = []
|
45
|
-
|
46
|
-
transforms.forEach(transform => {
|
47
|
-
const [property] = Object.keys(transform)
|
48
|
-
|
49
|
-
if (!property) {
|
50
|
-
return
|
51
|
-
}
|
52
|
-
|
53
|
-
const value = transform[property]
|
54
|
-
|
55
|
-
if (typeof value === 'object' && !Array.isArray(value)) {
|
56
|
-
Object.keys(value).forEach(breakpoint => breakpoints.add(breakpoint))
|
57
|
-
|
58
|
-
return
|
59
|
-
}
|
60
|
-
|
61
|
-
normalTransforms.push(transform)
|
62
|
-
})
|
63
|
-
|
64
|
-
const breakpointTransforms = Array.from(breakpoints).flatMap(breakpoint => {
|
65
|
-
const transformsPerBreakpoint = transforms.flatMap(transform => {
|
66
|
-
const [property] = Object.keys(transform)
|
67
|
-
|
68
|
-
if (!property) {
|
69
|
-
return []
|
70
|
-
}
|
71
|
-
|
72
|
-
const value = transform[property]
|
73
|
-
|
74
|
-
if (typeof value === 'object' && !Array.isArray(value)) {
|
75
|
-
return keyInObject(value, breakpoint) ? [{ [property]: value[breakpoint] }] : []
|
76
|
-
}
|
77
|
-
|
78
|
-
return []
|
79
|
-
})
|
80
|
-
|
81
|
-
return media(convertBreakpoint(breakpoint), {
|
82
|
-
transform: createTransformValue(transformsPerBreakpoint)
|
83
|
-
})
|
84
|
-
})
|
85
|
-
|
86
|
-
return deepMergeObjects({
|
87
|
-
transform: createTransformValue(normalTransforms)
|
88
|
-
}, ...breakpointTransforms)
|
89
|
-
}
|
package/web/create.ts
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
import type { TypeStyle } from 'typestyle'
|
2
|
-
import type { ReactNativeStyleSheet } from '../src/types'
|
3
|
-
import type { StyleSheetWithSuperPowers, StyleSheet } from '../src/types/stylesheet'
|
4
|
-
import { UnistylesRegistry } from './registry'
|
5
|
-
import { keyInObject, reduceObject, toReactNativeClassName } from './utils'
|
6
|
-
import { UnistylesRuntime } from './runtime'
|
7
|
-
import { createUseVariants } from './useVariants'
|
8
|
-
import { UnistylesListener } from './listener'
|
9
|
-
import type { UnistyleDependency } from '../src/specs/NativePlatform'
|
10
|
-
|
11
|
-
type ListenToDependenciesProps = {
|
12
|
-
value: StyleSheet[keyof StyleSheet],
|
13
|
-
key: PropertyKey,
|
14
|
-
unistyles: TypeStyle,
|
15
|
-
className: string,
|
16
|
-
args?: Array<any>
|
17
|
-
}
|
18
|
-
|
19
|
-
export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
|
20
|
-
const computedStylesheet = typeof stylesheet === 'function'
|
21
|
-
? stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime)
|
22
|
-
: stylesheet
|
23
|
-
|
24
|
-
const listenToDependencies = ({ key, className, unistyles, value, args = [] } : ListenToDependenciesProps) => {
|
25
|
-
const dependencies = ('uni__dependencies' in value ? value['uni__dependencies'] : []) as Array<UnistyleDependency>
|
26
|
-
|
27
|
-
if (dependencies.length === 0) {
|
28
|
-
return
|
29
|
-
}
|
30
|
-
|
31
|
-
return UnistylesListener.addListeners(dependencies, () => {
|
32
|
-
const newComputedStylesheet = typeof stylesheet === 'function'
|
33
|
-
? stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime)
|
34
|
-
: stylesheet
|
35
|
-
|
36
|
-
if (!keyInObject(newComputedStylesheet, key)) {
|
37
|
-
return
|
38
|
-
}
|
39
|
-
|
40
|
-
const value = newComputedStylesheet[key]!
|
41
|
-
const result = typeof value === 'function'
|
42
|
-
? value(...args)
|
43
|
-
: value
|
44
|
-
|
45
|
-
UnistylesRegistry.updateStyles(unistyles, result, className)
|
46
|
-
})
|
47
|
-
}
|
48
|
-
|
49
|
-
const styles = reduceObject(computedStylesheet, (value, key) => {
|
50
|
-
if (typeof value === 'function') {
|
51
|
-
const classNameMap = new Map<number, string>()
|
52
|
-
const unistylesMap = new Map<number, TypeStyle>()
|
53
|
-
const disposeMap = new Map<number, VoidFunction | undefined>()
|
54
|
-
|
55
|
-
return (...args: Array<any>) => {
|
56
|
-
const [id] = args.slice(-1)
|
57
|
-
const result = value(...args.slice(0, -1))
|
58
|
-
const dispose = disposeMap.get(id)
|
59
|
-
const unistyles = unistylesMap.get(id)
|
60
|
-
const className = classNameMap.get(id)
|
61
|
-
|
62
|
-
if (unistyles && className && dispose) {
|
63
|
-
dispose()
|
64
|
-
UnistylesRegistry.updateStyles(unistyles, result, className)
|
65
|
-
disposeMap.set(id, listenToDependencies({
|
66
|
-
key,
|
67
|
-
value,
|
68
|
-
unistyles,
|
69
|
-
className,
|
70
|
-
args
|
71
|
-
}))
|
72
|
-
|
73
|
-
return toReactNativeClassName(className, result)
|
74
|
-
}
|
75
|
-
|
76
|
-
const entry = UnistylesRegistry.createStyles(result, key)
|
77
|
-
|
78
|
-
classNameMap.set(id, entry.className)
|
79
|
-
unistylesMap.set(id, entry.unistyles)
|
80
|
-
disposeMap.set(id, listenToDependencies({
|
81
|
-
key,
|
82
|
-
value,
|
83
|
-
unistyles: entry.unistyles,
|
84
|
-
className: entry.className,
|
85
|
-
args
|
86
|
-
}))
|
87
|
-
|
88
|
-
return toReactNativeClassName(entry.className, result)
|
89
|
-
}
|
90
|
-
}
|
91
|
-
|
92
|
-
const { className, unistyles } = UnistylesRegistry.createStyles(value, key)
|
93
|
-
|
94
|
-
listenToDependencies({ key, value, unistyles, className })
|
95
|
-
|
96
|
-
return toReactNativeClassName(className, value)
|
97
|
-
}) as ReactNativeStyleSheet<StyleSheet>
|
98
|
-
|
99
|
-
createUseVariants(styles)
|
100
|
-
|
101
|
-
return styles
|
102
|
-
}
|
package/web/listener/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export { UnistylesListener } from './listener'
|
package/web/listener/listener.ts
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
import { UnistyleDependency } from '../../src/specs/NativePlatform'
|
2
|
-
import { UnistylesRuntime } from '../runtime'
|
3
|
-
|
4
|
-
export class UnistylesListenerBuilder {
|
5
|
-
private isInitialized = false
|
6
|
-
private listeners = Array.from({ length: Object.keys(UnistyleDependency).length / 2 }, () => new Set<VoidFunction>())
|
7
|
-
|
8
|
-
emitChange = (dependency: UnistyleDependency) => {
|
9
|
-
this.listeners[dependency]?.forEach(listener => listener())
|
10
|
-
}
|
11
|
-
|
12
|
-
initListeners = () => {
|
13
|
-
if (this.isInitialized) {
|
14
|
-
return
|
15
|
-
}
|
16
|
-
|
17
|
-
this.isInitialized = true
|
18
|
-
UnistylesRuntime.darkMedia?.addEventListener('change', () => this.emitChange(UnistyleDependency.ColorScheme))
|
19
|
-
UnistylesRuntime.lightMedia?.addEventListener('change', () => this.emitChange(UnistyleDependency.ColorScheme))
|
20
|
-
window.addEventListener('orientationchange', () => this.emitChange(UnistyleDependency.Orientation))
|
21
|
-
window.addEventListener('resize', () => this.emitChange(UnistyleDependency.Dimensions))
|
22
|
-
}
|
23
|
-
|
24
|
-
addListeners = (dependencies: Array<UnistyleDependency>, listener: VoidFunction) => {
|
25
|
-
dependencies.forEach(dependency => this.listeners[dependency]?.add(listener))
|
26
|
-
|
27
|
-
return () => {
|
28
|
-
dependencies.forEach(dependency => this.listeners[dependency]?.delete(listener))
|
29
|
-
}
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
export const UnistylesListener = new UnistylesListenerBuilder()
|
package/web/mq.ts
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
import type { MediaQuery } from 'typestyle/lib/types'
|
2
|
-
|
3
|
-
const IS_UNISTYLES_REGEX = /:([hw])\[(\d+)(?:,\s*(\d+|Infinity))?]/
|
4
|
-
const UNISTYLES_WIDTH_REGEX = /:(w)\[(\d+)(?:,\s*(\d+|Infinity))?]/
|
5
|
-
const UNISTYLES_HEIGHT_REGEX = /:(h)\[(\d+)(?:,\s*(\d+|Infinity))?]/
|
6
|
-
|
7
|
-
export const parseMq = (mq: string): MediaQuery => {
|
8
|
-
const [, width, fromW, toW] = UNISTYLES_WIDTH_REGEX.exec(mq) || []
|
9
|
-
const [, height, fromH, toH] = UNISTYLES_HEIGHT_REGEX.exec(mq) || []
|
10
|
-
|
11
|
-
return {
|
12
|
-
minWidth: !width || fromW === 'Infinity' ? undefined : Number(fromW),
|
13
|
-
maxWidth: !width || toW === 'Infinity' ? undefined : Number(toW),
|
14
|
-
minHeight: !height || fromH === 'Infinity' ? undefined : Number(fromH),
|
15
|
-
maxHeight: !height || toH === 'Infinity' ? undefined : Number(toH),
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
export const isUnistylesMq = (mq: string) => IS_UNISTYLES_REGEX.test(mq)
|
package/web/pseudo.ts
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
// TODO: Add complete list of pseudo selectors
|
2
|
-
export const pseudos = [
|
3
|
-
'_hover',
|
4
|
-
'_css',
|
5
|
-
'_before',
|
6
|
-
'_after'
|
7
|
-
] as const
|
8
|
-
|
9
|
-
export const isPseudo = (selector: string) => pseudos.includes(selector as Pseudo)
|
10
|
-
|
11
|
-
export type Pseudo = typeof pseudos[number]
|
package/web/registry.ts
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
import { createTypeStyle, TypeStyle } from 'typestyle'
|
2
|
-
import type { UnistylesValues } from '../src/types'
|
3
|
-
import { convertToTypeStyle } from './convert'
|
4
|
-
import { UnistylesState } from './state'
|
5
|
-
|
6
|
-
class UnistylesRegistryBuilder {
|
7
|
-
createStyles = (stylesheet: UnistylesValues, key: string | number) => {
|
8
|
-
const stylesTag = UnistylesState.createTag()
|
9
|
-
const unistyles = createTypeStyle(stylesTag)
|
10
|
-
const typestyleStylesheet = convertToTypeStyle(stylesheet)
|
11
|
-
|
12
|
-
const className = unistyles.style({
|
13
|
-
$debugName: String(key),
|
14
|
-
}, typestyleStylesheet)
|
15
|
-
|
16
|
-
if (stylesheet._web?._css) {
|
17
|
-
const customClassName = Array.isArray(stylesheet._web._css)
|
18
|
-
? stylesheet._web._css.join(' ')
|
19
|
-
: stylesheet._web._css
|
20
|
-
|
21
|
-
return {
|
22
|
-
className: `${className} ${customClassName}`,
|
23
|
-
unistyles
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
27
|
-
return {
|
28
|
-
className,
|
29
|
-
unistyles
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
updateStyles = (unistyles: TypeStyle, stylesheet: UnistylesValues, className: string) => {
|
34
|
-
const typestyleStylesheet = convertToTypeStyle(stylesheet)
|
35
|
-
|
36
|
-
unistyles.reinit()
|
37
|
-
unistyles.cssRule(`.${className}`, typestyleStylesheet)
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
export const UnistylesRegistry = new UnistylesRegistryBuilder()
|
package/web/state.ts
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
import { type ReactElement, createElement, createRef } from 'react'
|
2
|
-
import type { UnistylesTheme } from '../src/types'
|
3
|
-
import type { UnistylesConfig } from '../src/specs/StyleSheet'
|
4
|
-
import type { AppBreakpoint, AppThemeName } from '../src/specs/types'
|
5
|
-
import type { UnistylesBreakpoints, UnistylesThemes } from '../src/global'
|
6
|
-
import { UnistylesRuntime } from './runtime'
|
7
|
-
import { isServer, schemeToTheme } from './utils'
|
8
|
-
import { UnistylesListener } from './listener'
|
9
|
-
import { UnistyleDependency } from '../src/specs/NativePlatform'
|
10
|
-
|
11
|
-
class UnistylesStateBuilder {
|
12
|
-
private readonly isSSR = isServer()
|
13
|
-
readonly tags = [] as Array<ReactElement>
|
14
|
-
|
15
|
-
themes = new Map<string, UnistylesTheme>()
|
16
|
-
themeName?: AppThemeName
|
17
|
-
|
18
|
-
breakpoint?: AppBreakpoint
|
19
|
-
breakpoints?: UnistylesBreakpoints
|
20
|
-
|
21
|
-
hasAdaptiveThemes = false
|
22
|
-
|
23
|
-
init = (config: UnistylesConfig) => {
|
24
|
-
this.initThemes(config.themes)
|
25
|
-
this.initBreakpoints(config.breakpoints)
|
26
|
-
this.initSettings(config.settings)
|
27
|
-
|
28
|
-
if (this.isSSR) {
|
29
|
-
return
|
30
|
-
}
|
31
|
-
|
32
|
-
UnistylesListener.initListeners()
|
33
|
-
}
|
34
|
-
|
35
|
-
private initThemes = (themes = {} as UnistylesThemes) => {
|
36
|
-
Object.entries(themes).forEach(([themeName, theme]) => {
|
37
|
-
this.themes.set(themeName, theme)
|
38
|
-
})
|
39
|
-
}
|
40
|
-
|
41
|
-
private initSettings = (settings: UnistylesConfig['settings']) => {
|
42
|
-
this.hasAdaptiveThemes = settings?.adaptiveThemes ?? false
|
43
|
-
const themeNames = Array.from(this.themes.keys()) as Array<AppThemeName>
|
44
|
-
|
45
|
-
// Single theme + no settings
|
46
|
-
if (!settings?.adaptiveThemes && !settings?.initialTheme && themeNames.length === 1) {
|
47
|
-
this.themeName = themeNames[0]
|
48
|
-
|
49
|
-
return
|
50
|
-
}
|
51
|
-
|
52
|
-
// No settings
|
53
|
-
if (!settings?.adaptiveThemes && !settings?.initialTheme) {
|
54
|
-
throw new Error('🦄 You need to specify either "initialTheme" or "adaptiveThemes" in your config')
|
55
|
-
}
|
56
|
-
|
57
|
-
// Adaptive themes
|
58
|
-
if (settings.adaptiveThemes) {
|
59
|
-
this.themeName = schemeToTheme(UnistylesRuntime.colorScheme)
|
60
|
-
|
61
|
-
return
|
62
|
-
}
|
63
|
-
|
64
|
-
// Initial theme
|
65
|
-
this.themeName = typeof settings.initialTheme === 'function' ? settings.initialTheme() : settings.initialTheme
|
66
|
-
}
|
67
|
-
|
68
|
-
private initBreakpoints = (breakpoints = {} as UnistylesBreakpoints) => {
|
69
|
-
const breakpointsMap = new Map<string, MediaQueryList>()
|
70
|
-
|
71
|
-
this.breakpoints = breakpoints
|
72
|
-
|
73
|
-
Object.entries(breakpoints)
|
74
|
-
.sort(([, a], [, b]) => a - b)
|
75
|
-
.forEach(([breakpoint, value]) => {
|
76
|
-
if (isServer()) {
|
77
|
-
return
|
78
|
-
}
|
79
|
-
|
80
|
-
const mediaQuery = window.matchMedia(`(min-width: ${value}px)`)
|
81
|
-
breakpointsMap.set(breakpoint, mediaQuery)
|
82
|
-
|
83
|
-
if (mediaQuery.matches) {
|
84
|
-
this.breakpoint = breakpoint as AppBreakpoint
|
85
|
-
}
|
86
|
-
|
87
|
-
mediaQuery.addEventListener('change', event => {
|
88
|
-
if (!event.matches) {
|
89
|
-
const [currentBreakpoint] = Array.from(breakpointsMap).find(([,mq]) => mq.matches) ?? []
|
90
|
-
|
91
|
-
if (currentBreakpoint) {
|
92
|
-
this.breakpoint = currentBreakpoint as AppBreakpoint
|
93
|
-
UnistylesListener.emitChange(UnistyleDependency.Breakpoints)
|
94
|
-
}
|
95
|
-
|
96
|
-
return
|
97
|
-
}
|
98
|
-
|
99
|
-
this.breakpoint = breakpoint as AppBreakpoint
|
100
|
-
UnistylesListener.emitChange(UnistyleDependency.Breakpoints)
|
101
|
-
})
|
102
|
-
})
|
103
|
-
}
|
104
|
-
|
105
|
-
createTag() {
|
106
|
-
if (!this.isSSR) {
|
107
|
-
const tag = document.createElement('style')
|
108
|
-
|
109
|
-
document.head.appendChild(tag)
|
110
|
-
|
111
|
-
return tag
|
112
|
-
}
|
113
|
-
|
114
|
-
const tagRef = new Proxy(createRef<HTMLStyleElement>(), {
|
115
|
-
set: (target, prop, value) => {
|
116
|
-
// When ref is assigned
|
117
|
-
if ('textContent' in value) {
|
118
|
-
value.textContent = tag.textContent
|
119
|
-
}
|
120
|
-
|
121
|
-
return Reflect.set(target, prop, value)
|
122
|
-
}
|
123
|
-
})
|
124
|
-
const tagElement = createElement('style', { ref: tagRef, key: this.tags.length }, '')
|
125
|
-
const tag = new Proxy({ textContent: '' }, {
|
126
|
-
set: (target, prop, value) => {
|
127
|
-
if (prop !== 'textContent') {
|
128
|
-
return false
|
129
|
-
}
|
130
|
-
|
131
|
-
// When css is updated
|
132
|
-
target.textContent = value
|
133
|
-
|
134
|
-
if (tagRef.current) {
|
135
|
-
tagRef.current.textContent = value
|
136
|
-
}
|
137
|
-
|
138
|
-
return true
|
139
|
-
}
|
140
|
-
})
|
141
|
-
|
142
|
-
this.tags.push(tagElement)
|
143
|
-
|
144
|
-
return tag
|
145
|
-
}
|
146
|
-
}
|
147
|
-
|
148
|
-
export const UnistylesState = new UnistylesStateBuilder()
|
package/web/useVariants.ts
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
import { useMemo, useRef, useState } from 'react'
|
2
|
-
import type { TypeStyle } from 'typestyle'
|
3
|
-
import type { ReactNativeStyleSheet, StyleSheet } from '../src/types'
|
4
|
-
import { deepMergeObjects, equal, reduceObject } from './utils'
|
5
|
-
import { UnistylesRegistry } from './registry'
|
6
|
-
|
7
|
-
type StylesWithVariants = {
|
8
|
-
variants: Record<string, any>,
|
9
|
-
compoundVariants?: Array<Record<string, any> & {
|
10
|
-
styles: Record<string, any>
|
11
|
-
}>
|
12
|
-
}
|
13
|
-
|
14
|
-
const hasVariants = <T extends object>(value: [string, T]): value is [string, T & StylesWithVariants] => 'variants' in value[1]
|
15
|
-
|
16
|
-
export const createUseVariants = (styles: ReactNativeStyleSheet<StyleSheet>) => {
|
17
|
-
const useVariants = (selectedVariants: Record<string, any>) => {
|
18
|
-
const [unistylesMap] = useState(() => new Map<string, TypeStyle>())
|
19
|
-
const [classNameMap] = useState(() => new Map<string, string>())
|
20
|
-
const [selectedVariantStylesMap] = useState(() => new Map<string, Record<string, any>>())
|
21
|
-
const lastSelectedVariantsRef = useRef<Record<string, any>>()
|
22
|
-
// Variable that determines if variants have changed and we need to recalculate styles
|
23
|
-
const variantsChanged = !equal(lastSelectedVariantsRef.current, selectedVariants)
|
24
|
-
|
25
|
-
if (variantsChanged) {
|
26
|
-
lastSelectedVariantsRef.current = selectedVariants
|
27
|
-
}
|
28
|
-
|
29
|
-
const combinedVariantStyles = useMemo(() => {
|
30
|
-
return Object.entries(styles)
|
31
|
-
.filter(hasVariants)
|
32
|
-
.filter(([_key, { variants }]) => Object.keys(variants).some(variant => variant in variants))
|
33
|
-
.map(([key, { variants, compoundVariants = [] }]) => {
|
34
|
-
const variantStyles = Object.entries(variants).flatMap(([variant, styles]) => {
|
35
|
-
const selectedVariant = selectedVariants[variant]
|
36
|
-
const selectedVariantStyles = styles[selectedVariant] ?? styles['default']
|
37
|
-
|
38
|
-
if (!selectedVariantStyles) {
|
39
|
-
return []
|
40
|
-
}
|
41
|
-
|
42
|
-
return selectedVariantStyles
|
43
|
-
})
|
44
|
-
|
45
|
-
const compoundVariantStyles = compoundVariants.flatMap(compoundVariant => {
|
46
|
-
const { styles, ...conditions } = compoundVariant
|
47
|
-
|
48
|
-
if (Object.entries(conditions).some(([variant, value]) => String(selectedVariants[variant]) !== String(value))) {
|
49
|
-
return []
|
50
|
-
}
|
51
|
-
|
52
|
-
return styles
|
53
|
-
})
|
54
|
-
|
55
|
-
const mergedVariantStyles = deepMergeObjects(...variantStyles, ...compoundVariantStyles)
|
56
|
-
|
57
|
-
selectedVariantStylesMap.set(key, mergedVariantStyles)
|
58
|
-
|
59
|
-
return [key, mergedVariantStyles] as const
|
60
|
-
})
|
61
|
-
}, [lastSelectedVariantsRef.current])
|
62
|
-
|
63
|
-
if (unistylesMap.size === 0 && combinedVariantStyles.length > 0) {
|
64
|
-
combinedVariantStyles.forEach(([key, value]) => {
|
65
|
-
const { className, unistyles } = UnistylesRegistry.createStyles(value, `variant-${key}`)
|
66
|
-
|
67
|
-
unistylesMap.set(key, unistyles)
|
68
|
-
classNameMap.set(key, className)
|
69
|
-
})
|
70
|
-
}
|
71
|
-
|
72
|
-
combinedVariantStyles.forEach(([key, value]) => {
|
73
|
-
const styleEntry = styles[key]
|
74
|
-
const unistyles = unistylesMap.get(key)
|
75
|
-
const className = classNameMap.get(key)
|
76
|
-
const selectedVariantStyles = selectedVariantStylesMap.get(key)
|
77
|
-
|
78
|
-
if (!unistyles || !className) {
|
79
|
-
return
|
80
|
-
}
|
81
|
-
|
82
|
-
if (variantsChanged) {
|
83
|
-
UnistylesRegistry.updateStyles(unistyles, value, className)
|
84
|
-
}
|
85
|
-
|
86
|
-
Object.defineProperties(styleEntry, reduceObject(selectedVariantStyles ?? {}, value => ({
|
87
|
-
value,
|
88
|
-
enumerable: false,
|
89
|
-
configurable: true
|
90
|
-
})))
|
91
|
-
// @ts-expect-error - apply variant className
|
92
|
-
styleEntry[className] = className
|
93
|
-
})
|
94
|
-
}
|
95
|
-
|
96
|
-
Object.defineProperty(styles, 'useVariants', {
|
97
|
-
value: useVariants
|
98
|
-
})
|
99
|
-
}
|
package/web/utils.ts
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
import { ColorScheme, type AppThemeName} from '../src/specs/types'
|
2
|
-
import type { UnistylesValues } from '../src/types'
|
3
|
-
|
4
|
-
export const reduceObject = <TObj extends Record<string, any>, TReducer>(
|
5
|
-
obj: TObj,
|
6
|
-
reducer: (value: TObj[keyof TObj], key: keyof TObj) => TReducer,
|
7
|
-
) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, reducer(value as TObj[keyof TObj], key)])) as { [K in keyof TObj]: TReducer }
|
8
|
-
|
9
|
-
export const toReactNativeClassName = (className: string, values: UnistylesValues) => {
|
10
|
-
const returnValue = {
|
11
|
-
$$css: true,
|
12
|
-
[className]: className
|
13
|
-
}
|
14
|
-
|
15
|
-
Object.defineProperties(returnValue, reduceObject(values, value => ({
|
16
|
-
value,
|
17
|
-
enumerable: false,
|
18
|
-
configurable: true
|
19
|
-
})))
|
20
|
-
|
21
|
-
return returnValue
|
22
|
-
}
|
23
|
-
|
24
|
-
export const keyInObject = <T extends Record<string, any>>(obj: T, key: PropertyKey): key is keyof T => key in obj
|
25
|
-
|
26
|
-
export const schemeToTheme = (scheme: ColorScheme): AppThemeName => {
|
27
|
-
switch (scheme) {
|
28
|
-
case ColorScheme.Dark:
|
29
|
-
return 'dark'
|
30
|
-
case ColorScheme.Light:
|
31
|
-
default:
|
32
|
-
return 'light'
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
export const hexToRGBA = (hex: string, opacity: number) => hex
|
37
|
-
.replace('#', '')
|
38
|
-
.split(/(?=(?:..)*$)/)
|
39
|
-
.map(x => parseInt(x, 16))
|
40
|
-
.filter(num => !isNaN(num))
|
41
|
-
.reduce((acc, color) => `${acc}${color},`, 'rgba(')
|
42
|
-
.concat(`${opacity})`)
|
43
|
-
|
44
|
-
export const isServer = () => typeof window === 'undefined'
|
45
|
-
|
46
|
-
/**
|
47
|
-
* Deeply merges properties of passed object
|
48
|
-
*/
|
49
|
-
export const deepMergeObjects = <T extends Record<PropertyKey, any>>(...sources: Array<T>) => {
|
50
|
-
const target = {} as T
|
51
|
-
|
52
|
-
sources.forEach(source => {
|
53
|
-
Object.keys(source).forEach(key => {
|
54
|
-
const sourceValue = source[key]
|
55
|
-
const targetValue = target[key]
|
56
|
-
|
57
|
-
if (Object(sourceValue) == sourceValue && Object(targetValue) === targetValue) {
|
58
|
-
// @ts-expect-error - can't assign to generic
|
59
|
-
target[key] = deepMergeObjects(targetValue, sourceValue)
|
60
|
-
|
61
|
-
return
|
62
|
-
}
|
63
|
-
|
64
|
-
// @ts-expect-error - can't assign to generic
|
65
|
-
target[key] = sourceValue
|
66
|
-
})
|
67
|
-
})
|
68
|
-
|
69
|
-
return target
|
70
|
-
}
|
71
|
-
|
72
|
-
export const warn = (message: string) => console.warn(`🦄 [react-native-unistyles] ${message}`)
|
73
|
-
|
74
|
-
export const equal = <T>(a: T, b: T) => {
|
75
|
-
if (Object.is(a, b)) {
|
76
|
-
return true
|
77
|
-
}
|
78
|
-
|
79
|
-
if (
|
80
|
-
typeof a !== 'object'
|
81
|
-
|| a === null
|
82
|
-
|| typeof b !== 'object'
|
83
|
-
|| b === null
|
84
|
-
) {
|
85
|
-
return false
|
86
|
-
}
|
87
|
-
|
88
|
-
const keysA = Object.keys(a) as Array<keyof T>
|
89
|
-
|
90
|
-
if (keysA.length !== Object.keys(b).length) {
|
91
|
-
return false
|
92
|
-
}
|
93
|
-
|
94
|
-
return keysA.every(key => Object.is(a[key], b[key]) && Object.prototype.hasOwnProperty.call(b, key))
|
95
|
-
}
|
File without changes
|
File without changes
|