@plumeria/vite-plugin 6.3.1 → 7.0.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 +80 -40
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -269,7 +269,7 @@ export function plumeria(options = {}) {
|
|
|
269
269
|
if (obj) {
|
|
270
270
|
const hashMap = {};
|
|
271
271
|
Object.entries(obj).forEach(([key, style]) => {
|
|
272
|
-
const records = getStyleRecords(
|
|
272
|
+
const records = getStyleRecords(style);
|
|
273
273
|
extractOndemandStyles(style, extractedSheets, scannedTables);
|
|
274
274
|
records.forEach((r) => {
|
|
275
275
|
addSheet(r.sheet);
|
|
@@ -461,9 +461,9 @@ export function plumeria(options = {}) {
|
|
|
461
461
|
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
462
462
|
const hash = genBase36Hash(obj, 1, 8);
|
|
463
463
|
scannedTables.createObjectTable[hash] = obj;
|
|
464
|
-
Object.entries(obj).forEach(([
|
|
464
|
+
Object.entries(obj).forEach(([_key, style]) => {
|
|
465
465
|
if (typeof style === 'object' && style !== null) {
|
|
466
|
-
const records = getStyleRecords(
|
|
466
|
+
const records = getStyleRecords(style);
|
|
467
467
|
extractOndemandStyles(style, extractedSheets, scannedTables);
|
|
468
468
|
records.forEach((r) => addSheet(r.sheet));
|
|
469
469
|
}
|
|
@@ -809,8 +809,7 @@ export function plumeria(options = {}) {
|
|
|
809
809
|
(args.length > 0 || Object.keys(baseStyle).length > 0)) {
|
|
810
810
|
if (conditionals.length === 0) {
|
|
811
811
|
extractOndemandStyles(baseStyle, extractedSheets, scannedTables);
|
|
812
|
-
const
|
|
813
|
-
const records = getStyleRecords(hash, baseStyle);
|
|
812
|
+
const records = getStyleRecords(baseStyle);
|
|
814
813
|
records.forEach((r) => addSheet(r.sheet));
|
|
815
814
|
const className = records
|
|
816
815
|
.map((r) => r.hash)
|
|
@@ -823,55 +822,96 @@ export function plumeria(options = {}) {
|
|
|
823
822
|
}
|
|
824
823
|
else {
|
|
825
824
|
const table = {};
|
|
826
|
-
const
|
|
827
|
-
|
|
825
|
+
const groups = {};
|
|
826
|
+
let strayIdCounter = groupIdCounter + 1;
|
|
827
|
+
conditionals.forEach((c) => {
|
|
828
|
+
const gid = c.groupId !== undefined ? c.groupId : strayIdCounter++;
|
|
829
|
+
if (!groups[gid]) {
|
|
830
|
+
groups[gid] = [];
|
|
831
|
+
}
|
|
832
|
+
groups[gid].push(c);
|
|
833
|
+
});
|
|
834
|
+
const sortedGroupIds = Object.keys(groups)
|
|
835
|
+
.map(Number)
|
|
836
|
+
.sort((a, b) => a - b);
|
|
837
|
+
let totalCombinations = 1;
|
|
838
|
+
const groupMeta = sortedGroupIds.map((gid) => {
|
|
839
|
+
const options = groups[gid];
|
|
840
|
+
const isVariantGroup = options[0].groupId !== undefined;
|
|
841
|
+
const size = isVariantGroup ? options.length : 2;
|
|
842
|
+
const stride = totalCombinations;
|
|
843
|
+
totalCombinations *= size;
|
|
844
|
+
return { gid, options, size, stride, isVariantGroup };
|
|
845
|
+
});
|
|
846
|
+
for (let i = 0; i < totalCombinations; i++) {
|
|
828
847
|
let currentStyle = { ...baseStyle };
|
|
829
|
-
const
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
if (conditionals[j].groupId !== undefined) {
|
|
834
|
-
if (seenGroups.has(conditionals[j].groupId)) {
|
|
835
|
-
impossible = true;
|
|
836
|
-
break;
|
|
837
|
-
}
|
|
838
|
-
seenGroups.add(conditionals[j].groupId);
|
|
839
|
-
}
|
|
840
|
-
currentStyle = deepMerge(currentStyle, conditionals[j].truthy);
|
|
848
|
+
for (const meta of groupMeta) {
|
|
849
|
+
const localIndex = Math.floor(i / meta.stride) % meta.size;
|
|
850
|
+
if (meta.isVariantGroup) {
|
|
851
|
+
currentStyle = deepMerge(currentStyle, meta.options[localIndex].truthy);
|
|
841
852
|
}
|
|
842
853
|
else {
|
|
843
|
-
|
|
854
|
+
const cond = meta.options[0];
|
|
855
|
+
if (localIndex === 1) {
|
|
856
|
+
currentStyle = deepMerge(currentStyle, cond.truthy);
|
|
857
|
+
}
|
|
858
|
+
else {
|
|
859
|
+
currentStyle = deepMerge(currentStyle, cond.falsy);
|
|
860
|
+
}
|
|
844
861
|
}
|
|
845
862
|
}
|
|
846
|
-
if (impossible) {
|
|
847
|
-
table[i] = '';
|
|
848
|
-
continue;
|
|
849
|
-
}
|
|
850
863
|
extractOndemandStyles(currentStyle, extractedSheets, scannedTables);
|
|
851
|
-
const
|
|
852
|
-
const records = getStyleRecords(hash, currentStyle);
|
|
864
|
+
const records = getStyleRecords(currentStyle);
|
|
853
865
|
records.forEach((r) => extractedSheets.push(r.sheet));
|
|
854
866
|
const className = records
|
|
855
867
|
.map((r) => r.hash)
|
|
856
868
|
.join(' ');
|
|
857
869
|
table[i] = className;
|
|
858
870
|
}
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
871
|
+
const indexParts = [];
|
|
872
|
+
for (const meta of groupMeta) {
|
|
873
|
+
if (meta.isVariantGroup) {
|
|
874
|
+
const exprs = meta.options
|
|
875
|
+
.map((opt, idx) => {
|
|
876
|
+
if (idx === 0)
|
|
877
|
+
return null;
|
|
878
|
+
let testStr = opt.testString;
|
|
879
|
+
if (!testStr && opt.test) {
|
|
880
|
+
const start = opt.test.span.start - ast.span.start;
|
|
881
|
+
const end = opt.test.span.end - ast.span.start;
|
|
882
|
+
testStr = source.substring(start, end);
|
|
883
|
+
}
|
|
884
|
+
return `(!!(${testStr}) * ${idx})`;
|
|
885
|
+
})
|
|
886
|
+
.filter(Boolean);
|
|
887
|
+
if (exprs.length > 0) {
|
|
888
|
+
const groupSum = `(${exprs.join(' + ')})`;
|
|
889
|
+
if (meta.stride > 1) {
|
|
890
|
+
indexParts.push(`(${groupSum} * ${meta.stride})`);
|
|
891
|
+
}
|
|
892
|
+
else {
|
|
893
|
+
indexParts.push(groupSum);
|
|
894
|
+
}
|
|
867
895
|
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
const
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
896
|
+
}
|
|
897
|
+
else {
|
|
898
|
+
const cond = meta.options[0];
|
|
899
|
+
let testStr = cond.testString;
|
|
900
|
+
if (!testStr && cond.test) {
|
|
901
|
+
const start = cond.test.span.start - ast.span.start;
|
|
902
|
+
const end = cond.test.span.end - ast.span.start;
|
|
903
|
+
testStr = source.substring(start, end);
|
|
904
|
+
}
|
|
905
|
+
const expr = `(!!(${testStr}))`;
|
|
906
|
+
if (meta.stride > 1) {
|
|
907
|
+
indexParts.push(`(${expr} * ${meta.stride})`);
|
|
908
|
+
}
|
|
909
|
+
else {
|
|
910
|
+
indexParts.push(`(${expr} * 1)`);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
874
913
|
}
|
|
914
|
+
const indexExpr = indexParts.join(' + ') || '0';
|
|
875
915
|
const tableStr = JSON.stringify(table);
|
|
876
916
|
const replacement = `${tableStr}[${indexExpr}]`;
|
|
877
917
|
replacements.push({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/vite-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Plumeria Vite plugin",
|
|
6
6
|
"author": "Refirst 11",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"dist/"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@plumeria/utils": "^
|
|
25
|
+
"@plumeria/utils": "^7.0.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.8",
|
|
29
29
|
"vite": "^7.1.1",
|
|
30
|
-
"zss-engine": "2.2.
|
|
30
|
+
"zss-engine": "2.2.3"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public",
|