react-native-css 3.0.0-preview.0 → 3.0.0-preview.1

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 (63) hide show
  1. package/dist/commonjs/compiler/declarations.js +99 -24
  2. package/dist/commonjs/compiler/declarations.js.map +1 -1
  3. package/dist/commonjs/compiler/stylesheet.js +5 -0
  4. package/dist/commonjs/compiler/stylesheet.js.map +1 -1
  5. package/dist/commonjs/jest/index.js +0 -1
  6. package/dist/commonjs/jest/index.js.map +1 -1
  7. package/dist/commonjs/runtime/native/api.js +21 -2
  8. package/dist/commonjs/runtime/native/api.js.map +1 -1
  9. package/dist/commonjs/runtime/native/reactivity.js +1 -5
  10. package/dist/commonjs/runtime/native/reactivity.js.map +1 -1
  11. package/dist/commonjs/runtime/native/styles/units.js +10 -8
  12. package/dist/commonjs/runtime/native/styles/units.js.map +1 -1
  13. package/dist/commonjs/runtime/web/api.js +18 -0
  14. package/dist/commonjs/runtime/web/api.js.map +1 -1
  15. package/dist/commonjs/style-collection/root.js +1 -0
  16. package/dist/commonjs/style-collection/root.js.map +1 -1
  17. package/dist/module/compiler/declarations.js +94 -24
  18. package/dist/module/compiler/declarations.js.map +1 -1
  19. package/dist/module/compiler/stylesheet.js +5 -0
  20. package/dist/module/compiler/stylesheet.js.map +1 -1
  21. package/dist/module/jest/index.js +1 -2
  22. package/dist/module/jest/index.js.map +1 -1
  23. package/dist/module/runtime/native/api.js +21 -3
  24. package/dist/module/runtime/native/api.js.map +1 -1
  25. package/dist/module/runtime/native/reactivity.js +0 -4
  26. package/dist/module/runtime/native/reactivity.js.map +1 -1
  27. package/dist/module/runtime/native/styles/units.js +11 -8
  28. package/dist/module/runtime/native/styles/units.js.map +1 -1
  29. package/dist/module/runtime/web/api.js +18 -1
  30. package/dist/module/runtime/web/api.js.map +1 -1
  31. package/dist/module/style-collection/root.js +1 -0
  32. package/dist/module/style-collection/root.js.map +1 -1
  33. package/dist/typescript/commonjs/src/compiler/declarations.d.ts +12 -1
  34. package/dist/typescript/commonjs/src/compiler/declarations.d.ts.map +1 -1
  35. package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts.map +1 -1
  36. package/dist/typescript/commonjs/src/jest/index.d.ts.map +1 -1
  37. package/dist/typescript/commonjs/src/runtime/native/api.d.ts +13 -1
  38. package/dist/typescript/commonjs/src/runtime/native/api.d.ts.map +1 -1
  39. package/dist/typescript/commonjs/src/runtime/native/reactivity.d.ts +0 -2
  40. package/dist/typescript/commonjs/src/runtime/native/reactivity.d.ts.map +1 -1
  41. package/dist/typescript/commonjs/src/runtime/native/styles/units.d.ts.map +1 -1
  42. package/dist/typescript/commonjs/src/runtime/web/api.d.ts +8 -2
  43. package/dist/typescript/commonjs/src/runtime/web/api.d.ts.map +1 -1
  44. package/dist/typescript/module/src/compiler/declarations.d.ts +12 -1
  45. package/dist/typescript/module/src/compiler/declarations.d.ts.map +1 -1
  46. package/dist/typescript/module/src/compiler/stylesheet.d.ts.map +1 -1
  47. package/dist/typescript/module/src/jest/index.d.ts.map +1 -1
  48. package/dist/typescript/module/src/runtime/native/api.d.ts +13 -1
  49. package/dist/typescript/module/src/runtime/native/api.d.ts.map +1 -1
  50. package/dist/typescript/module/src/runtime/native/reactivity.d.ts +0 -2
  51. package/dist/typescript/module/src/runtime/native/reactivity.d.ts.map +1 -1
  52. package/dist/typescript/module/src/runtime/native/styles/units.d.ts.map +1 -1
  53. package/dist/typescript/module/src/runtime/web/api.d.ts +8 -2
  54. package/dist/typescript/module/src/runtime/web/api.d.ts.map +1 -1
  55. package/package.json +1 -2
  56. package/src/compiler/declarations.ts +126 -32
  57. package/src/compiler/stylesheet.ts +6 -0
  58. package/src/jest/index.ts +1 -2
  59. package/src/runtime/native/{api.ts → api.tsx} +31 -4
  60. package/src/runtime/native/reactivity.ts +0 -4
  61. package/src/runtime/native/styles/units.ts +13 -8
  62. package/src/runtime/web/{api.ts → api.tsx} +28 -2
  63. package/src/style-collection/root.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-css",
