react-native-css 3.0.0-nightly.75f8b74 → 3.0.0-nightly.fa5e95b
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/atRules.js +1 -1
- 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 +40 -11
- 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 +87 -29
- package/dist/commonjs/compiler/stylesheet.js.map +1 -1
- package/dist/commonjs/jest/index.js +16 -5
- 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 +17 -17
- 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/calculate-props.js +53 -48
- package/dist/commonjs/runtime/native/styles/calculate-props.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/commonjs/runtime/native/styles/units.js +6 -3
- package/dist/commonjs/runtime/native/styles/units.js.map +1 -1
- package/dist/module/compiler/atRules.js +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 +39 -11
- 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 +87 -29
- package/dist/module/compiler/stylesheet.js.map +1 -1
- package/dist/module/jest/index.js +16 -4
- 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 +17 -17
- 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/calculate-props.js +53 -48
- package/dist/module/runtime/native/styles/calculate-props.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/module/runtime/native/styles/units.js +6 -3
- package/dist/module/runtime/native/styles/units.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 +16 -2
- package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/jest/index.d.ts +8 -1
- 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/commonjs/src/runtime/native/styles/calculate-props.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/styles/units.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 +16 -2
- package/dist/typescript/module/src/compiler/stylesheet.d.ts.map +1 -1
- package/dist/typescript/module/src/jest/index.d.ts +8 -1
- 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/dist/typescript/module/src/runtime/native/styles/calculate-props.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/styles/units.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/compiler/atRules.ts +1 -1
- 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 +59 -13
- package/src/compiler/inheritance.test.ts +3 -3
- package/src/compiler/stylesheet.ts +113 -32
- package/src/jest/index.ts +19 -4
- 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 +18 -20
- 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/calculate-props.ts +59 -49
- package/src/runtime/native/styles/index.ts +12 -12
- package/src/runtime/native/styles/units.ts +7 -3
|
@@ -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,18 @@ export class StylesheetBuilder {
|
|
|
56
57
|
animations?: AnimationRecord;
|
|
57
58
|
rem: number;
|
|
58
59
|
ruleOrder: number;
|
|
59
|
-
|
|
60
|
+
warningProperty?: string;
|
|
61
|
+
warningProperties: string[];
|
|
62
|
+
warningValues: Record<string, unknown[]>;
|
|
63
|
+
warningFunctions: string[];
|
|
64
|
+
} = {
|
|
65
|
+
ruleSets: {},
|
|
66
|
+
rem: 14,
|
|
67
|
+
ruleOrder: 0,
|
|
68
|
+
warningProperties: [],
|
|
69
|
+
warningValues: {},
|
|
70
|
+
warningFunctions: [],
|
|
71
|
+
},
|
|
60
72
|
private selectors?: NormalizeSelector[],
|
|
61
73
|
) {}
|
|
62
74
|
|
|
@@ -76,7 +88,7 @@ export class StylesheetBuilder {
|
|
|
76
88
|
);
|
|
77
89
|
}
|
|
78
90
|
|
|
79
|
-
cloneRule({ ...rule } = this.
|
|
91
|
+
cloneRule({ ...rule } = this.ruleTemplate): StyleRule {
|
|
80
92
|
rule.s = [...rule.s];
|
|
81
93
|
rule.aq &&= [...rule.aq];
|
|
82
94
|
rule.c &&= [...rule.c];
|
|
@@ -128,11 +140,17 @@ export class StylesheetBuilder {
|
|
|
128
140
|
}
|
|
129
141
|
|
|
130
142
|
if (this.shared.rootVariables) {
|
|
131
|
-
stylesheetOptions.vr = Object.entries(this.shared.rootVariables)
|
|
143
|
+
stylesheetOptions.vr = Object.entries(this.shared.rootVariables).map(
|
|
144
|
+
// Reverse these so the most specific variables are first
|
|
145
|
+
([key, value]) => [key, value.reverse()] as const,
|
|
146
|
+
);
|
|
132
147
|
}
|
|
133
148
|
|
|
134
149
|
if (this.shared.universalVariables) {
|
|
135
|
-
stylesheetOptions.vu = Object.entries(this.shared.universalVariables)
|
|
150
|
+
stylesheetOptions.vu = Object.entries(this.shared.universalVariables).map(
|
|
151
|
+
// Reverse these so the most specific variables are first
|
|
152
|
+
([key, value]) => [key, value.reverse()] as const,
|
|
153
|
+
);
|
|
136
154
|
}
|
|
137
155
|
|
|
138
156
|
if (this.shared.animations) {
|
|
@@ -155,11 +173,64 @@ export class StylesheetBuilder {
|
|
|
155
173
|
);
|
|
156
174
|
}
|
|
157
175
|
|
|
176
|
+
setWarningProperty(property: string) {
|
|
177
|
+
this.shared.warningProperty = property;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
addWarning(type: "property" | "value", property: string): void;
|
|
181
|
+
addWarning(type: "style", property: string, value: unknown): void;
|
|
158
182
|
addWarning(
|
|
159
|
-
|
|
160
|
-
|
|
183
|
+
type: "property" | "style" | "value",
|
|
184
|
+
property: string,
|
|
185
|
+
value?: unknown,
|
|
161
186
|
): void {
|
|
162
|
-
|
|
187
|
+
switch (type) {
|
|
188
|
+
case "property":
|
|
189
|
+
this.shared.warningProperties.push(property);
|
|
190
|
+
break;
|
|
191
|
+
case "value": {
|
|
192
|
+
value = property;
|
|
193
|
+
property = this.shared.warningProperty ?? "";
|
|
194
|
+
|
|
195
|
+
if (!property) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
this.shared.warningValues[property] ??= [];
|
|
200
|
+
this.shared.warningValues[property]?.push(value);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
case "style":
|
|
204
|
+
this.shared.warningValues[property] ??= [];
|
|
205
|
+
this.shared.warningValues[property]?.push(value);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
getWarnings() {
|
|
211
|
+
const result: {
|
|
212
|
+
properties?: string[];
|
|
213
|
+
values?: Record<string, unknown[]>;
|
|
214
|
+
functions?: string[];
|
|
215
|
+
} = {};
|
|
216
|
+
|
|
217
|
+
if (this.shared.warningProperties.length) {
|
|
218
|
+
result.properties = this.shared.warningProperties;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (Object.keys(this.shared.warningValues).length) {
|
|
222
|
+
result.values = this.shared.warningValues;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (this.shared.warningFunctions.length) {
|
|
226
|
+
result.functions = this.shared.warningFunctions;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
addMapping(mapping: StyleRuleMapping) {
|
|
233
|
+
this.mapping = { ...this.mapping, ...mapping };
|
|
163
234
|
}
|
|
164
235
|
|
|
165
236
|
newRule(mapping = this.mapping, { important = false } = {}) {
|
|
@@ -171,14 +242,12 @@ export class StylesheetBuilder {
|
|
|
171
242
|
}
|
|
172
243
|
}
|
|
173
244
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
this.
|
|
177
|
-
if (important) {
|
|
178
|
-
this.rule.s[Specificity.Important] = 1;
|
|
179
|
-
}
|
|
245
|
+
/** Used by nested declarations (for example @media inside a RuleSet) */
|
|
246
|
+
newNestedRule({ important = false } = {}) {
|
|
247
|
+
this.newRule(this.mapping, { important });
|
|
180
248
|
}
|
|
181
249
|
|
|
250
|
+
/** Hack for light-dark, which requires adding a new rule without changing the current rule */
|
|
182
251
|
addExtraRule(rule: Partial<StyleRule>) {
|
|
183
252
|
let extraRuleArray = extraRules.get(this.rule);
|
|
184
253
|
if (!extraRuleArray) {
|
|
@@ -197,8 +266,8 @@ export class StylesheetBuilder {
|
|
|
197
266
|
}
|
|
198
267
|
|
|
199
268
|
addMediaQuery(condition: MediaCondition) {
|
|
200
|
-
this.
|
|
201
|
-
this.
|
|
269
|
+
this.ruleTemplate.m ??= [];
|
|
270
|
+
this.ruleTemplate.m.push(condition);
|
|
202
271
|
}
|
|
203
272
|
|
|
204
273
|
addContainer(value: string[] | false) {
|
|
@@ -297,30 +366,29 @@ export class StylesheetBuilder {
|
|
|
297
366
|
}
|
|
298
367
|
|
|
299
368
|
private pushDescriptor(
|
|
300
|
-
|
|
369
|
+
rawProperty: string,
|
|
301
370
|
value: StyleDescriptor,
|
|
302
371
|
declarations: StyleDeclaration[],
|
|
303
372
|
forceTuple = false,
|
|
304
373
|
delayed = false,
|
|
305
374
|
) {
|
|
306
|
-
property = toRNProperty(
|
|
375
|
+
const property = toRNProperty(rawProperty);
|
|
307
376
|
|
|
308
|
-
let propPath: string | string[] =
|
|
309
|
-
this.mapping[property] ?? this.mapping["*"]
|
|
377
|
+
let propPath: string | string[] | undefined =
|
|
378
|
+
this.mapping[rawProperty] ?? this.mapping[property] ?? this.mapping["*"];
|
|
310
379
|
|
|
311
380
|
if (Array.isArray(propPath)) {
|
|
312
|
-
const first = propPath
|
|
381
|
+
const [first, second] = propPath;
|
|
313
382
|
|
|
314
|
-
if (
|
|
315
|
-
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if (propPath.length === 1) {
|
|
320
|
-
propPath = first;
|
|
383
|
+
if (propPath.length === 2 && first === "*" && second) {
|
|
384
|
+
propPath = second;
|
|
321
385
|
} else {
|
|
322
386
|
forceTuple = true;
|
|
323
387
|
}
|
|
388
|
+
} else if (propPath) {
|
|
389
|
+
forceTuple = true;
|
|
390
|
+
} else {
|
|
391
|
+
propPath = property;
|
|
324
392
|
}
|
|
325
393
|
|
|
326
394
|
if (isStyleFunction(value)) {
|
|
@@ -355,7 +423,8 @@ export class StylesheetBuilder {
|
|
|
355
423
|
}
|
|
356
424
|
|
|
357
425
|
for (const selector of selectorList) {
|
|
358
|
-
|
|
426
|
+
// We are going to be apply the current rule to n selectors, so we clone the rule
|
|
427
|
+
const rule = this.cloneRule(this.rule);
|
|
359
428
|
|
|
360
429
|
if (selector.type === "className") {
|
|
361
430
|
const {
|
|
@@ -431,16 +500,28 @@ export class StylesheetBuilder {
|
|
|
431
500
|
|
|
432
501
|
for (const [name, value] of this.rule.v) {
|
|
433
502
|
this.shared[type] ??= {};
|
|
434
|
-
this.shared[type][name] ??= [
|
|
435
|
-
|
|
503
|
+
this.shared[type][name] ??= [];
|
|
504
|
+
|
|
505
|
+
const variableValue: VariableValue =
|
|
506
|
+
subtype === "light"
|
|
507
|
+
? [value]
|
|
508
|
+
: [value, [["=", "prefers-color-scheme", "dark"]]];
|
|
509
|
+
|
|
510
|
+
// Append extra media queries if they exist
|
|
511
|
+
if (this.rule.m) {
|
|
512
|
+
variableValue[1] ??= [];
|
|
513
|
+
variableValue[1].push(...this.rule.m);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
this.shared[type][name].push(variableValue);
|
|
436
517
|
}
|
|
437
518
|
}
|
|
438
519
|
}
|
|
439
520
|
}
|
|
440
521
|
|
|
441
522
|
addContainerQuery(query: ContainerQuery) {
|
|
442
|
-
this.
|
|
443
|
-
this.
|
|
523
|
+
this.ruleTemplate.cq ??= [];
|
|
524
|
+
this.ruleTemplate.cq.push(query);
|
|
444
525
|
}
|
|
445
526
|
|
|
446
527
|
newAnimationFrames(name: string) {
|
package/src/jest/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Appearance, Dimensions } from "react-native";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { inspect } from "node:util";
|
|
4
4
|
|
|
5
5
|
import { compile, type CompilerOptions } from "../compiler";
|
|
6
6
|
import { StyleCollection } from "../runtime/native/injection";
|
|
@@ -37,14 +37,29 @@ export function registerCSS(
|
|
|
37
37
|
...options
|
|
38
38
|
}: CompilerOptions & { debug?: boolean } = {},
|
|
39
39
|
) {
|
|
40
|
-
const
|
|
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 });
|
|
41
50
|
if (debug) {
|
|
42
51
|
console.log(
|
|
43
|
-
`Compiled:\n---\n${
|
|
52
|
+
`Compiled:\n---\n${inspect(
|
|
53
|
+
{
|
|
54
|
+
stylesheet: compiled.stylesheet(),
|
|
55
|
+
warnings: compiled.warnings(),
|
|
56
|
+
},
|
|
57
|
+
{ depth: null, colors: true, compact: false },
|
|
58
|
+
)}`,
|
|
44
59
|
);
|
|
45
60
|
}
|
|
46
61
|
|
|
47
|
-
StyleCollection.inject(compiled);
|
|
62
|
+
StyleCollection.inject(compiled.stylesheet());
|
|
48
63
|
|
|
49
64
|
return compiled;
|
|
50
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,61 +2,59 @@
|
|
|
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
|
|
|
40
40
|
switch (mediaQuery[1]) {
|
|
41
41
|
case "platform":
|
|
42
|
-
return right === Platform.OS;
|
|
42
|
+
return right === "native" || 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
|
};
|