react-native-unistyles 2.0.0-alpha.1 → 2.0.0-alpha.10
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -4
- package/cxx/UnistylesRuntime.cpp +255 -0
- package/cxx/UnistylesRuntime.h +60 -0
- package/ios/UnistylesHelpers.h +4 -0
- package/ios/UnistylesHelpers.mm +20 -0
- package/ios/UnistylesModule.h +10 -0
- package/ios/UnistylesModule.mm +158 -0
- package/lib/commonjs/common.js +26 -0
- package/lib/commonjs/common.js.map +1 -0
- package/lib/commonjs/core/UnistyleRegistry.js +38 -0
- package/lib/commonjs/core/UnistyleRegistry.js.map +1 -0
- package/lib/commonjs/core/Unistyles.js +31 -0
- package/lib/commonjs/core/Unistyles.js.map +1 -0
- package/lib/commonjs/core/UnistylesModule.js +9 -0
- package/lib/commonjs/core/UnistylesModule.js.map +1 -0
- package/lib/commonjs/core/UnistylesRuntime.js +66 -0
- package/lib/commonjs/core/UnistylesRuntime.js.map +1 -0
- package/lib/commonjs/core/index.js +13 -0
- package/lib/commonjs/core/index.js.map +1 -0
- package/lib/commonjs/createStyleSheet.js +14 -0
- package/lib/commonjs/createStyleSheet.js.map +1 -0
- package/lib/commonjs/global.js +2 -0
- package/lib/commonjs/global.js.map +1 -0
- package/lib/commonjs/hooks/index.js +10 -3
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useInitialTheme.js +17 -0
- package/lib/commonjs/hooks/useInitialTheme.js.map +1 -0
- package/lib/commonjs/hooks/useUnistyles.js +54 -0
- package/lib/commonjs/hooks/useUnistyles.js.map +1 -0
- package/lib/commonjs/index.js +35 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/common.js +2 -0
- package/lib/commonjs/types/{mediaQueries.js.map → common.js.map} +1 -1
- package/lib/commonjs/types/index.js +26 -0
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/types/mq.js +6 -0
- package/lib/{module/types/mediaQueries.js.map → commonjs/types/mq.js.map} +1 -1
- package/lib/commonjs/types/normalizer.js +6 -0
- package/lib/commonjs/types/normalizer.js.map +1 -0
- package/lib/commonjs/types/unistyles.js +6 -0
- package/lib/commonjs/types/unistyles.js.map +1 -0
- package/lib/commonjs/useStyles.js +49 -0
- package/lib/commonjs/useStyles.js.map +1 -0
- package/lib/commonjs/utils/breakpoints.js +44 -82
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/common.js +10 -3
- package/lib/commonjs/utils/common.js.map +1 -1
- package/lib/commonjs/utils/index.js +46 -17
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/module.d.js +2 -0
- package/lib/commonjs/utils/module.d.js.map +1 -0
- package/lib/commonjs/utils/mq.js +89 -0
- package/lib/commonjs/utils/mq.js.map +1 -0
- package/lib/commonjs/utils/mqParser.js +86 -0
- package/lib/commonjs/utils/mqParser.js.map +1 -0
- package/lib/commonjs/utils/normalizeStyles.web.js +13 -13
- package/lib/commonjs/utils/normalizeStyles.web.js.map +1 -1
- package/lib/commonjs/utils/normalizer.js +89 -0
- package/lib/commonjs/utils/normalizer.js.map +1 -0
- package/lib/commonjs/utils/styles.js +17 -57
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/commonjs/utils/variants.js +20 -0
- package/lib/commonjs/utils/variants.js.map +1 -0
- package/lib/module/common.js +22 -0
- package/lib/module/common.js.map +1 -0
- package/lib/module/core/UnistyleRegistry.js +31 -0
- package/lib/module/core/UnistyleRegistry.js.map +1 -0
- package/lib/module/core/Unistyles.js +25 -0
- package/lib/module/core/Unistyles.js.map +1 -0
- package/lib/module/core/UnistylesModule.js +3 -0
- package/lib/module/core/UnistylesModule.js.map +1 -0
- package/lib/module/core/UnistylesRuntime.js +59 -0
- package/lib/module/core/UnistylesRuntime.js.map +1 -0
- package/lib/module/core/index.js +2 -0
- package/lib/module/core/index.js.map +1 -0
- package/lib/module/createStyleSheet.js +7 -0
- package/lib/module/createStyleSheet.js.map +1 -0
- package/lib/module/global.js +2 -0
- package/lib/module/global.js.map +1 -0
- package/lib/module/hooks/index.js +2 -1
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useInitialTheme.js +10 -0
- package/lib/module/hooks/useInitialTheme.js.map +1 -0
- package/lib/module/hooks/useUnistyles.js +47 -0
- package/lib/module/hooks/useUnistyles.js.map +1 -0
- package/lib/module/index.js +13 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/common.js +2 -0
- package/lib/module/types/common.js.map +1 -0
- package/lib/module/types/index.js +2 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/types/mq.js +2 -0
- package/lib/module/types/mq.js.map +1 -0
- package/lib/module/types/normalizer.js +2 -0
- package/lib/module/types/normalizer.js.map +1 -0
- package/lib/module/types/unistyles.js +2 -0
- package/lib/module/types/unistyles.js.map +1 -0
- package/lib/module/useStyles.js +42 -0
- package/lib/module/useStyles.js.map +1 -0
- package/lib/module/utils/breakpoints.js +43 -82
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/common.js +9 -1
- package/lib/module/utils/common.js.map +1 -1
- package/lib/module/utils/index.js +6 -2
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/module.d.js +2 -0
- package/lib/module/utils/module.d.js.map +1 -0
- package/lib/module/utils/mq.js +83 -0
- package/lib/module/utils/mq.js.map +1 -0
- package/lib/module/utils/mqParser.js +79 -0
- package/lib/module/utils/mqParser.js.map +1 -0
- package/lib/module/utils/normalizeStyles.web.js +13 -13
- package/lib/module/utils/normalizeStyles.web.js.map +1 -1
- package/lib/module/utils/normalizer.js +79 -0
- package/lib/module/utils/normalizer.js.map +1 -0
- package/lib/module/utils/styles.js +17 -59
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/module/utils/variants.js +13 -0
- package/lib/module/utils/variants.js.map +1 -0
- package/lib/typescript/src/common.d.ts +17 -0
- package/lib/typescript/src/common.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistyleRegistry.d.ts +15 -0
- package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -0
- package/lib/typescript/src/core/Unistyles.d.ts +13 -0
- package/lib/typescript/src/core/Unistyles.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts +6 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesRuntime.d.ts +24 -0
- package/lib/typescript/src/core/UnistylesRuntime.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 -0
- package/lib/typescript/src/createStyleSheet.d.ts +3 -0
- package/lib/typescript/src/createStyleSheet.d.ts.map +1 -0
- package/lib/typescript/src/global.d.ts +7 -0
- package/lib/typescript/src/global.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +2 -1
- package/lib/typescript/src/hooks/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useInitialTheme.d.ts +3 -0
- package/lib/typescript/src/hooks/useInitialTheme.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts +12 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +14 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +13 -13
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/common.d.ts +3 -0
- package/lib/typescript/src/types/common.d.ts.map +1 -0
- package/lib/typescript/src/types/core.d.ts +34 -18
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +6 -2
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/mq.d.ts +3 -0
- package/lib/typescript/src/types/mq.d.ts.map +1 -0
- package/lib/typescript/src/types/normalizer.d.ts +20 -0
- package/lib/typescript/src/types/normalizer.d.ts.map +1 -0
- package/lib/typescript/src/types/unistyles.d.ts +37 -0
- package/lib/typescript/src/types/unistyles.d.ts.map +1 -0
- package/lib/typescript/src/useStyles.d.ts +10 -0
- package/lib/typescript/src/useStyles.d.ts.map +1 -0
- package/lib/typescript/src/utils/breakpoints.d.ts +5 -62
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/utils/common.d.ts +9 -1
- package/lib/typescript/src/utils/common.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +6 -2
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/mq.d.ts +21 -0
- package/lib/typescript/src/utils/mq.d.ts.map +1 -0
- package/lib/typescript/src/utils/mqParser.d.ts +3 -0
- package/lib/typescript/src/utils/mqParser.d.ts.map +1 -0
- package/lib/typescript/src/utils/normalizeStyles.web.d.ts +4 -1
- package/lib/typescript/src/utils/normalizeStyles.web.d.ts.map +1 -1
- package/lib/typescript/src/utils/normalizer.d.ts +11 -0
- package/lib/typescript/src/utils/normalizer.d.ts.map +1 -0
- package/lib/typescript/src/utils/styles.d.ts +5 -49
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/lib/typescript/src/utils/variants.d.ts +3 -0
- package/lib/typescript/src/utils/variants.d.ts.map +1 -0
- package/package.json +33 -15
- package/react-native-unistyles.podspec +22 -0
- package/src/common.ts +19 -0
- package/src/core/UnistyleRegistry.ts +41 -0
- package/src/core/Unistyles.ts +34 -0
- package/src/core/UnistylesModule.ts +7 -0
- package/src/core/UnistylesRuntime.ts +73 -0
- package/src/core/index.ts +1 -0
- package/src/createStyleSheet.ts +9 -0
- package/src/global.ts +5 -0
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useInitialTheme.ts +11 -0
- package/src/hooks/useUnistyles.ts +55 -0
- package/src/index.ts +30 -2
- package/src/types/breakpoints.ts +20 -20
- package/src/types/common.ts +2 -0
- package/src/types/core.ts +42 -24
- package/src/types/index.ts +6 -9
- package/src/types/mq.ts +3 -0
- package/src/types/normalizer.ts +29 -0
- package/src/types/unistyles.ts +45 -0
- package/src/useStyles.ts +56 -0
- package/src/utils/breakpoints.ts +57 -88
- package/src/utils/common.ts +10 -1
- package/src/utils/index.ts +6 -9
- package/src/utils/module.d.ts +3 -0
- package/src/utils/mq.ts +106 -0
- package/src/utils/mqParser.ts +99 -0
- package/src/utils/normalizeStyles.web.ts +21 -42
- package/src/utils/normalizer.ts +99 -0
- package/src/utils/styles.ts +29 -68
- package/src/utils/variants.ts +17 -0
- package/lib/commonjs/UnistylesTheme.js +0 -21
- package/lib/commonjs/UnistylesTheme.js.map +0 -1
- package/lib/commonjs/createUnistyles.js +0 -57
- package/lib/commonjs/createUnistyles.js.map +0 -1
- package/lib/commonjs/hooks/useDimensions.js +0 -10
- package/lib/commonjs/hooks/useDimensions.js.map +0 -1
- package/lib/commonjs/hooks/useDimensions.web.js +0 -31
- package/lib/commonjs/hooks/useDimensions.web.js.map +0 -1
- package/lib/commonjs/types/mediaQueries.js +0 -2
- package/lib/commonjs/utils/mediaQueries.js +0 -189
- package/lib/commonjs/utils/mediaQueries.js.map +0 -1
- package/lib/module/UnistylesTheme.js +0 -12
- package/lib/module/UnistylesTheme.js.map +0 -1
- package/lib/module/createUnistyles.js +0 -50
- package/lib/module/createUnistyles.js.map +0 -1
- package/lib/module/hooks/useDimensions.js +0 -3
- package/lib/module/hooks/useDimensions.js.map +0 -1
- package/lib/module/hooks/useDimensions.web.js +0 -24
- package/lib/module/hooks/useDimensions.web.js.map +0 -1
- package/lib/module/types/mediaQueries.js +0 -2
- package/lib/module/utils/mediaQueries.js +0 -176
- package/lib/module/utils/mediaQueries.js.map +0 -1
- package/lib/typescript/src/UnistylesTheme.d.ts +0 -9
- package/lib/typescript/src/UnistylesTheme.d.ts.map +0 -1
- package/lib/typescript/src/createUnistyles.d.ts +0 -10
- package/lib/typescript/src/createUnistyles.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useDimensions.d.ts +0 -3
- package/lib/typescript/src/hooks/useDimensions.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useDimensions.web.d.ts +0 -3
- package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +0 -1
- package/lib/typescript/src/types/mediaQueries.d.ts +0 -8
- package/lib/typescript/src/types/mediaQueries.d.ts.map +0 -1
- package/lib/typescript/src/utils/mediaQueries.d.ts +0 -130
- package/lib/typescript/src/utils/mediaQueries.d.ts.map +0 -1
- package/src/UnistylesTheme.tsx +0 -17
- package/src/__tests__/createUnistyles.spec.tsx +0 -192
- package/src/createUnistyles.ts +0 -70
- package/src/hooks/useDimensions.ts +0 -4
- package/src/hooks/useDimensions.web.ts +0 -30
- package/src/types/mediaQueries.ts +0 -10
- package/src/utils/mediaQueries.ts +0 -201
@@ -0,0 +1,99 @@
|
|
1
|
+
// based on react-native-web normalizer
|
2
|
+
// https://github.com/necolas/react-native-web
|
3
|
+
import normalizeColors from '@react-native/normalize-colors'
|
4
|
+
import type { TextShadow, Transforms, BoxShadow } from '../types'
|
5
|
+
|
6
|
+
type Preprocessor = {
|
7
|
+
createTextShadowValue(style: TextShadow): string,
|
8
|
+
createBoxShadowValue(style: Required<BoxShadow>): string,
|
9
|
+
createTransformValue(transforms: Required<Transforms>): string,
|
10
|
+
}
|
11
|
+
|
12
|
+
export const normalizeColor = (color: string, opacity: number = 1) => {
|
13
|
+
// If the opacity is 1 there's no need to normalize the color
|
14
|
+
if (opacity === 1) {
|
15
|
+
return color
|
16
|
+
}
|
17
|
+
|
18
|
+
const integer = normalizeColors(color) as number | null
|
19
|
+
|
20
|
+
// If the colour is an unknown format, the return value is null
|
21
|
+
if (integer === null) {
|
22
|
+
return color
|
23
|
+
}
|
24
|
+
|
25
|
+
const hex = integer.toString(16).padStart(8, '0')
|
26
|
+
|
27
|
+
if (hex.length === 8) {
|
28
|
+
const [r = 0, g = 0, b = 0, a = 1] = hex
|
29
|
+
.split(/(?=(?:..)*$)/)
|
30
|
+
.map(x => parseInt(x, 16))
|
31
|
+
.filter(num => !isNaN(num))
|
32
|
+
|
33
|
+
return `rgba(${r},${g},${b},${((a as number) / 255) * opacity})`
|
34
|
+
}
|
35
|
+
|
36
|
+
return color
|
37
|
+
}
|
38
|
+
|
39
|
+
export const normalizeNumericValue = (value: number) => value ? `${value}px` : value
|
40
|
+
const normalizeTransform = (key: string, value: number | string) => {
|
41
|
+
if (key.includes('scale')) {
|
42
|
+
return value
|
43
|
+
}
|
44
|
+
|
45
|
+
if (typeof value === 'number') {
|
46
|
+
return normalizeNumericValue(value)
|
47
|
+
}
|
48
|
+
|
49
|
+
return value
|
50
|
+
}
|
51
|
+
|
52
|
+
const createTextShadowValue = (style: TextShadow) => {
|
53
|
+
// at this point every prop is present
|
54
|
+
const { textShadowColor, textShadowOffset, textShadowRadius } = style
|
55
|
+
const offsetX = normalizeNumericValue(textShadowOffset.width)
|
56
|
+
const offsetY = normalizeNumericValue(textShadowOffset.height)
|
57
|
+
const radius = normalizeNumericValue(textShadowRadius)
|
58
|
+
const color = normalizeColor(textShadowColor as string)
|
59
|
+
|
60
|
+
return `${offsetX} ${offsetY} ${radius} ${color}`
|
61
|
+
}
|
62
|
+
|
63
|
+
const createBoxShadowValue = (style: BoxShadow) => {
|
64
|
+
// at this point every prop is present
|
65
|
+
const { shadowColor, shadowOffset, shadowOpacity, shadowRadius } = style
|
66
|
+
const offsetX = normalizeNumericValue(shadowOffset.width)
|
67
|
+
const offsetY = normalizeNumericValue(shadowOffset.height)
|
68
|
+
const radius = normalizeNumericValue(shadowRadius)
|
69
|
+
const color = normalizeColor(shadowColor as string, shadowOpacity as number)
|
70
|
+
|
71
|
+
return `${offsetX} ${offsetY} ${radius} ${color}`
|
72
|
+
}
|
73
|
+
|
74
|
+
const createTransformValue = (transforms: Transforms) => transforms
|
75
|
+
.map(transform => {
|
76
|
+
const [key] = Object.keys(transform)
|
77
|
+
|
78
|
+
if (!key) {
|
79
|
+
return undefined
|
80
|
+
}
|
81
|
+
|
82
|
+
const value = transform[key as keyof typeof transform]
|
83
|
+
|
84
|
+
switch(key) {
|
85
|
+
case 'matrix':
|
86
|
+
case 'matrix3d':
|
87
|
+
return `${key}(${(value as Array<number>).join(',')})`
|
88
|
+
default:
|
89
|
+
return `${key}(${normalizeTransform(key, value)})`
|
90
|
+
}
|
91
|
+
})
|
92
|
+
.filter(Boolean)
|
93
|
+
.join(' ')
|
94
|
+
|
95
|
+
export const preprocessor: Preprocessor = {
|
96
|
+
createTextShadowValue,
|
97
|
+
createBoxShadowValue,
|
98
|
+
createTransformValue
|
99
|
+
}
|
package/src/utils/styles.ts
CHANGED
@@ -1,72 +1,35 @@
|
|
1
|
-
import type {
|
2
|
-
import {
|
1
|
+
import type { CustomNamedStyles, ScreenSize, NestedStyle } from '../types'
|
2
|
+
import { getValueForNestedStyle } from './breakpoints'
|
3
3
|
import { normalizeStyles } from './normalizeStyles'
|
4
|
-
import {
|
4
|
+
import type { UnistylesBreakpoints } from '../global'
|
5
|
+
import { isAndroid, isIOS, isWeb } from './common'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
*
|
9
|
-
* @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
|
10
|
-
*
|
11
|
-
* @param {Function} fn - The function to be proxified.
|
12
|
-
* @param {keyof B & string} breakpoint - The breakpoint name to check against.
|
13
|
-
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
14
|
-
* @param breakpointPairs - sorted pairs of breakpoints
|
15
|
-
*
|
16
|
-
* @returns {Function} Returns the proxified function
|
17
|
-
*
|
18
|
-
* @example
|
19
|
-
*
|
20
|
-
* const myFunction = () => ({ ':w[200]': 'value1', sm: 'value2' })
|
21
|
-
* const screenSize = { width: 250, height: 400 }
|
22
|
-
* const breakpoints = { sm: 300, md: 600 }
|
23
|
-
*
|
24
|
-
* const proxifiedFunction = proxifyFunction(myFunction, 'sm', screenSize, breakpoints)
|
25
|
-
* proxifiedFunction() // parsed style based on screenSize and breakpoints
|
26
|
-
*/
|
27
|
-
export const proxifyFunction = <B extends Breakpoints>(
|
28
|
-
fn: Function, breakpoint: keyof B & string,
|
7
|
+
export const proxifyFunction = (
|
8
|
+
fn: Function, breakpoint: keyof UnistylesBreakpoints & string,
|
29
9
|
screenSize: ScreenSize,
|
30
|
-
|
10
|
+
variant?: string
|
31
11
|
): Function => new Proxy(fn, {
|
32
12
|
apply: (target, thisArg, argumentsList) =>
|
33
|
-
parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize,
|
13
|
+
parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize, variant)
|
34
14
|
})
|
35
15
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
48
|
-
* @param breakpointPairs - sorted pairs of breakpoints
|
49
|
-
*
|
50
|
-
* @returns {Record<string, string | number | Function>} Returns the parsed style object with resolved custom media queries or breakpoints.
|
51
|
-
*
|
52
|
-
* @example
|
53
|
-
*
|
54
|
-
* const style = { fontSize: { sm: '12px', md: '16px' } }
|
55
|
-
* const screenSize = { width: 300, height: 400 }
|
56
|
-
* const breakpoints = { xs: 0, sm: 300, md: 600 }
|
57
|
-
*
|
58
|
-
* const parsedStyle = parseStyle(style, 'sm', screenSize, breakpoints)
|
59
|
-
* // { fontSize: '12px' }
|
60
|
-
*/
|
61
|
-
export const parseStyle = <T, B extends Breakpoints>(
|
62
|
-
style: CustomNamedStyles<T, B>,
|
63
|
-
breakpoint: keyof B & string,
|
16
|
+
export const isPlatformColor = <T extends {}>(value: T): boolean => {
|
17
|
+
if (isIOS) {
|
18
|
+
return 'semantic' in value && typeof value.semantic === 'object'
|
19
|
+
}
|
20
|
+
|
21
|
+
return isAndroid && 'resource_paths' in value && typeof value.resource_paths === 'object'
|
22
|
+
}
|
23
|
+
|
24
|
+
export const parseStyle = <T>(
|
25
|
+
style: CustomNamedStyles<T>,
|
26
|
+
breakpoint: keyof UnistylesBreakpoints & string,
|
64
27
|
screenSize: ScreenSize,
|
65
|
-
|
28
|
+
variant?: string
|
66
29
|
): T => {
|
67
|
-
const entries = Object.entries(style) as [[
|
30
|
+
const entries = Object.entries(style || {}) as [[
|
68
31
|
keyof T,
|
69
|
-
CustomNamedStyles<T
|
32
|
+
CustomNamedStyles<T> | NestedStyle]
|
70
33
|
]
|
71
34
|
|
72
35
|
const parsedStyles = Object
|
@@ -77,7 +40,7 @@ export const parseStyle = <T, B extends Breakpoints>(
|
|
77
40
|
if (hasNestedProperties) {
|
78
41
|
return [
|
79
42
|
key,
|
80
|
-
parseStyle(value as CustomNamedStyles<T
|
43
|
+
parseStyle(value as CustomNamedStyles<T>, breakpoint, screenSize, variant)
|
81
44
|
]
|
82
45
|
}
|
83
46
|
|
@@ -86,12 +49,12 @@ export const parseStyle = <T, B extends Breakpoints>(
|
|
86
49
|
if (isTransform && Array.isArray(value)) {
|
87
50
|
return [
|
88
51
|
key,
|
89
|
-
value.map(value => parseStyle(value, breakpoint, screenSize,
|
52
|
+
value.map(value => parseStyle(value, breakpoint, screenSize, variant))
|
90
53
|
]
|
91
54
|
}
|
92
55
|
|
93
56
|
const isDynamicFunction = typeof value === 'function'
|
94
|
-
const isValidStyle = typeof value !== 'object'
|
57
|
+
const isValidStyle = typeof value !== 'object' || isPlatformColor(value)
|
95
58
|
|
96
59
|
if (isDynamicFunction || isValidStyle) {
|
97
60
|
return [key, value]
|
@@ -99,17 +62,15 @@ export const parseStyle = <T, B extends Breakpoints>(
|
|
99
62
|
|
100
63
|
return [
|
101
64
|
key,
|
102
|
-
|
103
|
-
value as
|
104
|
-
|
105
|
-
screenSize,
|
106
|
-
breakpointPairs
|
65
|
+
getValueForNestedStyle(
|
66
|
+
value as NestedStyle,
|
67
|
+
variant
|
107
68
|
)
|
108
69
|
]
|
109
70
|
})
|
110
71
|
)
|
111
72
|
|
112
|
-
return isWeb
|
73
|
+
return isWeb
|
113
74
|
? normalizeStyles(parsedStyles)
|
114
75
|
: parsedStyles
|
115
76
|
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { Optional, NestedStyle } from '../types'
|
2
|
+
|
3
|
+
export const getKeyForVariant = (value: NestedStyle, variant?: string): Optional<keyof typeof value> => {
|
4
|
+
if (!value.variants) {
|
5
|
+
return undefined
|
6
|
+
}
|
7
|
+
|
8
|
+
if (variant && variant in value.variants) {
|
9
|
+
return variant as keyof typeof value
|
10
|
+
}
|
11
|
+
|
12
|
+
if ('default' in value.variants) {
|
13
|
+
return 'default' as keyof typeof value
|
14
|
+
}
|
15
|
+
|
16
|
+
return undefined
|
17
|
+
}
|
@@ -1,21 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.UnistylesTheme = exports.UnistylesContext = void 0;
|
7
|
-
var _react = _interopRequireWildcard(require("react"));
|
8
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
9
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
10
|
-
const UnistylesContext = exports.UnistylesContext = /*#__PURE__*/(0, _react.createContext)({});
|
11
|
-
const UnistylesTheme = _ref => {
|
12
|
-
let {
|
13
|
-
theme,
|
14
|
-
children
|
15
|
-
} = _ref;
|
16
|
-
return /*#__PURE__*/_react.default.createElement(UnistylesContext.Provider, {
|
17
|
-
value: theme
|
18
|
-
}, children);
|
19
|
-
};
|
20
|
-
exports.UnistylesTheme = UnistylesTheme;
|
21
|
-
//# sourceMappingURL=UnistylesTheme.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","UnistylesContext","exports","createContext","UnistylesTheme","_ref","theme","children","createElement","Provider","value"],"sourceRoot":"../../src","sources":["UnistylesTheme.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA4C,SAAAC,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAI,CAAA,KAAAA,CAAA,CAAAX,GAAA,IAAAW,CAAA,CAAAC,GAAA,IAAAR,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAI,CAAA,IAAAV,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAgB,GAAA,CAAAnB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AAOrC,MAAMY,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,gBAAG,IAAAE,oBAAa,EAAC,CAAC,CAAC,CAAC;AAE1C,MAAMC,cAA4D,GAAGC,IAAA;EAAA,IAAC;IACzEC,KAAK;IACLC;EACJ,CAAC,GAAAF,IAAA;EAAA,oBACG5B,MAAA,CAAAS,OAAA,CAAAsB,aAAA,CAACP,gBAAgB,CAACQ,QAAQ;IAACC,KAAK,EAAEJ;EAAM,GACnCC,QACsB,CAAC;AAAA,CAC/B;AAAAL,OAAA,CAAAE,cAAA,GAAAA,cAAA"}
|
@@ -1,57 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.createUnistyles = void 0;
|
7
|
-
var _react = require("react");
|
8
|
-
var _reactNative = require("react-native");
|
9
|
-
var _UnistylesTheme = require("./UnistylesTheme");
|
10
|
-
var _hooks = require("./hooks");
|
11
|
-
var _utils = require("./utils");
|
12
|
-
const createUnistyles = breakpoints => {
|
13
|
-
const sortedBreakpoints = (0, _utils.sortAndValidateBreakpoints)(breakpoints);
|
14
|
-
const sortedBreakpointEntries = Object.entries(sortedBreakpoints);
|
15
|
-
return {
|
16
|
-
createStyleSheet: styles => {
|
17
|
-
if (typeof styles === 'function') {
|
18
|
-
return styles;
|
19
|
-
}
|
20
|
-
return styles;
|
21
|
-
},
|
22
|
-
useStyles: stylesheet => {
|
23
|
-
const theme = (0, _react.useContext)(_UnistylesTheme.UnistylesContext);
|
24
|
-
const screenSize = (0, _hooks.useDimensions)();
|
25
|
-
const breakpoint = (0, _utils.getBreakpointFromScreenWidth)(screenSize.width, sortedBreakpointEntries);
|
26
|
-
if (!stylesheet) {
|
27
|
-
return {
|
28
|
-
theme,
|
29
|
-
breakpoint,
|
30
|
-
styles: {}
|
31
|
-
};
|
32
|
-
}
|
33
|
-
const parsedStyles = (0, _react.useMemo)(() => typeof stylesheet === 'function' ? stylesheet(theme) : stylesheet, [theme, stylesheet]);
|
34
|
-
const dynamicStyleSheet = (0, _react.useMemo)(() => Object.entries(parsedStyles).reduce((acc, _ref) => {
|
35
|
-
let [key, value] = _ref;
|
36
|
-
const style = value;
|
37
|
-
if (typeof value === 'function') {
|
38
|
-
return {
|
39
|
-
...acc,
|
40
|
-
[key]: (0, _utils.proxifyFunction)(value, breakpoint, screenSize, sortedBreakpointEntries)
|
41
|
-
};
|
42
|
-
}
|
43
|
-
return _reactNative.StyleSheet.create({
|
44
|
-
...acc,
|
45
|
-
[key]: (0, _utils.parseStyle)(style, breakpoint, screenSize, sortedBreakpointEntries)
|
46
|
-
});
|
47
|
-
}, {}), [breakpoint, screenSize, parsedStyles]);
|
48
|
-
return {
|
49
|
-
theme,
|
50
|
-
breakpoint,
|
51
|
-
styles: dynamicStyleSheet
|
52
|
-
};
|
53
|
-
}
|
54
|
-
};
|
55
|
-
};
|
56
|
-
exports.createUnistyles = createUnistyles;
|
57
|
-
//# sourceMappingURL=createUnistyles.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNative","_UnistylesTheme","_hooks","_utils","createUnistyles","breakpoints","sortedBreakpoints","sortAndValidateBreakpoints","sortedBreakpointEntries","Object","entries","createStyleSheet","styles","useStyles","stylesheet","theme","useContext","UnistylesContext","screenSize","useDimensions","breakpoint","getBreakpointFromScreenWidth","width","parsedStyles","useMemo","dynamicStyleSheet","reduce","acc","_ref","key","value","style","proxifyFunction","StyleSheet","create","parseStyle","exports"],"s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AA;QACtB,MAAMG,KAAK,GAAGD,KAAiC;QAE/C,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;UAC7B,OAAO;YACH,GAAGH,GAAG;YACN,CAACE,GAAG,GAAG,IAAAG,sBAAe,EAAIF,KAAK,EAAEV,UAAU,EAAEF,UAAU,EAAEV,uBAAuB;UACpF,CAAC;QACL;QAEA,OAAOyB,uBAAU,CAACC,MAAM,CAAC;UACrB,GAAGP,GAAG;UACN,CAACE,GAAG,GAAG,IAAAM,iBAAU,EAAQJ,KAAK,EAAEX,UAAU,EAAEF,UAAU,EAAEV,uBAAuB;QACnF,CAAC,CAAC;MACN,CAAC,EAAE,CAAC,CAAO,CAAC,EAAE,CAACY,UAAU,EAAEF,UAAU,EAAEK,YAAY,CAAC,CAAC;MAEzD,OAAO;QACHR,KAAK;QACLK,UAAU;QACVR,MAAM,EAAEa;MACZ,CAAC;IACL;EACJ,CAAC;AACL,CAAC;AAAAW,OAAA,CAAAhC,eAAA,GAAAA,eAAA"}
|
@@ -1,10 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.useDimensions = void 0;
|
7
|
-
var _reactNative = require("react-native");
|
8
|
-
const useDimensions = () => (0, _reactNative.useWindowDimensions)();
|
9
|
-
exports.useDimensions = useDimensions;
|
10
|
-
//# sourceMappingURL=useDimensions.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_reactNative","require","useDimensions","useWindowDimensions","exports"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAGO,MAAMC,aAAa,GAAGA,CAAA,KAAkB,IAAAC,gCAAmB,EAAC,CAAC;AAAAC,OAAA,CAAAF,aAAA,GAAAA,aAAA"}
|
@@ -1,31 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.useDimensions = void 0;
|
7
|
-
var _react = require("react");
|
8
|
-
const useDimensions = () => {
|
9
|
-
const timerRef = (0, _react.useRef)();
|
10
|
-
const [screenSize, setScreenSize] = (0, _react.useState)({
|
11
|
-
width: window.innerWidth,
|
12
|
-
height: window.innerHeight
|
13
|
-
});
|
14
|
-
(0, _react.useEffect)(() => {
|
15
|
-
const handleResize = () => {
|
16
|
-
clearTimeout(timerRef.current);
|
17
|
-
timerRef.current = setTimeout(() => setScreenSize({
|
18
|
-
width: window.innerWidth,
|
19
|
-
height: window.innerHeight
|
20
|
-
}), 100);
|
21
|
-
};
|
22
|
-
window.addEventListener('resize', handleResize);
|
23
|
-
return () => {
|
24
|
-
window.removeEventListener('resize', handleResize);
|
25
|
-
clearTimeout(timerRef.current);
|
26
|
-
};
|
27
|
-
}, []);
|
28
|
-
return screenSize;
|
29
|
-
};
|
30
|
-
exports.useDimensions = useDimensions;
|
31
|
-
//# sourceMappingURL=useDimensions.web.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_react","require","useDimensions","timerRef","useRef","screenSize","setScreenSize","useState","width","window","innerWidth","height","innerHeight","useEffect","handleResize","clearTimeout","current","setTimeout","addEventListener","removeEventListener","exports"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.web.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGO,MAAMC,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAMC,QAAQ,GAAG,IAAAC,aAAM,EAAgC,CAAC;EACxD,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAC,eAAQ,EAAa;IACrDC,KAAK,EAAEC,MAAM,CAACC,UAAU;IACxBC,MAAM,EAAEF,MAAM,CAACG;EACnB,CAAC,CAAC;EAEF,IAAAC,gBAAS,EAAC,MAAM;IACZ,MAAMC,YAAY,GAAGA,CAAA,KAAM;MACvBC,YAAY,CAACZ,QAAQ,CAACa,OAAO,CAAC;MAE9Bb,QAAQ,CAACa,OAAO,GAAGC,UAAU,CAAC,MAAMX,aAAa,CAAC;QAC9CE,KAAK,EAAEC,MAAM,CAACC,UAAU;QACxBC,MAAM,EAAEF,MAAM,CAACG;MACnB,CAAC,CAAC,EAAE,GAAG,CAAC;IACZ,CAAC;IAEDH,MAAM,CAACS,gBAAgB,CAAC,QAAQ,EAAEJ,YAAY,CAAC;IAE/C,OAAO,MAAM;MACTL,MAAM,CAACU,mBAAmB,CAAC,QAAQ,EAAEL,YAAY,CAAC;MAClDC,YAAY,CAACZ,QAAQ,CAACa,OAAO,CAAC;IAClC,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOX,UAAU;AACrB,CAAC;AAAAe,OAAA,CAAAlB,aAAA,GAAAA,aAAA"}
|
@@ -1,189 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.isWithinTheWidthAndHeight = exports.isWithinTheWidth = exports.isWithinTheHeight = exports.isWithinBreakpoint = exports.isMediaQuery = exports.getKeyForCustomMediaQuery = exports.extractValues = void 0;
|
7
|
-
/**
|
8
|
-
* Extracts numeric values from a coded string.
|
9
|
-
*
|
10
|
-
* The function is designed to process strings that have a format like "w[100,200]" or "h[300]".
|
11
|
-
* It removes characters 'w', 'h', '[', and ']' from the input string and then extracts the numbers.
|
12
|
-
*
|
13
|
-
* @param {string} codedValue - The input string to extract values from.
|
14
|
-
* @returns {Array<number>} An array of extracted numbers. Can contain one or two numbers based on the input format.
|
15
|
-
*
|
16
|
-
* @example
|
17
|
-
* extractValues("w[100,200]") // returns [100, 200]
|
18
|
-
* extractValues("h[300]") // returns [300]
|
19
|
-
* extractValues("h[,300]") // returns [0,300]
|
20
|
-
* extractValues("h[100,]") // returns [100]
|
21
|
-
*/
|
22
|
-
const extractValues = codedValue => {
|
23
|
-
const [lh, rh] = codedValue.replace(/[wh[\]]/g, '').split(',');
|
24
|
-
return rh ? [Number(lh), Number(rh)] : [Number(lh)];
|
25
|
-
};
|
26
|
-
|
27
|
-
/**
|
28
|
-
* Determines if the given screen size matches the specified breakpoint query.
|
29
|
-
*
|
30
|
-
* The function checks if the screen size (width and/or height) falls within the range
|
31
|
-
* specified by the breakpoint query. The query can specify width (using 'w'), height (using 'h'),
|
32
|
-
* or both.
|
33
|
-
*
|
34
|
-
* @param {string} query - The breakpoint query string. Examples: 'w[100,200]', 'h[300]', 'w[100,200]h[300,400]'.
|
35
|
-
* @param {ScreenSize} screenSize - The screen size to check against the breakpoint query.
|
36
|
-
* @returns {boolean} True if the screen size matches the breakpoint query, false otherwise.
|
37
|
-
*
|
38
|
-
* @example
|
39
|
-
* const screenSize = { width: 150, height: 350 }
|
40
|
-
* isWithinBreakpoint('w[100,200]', screenSize) // returns true
|
41
|
-
* isWithinBreakpoint('h[400]', screenSize) // returns false
|
42
|
-
*/
|
43
|
-
exports.extractValues = extractValues;
|
44
|
-
const isWithinBreakpoint = (query, screenSize) => {
|
45
|
-
if (query.includes('w') && query.includes('h')) {
|
46
|
-
return isWithinTheWidthAndHeight(query, screenSize);
|
47
|
-
}
|
48
|
-
if (query.charAt(0) === 'w') {
|
49
|
-
return isWithinTheWidth(query, screenSize.width);
|
50
|
-
}
|
51
|
-
if (query.charAt(0) === 'h') {
|
52
|
-
return isWithinTheHeight(query, screenSize.height);
|
53
|
-
}
|
54
|
-
return false;
|
55
|
-
};
|
56
|
-
|
57
|
-
/**
|
58
|
-
* Determines if the given width matches the specified width range in the query.
|
59
|
-
*
|
60
|
-
* The function checks if the provided width falls within the range specified by the query.
|
61
|
-
* The query specifies a width range using a format like 'w[100,200]'. If only one value is provided,
|
62
|
-
* it's treated as a minimum width.
|
63
|
-
*
|
64
|
-
* @param {string} query - The width query string. Examples: 'w[100,200]' or 'w[100]'.
|
65
|
-
* @param {number} width - The width to check against the query.
|
66
|
-
* @returns {boolean} True if the width matches the query range, false otherwise.
|
67
|
-
*
|
68
|
-
* @example
|
69
|
-
* isWithinTheWidth('w[100,200]', 150) // returns true
|
70
|
-
* isWithinTheWidth('w[100]', 50) // returns false
|
71
|
-
* isWithinTheWidth('w[100]', 150) // returns true
|
72
|
-
*/
|
73
|
-
exports.isWithinBreakpoint = isWithinBreakpoint;
|
74
|
-
const isWithinTheWidth = (query, width) => {
|
75
|
-
const [minWidth, maxWidth] = extractValues(query);
|
76
|
-
if (maxWidth && width >= minWidth && width <= maxWidth) {
|
77
|
-
return true;
|
78
|
-
}
|
79
|
-
return !maxWidth && width >= minWidth;
|
80
|
-
};
|
81
|
-
|
82
|
-
/**
|
83
|
-
* Determines if the given height matches the specified height range in the query.
|
84
|
-
*
|
85
|
-
* The function checks if the provided height falls within the range specified by the query.
|
86
|
-
* The query specifies a height range using a format like 'h[100,200]'. If only one value is provided,
|
87
|
-
* it's treated as a minimum height.
|
88
|
-
*
|
89
|
-
* @param {string} query - The height query string. Examples: 'h[100,200]' or 'h[100]'.
|
90
|
-
* @param {number} height - The height to check against the query.
|
91
|
-
* @returns {boolean} True if the height matches the query range, false otherwise.
|
92
|
-
*
|
93
|
-
* @example
|
94
|
-
* isWithinTheHeight('h[100,200]', 150) // returns true
|
95
|
-
* isWithinTheHeight('h[100]', 50) // returns false
|
96
|
-
* isWithinTheHeight('h[100]', 150) // returns true
|
97
|
-
*/
|
98
|
-
exports.isWithinTheWidth = isWithinTheWidth;
|
99
|
-
const isWithinTheHeight = (query, height) => {
|
100
|
-
const [minHeight, maxHeight] = extractValues(query);
|
101
|
-
if (maxHeight && height >= minHeight && height <= maxHeight) {
|
102
|
-
return true;
|
103
|
-
}
|
104
|
-
return !maxHeight && height >= minHeight;
|
105
|
-
};
|
106
|
-
|
107
|
-
/**
|
108
|
-
* Determines if the given screen size matches both the specified width and height ranges in the query.
|
109
|
-
*
|
110
|
-
* The function checks if the provided screen size (both width and height) falls within the ranges
|
111
|
-
* specified by the query. The query can specify both width and height using a format like 'w[100,200]:h[300,400]'.
|
112
|
-
*
|
113
|
-
* @param {string} query - The combined width and height query string. Example: 'w[100,200]:h[300,400]'.
|
114
|
-
* @param {ScreenSize} screenSize - The screen size to check against the query.
|
115
|
-
* @returns {boolean} True if the screen size matches both the width and height ranges in the query, false otherwise.
|
116
|
-
*
|
117
|
-
* @example
|
118
|
-
* const screenSize = { width: 150, height: 350 }
|
119
|
-
* isWithinTheWidthAndHeight('w[100,200]:h[300,400]', screenSize) // returns true
|
120
|
-
* isWithinTheWidthAndHeight('w[100,200]:h[400,500]', screenSize) // returns false
|
121
|
-
*/
|
122
|
-
exports.isWithinTheHeight = isWithinTheHeight;
|
123
|
-
const isWithinTheWidthAndHeight = (query, screenSize) => {
|
124
|
-
const result = query.split(':').filter(Boolean).map(q => isWithinBreakpoint(q, screenSize)).filter(Boolean);
|
125
|
-
return result.length === 2;
|
126
|
-
};
|
127
|
-
|
128
|
-
/**
|
129
|
-
* Checks if the given query string is a valid custom media query.
|
130
|
-
*
|
131
|
-
* The valid custom media query formats include:
|
132
|
-
* - :w[200]
|
133
|
-
* - :w[0, 200]
|
134
|
-
* - :w[, 300]
|
135
|
-
* - :h[200]
|
136
|
-
* - :h[0, 500]
|
137
|
-
* - :h[,200]
|
138
|
-
* - :w[100, 300]:h[200,500]
|
139
|
-
* - :h[200,500]:w[100, 300]
|
140
|
-
*
|
141
|
-
* @param {string} query - The query string to be checked.
|
142
|
-
* @returns {boolean} Returns `true` if the query is a valid custom media query, otherwise `false`.
|
143
|
-
* @example
|
144
|
-
*
|
145
|
-
* isMediaQuery(':w[200]') // true
|
146
|
-
* isMediaQuery(':w100]') // false
|
147
|
-
*/
|
148
|
-
exports.isWithinTheWidthAndHeight = isWithinTheWidthAndHeight;
|
149
|
-
const isMediaQuery = query => {
|
150
|
-
const regex = /^(?:(:w\[\d*(?:,\s?\d+)?])?(:h\[\d*(?:,\s?\d+)?])?|(:h\[\d*(?:,\s?\d+)?])?(:w\[\d*(?:,\s?\d+)?])?)$/;
|
151
|
-
return query.length > 0 && regex.test(query);
|
152
|
-
};
|
153
|
-
|
154
|
-
/**
|
155
|
-
* Retrieves the first matching custom media query key based on the provided screen size.
|
156
|
-
*
|
157
|
-
* The function processes an array of media queries and returns the first query that matches
|
158
|
-
* the given screen size. The media queries can be in formats like:
|
159
|
-
* - w[200]
|
160
|
-
* - w[0, 200]
|
161
|
-
* - w[, 300]
|
162
|
-
* - h[200]
|
163
|
-
* - h[0, 500]
|
164
|
-
* - h[,200]
|
165
|
-
* - w[100, 300]:h[200,500]
|
166
|
-
* - h[200,500]:w[100, 300]
|
167
|
-
*
|
168
|
-
* @param {Array<[string, string | number]>} mediaQueries - An array of tuples containing media query keys and associated values.
|
169
|
-
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
170
|
-
* @returns {string | undefined} Returns the first matching media query key or `undefined` if no match is found.
|
171
|
-
* @example
|
172
|
-
*
|
173
|
-
* const queries = [[':w[200]', 'value1'], [':h[300,500]', 'value2']]
|
174
|
-
* const size = { width: 250, height: 400 }
|
175
|
-
* getKeyForCustomMediaQuery(queries, size) // ':w[200]
|
176
|
-
*/
|
177
|
-
exports.isMediaQuery = isMediaQuery;
|
178
|
-
const getKeyForCustomMediaQuery = (mediaQueries, screenSize) => {
|
179
|
-
const [matchedQuery] = mediaQueries.flatMap(_ref => {
|
180
|
-
let [key] = _ref;
|
181
|
-
if (key.includes('w') && key.includes('h')) {
|
182
|
-
return isWithinBreakpoint(key, screenSize) ? key : undefined;
|
183
|
-
}
|
184
|
-
return key.split(':').filter(Boolean).map(query => isWithinBreakpoint(query, screenSize) ? key : undefined);
|
185
|
-
}).filter(Boolean);
|
186
|
-
return matchedQuery;
|
187
|
-
};
|
188
|
-
exports.getKeyForCustomMediaQuery = getKeyForCustomMediaQuery;
|
189
|
-
//# sourceMappingURL=mediaQueries.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["extractValues","codedValue","lh","rh","replace","split","Number","exports","isWithinBreakpoint","query","screenSize","includes","isWithinTheWidthAndHeight","charAt","isWithinTheWidth","width","isWithinTheHeight","height","minWidth","maxWidth","minHeight","maxHeight","result","filter","Boolean","map","q","length","isMediaQuery","regex","test","getKeyForCustomMediaQuery","mediaQueries","matchedQuery","flatMap","_ref","key","undefined"],"sourceRoot":"../../../src","sources":["utils/mediaQueries.ts"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,aAAa,GAAIC,UAAkB,IAAoB;EAChE,MAAM,CAACC,EAAE,EAAEC,EAAE,CAAC,GAAGF,UAAU,CACtBG,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CACvBC,KAAK,CAAC,GAAG,CAAC;EAEf,OAAOF,EAAE,GACH,CAACG,MAAM,CAACJ,EAAE,CAAC,EAAEI,MAAM,CAACH,EAAE,CAAC,CAAC,GACxB,CAACG,MAAM,CAACJ,EAAE,CAAC,CAAC;AACtB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAfAK,OAAA,CAAAP,aAAA,GAAAA,aAAA;AAgBO,MAAMQ,kBAAkB,GAAGA,CAACC,KAAa,EAAEC,UAAsB,KAAc;EAClF,IAAID,KAAK,CAACE,QAAQ,CAAC,GAAG,CAAC,IAAIF,KAAK,CAACE,QAAQ,CAAC,GAAG,CAAC,EAAE;IAC5C,OAAOC,yBAAyB,CAACH,KAAK,EAAEC,UAAU,CAAC;EACvD;EAEA,IAAID,KAAK,CAACI,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;IACzB,OAAOC,gBAAgB,CAACL,KAAK,EAAEC,UAAU,CAACK,KAAK,CAAC;EACpD;EAEA,IAAIN,KAAK,CAACI,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;IACzB,OAAOG,iBAAiB,CAACP,KA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C;EAEpB,OAAOS,YAAY;AACvB,CAAC;AAAA1B,OAAA,CAAAwB,yBAAA,GAAAA,yBAAA"}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import React, { createContext } from 'react';
|
2
|
-
export const UnistylesContext = /*#__PURE__*/createContext({});
|
3
|
-
export const UnistylesTheme = _ref => {
|
4
|
-
let {
|
5
|
-
theme,
|
6
|
-
children
|
7
|
-
} = _ref;
|
8
|
-
return /*#__PURE__*/React.createElement(UnistylesContext.Provider, {
|
9
|
-
value: theme
|
10
|
-
}, children);
|
11
|
-
};
|
12
|
-
//# sourceMappingURL=UnistylesTheme.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["React","createContext","UnistylesContext","UnistylesTheme","_ref","theme","children","createElement","Provider","value"],"sourceRoot":"../../src","sources":["UnistylesTheme.tsx"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,aAAa,QAAQ,OAAO;AAO5C,OAAO,MAAMC,gBAAgB,gBAAGD,aAAa,CAAC,CAAC,CAAC,CAAC;AAEjD,OAAO,MAAME,cAA4D,GAAGC,IAAA;EAAA,IAAC;IACzEC,KAAK;IACLC;EACJ,CAAC,GAAAF,IAAA;EAAA,oBACGJ,KAAA,CAAAO,aAAA,CAACL,gBAAgB,CAACM,QAAQ;IAACC,KAAK,EAAEJ;EAAM,GACnCC,QACsB,CAAC;AAAA,CAC/B"}
|