react-native-unistyles 3.0.0-alpha.28 → 3.0.0-alpha.29
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +7 -0
- package/android/CMakeLists.txt +12 -21
- package/cxx/core/UnistylesMountHook.cpp +0 -10
- package/cxx/core/UnistylesMountHook.h +3 -8
- package/cxx/hybridObjects/HybridStyleSheet.cpp +66 -32
- package/cxx/hybridObjects/HybridStyleSheet.h +9 -1
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +15 -7
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +5 -1
- package/cxx/parser/Parser.cpp +0 -1
- package/ios/NativePlatform+ios.swift +16 -5
- package/ios/NativePlatform+keyboard.swift +83 -0
- package/ios/NativePlatformListener+ios.swift +19 -6
- package/ios/UnistylesModuleOnLoad.h +3 -1
- package/ios/UnistylesModuleOnLoad.mm +11 -1
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mq.js +4 -1
- package/lib/commonjs/mq.js.map +1 -2
- package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +1 -0
- package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -2
- package/lib/commonjs/specs/NavigtionBar/UnistylesNavigationBar.nitro.js.map +1 -1
- package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -2
- package/lib/commonjs/specs/StatusBar/index.js.map +1 -2
- package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js +1 -3
- package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js.map +2 -1
- package/lib/commonjs/specs/TurboUnistyles/index.js.map +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js.map +2 -1
- package/lib/commonjs/specs/index.js.map +1 -1
- package/lib/commonjs/specs/index.web.js.map +2 -1
- package/lib/commonjs/web/convert/index.js +7 -1
- package/lib/commonjs/web/convert/shadow.js +5 -1
- package/lib/commonjs/web/convert/shadow.js.map +1 -2
- package/lib/commonjs/web/convert/textShadow.js +4 -1
- package/lib/commonjs/web/convert/textShadow.js.map +1 -2
- package/lib/commonjs/web/convert/transform.js.map +1 -2
- package/lib/commonjs/web/create.js +6 -5
- package/lib/commonjs/web/create.js.map +1 -2
- package/lib/commonjs/web/mock.js.map +1 -2
- package/lib/commonjs/web/registry.js +1 -4
- package/lib/commonjs/web/registry.js.map +1 -1
- package/lib/commonjs/web/runtime.js.map +1 -2
- package/lib/commonjs/web/shadowRegistry.js +1 -4
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/utils/common.js +3 -1
- package/lib/commonjs/web/utils/common.js.map +1 -2
- package/lib/commonjs/web/variants/index.js.map +1 -1
- package/lib/module/common.js.map +1 -1
- package/lib/module/core/useBreakpoint.js.map +1 -1
- package/lib/module/core/useBreakpoint.native.js.map +1 -2
- package/lib/module/core/useTheme.js.map +1 -2
- package/lib/module/core/useTheme.native.js.map +1 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/mq.js +4 -1
- package/lib/module/mq.js.map +1 -2
- package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +7 -5
- package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +2 -1
- package/lib/module/specs/NavigtionBar/index.js.map +1 -2
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -2
- package/lib/module/specs/StatusBar/UnistylesStatusBar.nitro.js.map +2 -1
- package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js.map +1 -2
- package/lib/module/specs/index.js.map +2 -1
- package/lib/module/specs/types.js +10 -10
- package/lib/module/specs/types.js.map +2 -1
- package/lib/module/web/convert/boxShadow.js +4 -1
- package/lib/module/web/convert/boxShadow.js.map +1 -2
- package/lib/module/web/convert/pseudo.js.map +1 -2
- package/lib/module/web/convert/shadow.js +5 -1
- package/lib/module/web/convert/shadow.js.map +1 -2
- package/lib/module/web/convert/style.js.map +1 -2
- package/lib/module/web/convert/textShadow.js +4 -1
- package/lib/module/web/convert/textShadow.js.map +1 -2
- package/lib/module/web/convert/transform.js.map +1 -2
- package/lib/module/web/convert/utils.js.map +1 -2
- package/lib/module/web/create.js +2 -5
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/index.js +2 -1
- package/lib/module/web/index.js.map +1 -2
- package/lib/module/web/listener.js.map +1 -2
- package/lib/module/web/mock.js.map +1 -2
- package/lib/module/web/registry.js +5 -6
- package/lib/module/web/registry.js.map +1 -2
- package/lib/module/web/runtime.js.map +1 -2
- package/lib/module/web/shadowRegistry.js +11 -6
- package/lib/module/web/shadowRegistry.js.map +1 -2
- package/lib/module/web/utils/index.js.map +1 -1
- package/lib/module/web/utils/unistyle.js.map +1 -2
- package/lib/module/web/variants/index.js.map +1 -1
- package/lib/module/web/variants/useVariants.js +2 -1
- package/lib/module/web/variants/useVariants.js.map +1 -2
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +4 -1
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +11 -11
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/web/create.d.ts.map +1 -1
- package/lib/typescript/src/web/registry.d.ts.map +1 -1
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JFunc_void.hpp +48 -0
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +9 -0
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +2 -0
- package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +3 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void.kt +45 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +15 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +2 -1
- package/nitrogen/generated/android/unistylesOnLoad.cpp +2 -0
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +29 -1
- package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +6 -0
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +2 -0
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +27 -0
- package/nitrogen/generated/ios/swift/UnistyleDependency.swift +4 -0
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +2 -0
- package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -1
- package/package.json +1 -1
- package/plugin/common.js +9 -0
- package/plugin/stylesheet.js +7 -1
- package/src/specs/NativePlatform/NativePlatform.nitro.ts +5 -2
- package/src/types/breakpoints.ts +25 -13
- package/src/web/create.ts +2 -5
- package/src/web/registry.ts +2 -5
- package/src/web/shadowRegistry.ts +2 -5
- package/src/common.js +0 -4
- package/src/core/index.js +0 -2
- package/src/core/useBreakpoint.js +0 -14
- package/src/core/useBreakpoint.native.js +0 -16
- package/src/core/useTheme.js +0 -14
- package/src/core/useTheme.native.js +0 -16
- package/src/index.js +0 -3
- package/src/mq.js +0 -38
- package/src/web/convert/boxShadow.js +0 -59
- package/src/web/convert/index.js +0 -56
- package/src/web/convert/pseudo.js +0 -131
- package/src/web/convert/shadow.js +0 -50
- package/src/web/convert/style.js +0 -137
- package/src/web/convert/textShadow.js +0 -56
- package/src/web/convert/transform.js +0 -65
- package/src/web/convert/types.js +0 -2
- package/src/web/convert/utils.js +0 -39
- package/src/web/create.js +0 -39
- package/src/web/index.js +0 -22
- package/src/web/listener.js +0 -26
- package/src/web/mock.js +0 -21
- package/src/web/mq.js +0 -14
- package/src/web/registry.js +0 -168
- package/src/web/runtime.js +0 -160
- package/src/web/shadowRegistry.js +0 -99
- package/src/web/utils/common.js +0 -79
- package/src/web/utils/index.js +0 -2
- package/src/web/utils/unistyle.js +0 -72
- package/src/web/variants/getVariants.js +0 -26
- package/src/web/variants/index.js +0 -2
- package/src/web/variants/useVariants.js +0 -50
@@ -39,6 +39,7 @@ namespace margelo::nitro::unistyles {
|
|
39
39
|
FONTSCALE SWIFT_NAME(fontscale) = 11,
|
40
40
|
STATUSBAR SWIFT_NAME(statusbar) = 12,
|
41
41
|
NAVIGATIONBAR SWIFT_NAME(navigationbar) = 13,
|
42
|
+
IME SWIFT_NAME(ime) = 14,
|
42
43
|
} CLOSED_ENUM;
|
43
44
|
|
44
45
|
} // namespace margelo::nitro::unistyles
|
@@ -69,7 +70,7 @@ namespace margelo::nitro {
|
|
69
70
|
return false;
|
70
71
|
}
|
71
72
|
// Check if we are within the bounds of the enum.
|
72
|
-
return integer >= 0 && integer <=
|
73
|
+
return integer >= 0 && integer <= 14;
|
73
74
|
}
|
74
75
|
};
|
75
76
|
|
package/package.json
CHANGED
package/plugin/common.js
CHANGED
@@ -104,6 +104,15 @@ function getSecondPropertyName(t, memberExpression) {
|
|
104
104
|
current = current.object
|
105
105
|
}
|
106
106
|
|
107
|
+
// special case for IME
|
108
|
+
if (propertyName && t.isIdentifier(propertyName) && propertyName.name === 'insets') {
|
109
|
+
if (t.isIdentifier(memberExpression.property) && memberExpression.property.name === "ime") {
|
110
|
+
return [memberExpression.property.name]
|
111
|
+
}
|
112
|
+
|
113
|
+
return [propertyName.name]
|
114
|
+
}
|
115
|
+
|
107
116
|
if (propertyName && t.isIdentifier(propertyName)) {
|
108
117
|
return [propertyName.name]
|
109
118
|
}
|
package/plugin/stylesheet.js
CHANGED
@@ -14,7 +14,8 @@ const UnistyleDependency = {
|
|
14
14
|
PixelRatio: 10,
|
15
15
|
FontScale: 11,
|
16
16
|
StatusBar: 12,
|
17
|
-
NavigationBar: 13
|
17
|
+
NavigationBar: 13,
|
18
|
+
Ime: 14
|
18
19
|
}
|
19
20
|
|
20
21
|
function stringToUniqueId(str) {
|
@@ -111,6 +112,11 @@ function analyzeDependencies(t, state, name, unistyleObj, themeName, rtName) {
|
|
111
112
|
|
112
113
|
return
|
113
114
|
}
|
115
|
+
case 'ime': {
|
116
|
+
dependencies.push(UnistyleDependency.Ime)
|
117
|
+
|
118
|
+
return
|
119
|
+
}
|
114
120
|
case 'insets': {
|
115
121
|
dependencies.push(UnistyleDependency.Insets)
|
116
122
|
|
@@ -18,7 +18,8 @@ export enum UnistyleDependency {
|
|
18
18
|
PixelRatio = 10,
|
19
19
|
FontScale = 11,
|
20
20
|
StatusBar = 12,
|
21
|
-
NavigationBar = 13
|
21
|
+
NavigationBar = 13,
|
22
|
+
Ime = 14
|
22
23
|
}
|
23
24
|
|
24
25
|
export interface UnistylesNativeMiniRuntime {
|
@@ -58,5 +59,7 @@ export interface NativePlatform extends HybridObject<{ ios: 'swift', android: 'k
|
|
58
59
|
|
59
60
|
// private
|
60
61
|
getMiniRuntime(): UnistylesNativeMiniRuntime,
|
61
|
-
registerPlatformListener(callback: (dependencies: Array<UnistyleDependency>) => void): void
|
62
|
+
registerPlatformListener(callback: (dependencies: Array<UnistyleDependency>) => void): void,
|
63
|
+
registerImeListener(callback: () => void): void,
|
64
|
+
unregisterPlatformListeners(): void
|
62
65
|
}
|
package/src/types/breakpoints.ts
CHANGED
@@ -17,45 +17,57 @@ type ExtractBreakpoints<T> = T extends object
|
|
17
17
|
}
|
18
18
|
: T
|
19
19
|
|
20
|
-
type ParseNestedObject<T> = T extends (...args: infer A) => infer R
|
21
|
-
? (...args: A) => ParseNestedObject<R>
|
20
|
+
type ParseNestedObject<T, ShouldFlatten> = T extends (...args: infer A) => infer R
|
21
|
+
? (...args: A) => ParseNestedObject<R, false>
|
22
22
|
: T extends object
|
23
23
|
? T extends { variants: infer R, compoundVariants: infer C }
|
24
|
-
|
24
|
+
// // if intersection of Base, Variants and Compound Variants is never, then flatten variants and compound variants to generic "string"
|
25
|
+
? (ParseVariants<FlattenVariants<R, false>> & FlattenCompoundVariants<C, false> & ParseNestedObject<Omit<T, 'variants' | 'compoundVariants'>, false>) extends never
|
26
|
+
? ParseVariants<FlattenVariants<R, true>> & FlattenCompoundVariants<C, true> & ParseNestedObject<Omit<T, 'variants' | 'compoundVariants'>, false>
|
27
|
+
: ParseVariants<FlattenVariants<R, false>> & FlattenCompoundVariants<C, false> & ParseNestedObject<Omit<T, 'variants' | 'compoundVariants'>, false>
|
25
28
|
: T extends { variants: infer R }
|
26
|
-
|
29
|
+
// if intersection of Base and Variants is never, then flatten variants to generic "string"
|
30
|
+
? (ParseVariants<FlattenVariants<R, false>> & ParseNestedObject<Omit<T, 'variants'>, false>) extends never
|
31
|
+
? ParseVariants<FlattenVariants<R, true>> & ParseNestedObject<Omit<T, 'variants'>, false>
|
32
|
+
: ParseVariants<FlattenVariants<R, false>> & ParseNestedObject<Omit<T, 'variants'>, false>
|
27
33
|
: T extends { compoundVariants: object }
|
28
|
-
? ParseNestedObject<Omit<T, 'compoundVariants'
|
34
|
+
? ParseNestedObject<Omit<T, 'compoundVariants'>, false>
|
29
35
|
: {
|
30
36
|
[K in keyof T as K extends '_web' ? never : K]: T[K] extends object
|
31
37
|
? T[K] extends OpaqueColorValue
|
32
38
|
? ColorValue
|
33
39
|
: ExtractBreakpoints<T[K]>
|
34
|
-
: T[K]
|
40
|
+
: T[K] extends string
|
41
|
+
? ShouldFlatten extends true
|
42
|
+
? string
|
43
|
+
: T[K]
|
44
|
+
: T[K]
|
35
45
|
}
|
36
46
|
: T
|
37
47
|
|
38
|
-
type FlattenVariants<T> = T extends object
|
48
|
+
type FlattenVariants<T, ShouldFlatten> = T extends object
|
39
49
|
? {
|
40
50
|
[K in keyof T]: T[K] extends object
|
41
51
|
? {
|
42
52
|
[key in keyof T[K]]: T[K][key] extends object
|
43
|
-
? ParseNestedObject<T[K][key]>
|
53
|
+
? ParseNestedObject<T[K][key], ShouldFlatten>
|
44
54
|
: never
|
45
55
|
}
|
46
56
|
: never
|
47
57
|
}
|
48
58
|
: never
|
49
59
|
|
50
|
-
type FlattenCompoundVariants<T> = T extends Array<infer _>
|
51
|
-
? FlattenCompoundVariants<T[number]>
|
60
|
+
type FlattenCompoundVariants<T, ShouldFlatten> = T extends Array<infer _>
|
61
|
+
? FlattenCompoundVariants<T[number], ShouldFlatten>
|
52
62
|
: T extends { styles: infer S }
|
53
|
-
? ParseNestedObject<S>
|
63
|
+
? ParseNestedObject<S, ShouldFlatten>
|
54
64
|
: never
|
55
65
|
|
56
66
|
type ParseVariants<T> = T extends object
|
57
67
|
? T[keyof T] extends object
|
58
|
-
? UnionToIntersection<ParseVariants<T[keyof T]>>
|
68
|
+
? UnionToIntersection<ParseVariants<T[keyof T]>> extends never
|
69
|
+
? ParseVariants<T[keyof T]>
|
70
|
+
: UnionToIntersection<ParseVariants<T[keyof T]>>
|
59
71
|
: T
|
60
72
|
: T
|
61
73
|
|
@@ -63,7 +75,7 @@ type UnionToIntersection<U> =
|
|
63
75
|
(U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
|
64
76
|
|
65
77
|
type ParseStyleKeys<T> = T extends object
|
66
|
-
? { [K in keyof T]: ParseNestedObject<T[K]> }
|
78
|
+
? { [K in keyof T]: ParseNestedObject<T[K], false> }
|
67
79
|
: never
|
68
80
|
|
69
81
|
export type ReactNativeStyleSheet<T> = ParseStyleKeys<SafeReturnType<T>>
|
package/src/web/create.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { ReactNativeStyleSheet } from '../types'
|
2
2
|
import type { StyleSheetWithSuperPowers, StyleSheet } from '../types/stylesheet'
|
3
|
-
import { assignSecrets, reduceObject, getStyles } from './utils'
|
3
|
+
import { assignSecrets, reduceObject, getStyles, deepMergeObjects } from './utils'
|
4
4
|
import { UnistylesRuntime } from './runtime'
|
5
5
|
import { createUseVariants, getVariants } from './variants'
|
6
6
|
|
@@ -26,10 +26,7 @@ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
|
|
26
26
|
const dynamicStyle = (...args: Array<any>) => {
|
27
27
|
const result = value(...args)
|
28
28
|
const variants = Object.fromEntries(getVariants({ [key]: result } as ReactNativeStyleSheet<StyleSheet>, copyVariants()))
|
29
|
-
const resultWithVariants = {
|
30
|
-
...result,
|
31
|
-
...variants[key]
|
32
|
-
}
|
29
|
+
const resultWithVariants = deepMergeObjects(result, variants[key] ?? {})
|
33
30
|
|
34
31
|
// Add secrets to result of dynamic styles function
|
35
32
|
return addSecrets(getStyles(resultWithVariants), key, args)
|
package/src/web/registry.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { UnistylesTheme, UnistylesValues } from '../types'
|
2
2
|
import type { StyleSheet, StyleSheetWithSuperPowers } from '../types/stylesheet'
|
3
3
|
import { UnistylesRuntime } from './runtime'
|
4
|
-
import { extractMediaQueryValue, keyInObject, getMediaQuery, generateHash, extractUnistyleDependencies } from './utils'
|
4
|
+
import { extractMediaQueryValue, keyInObject, getMediaQuery, generateHash, extractUnistyleDependencies, deepMergeObjects } from './utils'
|
5
5
|
import { UnistylesListener } from './listener'
|
6
6
|
import { convertUnistyles } from './convert'
|
7
7
|
import type { UnistyleDependency } from '../specs/NativePlatform'
|
@@ -107,10 +107,7 @@ class UnistylesRegistryBuilder {
|
|
107
107
|
? newValue(...args)
|
108
108
|
: newValue
|
109
109
|
const { variantsResult } = Object.fromEntries(getVariants({ variantsResult: result }, variants))
|
110
|
-
const resultWithVariants = {
|
111
|
-
...result,
|
112
|
-
...variantsResult
|
113
|
-
}
|
110
|
+
const resultWithVariants = deepMergeObjects(result, variantsResult ?? {})
|
114
111
|
|
115
112
|
this.applyStyles(hash, convertUnistyles(resultWithVariants))
|
116
113
|
})
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { UnistylesValues } from '../types'
|
2
2
|
import { UnistylesRegistry } from './registry'
|
3
|
-
import { createDoubleMap, equal, extractSecrets, extractUnistyleDependencies, isInDocument } from './utils'
|
3
|
+
import { createDoubleMap, deepMergeObjects, equal, extractSecrets, extractUnistyleDependencies, isInDocument } from './utils'
|
4
4
|
import { getVariants } from './variants'
|
5
5
|
|
6
6
|
type Style = UnistylesValues | ((...args: Array<any>) => UnistylesValues)
|
@@ -73,10 +73,7 @@ class UnistylesShadowRegistryBuilder {
|
|
73
73
|
? style(...args)
|
74
74
|
: style
|
75
75
|
const { variantsResult } = Object.fromEntries(getVariants({ variantsResult: result }, variants))
|
76
|
-
const resultWithVariants = {
|
77
|
-
...result,
|
78
|
-
...variantsResult
|
79
|
-
}
|
76
|
+
const resultWithVariants = deepMergeObjects(result, variantsResult ?? {})
|
80
77
|
const oldResult = this.resultsMap.get(ref, __uni__key)
|
81
78
|
|
82
79
|
// If results are the same do nothing
|
package/src/common.js
DELETED
package/src/core/index.js
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
import { useEffect, useState } from 'react';
|
2
|
-
import { UnistylesRuntime } from '../web';
|
3
|
-
import { UnistylesListener } from '../web/listener';
|
4
|
-
import { UnistyleDependency } from '../specs/NativePlatform';
|
5
|
-
export const useBreakpoint = () => {
|
6
|
-
const [breakpoint, setBreakpoint] = useState(UnistylesRuntime.breakpoint);
|
7
|
-
useEffect(() => {
|
8
|
-
const removeChangeListener = UnistylesListener.addListeners([UnistyleDependency.Breakpoints], () => setBreakpoint(UnistylesRuntime.breakpoint));
|
9
|
-
return () => {
|
10
|
-
removeChangeListener();
|
11
|
-
};
|
12
|
-
}, []);
|
13
|
-
return breakpoint;
|
14
|
-
};
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { useEffect, useState } from 'react';
|
2
|
-
import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs';
|
3
|
-
export const useBreakpoint = () => {
|
4
|
-
const [breakpoint, setBreakpoint] = useState(UnistylesRuntime.breakpoint);
|
5
|
-
useEffect(() => {
|
6
|
-
const removeChangeListener = StyleSheet.addChangeListener(dependencies => {
|
7
|
-
if (dependencies.includes(UnistyleDependency.Breakpoints)) {
|
8
|
-
setBreakpoint(UnistylesRuntime.breakpoint);
|
9
|
-
}
|
10
|
-
});
|
11
|
-
return () => {
|
12
|
-
removeChangeListener();
|
13
|
-
};
|
14
|
-
}, []);
|
15
|
-
return breakpoint;
|
16
|
-
};
|
package/src/core/useTheme.js
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
import { useEffect, useState } from 'react';
|
2
|
-
import { UnistylesRuntime } from '../web';
|
3
|
-
import { UnistylesListener } from '../web/listener';
|
4
|
-
import { UnistyleDependency } from '../specs/NativePlatform';
|
5
|
-
export const useTheme = () => {
|
6
|
-
const [theme, setTheme] = useState(UnistylesRuntime.getTheme());
|
7
|
-
useEffect(() => {
|
8
|
-
const removeChangeListener = UnistylesListener.addListeners([UnistyleDependency.Theme], () => setTheme(UnistylesRuntime.getTheme()));
|
9
|
-
return () => {
|
10
|
-
removeChangeListener();
|
11
|
-
};
|
12
|
-
}, []);
|
13
|
-
return theme;
|
14
|
-
};
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { useEffect, useState } from 'react';
|
2
|
-
import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs';
|
3
|
-
export const useTheme = () => {
|
4
|
-
const [theme, setTheme] = useState(UnistylesRuntime.getTheme());
|
5
|
-
useEffect(() => {
|
6
|
-
const removeChangeListener = StyleSheet.addChangeListener(dependencies => {
|
7
|
-
if (dependencies.includes(UnistyleDependency.Theme)) {
|
8
|
-
setTheme(UnistylesRuntime.getTheme());
|
9
|
-
}
|
10
|
-
});
|
11
|
-
return () => {
|
12
|
-
removeChangeListener();
|
13
|
-
};
|
14
|
-
}, []);
|
15
|
-
return theme;
|
16
|
-
};
|
package/src/index.js
DELETED
package/src/mq.js
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
const getMQValue = (value) => {
|
2
|
-
if (typeof value === 'number') {
|
3
|
-
return value;
|
4
|
-
}
|
5
|
-
if (value === null) {
|
6
|
-
return 0;
|
7
|
-
}
|
8
|
-
// todo take it from js
|
9
|
-
const breakpoints = {
|
10
|
-
xs: 0,
|
11
|
-
sm: 300,
|
12
|
-
md: 500,
|
13
|
-
lg: 800,
|
14
|
-
xl: 1200
|
15
|
-
};
|
16
|
-
// @ts-ignore
|
17
|
-
return breakpoints[value] ?? 0;
|
18
|
-
};
|
19
|
-
/**
|
20
|
-
* Utility to create cross-platform media queries
|
21
|
-
* @returns - JavaScript symbol to be used in your stylesheet
|
22
|
-
*/
|
23
|
-
export const mq = {
|
24
|
-
only: {
|
25
|
-
width: (wMin = 0, wMax = Infinity) => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]`,
|
26
|
-
height: (hMin = 0, hMax = Infinity) => `:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`
|
27
|
-
},
|
28
|
-
width: (wMin = 0, wMax = Infinity) => ({
|
29
|
-
and: {
|
30
|
-
height: (hMin = 0, hMax = Infinity) => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`
|
31
|
-
}
|
32
|
-
}),
|
33
|
-
height: (hMin = 0, hMax = Infinity) => ({
|
34
|
-
and: {
|
35
|
-
width: (wMin = 0, wMax = Infinity) => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`
|
36
|
-
}
|
37
|
-
})
|
38
|
-
};
|
@@ -1,59 +0,0 @@
|
|
1
|
-
import { deepMergeObjects, warn } from '../utils';
|
2
|
-
import { validateShadow } from './shadow';
|
3
|
-
import { BOX_SHADOW_STYLES } from './types';
|
4
|
-
import { extractShadowValue, normalizeColor, normalizeNumericValue } from './utils';
|
5
|
-
const createBoxShadowValue = (style) => {
|
6
|
-
// at this point every prop is present
|
7
|
-
const { shadowColor, shadowOffset, shadowOpacity, shadowRadius } = style;
|
8
|
-
const offsetX = normalizeNumericValue(shadowOffset.width);
|
9
|
-
const offsetY = normalizeNumericValue(shadowOffset.height);
|
10
|
-
const radius = normalizeNumericValue(shadowRadius);
|
11
|
-
const color = normalizeColor(shadowColor, shadowOpacity);
|
12
|
-
return `${offsetX} ${offsetY} ${radius} ${color}`;
|
13
|
-
};
|
14
|
-
export const getBoxShadowStyle = (styles) => {
|
15
|
-
const missingStyles = BOX_SHADOW_STYLES.filter(key => !(key in styles));
|
16
|
-
if (missingStyles.length) {
|
17
|
-
warn(`can't apply box shadow as you miss these properties: ${missingStyles.join(', ')}`);
|
18
|
-
return {};
|
19
|
-
}
|
20
|
-
const breakpointsSet = new Set();
|
21
|
-
try {
|
22
|
-
validateShadow(BOX_SHADOW_STYLES, styles, breakpointsSet);
|
23
|
-
}
|
24
|
-
catch (error) {
|
25
|
-
if (typeof error === 'string') {
|
26
|
-
warn(error);
|
27
|
-
}
|
28
|
-
return {};
|
29
|
-
}
|
30
|
-
const breakpoints = Array.from(breakpointsSet);
|
31
|
-
// If no breakpoints were used return styles without media queries
|
32
|
-
if (breakpoints.length === 0) {
|
33
|
-
return {
|
34
|
-
boxShadow: createBoxShadowValue(styles)
|
35
|
-
};
|
36
|
-
}
|
37
|
-
// Create boxShadow for each breakpoint
|
38
|
-
const breakpointStyles = breakpoints.map(breakpoint => {
|
39
|
-
const color = extractShadowValue('shadowColor', breakpoint, styles);
|
40
|
-
const { width, height } = extractShadowValue('shadowOffset', breakpoint, styles);
|
41
|
-
const radius = extractShadowValue('shadowRadius', breakpoint, styles);
|
42
|
-
const opacity = extractShadowValue('shadowOpacity', breakpoint, styles);
|
43
|
-
return {
|
44
|
-
[breakpoint]: {
|
45
|
-
boxShadow: createBoxShadowValue({
|
46
|
-
shadowColor: color,
|
47
|
-
shadowOffset: {
|
48
|
-
width,
|
49
|
-
height
|
50
|
-
},
|
51
|
-
shadowRadius: radius,
|
52
|
-
shadowOpacity: opacity
|
53
|
-
})
|
54
|
-
}
|
55
|
-
};
|
56
|
-
});
|
57
|
-
// Merge all breakpoints styles into one
|
58
|
-
return deepMergeObjects(...breakpointStyles);
|
59
|
-
};
|
package/src/web/convert/index.js
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
import { isPseudo } from './pseudo';
|
2
|
-
import { getStyle } from './style';
|
3
|
-
import { deepMergeObjects } from '../utils';
|
4
|
-
import { getTransformStyle } from './transform';
|
5
|
-
import { isBoxShadow, isTextShadow, isTransform } from './utils';
|
6
|
-
import { getTextShadowStyle } from './textShadow';
|
7
|
-
import { getBoxShadowStyle } from './boxShadow';
|
8
|
-
export const convertUnistyles = (value) => {
|
9
|
-
// Flag to mark if textShadow is already created
|
10
|
-
let hasTextShadow = false;
|
11
|
-
// Flag to mark if boxShadow is already created
|
12
|
-
let hasBoxShadow = false;
|
13
|
-
const stylesArray = Object.entries({
|
14
|
-
...value,
|
15
|
-
...value._web
|
16
|
-
}).flatMap(([unistylesKey, unistylesValue]) => {
|
17
|
-
// Keys to omit
|
18
|
-
if (['_classNames', '_web', 'variants', 'compoundVariants', 'uni__dependencies', '__unistyles-secrets__'].includes(unistylesKey) || unistylesKey.startsWith('variant-')) {
|
19
|
-
return [];
|
20
|
-
}
|
21
|
-
// Pseudo classes :hover, :before etc.
|
22
|
-
if (isPseudo(unistylesKey)) {
|
23
|
-
const flattenValues = convertUnistyles(unistylesValue);
|
24
|
-
return { [unistylesKey]: flattenValues };
|
25
|
-
}
|
26
|
-
// Text shadow
|
27
|
-
if (isTextShadow(unistylesKey)) {
|
28
|
-
if (hasTextShadow) {
|
29
|
-
return [];
|
30
|
-
}
|
31
|
-
hasTextShadow = true;
|
32
|
-
return getTextShadowStyle(value);
|
33
|
-
}
|
34
|
-
// Box shadow
|
35
|
-
if (isBoxShadow(unistylesKey)) {
|
36
|
-
if (hasBoxShadow) {
|
37
|
-
return [];
|
38
|
-
}
|
39
|
-
hasBoxShadow = true;
|
40
|
-
return getBoxShadowStyle(value);
|
41
|
-
}
|
42
|
-
// Transforms
|
43
|
-
if (isTransform(unistylesKey, unistylesValue)) {
|
44
|
-
return getTransformStyle(unistylesValue);
|
45
|
-
}
|
46
|
-
// Breakpoints
|
47
|
-
if (typeof unistylesValue === 'object' && unistylesValue !== null) {
|
48
|
-
return Object.entries(unistylesValue).map(([breakpointKey, breakpointValue]) => {
|
49
|
-
return { [breakpointKey]: getStyle(unistylesKey, breakpointValue) };
|
50
|
-
});
|
51
|
-
}
|
52
|
-
// Regular styles
|
53
|
-
return getStyle(unistylesKey, unistylesValue);
|
54
|
-
});
|
55
|
-
return deepMergeObjects(...stylesArray);
|
56
|
-
};
|
@@ -1,131 +0,0 @@
|
|
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
|
-
];
|
131
|
-
export const isPseudo = (selector) => pseudos.some(pseudo => selector.startsWith(pseudo));
|
@@ -1,50 +0,0 @@
|
|
1
|
-
export const validateShadow = (shadowProperties, styles, breakpoints) => {
|
2
|
-
// Collect breakpoints
|
3
|
-
shadowProperties.forEach(key => {
|
4
|
-
const value = styles[key];
|
5
|
-
if (typeof value !== 'object') {
|
6
|
-
return;
|
7
|
-
}
|
8
|
-
if (key === 'shadowOffset' || key === 'textShadowOffset') {
|
9
|
-
const { width, height } = value;
|
10
|
-
// If shadowOffset.width has breakpoints
|
11
|
-
if (typeof width === 'object') {
|
12
|
-
Object.keys(width).forEach(breakpoint => breakpoints.add(breakpoint));
|
13
|
-
}
|
14
|
-
// If shadowOffset.height has breakpoints
|
15
|
-
if (typeof height === 'object') {
|
16
|
-
Object.keys(height).forEach(breakpoint => breakpoints.add(breakpoint));
|
17
|
-
}
|
18
|
-
return;
|
19
|
-
}
|
20
|
-
// Collect regular breakpoints
|
21
|
-
Object.keys(value).forEach(breakpoint => breakpoints.add(breakpoint));
|
22
|
-
});
|
23
|
-
// Validate if all breakpoints are present
|
24
|
-
shadowProperties.forEach(key => {
|
25
|
-
const value = styles[key];
|
26
|
-
if (typeof value !== 'object') {
|
27
|
-
return;
|
28
|
-
}
|
29
|
-
if (key === 'shadowOffset' || key === 'textShadowOffset') {
|
30
|
-
const { width, height } = value;
|
31
|
-
if (typeof width === 'object') {
|
32
|
-
const missingBreakpoints = Array.from(breakpoints).filter(breakpoint => !(breakpoint in width));
|
33
|
-
if (missingBreakpoints.length) {
|
34
|
-
throw `missing breakpoints in ${key}.width: ${missingBreakpoints.join(', ')}`;
|
35
|
-
}
|
36
|
-
}
|
37
|
-
if (typeof height === 'object') {
|
38
|
-
const missingBreakpoints = Array.from(breakpoints).filter(breakpoint => !(breakpoint in height));
|
39
|
-
if (missingBreakpoints.length) {
|
40
|
-
throw `missing breakpoints in ${key}.height: ${missingBreakpoints.join(', ')}`;
|
41
|
-
}
|
42
|
-
}
|
43
|
-
return;
|
44
|
-
}
|
45
|
-
const missingBreakpoints = Array.from(breakpoints).filter(breakpoint => !(breakpoint in value));
|
46
|
-
if (missingBreakpoints.length) {
|
47
|
-
throw `missing breakpoints in ${key}: ${missingBreakpoints.join(', ')}`;
|
48
|
-
}
|
49
|
-
});
|
50
|
-
};
|