react-native-css 3.0.3 → 3.0.5

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 (47) hide show
  1. package/README.md +5 -5
  2. package/dist/commonjs/compiler/compiler.js +49 -1
  3. package/dist/commonjs/compiler/compiler.js.map +1 -1
  4. package/dist/commonjs/compiler/stylesheet.js +5 -0
  5. package/dist/commonjs/compiler/stylesheet.js.map +1 -1
  6. package/dist/commonjs/compiler/supports.js +1 -3
  7. package/dist/commonjs/compiler/supports.js.map +1 -1
  8. package/dist/commonjs/native/styles/index.js +1 -3
  9. package/dist/commonjs/native/styles/index.js.map +1 -1
  10. package/dist/commonjs/native/styles/shorthands/_handler.js +10 -0
  11. package/dist/commonjs/native/styles/shorthands/_handler.js.map +1 -1
  12. package/dist/commonjs/native/styles/shorthands/box-shadow.js +27 -5
  13. package/dist/commonjs/native/styles/shorthands/box-shadow.js.map +1 -1
  14. package/dist/commonjs/web/api.js +1 -1
  15. package/dist/commonjs/web/api.js.map +1 -1
  16. package/dist/module/compiler/compiler.js +50 -2
  17. package/dist/module/compiler/compiler.js.map +1 -1
  18. package/dist/module/compiler/stylesheet.js +5 -0
  19. package/dist/module/compiler/stylesheet.js.map +1 -1
  20. package/dist/module/compiler/supports.js +1 -3
  21. package/dist/module/compiler/supports.js.map +1 -1
  22. package/dist/module/native/styles/index.js +1 -3
  23. package/dist/module/native/styles/index.js.map +1 -1
  24. package/dist/module/native/styles/shorthands/_handler.js +11 -1
  25. package/dist/module/native/styles/shorthands/_handler.js.map +1 -1
  26. package/dist/module/native/styles/shorthands/box-shadow.js +28 -5
  27. package/dist/module/native/styles/shorthands/box-shadow.js.map +1 -1
  28. package/dist/module/web/api.js +1 -1
  29. package/dist/module/web/api.js.map +1 -1
  30. package/dist/typescript/commonjs/src/compiler/compiler.d.ts.map +1 -1
  31. package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts +1 -0
  32. package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts.map +1 -1
  33. package/dist/typescript/commonjs/src/native/styles/shorthands/_handler.d.ts.map +1 -1
  34. package/dist/typescript/commonjs/src/native/styles/shorthands/box-shadow.d.ts.map +1 -1
  35. package/dist/typescript/module/src/compiler/compiler.d.ts.map +1 -1
  36. package/dist/typescript/module/src/compiler/stylesheet.d.ts +1 -0
  37. package/dist/typescript/module/src/compiler/stylesheet.d.ts.map +1 -1
  38. package/dist/typescript/module/src/native/styles/shorthands/_handler.d.ts.map +1 -1
  39. package/dist/typescript/module/src/native/styles/shorthands/box-shadow.d.ts.map +1 -1
  40. package/package.json +3 -2
  41. package/src/compiler/compiler.ts +76 -2
  42. package/src/compiler/stylesheet.ts +6 -0
  43. package/src/compiler/supports.ts +1 -3
  44. package/src/native/styles/index.ts +1 -1
  45. package/src/native/styles/shorthands/_handler.ts +14 -1
  46. package/src/native/styles/shorthands/box-shadow.ts +29 -4
  47. package/src/web/api.tsx +1 -1
@@ -7,6 +7,8 @@ import {
7
7
  type MediaQuery as CSSMediaQuery,
8
8
  type CustomAtRules,
9
9
  type MediaRule,
10
+ type ParsedComponent,
11
+ type PropertyRule,
10
12
  type Rule,
11
13
  type Visitor,
12
14
  } from "lightningcss";
@@ -15,11 +17,19 @@ import { maybeMutateReactNativeOptions, parsePropAtRule } from "./atRules";
15
17
  import type {
16
18
  CompilerOptions,
17
19
  ContainerQuery,
20
+ StyleDescriptor,
18
21
  StyleRuleMapping,
19
22
  UniqueVarInfo,
20
23
  } from "./compiler.types";
21
24
  import { parseContainerCondition } from "./container-query";
22
- import { parseDeclaration, round } from "./declarations";
25
+ import {
26
+ parseAngle,
27
+ parseColor,
28
+ parseDeclaration,
29
+ parseLength,
30
+ reduceParseUnparsed,
31
+ round,
32
+ } from "./declarations";
23
33
  import { inlineVariables } from "./inline-variables";
