@plumeria/unplugin 18.1.1 → 18.1.3
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/core.js +36 -12
- package/dist/core.mjs +36 -12
- package/package.json +3 -3
package/dist/core.js
CHANGED
|
@@ -841,15 +841,15 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
841
841
|
? { varName, keyExpr: node.property.expression, obj }
|
|
842
842
|
: null;
|
|
843
843
|
};
|
|
844
|
-
const buildDecision = (node, prefix, off, counter) => {
|
|
844
|
+
const buildDecision = (node, prefix, off, counter, scoped) => {
|
|
845
845
|
if (node.type === 'ParenthesisExpression') {
|
|
846
|
-
return buildDecision(node.expression, prefix, off, counter);
|
|
846
|
+
return buildDecision(node.expression, prefix, off, counter, scoped);
|
|
847
847
|
}
|
|
848
848
|
if (node.type === 'ConditionalExpression') {
|
|
849
|
-
const a = buildDecision(node.consequent, prefix, off, counter);
|
|
849
|
+
const a = buildDecision(node.consequent, prefix, off, counter, scoped);
|
|
850
850
|
if (!a)
|
|
851
851
|
return null;
|
|
852
|
-
const b = buildDecision(node.alternate, prefix, off, counter);
|
|
852
|
+
const b = buildDecision(node.alternate, prefix, off, counter, scoped);
|
|
853
853
|
if (!b)
|
|
854
854
|
return null;
|
|
855
855
|
return {
|
|
@@ -860,7 +860,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
860
860
|
};
|
|
861
861
|
}
|
|
862
862
|
if (node.type === 'BinaryExpression' && node.operator === '&&') {
|
|
863
|
-
const right = buildDecision(node.right, prefix, off, counter);
|
|
863
|
+
const right = buildDecision(node.right, prefix, off, counter, scoped);
|
|
864
864
|
if (!right)
|
|
865
865
|
return null;
|
|
866
866
|
return {
|
|
@@ -872,10 +872,14 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
872
872
|
}
|
|
873
873
|
const group = resolveBracketGroup(node);
|
|
874
874
|
if (group) {
|
|
875
|
+
const tag = scoped ? `${counter.n++}:` : '';
|
|
876
|
+
const keySource = getSource(group.keyExpr);
|
|
875
877
|
return {
|
|
876
|
-
keyExpr:
|
|
878
|
+
keyExpr: tag
|
|
879
|
+
? `(${JSON.stringify(tag)} + ${keySource})`
|
|
880
|
+
: keySource,
|
|
877
881
|
options: Object.entries(group.obj).map(([value, style]) => ({
|
|
878
|
-
value
|
|
882
|
+
value: `${tag}${value}`,
|
|
879
883
|
style: style,
|
|
880
884
|
})),
|
|
881
885
|
leaves: 1,
|
|
@@ -908,17 +912,23 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
908
912
|
else {
|
|
909
913
|
const group = resolveBracketGroup(node);
|
|
910
914
|
if (group)
|
|
911
|
-
Object.
|
|
915
|
+
Object.entries(group.obj).forEach(([key, style]) => {
|
|
916
|
+
let styles = acc.get(key);
|
|
917
|
+
if (!styles)
|
|
918
|
+
acc.set(key, (styles = new Set()));
|
|
919
|
+
styles.add(style);
|
|
920
|
+
});
|
|
912
921
|
}
|
|
913
922
|
};
|
|
914
923
|
const resolveDecision = (node) => {
|
|
915
|
-
const groupKeys = new
|
|
924
|
+
const groupKeys = new Map();
|
|
916
925
|
collectGroupKeys(node, groupKeys);
|
|
917
926
|
let prefix = '#';
|
|
918
|
-
while ([...groupKeys].some((k) => k.startsWith(prefix)))
|
|
927
|
+
while ([...groupKeys.keys()].some((k) => k.startsWith(prefix)))
|
|
919
928
|
prefix += '#';
|
|
920
|
-
const
|
|
921
|
-
|
|
929
|
+
const scoped = [...groupKeys.values()].some((styles) => styles.size > 1);
|
|
930
|
+
const off = !scoped && groupKeys.has('') ? `${prefix}off` : '';
|
|
931
|
+
return buildDecision(node, prefix, off, { n: 0 }, scoped);
|
|
922
932
|
};
|
|
923
933
|
const collectConditions = (node, currentTestStrings = []) => {
|
|
924
934
|
const staticStyle = resolveStyleObject(node);
|
|
@@ -1195,6 +1205,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1195
1205
|
groupName: undefined,
|
|
1196
1206
|
valueName: optionName,
|
|
1197
1207
|
varName,
|
|
1208
|
+
ownKeys: true,
|
|
1198
1209
|
});
|
|
1199
1210
|
});
|
|
1200
1211
|
continue;
|
|
@@ -1215,6 +1226,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1215
1226
|
groupName: undefined,
|
|
1216
1227
|
valueName: value,
|
|
1217
1228
|
varName: undefined,
|
|
1229
|
+
ownKeys: true,
|
|
1218
1230
|
}));
|
|
1219
1231
|
continue;
|
|
1220
1232
|
}
|
|
@@ -1432,11 +1444,23 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1432
1444
|
style: opt.truthy,
|
|
1433
1445
|
label: opt.valueName || 'default',
|
|
1434
1446
|
})),
|
|
1447
|
+
ownKeys: opts[0].ownKeys,
|
|
1435
1448
|
},
|
|
1436
1449
|
});
|
|
1437
1450
|
});
|
|
1438
1451
|
ordered.sort((a, b) => a.order - b.order);
|
|
1439
1452
|
const dimensions = ordered.map((o) => o.dimension);
|
|
1453
|
+
const joined = dimensions.filter((dim) => dim.type !== 'const').length > 1;
|
|
1454
|
+
dimensions.forEach((dim) => {
|
|
1455
|
+
if (!joined || dim.type !== 'var' || !dim.ownKeys)
|
|
1456
|
+
return;
|
|
1457
|
+
const numbers = {};
|
|
1458
|
+
dim.options.forEach((opt, index) => {
|
|
1459
|
+
numbers[String(opt.value)] = String(index);
|
|
1460
|
+
opt.value = String(index);
|
|
1461
|
+
});
|
|
1462
|
+
dim.testExpr = `(${JSON.stringify(numbers)}[${dim.testExpr}] || "")`;
|
|
1463
|
+
});
|
|
1440
1464
|
const results = {};
|
|
1441
1465
|
const recurse = (dimIndex, currentStyle, keyParts) => {
|
|
1442
1466
|
if (dimIndex >= dimensions.length) {
|
package/dist/core.mjs
CHANGED
|
@@ -805,15 +805,15 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
805
805
|
? { varName, keyExpr: node.property.expression, obj }
|
|
806
806
|
: null;
|
|
807
807
|
};
|
|
808
|
-
const buildDecision = (node, prefix, off, counter) => {
|
|
808
|
+
const buildDecision = (node, prefix, off, counter, scoped) => {
|
|
809
809
|
if (node.type === 'ParenthesisExpression') {
|
|
810
|
-
return buildDecision(node.expression, prefix, off, counter);
|
|
810
|
+
return buildDecision(node.expression, prefix, off, counter, scoped);
|
|
811
811
|
}
|
|
812
812
|
if (node.type === 'ConditionalExpression') {
|
|
813
|
-
const a = buildDecision(node.consequent, prefix, off, counter);
|
|
813
|
+
const a = buildDecision(node.consequent, prefix, off, counter, scoped);
|
|
814
814
|
if (!a)
|
|
815
815
|
return null;
|
|
816
|
-
const b = buildDecision(node.alternate, prefix, off, counter);
|
|
816
|
+
const b = buildDecision(node.alternate, prefix, off, counter, scoped);
|
|
817
817
|
if (!b)
|
|
818
818
|
return null;
|
|
819
819
|
return {
|
|
@@ -824,7 +824,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
824
824
|
};
|
|
825
825
|
}
|
|
826
826
|
if (node.type === 'BinaryExpression' && node.operator === '&&') {
|
|
827
|
-
const right = buildDecision(node.right, prefix, off, counter);
|
|
827
|
+
const right = buildDecision(node.right, prefix, off, counter, scoped);
|
|
828
828
|
if (!right)
|
|
829
829
|
return null;
|
|
830
830
|
return {
|
|
@@ -836,10 +836,14 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
836
836
|
}
|
|
837
837
|
const group = resolveBracketGroup(node);
|
|
838
838
|
if (group) {
|
|
839
|
+
const tag = scoped ? `${counter.n++}:` : '';
|
|
840
|
+
const keySource = getSource(group.keyExpr);
|
|
839
841
|
return {
|
|
840
|
-
keyExpr:
|
|
842
|
+
keyExpr: tag
|
|
843
|
+
? `(${JSON.stringify(tag)} + ${keySource})`
|
|
844
|
+
: keySource,
|
|
841
845
|
options: Object.entries(group.obj).map(([value, style]) => ({
|
|
842
|
-
value
|
|
846
|
+
value: `${tag}${value}`,
|
|
843
847
|
style: style,
|
|
844
848
|
})),
|
|
845
849
|
leaves: 1,
|
|
@@ -872,17 +876,23 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
872
876
|
else {
|
|
873
877
|
const group = resolveBracketGroup(node);
|
|
874
878
|
if (group)
|
|
875
|
-
Object.
|
|
879
|
+
Object.entries(group.obj).forEach(([key, style]) => {
|
|
880
|
+
let styles = acc.get(key);
|
|
881
|
+
if (!styles)
|
|
882
|
+
acc.set(key, (styles = new Set()));
|
|
883
|
+
styles.add(style);
|
|
884
|
+
});
|
|
876
885
|
}
|
|
877
886
|
};
|
|
878
887
|
const resolveDecision = (node) => {
|
|
879
|
-
const groupKeys = new
|
|
888
|
+
const groupKeys = new Map();
|
|
880
889
|
collectGroupKeys(node, groupKeys);
|
|
881
890
|
let prefix = '#';
|
|
882
|
-
while ([...groupKeys].some((k) => k.startsWith(prefix)))
|
|
891
|
+
while ([...groupKeys.keys()].some((k) => k.startsWith(prefix)))
|
|
883
892
|
prefix += '#';
|
|
884
|
-
const
|
|
885
|
-
|
|
893
|
+
const scoped = [...groupKeys.values()].some((styles) => styles.size > 1);
|
|
894
|
+
const off = !scoped && groupKeys.has('') ? `${prefix}off` : '';
|
|
895
|
+
return buildDecision(node, prefix, off, { n: 0 }, scoped);
|
|
886
896
|
};
|
|
887
897
|
const collectConditions = (node, currentTestStrings = []) => {
|
|
888
898
|
const staticStyle = resolveStyleObject(node);
|
|
@@ -1159,6 +1169,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1159
1169
|
groupName: undefined,
|
|
1160
1170
|
valueName: optionName,
|
|
1161
1171
|
varName,
|
|
1172
|
+
ownKeys: true,
|
|
1162
1173
|
});
|
|
1163
1174
|
});
|
|
1164
1175
|
continue;
|
|
@@ -1179,6 +1190,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1179
1190
|
groupName: undefined,
|
|
1180
1191
|
valueName: value,
|
|
1181
1192
|
varName: undefined,
|
|
1193
|
+
ownKeys: true,
|
|
1182
1194
|
}));
|
|
1183
1195
|
continue;
|
|
1184
1196
|
}
|
|
@@ -1396,11 +1408,23 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1396
1408
|
style: opt.truthy,
|
|
1397
1409
|
label: opt.valueName || 'default',
|
|
1398
1410
|
})),
|
|
1411
|
+
ownKeys: opts[0].ownKeys,
|
|
1399
1412
|
},
|
|
1400
1413
|
});
|
|
1401
1414
|
});
|
|
1402
1415
|
ordered.sort((a, b) => a.order - b.order);
|
|
1403
1416
|
const dimensions = ordered.map((o) => o.dimension);
|
|
1417
|
+
const joined = dimensions.filter((dim) => dim.type !== 'const').length > 1;
|
|
1418
|
+
dimensions.forEach((dim) => {
|
|
1419
|
+
if (!joined || dim.type !== 'var' || !dim.ownKeys)
|
|
1420
|
+
return;
|
|
1421
|
+
const numbers = {};
|
|
1422
|
+
dim.options.forEach((opt, index) => {
|
|
1423
|
+
numbers[String(opt.value)] = String(index);
|
|
1424
|
+
opt.value = String(index);
|
|
1425
|
+
});
|
|
1426
|
+
dim.testExpr = `(${JSON.stringify(numbers)}[${dim.testExpr}] || "")`;
|
|
1427
|
+
});
|
|
1404
1428
|
const results = {};
|
|
1405
1429
|
const recurse = (dimIndex, currentStyle, keyParts) => {
|
|
1406
1430
|
if (dimIndex >= dimensions.length) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/unplugin",
|
|
3
|
-
"version": "18.1.
|
|
3
|
+
"version": "18.1.3",
|
|
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": "^18.1.
|
|
92
|
+
"@plumeria/utils": "^18.1.3"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
|
-
"@swc/core": "1.15.
|
|
95
|
+
"@swc/core": "1.15.47",
|
|
96
96
|
"vite": "^8.0.13",
|
|
97
97
|
"zss-engine": "2.3.2"
|
|
98
98
|
},
|