react-native-css 0.0.0-nightly.38ce466 → 0.0.0-nightly.5ce6396
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/babel/index.js +6 -2
- package/dist/commonjs/babel/index.js.map +1 -1
- package/dist/commonjs/compiler/atRules.js +3 -1
- package/dist/commonjs/compiler/atRules.js.map +1 -1
- package/dist/commonjs/compiler/declarations.js +112 -31
- package/dist/commonjs/compiler/declarations.js.map +1 -1
- package/dist/commonjs/compiler/stylesheet.js +5 -0
- package/dist/commonjs/compiler/stylesheet.js.map +1 -1
- package/dist/commonjs/jest/index.js +0 -1
- package/dist/commonjs/jest/index.js.map +1 -1
- package/dist/commonjs/runtime/native/api.js +21 -2
- package/dist/commonjs/runtime/native/api.js.map +1 -1
- package/dist/commonjs/runtime/native/reactivity.js +1 -5
- package/dist/commonjs/runtime/native/reactivity.js.map +1 -1
- package/dist/commonjs/runtime/native/styles/shorthands/box-shadow.js +19 -11
- package/dist/commonjs/runtime/native/styles/shorthands/box-shadow.js.map +1 -1
- package/dist/commonjs/runtime/native/styles/units.js +10 -8
- package/dist/commonjs/runtime/native/styles/units.js.map +1 -1
- package/dist/commonjs/runtime/web/api.js +18 -0
- package/dist/commonjs/runtime/web/api.js.map +1 -1
- package/dist/commonjs/style-collection/root.js +1 -0
- package/dist/commonjs/style-collection/root.js.map +1 -1
- package/dist/module/babel/index.js +2 -2
- package/dist/module/babel/index.js.map +1 -1
- package/dist/module/compiler/atRules.js +3 -1
- package/dist/module/compiler/atRules.js.map +1 -1
- package/dist/module/compiler/declarations.js +107 -31
- package/dist/module/compiler/declarations.js.map +1 -1
- package/dist/module/compiler/stylesheet.js +5 -0
- package/dist/module/compiler/stylesheet.js.map +1 -1
- package/dist/module/jest/index.js +1 -2
- package/dist/module/jest/index.js.map +1 -1
- package/dist/module/runtime/native/api.js +21 -3
- package/dist/module/runtime/native/api.js.map +1 -1
- package/dist/module/runtime/native/reactivity.js +0 -4
- package/dist/module/runtime/native/reactivity.js.map +1 -1
- package/dist/module/runtime/native/styles/shorthands/box-shadow.js +19 -11
- package/dist/module/runtime/native/styles/shorthands/box-shadow.js.map +1 -1
- package/dist/module/runtime/native/styles/units.js +11 -8
- package/dist/module/runtime/native/styles/units.js.map +1 -1
- package/dist/module/runtime/web/api.js +18 -1
- package/dist/module/runtime/web/api.js.map +1 -1
- package/dist/module/style-collection/root.js +1 -0
- package/dist/module/style-collection/root.js.map +1 -1
- package/dist/typescript/commonjs/src/babel/index.d.ts +3 -0
- package/dist/typescript/commonjs/src/babel/index.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/atRules.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/declarations.d.ts +14 -3
- package/dist/typescript/commonjs/src/compiler/declarations.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/jest/index.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/api.d.ts +13 -1
- package/dist/typescript/commonjs/src/runtime/native/api.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/reactivity.d.ts +0 -2
- package/dist/typescript/commonjs/src/runtime/native/reactivity.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/styles/shorthands/box-shadow.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/styles/units.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/web/api.d.ts +8 -2
- package/dist/typescript/commonjs/src/runtime/web/api.d.ts.map +1 -1
- package/dist/typescript/module/src/babel/index.d.ts +3 -0
- package/dist/typescript/module/src/babel/index.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/atRules.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/declarations.d.ts +14 -3
- package/dist/typescript/module/src/compiler/declarations.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/stylesheet.d.ts.map +1 -1
- package/dist/typescript/module/src/jest/index.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/api.d.ts +13 -1
- package/dist/typescript/module/src/runtime/native/api.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/reactivity.d.ts +0 -2
- package/dist/typescript/module/src/runtime/native/reactivity.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/styles/shorthands/box-shadow.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/styles/units.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/web/api.d.ts +8 -2
- package/dist/typescript/module/src/runtime/web/api.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/babel/index.ts +2 -2
- package/src/compiler/atRules.ts +2 -0
- package/src/compiler/declarations.ts +147 -42
- package/src/compiler/stylesheet.ts +6 -0
- package/src/jest/index.ts +1 -2
- package/src/runtime/native/{api.ts → api.tsx} +31 -4
- package/src/runtime/native/reactivity.ts +0 -4
- package/src/runtime/native/styles/shorthands/box-shadow.ts +24 -18
- package/src/runtime/native/styles/units.ts +13 -8
- package/src/runtime/web/{api.ts → api.tsx} +28 -2
- package/src/style-collection/root.ts +2 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StyleDescriptor } from "../../../../compiler";
|
|
1
2
|
import { isStyleDescriptorArray } from "../../../utils";
|
|
2
3
|
import type { StyleFunctionResolver } from "../resolve";
|
|
3
4
|
import { shorthandHandler } from "./_handler";
|
|
@@ -9,6 +10,27 @@ const blurRadius = ["blurRadius", "number"] as const;
|
|
|
9
10
|
const spreadDistance = ["spreadDistance", "number"] as const;
|
|
10
11
|
// const inset = ["inset", "string"] as const;
|
|
11
12
|
|
|
13
|
+
function deepFlattenToArrayOfStyleDescriptors(
|
|
14
|
+
arr: StyleDescriptor[],
|
|
15
|
+
): StyleDescriptor[] {
|
|
16
|
+
const result: StyleDescriptor[] = [];
|
|
17
|
+
const stack = [arr];
|
|
18
|
+
while (stack.length > 0) {
|
|
19
|
+
const current = stack.pop();
|
|
20
|
+
if (Array.isArray(current)) {
|
|
21
|
+
if (current.length > 0 && Array.isArray(current[0])) {
|
|
22
|
+
for (let i = current.length - 1; i >= 0; i--) {
|
|
23
|
+
const elem = current[i];
|
|
24
|
+
if (isStyleDescriptorArray(elem)) stack.push(elem);
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
result.push(current);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
12
34
|
const handler = shorthandHandler(
|
|
13
35
|
[
|
|
14
36
|
[offsetX, offsetY, blurRadius, spreadDistance, color],
|
|
@@ -33,26 +55,10 @@ export const boxShadow: StyleFunctionResolver = (
|
|
|
33
55
|
if (!isStyleDescriptorArray(args)) {
|
|
34
56
|
return args;
|
|
35
57
|
} else {
|
|
36
|
-
return args
|
|
37
|
-
.
|
|
58
|
+
return deepFlattenToArrayOfStyleDescriptors(args)
|
|
59
|
+
.map((shadows) => {
|
|
38
60
|
if (shadows === undefined) {
|
|
39
61
|
return [];
|
|
40
|
-
} else if (isStyleDescriptorArray(shadows)) {
|
|
41
|
-
if (shadows.length === 0) {
|
|
42
|
-
return [];
|
|
43
|
-
} else if (Array.isArray(shadows[0])) {
|
|
44
|
-
return shadows
|
|
45
|
-
.map((shadow) => {
|
|
46
|
-
return omitTransparentShadows(
|
|
47
|
-
handler(resolveValue, shadow, get, options),
|
|
48
|
-
);
|
|
49
|
-
})
|
|
50
|
-
.filter((v) => v !== undefined);
|
|
51
|
-
} else {
|
|
52
|
-
return omitTransparentShadows(
|
|
53
|
-
handler(resolveValue, shadows, get, options),
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
62
|
} else {
|
|
57
63
|
return omitTransparentShadows(
|
|
58
64
|
handler(resolveValue, shadows, get, options),
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import { rem as remObs, vh as vhObs, vw as vwObs } from "../reactivity";
|
|
1
|
+
import { vh as vhObs, vw as vwObs } from "../reactivity";
|
|
3
2
|
import type { StyleFunctionResolver } from "./resolve";
|
|
4
3
|
|
|
5
|
-
export const em: StyleFunctionResolver = (resolve, func
|
|
6
|
-
|
|
4
|
+
export const em: StyleFunctionResolver = (resolve, func) => {
|
|
5
|
+
const value = func[2];
|
|
7
6
|
|
|
8
7
|
if (typeof value !== "number") {
|
|
9
8
|
return;
|
|
@@ -12,14 +11,14 @@ export const em: StyleFunctionResolver = (resolve, func, get) => {
|
|
|
12
11
|
let emValue = resolve([{}, "var", ["__rn-css-em"]]);
|
|
13
12
|
|
|
14
13
|
if (typeof emValue !== "number") {
|
|
15
|
-
emValue =
|
|
14
|
+
emValue = resolve([{}, "var", ["__rn-css-rem"]]);
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
if (typeof emValue !== "number") {
|
|
19
18
|
return;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
return round(
|
|
21
|
+
return round(value * emValue);
|
|
23
22
|
};
|
|
24
23
|
|
|
25
24
|
export const vw: StyleFunctionResolver = (_, func, get) => {
|
|
@@ -42,14 +41,20 @@ export const vh: StyleFunctionResolver = (_, func, get) => {
|
|
|
42
41
|
return round((value / 100) * get(vhObs));
|
|
43
42
|
};
|
|
44
43
|
|
|
45
|
-
export const rem: StyleFunctionResolver = (
|
|
44
|
+
export const rem: StyleFunctionResolver = (resolve, func) => {
|
|
46
45
|
const value = func[2];
|
|
47
46
|
|
|
48
47
|
if (typeof value !== "number") {
|
|
49
48
|
return;
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
|
|
51
|
+
const remValue = resolve([{}, "var", ["__rn-css-rem"]]);
|
|
52
|
+
|
|
53
|
+
if (typeof remValue === "number") {
|
|
54
|
+
return round(value * remValue);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return;
|
|
53
58
|
};
|
|
54
59
|
|
|
55
60
|
function round(number: number) {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createElement,
|
|
3
|
+
useMemo,
|
|
4
|
+
type ComponentProps,
|
|
5
|
+
type PropsWithChildren,
|
|
6
|
+
} from "react";
|
|
2
7
|
import { Appearance } from "react-native";
|
|
3
8
|
|
|
4
9
|
import type {
|
|
@@ -24,7 +29,7 @@ export const styled = <
|
|
|
24
29
|
};
|
|
25
30
|
};
|
|
26
31
|
|
|
27
|
-
export const useCssElement = <
|
|
32
|
+
export const useCssElement = <C extends ReactComponent>(
|
|
28
33
|
component: C,
|
|
29
34
|
incomingProps: Props,
|
|
30
35
|
mapping: StyledConfiguration<C>,
|
|
@@ -66,6 +71,9 @@ export const colorScheme: ColorScheme = {
|
|
|
66
71
|
},
|
|
67
72
|
};
|
|
68
73
|
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated Use `<VariableContextProvider />` instead.
|
|
76
|
+
*/
|
|
69
77
|
export function vars(variables: Record<string, string | number>) {
|
|
70
78
|
const $variables: Record<string, string> = {};
|
|
71
79
|
|
|
@@ -79,6 +87,24 @@ export function vars(variables: Record<string, string | number>) {
|
|
|
79
87
|
return $variables;
|
|
80
88
|
}
|
|
81
89
|
|
|
90
|
+
export function VariableContextProvider(
|
|
91
|
+
props: PropsWithChildren<{ value: Record<`--${string}`, string> }>,
|
|
92
|
+
) {
|
|
93
|
+
const style = useMemo(() => {
|
|
94
|
+
return {
|
|
95
|
+
display: "content",
|
|
96
|
+
...Object.fromEntries(
|
|
97
|
+
Object.entries(props.value).map(([key, value]) => [
|
|
98
|
+
key.startsWith("--") ? key : `--${key}`,
|
|
99
|
+
value,
|
|
100
|
+
]),
|
|
101
|
+
),
|
|
102
|
+
};
|
|
103
|
+
}, [props.value]);
|
|
104
|
+
|
|
105
|
+
return <div style={style}>{props.children}</div>;
|
|
106
|
+
}
|
|
107
|
+
|
|
82
108
|
export const useNativeVariable = () => {
|
|
83
109
|
throw new Error("useNativeVariable is not supported in web");
|
|
84
110
|
};
|