@plumeria/vite-plugin 6.0.2 → 6.1.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.
Files changed (2) hide show
  1. package/dist/index.js +101 -33
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -86,9 +86,26 @@ export function plumeria(options = {}) {
86
86
  const localConsts = collectLocalConsts(ast);
87
87
  const resourcePath = id;
88
88
  const importMap = {};
89
+ const plumeriaAliases = {};
89
90
  traverse(ast, {
90
91
  ImportDeclaration({ node }) {
91
92
  const sourcePath = node.source.value;
93
+ if (sourcePath === '@plumeria/core') {
94
+ node.specifiers.forEach((specifier) => {
95
+ if (specifier.type === 'ImportNamespaceSpecifier') {
96
+ plumeriaAliases[specifier.local.value] = 'NAMESPACE';
97
+ }
98
+ else if (specifier.type === 'ImportDefaultSpecifier') {
99
+ plumeriaAliases[specifier.local.value] = 'NAMESPACE';
100
+ }
101
+ else if (specifier.type === 'ImportSpecifier') {
102
+ const importedName = specifier.imported
103
+ ? specifier.imported.value
104
+ : specifier.local.value;
105
+ plumeriaAliases[specifier.local.value] = importedName;
106
+ }
107
+ });
108
+ }
92
109
  const actualPath = resolveImportPath(sourcePath, resourcePath);
93
110
  if (actualPath) {
94
111
  node.specifiers.forEach((specifier) => {
@@ -182,6 +199,9 @@ export function plumeria(options = {}) {
182
199
  const processedDecls = new Set();
183
200
  const idSpans = new Set();
184
201
  const excludedSpans = new Set();
202
+ if (scannedTables.extractedSheet) {
203
+ addSheet(scannedTables.extractedSheet);
204
+ }
185
205
  const checkVariantAssignment = (decl) => {
186
206
  if (decl.init &&
187
207
  t.isCallExpression(decl.init) &&
@@ -195,14 +215,31 @@ export function plumeria(options = {}) {
195
215
  }
196
216
  };
197
217
  const registerStyle = (node, declSpan, isExported) => {
218
+ let propName;
198
219
  if (t.isIdentifier(node.id) &&
199
220
  node.init &&
200
221
  t.isCallExpression(node.init) &&
201
- t.isMemberExpression(node.init.callee) &&
202
- t.isIdentifier(node.init.callee.object, { name: 'css' }) &&
203
- t.isIdentifier(node.init.callee.property) &&
204
222
  node.init.arguments.length >= 1) {
205
- const propName = node.init.callee.property.value;
223
+ const callee = node.init.callee;
224
+ if (t.isMemberExpression(callee) &&
225
+ t.isIdentifier(callee.object) &&
226
+ t.isIdentifier(callee.property)) {
227
+ const objectName = callee.object.value;
228
+ const propertyName = callee.property.value;
229
+ const alias = plumeriaAliases[objectName];
230
+ if (alias === 'NAMESPACE' || objectName === 'css') {
231
+ propName = propertyName;
232
+ }
233
+ }
234
+ else if (t.isIdentifier(callee)) {
235
+ const calleeName = callee.value;
236
+ const originalName = plumeriaAliases[calleeName];
237
+ if (originalName) {
238
+ propName = originalName;
239
+ }
240
+ }
241
+ }
242
+ if (propName) {
206
243
  if (propName === 'create' &&
207
244
  t.isObjectExpression(node.init.arguments[0].expression)) {
208
245
  const obj = objectExpressionToObject(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedThemeTable, mergedCreateTable, mergedVariantsTable);
@@ -321,10 +358,25 @@ export function plumeria(options = {}) {
321
358
  },
322
359
  CallExpression({ node }) {
323
360
  const callee = node.callee;
361
+ let propName;
324
362
  if (t.isMemberExpression(callee) &&
325
- t.isIdentifier(callee.object, { name: 'css' }) &&
363
+ t.isIdentifier(callee.object) &&
326
364
  t.isIdentifier(callee.property)) {
327
- const propName = callee.property.value;
365
+ const objectName = callee.object.value;
366
+ const propertyName = callee.property.value;
367
+ const alias = plumeriaAliases[objectName];
368
+ if (alias === 'NAMESPACE' || objectName === 'css') {
369
+ propName = propertyName;
370
+ }
371
+ }
372
+ else if (t.isIdentifier(callee)) {
373
+ const calleeName = callee.value;
374
+ const originalName = plumeriaAliases[calleeName];
375
+ if (originalName) {
376
+ propName = originalName;
377
+ }
378
+ }
379
+ if (propName) {
328
380
  const args = node.arguments;
329
381
  if (propName === 'keyframes' &&
330
382
  args.length > 0 &&
@@ -381,46 +433,62 @@ export function plumeria(options = {}) {
381
433
  if (t.isIdentifier(node.object) && t.isIdentifier(node.property)) {
382
434
  const varName = node.object.value;
383
435
  const propName = node.property.value;
384
- const styleInfo = localCreateStyles[varName];
385
- if (styleInfo) {
386
- const atomMap = styleInfo.hashMap[propName];
436
+ const uniqueKey = `${id}-${varName}`;
437
+ let hash = scannedTables.createHashTable[uniqueKey];
438
+ if (!hash) {
439
+ hash = mergedCreateTable[varName];
440
+ }
441
+ if (!hash) {
442
+ const styleInfo = localCreateStyles[varName];
443
+ if (styleInfo) {
444
+ const atomMap = styleInfo.hashMap[propName];
445
+ if (atomMap) {
446
+ replacements.push({
447
+ start: node.span.start - ast.span.start,
448
+ end: node.span.end - ast.span.start,
449
+ content: JSON.stringify(atomMap),
450
+ });
451
+ return;
452
+ }
453
+ }
454
+ }
455
+ if (hash) {
456
+ let atomMap;
457
+ if (scannedTables.createAtomicMapTable[hash]) {
458
+ atomMap = scannedTables.createAtomicMapTable[hash][propName];
459
+ }
387
460
  if (atomMap) {
388
461
  replacements.push({
389
462
  start: node.span.start - ast.span.start,
390
463
  end: node.span.end - ast.span.start,
391
464
  content: JSON.stringify(atomMap),
392
465
  });
393
- return;
394
- }
395
- }
396
- const hash = mergedCreateTable[varName];
397
- if (hash) {
398
- const obj = scannedTables.createObjectTable[hash];
399
- if (obj && obj[propName]) {
400
- const style = obj[propName];
401
- if (typeof style === 'object' && style !== null) {
402
- const records = getStyleRecords(propName, style, 2);
403
- extractOndemandStyles(style, extractedSheets, scannedTables);
404
- records.forEach((r) => addSheet(r.sheet));
405
- const atomMap = {};
406
- records.forEach((r) => (atomMap[r.key] = r.hash));
407
- if (Object.keys(atomMap).length > 0) {
408
- replacements.push({
409
- start: node.span.start - ast.span.start,
410
- end: node.span.end - ast.span.start,
411
- content: JSON.stringify(atomMap),
412
- });
413
- }
414
- }
415
466
  }
416
467
  }
417
468
  }
418
469
  },
419
470
  CallExpression({ node }) {
420
471
  const callee = node.callee;
472
+ let isPropsCall = false;
421
473
  if (t.isMemberExpression(callee) &&
422
- t.isIdentifier(callee.object, { name: 'css' }) &&
423
- t.isIdentifier(callee.property, { name: 'props' })) {
474
+ t.isIdentifier(callee.object) &&
475
+ t.isIdentifier(callee.property)) {
476
+ const objectName = callee.object.value;
477
+ const propertyName = callee.property.value;
478
+ const alias = plumeriaAliases[objectName];
479
+ if ((alias === 'NAMESPACE' || objectName === 'css') &&
480
+ propertyName === 'props') {
481
+ isPropsCall = true;
482
+ }
483
+ }
484
+ else if (t.isIdentifier(callee)) {
485
+ const calleeName = callee.value;
486
+ const originalName = plumeriaAliases[calleeName];
487
+ if (originalName === 'props') {
488
+ isPropsCall = true;
489
+ }
490
+ }
491
+ if (isPropsCall) {
424
492
  const args = node.arguments;
425
493
  const resolveStyleObject = (expr) => {
426
494
  if (t.isObjectExpression(expr)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/vite-plugin",
3
- "version": "6.0.2",
3
+ "version": "6.1.1",
4
4
  "type": "module",
5
5
  "description": "Plumeria Vite plugin",
6
6
  "author": "Refirst 11",
@@ -22,7 +22,7 @@
22
22
  "dist/"
23
23
  ],
24
24
  "dependencies": {
25
- "@plumeria/utils": "^6.0.2"
25
+ "@plumeria/utils": "^6.1.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@swc/core": "1.15.8",