react-native-unistyles 3.0.0-alpha.41 → 3.0.0-alpha.43
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +7 -1
- package/cxx/common/Constants.h +0 -1
- package/cxx/core/UnistylesRegistry.cpp +10 -4
- package/cxx/core/UnistylesRegistry.h +1 -1
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +2 -2
- package/cxx/parser/Parser.cpp +7 -22
- package/cxx/parser/Parser.h +0 -1
- package/lib/commonjs/components/Display.js +2 -2
- package/lib/commonjs/components/Display.js.map +1 -1
- package/lib/commonjs/components/Hide.js +2 -2
- package/lib/commonjs/components/Hide.js.map +1 -1
- package/lib/commonjs/components/Pressable.js +82 -0
- package/lib/commonjs/components/Pressable.js.map +1 -0
- package/lib/commonjs/components/Pressable.web.js +97 -0
- package/lib/commonjs/components/Pressable.web.js.map +1 -0
- package/lib/commonjs/components/index.js +7 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/core/getBoundArgs.js +18 -0
- package/lib/commonjs/core/getBoundArgs.js.map +1 -0
- package/lib/commonjs/core/getId.js +9 -0
- package/lib/commonjs/core/getId.js.map +1 -0
- package/lib/commonjs/core/index.js +14 -0
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/hooks/index.js +13 -0
- package/lib/commonjs/hooks/index.js.map +1 -0
- package/lib/commonjs/hooks/useMedia.js.map +1 -0
- package/lib/commonjs/hooks/useMedia.web.js.map +1 -0
- package/lib/commonjs/index.js +8 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mq.js +6 -6
- package/lib/commonjs/mq.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +3 -4
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js +1 -2
- package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js.map +1 -1
- package/lib/commonjs/specs/index.web.js +0 -7
- package/lib/commonjs/specs/index.web.js.map +1 -1
- package/lib/commonjs/utils.js +1 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/convert/types.js.map +1 -1
- package/lib/commonjs/web/convert/utils.js +1 -1
- package/lib/commonjs/web/convert/utils.js.map +1 -1
- package/lib/commonjs/web/create.js +10 -2
- package/lib/commonjs/web/create.js.map +1 -1
- package/lib/commonjs/web/index.js +7 -5
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/commonjs/web/listener.js.map +1 -1
- package/lib/commonjs/web/runtime.js +7 -7
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +1 -1
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/state.js +23 -16
- package/lib/commonjs/web/state.js.map +1 -1
- package/lib/commonjs/web/utils/common.js +3 -3
- package/lib/commonjs/web/utils/common.js.map +1 -1
- package/lib/commonjs/web/utils/unistyle.js +2 -4
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/commonjs/web/{variants/getVariants.js → variants.js} +3 -3
- package/lib/commonjs/web/variants.js.map +1 -0
- package/lib/module/components/Display.js +1 -1
- package/lib/module/components/Display.js.map +1 -1
- package/lib/module/components/Hide.js +1 -1
- package/lib/module/components/Hide.js.map +1 -1
- package/lib/module/components/Pressable.js +76 -0
- package/lib/module/components/Pressable.js.map +1 -0
- package/lib/module/components/Pressable.web.js +91 -0
- package/lib/module/components/Pressable.web.js.map +1 -0
- package/lib/module/components/index.js +1 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/core/getBoundArgs.js +13 -0
- package/lib/module/core/getBoundArgs.js.map +1 -0
- package/lib/module/core/getId.js +4 -0
- package/lib/module/core/getId.js.map +1 -0
- package/lib/module/core/index.js +2 -0
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/hooks/index.js +4 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/useMedia.js.map +1 -0
- package/lib/module/hooks/useMedia.web.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/mq.js +6 -6
- package/lib/module/mq.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +3 -4
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js +1 -2
- package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js.map +1 -1
- package/lib/module/specs/index.web.js +0 -1
- package/lib/module/specs/index.web.js.map +1 -1
- package/lib/module/utils.js +1 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/convert/types.js.map +1 -1
- package/lib/module/web/convert/utils.js +1 -1
- package/lib/module/web/convert/utils.js.map +1 -1
- package/lib/module/web/create.js +12 -4
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/index.js +7 -3
- package/lib/module/web/index.js.map +1 -1
- package/lib/module/web/listener.js.map +1 -1
- package/lib/module/web/runtime.js +8 -8
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +1 -1
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/state.js +24 -17
- package/lib/module/web/state.js.map +1 -1
- package/lib/module/web/utils/common.js +1 -1
- package/lib/module/web/utils/common.js.map +1 -1
- package/lib/module/web/utils/unistyle.js +1 -2
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/module/web/{variants/getVariants.js → variants.js} +3 -3
- package/lib/module/web/variants.js.map +1 -0
- package/lib/typescript/src/components/Pressable.d.ts +7 -0
- package/lib/typescript/src/components/Pressable.d.ts.map +1 -0
- package/lib/typescript/src/components/Pressable.web.d.ts +13 -0
- package/lib/typescript/src/components/Pressable.web.d.ts.map +1 -0
- package/lib/typescript/src/components/index.d.ts +1 -0
- package/lib/typescript/src/components/index.d.ts.map +1 -1
- package/lib/typescript/src/core/getBoundArgs.d.ts +2 -0
- package/lib/typescript/src/core/getBoundArgs.d.ts.map +1 -0
- package/lib/typescript/src/core/getId.d.ts +2 -0
- package/lib/typescript/src/core/getId.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +2 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/index.d.ts +2 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useMedia.web.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +1 -1
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -2
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/types.d.ts +1 -0
- package/lib/typescript/src/specs/ShadowRegistry/types.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts +1 -1
- package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +3 -2
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.web.d.ts +0 -2
- package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
- package/lib/typescript/src/types/common.d.ts +1 -0
- package/lib/typescript/src/types/common.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +1 -1
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/types.d.ts +1 -1
- package/lib/typescript/src/web/convert/types.d.ts.map +1 -1
- package/lib/typescript/src/web/create.d.ts +1 -1
- package/lib/typescript/src/web/create.d.ts.map +1 -1
- package/lib/typescript/src/web/index.d.ts +8 -2
- package/lib/typescript/src/web/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener.d.ts.map +1 -1
- package/lib/typescript/src/web/runtime.d.ts.map +1 -1
- package/lib/typescript/src/web/state.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/common.d.ts +1 -1
- package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts +0 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
- package/lib/typescript/src/web/{variants/getVariants.d.ts → variants.d.ts} +2 -2
- package/lib/typescript/src/web/variants.d.ts.map +1 -0
- package/package.json +12 -16
- package/plugin/common.js +1 -4
- package/plugin/import.js +29 -3
- package/plugin/index.js +18 -8
- package/plugin/ref.js +15 -75
- package/plugin/style.js +251 -88
- package/src/components/Display.tsx +1 -1
- package/src/components/Hide.tsx +1 -1
- package/src/components/Pressable.tsx +101 -0
- package/src/components/Pressable.web.tsx +103 -0
- package/src/components/index.ts +1 -0
- package/src/core/getBoundArgs.ts +15 -0
- package/src/core/getId.ts +1 -0
- package/src/core/index.ts +2 -0
- package/src/hooks/index.ts +1 -0
- package/src/index.ts +1 -1
- package/src/mq.ts +6 -6
- package/src/specs/NativePlatform/NativePlatform.nitro.ts +1 -1
- package/src/specs/ShadowRegistry/index.ts +5 -6
- package/src/specs/ShadowRegistry/types.ts +2 -1
- package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.ts +1 -1
- package/src/specs/StyleSheet/index.ts +3 -2
- package/src/specs/TurboUnistyles/NativeTurboUnistyles.ts +1 -2
- package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +1 -1
- package/src/specs/UnistylesRuntime/index.ts +1 -1
- package/src/specs/index.web.ts +0 -4
- package/src/types/common.ts +1 -0
- package/src/types/index.ts +1 -1
- package/src/utils.ts +1 -1
- package/src/web/convert/types.ts +1 -1
- package/src/web/convert/utils.ts +2 -2
- package/src/web/create.ts +13 -4
- package/src/web/index.ts +7 -3
- package/src/web/listener.ts +2 -0
- package/src/web/registry.ts +1 -1
- package/src/web/runtime.ts +9 -9
- package/src/web/shadowRegistry.ts +3 -3
- package/src/web/state.ts +36 -17
- package/src/web/utils/common.ts +1 -1
- package/src/web/utils/unistyle.ts +3 -9
- package/src/web/{variants/getVariants.ts → variants.ts} +3 -3
- package/lib/commonjs/components/useMedia.js.map +0 -1
- package/lib/commonjs/components/useMedia.web.js.map +0 -1
- package/lib/commonjs/web/variants/getVariants.js.map +0 -1
- package/lib/commonjs/web/variants/index.js +0 -28
- package/lib/commonjs/web/variants/index.js.map +0 -1
- package/lib/commonjs/web/variants/useVariants.js +0 -59
- package/lib/commonjs/web/variants/useVariants.js.map +0 -1
- package/lib/module/components/useMedia.js.map +0 -1
- package/lib/module/components/useMedia.web.js.map +0 -1
- package/lib/module/web/variants/getVariants.js.map +0 -1
- package/lib/module/web/variants/index.js +0 -5
- package/lib/module/web/variants/index.js.map +0 -1
- package/lib/module/web/variants/useVariants.js +0 -54
- package/lib/module/web/variants/useVariants.js.map +0 -1
- package/lib/typescript/src/components/useMedia.d.ts.map +0 -1
- package/lib/typescript/src/components/useMedia.web.d.ts.map +0 -1
- package/lib/typescript/src/web/variants/getVariants.d.ts.map +0 -1
- package/lib/typescript/src/web/variants/index.d.ts +0 -3
- package/lib/typescript/src/web/variants/index.d.ts.map +0 -1
- package/lib/typescript/src/web/variants/useVariants.d.ts +0 -3
- package/lib/typescript/src/web/variants/useVariants.d.ts.map +0 -1
- package/src/web/variants/index.ts +0 -2
- package/src/web/variants/useVariants.ts +0 -65
- /package/lib/commonjs/{components → hooks}/useMedia.js +0 -0
- /package/lib/commonjs/{components → hooks}/useMedia.web.js +0 -0
- /package/lib/module/{components → hooks}/useMedia.js +0 -0
- /package/lib/module/{components → hooks}/useMedia.web.js +0 -0
- /package/lib/typescript/src/{components → hooks}/useMedia.d.ts +0 -0
- /package/lib/typescript/src/{components → hooks}/useMedia.web.d.ts +0 -0
- /package/src/{components → hooks}/useMedia.ts +0 -0
- /package/src/{components → hooks}/useMedia.web.ts +0 -0
package/src/index.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
export * from './specs'
|
2
2
|
export { mq } from './mq'
|
3
3
|
export type { UnistylesThemes, UnistylesBreakpoints } from './global'
|
4
|
-
export { createUnistylesComponent } from './core'
|
4
|
+
export { createUnistylesComponent, getBoundArgs } from './core'
|
5
5
|
export type { UnistylesVariants } from './types'
|
6
6
|
export * from './components'
|
package/src/mq.ts
CHANGED
@@ -45,18 +45,18 @@ const getMQValue = (value: Nullable<MQValue>) => {
|
|
45
45
|
*/
|
46
46
|
export const mq: MQHandler = {
|
47
47
|
only: {
|
48
|
-
width: (wMin: Nullable<MQValue> = 0, wMax: MQValue =
|
49
|
-
height: (hMin: Nullable<MQValue> = 0, hMax: MQValue =
|
48
|
+
width: (wMin: Nullable<MQValue> = 0, wMax: MQValue = Number.POSITIVE_INFINITY) => (`:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]` as unknown as symbol),
|
49
|
+
height: (hMin: Nullable<MQValue> = 0, hMax: MQValue = Number.POSITIVE_INFINITY) => (`:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]` as unknown as symbol)
|
50
50
|
},
|
51
|
-
width: (wMin: Nullable<MQValue> = 0, wMax: MQValue =
|
51
|
+
width: (wMin: Nullable<MQValue> = 0, wMax: MQValue = Number.POSITIVE_INFINITY) => ({
|
52
52
|
and: {
|
53
|
-
height: (hMin: Nullable<MQValue> = 0, hMax: MQValue =
|
53
|
+
height: (hMin: Nullable<MQValue> = 0, hMax: MQValue = Number.POSITIVE_INFINITY) =>
|
54
54
|
(`:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]` as unknown as symbol)
|
55
55
|
}
|
56
56
|
}),
|
57
|
-
height: (hMin: Nullable<MQValue> = 0, hMax: MQValue =
|
57
|
+
height: (hMin: Nullable<MQValue> = 0, hMax: MQValue = Number.POSITIVE_INFINITY) => ({
|
58
58
|
and: {
|
59
|
-
width: (wMin: Nullable<MQValue> = 0, wMax: MQValue =
|
59
|
+
width: (wMin: Nullable<MQValue> = 0, wMax: MQValue = Number.POSITIVE_INFINITY) =>
|
60
60
|
(`:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]` as unknown as symbol)
|
61
61
|
}
|
62
62
|
})
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { HybridObject } from 'react-native-nitro-modules'
|
2
|
-
import {
|
2
|
+
import type { Dimensions, Insets } from '../types'
|
3
3
|
|
4
4
|
type ColorScheme = 'dark' | 'light' | 'unspecified'
|
5
5
|
type Orientation = 'portrait' | 'landscape'
|
@@ -4,10 +4,10 @@ import type { ShadowNode, Unistyle, ViewHandle } from './types'
|
|
4
4
|
|
5
5
|
interface ShadowRegistry extends UnistylesShadowRegistrySpec {
|
6
6
|
// Babel API
|
7
|
-
add(handle?: ViewHandle, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>,
|
7
|
+
add(handle?: ViewHandle, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>, id?: string): void,
|
8
8
|
remove(handle?: ViewHandle): void,
|
9
9
|
// JSI
|
10
|
-
link(node: ShadowNode, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>,
|
10
|
+
link(node: ShadowNode, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>, id?: string): void,
|
11
11
|
unlink(node: ShadowNode): void
|
12
12
|
}
|
13
13
|
|
@@ -19,14 +19,13 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
|
|
19
19
|
?? handle?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node
|
20
20
|
|
21
21
|
if (!node) {
|
22
|
-
|
23
|
-
throw new Error('Could not find shadow node for one of your components')
|
22
|
+
throw new Error(`Unistyles: Could not find shadow node for one of your components of type ${handle?.__internalInstanceHandle?.elementType ?? 'unknown'}`)
|
24
23
|
}
|
25
24
|
|
26
25
|
return node
|
27
26
|
}
|
28
27
|
|
29
|
-
HybridShadowRegistry.add = (handle, styles, variants, args,
|
28
|
+
HybridShadowRegistry.add = (handle, styles, variants, args, id) => {
|
30
29
|
// virtualized nodes can be null
|
31
30
|
if (!handle || !styles || !Array.isArray(styles)) {
|
32
31
|
return
|
@@ -37,7 +36,7 @@ HybridShadowRegistry.add = (handle, styles, variants, args, uniquePressableId) =
|
|
37
36
|
.filter(style => !style?.initial?.updater)
|
38
37
|
.filter(Boolean)
|
39
38
|
|
40
|
-
HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles, variants ?? {}, args ?? [],
|
39
|
+
HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles, variants ?? {}, args ?? [], id)
|
41
40
|
}
|
42
41
|
|
43
42
|
HybridShadowRegistry.remove = handle => {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { HybridObject } from 'react-native-nitro-modules'
|
2
|
-
import { UnistyleDependency } from '../NativePlatform'
|
2
|
+
import type { UnistyleDependency } from '../NativePlatform'
|
3
3
|
|
4
4
|
export interface UnistylesStyleSheet extends HybridObject<{ ios: 'c++', android: 'c++' }> {
|
5
5
|
readonly hairlineWidth: number
|
@@ -6,8 +6,9 @@ import type { UnistylesBreakpoints, UnistylesThemes } from '../../global'
|
|
6
6
|
import type { CreateUnistylesStyleSheet } from '../../types'
|
7
7
|
|
8
8
|
type UnistylesSettings = {
|
9
|
-
|
10
|
-
|
9
|
+
initialTheme: (() => keyof UnistylesThemes) | keyof UnistylesThemes
|
10
|
+
} | {
|
11
|
+
adaptiveThemes: boolean
|
11
12
|
}
|
12
13
|
|
13
14
|
export type UnistylesConfig = {
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import type { TurboModule } from 'react-native'
|
2
2
|
import { TurboModuleRegistry } from 'react-native'
|
3
3
|
|
4
|
-
// this is empty spec for TurboModule that is required to hook
|
5
|
-
// Unistyles to Fabric
|
4
|
+
// this is empty spec for TurboModule that is required to hook Unistyles to Fabric
|
6
5
|
interface Spec extends TurboModule {}
|
7
6
|
|
8
7
|
TurboModuleRegistry.get<Spec>('Unistyles')
|
@@ -6,7 +6,7 @@ import type { UnistylesNativeMiniRuntime } from '../NativePlatform'
|
|
6
6
|
type ColorScheme = 'light' | 'dark' | 'unspecified'
|
7
7
|
type Orientation = 'portrait' | 'landscape'
|
8
8
|
|
9
|
-
// used for Nitro. It's Native + Cxx
|
9
|
+
// used for Nitro. It's (Native + Cxx) type
|
10
10
|
export interface UnistylesCxxMiniRuntime extends UnistylesNativeMiniRuntime {
|
11
11
|
readonly themeName?: string,
|
12
12
|
readonly breakpoint?: string,
|
@@ -3,7 +3,7 @@ import { NitroModules } from 'react-native-nitro-modules'
|
|
3
3
|
import type { UnistylesRuntime as UnistylesRuntimeSpec, UnistylesMiniRuntime } from './UnistylesRuntime.nitro'
|
4
4
|
import type { AppBreakpoint, AppTheme, AppThemeName, Color, ColorScheme, Orientation } from '../types'
|
5
5
|
import { attachStatusBarJSMethods, type UnistylesStatusBar } from '../StatusBar'
|
6
|
-
import {
|
6
|
+
import type { UnistylesNavigationBar } from '../NavigtionBar'
|
7
7
|
import type { AndroidContentSizeCategory, IOSContentSizeCategory, UnistylesTheme } from '../../types'
|
8
8
|
import { isIOS } from '../../common'
|
9
9
|
import type { UnistylesThemes } from '../../global'
|
package/src/specs/index.web.ts
CHANGED
package/src/types/common.ts
CHANGED
@@ -2,3 +2,4 @@ export type Optional<T> = T | undefined
|
|
2
2
|
export type Nullable<T> = T | null
|
3
3
|
export type SafeReturnType<T> = T extends (...args: any) => infer R ? R : T
|
4
4
|
export type PartialBy<T, K> = Omit<T, K & keyof T> & Partial<Pick<T, K & keyof T>>
|
5
|
+
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
|
package/src/types/index.ts
CHANGED
package/src/utils.ts
CHANGED
@@ -6,7 +6,7 @@ export const deepMergeObjects = <T extends Record<PropertyKey, any>>(...sources:
|
|
6
6
|
const sourceValue = source[key]
|
7
7
|
const targetValue = target[key]
|
8
8
|
|
9
|
-
if (Object(sourceValue)
|
9
|
+
if (Object(sourceValue) === sourceValue && Object(targetValue) === targetValue) {
|
10
10
|
// @ts-expect-error - can't assign to generic
|
11
11
|
target[key] = deepMergeObjects(targetValue, sourceValue)
|
12
12
|
|
package/src/web/convert/types.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { FilterFunction, TextStyle, ViewStyle } from 'react-native'
|
2
2
|
import type { ToDeepUnistyles } from '../../types/stylesheet'
|
3
|
+
import type { UnionToIntersection } from '../../types'
|
3
4
|
|
4
5
|
export type ShadowOffset = ToDeepUnistyles<{ width: number, height: number }>
|
5
6
|
|
@@ -15,7 +16,6 @@ export type AllShadow = TextShadow & BoxShadow
|
|
15
16
|
|
16
17
|
export type AllShadowKeys = keyof AllShadow
|
17
18
|
|
18
|
-
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
|
19
19
|
type FilterKeys = keyof UnionToIntersection<FilterFunction>
|
20
20
|
|
21
21
|
export type Filters = {
|
package/src/web/convert/utils.ts
CHANGED
@@ -35,8 +35,8 @@ export const normalizeColor = (color: string, opacity = 1) => {
|
|
35
35
|
if (hex.length === 8) {
|
36
36
|
const [r = 0, g = 0, b = 0, a = 1] = hex
|
37
37
|
.split(/(?=(?:..)*$)/)
|
38
|
-
.map(x => parseInt(x, 16))
|
39
|
-
.filter(num => !isNaN(num))
|
38
|
+
.map(x => Number.parseInt(x, 16))
|
39
|
+
.filter(num => !Number.isNaN(num))
|
40
40
|
|
41
41
|
return `rgba(${r},${g},${b},${(a / 255) * opacity})`
|
42
42
|
}
|
package/src/web/create.ts
CHANGED
@@ -1,11 +1,15 @@
|
|
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, error } from './utils'
|
4
4
|
import { deepMergeObjects } from '../utils'
|
5
5
|
import { UnistylesRuntime } from './runtime'
|
6
|
-
import {
|
6
|
+
import { getVariants } from './variants'
|
7
|
+
|
8
|
+
export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, id?: string) => {
|
9
|
+
if (!id) {
|
10
|
+
throw error('Unistyles is not initialized correctly. Please add babel plugin to your babel config.')
|
11
|
+
}
|
7
12
|
|
8
|
-
export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
|
9
13
|
const computedStylesheet = typeof stylesheet === 'function'
|
10
14
|
? stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime)
|
11
15
|
: stylesheet
|
@@ -42,7 +46,12 @@ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
|
|
42
46
|
}) as ReactNativeStyleSheet<StyleSheet>
|
43
47
|
|
44
48
|
// Inject useVariants hook to styles
|
45
|
-
|
49
|
+
Object.defineProperty(styles, 'useVariants', {
|
50
|
+
value: (variants: Record<string, string | boolean>) => {
|
51
|
+
Object.entries(variants).forEach(([key, value]) => selectedVariants.set(key, value))
|
52
|
+
},
|
53
|
+
configurable: false,
|
54
|
+
})
|
46
55
|
|
47
56
|
return styles
|
48
57
|
}
|
package/src/web/index.ts
CHANGED
@@ -12,6 +12,13 @@ export const StyleSheet = {
|
|
12
12
|
right: 0,
|
13
13
|
bottom: 0,
|
14
14
|
},
|
15
|
+
absoluteFillObject: {
|
16
|
+
position: 'absolute',
|
17
|
+
left: 0,
|
18
|
+
top: 0,
|
19
|
+
right: 0,
|
20
|
+
bottom: 0
|
21
|
+
},
|
15
22
|
compose: (a: object, b: object) => deepMergeObjects(a, b),
|
16
23
|
flatten: (...styles: Array<object>) => deepMergeObjects(...styles),
|
17
24
|
hairlineWidth: 1
|
@@ -20,6 +27,3 @@ export const StyleSheet = {
|
|
20
27
|
export { UnistylesRuntime } from './runtime'
|
21
28
|
export { UnistylesShadowRegistry } from './shadowRegistry'
|
22
29
|
export * from './mock'
|
23
|
-
|
24
|
-
// TODO: Work on SSR
|
25
|
-
export const getSSRUnistyles = () => []
|
package/src/web/listener.ts
CHANGED
@@ -17,6 +17,7 @@ class UnistylesListenerBuilder {
|
|
17
17
|
}
|
18
18
|
|
19
19
|
this.isInitialized = true
|
20
|
+
|
20
21
|
UnistylesRuntime.darkMedia?.addEventListener('change', event => {
|
21
22
|
if (!event.matches) {
|
22
23
|
return
|
@@ -39,6 +40,7 @@ class UnistylesListenerBuilder {
|
|
39
40
|
this.emitChange(UnistyleDependency.Theme)
|
40
41
|
}
|
41
42
|
})
|
43
|
+
|
42
44
|
window.addEventListener('orientationchange', () => this.emitChange(UnistyleDependency.Orientation))
|
43
45
|
window.addEventListener('resize', () => this.emitChange(UnistyleDependency.Dimensions))
|
44
46
|
}
|
package/src/web/registry.ts
CHANGED
package/src/web/runtime.ts
CHANGED
@@ -5,7 +5,7 @@ import { WebContentSizeCategory } from '../types'
|
|
5
5
|
import { UnistylesListener } from './listener'
|
6
6
|
import { NavigationBar, StatusBar } from './mock'
|
7
7
|
import { UnistylesState } from './state'
|
8
|
-
import { isServer, schemeToTheme } from './utils'
|
8
|
+
import { error, isServer, schemeToTheme } from './utils'
|
9
9
|
|
10
10
|
class UnistylesRuntimeBuilder {
|
11
11
|
lightMedia = this.getLightMedia()
|
@@ -152,6 +152,10 @@ class UnistylesRuntimeBuilder {
|
|
152
152
|
}
|
153
153
|
|
154
154
|
setTheme = (themeName: AppThemeName) => {
|
155
|
+
if (this.hasAdaptiveThemes) {
|
156
|
+
throw error(`You're trying to set theme to: '${themeName}', but adaptiveThemes are enabled.`)
|
157
|
+
}
|
158
|
+
|
155
159
|
if (themeName === UnistylesRuntime.themeName) {
|
156
160
|
return
|
157
161
|
}
|
@@ -185,21 +189,17 @@ class UnistylesRuntimeBuilder {
|
|
185
189
|
const oldTheme = UnistylesState.themes.get(themeName)
|
186
190
|
|
187
191
|
if (!oldTheme) {
|
188
|
-
throw
|
192
|
+
throw error(`Unistyles: You're trying to update theme "${themeName}" but it wasn't registered.`)
|
189
193
|
}
|
190
194
|
|
191
195
|
UnistylesState.themes.set(themeName, updater(oldTheme))
|
192
196
|
}
|
193
197
|
|
194
198
|
getTheme = (themeName = this.themeName) => {
|
195
|
-
|
196
|
-
throw new Error('🦄 No theme selected!')
|
197
|
-
}
|
198
|
-
|
199
|
-
const theme = UnistylesState.themes.get(themeName)
|
199
|
+
const theme = UnistylesState.themes.get(themeName ?? '')
|
200
200
|
|
201
|
-
if (!theme) {
|
202
|
-
throw
|
201
|
+
if (!themeName || !theme) {
|
202
|
+
throw error(`You're trying to get theme "${themeName}" but it wasn't registered.`)
|
203
203
|
}
|
204
204
|
|
205
205
|
return theme
|
@@ -65,9 +65,9 @@ class UnistylesShadowRegistryBuilder {
|
|
65
65
|
const parsedStyles = styles.flatMap((style, styleIndex) => extractSecrets(style).map(secret => {
|
66
66
|
const { __uni__key, __uni__stylesheet, __uni__variants, __uni__args = [], __uni__refs } = secret
|
67
67
|
const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
|
68
|
-
const style = newComputedStylesheet[__uni__key]
|
68
|
+
const style = newComputedStylesheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
|
69
69
|
const variants = _variants && Object.keys(_variants).length > 0 ? _variants : __uni__variants
|
70
|
-
const args = _args[styleIndex] ? _args[styleIndex] : __uni__args
|
70
|
+
const args = _args[styleIndex] && _args[styleIndex].length > 0 ? _args[styleIndex] : __uni__args
|
71
71
|
const result = typeof style === 'function'
|
72
72
|
? style(...args)
|
73
73
|
: style
|
@@ -93,7 +93,7 @@ class UnistylesShadowRegistryBuilder {
|
|
93
93
|
}
|
94
94
|
|
95
95
|
const newComputedStyleSheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
|
96
|
-
const newValue = newComputedStyleSheet[__uni__key]
|
96
|
+
const newValue = newComputedStyleSheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
|
97
97
|
const result = typeof newValue === 'function'
|
98
98
|
? newValue(...args)
|
99
99
|
: newValue
|
package/src/web/state.ts
CHANGED
@@ -3,9 +3,12 @@ import type { UnistylesConfig } from '../specs/StyleSheet'
|
|
3
3
|
import type { AppBreakpoint, AppTheme, AppThemeName } from '../specs/types'
|
4
4
|
import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
|
5
5
|
import { UnistylesRuntime } from './runtime'
|
6
|
-
import { isServer, schemeToTheme } from './utils'
|
6
|
+
import { error, isServer, schemeToTheme } from './utils'
|
7
7
|
import { UnistylesListener } from './listener'
|
8
8
|
import { UnistyleDependency } from '../specs/NativePlatform'
|
9
|
+
import type { UnionToIntersection } from '../types'
|
10
|
+
|
11
|
+
type UnistylesSettings = Partial<UnionToIntersection<Required<UnistylesConfig>['settings']>>
|
9
12
|
|
10
13
|
class UnistylesStateBuilder {
|
11
14
|
themes = new Map<string, UnistylesTheme>()
|
@@ -28,7 +31,10 @@ class UnistylesStateBuilder {
|
|
28
31
|
init = (config: UnistylesConfig) => {
|
29
32
|
this.initThemes(config.themes)
|
30
33
|
this.initBreakpoints(config.breakpoints)
|
31
|
-
|
34
|
+
|
35
|
+
if (config.settings) {
|
36
|
+
this.initSettings(config.settings as UnistylesSettings)
|
37
|
+
}
|
32
38
|
|
33
39
|
if (isServer()) {
|
34
40
|
return
|
@@ -43,37 +49,50 @@ class UnistylesStateBuilder {
|
|
43
49
|
})
|
44
50
|
}
|
45
51
|
|
46
|
-
private initSettings = (settings:
|
52
|
+
private initSettings = (settings: UnistylesSettings) => {
|
47
53
|
this.hasAdaptiveThemes = settings?.adaptiveThemes ?? false
|
48
|
-
const themeNames = Array.from(this.themes.keys()) as Array<AppThemeName>
|
49
|
-
|
50
|
-
// Single theme + no settings
|
51
|
-
if (!settings?.adaptiveThemes && !settings?.initialTheme && themeNames.length === 1) {
|
52
|
-
this.themeName = themeNames[0]
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
// No settings
|
58
|
-
if (!settings?.adaptiveThemes && !settings?.initialTheme) {
|
59
|
-
throw new Error('🦄 You need to specify either "initialTheme" or "adaptiveThemes" in your config')
|
55
|
+
if (settings.initialTheme && settings.adaptiveThemes) {
|
56
|
+
throw error('You\'re trying to set initial theme and enable adaptiveThemes, but these options are mutually exclusive.')
|
60
57
|
}
|
61
58
|
|
62
59
|
// Adaptive themes
|
63
60
|
if (settings.adaptiveThemes) {
|
61
|
+
if (!this.themes.get('light') || !this.themes.get('dark')) {
|
62
|
+
throw error(`You're trying to enable adaptiveThemes, but you didn't register both 'light' and 'dark' themes.`)
|
63
|
+
}
|
64
|
+
|
64
65
|
this.themeName = schemeToTheme(UnistylesRuntime.colorScheme) as AppThemeName
|
65
66
|
|
66
67
|
return
|
67
68
|
}
|
68
69
|
|
69
|
-
|
70
|
-
|
70
|
+
if (settings.initialTheme) {
|
71
|
+
const initialTheme = typeof settings.initialTheme === 'function'
|
72
|
+
? settings.initialTheme()
|
73
|
+
: settings.initialTheme
|
74
|
+
|
75
|
+
if (!this.themes.get(initialTheme)) {
|
76
|
+
throw error(`You're trying to select theme "${initialTheme}" but it wasn't registered.`)
|
77
|
+
}
|
78
|
+
|
79
|
+
this.themeName = initialTheme
|
80
|
+
}
|
71
81
|
}
|
72
82
|
|
73
83
|
private initBreakpoints = (breakpoints = {} as UnistylesBreakpoints) => {
|
74
84
|
this.breakpoints = breakpoints
|
85
|
+
const breakpointsEntries = Object.entries(breakpoints)
|
86
|
+
|
87
|
+
if (breakpointsEntries.length === 0) {
|
88
|
+
throw error('StyleSheet.configure\'s breakpoints can\'t be empty.')
|
89
|
+
}
|
90
|
+
|
91
|
+
if (breakpointsEntries?.[0]?.[1] !== 0) {
|
92
|
+
throw error('StyleSheet.configure\'s first breakpoint must start from 0.')
|
93
|
+
}
|
75
94
|
|
76
|
-
|
95
|
+
breakpointsEntries
|
77
96
|
.sort(([, a], [, b]) => a - b)
|
78
97
|
.forEach(([breakpoint, value]) => {
|
79
98
|
if (isServer()) {
|
package/src/web/utils/common.ts
CHANGED
@@ -7,7 +7,7 @@ export const keyInObject = <T extends Record<string, any>>(obj: T, key: Property
|
|
7
7
|
|
8
8
|
export const isServer = () => typeof window === 'undefined'
|
9
9
|
|
10
|
-
export const
|
10
|
+
export const error = (message: string) => new Error(`Unistyles: ${message}`)
|
11
11
|
|
12
12
|
export const equal = <T>(a: T, b: T) => {
|
13
13
|
if (Object.is(a, b)) {
|
@@ -15,14 +15,6 @@ export const schemeToTheme = (scheme: ColorScheme) => {
|
|
15
15
|
}
|
16
16
|
}
|
17
17
|
|
18
|
-
export const hexToRGBA = (hex: string, opacity: number) => hex
|
19
|
-
.replace('#', '')
|
20
|
-
.split(/(?=(?:..)*$)/)
|
21
|
-
.map(x => parseInt(x, 16))
|
22
|
-
.filter(num => !isNaN(num))
|
23
|
-
.reduce((acc, color) => `${acc}${color},`, 'rgba(')
|
24
|
-
.concat(`${opacity})`)
|
25
|
-
|
26
18
|
export type UnistyleSecrets = {
|
27
19
|
__uni__stylesheet: StyleSheetWithSuperPowers<StyleSheet>,
|
28
20
|
__uni__key: string,
|
@@ -73,7 +65,9 @@ export const extractMediaQueryValue = (query: string) => {
|
|
73
65
|
|
74
66
|
const value = Number(px)
|
75
67
|
|
76
|
-
return isNaN(value)
|
68
|
+
return Number.isNaN(value)
|
69
|
+
? undefined
|
70
|
+
: value
|
77
71
|
}
|
78
72
|
|
79
73
|
export const getMediaQuery = (query: string) => {
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import type { ReactNativeStyleSheet, StyleSheet } from '
|
2
|
-
import { deepMergeObjects } from '
|
1
|
+
import type { ReactNativeStyleSheet, StyleSheet } from '../types'
|
2
|
+
import { deepMergeObjects } from '../utils'
|
3
3
|
|
4
4
|
type StylesWithVariants = {
|
5
5
|
variants: Record<string, any>,
|
@@ -16,7 +16,7 @@ export const getVariants = (styles: ReactNativeStyleSheet<StyleSheet>, selectedV
|
|
16
16
|
.map(([key, { variants, compoundVariants = [] }]) => {
|
17
17
|
const variantStyles = Object.entries(variants).flatMap(([variant, styles]) => {
|
18
18
|
const selectedVariant = selectedVariants[variant]
|
19
|
-
const selectedVariantStyles = styles[selectedVariant] ?? styles
|
19
|
+
const selectedVariantStyles = styles[selectedVariant] ?? styles.default
|
20
20
|
|
21
21
|
if (!selectedVariantStyles) {
|
22
22
|
return []
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_react","require","_specs","_mq","useMedia","config","computeIsVisible","maybeMq","mq","isUnistylesMq","console","error","parsedMq","parseMq","isValidMq","width","height","UnistylesRuntime","screen","minWidth","undefined","maxWidth","minHeight","maxHeight","isVisible","setIsVisible","useState","useEffect","useLayoutEffect","removeChangeListener","StyleSheet","addChangeListener","dependencies","includes","UnistyleDependency","Breakpoints","exports"],"sourceRoot":"../../../src","sources":["components/useMedia.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,GAAA,GAAAF,OAAA;AAEO,MAAMG,QAAQ,GAAIC,MAAsB,IAAK;EAChD,MAAMC,gBAAgB,GAAGA,CAAA,KAAe;IACpC,MAAMC,OAAO,GAAGF,MAAM,CAACG,EAAuB;IAE9C,IAAI,CAAC,IAAAC,iBAAa,EAACF,OAAO,CAAC,EAAE;MACzBG,OAAO,CAACC,KAAK,CAAC,sCAAsCJ,OAAO,EAAE,CAAC;MAE9D,OAAO,KAAK;IAChB;IAEA,MAAMK,QAAQ,GAAG,IAAAC,WAAO,EAACN,OAAO,CAAC;IAEjC,IAAI,CAAC,IAAAO,aAAS,EAACF,QAAQ,CAAC,EAAE;MACt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ACG,EAAE,CAAC,CAAC;EAEf,OAAO;IACHgB;EACJ,CAAC;AACL,CAAC;AAAAY,OAAA,CAAAhC,QAAA,GAAAA,QAAA","ignoreList":[]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_react","require","_mq","useMedia","config","disposeRef","useRef","isVisible","setIsVisible","useState","maybeMq","mq","isUnistylesMq","console","error","parsedMq","parseMq","isValidMq","minWidth","maxWidth","minHeight","maxHeight","mediaQuery","undefined","filter","Boolean","join","media","window","matchMedia","handler","event","matches","addEventListener","current","removeEventListener","useEffect","exports"],"sourceRoot":"../../../src","sources":["components/useMedia.web.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,GAAA,GAAAD,OAAA;AAEO,MAAME,QAAQ,GAAIC,MAAsB,IAAK;EAChD,MAAMC,UAAU,GAAG,IAAAC,aAAM,EAAC,MAAM,CAAC,CAAC,CAAC;EACnC,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAG,IAAAC,eAAQ,EAAC,MAAM;IAC7C,MAAMC,OAAO,GAAGN,MAAM,CAACO,EAAuB;IAE9C,IAAI,CAAC,IAAAC,iBAAa,EAACF,OAAO,CAAC,EAAE;MACzBG,OAAO,CAACC,KAAK,CAAC,sCAAsCJ,OAAO,EAAE,CAAC;MAE9D,OAAO,KAAK;IAChB;IAEA,MAAMK,QAAQ,GAAG,IAAAC,WAAO,EAACN,OAAO,CAAC;IAEjC,IAAI,CAAC,IAAAO,aAAS,EAACF,QAAQ,CAAC,EAAE;MACtBF,OAAO,CAACC,KAAK,CAAC,oEAAoEJ,OAAO,EAAE,CAAC;MAE5F,OAAO,KAAK;IAChB;IAEA,MAAM;MAAEQ,QAAQ;MAAEC,QAAQ;MAAEC,SAAS;MAAEC;IAAU,CAAC,GAAGN,QAAQ;IAE7D,MAAMO,UAAU,GAAG,CACfJ,QAAQ,KAAKK,SAAS,GAAG,eAAeL,QAAQ,KAAK,GAAGK,SAAS,EACjEJ,QAAQ,KAAKI,SAAS,GAAG,eAAeJ,QAAQ,KAAK,GAAGI,SAAS,EACjEH,SAAS,KAAKG,SAAS,GAAG,gBAAgBH,SAAS,KAAK,GAAGG,SAAS,EACpEF,SAAS,KAAKE,SAAS,GAAG,gBAAgBF,SAAS,KAAK,GAAGE,SAAS,CACvE,CAACC,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,OAAO,CAAC;IAE/B,MAAMC,KAAK,GAAGC,MAAM,CAACC,UAAU,CAACP,UAAU,CAAC;IAC3C,MAAMQ,OAAO,GAAIC,KAA0B,IAAKvB,YAAY,CAACuB,KAAK,CAACC,OAAO,CAAC;IAE3EL,KAAK,CAACM,gBAAgB,CAAC,QAAQ,EAAEH,OAAO,CAAC;IACzCzB,UAAU,CAAC6B,OAAO,GAAG,MAAMP,KAAK,CAACQ,mBAAmB,CAAC,QAAQ,EAAEL,OAAO,CAAC;IAEvE,OAAOH,KAAK,CAACK,OAAO;EACxB,CAAC,CAAC;;EAEF;EACA,IAAAI,gBAAS,EAAC,MAAM,MAAM/B,UAAU,CAAC6B,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC;EAE/C,OAAO;IACH3B;EACJ,CAAC;AACL,CAAC;AAAA8B,OAAA,CAAAlC,QAAA,GAAAA,QAAA","ignoreList":[]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_utils","require","hasVariants","value","getVariants","styles","selectedVariants","Object","entries","filter","_key","variants","keys","some","variant","map","key","compoundVariants","variantStyles","flatMap","selectedVariant","selectedVariantStyles","compoundVariantStyles","compoundVariant","conditions","String","mergedVariantStyles","deepMergeObjects","exports"],"sourceRoot":"../../../../src","sources":["web/variants/getVariants.ts"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAQA,MAAMC,WAAW,GAAsBC,KAAkB,IAAgD,UAAU,IAAIA,KAAK,CAAC,CAAC,CAAC;AAExH,MAAMC,WAAW,GAAGA,CAACC,MAAyC,EA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B,CAAC;IAExF,OAAO,CAACN,GAAG,EAAEU,mBAAmB,CAAC;EACrC,CAAC,CAAC;AACV,CAAC;AAAAE,OAAA,CAAAxB,WAAA,GAAAA,WAAA","ignoreList":[]}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
var _useVariants = require("./useVariants");
|
7
|
-
Object.keys(_useVariants).forEach(function (key) {
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
9
|
-
if (key in exports && exports[key] === _useVariants[key]) return;
|
10
|
-
Object.defineProperty(exports, key, {
|
11
|
-
enumerable: true,
|
12
|
-
get: function () {
|
13
|
-
return _useVariants[key];
|
14
|
-
}
|
15
|
-
});
|
16
|
-
});
|
17
|
-
var _getVariants = require("./getVariants");
|
18
|
-
Object.keys(_getVariants).forEach(function (key) {
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
20
|
-
if (key in exports && exports[key] === _getVariants[key]) return;
|
21
|
-
Object.defineProperty(exports, key, {
|
22
|
-
enumerable: true,
|
23
|
-
get: function () {
|
24
|
-
return _getVariants[key];
|
25
|
-
}
|
26
|
-
});
|
27
|
-
});
|
28
|
-
//# sourceMappingURL=index.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_useVariants","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_getVariants"],"sourceRoot":"../../../../src","sources":["web/variants/index.ts"],"mappings":";;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,YAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,YAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,YAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,YAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,YAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,YAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,YAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
@@ -1,59 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.createUseVariants = void 0;
|
7
|
-
var _react = require("react");
|
8
|
-
var _utils = require("../utils");
|
9
|
-
var _getVariants = require("./getVariants");
|
10
|
-
const createUseVariants = (styles, setSelectedVariants) => {
|
11
|
-
const useVariants = selectedVariants => {
|
12
|
-
const [selectedVariantStylesMap] = (0, _react.useState)(() => new Map());
|
13
|
-
const lastSelectedVariantsRef = (0, _react.useRef)();
|
14
|
-
// Variable that determines if variants have changed and we need to recalculate styles
|
15
|
-
const variantsChanged = !(0, _utils.equal)(lastSelectedVariantsRef.current, selectedVariants);
|
16
|
-
if (variantsChanged) {
|
17
|
-
lastSelectedVariantsRef.current = selectedVariants;
|
18
|
-
setSelectedVariants(selectedVariants);
|
19
|
-
}
|
20
|
-
const combinedVariantStyles = (0, _react.useMemo)(() => {
|
21
|
-
const result = (0, _getVariants.getVariants)(styles, selectedVariants);
|
22
|
-
result.forEach(([key, value]) => {
|
23
|
-
selectedVariantStylesMap.set(key, value);
|
24
|
-
});
|
25
|
-
return result;
|
26
|
-
}, [lastSelectedVariantsRef.current]);
|
27
|
-
combinedVariantStyles.forEach(([key]) => {
|
28
|
-
const styleEntry = styles[key];
|
29
|
-
if (!styleEntry) {
|
30
|
-
return;
|
31
|
-
}
|
32
|
-
const selectedVariantStyles = selectedVariantStylesMap.get(key);
|
33
|
-
Object.defineProperties(styleEntry, (0, _utils.reduceObject)(selectedVariantStyles ?? {}, value => ({
|
34
|
-
value,
|
35
|
-
enumerable: false,
|
36
|
-
configurable: true
|
37
|
-
})));
|
38
|
-
|
39
|
-
// Add __uni__variants to static styles
|
40
|
-
Object.keys(styleEntry).forEach(key => {
|
41
|
-
if (!key.startsWith('__uni__secrets__')) {
|
42
|
-
return;
|
43
|
-
}
|
44
|
-
const secret = (0, _utils.keyInObject)(styleEntry, key) ? styleEntry[key] : undefined;
|
45
|
-
if (!secret) {
|
46
|
-
return;
|
47
|
-
}
|
48
|
-
Object.defineProperty(secret, '__uni__variants', {
|
49
|
-
value: selectedVariants
|
50
|
-
});
|
51
|
-
});
|
52
|
-
});
|
53
|
-
};
|
54
|
-
Object.defineProperty(styles, 'useVariants', {
|
55
|
-
value: useVariants
|
56
|
-
});
|
57
|
-
};
|
58
|
-
exports.createUseVariants = createUseVariants;
|
59
|
-
//# sourceMappingURL=useVariants.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_react","require","_utils","_getVariants","createUseVariants","styles","setSelectedVariants","useVariants","selectedVariants","selectedVariantStylesMap","useState","Map","lastSelectedVariantsRef","useRef","variantsChanged","equal","current","combinedVariantStyles","useMemo","result","getVariants","forEach","key","value","set","styleEntry","selectedVariantStyles","get","Object","defineProperties","reduceObject","enumerable","configurable","keys","startsWith","secret","keyInObject","undefined","defineProperty","exports"],"sourceRoot":"../../../../src","sources":["web/variants/useVariants.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEO,MAAMG,iBAAiB,GAAGA,CAACC,MAAyC,EAAEC,mB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ACK,IAAI,CAACR,UAAU,CAAC,CAACJ,OAAO,CAACC,GAAG,IAAI;QACnC,IAAI,CAACA,GAAG,CAACY,UAAU,CAAC,kBAAkB,CAAC,EAAE;UACrC;QACJ;QAEA,MAAMC,MAAM,GAAG,IAAAC,kBAAW,EAACX,UAAU,EAAEH,GAAG,CAAC,GAAGG,UAAU,CAACH,GAAG,CAAC,GAAGe,SAAS;QAEzE,IAAI,CAACF,MAAM,EAAE;UACT;QACJ;QAEAP,MAAM,CAACU,cAAc,CAACH,MAAM,EAAE,iBAAiB,EAAE;UAC7CZ,KAAK,EAAEf;QACX,CAAC,CAAC;MACN,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC;EAEDoB,MAAM,CAACU,cAAc,CAACjC,MAAM,EAAE,aAAa,EAAE;IACzCkB,KAAK,EAAEhB;EACX,CAAC,CAAC;AACN,CAAC;AAAAgC,OAAA,CAAAnC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["useEffect","useLayoutEffect","useState","StyleSheet","UnistyleDependency","UnistylesRuntime","isValidMq","parseMq","isUnistylesMq","useMedia","config","computeIsVisible","maybeMq","mq","console","error","parsedMq","width","height","screen","minWidth","undefined","maxWidth","minHeight","maxHeight","isVisible","setIsVisible","removeChangeListener","addChangeListener","dependencies","includes","Breakpoints"],"sourceRoot":"../../../src","sources":["components/useMedia.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,eAAe,EAAEC,QAAQ,QAAQ,OAAO;AAC5D,SAASC,UAAU,EAAEC,kBAAkB,EAAEC,gBAAgB,QAAkC,UAAU;AACrG,SAASC,SAAS,EAAEC,OAAO,EAAEC,aAAa,QAAQ,OAAO;AAEzD,OAAO,MAAMC,QAAQ,GAAIC,MAAsB,IAAK;EAChD,MAAMC,gBAAgB,GAAGA,CAAA,KAAe;IACpC,MAAMC,OAAO,GAAGF,MAAM,CAACG,EAAuB;IAE9C,IAAI,CAACL,aAAa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