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.
- package/dist/commonjs/compiler/attributes.test.js +1 -1
- package/dist/commonjs/compiler/attributes.test.js.map +1 -1
- package/dist/commonjs/compiler/compiler.js +25 -14
- package/dist/commonjs/compiler/compiler.js.map +1 -1
- package/dist/commonjs/compiler/declarations.js +31 -7
- package/dist/commonjs/compiler/declarations.js.map +1 -1
- package/dist/commonjs/compiler/inheritance.test.js +3 -3
- package/dist/commonjs/compiler/inheritance.test.js.map +1 -1
- package/dist/commonjs/compiler/stylesheet.js +53 -19
- package/dist/commonjs/compiler/stylesheet.js.map +1 -1
- package/dist/commonjs/jest/index.js +23 -7
- package/dist/commonjs/jest/index.js.map +1 -1
- package/dist/commonjs/poison.pill.js +4 -1
- package/dist/commonjs/poison.pill.js.map +1 -1
- package/dist/commonjs/runtime/native/conditions/container-query.js +21 -21
- package/dist/commonjs/runtime/native/conditions/container-query.js.map +1 -1
- package/dist/commonjs/runtime/native/conditions/guards.js.map +1 -1
- package/dist/commonjs/runtime/native/conditions/index.js +8 -8
- package/dist/commonjs/runtime/native/conditions/index.js.map +1 -1
- package/dist/commonjs/runtime/native/conditions/media-query.js +16 -16
- package/dist/commonjs/runtime/native/conditions/media-query.js.map +1 -1
- package/dist/commonjs/runtime/native/react/interaction.js +10 -10
- package/dist/commonjs/runtime/native/react/interaction.js.map +1 -1
- package/dist/commonjs/runtime/native/react/rules.js +9 -9
- package/dist/commonjs/runtime/native/react/rules.js.map +1 -1
- package/dist/commonjs/runtime/native/react/useNativeCss.js +1 -0
- package/dist/commonjs/runtime/native/react/useNativeCss.js.map +1 -1
- package/dist/commonjs/runtime/native/reactivity.js +15 -6
- package/dist/commonjs/runtime/native/reactivity.js.map +1 -1
- package/dist/commonjs/runtime/native/styles/index.js +12 -12
- package/dist/commonjs/runtime/native/styles/index.js.map +1 -1
- package/dist/module/compiler/attributes.test.js +1 -1
- package/dist/module/compiler/attributes.test.js.map +1 -1
- package/dist/module/compiler/compiler.js +25 -14
- package/dist/module/compiler/compiler.js.map +1 -1
- package/dist/module/compiler/compiler.types.js.map +1 -1
- package/dist/module/compiler/declarations.js +30 -7
- package/dist/module/compiler/declarations.js.map +1 -1
- package/dist/module/compiler/inheritance.test.js +3 -3
- package/dist/module/compiler/inheritance.test.js.map +1 -1
- package/dist/module/compiler/stylesheet.js +53 -19
- package/dist/module/compiler/stylesheet.js.map +1 -1
- package/dist/module/jest/index.js +23 -7
- package/dist/module/jest/index.js.map +1 -1
- package/dist/module/poison.pill.js +4 -1
- package/dist/module/poison.pill.js.map +1 -1
- package/dist/module/runtime/native/conditions/container-query.js +21 -21
- package/dist/module/runtime/native/conditions/container-query.js.map +1 -1
- package/dist/module/runtime/native/conditions/guards.js.map +1 -1
- package/dist/module/runtime/native/conditions/index.js +8 -8
- package/dist/module/runtime/native/conditions/index.js.map +1 -1
- package/dist/module/runtime/native/conditions/media-query.js +16 -16
- package/dist/module/runtime/native/conditions/media-query.js.map +1 -1
- package/dist/module/runtime/native/react/interaction.js +10 -10
- package/dist/module/runtime/native/react/interaction.js.map +1 -1
- package/dist/module/runtime/native/react/rules.js +9 -9
- package/dist/module/runtime/native/react/rules.js.map +1 -1
- package/dist/module/runtime/native/react/useNativeCss.js +1 -0
- package/dist/module/runtime/native/react/useNativeCss.js.map +1 -1
- package/dist/module/runtime/native/reactivity.js +15 -6
- package/dist/module/runtime/native/reactivity.js.map +1 -1
- package/dist/module/runtime/native/styles/index.js +12 -12
- package/dist/module/runtime/native/styles/index.js.map +1 -1
- package/dist/typescript/commonjs/src/compiler/compiler.d.ts +9 -2
- package/dist/typescript/commonjs/src/compiler/compiler.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/compiler.types.d.ts +5 -4
- package/dist/typescript/commonjs/src/compiler/compiler.types.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/declarations.d.ts +2 -1
- package/dist/typescript/commonjs/src/compiler/declarations.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts +12 -2
- package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/jest/index.d.ts +10 -3
- package/dist/typescript/commonjs/src/jest/index.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/poison.pill.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/conditions/container-query.d.ts +3 -3
- package/dist/typescript/commonjs/src/runtime/native/conditions/container-query.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/conditions/guards.d.ts +2 -2
- package/dist/typescript/commonjs/src/runtime/native/conditions/guards.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/conditions/index.d.ts +2 -2
- package/dist/typescript/commonjs/src/runtime/native/conditions/index.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/conditions/media-query.d.ts +2 -2
- package/dist/typescript/commonjs/src/runtime/native/conditions/media-query.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/react/interaction.d.ts +2 -2
- package/dist/typescript/commonjs/src/runtime/native/react/interaction.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/react/useNativeCss.d.ts +2 -1
- package/dist/typescript/commonjs/src/runtime/native/react/useNativeCss.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/reactivity.d.ts +4 -4
- package/dist/typescript/commonjs/src/runtime/native/reactivity.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/compiler.d.ts +9 -2
- package/dist/typescript/module/src/compiler/compiler.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/compiler.types.d.ts +5 -4
- package/dist/typescript/module/src/compiler/compiler.types.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/declarations.d.ts +2 -1
- package/dist/typescript/module/src/compiler/declarations.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/stylesheet.d.ts +12 -2
- package/dist/typescript/module/src/compiler/stylesheet.d.ts.map +1 -1
- package/dist/typescript/module/src/jest/index.d.ts +10 -3
- package/dist/typescript/module/src/jest/index.d.ts.map +1 -1
- package/dist/typescript/module/src/poison.pill.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/conditions/container-query.d.ts +3 -3
- package/dist/typescript/module/src/runtime/native/conditions/container-query.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/conditions/guards.d.ts +2 -2
- package/dist/typescript/module/src/runtime/native/conditions/guards.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/conditions/index.d.ts +2 -2
- package/dist/typescript/module/src/runtime/native/conditions/index.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/conditions/media-query.d.ts +2 -2
- package/dist/typescript/module/src/runtime/native/conditions/media-query.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/react/interaction.d.ts +2 -2
- package/dist/typescript/module/src/runtime/native/react/interaction.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/react/useNativeCss.d.ts +2 -1
- package/dist/typescript/module/src/runtime/native/react/useNativeCss.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/reactivity.d.ts +4 -4
- package/dist/typescript/module/src/runtime/native/reactivity.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/compiler/attributes.test.ts +1 -1
- package/src/compiler/compiler.ts +29 -24
- package/src/compiler/compiler.types.ts +7 -5
- package/src/compiler/declarations.ts +52 -8
- package/src/compiler/inheritance.test.ts +3 -3
- package/src/compiler/stylesheet.ts +67 -20
- package/src/jest/index.ts +30 -6
- package/src/poison.pill.ts +5 -1
- package/src/runtime/native/conditions/container-query.ts +22 -22
- package/src/runtime/native/conditions/guards.ts +1 -2
- package/src/runtime/native/conditions/index.ts +9 -9
- package/src/runtime/native/conditions/media-query.ts +17 -19
- package/src/runtime/native/react/interaction.ts +12 -12
- package/src/runtime/native/react/rules.ts +9 -9
- package/src/runtime/native/react/useNativeCss.ts +3 -0
- package/src/runtime/native/reactivity.ts +22 -13
- 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
|
-
|
|
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.
|
|
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
|
-
|
|
160
|
-
|
|
176
|
+
type: "property" | "value" | "function",
|
|
177
|
+
property: string,
|
|
178
|
+
value?: unknown,
|
|
161
179
|
): void {
|
|
162
|
-
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
this.
|
|
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.
|
|
201
|
-
this.
|
|
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
|
-
|
|
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] ??= [
|
|
435
|
-
|
|
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.
|
|
443
|
-
this.
|
|
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
|
-
|
|
36
|
+
debug = debugDefault,
|
|
30
37
|
...options
|
|
31
|
-
}: CompilerOptions & {
|
|
38
|
+
}: CompilerOptions & { debug?: boolean } = {},
|
|
32
39
|
) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
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
|
}
|
package/src/poison.pill.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
-
|
|
27
|
+
get: Getter,
|
|
28
28
|
) {
|
|
29
29
|
return queries.every((query) => {
|
|
30
|
-
return testContainerQuery(query, inheritedContainers, guards,
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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
|
-
|
|
63
|
+
get: Getter,
|
|
64
64
|
): boolean {
|
|
65
|
-
if (query.h && !hoverFamily(containerKey)
|
|
65
|
+
if (query.h && !get(hoverFamily(containerKey))) {
|
|
66
66
|
return false;
|
|
67
67
|
}
|
|
68
|
-
if (query.a && !activeFamily(containerKey)
|
|
68
|
+
if (query.a && !get(activeFamily(containerKey))) {
|
|
69
69
|
return false;
|
|
70
70
|
}
|
|
71
|
-
if (query.f && !focusFamily(containerKey)
|
|
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
|
-
|
|
80
|
+
get: Getter,
|
|
81
81
|
): boolean {
|
|
82
82
|
switch (condition[0]) {
|
|
83
83
|
case "!":
|
|
84
|
-
return !testContainerMediaCondition(condition[1], containerKey,
|
|
84
|
+
return !testContainerMediaCondition(condition[1], containerKey, get);
|
|
85
85
|
case "&":
|
|
86
86
|
return condition[1].every((query) => {
|
|
87
|
-
return testContainerMediaCondition(query, containerKey,
|
|
87
|
+
return testContainerMediaCondition(query, containerKey, get);
|
|
88
88
|
});
|
|
89
89
|
case "|":
|
|
90
90
|
return condition[1].some((query) => {
|
|
91
|
-
return testContainerMediaCondition(query, containerKey,
|
|
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,
|
|
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
|
-
|
|
136
|
+
get: Getter,
|
|
137
137
|
): StyleDescriptor {
|
|
138
138
|
switch (name) {
|
|
139
139
|
case "width":
|
|
140
|
-
return containerWidthFamily(containerKey)
|
|
140
|
+
return get(containerWidthFamily(containerKey));
|
|
141
141
|
case "height":
|
|
142
|
-
return containerHeightFamily(containerKey)
|
|
142
|
+
return get(containerHeightFamily(containerKey));
|
|
143
143
|
case "aspect-ratio": {
|
|
144
|
-
const width = containerWidthFamily(containerKey)
|
|
145
|
-
const height =
|
|
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)
|
|
150
|
-
const height =
|
|
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,
|
|
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
|
|
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
|
-
|
|
21
|
+
get: Getter,
|
|
22
22
|
props: Props,
|
|
23
23
|
guards: RenderGuard[],
|
|
24
24
|
containerContext: ContainerContextValue,
|
|
25
25
|
) {
|
|
26
|
-
if (rule.p && !pseudoClasses(rule.p,
|
|
26
|
+
if (rule.p && !pseudoClasses(rule.p, get)) {
|
|
27
27
|
return false;
|
|
28
28
|
}
|
|
29
|
-
if (rule.m && !testMediaQuery(rule.m,
|
|
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,
|
|
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,
|
|
46
|
-
if (query.h && !hoverFamily(
|
|
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(
|
|
49
|
+
if (query.a && !get(activeFamily(get))) {
|
|
50
50
|
return false;
|
|
51
51
|
}
|
|
52
|
-
if (query.f && !focusFamily(
|
|
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
|
|
5
|
+
import { colorScheme, vh, vw, type Getter } from "../reactivity";
|
|
6
6
|
|
|
7
|
-
export function testMediaQuery(mediaQueries: MediaCondition[],
|
|
8
|
-
return mediaQueries.every((query) => test(query,
|
|
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,
|
|
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],
|
|
17
|
+
return !test(mediaQuery[1], get);
|
|
18
18
|
case "&":
|
|
19
19
|
return mediaQuery[1].every((query) => {
|
|
20
|
-
return test(query,
|
|
20
|
+
return test(query, get);
|
|
21
21
|
});
|
|
22
22
|
case "|":
|
|
23
23
|
return mediaQuery[1].some((query) => {
|
|
24
|
-
return test(query,
|
|
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,
|
|
31
|
+
return testComparison(mediaQuery, get);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
function testComparison(mediaQuery: MediaCondition,
|
|
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 ===
|
|
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" &&
|
|
49
|
+
return typeof right === "number" && get(vw) >= right;
|
|
50
50
|
case "max-width":
|
|
51
|
-
return typeof right === "number" &&
|
|
51
|
+
return typeof right === "number" && get(vw) <= right;
|
|
52
52
|
case "min-height":
|
|
53
|
-
return typeof right === "number" &&
|
|
53
|
+
return typeof right === "number" && get(vh) >= right;
|
|
54
54
|
case "max-height":
|
|
55
|
-
return typeof right === "number" &&
|
|
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 =
|
|
66
|
+
left = get(vw);
|
|
69
67
|
break;
|
|
70
68
|
case "height":
|
|
71
|
-
left =
|
|
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
|
|
9
|
+
type Getter as WeakKey,
|
|
10
10
|
} from "../reactivity";
|
|
11
11
|
|
|
12
12
|
const mainCache = new WeakMap<
|
|
13
|
-
|
|
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
|
-
|
|
41
|
+
weakKey: WeakKey,
|
|
42
42
|
type: InteractionType,
|
|
43
43
|
handler = defaultHandlers[type],
|
|
44
44
|
) {
|
|
45
|
-
let cache = mainCache.get(
|
|
45
|
+
let cache = mainCache.get(weakKey);
|
|
46
46
|
if (!cache) {
|
|
47
47
|
cache = new WeakMap();
|
|
48
|
-
mainCache.set(
|
|
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(
|
|
60
|
+
containerLayoutFamily(weakKey).set(
|
|
61
61
|
(event as LayoutChangeEvent).nativeEvent.layout,
|
|
62
62
|
);
|
|
63
63
|
break;
|
|
64
64
|
case "onHoverIn":
|
|
65
|
-
hoverFamily(
|
|
65
|
+
hoverFamily(weakKey).set(true);
|
|
66
66
|
break;
|
|
67
67
|
case "onHoverOut":
|
|
68
|
-
hoverFamily(
|
|
68
|
+
hoverFamily(weakKey).set(false);
|
|
69
69
|
break;
|
|
70
70
|
case "onPress":
|
|
71
71
|
break;
|
|
72
72
|
case "onPressIn":
|
|
73
|
-
activeFamily(
|
|
73
|
+
activeFamily(weakKey).set(true);
|
|
74
74
|
break;
|
|
75
75
|
case "onPressOut":
|
|
76
|
-
activeFamily(
|
|
76
|
+
activeFamily(weakKey).set(false);
|
|
77
77
|
break;
|
|
78
78
|
case "onFocus":
|
|
79
|
-
focusFamily(
|
|
79
|
+
focusFamily(weakKey).set(true);
|
|
80
80
|
break;
|
|
81
81
|
case "onBlur":
|
|
82
|
-
focusFamily(
|
|
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.
|
|
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.
|
|
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.
|
|
141
|
+
containers![name] = state.ruleEffectGetter;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
// Enable hover/active/focus/layout handlers
|
|
145
|
-
hoverFamily(state.
|
|
146
|
-
activeFamily(state.
|
|
147
|
-
focusFamily(state.
|
|
148
|
-
containerLayoutFamily(state.
|
|
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.
|
|
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.
|
|
193
|
+
: activeFamily.has(state.ruleEffectGetter);
|
|
194
194
|
|
|
195
195
|
if (!rules.size && !state.stylesObs && !inlineVariables.size) {
|
|
196
196
|
return {
|