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.
- package/dist/commonjs/babel/index.js +6 -2
- package/dist/commonjs/babel/index.js.map +1 -1
- package/dist/commonjs/compiler/atRules.js +3 -25
- package/dist/commonjs/compiler/atRules.js.map +1 -1
- package/dist/commonjs/compiler/compiler.js +43 -23
- package/dist/commonjs/compiler/compiler.js.map +1 -1
- package/dist/commonjs/compiler/declarations.js +11 -13
- package/dist/commonjs/compiler/declarations.js.map +1 -1
- package/dist/commonjs/compiler/selector-builder.js +6 -4
- package/dist/commonjs/compiler/selector-builder.js.map +1 -1
- package/dist/commonjs/compiler/stylesheet.js +0 -4
- package/dist/commonjs/compiler/stylesheet.js.map +1 -1
- package/dist/commonjs/metro/index.js +8 -8
- package/dist/commonjs/metro/index.js.map +1 -1
- package/dist/commonjs/runtime/native/styles/calculate-props.js +2 -0
- package/dist/commonjs/runtime/native/styles/calculate-props.js.map +1 -1
- package/dist/commonjs/runtime/native/styles/line-height.js +25 -0
- package/dist/commonjs/runtime/native/styles/line-height.js.map +1 -0
- package/dist/commonjs/runtime/native/styles/resolve.js +2 -0
- package/dist/commonjs/runtime/native/styles/resolve.js.map +1 -1
- package/dist/commonjs/runtime/native/styles/shorthands/box-shadow.js +19 -11
- package/dist/commonjs/runtime/native/styles/shorthands/box-shadow.js.map +1 -1
- package/dist/commonjs/runtime/native/styles/variables.js +1 -1
- package/dist/commonjs/runtime/native/styles/variables.js.map +1 -1
- package/dist/module/babel/index.js +2 -2
- package/dist/module/babel/index.js.map +1 -1
- package/dist/module/compiler/atRules.js +3 -25
- package/dist/module/compiler/atRules.js.map +1 -1
- package/dist/module/compiler/compiler.js +45 -25
- 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 +11 -13
- package/dist/module/compiler/declarations.js.map +1 -1
- package/dist/module/compiler/selector-builder.js +6 -4
- package/dist/module/compiler/selector-builder.js.map +1 -1
- package/dist/module/compiler/stylesheet.js +0 -4
- package/dist/module/compiler/stylesheet.js.map +1 -1
- package/dist/module/metro/index.js +8 -8
- package/dist/module/metro/index.js.map +1 -1
- package/dist/module/runtime/native/styles/calculate-props.js +2 -0
- package/dist/module/runtime/native/styles/calculate-props.js.map +1 -1
- package/dist/module/runtime/native/styles/line-height.js +20 -0
- package/dist/module/runtime/native/styles/line-height.js.map +1 -0
- package/dist/module/runtime/native/styles/resolve.js +2 -0
- package/dist/module/runtime/native/styles/resolve.js.map +1 -1
- package/dist/module/runtime/native/styles/shorthands/box-shadow.js +19 -11
- package/dist/module/runtime/native/styles/shorthands/box-shadow.js.map +1 -1
- package/dist/module/runtime/native/styles/variables.js +1 -1
- package/dist/module/runtime/native/styles/variables.js.map +1 -1
- package/dist/typescript/commonjs/src/babel/index.d.ts +3 -0
- package/dist/typescript/commonjs/src/babel/index.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/atRules.d.ts +1 -1
- package/dist/typescript/commonjs/src/compiler/atRules.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/compiler.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/compiler.types.d.ts +0 -5
- package/dist/typescript/commonjs/src/compiler/compiler.types.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/declarations.d.ts +3 -3
- package/dist/typescript/commonjs/src/compiler/declarations.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/selector-builder.d.ts +1 -1
- package/dist/typescript/commonjs/src/compiler/selector-builder.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/metro/index.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/line-height.d.ts +3 -0
- package/dist/typescript/commonjs/src/runtime/native/styles/line-height.d.ts.map +1 -0
- package/dist/typescript/commonjs/src/runtime/native/styles/resolve.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/styles/shorthands/box-shadow.d.ts.map +1 -1
- package/dist/typescript/module/src/babel/index.d.ts +3 -0
- package/dist/typescript/module/src/babel/index.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/atRules.d.ts +1 -1
- package/dist/typescript/module/src/compiler/atRules.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/compiler.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/compiler.types.d.ts +0 -5
- package/dist/typescript/module/src/compiler/compiler.types.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/declarations.d.ts +3 -3
- package/dist/typescript/module/src/compiler/declarations.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/selector-builder.d.ts +1 -1
- package/dist/typescript/module/src/compiler/selector-builder.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/stylesheet.d.ts.map +1 -1
- package/dist/typescript/module/src/metro/index.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/line-height.d.ts +3 -0
- package/dist/typescript/module/src/runtime/native/styles/line-height.d.ts.map +1 -0
- package/dist/typescript/module/src/runtime/native/styles/resolve.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/styles/shorthands/box-shadow.d.ts.map +1 -1
- package/package.json +11 -13
- package/src/babel/index.ts +2 -2
- package/src/compiler/atRules.ts +2 -26
- package/src/compiler/compiler.ts +51 -26
- package/src/compiler/compiler.types.ts +0 -5
- package/src/compiler/declarations.ts +22 -12
- package/src/compiler/selector-builder.ts +7 -5
- package/src/compiler/stylesheet.ts +0 -9
- package/src/metro/index.ts +12 -11
- package/src/runtime/native/styles/calculate-props.ts +4 -0
- package/src/runtime/native/styles/line-height.ts +25 -0
- package/src/runtime/native/styles/resolve.ts +2 -0
- package/src/runtime/native/styles/shorthands/box-shadow.ts +24 -18
- 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)) {
|
package/src/metro/index.ts
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
-
.
|
|
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),
|