@plumeria/unplugin 15.1.0 → 15.1.2

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 (3) hide show
  1. package/dist/core.js +29 -14
  2. package/dist/core.mjs +29 -14
  3. package/package.json +3 -3
package/dist/core.js CHANGED
@@ -161,8 +161,8 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
161
161
  });
162
162
  return records;
163
163
  };
164
- const localConsts = (0, utils_1.collectLocalConsts)(ast);
165
164
  const resourcePath = id;
165
+ const localConsts = (0, utils_1.collectLocalConsts)(ast);
166
166
  const importMap = {};
167
167
  const keyframesImportMap = {};
168
168
  const viewTransitionImportMap = {};
@@ -1055,7 +1055,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1055
1055
  });
1056
1056
  const classParts = [];
1057
1057
  if (existingClass)
1058
- classParts.push(JSON.stringify(existingClass));
1058
+ classParts.push(existingClass);
1059
1059
  if (Object.keys(baseIndependent).length > 0) {
1060
1060
  const className = processStyleRecords(baseIndependent)
1061
1061
  .map((r) => r.hash)
@@ -1353,18 +1353,30 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1353
1353
  const classNameAttr = attributes.find((attr) => attr.type === 'JSXAttribute' &&
1354
1354
  attr.name.type === 'Identifier' &&
1355
1355
  attr.name.value === 'className');
1356
- let existingClass = '';
1357
- if (classNameAttr?.value?.type === 'StringLiteral') {
1358
- existingClass = classNameAttr.value.value;
1356
+ let existingClassExpr = '';
1357
+ if (classNameAttr) {
1359
1358
  replacements.push({
1360
1359
  start: classNameAttr.span.start - baseByteOffset,
1361
1360
  end: classNameAttr.span.end - baseByteOffset,
1362
1361
  content: '',
1363
1362
  });
1363
+ if (classNameAttr.value?.type === 'StringLiteral') {
1364
+ existingClassExpr = JSON.stringify(classNameAttr.value.value);
1365
+ }
1366
+ else if (classNameAttr.value?.type === 'JSXExpressionContainer') {
1367
+ const start = classNameAttr.value.expression.span.start -
1368
+ baseByteOffset;
1369
+ const end = classNameAttr.value.expression.span.end -
1370
+ baseByteOffset;
1371
+ existingClassExpr = `(${sourceBuffer
1372
+ .subarray(start, end)
1373
+ .toString('utf-8')})`;
1374
+ }
1364
1375
  }
1365
1376
  const styleAttrExisting = attributes.find((attr) => attr.type === 'JSXAttribute' &&
1366
1377
  attr.name.type === 'Identifier' &&
1367
1378
  attr.name.value === 'style');
1379
+ let existingStyleExpr = '';
1368
1380
  if (styleAttrExisting) {
1369
1381
  replacements.push({
1370
1382
  start: styleAttrExisting.span.start - baseByteOffset,
@@ -1373,16 +1385,19 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1373
1385
  });
1374
1386
  if (styleAttrExisting.value?.type === 'JSXExpressionContainer') {
1375
1387
  const innerExpr = styleAttrExisting.value?.expression;
1376
- if (innerExpr?.type === 'ObjectExpression') {
1377
- const start = innerExpr.span.start - baseByteOffset;
1378
- const end = innerExpr.span.end - baseByteOffset;
1379
- const innerSource = sourceBuffer
1380
- .subarray(start, end)
1381
- .toString('utf-8');
1388
+ const start = innerExpr.span.start - baseByteOffset;
1389
+ const end = innerExpr.span.end - baseByteOffset;
1390
+ const innerSource = sourceBuffer
1391
+ .subarray(start, end)
1392
+ .toString('utf-8');
1393
+ if (innerExpr.type === 'ObjectExpression') {
1382
1394
  const stripped = innerSource.slice(1, -1).trim();
1383
1395
  if (stripped)
1384
1396
  dynamicStyleParts.push(stripped);
1385
1397
  }
1398
+ else {
1399
+ existingStyleExpr = `...(${innerSource})`;
1400
+ }
1386
1401
  }
1387
1402
  }
1388
1403
  args = args.filter((arg) => {
@@ -1467,10 +1482,10 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1467
1482
  }
1468
1483
  return true;
1469
1484
  });
1470
- const styleAttr = dynamicStyleParts.length > 0
1471
- ? ` style={{${dynamicStyleParts.join(', ')}}}`
1485
+ const styleAttr = dynamicStyleParts.length > 0 || existingStyleExpr
1486
+ ? ` style={{ ${[existingStyleExpr, ...dynamicStyleParts].filter(Boolean).join(', ')} }}`
1472
1487
  : '';
1473
- const { classParts, isOptimizable, baseStyle } = buildClassParts(args, dynamicClassParts, existingClass);
1488
+ const { classParts, isOptimizable, baseStyle } = buildClassParts(args, dynamicClassParts, existingClassExpr);
1474
1489
  if (isOptimizable &&
1475
1490
  (args.length > 0 ||
1476
1491
  Object.keys(baseStyle).length > 0 ||
package/dist/core.mjs CHANGED
@@ -125,8 +125,8 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
125
125
  });
126
126
  return records;
127
127
  };
128
- const localConsts = collectLocalConsts(ast);
129
128
  const resourcePath = id;
129
+ const localConsts = collectLocalConsts(ast);
130
130
  const importMap = {};
131
131
  const keyframesImportMap = {};
132
132
  const viewTransitionImportMap = {};
@@ -1019,7 +1019,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1019
1019
  });
