@plumeria/unplugin 11.1.3 → 11.2.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/core.js CHANGED
@@ -290,6 +290,325 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
290
290
  const processedDecls = new Set();
291
291
  const idSpans = new Set();
292
292
  const excludedSpans = new Set();
293
+ const checkVariantAssignment = (decl) => {
294
+ const init = decl.init;
295
+ if (init && utils_1.t.isCallExpression(init) && utils_1.t.isIdentifier(init.callee)) {
296
+ const varName = init.callee.value;
297
+ if ((localCreateStyles[varName] &&
298
+ localCreateStyles[varName].type === 'variant') ||
299
+ mergedVariantsTable[varName]) {
300
+ throw new Error(`Plumeria: Assigning the return value of "css.variants" to a variable is not supported.\nPlease pass the variant function directly to "css.use". Found assignment to: ${utils_1.t.isIdentifier(decl.id) ? decl.id.value : 'unknown'}`);
301
+ }
302
+ }
303
+ };
304
+ const registerStyle = (node, declSpan, isExported) => {
305
+ let propName;
306
+ const init = node.init;
307
+ if (utils_1.t.isIdentifier(node.id) &&
308
+ init &&
309
+ utils_1.t.isCallExpression(init) &&
310
+ init.arguments.length >= 1) {
311
+ const callee = init.callee;
312
+ if (utils_1.t.isMemberExpression(callee) &&
313
+ utils_1.t.isIdentifier(callee.object) &&
314
+ utils_1.t.isIdentifier(callee.property)) {
315
+ const objectName = callee.object.value;
316
+ const propertyName = callee.property.value;
317
+ const alias = plumeriaAliases[objectName];
318
+ if (alias === 'NAMESPACE') {
319
+ propName = propertyName;
320
+ }
321
+ }
322
+ else if (utils_1.t.isIdentifier(callee)) {
323
+ const calleeName = callee.value;
324
+ const originalName = plumeriaAliases[calleeName];
325
+ if (originalName) {
326
+ propName = originalName;
327
+ }
328
+ }
329
+ }
330
+ if (propName && init && utils_1.t.isCallExpression(init)) {
331
+ if (propName === 'create' &&
332
+ utils_1.t.isObjectExpression(init.arguments[0].expression)) {
333
+ const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
334
+ if (obj) {
335
+ const hashMap = {};
336
+ Object.entries(obj).forEach(([key, style]) => {
337
+ if (typeof style !== 'object' || style === null)
338
+ return;
339
+ const records = (0, utils_1.getStyleRecords)(style);
340
+ const atomMap = {};
341
+ records.forEach((r) => (atomMap[r.key] = r.hash));
342
+ hashMap[key] = atomMap;
343
+ });
344
+ const styleFunctions = {};
345
+ const objExpr = init.arguments[0].expression;
346
+ objExpr.properties.forEach((prop) => {
347
+ if (prop.type !== 'KeyValueProperty' ||
348
+ prop.key.type !== 'Identifier')
349
+ return;
350
+ const func = prop.value;
351
+ if (func.type !== 'ArrowFunctionExpression' &&
352
+ func.type !== 'FunctionExpression')
353
+ return;
354
+ const params = func.params.map((p) => {
355
+ if (utils_1.t.isIdentifier(p))
356
+ return p.value;
357
+ if (typeof p === 'object' &&
358
+ p !== null &&
359
+ 'pat' in p &&
360
+ utils_1.t.isIdentifier(p.pat))
361
+ return p.pat.value;
362
+ return 'arg';
363
+ });
364
+ let actualBody = func.body;
365
+ if (actualBody?.type === 'ParenthesisExpression')
366
+ actualBody = actualBody.expression;
367
+ if (actualBody?.type === 'BlockStatement') {
368
+ const first = actualBody.stmts?.[0];
369
+ if (first?.type === 'ReturnStatement')
370
+ actualBody = first.argument;
371
+ if (actualBody?.type === 'ParenthesisExpression')
372
+ actualBody = actualBody.expression;
373
+ }
374
+ if (actualBody && actualBody.type === 'ObjectExpression') {
375
+ styleFunctions[prop.key.value] = {
376
+ params,
377
+ body: actualBody,
378
+ };
379
+ }
380
+ });
381
+ if (utils_1.t.isIdentifier(node.id)) {
382
+ idSpans.add(node.id.span.start);
383
+ }
384
+ if (utils_1.t.isIdentifier(node.id)) {
385
+ localCreateStyles[node.id.value] = {
386
+ name: node.id.value,
387
+ type: 'create',
388
+ obj,
389
+ hashMap,
390
+ isExported,
391
+ initSpan: {
392
+ start: init.span.start - baseByteOffset,
393
+ end: init.span.end - baseByteOffset,
394
+ },
395
+ declSpan: {
396
+ start: declSpan.start - baseByteOffset,
397
+ end: declSpan.end - baseByteOffset,
398
+ },
399
+ functions: styleFunctions,
400
+ };
401
+ }
402
+ }
403
+ }
404
+ else if (propName === 'variants' &&
405
+ utils_1.t.isObjectExpression(init.arguments[0].expression)) {
406
+ if (utils_1.t.isIdentifier(node.id)) {
407
+ idSpans.add(node.id.span.start);
408
+ }
409
+ const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, (name) => {
410
+ if (localCreateStyles[name]) {
411
+ return localCreateStyles[name].obj;
412
+ }
413
+ if (mergedCreateTable[name]) {
414
+ const hash = mergedCreateTable[name];
415
+ if (scannedTables.createObjectTable[hash]) {
416
+ return scannedTables.createObjectTable[hash];
417
+ }
418
+ }
419
+ return undefined;
420
+ });
421
+ const { hashMap } = (0, utils_1.processVariants)(obj);
422
+ if (utils_1.t.isIdentifier(node.id)) {
423
+ localCreateStyles[node.id.value] = {
424
+ name: node.id.value,
425
+ type: 'variant',
426
+ obj,
427
+ hashMap,
428
+ isExported,
429
+ initSpan: {
430
+ start: init.span.start - baseByteOffset,
431
+ end: init.span.end - baseByteOffset,
432
+ },
433
+ declSpan: {
434
+ start: declSpan.start - baseByteOffset,
435
+ end: declSpan.end - baseByteOffset,
436
+ },
437
+ };
438
+ }
439
+ }
440
+ else if (propName === 'createTheme' &&
441
+ utils_1.t.isObjectExpression(init.arguments[0].expression)) {
442
+ if (utils_1.t.isIdentifier(node.id)) {
443
+ idSpans.add(node.id.span.start);
444
+ }
445
+ const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
446
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
447
+ if (utils_1.t.isIdentifier(node.id)) {
448
+ const uniqueKey = `${resourcePath}-${node.id.value}`;
449
+ scannedTables.createThemeHashTable[uniqueKey] = hash;
450
+ scannedTables.createThemeObjectTable[hash] = obj;
451
+ mergedCreateThemeHashTable[node.id.value] = hash;
452
+ const themeHashMap = {};
453
+ for (const [key] of Object.entries(obj)) {
454
+ const cssVarName = (0, zss_engine_1.camelToKebabCase)(key);
455
+ themeHashMap[key] = `var(--${hash}-${cssVarName})`;
456
+ }
457
+ localCreateStyles[node.id.value] = {
458
+ name: node.id.value,
459
+ type: 'constant',
460
+ obj,
461
+ hashMap: themeHashMap,
462
+ isExported,
463
+ initSpan: {
464
+ start: init.span.start - baseByteOffset,
465
+ end: init.span.end - baseByteOffset,
466
+ },
467
+ declSpan: {
468
+ start: declSpan.start - baseByteOffset,
469
+ end: declSpan.end - baseByteOffset,
470
+ },
471
+ };
472
+ }
473
+ }
474
+ }
475
+ };
476
+ (0, utils_1.traverse)(ast, {
477
+ ImportDeclaration({ node }) {
478
+ if (node.source.value === '@plumeria/core') {
479
+ if (node.typeOnly)
480
+ return;
481
+ const typeOnlySpecs = node.specifiers.filter((s) => s.type === 'ImportSpecifier' && s.isTypeOnly);
482
+ if (typeOnlySpecs.length > 0) {
483
+ const names = typeOnlySpecs
484
+ .map((s) => {
485
+ if (s.type !== 'ImportSpecifier')
486
+ return;
487
+ const imported = s.imported
488
+ ? s.imported.value
489
+ : s.local.value;
490
+ const local = s.local.value;
491
+ return imported === local
492
+ ? imported
493
+ : `${imported} as ${local}`;
494
+ })
495
+ .join(', ');
496
+ replacements.push({
497
+ start: node.span.start - baseByteOffset,
498
+ end: node.span.end - baseByteOffset,
499
+ content: `import type { ${names} } from '@plumeria/core'`,
500
+ });
501
+ }
502
+ else {
503
+ replacements.push({
504
+ start: node.span.start - baseByteOffset,
505
+ end: node.span.end - baseByteOffset,
506
+ content: '',
507
+ });
508
+ }
509
+ }
510
+ node.specifiers.forEach((specifier) => {
511
+ if (specifier.local) {
512
+ excludedSpans.add(specifier.local.span.start);
513
+ }
514
+ if (specifier.type === 'ImportSpecifier' && specifier.imported) {
515
+ excludedSpans.add(specifier.imported.span.start);
516
+ }
517
+ });
518
+ },
519
+ ExportDeclaration({ node }) {
520
+ if (utils_1.t.isVariableDeclaration(node.declaration)) {
521
+ processedDecls.add(node.declaration);
522
+ node.declaration.declarations.forEach((decl) => {
523
+ checkVariantAssignment(decl);
524
+ registerStyle(decl, node.span, true);
525
+ });
526
+ }
527
+ },
528
+ VariableDeclaration({ node }) {
529
+ if (processedDecls.has(node))
530
+ return;
531
+ node.declarations.forEach((decl) => {
532
+ checkVariantAssignment(decl);
533
+ registerStyle(decl, node.span, false);
534
+ });
535
+ },
536
+ CallExpression({ node }) {
537
+ const callee = node.callee;
538
+ let propName;
539
+ if (utils_1.t.isMemberExpression(callee) &&
540
+ utils_1.t.isIdentifier(callee.object) &&
541
+ utils_1.t.isIdentifier(callee.property)) {
542
+ const objectName = callee.object.value;
543
+ const propertyName = callee.property.value;
544
+ const alias = plumeriaAliases[objectName];
545
+ if (alias === 'NAMESPACE') {
546
+ propName = propertyName;
547
+ }
548
+ }
549
+ else if (utils_1.t.isIdentifier(callee)) {
550
+ const calleeName = callee.value;
551
+ const originalName = plumeriaAliases[calleeName];
552
+ if (originalName) {
553
+ propName = originalName;
554
+ }
555
+ }
556
+ if (propName) {
557
+ const args = node.arguments;
558
+ if (propName === 'keyframes') {
559
+ const expr = args[0].expression;
560
+ if (utils_1.t.isObjectExpression(expr)) {
561
+ const obj = (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
562
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
563
+ scannedTables.keyframesObjectTable[hash] = obj;
564
+ replacements.push({
565
+ start: node.span.start - baseByteOffset,
566
+ end: node.span.end - baseByteOffset,
567
+ content: JSON.stringify(`kf-${hash}`),
568
+ });
569
+ }
570
+ }
571
+ else if (propName === 'viewTransition' &&
572
+ args.length > 0 &&
573
+ utils_1.t.isObjectExpression(args[0].expression)) {
574
+ const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
575
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
576
+ scannedTables.viewTransitionObjectTable[hash] = obj;
577
+ replacements.push({
578
+ start: node.span.start - baseByteOffset,
579
+ end: node.span.end - baseByteOffset,
580
+ content: JSON.stringify(`vt-${hash}`),
581
+ });
582
+ }
583
+ else if ((propName === 'createTheme' || propName === 'createStatic') &&
584
+ args.length > 0 &&
585
+ utils_1.t.isObjectExpression(args[0].expression)) {
586
+ const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
587
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
588
+ if (propName === 'createTheme') {
589
+ scannedTables.createThemeObjectTable[hash] = obj;
590
+ }
591
+ else {
592
+ scannedTables.createStaticObjectTable[hash] = obj;
593
+ }
594
+ const prefix = propName === 'createTheme' ? 'tm-' : 'st-';
595
+ replacements.push({
596
+ start: node.span.start - baseByteOffset,
597
+ end: node.span.end - baseByteOffset,
598
+ content: JSON.stringify(`${prefix}${hash}`),
599
+ });
600
+ }
601
+ else if (propName === 'create' &&
602
+ args.length > 0 &&
603
+ utils_1.t.isObjectExpression(args[0].expression)) {
604
+ const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
605
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
606
+ scannedTables.createObjectTable[hash] = obj;
607
+ }
608
+ }
609
+ },
610
+ });
611
+ const jsxOpeningElementMap = new Map();
293
612
  const getSource = (node) => {
294
613
  const start = node.span.start - baseByteOffset;
295
614
  const end = node.span.end - baseByteOffset;
@@ -416,9 +735,9 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
416
735
  if (variantObj) {
417
736
  const callArgs = expr.arguments;
418
737
  if (callArgs.length === 1 && !callArgs[0].spread) {
419
- const innerArg = callArgs[0].expression;
420
- if (innerArg.type === 'ObjectExpression') {
421
- for (const prop of innerArg.properties) {
738
+ const arg = callArgs[0].expression;
739
+ if (arg.type === 'ObjectExpression') {
740
+ for (const prop of arg.properties) {
422
741
  let groupName;
423
742
  let valExpr;
424
743
  if (prop.type === 'KeyValueProperty' &&
@@ -459,16 +778,16 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
459
778
  }
460
779
  continue;
461
780
  }
462
- const argSource = getSource(innerArg);
463
- if (utils_1.t.isStringLiteral(innerArg)) {
464
- if (variantObj[innerArg.value])
465
- baseStyle = (0, utils_1.deepMerge)(baseStyle, variantObj[innerArg.value]);
781
+ const argSource = getSource(arg);
782
+ if (utils_1.t.isStringLiteral(arg)) {
783
+ if (variantObj[arg.value])
784
+ baseStyle = (0, utils_1.deepMerge)(baseStyle, variantObj[arg.value]);
466
785
  continue;
467
786
  }
468
787
  const currentGroupId = ++groupIdCounter;
469
788
  Object.entries(variantObj).forEach(([key, style]) => {
470
789
  conditionals.push({
471
- test: innerArg,
790
+ test: arg,
472
791
  testLHS: argSource,
473
792
  testString: `${argSource} === '${key}'`,
474
793
  truthy: style,
@@ -644,10 +963,12 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
644
963
  indepVarGroups[c.groupId].push(c);
645
964
  }
646
965
  });
647
- Object.values(indepVarGroups).forEach((opts) => {
648
- const commonTestExpr = opts[0].testLHS ?? opts[0].testString ?? getSource(opts[0].test);
966
+ Object.values(indepVarGroups).forEach((options) => {
967
+ const commonTestExpr = options[0].testLHS ??
968
+ options[0].testString ??
969
+ getSource(options[0].test);
649
970
  const lookupMap = {};
650
- opts.forEach((opt) => {
971
+ options.forEach((opt) => {
651
972
  if (opt.valueName && opt.truthy) {
652
973
  const className = processStyleRecords(opt.truthy)
653
974
  .map((r) => r.hash)
@@ -730,193 +1051,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
730
1051
  classParts.push(...dynamicClassParts);
731
1052
  return { classParts, isOptimizable, baseStyle };
732
1053
  };
733
- const registerStyle = (node, declSpan, isExported) => {
734
- let propName;
735
- const init = node.init;
736
- if (utils_1.t.isIdentifier(node.id) &&
737
- init &&
738
- utils_1.t.isCallExpression(init) &&
739
- init.arguments.length >= 1) {
740
- const callee = init.callee;
741
- if (utils_1.t.isMemberExpression(callee) &&
742
- utils_1.t.isIdentifier(callee.object) &&
743
- utils_1.t.isIdentifier(callee.property)) {
744
- const objectName = callee.object.value;
745
- const propertyName = callee.property.value;
746
- const alias = plumeriaAliases[objectName];
747
- if (alias === 'NAMESPACE')
748
- propName = propertyName;
749
- }
750
- else if (utils_1.t.isIdentifier(callee)) {
751
- const calleeName = callee.value;
752
- const originalName = plumeriaAliases[calleeName];
753
- if (originalName)
754
- propName = originalName;
755
- }
756
- }
757
- if (propName && init && utils_1.t.isCallExpression(init)) {
758
- if (propName === 'create' &&
759
- utils_1.t.isObjectExpression(init.arguments[0].expression)) {
760
- const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
761
- if (obj) {
762
- const hashMap = {};
763
- Object.entries(obj).forEach(([key, style]) => {
764
- if (typeof style !== 'object' || style === null)
765
- return;
766
- const records = (0, utils_1.getStyleRecords)(style);
767
- const atomMap = {};
768
- records.forEach((r) => (atomMap[r.key] = r.hash));
769
- hashMap[key] = atomMap;
770
- });
771
- const styleFunctions = {};
772
- const objExpr = init.arguments[0].expression;
773
- objExpr.properties.forEach((prop) => {
774
- if (prop.type !== 'KeyValueProperty' ||
775
- prop.key.type !== 'Identifier')
776
- return;
777
- const func = prop.value;
778
- if (func.type !== 'ArrowFunctionExpression' &&
779
- func.type !== 'FunctionExpression')
780
- return;
781
- const params = func.params.map((p) => {
782
- if (utils_1.t.isIdentifier(p))
783
- return p.value;
784
- if (typeof p === 'object' &&
785
- p !== null &&
786
- 'pat' in p &&
787
- utils_1.t.isIdentifier(p.pat))
788
- return p.pat.value;
789
- return 'arg';
790
- });
791
- let actualBody = func.body;
792
- if (actualBody?.type === 'ParenthesisExpression')
793
- actualBody = actualBody.expression;
794
- if (actualBody?.type === 'BlockStatement') {
795
- const first = actualBody.stmts?.[0];
796
- if (first?.type === 'ReturnStatement')
797
- actualBody = first.argument;
798
- if (actualBody?.type === 'ParenthesisExpression')
799
- actualBody = actualBody.expression;
800
- }
801
- if (actualBody && actualBody.type === 'ObjectExpression') {
802
- styleFunctions[prop.key.value] = {
803
- params,
804
- body: actualBody,
805
- };
806
- }
807
- });
808
- if (utils_1.t.isIdentifier(node.id)) {
809
- idSpans.add(node.id.span.start);
810
- localCreateStyles[node.id.value] = {
811
- name: node.id.value,
812
- type: 'create',
813
- obj,
814
- hashMap,
815
- isExported,
816
- initSpan: {
817
- start: init.span.start - baseByteOffset,
818
- end: init.span.end - baseByteOffset,
819
- },
820
- declSpan: {
821
- start: declSpan.start - baseByteOffset,
822
- end: declSpan.end - baseByteOffset,
823
- },
824
- functions: styleFunctions,
825
- };
826
- }
827
- }
828
- }
829
- else if (propName === 'variants' &&
830
- utils_1.t.isObjectExpression(init.arguments[0].expression)) {
831
- if (utils_1.t.isIdentifier(node.id))
832
- idSpans.add(node.id.span.start);
833
- const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, (name) => {
834
- if (localCreateStyles[name])
835
- return localCreateStyles[name].obj;
836
- if (mergedCreateTable[name]) {
837
- const hash = mergedCreateTable[name];
838
- if (scannedTables.createObjectTable[hash])
839
- return scannedTables.createObjectTable[hash];
840
- }
841
- return undefined;
842
- });
843
- const { hashMap } = (0, utils_1.processVariants)(obj);
844
- if (utils_1.t.isIdentifier(node.id)) {
845
- localCreateStyles[node.id.value] = {
846
- name: node.id.value,
847
- type: 'variant',
848
- obj,
849
- hashMap,
850
- isExported,
851
- initSpan: {
852
- start: init.span.start - baseByteOffset,
853
- end: init.span.end - baseByteOffset,
854
- },
855
- declSpan: {
856
- start: declSpan.start - baseByteOffset,
857
- end: declSpan.end - baseByteOffset,
858
- },
859
- };
860
- }
861
- }
862
- else if (propName === 'createTheme' &&
863
- utils_1.t.isObjectExpression(init.arguments[0].expression)) {
864
- if (utils_1.t.isIdentifier(node.id))
865
- idSpans.add(node.id.span.start);
866
- const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
867
- const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
868
- if (utils_1.t.isIdentifier(node.id)) {
869
- const uniqueKey = `${resourcePath}-${node.id.value}`;
870
- scannedTables.createThemeHashTable[uniqueKey] = hash;
871
- scannedTables.createThemeObjectTable[hash] = obj;
872
- mergedCreateThemeHashTable[node.id.value] = hash;
873
- const themeHashMap = {};
874
- for (const [key] of Object.entries(obj)) {
875
- const cssVarName = (0, zss_engine_1.camelToKebabCase)(key);
876
- themeHashMap[key] = `var(--${hash}-${cssVarName})`;
877
- }
878
- localCreateStyles[node.id.value] = {
879
- name: node.id.value,
880
- type: 'constant',
881
- obj,
882
- hashMap: themeHashMap,
883
- isExported,
884
- initSpan: {
885
- start: init.span.start - baseByteOffset,
886
- end: init.span.end - baseByteOffset,
887
- },
888
- declSpan: {
889
- start: declSpan.start - baseByteOffset,
890
- end: declSpan.end - baseByteOffset,
891
- },
892
- };
893
- }
894
- }
895
- }
896
- };
897
- const jsxOpeningElementMap = new Map();
898
1054
  (0, utils_1.traverse)(ast, {
899
- ImportDeclaration({ node }) {
900
- if (node.specifiers) {
901
- node.specifiers.forEach((specifier) => {
902
- if (specifier.local)
903
- excludedSpans.add(specifier.local.span.start);
904
- if (specifier.type === 'ImportSpecifier' && specifier.imported)
905
- excludedSpans.add(specifier.imported.span.start);
906
- });
907
- }
908
- },
909
- ExportDeclaration({ node }) {
910
- if (utils_1.t.isVariableDeclaration(node.declaration)) {
911
- processedDecls.add(node.declaration);
912
- node.declaration.declarations.forEach((decl) => registerStyle(decl, node.span, true));
913
- }
914
- },
915
- VariableDeclaration({ node }) {
916
- if (processedDecls.has(node))
917
- return;
918
- node.declarations.forEach((decl) => registerStyle(decl, node.span, false));
919
- },
920
1055
  JSXOpeningElement({ node }) {
921
1056
  jsxOpeningElementMap.set(node.span.start, node.attributes);
922
1057
  },
@@ -926,42 +1061,49 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
926
1061
  const propName = node.property.value;
927
1062
  const uniqueKey = `${resourcePath}-${varName}`;
928
1063
  let hash = scannedTables.createHashTable[uniqueKey];
929
- if (!hash)
1064
+ if (!hash) {
930
1065
  hash = mergedCreateTable[varName];
1066
+ }
931
1067
  if (hash) {
932
1068
  let atomMap;
933
- if (scannedTables.createAtomicMapTable[hash])
1069
+ if (scannedTables.createAtomicMapTable[hash]) {
934
1070
  atomMap = scannedTables.createAtomicMapTable[hash][propName];
935
- if (atomMap)
1071
+ }
1072
+ if (atomMap) {
936
1073
  replacements.push({
937
1074
  start: node.span.start - baseByteOffset,
938
1075
  end: node.span.end - baseByteOffset,
939
1076
  content: `(${JSON.stringify(atomMap)})`,
940
1077
  });
1078
+ }
941
1079
  }
942
1080
  let themeHash = scannedTables.createThemeHashTable[uniqueKey];
943
- if (!themeHash)
1081
+ if (!themeHash) {
944
1082
  themeHash = mergedCreateThemeHashTable[varName];
1083
+ }
945
1084
  if (themeHash) {
946
1085
  const atomicMap = scannedTables.createAtomicMapTable[themeHash];
947
- if (atomicMap && atomicMap[propName])
1086
+ if (atomicMap && atomicMap && atomicMap[propName]) {
948
1087
  replacements.push({
949
1088
  start: node.span.start - baseByteOffset,
950
1089
  end: node.span.end - baseByteOffset,
951
1090
  content: `(${JSON.stringify(atomicMap[propName])})`,
952
1091
  });
1092
+ }
953
1093
  }
954
1094
  let staticHash = scannedTables.createStaticHashTable[uniqueKey];
955
- if (!staticHash)
1095
+ if (!staticHash) {
956
1096
  staticHash = mergedCreateStaticHashTable[varName];
1097
+ }
957
1098
  if (staticHash) {
958
1099
  const staticObj = scannedTables.createStaticObjectTable[staticHash];
959
- if (staticObj && staticObj[propName] !== undefined)
1100
+ if (staticObj && staticObj[propName] !== undefined) {
960
1101
  replacements.push({
961
1102
  start: node.span.start - baseByteOffset,
962
1103
  end: node.span.end - baseByteOffset,
963
1104
  content: `(${JSON.stringify(staticObj[propName])})`,
964
1105
  });
1106
+ }
965
1107
  }
966
1108
  }
967
1109
  },
@@ -982,16 +1124,18 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
982
1124
  const varName = node.value;
983
1125
  const uniqueKey = `${resourcePath}-${varName}`;
984
1126
  let hash = scannedTables.createHashTable[uniqueKey];
985
- if (!hash)
1127
+ if (!hash) {
986
1128
  hash = mergedCreateTable[varName];
1129
+ }
987
1130
  if (hash) {
988
1131
  const obj = scannedTables.createObjectTable[hash];
989
1132
  const atomicMap = scannedTables.createAtomicMapTable[hash];
990
1133
  if (obj && atomicMap) {
991
1134
  const hashMap = {};
992
1135
  Object.keys(obj).forEach((key) => {
993
- if (atomicMap[key])
1136
+ if (atomicMap[key]) {
994
1137
  hashMap[key] = atomicMap[key];
1138
+ }
995
1139
  });
996
1140
  replacements.push({
997
1141
  start: node.span.start - baseByteOffset,
@@ -1001,29 +1145,33 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1001
1145
  }
1002
1146
  }
1003
1147
  let themeHash = scannedTables.createThemeHashTable[uniqueKey];
1004
- if (!themeHash)
1148
+ if (!themeHash) {
1005
1149
  themeHash = mergedCreateThemeHashTable[varName];
1150
+ }
1006
1151
  if (themeHash) {
1007
1152
  const atomicMap = scannedTables.createAtomicMapTable[themeHash];
1008
- if (atomicMap)
1153
+ if (atomicMap) {
1009
1154
  replacements.push({
1010
1155
  start: node.span.start - baseByteOffset,
1011
1156
  end: node.span.end - baseByteOffset,
1012
1157
  content: `(${JSON.stringify(atomicMap)})`,
1013
1158
  });
1014
- return;
1159
+ return;
1160
+ }
1015
1161
  }
1016
1162
  let staticHash = scannedTables.createStaticHashTable[uniqueKey];
1017
- if (!staticHash)
1163
+ if (!staticHash) {
1018
1164
  staticHash = mergedCreateStaticHashTable[varName];
1165
+ }
1019
1166
  if (staticHash) {
1020
1167
  const staticObj = scannedTables.createStaticObjectTable[staticHash];
1021
- if (staticObj)
1168
+ if (staticObj) {
1022
1169
  replacements.push({
1023
1170
  start: node.span.start - baseByteOffset,
1024
1171
  end: node.span.end - baseByteOffset,
1025
1172
  content: `(${JSON.stringify(staticObj)})`,
1026
1173
  });
1174
+ }
1027
1175
  }
1028
1176
  },
1029
1177
  JSXAttribute({ node }) {
@@ -1086,11 +1234,10 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1086
1234
  }
1087
1235
  }
1088
1236
  args = args.filter((arg) => {
1089
- const innerExpr = arg.expression;
1090
- if (!utils_1.t.isCallExpression(innerExpr) ||
1091
- !utils_1.t.isMemberExpression(innerExpr.callee))
1237
+ const expr = arg.expression;
1238
+ if (!utils_1.t.isCallExpression(expr) || !utils_1.t.isMemberExpression(expr.callee))
1092
1239
  return true;
1093
- const callee = innerExpr.callee;
1240
+ const callee = expr.callee;
1094
1241
  if (!utils_1.t.isIdentifier(callee.object) ||
1095
1242
  !utils_1.t.isIdentifier(callee.property))
1096
1243
  return true;
@@ -1099,7 +1246,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1099
1246
  const styleInfo = localCreateStyles[varName];
1100
1247
  if (styleInfo?.functions?.[propKey]) {
1101
1248
  const func = styleInfo.functions[propKey];
1102
- const callArgs = innerExpr.arguments;
1249
+ const callArgs = expr.arguments;
1103
1250
  const hasSpread = callArgs.some((a) => a.spread);
1104
1251
  if (!hasSpread && callArgs.length >= 1) {
1105
1252
  const tempStaticTable = { ...mergedStaticTable };
@@ -1200,32 +1347,33 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1200
1347
  const objectName = callee.object.value;
1201
1348
  const propertyName = callee.property.value;
1202
1349
  const alias = plumeriaAliases[objectName];
1203
- if (alias === 'NAMESPACE' && propertyName === 'use')
1350
+ if (alias === 'NAMESPACE' && propertyName === 'use') {
1204
1351
  isUseCall = true;
1352
+ }
1205
1353
  }
1206
1354
  else if (utils_1.t.isIdentifier(callee)) {
1207
1355
  const calleeName = callee.value;
1208
1356
  const originalName = plumeriaAliases[calleeName];
1209
- if (originalName === 'use')
1357
+ if (originalName === 'use') {
1210
1358
  isUseCall = true;
1359
+ }
1211
1360
  }
1212
1361
  if (!isUseCall)
1213
1362
  return;
1214
1363
  const args = node.arguments;
1215
1364
  for (const arg of args) {
1216
- const innerExpr = arg.expression;
1217
- if (!utils_1.t.isCallExpression(innerExpr) ||
1218
- !utils_1.t.isMemberExpression(innerExpr.callee))
1365
+ const expr = arg.expression;
1366
+ if (!utils_1.t.isCallExpression(expr) || !utils_1.t.isMemberExpression(expr.callee))
1219
1367
  continue;
1220
- const innerCallee = innerExpr.callee;
1221
- if (!utils_1.t.isIdentifier(innerCallee.object) ||
1222
- !utils_1.t.isIdentifier(innerCallee.property))
1368
+ const callee = expr.callee;
1369
+ if (!utils_1.t.isIdentifier(callee.object) ||
1370
+ !utils_1.t.isIdentifier(callee.property))
1223
1371
  continue;
1224
- const varName = innerCallee.object.value;
1225
- const propKey = innerCallee.property.value;
1372
+ const varName = callee.object.value;
1373
+ const propKey = callee.property.value;
1226
1374
  const styleInfo = localCreateStyles[varName];
1227
1375
  if (styleInfo?.functions?.[propKey]) {
1228
- throw new Error(`Plumeria: css.use(${getSource(innerExpr)}) does not support dynamic function keys.\n`);
1376
+ throw new Error(`Plumeria: css.use(${getSource(expr)}) does not support dynamic function keys.\n`);
1229
1377
  }
1230
1378
  }
1231
1379
  const { classParts, isOptimizable, baseStyle } = buildClassParts(args);
@@ -1241,8 +1389,9 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1241
1389
  },
1242
1390
  });
1243
1391
  Object.values(localCreateStyles).forEach((info) => {
1244
- if (info.type === 'constant')
1392
+ if (info.type === 'constant') {
1245
1393
  return;
1394
+ }
1246
1395
  if (info.isExported) {
1247
1396
  replacements.push({
1248
1397
  start: info.declSpan.start,
@@ -1258,7 +1407,6 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1258
1407
  });
1259
1408
  }
1260
1409
  });
1261
- const optInCSS = await (0, utils_1.optimizer)(extractedSheets.join(''));
1262
1410
  const buffer = Buffer.from(source);
1263
1411
  let offset = 0;
1264
1412
  const parts = [];
@@ -1273,6 +1421,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1273
1421
  });
1274
1422
  parts.push(buffer.subarray(offset));
1275
1423
  const transformedSource = Buffer.concat(parts).toString();
1424
+ const optInCSS = await (0, utils_1.optimizer)(extractedSheets.join(''));
1276
1425
  if (extractedSheets.length > 0) {
1277
1426
  const baseId = id.replace(exports.EXTENSION_PATTERN, '');
1278
1427
  const cssFilename = `${baseId}.zero.css`;