@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.
Files changed (2) hide show
  1. package/dist/index.js +222 -182
  2. 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
- mergedKeyframesTable[key] = importMap[key];
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
- mergedViewTransitionTable[key] = importMap[key];
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
- mergedCreateTable[key] = importMap[key];
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
- mergedVariantsTable[key] = importMap[key];
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
- if (decl.init &&
210
- utils_1.t.isCallExpression(decl.init) &&
211
- utils_1.t.isIdentifier(decl.init.callee)) {
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
- node.init &&
224
- utils_1.t.isCallExpression(node.init) &&
225
- node.init.arguments.length >= 1) {
226
- const callee = node.init.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(node.init.arguments[0].expression)) {
248
- const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
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 objExpr = node.init.arguments[0].expression;
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 isArrow = prop.value.type === 'ArrowFunctionExpression';
271
- const isFunc = prop.value.type === 'FunctionExpression';
272
- if (!isArrow && !isFunc)
287
+ const func = prop.value;
288
+ if (func.type !== 'ArrowFunctionExpression' &&
289
+ func.type !== 'FunctionExpression')
273
290
  return;
274
- const key = prop.key.value;
275
- const params = prop.value.params.map((p) => p.type === 'Identifier' ? p.value : (p.pat?.value ?? 'arg'));
276
- const cssVarInfo = {};
277
- const tempStaticTable = { ...mergedStaticTable };
278
- const substitutedArgs = params.map((paramName) => {
279
- const cssVar = `--${key}-${paramName}`;
280
- cssVarInfo[paramName] = { cssVar, propKey: '' };
281
- return `var(${cssVar})`;
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 = prop.value.body;
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 (!actualBody || actualBody.type !== 'ObjectExpression')
297
- return;
298
- const substituted = (0, utils_1.objectExpressionToObject)(actualBody, tempStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
299
- if (!substituted)
300
- return;
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
- localCreateStyles[node.id.value] = {
320
- name: node.id.value,
321
- type: 'create',
322
- obj,
323
- hashMap,
324
- isExported,
325
- initSpan: {
326
- start: node.init.span.start - baseByteOffset,
327
- end: node.init.span.end - baseByteOffset,
328
- },
329
- declSpan: {
330
- start: declSpan.start - baseByteOffset,
331
- end: declSpan.end - baseByteOffset,
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(node.init.arguments[0].expression)) {
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)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, (name) => {
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
- localCreateStyles[node.id.value] = {
355
- name: node.id.value,
356
- type: 'variant',
357
- obj,
358
- hashMap,
359
- isExported,
360
- initSpan: {
361
- start: node.init.span.start - baseByteOffset,
362
- end: node.init.span.end - baseByteOffset,
363
- },
364
- declSpan: {
365
- start: declSpan.start - baseByteOffset,
366
- end: declSpan.end - baseByteOffset,
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(node.init.arguments[0].expression)) {
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)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
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
- const uniqueKey = `${resourcePath}-${node.id.value}`;
378
- scannedTables.createThemeHashTable[uniqueKey] = hash;
379
- scannedTables.createThemeObjectTable[hash] = obj;
380
- localCreateStyles[node.id.value] = {
381
- name: node.id.value,
382
- type: 'constant',
383
- obj,
384
- hashMap: scannedTables.createAtomicMapTable[hash],
385
- isExported,
386
- initSpan: {
387
- start: node.init.span.start - baseByteOffset,
388
- end: node.init.span.end - baseByteOffset,
389
- },
390
- declSpan: {
391
- start: declSpan.start - baseByteOffset,
392
- end: declSpan.end - baseByteOffset,
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
- args.length > 0 &&
452
- utils_1.t.isObjectExpression(args[0].expression)) {
453
- const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
454
- const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
455
- scannedTables.keyframesObjectTable[hash] = obj;
456
- replacements.push({
457
- start: node.span.start - baseByteOffset,
458
- end: node.span.end - baseByteOffset,
459
- content: JSON.stringify(`kf-${hash}`),
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
- if (groupVariants[valExpr.value])
651
- baseStyle = (0, utils_1.deepMerge)(baseStyle, groupVariants[valExpr.value]);
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 = (0, utils_1.getStyleRecords)(baseIndependent)
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((0, utils_1.getStyleRecords)(style)
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 = (0, utils_1.getStyleRecords)(opt.truthy)
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 = (0, utils_1.getStyleRecords)(currentStyle)
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
- ? (0, utils_1.getStyleRecords)(baseConflict)
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(Boolean)
1070
- .map((el) => ({ expression: el.expression ?? el }))
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.find((a) => a.span?.start === node.span.start);
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.name?.value === 'className');
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.name?.value === 'style');
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
- const innerExpr = styleAttrExisting.value?.expression;
1100
- if (innerExpr?.type === 'ObjectExpression') {
1101
- const start = innerExpr.span.start - baseByteOffset;
1102
- const end = innerExpr.span.end - baseByteOffset;
1103
- const innerSource = sourceBuffer
1104
- .subarray(start, end)
1105
- .toString('utf-8');
1106
- const stripped = innerSource.slice(1, -1).trim();
1107
- if (stripped)
1108
- dynamicStyleParts.push(stripped);
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
- const atomMap = styleInfo?.hashMap?.[propKey];
1122
- if (!atomMap?.['__cssVars__'])
1123
- return true;
1124
- const cssVarInfo = JSON.parse(atomMap['__cssVars__']);
1125
- const hashes = Object.entries(atomMap)
1126
- .filter(([k]) => k !== '__cssVars__')
1127
- .map(([, v]) => v)
1128
- .join(' ');
1129
- if (hashes)
1130
- dynamicClassParts.push(JSON.stringify(hashes));
1131
- const callArgs = expr.arguments;
1132
- Object.entries(cssVarInfo).forEach(([_, { cssVar, propKey: targetProp }], i) => {
1133
- const callArg = callArgs[i];
1134
- if (!callArg)
1135
- return;
1136
- const argStart = callArg.expression.span.start - baseByteOffset;
1137
- const argEnd = callArg.expression.span.end - baseByteOffset;
1138
- const argSource = sourceBuffer
1139
- .subarray(argStart, argEnd)
1140
- .toString('utf-8');
1141
- let valueExpr;
1142
- const maybeNumber = Number(argSource);
1143
- if (!isNaN(maybeNumber) &&
1144
- argSource.trim() === String(maybeNumber)) {
1145
- valueExpr = JSON.stringify((0, zss_engine_1.applyCssValue)(maybeNumber, targetProp));
1146
- }
1147
- else if ((argSource.startsWith('"') && argSource.endsWith('"')) ||
1148
- (argSource.startsWith("'") && argSource.endsWith("'"))) {
1149
- valueExpr = JSON.stringify((0, zss_engine_1.applyCssValue)(argSource.slice(1, -1), targetProp));
1150
- }
1151
- else {
1152
- valueExpr = zss_engine_1.exceptionCamelCase.includes(targetProp)
1153
- ? argSource
1154
- : `(typeof ${argSource} === 'number' ? ${argSource} + 'px' : ${argSource})`;
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
- dynamicStyleParts.push(`"${cssVar}": ${valueExpr}`);
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
- const atomMap = styleInfo?.hashMap?.[propKey];
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.6",
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.6"
25
+ "@plumeria/utils": "^10.0.8"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@swc/core": "1.15.21",