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
package/{web → src/web}/index.ts
RENAMED
@@ -1,5 +1,4 @@
|
|
1
1
|
import { create } from './create'
|
2
|
-
import { UnistylesRuntime } from './runtime'
|
3
2
|
import { UnistylesState } from './state'
|
4
3
|
import { deepMergeObjects } from './utils'
|
5
4
|
|
@@ -19,6 +18,8 @@ export const StyleSheet = {
|
|
19
18
|
}
|
20
19
|
|
21
20
|
export { UnistylesRuntime } from './runtime'
|
21
|
+
export { UnistylesShadowRegistry } from './shadowRegistry'
|
22
22
|
export * from './mock'
|
23
23
|
|
24
|
-
|
24
|
+
// TODO: Work on SSR
|
25
|
+
export const getSSRUnistyles = () => []
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import type { TypeStyle } from 'typestyle'
|
2
|
+
import type { StyleSheet, StyleSheetWithSuperPowers } from '../../types/stylesheet'
|
3
|
+
import type { UnistyleDependency } from '../../specs/NativePlatform'
|
4
|
+
import { UnistylesListener } from './listener'
|
5
|
+
import { keyInObject } from '../utils'
|
6
|
+
import { UnistylesRegistry } from '../registry'
|
7
|
+
|
8
|
+
type ListenToDependenciesProps = {
|
9
|
+
key: PropertyKey,
|
10
|
+
unistyles: TypeStyle,
|
11
|
+
className: string,
|
12
|
+
stylesheet: StyleSheetWithSuperPowers<StyleSheet>
|
13
|
+
args?: Array<any>
|
14
|
+
}
|
15
|
+
|
16
|
+
export const listenToDependencies = ({ key, className, unistyles, args = [], stylesheet }: ListenToDependenciesProps) => {
|
17
|
+
const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(stylesheet)
|
18
|
+
const _value = keyInObject(newComputedStylesheet, key) ? newComputedStylesheet[key] : undefined
|
19
|
+
|
20
|
+
if (!_value) {
|
21
|
+
return
|
22
|
+
}
|
23
|
+
|
24
|
+
const value = typeof _value === 'function' ? _value(...args) : _value
|
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 = UnistylesRegistry.getComputedStylesheet(stylesheet)
|
33
|
+
|
34
|
+
if (!keyInObject(newComputedStylesheet, key)) {
|
35
|
+
return
|
36
|
+
}
|
37
|
+
|
38
|
+
const value = newComputedStylesheet[key]!
|
39
|
+
const result = typeof value === 'function'
|
40
|
+
? value(...args)
|
41
|
+
: value
|
42
|
+
|
43
|
+
UnistylesRegistry.updateStyles(unistyles, result, className)
|
44
|
+
})
|
45
|
+
}
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import { UnistyleDependency } from '../../
|
1
|
+
import { UnistyleDependency } from '../../specs/NativePlatform'
|
2
2
|
import { UnistylesRuntime } from '../runtime'
|
3
3
|
|
4
|
-
|
4
|
+
class UnistylesListenerBuilder {
|
5
5
|
private isInitialized = false
|
6
6
|
private listeners = Array.from({ length: Object.keys(UnistyleDependency).length / 2 }, () => new Set<VoidFunction>())
|
7
7
|
|
package/{web → src/web}/mock.ts
RENAMED
@@ -1,5 +1,5 @@
|
|
1
|
-
import type { UnistylesNavigationBar as NavigationBarSpec } from '../
|
2
|
-
import type { UnistylesStatusBar as StatusBarSpec } from '../
|
1
|
+
import type { UnistylesNavigationBar as NavigationBarSpec } from '../specs/NavigtionBar'
|
2
|
+
import type { UnistylesStatusBar as StatusBarSpec } from '../specs/StatusBar'
|
3
3
|
|
4
4
|
export const StatusBar: StatusBarSpec = {
|
5
5
|
width: 0,
|
@@ -23,13 +23,3 @@ export const NavigationBar: NavigationBarSpec = {
|
|
23
23
|
__type: 'web',
|
24
24
|
name: 'NavigationBar'
|
25
25
|
}
|
26
|
-
|
27
|
-
export const UnistylesShadowRegistry = {
|
28
|
-
name: 'UnistylesShadowRegistry',
|
29
|
-
__type: 'web',
|
30
|
-
equals: () => true,
|
31
|
-
toString: () => 'UnistylesShadowRegistry',
|
32
|
-
dispose: () => {},
|
33
|
-
add: () => {},
|
34
|
-
remove: () => {},
|
35
|
-
}
|
@@ -0,0 +1,137 @@
|
|
1
|
+
export const pseudos = [
|
2
|
+
'_-moz-broken',
|
3
|
+
'_-moz-drag-over',
|
4
|
+
'_-moz-first-node',
|
5
|
+
'_-moz-handler-blocked',
|
6
|
+
'_-moz-handler-crashed',
|
7
|
+
'_-moz-handler-disabled',
|
8
|
+
'_-moz-last-node',
|
9
|
+
'_-moz-loading',
|
10
|
+
'_-moz-locale-dir(ltr)',
|
11
|
+
'_-moz-locale-dir(rtl)',
|
12
|
+
'_-moz-only-whitespace',
|
13
|
+
'_-moz-submit-invalid',
|
14
|
+
'_-moz-suppressed',
|
15
|
+
'_-moz-user-disabled',
|
16
|
+
'_-moz-window-inactive',
|
17
|
+
'_active',
|
18
|
+
'_any-link',
|
19
|
+
'_autofill',
|
20
|
+
'_blank',
|
21
|
+
'_buffering',
|
22
|
+
'_checked',
|
23
|
+
'_current',
|
24
|
+
'_default',
|
25
|
+
'_defined',
|
26
|
+
'_dir(',
|
27
|
+
'_disabled',
|
28
|
+
'_empty',
|
29
|
+
'_enabled',
|
30
|
+
'_first',
|
31
|
+
'_first-child',
|
32
|
+
'_first-of-type',
|
33
|
+
'_focus',
|
34
|
+
'_focus-visible',
|
35
|
+
'_focus-within',
|
36
|
+
'_fullscreen',
|
37
|
+
'_future',
|
38
|
+
'_has(',
|
39
|
+
'_host',
|
40
|
+
'_host-context(',
|
41
|
+
'_host(',
|
42
|
+
'_hover',
|
43
|
+
'_in-range',
|
44
|
+
'_indeterminate',
|
45
|
+
'_invalid',
|
46
|
+
'_is(',
|
47
|
+
'_lang(',
|
48
|
+
'_last-child',
|
49
|
+
'_last-of-type',
|
50
|
+
'_left',
|
51
|
+
'_link',
|
52
|
+
'_local-link',
|
53
|
+
'_modal',
|
54
|
+
'_muted',
|
55
|
+
'_not(',
|
56
|
+
'_nth-child(',
|
57
|
+
'_nth-last-child(',
|
58
|
+
'_nth-last-of-type(',
|
59
|
+
'_nth-of-type(',
|
60
|
+
'_only-child',
|
61
|
+
'_only-of-type',
|
62
|
+
'_optional',
|
63
|
+
'_out-of-range',
|
64
|
+
'_past',
|
65
|
+
'_paused',
|
66
|
+
'_picture-in-picture',
|
67
|
+
'_placeholder-shown',
|
68
|
+
'_playing',
|
69
|
+
'_popover-open',
|
70
|
+
'_read-only',
|
71
|
+
'_read-write',
|
72
|
+
'_required',
|
73
|
+
'_right',
|
74
|
+
'_scope',
|
75
|
+
'_seeking',
|
76
|
+
'_stalled',
|
77
|
+
'_state(',
|
78
|
+
'_target',
|
79
|
+
'_target-within',
|
80
|
+
'_user-invalid',
|
81
|
+
'_user-valid',
|
82
|
+
'_valid',
|
83
|
+
'_visited',
|
84
|
+
'_volume-locked',
|
85
|
+
'_where(',
|
86
|
+
'_-moz-color-swatch',
|
87
|
+
'_-moz-focus-inner',
|
88
|
+
'_-moz-list-bullet',
|
89
|
+
'_-moz-list-number',
|
90
|
+
'_-moz-meter-bar',
|
91
|
+
'_-moz-progress-bar',
|
92
|
+
'_-moz-range-progress',
|
93
|
+
'_-moz-range-thumb',
|
94
|
+
'_-moz-range-track',
|
95
|
+
'_-webkit-inner-spin-button',
|
96
|
+
'_-webkit-meter-barDeprecated',
|
97
|
+
'_-webkit-meter-even-less-good-value',
|
98
|
+
'_-webkit-meter-inner-element',
|
99
|
+
'_-webkit-meter-optimum-value',
|
100
|
+
'_-webkit-meter-suboptimum-value',
|
101
|
+
'_-webkit-progress-bar',
|
102
|
+
'_-webkit-progress-inner-element',
|
103
|
+
'_-webkit-progress-value',
|
104
|
+
'_-webkit-scrollbar',
|
105
|
+
'_-webkit-search-cancel-button',
|
106
|
+
'_-webkit-search-results-button',
|
107
|
+
'_-webkit-slider-runnable-track',
|
108
|
+
'_-webkit-slider-thumb',
|
109
|
+
'_after',
|
110
|
+
'_backdrop',
|
111
|
+
'_before',
|
112
|
+
'_cue',
|
113
|
+
'_file-selector-button',
|
114
|
+
'_first-letter',
|
115
|
+
'_first-line',
|
116
|
+
'_grammar-error',
|
117
|
+
'_highlight(',
|
118
|
+
'_marker',
|
119
|
+
'_part(',
|
120
|
+
'_placeholder',
|
121
|
+
'_selection',
|
122
|
+
'_slotted(',
|
123
|
+
'_spelling-error',
|
124
|
+
'_target-text',
|
125
|
+
'_view-transition',
|
126
|
+
'_view-transition-group',
|
127
|
+
'_view-transition-image-pair',
|
128
|
+
'_view-transition-new',
|
129
|
+
'_view-transition-old',
|
130
|
+
] as const
|
131
|
+
|
132
|
+
export const isPseudo = (selector: string) => pseudos.some(pseudo => selector.startsWith(pseudo))
|
133
|
+
|
134
|
+
type AddDynamicSelector<T extends string> = T extends `${infer U}(` ? `${U}(${string})` : T
|
135
|
+
|
136
|
+
export type Pseudo = AddDynamicSelector<typeof pseudos[number]>
|
137
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import { createTypeStyle, TypeStyle } from 'typestyle'
|
2
|
+
import type { UnistylesValues } from '../types'
|
3
|
+
import { convertToTypeStyle } from './convert'
|
4
|
+
import type { StyleSheet, StyleSheetWithSuperPowers } from '../types/stylesheet'
|
5
|
+
import { UnistylesRuntime } from './runtime'
|
6
|
+
import { keyInObject } from './utils'
|
7
|
+
import { UnistylesListener } from './listener'
|
8
|
+
|
9
|
+
class UnistylesRegistryBuilder {
|
10
|
+
private stylesheets = new Map<StyleSheetWithSuperPowers<StyleSheet>, StyleSheet>()
|
11
|
+
|
12
|
+
getComputedStylesheet = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
|
13
|
+
if (typeof stylesheet !== 'function') {
|
14
|
+
return stylesheet
|
15
|
+
}
|
16
|
+
|
17
|
+
const computedStylesheet = this.stylesheets.get(stylesheet)
|
18
|
+
|
19
|
+
if (computedStylesheet) {
|
20
|
+
return computedStylesheet
|
21
|
+
}
|
22
|
+
|
23
|
+
const createdStylesheet = stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime)
|
24
|
+
// @ts-expect-error uni__dependencies is hidden
|
25
|
+
const dependencies = Object.values(createdStylesheet).flatMap(value => keyInObject(value, 'uni__dependencies') ? value.uni__dependencies : [])
|
26
|
+
|
27
|
+
UnistylesListener.addListeners(dependencies, () => {
|
28
|
+
const newComputedStylesheet = stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime)
|
29
|
+
|
30
|
+
this.stylesheets.set(stylesheet, newComputedStylesheet)
|
31
|
+
})
|
32
|
+
|
33
|
+
this.stylesheets.set(stylesheet, createdStylesheet)
|
34
|
+
|
35
|
+
return createdStylesheet
|
36
|
+
}
|
37
|
+
|
38
|
+
createStyles = (stylesheet: UnistylesValues, key: string) => {
|
39
|
+
const unistyles = createTypeStyle()
|
40
|
+
const typestyleStylesheet = convertToTypeStyle(stylesheet)
|
41
|
+
|
42
|
+
const className = unistyles.style({
|
43
|
+
$debugName: `${key}-${Math.random().toString(16).slice(10)}`,
|
44
|
+
}, typestyleStylesheet)
|
45
|
+
|
46
|
+
return {
|
47
|
+
className,
|
48
|
+
unistyles
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
updateStyles = (unistyles: TypeStyle, stylesheet: UnistylesValues, className: string) => {
|
53
|
+
const typestyleStylesheet = convertToTypeStyle(stylesheet)
|
54
|
+
|
55
|
+
unistyles.reinit()
|
56
|
+
unistyles.cssRule(`.${className}`, typestyleStylesheet)
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
export const UnistylesRegistry = new UnistylesRegistryBuilder()
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import { UnistyleDependency } from '../
|
2
|
-
import { ColorScheme, Orientation, type AppTheme, type AppThemeName } from '../
|
3
|
-
import type { UnistylesMiniRuntime } from '../
|
4
|
-
import { WebContentSizeCategory } from '../
|
1
|
+
import { UnistyleDependency } from '../specs/NativePlatform'
|
2
|
+
import { ColorScheme, Orientation, type AppTheme, type AppThemeName } from '../specs/types'
|
3
|
+
import type { UnistylesMiniRuntime } from '../specs/UnistylesRuntime'
|
4
|
+
import { WebContentSizeCategory } from '../types'
|
5
5
|
import { UnistylesListener } from './listener'
|
6
6
|
import { NavigationBar, StatusBar } from './mock'
|
7
7
|
import { UnistylesState } from './state'
|
@@ -191,8 +191,6 @@ class UnistylesRuntimeBuilder {
|
|
191
191
|
|
192
192
|
UnistylesState.themes.set(themeName, updater(oldTheme))
|
193
193
|
}
|
194
|
-
|
195
|
-
getSSRUnistyles = () => UnistylesState.tags
|
196
194
|
}
|
197
195
|
|
198
196
|
export const UnistylesRuntime = new UnistylesRuntimeBuilder()
|
@@ -0,0 +1,124 @@
|
|
1
|
+
import type { UnistylesValues } from '../types'
|
2
|
+
import { listenToDependencies } from './listener'
|
3
|
+
import { UnistylesRegistry } from './registry'
|
4
|
+
import { createDoubleMap, extractHiddenProperties, extractSecrets, isInDocument } from './utils'
|
5
|
+
import { getVariants } from './variants'
|
6
|
+
|
7
|
+
type WebUnistyle = ReturnType<typeof UnistylesRegistry.createStyles>
|
8
|
+
|
9
|
+
type Style = UnistylesValues | ((...args: Array<any>) => UnistylesValues)
|
10
|
+
|
11
|
+
class UnistylesShadowRegistryBuilder {
|
12
|
+
// MOCKS
|
13
|
+
name = 'UnistylesShadowRegistry'
|
14
|
+
__type = 'web'
|
15
|
+
equals = () => true
|
16
|
+
toString = () => 'UnistylesShadowRegistry'
|
17
|
+
dispose = () => {}
|
18
|
+
// END MOCKS
|
19
|
+
|
20
|
+
private readonly webUnistylesMap = createDoubleMap<HTMLElement, string, WebUnistyle>()
|
21
|
+
private readonly disposeMap = createDoubleMap<HTMLElement, string, VoidFunction | undefined>()
|
22
|
+
private readonly stylesMap = createDoubleMap<HTMLElement, string, HTMLStyleElement>()
|
23
|
+
|
24
|
+
add = (ref: any, _style?: Style | Array<Style>, _variants?: Record<string, any>, _args?: Array<any>) => {
|
25
|
+
// Style is not provided
|
26
|
+
if (!_style) {
|
27
|
+
return
|
28
|
+
}
|
29
|
+
|
30
|
+
// Array of styles
|
31
|
+
if (Array.isArray(_style)) {
|
32
|
+
_style.forEach(style => this.add(ref, style, _variants, _args))
|
33
|
+
|
34
|
+
return
|
35
|
+
}
|
36
|
+
|
37
|
+
// Not a unistyle
|
38
|
+
if (!Object.keys(_style).some(key => key.startsWith('__uni__'))) {
|
39
|
+
return
|
40
|
+
}
|
41
|
+
|
42
|
+
// Ref is unmounted, remove style tags from the document
|
43
|
+
if (ref === null) {
|
44
|
+
const secrets = extractSecrets(_style)
|
45
|
+
|
46
|
+
secrets.forEach(({ __uni__refs }) => {
|
47
|
+
__uni__refs.forEach(ref => {
|
48
|
+
if (isInDocument(ref)) {
|
49
|
+
return
|
50
|
+
}
|
51
|
+
|
52
|
+
this.remove(ref, _style)
|
53
|
+
})
|
54
|
+
})
|
55
|
+
|
56
|
+
return
|
57
|
+
}
|
58
|
+
|
59
|
+
// Ref is not an HTMLElement
|
60
|
+
if (!(ref instanceof HTMLElement)) {
|
61
|
+
return
|
62
|
+
}
|
63
|
+
|
64
|
+
extractSecrets(_style).forEach(secret => {
|
65
|
+
const { __uni__key, __uni__stylesheet, __uni__refs, __uni__variants, __uni__args = [] } = secret
|
66
|
+
const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
|
67
|
+
const style = newComputedStylesheet[__uni__key]
|
68
|
+
const args = _args ?? __uni__args
|
69
|
+
const resultHidden = typeof style === 'function'
|
70
|
+
? style(...args)
|
71
|
+
: style
|
72
|
+
const result = extractHiddenProperties(resultHidden)
|
73
|
+
const { variants } = Object.fromEntries(getVariants({ variants: result }, _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
|
+
|
81
|
+
this.webUnistylesMap.set(ref, __uni__key, webUnistyle)
|
82
|
+
this.disposeMap.get(ref, __uni__key)?.()
|
83
|
+
this.disposeMap.set(ref, __uni__key, listenToDependencies({
|
84
|
+
key: __uni__key,
|
85
|
+
stylesheet: __uni__stylesheet,
|
86
|
+
args,
|
87
|
+
className: webUnistyle.className,
|
88
|
+
unistyles: webUnistyle.unistyles,
|
89
|
+
}))
|
90
|
+
|
91
|
+
if (!storedWebUnistyle) {
|
92
|
+
const styleTag = document.createElement('style')
|
93
|
+
|
94
|
+
const additionalClasses = resultWithVariants?._web?._classNames
|
95
|
+
|
96
|
+
if (additionalClasses) {
|
97
|
+
ref.classList.add(...Array.isArray(additionalClasses) ? additionalClasses : [additionalClasses])
|
98
|
+
}
|
99
|
+
|
100
|
+
ref.classList.add(webUnistyle.className)
|
101
|
+
webUnistyle.unistyles.setStylesTarget(styleTag)
|
102
|
+
document.head.appendChild(styleTag)
|
103
|
+
__uni__refs.add(ref)
|
104
|
+
this.stylesMap.set(ref, __uni__key, styleTag)
|
105
|
+
}
|
106
|
+
|
107
|
+
if (storedWebUnistyle) {
|
108
|
+
UnistylesRegistry.updateStyles(webUnistyle.unistyles, resultWithVariants, webUnistyle.className)
|
109
|
+
}
|
110
|
+
})
|
111
|
+
}
|
112
|
+
|
113
|
+
remove = (ref: HTMLElement, style: Style) => {
|
114
|
+
extractSecrets(style).forEach(({ __uni__key }) => {
|
115
|
+
this.webUnistylesMap.delete(ref, __uni__key)
|
116
|
+
this.disposeMap.get(ref, __uni__key)?.()
|
117
|
+
this.disposeMap.delete(ref, __uni__key)
|
118
|
+
this.stylesMap.get(ref, __uni__key)?.remove()
|
119
|
+
this.stylesMap.delete(ref, __uni__key)
|
120
|
+
})
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
export const UnistylesShadowRegistry = new UnistylesShadowRegistryBuilder()
|
package/{web → src/web}/state.ts
RENAMED
@@ -1,16 +1,14 @@
|
|
1
|
-
import
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
import type { UnistylesBreakpoints, UnistylesThemes } from '../src/global'
|
1
|
+
import type { UnistylesTheme } from '../types'
|
2
|
+
import type { UnistylesConfig } from '../specs/StyleSheet'
|
3
|
+
import type { AppBreakpoint, AppThemeName } from '../specs/types'
|
4
|
+
import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
|
6
5
|
import { UnistylesRuntime } from './runtime'
|
7
6
|
import { isServer, schemeToTheme } from './utils'
|
8
7
|
import { UnistylesListener } from './listener'
|
9
|
-
import { UnistyleDependency } from '../
|
8
|
+
import { UnistyleDependency } from '../specs/NativePlatform'
|
10
9
|
|
11
10
|
class UnistylesStateBuilder {
|
12
11
|
private readonly isSSR = isServer()
|
13
|
-
readonly tags = [] as Array<ReactElement>
|
14
12
|
|
15
13
|
themes = new Map<string, UnistylesTheme>()
|
16
14
|
themeName?: AppThemeName
|
@@ -101,48 +99,6 @@ class UnistylesStateBuilder {
|
|
101
99
|
})
|
102
100
|
})
|
103
101
|
}
|
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
102
|
}
|
147
103
|
|
148
104
|
export const UnistylesState = new UnistylesStateBuilder()
|
package/{web → src/web}/utils.ts
RENAMED
@@ -1,26 +1,11 @@
|
|
1
|
-
import { ColorScheme, type AppThemeName} from '../
|
2
|
-
import type { UnistylesValues } from '../
|
1
|
+
import { ColorScheme, type AppThemeName} from '../specs/types'
|
2
|
+
import type { StyleSheet, StyleSheetWithSuperPowers, UnistylesValues } from '../types/stylesheet'
|
3
3
|
|
4
4
|
export const reduceObject = <TObj extends Record<string, any>, TReducer>(
|
5
5
|
obj: TObj,
|
6
6
|
reducer: (value: TObj[keyof TObj], key: keyof TObj) => TReducer,
|
7
7
|
) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, reducer(value as TObj[keyof TObj], key)])) as { [K in keyof TObj]: TReducer }
|
8
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
9
|
export const keyInObject = <T extends Record<string, any>>(obj: T, key: PropertyKey): key is keyof T => key in obj
|
25
10
|
|
26
11
|
export const schemeToTheme = (scheme: ColorScheme): AppThemeName => {
|
@@ -93,3 +78,92 @@ export const equal = <T>(a: T, b: T) => {
|
|
93
78
|
|
94
79
|
return keysA.every(key => Object.is(a[key], b[key]) && Object.prototype.hasOwnProperty.call(b, key))
|
95
80
|
}
|
81
|
+
|
82
|
+
type UnistyleSecrets = {
|
83
|
+
__uni__stylesheet: StyleSheetWithSuperPowers<StyleSheet>,
|
84
|
+
__uni__key: string,
|
85
|
+
__uni__refs: Set<HTMLElement>
|
86
|
+
__uni__variants: Record<string, any>
|
87
|
+
__uni__args?: Array<any>
|
88
|
+
}
|
89
|
+
|
90
|
+
export const assignSecrets = <T>(object: T, secrets: UnistyleSecrets) => {
|
91
|
+
// @ts-expect-error - assign secrets to object
|
92
|
+
object[`__uni__secrets__${Math.random().toString(16).slice(2)}`] = secrets
|
93
|
+
|
94
|
+
return object
|
95
|
+
}
|
96
|
+
|
97
|
+
export const extractSecrets = (object: any) => {
|
98
|
+
const secrets = Object.entries(object).reduce((acc, [key, value]) => {
|
99
|
+
if (key.startsWith('__uni__secrets__')) {
|
100
|
+
acc.push(value as UnistyleSecrets)
|
101
|
+
}
|
102
|
+
|
103
|
+
return acc
|
104
|
+
}, [] as Array<UnistyleSecrets>)
|
105
|
+
|
106
|
+
return secrets
|
107
|
+
}
|
108
|
+
|
109
|
+
export const getStyles = (values: UnistylesValues) => {
|
110
|
+
const returnValue = {}
|
111
|
+
|
112
|
+
Object.defineProperties(returnValue, reduceObject(values, value => ({
|
113
|
+
value,
|
114
|
+
enumerable: false,
|
115
|
+
configurable: true
|
116
|
+
})))
|
117
|
+
|
118
|
+
return returnValue
|
119
|
+
}
|
120
|
+
|
121
|
+
export const createDoubleMap = <TKey, TSecondKey, TValue>() => {
|
122
|
+
const map = new Map<TKey, Map<TSecondKey, TValue>>()
|
123
|
+
|
124
|
+
return {
|
125
|
+
get: (key: TKey, secondKey: TSecondKey) => {
|
126
|
+
const mapForKey = map.get(key)
|
127
|
+
|
128
|
+
if (!mapForKey) {
|
129
|
+
return undefined
|
130
|
+
}
|
131
|
+
|
132
|
+
return mapForKey.get(secondKey)
|
133
|
+
},
|
134
|
+
set: (key: TKey, secondKey: TSecondKey, value: TValue) => {
|
135
|
+
const mapForKey = map.get(key) ?? new Map<TSecondKey, TValue>()
|
136
|
+
|
137
|
+
map.set(key, mapForKey)
|
138
|
+
mapForKey.set(secondKey, value)
|
139
|
+
},
|
140
|
+
delete: (key: TKey, secondKey: TSecondKey) => {
|
141
|
+
const mapForKey = map.get(key)
|
142
|
+
|
143
|
+
if (!mapForKey) {
|
144
|
+
return
|
145
|
+
}
|
146
|
+
|
147
|
+
mapForKey.delete(secondKey)
|
148
|
+
},
|
149
|
+
forEach: (callback: (key: TKey, secondKey: TSecondKey, value: TValue) => void) => {
|
150
|
+
map.forEach((mapForKey, key) => {
|
151
|
+
mapForKey.forEach((value, secondKey) => {
|
152
|
+
callback(key, secondKey, value)
|
153
|
+
})
|
154
|
+
})
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
export const extractHiddenProperties = (object: any) => {
|
160
|
+
const hiddenProperties = Object.getOwnPropertyNames(object)
|
161
|
+
|
162
|
+
return Object.fromEntries(
|
163
|
+
hiddenProperties
|
164
|
+
.filter(key => !key.startsWith('__uni__'))
|
165
|
+
.map(key => [key, object[key]])
|
166
|
+
)
|
167
|
+
}
|
168
|
+
|
169
|
+
export const isInDocument = (element: HTMLElement) => document.body.contains(element)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import type { ReactNativeStyleSheet, StyleSheet } from '../../types'
|
2
|
+
import { deepMergeObjects } from '../utils'
|
3
|
+
|
4
|
+
type StylesWithVariants = {
|
5
|
+
variants: Record<string, any>,
|
6
|
+
compoundVariants?: Array<Record<string, any> & {
|
7
|
+
styles: Record<string, any>
|
8
|
+
}>
|
9
|
+
}
|
10
|
+
const hasVariants = <T extends object>(value: [string, T]): value is [string, T & StylesWithVariants] => 'variants' in value[1]
|
11
|
+
|
12
|
+
export const getVariants = (styles: ReactNativeStyleSheet<StyleSheet>, selectedVariants: Record<string, any>) => {
|
13
|
+
return Object.entries(styles)
|
14
|
+
.filter(hasVariants)
|
15
|
+
.filter(([_key, { variants }]) => Object.keys(variants).some(variant => variant in variants))
|
16
|
+
.map(([key, { variants, compoundVariants = [] }]) => {
|
17
|
+
const variantStyles = Object.entries(variants).flatMap(([variant, styles]) => {
|
18
|
+
const selectedVariant = selectedVariants[variant]
|
19
|
+
const selectedVariantStyles = styles[selectedVariant] ?? styles['default']
|
20
|
+
|
21
|
+
if (!selectedVariantStyles) {
|
22
|
+
return []
|
23
|
+
}
|
24
|
+
|
25
|
+
return selectedVariantStyles
|
26
|
+
})
|
27
|
+
|
28
|
+
const compoundVariantStyles = compoundVariants.flatMap(compoundVariant => {
|
29
|
+
const { styles, ...conditions } = compoundVariant
|
30
|
+
|
31
|
+
if (Object.entries(conditions).some(([variant, value]) => String(selectedVariants[variant]) !== String(value))) {
|
32
|
+
return []
|
33
|
+
}
|
34
|
+
|
35
|
+
return styles
|
36
|
+
})
|
37
|
+
|
38
|
+
const mergedVariantStyles = deepMergeObjects(...variantStyles, ...compoundVariantStyles)
|
39
|
+
|
40
|
+
return [key, mergedVariantStyles] as const
|
41
|
+
})
|
42
|
+
}
|