@plumeria/vite-plugin 6.2.1 → 6.3.0
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/index.js +107 -94
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -82,6 +82,8 @@ export function plumeria(options = {}) {
|
|
|
82
82
|
const localConsts = collectLocalConsts(ast);
|
|
83
83
|
const resourcePath = id;
|
|
84
84
|
const importMap = {};
|
|
85
|
+
const createThemeImportMap = {};
|
|
86
|
+
const createStaticImportMap = {};
|
|
85
87
|
const plumeriaAliases = {};
|
|
86
88
|
traverse(ast, {
|
|
87
89
|
ImportDeclaration({ node }) {
|
|
@@ -131,11 +133,11 @@ export function plumeria(options = {}) {
|
|
|
131
133
|
scannedTables.variantsHashTable[uniqueKey];
|
|
132
134
|
}
|
|
133
135
|
if (scannedTables.createThemeHashTable[uniqueKey]) {
|
|
134
|
-
|
|
136
|
+
createThemeImportMap[localName] =
|
|
135
137
|
scannedTables.createThemeHashTable[uniqueKey];
|
|
136
138
|
}
|
|
137
139
|
if (scannedTables.createStaticHashTable[uniqueKey]) {
|
|
138
|
-
|
|
140
|
+
createStaticImportMap[localName] =
|
|
139
141
|
scannedTables.createStaticHashTable[uniqueKey];
|
|
140
142
|
}
|
|
141
143
|
}
|
|
@@ -168,22 +170,6 @@ export function plumeria(options = {}) {
|
|
|
168
170
|
for (const key of Object.keys(importMap)) {
|
|
169
171
|
mergedViewTransitionTable[key] = importMap[key];
|
|
170
172
|
}
|
|
171
|
-
const mergedCreateThemeHashTable = {};
|
|
172
|
-
for (const key of Object.keys(scannedTables.createThemeHashTable)) {
|
|
173
|
-
mergedCreateThemeHashTable[key] =
|
|
174
|
-
scannedTables.createThemeHashTable[key];
|
|
175
|
-
}
|
|
176
|
-
for (const key of Object.keys(importMap)) {
|
|
177
|
-
mergedCreateThemeHashTable[key] = importMap[key];
|
|
178
|
-
}
|
|
179
|
-
const mergedCreateStaticHashTable = {};
|
|
180
|
-
for (const key of Object.keys(scannedTables.createStaticHashTable)) {
|
|
181
|
-
mergedCreateStaticHashTable[key] =
|
|
182
|
-
scannedTables.createStaticHashTable[key];
|
|
183
|
-
}
|
|
184
|
-
for (const key of Object.keys(importMap)) {
|
|
185
|
-
mergedCreateStaticHashTable[key] = importMap[key];
|
|
186
|
-
}
|
|
187
173
|
const mergedCreateTable = {};
|
|
188
174
|
for (const key of Object.keys(scannedTables.createHashTable)) {
|
|
189
175
|
mergedCreateTable[key] = scannedTables.createHashTable[key];
|
|
@@ -198,6 +184,32 @@ export function plumeria(options = {}) {
|
|
|
198
184
|
for (const key of Object.keys(importMap)) {
|
|
199
185
|
mergedVariantsTable[key] = importMap[key];
|
|
200
186
|
}
|
|
187
|
+
const mergedCreateThemeHashTable = {};
|
|
188
|
+
for (const key of Object.keys(scannedTables.createThemeHashTable)) {
|
|
189
|
+
mergedCreateThemeHashTable[key] =
|
|
190
|
+
scannedTables.createThemeHashTable[key];
|
|
191
|
+
if (key.startsWith(`${resourcePath}-`)) {
|
|
192
|
+
const varName = key.slice(resourcePath.length + 1);
|
|
193
|
+
mergedCreateThemeHashTable[varName] =
|
|
194
|
+
scannedTables.createThemeHashTable[key];
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
for (const key of Object.keys(createThemeImportMap)) {
|
|
198
|
+
mergedCreateThemeHashTable[key] = createThemeImportMap[key];
|
|
199
|
+
}
|
|
200
|
+
const mergedCreateStaticHashTable = {};
|
|
201
|
+
for (const key of Object.keys(scannedTables.createStaticHashTable)) {
|
|
202
|
+
mergedCreateStaticHashTable[key] =
|
|
203
|
+
scannedTables.createStaticHashTable[key];
|
|
204
|
+
if (key.startsWith(`${resourcePath}-`)) {
|
|
205
|
+
const varName = key.slice(resourcePath.length + 1);
|
|
206
|
+
mergedCreateStaticHashTable[varName] =
|
|
207
|
+
scannedTables.createStaticHashTable[key];
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
for (const key of Object.keys(createStaticImportMap)) {
|
|
211
|
+
mergedCreateStaticHashTable[key] = createStaticImportMap[key];
|
|
212
|
+
}
|
|
201
213
|
const localCreateStyles = {};
|
|
202
214
|
const replacements = [];
|
|
203
215
|
const extractedSheets = [];
|
|
@@ -285,27 +297,11 @@ export function plumeria(options = {}) {
|
|
|
285
297
|
};
|
|
286
298
|
}
|
|
287
299
|
}
|
|
288
|
-
else if ((propName === 'createTheme' || propName === 'createStatic') &&
|
|
289
|
-
(t.isObjectExpression(node.init.arguments[0].expression) ||
|
|
290
|
-
t.isStringLiteral(node.init.arguments[0].expression))) {
|
|
291
|
-
localCreateStyles[node.id.value] = {
|
|
292
|
-
name: node.id.value,
|
|
293
|
-
type: 'constant',
|
|
294
|
-
obj: {},
|
|
295
|
-
hashMap: {},
|
|
296
|
-
isExported,
|
|
297
|
-
initSpan: {
|
|
298
|
-
start: node.init.span.start - ast.span.start,
|
|
299
|
-
end: node.init.span.end - ast.span.start,
|
|
300
|
-
},
|
|
301
|
-
declSpan: {
|
|
302
|
-
start: declSpan.start - ast.span.start,
|
|
303
|
-
end: declSpan.end - ast.span.start,
|
|
304
|
-
},
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
300
|
else if (propName === 'variants' &&
|
|
308
301
|
t.isObjectExpression(node.init.arguments[0].expression)) {
|
|
302
|
+
if (t.isIdentifier(node.id)) {
|
|
303
|
+
idSpans.add(node.id.span.start);
|
|
304
|
+
}
|
|
309
305
|
const obj = objectExpressionToObject(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, (name) => {
|
|
310
306
|
if (localCreateStyles[name]) {
|
|
311
307
|
return localCreateStyles[name].obj;
|
|
@@ -334,6 +330,32 @@ export function plumeria(options = {}) {
|
|
|
334
330
|
},
|
|
335
331
|
};
|
|
336
332
|
}
|
|
333
|
+
else if (propName === 'createTheme' &&
|
|
334
|
+
t.isObjectExpression(node.init.arguments[0].expression)) {
|
|
335
|
+
if (t.isIdentifier(node.id)) {
|
|
336
|
+
idSpans.add(node.id.span.start);
|
|
337
|
+
}
|
|
338
|
+
const obj = objectExpressionToObject(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
339
|
+
const hash = genBase36Hash(obj, 1, 8);
|
|
340
|
+
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
341
|
+
scannedTables.createThemeHashTable[uniqueKey] = hash;
|
|
342
|
+
scannedTables.createThemeObjectTable[hash] = obj;
|
|
343
|
+
localCreateStyles[node.id.value] = {
|
|
344
|
+
name: node.id.value,
|
|
345
|
+
type: 'constant',
|
|
346
|
+
obj,
|
|
347
|
+
hashMap: scannedTables.createAtomicMapTable[hash],
|
|
348
|
+
isExported,
|
|
349
|
+
initSpan: {
|
|
350
|
+
start: node.init.span.start - ast.span.start,
|
|
351
|
+
end: node.init.span.end - ast.span.start,
|
|
352
|
+
},
|
|
353
|
+
declSpan: {
|
|
354
|
+
start: declSpan.start - ast.span.start,
|
|
355
|
+
end: declSpan.end - ast.span.start,
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
}
|
|
337
359
|
}
|
|
338
360
|
};
|
|
339
361
|
traverse(ast, {
|
|
@@ -406,7 +428,6 @@ export function plumeria(options = {}) {
|
|
|
406
428
|
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
407
429
|
const hash = genBase36Hash(obj, 1, 8);
|
|
408
430
|
scannedTables.viewTransitionObjectTable[hash] = obj;
|
|
409
|
-
extractOndemandStyles(obj, extractedSheets, scannedTables);
|
|
410
431
|
extractOndemandStyles({ vt: `vt-${hash}` }, extractedSheets, scannedTables);
|
|
411
432
|
replacements.push({
|
|
412
433
|
start: node.span.start - ast.span.start,
|
|
@@ -414,12 +435,23 @@ export function plumeria(options = {}) {
|
|
|
414
435
|
content: JSON.stringify(`vt-${hash}`),
|
|
415
436
|
});
|
|
416
437
|
}
|
|
417
|
-
else if (propName === 'createTheme' &&
|
|
438
|
+
else if ((propName === 'createTheme' || propName === 'createStatic') &&
|
|
418
439
|
args.length > 0 &&
|
|
419
440
|
t.isObjectExpression(args[0].expression)) {
|
|
420
441
|
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
421
442
|
const hash = genBase36Hash(obj, 1, 8);
|
|
422
|
-
|
|
443
|
+
if (propName === 'createTheme') {
|
|
444
|
+
scannedTables.createThemeObjectTable[hash] = obj;
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
scannedTables.createStaticObjectTable[hash] = obj;
|
|
448
|
+
}
|
|
449
|
+
const prefix = propName === 'createTheme' ? 'tm-' : 'st-';
|
|
450
|
+
replacements.push({
|
|
451
|
+
start: node.span.start - ast.span.start,
|
|
452
|
+
end: node.span.end - ast.span.start,
|
|
453
|
+
content: JSON.stringify(`${prefix}${hash}`),
|
|
454
|
+
});
|
|
423
455
|
}
|
|
424
456
|
else if (propName === 'create' &&
|
|
425
457
|
args.length > 0 &&
|
|
@@ -443,7 +475,7 @@ export function plumeria(options = {}) {
|
|
|
443
475
|
if (t.isIdentifier(node.object) && t.isIdentifier(node.property)) {
|
|
444
476
|
const varName = node.object.value;
|
|
445
477
|
const propName = node.property.value;
|
|
446
|
-
const uniqueKey = `${
|
|
478
|
+
const uniqueKey = `${resourcePath}-${varName}`;
|
|
447
479
|
let hash = scannedTables.createHashTable[uniqueKey];
|
|
448
480
|
if (!hash) {
|
|
449
481
|
hash = mergedCreateTable[varName];
|
|
@@ -466,14 +498,12 @@ export function plumeria(options = {}) {
|
|
|
466
498
|
themeHash = mergedCreateThemeHashTable[varName];
|
|
467
499
|
}
|
|
468
500
|
if (themeHash) {
|
|
469
|
-
const
|
|
470
|
-
if (
|
|
471
|
-
const camelToKebabCase = (str) => str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
472
|
-
const cssVarName = camelToKebabCase(propName);
|
|
501
|
+
const atomicMap = scannedTables.createAtomicMapTable[themeHash];
|
|
502
|
+
if (atomicMap && atomicMap && atomicMap[propName]) {
|
|
473
503
|
replacements.push({
|
|
474
504
|
start: node.span.start - ast.span.start,
|
|
475
505
|
end: node.span.end - ast.span.start,
|
|
476
|
-
content: JSON.stringify(
|
|
506
|
+
content: JSON.stringify(atomicMap[propName]),
|
|
477
507
|
});
|
|
478
508
|
}
|
|
479
509
|
}
|
|
@@ -508,7 +538,7 @@ export function plumeria(options = {}) {
|
|
|
508
538
|
return;
|
|
509
539
|
}
|
|
510
540
|
const varName = node.value;
|
|
511
|
-
const uniqueKey = `${
|
|
541
|
+
const uniqueKey = `${resourcePath}-${varName}`;
|
|
512
542
|
let hash = scannedTables.createHashTable[uniqueKey];
|
|
513
543
|
if (!hash) {
|
|
514
544
|
hash = mergedCreateTable[varName];
|
|
@@ -530,47 +560,19 @@ export function plumeria(options = {}) {
|
|
|
530
560
|
});
|
|
531
561
|
}
|
|
532
562
|
}
|
|
533
|
-
let kfHash = scannedTables.keyframesHashTable[uniqueKey];
|
|
534
|
-
if (!kfHash) {
|
|
535
|
-
kfHash = mergedKeyframesTable[varName];
|
|
536
|
-
}
|
|
537
|
-
if (kfHash) {
|
|
538
|
-
replacements.push({
|
|
539
|
-
start: node.span.start - ast.span.start,
|
|
540
|
-
end: node.span.end - ast.span.start,
|
|
541
|
-
content: JSON.stringify(`kf-${kfHash}`),
|
|
542
|
-
});
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
let vtHash = scannedTables.viewTransitionHashTable[uniqueKey];
|
|
546
|
-
if (!vtHash) {
|
|
547
|
-
vtHash = mergedViewTransitionTable[varName];
|
|
548
|
-
}
|
|
549
|
-
if (vtHash) {
|
|
550
|
-
replacements.push({
|
|
551
|
-
start: node.span.start - ast.span.start,
|
|
552
|
-
end: node.span.end - ast.span.start,
|
|
553
|
-
content: JSON.stringify(`vt-${vtHash}`),
|
|
554
|
-
});
|
|
555
|
-
return;
|
|
556
|
-
}
|
|
557
563
|
let themeHash = scannedTables.createThemeHashTable[uniqueKey];
|
|
558
564
|
if (!themeHash) {
|
|
559
565
|
themeHash = mergedCreateThemeHashTable[varName];
|
|
560
566
|
}
|
|
561
567
|
if (themeHash) {
|
|
562
|
-
const
|
|
563
|
-
if (
|
|
564
|
-
const themeVars = {};
|
|
565
|
-
const camelToKebabCase = (str) => str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
566
|
-
Object.keys(themeObj).forEach((key) => {
|
|
567
|
-
themeVars[key] = `var(--${camelToKebabCase(key)})`;
|
|
568
|
-
});
|
|
568
|
+
const atomicMap = scannedTables.createAtomicMapTable[themeHash];
|
|
569
|
+
if (atomicMap) {
|
|
569
570
|
replacements.push({
|
|
570
571
|
start: node.span.start - ast.span.start,
|
|
571
572
|
end: node.span.end - ast.span.start,
|
|
572
|
-
content: JSON.stringify(
|
|
573
|
+
content: JSON.stringify(atomicMap),
|
|
573
574
|
});
|
|
575
|
+
return;
|
|
574
576
|
}
|
|
575
577
|
}
|
|
576
578
|
let staticHash = scannedTables.createStaticHashTable[uniqueKey];
|
|
@@ -644,17 +646,21 @@ export function plumeria(options = {}) {
|
|
|
644
646
|
}
|
|
645
647
|
else if (t.isIdentifier(expr)) {
|
|
646
648
|
const varName = expr.value;
|
|
647
|
-
const
|
|
648
|
-
|
|
649
|
-
|
|
649
|
+
const uniqueKey = `${this.resourcePath}-${varName}`;
|
|
650
|
+
let hash = scannedTables.createHashTable[uniqueKey];
|
|
651
|
+
if (!hash) {
|
|
652
|
+
hash = mergedCreateTable[varName];
|
|
650
653
|
}
|
|
651
|
-
const hash = mergedCreateTable[varName];
|
|
652
654
|
if (hash) {
|
|
653
655
|
const obj = scannedTables.createObjectTable[hash];
|
|
654
656
|
if (obj && typeof obj === 'object') {
|
|
655
657
|
return obj;
|
|
656
658
|
}
|
|
657
659
|
}
|
|
660
|
+
const styleInfo = localCreateStyles[varName];
|
|
661
|
+
if (styleInfo && styleInfo.obj) {
|
|
662
|
+
return styleInfo.obj;
|
|
663
|
+
}
|
|
658
664
|
if (localCreateStyles[varName]) {
|
|
659
665
|
return localCreateStyles[varName].obj;
|
|
660
666
|
}
|
|
@@ -674,14 +680,18 @@ export function plumeria(options = {}) {
|
|
|
674
680
|
if (t.isCallExpression(expr) && t.isIdentifier(expr.callee)) {
|
|
675
681
|
const varName = expr.callee.value;
|
|
676
682
|
let variantObj;
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
683
|
+
const uniqueKey = `${this.resourcePath}-${varName}`;
|
|
684
|
+
let hash = scannedTables.variantsHashTable[uniqueKey];
|
|
685
|
+
if (!hash) {
|
|
686
|
+
hash = mergedVariantsTable[varName];
|
|
687
|
+
}
|
|
688
|
+
if (hash && scannedTables.variantsObjectTable[hash]) {
|
|
689
|
+
variantObj = scannedTables.variantsObjectTable[hash];
|
|
680
690
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
variantObj =
|
|
691
|
+
if (!variantObj) {
|
|
692
|
+
if (localCreateStyles[varName] &&
|
|
693
|
+
localCreateStyles[varName].obj) {
|
|
694
|
+
variantObj = localCreateStyles[varName].obj;
|
|
685
695
|
}
|
|
686
696
|
}
|
|
687
697
|
if (variantObj) {
|
|
@@ -838,7 +848,7 @@ export function plumeria(options = {}) {
|
|
|
838
848
|
extractOndemandStyles(currentStyle, extractedSheets, scannedTables);
|
|
839
849
|
const hash = genBase36Hash(currentStyle, 1, 8);
|
|
840
850
|
const records = getStyleRecords(hash, currentStyle, 2);
|
|
841
|
-
records.forEach((r) =>
|
|
851
|
+
records.forEach((r) => extractedSheets.push(r.sheet));
|
|
842
852
|
const className = records
|
|
843
853
|
.map((r) => r.hash)
|
|
844
854
|
.join(' ');
|
|
@@ -873,6 +883,9 @@ export function plumeria(options = {}) {
|
|
|
873
883
|
},
|
|
874
884
|
});
|
|
875
885
|
Object.values(localCreateStyles).forEach((info) => {
|
|
886
|
+
if (info.type === 'constant' || info.type === 'variant') {
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
876
889
|
if (info.isExported) {
|
|
877
890
|
replacements.push({
|
|
878
891
|
start: info.declSpan.start,
|
|
@@ -901,7 +914,7 @@ export function plumeria(options = {}) {
|
|
|
901
914
|
offset = r.end;
|
|
902
915
|
});
|
|
903
916
|
parts.push(buffer.subarray(offset));
|
|
904
|
-
const
|
|
917
|
+
const transformedSource = Buffer.concat(parts).toString();
|
|
905
918
|
if (extractedSheets.length > 0) {
|
|
906
919
|
const generatedCSS = extractedSheets.join('');
|
|
907
920
|
const baseId = id.replace(EXTENSION_PATTERN, '');
|
|
@@ -925,12 +938,12 @@ export function plumeria(options = {}) {
|
|
|
925
938
|
devServer.reloadModule(cssModule);
|
|
926
939
|
}
|
|
927
940
|
return {
|
|
928
|
-
code: injectImport(
|
|
941
|
+
code: injectImport(transformedSource, id, cssFilename),
|
|
929
942
|
map: null,
|
|
930
943
|
};
|
|
931
944
|
}
|
|
932
945
|
return {
|
|
933
|
-
code:
|
|
946
|
+
code: transformedSource,
|
|
934
947
|
map: null,
|
|
935
948
|
};
|
|
936
949
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/vite-plugin",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
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.
|
|
25
|
+
"@plumeria/utils": "^6.3.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.8",
|