@plumeria/vite-plugin 8.0.1 → 8.0.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.
- package/dist/index.js +80 -63
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { parseSync } from '@swc/core';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { genBase36Hash } from 'zss-engine';
|
|
5
5
|
import { traverse, getStyleRecords, collectLocalConsts, objectExpressionToObject, t, extractOndemandStyles, deepMerge, scanAll, resolveImportPath, optimizer, processVariants, } from '@plumeria/utils';
|
|
6
|
+
import { getLeadingCommentLength } from '@plumeria/utils';
|
|
6
7
|
const TARGET_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx'];
|
|
7
8
|
const EXTENSION_PATTERN = /\.(ts|tsx|js|jsx)$/;
|
|
8
9
|
export function plumeria(options = {}) {
|
|
@@ -83,6 +84,10 @@ export function plumeria(options = {}) {
|
|
|
83
84
|
tsx: true,
|
|
84
85
|
target: 'es2022',
|
|
85
86
|
});
|
|
87
|
+
const leadingLen = getLeadingCommentLength(source);
|
|
88
|
+
const sourceBuffer = Buffer.from(source, 'utf-8');
|
|
89
|
+
const leadingBytes = Buffer.byteLength(source.slice(0, leadingLen), 'utf-8');
|
|
90
|
+
const baseByteOffset = ast.span.start - leadingBytes;
|
|
86
91
|
for (const node of ast.body) {
|
|
87
92
|
if (node.type === 'ImportDeclaration') {
|
|
88
93
|
const sourcePath = node.source.value;
|
|
@@ -93,6 +98,12 @@ export function plumeria(options = {}) {
|
|
|
93
98
|
}
|
|
94
99
|
}
|
|
95
100
|
const scannedTables = scanAll();
|
|
101
|
+
const extractedSheets = [];
|
|
102
|
+
const addSheet = (sheet) => {
|
|
103
|
+
if (!extractedSheets.includes(sheet)) {
|
|
104
|
+
extractedSheets.push(sheet);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
96
107
|
const localConsts = collectLocalConsts(ast);
|
|
97
108
|
const resourcePath = id;
|
|
98
109
|
const importMap = {};
|
|
@@ -226,12 +237,6 @@ export function plumeria(options = {}) {
|
|
|
226
237
|
}
|
|
227
238
|
const localCreateStyles = {};
|
|
228
239
|
const replacements = [];
|
|
229
|
-
const extractedSheets = [];
|
|
230
|
-
const addSheet = (sheet) => {
|
|
231
|
-
if (!extractedSheets.includes(sheet)) {
|
|
232
|
-
extractedSheets.push(sheet);
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
240
|
const processedDecls = new Set();
|
|
236
241
|
const idSpans = new Set();
|
|
237
242
|
const excludedSpans = new Set();
|
|
@@ -298,12 +303,12 @@ export function plumeria(options = {}) {
|
|
|
298
303
|
hashMap,
|
|
299
304
|
isExported,
|
|
300
305
|
initSpan: {
|
|
301
|
-
start: node.init.span.start -
|
|
302
|
-
end: node.init.span.end -
|
|
306
|
+
start: node.init.span.start - baseByteOffset,
|
|
307
|
+
end: node.init.span.end - baseByteOffset,
|
|
303
308
|
},
|
|
304
309
|
declSpan: {
|
|
305
|
-
start: declSpan.start -
|
|
306
|
-
end: declSpan.end -
|
|
310
|
+
start: declSpan.start - baseByteOffset,
|
|
311
|
+
end: declSpan.end - baseByteOffset,
|
|
307
312
|
},
|
|
308
313
|
};
|
|
309
314
|
}
|
|
@@ -333,12 +338,12 @@ export function plumeria(options = {}) {
|
|
|
333
338
|
hashMap,
|
|
334
339
|
isExported,
|
|
335
340
|
initSpan: {
|
|
336
|
-
start: node.init.span.start -
|
|
337
|
-
end: node.init.span.end -
|
|
341
|
+
start: node.init.span.start - baseByteOffset,
|
|
342
|
+
end: node.init.span.end - baseByteOffset,
|
|
338
343
|
},
|
|
339
344
|
declSpan: {
|
|
340
|
-
start: declSpan.start -
|
|
341
|
-
end: declSpan.end -
|
|
345
|
+
start: declSpan.start - baseByteOffset,
|
|
346
|
+
end: declSpan.end - baseByteOffset,
|
|
342
347
|
},
|
|
343
348
|
};
|
|
344
349
|
}
|
|
@@ -359,12 +364,12 @@ export function plumeria(options = {}) {
|
|
|
359
364
|
hashMap: scannedTables.createAtomicMapTable[hash],
|
|
360
365
|
isExported,
|
|
361
366
|
initSpan: {
|
|
362
|
-
start: node.init.span.start -
|
|
363
|
-
end: node.init.span.end -
|
|
367
|
+
start: node.init.span.start - baseByteOffset,
|
|
368
|
+
end: node.init.span.end - baseByteOffset,
|
|
364
369
|
},
|
|
365
370
|
declSpan: {
|
|
366
|
-
start: declSpan.start -
|
|
367
|
-
end: declSpan.end -
|
|
371
|
+
start: declSpan.start - baseByteOffset,
|
|
372
|
+
end: declSpan.end - baseByteOffset,
|
|
368
373
|
},
|
|
369
374
|
};
|
|
370
375
|
}
|
|
@@ -429,8 +434,8 @@ export function plumeria(options = {}) {
|
|
|
429
434
|
const hash = genBase36Hash(obj, 1, 8);
|
|
430
435
|
scannedTables.keyframesObjectTable[hash] = obj;
|
|
431
436
|
replacements.push({
|
|
432
|
-
start: node.span.start -
|
|
433
|
-
end: node.span.end -
|
|
437
|
+
start: node.span.start - baseByteOffset,
|
|
438
|
+
end: node.span.end - baseByteOffset,
|
|
434
439
|
content: JSON.stringify(`kf-${hash}`),
|
|
435
440
|
});
|
|
436
441
|
}
|
|
@@ -441,8 +446,8 @@ export function plumeria(options = {}) {
|
|
|
441
446
|
const hash = genBase36Hash(obj, 1, 8);
|
|
442
447
|
scannedTables.viewTransitionObjectTable[hash] = obj;
|
|
443
448
|
replacements.push({
|
|
444
|
-
start: node.span.start -
|
|
445
|
-
end: node.span.end -
|
|
449
|
+
start: node.span.start - baseByteOffset,
|
|
450
|
+
end: node.span.end - baseByteOffset,
|
|
446
451
|
content: JSON.stringify(`vt-${hash}`),
|
|
447
452
|
});
|
|
448
453
|
}
|
|
@@ -459,8 +464,8 @@ export function plumeria(options = {}) {
|
|
|
459
464
|
}
|
|
460
465
|
const prefix = propName === 'createTheme' ? 'tm-' : 'st-';
|
|
461
466
|
replacements.push({
|
|
462
|
-
start: node.span.start -
|
|
463
|
-
end: node.span.end -
|
|
467
|
+
start: node.span.start - baseByteOffset,
|
|
468
|
+
end: node.span.end - baseByteOffset,
|
|
464
469
|
content: JSON.stringify(`${prefix}${hash}`),
|
|
465
470
|
});
|
|
466
471
|
}
|
|
@@ -491,8 +496,8 @@ export function plumeria(options = {}) {
|
|
|
491
496
|
}
|
|
492
497
|
if (atomMap) {
|
|
493
498
|
replacements.push({
|
|
494
|
-
start: node.span.start -
|
|
495
|
-
end: node.span.end -
|
|
499
|
+
start: node.span.start - baseByteOffset,
|
|
500
|
+
end: node.span.end - baseByteOffset,
|
|
496
501
|
content: JSON.stringify(atomMap),
|
|
497
502
|
});
|
|
498
503
|
}
|
|
@@ -505,8 +510,8 @@ export function plumeria(options = {}) {
|
|
|
505
510
|
const atomicMap = scannedTables.createAtomicMapTable[themeHash];
|
|
506
511
|
if (atomicMap && atomicMap && atomicMap[propName]) {
|
|
507
512
|
replacements.push({
|
|
508
|
-
start: node.span.start -
|
|
509
|
-
end: node.span.end -
|
|
513
|
+
start: node.span.start - baseByteOffset,
|
|
514
|
+
end: node.span.end - baseByteOffset,
|
|
510
515
|
content: JSON.stringify(atomicMap[propName]),
|
|
511
516
|
});
|
|
512
517
|
}
|
|
@@ -519,8 +524,8 @@ export function plumeria(options = {}) {
|
|
|
519
524
|
const staticObj = scannedTables.createStaticObjectTable[staticHash];
|
|
520
525
|
if (staticObj && staticObj[propName] !== undefined) {
|
|
521
526
|
replacements.push({
|
|
522
|
-
start: node.span.start -
|
|
523
|
-
end: node.span.end -
|
|
527
|
+
start: node.span.start - baseByteOffset,
|
|
528
|
+
end: node.span.end - baseByteOffset,
|
|
524
529
|
content: JSON.stringify(staticObj[propName]),
|
|
525
530
|
});
|
|
526
531
|
}
|
|
@@ -535,8 +540,8 @@ export function plumeria(options = {}) {
|
|
|
535
540
|
const styleInfo = localCreateStyles[node.value];
|
|
536
541
|
if (styleInfo) {
|
|
537
542
|
replacements.push({
|
|
538
|
-
start: node.span.start -
|
|
539
|
-
end: node.span.end -
|
|
543
|
+
start: node.span.start - baseByteOffset,
|
|
544
|
+
end: node.span.end - baseByteOffset,
|
|
540
545
|
content: JSON.stringify(styleInfo.hashMap),
|
|
541
546
|
});
|
|
542
547
|
return;
|
|
@@ -558,8 +563,8 @@ export function plumeria(options = {}) {
|
|
|
558
563
|
}
|
|
559
564
|
});
|
|
560
565
|
replacements.push({
|
|
561
|
-
start: node.span.start -
|
|
562
|
-
end: node.span.end -
|
|
566
|
+
start: node.span.start - baseByteOffset,
|
|
567
|
+
end: node.span.end - baseByteOffset,
|
|
563
568
|
content: JSON.stringify(hashMap),
|
|
564
569
|
});
|
|
565
570
|
}
|
|
@@ -572,8 +577,8 @@ export function plumeria(options = {}) {
|
|
|
572
577
|
const atomicMap = scannedTables.createAtomicMapTable[themeHash];
|
|
573
578
|
if (atomicMap) {
|
|
574
579
|
replacements.push({
|
|
575
|
-
start: node.span.start -
|
|
576
|
-
end: node.span.end -
|
|
580
|
+
start: node.span.start - baseByteOffset,
|
|
581
|
+
end: node.span.end - baseByteOffset,
|
|
577
582
|
content: JSON.stringify(atomicMap),
|
|
578
583
|
});
|
|
579
584
|
return;
|
|
@@ -587,8 +592,8 @@ export function plumeria(options = {}) {
|
|
|
587
592
|
const staticObj = scannedTables.createStaticObjectTable[staticHash];
|
|
588
593
|
if (staticObj) {
|
|
589
594
|
replacements.push({
|
|
590
|
-
start: node.span.start -
|
|
591
|
-
end: node.span.end -
|
|
595
|
+
start: node.span.start - baseByteOffset,
|
|
596
|
+
end: node.span.end - baseByteOffset,
|
|
592
597
|
content: JSON.stringify(staticObj),
|
|
593
598
|
});
|
|
594
599
|
}
|
|
@@ -720,9 +725,11 @@ export function plumeria(options = {}) {
|
|
|
720
725
|
if (!groupVariants)
|
|
721
726
|
continue;
|
|
722
727
|
const currentGroupId = ++groupIdCounter;
|
|
723
|
-
const valStart = valExpr.span.start -
|
|
724
|
-
const valEnd = valExpr.span.end -
|
|
725
|
-
const valSource =
|
|
728
|
+
const valStart = valExpr.span.start - baseByteOffset;
|
|
729
|
+
const valEnd = valExpr.span.end - baseByteOffset;
|
|
730
|
+
const valSource = sourceBuffer
|
|
731
|
+
.subarray(valStart, valEnd)
|
|
732
|
+
.toString('utf-8');
|
|
726
733
|
if (valExpr.type === 'StringLiteral') {
|
|
727
734
|
if (groupVariants[valExpr.value]) {
|
|
728
735
|
baseStyle = deepMerge(baseStyle, groupVariants[valExpr.value]);
|
|
@@ -746,9 +753,11 @@ export function plumeria(options = {}) {
|
|
|
746
753
|
}
|
|
747
754
|
continue;
|
|
748
755
|
}
|
|
749
|
-
const argStart = arg.span.start -
|
|
750
|
-
const argEnd = arg.span.end -
|
|
751
|
-
const argSource =
|
|
756
|
+
const argStart = arg.span.start - baseByteOffset;
|
|
757
|
+
const argEnd = arg.span.end - baseByteOffset;
|
|
758
|
+
const argSource = sourceBuffer
|
|
759
|
+
.subarray(argStart, argEnd)
|
|
760
|
+
.toString('utf-8');
|
|
752
761
|
if (t.isStringLiteral(arg)) {
|
|
753
762
|
if (variantObj[arg.value]) {
|
|
754
763
|
baseStyle = deepMerge(baseStyle, variantObj[arg.value]);
|
|
@@ -815,9 +824,9 @@ export function plumeria(options = {}) {
|
|
|
815
824
|
}
|
|
816
825
|
}
|
|
817
826
|
const getSource = (node) => {
|
|
818
|
-
const start = node.span.start -
|
|
819
|
-
const end = node.span.end -
|
|
820
|
-
return
|
|
827
|
+
const start = node.span.start - baseByteOffset;
|
|
828
|
+
const end = node.span.end - baseByteOffset;
|
|
829
|
+
return sourceBuffer.subarray(start, end).toString('utf-8');
|
|
821
830
|
};
|
|
822
831
|
const collectConditions = (node, currentTestStrings = []) => {
|
|
823
832
|
const staticStyle = resolveStyleObject(node);
|
|
@@ -891,8 +900,8 @@ export function plumeria(options = {}) {
|
|
|
891
900
|
.map((r) => r.hash)
|
|
892
901
|
.join(' ');
|
|
893
902
|
replacements.push({
|
|
894
|
-
start: node.span.start -
|
|
895
|
-
end: node.span.end -
|
|
903
|
+
start: node.span.start - baseByteOffset,
|
|
904
|
+
end: node.span.end - baseByteOffset,
|
|
896
905
|
content: JSON.stringify(className),
|
|
897
906
|
});
|
|
898
907
|
}
|
|
@@ -1015,9 +1024,11 @@ export function plumeria(options = {}) {
|
|
|
1015
1024
|
const fClass = processBranch(c.falsy);
|
|
1016
1025
|
let testStr = c.testString;
|
|
1017
1026
|
if (!testStr && c.test) {
|
|
1018
|
-
const start = c.test.span.start -
|
|
1019
|
-
const end = c.test.span.end -
|
|
1020
|
-
testStr =
|
|
1027
|
+
const start = c.test.span.start - baseByteOffset;
|
|
1028
|
+
const end = c.test.span.end - baseByteOffset;
|
|
1029
|
+
testStr = sourceBuffer
|
|
1030
|
+
.subarray(start, end)
|
|
1031
|
+
.toString('utf-8');
|
|
1021
1032
|
}
|
|
1022
1033
|
classParts.push(`(${testStr} ? ${tClass} : ${fClass})`);
|
|
1023
1034
|
});
|
|
@@ -1041,9 +1052,11 @@ export function plumeria(options = {}) {
|
|
|
1041
1052
|
}
|
|
1042
1053
|
else {
|
|
1043
1054
|
const firstTest = options[0].test;
|
|
1044
|
-
const firstStart = firstTest.span.start -
|
|
1045
|
-
const firstEnd = firstTest.span.end -
|
|
1046
|
-
commonTestExpr =
|
|
1055
|
+
const firstStart = firstTest.span.start - baseByteOffset;
|
|
1056
|
+
const firstEnd = firstTest.span.end - baseByteOffset;
|
|
1057
|
+
commonTestExpr = sourceBuffer
|
|
1058
|
+
.subarray(firstStart, firstEnd)
|
|
1059
|
+
.toString('utf-8');
|
|
1047
1060
|
}
|
|
1048
1061
|
options.forEach((opt) => {
|
|
1049
1062
|
if (opt.valueName && opt.truthy) {
|
|
@@ -1077,9 +1090,11 @@ export function plumeria(options = {}) {
|
|
|
1077
1090
|
conflictStd.forEach((c) => {
|
|
1078
1091
|
let testStr = c.testString;
|
|
1079
1092
|
if (!testStr && c.test) {
|
|
1080
|
-
const start = c.test.span.start -
|
|
1081
|
-
const end = c.test.span.end -
|
|
1082
|
-
testStr =
|
|
1093
|
+
const start = c.test.span.start - baseByteOffset;
|
|
1094
|
+
const end = c.test.span.end - baseByteOffset;
|
|
1095
|
+
testStr = sourceBuffer
|
|
1096
|
+
.subarray(start, end)
|
|
1097
|
+
.toString('utf-8');
|
|
1083
1098
|
}
|
|
1084
1099
|
dimensions.push({
|
|
1085
1100
|
type: 'std',
|
|
@@ -1101,9 +1116,11 @@ export function plumeria(options = {}) {
|
|
|
1101
1116
|
}
|
|
1102
1117
|
else {
|
|
1103
1118
|
const firstTest = opts[0].test;
|
|
1104
|
-
const firstStart = firstTest.span.start -
|
|
1105
|
-
const firstEnd = firstTest.span.end -
|
|
1106
|
-
commonTestExpr =
|
|
1119
|
+
const firstStart = firstTest.span.start - baseByteOffset;
|
|
1120
|
+
const firstEnd = firstTest.span.end - baseByteOffset;
|
|
1121
|
+
commonTestExpr = sourceBuffer
|
|
1122
|
+
.subarray(firstStart, firstEnd)
|
|
1123
|
+
.toString('utf-8');
|
|
1107
1124
|
}
|
|
1108
1125
|
}
|
|
1109
1126
|
const options = opts.map((opt) => ({
|
|
@@ -1160,8 +1177,8 @@ export function plumeria(options = {}) {
|
|
|
1160
1177
|
}
|
|
1161
1178
|
const replacement = classParts.length > 0 ? classParts.join(' + " " + ') : '""';
|
|
1162
1179
|
replacements.push({
|
|
1163
|
-
start: node.span.start -
|
|
1164
|
-
end: node.span.end -
|
|
1180
|
+
start: node.span.start - baseByteOffset,
|
|
1181
|
+
end: node.span.end - baseByteOffset,
|
|
1165
1182
|
content: replacement,
|
|
1166
1183
|
});
|
|
1167
1184
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/vite-plugin",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
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": "^8.0.
|
|
25
|
+
"@plumeria/utils": "^8.0.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.8",
|