react-native-css 0.0.0-nightly.96f5ce2 → 0.0.0-nightly.d48061c

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 (99) hide show
  1. package/dist/commonjs/babel/index.js +6 -2
  2. package/dist/commonjs/babel/index.js.map +1 -1
  3. package/dist/commonjs/compiler/atRules.js +3 -25
  4. package/dist/commonjs/compiler/atRules.js.map +1 -1
  5. package/dist/commonjs/compiler/compiler.js +43 -23
  6. package/dist/commonjs/compiler/compiler.js.map +1 -1
  7. package/dist/commonjs/compiler/declarations.js +11 -13
  8. package/dist/commonjs/compiler/declarations.js.map +1 -1
  9. package/dist/commonjs/compiler/selector-builder.js +6 -4
  10. package/dist/commonjs/compiler/selector-builder.js.map +1 -1
  11. package/dist/commonjs/compiler/stylesheet.js +0 -4
  12. package/dist/commonjs/compiler/stylesheet.js.map +1 -1
  13. package/dist/commonjs/metro/index.js +8 -8
  14. package/dist/commonjs/metro/index.js.map +1 -1
  15. package/dist/commonjs/runtime/native/styles/calculate-props.js +2 -0
  16. package/dist/commonjs/runtime/native/styles/calculate-props.js.map +1 -1
  17. package/dist/commonjs/runtime/native/styles/line-height.js +25 -0
  18. package/dist/commonjs/runtime/native/styles/line-height.js.map +1 -0
  19. package/dist/commonjs/runtime/native/styles/resolve.js +2 -0
  20. package/dist/commonjs/runtime/native/styles/resolve.js.map +1 -1
  21. package/dist/commonjs/runtime/native/styles/shorthands/box-shadow.js +19 -11
  22. package/dist/commonjs/runtime/native/styles/shorthands/box-shadow.js.map +1 -1
  23. package/dist/commonjs/runtime/native/styles/variables.js +1 -1
  24. package/dist/commonjs/runtime/native/styles/variables.js.map +1 -1
  25. package/dist/module/babel/index.js +2 -2
  26. package/dist/module/babel/index.js.map +1 -1
  27. package/dist/module/compiler/atRules.js +3 -25
  28. package/dist/module/compiler/atRules.js.map +1 -1
  29. package/dist/module/compiler/compiler.js +45 -25
  30. package/dist/module/compiler/compiler.js.map +1 -1
  31. package/dist/module/compiler/compiler.types.js.map +1 -1
  32. package/dist/module/compiler/declarations.js +11 -13
  33. package/dist/module/compiler/declarations.js.map +1 -1
  34. package/dist/module/compiler/selector-builder.js +6 -4
  35. package/dist/module/compiler/selector-builder.js.map +1 -1
  36. package/dist/module/compiler/stylesheet.js +0 -4
  37. package/dist/module/compiler/stylesheet.js.map +1 -1
  38. package/dist/module/metro/index.js +8 -8
  39. package/dist/module/metro/index.js.map +1 -1
  40. package/dist/module/runtime/native/styles/calculate-props.js +2 -0
  41. package/dist/module/runtime/native/styles/calculate-props.js.map +1 -1
  42. package/dist/module/runtime/native/styles/line-height.js +20 -0
  43. package/dist/module/runtime/native/styles/line-height.js.map +1 -0
  44. package/dist/module/runtime/native/styles/resolve.js +2 -0
  45. package/dist/module/runtime/native/styles/resolve.js.map +1 -1
  46. package/dist/module/runtime/native/styles/shorthands/box-shadow.js +19 -11
  47. package/dist/module/runtime/native/styles/shorthands/box-shadow.js.map +1 -1
  48. package/dist/module/runtime/native/styles/variables.js +1 -1
  49. package/dist/module/runtime/native/styles/variables.js.map +1 -1
  50. package/dist/typescript/commonjs/src/babel/index.d.ts +3 -0
  51. package/dist/typescript/commonjs/src/babel/index.d.ts.map +1 -1
  52. package/dist/typescript/commonjs/src/compiler/atRules.d.ts +1 -1
  53. package/dist/typescript/commonjs/src/compiler/atRules.d.ts.map +1 -1
  54. package/dist/typescript/commonjs/src/compiler/compiler.d.ts.map +1 -1
  55. package/dist/typescript/commonjs/src/compiler/compiler.types.d.ts +0 -5
  56. package/dist/typescript/commonjs/src/compiler/compiler.types.d.ts.map +1 -1
  57. package/dist/typescript/commonjs/src/compiler/declarations.d.ts +3 -3
  58. package/dist/typescript/commonjs/src/compiler/declarations.d.ts.map +1 -1
  59. package/dist/typescript/commonjs/src/compiler/selector-builder.d.ts +1 -1
  60. package/dist/typescript/commonjs/src/compiler/selector-builder.d.ts.map +1 -1
  61. package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts.map +1 -1
  62. package/dist/typescript/commonjs/src/metro/index.d.ts.map +1 -1
  63. package/dist/typescript/commonjs/src/runtime/native/styles/calculate-props.d.ts.map +1 -1
  64. package/dist/typescript/commonjs/src/runtime/native/styles/line-height.d.ts +3 -0
  65. package/dist/typescript/commonjs/src/runtime/native/styles/line-height.d.ts.map +1 -0
  66. package/dist/typescript/commonjs/src/runtime/native/styles/resolve.d.ts.map +1 -1
  67. package/dist/typescript/commonjs/src/runtime/native/styles/shorthands/box-shadow.d.ts.map +1 -1
  68. package/dist/typescript/module/src/babel/index.d.ts +3 -0
  69. package/dist/typescript/module/src/babel/index.d.ts.map +1 -1
  70. package/dist/typescript/module/src/compiler/atRules.d.ts +1 -1
  71. package/dist/typescript/module/src/compiler/atRules.d.ts.map +1 -1
  72. package/dist/typescript/module/src/compiler/compiler.d.ts.map +1 -1
  73. package/dist/typescript/module/src/compiler/compiler.types.d.ts +0 -5
  74. package/dist/typescript/module/src/compiler/compiler.types.d.ts.map +1 -1
  75. package/dist/typescript/module/src/compiler/declarations.d.ts +3 -3
  76. package/dist/typescript/module/src/compiler/declarations.d.ts.map +1 -1
  77. package/dist/typescript/module/src/compiler/selector-builder.d.ts +1 -1
  78. package/dist/typescript/module/src/compiler/selector-builder.d.ts.map +1 -1
  79. package/dist/typescript/module/src/compiler/stylesheet.d.ts.map +1 -1
  80. package/dist/typescript/module/src/metro/index.d.ts.map +1 -1
  81. package/dist/typescript/module/src/runtime/native/styles/calculate-props.d.ts.map +1 -1
  82. package/dist/typescript/module/src/runtime/native/styles/line-height.d.ts +3 -0
  83. package/dist/typescript/module/src/runtime/native/styles/line-height.d.ts.map +1 -0
  84. package/dist/typescript/module/src/runtime/native/styles/resolve.d.ts.map +1 -1
  85. package/dist/typescript/module/src/runtime/native/styles/shorthands/box-shadow.d.ts.map +1 -1
  86. package/package.json +11 -13
  87. package/src/babel/index.ts +2 -2
  88. package/src/compiler/atRules.ts +2 -26
  89. package/src/compiler/compiler.ts +51 -26
  90. package/src/compiler/compiler.types.ts +0 -5
  91. package/src/compiler/declarations.ts +22 -12
  92. package/src/compiler/selector-builder.ts +7 -5
  93. package/src/compiler/stylesheet.ts +0 -9
  94. package/src/metro/index.ts +12 -11
  95. package/src/runtime/native/styles/calculate-props.ts +4 -0
  96. package/src/runtime/native/styles/line-height.ts +25 -0
  97. package/src/runtime/native/styles/resolve.ts +2 -0
  98. package/src/runtime/native/styles/shorthands/box-shadow.ts +24 -18
  99. package/src/runtime/native/styles/variables.ts +1 -1
