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,65 @@
|
|
1
|
+
import { useMemo, useRef, useState } from 'react'
|
2
|
+
import type { ReactNativeStyleSheet, StyleSheet } from '../../types'
|
3
|
+
import { equal, keyInObject, reduceObject } from '../utils'
|
4
|
+
import { getVariants } from './getVariants'
|
5
|
+
|
6
|
+
export const createUseVariants = (styles: ReactNativeStyleSheet<StyleSheet>, setSelectedVariants: (variants: Record<string, any>) => void) => {
|
7
|
+
const useVariants = (selectedVariants: Record<string, any>) => {
|
8
|
+
const [selectedVariantStylesMap] = useState(() => new Map<string, Record<string, any>>())
|
9
|
+
const lastSelectedVariantsRef = useRef<Record<string, any>>()
|
10
|
+
// Variable that determines if variants have changed and we need to recalculate styles
|
11
|
+
const variantsChanged = !equal(lastSelectedVariantsRef.current, selectedVariants)
|
12
|
+
|
13
|
+
if (variantsChanged) {
|
14
|
+
lastSelectedVariantsRef.current = selectedVariants
|
15
|
+
setSelectedVariants(selectedVariants)
|
16
|
+
}
|
17
|
+
|
18
|
+
const combinedVariantStyles = useMemo(() => {
|
19
|
+
const result = getVariants(styles, selectedVariants)
|
20
|
+
|
21
|
+
result.forEach(([key, value]) => {
|
22
|
+
selectedVariantStylesMap.set(key, value)
|
23
|
+
})
|
24
|
+
|
25
|
+
return result
|
26
|
+
}, [lastSelectedVariantsRef.current])
|
27
|
+
|
28
|
+
combinedVariantStyles.forEach(([key]) => {
|
29
|
+
const styleEntry = styles[key]
|
30
|
+
|
31
|
+
if (!styleEntry) {
|
32
|
+
return
|
33
|
+
}
|
34
|
+
|
35
|
+
const selectedVariantStyles = selectedVariantStylesMap.get(key)
|
36
|
+
|
37
|
+
Object.defineProperties(styleEntry, reduceObject(selectedVariantStyles ?? {}, value => ({
|
38
|
+
value,
|
39
|
+
enumerable: false,
|
40
|
+
configurable: true
|
41
|
+
})))
|
42
|
+
|
43
|
+
// Add __uni__variants to static styles
|
44
|
+
Object.keys(styleEntry).forEach(key => {
|
45
|
+
if (!key.startsWith('__uni__secrets__')) {
|
46
|
+
return
|
47
|
+
}
|
48
|
+
|
49
|
+
const secret = keyInObject(styleEntry, key) ? styleEntry[key] : undefined
|
50
|
+
|
51
|
+
if (!secret) {
|
52
|
+
return
|
53
|
+
}
|
54
|
+
|
55
|
+
Object.defineProperty(secret, '__uni__variants', {
|
56
|
+
value: selectedVariants
|
57
|
+
})
|
58
|
+
})
|
59
|
+
})
|
60
|
+
}
|
61
|
+
|
62
|
+
Object.defineProperty(styles, 'useVariants', {
|
63
|
+
value: useVariants
|
64
|
+
})
|
65
|
+
}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"boxShadow.d.ts","sourceRoot":"","sources":["../../../../web/convert/boxShadow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAkB9D,eAAO,MAAM,iBAAiB,WAAY,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,mBAoD/D,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"breakpoint.d.ts","sourceRoot":"","sources":["../../../../web/convert/breakpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAMrD,eAAO,MAAM,iBAAiB,eAAgB,MAAM,KAAG,UActD,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../web/convert/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAWtD,eAAO,MAAM,kBAAkB,UAAW,eAAe,wBAiExD,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"shadow.d.ts","sourceRoot":"","sources":["../../../../web/convert/shadow.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,qBAAsB,aAAa,CAAC,MAAM,CAAC,UAAU,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,eAAe,GAAG,CAAC,MAAM,CAAC,SAiE5H,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../../../web/convert/style.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAgF9D,eAAO,MAAM,QAAQ,QAAS,MAAM,SAAS,GAAG,wBAY/C,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"textShadow.d.ts","sourceRoot":"","sources":["../../../../web/convert/textShadow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAiB9D,eAAO,MAAM,kBAAkB,WAAY,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,mBAkDhE,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../../web/convert/transform.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAK9D,KAAK,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;AAmC5C,eAAO,MAAM,iBAAiB,eAAgB,UAAU,KAAG,mBA+C1D,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../web/convert/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAEjE,MAAM,MAAM,YAAY,GAAG,eAAe,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAE7E,eAAO,MAAM,kBAAkB,sEAAuE,CAAA;AAEtG,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AAErF,eAAO,MAAM,iBAAiB,2EAA4E,CAAA;AAE1G,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AAEnF,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,SAAS,CAAA;AAE9C,MAAM,MAAM,aAAa,GAAG,MAAM,SAAS,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../web/convert/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyC,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAEnG,eAAO,MAAM,WAAW,QAAS,MAAM,SAAS,GAAG,KAAG,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAgD,CAAA;AAExI,eAAO,MAAM,YAAY,QAAS,MAAM,YAA0E,CAAA;AAElH,eAAO,MAAM,WAAW,QAAS,MAAM,YAAwE,CAAA;AAE/G,eAAO,MAAM,qBAAqB,UAAW,MAAM,oBAAiC,CAAA;AAEpF,eAAO,MAAM,cAAc,UAAW,MAAM,YAAW,MAAM,WAyB5D,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,IAAI,SAAS,aAAa,OAAO,IAAI,cAAc,MAAM,UAAU,GAAG,KAAG,SAAS,CAAC,IAAI,CAazH,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../web/listener/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../../web/listener/listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAGnE,qBAAa,wBAAwB;IACjC,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,SAAS,CAAoG;IAErH,UAAU,eAAgB,kBAAkB,UAE3C;IAED,aAAa,aAUZ;IAED,YAAY,iBAAkB,KAAK,CAAC,kBAAkB,CAAC,YAAY,YAAY,gBAM9E;CACJ;AAED,eAAO,MAAM,iBAAiB,0BAAiC,CAAA"}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import type { UnistylesNavigationBar as NavigationBarSpec } from '../src/specs/NavigtionBar';
|
2
|
-
import type { UnistylesStatusBar as StatusBarSpec } from '../src/specs/StatusBar';
|
3
|
-
export declare const StatusBar: StatusBarSpec;
|
4
|
-
export declare const NavigationBar: NavigationBarSpec;
|
5
|
-
export declare const UnistylesShadowRegistry: {
|
6
|
-
name: string;
|
7
|
-
__type: string;
|
8
|
-
equals: () => boolean;
|
9
|
-
toString: () => string;
|
10
|
-
dispose: () => void;
|
11
|
-
add: () => void;
|
12
|
-
remove: () => void;
|
13
|
-
};
|
14
|
-
//# sourceMappingURL=mock.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../web/mock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,IAAI,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC5F,OAAO,KAAK,EAAE,kBAAkB,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAEjF,eAAO,MAAM,SAAS,EAAE,aAUvB,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,iBAS3B,CAAA;AAED,eAAO,MAAM,uBAAuB;;;;;;;;CAQnC,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"mq.d.ts","sourceRoot":"","sources":["../../../web/mq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAMrD,eAAO,MAAM,OAAO,OAAQ,MAAM,KAAG,UAUpC,CAAA;AAED,eAAO,MAAM,aAAa,OAAQ,MAAM,YAAgC,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"pseudo.d.ts","sourceRoot":"","sources":["../../../web/pseudo.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,kDAKV,CAAA;AAEV,eAAO,MAAM,QAAQ,aAAc,MAAM,YAAyC,CAAA;AAElF,MAAM,MAAM,MAAM,GAAG,OAAO,OAAO,CAAC,MAAM,CAAC,CAAA"}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { TypeStyle } from 'typestyle';
|
2
|
-
import type { UnistylesValues } from '../src/types';
|
3
|
-
declare class UnistylesRegistryBuilder {
|
4
|
-
createStyles: (stylesheet: UnistylesValues, key: string | number) => {
|
5
|
-
className: string;
|
6
|
-
unistyles: TypeStyle;
|
7
|
-
};
|
8
|
-
updateStyles: (unistyles: TypeStyle, stylesheet: UnistylesValues, className: string) => void;
|
9
|
-
}
|
10
|
-
export declare const UnistylesRegistry: UnistylesRegistryBuilder;
|
11
|
-
export {};
|
12
|
-
//# sourceMappingURL=registry.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../web/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,SAAS,EAAE,MAAM,WAAW,CAAA;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAInD,cAAM,wBAAwB;IAC1B,YAAY,eAAgB,eAAe,OAAO,MAAM,GAAG,MAAM;;;MAwBhE;IAED,YAAY,cAAe,SAAS,cAAc,eAAe,aAAa,MAAM,UAKnF;CACJ;AAED,eAAO,MAAM,iBAAiB,0BAAiC,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../web/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAC/F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAMrD,cAAM,uBAAuB;IACzB,UAAU,wBAAuB;IACjC,SAAS,wBAAsB;IAE/B,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,YAAY;IAYpB,IAAI,WAAW,gBASd;IAED,IAAI,SAAS,uEAEZ;IAED,IAAI,mBAAmB,2BAEtB;IAED,IAAI,UAAU,4EAEb;IAED,IAAI,WAAW,gBAMd;IAED,IAAI,KAAK,0CAYR;IAED,IAAI,UAAU,WAEb;IAED,IAAI,MAAM;;;MAYT;IAED,IAAI,SAAS,WAEZ;IAED,IAAI,MAAM;;;;;;MAQT;IAED,IAAI,SAAS,wDAEZ;IAED,IAAI,GAAG,YAEN;IAED,IAAI,iBAAiB,YAEpB;IAED,IAAI,aAAa,+DAEhB;IAED,IAAI,WAAW,IAAI,oBAAoB,CAsBtC;IAED,QAAQ,cAAe,YAAY,UAQlC;IAED,iBAAiB,cAAe,OAAO,UAQtC;IAED,0BAA0B,QAAS,MAAM,UAAU,MAAM,UAMxD;IAED,gBAAgB,aAAW;IAE3B,WAAW,cAAe,YAAY,WAAW,CAAC,YAAY,EAAE,QAAQ,KAAK,QAAQ,UAQpF;IAED,eAAe,iGAA4B;CAC9C;AAED,eAAO,MAAM,gBAAgB,yBAAgC,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../web/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAA4B,MAAM,OAAO,CAAA;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACrE,OAAO,KAAK,EAAE,oBAAoB,EAAmB,MAAM,eAAe,CAAA;AAM1E,cAAM,qBAAqB;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,QAAQ,CAAC,IAAI,EAAS,KAAK,CAAC,YAAY,CAAC,CAAA;IAEzC,MAAM,8BAAoC;IAC1C,SAAS,CAAC,EAAE,YAAY,CAAA;IAExB,UAAU,CAAC,EAAE,aAAa,CAAA;IAC1B,WAAW,CAAC,EAAE,oBAAoB,CAAA;IAElC,iBAAiB,UAAQ;IAEzB,IAAI,WAAY,eAAe,UAU9B;IAED,OAAO,CAAC,UAAU,CAIjB;IAED,OAAO,CAAC,YAAY,CAyBnB;IAED,OAAO,CAAC,eAAe,CAmCtB;IAED,SAAS;;;CAyCZ;AAED,eAAO,MAAM,cAAc,uBAA8B,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"useVariants.d.ts","sourceRoot":"","sources":["../../../web/useVariants.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAarE,eAAO,MAAM,iBAAiB,WAAY,qBAAqB,CAAC,UAAU,CAAC,SAmF1E,CAAA"}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import { ColorScheme, type AppThemeName } from '../src/specs/types';
|
2
|
-
import type { UnistylesValues } from '../src/types';
|
3
|
-
export declare const reduceObject: <TObj extends Record<string, any>, TReducer>(obj: TObj, reducer: (value: TObj[keyof TObj], key: keyof TObj) => TReducer) => { [K in keyof TObj]: TReducer; };
|
4
|
-
export declare const toReactNativeClassName: (className: string, values: UnistylesValues) => {
|
5
|
-
[x: string]: string | boolean;
|
6
|
-
$$css: boolean;
|
7
|
-
};
|
8
|
-
export declare const keyInObject: <T extends Record<string, any>>(obj: T, key: PropertyKey) => key is keyof T;
|
9
|
-
export declare const schemeToTheme: (scheme: ColorScheme) => AppThemeName;
|
10
|
-
export declare const hexToRGBA: (hex: string, opacity: number) => string;
|
11
|
-
export declare const isServer: () => boolean;
|
12
|
-
/**
|
13
|
-
* Deeply merges properties of passed object
|
14
|
-
*/
|
15
|
-
export declare const deepMergeObjects: <T extends Record<PropertyKey, any>>(...sources: Array<T>) => T;
|
16
|
-
export declare const warn: (message: string) => void;
|
17
|
-
export declare const equal: <T>(a: T, b: T) => boolean;
|
18
|
-
//# sourceMappingURL=utils.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../web/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,YAAY,EAAC,MAAM,oBAAoB,CAAA;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAEnD,eAAO,MAAM,YAAY,GAAI,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,OAC9D,IAAI,WACA,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,IAAI,KAAK,QAAQ,KACmD,GAAG,CAAe,IAAV,MAAM,IAAI,GAAG,QAAQ,GAAE,CAAA;AAErJ,eAAO,MAAM,sBAAsB,cAAe,MAAM,UAAU,eAAe;;;CAahF,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO,WAAW,KAAG,GAAG,IAAI,MAAM,CAAe,CAAA;AAElH,eAAO,MAAM,aAAa,WAAY,WAAW,KAAG,YAQnD,CAAA;AAED,eAAO,MAAM,SAAS,QAAS,MAAM,WAAW,MAAM,WAM5B,CAAA;AAE1B,eAAO,MAAM,QAAQ,eAAsC,CAAA;AAE3D;;EAEE;AACF,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,cAAc,KAAK,CAAC,CAAC,CAAC,MAqBxF,CAAA;AAED,eAAO,MAAM,IAAI,YAAa,MAAM,SAA2D,CAAA;AAE/F,eAAO,MAAM,KAAK,GAAI,CAAC,KAAK,CAAC,KAAK,CAAC,YAqBlC,CAAA"}
|
package/web/create.ts
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
import type { TypeStyle } from 'typestyle'
|
2
|
-
import type { ReactNativeStyleSheet } from '../src/types'
|
3
|
-
import type { StyleSheetWithSuperPowers, StyleSheet } from '../src/types/stylesheet'
|
4
|
-
import { UnistylesRegistry } from './registry'
|
5
|
-
import { keyInObject, reduceObject, toReactNativeClassName } from './utils'
|
6
|
-
import { UnistylesRuntime } from './runtime'
|
7
|
-
import { createUseVariants } from './useVariants'
|
8
|
-
import { UnistylesListener } from './listener'
|
9
|
-
import type { UnistyleDependency } from '../src/specs/NativePlatform'
|
10
|
-
|
11
|
-
type ListenToDependenciesProps = {
|
12
|
-
value: StyleSheet[keyof StyleSheet],
|
13
|
-
key: PropertyKey,
|
14
|
-
unistyles: TypeStyle,
|
15
|
-
className: string,
|
16
|
-
args?: Array<any>
|
17
|
-
}
|
18
|
-
|
19
|
-
export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
|
20
|
-
const computedStylesheet = typeof stylesheet === 'function'
|
21
|
-
? stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime)
|
22
|
-
: stylesheet
|
23
|
-
|
24
|
-
const listenToDependencies = ({ key, className, unistyles, value, args = [] } : ListenToDependenciesProps) => {
|
25
|
-
const dependencies = ('uni__dependencies' in value ? value['uni__dependencies'] : []) as Array<UnistyleDependency>
|
26
|
-
|
27
|
-
if (dependencies.length === 0) {
|
28
|
-
return
|
29
|
-
}
|
30
|
-
|
31
|
-
return UnistylesListener.addListeners(dependencies, () => {
|
32
|
-
const newComputedStylesheet = typeof stylesheet === 'function'
|
33
|
-
? stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime)
|
34
|
-
: stylesheet
|
35
|
-
|
36
|
-
if (!keyInObject(newComputedStylesheet, key)) {
|
37
|
-
return
|
38
|
-
}
|
39
|
-
|
40
|
-
const value = newComputedStylesheet[key]!
|
41
|
-
const result = typeof value === 'function'
|
42
|
-
? value(...args)
|
43
|
-
: value
|
44
|
-
|
45
|
-
UnistylesRegistry.updateStyles(unistyles, result, className)
|
46
|
-
})
|
47
|
-
}
|
48
|
-
|
49
|
-
const styles = reduceObject(computedStylesheet, (value, key) => {
|
50
|
-
if (typeof value === 'function') {
|
51
|
-
const classNameMap = new Map<number, string>()
|
52
|
-
const unistylesMap = new Map<number, TypeStyle>()
|
53
|
-
const disposeMap = new Map<number, VoidFunction | undefined>()
|
54
|
-
|
55
|
-
return (...args: Array<any>) => {
|
56
|
-
const [id] = args.slice(-1)
|
57
|
-
const result = value(...args.slice(0, -1))
|
58
|
-
const dispose = disposeMap.get(id)
|
59
|
-
const unistyles = unistylesMap.get(id)
|
60
|
-
const className = classNameMap.get(id)
|
61
|
-
|
62
|
-
if (unistyles && className && dispose) {
|
63
|
-
dispose()
|
64
|
-
UnistylesRegistry.updateStyles(unistyles, result, className)
|
65
|
-
disposeMap.set(id, listenToDependencies({
|
66
|
-
key,
|
67
|
-
value,
|
68
|
-
unistyles,
|
69
|
-
className,
|
70
|
-
args
|
71
|
-
}))
|
72
|
-
|
73
|
-
return toReactNativeClassName(className, result)
|
74
|
-
}
|
75
|
-
|
76
|
-
const entry = UnistylesRegistry.createStyles(result, key)
|
77
|
-
|
78
|
-
classNameMap.set(id, entry.className)
|
79
|
-
unistylesMap.set(id, entry.unistyles)
|
80
|
-
disposeMap.set(id, listenToDependencies({
|
81
|
-
key,
|
82
|
-
value,
|
83
|
-
unistyles: entry.unistyles,
|
84
|
-
className: entry.className,
|
85
|
-
args
|
86
|
-
}))
|
87
|
-
|
88
|
-
return toReactNativeClassName(entry.className, result)
|
89
|
-
}
|
90
|
-
}
|
91
|
-
|
92
|
-
const { className, unistyles } = UnistylesRegistry.createStyles(value, key)
|
93
|
-
|
94
|
-
listenToDependencies({ key, value, unistyles, className })
|
95
|
-
|
96
|
-
return toReactNativeClassName(className, value)
|
97
|
-
}) as ReactNativeStyleSheet<StyleSheet>
|
98
|
-
|
99
|
-
createUseVariants(styles)
|
100
|
-
|
101
|
-
return styles
|
102
|
-
}
|
package/web/listener/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export { UnistylesListener } from './listener'
|
package/web/pseudo.ts
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
// TODO: Add complete list of pseudo selectors
|
2
|
-
export const pseudos = [
|
3
|
-
'_hover',
|
4
|
-
'_css',
|
5
|
-
'_before',
|
6
|
-
'_after'
|
7
|
-
] as const
|
8
|
-
|
9
|
-
export const isPseudo = (selector: string) => pseudos.includes(selector as Pseudo)
|
10
|
-
|
11
|
-
export type Pseudo = typeof pseudos[number]
|
package/web/registry.ts
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
import { createTypeStyle, TypeStyle } from 'typestyle'
|
2
|
-
import type { UnistylesValues } from '../src/types'
|
3
|
-
import { convertToTypeStyle } from './convert'
|
4
|
-
import { UnistylesState } from './state'
|
5
|
-
|
6
|
-
class UnistylesRegistryBuilder {
|
7
|
-
createStyles = (stylesheet: UnistylesValues, key: string | number) => {
|
8
|
-
const stylesTag = UnistylesState.createTag()
|
9
|
-
const unistyles = createTypeStyle(stylesTag)
|
10
|
-
const typestyleStylesheet = convertToTypeStyle(stylesheet)
|
11
|
-
|
12
|
-
const className = unistyles.style({
|
13
|
-
$debugName: String(key),
|
14
|
-
}, typestyleStylesheet)
|
15
|
-
|
16
|
-
if (stylesheet._web?._css) {
|
17
|
-
const customClassName = Array.isArray(stylesheet._web._css)
|
18
|
-
? stylesheet._web._css.join(' ')
|
19
|
-
: stylesheet._web._css
|
20
|
-
|
21
|
-
return {
|
22
|
-
className: `${className} ${customClassName}`,
|
23
|
-
unistyles
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
27
|
-
return {
|
28
|
-
className,
|
29
|
-
unistyles
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
updateStyles = (unistyles: TypeStyle, stylesheet: UnistylesValues, className: string) => {
|
34
|
-
const typestyleStylesheet = convertToTypeStyle(stylesheet)
|
35
|
-
|
36
|
-
unistyles.reinit()
|
37
|
-
unistyles.cssRule(`.${className}`, typestyleStylesheet)
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
export const UnistylesRegistry = new UnistylesRegistryBuilder()
|
package/web/useVariants.ts
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
import { useMemo, useRef, useState } from 'react'
|
2
|
-
import type { TypeStyle } from 'typestyle'
|
3
|
-
import type { ReactNativeStyleSheet, StyleSheet } from '../src/types'
|
4
|
-
import { deepMergeObjects, equal, reduceObject } from './utils'
|
5
|
-
import { UnistylesRegistry } from './registry'
|
6
|
-
|
7
|
-
type StylesWithVariants = {
|
8
|
-
variants: Record<string, any>,
|
9
|
-
compoundVariants?: Array<Record<string, any> & {
|
10
|
-
styles: Record<string, any>
|
11
|
-
}>
|
12
|
-
}
|
13
|
-
|
14
|
-
const hasVariants = <T extends object>(value: [string, T]): value is [string, T & StylesWithVariants] => 'variants' in value[1]
|
15
|
-
|
16
|
-
export const createUseVariants = (styles: ReactNativeStyleSheet<StyleSheet>) => {
|
17
|
-
const useVariants = (selectedVariants: Record<string, any>) => {
|
18
|
-
const [unistylesMap] = useState(() => new Map<string, TypeStyle>())
|
19
|
-
const [classNameMap] = useState(() => new Map<string, string>())
|
20
|
-
const [selectedVariantStylesMap] = useState(() => new Map<string, Record<string, any>>())
|
21
|
-
const lastSelectedVariantsRef = useRef<Record<string, any>>()
|
22
|
-
// Variable that determines if variants have changed and we need to recalculate styles
|
23
|
-
const variantsChanged = !equal(lastSelectedVariantsRef.current, selectedVariants)
|
24
|
-
|
25
|
-
if (variantsChanged) {
|
26
|
-
lastSelectedVariantsRef.current = selectedVariants
|
27
|
-
}
|
28
|
-
|
29
|
-
const combinedVariantStyles = useMemo(() => {
|
30
|
-
return Object.entries(styles)
|
31
|
-
.filter(hasVariants)
|
32
|
-
.filter(([_key, { variants }]) => Object.keys(variants).some(variant => variant in variants))
|
33
|
-
.map(([key, { variants, compoundVariants = [] }]) => {
|
34
|
-
const variantStyles = Object.entries(variants).flatMap(([variant, styles]) => {
|
35
|
-
const selectedVariant = selectedVariants[variant]
|
36
|
-
const selectedVariantStyles = styles[selectedVariant] ?? styles['default']
|
37
|
-
|
38
|
-
if (!selectedVariantStyles) {
|
39
|
-
return []
|
40
|
-
}
|
41
|
-
|
42
|
-
return selectedVariantStyles
|
43
|
-
})
|
44
|
-
|
45
|
-
const compoundVariantStyles = compoundVariants.flatMap(compoundVariant => {
|
46
|
-
const { styles, ...conditions } = compoundVariant
|
47
|
-
|
48
|
-
if (Object.entries(conditions).some(([variant, value]) => String(selectedVariants[variant]) !== String(value))) {
|
49
|
-
return []
|
50
|
-
}
|
51
|
-
|
52
|
-
return styles
|
53
|
-
})
|
54
|
-
|
55
|
-
const mergedVariantStyles = deepMergeObjects(...variantStyles, ...compoundVariantStyles)
|
56
|
-
|
57
|
-
selectedVariantStylesMap.set(key, mergedVariantStyles)
|
58
|
-
|
59
|
-
return [key, mergedVariantStyles] as const
|
60
|
-
})
|
61
|
-
}, [lastSelectedVariantsRef.current])
|
62
|
-
|
63
|
-
if (unistylesMap.size === 0 && combinedVariantStyles.length > 0) {
|
64
|
-
combinedVariantStyles.forEach(([key, value]) => {
|
65
|
-
const { className, unistyles } = UnistylesRegistry.createStyles(value, `variant-${key}`)
|
66
|
-
|
67
|
-
unistylesMap.set(key, unistyles)
|
68
|
-
classNameMap.set(key, className)
|
69
|
-
})
|
70
|
-
}
|
71
|
-
|
72
|
-
combinedVariantStyles.forEach(([key, value]) => {
|
73
|
-
const styleEntry = styles[key]
|
74
|
-
const unistyles = unistylesMap.get(key)
|
75
|
-
const className = classNameMap.get(key)
|
76
|
-
const selectedVariantStyles = selectedVariantStylesMap.get(key)
|
77
|
-
|
78
|
-
if (!unistyles || !className) {
|
79
|
-
return
|
80
|
-
}
|
81
|
-
|
82
|
-
if (variantsChanged) {
|
83
|
-
UnistylesRegistry.updateStyles(unistyles, value, className)
|
84
|
-
}
|
85
|
-
|
86
|
-
Object.defineProperties(styleEntry, reduceObject(selectedVariantStyles ?? {}, value => ({
|
87
|
-
value,
|
88
|
-
enumerable: false,
|
89
|
-
configurable: true
|
90
|
-
})))
|
91
|
-
// @ts-expect-error - apply variant className
|
92
|
-
styleEntry[className] = className
|
93
|
-
})
|
94
|
-
}
|
95
|
-
|
96
|
-
Object.defineProperty(styles, 'useVariants', {
|
97
|
-
value: useVariants
|
98
|
-
})
|
99
|
-
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
/package/{web → src/web}/mq.ts
RENAMED
File without changes
|