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.
Files changed (86) hide show
  1. package/dist/commonjs/babel/index.js +6 -2
  2. package/dist/commonjs/babel/index.js.map +1 -1
  3. package/dist/commonjs/compiler/atRules.js +3 -1
  4. package/dist/commonjs/compiler/atRules.js.map +1 -1
  5. package/dist/commonjs/compiler/declarations.js +112 -31
  6. package/dist/commonjs/compiler/declarations.js.map +1 -1
  7. package/dist/commonjs/compiler/stylesheet.js +5 -0
  8. package/dist/commonjs/compiler/stylesheet.js.map +1 -1
  9. package/dist/commonjs/jest/index.js +0 -1
  10. package/dist/commonjs/jest/index.js.map +1 -1
  11. package/dist/commonjs/runtime/native/api.js +21 -2
  12. package/dist/commonjs/runtime/native/api.js.map +1 -1
  13. package/dist/commonjs/runtime/native/reactivity.js +1 -5
  14. package/dist/commonjs/runtime/native/reactivity.js.map +1 -1
  15. package/dist/commonjs/runtime/native/styles/shorthands/box-shadow.js +19 -11
  16. package/dist/commonjs/runtime/native/styles/shorthands/box-shadow.js.map +1 -1
  17. package/dist/commonjs/runtime/native/styles/units.js +10 -8
  18. package/dist/commonjs/runtime/native/styles/units.js.map +1 -1
  19. package/dist/commonjs/runtime/web/api.js +18 -0
  20. package/dist/commonjs/runtime/web/api.js.map +1 -1
  21. package/dist/commonjs/style-collection/root.js +1 -0
  22. package/dist/commonjs/style-collection/root.js.map +1 -1
  23. package/dist/module/babel/index.js +2 -2
  24. package/dist/module/babel/index.js.map +1 -1
  25. package/dist/module/compiler/atRules.js +3 -1
  26. package/dist/module/compiler/atRules.js.map +1 -1
  27. package/dist/module/compiler/declarations.js +107 -31
  28. package/dist/module/compiler/declarations.js.map +1 -1
  29. package/dist/module/compiler/stylesheet.js +5 -0
  30. package/dist/module/compiler/stylesheet.js.map +1 -1
  31. package/dist/module/jest/index.js +1 -2
  32. package/dist/module/jest/index.js.map +1 -1
  33. package/dist/module/runtime/native/api.js +21 -3
  34. package/dist/module/runtime/native/api.js.map +1 -1
  35. package/dist/module/runtime/native/reactivity.js +0 -4
  36. package/dist/module/runtime/native/reactivity.js.map +1 -1
  37. package/dist/module/runtime/native/styles/shorthands/box-shadow.js +19 -11
  38. package/dist/module/runtime/native/styles/shorthands/box-shadow.js.map +1 -1
  39. package/dist/module/runtime/native/styles/units.js +11 -8
  40. package/dist/module/runtime/native/styles/units.js.map +1 -1
  41. package/dist/module/runtime/web/api.js +18 -1
  42. package/dist/module/runtime/web/api.js.map +1 -1
  43. package/dist/module/style-collection/root.js +1 -0
  44. package/dist/module/style-collection/root.js.map +1 -1
  45. package/dist/typescript/commonjs/src/babel/index.d.ts +3 -0
  46. package/dist/typescript/commonjs/src/babel/index.d.ts.map +1 -1
  47. package/dist/typescript/commonjs/src/compiler/atRules.d.ts.map +1 -1
  48. package/dist/typescript/commonjs/src/compiler/declarations.d.ts +14 -3
  49. package/dist/typescript/commonjs/src/compiler/declarations.d.ts.map +1 -1
  50. package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts.map +1 -1
  51. package/dist/typescript/commonjs/src/jest/index.d.ts.map +1 -1
  52. package/dist/typescript/commonjs/src/runtime/native/api.d.ts +13 -1
  53. package/dist/typescript/commonjs/src/runtime/native/api.d.ts.map +1 -1
  54. package/dist/typescript/commonjs/src/runtime/native/reactivity.d.ts +0 -2
  55. package/dist/typescript/commonjs/src/runtime/native/reactivity.d.ts.map +1 -1
  56. package/dist/typescript/commonjs/src/runtime/native/styles/shorthands/box-shadow.d.ts.map +1 -1
  57. package/dist/typescript/commonjs/src/runtime/native/styles/units.d.ts.map +1 -1
  58. package/dist/typescript/commonjs/src/runtime/web/api.d.ts +8 -2
  59. package/dist/typescript/commonjs/src/runtime/web/api.d.ts.map +1 -1
  60. package/dist/typescript/module/src/babel/index.d.ts +3 -0
  61. package/dist/typescript/module/src/babel/index.d.ts.map +1 -1
  62. package/dist/typescript/module/src/compiler/atRules.d.ts.map +1 -1
  63. package/dist/typescript/module/src/compiler/declarations.d.ts +14 -3
  64. package/dist/typescript/module/src/compiler/declarations.d.ts.map +1 -1
  65. package/dist/typescript/module/src/compiler/stylesheet.d.ts.map +1 -1
  66. package/dist/typescript/module/src/jest/index.d.ts.map +1 -1
  67. package/dist/typescript/module/src/runtime/native/api.d.ts +13 -1
  68. package/dist/typescript/module/src/runtime/native/api.d.ts.map +1 -1
  69. package/dist/typescript/module/src/runtime/native/reactivity.d.ts +0 -2
  70. package/dist/typescript/module/src/runtime/native/reactivity.d.ts.map +1 -1
  71. package/dist/typescript/module/src/runtime/native/styles/shorthands/box-shadow.d.ts.map +1 -1
  72. package/dist/typescript/module/src/runtime/native/styles/units.d.ts.map +1 -1
  73. package/dist/typescript/module/src/runtime/web/api.d.ts +8 -2
  74. package/dist/typescript/module/src/runtime/web/api.d.ts.map +1 -1
  75. package/package.json +3 -3
  76. package/src/babel/index.ts +2 -2
  77. package/src/compiler/atRules.ts +2 -0
  78. package/src/compiler/declarations.ts +147 -42
  79. package/src/compiler/stylesheet.ts +6 -0
  80. package/src/jest/index.ts +1 -2
  81. package/src/runtime/native/{api.ts → api.tsx} +31 -4
  82. package/src/runtime/native/reactivity.ts +0 -4
  83. package/src/runtime/native/styles/shorthands/box-shadow.ts +24 -18
  84. package/src/runtime/native/styles/units.ts +13 -8
  85. package/src/runtime/web/{api.ts → api.tsx} +28 -2
  86. 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
- .flatMap((shadows) => {
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
- /* eslint-disable */
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, get) => {
6
- let value = func[2];
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 = get(remObs);
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(Number(value) * emValue);
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 = (_, func, get) => {
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
- return round(value * get(remObs));
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 { createElement, type ComponentProps } from "react";
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 = <const C extends ReactComponent>(
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
  };
@@ -33,3 +33,5 @@ const rootVariableFamily = () => {
33
33
 
34
34
  export const rootVariables = rootVariableFamily();
35
35
  export const universalVariables = rootVariableFamily();
36
+
37
+ rootVariables("__rn-css-rem").set([[14]]);