react-native-css 3.0.0-nightly.61014be → 3.0.0-nightly.df0f885

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 (131) hide show
  1. package/dist/commonjs/compiler/attributes.test.js +1 -1
  2. package/dist/commonjs/compiler/attributes.test.js.map +1 -1
  3. package/dist/commonjs/compiler/compiler.js +25 -14
  4. package/dist/commonjs/compiler/compiler.js.map +1 -1
  5. package/dist/commonjs/compiler/declarations.js +31 -7
  6. package/dist/commonjs/compiler/declarations.js.map +1 -1
  7. package/dist/commonjs/compiler/inheritance.test.js +3 -3
  8. package/dist/commonjs/compiler/inheritance.test.js.map +1 -1
  9. package/dist/commonjs/compiler/stylesheet.js +53 -19
  10. package/dist/commonjs/compiler/stylesheet.js.map +1 -1
  11. package/dist/commonjs/jest/index.js +23 -7
  12. package/dist/commonjs/jest/index.js.map +1 -1
  13. package/dist/commonjs/poison.pill.js +4 -1
  14. package/dist/commonjs/poison.pill.js.map +1 -1
  15. package/dist/commonjs/runtime/native/conditions/container-query.js +21 -21
  16. package/dist/commonjs/runtime/native/conditions/container-query.js.map +1 -1
  17. package/dist/commonjs/runtime/native/conditions/guards.js.map +1 -1
  18. package/dist/commonjs/runtime/native/conditions/index.js +8 -8
  19. package/dist/commonjs/runtime/native/conditions/index.js.map +1 -1
  20. package/dist/commonjs/runtime/native/conditions/media-query.js +16 -16
  21. package/dist/commonjs/runtime/native/conditions/media-query.js.map +1 -1
  22. package/dist/commonjs/runtime/native/react/interaction.js +10 -10
  23. package/dist/commonjs/runtime/native/react/interaction.js.map +1 -1
  24. package/dist/commonjs/runtime/native/react/rules.js +9 -9
  25. package/dist/commonjs/runtime/native/react/rules.js.map +1 -1
  26. package/dist/commonjs/runtime/native/react/useNativeCss.js +1 -0
  27. package/dist/commonjs/runtime/native/react/useNativeCss.js.map +1 -1
  28. package/dist/commonjs/runtime/native/reactivity.js +15 -6
  29. package/dist/commonjs/runtime/native/reactivity.js.map +1 -1
  30. package/dist/commonjs/runtime/native/styles/index.js +12 -12
  31. package/dist/commonjs/runtime/native/styles/index.js.map +1 -1
  32. package/dist/module/compiler/attributes.test.js +1 -1
  33. package/dist/module/compiler/attributes.test.js.map +1 -1
  34. package/dist/module/compiler/compiler.js +25 -14
  35. package/dist/module/compiler/compiler.js.map +1 -1
  36. package/dist/module/compiler/compiler.types.js.map +1 -1
  37. package/dist/module/compiler/declarations.js +30 -7
  38. package/dist/module/compiler/declarations.js.map +1 -1
  39. package/dist/module/compiler/inheritance.test.js +3 -3
  40. package/dist/module/compiler/inheritance.test.js.map +1 -1
  41. package/dist/module/compiler/stylesheet.js +53 -19
  42. package/dist/module/compiler/stylesheet.js.map +1 -1
  43. package/dist/module/jest/index.js +23 -7
  44. package/dist/module/jest/index.js.map +1 -1
  45. package/dist/module/poison.pill.js +4 -1
  46. package/dist/module/poison.pill.js.map +1 -1
  47. package/dist/module/runtime/native/conditions/container-query.js +21 -21
  48. package/dist/module/runtime/native/conditions/container-query.js.map +1 -1
  49. package/dist/module/runtime/native/conditions/guards.js.map +1 -1
  50. package/dist/module/runtime/native/conditions/index.js +8 -8
  51. package/dist/module/runtime/native/conditions/index.js.map +1 -1
  52. package/dist/module/runtime/native/conditions/media-query.js +16 -16
  53. package/dist/module/runtime/native/conditions/media-query.js.map +1 -1
  54. package/dist/module/runtime/native/react/interaction.js +10 -10
  55. package/dist/module/runtime/native/react/interaction.js.map +1 -1
  56. package/dist/module/runtime/native/react/rules.js +9 -9
  57. package/dist/module/runtime/native/react/rules.js.map +1 -1
  58. package/dist/module/runtime/native/react/useNativeCss.js +1 -0
  59. package/dist/module/runtime/native/react/useNativeCss.js.map +1 -1
  60. package/dist/module/runtime/native/reactivity.js +15 -6
  61. package/dist/module/runtime/native/reactivity.js.map +1 -1
  62. package/dist/module/runtime/native/styles/index.js +12 -12
  63. package/dist/module/runtime/native/styles/index.js.map +1 -1
  64. package/dist/typescript/commonjs/src/compiler/compiler.d.ts +9 -2
  65. package/dist/typescript/commonjs/src/compiler/compiler.d.ts.map +1 -1
  66. package/dist/typescript/commonjs/src/compiler/compiler.types.d.ts +5 -4
  67. package/dist/typescript/commonjs/src/compiler/compiler.types.d.ts.map +1 -1
  68. package/dist/typescript/commonjs/src/compiler/declarations.d.ts +2 -1
  69. package/dist/typescript/commonjs/src/compiler/declarations.d.ts.map +1 -1
  70. package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts +12 -2
  71. package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts.map +1 -1
  72. package/dist/typescript/commonjs/src/jest/index.d.ts +10 -3
  73. package/dist/typescript/commonjs/src/jest/index.d.ts.map +1 -1
  74. package/dist/typescript/commonjs/src/poison.pill.d.ts.map +1 -1
  75. package/dist/typescript/commonjs/src/runtime/native/conditions/container-query.d.ts +3 -3
  76. package/dist/typescript/commonjs/src/runtime/native/conditions/container-query.d.ts.map +1 -1
  77. package/dist/typescript/commonjs/src/runtime/native/conditions/guards.d.ts +2 -2
  78. package/dist/typescript/commonjs/src/runtime/native/conditions/guards.d.ts.map +1 -1
  79. package/dist/typescript/commonjs/src/runtime/native/conditions/index.d.ts +2 -2
  80. package/dist/typescript/commonjs/src/runtime/native/conditions/index.d.ts.map +1 -1
  81. package/dist/typescript/commonjs/src/runtime/native/conditions/media-query.d.ts +2 -2
  82. package/dist/typescript/commonjs/src/runtime/native/conditions/media-query.d.ts.map +1 -1
  83. package/dist/typescript/commonjs/src/runtime/native/react/interaction.d.ts +2 -2
  84. package/dist/typescript/commonjs/src/runtime/native/react/interaction.d.ts.map +1 -1
  85. package/dist/typescript/commonjs/src/runtime/native/react/useNativeCss.d.ts +2 -1
  86. package/dist/typescript/commonjs/src/runtime/native/react/useNativeCss.d.ts.map +1 -1
  87. package/dist/typescript/commonjs/src/runtime/native/reactivity.d.ts +4 -4
  88. package/dist/typescript/commonjs/src/runtime/native/reactivity.d.ts.map +1 -1
  89. package/dist/typescript/module/src/compiler/compiler.d.ts +9 -2
  90. package/dist/typescript/module/src/compiler/compiler.d.ts.map +1 -1
  91. package/dist/typescript/module/src/compiler/compiler.types.d.ts +5 -4
  92. package/dist/typescript/module/src/compiler/compiler.types.d.ts.map +1 -1
  93. package/dist/typescript/module/src/compiler/declarations.d.ts +2 -1
  94. package/dist/typescript/module/src/compiler/declarations.d.ts.map +1 -1
  95. package/dist/typescript/module/src/compiler/stylesheet.d.ts +12 -2
  96. package/dist/typescript/module/src/compiler/stylesheet.d.ts.map +1 -1
  97. package/dist/typescript/module/src/jest/index.d.ts +10 -3
  98. package/dist/typescript/module/src/jest/index.d.ts.map +1 -1
  99. package/dist/typescript/module/src/poison.pill.d.ts.map +1 -1
  100. package/dist/typescript/module/src/runtime/native/conditions/container-query.d.ts +3 -3
  101. package/dist/typescript/module/src/runtime/native/conditions/container-query.d.ts.map +1 -1
  102. package/dist/typescript/module/src/runtime/native/conditions/guards.d.ts +2 -2
  103. package/dist/typescript/module/src/runtime/native/conditions/guards.d.ts.map +1 -1
  104. package/dist/typescript/module/src/runtime/native/conditions/index.d.ts +2 -2
  105. package/dist/typescript/module/src/runtime/native/conditions/index.d.ts.map +1 -1
  106. package/dist/typescript/module/src/runtime/native/conditions/media-query.d.ts +2 -2
  107. package/dist/typescript/module/src/runtime/native/conditions/media-query.d.ts.map +1 -1
  108. package/dist/typescript/module/src/runtime/native/react/interaction.d.ts +2 -2
  109. package/dist/typescript/module/src/runtime/native/react/interaction.d.ts.map +1 -1
  110. package/dist/typescript/module/src/runtime/native/react/useNativeCss.d.ts +2 -1
  111. package/dist/typescript/module/src/runtime/native/react/useNativeCss.d.ts.map +1 -1
  112. package/dist/typescript/module/src/runtime/native/reactivity.d.ts +4 -4
  113. package/dist/typescript/module/src/runtime/native/reactivity.d.ts.map +1 -1
  114. package/package.json +4 -3
  115. package/src/compiler/attributes.test.ts +1 -1
  116. package/src/compiler/compiler.ts +29 -24
  117. package/src/compiler/compiler.types.ts +7 -5
  118. package/src/compiler/declarations.ts +52 -8
  119. package/src/compiler/inheritance.test.ts +3 -3
  120. package/src/compiler/stylesheet.ts +67 -20
  121. package/src/jest/index.ts +30 -6
  122. package/src/poison.pill.ts +5 -1
  123. package/src/runtime/native/conditions/container-query.ts +22 -22
  124. package/src/runtime/native/conditions/guards.ts +1 -2
  125. package/src/runtime/native/conditions/index.ts +9 -9
  126. package/src/runtime/native/conditions/media-query.ts +17 -19
  127. package/src/runtime/native/react/interaction.ts +12 -12
  128. package/src/runtime/native/react/rules.ts +9 -9
  129. package/src/runtime/native/react/useNativeCss.ts +3 -0
  130. package/src/runtime/native/reactivity.ts +22 -13
  131. package/src/runtime/native/styles/index.ts +12 -12
