@plumeria/webpack-plugin 7.1.2 → 7.2.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.d.ts +2 -2
- package/dist/index.js +2 -1319
- package/package.json +3 -9
- package/zero-virtual.css +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default
|
|
1
|
+
import loader from '@plumeria/turbopack-loader';
|
|
2
|
+
export default loader;
|
package/dist/index.js
CHANGED
|
@@ -3,1322 +3,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const zss_engine_1 = require("zss-engine");
|
|
11
|
-
const utils_1 = require("@plumeria/utils");
|
|
12
|
-
const VIRTUAL_FILE_PATH = path_1.default.resolve(__dirname, '..', 'zero-virtual.css');
|
|
13
|
-
if (process.env.NODE_ENV === 'production') {
|
|
14
|
-
(0, fs_1.writeFileSync)(VIRTUAL_FILE_PATH, '/** Placeholder file */\n', 'utf-8');
|
|
15
|
-
}
|
|
16
|
-
async function loader(source) {
|
|
17
|
-
const callback = this.async();
|
|
18
|
-
const isProduction = process.env.NODE_ENV === 'production';
|
|
19
|
-
if (this.resourcePath.includes('node_modules') ||
|
|
20
|
-
!source.includes('@plumeria/core')) {
|
|
21
|
-
return callback(null, source);
|
|
22
|
-
}
|
|
23
|
-
const fileStyles = {};
|
|
24
|
-
this.clearDependencies();
|
|
25
|
-
this.addDependency(this.resourcePath);
|
|
26
|
-
const ast = (0, core_1.parseSync)(source, {
|
|
27
|
-
syntax: 'typescript',
|
|
28
|
-
tsx: true,
|
|
29
|
-
target: 'es2022',
|
|
30
|
-
});
|
|
31
|
-
for (const node of ast.body) {
|
|
32
|
-
if (node.type === 'ImportDeclaration') {
|
|
33
|
-
const sourcePath = node.source.value;
|
|
34
|
-
const actualPath = (0, utils_1.resolveImportPath)(sourcePath, this.resourcePath);
|
|
35
|
-
if (actualPath) {
|
|
36
|
-
this.addDependency(actualPath);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const scannedTables = (0, utils_1.scanAll)();
|
|
41
|
-
const localConsts = (0, utils_1.collectLocalConsts)(ast);
|
|
42
|
-
const resourcePath = this.resourcePath;
|
|
43
|
-
const importMap = {};
|
|
44
|
-
const createThemeImportMap = {};
|
|
45
|
-
const createStaticImportMap = {};
|
|
46
|
-
const plumeriaAliases = {};
|
|
47
|
-
(0, utils_1.traverse)(ast, {
|
|
48
|
-
ImportDeclaration({ node }) {
|
|
49
|
-
const sourcePath = node.source.value;
|
|
50
|
-
if (sourcePath === '@plumeria/core') {
|
|
51
|
-
node.specifiers.forEach((specifier) => {
|
|
52
|
-
if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
53
|
-
plumeriaAliases[specifier.local.value] = 'NAMESPACE';
|
|
54
|
-
}
|
|
55
|
-
else if (specifier.type === 'ImportDefaultSpecifier') {
|
|
56
|
-
plumeriaAliases[specifier.local.value] = 'NAMESPACE';
|
|
57
|
-
}
|
|
58
|
-
else if (specifier.type === 'ImportSpecifier') {
|
|
59
|
-
const importedName = specifier.imported
|
|
60
|
-
? specifier.imported.value
|
|
61
|
-
: specifier.local.value;
|
|
62
|
-
plumeriaAliases[specifier.local.value] = importedName;
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
const actualPath = (0, utils_1.resolveImportPath)(sourcePath, resourcePath);
|
|
67
|
-
if (actualPath) {
|
|
68
|
-
node.specifiers.forEach((specifier) => {
|
|
69
|
-
if (specifier.type === 'ImportSpecifier') {
|
|
70
|
-
const importedName = specifier.imported
|
|
71
|
-
? specifier.imported.value
|
|
72
|
-
: specifier.local.value;
|
|
73
|
-
const localName = specifier.local.value;
|
|
74
|
-
const uniqueKey = `${actualPath}-${importedName}`;
|
|
75
|
-
if (scannedTables.staticTable[uniqueKey]) {
|
|
76
|
-
importMap[localName] = scannedTables.staticTable[uniqueKey];
|
|
77
|
-
}
|
|
78
|
-
if (scannedTables.keyframesHashTable[uniqueKey]) {
|
|
79
|
-
importMap[localName] =
|
|
80
|
-
scannedTables.keyframesHashTable[uniqueKey];
|
|
81
|
-
}
|
|
82
|
-
if (scannedTables.viewTransitionHashTable[uniqueKey]) {
|
|
83
|
-
importMap[localName] =
|
|
84
|
-
scannedTables.viewTransitionHashTable[uniqueKey];
|
|
85
|
-
}
|
|
86
|
-
if (scannedTables.createHashTable[uniqueKey]) {
|
|
87
|
-
importMap[localName] = scannedTables.createHashTable[uniqueKey];
|
|
88
|
-
}
|
|
89
|
-
if (scannedTables.variantsHashTable[uniqueKey]) {
|
|
90
|
-
importMap[localName] = scannedTables.variantsHashTable[uniqueKey];
|
|
91
|
-
}
|
|
92
|
-
if (scannedTables.createThemeHashTable[uniqueKey]) {
|
|
93
|
-
createThemeImportMap[localName] =
|
|
94
|
-
scannedTables.createThemeHashTable[uniqueKey];
|
|
95
|
-
}
|
|
96
|
-
if (scannedTables.createStaticHashTable[uniqueKey]) {
|
|
97
|
-
createStaticImportMap[localName] =
|
|
98
|
-
scannedTables.createStaticHashTable[uniqueKey];
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
const mergedStaticTable = {};
|
|
106
|
-
for (const key of Object.keys(scannedTables.staticTable)) {
|
|
107
|
-
mergedStaticTable[key] = scannedTables.staticTable[key];
|
|
108
|
-
}
|
|
109
|
-
for (const key of Object.keys(localConsts)) {
|
|
110
|
-
mergedStaticTable[key] = localConsts[key];
|
|
111
|
-
}
|
|
112
|
-
for (const key of Object.keys(importMap)) {
|
|
113
|
-
mergedStaticTable[key] = importMap[key];
|
|
114
|
-
}
|
|
115
|
-
const mergedKeyframesTable = {};
|
|
116
|
-
for (const key of Object.keys(scannedTables.keyframesHashTable)) {
|
|
117
|
-
mergedKeyframesTable[key] = scannedTables.keyframesHashTable[key];
|
|
118
|
-
}
|
|
119
|
-
for (const key of Object.keys(importMap)) {
|
|
120
|
-
mergedKeyframesTable[key] = importMap[key];
|
|
121
|
-
}
|
|
122
|
-
const mergedViewTransitionTable = {};
|
|
123
|
-
for (const key of Object.keys(scannedTables.viewTransitionHashTable)) {
|
|
124
|
-
mergedViewTransitionTable[key] = scannedTables.viewTransitionHashTable[key];
|
|
125
|
-
}
|
|
126
|
-
for (const key of Object.keys(importMap)) {
|
|
127
|
-
mergedViewTransitionTable[key] = importMap[key];
|
|
128
|
-
}
|
|
129
|
-
const mergedCreateTable = {};
|
|
130
|
-
for (const key of Object.keys(scannedTables.createHashTable)) {
|
|
131
|
-
mergedCreateTable[key] = scannedTables.createHashTable[key];
|
|
132
|
-
}
|
|
133
|
-
for (const key of Object.keys(importMap)) {
|
|
134
|
-
mergedCreateTable[key] = importMap[key];
|
|
135
|
-
}
|
|
136
|
-
const mergedVariantsTable = {};
|
|
137
|
-
for (const key of Object.keys(scannedTables.variantsHashTable)) {
|
|
138
|
-
mergedVariantsTable[key] = scannedTables.variantsHashTable[key];
|
|
139
|
-
}
|
|
140
|
-
for (const key of Object.keys(importMap)) {
|
|
141
|
-
mergedVariantsTable[key] = importMap[key];
|
|
142
|
-
}
|
|
143
|
-
const mergedCreateThemeHashTable = {};
|
|
144
|
-
for (const key of Object.keys(scannedTables.createThemeHashTable)) {
|
|
145
|
-
mergedCreateThemeHashTable[key] = scannedTables.createThemeHashTable[key];
|
|
146
|
-
if (key.startsWith(`${resourcePath}-`)) {
|
|
147
|
-
const varName = key.slice(resourcePath.length + 1);
|
|
148
|
-
mergedCreateThemeHashTable[varName] =
|
|
149
|
-
scannedTables.createThemeHashTable[key];
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
for (const key of Object.keys(createThemeImportMap)) {
|
|
153
|
-
mergedCreateThemeHashTable[key] = createThemeImportMap[key];
|
|
154
|
-
}
|
|
155
|
-
const mergedCreateStaticHashTable = {};
|
|
156
|
-
for (const key of Object.keys(scannedTables.createStaticHashTable)) {
|
|
157
|
-
mergedCreateStaticHashTable[key] = scannedTables.createStaticHashTable[key];
|
|
158
|
-
if (key.startsWith(`${resourcePath}-`)) {
|
|
159
|
-
const varName = key.slice(resourcePath.length + 1);
|
|
160
|
-
mergedCreateStaticHashTable[varName] =
|
|
161
|
-
scannedTables.createStaticHashTable[key];
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
for (const key of Object.keys(createStaticImportMap)) {
|
|
165
|
-
mergedCreateStaticHashTable[key] = createStaticImportMap[key];
|
|
166
|
-
}
|
|
167
|
-
const localCreateStyles = {};
|
|
168
|
-
const replacements = [];
|
|
169
|
-
const extractedSheets = [];
|
|
170
|
-
const addSheet = (sheet) => {
|
|
171
|
-
if (!extractedSheets.includes(sheet)) {
|
|
172
|
-
extractedSheets.push(sheet);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
const processedDecls = new Set();
|
|
176
|
-
const idSpans = new Set();
|
|
177
|
-
const excludedSpans = new Set();
|
|
178
|
-
if (scannedTables.extractedSheet) {
|
|
179
|
-
addSheet(scannedTables.extractedSheet);
|
|
180
|
-
}
|
|
181
|
-
const checkVariantAssignment = (decl) => {
|
|
182
|
-
if (decl.init &&
|
|
183
|
-
utils_1.t.isCallExpression(decl.init) &&
|
|
184
|
-
utils_1.t.isIdentifier(decl.init.callee)) {
|
|
185
|
-
const varName = decl.init.callee.value;
|
|
186
|
-
if ((localCreateStyles[varName] &&
|
|
187
|
-
localCreateStyles[varName].type === 'variant') ||
|
|
188
|
-
mergedVariantsTable[varName]) {
|
|
189
|
-
throw new Error(`Plumeria: Assigning the return value of "css.variants" to a variable is not supported.\nPlease pass the variant function directly to "css.props". Found assignment to: ${utils_1.t.isIdentifier(decl.id) ? decl.id.value : 'unknown'}`);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
const registerStyle = (node, declSpan, isExported) => {
|
|
194
|
-
let propName;
|
|
195
|
-
if (utils_1.t.isIdentifier(node.id) &&
|
|
196
|
-
node.init &&
|
|
197
|
-
utils_1.t.isCallExpression(node.init) &&
|
|
198
|
-
node.init.arguments.length >= 1) {
|
|
199
|
-
const callee = node.init.callee;
|
|
200
|
-
if (utils_1.t.isMemberExpression(callee) &&
|
|
201
|
-
utils_1.t.isIdentifier(callee.object) &&
|
|
202
|
-
utils_1.t.isIdentifier(callee.property)) {
|
|
203
|
-
const objectName = callee.object.value;
|
|
204
|
-
const propertyName = callee.property.value;
|
|
205
|
-
const alias = plumeriaAliases[objectName];
|
|
206
|
-
if (alias === 'NAMESPACE' || objectName === 'css') {
|
|
207
|
-
propName = propertyName;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
else if (utils_1.t.isIdentifier(callee)) {
|
|
211
|
-
const calleeName = callee.value;
|
|
212
|
-
const originalName = plumeriaAliases[calleeName];
|
|
213
|
-
if (originalName) {
|
|
214
|
-
propName = originalName;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
if (propName) {
|
|
219
|
-
if (propName === 'create' &&
|
|
220
|
-
utils_1.t.isObjectExpression(node.init.arguments[0].expression)) {
|
|
221
|
-
const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
222
|
-
if (obj) {
|
|
223
|
-
const hashMap = {};
|
|
224
|
-
Object.entries(obj).forEach(([key, style]) => {
|
|
225
|
-
const records = (0, utils_1.getStyleRecords)(style);
|
|
226
|
-
if (!isProduction) {
|
|
227
|
-
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
228
|
-
records.forEach((r) => {
|
|
229
|
-
addSheet(r.sheet);
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
const atomMap = {};
|
|
233
|
-
records.forEach((r) => (atomMap[r.key] = r.hash));
|
|
234
|
-
hashMap[key] = atomMap;
|
|
235
|
-
});
|
|
236
|
-
if (utils_1.t.isIdentifier(node.id)) {
|
|
237
|
-
idSpans.add(node.id.span.start);
|
|
238
|
-
}
|
|
239
|
-
localCreateStyles[node.id.value] = {
|
|
240
|
-
name: node.id.value,
|
|
241
|
-
type: 'create',
|
|
242
|
-
obj,
|
|
243
|
-
hashMap,
|
|
244
|
-
isExported,
|
|
245
|
-
initSpan: {
|
|
246
|
-
start: node.init.span.start - ast.span.start,
|
|
247
|
-
end: node.init.span.end - ast.span.start,
|
|
248
|
-
},
|
|
249
|
-
declSpan: {
|
|
250
|
-
start: declSpan.start - ast.span.start,
|
|
251
|
-
end: declSpan.end - ast.span.start,
|
|
252
|
-
},
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
else if (propName === 'variants' &&
|
|
257
|
-
utils_1.t.isObjectExpression(node.init.arguments[0].expression)) {
|
|
258
|
-
if (utils_1.t.isIdentifier(node.id)) {
|
|
259
|
-
idSpans.add(node.id.span.start);
|
|
260
|
-
}
|
|
261
|
-
const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, (name) => {
|
|
262
|
-
if (localCreateStyles[name]) {
|
|
263
|
-
return localCreateStyles[name].obj;
|
|
264
|
-
}
|
|
265
|
-
if (mergedCreateTable[name]) {
|
|
266
|
-
const hash = mergedCreateTable[name];
|
|
267
|
-
if (scannedTables.createObjectTable[hash]) {
|
|
268
|
-
return scannedTables.createObjectTable[hash];
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return undefined;
|
|
272
|
-
});
|
|
273
|
-
const { hashMap, sheets } = (0, utils_1.processVariants)(obj);
|
|
274
|
-
if (!isProduction) {
|
|
275
|
-
sheets.forEach(addSheet);
|
|
276
|
-
}
|
|
277
|
-
localCreateStyles[node.id.value] = {
|
|
278
|
-
name: node.id.value,
|
|
279
|
-
type: 'variant',
|
|
280
|
-
obj,
|
|
281
|
-
hashMap,
|
|
282
|
-
isExported,
|
|
283
|
-
initSpan: {
|
|
284
|
-
start: node.init.span.start - ast.span.start,
|
|
285
|
-
end: node.init.span.end - ast.span.start,
|
|
286
|
-
},
|
|
287
|
-
declSpan: {
|
|
288
|
-
start: declSpan.start - ast.span.start,
|
|
289
|
-
end: declSpan.end - ast.span.start,
|
|
290
|
-
},
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
else if (propName === 'createTheme' &&
|
|
294
|
-
utils_1.t.isObjectExpression(node.init.arguments[0].expression)) {
|
|
295
|
-
if (utils_1.t.isIdentifier(node.id)) {
|
|
296
|
-
idSpans.add(node.id.span.start);
|
|
297
|
-
}
|
|
298
|
-
const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
299
|
-
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
300
|
-
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
301
|
-
scannedTables.createThemeHashTable[uniqueKey] = hash;
|
|
302
|
-
scannedTables.createThemeObjectTable[hash] = obj;
|
|
303
|
-
localCreateStyles[node.id.value] = {
|
|
304
|
-
name: node.id.value,
|
|
305
|
-
type: 'constant',
|
|
306
|
-
obj,
|
|
307
|
-
hashMap: scannedTables.createAtomicMapTable[hash],
|
|
308
|
-
isExported,
|
|
309
|
-
initSpan: {
|
|
310
|
-
start: node.init.span.start - ast.span.start,
|
|
311
|
-
end: node.init.span.end - ast.span.start,
|
|
312
|
-
},
|
|
313
|
-
declSpan: {
|
|
314
|
-
start: declSpan.start - ast.span.start,
|
|
315
|
-
end: declSpan.end - ast.span.start,
|
|
316
|
-
},
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
(0, utils_1.traverse)(ast, {
|
|
322
|
-
ImportDeclaration({ node }) {
|
|
323
|
-
if (node.specifiers) {
|
|
324
|
-
node.specifiers.forEach((specifier) => {
|
|
325
|
-
if (specifier.local) {
|
|
326
|
-
excludedSpans.add(specifier.local.span.start);
|
|
327
|
-
}
|
|
328
|
-
if (specifier.imported) {
|
|
329
|
-
excludedSpans.add(specifier.imported.span.start);
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
},
|
|
334
|
-
ExportDeclaration({ node }) {
|
|
335
|
-
if (utils_1.t.isVariableDeclaration(node.declaration)) {
|
|
336
|
-
processedDecls.add(node.declaration);
|
|
337
|
-
node.declaration.declarations.forEach((decl) => {
|
|
338
|
-
checkVariantAssignment(decl);
|
|
339
|
-
registerStyle(decl, node.span, true);
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
},
|
|
343
|
-
VariableDeclaration({ node }) {
|
|
344
|
-
if (processedDecls.has(node))
|
|
345
|
-
return;
|
|
346
|
-
node.declarations.forEach((decl) => {
|
|
347
|
-
checkVariantAssignment(decl);
|
|
348
|
-
registerStyle(decl, node.span, false);
|
|
349
|
-
});
|
|
350
|
-
},
|
|
351
|
-
CallExpression({ node }) {
|
|
352
|
-
const callee = node.callee;
|
|
353
|
-
let propName;
|
|
354
|
-
if (utils_1.t.isMemberExpression(callee) &&
|
|
355
|
-
utils_1.t.isIdentifier(callee.object) &&
|
|
356
|
-
utils_1.t.isIdentifier(callee.property)) {
|
|
357
|
-
const objectName = callee.object.value;
|
|
358
|
-
const propertyName = callee.property.value;
|
|
359
|
-
const alias = plumeriaAliases[objectName];
|
|
360
|
-
if (alias === 'NAMESPACE' || objectName === 'css') {
|
|
361
|
-
propName = propertyName;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
else if (utils_1.t.isIdentifier(callee)) {
|
|
365
|
-
const calleeName = callee.value;
|
|
366
|
-
const originalName = plumeriaAliases[calleeName];
|
|
367
|
-
if (originalName) {
|
|
368
|
-
propName = originalName;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
if (propName) {
|
|
372
|
-
const args = node.arguments;
|
|
373
|
-
if (propName === 'keyframes' &&
|
|
374
|
-
args.length > 0 &&
|
|
375
|
-
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
376
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
377
|
-
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
378
|
-
scannedTables.keyframesObjectTable[hash] = obj;
|
|
379
|
-
if (!isProduction) {
|
|
380
|
-
(0, utils_1.extractOndemandStyles)({ kf: `kf-${hash}` }, extractedSheets, scannedTables);
|
|
381
|
-
}
|
|
382
|
-
replacements.push({
|
|
383
|
-
start: node.span.start - ast.span.start,
|
|
384
|
-
end: node.span.end - ast.span.start,
|
|
385
|
-
content: JSON.stringify(`kf-${hash}`),
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
else if (propName === 'viewTransition' &&
|
|
389
|
-
args.length > 0 &&
|
|
390
|
-
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
391
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
392
|
-
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
393
|
-
scannedTables.viewTransitionObjectTable[hash] = obj;
|
|
394
|
-
if (!isProduction) {
|
|
395
|
-
(0, utils_1.extractOndemandStyles)({ vt: `vt-${hash}` }, extractedSheets, scannedTables);
|
|
396
|
-
}
|
|
397
|
-
replacements.push({
|
|
398
|
-
start: node.span.start - ast.span.start,
|
|
399
|
-
end: node.span.end - ast.span.start,
|
|
400
|
-
content: JSON.stringify(`vt-${hash}`),
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
else if ((propName === 'createTheme' || propName === 'createStatic') &&
|
|
404
|
-
args.length > 0 &&
|
|
405
|
-
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
406
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
407
|
-
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
408
|
-
if (propName === 'createTheme') {
|
|
409
|
-
scannedTables.createThemeObjectTable[hash] = obj;
|
|
410
|
-
}
|
|
411
|
-
else {
|
|
412
|
-
scannedTables.createStaticObjectTable[hash] = obj;
|
|
413
|
-
}
|
|
414
|
-
const prefix = propName === 'createTheme' ? 'tm-' : 'st-';
|
|
415
|
-
replacements.push({
|
|
416
|
-
start: node.span.start - ast.span.start,
|
|
417
|
-
end: node.span.end - ast.span.start,
|
|
418
|
-
content: JSON.stringify(`${prefix}${hash}`),
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
else if (propName === 'create' &&
|
|
422
|
-
args.length > 0 &&
|
|
423
|
-
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
424
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
425
|
-
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
426
|
-
scannedTables.createObjectTable[hash] = obj;
|
|
427
|
-
Object.entries(obj).forEach(([_key, style]) => {
|
|
428
|
-
if (typeof style === 'object' && style !== null) {
|
|
429
|
-
const records = (0, utils_1.getStyleRecords)(style);
|
|
430
|
-
if (!isProduction) {
|
|
431
|
-
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
432
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
},
|
|
439
|
-
});
|
|
440
|
-
(0, utils_1.traverse)(ast, {
|
|
441
|
-
MemberExpression({ node }) {
|
|
442
|
-
if (utils_1.t.isIdentifier(node.object) && utils_1.t.isIdentifier(node.property)) {
|
|
443
|
-
const varName = node.object.value;
|
|
444
|
-
const propName = node.property.value;
|
|
445
|
-
const uniqueKey = `${resourcePath}-${varName}`;
|
|
446
|
-
let hash = scannedTables.createHashTable[uniqueKey];
|
|
447
|
-
if (!hash) {
|
|
448
|
-
hash = mergedCreateTable[varName];
|
|
449
|
-
}
|
|
450
|
-
if (hash) {
|
|
451
|
-
let atomMap;
|
|
452
|
-
if (scannedTables.createAtomicMapTable[hash]) {
|
|
453
|
-
atomMap = scannedTables.createAtomicMapTable[hash][propName];
|
|
454
|
-
}
|
|
455
|
-
if (atomMap) {
|
|
456
|
-
replacements.push({
|
|
457
|
-
start: node.span.start - ast.span.start,
|
|
458
|
-
end: node.span.end - ast.span.start,
|
|
459
|
-
content: JSON.stringify(atomMap),
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
let themeHash = scannedTables.createThemeHashTable[uniqueKey];
|
|
464
|
-
if (!themeHash) {
|
|
465
|
-
themeHash = mergedCreateThemeHashTable[varName];
|
|
466
|
-
}
|
|
467
|
-
if (themeHash) {
|
|
468
|
-
const atomicMap = scannedTables.createAtomicMapTable[themeHash];
|
|
469
|
-
if (atomicMap && atomicMap && atomicMap[propName]) {
|
|
470
|
-
replacements.push({
|
|
471
|
-
start: node.span.start - ast.span.start,
|
|
472
|
-
end: node.span.end - ast.span.start,
|
|
473
|
-
content: JSON.stringify(atomicMap[propName]),
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
let staticHash = scannedTables.createStaticHashTable[uniqueKey];
|
|
478
|
-
if (!staticHash) {
|
|
479
|
-
staticHash = mergedCreateStaticHashTable[varName];
|
|
480
|
-
}
|
|
481
|
-
if (staticHash) {
|
|
482
|
-
const staticObj = scannedTables.createStaticObjectTable[staticHash];
|
|
483
|
-
if (staticObj && staticObj[propName] !== undefined) {
|
|
484
|
-
replacements.push({
|
|
485
|
-
start: node.span.start - ast.span.start,
|
|
486
|
-
end: node.span.end - ast.span.start,
|
|
487
|
-
content: JSON.stringify(staticObj[propName]),
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
},
|
|
493
|
-
Identifier({ node }) {
|
|
494
|
-
if (excludedSpans.has(node.span.start))
|
|
495
|
-
return;
|
|
496
|
-
if (idSpans.has(node.span.start))
|
|
497
|
-
return;
|
|
498
|
-
const styleInfo = localCreateStyles[node.value];
|
|
499
|
-
if (styleInfo) {
|
|
500
|
-
if (styleInfo.type === 'variant') {
|
|
501
|
-
const hashMap = styleInfo.hashMap;
|
|
502
|
-
const independentKeys = Object.keys(hashMap).filter((k) => k !== '_compound');
|
|
503
|
-
const compoundGroups = hashMap._compound || [];
|
|
504
|
-
const independentChecks = independentKeys
|
|
505
|
-
.map((key) => {
|
|
506
|
-
const mapObj = hashMap[key];
|
|
507
|
-
if (typeof mapObj === 'string') {
|
|
508
|
-
return `classes.push("${mapObj}");`;
|
|
509
|
-
}
|
|
510
|
-
const mapStr = JSON.stringify(mapObj);
|
|
511
|
-
return `
|
|
512
|
-
var v${key} = ${mapStr};
|
|
513
|
-
if (props["${key}"] && v${key}[props["${key}"]]) {
|
|
514
|
-
classes.push(v${key}[props["${key}"]]);
|
|
515
|
-
} else if (v${key}["default"]) {
|
|
516
|
-
classes.push(v${key}["default"]);
|
|
517
|
-
}
|
|
518
|
-
`;
|
|
519
|
-
})
|
|
520
|
-
.join('\n');
|
|
521
|
-
const compoundChecks = compoundGroups
|
|
522
|
-
.map((group) => {
|
|
523
|
-
const keys = group.keys;
|
|
524
|
-
const mapObj = group.map;
|
|
525
|
-
const mapStr = JSON.stringify(mapObj);
|
|
526
|
-
const keyExpr = keys
|
|
527
|
-
.map((k) => `(props["${k}"] || "default")`)
|
|
528
|
-
.join(' + ":" + ');
|
|
529
|
-
return `
|
|
530
|
-
var c${keys.join('_')} = ${mapStr};
|
|
531
|
-
var k = ${keyExpr};
|
|
532
|
-
if (c${keys.join('_')}[k]) {
|
|
533
|
-
classes.push(c${keys.join('_')}[k]);
|
|
534
|
-
}
|
|
535
|
-
`;
|
|
536
|
-
})
|
|
537
|
-
.join('\n');
|
|
538
|
-
const runtimeFn = `(props) => {
|
|
539
|
-
var classes = [];
|
|
540
|
-
${independentChecks}
|
|
541
|
-
${compoundChecks}
|
|
542
|
-
return classes.join(" ");
|
|
543
|
-
}`;
|
|
544
|
-
replacements.push({
|
|
545
|
-
start: node.span.start - ast.span.start,
|
|
546
|
-
end: node.span.end - ast.span.start,
|
|
547
|
-
content: runtimeFn,
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
else {
|
|
551
|
-
replacements.push({
|
|
552
|
-
start: node.span.start - ast.span.start,
|
|
553
|
-
end: node.span.end - ast.span.start,
|
|
554
|
-
content: JSON.stringify(styleInfo.hashMap),
|
|
555
|
-
});
|
|
556
|
-
}
|
|
557
|
-
return;
|
|
558
|
-
}
|
|
559
|
-
const varName = node.value;
|
|
560
|
-
const uniqueKey = `${resourcePath}-${varName}`;
|
|
561
|
-
let hash = scannedTables.createHashTable[uniqueKey];
|
|
562
|
-
if (!hash) {
|
|
563
|
-
hash = mergedCreateTable[varName];
|
|
564
|
-
}
|
|
565
|
-
if (hash) {
|
|
566
|
-
const obj = scannedTables.createObjectTable[hash];
|
|
567
|
-
const atomicMap = scannedTables.createAtomicMapTable[hash];
|
|
568
|
-
if (obj && atomicMap) {
|
|
569
|
-
const hashMap = {};
|
|
570
|
-
Object.keys(obj).forEach((key) => {
|
|
571
|
-
if (atomicMap[key]) {
|
|
572
|
-
hashMap[key] = atomicMap[key];
|
|
573
|
-
}
|
|
574
|
-
});
|
|
575
|
-
replacements.push({
|
|
576
|
-
start: node.span.start - ast.span.start,
|
|
577
|
-
end: node.span.end - ast.span.start,
|
|
578
|
-
content: JSON.stringify(hashMap),
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
let themeHash = scannedTables.createThemeHashTable[uniqueKey];
|
|
583
|
-
if (!themeHash) {
|
|
584
|
-
themeHash = mergedCreateThemeHashTable[varName];
|
|
585
|
-
}
|
|
586
|
-
if (themeHash) {
|
|
587
|
-
const atomicMap = scannedTables.createAtomicMapTable[themeHash];
|
|
588
|
-
if (atomicMap) {
|
|
589
|
-
replacements.push({
|
|
590
|
-
start: node.span.start - ast.span.start,
|
|
591
|
-
end: node.span.end - ast.span.start,
|
|
592
|
-
content: JSON.stringify(atomicMap),
|
|
593
|
-
});
|
|
594
|
-
return;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
let staticHash = scannedTables.createStaticHashTable[uniqueKey];
|
|
598
|
-
if (!staticHash) {
|
|
599
|
-
staticHash = mergedCreateStaticHashTable[varName];
|
|
600
|
-
}
|
|
601
|
-
if (staticHash) {
|
|
602
|
-
const staticObj = scannedTables.createStaticObjectTable[staticHash];
|
|
603
|
-
if (staticObj) {
|
|
604
|
-
replacements.push({
|
|
605
|
-
start: node.span.start - ast.span.start,
|
|
606
|
-
end: node.span.end - ast.span.start,
|
|
607
|
-
content: JSON.stringify(staticObj),
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
},
|
|
612
|
-
CallExpression({ node }) {
|
|
613
|
-
const callee = node.callee;
|
|
614
|
-
let isPropsCall = false;
|
|
615
|
-
if (utils_1.t.isMemberExpression(callee) &&
|
|
616
|
-
utils_1.t.isIdentifier(callee.object) &&
|
|
617
|
-
utils_1.t.isIdentifier(callee.property)) {
|
|
618
|
-
const objectName = callee.object.value;
|
|
619
|
-
const propertyName = callee.property.value;
|
|
620
|
-
const alias = plumeriaAliases[objectName];
|
|
621
|
-
if ((alias === 'NAMESPACE' || objectName === 'css') &&
|
|
622
|
-
propertyName === 'props') {
|
|
623
|
-
isPropsCall = true;
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
else if (utils_1.t.isIdentifier(callee)) {
|
|
627
|
-
const calleeName = callee.value;
|
|
628
|
-
const originalName = plumeriaAliases[calleeName];
|
|
629
|
-
if (originalName === 'props') {
|
|
630
|
-
isPropsCall = true;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
if (isPropsCall) {
|
|
634
|
-
const args = node.arguments;
|
|
635
|
-
const resolveStyleObject = (expr) => {
|
|
636
|
-
if (utils_1.t.isObjectExpression(expr)) {
|
|
637
|
-
return (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
638
|
-
}
|
|
639
|
-
else if (utils_1.t.isMemberExpression(expr) &&
|
|
640
|
-
utils_1.t.isIdentifier(expr.object) &&
|
|
641
|
-
(utils_1.t.isIdentifier(expr.property) ||
|
|
642
|
-
expr.property.type === 'Computed')) {
|
|
643
|
-
if (expr.property.type === 'Computed') {
|
|
644
|
-
return {};
|
|
645
|
-
}
|
|
646
|
-
const varName = expr.object.value;
|
|
647
|
-
const propName = expr.property.value;
|
|
648
|
-
const styleInfo = localCreateStyles[varName];
|
|
649
|
-
if (styleInfo && styleInfo.obj[propName]) {
|
|
650
|
-
const style = styleInfo.obj[propName];
|
|
651
|
-
if (typeof style === 'object' && style !== null) {
|
|
652
|
-
return style;
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
const hash = mergedCreateTable[varName];
|
|
656
|
-
if (hash) {
|
|
657
|
-
const obj = scannedTables.createObjectTable[hash];
|
|
658
|
-
if (obj && obj[propName]) {
|
|
659
|
-
const style = obj[propName];
|
|
660
|
-
if (typeof style === 'object' && style !== null) {
|
|
661
|
-
return style;
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
else if (utils_1.t.isIdentifier(expr)) {
|
|
667
|
-
const varName = expr.value;
|
|
668
|
-
const uniqueKey = `${this.resourcePath}-${varName}`;
|
|
669
|
-
let hash = scannedTables.createHashTable[uniqueKey];
|
|
670
|
-
if (!hash) {
|
|
671
|
-
hash = mergedCreateTable[varName];
|
|
672
|
-
}
|
|
673
|
-
if (hash) {
|
|
674
|
-
const obj = scannedTables.createObjectTable[hash];
|
|
675
|
-
if (obj && typeof obj === 'object') {
|
|
676
|
-
return obj;
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
const styleInfo = localCreateStyles[varName];
|
|
680
|
-
if (styleInfo && styleInfo.obj) {
|
|
681
|
-
return styleInfo.obj;
|
|
682
|
-
}
|
|
683
|
-
if (localCreateStyles[varName]) {
|
|
684
|
-
return localCreateStyles[varName].obj;
|
|
685
|
-
}
|
|
686
|
-
const vHash = mergedVariantsTable[varName];
|
|
687
|
-
if (vHash) {
|
|
688
|
-
return scannedTables.variantsObjectTable[vHash];
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
return null;
|
|
692
|
-
};
|
|
693
|
-
const conditionals = [];
|
|
694
|
-
let groupIdCounter = 0;
|
|
695
|
-
let baseStyle = {};
|
|
696
|
-
let isOptimizable = true;
|
|
697
|
-
for (const arg of args) {
|
|
698
|
-
const expr = arg.expression;
|
|
699
|
-
if (utils_1.t.isCallExpression(expr) && utils_1.t.isIdentifier(expr.callee)) {
|
|
700
|
-
const varName = expr.callee.value;
|
|
701
|
-
let variantObj;
|
|
702
|
-
const uniqueKey = `${this.resourcePath}-${varName}`;
|
|
703
|
-
let hash = scannedTables.variantsHashTable[uniqueKey];
|
|
704
|
-
if (!hash) {
|
|
705
|
-
hash = mergedVariantsTable[varName];
|
|
706
|
-
}
|
|
707
|
-
if (hash && scannedTables.variantsObjectTable[hash]) {
|
|
708
|
-
variantObj = scannedTables.variantsObjectTable[hash];
|
|
709
|
-
}
|
|
710
|
-
if (!variantObj) {
|
|
711
|
-
if (localCreateStyles[varName] &&
|
|
712
|
-
localCreateStyles[varName].obj) {
|
|
713
|
-
variantObj = localCreateStyles[varName].obj;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
if (variantObj) {
|
|
717
|
-
const callArgs = expr.arguments;
|
|
718
|
-
if (callArgs.length === 1 && !callArgs[0].spread) {
|
|
719
|
-
const arg = callArgs[0].expression;
|
|
720
|
-
if (arg.type === 'ObjectExpression') {
|
|
721
|
-
for (const prop of arg.properties) {
|
|
722
|
-
let groupName;
|
|
723
|
-
let valExpr;
|
|
724
|
-
if (prop.type === 'KeyValueProperty' &&
|
|
725
|
-
prop.key.type === 'Identifier') {
|
|
726
|
-
groupName = prop.key.value;
|
|
727
|
-
valExpr = prop.value;
|
|
728
|
-
}
|
|
729
|
-
else if (prop.type === 'Identifier') {
|
|
730
|
-
groupName = prop.value;
|
|
731
|
-
valExpr = prop;
|
|
732
|
-
}
|
|
733
|
-
if (groupName && valExpr) {
|
|
734
|
-
const groupVariants = variantObj[groupName];
|
|
735
|
-
if (!groupVariants)
|
|
736
|
-
continue;
|
|
737
|
-
const currentGroupId = ++groupIdCounter;
|
|
738
|
-
const valStart = valExpr.span.start - ast.span.start;
|
|
739
|
-
const valEnd = valExpr.span.end - ast.span.start;
|
|
740
|
-
const valSource = source.substring(valStart, valEnd);
|
|
741
|
-
if (valExpr.type === 'StringLiteral') {
|
|
742
|
-
if (groupVariants[valExpr.value]) {
|
|
743
|
-
baseStyle = (0, utils_1.deepMerge)(baseStyle, groupVariants[valExpr.value]);
|
|
744
|
-
}
|
|
745
|
-
continue;
|
|
746
|
-
}
|
|
747
|
-
Object.entries(groupVariants).forEach(([optionName, style]) => {
|
|
748
|
-
conditionals.push({
|
|
749
|
-
test: valExpr,
|
|
750
|
-
testLHS: valSource,
|
|
751
|
-
testString: `${valSource} === '${optionName}'`,
|
|
752
|
-
truthy: style,
|
|
753
|
-
falsy: {},
|
|
754
|
-
groupId: currentGroupId,
|
|
755
|
-
groupName,
|
|
756
|
-
valueName: optionName,
|
|
757
|
-
varName,
|
|
758
|
-
});
|
|
759
|
-
});
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
continue;
|
|
763
|
-
}
|
|
764
|
-
const argStart = arg.span.start - ast.span.start;
|
|
765
|
-
const argEnd = arg.span.end - ast.span.start;
|
|
766
|
-
const argSource = source.substring(argStart, argEnd);
|
|
767
|
-
if (utils_1.t.isStringLiteral(arg)) {
|
|
768
|
-
if (variantObj[arg.value]) {
|
|
769
|
-
baseStyle = (0, utils_1.deepMerge)(baseStyle, variantObj[arg.value]);
|
|
770
|
-
}
|
|
771
|
-
continue;
|
|
772
|
-
}
|
|
773
|
-
const currentGroupId = ++groupIdCounter;
|
|
774
|
-
Object.entries(variantObj).forEach(([key, style]) => {
|
|
775
|
-
conditionals.push({
|
|
776
|
-
test: arg,
|
|
777
|
-
testLHS: argSource,
|
|
778
|
-
testString: `${argSource} === '${key}'`,
|
|
779
|
-
truthy: style,
|
|
780
|
-
falsy: {},
|
|
781
|
-
groupId: currentGroupId,
|
|
782
|
-
groupName: undefined,
|
|
783
|
-
valueName: key,
|
|
784
|
-
varName,
|
|
785
|
-
});
|
|
786
|
-
});
|
|
787
|
-
continue;
|
|
788
|
-
}
|
|
789
|
-
isOptimizable = false;
|
|
790
|
-
break;
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
else if (utils_1.t.isIdentifier(expr)) {
|
|
794
|
-
const varName = expr.value;
|
|
795
|
-
let variantObj;
|
|
796
|
-
const uniqueKey = `${this.resourcePath}-${varName}`;
|
|
797
|
-
let hash = scannedTables.variantsHashTable[uniqueKey];
|
|
798
|
-
if (!hash) {
|
|
799
|
-
hash = mergedVariantsTable[varName];
|
|
800
|
-
}
|
|
801
|
-
if (hash && scannedTables.variantsObjectTable[hash]) {
|
|
802
|
-
variantObj = scannedTables.variantsObjectTable[hash];
|
|
803
|
-
}
|
|
804
|
-
if (!variantObj) {
|
|
805
|
-
if (localCreateStyles[varName] &&
|
|
806
|
-
localCreateStyles[varName].obj) {
|
|
807
|
-
variantObj = localCreateStyles[varName].obj;
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
if (variantObj) {
|
|
811
|
-
Object.entries(variantObj).forEach(([groupName, groupVariants]) => {
|
|
812
|
-
if (!groupVariants)
|
|
813
|
-
return;
|
|
814
|
-
const currentGroupId = ++groupIdCounter;
|
|
815
|
-
Object.entries(groupVariants).forEach(([optionName, style]) => {
|
|
816
|
-
conditionals.push({
|
|
817
|
-
test: expr,
|
|
818
|
-
testLHS: `props["${groupName}"]`,
|
|
819
|
-
testString: `props["${groupName}"] === '${optionName}'`,
|
|
820
|
-
truthy: style,
|
|
821
|
-
falsy: {},
|
|
822
|
-
groupId: currentGroupId,
|
|
823
|
-
groupName: groupName,
|
|
824
|
-
valueName: optionName,
|
|
825
|
-
varName: varName,
|
|
826
|
-
});
|
|
827
|
-
});
|
|
828
|
-
});
|
|
829
|
-
continue;
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
const getSource = (node) => {
|
|
833
|
-
const start = node.span.start - ast.span.start;
|
|
834
|
-
const end = node.span.end - ast.span.start;
|
|
835
|
-
return source.substring(start, end);
|
|
836
|
-
};
|
|
837
|
-
const collectConditions = (node, currentTestStrings = []) => {
|
|
838
|
-
const staticStyle = resolveStyleObject(node);
|
|
839
|
-
if (staticStyle) {
|
|
840
|
-
if (currentTestStrings.length === 0) {
|
|
841
|
-
baseStyle = (0, utils_1.deepMerge)(baseStyle, staticStyle);
|
|
842
|
-
}
|
|
843
|
-
else {
|
|
844
|
-
const combinedTest = currentTestStrings.join(' && ');
|
|
845
|
-
conditionals.push({
|
|
846
|
-
test: node,
|
|
847
|
-
testString: combinedTest,
|
|
848
|
-
truthy: staticStyle,
|
|
849
|
-
falsy: {},
|
|
850
|
-
varName: undefined,
|
|
851
|
-
});
|
|
852
|
-
}
|
|
853
|
-
return true;
|
|
854
|
-
}
|
|
855
|
-
if (node.type === 'ConditionalExpression') {
|
|
856
|
-
const testSource = getSource(node.test);
|
|
857
|
-
if (currentTestStrings.length === 0) {
|
|
858
|
-
const trueStyle = resolveStyleObject(node.consequent);
|
|
859
|
-
const falseStyle = resolveStyleObject(node.alternate);
|
|
860
|
-
if (trueStyle && falseStyle) {
|
|
861
|
-
conditionals.push({
|
|
862
|
-
test: node,
|
|
863
|
-
testString: testSource,
|
|
864
|
-
truthy: trueStyle,
|
|
865
|
-
falsy: falseStyle,
|
|
866
|
-
varName: undefined,
|
|
867
|
-
});
|
|
868
|
-
return true;
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
collectConditions(node.consequent, [
|
|
872
|
-
...currentTestStrings,
|
|
873
|
-
`(${testSource})`,
|
|
874
|
-
]);
|
|
875
|
-
collectConditions(node.alternate, [
|
|
876
|
-
...currentTestStrings,
|
|
877
|
-
`!(${testSource})`,
|
|
878
|
-
]);
|
|
879
|
-
return true;
|
|
880
|
-
}
|
|
881
|
-
else if (node.type === 'BinaryExpression' &&
|
|
882
|
-
node.operator === '&&') {
|
|
883
|
-
const leftSource = getSource(node.left);
|
|
884
|
-
collectConditions(node.right, [
|
|
885
|
-
...currentTestStrings,
|
|
886
|
-
`(${leftSource})`,
|
|
887
|
-
]);
|
|
888
|
-
return true;
|
|
889
|
-
}
|
|
890
|
-
else if (node.type === 'ParenthesisExpression') {
|
|
891
|
-
return collectConditions(node.expression, currentTestStrings);
|
|
892
|
-
}
|
|
893
|
-
return false;
|
|
894
|
-
};
|
|
895
|
-
const handled = collectConditions(expr);
|
|
896
|
-
if (handled)
|
|
897
|
-
continue;
|
|
898
|
-
isOptimizable = false;
|
|
899
|
-
break;
|
|
900
|
-
}
|
|
901
|
-
if (isOptimizable &&
|
|
902
|
-
(args.length > 0 || Object.keys(baseStyle).length > 0)) {
|
|
903
|
-
if (conditionals.length === 0) {
|
|
904
|
-
if (!isProduction) {
|
|
905
|
-
(0, utils_1.extractOndemandStyles)(baseStyle, extractedSheets, scannedTables);
|
|
906
|
-
}
|
|
907
|
-
const records = (0, utils_1.getStyleRecords)(baseStyle);
|
|
908
|
-
if (!isProduction) {
|
|
909
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
910
|
-
}
|
|
911
|
-
const className = records.map((r) => r.hash).join(' ');
|
|
912
|
-
replacements.push({
|
|
913
|
-
start: node.span.start - ast.span.start,
|
|
914
|
-
end: node.span.end - ast.span.start,
|
|
915
|
-
content: JSON.stringify(className),
|
|
916
|
-
});
|
|
917
|
-
}
|
|
918
|
-
else {
|
|
919
|
-
const propertyCounts = {};
|
|
920
|
-
const addCounts = (style) => {
|
|
921
|
-
Object.keys(style).forEach((key) => {
|
|
922
|
-
propertyCounts[key] = (propertyCounts[key] || 0) + 1;
|
|
923
|
-
});
|
|
924
|
-
};
|
|
925
|
-
addCounts(baseStyle);
|
|
926
|
-
const participation = {};
|
|
927
|
-
const registerParticipation = (style, sourceId) => {
|
|
928
|
-
Object.keys(style).forEach((key) => {
|
|
929
|
-
if (!participation[key])
|
|
930
|
-
participation[key] = new Set();
|
|
931
|
-
participation[key].add(sourceId);
|
|
932
|
-
});
|
|
933
|
-
};
|
|
934
|
-
registerParticipation(baseStyle, 'base');
|
|
935
|
-
conditionals
|
|
936
|
-
.filter((c) => c.groupId === undefined)
|
|
937
|
-
.forEach((c, idx) => {
|
|
938
|
-
const sourceId = `std_${idx}`;
|
|
939
|
-
registerParticipation(c.truthy, sourceId);
|
|
940
|
-
registerParticipation(c.falsy, sourceId);
|
|
941
|
-
});
|
|
942
|
-
const variantGroups = {};
|
|
943
|
-
conditionals.forEach((c) => {
|
|
944
|
-
if (c.groupId !== undefined) {
|
|
945
|
-
if (!variantGroups[c.groupId])
|
|
946
|
-
variantGroups[c.groupId] = [];
|
|
947
|
-
variantGroups[c.groupId].push(c);
|
|
948
|
-
}
|
|
949
|
-
});
|
|
950
|
-
Object.entries(variantGroups).forEach(([groupId, opts]) => {
|
|
951
|
-
const sourceId = `var_${groupId}`;
|
|
952
|
-
opts.forEach((opt) => {
|
|
953
|
-
registerParticipation(opt.truthy, sourceId);
|
|
954
|
-
registerParticipation(opt.falsy, sourceId);
|
|
955
|
-
});
|
|
956
|
-
});
|
|
957
|
-
const conflictingKeys = new Set();
|
|
958
|
-
Object.entries(participation).forEach(([key, sources]) => {
|
|
959
|
-
if (sources.size > 1) {
|
|
960
|
-
conflictingKeys.add(key);
|
|
961
|
-
}
|
|
962
|
-
});
|
|
963
|
-
const baseIndependent = {};
|
|
964
|
-
const baseConflict = {};
|
|
965
|
-
Object.entries(baseStyle).forEach(([key, val]) => {
|
|
966
|
-
if (conflictingKeys.has(key)) {
|
|
967
|
-
baseConflict[key] = val;
|
|
968
|
-
}
|
|
969
|
-
else {
|
|
970
|
-
baseIndependent[key] = val;
|
|
971
|
-
}
|
|
972
|
-
});
|
|
973
|
-
const indepConditionals = [];
|
|
974
|
-
const conflictConditionals = [];
|
|
975
|
-
const splitConditional = (c) => {
|
|
976
|
-
const truthyIndep = {};
|
|
977
|
-
const truthyConf = {};
|
|
978
|
-
const falsyIndep = {};
|
|
979
|
-
const falsyConf = {};
|
|
980
|
-
let hasIndep = false;
|
|
981
|
-
let hasConf = false;
|
|
982
|
-
Object.entries(c.truthy).forEach(([k, v]) => {
|
|
983
|
-
if (conflictingKeys.has(k)) {
|
|
984
|
-
truthyConf[k] = v;
|
|
985
|
-
hasConf = true;
|
|
986
|
-
}
|
|
987
|
-
else {
|
|
988
|
-
truthyIndep[k] = v;
|
|
989
|
-
hasIndep = true;
|
|
990
|
-
}
|
|
991
|
-
});
|
|
992
|
-
Object.entries(c.falsy).forEach(([k, v]) => {
|
|
993
|
-
if (conflictingKeys.has(k)) {
|
|
994
|
-
falsyConf[k] = v;
|
|
995
|
-
hasConf = true;
|
|
996
|
-
}
|
|
997
|
-
else {
|
|
998
|
-
falsyIndep[k] = v;
|
|
999
|
-
hasIndep = true;
|
|
1000
|
-
}
|
|
1001
|
-
});
|
|
1002
|
-
if (hasIndep) {
|
|
1003
|
-
indepConditionals.push({
|
|
1004
|
-
...c,
|
|
1005
|
-
truthy: truthyIndep,
|
|
1006
|
-
falsy: falsyIndep,
|
|
1007
|
-
});
|
|
1008
|
-
}
|
|
1009
|
-
if (hasConf) {
|
|
1010
|
-
conflictConditionals.push({
|
|
1011
|
-
...c,
|
|
1012
|
-
truthy: truthyConf,
|
|
1013
|
-
falsy: falsyConf,
|
|
1014
|
-
});
|
|
1015
|
-
}
|
|
1016
|
-
};
|
|
1017
|
-
conditionals.forEach(splitConditional);
|
|
1018
|
-
const classParts = [];
|
|
1019
|
-
if (Object.keys(baseIndependent).length > 0) {
|
|
1020
|
-
if (!isProduction) {
|
|
1021
|
-
(0, utils_1.extractOndemandStyles)(baseIndependent, extractedSheets, scannedTables);
|
|
1022
|
-
}
|
|
1023
|
-
const records = (0, utils_1.getStyleRecords)(baseIndependent);
|
|
1024
|
-
if (!isProduction) {
|
|
1025
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
1026
|
-
}
|
|
1027
|
-
const className = records.map((r) => r.hash).join(' ');
|
|
1028
|
-
if (className)
|
|
1029
|
-
classParts.push(JSON.stringify(className));
|
|
1030
|
-
}
|
|
1031
|
-
const indepStd = indepConditionals.filter((c) => c.groupId === undefined);
|
|
1032
|
-
indepStd.forEach((c) => {
|
|
1033
|
-
const processBranch = (style) => {
|
|
1034
|
-
if (Object.keys(style).length === 0)
|
|
1035
|
-
return '""';
|
|
1036
|
-
if (!isProduction)
|
|
1037
|
-
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
1038
|
-
const records = (0, utils_1.getStyleRecords)(style);
|
|
1039
|
-
if (!isProduction)
|
|
1040
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
1041
|
-
return JSON.stringify(records.map((r) => r.hash).join(' '));
|
|
1042
|
-
};
|
|
1043
|
-
const tClass = processBranch(c.truthy);
|
|
1044
|
-
const fClass = processBranch(c.falsy);
|
|
1045
|
-
let testStr = c.testString;
|
|
1046
|
-
if (!testStr && c.test) {
|
|
1047
|
-
const start = c.test.span.start - ast.span.start;
|
|
1048
|
-
const end = c.test.span.end - ast.span.start;
|
|
1049
|
-
testStr = source.substring(start, end);
|
|
1050
|
-
}
|
|
1051
|
-
classParts.push(`(${testStr} ? ${tClass} : ${fClass})`);
|
|
1052
|
-
});
|
|
1053
|
-
const indepVarGroups = {};
|
|
1054
|
-
indepConditionals.forEach((c) => {
|
|
1055
|
-
if (c.groupId !== undefined) {
|
|
1056
|
-
if (!indepVarGroups[c.groupId])
|
|
1057
|
-
indepVarGroups[c.groupId] = [];
|
|
1058
|
-
indepVarGroups[c.groupId].push(c);
|
|
1059
|
-
}
|
|
1060
|
-
});
|
|
1061
|
-
Object.values(indepVarGroups).forEach((options) => {
|
|
1062
|
-
let commonTestExpr = null;
|
|
1063
|
-
const lookupMap = {};
|
|
1064
|
-
if (options.length > 0) {
|
|
1065
|
-
if (options[0].testLHS) {
|
|
1066
|
-
commonTestExpr = options[0].testLHS;
|
|
1067
|
-
}
|
|
1068
|
-
else if (options[0].testString) {
|
|
1069
|
-
commonTestExpr = options[0].testString;
|
|
1070
|
-
}
|
|
1071
|
-
else {
|
|
1072
|
-
const firstTest = options[0].test;
|
|
1073
|
-
const firstStart = firstTest.span.start - ast.span.start;
|
|
1074
|
-
const firstEnd = firstTest.span.end - ast.span.start;
|
|
1075
|
-
commonTestExpr = source.substring(firstStart, firstEnd);
|
|
1076
|
-
}
|
|
1077
|
-
options.forEach((opt) => {
|
|
1078
|
-
if (opt.valueName && opt.truthy) {
|
|
1079
|
-
if (!isProduction)
|
|
1080
|
-
(0, utils_1.extractOndemandStyles)(opt.truthy, extractedSheets, scannedTables);
|
|
1081
|
-
const records = (0, utils_1.getStyleRecords)(opt.truthy);
|
|
1082
|
-
if (!isProduction)
|
|
1083
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
1084
|
-
const className = records.map((r) => r.hash).join(' ');
|
|
1085
|
-
if (className) {
|
|
1086
|
-
lookupMap[opt.valueName] = className;
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
});
|
|
1090
|
-
}
|
|
1091
|
-
if (commonTestExpr && Object.keys(lookupMap).length > 0) {
|
|
1092
|
-
const entries = Object.entries(lookupMap)
|
|
1093
|
-
.map(([key, val]) => `"${key}":"${val}"`)
|
|
1094
|
-
.join(',');
|
|
1095
|
-
classParts.push(`({${entries}}[${commonTestExpr}] || "")`);
|
|
1096
|
-
}
|
|
1097
|
-
});
|
|
1098
|
-
if (Object.keys(baseConflict).length > 0 ||
|
|
1099
|
-
conflictConditionals.length > 0) {
|
|
1100
|
-
const conflictStd = conflictConditionals.filter((c) => c.groupId === undefined);
|
|
1101
|
-
const conflictVarGroups = {};
|
|
1102
|
-
conflictConditionals.forEach((c) => {
|
|
1103
|
-
if (c.groupId !== undefined) {
|
|
1104
|
-
if (!conflictVarGroups[c.groupId])
|
|
1105
|
-
conflictVarGroups[c.groupId] = [];
|
|
1106
|
-
conflictVarGroups[c.groupId].push(c);
|
|
1107
|
-
}
|
|
1108
|
-
});
|
|
1109
|
-
const dimensions = [];
|
|
1110
|
-
conflictStd.forEach((c) => {
|
|
1111
|
-
let testStr = c.testString;
|
|
1112
|
-
if (!testStr && c.test) {
|
|
1113
|
-
const start = c.test.span.start - ast.span.start;
|
|
1114
|
-
const end = c.test.span.end - ast.span.start;
|
|
1115
|
-
testStr = source.substring(start, end);
|
|
1116
|
-
}
|
|
1117
|
-
dimensions.push({
|
|
1118
|
-
type: 'std',
|
|
1119
|
-
testExpr: testStr,
|
|
1120
|
-
options: [
|
|
1121
|
-
{ value: 0, style: c.falsy, label: 'false' },
|
|
1122
|
-
{ value: 1, style: c.truthy, label: 'true' },
|
|
1123
|
-
],
|
|
1124
|
-
});
|
|
1125
|
-
});
|
|
1126
|
-
Object.entries(conflictVarGroups).forEach(([_groupId, opts]) => {
|
|
1127
|
-
let commonTestExpr = null;
|
|
1128
|
-
if (opts.length > 0) {
|
|
1129
|
-
if (opts[0].testLHS) {
|
|
1130
|
-
commonTestExpr = opts[0].testLHS;
|
|
1131
|
-
}
|
|
1132
|
-
else if (opts[0].testString) {
|
|
1133
|
-
commonTestExpr = opts[0].testString;
|
|
1134
|
-
}
|
|
1135
|
-
else {
|
|
1136
|
-
const firstTest = opts[0].test;
|
|
1137
|
-
const firstStart = firstTest.span.start - ast.span.start;
|
|
1138
|
-
const firstEnd = firstTest.span.end - ast.span.start;
|
|
1139
|
-
commonTestExpr = source.substring(firstStart, firstEnd);
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
const options = opts.map((opt) => ({
|
|
1143
|
-
value: opt.valueName,
|
|
1144
|
-
style: opt.truthy,
|
|
1145
|
-
label: opt.valueName || 'default',
|
|
1146
|
-
}));
|
|
1147
|
-
dimensions.push({
|
|
1148
|
-
type: 'var',
|
|
1149
|
-
testExpr: commonTestExpr || '""',
|
|
1150
|
-
options: options,
|
|
1151
|
-
});
|
|
1152
|
-
});
|
|
1153
|
-
const results = {};
|
|
1154
|
-
const recurse = (dimIndex, currentStyle, keyParts) => {
|
|
1155
|
-
if (dimIndex >= dimensions.length) {
|
|
1156
|
-
if (!isProduction)
|
|
1157
|
-
(0, utils_1.extractOndemandStyles)(currentStyle, extractedSheets, scannedTables);
|
|
1158
|
-
const records = (0, utils_1.getStyleRecords)(currentStyle);
|
|
1159
|
-
if (!isProduction)
|
|
1160
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
1161
|
-
const className = records.map((r) => r.hash).join(' ');
|
|
1162
|
-
const finalKey = keyParts.join('__');
|
|
1163
|
-
if (className)
|
|
1164
|
-
results[finalKey] = className;
|
|
1165
|
-
return;
|
|
1166
|
-
}
|
|
1167
|
-
const dim = dimensions[dimIndex];
|
|
1168
|
-
dim.options.forEach((opt) => {
|
|
1169
|
-
const nextStyle = (0, utils_1.deepMerge)(currentStyle, opt.style);
|
|
1170
|
-
recurse(dimIndex + 1, nextStyle, [
|
|
1171
|
-
...keyParts,
|
|
1172
|
-
String(opt.value),
|
|
1173
|
-
]);
|
|
1174
|
-
});
|
|
1175
|
-
};
|
|
1176
|
-
recurse(0, baseConflict, []);
|
|
1177
|
-
let baseConflictClass = '';
|
|
1178
|
-
if (Object.keys(baseConflict).length > 0) {
|
|
1179
|
-
if (!isProduction)
|
|
1180
|
-
(0, utils_1.extractOndemandStyles)(baseConflict, extractedSheets, scannedTables);
|
|
1181
|
-
const records = (0, utils_1.getStyleRecords)(baseConflict);
|
|
1182
|
-
if (!isProduction)
|
|
1183
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
1184
|
-
baseConflictClass = records.map((r) => r.hash).join(' ');
|
|
1185
|
-
}
|
|
1186
|
-
const keyExprs = [];
|
|
1187
|
-
dimensions.forEach((dim) => {
|
|
1188
|
-
if (dim.type === 'std') {
|
|
1189
|
-
keyExprs.push(`(${dim.testExpr} ? "1" : "0")`);
|
|
1190
|
-
}
|
|
1191
|
-
else {
|
|
1192
|
-
keyExprs.push(dim.testExpr || '""');
|
|
1193
|
-
}
|
|
1194
|
-
});
|
|
1195
|
-
const masterKeyExpr = keyExprs.length > 0 ? keyExprs.join(' + "__" + ') : '""';
|
|
1196
|
-
const tableJson = JSON.stringify(results);
|
|
1197
|
-
const fallback = baseConflictClass
|
|
1198
|
-
? JSON.stringify(baseConflictClass)
|
|
1199
|
-
: '""';
|
|
1200
|
-
classParts.push(`(${tableJson}[${masterKeyExpr}] || ${fallback})`);
|
|
1201
|
-
}
|
|
1202
|
-
const replacement = classParts.length > 0 ? classParts.join(' + " " + ') : '""';
|
|
1203
|
-
replacements.push({
|
|
1204
|
-
start: node.span.start - ast.span.start,
|
|
1205
|
-
end: node.span.end - ast.span.start,
|
|
1206
|
-
content: replacement,
|
|
1207
|
-
});
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
},
|
|
1212
|
-
});
|
|
1213
|
-
Object.values(localCreateStyles).forEach((info) => {
|
|
1214
|
-
if (info.type === 'constant') {
|
|
1215
|
-
return;
|
|
1216
|
-
}
|
|
1217
|
-
if (info.isExported) {
|
|
1218
|
-
replacements.push({
|
|
1219
|
-
start: info.declSpan.start,
|
|
1220
|
-
end: info.declSpan.end,
|
|
1221
|
-
content: JSON.stringify(''),
|
|
1222
|
-
});
|
|
1223
|
-
}
|
|
1224
|
-
else {
|
|
1225
|
-
replacements.push({
|
|
1226
|
-
start: info.declSpan.start,
|
|
1227
|
-
end: info.declSpan.end,
|
|
1228
|
-
content: '',
|
|
1229
|
-
});
|
|
1230
|
-
}
|
|
1231
|
-
});
|
|
1232
|
-
const optInCSS = await (0, utils_1.optimizer)(extractedSheets.join(''));
|
|
1233
|
-
const buffer = Buffer.from(source);
|
|
1234
|
-
let offset = 0;
|
|
1235
|
-
const parts = [];
|
|
1236
|
-
replacements
|
|
1237
|
-
.sort((a, b) => a.start - b.start || b.end - a.end)
|
|
1238
|
-
.forEach((r) => {
|
|
1239
|
-
if (r.start < offset)
|
|
1240
|
-
return;
|
|
1241
|
-
parts.push(buffer.subarray(offset, r.start));
|
|
1242
|
-
parts.push(Buffer.from(r.content));
|
|
1243
|
-
offset = r.end;
|
|
1244
|
-
});
|
|
1245
|
-
parts.push(buffer.subarray(offset));
|
|
1246
|
-
const transformedSource = Buffer.concat(parts).toString();
|
|
1247
|
-
const VIRTUAL_CSS_PATH = require.resolve(VIRTUAL_FILE_PATH);
|
|
1248
|
-
function stringifyRequest(loaderContext, request) {
|
|
1249
|
-
const context = loaderContext.context || loaderContext.rootContext;
|
|
1250
|
-
const relativePath = path_1.default.relative(context, request);
|
|
1251
|
-
const requestPath = relativePath.startsWith('.')
|
|
1252
|
-
? relativePath
|
|
1253
|
-
: './' + relativePath;
|
|
1254
|
-
return JSON.stringify(requestPath);
|
|
1255
|
-
}
|
|
1256
|
-
const virtualCssRequest = stringifyRequest(this, `${VIRTUAL_CSS_PATH}`);
|
|
1257
|
-
const postfix = `\nimport ${virtualCssRequest};`;
|
|
1258
|
-
const css = (0, fs_1.readFileSync)(VIRTUAL_FILE_PATH, 'utf-8');
|
|
1259
|
-
function generateOrderedCSS(styles) {
|
|
1260
|
-
const sections = [];
|
|
1261
|
-
if (styles.keyframeStyles?.trim()) {
|
|
1262
|
-
if (!css.includes(styles.keyframeStyles))
|
|
1263
|
-
sections.push(styles.keyframeStyles);
|
|
1264
|
-
}
|
|
1265
|
-
if (styles.viewTransitionStyles?.trim()) {
|
|
1266
|
-
if (!css.includes(styles.viewTransitionStyles))
|
|
1267
|
-
sections.push(styles.viewTransitionStyles);
|
|
1268
|
-
}
|
|
1269
|
-
if (styles.themeStyles?.trim()) {
|
|
1270
|
-
if (!css.includes(styles.themeStyles))
|
|
1271
|
-
sections.push(styles.themeStyles);
|
|
1272
|
-
}
|
|
1273
|
-
if (styles.baseStyles?.trim()) {
|
|
1274
|
-
sections.push(styles.baseStyles);
|
|
1275
|
-
}
|
|
1276
|
-
return sections.join('\n');
|
|
1277
|
-
}
|
|
1278
|
-
const orderedCSS = await (0, utils_1.optimizer)(generateOrderedCSS(fileStyles));
|
|
1279
|
-
const relativeId = path_1.default.relative(process.cwd(), this.resourcePath);
|
|
1280
|
-
const hmrCode = `
|
|
1281
|
-
if (module.hot) {
|
|
1282
|
-
module.hot.accept(${virtualCssRequest});
|
|
1283
|
-
|
|
1284
|
-
const styleId = "plumeria-hmr";
|
|
1285
|
-
const fileKey = ${JSON.stringify(relativeId)};
|
|
1286
|
-
|
|
1287
|
-
let styleEl = document.getElementById(styleId);
|
|
1288
|
-
|
|
1289
|
-
if (!styleEl) {
|
|
1290
|
-
styleEl = document.createElement("style");
|
|
1291
|
-
styleEl.id = styleId;
|
|
1292
|
-
document.head.prepend(styleEl);
|
|
1293
|
-
styleEl.__plumeriaStyles = {};
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
styleEl.__plumeriaStyles[fileKey] = ${JSON.stringify(orderedCSS)};
|
|
1297
|
-
styleEl.textContent = Object.values(styleEl.__plumeriaStyles).join('\\n');
|
|
1298
|
-
|
|
1299
|
-
module.hot.dispose(() => {
|
|
1300
|
-
if (styleEl && styleEl.__plumeriaStyles) {
|
|
1301
|
-
delete styleEl.__plumeriaStyles[fileKey];
|
|
1302
|
-
styleEl.textContent = Object.values(styleEl.__plumeriaStyles).join('\\n');
|
|
1303
|
-
|
|
1304
|
-
if (Object.keys(styleEl.__plumeriaStyles).length === 0 && styleEl.parentNode) {
|
|
1305
|
-
styleEl.parentNode.removeChild(styleEl);
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
});
|
|
1309
|
-
}
|
|
1310
|
-
`;
|
|
1311
|
-
if (extractedSheets.length > 0 && process.env.NODE_ENV === 'development') {
|
|
1312
|
-
(0, fs_1.appendFileSync)(VIRTUAL_FILE_PATH, optInCSS, 'utf-8');
|
|
1313
|
-
}
|
|
1314
|
-
const useClientDirective = /^\s*['"]use client['"]/;
|
|
1315
|
-
if (process.env.NODE_ENV === 'production')
|
|
1316
|
-
return callback(null, transformedSource);
|
|
1317
|
-
if (!useClientDirective.test(source)) {
|
|
1318
|
-
callback(null, transformedSource + postfix);
|
|
1319
|
-
return;
|
|
1320
|
-
}
|
|
1321
|
-
else {
|
|
1322
|
-
callback(null, transformedSource + hmrCode);
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
6
|
+
const turbopack_loader_1 = __importDefault(require("@plumeria/turbopack-loader"));
|
|
7
|
+
exports.default = turbopack_loader_1.default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/webpack-plugin",
|
|
3
|
-
"version": "7.1
|
|
3
|
+
"version": "7.2.1",
|
|
4
4
|
"description": "Plumeria Webpack plugin",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,16 +18,10 @@
|
|
|
18
18
|
"main": "dist/index.js",
|
|
19
19
|
"types": "dist/index.d.ts",
|
|
20
20
|
"files": [
|
|
21
|
-
"dist/"
|
|
22
|
-
"zero-virtual.css"
|
|
21
|
+
"dist/"
|
|
23
22
|
],
|
|
24
23
|
"dependencies": {
|
|
25
|
-
"@plumeria/
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"@swc/core": "1.15.8",
|
|
29
|
-
"webpack": "5.101.0",
|
|
30
|
-
"zss-engine": "2.2.4"
|
|
24
|
+
"@plumeria/turbopack-loader": "^7.2.1"
|
|
31
25
|
},
|
|
32
26
|
"publishConfig": {
|
|
33
27
|
"access": "public",
|
package/zero-virtual.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/** Placeholder file */
|