24
34
  import { extractKeyFrames } from "./keyframes";
25
35
  import { lightningcssLoader } from "./lightningcss-loader";
@@ -276,13 +286,15 @@ function extractRule(
276
286
  }
277
287
  }
278
288
  break;
289
+ case "property":
290
+ extractPropertyRule(rule.value, builder);
291
+ break;
279
292
  case "custom":
280
293
  case "font-face":
281
294
  case "font-palette-values":
282
295
  case "font-feature-values":
283
296
  case "namespace":
284
297
  case "layer-statement":
285
- case "property":
286
298
  case "view-transition":
287
299
  case "ignored":
288
300
  case "unknown":
@@ -377,3 +389,65 @@ function extractContainer(
377
389
  extractRule(rule, builder, mapping);
378
390
  }
379
391
  }
392
+
393
+ function extractPropertyRule(
394
+ propertyRule: PropertyRule,
395
+ builder: StylesheetBuilder,
396
+ ) {
397
+ const { initialValue, name } = propertyRule;
398
+
399
+ if (initialValue == null) {
400
+ return;
401
+ }
402
+
403
+ const varName = name.startsWith("--") ? name.slice(2) : name;
404
+ const value = parsePropertyInitialValue(initialValue, builder);
405
+
406
+ if (value !== undefined) {
407
+ builder.addRootVariable(varName, value);
408
+ }
409
+ }
410
+
411
+ function parsePropertyInitialValue(
412
+ component: ParsedComponent,
413
+ builder: StylesheetBuilder,
414
+ ): StyleDescriptor {
415
+ switch (component.type) {
416
+ case "length":
417
+ return parseLength(component.value, builder);
418
+ case "number":
419
+ case "integer":
420
+ return round(component.value);
421
+ case "percentage":
422
+ return `${round(component.value * 100)}%`;
423
+ case "color":
424
+ return parseColor(component.value, builder);
425
+ case "angle":
426
+ return parseAngle(component.value, builder);
427
+ case "length-percentage":
428
+ return parseLength(component.value, builder);
429
+ case "token-list":
430
+ return reduceParseUnparsed(
431
+ component.value,
432
+ builder,
433
+ "@property",
434
+ false,
435
+ );
436
+ case "custom-ident":
437
+ case "literal":
438
+ return component.value;
439
+ case "repeated": {
440
+ const results = component.value.components
441
+ .map((c) => parsePropertyInitialValue(c, builder))
442
+ .filter(
443
+ (v): v is NonNullable<StyleDescriptor> => v !== undefined,
444
+ );
445
+ // Unwrap single-child repeated values so downstream consumers get a
446
+ // scalar instead of a 1-element array. For example, `<length>+` with
447
+ // initial-value `10px` should produce the same shape as `<length>`.
448
+ return results.length === 1 ? results[0] : results;
449
+ }
450
+ default:
451
+ return undefined;
452
+ }
453
+ }
@@ -577,6 +577,12 @@ export class StylesheetBuilder {
577
577
  this.ruleTemplate.cq.push(query);
578
578
  }
579
579
 
580
+ addRootVariable(name: string, value: StyleDescriptor) {
581
+ this.shared.rootVariables ??= {};
582
+ this.shared.rootVariables[name] ??= [];
583
+ this.shared.rootVariables[name].push([value]);
584
+ }
585
+
580
586
  newAnimationFrames(name: string) {
581
587
  this.shared.animations ??= {};
582
588
 
@@ -21,8 +21,6 @@ export function supportsConditionValid(condition: SupportsCondition): boolean {
21
21
  }
22
22
 
23
23
  const declarations: Record<string, string[]> = {
24
- // We don't actually support this, but its needed for Tailwind CSS
25
- "-moz-orient": ["inline"],
26
24
  // Special text used by TailwindCSS. We should probably change this to all color-mix
27
- "color": ["color-mix(in lab, red, red)"],
25
+ color: ["color-mix(in lab, red, red)"],
28
26
  };
@@ -362,7 +362,7 @@ function deepMergeConfig(
362
362
  result = Object.assign({}, left, right);
363
363
  }
364
364
  } else {
365
- result = { ...left };
365
+ result = Object.assign({}, left, right);
366
366
  }
367
367
 
