react-native-unistyles 3.0.0-alpha.2 → 3.0.0-alpha.21
Sign up to get free protection for your applications and to get access to all the features.
- package/Unistyles.podspec +3 -2
- package/cxx/common/Constants.h +3 -0
- package/cxx/common/Helpers.h +97 -5
- package/cxx/core/HostStyle.cpp +19 -13
- 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 +58 -10
- package/cxx/core/UnistylesCommitHook.cpp +22 -13
- package/cxx/core/UnistylesCommitHook.h +8 -1
- package/cxx/core/UnistylesCommitShadowNode.h +13 -0
- package/cxx/core/UnistylesMountHook.cpp +37 -0
- package/cxx/core/UnistylesMountHook.h +31 -0
- package/cxx/core/UnistylesRegistry.cpp +56 -81
- package/cxx/core/UnistylesRegistry.h +15 -13
- package/cxx/core/UnistylesState.cpp +14 -8
- package/cxx/core/UnistylesState.h +1 -0
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +15 -9
- package/cxx/hybridObjects/HybridStyleSheet.cpp +43 -38
- package/cxx/hybridObjects/HybridStyleSheet.h +10 -7
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +35 -16
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
- package/cxx/parser/Parser.cpp +105 -164
- package/cxx/parser/Parser.h +8 -14
- package/cxx/shadowTree/ShadowLeafUpdate.h +1 -1
- package/cxx/shadowTree/ShadowTrafficController.h +33 -0
- package/cxx/shadowTree/ShadowTreeManager.cpp +13 -11
- package/cxx/shadowTree/ShadowTreeManager.h +1 -0
- package/ios/Unistyles.h +1 -0
- package/ios/UnistylesModuleOnLoad.h +2 -0
- package/ios/UnistylesModuleOnLoad.mm +8 -1
- package/lib/commonjs/index.js +4 -0
- package/lib/commonjs/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/StatusBar/index.js +1 -1
- package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -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.web.js +1 -1
- package/lib/commonjs/web/convert/boxShadow.js +77 -0
- package/lib/commonjs/web/convert/boxShadow.js.map +1 -0
- package/lib/commonjs/web/convert/breakpoint.js +25 -0
- package/lib/commonjs/web/convert/breakpoint.js.map +1 -0
- package/lib/commonjs/web/convert/index.js +76 -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/shadow.js +68 -0
- package/lib/commonjs/web/convert/shadow.js.map +1 -0
- package/lib/commonjs/web/convert/style.js +89 -0
- package/lib/commonjs/web/convert/style.js.map +1 -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 +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 +55 -0
- package/lib/commonjs/web/convert/utils.js.map +1 -0
- package/lib/commonjs/web/create.js +51 -0
- package/lib/commonjs/web/create.js.map +1 -0
- package/lib/commonjs/web/createUnistylesComponent.js +61 -0
- package/lib/commonjs/web/createUnistylesComponent.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/index.js +20 -0
- package/lib/commonjs/web/listener/index.js.map +1 -0
- package/lib/commonjs/web/listener/listenToDependencies.js +38 -0
- package/lib/commonjs/web/listener/listenToDependencies.js.map +1 -0
- package/lib/commonjs/web/listener/listener.js +35 -0
- package/lib/commonjs/web/listener/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/pseudo.js +10 -0
- package/lib/commonjs/web/pseudo.js.map +1 -0
- package/lib/commonjs/web/registry.js +50 -0
- package/lib/commonjs/web/registry.js.map +1 -0
- package/lib/commonjs/web/runtime.js +163 -0
- package/lib/commonjs/web/runtime.js.map +1 -0
- package/lib/commonjs/web/shadowRegistry.js +123 -0
- package/lib/commonjs/web/shadowRegistry.js.map +1 -0
- package/lib/commonjs/web/state.js +81 -0
- package/lib/commonjs/web/state.js.map +1 -0
- package/lib/commonjs/web/utils.js +130 -0
- package/lib/commonjs/web/utils.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/index.js +4 -0
- package/lib/module/index.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/index.js +7 -6
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StatusBar/index.js +1 -1
- package/lib/module/specs/StatusBar/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js +1 -1
- package/lib/module/specs/UnistylesRuntime/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/web/convert/boxShadow.js +72 -0
- package/lib/module/web/convert/boxShadow.js.map +1 -0
- package/lib/module/web/convert/breakpoint.js +20 -0
- package/lib/module/web/convert/breakpoint.js.map +1 -0
- package/lib/module/web/convert/index.js +71 -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/shadow.js +63 -0
- package/lib/module/web/convert/shadow.js.map +1 -0
- package/lib/module/web/convert/style.js +84 -0
- package/lib/module/web/convert/style.js.map +1 -0
- package/lib/module/web/convert/textShadow.js +68 -0
- package/lib/module/web/convert/textShadow.js.map +1 -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 +43 -0
- package/lib/module/web/convert/utils.js.map +1 -0
- package/lib/module/web/create.js +46 -0
- package/lib/module/web/create.js.map +1 -0
- package/lib/module/web/createUnistylesComponent.js +54 -0
- package/lib/module/web/createUnistylesComponent.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/index.js +5 -0
- package/lib/module/web/listener/index.js.map +1 -0
- package/lib/module/web/listener/listenToDependencies.js +33 -0
- package/lib/module/web/listener/listenToDependencies.js.map +1 -0
- package/lib/module/web/listener/listener.js +31 -0
- package/lib/module/web/listener/listener.js.map +1 -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/pseudo.js +5 -0
- package/lib/module/web/pseudo.js.map +1 -0
- package/lib/module/web/registry.js +46 -0
- package/lib/module/web/registry.js.map +1 -0
- package/lib/module/web/runtime.js +159 -0
- package/lib/module/web/runtime.js.map +1 -0
- package/lib/module/web/shadowRegistry.js +119 -0
- package/lib/module/web/shadowRegistry.js.map +1 -0
- package/lib/module/web/state.js +77 -0
- package/lib/module/web/state.js.map +1 -0
- package/lib/module/web/utils.js +112 -0
- package/lib/module/web/utils.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/example/App.d.ts.map +1 -1
- package/lib/typescript/example/Typography.d.ts +12 -0
- package/lib/typescript/example/Typography.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/(tabs)/_layout.d.ts +3 -0
- package/lib/typescript/expo-example/app/(tabs)/_layout.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/(tabs)/explore.d.ts +3 -0
- package/lib/typescript/expo-example/app/(tabs)/explore.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/(tabs)/index.d.ts +3 -0
- package/lib/typescript/expo-example/app/(tabs)/index.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/+html.d.ts +4 -0
- package/lib/typescript/expo-example/app/+html.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/+not-found.d.ts +3 -0
- package/lib/typescript/expo-example/app/+not-found.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/_layout.d.ts +3 -0
- package/lib/typescript/expo-example/app/_layout.d.ts.map +1 -0
- 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/StyleSheet/index.d.ts +2 -1
- package/lib/typescript/src/specs/StyleSheet/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/stylesheet.d.ts +2 -2
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
- package/lib/typescript/src/web/convert/index.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.map +1 -0
- package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -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/{web → src/web}/create.d.ts +11 -11
- package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
- package/lib/typescript/src/web/createUnistylesComponent.d.ts +3 -0
- package/lib/typescript/src/web/createUnistylesComponent.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/index.d.ts +14 -13
- package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener/index.d.ts +3 -0
- package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
- package/lib/typescript/src/web/listener/listenToDependencies.d.ts +12 -0
- package/lib/typescript/src/web/listener/listenToDependencies.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/listener/listener.d.ts +3 -2
- package/lib/typescript/src/web/listener/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.map +1 -0
- package/lib/typescript/src/web/pseudo.d.ts +6 -0
- package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
- package/lib/typescript/src/web/registry.d.ts +15 -0
- package/lib/typescript/src/web/registry.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/runtime.d.ts +6 -7
- 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/{web → src/web}/state.d.ts +4 -9
- package/lib/typescript/src/web/state.d.ts.map +1 -0
- package/lib/typescript/src/web/utils.d.ts +35 -0
- package/lib/typescript/src/web/utils.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++/JHybridNativePlatformSpec.hpp +6 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +8 -3
- package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +14 -2
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +3 -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 +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +4 -1
- package/package.json +3 -3
- package/plugin/__tests__/dependencies.spec.js +199 -111
- package/plugin/__tests__/ref.spec.js +638 -202
- package/plugin/__tests__/stylesheet.spec.js +182 -71
- package/plugin/index.js +110 -23
- package/plugin/ref.js +64 -13
- package/plugin/style.js +82 -22
- package/plugin/stylesheet.js +44 -1
- package/plugin/variants.js +33 -0
- package/src/index.ts +3 -0
- package/src/specs/NavigtionBar/index.ts +1 -1
- package/src/specs/ShadowRegistry/index.ts +10 -9
- package/src/specs/StatusBar/index.ts +1 -1
- package/src/specs/StyleSheet/index.ts +3 -1
- package/src/specs/UnistylesRuntime/index.ts +1 -1
- package/src/specs/index.web.ts +1 -1
- package/src/types/stylesheet.ts +2 -2
- package/{web → src/web}/convert/breakpoint.ts +1 -1
- package/{web → src/web}/convert/index.ts +2 -2
- package/{web → src/web}/convert/types.ts +1 -1
- package/src/web/create.ts +50 -0
- package/src/web/createUnistylesComponent.tsx +54 -0
- package/{web → src/web}/index.ts +3 -2
- package/src/web/listener/index.ts +2 -0
- package/src/web/listener/listenToDependencies.ts +45 -0
- package/{web → src/web}/listener/listener.ts +2 -2
- package/{web → src/web}/mock.ts +2 -12
- package/src/web/pseudo.ts +137 -0
- package/src/web/registry.ts +60 -0
- package/{web → src/web}/runtime.ts +4 -6
- package/src/web/shadowRegistry.ts +124 -0
- package/{web → src/web}/state.ts +5 -49
- package/{web → src/web}/utils.ts +91 -17
- 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/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
- 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.map +0 -1
- package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
- 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/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.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.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/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/useVariants.ts +0 -99
- /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
- /package/{web → src/web}/convert/boxShadow.ts +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/style.ts +0 -0
- /package/{web → src/web}/convert/textShadow.ts +0 -0
- /package/{web → src/web}/convert/transform.ts +0 -0
- /package/{web → src/web}/convert/utils.ts +0 -0
- /package/{web → src/web}/mq.ts +0 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
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
|
+
export const parseMq = mq => {
|
7
|
+
const [, width, fromW, toW] = UNISTYLES_WIDTH_REGEX.exec(mq) || [];
|
8
|
+
const [, height, fromH, toH] = UNISTYLES_HEIGHT_REGEX.exec(mq) || [];
|
9
|
+
return {
|
10
|
+
minWidth: !width || fromW === 'Infinity' ? undefined : Number(fromW),
|
11
|
+
maxWidth: !width || toW === 'Infinity' ? undefined : Number(toW),
|
12
|
+
minHeight: !height || fromH === 'Infinity' ? undefined : Number(fromH),
|
13
|
+
maxHeight: !height || toH === 'Infinity' ? undefined : Number(toH)
|
14
|
+
};
|
15
|
+
};
|
16
|
+
export const isUnistylesMq = mq => IS_UNISTYLES_REGEX.test(mq);
|
17
|
+
//# sourceMappingURL=mq.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["IS_UNISTYLES_REGEX","UNISTYLES_WIDTH_REGEX","UNISTYLES_HEIGHT_REGEX","parseMq","mq","width","fromW","toW","exec","height","fromH","toH","minWidth","undefined","Number","maxWidth","minHeight","maxHeight","isUnistylesMq","test"],"sourceRoot":"../../../src","sources":["web/mq.ts"],"mappings":";;AAEA,MAAMA,kBAAkB,GAAG,wCAAwC;AACnE,MAAMC,qBAAqB,GAAG,qCAAqC;AACnE,MAAMC,sBAAsB,GAAG,qCAAqC;AAEpE,OAAO,MAAMC,OAAO,GAAIC,EAAU,IAAiB;EAC/C,MAAM,GAAGC,KAAK,EAAEC,KAAK,EAAEC,GAAG,CAAC,GAAGN,qBAAqB,CAACO,IAAI,CAACJ,EAAE,CAAC,IAAI,EAAE;EAClE,MAAM,GAAGK,MAAM,EAAEC,KAAK,EAAEC,GAAG,CAAC,GAAGT,sBAAsB,CAACM,IAAI,CAACJ,EAAE,CAAC,IAAI,EAAE;EAEpE,OAAO;IACHQ,QAAQ,EAAE,CAACP,KAAK,IAAIC,KAAK,KAAK,UAAU,GAAGO,SAAS,GAAGC,MAAM,CAACR,KAAK,CAAC;IACpES,QAAQ,EAAE,CAACV,KAAK,IAAIE,GAAG,KAAK,UAAU,GAAGM,SAAS,GAAGC,MAAM,CAACP,GAAG,CAAC;IAChES,SAAS,EAAE,CAACP,MAAM,IAAIC,KAAK,KAAK,UAAU,GAAGG,SAAS,GAAGC,MAAM,CAACJ,KAAK,CAAC;IACtEO,SAAS,EAAE,CAACR,MAAM,IAAIE,GAAG,KAAK,UAAU,GAAGE,SAAS,GAAGC,MAAM,CAACH,GAAG;EACrE,CAAC;AACL,CAAC;AAED,OAAO,MAAMO,aAAa,GAAId,EAAU,IAAKJ,kBAAkB,CAACmB,IAAI,CAACf,EAAE,CAAC","ignoreList":[]}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
export const pseudos = ['_-moz-broken', '_-moz-drag-over', '_-moz-first-node', '_-moz-handler-blocked', '_-moz-handler-crashed', '_-moz-handler-disabled', '_-moz-last-node', '_-moz-loading', '_-moz-locale-dir(ltr)', '_-moz-locale-dir(rtl)', '_-moz-only-whitespace', '_-moz-submit-invalid', '_-moz-suppressed', '_-moz-user-disabled', '_-moz-window-inactive', '_active', '_any-link', '_autofill', '_blank', '_buffering', '_checked', '_current', '_default', '_defined', '_dir(', '_disabled', '_empty', '_enabled', '_first', '_first-child', '_first-of-type', '_focus', '_focus-visible', '_focus-within', '_fullscreen', '_future', '_has(', '_host', '_host-context(', '_host(', '_hover', '_in-range', '_indeterminate', '_invalid', '_is(', '_lang(', '_last-child', '_last-of-type', '_left', '_link', '_local-link', '_modal', '_muted', '_not(', '_nth-child(', '_nth-last-child(', '_nth-last-of-type(', '_nth-of-type(', '_only-child', '_only-of-type', '_optional', '_out-of-range', '_past', '_paused', '_picture-in-picture', '_placeholder-shown', '_playing', '_popover-open', '_read-only', '_read-write', '_required', '_right', '_scope', '_seeking', '_stalled', '_state(', '_target', '_target-within', '_user-invalid', '_user-valid', '_valid', '_visited', '_volume-locked', '_where(', '_-moz-color-swatch', '_-moz-focus-inner', '_-moz-list-bullet', '_-moz-list-number', '_-moz-meter-bar', '_-moz-progress-bar', '_-moz-range-progress', '_-moz-range-thumb', '_-moz-range-track', '_-webkit-inner-spin-button', '_-webkit-meter-barDeprecated', '_-webkit-meter-even-less-good-value', '_-webkit-meter-inner-element', '_-webkit-meter-optimum-value', '_-webkit-meter-suboptimum-value', '_-webkit-progress-bar', '_-webkit-progress-inner-element', '_-webkit-progress-value', '_-webkit-scrollbar', '_-webkit-search-cancel-button', '_-webkit-search-results-button', '_-webkit-slider-runnable-track', '_-webkit-slider-thumb', '_after', '_backdrop', '_before', '_cue', '_file-selector-button', '_first-letter', '_first-line', '_grammar-error', '_highlight(', '_marker', '_part(', '_placeholder', '_selection', '_slotted(', '_spelling-error', '_target-text', '_view-transition', '_view-transition-group', '_view-transition-image-pair', '_view-transition-new', '_view-transition-old'];
|
4
|
+
export const isPseudo = selector => pseudos.some(pseudo => selector.startsWith(pseudo));
|
5
|
+
//# sourceMappingURL=pseudo.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["pseudos","isPseudo","selector","some","pseudo","startsWith"],"sourceRoot":"../../../src","sources":["web/pseudo.ts"],"mappings":";;AAAA,OAAO,MAAMA,OAAO,GAAG,CACnB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EACf,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,SAAS,EACT,WAAW,EACX,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV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,EACd,kBAAkB,EAClB,wBAAwB,EACxB,6BAA6B,EAC7B,sBAAsB,EACtB,sBAAsB,CAChB;AAEV,OAAO,MAAMC,QAAQ,GAAIC,QAAgB,IAAKF,OAAO,CAACG,IAAI,CAACC,MAAM,IAAIF,QAAQ,CAACG,UAAU,CAACD,MAAM,CAAC,CAAC","ignoreList":[]}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
import { createTypeStyle } from 'typestyle';
|
4
|
+
import { convertToTypeStyle } from './convert';
|
5
|
+
import { UnistylesRuntime } from './runtime';
|
6
|
+
import { keyInObject } from './utils';
|
7
|
+
import { UnistylesListener } from './listener';
|
8
|
+
class UnistylesRegistryBuilder {
|
9
|
+
stylesheets = new Map();
|
10
|
+
getComputedStylesheet = stylesheet => {
|
11
|
+
if (typeof stylesheet !== 'function') {
|
12
|
+
return stylesheet;
|
13
|
+
}
|
14
|
+
const computedStylesheet = this.stylesheets.get(stylesheet);
|
15
|
+
if (computedStylesheet) {
|
16
|
+
return computedStylesheet;
|
17
|
+
}
|
18
|
+
const createdStylesheet = stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime);
|
19
|
+
// @ts-expect-error uni__dependencies is hidden
|
20
|
+
const dependencies = Object.values(createdStylesheet).flatMap(value => keyInObject(value, 'uni__dependencies') ? value.uni__dependencies : []);
|
21
|
+
UnistylesListener.addListeners(dependencies, () => {
|
22
|
+
const newComputedStylesheet = stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime);
|
23
|
+
this.stylesheets.set(stylesheet, newComputedStylesheet);
|
24
|
+
});
|
25
|
+
this.stylesheets.set(stylesheet, createdStylesheet);
|
26
|
+
return createdStylesheet;
|
27
|
+
};
|
28
|
+
createStyles = (stylesheet, key) => {
|
29
|
+
const unistyles = createTypeStyle();
|
30
|
+
const typestyleStylesheet = convertToTypeStyle(stylesheet);
|
31
|
+
const className = unistyles.style({
|
32
|
+
$debugName: `${key}-${Math.random().toString(16).slice(10)}`
|
33
|
+
}, typestyleStylesheet);
|
34
|
+
return {
|
35
|
+
className,
|
36
|
+
unistyles
|
37
|
+
};
|
38
|
+
};
|
39
|
+
updateStyles = (unistyles, stylesheet, className) => {
|
40
|
+
const typestyleStylesheet = convertToTypeStyle(stylesheet);
|
41
|
+
unistyles.reinit();
|
42
|
+
unistyles.cssRule(`.${className}`, typestyleStylesheet);
|
43
|
+
};
|
44
|
+
}
|
45
|
+
export const UnistylesRegistry = new UnistylesRegistryBuilder();
|
46
|
+
//# sourceMappingURL=registry.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["createTypeStyle","convertToTypeStyle","UnistylesRuntime","keyInObject","UnistylesListener","UnistylesRegistryBuilder","stylesheets","Map","getComputedStylesheet","stylesheet","computedStylesheet","get","createdStylesheet","theme","miniRuntime","dependencies","Object","values","flatMap","value","uni__dependencies","addListeners","newComputedStylesheet","set","createStyles","key","unistyles","typestyleStylesheet","className","style","$debugName","Math","random","toString","slice","updateStyles","reinit","cssRule","UnistylesRegistry"],"sourceRoot":"../../../src","sources":["web/registry.ts"],"mappings":";;AAAA,SAASA,eAAe,QAAmB,WAAW;AAEtD,SAASC,kBAAkB,QAAQ,WAAW;AAE9C,SAASC,gBAAgB,QAAQ,WAAW;AAC5C,SAASC,WAAW,QAAQ,SAAS;AACrC,SAASC,iBAAiB,QAAQ,YAAY;AAE9C,MAAMC,wBAAwB,CAAC;EACnBC,WAAW,GAAG,IAAIC,GAAG,CAAoD,CAAC;EAElFC,qBAAqB,GAAIC,UAAiD,IAAK;IAC3E,IAAI,OAAOA,UAAU,KAAK,UAAU,EAAE;MAClC,OAAOA,UAAU;IACrB;IAEA,MAAMC,kBAAkB,GAAG,IAAI,CAACJ,WAAW,CAACK,GAAG,CAACF,UAAU,CAAC;IAE3D,IAAIC,kBAAkB,EAAE;MACpB,OAAOA,kBAAkB;IAC7B;IAEA,MAAME,iBAAiB,GAAGH,UAAU,CAACP,gBAAgB,CAAC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E,EAAED,mBAAmB,CAAC;EAC3D,CAAC;AACL;AAEA,OAAO,MAAMW,iBAAiB,GAAG,IAAIjC,wBAAwB,CAAC,CAAC","ignoreList":[]}
|
@@ -0,0 +1,159 @@
|
|
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
|
+
if (!this.themeName) {
|
58
|
+
throw new Error('🦄 No theme selected!');
|
59
|
+
}
|
60
|
+
const theme = UnistylesState.themes.get(this.themeName);
|
61
|
+
if (!theme) {
|
62
|
+
throw new Error(`🦄 Theme "${this.themeName}" is not registered!`);
|
63
|
+
}
|
64
|
+
return theme;
|
65
|
+
}
|
66
|
+
get pixelRatio() {
|
67
|
+
return isServer() ? 1 : window.devicePixelRatio;
|
68
|
+
}
|
69
|
+
get screen() {
|
70
|
+
if (isServer()) {
|
71
|
+
return {
|
72
|
+
width: 0,
|
73
|
+
height: 0
|
74
|
+
};
|
75
|
+
}
|
76
|
+
return {
|
77
|
+
width: window.innerWidth,
|
78
|
+
height: window.innerHeight
|
79
|
+
};
|
80
|
+
}
|
81
|
+
get fontScale() {
|
82
|
+
return 1;
|
83
|
+
}
|
84
|
+
get insets() {
|
85
|
+
return {
|
86
|
+
top: 0,
|
87
|
+
bottom: 0,
|
88
|
+
left: 0,
|
89
|
+
right: 0,
|
90
|
+
ime: 0
|
91
|
+
};
|
92
|
+
}
|
93
|
+
get statusBar() {
|
94
|
+
return StatusBar;
|
95
|
+
}
|
96
|
+
get rtl() {
|
97
|
+
return isServer() ? true : document.documentElement.dir === 'rtl';
|
98
|
+
}
|
99
|
+
get hasAdaptiveThemes() {
|
100
|
+
return UnistylesState.hasAdaptiveThemes;
|
101
|
+
}
|
102
|
+
get navigationBar() {
|
103
|
+
return NavigationBar;
|
104
|
+
}
|
105
|
+
get miniRuntime() {
|
106
|
+
return {
|
107
|
+
colorScheme: this.colorScheme,
|
108
|
+
themeName: this.themeName,
|
109
|
+
contentSizeCategory: this.contentSizeCategory,
|
110
|
+
breakpoint: this.breakpoint,
|
111
|
+
orientation: this.orientation,
|
112
|
+
pixelRatio: this.pixelRatio,
|
113
|
+
screen: this.screen,
|
114
|
+
fontScale: this.fontScale,
|
115
|
+
insets: this.insets,
|
116
|
+
statusBar: {
|
117
|
+
width: this.statusBar.width,
|
118
|
+
height: this.statusBar.height
|
119
|
+
},
|
120
|
+
navigationBar: {
|
121
|
+
width: this.navigationBar.width,
|
122
|
+
height: this.navigationBar.height
|
123
|
+
},
|
124
|
+
rtl: this.rtl,
|
125
|
+
hasAdaptiveThemes: this.hasAdaptiveThemes
|
126
|
+
};
|
127
|
+
}
|
128
|
+
setTheme = themeName => {
|
129
|
+
if (themeName === UnistylesRuntime.themeName) {
|
130
|
+
return;
|
131
|
+
}
|
132
|
+
UnistylesState.themeName = themeName;
|
133
|
+
UnistylesListener.emitChange(UnistyleDependency.Theme);
|
134
|
+
UnistylesListener.emitChange(UnistyleDependency.ThemeName);
|
135
|
+
};
|
136
|
+
setAdaptiveThemes = isEnabled => {
|
137
|
+
UnistylesState.hasAdaptiveThemes = isEnabled;
|
138
|
+
if (!isEnabled) {
|
139
|
+
return;
|
140
|
+
}
|
141
|
+
this.setTheme(schemeToTheme(UnistylesRuntime.colorScheme));
|
142
|
+
};
|
143
|
+
setRootViewBackgroundColor = (hex, alpha) => {
|
144
|
+
if (isServer()) {
|
145
|
+
return;
|
146
|
+
}
|
147
|
+
document.documentElement.style.backgroundColor = alpha ? hexToRGBA(hex, alpha) : hex;
|
148
|
+
};
|
149
|
+
setImmersiveMode = () => {};
|
150
|
+
updateTheme = (themeName, updater) => {
|
151
|
+
const oldTheme = UnistylesState.themes.get(themeName);
|
152
|
+
if (!oldTheme) {
|
153
|
+
throw new Error(`🦄 Theme "${themeName}" is not registered!`);
|
154
|
+
}
|
155
|
+
UnistylesState.themes.set(themeName, updater(oldTheme));
|
156
|
+
};
|
157
|
+
}
|
158
|
+
export const UnistylesRuntime = new UnistylesRuntimeBuilder();
|
159
|
+
//# 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","Error","themes","get","pixelRatio","devicePixelRatio","width","height","innerWidth","innerHeight","fontScale","insets","top","bottom","left","right","ime","statusBar","rtl","document","documentElement","dir","hasAdaptiveThemes","navigationBar","miniRuntime","setTheme","UnistylesRuntime","emitChange","Theme","ThemeName","setAdaptiveThemes","isEnabled","setRootViewBackgroundColor","hex","alpha","style","backgroundColor","setImmersiveMode","updateTheme","updater","oldTheme","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,EAA0B;IAC3C,IAAIJ,QAAQ,CAAC,CAAC,EAAE;MACZ,OAAO,IAAI;IACf;IAEA,IAAI,CAAC,IAAI,CAACG,UAAU,EAAE;MAClB,IAAI,CAACA,UAAU,GAAGI,MAAM,CAACC,UAAU,CAAC,+BAA+B,CAAC;IACxE;IAEA,OAAO,IAA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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,CAAC2B,MAAM,CAACC,GAAG,CAACZ,SAAS,CAAC;IAErD,IAAI,CAACiD,QAAQ,EAAE;MACX,MAAM,IAAIvC,KAAK,CAAC,aAAaV,SAAS,sBAAsB,CAAC;IACjE;IAEAhB,cAAc,CAAC2B,MAAM,CAACuC,GAAG,CAAClD,SAAS,EAAEgD,OAAO,CAACC,QAAQ,CAAC,CAAC;EAC3D,CAAC;AACL;AAEA,OAAO,MAAMd,gBAAgB,GAAG,IAAI/C,uBAAuB,CAAC,CAAC","ignoreList":[]}
|
@@ -0,0 +1,119 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
import { listenToDependencies } from './listener';
|
4
|
+
import { UnistylesRegistry } from './registry';
|
5
|
+
import { createDoubleMap, extractHiddenProperties, extractSecrets, isInDocument } from './utils';
|
6
|
+
import { getVariants } from './variants';
|
7
|
+
class UnistylesShadowRegistryBuilder {
|
8
|
+
// MOCKS
|
9
|
+
name = 'UnistylesShadowRegistry';
|
10
|
+
__type = 'web';
|
11
|
+
equals = () => true;
|
12
|
+
toString = () => 'UnistylesShadowRegistry';
|
13
|
+
dispose = () => {};
|
14
|
+
// END MOCKS
|
15
|
+
|
16
|
+
webUnistylesMap = createDoubleMap();
|
17
|
+
disposeMap = createDoubleMap();
|
18
|
+
stylesMap = createDoubleMap();
|
19
|
+
add = (ref, _style, _variants, _args) => {
|
20
|
+
// Style is not provided
|
21
|
+
if (!_style) {
|
22
|
+
return;
|
23
|
+
}
|
24
|
+
|
25
|
+
// Array of styles
|
26
|
+
if (Array.isArray(_style)) {
|
27
|
+
_style.forEach(style => this.add(ref, style, _variants, _args));
|
28
|
+
return;
|
29
|
+
}
|
30
|
+
|
31
|
+
// Not a unistyle
|
32
|
+
if (!Object.keys(_style).some(key => key.startsWith('__uni__'))) {
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
|
36
|
+
// Ref is unmounted, remove style tags from the document
|
37
|
+
if (ref === null) {
|
38
|
+
const secrets = extractSecrets(_style);
|
39
|
+
secrets.forEach(({
|
40
|
+
__uni__refs
|
41
|
+
}) => {
|
42
|
+
__uni__refs.forEach(ref => {
|
43
|
+
if (isInDocument(ref)) {
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
this.remove(ref, _style);
|
47
|
+
});
|
48
|
+
});
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
|
52
|
+
// Ref is not an HTMLElement
|
53
|
+
if (!(ref instanceof HTMLElement)) {
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
extractSecrets(_style).forEach(secret => {
|
57
|
+
const {
|
58
|
+
__uni__key,
|
59
|
+
__uni__stylesheet,
|
60
|
+
__uni__refs,
|
61
|
+
__uni__variants,
|
62
|
+
__uni__args = []
|
63
|
+
} = secret;
|
64
|
+
const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet);
|
65
|
+
const style = newComputedStylesheet[__uni__key];
|
66
|
+
const args = _args ?? __uni__args;
|
67
|
+
const resultHidden = typeof style === 'function' ? style(...args) : style;
|
68
|
+
const result = extractHiddenProperties(resultHidden);
|
69
|
+
const {
|
70
|
+
variants
|
71
|
+
} = Object.fromEntries(getVariants({
|
72
|
+
variants: result
|
73
|
+
}, _variants && Object.keys(_variants).length > 0 ? _variants : __uni__variants));
|
74
|
+
const resultWithVariants = {
|
75
|
+
...result,
|
76
|
+
...variants
|
77
|
+
};
|
78
|
+
const storedWebUnistyle = this.webUnistylesMap.get(ref, __uni__key);
|
79
|
+
const webUnistyle = storedWebUnistyle ?? UnistylesRegistry.createStyles(resultWithVariants, __uni__key);
|
80
|
+
this.webUnistylesMap.set(ref, __uni__key, webUnistyle);
|
81
|
+
this.disposeMap.get(ref, __uni__key)?.();
|
82
|
+
this.disposeMap.set(ref, __uni__key, listenToDependencies({
|
83
|
+
key: __uni__key,
|
84
|
+
stylesheet: __uni__stylesheet,
|
85
|
+
args,
|
86
|
+
className: webUnistyle.className,
|
87
|
+
unistyles: webUnistyle.unistyles
|
88
|
+
}));
|
89
|
+
if (!storedWebUnistyle) {
|
90
|
+
const styleTag = document.createElement('style');
|
91
|
+
const additionalClasses = resultWithVariants?._web?._classNames;
|
92
|
+
if (additionalClasses) {
|
93
|
+
ref.classList.add(...(Array.isArray(additionalClasses) ? additionalClasses : [additionalClasses]));
|
94
|
+
}
|
95
|
+
ref.classList.add(webUnistyle.className);
|
96
|
+
webUnistyle.unistyles.setStylesTarget(styleTag);
|
97
|
+
document.head.appendChild(styleTag);
|
98
|
+
__uni__refs.add(ref);
|
99
|
+
this.stylesMap.set(ref, __uni__key, styleTag);
|
100
|
+
}
|
101
|
+
if (storedWebUnistyle) {
|
102
|
+
UnistylesRegistry.updateStyles(webUnistyle.unistyles, resultWithVariants, webUnistyle.className);
|
103
|
+
}
|
104
|
+
});
|
105
|
+
};
|
106
|
+
remove = (ref, style) => {
|
107
|
+
extractSecrets(style).forEach(({
|
108
|
+
__uni__key
|
109
|
+
}) => {
|
110
|
+
this.webUnistylesMap.delete(ref, __uni__key);
|
111
|
+
this.disposeMap.get(ref, __uni__key)?.();
|
112
|
+
this.disposeMap.delete(ref, __uni__key);
|
113
|
+
this.stylesMap.get(ref, __uni__key)?.remove();
|
114
|
+
this.stylesMap.delete(ref, __uni__key);
|
115
|
+
});
|
116
|
+
};
|
117
|
+
}
|
118
|
+
export const UnistylesShadowRegistry = new UnistylesShadowRegistryBuilder();
|
119
|
+
//# sourceMappingURL=shadowRegistry.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["listenToDependencies","UnistylesRegistry","createDoubleMap","extractHiddenProperties","extractSecrets","isInDocument","getVariants","UnistylesShadowRegistryBuilder","name","__type","equals","toString","dispose","webUnistylesMap","disposeMap","stylesMap","add","ref","_style","_variants","_args","Array","isArray","forEach","style","Object","keys","some","key","startsWith","secrets","__uni__refs","remove","HTMLElement","secret","__uni__key","__uni__stylesheet","__uni__variants","__uni__args","newComputedStylesheet","getComputedStylesheet","args","resultHidden","result","variants","fromEntries","length","resultWithVariants","storedWebUnistyle","get","webUnistyle","createStyles","set","stylesheet","className","unistyles","styleTag","document","createElement","additionalClasses","_web","_classNames","classList","setStylesTarget","head","appendChild","updateStyles","delete","UnistylesShadowRegistry"],"sourceRoot":"../../../src","sources":["web/shadowRegistry.ts"],"mappings":";;AACA,SAASA,oBAAoB,QAAQ,YAAY;AACjD,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,eAAe,EAAEC,uBAAuB,EAAEC,cAAc,EAAEC,YAAY,QAAQ,SAAS;AAChG,SAASC,WAAW,QAAQ,YAAY;AAMxC,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;;EAEiBC,eAAe,GAAGX,eAAe,CAAmC,CAAC;EACrEY,UAAU,GAAGZ,eAAe,CAAgD,CAAC;EAC7Ea,SAAS,GAAGb,eAAe,CAAwC,CAAC;EAErFc,GAAG,GAAGA,CAACC,GAAQ,EAAEC,MAA6B,EAAEC,SAA+B,EAAEC,KAAkB,KAAK;IACpG;IACA,IAAI,CAACF,MAAM,EAAE;MACT;IACJ;;IAEA;IACA,IAAIG,KAAK,CAACC,OAAO,CAACJ,MAAM,CAAC,EAAE;MACvBA,MAAM,CAACK,OAAO,CAACC,KAAK,IAAI,IAAI,CAACR,GAAG,CAACC,GAAG,EAAEO,KAAK,EAAEL,SAAS,EAAEC,KAAK,CAAC,CAAC;MAE/D;IACJ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AW,CAACK,SAAS,CAACQ,eAAe,CAACP,QAAQ,CAAC;QAC/CC,QAAQ,CAACO,IAAI,CAACC,WAAW,CAACT,QAAQ,CAAC;QACnCzB,WAAW,CAACf,GAAG,CAACC,GAAG,CAAC;QACpB,IAAI,CAACF,SAAS,CAACqC,GAAG,CAACnC,GAAG,EAAEkB,UAAU,EAAEqB,QAAQ,CAAC;MACjD;MAEA,IAAIR,iBAAiB,EAAE;QACnB/C,iBAAiB,CAACiE,YAAY,CAAChB,WAAW,CAACK,SAAS,EAAER,kBAAkB,EAAEG,WAAW,CAACI,SAAS,CAAC;MACpG;IACJ,CAAC,CAAC;EACN,CAAC;EAEDtB,MAAM,GAAGA,CAACf,GAAgB,EAAEO,KAAY,KAAK;IACzCpB,cAAc,CAACoB,KAAK,CAAC,CAACD,OAAO,CAAC,CAAC;MAAEY;IAAW,CAAC,KAAK;MAC9C,IAAI,CAACtB,eAAe,CAACsD,MAAM,CAAClD,GAAG,EAAEkB,UAAU,CAAC;MAC5C,IAAI,CAACrB,UAAU,CAACmC,GAAG,CAAChC,GAAG,EAAEkB,UAAU,CAAC,GAAG,CAAC;MACxC,IAAI,CAACrB,UAAU,CAACqD,MAAM,CAAClD,GAAG,EAAEkB,UAAU,CAAC;MACvC,IAAI,CAACpB,SAAS,CAACkC,GAAG,CAAChC,GAAG,EAAEkB,UAAU,CAAC,EAAEH,MAAM,CAAC,CAAC;MAC7C,IAAI,CAACjB,SAAS,CAACoD,MAAM,CAAClD,GAAG,EAAEkB,UAAU,CAAC;IAC1C,CAAC,CAAC;EACN,CAAC;AACL;AAEA,OAAO,MAAMiC,uBAAuB,GAAG,IAAI7D,8BAA8B,CAAC,CAAC","ignoreList":[]}
|
@@ -0,0 +1,77 @@
|
|
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
|
+
isSSR = isServer();
|
9
|
+
themes = new Map();
|
10
|
+
hasAdaptiveThemes = false;
|
11
|
+
init = config => {
|
12
|
+
this.initThemes(config.themes);
|
13
|
+
this.initBreakpoints(config.breakpoints);
|
14
|
+
this.initSettings(config.settings);
|
15
|
+
if (this.isSSR) {
|
16
|
+
return;
|
17
|
+
}
|
18
|
+
UnistylesListener.initListeners();
|
19
|
+
};
|
20
|
+
initThemes = (themes = {}) => {
|
21
|
+
Object.entries(themes).forEach(([themeName, theme]) => {
|
22
|
+
this.themes.set(themeName, theme);
|
23
|
+
});
|
24
|
+
};
|
25
|
+
initSettings = settings => {
|
26
|
+
this.hasAdaptiveThemes = settings?.adaptiveThemes ?? false;
|
27
|
+
const themeNames = Array.from(this.themes.keys());
|
28
|
+
|
29
|
+
// Single theme + no settings
|
30
|
+
if (!settings?.adaptiveThemes && !settings?.initialTheme && themeNames.length === 1) {
|
31
|
+
this.themeName = themeNames[0];
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
|
35
|
+
// No settings
|
36
|
+
if (!settings?.adaptiveThemes && !settings?.initialTheme) {
|
37
|
+
throw new Error('🦄 You need to specify either "initialTheme" or "adaptiveThemes" in your config');
|
38
|
+
}
|
39
|
+
|
40
|
+
// Adaptive themes
|
41
|
+
if (settings.adaptiveThemes) {
|
42
|
+
this.themeName = schemeToTheme(UnistylesRuntime.colorScheme);
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
|
46
|
+
// Initial theme
|
47
|
+
this.themeName = typeof settings.initialTheme === 'function' ? settings.initialTheme() : settings.initialTheme;
|
48
|
+
};
|
49
|
+
initBreakpoints = (breakpoints = {}) => {
|
50
|
+
const breakpointsMap = new Map();
|
51
|
+
this.breakpoints = breakpoints;
|
52
|
+
Object.entries(breakpoints).sort(([, a], [, b]) => a - b).forEach(([breakpoint, value]) => {
|
53
|
+
if (isServer()) {
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
const mediaQuery = window.matchMedia(`(min-width: ${value}px)`);
|
57
|
+
breakpointsMap.set(breakpoint, mediaQuery);
|
58
|
+
if (mediaQuery.matches) {
|
59
|
+
this.breakpoint = breakpoint;
|
60
|
+
}
|
61
|
+
mediaQuery.addEventListener('change', event => {
|
62
|
+
if (!event.matches) {
|
63
|
+
const [currentBreakpoint] = Array.from(breakpointsMap).find(([, mq]) => mq.matches) ?? [];
|
64
|
+
if (currentBreakpoint) {
|
65
|
+
this.breakpoint = currentBreakpoint;
|
66
|
+
UnistylesListener.emitChange(UnistyleDependency.Breakpoints);
|
67
|
+
}
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
this.breakpoint = breakpoint;
|
71
|
+
UnistylesListener.emitChange(UnistyleDependency.Breakpoints);
|
72
|
+
});
|
73
|
+
});
|
74
|
+
};
|
75
|
+
}
|
76
|
+
export const UnistylesState = new UnistylesStateBuilder();
|
77
|
+
//# sourceMappingURL=state.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["UnistylesRuntime","isServer","schemeToTheme","UnistylesListener","UnistyleDependency","UnistylesStateBuilder","isSSR","themes","Map","hasAdaptiveThemes","init","config","initThemes","initBreakpoints","breakpoints","initSettings","settings","initListeners","Object","entries","forEach","themeName","theme","set","adaptiveThemes","themeNames","Array","from","keys","initialTheme","length","Error","colorScheme","breakpointsMap","sort","a","b","breakpoint","value","mediaQuery","window","matchMedia","matches","addEventListener","event","currentBreakpoint","find","mq","emitChange","Breakpoints","UnistylesState"],"sourceRoot":"../../../src","sources":["web/state.ts"],"mappings":";;AAIA,SAASA,gBAAgB,QAAQ,WAAW;AAC5C,SAASC,QAAQ,EAAEC,aAAa,QAAQ,SAAS;AACjD,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,kBAAkB,QAAQ,yBAAyB;AAE5D,MAAMC,qBAAqB,CAAC;EACPC,KAAK,GAAGL,QAAQ,CAAC,CAAC;EAEnCM,MAAM,GAAG,IAAIC,GAAG,C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E;UAEA;QACJ;QAEA,IAAI,CAACZ,UAAU,GAAGA,UAA2B;QAC7ClC,iBAAiB,CAAC6C,UAAU,CAAC5C,kBAAkB,CAAC6C,WAAW,CAAC;MAChE,CAAC,CAAC;IACN,CAAC,CAAC;EACV,CAAC;AACL;AAEA,OAAO,MAAMC,cAAc,GAAG,IAAI7C,qBAAqB,CAAC,CAAC","ignoreList":[]}
|
@@ -0,0 +1,112 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
import { ColorScheme } from '../specs/types';
|
4
|
+
export const reduceObject = (obj, reducer) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, reducer(value, key)]));
|
5
|
+
export const keyInObject = (obj, key) => key in obj;
|
6
|
+
export const schemeToTheme = scheme => {
|
7
|
+
switch (scheme) {
|
8
|
+
case ColorScheme.Dark:
|
9
|
+
return 'dark';
|
10
|
+
case ColorScheme.Light:
|
11
|
+
default:
|
12
|
+
return 'light';
|
13
|
+
}
|
14
|
+
};
|
15
|
+
export const hexToRGBA = (hex, opacity) => hex.replace('#', '').split(/(?=(?:..)*$)/).map(x => parseInt(x, 16)).filter(num => !isNaN(num)).reduce((acc, color) => `${acc}${color},`, 'rgba(').concat(`${opacity})`);
|
16
|
+
export const isServer = () => typeof window === 'undefined';
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Deeply merges properties of passed object
|
20
|
+
*/
|
21
|
+
export const deepMergeObjects = (...sources) => {
|
22
|
+
const target = {};
|
23
|
+
sources.forEach(source => {
|
24
|
+
Object.keys(source).forEach(key => {
|
25
|
+
const sourceValue = source[key];
|
26
|
+
const targetValue = target[key];
|
27
|
+
if (Object(sourceValue) == sourceValue && Object(targetValue) === targetValue) {
|
28
|
+
// @ts-expect-error - can't assign to generic
|
29
|
+
target[key] = deepMergeObjects(targetValue, sourceValue);
|
30
|
+
return;
|
31
|
+
}
|
32
|
+
|
33
|
+
// @ts-expect-error - can't assign to generic
|
34
|
+
target[key] = sourceValue;
|
35
|
+
});
|
36
|
+
});
|
37
|
+
return target;
|
38
|
+
};
|
39
|
+
export const warn = message => console.warn(`🦄 [react-native-unistyles] ${message}`);
|
40
|
+
export const equal = (a, b) => {
|
41
|
+
if (Object.is(a, b)) {
|
42
|
+
return true;
|
43
|
+
}
|
44
|
+
if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) {
|
45
|
+
return false;
|
46
|
+
}
|
47
|
+
const keysA = Object.keys(a);
|
48
|
+
if (keysA.length !== Object.keys(b).length) {
|
49
|
+
return false;
|
50
|
+
}
|
51
|
+
return keysA.every(key => Object.is(a[key], b[key]) && Object.prototype.hasOwnProperty.call(b, key));
|
52
|
+
};
|
53
|
+
export const assignSecrets = (object, secrets) => {
|
54
|
+
// @ts-expect-error - assign secrets to object
|
55
|
+
object[`__uni__secrets__${Math.random().toString(16).slice(2)}`] = secrets;
|
56
|
+
return object;
|
57
|
+
};
|
58
|
+
export const extractSecrets = object => {
|
59
|
+
const secrets = Object.entries(object).reduce((acc, [key, value]) => {
|
60
|
+
if (key.startsWith('__uni__secrets__')) {
|
61
|
+
acc.push(value);
|
62
|
+
}
|
63
|
+
return acc;
|
64
|
+
}, []);
|
65
|
+
return secrets;
|
66
|
+
};
|
67
|
+
export const getStyles = values => {
|
68
|
+
const returnValue = {};
|
69
|
+
Object.defineProperties(returnValue, reduceObject(values, value => ({
|
70
|
+
value,
|
71
|
+
enumerable: false,
|
72
|
+
configurable: true
|
73
|
+
})));
|
74
|
+
return returnValue;
|
75
|
+
};
|
76
|
+
export const createDoubleMap = () => {
|
77
|
+
const map = new Map();
|
78
|
+
return {
|
79
|
+
get: (key, secondKey) => {
|
80
|
+
const mapForKey = map.get(key);
|
81
|
+
if (!mapForKey) {
|
82
|
+
return undefined;
|
83
|
+
}
|
84
|
+
return mapForKey.get(secondKey);
|
85
|
+
},
|
86
|
+
set: (key, secondKey, value) => {
|
87
|
+
const mapForKey = map.get(key) ?? new Map();
|
88
|
+
map.set(key, mapForKey);
|
89
|
+
mapForKey.set(secondKey, value);
|
90
|
+
},
|
91
|
+
delete: (key, secondKey) => {
|
92
|
+
const mapForKey = map.get(key);
|
93
|
+
if (!mapForKey) {
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
mapForKey.delete(secondKey);
|
97
|
+
},
|
98
|
+
forEach: callback => {
|
99
|
+
map.forEach((mapForKey, key) => {
|
100
|
+
mapForKey.forEach((value, secondKey) => {
|
101
|
+
callback(key, secondKey, value);
|
102
|
+
});
|
103
|
+
});
|
104
|
+
}
|
105
|
+
};
|
106
|
+
};
|
107
|
+
export const extractHiddenProperties = object => {
|
108
|
+
const hiddenProperties = Object.getOwnPropertyNames(object);
|
109
|
+
return Object.fromEntries(hiddenProperties.filter(key => !key.startsWith('__uni__')).map(key => [key, object[key]]));
|
110
|
+
};
|
111
|
+
export const isInDocument = element => document.body.contains(element);
|
112
|
+
//# sourceMappingURL=utils.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["ColorScheme","reduceObject","obj","reducer","Object","fromEntries","entries","map","key","value","keyInObject","schemeToTheme","scheme","Dark","Light","hexToRGBA","hex","opacity","replace","split","x","parseInt","filter","num","isNaN","reduce","acc","color","concat","isServer","window","deepMergeObjects","sources","target","forEach","source","keys","sourceValue","targetValue","warn","message","console","equal","a","b","is","keysA","length","every","prototype","hasOwnProperty","call","assignSecrets","object","secrets","Math","random","toString","slice","extractSecrets","startsWith","push","getStyles","values","returnValue","defineProperties","enumerable","configurable","createDoubleMap","Map","get","secondKey","mapForKey","undefined","set","delete","callback","extractHiddenProperties","hiddenProperties","getOwnPropertyNames","isInDocument","element","document","body","contains"],"sourceRoot":"../../../src","sources":["web/utils.ts"],"mappings":";;AAAA,SAASA,WAAW,QAA0B,gBAAgB;AAG9D,OAAO,MAAMC,YAAY,GAAGA,CACxBC,GAAS,EACTC,OAA+D,KAC9DC,MAAM,CAACC,WAAW,CAACD,MAAM,CAACE,OAAO,CAACJ,GAAG,CAAC,CAACK,GAAG,CAAC,CAAC,CAAC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AKC,QAAQ,CAACC,IAAI,CAACC,QAAQ,CAACH,OAAO,CAAC","ignoreList":[]}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
import { deepMergeObjects } from '../utils';
|
4
|
+
const hasVariants = value => 'variants' in value[1];
|
5
|
+
export const getVariants = (styles, selectedVariants) => {
|
6
|
+
return Object.entries(styles).filter(hasVariants).filter(([_key, {
|
7
|
+
variants
|
8
|
+
}]) => Object.keys(variants).some(variant => variant in variants)).map(([key, {
|
9
|
+
variants,
|
10
|
+
compoundVariants = []
|
11
|
+
}]) => {
|
12
|
+
const variantStyles = Object.entries(variants).flatMap(([variant, styles]) => {
|
13
|
+
const selectedVariant = selectedVariants[variant];
|
14
|
+
const selectedVariantStyles = styles[selectedVariant] ?? styles['default'];
|
15
|
+
if (!selectedVariantStyles) {
|
16
|
+
return [];
|
17
|
+
}
|
18
|
+
return selectedVariantStyles;
|
19
|
+
});
|
20
|
+
const compoundVariantStyles = compoundVariants.flatMap(compoundVariant => {
|
21
|
+
const {
|
22
|
+
styles,
|
23
|
+
...conditions
|
24
|
+
} = compoundVariant;
|
25
|
+
if (Object.entries(conditions).some(([variant, value]) => String(selectedVariants[variant]) !== String(value))) {
|
26
|
+
return [];
|
27
|
+
}
|
28
|
+
return styles;
|
29
|
+
});
|
30
|
+
const mergedVariantStyles = deepMergeObjects(...variantStyles, ...compoundVariantStyles);
|
31
|
+
return [key, mergedVariantStyles];
|
32
|
+
});
|
33
|
+
};
|
34
|
+
//# sourceMappingURL=getVariants.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["deepMergeObjects","hasVariants","value","getVariants","styles","selectedVariants","Object","entries","filter","_key","variants","keys","some","variant","map","key","compoundVariants","variantStyles","flatMap","selectedVariant","selectedVariantStyles","compoundVariantStyles","compoundVariant","conditions","String","mergedVariantStyles"],"sourceRoot":"../../../../src","sources":["web/variants/getVariants.ts"],"mappings":";;AACA,SAASA,gBAAgB,QA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