@plumeria/utils 18.4.0 → 18.4.1
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/dynamicKey.d.ts +38 -0
- package/dist/dynamicKey.js +173 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -1
- package/dist/parser.js +102 -7
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Expression, ObjectExpression } from '@swc/core';
|
|
2
|
+
import type { CSSObject, StaticTable, KeyframesHashTable, ViewTransitionHashTable, CreateHashTable, CreateThemeHashTable, CreateThemeObjectTable, CreateStaticHashTable, CreateStaticObjectTable, VariantsHashTable } from './types';
|
|
3
|
+
export type NamedParam = {
|
|
4
|
+
key: string;
|
|
5
|
+
local: string;
|
|
6
|
+
};
|
|
7
|
+
export type StyleFunction = {
|
|
8
|
+
params: string[];
|
|
9
|
+
named?: NamedParam[];
|
|
10
|
+
defaults?: Record<string, Expression>;
|
|
11
|
+
body: ObjectExpression;
|
|
12
|
+
};
|
|
13
|
+
export type StyleFunctions = Record<string, StyleFunction>;
|
|
14
|
+
export declare const styleFunctionsOf: (objExpr: ObjectExpression) => StyleFunctions;
|
|
15
|
+
export declare const isUnitlessProp: (prop: string) => boolean;
|
|
16
|
+
export declare const splitVarByUnit: (style: CSSObject, cssVar: string) => Array<{
|
|
17
|
+
cssVar: string;
|
|
18
|
+
prop: string;
|
|
19
|
+
}>;
|
|
20
|
+
export declare const applyVarFallback: (style: CSSObject, cssVar: string, literal: string | number) => void;
|
|
21
|
+
export type DynamicStyleTables = {
|
|
22
|
+
keyframesHashTable: KeyframesHashTable;
|
|
23
|
+
viewTransitionHashTable: ViewTransitionHashTable;
|
|
24
|
+
createThemeHashTable: CreateThemeHashTable;
|
|
25
|
+
createThemeObjectTable: CreateThemeObjectTable;
|
|
26
|
+
createHashTable: CreateHashTable;
|
|
27
|
+
createStaticHashTable: CreateStaticHashTable;
|
|
28
|
+
createStaticObjectTable: CreateStaticObjectTable;
|
|
29
|
+
variantsHashTable: VariantsHashTable;
|
|
30
|
+
};
|
|
31
|
+
export type DynamicStyleResult = {
|
|
32
|
+
style: CSSObject;
|
|
33
|
+
varGroups: Map<string, Array<{
|
|
34
|
+
cssVar: string;
|
|
35
|
+
prop: string;
|
|
36
|
+
}>>;
|
|
37
|
+
};
|
|
38
|
+
export declare const resolveDynamicStyle: (func: StyleFunction, runtimeParams: string[], staticTable: StaticTable, tables: DynamicStyleTables) => DynamicStyleResult | null;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveDynamicStyle = exports.applyVarFallback = exports.splitVarByUnit = exports.isUnitlessProp = exports.styleFunctionsOf = void 0;
|
|
4
|
+
const zss_engine_1 = require("zss-engine");
|
|
5
|
+
const zss_engine_2 = require("zss-engine");
|
|
6
|
+
const parser_1 = require("./parser");
|
|
7
|
+
const namedParamsOf = (params, defaults) => {
|
|
8
|
+
if (params.length !== 1)
|
|
9
|
+
return undefined;
|
|
10
|
+
const first = params[0];
|
|
11
|
+
const pattern = (first?.pat ?? first);
|
|
12
|
+
if (pattern?.type !== 'ObjectPattern')
|
|
13
|
+
return undefined;
|
|
14
|
+
const named = [];
|
|
15
|
+
for (const prop of pattern.properties ?? []) {
|
|
16
|
+
if (prop.type === 'AssignmentPatternProperty' && parser_1.t.isIdentifier(prop.key)) {
|
|
17
|
+
named.push({ key: prop.key.value, local: prop.key.value });
|
|
18
|
+
if (prop.value)
|
|
19
|
+
defaults[prop.key.value] = prop.value;
|
|
20
|
+
}
|
|
21
|
+
else if (prop.type === 'KeyValuePatternProperty' &&
|
|
22
|
+
parser_1.t.isIdentifier(prop.key) &&
|
|
23
|
+
parser_1.t.isIdentifier(prop.value)) {
|
|
24
|
+
named.push({ key: prop.key.value, local: prop.value.value });
|
|
25
|
+
}
|
|
26
|
+
else if (prop.type === 'KeyValuePatternProperty' &&
|
|
27
|
+
parser_1.t.isIdentifier(prop.key) &&
|
|
28
|
+
prop.value?.type === 'AssignmentPattern' &&
|
|
29
|
+
parser_1.t.isIdentifier(prop.value.left)) {
|
|
30
|
+
const pattern = prop.value;
|
|
31
|
+
named.push({ key: String(prop.key.value), local: pattern.left.value });
|
|
32
|
+
defaults[pattern.left.value] = pattern.right;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return named.length > 0 ? named : undefined;
|
|
39
|
+
};
|
|
40
|
+
const styleFunctionsOf = (objExpr) => {
|
|
41
|
+
const styleFunctions = {};
|
|
42
|
+
objExpr.properties.forEach((prop) => {
|
|
43
|
+
if (prop.type !== 'KeyValueProperty' || prop.key.type !== 'Identifier')
|
|
44
|
+
return;
|
|
45
|
+
const func = prop.value;
|
|
46
|
+
if (func.type !== 'ArrowFunctionExpression' &&
|
|
47
|
+
func.type !== 'FunctionExpression')
|
|
48
|
+
return;
|
|
49
|
+
const defaults = {};
|
|
50
|
+
const params = func.params.map((p) => {
|
|
51
|
+
const pattern = typeof p === 'object' && p !== null && 'pat' in p ? p.pat : p;
|
|
52
|
+
if (parser_1.t.isIdentifier(pattern))
|
|
53
|
+
return pattern.value;
|
|
54
|
+
if (pattern?.type === 'AssignmentPattern' &&
|
|
55
|
+
parser_1.t.isIdentifier(pattern.left)) {
|
|
56
|
+
defaults[pattern.left.value] = pattern.right;
|
|
57
|
+
return pattern.left.value;
|
|
58
|
+
}
|
|
59
|
+
return 'arg';
|
|
60
|
+
});
|
|
61
|
+
let actualBody = func.body;
|
|
62
|
+
if (actualBody?.type === 'ParenthesisExpression')
|
|
63
|
+
actualBody = actualBody.expression;
|
|
64
|
+
if (actualBody?.type === 'BlockStatement') {
|
|
65
|
+
const first = actualBody.stmts?.[0];
|
|
66
|
+
if (first?.type === 'ReturnStatement')
|
|
67
|
+
actualBody = first.argument;
|
|
68
|
+
if (actualBody?.type === 'ParenthesisExpression')
|
|
69
|
+
actualBody = actualBody.expression;
|
|
70
|
+
}
|
|
71
|
+
if (actualBody && actualBody.type === 'ObjectExpression') {
|
|
72
|
+
styleFunctions[prop.key.value] = {
|
|
73
|
+
params,
|
|
74
|
+
named: namedParamsOf(func.params, defaults),
|
|
75
|
+
defaults,
|
|
76
|
+
body: actualBody,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return styleFunctions;
|
|
81
|
+
};
|
|
82
|
+
exports.styleFunctionsOf = styleFunctionsOf;
|
|
83
|
+
const isUnitlessProp = (prop) => zss_engine_1.exceptionCamelCase.includes(prop) || prop.startsWith('--');
|
|
84
|
+
exports.isUnitlessProp = isUnitlessProp;
|
|
85
|
+
const collectVarProps = (style, cssVar, props) => {
|
|
86
|
+
const reference = `var(${cssVar})`;
|
|
87
|
+
for (const [prop, value] of Object.entries(style)) {
|
|
88
|
+
if (typeof value === 'string' && value.includes(reference))
|
|
89
|
+
props.push(prop);
|
|
90
|
+
else if (value !== null && typeof value === 'object')
|
|
91
|
+
collectVarProps(value, cssVar, props);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const retargetVar = (style, cssVar, next, unitless) => {
|
|
95
|
+
const reference = `var(${cssVar})`;
|
|
96
|
+
for (const [prop, value] of Object.entries(style)) {
|
|
97
|
+
if (typeof value === 'string' && value.includes(reference)) {
|
|
98
|
+
if ((0, exports.isUnitlessProp)(prop) === unitless)
|
|
99
|
+
style[prop] = value
|
|
100
|
+
.split(reference)
|
|
101
|
+
.join(`var(${next})`);
|
|
102
|
+
}
|
|
103
|
+
else if (value !== null && typeof value === 'object') {
|
|
104
|
+
retargetVar(value, cssVar, next, unitless);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const splitVarByUnit = (style, cssVar) => {
|
|
109
|
+
const props = [];
|
|
110
|
+
collectVarProps(style, cssVar, props);
|
|
111
|
+
if (props.length === 0)
|
|
112
|
+
return [];
|
|
113
|
+
const lead = props[0];
|
|
114
|
+
const split = props.find((prop) => (0, exports.isUnitlessProp)(prop) !== (0, exports.isUnitlessProp)(lead));
|
|
115
|
+
if (!split)
|
|
116
|
+
return [{ cssVar, prop: lead }];
|
|
117
|
+
const splitVar = `${cssVar}-${(0, zss_engine_1.camelToKebabCase)(split).replace(/^-+/, '')}`;
|
|
118
|
+
retargetVar(style, cssVar, splitVar, (0, exports.isUnitlessProp)(split));
|
|
119
|
+
return [
|
|
120
|
+
{ cssVar, prop: lead },
|
|
121
|
+
{ cssVar: splitVar, prop: split },
|
|
122
|
+
];
|
|
123
|
+
};
|
|
124
|
+
exports.splitVarByUnit = splitVarByUnit;
|
|
125
|
+
const applyVarFallback = (style, cssVar, literal) => {
|
|
126
|
+
const reference = `var(${cssVar})`;
|
|
127
|
+
for (const [prop, value] of Object.entries(style)) {
|
|
128
|
+
if (typeof value === 'string' && value.includes(reference)) {
|
|
129
|
+
style[prop] = value
|
|
130
|
+
.split(reference)
|
|
131
|
+
.join(`var(${cssVar}, ${(0, zss_engine_1.applyCssValue)(literal, (0, zss_engine_1.camelToKebabCase)(prop))})`);
|
|
132
|
+
}
|
|
133
|
+
else if (value !== null && typeof value === 'object') {
|
|
134
|
+
(0, exports.applyVarFallback)(value, cssVar, literal);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
exports.applyVarFallback = applyVarFallback;
|
|
139
|
+
const resolveDynamicStyle = (func, runtimeParams, staticTable, tables) => {
|
|
140
|
+
const tempStaticTable = { ...staticTable };
|
|
141
|
+
const resolveBody = () => (0, parser_1.objectExpressionToObject)(func.body, tempStaticTable, tables.keyframesHashTable, tables.viewTransitionHashTable, tables.createThemeHashTable, tables.createThemeObjectTable, tables.createHashTable, tables.createStaticHashTable, tables.createStaticObjectTable, tables.variantsHashTable);
|
|
142
|
+
const withDefault = Object.entries(func.defaults ?? {}).filter(([param]) => tempStaticTable[param] === undefined);
|
|
143
|
+
const cssVars = {};
|
|
144
|
+
const varParams = Array.from(new Set([...runtimeParams, ...withDefault.map(([param]) => param)]));
|
|
145
|
+
if (varParams.length > 0) {
|
|
146
|
+
varParams.forEach((param) => (tempStaticTable[param] = param));
|
|
147
|
+
const hash = (0, zss_engine_2.genBase36Hash)(resolveBody() ?? {}, 1, 8);
|
|
148
|
+
varParams.forEach((param) => {
|
|
149
|
+
const cssVar = `--${hash}-${param}`;
|
|
150
|
+
tempStaticTable[param] = `var(${cssVar})`;
|
|
151
|
+
cssVars[param] = cssVar;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
const style = resolveBody();
|
|
155
|
+
if (!style)
|
|
156
|
+
return null;
|
|
157
|
+
const varGroups = new Map();
|
|
158
|
+
varParams.forEach((param) => {
|
|
159
|
+
const cssVar = cssVars[param];
|
|
160
|
+
if (cssVar)
|
|
161
|
+
varGroups.set(param, (0, exports.splitVarByUnit)(style, cssVar));
|
|
162
|
+
});
|
|
163
|
+
withDefault.forEach(([param, expr]) => {
|
|
164
|
+
const literal = expr.type === 'StringLiteral' || expr.type === 'NumericLiteral'
|
|
165
|
+
? expr.value
|
|
166
|
+
: undefined;
|
|
167
|
+
if (literal === undefined)
|
|
168
|
+
return;
|
|
169
|
+
(varGroups.get(param) ?? []).forEach(({ cssVar }) => (0, exports.applyVarFallback)(style, cssVar, literal));
|
|
170
|
+
});
|
|
171
|
+
return { style, varGroups };
|
|
172
|
+
};
|
|
173
|
+
exports.resolveDynamicStyle = resolveDynamicStyle;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export type { CSSObject, StaticTable, KeyframesHashTable, ViewTransitionHashTabl
|
|
|
2
2
|
export { objectExpressionToObject, collectLocalConsts, traverse, t, getRootIdentifier, extractOndemandStyles, deepMerge, scanAll, resolveFileError, getFileDependencies, resolveExport, resolveComponentKey, resolveThemeSelector, } from './parser';
|
|
3
3
|
export type { StyleRecord } from './create';
|
|
4
4
|
export { getStyleRecords } from './create';
|
|
5
|
+
export type { NamedParam, StyleFunction, StyleFunctions, DynamicStyleTables, DynamicStyleResult, } from './dynamicKey';
|
|
6
|
+
export { styleFunctionsOf, isUnitlessProp, splitVarByUnit, applyVarFallback, resolveDynamicStyle, } from './dynamicKey';
|
|
5
7
|
export type { Specificity } from 'zss-engine';
|
|
6
8
|
export { getSpecificity, getPseudoElement } from 'zss-engine';
|
|
7
9
|
export type { StyleSource } from './escalation';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertPropertyPolicy = exports.resolvePropertyPolicy = exports.DEFAULT_STYLE_PROP = exports.timedAsync = exports.timed = exports.tally = exports.measure = exports.mark = exports.profiling = exports.collectReferenceIdentifiers = exports.getLeadingCommentLength = exports.processVariants = exports.optimizer = exports.resolveImportPath = exports.themeHashOf = exports.getStateWeights = exports.getPseudoElement = exports.getSpecificity = exports.getStyleRecords = exports.resolveThemeSelector = exports.resolveComponentKey = exports.resolveExport = exports.getFileDependencies = exports.resolveFileError = exports.scanAll = exports.deepMerge = exports.extractOndemandStyles = exports.getRootIdentifier = exports.t = exports.traverse = exports.collectLocalConsts = exports.objectExpressionToObject = void 0;
|
|
3
|
+
exports.assertPropertyPolicy = exports.resolvePropertyPolicy = exports.DEFAULT_STYLE_PROP = exports.timedAsync = exports.timed = exports.tally = exports.measure = exports.mark = exports.profiling = exports.collectReferenceIdentifiers = exports.getLeadingCommentLength = exports.processVariants = exports.optimizer = exports.resolveImportPath = exports.themeHashOf = exports.getStateWeights = exports.getPseudoElement = exports.getSpecificity = exports.resolveDynamicStyle = exports.applyVarFallback = exports.splitVarByUnit = exports.isUnitlessProp = exports.styleFunctionsOf = exports.getStyleRecords = exports.resolveThemeSelector = exports.resolveComponentKey = exports.resolveExport = exports.getFileDependencies = exports.resolveFileError = exports.scanAll = exports.deepMerge = exports.extractOndemandStyles = exports.getRootIdentifier = exports.t = exports.traverse = exports.collectLocalConsts = exports.objectExpressionToObject = void 0;
|
|
4
4
|
var parser_1 = require("./parser");
|
|
5
5
|
Object.defineProperty(exports, "objectExpressionToObject", { enumerable: true, get: function () { return parser_1.objectExpressionToObject; } });
|
|
6
6
|
Object.defineProperty(exports, "collectLocalConsts", { enumerable: true, get: function () { return parser_1.collectLocalConsts; } });
|
|
@@ -17,6 +17,12 @@ Object.defineProperty(exports, "resolveComponentKey", { enumerable: true, get: f
|
|
|
17
17
|
Object.defineProperty(exports, "resolveThemeSelector", { enumerable: true, get: function () { return parser_1.resolveThemeSelector; } });
|
|
18
18
|
var create_1 = require("./create");
|
|
19
19
|
Object.defineProperty(exports, "getStyleRecords", { enumerable: true, get: function () { return create_1.getStyleRecords; } });
|
|
20
|
+
var dynamicKey_1 = require("./dynamicKey");
|
|
21
|
+
Object.defineProperty(exports, "styleFunctionsOf", { enumerable: true, get: function () { return dynamicKey_1.styleFunctionsOf; } });
|
|
22
|
+
Object.defineProperty(exports, "isUnitlessProp", { enumerable: true, get: function () { return dynamicKey_1.isUnitlessProp; } });
|
|
23
|
+
Object.defineProperty(exports, "splitVarByUnit", { enumerable: true, get: function () { return dynamicKey_1.splitVarByUnit; } });
|
|
24
|
+
Object.defineProperty(exports, "applyVarFallback", { enumerable: true, get: function () { return dynamicKey_1.applyVarFallback; } });
|
|
25
|
+
Object.defineProperty(exports, "resolveDynamicStyle", { enumerable: true, get: function () { return dynamicKey_1.resolveDynamicStyle; } });
|
|
20
26
|
var zss_engine_1 = require("zss-engine");
|
|
21
27
|
Object.defineProperty(exports, "getSpecificity", { enumerable: true, get: function () { return zss_engine_1.getSpecificity; } });
|
|
22
28
|
Object.defineProperty(exports, "getPseudoElement", { enumerable: true, get: function () { return zss_engine_1.getPseudoElement; } });
|
package/dist/parser.js
CHANGED
|
@@ -53,6 +53,7 @@ const rs = __importStar(require("@rust-gear/glob"));
|
|
|
53
53
|
const zss_engine_1 = require("zss-engine");
|
|
54
54
|
const viewTransition_1 = require("./viewTransition");
|
|
55
55
|
const create_1 = require("./create");
|
|
56
|
+
const dynamicKey_1 = require("./dynamicKey");
|
|
56
57
|
const resolver_1 = require("./resolver");
|
|
57
58
|
const toIdent = (value) => value.replace(/[^A-Za-z0-9-]/g, '');
|
|
58
59
|
const getMarkerVar = (id, pseudo) => {
|
|
@@ -1476,6 +1477,7 @@ function scanAll() {
|
|
|
1476
1477
|
try {
|
|
1477
1478
|
delete fileErrors[entry.filePath];
|
|
1478
1479
|
const { filePath, ast, mtimeMs, localDependencies, localStaticTable, localKeyframesHashTable, localKeyframesObjectTable, localViewTransitionHashTable, localViewTransitionObjectTable, localCreateThemeObjectTable, localCreateThemeSelectorTable, localCreateHashTable, localCreateObjectTable, localCreateAtomicMapTable, localVariantsHashTable, localVariantsObjectTable, localCreateThemeHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, localImports, } = entry;
|
|
1480
|
+
const localCreateFunctionTable = {};
|
|
1479
1481
|
for (const localName of Object.keys(localImports)) {
|
|
1480
1482
|
const { actualPath, importedName } = localImports[localName];
|
|
1481
1483
|
let resolvedKey = `${actualPath}-${importedName}`;
|
|
@@ -1487,27 +1489,118 @@ function scanAll() {
|
|
|
1487
1489
|
if (hash) {
|
|
1488
1490
|
localCreateHashTable[localName] = hash;
|
|
1489
1491
|
}
|
|
1492
|
+
const fnObj = localTables.createFunctionTable[resolvedKey];
|
|
1493
|
+
if (fnObj) {
|
|
1494
|
+
localCreateFunctionTable[localName] = fnObj;
|
|
1495
|
+
}
|
|
1490
1496
|
}
|
|
1497
|
+
const dynamicStyleTables = {
|
|
1498
|
+
keyframesHashTable: localKeyframesHashTable,
|
|
1499
|
+
viewTransitionHashTable: localViewTransitionHashTable,
|
|
1500
|
+
createThemeHashTable: localCreateThemeHashTable,
|
|
1501
|
+
createThemeObjectTable: localTables.createThemeObjectTable,
|
|
1502
|
+
createHashTable: localCreateHashTable,
|
|
1503
|
+
createStaticHashTable: localCreateStaticHashTable,
|
|
1504
|
+
createStaticObjectTable: localTables.createStaticObjectTable,
|
|
1505
|
+
variantsHashTable: localVariantsHashTable,
|
|
1506
|
+
};
|
|
1507
|
+
const dynamicStaticTable = {
|
|
1508
|
+
...localTables.staticTable,
|
|
1509
|
+
...localStaticTable,
|
|
1510
|
+
};
|
|
1511
|
+
const resolveDynamicCallInScan = (expr) => {
|
|
1512
|
+
const callee = expr.callee;
|
|
1513
|
+
if (callee.type !== 'MemberExpression' ||
|
|
1514
|
+
callee.object.type !== 'Identifier' ||
|
|
1515
|
+
callee.property.type !== 'Identifier')
|
|
1516
|
+
return null;
|
|
1517
|
+
const fnObj = localCreateFunctionTable[callee.object.value] ??
|
|
1518
|
+
localTables.createFunctionTable[`${filePath}-${callee.object.value}`];
|
|
1519
|
+
if (!fnObj)
|
|
1520
|
+
return null;
|
|
1521
|
+
const func = (0, dynamicKey_1.styleFunctionsOf)(fnObj)[callee.property.value];
|
|
1522
|
+
if (!func)
|
|
1523
|
+
return null;
|
|
1524
|
+
const callArgs = expr.arguments;
|
|
1525
|
+
if (callArgs.some((a) => a.spread))
|
|
1526
|
+
return null;
|
|
1527
|
+
const runtime = [];
|
|
1528
|
+
if (func.named) {
|
|
1529
|
+
const argExpr = callArgs[0]?.expression;
|
|
1530
|
+
if (callArgs.length > 1 ||
|
|
1531
|
+
(argExpr && argExpr.type !== 'ObjectExpression'))
|
|
1532
|
+
return null;
|
|
1533
|
+
const given = new Set();
|
|
1534
|
+
(argExpr?.properties ?? []).forEach((prop) => {
|
|
1535
|
+
if (prop.type === 'Identifier')
|
|
1536
|
+
given.add(prop.value);
|
|
1537
|
+
else if (prop.type === 'KeyValueProperty' &&
|
|
1538
|
+
(exports.t.isIdentifier(prop.key) || exports.t.isStringLiteral(prop.key)))
|
|
1539
|
+
given.add(String(prop.key.value));
|
|
1540
|
+
});
|
|
1541
|
+
for (const { key, local } of func.named) {
|
|
1542
|
+
if (given.has(key))
|
|
1543
|
+
runtime.push(local);
|
|
1544
|
+
else if (!func.defaults?.[local])
|
|
1545
|
+
return null;
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
else if (callArgs.length === 1 &&
|
|
1549
|
+
callArgs[0].expression.type === 'ObjectExpression') {
|
|
1550
|
+
return null;
|
|
1551
|
+
}
|
|
1552
|
+
else {
|
|
1553
|
+
callArgs.forEach((_, i) => {
|
|
1554
|
+
const param = func.params[i];
|
|
1555
|
+
if (param)
|
|
1556
|
+
runtime.push(param);
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
const resolved = (0, dynamicKey_1.resolveDynamicStyle)(func, runtime, dynamicStaticTable, dynamicStyleTables);
|
|
1560
|
+
if (!resolved)
|
|
1561
|
+
return null;
|
|
1562
|
+
const hasVars = runtime.some((param) => (resolved.varGroups.get(param) ?? []).length > 0);
|
|
1563
|
+
return { style: resolved.style, hasVars };
|
|
1564
|
+
};
|
|
1491
1565
|
const resolveCallStylePropInScan = (expr) => {
|
|
1492
1566
|
if (expr.type === 'ArrayExpression') {
|
|
1493
1567
|
let mergedStyle = {};
|
|
1494
1568
|
const classList = [];
|
|
1495
1569
|
let valid = false;
|
|
1570
|
+
let hasVars = false;
|
|
1496
1571
|
for (const el of expr.elements) {
|
|
1497
1572
|
if (el && el.expression) {
|
|
1498
1573
|
const res = resolveCallStylePropInScan(el.expression);
|
|
1499
|
-
if (res)
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1574
|
+
if (!res)
|
|
1575
|
+
continue;
|
|
1576
|
+
mergedStyle = deepMerge(mergedStyle, res.styleObj);
|
|
1577
|
+
if (res.classString)
|
|
1578
|
+
classList.push(res.classString);
|
|
1579
|
+
if (res.hasVars)
|
|
1580
|
+
hasVars = true;
|
|
1581
|
+
valid = true;
|
|
1505
1582
|
}
|
|
1506
1583
|
}
|
|
1507
1584
|
return valid
|
|
1508
|
-
? {
|
|
1585
|
+
? {
|
|
1586
|
+
classString: classList.join(' '),
|
|
1587
|
+
styleObj: mergedStyle,
|
|
1588
|
+
hasVars,
|
|
1589
|
+
}
|
|
1509
1590
|
: null;
|
|
1510
1591
|
}
|
|
1592
|
+
if (expr.type === 'CallExpression') {
|
|
1593
|
+
const resolved = resolveDynamicCallInScan(expr);
|
|
1594
|
+
if (!resolved)
|
|
1595
|
+
return null;
|
|
1596
|
+
const atomMap = {};
|
|
1597
|
+
(0, create_1.getStyleRecords)(resolved.style).forEach((record) => (atomMap[record.key] = record.hash));
|
|
1598
|
+
return {
|
|
1599
|
+
classString: Object.values(atomMap).join(' '),
|
|
1600
|
+
styleObj: resolved.style,
|
|
1601
|
+
hasVars: resolved.hasVars,
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1511
1604
|
if (expr.type === 'ConditionalExpression') {
|
|
1512
1605
|
if (expr.test.type === 'BooleanLiteral') {
|
|
1513
1606
|
return resolveCallStylePropInScan(expr.test.value ? expr.consequent : expr.alternate);
|
|
@@ -1575,6 +1668,8 @@ function scanAll() {
|
|
|
1575
1668
|
spanStart: node.span.start,
|
|
1576
1669
|
filePath,
|
|
1577
1670
|
};
|
|
1671
|
+
if (resolved.hasVars)
|
|
1672
|
+
entry.hasVars = true;
|
|
1578
1673
|
list.push(entry);
|
|
1579
1674
|
}
|
|
1580
1675
|
};
|
package/dist/types.d.ts
CHANGED