react-native-css 3.0.0-nightly.df0f885 → 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.
Files changed (43) hide show
  1. package/dist/commonjs/compiler/atRules.js +1 -1
  2. package/dist/commonjs/compiler/declarations.js +21 -9
  3. package/dist/commonjs/compiler/declarations.js.map +1 -1
  4. package/dist/commonjs/compiler/stylesheet.js +43 -19
  5. package/dist/commonjs/compiler/stylesheet.js.map +1 -1
  6. package/dist/commonjs/runtime/native/conditions/media-query.js +1 -1
  7. package/dist/commonjs/runtime/native/conditions/media-query.js.map +1 -1
  8. package/dist/commonjs/runtime/native/styles/calculate-props.js +53 -48
  9. package/dist/commonjs/runtime/native/styles/calculate-props.js.map +1 -1
  10. package/dist/commonjs/runtime/native/styles/units.js +6 -3
  11. package/dist/commonjs/runtime/native/styles/units.js.map +1 -1
  12. package/dist/module/compiler/atRules.js +1 -1
  13. package/dist/module/compiler/declarations.js +21 -9
  14. package/dist/module/compiler/declarations.js.map +1 -1
  15. package/dist/module/compiler/stylesheet.js +43 -19
  16. package/dist/module/compiler/stylesheet.js.map +1 -1
  17. package/dist/module/runtime/native/conditions/media-query.js +1 -1
  18. package/dist/module/runtime/native/conditions/media-query.js.map +1 -1
  19. package/dist/module/runtime/native/styles/calculate-props.js +53 -48
  20. package/dist/module/runtime/native/styles/calculate-props.js.map +1 -1
  21. package/dist/module/runtime/native/styles/units.js +6 -3
  22. package/dist/module/runtime/native/styles/units.js.map +1 -1
  23. package/dist/typescript/commonjs/src/compiler/compiler.d.ts +3 -3
  24. package/dist/typescript/commonjs/src/compiler/declarations.d.ts.map +1 -1
  25. package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts +9 -5
  26. package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts.map +1 -1
  27. package/dist/typescript/commonjs/src/jest/index.d.ts +3 -3
  28. package/dist/typescript/commonjs/src/runtime/native/styles/calculate-props.d.ts.map +1 -1
  29. package/dist/typescript/commonjs/src/runtime/native/styles/units.d.ts.map +1 -1
  30. package/dist/typescript/module/src/compiler/compiler.d.ts +3 -3
  31. package/dist/typescript/module/src/compiler/declarations.d.ts.map +1 -1
  32. package/dist/typescript/module/src/compiler/stylesheet.d.ts +9 -5
  33. package/dist/typescript/module/src/compiler/stylesheet.d.ts.map +1 -1
  34. package/dist/typescript/module/src/jest/index.d.ts +3 -3
  35. package/dist/typescript/module/src/runtime/native/styles/calculate-props.d.ts.map +1 -1
  36. package/dist/typescript/module/src/runtime/native/styles/units.d.ts.map +1 -1
  37. package/package.json +2 -2
  38. package/src/compiler/atRules.ts +1 -1
  39. package/src/compiler/declarations.ts +29 -9
  40. package/src/compiler/stylesheet.ts +58 -24
  41. package/src/runtime/native/conditions/media-query.ts +1 -1
  42. package/src/runtime/native/styles/calculate-props.ts +59 -49
  43. package/src/runtime/native/styles/units.ts +7 -3
@@ -57,15 +57,16 @@ export class StylesheetBuilder {
57
57
  animations?: AnimationRecord;
58
58
  rem: number;
59
59
  ruleOrder: number;
60
+ warningProperty?: string;
60
61
  warningProperties: string[];
61
- warningValues: [string, unknown][];
62
+ warningValues: Record<string, unknown[]>;
62
63
  warningFunctions: string[];
63
64
  } = {
64
65
  ruleSets: {},
65
66
  rem: 14,
66
67
  ruleOrder: 0,
67
68
  warningProperties: [],
68
- warningValues: [],
69
+ warningValues: {},
69
70
  warningFunctions: [],
70
71
  },
