@plumeria/compiler 7.0.2 → 7.1.0
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/index.js +280 -320
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -18,18 +18,11 @@ function compileCSS(options) {
|
|
|
18
18
|
const processFile = (filePath) => {
|
|
19
19
|
const source = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
20
20
|
const extractedSheets = [];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
target: 'es2022',
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
console.warn(`Failed to parse ${filePath}:`, err);
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
21
|
+
const ast = (0, core_1.parseSync)(source, {
|
|
22
|
+
syntax: 'typescript',
|
|
23
|
+
tsx: true,
|
|
24
|
+
target: 'es2022',
|
|
25
|
+
});
|
|
33
26
|
const scannedTables = (0, utils_1.scanAll)();
|
|
34
27
|
const localConsts = (0, utils_1.collectLocalConsts)(ast);
|
|
35
28
|
const resourcePath = filePath;
|
|
@@ -149,355 +142,322 @@ function compileCSS(options) {
|
|
|
149
142
|
mergedVariantsTable[key] = importMap[key];
|
|
150
143
|
}
|
|
151
144
|
const localCreateStyles = {};
|
|
152
|
-
(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
145
|
+
const processCall = (node) => {
|
|
146
|
+
node._processed = true;
|
|
147
|
+
const callee = node.callee;
|
|
148
|
+
let propName;
|
|
149
|
+
if (utils_1.t.isMemberExpression(callee) &&
|
|
150
|
+
utils_1.t.isIdentifier(callee.object) &&
|
|
151
|
+
utils_1.t.isIdentifier(callee.property)) {
|
|
152
|
+
const objectName = callee.object.value;
|
|
153
|
+
const propertyName = callee.property.value;
|
|
154
|
+
const alias = plumeriaAliases[objectName];
|
|
155
|
+
if (alias === 'NAMESPACE' || objectName === 'css')
|
|
156
|
+
propName = propertyName;
|
|
157
|
+
}
|
|
158
|
+
else if (utils_1.t.isIdentifier(callee)) {
|
|
159
|
+
const originalName = plumeriaAliases[callee.value];
|
|
160
|
+
if (originalName)
|
|
161
|
+
propName = originalName;
|
|
162
|
+
}
|
|
163
|
+
let localVariantName;
|
|
164
|
+
if (!propName && utils_1.t.isIdentifier(callee)) {
|
|
165
|
+
const varName = callee.value;
|
|
166
|
+
if (localCreateStyles[varName] &&
|
|
167
|
+
localCreateStyles[varName].type === 'variant') {
|
|
168
|
+
localVariantName = varName;
|
|
169
|
+
propName = 'props';
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (propName) {
|
|
173
|
+
const args = node.arguments;
|
|
174
|
+
const extractStylesFromExpression = (expression) => {
|
|
175
|
+
const results = [];
|
|
176
|
+
if (utils_1.t.isObjectExpression(expression)) {
|
|
177
|
+
const object = (0, utils_1.objectExpressionToObject)(expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
178
|
+
if (object)
|
|
179
|
+
results.push(object);
|
|
175
180
|
}
|
|
176
|
-
if (
|
|
177
|
-
|
|
178
|
-
utils_1.t.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
181
|
+
else if (utils_1.t.isMemberExpression(expression)) {
|
|
182
|
+
const memberExpr = expression;
|
|
183
|
+
if (utils_1.t.isIdentifier(memberExpr.object) &&
|
|
184
|
+
utils_1.t.isIdentifier(memberExpr.property)) {
|
|
185
|
+
const variableName = memberExpr.object.value;
|
|
186
|
+
const propertyName = memberExpr.property.value;
|
|
187
|
+
const styleSet = localCreateStyles[variableName];
|
|
188
|
+
if (styleSet && styleSet.obj[propertyName]) {
|
|
189
|
+
results.push(styleSet.obj[propertyName]);
|
|
182
190
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const themeHash = mergedCreateThemeHashTable[name];
|
|
191
|
-
return scannedTables.createAtomicMapTable[themeHash];
|
|
191
|
+
else {
|
|
192
|
+
const hash = mergedCreateTable[variableName];
|
|
193
|
+
if (hash) {
|
|
194
|
+
const object = scannedTables.createObjectTable[hash];
|
|
195
|
+
if (object && object[propertyName]) {
|
|
196
|
+
results.push(object[propertyName]);
|
|
197
|
+
}
|
|
192
198
|
}
|
|
193
|
-
return undefined;
|
|
194
|
-
};
|
|
195
|
-
const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, resolveVariable);
|
|
196
|
-
if (obj) {
|
|
197
|
-
localCreateStyles[node.id.value] = { type: 'create', obj };
|
|
198
|
-
Object.entries(obj).forEach(([_key, style]) => {
|
|
199
|
-
const records = (0, utils_1.getStyleRecords)(style);
|
|
200
|
-
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
201
|
-
records.forEach((r) => {
|
|
202
|
-
extractedSheets.push(r.sheet);
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
199
|
}
|
|
206
200
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
201
|
+
}
|
|
202
|
+
else if (utils_1.t.isIdentifier(expression)) {
|
|
203
|
+
const identifier = expression;
|
|
204
|
+
const object = localCreateStyles[identifier.value];
|
|
205
|
+
if (object)
|
|
206
|
+
results.push(object.obj);
|
|
207
|
+
else {
|
|
208
|
+
const hash = mergedCreateTable[identifier.value];
|
|
209
|
+
if (hash) {
|
|
210
|
+
const objectFromTable = scannedTables.createObjectTable[hash];
|
|
211
|
+
if (objectFromTable)
|
|
212
|
+
results.push(objectFromTable);
|
|
211
213
|
}
|
|
212
214
|
}
|
|
213
|
-
else if (propName === 'createTheme') {
|
|
214
|
-
const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
215
|
-
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
216
|
-
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
217
|
-
scannedTables.createThemeHashTable[uniqueKey] = hash;
|
|
218
|
-
scannedTables.createThemeObjectTable[hash] = obj;
|
|
219
|
-
localCreateStyles[node.id.value] = {
|
|
220
|
-
type: 'create',
|
|
221
|
-
obj: scannedTables.createAtomicMapTable[hash],
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
215
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
let propName;
|
|
230
|
-
if (utils_1.t.isMemberExpression(callee) &&
|
|
231
|
-
utils_1.t.isIdentifier(callee.object) &&
|
|
232
|
-
utils_1.t.isIdentifier(callee.property)) {
|
|
233
|
-
const objectName = callee.object.value;
|
|
234
|
-
const propertyName = callee.property.value;
|
|
235
|
-
const alias = plumeriaAliases[objectName];
|
|
236
|
-
if (alias === 'NAMESPACE' || objectName === 'css') {
|
|
237
|
-
propName = propertyName;
|
|
216
|
+
else if (utils_1.t.isConditionalExpression(expression)) {
|
|
217
|
+
const conditionalExpr = expression;
|
|
218
|
+
results.push(...extractStylesFromExpression(conditionalExpr.consequent));
|
|
219
|
+
results.push(...extractStylesFromExpression(conditionalExpr.alternate));
|
|
238
220
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
propName = originalName;
|
|
221
|
+
else if (utils_1.t.isBinaryExpression(expression) &&
|
|
222
|
+
['&&', '||', '??'].includes(expression.operator)) {
|
|
223
|
+
const binaryExpr = expression;
|
|
224
|
+
results.push(...extractStylesFromExpression(binaryExpr.left));
|
|
225
|
+
results.push(...extractStylesFromExpression(binaryExpr.right));
|
|
245
226
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const hash = mergedCreateTable[varName];
|
|
267
|
-
if (hash) {
|
|
268
|
-
const obj = scannedTables.createObjectTable[hash];
|
|
269
|
-
if (obj && obj[propName]) {
|
|
270
|
-
results.push(obj[propName]);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
else if (utils_1.t.isIdentifier(expr.object) &&
|
|
276
|
-
expr.property.type === 'Computed') {
|
|
277
|
-
return [];
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
else if (utils_1.t.isIdentifier(expr)) {
|
|
281
|
-
const obj = localCreateStyles[expr.value];
|
|
282
|
-
if (obj) {
|
|
283
|
-
results.push(obj.obj);
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
const hash = mergedCreateTable[expr.value];
|
|
287
|
-
if (hash) {
|
|
288
|
-
const obj = scannedTables.createObjectTable[hash];
|
|
289
|
-
if (obj)
|
|
290
|
-
results.push(obj);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
else if (utils_1.t.isConditionalExpression(expr)) {
|
|
295
|
-
results.push(...extractStylesFromExpression(expr.consequent));
|
|
296
|
-
results.push(...extractStylesFromExpression(expr.alternate));
|
|
297
|
-
}
|
|
298
|
-
else if (utils_1.t.isBinaryExpression(expr) &&
|
|
299
|
-
(expr.operator === '&&' ||
|
|
300
|
-
expr.operator === '||' ||
|
|
301
|
-
expr.operator === '??')) {
|
|
302
|
-
results.push(...extractStylesFromExpression(expr.left));
|
|
303
|
-
results.push(...extractStylesFromExpression(expr.right));
|
|
304
|
-
}
|
|
305
|
-
else if (expr.type === 'ParenthesisExpression') {
|
|
306
|
-
results.push(...extractStylesFromExpression(expr.expression));
|
|
307
|
-
}
|
|
308
|
-
return results;
|
|
309
|
-
};
|
|
310
|
-
const processStyle = (style) => {
|
|
311
|
-
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
312
|
-
const records = (0, utils_1.getStyleRecords)(style);
|
|
313
|
-
records.forEach((r) => extractedSheets.push(r.sheet));
|
|
227
|
+
else if (expression.type === 'ParenthesisExpression') {
|
|
228
|
+
const parenExpr = expression;
|
|
229
|
+
results.push(...extractStylesFromExpression(parenExpr.expression));
|
|
230
|
+
}
|
|
231
|
+
return results;
|
|
232
|
+
};
|
|
233
|
+
const processStyle = (style) => {
|
|
234
|
+
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
235
|
+
const records = (0, utils_1.getStyleRecords)(style);
|
|
236
|
+
records.forEach((r) => extractedSheets.push(r.sheet));
|
|
237
|
+
};
|
|
238
|
+
if (propName === 'props') {
|
|
239
|
+
const conditionals = [];
|
|
240
|
+
let groupIdCounter = 0;
|
|
241
|
+
let baseStyle = {};
|
|
242
|
+
const resolveStyleObject = (expression) => {
|
|
243
|
+
const styles = extractStylesFromExpression(expression);
|
|
244
|
+
return styles.length === 1
|
|
245
|
+
? styles[0]
|
|
246
|
+
: null;
|
|
314
247
|
};
|
|
315
|
-
|
|
316
|
-
const
|
|
317
|
-
let
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
};
|
|
325
|
-
for (const arg of args) {
|
|
326
|
-
const expr = arg.expression;
|
|
327
|
-
if (utils_1.t.isCallExpression(expr) && utils_1.t.isIdentifier(expr.callee)) {
|
|
328
|
-
const varName = expr.callee.value;
|
|
329
|
-
let variantObj;
|
|
330
|
-
if (localCreateStyles[varName] &&
|
|
331
|
-
localCreateStyles[varName].type === 'variant') {
|
|
332
|
-
variantObj = localCreateStyles[varName].obj;
|
|
248
|
+
for (const arg of args) {
|
|
249
|
+
const expr = arg.expression;
|
|
250
|
+
let handledAsObjectArg = false;
|
|
251
|
+
if (localVariantName && utils_1.t.isObjectExpression(expr)) {
|
|
252
|
+
const variantObj = localCreateStyles[localVariantName].obj;
|
|
253
|
+
if (variantObj) {
|
|
254
|
+
const props = expr.properties;
|
|
255
|
+
if (variantObj.base && typeof variantObj.base === 'object') {
|
|
256
|
+
baseStyle = (0, utils_1.deepMerge)(baseStyle, variantObj.base);
|
|
333
257
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
258
|
+
const variantsMap = (variantObj.variants ||
|
|
259
|
+
variantObj);
|
|
260
|
+
for (const prop of props) {
|
|
261
|
+
let groupName;
|
|
262
|
+
let valueExpression;
|
|
263
|
+
if (prop.type === 'KeyValueProperty' &&
|
|
264
|
+
prop.key.type === 'Identifier') {
|
|
265
|
+
groupName = prop.key.value;
|
|
266
|
+
valueExpression = prop.value;
|
|
338
267
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
let groupName;
|
|
347
|
-
let valExpr;
|
|
348
|
-
if (prop.type === 'KeyValueProperty' &&
|
|
349
|
-
prop.key.type === 'Identifier') {
|
|
350
|
-
groupName = prop.key.value;
|
|
351
|
-
valExpr = prop.value;
|
|
352
|
-
}
|
|
353
|
-
else if (prop.type === 'Identifier') {
|
|
354
|
-
groupName = prop.value;
|
|
355
|
-
valExpr = prop;
|
|
356
|
-
}
|
|
357
|
-
if (groupName && valExpr) {
|
|
358
|
-
const groupVariants = variantObj[groupName];
|
|
359
|
-
if (!groupVariants)
|
|
360
|
-
continue;
|
|
361
|
-
const currentGroupId = ++groupIdCounter;
|
|
362
|
-
if (valExpr.type === 'StringLiteral') {
|
|
363
|
-
if (groupVariants[valExpr.value]) {
|
|
364
|
-
baseStyle = (0, utils_1.deepMerge)(baseStyle, groupVariants[valExpr.value]);
|
|
365
|
-
}
|
|
366
|
-
continue;
|
|
367
|
-
}
|
|
368
|
-
Object.entries(groupVariants).forEach(([_optionName, style]) => {
|
|
369
|
-
conditionals.push({
|
|
370
|
-
test: valExpr,
|
|
371
|
-
truthy: style,
|
|
372
|
-
falsy: {},
|
|
373
|
-
groupId: currentGroupId,
|
|
374
|
-
});
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
}
|
|
268
|
+
else if (prop.type === 'Identifier') {
|
|
269
|
+
groupName = prop.value;
|
|
270
|
+
valueExpression = prop;
|
|
271
|
+
}
|
|
272
|
+
if (groupName && valueExpression && variantsMap[groupName]) {
|
|
273
|
+
const groupVariants = variantsMap[groupName];
|
|
274
|
+
if (!groupVariants || typeof groupVariants !== 'object')
|
|
378
275
|
continue;
|
|
379
|
-
|
|
380
|
-
if (
|
|
381
|
-
if (
|
|
382
|
-
baseStyle = (0, utils_1.deepMerge)(baseStyle,
|
|
276
|
+
const currentGroupId = ++groupIdCounter;
|
|
277
|
+
if (valueExpression.type === 'StringLiteral') {
|
|
278
|
+
if (groupVariants[valueExpression.value]) {
|
|
279
|
+
baseStyle = (0, utils_1.deepMerge)(baseStyle, groupVariants[valueExpression.value]);
|
|
383
280
|
}
|
|
384
281
|
continue;
|
|
385
282
|
}
|
|
386
|
-
|
|
387
|
-
Object.entries(variantObj).forEach(([_key, style]) => {
|
|
283
|
+
Object.entries(groupVariants).forEach(([optionName, style]) => {
|
|
388
284
|
conditionals.push({
|
|
389
|
-
test:
|
|
285
|
+
test: valueExpression,
|
|
390
286
|
truthy: style,
|
|
391
287
|
falsy: {},
|
|
392
288
|
groupId: currentGroupId,
|
|
289
|
+
groupName: groupName,
|
|
290
|
+
valueName: optionName,
|
|
291
|
+
varName: localVariantName,
|
|
393
292
|
});
|
|
394
293
|
});
|
|
395
|
-
continue;
|
|
396
294
|
}
|
|
397
|
-
break;
|
|
398
295
|
}
|
|
296
|
+
handledAsObjectArg = true;
|
|
399
297
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
298
|
+
}
|
|
299
|
+
if (handledAsObjectArg)
|
|
300
|
+
continue;
|
|
301
|
+
const getSource = (node) => source.substring(node.span.start - ast.span.start, node.span.end - ast.span.start);
|
|
302
|
+
const collectConditions = (node, testStrings = []) => {
|
|
303
|
+
const staticStyle = resolveStyleObject(node);
|
|
304
|
+
if (staticStyle) {
|
|
305
|
+
if (testStrings.length === 0)
|
|
306
|
+
baseStyle = (0, utils_1.deepMerge)(baseStyle, staticStyle);
|
|
307
|
+
else
|
|
403
308
|
conditionals.push({
|
|
404
|
-
test:
|
|
405
|
-
|
|
309
|
+
test: node,
|
|
310
|
+
testString: testStrings.join(' && '),
|
|
311
|
+
truthy: staticStyle,
|
|
406
312
|
falsy: {},
|
|
407
313
|
});
|
|
408
|
-
|
|
409
|
-
}
|
|
314
|
+
return true;
|
|
410
315
|
}
|
|
411
|
-
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
316
|
+
if (node.type === 'ConditionalExpression') {
|
|
317
|
+
const testSource = getSource(node.test);
|
|
318
|
+
collectConditions(node.consequent, [
|
|
319
|
+
...testStrings,
|
|
320
|
+
`(${testSource})`,
|
|
321
|
+
]);
|
|
322
|
+
collectConditions(node.alternate, [
|
|
323
|
+
...testStrings,
|
|
324
|
+
`!(${testSource})`,
|
|
325
|
+
]);
|
|
326
|
+
return true;
|
|
418
327
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
const falsyStyle = resolveStyleObject(expr.alternate);
|
|
427
|
-
if (truthyStyle !== null && falsyStyle !== null) {
|
|
428
|
-
conditionals.push({
|
|
429
|
-
test: expr.test,
|
|
430
|
-
truthy: truthyStyle,
|
|
431
|
-
falsy: falsyStyle,
|
|
432
|
-
});
|
|
433
|
-
continue;
|
|
434
|
-
}
|
|
328
|
+
else if (node.type === 'BinaryExpression' &&
|
|
329
|
+
node.operator === '&&') {
|
|
330
|
+
collectConditions(node.right, [
|
|
331
|
+
...testStrings,
|
|
332
|
+
`(${getSource(node.left)})`,
|
|
333
|
+
]);
|
|
334
|
+
return true;
|
|
435
335
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
styles.forEach(processStyle);
|
|
439
|
-
continue;
|
|
336
|
+
else if (node.type === 'ParenthesisExpression') {
|
|
337
|
+
return collectConditions(node.expression, testStrings);
|
|
440
338
|
}
|
|
339
|
+
return false;
|
|
340
|
+
};
|
|
341
|
+
if (collectConditions(expr))
|
|
342
|
+
continue;
|
|
343
|
+
const extractedStyles = extractStylesFromExpression(expr);
|
|
344
|
+
if (extractedStyles.length > 0) {
|
|
345
|
+
extractedStyles.forEach(processStyle);
|
|
346
|
+
continue;
|
|
441
347
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
348
|
+
}
|
|
349
|
+
if (Object.keys(baseStyle).length > 0) {
|
|
350
|
+
processStyle(baseStyle);
|
|
351
|
+
}
|
|
352
|
+
for (const cond of conditionals) {
|
|
353
|
+
if (cond.truthy && Object.keys(cond.truthy).length > 0) {
|
|
354
|
+
processStyle(cond.truthy);
|
|
445
355
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
for (let i = 0; i < combinations; i++) {
|
|
449
|
-
let currentStyle = { ...baseStyle };
|
|
450
|
-
const seenGroups = new Set();
|
|
451
|
-
let impossible = false;
|
|
452
|
-
for (let j = 0; j < conditionals.length; j++) {
|
|
453
|
-
if ((i >> j) & 1) {
|
|
454
|
-
if (conditionals[j].groupId !== undefined) {
|
|
455
|
-
if (seenGroups.has(conditionals[j].groupId)) {
|
|
456
|
-
impossible = true;
|
|
457
|
-
break;
|
|
458
|
-
}
|
|
459
|
-
seenGroups.add(conditionals[j].groupId);
|
|
460
|
-
}
|
|
461
|
-
currentStyle = (0, utils_1.deepMerge)(currentStyle, conditionals[j].truthy);
|
|
462
|
-
}
|
|
463
|
-
else {
|
|
464
|
-
currentStyle = (0, utils_1.deepMerge)(currentStyle, conditionals[j].falsy);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
if (impossible) {
|
|
468
|
-
continue;
|
|
469
|
-
}
|
|
470
|
-
if (Object.keys(currentStyle).length > 0) {
|
|
471
|
-
processStyle(currentStyle);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
356
|
+
if (cond.falsy && Object.keys(cond.falsy).length > 0) {
|
|
357
|
+
processStyle(cond.falsy);
|
|
474
358
|
}
|
|
475
359
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
360
|
+
}
|
|
361
|
+
else if (propName === 'keyframes' &&
|
|
362
|
+
args.length > 0 &&
|
|
363
|
+
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
364
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
365
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
366
|
+
(0, utils_1.extractOndemandStyles)({ kf: `kf-${hash}` }, extractedSheets, scannedTables);
|
|
367
|
+
scannedTables.keyframesObjectTable[hash] = obj;
|
|
368
|
+
}
|
|
369
|
+
else if (propName === 'viewTransition' &&
|
|
370
|
+
args.length > 0 &&
|
|
371
|
+
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
372
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
373
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
374
|
+
scannedTables.viewTransitionObjectTable[hash] = obj;
|
|
375
|
+
(0, utils_1.extractOndemandStyles)({ vt: `vt-${hash}` }, extractedSheets, scannedTables);
|
|
376
|
+
}
|
|
377
|
+
else if (propName === 'createTheme' &&
|
|
378
|
+
args.length > 0 &&
|
|
379
|
+
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
380
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
381
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
382
|
+
scannedTables.createThemeObjectTable[hash] = obj;
|
|
383
|
+
(0, utils_1.extractOndemandStyles)(obj, extractedSheets, scannedTables);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
const traverseInternal = (node) => {
|
|
388
|
+
if (!node || typeof node !== 'object')
|
|
389
|
+
return;
|
|
390
|
+
if (utils_1.t.isCallExpression(node))
|
|
391
|
+
processCall(node);
|
|
392
|
+
for (const k in node)
|
|
393
|
+
if (k !== 'span' && k !== 'loc')
|
|
394
|
+
traverseInternal(node[k]);
|
|
395
|
+
};
|
|
396
|
+
(0, utils_1.traverse)(ast, {
|
|
397
|
+
VariableDeclarator({ node }) {
|
|
398
|
+
if (utils_1.t.isIdentifier(node.id) &&
|
|
399
|
+
node.init &&
|
|
400
|
+
utils_1.t.isCallExpression(node.init)) {
|
|
401
|
+
const callee = node.init.callee;
|
|
402
|
+
let pName;
|
|
403
|
+
if (utils_1.t.isMemberExpression(callee) &&
|
|
404
|
+
utils_1.t.isIdentifier(callee.object) &&
|
|
405
|
+
utils_1.t.isIdentifier(callee.property)) {
|
|
406
|
+
if (callee.object.value === 'css' ||
|
|
407
|
+
plumeriaAliases[callee.object.value] === 'NAMESPACE')
|
|
408
|
+
pName = callee.property.value;
|
|
483
409
|
}
|
|
484
|
-
else if (
|
|
485
|
-
|
|
486
|
-
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
487
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
488
|
-
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
489
|
-
scannedTables.viewTransitionObjectTable[hash] = obj;
|
|
490
|
-
(0, utils_1.extractOndemandStyles)({ vt: `vt-${hash}` }, extractedSheets, scannedTables);
|
|
410
|
+
else if (utils_1.t.isIdentifier(callee) && plumeriaAliases[callee.value]) {
|
|
411
|
+
pName = plumeriaAliases[callee.value];
|
|
491
412
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
utils_1.t.isObjectExpression(
|
|
495
|
-
const
|
|
496
|
-
const
|
|
497
|
-
|
|
498
|
-
|
|
413
|
+
if (pName &&
|
|
414
|
+
node.init.arguments.length === 1 &&
|
|
415
|
+
utils_1.t.isObjectExpression(node.init.arguments[0].expression)) {
|
|
416
|
+
const arg = node.init.arguments[0].expression;
|
|
417
|
+
const resolveVariable = (name) => localCreateStyles[name]?.obj ||
|
|
418
|
+
(mergedCreateThemeHashTable[name]
|
|
419
|
+
? scannedTables.createAtomicMapTable[mergedCreateThemeHashTable[name]]
|
|
420
|
+
: undefined);
|
|
421
|
+
if (pName === 'create') {
|
|
422
|
+
const obj = (0, utils_1.objectExpressionToObject)(arg, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, resolveVariable);
|
|
423
|
+
if (obj) {
|
|
424
|
+
localCreateStyles[node.id.value] = { type: 'create', obj };
|
|
425
|
+
Object.entries(obj).forEach(([, s]) => {
|
|
426
|
+
(0, utils_1.extractOndemandStyles)(s, extractedSheets, scannedTables);
|
|
427
|
+
(0, utils_1.getStyleRecords)(s).forEach((r) => extractedSheets.push(r.sheet));
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
else if (pName === 'variants') {
|
|
432
|
+
const obj = (0, utils_1.objectExpressionToObject)(arg, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, resolveVariable);
|
|
433
|
+
if (obj)
|
|
434
|
+
localCreateStyles[node.id.value] = { type: 'variant', obj };
|
|
435
|
+
}
|
|
436
|
+
else if (pName === 'createTheme') {
|
|
437
|
+
const obj = (0, utils_1.objectExpressionToObject)(arg, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
438
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
439
|
+
const uKey = `${resourcePath}-${node.id.value}`;
|
|
440
|
+
scannedTables.createThemeHashTable[uKey] = hash;
|
|
441
|
+
scannedTables.createThemeObjectTable[hash] = obj;
|
|
442
|
+
localCreateStyles[node.id.value] = {
|
|
443
|
+
type: 'create',
|
|
444
|
+
obj: scannedTables.createAtomicMapTable[hash],
|
|
445
|
+
};
|
|
446
|
+
}
|
|
499
447
|
}
|
|
500
448
|
}
|
|
449
|
+
if (utils_1.t.isIdentifier(node.id)) {
|
|
450
|
+
if (node.init)
|
|
451
|
+
traverseInternal(node.init);
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
FunctionDeclaration({ node }) {
|
|
455
|
+
if (node.identifier)
|
|
456
|
+
traverseInternal(node.body);
|
|
457
|
+
},
|
|
458
|
+
CallExpression: (path) => {
|
|
459
|
+
if (!path.node._processed)
|
|
460
|
+
processCall(path.node);
|
|
501
461
|
},
|
|
502
462
|
});
|
|
503
463
|
return extractedSheets;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/compiler",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Plumeria swc based compiler for statically extracting css",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dist/"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@plumeria/utils": "^7.0
|
|
24
|
+
"@plumeria/utils": "^7.1.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@swc/core": "1.15.8",
|