@@ -331,15 +331,6 @@ export class StylesheetBuilder {
331
331
  forceTuple,
332
332
  );
333
333
  } else if (property.startsWith("--")) {
334
- // If we have enabled variable usage tracking, skip unused variables
335
- if (
336
- this.options.stripUnusedVariables &&
337
- !property.startsWith("--__rn-css") &&
338
- !this.varUsage.has(property)
339
- ) {
340
- return;
341
- }
342
-
343
334
  rule.v ??= [];
344
335
  rule.v.push([property.slice(2), value]);
345
336
  } else if (isStyleFunction(value)) {
@@ -2,7 +2,6 @@
2
2
  import { dirname, relative, sep } from "node:path";
3
3
  import { versions } from "node:process";
4
4
 
5
- import connect from "connect";
6
5
  import debug from "debug";
7
6
  import type { MetroConfig } from "metro-config";
8
7
 
@@ -50,9 +49,6 @@ export function withReactNativeCSS<
50
49
  setupTypeScript(typescriptEnvPath);
51
50
  }
52
51
 
53
- const originalMiddleware = config.server?.enhanceMiddleware;
54
- const originalResolver = config.resolver?.resolveRequest;
55
-
56
52
  return {
57
53
  ...config,
58
54
  transformerPath: require.resolve("./metro-transformer"),
@@ -68,13 +64,14 @@ export function withReactNativeCSS<
68
64
  return { type: "empty" };
69
65
  }
