@plumeria/vite-plugin 10.0.6 → 10.0.7

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 +144 -104
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -185,7 +185,10 @@ export function plumeria(options = {}) {
185
185
  mergedKeyframesTable[key] = scannedTables.keyframesHashTable[key];
186
186
  }
187
187
  for (const key of Object.keys(importMap)) {
188
- mergedKeyframesTable[key] = importMap[key];
188
+ const val = importMap[key];
189
+ if (typeof val === 'string') {
190
+ mergedKeyframesTable[key] = val;
191
+ }
189
192
  }
190
193
  const mergedViewTransitionTable = {};
191
194
  for (const key of Object.keys(scannedTables.viewTransitionHashTable)) {
@@ -193,21 +196,30 @@ export function plumeria(options = {}) {
193
196
  scannedTables.viewTransitionHashTable[key];
194
197
  }
195
198
  for (const key of Object.keys(importMap)) {
196
- mergedViewTransitionTable[key] = importMap[key];
199
+ const val = importMap[key];
200
+ if (typeof val === 'string') {
201
+ mergedViewTransitionTable[key] = val;
202
+ }
197
203
  }
198
204
  const mergedCreateTable = {};
199
205
  for (const key of Object.keys(scannedTables.createHashTable)) {
200
206
  mergedCreateTable[key] = scannedTables.createHashTable[key];
201
207
  }
202
208
  for (const key of Object.keys(importMap)) {
203
- mergedCreateTable[key] = importMap[key];
209
+ const val = importMap[key];
210
+ if (typeof val === 'string') {
211
+ mergedCreateTable[key] = val;
212
+ }
204
213
  }
205
214
  const mergedVariantsTable = {};
206
215
  for (const key of Object.keys(scannedTables.variantsHashTable)) {
207
216
  mergedVariantsTable[key] = scannedTables.variantsHashTable[key];
208
217
  }
209
218
  for (const key of Object.keys(importMap)) {
210
- mergedVariantsTable[key] = importMap[key];
219
+ const val = importMap[key];
220
+ if (typeof val === 'string') {
221
+ mergedVariantsTable[key] = val;
222
+ }
211
223
  }
212
224
  const mergedCreateThemeHashTable = {};
213
225
  for (const key of Object.keys(scannedTables.createThemeHashTable)) {
@@ -241,10 +253,9 @@ export function plumeria(options = {}) {
241
253
  const idSpans = new Set();
242
254
  const excludedSpans = new Set();
243
255
  const checkVariantAssignment = (decl) => {
244
- if (decl.init &&
245
- t.isCallExpression(decl.init) &&
246
- t.isIdentifier(decl.init.callee)) {
247
- const varName = decl.init.callee.value;
256
+ const init = decl.init;
257
+ if (init && t.isCallExpression(init) && t.isIdentifier(init.callee)) {
258
+ const varName = init.callee.value;
248
259
  if ((localCreateStyles[varName] &&
249
260
  localCreateStyles[varName].type === 'variant') ||
250
261
  mergedVariantsTable[varName]) {
@@ -254,11 +265,12 @@ export function plumeria(options = {}) {
254
265
  };
255
266
  const registerStyle = (node, declSpan, isExported) => {
256
267
  let propName;
268
+ const init = node.init;
257
269
  if (t.isIdentifier(node.id) &&
258
- node.init &&
259
- t.isCallExpression(node.init) &&
260
- node.init.arguments.length >= 1) {
261
- const callee = node.init.callee;
270
+ init &&
271
+ t.isCallExpression(init) &&
272
+ init.arguments.length >= 1) {
273
+ const callee = init.callee;
262
274
  if (t.isMemberExpression(callee) &&
263
275
  t.isIdentifier(callee.object) &&
264
276
  t.isIdentifier(callee.property)) {
@@ -277,10 +289,10 @@ export function plumeria(options = {}) {
277
289
  }
278
290
  }
279
291
  }
280
- if (propName) {
292
+ if (propName && init && t.isCallExpression(init)) {
281
293
  if (propName === 'create' &&
282
- t.isObjectExpression(node.init.arguments[0].expression)) {
283
- const obj = objectExpressionToObject(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
294
+ t.isObjectExpression(init.arguments[0].expression)) {
295
+ const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
284
296
  if (obj) {
285
297
  const hashMap = {};
286
298
  Object.entries(obj).forEach(([key, style]) => {
@@ -295,8 +307,7 @@ export function plumeria(options = {}) {
295
307
  records.forEach((r) => (atomMap[r.key] = r.hash));
296
308
  hashMap[key] = atomMap;
297
309
  });
298
- const objExpr = node.init.arguments[0]
299
- .expression;
310
+ const objExpr = init.arguments[0].expression;
300
311
  objExpr.properties.forEach((prop) => {
301
312
  if (prop.type !== 'KeyValueProperty' ||
302
313
  prop.key.type !== 'Identifier')
@@ -306,7 +317,20 @@ export function plumeria(options = {}) {
306
317
  if (!isArrow && !isFunc)
307
318
  return;
308
319
  const key = prop.key.value;
309
- const params = prop.value.params.map((p) => p.type === 'Identifier' ? p.value : (p.pat?.value ?? 'arg'));
320
+ const func = prop.value;
321
+ if (func.type !== 'ArrowFunctionExpression' &&
322
+ func.type !== 'FunctionExpression')
323
+ return;
324
+ const params = func.params.map((p) => {
325
+ if (t.isIdentifier(p))
326
+ return p.value;
327
+ if (typeof p === 'object' &&
328
+ p !== null &&
329
+ 'pat' in p &&
330
+ t.isIdentifier(p.pat))
331
+ return p.pat.value;
332
+ return 'arg';
333
+ });
310
334
  const cssVarInfo = {};
311
335
  const tempStaticTable = { ...mergedStaticTable };
312
336
  const substitutedArgs = params.map((paramName) => {
@@ -317,7 +341,7 @@ export function plumeria(options = {}) {
317
341
  params.forEach((paramName, i) => {
318
342
  tempStaticTable[paramName] = substitutedArgs[i];
319
343
  });
320
- let actualBody = prop.value.body;
344
+ let actualBody = func.body;
321
345
  if (actualBody?.type === 'ParenthesisExpression')
322
346
  actualBody = actualBody.expression;
323
347
  if (actualBody?.type === 'BlockStatement') {
@@ -350,29 +374,31 @@ export function plumeria(options = {}) {
350
374
  if (t.isIdentifier(node.id)) {
351
375
  idSpans.add(node.id.span.start);
352
376
  }
353
- localCreateStyles[node.id.value] = {
354
- name: node.id.value,
355
- type: 'create',
356
- obj,
357
- hashMap,
358
- isExported,
359
- initSpan: {
360
- start: node.init.span.start - baseByteOffset,
361
- end: node.init.span.end - baseByteOffset,
362
- },
363
- declSpan: {
364
- start: declSpan.start - baseByteOffset,
365
- end: declSpan.end - baseByteOffset,
366
- },
367
- };
377
+ if (t.isIdentifier(node.id)) {
378
+ localCreateStyles[node.id.value] = {
379
+ name: node.id.value,
380
+ type: 'create',
381
+ obj,
382
+ hashMap,
383
+ isExported,
384
+ initSpan: {
385
+ start: init.span.start - baseByteOffset,
386
+ end: init.span.end - baseByteOffset,
387
+ },
388
+ declSpan: {
389
+ start: declSpan.start - baseByteOffset,
390
+ end: declSpan.end - baseByteOffset,
391
+ },
392
+ };
393
+ }
368
394
  }
369
395
  }
370
396
  else if (propName === 'variants' &&
371
- t.isObjectExpression(node.init.arguments[0].expression)) {
397
+ t.isObjectExpression(init.arguments[0].expression)) {
372
398
  if (t.isIdentifier(node.id)) {
373
399
  idSpans.add(node.id.span.start);
374
400
  }
375
- const obj = objectExpressionToObject(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, (name) => {
401
+ const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, (name) => {
376
402
  if (localCreateStyles[name]) {
377
403
  return localCreateStyles[name].obj;
378
404
  }
@@ -385,47 +411,51 @@ export function plumeria(options = {}) {
385
411
  return undefined;
386
412
  });
387
413
  const { hashMap } = processVariants(obj);
388
- localCreateStyles[node.id.value] = {
389
- name: node.id.value,
390
- type: 'variant',
391
- obj,
392
- hashMap,
393
- isExported,
394
- initSpan: {
395
- start: node.init.span.start - baseByteOffset,
396
- end: node.init.span.end - baseByteOffset,
397
- },
398
- declSpan: {
399
- start: declSpan.start - baseByteOffset,
400
- end: declSpan.end - baseByteOffset,
401
- },
402
- };
414
+ if (t.isIdentifier(node.id)) {
415
+ localCreateStyles[node.id.value] = {
416
+ name: node.id.value,
417
+ type: 'variant',
418
+ obj,
419
+ hashMap,
420
+ isExported,
421
+ initSpan: {
422
+ start: init.span.start - baseByteOffset,
423
+ end: init.span.end - baseByteOffset,
424
+ },
425
+ declSpan: {
426
+ start: declSpan.start - baseByteOffset,
427
+ end: declSpan.end - baseByteOffset,
428
+ },
429
+ };
430
+ }
403
431
  }
404
432
  else if (propName === 'createTheme' &&
405
- t.isObjectExpression(node.init.arguments[0].expression)) {
433
+ t.isObjectExpression(init.arguments[0].expression)) {
406
434
  if (t.isIdentifier(node.id)) {
407
435
  idSpans.add(node.id.span.start);
408
436
  }
409
- const obj = objectExpressionToObject(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
437
+ const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
410
438
  const hash = genBase36Hash(obj, 1, 8);
411
- const uniqueKey = `${resourcePath}-${node.id.value}`;
412
- scannedTables.createThemeHashTable[uniqueKey] = hash;
413
- scannedTables.createThemeObjectTable[hash] = obj;
414
- localCreateStyles[node.id.value] = {
415
- name: node.id.value,
416
- type: 'constant',
417
- obj,
418
- hashMap: scannedTables.createAtomicMapTable[hash],
419
- isExported,
420
- initSpan: {
421
- start: node.init.span.start - baseByteOffset,
422
- end: node.init.span.end - baseByteOffset,
423
- },
424
- declSpan: {
425
- start: declSpan.start - baseByteOffset,
426
- end: declSpan.end - baseByteOffset,
427
- },
428
- };
439
+ if (t.isIdentifier(node.id)) {
440
+ const uniqueKey = `${resourcePath}-${node.id.value}`;
441
+ scannedTables.createThemeHashTable[uniqueKey] = hash;
442
+ scannedTables.createThemeObjectTable[hash] = obj;
443
+ localCreateStyles[node.id.value] = {
444
+ name: node.id.value,
445
+ type: 'constant',
446
+ obj,
447
+ hashMap: scannedTables.createAtomicMapTable[hash],
448
+ isExported,
449
+ initSpan: {
450
+ start: init.span.start - baseByteOffset,
451
+ end: init.span.end - baseByteOffset,
452
+ },
453
+ declSpan: {
454
+ start: declSpan.start - baseByteOffset,
455
+ end: declSpan.end - baseByteOffset,
456
+ },
457
+ };
458
+ }
429
459
  }
430
460
  }
431
461
  };
@@ -436,7 +466,7 @@ export function plumeria(options = {}) {
436
466
  if (specifier.local) {
437
467
  excludedSpans.add(specifier.local.span.start);
438
468
  }
439
- if (specifier.imported) {
469
+ if (specifier.type === 'ImportSpecifier' && specifier.imported) {
440
470
  excludedSpans.add(specifier.imported.span.start);
441
471
  }
442
472
  });
@@ -481,17 +511,18 @@ export function plumeria(options = {}) {
481
511
  }
482
512
  if (propName) {
483
513
  const args = node.arguments;
484
- if (propName === 'keyframes' &&
485
- args.length > 0 &&
486
- t.isObjectExpression(args[0].expression)) {
487
- const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
488
- const hash = genBase36Hash(obj, 1, 8);
489
- scannedTables.keyframesObjectTable[hash] = obj;
490
- replacements.push({
491
- start: node.span.start - baseByteOffset,
492
- end: node.span.end - baseByteOffset,
493
- content: JSON.stringify(`kf-${hash}`),
494
- });
514
+ if (propName === 'keyframes') {
515
+ const expr = args[0].expression;
516
+ if (t.isObjectExpression(expr)) {
517
+ const obj = objectExpressionToObject(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
518
+ const hash = genBase36Hash(obj, 1, 8);
519
+ scannedTables.keyframesObjectTable[hash] = obj;
520
+ replacements.push({
521
+ start: node.span.start - baseByteOffset,
522
+ end: node.span.end - baseByteOffset,
523
+ content: JSON.stringify(`kf-${hash}`),
524
+ });
525
+ }
495
526
  }
496
527
  else if (propName === 'viewTransition' &&
497
528
  args.length > 0 &&
@@ -545,8 +576,7 @@ export function plumeria(options = {}) {
545
576
  }
546
577
  else if (t.isMemberExpression(expr) &&
547
578
  t.isIdentifier(expr.object) &&
548
- (t.isIdentifier(expr.property) ||
549
- expr.property.type === 'Computed')) {
579
+ (t.isIdentifier(expr.property) || expr.property.type === 'Computed')) {
550
580
  if (expr.property.type === 'Computed')
551
581
  return {};
552
582
  const varName = expr.object.value;
@@ -682,8 +712,9 @@ export function plumeria(options = {}) {
682
712
  const currentGroupId = ++groupIdCounter;
683
713
  const valSource = getSource(valExpr);
684
714
  if (valExpr.type === 'StringLiteral') {
685
- if (groupVariants[valExpr.value])
686
- baseStyle = deepMerge(baseStyle, groupVariants[valExpr.value]);
715
+ const groupVariantsAsObj = groupVariants;
716
+ if (groupVariantsAsObj[valExpr.value])
717
+ baseStyle = deepMerge(baseStyle, groupVariantsAsObj[valExpr.value]);
687
718
  continue;
688
719
  }
689
720
  Object.entries(groupVariants).forEach(([optionName, style]) => {
@@ -1108,20 +1139,24 @@ export function plumeria(options = {}) {
1108
1139
  const expr = node.value.expression;
1109
1140
  let args = expr.type === 'ArrayExpression'
1110
1141
  ? expr.elements
1111
- .filter(Boolean)
1112
- .map((el) => ({ expression: el.expression ?? el }))
1142
+ .filter((el) => el !== undefined)
1143
+ .map((el) => ({ expression: el.expression }))
1113
1144
  : [{ expression: expr }];
1114
1145
  const dynamicClassParts = [];
1115
1146
  const dynamicStyleParts = [];
1116
1147
  let attributes = [];
1117
1148
  for (const [, attrs] of jsxOpeningElementMap) {
1118
- const found = attrs.find((a) => a.span?.start === node.span.start);
1149
+ const found = attrs
1150
+ .filter((a) => a.type === 'JSXAttribute')
1151
+ .find((a) => a.span.start === node.span.start);
1119
1152
  if (found) {
1120
1153
  attributes = attrs;
1121
1154
  break;
1122
1155
  }
1123
1156
  }
1124
- const classNameAttr = attributes.find((attr) => attr.name?.value === 'className');
1157
+ const classNameAttr = attributes.find((attr) => attr.type === 'JSXAttribute' &&
1158
+ attr.name.type === 'Identifier' &&
1159
+ attr.name.value === 'className');
1125
1160
  let existingClass = '';
1126
1161
  if (classNameAttr?.value?.type === 'StringLiteral') {
1127
1162
  existingClass = classNameAttr.value.value;
@@ -1131,23 +1166,27 @@ export function plumeria(options = {}) {
1131
1166
  content: '',
1132
1167
  });
1133
1168
  }
1134
- const styleAttrExisting = attributes.find((attr) => attr.name?.value === 'style');
1169
+ const styleAttrExisting = attributes.find((attr) => attr.type === 'JSXAttribute' &&
1170
+ attr.name.type === 'Identifier' &&
1171
+ attr.name.value === 'style');
1135
1172
  if (styleAttrExisting) {
1136
1173
  replacements.push({
1137
1174
  start: styleAttrExisting.span.start - baseByteOffset,
1138
1175
  end: styleAttrExisting.span.end - baseByteOffset,
1139
1176
  content: '',
1140
1177
  });
1141
- const innerExpr = styleAttrExisting.value?.expression;
1142
- if (innerExpr?.type === 'ObjectExpression') {
1143
- const start = innerExpr.span.start - baseByteOffset;
1144
- const end = innerExpr.span.end - baseByteOffset;
1145
- const innerSource = sourceBuffer
1146
- .subarray(start, end)
1147
- .toString('utf-8');
1148
- const stripped = innerSource.slice(1, -1).trim();
1149
- if (stripped)
1150
- dynamicStyleParts.push(stripped);
1178
+ if (styleAttrExisting.value?.type === 'JSXExpressionContainer') {
1179
+ const innerExpr = styleAttrExisting.value?.expression;
1180
+ if (innerExpr?.type === 'ObjectExpression') {
1181
+ const start = innerExpr.span.start - baseByteOffset;
1182
+ const end = innerExpr.span.end - baseByteOffset;
1183
+ const innerSource = sourceBuffer
1184
+ .subarray(start, end)
1185
+ .toString('utf-8');
1186
+ const stripped = innerSource.slice(1, -1).trim();
1187
+ if (stripped)
1188
+ dynamicStyleParts.push(stripped);
1189
+ }
1151
1190
  }
1152
1191
  }
1153
1192
  args = args.filter((arg) => {
@@ -1176,8 +1215,9 @@ export function plumeria(options = {}) {
1176
1215
  const callArg = callArgs[i];
1177
1216
  if (!callArg)
1178
1217
  return;
1179
- const argStart = callArg.expression.span.start - baseByteOffset;
1180
- const argEnd = callArg.expression.span.end - baseByteOffset;
1218
+ const argExpr = callArg.expression;
1219
+ const argStart = argExpr.span.start - baseByteOffset;
1220
+ const argEnd = argExpr.span.end - baseByteOffset;
1181
1221
  const argSource = sourceBuffer
1182
1222
  .subarray(argStart, argEnd)
1183
1223
  .toString('utf-8');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/vite-plugin",
3
- "version": "10.0.6",
3
+ "version": "10.0.7",
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": "^10.0.6"
25
+ "@plumeria/utils": "^10.0.7"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@swc/core": "1.15.21",