@plumeria/turbopack-loader 18.1.0 → 18.1.1
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 -25
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -796,6 +796,8 @@ async function loader(source) {
|
|
|
796
796
|
});
|
|
797
797
|
const conditionals = [];
|
|
798
798
|
let groupIdCounter = 0;
|
|
799
|
+
let sourceOrder = 0;
|
|
800
|
+
const baseChunks = [];
|
|
799
801
|
let baseStyle = {};
|
|
800
802
|
let isOptimizable = true;
|
|
801
803
|
const resolveCreateObject = (varName) => {
|
|
@@ -903,6 +905,7 @@ async function loader(source) {
|
|
|
903
905
|
if (staticStyle) {
|
|
904
906
|
if (currentTestStrings.length === 0) {
|
|
905
907
|
baseStyle = (0, utils_1.deepMerge)(baseStyle, staticStyle);
|
|
908
|
+
baseChunks.push({ order: sourceOrder++, style: staticStyle });
|
|
906
909
|
}
|
|
907
910
|
else {
|
|
908
911
|
conditionals.push({
|
|
@@ -911,6 +914,7 @@ async function loader(source) {
|
|
|
911
914
|
truthy: staticStyle,
|
|
912
915
|
falsy: {},
|
|
913
916
|
varName: undefined,
|
|
917
|
+
order: sourceOrder++,
|
|
914
918
|
});
|
|
915
919
|
}
|
|
916
920
|
return true;
|
|
@@ -927,6 +931,7 @@ async function loader(source) {
|
|
|
927
931
|
truthy: trueStyle,
|
|
928
932
|
falsy: falseStyle,
|
|
929
933
|
varName: undefined,
|
|
934
|
+
order: sourceOrder++,
|
|
930
935
|
});
|
|
931
936
|
return true;
|
|
932
937
|
}
|
|
@@ -977,6 +982,7 @@ async function loader(source) {
|
|
|
977
982
|
}
|
|
978
983
|
if (propPossibilities && propPossibilities.length > 0) {
|
|
979
984
|
const currentGroupId = ++groupIdCounter;
|
|
985
|
+
const currentOrder = sourceOrder++;
|
|
980
986
|
const uniqueEntries = [];
|
|
981
987
|
propPossibilities.forEach((entry) => {
|
|
982
988
|
if (!uniqueEntries.some((x) => x.key === entry.key)) {
|
|
@@ -991,6 +997,7 @@ async function loader(source) {
|
|
|
991
997
|
truthy: entry.styleObj,
|
|
992
998
|
falsy: {},
|
|
993
999
|
groupId: currentGroupId,
|
|
1000
|
+
order: currentOrder,
|
|
994
1001
|
groupName: undefined,
|
|
995
1002
|
valueName: entry.key,
|
|
996
1003
|
varName,
|
|
@@ -1047,11 +1054,18 @@ async function loader(source) {
|
|
|
1047
1054
|
if (!groupVariants)
|
|
1048
1055
|
continue;
|
|
1049
1056
|
const currentGroupId = ++groupIdCounter;
|
|
1057
|
+
const currentOrder = sourceOrder++;
|
|
1050
1058
|
const valSource = getSource(valExpr);
|
|
1051
1059
|
if (valExpr.type === 'StringLiteral') {
|
|
1052
1060
|
const groupVariantsAsObj = groupVariants;
|
|
1053
|
-
|
|
1054
|
-
|
|
1061
|
+
const picked = groupVariantsAsObj[valExpr.value];
|
|
1062
|
+
if (picked) {
|
|
1063
|
+
baseStyle = (0, utils_1.deepMerge)(baseStyle, picked);
|
|
1064
|
+
baseChunks.push({
|
|
1065
|
+
order: sourceOrder++,
|
|
1066
|
+
style: picked,
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1055
1069
|
continue;
|
|
1056
1070
|
}
|
|
1057
1071
|
Object.entries(groupVariants).forEach(([optionName, style]) => {
|
|
@@ -1062,6 +1076,7 @@ async function loader(source) {
|
|
|
1062
1076
|
truthy: style,
|
|
1063
1077
|
falsy: {},
|
|
1064
1078
|
groupId: currentGroupId,
|
|
1079
|
+
order: currentOrder,
|
|
1065
1080
|
groupName,
|
|
1066
1081
|
valueName: optionName,
|
|
1067
1082
|
varName,
|
|
@@ -1073,11 +1088,15 @@ async function loader(source) {
|
|
|
1073
1088
|
}
|
|
1074
1089
|
const argSource = getSource(arg);
|
|
1075
1090
|
if (utils_1.t.isStringLiteral(arg)) {
|
|
1076
|
-
|
|
1077
|
-
|
|
1091
|
+
const picked = variantObj[arg.value];
|
|
1092
|
+
if (picked) {
|
|
1093
|
+
baseStyle = (0, utils_1.deepMerge)(baseStyle, picked);
|
|
1094
|
+
baseChunks.push({ order: sourceOrder++, style: picked });
|
|
1095
|
+
}
|
|
1078
1096
|
continue;
|
|
1079
1097
|
}
|
|
1080
1098
|
const currentGroupId = ++groupIdCounter;
|
|
1099
|
+
const currentOrder = sourceOrder++;
|
|
1081
1100
|
Object.entries(variantObj).forEach(([key, style]) => {
|
|
1082
1101
|
conditionals.push({
|
|
1083
1102
|
test: arg,
|
|
@@ -1086,6 +1105,7 @@ async function loader(source) {
|
|
|
1086
1105
|
truthy: style,
|
|
1087
1106
|
falsy: {},
|
|
1088
1107
|
groupId: currentGroupId,
|
|
1108
|
+
order: currentOrder,
|
|
1089
1109
|
groupName: undefined,
|
|
1090
1110
|
valueName: key,
|
|
1091
1111
|
varName,
|
|
@@ -1113,6 +1133,7 @@ async function loader(source) {
|
|
|
1113
1133
|
if (!groupVariants)
|
|
1114
1134
|
return;
|
|
1115
1135
|
const currentGroupId = ++groupIdCounter;
|
|
1136
|
+
const currentOrder = sourceOrder++;
|
|
1116
1137
|
Object.entries(groupVariants).forEach(([optionName, style]) => {
|
|
1117
1138
|
conditionals.push({
|
|
1118
1139
|
test: expr,
|
|
@@ -1121,6 +1142,7 @@ async function loader(source) {
|
|
|
1121
1142
|
truthy: style,
|
|
1122
1143
|
falsy: {},
|
|
1123
1144
|
groupId: currentGroupId,
|
|
1145
|
+
order: currentOrder,
|
|
1124
1146
|
groupName,
|
|
1125
1147
|
valueName: optionName,
|
|
1126
1148
|
varName,
|
|
@@ -1139,6 +1161,7 @@ async function loader(source) {
|
|
|
1139
1161
|
const dynExpr = expr.property.expression;
|
|
1140
1162
|
const dynSource = getSource(dynExpr);
|
|
1141
1163
|
const currentGroupId = ++groupIdCounter;
|
|
1164
|
+
const currentOrder = sourceOrder++;
|
|
1142
1165
|
Object.entries(styleObj).forEach(([optionName, style]) => {
|
|
1143
1166
|
conditionals.push({
|
|
1144
1167
|
test: dynExpr,
|
|
@@ -1147,6 +1170,7 @@ async function loader(source) {
|
|
|
1147
1170
|
truthy: style,
|
|
1148
1171
|
falsy: {},
|
|
1149
1172
|
groupId: currentGroupId,
|
|
1173
|
+
order: currentOrder,
|
|
1150
1174
|
groupName: undefined,
|
|
1151
1175
|
valueName: optionName,
|
|
1152
1176
|
varName,
|
|
@@ -1158,6 +1182,7 @@ async function loader(source) {
|
|
|
1158
1182
|
const decision = resolveDecision(expr);
|
|
1159
1183
|
if (decision && (decision.hasGroup || decision.leaves > 2)) {
|
|
1160
1184
|
const groupId = ++groupIdCounter;
|
|
1185
|
+
const currentOrder = sourceOrder++;
|
|
1161
1186
|
decision.options.forEach(({ value, style }) => conditionals.push({
|
|
1162
1187
|
test: expr,
|
|
1163
1188
|
testLHS: decision.keyExpr,
|
|
@@ -1165,6 +1190,7 @@ async function loader(source) {
|
|
|
1165
1190
|
truthy: style,
|
|
1166
1191
|
falsy: {},
|
|
1167
1192
|
groupId,
|
|
1193
|
+
order: currentOrder,
|
|
1168
1194
|
groupName: undefined,
|
|
1169
1195
|
valueName: value,
|
|
1170
1196
|
varName: undefined,
|
|
@@ -1317,17 +1343,38 @@ async function loader(source) {
|
|
|
1317
1343
|
});
|
|
1318
1344
|
if (Object.keys(baseConflict).length > 0 ||
|
|
1319
1345
|
conflictConditionals.length > 0) {
|
|
1320
|
-
const
|
|
1346
|
+
const ordered = [];
|
|
1347
|
+
baseChunks.forEach(({ order, style }) => {
|
|
1348
|
+
const conflicting = {};
|
|
1349
|
+
Object.entries(style).forEach(([key, value]) => {
|
|
1350
|
+
if (conflictingKeys.has(key))
|
|
1351
|
+
conflicting[key] = value;
|
|
1352
|
+
});
|
|
1353
|
+
if (Object.keys(conflicting).length === 0)
|
|
1354
|
+
return;
|
|
1355
|
+
ordered.push({
|
|
1356
|
+
order,
|
|
1357
|
+
dimension: {
|
|
1358
|
+
type: 'const',
|
|
1359
|
+
options: [
|
|
1360
|
+
{ value: undefined, style: conflicting, label: 'base' },
|
|
1361
|
+
],
|
|
1362
|
+
},
|
|
1363
|
+
});
|
|
1364
|
+
});
|
|
1321
1365
|
conflictConditionals
|
|
1322
1366
|
.filter((c) => c.groupId === undefined)
|
|
1323
1367
|
.forEach((c) => {
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1368
|
+
ordered.push({
|
|
1369
|
+
order: c.order ?? 0,
|
|
1370
|
+
dimension: {
|
|
1371
|
+
type: 'std',
|
|
1372
|
+
testExpr: c.testString ?? getSource(c.test),
|
|
1373
|
+
options: [
|
|
1374
|
+
{ value: 0, style: c.falsy, label: 'false' },
|
|
1375
|
+
{ value: 1, style: c.truthy, label: 'true' },
|
|
1376
|
+
],
|
|
1377
|
+
},
|
|
1331
1378
|
});
|
|
1332
1379
|
});
|
|
1333
1380
|
const conflictVarGroups = {};
|
|
@@ -1348,16 +1395,23 @@ async function loader(source) {
|
|
|
1348
1395
|
opts.push({ ...off, truthy: {}, falsy: {} });
|
|
1349
1396
|
});
|
|
1350
1397
|
Object.entries(conflictVarGroups).forEach(([, opts]) => {
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1398
|
+
ordered.push({
|
|
1399
|
+
order: opts[0].order ?? 0,
|
|
1400
|
+
dimension: {
|
|
1401
|
+
type: 'var',
|
|
1402
|
+
testExpr: opts[0].testLHS ??
|
|
1403
|
+
opts[0].testString ??
|
|
1404
|
+
getSource(opts[0].test),
|
|
1405
|
+
options: opts.map((opt) => ({
|
|
1406
|
+
value: opt.valueName,
|
|
1407
|
+
style: opt.truthy,
|
|
1408
|
+
label: opt.valueName || 'default',
|
|
1409
|
+
})),
|
|
1410
|
+
},
|
|
1359
1411
|
});
|
|
1360
1412
|
});
|
|
1413
|
+
ordered.sort((a, b) => a.order - b.order);
|
|
1414
|
+
const dimensions = ordered.map((o) => o.dimension);
|
|
1361
1415
|
const results = {};
|
|
1362
1416
|
const recurse = (dimIndex, currentStyle, keyParts) => {
|
|
1363
1417
|
if (dimIndex >= dimensions.length) {
|
|
@@ -1368,18 +1422,19 @@ async function loader(source) {
|
|
|
1368
1422
|
results[keyParts.join('__')] = className;
|
|
1369
1423
|
return;
|
|
1370
1424
|
}
|
|
1371
|
-
dimensions[dimIndex]
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1425
|
+
const dimension = dimensions[dimIndex];
|
|
1426
|
+
dimension.options.forEach((opt) => recurse(dimIndex + 1, (0, utils_1.deepMerge)(currentStyle, opt.style), dimension.type === 'const'
|
|
1427
|
+
? keyParts
|
|
1428
|
+
: [...keyParts, String(opt.value)]));
|
|
1375
1429
|
};
|
|
1376
|
-
recurse(0,
|
|
1430
|
+
recurse(0, {}, []);
|
|
1377
1431
|
const baseConflictClass = Object.keys(baseConflict).length > 0
|
|
1378
1432
|
? processStyleRecords(baseConflict)
|
|
1379
1433
|
.map((r) => r.hash)
|
|
1380
1434
|
.join(' ')
|
|
1381
1435
|
: '';
|
|
1382
1436
|
const masterKeyExpr = dimensions
|
|
1437
|
+
.filter((dim) => dim.type !== 'const')
|
|
1383
1438
|
.map((dim) => dim.type === 'std'
|
|
1384
1439
|
? `(${dim.testExpr} ? "1" : "0")`
|
|
1385
1440
|
: dim.testExpr || '""')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/turbopack-loader",
|
|
3
|
-
"version": "18.1.
|
|
3
|
+
"version": "18.1.1",
|
|
4
4
|
"description": "Plumeria Turbopack-loader",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"zero-virtual.css"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@plumeria/compiler": "^18.1.
|
|
26
|
-
"@plumeria/utils": "^18.1.
|
|
25
|
+
"@plumeria/compiler": "^18.1.1",
|
|
26
|
+
"@plumeria/utils": "^18.1.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@swc/core": "1.15.43",
|