3
- "version": "3.0.0-preview.0",
3
+ "version": "3.0.0-preview.1",
4
4
  "description": "A CSS polyfill for React Native",
5
5
  "exports": {
6
6
  ".": {
@@ -116,7 +116,6 @@
116
116
  "prepare": "bob build",
117
117
  "prepublishOnly": "bob build",
118
118
  "release": "release-it --config ./.config/release-it.config.ts",
119
- "release:nightly": "release-it --config ./.config/release-it.nightly.config.ts 3.0.0-nightly.\"$(git rev-parse --short HEAD)\" --npm.tag=nightly && git restore :/",
120
119
  "start": "yarn example start",
121
120
  "start:build": "yarn build && yarn example build",
122
121
  "start:debug": "yarn build && yarn example debug",
@@ -1,4 +1,4 @@
1
- // cSpell:ignore rcap,vmin,svmin,lvmin,dvmin,cqmin,vmax,svmax,lvmax,dvmax,cqmax,currentcolor,oklab,oklch,prophoto
1
+ // cSpell:ignore rcap,vmin,svmin,lvmin,dvmin,cqmin,vmax,svmax,lvmax,dvmax,cqmax,currentcolor,oklab,oklch,prophoto,squircle,oldstyle,nums
2
2
 
3
3
  import Color from "colorjs.io";
4
4
  import type {
@@ -91,6 +91,7 @@ const parsers: {
91
91
  "animation-play-state": addAnimationValue,
92
92
  "animation-timing-function": addAnimationValue,
93
93
  "aspect-ratio": parseAspectRatio,
94
+ "backface-visibility": parseBackfaceVisibility,
94
95
  "background-color": parseColorDeclaration,
95
96
  "background-image": parseBackgroundImage,
96
97
  "block-size": parseSizeDeclaration,
@@ -146,8 +147,9 @@ const parsers: {
146
147
  "border-top-style": parseBorderStyleDeclaration,
147
148
  "border-top-width": parseBorderSideWidthDeclaration,
148
149
  "border-width": parseBorderWidth,
149
- "bottom": parseSizeDeclaration,
150
+ "bottom": parseSizeWithAutoDeclaration,
150
151
  "box-shadow": parseBoxShadow,
152
+ "box-sizing": parseBoxSizing,
151
153
  "caret-color": parseColorOrAutoDeclaration,
152
154
  "color": parseFontColorDeclaration,
153
155
  "column-gap": parseGap,
@@ -155,10 +157,11 @@ const parsers: {
155
157
  "container-name": parseContainerName,
156
158
  "container-type": parseContainerType,
157
159
  "display": parseDisplay,
160
+ "direction": parseDirection,
158
161
  "fill": parseSVGPaint,
159
162
  "filter": parseFilter,
160
163
  "flex": parseFlex,
161
- "flex-basis": parseLengthPercentageOrAutoDeclaration,
164
+ "flex-basis": parseLengthPercentageDeclaration,
162
165
  "flex-direction": ({ value }) => value,
163
166
  "flex-flow": parseFlexFlow,
164
167
  "flex-grow": ({ value }) => value,
@@ -175,26 +178,26 @@ const parsers: {
175
178
  "inline-size": parseSizeDeclaration,
176
179
  "inset": parseInset,
177
180
  "inset-block": parseInsetBlock,
178
- "inset-block-end": parseLengthPercentageOrAutoDeclaration,
179
- "inset-block-start": parseLengthPercentageOrAutoDeclaration,
181
+ "inset-block-end": parseLengthPercentageDeclaration,
182
+ "inset-block-start": parseLengthPercentageDeclaration,
180
183
  "inset-inline": parseInsetInline,
181
- "inset-inline-end": parseLengthPercentageOrAutoDeclaration,
182
- "inset-inline-start": parseLengthPercentageOrAutoDeclaration,
184
+ "inset-inline-end": parseLengthPercentageDeclaration,
185
+ "inset-inline-start": parseLengthPercentageDeclaration,
183
186
  "justify-content": parseJustifyContent,
184
- "left": parseSizeDeclaration,
187
+ "left": parseSizeWithAutoDeclaration,
185
188
  "letter-spacing": parseLetterSpacing,
186
189
  "line-height": parseLineHeightDeclaration,
187
190
  "margin": parseMargin,
188
191
  "margin-block": parseMarginBlock,
189
192
  "margin-block-end": parseLengthPercentageOrAutoDeclaration,
190
193
  "margin-block-start": parseLengthPercentageOrAutoDeclaration,
191
- "margin-bottom": parseSizeDeclaration,
194
+ "margin-bottom": parseSizeWithAutoDeclaration,
192
195
  "margin-inline": parseMarginInline,
193
196
  "margin-inline-end": parseLengthPercentageOrAutoDeclaration,
194
197
  "margin-inline-start": parseLengthPercentageOrAutoDeclaration,
195
- "margin-left": parseSizeDeclaration,
196
- "margin-right": parseSizeDeclaration,
197
- "margin-top": parseSizeDeclaration,
198
+ "margin-left": parseSizeWithAutoDeclaration,
199
+ "margin-right": parseSizeWithAutoDeclaration,
200
+ "margin-top": parseSizeWithAutoDeclaration,
198
201
  "max-block-size": parseSizeDeclaration,
199
202
  "max-height": parseSizeDeclaration,
200
203
  "max-inline-size": parseSizeDeclaration,
@@ -203,21 +206,24 @@ const parsers: {
203
206
  "min-height": parseSizeDeclaration,
204
207
  "min-inline-size": parseSizeDeclaration,
205
208
  "min-width": parseSizeDeclaration,
206
- "opacity": ({ value }) => value,
209
+ "opacity": ({ value }) => round(value),
210
+ "outline-color": parseColorDeclaration,
211
+ "outline-style": parseOutlineStyle,
212
+ "outline-width": parseBorderSideWidthDeclaration,
207
213
  "overflow": parseOverflow,
208
214
  "padding": parsePadding,
209
215
  "padding-block": parsePaddingBlock,
210
- "padding-block-end": parseLengthPercentageOrAutoDeclaration,
211
- "padding-block-start": parseLengthPercentageOrAutoDeclaration,
216
+ "padding-block-end": parseLengthPercentageDeclaration,
217
+ "padding-block-start": parseLengthPercentageDeclaration,
212
218
  "padding-bottom": parseSizeDeclaration,
213
219
  "padding-inline": parsePaddingInline,
214
- "padding-inline-end": parseLengthPercentageOrAutoDeclaration,
215
- "padding-inline-start": parseLengthPercentageOrAutoDeclaration,
220
+ "padding-inline-end": parseLengthPercentageDeclaration,
221
+ "padding-inline-start": parseLengthPercentageDeclaration,
216
222
  "padding-left": parseSizeDeclaration,
217
223
  "padding-right": parseSizeDeclaration,
218
224
  "padding-top": parseSizeDeclaration,
219
225
  "position": parsePosition,
220
- "right": parseSizeDeclaration,
226
+ "right": parseSizeWithAutoDeclaration,
221
227
  "rotate": parseRotate,
222
228
  "row-gap": parseGap,
223
229
  "scale": parseScale,
@@ -230,7 +236,7 @@ const parsers: {
230
236
  "text-decoration-style": parseTextDecorationStyle,
231
237
  "text-shadow": parseTextShadow,
232
238
  "text-transform": ({ value }) => value.case,
233
- "top": parseSizeDeclaration,
239
+ "top": parseSizeWithAutoDeclaration,
234
240
  "transform": parseTransform,
235
241
  "transition": addTransitionValue,
236
242
  "transition-delay": addTransitionValue,
@@ -611,8 +617,11 @@ function parseMarginBlock(
611
617
  "margin-block-start": parseLengthPercentageOrAuto(
612
618
  value.blockStart,
613
619
  builder,
620
+ { allowAuto: true },
614
621
  ),
615
- "margin-block-end": parseLengthPercentageOrAuto(value.blockEnd, builder),
622
+ "margin-block-end": parseLengthPercentageOrAuto(value.blockEnd, builder, {
623
+ allowAuto: true,
624
+ }),
616
625
  });
617
626
  }
618
627
 
@@ -624,8 +633,11 @@ function parseMarginInline(
624
633
  "margin-inline-start": parseLengthPercentageOrAuto(
625
634
  value.inlineStart,
626
635
  builder,
636
+ { allowAuto: true },
627
637
  ),
628
- "margin-inline-end": parseLengthPercentageOrAuto(value.inlineEnd, builder),
638
+ "margin-inline-end": parseLengthPercentageOrAuto(value.inlineEnd, builder, {
639
+ allowAuto: true,
640
+ }),
629
641
  });
630
642
  }
631
643
 
@@ -982,6 +994,14 @@ export function parseCustomDeclaration(
982
994
  } else if (property === "object-position") {
983
995
  // https://github.com/parcel-bundler/lightningcss/issues/1047
984
996
  parseObjectPosition(declaration.value, builder);
997
+ } else if (property === "outline-offset") {
998
+ // https://github.com/parcel-bundler/lightningcss/issues/1048
999
+ builder.addDescriptor(
1000
+ property,
1001
+ parseUnparsed(declaration.value.value, builder, property),
1002
+ );
1003
+ } else if (property === "corner-shape") {
1004
+ parseCornerShape(declaration.value, builder);
985
1005
  } else if (
986
1006
  validProperties.has(property) ||
987
1007
  property.startsWith("--") ||
@@ -1457,6 +1477,13 @@ export function parseSizeDeclaration(
1457
1477
  return parseSize(declaration.value, builder);
1458
1478
  }
1459
1479
 
1480
+ export function parseSizeWithAutoDeclaration(
1481
+ declaration: { value: Size | MaxSize },
1482
+ builder: StylesheetBuilder,
1483
+ ) {
1484
+ return parseSize(declaration.value, builder, { allowAuto: true });
1485
+ }
1486
+
1460
1487
  export function parsePointerEvents(
1461
1488
  { value }: { value: string },
1462
1489
  builder: StylesheetBuilder,
@@ -1709,13 +1736,20 @@ export function parseColor(cssColor: CssColor, builder: StylesheetBuilder) {
1709
1736
  }
1710
1737
  }
1711
1738
 
1712
- export function parseLengthPercentageOrAutoDeclaration(
1739
+ export function parseLengthPercentageDeclaration(
1713
1740
  value: { value: LengthPercentageOrAuto },
1714
1741
  builder: StylesheetBuilder,
1715
1742
  ) {
1716
1743
  return parseLengthPercentageOrAuto(value.value, builder);
1717
1744
  }
1718
1745
 
1746
+ export function parseLengthPercentageOrAutoDeclaration(
1747
+ value: { value: LengthPercentageOrAuto },
1748
+ builder: StylesheetBuilder,
1749
+ ) {
1750
+ return parseLengthPercentageOrAuto(value.value, builder, { allowAuto: true });
1751
+ }
1752
+
1719
1753
  export function parseLengthPercentageOrAuto(
1720
1754
  lengthPercentageOrAuto: LengthPercentageOrAuto,
1721
1755
  builder: StylesheetBuilder,
@@ -2097,16 +2131,7 @@ function parseBorderBlockStyle(
2097
2131
  }
2098
2132
 
2099
2133
  export function parseBorderSideWidthDeclaration(
2100
- declaration: DeclarationType<
2101
- | "border-block-end-width"
2102
- | "border-block-start-width"
2103
- | "border-bottom-width"
2104
- | "border-inline-end-width"
2105
- | "border-inline-start-width"
2106
- | "border-left-width"
2107
- | "border-right-width"
2108
- | "border-top-width"
2109
- >,
2134
+ declaration: Extract<Declaration, { value: BorderSideWidth }>,
2110
2135
  builder: StylesheetBuilder,
2111
2136
  ) {
2112
2137
  builder.addDescriptor(
@@ -2359,6 +2384,18 @@ export function parseBoxShadow(
2359
2384
  }
2360
2385
  }
2361
2386
 
2387
+ export function parseBoxSizing(
2388
+ declaration: DeclarationType<"box-sizing">,
2389
+ builder: StylesheetBuilder,
2390
+ ) {
2391
+ if (["border-box", "content-box"].includes(declaration.value)) {
2392
+ return declaration.value;
2393
+ }
2394
+
2395
+ builder.addWarning("value", declaration.value);
2396
+ return undefined;
2397
+ }
2398
+
2362
2399
  export function parseDisplay(
2363
2400
  { value }: DeclarationType<"display">,
2364
2401
  builder: StylesheetBuilder,
@@ -2416,6 +2453,19 @@ export function parseDisplay(
2416
2453
  }
2417
2454
  }
2418
2455
 
2456
+ export function parseDirection(
2457
+ declaration: DeclarationType<"direction">,
2458
+ builder: StylesheetBuilder,
2459
+ ) {
2460
+ if (["ltr", "rtl"].includes(declaration.value)) {
2461
+ builder.addDescriptor("direction", declaration.value);
2462
+ builder.addDescriptor("--__rn-css-direction", declaration.value);
2463
+ }
2464
+
2465
+ builder.addWarning("value", declaration.value);
2466
+ return;
2467
+ }
2468
+
2419
2469
  export function parseAspectRatio({
2420
2470
  value,
2421
2471
  }: DeclarationType<"aspect-ratio">): StyleDescriptor {
@@ -2433,6 +2483,18 @@ export function parseAspectRatio({
2433
2483
  }
2434
2484
  }
2435
2485
 
2486
+ export function parseBackfaceVisibility(
2487
+ { value }: DeclarationType<"backface-visibility">,
2488
+ builder: StylesheetBuilder,
2489
+ ): StyleDescriptor {
2490
+ if (["visible", "hidden"].includes(value)) {
2491
+ return value;
2492
+ } else {
2493
+ builder.addWarning("value", value);
2494
+ return;
2495
+ }
2496
+ }
2497
+
2436
2498
  export function parseDimension(
2437
2499
  { unit, value }: Extract<Token, { type: "dimension" }>,
2438
2500
  builder: StylesheetBuilder,
@@ -3031,6 +3093,19 @@ function parseObjectPosition(
3031
3093
  ]);
3032
3094
  }
3033
3095
 
3096
+ function parseCornerShape(
3097
+ declaration: CustomProperty,
3098
+ builder: StylesheetBuilder,
3099
+ ) {
3100
+ const shape = parseUnparsed(declaration.value, builder, "corner-shape");
3101
+
3102
+ if (shape === "round") {
3103
+ builder.addDescriptor("borderCurve", "circular");
3104
+ } else if (shape === "squircle") {
3105
+ builder.addDescriptor("borderCurve", "continuous");
3106
+ }
3107
+ }
3108
+
3034
3109
  function parseVisibility(
3035
3110
  declaration: DeclarationType<"visibility">,
3036
3111
  builder: StylesheetBuilder,
@@ -3044,6 +3119,25 @@ function parseVisibility(
3044
3119
  }
3045
3120
  }
3046
3121
 
3122
+ function parseOutlineStyle(
3123
+ declaration: DeclarationType<"outline-style">,
3124
+ builder: StylesheetBuilder,
3125
+ ) {
3126
+ const allowed = ["solid", "dotted", "dashed"];
3127
+
3128
+ if (
3129
+ declaration.value.type !== "auto" &&
3130
+ allowed.includes(declaration.value.value)
3131
+ ) {
3132
+ builder.addDescriptor("outlineStyle", declaration.value.value);
3133
+ } else {
3134
+ builder.addWarning(
3135
+ "value",
3136
+ declaration.value.type === "auto" ? "auto" : declaration.value.value,
3137
+ );
3138
+ }
3139
+ }
3140
+
3047
3141
  function parseFilter(
3048
3142
  declaration: DeclarationType<"filter">,
3049
3143
  builder: StylesheetBuilder,
@@ -568,6 +568,12 @@ export class StylesheetBuilder {
568
568
  : [value];
569
569
  // Append extra media queries if they exist
570
570
  this.shared[type][name].push(variableValue);
571
+
572
+ if (type === "rootVariables" && name === "__rn-css-em") {
573
+ const remName = "__rn-css-rem";
574
+ this.shared[type][remName] ??= [];
575
+ this.shared[type][remName].push(variableValue);
576
+ }
571
577
  }
572
578
  }
573
579
  }
package/src/jest/index.ts CHANGED
@@ -5,7 +5,7 @@ import { inspect } from "node:util";
5
5
  import { compile, type CompilerOptions } from "react-native-css/compiler";
6
6
  import { StyleCollection } from "react-native-css/style-collection";
7
7
 
8
- import { colorScheme, dimensions, rem } from "../runtime/native/reactivity";
8
+ import { colorScheme, dimensions } from "../runtime/native/reactivity";
9
9
 
10
10
  declare global {
11
11
  /* eslint-disable @typescript-eslint/no-namespace */
@@ -21,7 +21,6 @@ export const testID = "react-native-css";
21
21
  beforeEach(() => {
22
22
  StyleCollection.styles.clear();
23
23
  dimensions.set(Dimensions.get("window"));
24
- rem.set(14);
25
24
  Appearance.setColorScheme(null);
26
25
  colorScheme.set(null);
27
26
  });
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable */
2
- import { useContext, useState } from "react";
2
+ import { useContext, useMemo, useState, type PropsWithChildren } from "react";
3
3
  import { Appearance } from "react-native";
4
4
 
5
- import type { InlineVariable, StyleDescriptor } from "../../compiler";
5
+ import type { StyleDescriptor } from "../../compiler";
6
6
  import type {
7
7
  ColorScheme,
8
8
  Props,
@@ -18,6 +18,7 @@ import {
18
18
  VariableContext,
19
19
  type Effect,
20
20
  type Getter,
21
+ type VariableContextValue,
21
22
  } from "./reactivity";
22
23
  import { resolveValue } from "./styles/resolve";
23
24
 
@@ -102,7 +103,33 @@ export function useNativeVariable(name: string) {
102
103
  return resolveValue([{}, "var", [name]], effect.get, { inheritedVariables });
103
104
  }
104
105
 
106
+ /**
107
+ * @deprecated Use `<VariableContextProvider />` instead.
108
+ */
105
109
  export function vars(variables: Record<string, StyleDescriptor>) {
106
- (variables as InlineVariable)[VAR_SYMBOL] = "inline";
107
- return variables;
110
+ return Object.assign(
111
+ { [VAR_SYMBOL]: "inline" },
112
+ Object.fromEntries(
113
+ Object.entries(variables).map(([k, v]) => [k.replace(/^--/, ""), v]),
114
+ ),
115
+ );
116
+ }
117
+
118
+ export function VariableContextProvider(
119
+ props: PropsWithChildren<{ value: Record<`--${string}`, StyleDescriptor> }>,
120
+ ) {
121
+ const inheritedVariables = useContext(VariableContext);
122
+
123
+ const value: VariableContextValue = useMemo(
124
+ () => ({
125
+ ...inheritedVariables,
126
+ ...Object.fromEntries(
127
+ Object.entries(props.value).map(([k, v]) => [k.replace(/^--/, ""), v]),
128
+ ),
129
+ [VAR_SYMBOL]: true,
130
+ }),
131
+ [inheritedVariables, props.value],
132
+ );
133
+
134
+ return <VariableContext value={value}>{props.children}</VariableContext>;
108
135
  }
@@ -189,10 +189,6 @@ export const VariableContext = createContext<VariableContextValue>({
189
189
  [VAR_SYMBOL]: true,
190
190
  });
191
191
 
192
- /** Units *********************************************************************/
193
-
194
- export const rem = observable(14);
195
-
196
192
  /** Pseudo Classes ************************************************************/
197
193
 
198
194
  export const hoverFamily = weakFamily(() => observable(false));
@@ -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]]);