70
66
 
67
+ const parentResolver =
68
+ config.resolver?.resolveRequest ?? context.resolveRequest;
69
+
71
70
  // Don't hijack the resolution of react-native imports
72
71
  if (!globalClassNamePolyfill) {
73
- const parentResolver = originalResolver ?? context.resolveRequest;
74
72
  return parentResolver(context, moduleName, platform);
75
73
  }
76
74
 
77
- const parentResolver = originalResolver ?? context.resolveRequest;
78
75
  const resolver = platform === "web" ? webResolver : nativeResolver;
79
76
  const resolved = resolver(
80
77
  parentResolver,
@@ -88,8 +85,7 @@ export function withReactNativeCSS<
88
85
  },
89
86
  server: {
90
87
  ...config.server,
91
- enhanceMiddleware(middleware, metroServer) {
92
- const server = connect();
88
+ enhanceMiddleware(metroMiddleware, metroServer) {
93
89
  const bundler: any = metroServer.getBundler().getBundler();
94
90
 
95
91
  if (!bundler.__react_native_css__patched) {
@@ -230,9 +226,14 @@ export function withReactNativeCSS<
230
226
  };
231
227
  }
232
228
 
233
- return originalMiddleware
234
- ? server.use(originalMiddleware(middleware, metroServer))
235
- : server.use(middleware);
229
+ /**
230
+ * We don't modify the middleware, we just use this function to get the metroServer
231
+ * So simply return the existing middleware
232
+ */
233
+ return (
234
+ config.server?.enhanceMiddleware?.(metroMiddleware, metroServer) ??
235
+ metroMiddleware
236
+ );
236
237
  },
237
238
  },
238
239
  };