71
72
  private selectors?: NormalizeSelector[],
@@ -172,8 +173,14 @@ export class StylesheetBuilder {
172
173
  );
173
174
  }
174
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;
175
182
  addWarning(
176
- type: "property" | "value" | "function",
183
+ type: "property" | "style" | "value",
177
184
  property: string,
178
185
  value?: unknown,
179
186
  ): void {
@@ -181,21 +188,49 @@ export class StylesheetBuilder {
181
188
  case "property":
182
189
  this.shared.warningProperties.push(property);
183
190
  break;
184
- case "value":
185
- this.shared.warningValues.push([property, value]);
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);
186
201
  break;
187
- case "function":
188
- this.shared.warningFunctions.push(property);
202
+ }
203
+ case "style":
204
+ this.shared.warningValues[property] ??= [];
205
+ this.shared.warningValues[property]?.push(value);
189
206
  break;
190
207
  }
191
208
  }
192
209
 
193
210
  getWarnings() {
194
- return {
195
- properties: this.shared.warningProperties,
196
- values: this.shared.warningValues,
197
- functions: this.shared.warningFunctions,
198
- };
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 };
199
234
  }
200
235
 
201
236
  newRule(mapping = this.mapping, { important = false } = {}) {
@@ -331,30 +366,29 @@ export class StylesheetBuilder {
331
366
  }
332
367
 
333
368
  private pushDescriptor(
334
- property: string,
369
+ rawProperty: string,
335
370
  value: StyleDescriptor,
336
371
  declarations: StyleDeclaration[],
337
372
  forceTuple = false,
338
373
  delayed = false,
339
374
  ) {
340
- property = toRNProperty(property);
375
+ const property = toRNProperty(rawProperty);
341
376
 
342
- let propPath: string | string[] =
343
- this.mapping[property] ?? this.mapping["*"] ?? property;
377
+ let propPath: string | string[] | undefined =
378
+ this.mapping[rawProperty] ?? this.mapping[property] ?? this.mapping["*"];
344
379
 
345
380
  if (Array.isArray(propPath)) {
346
- const first = propPath[0];
381
+ const [first, second] = propPath;
347
382
 
348
- if (!first) {
349
- // This should not happen, but if it does, we skip the property
350
- return;
351
- }
352
-
353
- if (propPath.length === 1) {
354
- propPath = first;
383
+ if (propPath.length === 2 && first === "*" && second) {
384
+ propPath = second;
355
385
  } else {
356
386
  forceTuple = true;
357
387
  }
388
+ } else if (propPath) {
389
+ forceTuple = true;
390
+ } else {
391
+ propPath = property;
358
392
  }
359
393
 
360
394
  if (isStyleFunction(value)) {
@@ -39,7 +39,7 @@ function testComparison(mediaQuery: MediaCondition, get: Getter): Boolean {
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
44
  return right === get(colorScheme);
45
45
  }
@@ -103,63 +103,73 @@ export function applyDeclarations(
103
103
  // Dynamic styles
104
104
  let value: any = declaration[0];
105
105
  let propPath = declaration[1];
106
- let prop = "";
106
+ let prop: string;
107
107
 
108
- if (typeof propPath === "string") {
109
- if (propPath.startsWith("^")) {
110
- propPath = propPath.slice(1);
111
- target = topLevelTarget[propPath] ??= {};
108
+ if (Array.isArray(propPath)) {
109
+ const [first, ...rest] = propPath;
110
+
111
+ if (!first) {
112
+ continue;
112
113
  }
113
- prop = propPath;
114
- } else {
115
- for (prop of propPath) {
116
- if (prop.startsWith("^")) {
117
- prop = prop.slice(1);
118
- target = topLevelTarget[prop] ??= {};
119
- } else {
120
- target = target[prop] ??= {};
114
+
115
+ const final = rest.pop();
116
+
117
+ if (final) {
118
+ if (first !== "*") {
119
+ topLevelTarget[first] ??= {};
120
+ target = topLevelTarget[first];
121
+ }
122
+
123
+ for (prop of rest) {
124
+ target[prop] ??= {};
125
+ target = target[prop];
121
126
  }
122
- }
123
- }
124
127
 
125
- if (Array.isArray(value)) {
126
- const shouldDelay = declaration[2];
127
-
128
- if (shouldDelay) {
129
- /**
130
- * We need to delay the resolution of this value until after all
131
- * styles have been calculated. But another style might override
132
- * this value. So we set a placeholder value and only override
133
- * if the placeholder is preserved
134
- *
135
- * This also ensures the props exist, so setValue will properly
136
- * mutate the props object and not create a new one
137
- */
138
- const originalValue = value;
139
- value = {};
140
- delayedStyles.push(() => {
141
- if (target[prop] === value) {
142
- delete target[prop];
143
- value = resolveValue(originalValue, get, {
144
- inlineVariables,
145
- inheritedVariables,
146
- renderGuards: guards,
147
- calculateProps,
148
- });
149
- applyValue(target, prop, value);
150
- }
151
- });
128
+ prop = final;
152
129
  } else {
153
- value = resolveValue(value, get, {
154
- inlineVariables,
155
- inheritedVariables,
156
- renderGuards: guards,
157
- calculateProps,
158
- });
130
+ target = topLevelTarget;
131
+ prop = first;
159
132
  }
133
+ } else {
134
+ prop = propPath;
135
+ }
160
136
 
161
- applyValue(target, prop, value);
137
+ const shouldDelay = declaration[2];
138
+
139
+ if (shouldDelay) {
140
+ /**
141
+ * We need to delay the resolution of this value until after all
142
+ * styles have been calculated. But another style might override
143
+ * this value. So we set a placeholder value and only override
144
+ * if the placeholder is preserved
145
+ *
146
+ * This also ensures the props exist, so setValue will properly
147
+ * mutate the props object and not create a new one
148
+ */
149
+ const originalValue = value;
150
+ value = {};
151
+ delayedStyles.push(() => {
152
+ if (target[prop] === value) {
153
+ delete target[prop];
154
+ value = resolveValue(originalValue, get, {
155
+ inlineVariables,
156
+ inheritedVariables,
157
+ renderGuards: guards,
158
+ calculateProps,
159
+ });
160
+ applyValue(target, prop, value);
161
+ }
162
+ });
163
+ } else {
164
+ value = resolveValue(value, get, {
165
+ inlineVariables,
166
+ inheritedVariables,
167
+ renderGuards: guards,
168
+ calculateProps,
169
+ });
162
170
  }
171
+
172
+ applyValue(target, prop, value);
163
173
  }
164
174
  }
165
175
  }
@@ -2,17 +2,21 @@
2
2
  import { rem as remObs, vh as vhObs, vw as vwObs } from "../reactivity";
3
3
  import type { StyleFunctionResolver } from "./resolve";
4
4
 
5
- export const em: StyleFunctionResolver = (resolve, func) => {
5
+ export const em: StyleFunctionResolver = (resolve, func, get) => {
6
6
  let value = func[2];
7
7
 
8
8
  if (!value) {
9
9
  return;
10
10
  }
11
11
 
12
- const emValue = resolve([{}, "var", ["__rn-css-em"]]);
12
+ let emValue = resolve([{}, "var", ["__rn-css-em"]]);
13
13
 
14
14
  if (typeof emValue !== "number") {
15
- return undefined;
15
+ emValue = get(remObs);
16
+ }
17
+
18
+ if (typeof emValue !== "number") {
19
+ return;
16
20
  }
17
21
 
18
22
  return round(Number(value) * emValue);