368
368
  if (
@@ -1,5 +1,8 @@
1
1
  /* eslint-disable */
2
- import { isStyleDescriptorArray } from "react-native-css/utilities";
2
+ import {
3
+ isStyleDescriptorArray,
4
+ isStyleFunction,
5
+ } from "react-native-css/utilities";
3
6
 
4
7
  import { setDeepPath } from "../../objects";
5
8
  import { ShortHandSymbol } from "../constants";
@@ -56,6 +59,16 @@ export function shorthandHandler(
56
59
  return type.includes(value) || type.includes(typeof value);
57
60
  }
58
61
 
62
+ // Style functions (var, calc, env, etc.) are unresolved at pattern-match
63
+ // time — their actual values won't be known until runtime variable
64
+ // resolution. Accepting them in any type slot makes pattern matching
65
+ // less strict when variables are involved, but rejecting them would
66
+ // break variable-based shadows entirely (e.g. box-shadow: var(--shadow)
67
+ // where --shadow resolves to "0 4px 6px -1px #000").
68
+ if (isStyleFunction(value)) {
69
+ return true;
70
+ }
71
+
59
72
  switch (type) {
60
73
  case "string":
61
74
  case "number":
@@ -4,21 +4,30 @@ import { isStyleDescriptorArray } from "react-native-css/utilities";
4
4
  import type { StyleFunctionResolver } from "../resolve";
5
5
  import { shorthandHandler } from "./_handler";
6
6
 
7
- const color = ["color", "string"] as const;
7
+ // "color" type accepts both strings ("#fff") and objects (PlatformColor from currentcolor).
8
+ // Using "string" here would reject platform color objects and silently drop the shadow.
9
+ const color = ["color", "color"] as const;
8
10
  const offsetX = ["offsetX", "number"] as const;
9
11
  const offsetY = ["offsetY", "number"] as const;
10
12
  const blurRadius = ["blurRadius", "number"] as const;
11
13
  const spreadDistance = ["spreadDistance", "number"] as const;
12
- // const inset = ["inset", "string"] as const;
14
+ // Match the literal string "inset" - the array type checks if value is in array
15
+ const inset = ["inset", ["inset"]] as const;
13
16
 
14
17
  const handler = shorthandHandler(
15
18
  [
19
+ // Standard patterns (without inset)
16
20
  [offsetX, offsetY, blurRadius, spreadDistance],
17
21
  [offsetX, offsetY, blurRadius, spreadDistance, color],
18
22
  [color, offsetX, offsetY],
19
23
  [color, offsetX, offsetY, blurRadius, spreadDistance],
20
24
  [offsetX, offsetY, color],
21
25
  [offsetX, offsetY, blurRadius, color],
26
+ // Inset patterns - "inset" keyword at the beginning
27
+ [inset, offsetX, offsetY, blurRadius, spreadDistance],
28
+ [inset, offsetX, offsetY, blurRadius, spreadDistance, color],
29
+ [inset, offsetX, offsetY, blurRadius, color],
30
+ [inset, color, offsetX, offsetY, blurRadius, spreadDistance],
22
31
  ],
23
32
  [],
24
33
  "object",
@@ -41,8 +50,10 @@ export const boxShadow: StyleFunctionResolver = (
41
50
  if (shadows === undefined) {
42
51
  return;
43
52
  } else {
44
- return omitTransparentShadows(
45
- handler(resolveValue, shadows, get, options),
53
+ return normalizeInsetValue(
54
+ omitTransparentShadows(
55
+ handler(resolveValue, shadows, get, options),
56
+ ),
46
57
  );
47
58
  }
48
59
  })
@@ -69,3 +80,17 @@ function omitTransparentShadows(style: unknown) {
69
80
 
70
81
  return style;
71
82
  }
83
+
84
+ /**
85
+ * Convert inset: "inset" to inset: true for React Native boxShadow.
86
+ *
87
+ * The shorthand handler matches the literal "inset" string and assigns it as the value.
88
+ * React Native's boxShadow expects inset to be a boolean.
89
+ */
90
+ function normalizeInsetValue(style: unknown) {
91
+ if (typeof style === "object" && style && "inset" in style) {
92
+ return { ...style, inset: true };
93
+ }
94
+
95
+ return style;
96
+ }
package/src/web/api.tsx CHANGED
@@ -31,7 +31,7 @@ export const styled = <
31
31
  _options?: StyledOptions,
32
32
  ) => {
33
33
  return (props: StyledProps<ComponentPropsWithRef<C>, M>) => {
34
- return useCssElement(baseComponent, mapping, props);
34
+ return useCssElement(baseComponent, props, mapping);
35
35
  };
36
36
  };
37
37