@@ -6,7 +6,7 @@ test("nested classes", () => {
6
6
  color: red;
7
7
  }`);
8
8
 
9
- expect(compiled).toStrictEqual({
9
+ expect(compiled.stylesheet()).toStrictEqual({
10
10
  s: [
11
11
  [
12
12
  "my-class",
@@ -38,7 +38,7 @@ test("multiple tiers classes", () => {
38
38
  color: red;
39
39
  }`);
40
40
 
41
- expect(compiled).toStrictEqual({
41
+ expect(compiled.stylesheet()).toStrictEqual({
42
42
  s: [
43
43
  [
44
44
  "one",
@@ -79,7 +79,7 @@ test("tiers with multiple classes", () => {
79
79
  color: red;
80
80
  }`);
81
81
 
82
- expect(compiled).toStrictEqual({
82
+ expect(compiled.stylesheet()).toStrictEqual({
83
83
  s: [
84
84
  [
85
85
  "one",
@@ -17,6 +17,7 @@ import type {
17
17
  StyleRuleMapping,
18
18
  StyleRuleSet,
19
19
  VariableRecord,
20
+ VariableValue,
20
21
  } from "./compiler.types";
21
22
  import { toRNProperty, type NormalizeSelector } from "./selectors";
22
23
 
@@ -56,7 +57,17 @@ export class StylesheetBuilder {
56
57
  animations?: AnimationRecord;
57
58
  rem: number;
58
59
  ruleOrder: number;
59
- } = { ruleSets: {}, rem: 14, ruleOrder: 0 },
60
+ warningProperties: string[];
61
+ warningValues: [string, unknown][];
62
+ warningFunctions: string[];
63
+ } = {
64
+ ruleSets: {},
65
+ rem: 14,
66
+ ruleOrder: 0,
67
+ warningProperties: [],
68
+ warningValues: [],
69
+ warningFunctions: [],
70
+ },
60
71
  private selectors?: NormalizeSelector[],
61
72
  ) {}
62
73
 
@@ -76,7 +87,7 @@ export class StylesheetBuilder {
76
87
  );
77
88
  }
78
89
 
79
- cloneRule({ ...rule } = this.rule): StyleRule {
90
+ cloneRule({ ...rule } = this.ruleTemplate): StyleRule {
80
91
  rule.s = [...rule.s];
81
92
  rule.aq &&= [...rule.aq];
82
93
  rule.c &&= [...rule.c];
@@ -128,11 +139,17 @@ export class StylesheetBuilder {
128
139
  }
129
140
 
130
141
  if (this.shared.rootVariables) {
131
- stylesheetOptions.vr = Object.entries(this.shared.rootVariables);
142
+ stylesheetOptions.vr = Object.entries(this.shared.rootVariables).map(
143
+ // Reverse these so the most specific variables are first
144
+ ([key, value]) => [key, value.reverse()] as const,
145
+ );
132
146
  }
133
147
 
134
148
  if (this.shared.universalVariables) {
135
- stylesheetOptions.vu = Object.entries(this.shared.universalVariables);
149
+ stylesheetOptions.vu = Object.entries(this.shared.universalVariables).map(
150
+ // Reverse these so the most specific variables are first
151
+ ([key, value]) => [key, value.reverse()] as const,
152
+ );
136
153
  }
137
154
 
138
155
  if (this.shared.animations) {
@@ -156,10 +173,29 @@ export class StylesheetBuilder {
156
173
  }
157
174
 
158
175
  addWarning(
159
- _type: "property" | "value" | "function",
160
- _property: string | number,
176
+ type: "property" | "value" | "function",
177
+ property: string,
178
+ value?: unknown,
161
179
  ): void {
162
- // TODO
180
+ switch (type) {
181
+ case "property":
182
+ this.shared.warningProperties.push(property);
183
+ break;
184
+ case "value":
185
+ this.shared.warningValues.push([property, value]);
186
+ break;
187
+ case "function":
188
+ this.shared.warningFunctions.push(property);
189
+ break;
190
+ }
191
+ }
192
+
193
+ getWarnings() {
194
+ return {
195
+ properties: this.shared.warningProperties,
196
+ values: this.shared.warningValues,
197
+ functions: this.shared.warningFunctions,
198
+ };
163
199
  }
164
200
 
165
201
  newRule(mapping = this.mapping, { important = false } = {}) {
@@ -171,14 +207,12 @@ export class StylesheetBuilder {
171
207
  }
172
208
  }
173
209
 
174
- newRuleFork({ important = false } = {}) {
175
- this.rule = this.cloneRule(this.rule);
176
- this.rule.s[Specificity.Order] = this.shared.ruleOrder;
177
- if (important) {
178
- this.rule.s[Specificity.Important] = 1;
179
- }
210
+ /** Used by nested declarations (for example @media inside a RuleSet) */
211
+ newNestedRule({ important = false } = {}) {
212
+ this.newRule(this.mapping, { important });
180
213
  }
181
214
 
215
+ /** Hack for light-dark, which requires adding a new rule without changing the current rule */
182
216
  addExtraRule(rule: Partial<StyleRule>) {
183
217
  let extraRuleArray = extraRules.get(this.rule);
184
218
  if (!extraRuleArray) {
@@ -197,8 +231,8 @@ export class StylesheetBuilder {
197
231
  }
198
232
 
199
233
  addMediaQuery(condition: MediaCondition) {
200
- this.rule.m ??= [];
201
- this.rule.m.push(condition);
234
+ this.ruleTemplate.m ??= [];
235
+ this.ruleTemplate.m.push(condition);
202
236
  }
203
237
 
204
238
  addContainer(value: string[] | false) {
@@ -355,7 +389,8 @@ export class StylesheetBuilder {
355
389
  }
356
390
 
357
391
  for (const selector of selectorList) {
358
- const rule = this.cloneRule();
392
+ // We are going to be apply the current rule to n selectors, so we clone the rule
393
+ const rule = this.cloneRule(this.rule);
359
394
 
360
395
  if (selector.type === "className") {
361
396
  const {
@@ -431,16 +466,28 @@ export class StylesheetBuilder {
431
466
 
432
467
  for (const [name, value] of this.rule.v) {
433
468
  this.shared[type] ??= {};
434
- this.shared[type][name] ??= [undefined];
435
- this.shared[type][name][subtype === "light" ? 0 : 1] = value;
469
+ this.shared[type][name] ??= [];
470
+
471
+ const variableValue: VariableValue =
472
+ subtype === "light"
473
+ ? [value]
474
+ : [value, [["=", "prefers-color-scheme", "dark"]]];
475
+
476
+ // Append extra media queries if they exist
477
+ if (this.rule.m) {
478
+ variableValue[1] ??= [];
479
+ variableValue[1].push(...this.rule.m);
480
+ }
481
+
482
+ this.shared[type][name].push(variableValue);
436
483
  }
437
484
  }
438
485
  }
439
486
  }
440
487
 
441
488
  addContainerQuery(query: ContainerQuery) {
442
- this.rule.cq ??= [];
443
- this.rule.cq.push(query);
489
+ this.ruleTemplate.cq ??= [];
490
+ this.ruleTemplate.cq.push(query);
444
491
  }
445
492
 
446
493
  newAnimationFrames(name: string) {
package/src/jest/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Appearance, Dimensions } from "react-native";
2
2
 
3
+ import { inspect } from "node:util";
4
+
3
5
  import { compile, type CompilerOptions } from "../compiler";
4
6
  import { StyleCollection } from "../runtime/native/injection";
5
7
  import { colorScheme, dimensions, rem } from "../runtime/native/reactivity";
@@ -23,19 +25,41 @@ beforeEach(() => {
23
25
  colorScheme.set(null);
24
26
  });
25
27
 
28
+ const debugDefault = Boolean(
29
+ process.env.REACT_NATIVE_CSS_TEST_DEBUG &&
30
+ process.env.NODE_OPTIONS?.includes("--inspect"),
31
+ );
32
+
26
33
  export function registerCSS(
27
34
  css: string,
28
35
  {
29
- debugCompiled = process.env.NODE_OPTIONS?.includes("--inspect"),
36
+ debug = debugDefault,
30
37
  ...options
31
- }: CompilerOptions & { debugCompiled?: boolean } = {},
38
+ }: CompilerOptions & { debug?: boolean } = {},
32
39
  ) {
33
- const compiled = compile(css, options);
34
- if (debugCompiled) {
35
- console.log(`Compiled styles:\n\n${JSON.stringify({ compiled }, null, 2)}`);
40
+ const logger = debug
41
+ ? (text: string) => {
42
+ // Just log the rules
43
+ if (text.startsWith("[")) {
44
+ console.log(`Rules:\n---\n${text}`);
45
+ }
46
+ }
47
+ : undefined;
48
+
49
+ const compiled = compile(css, { ...options, logger });
50
+ if (debug) {
51
+ console.log(
52
+ `Compiled:\n---\n${inspect(
53
+ {
54
+ stylesheet: compiled.stylesheet(),
55
+ warnings: compiled.warnings(),
56
+ },
57
+ { depth: null, colors: true, compact: false },
58
+ )}`,
59
+ );
36
60
  }
37
61
 
38
- StyleCollection.inject(compiled);
62
+ StyleCollection.inject(compiled.stylesheet());
39
63
 
40
64
  return compiled;
41
65
  }
@@ -1,4 +1,7 @@
1
- throw new Error(`react-native-css has encountered a setup error.
1
+ const canWarn = process.env.NODE_ENV !== "test";
2
+
3
+ if (canWarn) {
4
+ throw new Error(`react-native-css has encountered a setup error.
2
5
 
3
6
  ┌─────-─┐
4
7
  | Metro |
@@ -28,5 +31,6 @@ If you are using NativeWind with the 'withNativeWind' function, follow the Metro
28
31
 
29
32
  If you are using another bundler (Vite, Webpack, etc), or non-Metro framework (Next.js, Remix, etc), please ensure you have included 'react-native-css/babel' as a babel preset.
30
33
  `);
34
+ }
31
35
 
32
36
  export {};
@@ -14,7 +14,7 @@ import {
14
14
  focusFamily,
15
15
  hoverFamily,
16
16
  type ContainerContextValue,
17
- type Effect,
17
+ type Getter,
18
18
  } from "../reactivity";
19
19
  import type { RenderGuard } from "./guards";
20
20
 
@@ -24,10 +24,10 @@ export function testContainerQueries(
24
24
  queries: ContainerQuery[],
25
25
  inheritedContainers: ContainerContextValue,
26
26
  guards: RenderGuard[],
27
- effect: Effect,
27
+ get: Getter,
28
28
  ) {
29
29
  return queries.every((query) => {
30
- return testContainerQuery(query, inheritedContainers, guards, effect);
30
+ return testContainerQuery(query, inheritedContainers, guards, get);
31
31
  });
32
32
  }
33
33
 
@@ -35,7 +35,7 @@ export function testContainerQuery(
35
35
  query: ContainerQuery,
36
36
  inheritedContainers: ContainerContextValue,
37
37
  guards: RenderGuard[],
38
- effect?: Effect,
38
+ get: Getter,
39
39
  ): boolean {
40
40
  const name = query.n ?? DEFAULT_CONTAINER_NAME;
41
41
  const container = inheritedContainers[name]!;
@@ -46,11 +46,11 @@ export function testContainerQuery(
46
46
  return false;
47
47
  }
48
48
 
49
- if (query.m && !testContainerMediaCondition(query.m, container, effect)) {
49
+ if (query.m && !testContainerMediaCondition(query.m, container, get)) {
50
50
  return false;
51
51
  }
52
52
 
53
- if (query.p && !testContainerPseudoCondition(query.p, container, effect)) {
53
+ if (query.p && !testContainerPseudoCondition(query.p, container, get)) {
54
54
  return false;
55
55
  }
56
56
 
@@ -60,15 +60,15 @@ export function testContainerQuery(
60
60
  function testContainerPseudoCondition(
61
61
  query: PseudoClassesQuery,
62
62
  containerKey: WeakKey,
63
- effect?: Effect,
63
+ get: Getter,
64
64
  ): boolean {
65
- if (query.h && !hoverFamily(containerKey).get(effect)) {
65
+ if (query.h && !get(hoverFamily(containerKey))) {
66
66
  return false;
67
67
  }
68
- if (query.a && !activeFamily(containerKey).get(effect)) {
68
+ if (query.a && !get(activeFamily(containerKey))) {
69
69
  return false;
70
70
  }
71
- if (query.f && !focusFamily(containerKey).get(effect)) {
71
+ if (query.f && !get(focusFamily(containerKey))) {
72
72
  return false;
73
73
  }
74
74
  return true;
@@ -77,18 +77,18 @@ function testContainerPseudoCondition(
77
77
  function testContainerMediaCondition(
78
78
  condition: MediaCondition,
79
79
  containerKey: WeakKey,
80
- effect?: Effect,
80
+ get: Getter,
81
81
  ): boolean {
82
82
  switch (condition[0]) {
83
83
  case "!":
84
- return !testContainerMediaCondition(condition[1], containerKey, effect);
84
+ return !testContainerMediaCondition(condition[1], containerKey, get);
85
85
  case "&":
86
86
  return condition[1].every((query) => {
87
- return testContainerMediaCondition(query, containerKey, effect);
87
+ return testContainerMediaCondition(query, containerKey, get);
88
88
  });
89
89
  case "|":
90
90
  return condition[1].some((query) => {
91
- return testContainerMediaCondition(query, containerKey, effect);
91
+ return testContainerMediaCondition(query, containerKey, get);
92
92
  });
93
93
  case "!!":
94
94
  return false;
@@ -99,7 +99,7 @@ function testContainerMediaCondition(
99
99
  case "<":
100
100
  case "<=":
101
101
  case "=": {
102
- const left = getContainerFeatureValue(condition[1], containerKey, effect);
102
+ const left = getContainerFeatureValue(condition[1], containerKey, get);
103
103
  const right = condition[2];
104
104
 
105
105
  if (condition[0] === "=") {
@@ -133,21 +133,21 @@ function testContainerMediaCondition(
133
133
  function getContainerFeatureValue(
134
134
  name: MediaFeatureNameFor_ContainerSizeFeatureId,
135
135
  containerKey: WeakKey,
136
- effect?: Effect,
136
+ get: Getter,
137
137
  ): StyleDescriptor {
138
138
  switch (name) {
139
139
  case "width":
140
- return containerWidthFamily(containerKey).get(effect);
140
+ return get(containerWidthFamily(containerKey));
141
141
  case "height":
142
- return containerHeightFamily(containerKey).get(effect);
142
+ return get(containerHeightFamily(containerKey));
143
143
  case "aspect-ratio": {
144
- const width = containerWidthFamily(containerKey).get(effect);
145
- const height = containerWidthFamily(containerKey).get(effect);
144
+ const width = get(containerWidthFamily(containerKey));
145
+ const height = get(containerHeightFamily(containerKey));
146
146
  return width / height;
147
147
  }
148
148
  case "orientation":
149
- const width = containerWidthFamily(containerKey).get(effect);
150
- const height = containerWidthFamily(containerKey).get(effect);
149
+ const width = get(containerWidthFamily(containerKey));
150
+ const height = get(containerHeightFamily(containerKey));
151
151
  return width > height ? "landscape" : "portrait";
152
152
  case "inline-size":
153
153
  case "block-size":
@@ -2,7 +2,6 @@
2
2
  import type { ComponentState } from "../react/useNativeCss";
3
3
  import type {
4
4
  ContainerContextValue,
5
- Effect,
6
5
  VariableContextValue,
7
6
  } from "../reactivity";
8
7
 
@@ -10,7 +9,7 @@ export type RenderGuard =
10
9
  | ["a", string, any]
11
10
  | ["d", string, any]
12
11
  | ["v", string, any]
13
- | ["c", string, Effect];
12
+ | ["c", string, WeakKey];
14
13
 
15
14
  export function testGuards(
16
15
  state: ComponentState,
@@ -10,7 +10,7 @@ import {
10
10
  focusFamily,
11
11
  hoverFamily,
12
12
  type ContainerContextValue,
13
- type Effect,
13
+ type Getter,
14
14
  } from "../reactivity";
15
15
  import { testContainerQueries } from "./container-query";
16
16
  import type { RenderGuard } from "./guards";
@@ -18,15 +18,15 @@ import { testMediaQuery } from "./media-query";
18
18
 
19
19
  export function testRule(
20
20
  rule: StyleRule,
21
- effect: Effect,
21
+ get: Getter,
22
22
  props: Props,
23
23
  guards: RenderGuard[],
24
24
  containerContext: ContainerContextValue,
25
25
  ) {
26
- if (rule.p && !pseudoClasses(rule.p, effect)) {
26
+ if (rule.p && !pseudoClasses(rule.p, get)) {
27
27
  return false;
28
28
  }
29
- if (rule.m && !testMediaQuery(rule.m, effect)) {
29
+ if (rule.m && !testMediaQuery(rule.m, get)) {
30
30
  return false;
31
31
  }
32
32
  if (rule.aq && !attributes(rule.aq, props, guards)) {
@@ -34,7 +34,7 @@ export function testRule(
34
34
  }
35
35
  if (
36
36
  rule.cq &&
37
- !testContainerQueries(rule.cq, containerContext, guards, effect)
37
+ !testContainerQueries(rule.cq, containerContext, guards, get)
38
38
  ) {
39
39
  return false;
40
40
  }
@@ -42,14 +42,14 @@ export function testRule(
42
42
  return true;
43
43
  }
44
44
 
45
- function pseudoClasses(query: PseudoClassesQuery, effect: Effect) {
46
- if (query.h && !hoverFamily(effect).get(effect)) {
45
+ function pseudoClasses(query: PseudoClassesQuery, get: Getter) {
46
+ if (query.h && !get(hoverFamily(get))) {
47
47
  return false;
48
48
  }
49
- if (query.a && !activeFamily(effect).get(effect)) {
49
+ if (query.a && !get(activeFamily(get))) {
50
50
  return false;
51
51
  }
52
- if (query.f && !focusFamily(effect).get(effect)) {
52
+ if (query.f && !get(focusFamily(get))) {
53
53
  return false;
54
54
  }
55
55
  return true;
@@ -2,38 +2,38 @@
2
2
  import { PixelRatio, Platform } from "react-native";
3
3
 
4
4
  import type { MediaCondition } from "../../../compiler";
5
- import { colorScheme, vh, vw, type Effect } from "../reactivity";
5
+ import { colorScheme, vh, vw, type Getter } from "../reactivity";
6
6
 
7
- export function testMediaQuery(mediaQueries: MediaCondition[], effect: Effect) {
8
- return mediaQueries.every((query) => test(query, effect));
7
+ export function testMediaQuery(mediaQueries: MediaCondition[], get: Getter) {
8
+ return mediaQueries.every((query) => test(query, get));
9
9
  }
10
10
 
11
- function test(mediaQuery: MediaCondition, effect: Effect): Boolean {
11
+ function test(mediaQuery: MediaCondition, get: Getter): Boolean {
12
12
  switch (mediaQuery[0]) {
13
13
  case "[]":
14
14
  case "!!":
15
15
  return false;
16
16
  case "!":
17
- return !test(mediaQuery[1], effect);
17
+ return !test(mediaQuery[1], get);
18
18
  case "&":
19
19
  return mediaQuery[1].every((query) => {
20
- return test(query, effect);
20
+ return test(query, get);
21
21
  });
22
22
  case "|":
23
23
  return mediaQuery[1].some((query) => {
24
- return test(query, effect);
24
+ return test(query, get);
25
25
  });
26
26
  case ">":
27
27
  case ">=":
28
28
  case "<":
29
29
  case "<=":
30
30
  case "=": {
31
- return testComparison(mediaQuery, effect);
31
+ return testComparison(mediaQuery, get);
32
32
  }
33
33
  }
34
34
  }
35
35
 
36
- function testComparison(mediaQuery: MediaCondition, effect: Effect): Boolean {
36
+ function testComparison(mediaQuery: MediaCondition, get: Getter): Boolean {
37
37
  let left: number | undefined;
38
38
  const right = mediaQuery[2];
39
39
 
@@ -41,22 +41,20 @@ function testComparison(mediaQuery: MediaCondition, effect: Effect): Boolean {
41
41
  case "platform":
42
42
  return right === Platform.OS;
43
43
  case "prefers-color-scheme": {
44
- return right === colorScheme.get(effect);
44
+ return right === get(colorScheme);
45
45
  }
46
46
  case "display-mode":
47
47
  return right === "native" || Platform.OS === right;
48
48
  case "min-width":
49
- return typeof right === "number" && vw.get(effect) >= right;
49
+ return typeof right === "number" && get(vw) >= right;
50
50
  case "max-width":
51
- return typeof right === "number" && vw.get(effect) <= right;
51
+ return typeof right === "number" && get(vw) <= right;
52
52
  case "min-height":
53
- return typeof right === "number" && vh.get(effect) >= right;
53
+ return typeof right === "number" && get(vh) >= right;
54
54
  case "max-height":
55
- return typeof right === "number" && vh.get(effect) <= right;
55
+ return typeof right === "number" && get(vh) <= right;
56
56
  case "orientation":
57
- return right === "landscape"
58
- ? vh.get(effect) < vw.get(effect)
59
- : vh.get(effect) >= vw.get(effect);
57
+ return right === "landscape" ? get(vh) < get(vw) : get(vh) >= get(vw);
60
58
  }
61
59
 
62
60
  if (typeof right !== "number") {
@@ -65,10 +63,10 @@ function testComparison(mediaQuery: MediaCondition, effect: Effect): Boolean {
65
63
 
66
64
  switch (mediaQuery[1]) {
67
65
  case "width":
68
- left = vw.get(effect);
66
+ left = get(vw);
69
67
  break;
70
68
  case "height":
71
- left = vh.get(effect);
69
+ left = get(vh);
72
70
  break;
73
71
  case "resolution":
74
72
  left = PixelRatio.get();
@@ -6,11 +6,11 @@ import {
6
6
  containerLayoutFamily,
7
7
  focusFamily,
8
8
  hoverFamily,
9
- type Effect,
9
+ type Getter as WeakKey,
10
10
  } from "../reactivity";
11
11
 
12
12
  const mainCache = new WeakMap<
13
- Effect,
13
+ WeakKey,
14
14
  WeakMap<Function, (event: any) => void>
15
15
  >();
16
16
 
@@ -38,14 +38,14 @@ const defaultHandlers: Record<InteractionType, Handler> = {
38
38
  };
39
39
 
40
40
  export function getInteractionHandler(
41
- effect: Effect,
41
+ weakKey: WeakKey,
42
42
  type: InteractionType,
43
43
  handler = defaultHandlers[type],
44
44
  ) {
45
- let cache = mainCache.get(effect);
45
+ let cache = mainCache.get(weakKey);
46
46
  if (!cache) {
47
47
  cache = new WeakMap();
48
- mainCache.set(effect, cache);
48
+ mainCache.set(weakKey, cache);
49
49
  }
50
50
 
51
51
  let cached = cache.get(handler);
@@ -57,29 +57,29 @@ export function getInteractionHandler(
57
57
 
58
58
  switch (type) {
59
59
  case "onLayout":
60
- containerLayoutFamily(effect).set(
60
+ containerLayoutFamily(weakKey).set(
61
61
  (event as LayoutChangeEvent).nativeEvent.layout,
62
62
  );
63
63
  break;
64
64
  case "onHoverIn":
65
- hoverFamily(effect).set(true);
65
+ hoverFamily(weakKey).set(true);
66
66
  break;
67
67
  case "onHoverOut":
68
- hoverFamily(effect).set(false);
68
+ hoverFamily(weakKey).set(false);
69
69
  break;
70
70
  case "onPress":
71
71
  break;
72
72
  case "onPressIn":
73
- activeFamily(effect).set(true);
73
+ activeFamily(weakKey).set(true);
74
74
  break;
75
75
  case "onPressOut":
76
- activeFamily(effect).set(false);
76
+ activeFamily(weakKey).set(false);
77
77
  break;
78
78
  case "onFocus":
79
- focusFamily(effect).set(true);
79
+ focusFamily(weakKey).set(true);
80
80
  break;
81
81
  case "onBlur":
82
- focusFamily(effect).set(false);
82
+ focusFamily(weakKey).set(false);
83
83
  break;
84
84
  }
85
85
  };
@@ -104,7 +104,7 @@ export function updateRules(
104
104
  if (
105
105
  !testRule(
106
106
  rule,
107
- state.ruleEffect,
107
+ state.ruleEffectGetter,
108
108
  currentProps,
109
109
  guards,
110
110
  inheritedContainers,
@@ -132,20 +132,20 @@ export function updateRules(
132
132
  containers = {
133
133
  ...inheritedContainers,
134
134
  // This container becomes the default container
135
- [DEFAULT_CONTAINER_NAME]: state.ruleEffect,
135
+ [DEFAULT_CONTAINER_NAME]: state.ruleEffectGetter,
136
136
  };
137
137
  }
138
138
 
139
139
  // This this component as the named container
140
140
  for (const name of rule.c) {
141
- containers![name] = state.ruleEffect;
141
+ containers![name] = state.ruleEffectGetter;
142
142
  }
143
143
 
144
144
  // Enable hover/active/focus/layout handlers
145
- hoverFamily(state.ruleEffect);
146
- activeFamily(state.ruleEffect);
147
- focusFamily(state.ruleEffect);
148
- containerLayoutFamily(state.ruleEffect);
145
+ hoverFamily(state.ruleEffectGetter);
146
+ activeFamily(state.ruleEffectGetter);
147
+ focusFamily(state.ruleEffectGetter);
148
+ containerLayoutFamily(state.ruleEffectGetter);
149
149
  }
150
150
 
151
151
  if (rule.a) {
@@ -163,7 +163,7 @@ export function updateRules(
163
163
 
164
164
  if (process.env.NODE_ENV !== "production") {
165
165
  if (isRerender) {
166
- let pressable = activeFamily.has(state.ruleEffect);
166
+ let pressable = activeFamily.has(state.ruleEffectGetter);
167
167
 
168
168
  if (Boolean(variables) !== Boolean(state.variables)) {
169
169
  console.log(
@@ -190,7 +190,7 @@ export function updateRules(
190
190
  let pressable =
191
191
  process.env.NODE_ENV === "production"
192
192
  ? undefined
193
- : activeFamily.has(state.ruleEffect);
193
+ : activeFamily.has(state.ruleEffectGetter);
194
194
 
195
195
  if (!rules.size && !state.stylesObs && !inlineVariables.size) {
196
196
  return {