1020
1020
  const classParts = [];
1021
1021
  if (existingClass)
1022
- classParts.push(JSON.stringify(existingClass));
1022
+ classParts.push(existingClass);
1023
1023
  if (Object.keys(baseIndependent).length > 0) {
1024
1024
  const className = processStyleRecords(baseIndependent)
1025
1025
  .map((r) => r.hash)
@@ -1317,18 +1317,30 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1317
1317
  const classNameAttr = attributes.find((attr) => attr.type === 'JSXAttribute' &&
1318
1318
  attr.name.type === 'Identifier' &&
1319
1319
  attr.name.value === 'className');
1320
- let existingClass = '';
1321
- if (classNameAttr?.value?.type === 'StringLiteral') {
1322
- existingClass = classNameAttr.value.value;
1320
+ let existingClassExpr = '';
1321
+ if (classNameAttr) {
1323
1322
  replacements.push({
1324
1323
  start: classNameAttr.span.start - baseByteOffset,
1325
1324
  end: classNameAttr.span.end - baseByteOffset,
1326
1325
  content: '',
1327
1326
  });
1327
+ if (classNameAttr.value?.type === 'StringLiteral') {
1328
+ existingClassExpr = JSON.stringify(classNameAttr.value.value);
1329
+ }
1330
+ else if (classNameAttr.value?.type === 'JSXExpressionContainer') {
1331
+ const start = classNameAttr.value.expression.span.start -
1332
+ baseByteOffset;
1333
+ const end = classNameAttr.value.expression.span.end -
1334
+ baseByteOffset;
1335
+ existingClassExpr = `(${sourceBuffer
1336
+ .subarray(start, end)
1337
+ .toString('utf-8')})`;
1338
+ }
1328
1339
  }
1329
1340
  const styleAttrExisting = attributes.find((attr) => attr.type === 'JSXAttribute' &&
1330
1341
  attr.name.type === 'Identifier' &&
1331
1342
  attr.name.value === 'style');
1343
+ let existingStyleExpr = '';
1332
1344
  if (styleAttrExisting) {
1333
1345
  replacements.push({
1334
1346
  start: styleAttrExisting.span.start - baseByteOffset,
@@ -1337,16 +1349,19 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1337
1349
  });
1338
1350
  if (styleAttrExisting.value?.type === 'JSXExpressionContainer') {
1339
1351
  const innerExpr = styleAttrExisting.value?.expression;
1340
- if (innerExpr?.type === 'ObjectExpression') {
1341
- const start = innerExpr.span.start - baseByteOffset;
1342
- const end = innerExpr.span.end - baseByteOffset;
1343
- const innerSource = sourceBuffer
1344
- .subarray(start, end)
1345
- .toString('utf-8');
1352
+ const start = innerExpr.span.start - baseByteOffset;
1353
+ const end = innerExpr.span.end - baseByteOffset;
1354
+ const innerSource = sourceBuffer
1355
+ .subarray(start, end)
1356
+ .toString('utf-8');
1357
+ if (innerExpr.type === 'ObjectExpression') {
1346
1358
  const stripped = innerSource.slice(1, -1).trim();
1347
1359
  if (stripped)
1348
1360
  dynamicStyleParts.push(stripped);
1349
1361
  }
1362
+ else {
1363
+ existingStyleExpr = `...(${innerSource})`;
1364
+ }
1350
1365
  }
1351
1366
  }
1352
1367
  args = args.filter((arg) => {
@@ -1431,10 +1446,10 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1431
1446
  }
1432
1447
  return true;
1433
1448
  });
1434
- const styleAttr = dynamicStyleParts.length > 0
1435
- ? ` style={{${dynamicStyleParts.join(', ')}}}`
1449
+ const styleAttr = dynamicStyleParts.length > 0 || existingStyleExpr
1450
+ ? ` style={{ ${[existingStyleExpr, ...dynamicStyleParts].filter(Boolean).join(', ')} }}`
1436
1451
  : '';
1437
- const { classParts, isOptimizable, baseStyle } = buildClassParts(args, dynamicClassParts, existingClass);
1452
+ const { classParts, isOptimizable, baseStyle } = buildClassParts(args, dynamicClassParts, existingClassExpr);
1438
1453
  if (isOptimizable &&
1439
1454
  (args.length > 0 ||
1440
1455
  Object.keys(baseStyle).length > 0 ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/unplugin",
3
- "version": "15.1.0",
3
+ "version": "15.1.2",
4
4
  "description": "Universal Plumeria plugin for various build tools",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -89,10 +89,10 @@
89
89
  "dependencies": {
90
90
  "@rollup/pluginutils": "^5.4.0",
91
91
  "unplugin": "^3.0.0",
92
- "@plumeria/utils": "^15.1.0"
92
+ "@plumeria/utils": "^15.1.2"
93
93
  },
94
94
  "devDependencies": {
95
- "@swc/core": "1.15.41",
95
+ "@swc/core": "1.15.43",
96
96
  "vite": "^8.0.13",
97
97
  "zss-engine": "2.3.0"
98
98
  },