@plumeria/turbopack-loader 10.0.7 → 10.1.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 +83 -84
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -75,6 +75,16 @@ async function loader(source) {
|
|
|
75
75
|
extractedSheets.push(sheet);
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
|
+
const processStyleRecords = (style) => {
|
|
79
|
+
const records = (0, utils_1.getStyleRecords)(style);
|
|
80
|
+
if (!isProduction) {
|
|
81
|
+
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
82
|
+
records.forEach((r) => {
|
|
83
|
+
addSheet(r.sheet);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return records;
|
|
87
|
+
};
|
|
78
88
|
const localConsts = (0, utils_1.collectLocalConsts)(ast);
|
|
79
89
|
const importMap = {};
|
|
80
90
|
const createThemeImportMap = {};
|
|
@@ -264,26 +274,16 @@ async function loader(source) {
|
|
|
264
274
|
if (typeof style !== 'object' || style === null)
|
|
265
275
|
return;
|
|
266
276
|
const records = (0, utils_1.getStyleRecords)(style);
|
|
267
|
-
if (!isProduction) {
|
|
268
|
-
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
269
|
-
records.forEach((r) => {
|
|
270
|
-
addSheet(r.sheet);
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
277
|
const atomMap = {};
|
|
274
278
|
records.forEach((r) => (atomMap[r.key] = r.hash));
|
|
275
279
|
hashMap[key] = atomMap;
|
|
276
280
|
});
|
|
281
|
+
const styleFunctions = {};
|
|
277
282
|
const objExpr = init.arguments[0].expression;
|
|
278
283
|
objExpr.properties.forEach((prop) => {
|
|
279
284
|
if (prop.type !== 'KeyValueProperty' ||
|
|
280
285
|
prop.key.type !== 'Identifier')
|
|
281
286
|
return;
|
|
282
|
-
const isArrow = prop.value.type === 'ArrowFunctionExpression';
|
|
283
|
-
const isFunc = prop.value.type === 'FunctionExpression';
|
|
284
|
-
if (!isArrow && !isFunc)
|
|
285
|
-
return;
|
|
286
|
-
const key = prop.key.value;
|
|
287
287
|
const func = prop.value;
|
|
288
288
|
if (func.type !== 'ArrowFunctionExpression' &&
|
|
289
289
|
func.type !== 'FunctionExpression')
|
|
@@ -298,16 +298,6 @@ async function loader(source) {
|
|
|
298
298
|
return p.pat.value;
|
|
299
299
|
return 'arg';
|
|
300
300
|
});
|
|
301
|
-
const cssVarInfo = {};
|
|
302
|
-
const tempStaticTable = { ...mergedStaticTable };
|
|
303
|
-
const substitutedArgs = params.map((paramName) => {
|
|
304
|
-
const cssVar = `--${key}-${paramName}`;
|
|
305
|
-
cssVarInfo[paramName] = { cssVar, propKey: '' };
|
|
306
|
-
return `var(${cssVar})`;
|
|
307
|
-
});
|
|
308
|
-
params.forEach((paramName, i) => {
|
|
309
|
-
tempStaticTable[paramName] = substitutedArgs[i];
|
|
310
|
-
});
|
|
311
301
|
let actualBody = func.body;
|
|
312
302
|
if (actualBody?.type === 'ParenthesisExpression')
|
|
313
303
|
actualBody = actualBody.expression;
|
|
@@ -318,25 +308,12 @@ async function loader(source) {
|
|
|
318
308
|
if (actualBody?.type === 'ParenthesisExpression')
|
|
319
309
|
actualBody = actualBody.expression;
|
|
320
310
|
}
|
|
321
|
-
if (
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
for (const [, info] of Object.entries(cssVarInfo)) {
|
|
327
|
-
const cssVar = info.cssVar;
|
|
328
|
-
const propKey = Object.keys(substituted).find((k) => typeof substituted[k] === 'string' &&
|
|
329
|
-
substituted[k].includes(cssVar));
|
|
330
|
-
if (propKey) {
|
|
331
|
-
info.propKey = propKey;
|
|
332
|
-
}
|
|
311
|
+
if (actualBody && actualBody.type === 'ObjectExpression') {
|
|
312
|
+
styleFunctions[prop.key.value] = {
|
|
313
|
+
params,
|
|
314
|
+
body: actualBody,
|
|
315
|
+
};
|
|
333
316
|
}
|
|
334
|
-
const records = (0, utils_1.getStyleRecords)(substituted);
|
|
335
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
336
|
-
const atomMap = {};
|
|
337
|
-
records.forEach((r) => (atomMap[r.key] = r.hash));
|
|
338
|
-
atomMap['__cssVars__'] = JSON.stringify(cssVarInfo);
|
|
339
|
-
hashMap[key] = atomMap;
|
|
340
317
|
});
|
|
341
318
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
342
319
|
idSpans.add(node.id.span.start);
|
|
@@ -356,6 +333,7 @@ async function loader(source) {
|
|
|
356
333
|
start: declSpan.start - baseByteOffset,
|
|
357
334
|
end: declSpan.end - baseByteOffset,
|
|
358
335
|
},
|
|
336
|
+
functions: styleFunctions,
|
|
359
337
|
};
|
|
360
338
|
}
|
|
361
339
|
}
|
|
@@ -854,7 +832,7 @@ async function loader(source) {
|
|
|
854
832
|
if (existingClass)
|
|
855
833
|
classParts.push(JSON.stringify(existingClass));
|
|
856
834
|
if (Object.keys(baseIndependent).length > 0) {
|
|
857
|
-
const className = (
|
|
835
|
+
const className = processStyleRecords(baseIndependent)
|
|
858
836
|
.map((r) => r.hash)
|
|
859
837
|
.join(' ');
|
|
860
838
|
if (className)
|
|
@@ -866,7 +844,7 @@ async function loader(source) {
|
|
|
866
844
|
const processBranch = (style) => {
|
|
867
845
|
if (Object.keys(style).length === 0)
|
|
868
846
|
return '""';
|
|
869
|
-
return JSON.stringify((
|
|
847
|
+
return JSON.stringify(processStyleRecords(style)
|
|
870
848
|
.map((r) => r.hash)
|
|
871
849
|
.join(' '));
|
|
872
850
|
};
|
|
@@ -888,7 +866,7 @@ async function loader(source) {
|
|
|
888
866
|
const lookupMap = {};
|
|
889
867
|
options.forEach((opt) => {
|
|
890
868
|
if (opt.valueName && opt.truthy) {
|
|
891
|
-
const className = (
|
|
869
|
+
const className = processStyleRecords(opt.truthy)
|
|
892
870
|
.map((r) => r.hash)
|
|
893
871
|
.join(' ');
|
|
894
872
|
if (className)
|
|
@@ -939,7 +917,7 @@ async function loader(source) {
|
|
|
939
917
|
const results = {};
|
|
940
918
|
const recurse = (dimIndex, currentStyle, keyParts) => {
|
|
941
919
|
if (dimIndex >= dimensions.length) {
|
|
942
|
-
const className = (
|
|
920
|
+
const className = processStyleRecords(currentStyle)
|
|
943
921
|
.map((r) => r.hash)
|
|
944
922
|
.join(' ');
|
|
945
923
|
if (className)
|
|
@@ -953,7 +931,7 @@ async function loader(source) {
|
|
|
953
931
|
};
|
|
954
932
|
recurse(0, baseConflict, []);
|
|
955
933
|
const baseConflictClass = Object.keys(baseConflict).length > 0
|
|
956
|
-
? (
|
|
934
|
+
? processStyleRecords(baseConflict)
|
|
957
935
|
.map((r) => r.hash)
|
|
958
936
|
.join(' ')
|
|
959
937
|
: '';
|
|
@@ -1158,45 +1136,67 @@ async function loader(source) {
|
|
|
1158
1136
|
const varName = callee.object.value;
|
|
1159
1137
|
const propKey = callee.property.value;
|
|
1160
1138
|
const styleInfo = localCreateStyles[varName];
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1139
|
+
if (styleInfo?.functions?.[propKey]) {
|
|
1140
|
+
const func = styleInfo.functions[propKey];
|
|
1141
|
+
const callArgs = expr.arguments;
|
|
1142
|
+
const tempStaticTable = { ...mergedStaticTable };
|
|
1143
|
+
if (callArgs.length === 1 && !callArgs[0].spread) {
|
|
1144
|
+
const argExpr = callArgs[0].expression;
|
|
1145
|
+
const cssVarInfo = {};
|
|
1146
|
+
if (argExpr.type === 'ObjectExpression') {
|
|
1147
|
+
const argObj = (0, utils_1.objectExpressionToObject)(argExpr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
1148
|
+
func.params.forEach((p) => {
|
|
1149
|
+
if (argObj[p] !== undefined)
|
|
1150
|
+
tempStaticTable[p] = argObj[p];
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
else {
|
|
1154
|
+
func.params.forEach((p) => {
|
|
1155
|
+
const cssVar = `--${propKey}-${p}`;
|
|
1156
|
+
tempStaticTable[p] = `var(${cssVar})`;
|
|
1157
|
+
cssVarInfo[p] = { cssVar, propKey: '' };
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
const substituted = (0, utils_1.objectExpressionToObject)(func.body, tempStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
1161
|
+
if (substituted) {
|
|
1162
|
+
const records = processStyleRecords(substituted);
|
|
1163
|
+
const hashes = records.map((r) => r.hash).join(' ');
|
|
1164
|
+
if (hashes)
|
|
1165
|
+
dynamicClassParts.push(JSON.stringify(hashes));
|
|
1166
|
+
if (Object.keys(cssVarInfo).length > 0) {
|
|
1167
|
+
Object.entries(cssVarInfo).forEach(([_, info]) => {
|
|
1168
|
+
const targetProp = Object.keys(substituted).find((k) => typeof substituted[k] === 'string' &&
|
|
1169
|
+
substituted[k].includes(info.cssVar));
|
|
1170
|
+
if (targetProp) {
|
|
1171
|
+
const argStart = argExpr.span.start - baseByteOffset;
|
|
1172
|
+
const argEnd = argExpr.span.end - baseByteOffset;
|
|
1173
|
+
const argSource = sourceBuffer
|
|
1174
|
+
.subarray(argStart, argEnd)
|
|
1175
|
+
.toString('utf-8');
|
|
1176
|
+
let valueExpr;
|
|
1177
|
+
const maybeNumber = Number(argSource);
|
|
1178
|
+
if (!isNaN(maybeNumber) &&
|
|
1179
|
+
argSource.trim() === String(maybeNumber)) {
|
|
1180
|
+
valueExpr = JSON.stringify((0, zss_engine_1.applyCssValue)(maybeNumber, targetProp));
|
|
1181
|
+
}
|
|
1182
|
+
else if ((argSource.startsWith('"') && argSource.endsWith('"')) ||
|
|
1183
|
+
(argSource.startsWith("'") && argSource.endsWith("'"))) {
|
|
1184
|
+
valueExpr = JSON.stringify((0, zss_engine_1.applyCssValue)(argSource.slice(1, -1), targetProp));
|
|
1185
|
+
}
|
|
1186
|
+
else {
|
|
1187
|
+
valueExpr = zss_engine_1.exceptionCamelCase.includes(targetProp)
|
|
1188
|
+
? argSource
|
|
1189
|
+
: `(typeof ${argSource} === 'number' ? ${argSource} + 'px' : ${argSource})`;
|
|
1190
|
+
}
|
|
1191
|
+
dynamicStyleParts.push(`"${info.cssVar}": ${valueExpr}`);
|
|
1192
|
+
}
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
return false;
|
|
1196
|
+
}
|
|
1196
1197
|
}
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
return false;
|
|
1198
|
+
}
|
|
1199
|
+
return true;
|
|
1200
1200
|
});
|
|
1201
1201
|
const styleAttr = dynamicStyleParts.length > 0
|
|
1202
1202
|
? ` style={{${dynamicStyleParts.join(', ')}}}`
|
|
@@ -1254,8 +1254,7 @@ async function loader(source) {
|
|
|
1254
1254
|
const varName = callee.object.value;
|
|
1255
1255
|
const propKey = callee.property.value;
|
|
1256
1256
|
const styleInfo = localCreateStyles[varName];
|
|
1257
|
-
|
|
1258
|
-
if (atomMap?.['__cssVars__']) {
|
|
1257
|
+
if (styleInfo?.functions?.[propKey]) {
|
|
1259
1258
|
throw new Error(`Plumeria: css.use(${getSource(expr)}) does not support dynamic function keys.\n`);
|
|
1260
1259
|
}
|
|
1261
1260
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/turbopack-loader",
|
|
3
|
-
"version": "10.0
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Plumeria Turbopack-loader",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"zero-virtual.css"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@plumeria/utils": "^10.0
|
|
25
|
+
"@plumeria/utils": "^10.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.21",
|