@plumeria/turbopack-loader 10.0.6 → 10.0.8
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 +222 -182
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -75,6 +75,16 @@ async function loader(source) {
|
|
|
75
75
|
extractedSheets.push(sheet);
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
|
+
const processStyleRecords = (style) => {
|
|
79
|
+
const records = (0, utils_1.getStyleRecords)(style);
|
|
80
|
+
if (!isProduction) {
|
|
81
|
+
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
82
|
+
records.forEach((r) => {
|
|
83
|
+
addSheet(r.sheet);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return records;
|
|
87
|
+
};
|
|
78
88
|
const localConsts = (0, utils_1.collectLocalConsts)(ast);
|
|
79
89
|
const importMap = {};
|
|
80
90
|
const createThemeImportMap = {};
|
|
@@ -153,28 +163,40 @@ async function loader(source) {
|
|
|
153
163
|
mergedKeyframesTable[key] = scannedTables.keyframesHashTable[key];
|
|
154
164
|
}
|
|
155
165
|
for (const key of Object.keys(importMap)) {
|
|
156
|
-
|
|
166
|
+
const val = importMap[key];
|
|
167
|
+
if (typeof val === 'string') {
|
|
168
|
+
mergedKeyframesTable[key] = val;
|
|
169
|
+
}
|
|
157
170
|
}
|
|
158
171
|
const mergedViewTransitionTable = {};
|
|
159
172
|
for (const key of Object.keys(scannedTables.viewTransitionHashTable)) {
|
|
160
173
|
mergedViewTransitionTable[key] = scannedTables.viewTransitionHashTable[key];
|
|
161
174
|
}
|
|
162
175
|
for (const key of Object.keys(importMap)) {
|
|
163
|
-
|
|
176
|
+
const val = importMap[key];
|
|
177
|
+
if (typeof val === 'string') {
|
|
178
|
+
mergedViewTransitionTable[key] = val;
|
|
179
|
+
}
|
|
164
180
|
}
|
|
165
181
|
const mergedCreateTable = {};
|
|
166
182
|
for (const key of Object.keys(scannedTables.createHashTable)) {
|
|
167
183
|
mergedCreateTable[key] = scannedTables.createHashTable[key];
|
|
168
184
|
}
|
|
169
185
|
for (const key of Object.keys(importMap)) {
|
|
170
|
-
|
|
186
|
+
const val = importMap[key];
|
|
187
|
+
if (typeof val === 'string') {
|
|
188
|
+
mergedCreateTable[key] = val;
|
|
189
|
+
}
|
|
171
190
|
}
|
|
172
191
|
const mergedVariantsTable = {};
|
|
173
192
|
for (const key of Object.keys(scannedTables.variantsHashTable)) {
|
|
174
193
|
mergedVariantsTable[key] = scannedTables.variantsHashTable[key];
|
|
175
194
|
}
|
|
176
195
|
for (const key of Object.keys(importMap)) {
|
|
177
|
-
|
|
196
|
+
const val = importMap[key];
|
|
197
|
+
if (typeof val === 'string') {
|
|
198
|
+
mergedVariantsTable[key] = val;
|
|
199
|
+
}
|
|
178
200
|
}
|
|
179
201
|
const mergedCreateThemeHashTable = {};
|
|
180
202
|
for (const key of Object.keys(scannedTables.createThemeHashTable)) {
|
|
@@ -206,10 +228,9 @@ async function loader(source) {
|
|
|
206
228
|
const idSpans = new Set();
|
|
207
229
|
const excludedSpans = new Set();
|
|
208
230
|
const checkVariantAssignment = (decl) => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const varName = decl.init.callee.value;
|
|
231
|
+
const init = decl.init;
|
|
232
|
+
if (init && utils_1.t.isCallExpression(init) && utils_1.t.isIdentifier(init.callee)) {
|
|
233
|
+
const varName = init.callee.value;
|
|
213
234
|
if ((localCreateStyles[varName] &&
|
|
214
235
|
localCreateStyles[varName].type === 'variant') ||
|
|
215
236
|
mergedVariantsTable[varName]) {
|
|
@@ -219,11 +240,12 @@ async function loader(source) {
|
|
|
219
240
|
};
|
|
220
241
|
const registerStyle = (node, declSpan, isExported) => {
|
|
221
242
|
let propName;
|
|
243
|
+
const init = node.init;
|
|
222
244
|
if (utils_1.t.isIdentifier(node.id) &&
|
|
223
|
-
|
|
224
|
-
utils_1.t.isCallExpression(
|
|
225
|
-
|
|
226
|
-
const callee =
|
|
245
|
+
init &&
|
|
246
|
+
utils_1.t.isCallExpression(init) &&
|
|
247
|
+
init.arguments.length >= 1) {
|
|
248
|
+
const callee = init.callee;
|
|
227
249
|
if (utils_1.t.isMemberExpression(callee) &&
|
|
228
250
|
utils_1.t.isIdentifier(callee.object) &&
|
|
229
251
|
utils_1.t.isIdentifier(callee.property)) {
|
|
@@ -242,48 +264,41 @@ async function loader(source) {
|
|
|
242
264
|
}
|
|
243
265
|
}
|
|
244
266
|
}
|
|
245
|
-
if (propName) {
|
|
267
|
+
if (propName && init && utils_1.t.isCallExpression(init)) {
|
|
246
268
|
if (propName === 'create' &&
|
|
247
|
-
utils_1.t.isObjectExpression(
|
|
248
|
-
const obj = (0, utils_1.objectExpressionToObject)(
|
|
269
|
+
utils_1.t.isObjectExpression(init.arguments[0].expression)) {
|
|
270
|
+
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
249
271
|
if (obj) {
|
|
250
272
|
const hashMap = {};
|
|
251
273
|
Object.entries(obj).forEach(([key, style]) => {
|
|
252
274
|
if (typeof style !== 'object' || style === null)
|
|
253
275
|
return;
|
|
254
276
|
const records = (0, utils_1.getStyleRecords)(style);
|
|
255
|
-
if (!isProduction) {
|
|
256
|
-
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
257
|
-
records.forEach((r) => {
|
|
258
|
-
addSheet(r.sheet);
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
277
|
const atomMap = {};
|
|
262
278
|
records.forEach((r) => (atomMap[r.key] = r.hash));
|
|
263
279
|
hashMap[key] = atomMap;
|
|
264
280
|
});
|
|
265
|
-
const
|
|
281
|
+
const styleFunctions = {};
|
|
282
|
+
const objExpr = init.arguments[0].expression;
|
|
266
283
|
objExpr.properties.forEach((prop) => {
|
|
267
284
|
if (prop.type !== 'KeyValueProperty' ||
|
|
268
285
|
prop.key.type !== 'Identifier')
|
|
269
286
|
return;
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
287
|
+
const func = prop.value;
|
|
288
|
+
if (func.type !== 'ArrowFunctionExpression' &&
|
|
289
|
+
func.type !== 'FunctionExpression')
|
|
273
290
|
return;
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
params.forEach((paramName, i) => {
|
|
284
|
-
tempStaticTable[paramName] = substitutedArgs[i];
|
|
291
|
+
const params = func.params.map((p) => {
|
|
292
|
+
if (utils_1.t.isIdentifier(p))
|
|
293
|
+
return p.value;
|
|
294
|
+
if (typeof p === 'object' &&
|
|
295
|
+
p !== null &&
|
|
296
|
+
'pat' in p &&
|
|
297
|
+
utils_1.t.isIdentifier(p.pat))
|
|
298
|
+
return p.pat.value;
|
|
299
|
+
return 'arg';
|
|
285
300
|
});
|
|
286
|
-
let actualBody =
|
|
301
|
+
let actualBody = func.body;
|
|
287
302
|
if (actualBody?.type === 'ParenthesisExpression')
|
|
288
303
|
actualBody = actualBody.expression;
|
|
289
304
|
if (actualBody?.type === 'BlockStatement') {
|
|
@@ -293,52 +308,42 @@ async function loader(source) {
|
|
|
293
308
|
if (actualBody?.type === 'ParenthesisExpression')
|
|
294
309
|
actualBody = actualBody.expression;
|
|
295
310
|
}
|
|
296
|
-
if (
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
for (const [, info] of Object.entries(cssVarInfo)) {
|
|
302
|
-
const cssVar = info.cssVar;
|
|
303
|
-
const propKey = Object.keys(substituted).find((k) => typeof substituted[k] === 'string' &&
|
|
304
|
-
substituted[k].includes(cssVar));
|
|
305
|
-
if (propKey) {
|
|
306
|
-
info.propKey = propKey;
|
|
307
|
-
}
|
|
311
|
+
if (actualBody && actualBody.type === 'ObjectExpression') {
|
|
312
|
+
styleFunctions[prop.key.value] = {
|
|
313
|
+
params,
|
|
314
|
+
body: actualBody,
|
|
315
|
+
};
|
|
308
316
|
}
|
|
309
|
-
const records = (0, utils_1.getStyleRecords)(substituted);
|
|
310
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
311
|
-
const atomMap = {};
|
|
312
|
-
records.forEach((r) => (atomMap[r.key] = r.hash));
|
|
313
|
-
atomMap['__cssVars__'] = JSON.stringify(cssVarInfo);
|
|
314
|
-
hashMap[key] = atomMap;
|
|
315
317
|
});
|
|
316
318
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
317
319
|
idSpans.add(node.id.span.start);
|
|
318
320
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
321
|
+
if (utils_1.t.isIdentifier(node.id)) {
|
|
322
|
+
localCreateStyles[node.id.value] = {
|
|
323
|
+
name: node.id.value,
|
|
324
|
+
type: 'create',
|
|
325
|
+
obj,
|
|
326
|
+
hashMap,
|
|
327
|
+
isExported,
|
|
328
|
+
initSpan: {
|
|
329
|
+
start: init.span.start - baseByteOffset,
|
|
330
|
+
end: init.span.end - baseByteOffset,
|
|
331
|
+
},
|
|
332
|
+
declSpan: {
|
|
333
|
+
start: declSpan.start - baseByteOffset,
|
|
334
|
+
end: declSpan.end - baseByteOffset,
|
|
335
|
+
},
|
|
336
|
+
functions: styleFunctions,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
334
339
|
}
|
|
335
340
|
}
|
|
336
341
|
else if (propName === 'variants' &&
|
|
337
|
-
utils_1.t.isObjectExpression(
|
|
342
|
+
utils_1.t.isObjectExpression(init.arguments[0].expression)) {
|
|
338
343
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
339
344
|
idSpans.add(node.id.span.start);
|
|
340
345
|
}
|
|
341
|
-
const obj = (0, utils_1.objectExpressionToObject)(
|
|
346
|
+
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, (name) => {
|
|
342
347
|
if (localCreateStyles[name]) {
|
|
343
348
|
return localCreateStyles[name].obj;
|
|
344
349
|
}
|
|
@@ -351,47 +356,51 @@ async function loader(source) {
|
|
|
351
356
|
return undefined;
|
|
352
357
|
});
|
|
353
358
|
const { hashMap } = (0, utils_1.processVariants)(obj);
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
359
|
+
if (utils_1.t.isIdentifier(node.id)) {
|
|
360
|
+
localCreateStyles[node.id.value] = {
|
|
361
|
+
name: node.id.value,
|
|
362
|
+
type: 'variant',
|
|
363
|
+
obj,
|
|
364
|
+
hashMap,
|
|
365
|
+
isExported,
|
|
366
|
+
initSpan: {
|
|
367
|
+
start: init.span.start - baseByteOffset,
|
|
368
|
+
end: init.span.end - baseByteOffset,
|
|
369
|
+
},
|
|
370
|
+
declSpan: {
|
|
371
|
+
start: declSpan.start - baseByteOffset,
|
|
372
|
+
end: declSpan.end - baseByteOffset,
|
|
373
|
+
},
|
|
374
|
+
};
|
|
375
|
+
}
|
|
369
376
|
}
|
|
370
377
|
else if (propName === 'createTheme' &&
|
|
371
|
-
utils_1.t.isObjectExpression(
|
|
378
|
+
utils_1.t.isObjectExpression(init.arguments[0].expression)) {
|
|
372
379
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
373
380
|
idSpans.add(node.id.span.start);
|
|
374
381
|
}
|
|
375
|
-
const obj = (0, utils_1.objectExpressionToObject)(
|
|
382
|
+
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
376
383
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
384
|
+
if (utils_1.t.isIdentifier(node.id)) {
|
|
385
|
+
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
386
|
+
scannedTables.createThemeHashTable[uniqueKey] = hash;
|
|
387
|
+
scannedTables.createThemeObjectTable[hash] = obj;
|
|
388
|
+
localCreateStyles[node.id.value] = {
|
|
389
|
+
name: node.id.value,
|
|
390
|
+
type: 'constant',
|
|
391
|
+
obj,
|
|
392
|
+
hashMap: scannedTables.createAtomicMapTable[hash],
|
|
393
|
+
isExported,
|
|
394
|
+
initSpan: {
|
|
395
|
+
start: init.span.start - baseByteOffset,
|
|
396
|
+
end: init.span.end - baseByteOffset,
|
|
397
|
+
},
|
|
398
|
+
declSpan: {
|
|
399
|
+
start: declSpan.start - baseByteOffset,
|
|
400
|
+
end: declSpan.end - baseByteOffset,
|
|
401
|
+
},
|
|
402
|
+
};
|
|
403
|
+
}
|
|
395
404
|
}
|
|
396
405
|
}
|
|
397
406
|
};
|
|
@@ -402,7 +411,7 @@ async function loader(source) {
|
|
|
402
411
|
if (specifier.local) {
|
|
403
412
|
excludedSpans.add(specifier.local.span.start);
|
|
404
413
|
}
|
|
405
|
-
if (specifier.imported) {
|
|
414
|
+
if (specifier.type === 'ImportSpecifier' && specifier.imported) {
|
|
406
415
|
excludedSpans.add(specifier.imported.span.start);
|
|
407
416
|
}
|
|
408
417
|
});
|
|
@@ -447,17 +456,18 @@ async function loader(source) {
|
|
|
447
456
|
}
|
|
448
457
|
if (propName) {
|
|
449
458
|
const args = node.arguments;
|
|
450
|
-
if (propName === 'keyframes'
|
|
451
|
-
|
|
452
|
-
utils_1.t.isObjectExpression(
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
459
|
+
if (propName === 'keyframes') {
|
|
460
|
+
const expr = args[0].expression;
|
|
461
|
+
if (utils_1.t.isObjectExpression(expr)) {
|
|
462
|
+
const obj = (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
463
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
464
|
+
scannedTables.keyframesObjectTable[hash] = obj;
|
|
465
|
+
replacements.push({
|
|
466
|
+
start: node.span.start - baseByteOffset,
|
|
467
|
+
end: node.span.end - baseByteOffset,
|
|
468
|
+
content: JSON.stringify(`kf-${hash}`),
|
|
469
|
+
});
|
|
470
|
+
}
|
|
461
471
|
}
|
|
462
472
|
else if (propName === 'viewTransition' &&
|
|
463
473
|
args.length > 0 &&
|
|
@@ -511,8 +521,7 @@ async function loader(source) {
|
|
|
511
521
|
}
|
|
512
522
|
else if (utils_1.t.isMemberExpression(expr) &&
|
|
513
523
|
utils_1.t.isIdentifier(expr.object) &&
|
|
514
|
-
(utils_1.t.isIdentifier(expr.property) ||
|
|
515
|
-
expr.property.type === 'Computed')) {
|
|
524
|
+
(utils_1.t.isIdentifier(expr.property) || expr.property.type === 'Computed')) {
|
|
516
525
|
if (expr.property.type === 'Computed')
|
|
517
526
|
return {};
|
|
518
527
|
const varName = expr.object.value;
|
|
@@ -647,8 +656,9 @@ async function loader(source) {
|
|
|
647
656
|
const currentGroupId = ++groupIdCounter;
|
|
648
657
|
const valSource = getSource(valExpr);
|
|
649
658
|
if (valExpr.type === 'StringLiteral') {
|
|
650
|
-
|
|
651
|
-
|
|
659
|
+
const groupVariantsAsObj = groupVariants;
|
|
660
|
+
if (groupVariantsAsObj[valExpr.value])
|
|
661
|
+
baseStyle = (0, utils_1.deepMerge)(baseStyle, groupVariantsAsObj[valExpr.value]);
|
|
652
662
|
continue;
|
|
653
663
|
}
|
|
654
664
|
Object.entries(groupVariants).forEach(([optionName, style]) => {
|
|
@@ -822,7 +832,7 @@ async function loader(source) {
|
|
|
822
832
|
if (existingClass)
|
|
823
833
|
classParts.push(JSON.stringify(existingClass));
|
|
824
834
|
if (Object.keys(baseIndependent).length > 0) {
|
|
825
|
-
const className = (
|
|
835
|
+
const className = processStyleRecords(baseIndependent)
|
|
826
836
|
.map((r) => r.hash)
|
|
827
837
|
.join(' ');
|
|
828
838
|
if (className)
|
|
@@ -834,7 +844,7 @@ async function loader(source) {
|
|
|
834
844
|
const processBranch = (style) => {
|
|
835
845
|
if (Object.keys(style).length === 0)
|
|
836
846
|
return '""';
|
|
837
|
-
return JSON.stringify((
|
|
847
|
+
return JSON.stringify(processStyleRecords(style)
|
|
838
848
|
.map((r) => r.hash)
|
|
839
849
|
.join(' '));
|
|
840
850
|
};
|
|
@@ -856,7 +866,7 @@ async function loader(source) {
|
|
|
856
866
|
const lookupMap = {};
|
|
857
867
|
options.forEach((opt) => {
|
|
858
868
|
if (opt.valueName && opt.truthy) {
|
|
859
|
-
const className = (
|
|
869
|
+
const className = processStyleRecords(opt.truthy)
|
|
860
870
|
.map((r) => r.hash)
|
|
861
871
|
.join(' ');
|
|
862
872
|
if (className)
|
|
@@ -907,7 +917,7 @@ async function loader(source) {
|
|
|
907
917
|
const results = {};
|
|
908
918
|
const recurse = (dimIndex, currentStyle, keyParts) => {
|
|
909
919
|
if (dimIndex >= dimensions.length) {
|
|
910
|
-
const className = (
|
|
920
|
+
const className = processStyleRecords(currentStyle)
|
|
911
921
|
.map((r) => r.hash)
|
|
912
922
|
.join(' ');
|
|
913
923
|
if (className)
|
|
@@ -921,7 +931,7 @@ async function loader(source) {
|
|
|
921
931
|
};
|
|
922
932
|
recurse(0, baseConflict, []);
|
|
923
933
|
const baseConflictClass = Object.keys(baseConflict).length > 0
|
|
924
|
-
? (
|
|
934
|
+
? processStyleRecords(baseConflict)
|
|
925
935
|
.map((r) => r.hash)
|
|
926
936
|
.join(' ')
|
|
927
937
|
: '';
|
|
@@ -1066,20 +1076,24 @@ async function loader(source) {
|
|
|
1066
1076
|
const expr = node.value.expression;
|
|
1067
1077
|
let args = expr.type === 'ArrayExpression'
|
|
1068
1078
|
? expr.elements
|
|
1069
|
-
.filter(
|
|
1070
|
-
.map((el) => ({ expression: el.expression
|
|
1079
|
+
.filter((el) => el !== undefined)
|
|
1080
|
+
.map((el) => ({ expression: el.expression }))
|
|
1071
1081
|
: [{ expression: expr }];
|
|
1072
1082
|
const dynamicClassParts = [];
|
|
1073
1083
|
const dynamicStyleParts = [];
|
|
1074
1084
|
let attributes = [];
|
|
1075
1085
|
for (const [, attrs] of jsxOpeningElementMap) {
|
|
1076
|
-
const found = attrs
|
|
1086
|
+
const found = attrs
|
|
1087
|
+
.filter((a) => a.type === 'JSXAttribute')
|
|
1088
|
+
.find((a) => a.span.start === node.span.start);
|
|
1077
1089
|
if (found) {
|
|
1078
1090
|
attributes = attrs;
|
|
1079
1091
|
break;
|
|
1080
1092
|
}
|
|
1081
1093
|
}
|
|
1082
|
-
const classNameAttr = attributes.find((attr) => attr.
|
|
1094
|
+
const classNameAttr = attributes.find((attr) => attr.type === 'JSXAttribute' &&
|
|
1095
|
+
attr.name.type === 'Identifier' &&
|
|
1096
|
+
attr.name.value === 'className');
|
|
1083
1097
|
let existingClass = '';
|
|
1084
1098
|
if (classNameAttr?.value?.type === 'StringLiteral') {
|
|
1085
1099
|
existingClass = classNameAttr.value.value;
|
|
@@ -1089,23 +1103,27 @@ async function loader(source) {
|
|
|
1089
1103
|
content: '',
|
|
1090
1104
|
});
|
|
1091
1105
|
}
|
|
1092
|
-
const styleAttrExisting = attributes.find((attr) => attr.
|
|
1106
|
+
const styleAttrExisting = attributes.find((attr) => attr.type === 'JSXAttribute' &&
|
|
1107
|
+
attr.name.type === 'Identifier' &&
|
|
1108
|
+
attr.name.value === 'style');
|
|
1093
1109
|
if (styleAttrExisting) {
|
|
1094
1110
|
replacements.push({
|
|
1095
1111
|
start: styleAttrExisting.span.start - baseByteOffset,
|
|
1096
1112
|
end: styleAttrExisting.span.end - baseByteOffset,
|
|
1097
1113
|
content: '',
|
|
1098
1114
|
});
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1115
|
+
if (styleAttrExisting.value?.type === 'JSXExpressionContainer') {
|
|
1116
|
+
const innerExpr = styleAttrExisting.value?.expression;
|
|
1117
|
+
if (innerExpr?.type === 'ObjectExpression') {
|
|
1118
|
+
const start = innerExpr.span.start - baseByteOffset;
|
|
1119
|
+
const end = innerExpr.span.end - baseByteOffset;
|
|
1120
|
+
const innerSource = sourceBuffer
|
|
1121
|
+
.subarray(start, end)
|
|
1122
|
+
.toString('utf-8');
|
|
1123
|
+
const stripped = innerSource.slice(1, -1).trim();
|
|
1124
|
+
if (stripped)
|
|
1125
|
+
dynamicStyleParts.push(stripped);
|
|
1126
|
+
}
|
|
1109
1127
|
}
|
|
1110
1128
|
}
|
|
1111
1129
|
args = args.filter((arg) => {
|
|
@@ -1118,44 +1136,67 @@ async function loader(source) {
|
|
|
1118
1136
|
const varName = callee.object.value;
|
|
1119
1137
|
const propKey = callee.property.value;
|
|
1120
1138
|
const styleInfo = localCreateStyles[varName];
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1139
|
+
if (styleInfo?.functions?.[propKey]) {
|
|
1140
|
+
const func = styleInfo.functions[propKey];
|
|
1141
|
+
const callArgs = expr.arguments;
|
|
1142
|
+
const tempStaticTable = { ...mergedStaticTable };
|
|
1143
|
+
if (callArgs.length === 1 && !callArgs[0].spread) {
|
|
1144
|
+
const argExpr = callArgs[0].expression;
|
|
1145
|
+
const cssVarInfo = {};
|
|
1146
|
+
if (argExpr.type === 'ObjectExpression') {
|
|
1147
|
+
const argObj = (0, utils_1.objectExpressionToObject)(argExpr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
1148
|
+
func.params.forEach((p) => {
|
|
1149
|
+
if (argObj[p] !== undefined)
|
|
1150
|
+
tempStaticTable[p] = argObj[p];
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
else {
|
|
1154
|
+
func.params.forEach((p) => {
|
|
1155
|
+
const cssVar = `--${propKey}-${p}`;
|
|
1156
|
+
tempStaticTable[p] = `var(${cssVar})`;
|
|
1157
|
+
cssVarInfo[p] = { cssVar, propKey: '' };
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
const substituted = (0, utils_1.objectExpressionToObject)(func.body, tempStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
1161
|
+
if (substituted) {
|
|
1162
|
+
const records = processStyleRecords(substituted);
|
|
1163
|
+
const hashes = records.map((r) => r.hash).join(' ');
|
|
1164
|
+
if (hashes)
|
|
1165
|
+
dynamicClassParts.push(JSON.stringify(hashes));
|
|
1166
|
+
if (Object.keys(cssVarInfo).length > 0) {
|
|
1167
|
+
Object.entries(cssVarInfo).forEach(([_, info]) => {
|
|
1168
|
+
const targetProp = Object.keys(substituted).find((k) => typeof substituted[k] === 'string' &&
|
|
1169
|
+
substituted[k].includes(info.cssVar));
|
|
1170
|
+
if (targetProp) {
|
|
1171
|
+
const argStart = argExpr.span.start - baseByteOffset;
|
|
1172
|
+
const argEnd = argExpr.span.end - baseByteOffset;
|
|
1173
|
+
const argSource = sourceBuffer
|
|
1174
|
+
.subarray(argStart, argEnd)
|
|
1175
|
+
.toString('utf-8');
|
|
1176
|
+
let valueExpr;
|
|
1177
|
+
const maybeNumber = Number(argSource);
|
|
1178
|
+
if (!isNaN(maybeNumber) &&
|
|
1179
|
+
argSource.trim() === String(maybeNumber)) {
|
|
1180
|
+
valueExpr = JSON.stringify((0, zss_engine_1.applyCssValue)(maybeNumber, targetProp));
|
|
1181
|
+
}
|
|
1182
|
+
else if ((argSource.startsWith('"') && argSource.endsWith('"')) ||
|
|
1183
|
+
(argSource.startsWith("'") && argSource.endsWith("'"))) {
|
|
1184
|
+
valueExpr = JSON.stringify((0, zss_engine_1.applyCssValue)(argSource.slice(1, -1), targetProp));
|
|
1185
|
+
}
|
|
1186
|
+
else {
|
|
1187
|
+
valueExpr = zss_engine_1.exceptionCamelCase.includes(targetProp)
|
|
1188
|
+
? argSource
|
|
1189
|
+
: `(typeof ${argSource} === 'number' ? ${argSource} + 'px' : ${argSource})`;
|
|
1190
|
+
}
|
|
1191
|
+
dynamicStyleParts.push(`"${info.cssVar}": ${valueExpr}`);
|
|
1192
|
+
}
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
return false;
|
|
1196
|
+
}
|
|
1155
1197
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
return false;
|
|
1198
|
+
}
|
|
1199
|
+
return true;
|
|
1159
1200
|
});
|
|
1160
1201
|
const styleAttr = dynamicStyleParts.length > 0
|
|
1161
1202
|
? ` style={{${dynamicStyleParts.join(', ')}}}`
|
|
@@ -1213,8 +1254,7 @@ async function loader(source) {
|
|
|
1213
1254
|
const varName = callee.object.value;
|
|
1214
1255
|
const propKey = callee.property.value;
|
|
1215
1256
|
const styleInfo = localCreateStyles[varName];
|
|
1216
|
-
|
|
1217
|
-
if (atomMap?.['__cssVars__']) {
|
|
1257
|
+
if (styleInfo?.functions?.[propKey]) {
|
|
1218
1258
|
throw new Error(`Plumeria: css.use(${getSource(expr)}) does not support dynamic function keys.\n`);
|
|
1219
1259
|
}
|
|
1220
1260
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/turbopack-loader",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.8",
|
|
4
4
|
"description": "Plumeria Turbopack-loader",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"zero-virtual.css"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@plumeria/utils": "^10.0.
|
|
25
|
+
"@plumeria/utils": "^10.0.8"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.21",
|