@@ -103,7 +103,11 @@ export function applyDeclarations(
103
103
  target: Record<string, any> = {},
104
104
  topLevelTarget = target,
105
105
  ) {
106
+ const originalTarget = target;
107
+
106
108
  for (const declaration of declarations) {
109
+ target = originalTarget;
110
+
107
111
  if (!Array.isArray(declaration)) {
108
112
  // Static styles
109
113
  Object.assign(target, declaration);
@@ -0,0 +1,25 @@
1
+ import type { StyleFunctionResolver } from "./resolve";
2
+
3
+ export const lineHeight: StyleFunctionResolver = (resolve, func) => {
4
+ const value = resolve(func[2]);
5
+
6
+ if (typeof value !== "number") {
7
+ return;
8
+ }
9
+
10
+ let emValue = resolve([{}, "var", ["__rn-css-em"]]);
11
+
12
+ if (typeof emValue !== "number") {
13
+ emValue = resolve([{}, "var", ["__rn-css-rem"]]);
14
+ }
15
+
16
+ if (typeof emValue !== "number") {
17
+ return;
18
+ }
19
+
20
+ return round(value * emValue);
21
+ };
22
+
23
+ function round(number: number) {
24
+ return Math.round((number + Number.EPSILON) * 100) / 100;
25
+ }
@@ -10,6 +10,7 @@ import { type Getter, type VariableContextValue } from "../reactivity";
10
10
  import type { calculateProps } from "./calculate-props";
11
11
  import { transformKeys } from "./defaults";
12
12
  import * as functions from "./functions";
13
+ import { lineHeight } from "./line-height";
13
14
  import * as shorthands from "./shorthands";
14
15
  import { em, rem, vh, vw } from "./units";
15
16
  import { varResolver } from "./variables";
@@ -37,6 +38,7 @@ const functionResolvers = {
37
38
  ...shorthands,
38
39
  ...functions,
39
40
  animationName: shorthands.animation,
41
+ lineHeight,
40
42
  em,
41
43
  rem,
42
44
  vh,
@@ -1,3 +1,4 @@
1
+ import type { StyleDescriptor } from "../../../../compiler";
1
2
  import { isStyleDescriptorArray } from "../../../utils";
2
3
  import type { StyleFunctionResolver } from "../resolve";
3
4
  import { shorthandHandler } from "./_handler";
@@ -9,6 +10,27 @@ const blurRadius = ["blurRadius", "number"] as const;
9
10
  const spreadDistance = ["spreadDistance", "number"] as const;
10
11
  // const inset = ["inset", "string"] as const;
11
12
 
13
+ function deepFlattenToArrayOfStyleDescriptors(
14
+ arr: StyleDescriptor[],
15
+ ): StyleDescriptor[] {
16
+ const result: StyleDescriptor[] = [];
17
+ const stack = [arr];
18
+ while (stack.length > 0) {
19
+ const current = stack.pop();
20
+ if (Array.isArray(current)) {
21
+ if (current.length > 0 && Array.isArray(current[0])) {
22
+ for (let i = current.length - 1; i >= 0; i--) {
23
+ const elem = current[i];
24
+ if (isStyleDescriptorArray(elem)) stack.push(elem);
25
+ }
26
+ } else {
27
+ result.push(current);
28
+ }
29
+ }
30
+ }
31
+ return result;
32
+ }
33
+
12
34
  const handler = shorthandHandler(
13
35
  [
14
36
  [offsetX, offsetY, blurRadius, spreadDistance, color],
@@ -33,26 +55,10 @@ export const boxShadow: StyleFunctionResolver = (
33
55
  if (!isStyleDescriptorArray(args)) {
34
56
  return args;
35
57
  } else {
36
- return args
37
- .flatMap((shadows) => {
58
+ return deepFlattenToArrayOfStyleDescriptors(args)
59
+ .map((shadows) => {
38
60
  if (shadows === undefined) {
39
61
  return [];
40
- } else if (isStyleDescriptorArray(shadows)) {
41
- if (shadows.length === 0) {
42
- return [];
43
- } else if (Array.isArray(shadows[0])) {
44
- return shadows
45
- .map((shadow) => {
46
- return omitTransparentShadows(
47
- handler(resolveValue, shadow, get, options),
48
- );
49
- })
50
- .filter((v) => v !== undefined);
51
- } else {
52
- return omitTransparentShadows(
53
- handler(resolveValue, shadows, get, options),
54
- );
55
- }
56
62
  } else {
57
63
  return omitTransparentShadows(
58
64
  handler(resolveValue, shadows, get, options),
@@ -48,7 +48,7 @@ export function varResolver(
48
48
 
49
49
  if (name in variables) {
50
50
  renderGuards?.push(["v", name, variables[name]]);
51
- return variables[name];
51
+ return resolve(variables[name]);
52
52
  }
53
53
 
54
54
  variableHistory.add(name);