@plumeria/webpack-plugin 0.29.0 → 1.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.d.ts +1 -1
- package/dist/index.js +5 -3
- package/dist/virtual-css-loader.js +106 -541
- package/package.json +5 -7
- package/dist/create.d.ts +0 -5
- package/dist/create.js +0 -117
- package/dist/types.d.ts +0 -15
- package/dist/types.js +0 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -19,6 +19,9 @@ class PlumeriaPlugin {
|
|
|
19
19
|
this.stylesByFile.delete(absPath);
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
|
+
compiler.hooks.watchRun.tap(PLUGIN_NAME, () => {
|
|
23
|
+
this.stylesByFile.clear();
|
|
24
|
+
});
|
|
22
25
|
compiler.hooks.normalModuleFactory.tap(PLUGIN_NAME, (nmf) => {
|
|
23
26
|
nmf.hooks.createModule.tap(PLUGIN_NAME, (createData) => {
|
|
24
27
|
const modPath = createData.matchResource ?? createData.resourceResolveData?.path;
|
|
@@ -51,7 +54,7 @@ class PlumeriaPlugin {
|
|
|
51
54
|
if (allStyles.length === 0) {
|
|
52
55
|
return '';
|
|
53
56
|
}
|
|
54
|
-
const sortedStyles = allStyles.sort((
|
|
57
|
+
const sortedStyles = allStyles.sort((b, a) => (b.lastAccessed || 0) - (a.lastAccessed || 0));
|
|
55
58
|
const keyframeStylesSet = new Set();
|
|
56
59
|
const viewTransitionStylesSet = new Set();
|
|
57
60
|
const tokenStylesSet = new Set();
|
|
@@ -76,8 +79,7 @@ class PlumeriaPlugin {
|
|
|
76
79
|
.join('\n');
|
|
77
80
|
}
|
|
78
81
|
writeCSS() {
|
|
79
|
-
|
|
80
|
-
css = '@layer base, queries;\n\n' + css;
|
|
82
|
+
const css = this.generateOrderedCSS();
|
|
81
83
|
fs_1.default.writeFileSync(this.outFile, css, 'utf-8');
|
|
82
84
|
}
|
|
83
85
|
}
|
|
@@ -1,529 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
6
|
exports.default = loader;
|
|
40
|
-
const core_1 = require("@
|
|
41
|
-
const t = __importStar(require("@babel/types"));
|
|
7
|
+
const core_1 = require("@swc/core");
|
|
42
8
|
const path_1 = __importDefault(require("path"));
|
|
43
9
|
const fs_1 = __importDefault(require("fs"));
|
|
44
|
-
const create_1 = require("./create");
|
|
45
10
|
const zss_engine_1 = require("zss-engine");
|
|
46
|
-
const
|
|
47
|
-
const PATTERN_PATH = path_1.default.join(PROJECT_ROOT, '**/*.{js,jsx,ts,tsx}');
|
|
48
|
-
const GLOB_OPTIONS = {
|
|
49
|
-
exclude: ['**/node_modules/**', '**/dist/**', '**/build/**', '**/.next/**'],
|
|
50
|
-
cwd: PROJECT_ROOT,
|
|
51
|
-
};
|
|
52
|
-
let constTable = {};
|
|
53
|
-
let tokensTable = {};
|
|
54
|
-
let keyframesHashTable = {};
|
|
55
|
-
let keyframesObjectTable = {};
|
|
56
|
-
let viewTransitionHashTable = {};
|
|
57
|
-
let viewTransitionObjectTable = {};
|
|
58
|
-
let defineTokensObjectTable = {};
|
|
59
|
-
function objectExpressionToObject(node, constTable, keyframesHashTable, viewTransitionHashTable, tokensTable) {
|
|
60
|
-
const obj = {};
|
|
61
|
-
node.properties.forEach((prop) => {
|
|
62
|
-
if (!t.isObjectProperty(prop))
|
|
63
|
-
return;
|
|
64
|
-
const key = getPropertyKey(prop.key, constTable);
|
|
65
|
-
if (!key)
|
|
66
|
-
return;
|
|
67
|
-
const val = prop.value;
|
|
68
|
-
if (t.isIdentifier(val) || t.isMemberExpression(val)) {
|
|
69
|
-
const resolvedKeyframe = resolveKeyframesTableMemberExpression(val, keyframesHashTable);
|
|
70
|
-
if (resolvedKeyframe !== undefined) {
|
|
71
|
-
obj[key] = 'kf-' + resolvedKeyframe;
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const resolvedViewTransitioin = resolveViewTransitionTableMemberExpression(val, viewTransitionHashTable);
|
|
75
|
-
if (resolvedViewTransitioin !== undefined) {
|
|
76
|
-
obj[key] = 'vt-' + resolvedViewTransitioin;
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const resolvedTheme = resolveTokensTableMemberExpressionByNode(val, tokensTable);
|
|
80
|
-
if (resolvedTheme !== undefined) {
|
|
81
|
-
obj[key] = resolvedTheme;
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (t.isStringLiteral(val) ||
|
|
86
|
-
t.isNumericLiteral(val) ||
|
|
87
|
-
t.isBooleanLiteral(val)) {
|
|
88
|
-
obj[key] = val.value;
|
|
89
|
-
}
|
|
90
|
-
else if (t.isUnaryExpression(val)) {
|
|
91
|
-
obj[key] = evaluateUnaryExpression(val);
|
|
92
|
-
}
|
|
93
|
-
else if (t.isObjectExpression(val)) {
|
|
94
|
-
obj[key] = objectExpressionToObject(val, constTable, keyframesHashTable, viewTransitionHashTable, tokensTable);
|
|
95
|
-
}
|
|
96
|
-
else if (t.isMemberExpression(val)) {
|
|
97
|
-
const resolved = resolveConstTableMemberExpression(val, constTable);
|
|
98
|
-
obj[key] = resolved !== undefined ? resolved : '[unresolved]';
|
|
99
|
-
}
|
|
100
|
-
else if (t.isIdentifier(val)) {
|
|
101
|
-
if (constTable[val.name] !== undefined) {
|
|
102
|
-
obj[key] = constTable[val.name];
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
obj[key] = '[unresolved identifier]';
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
obj[key] = '[unsupported value type]';
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
return obj;
|
|
113
|
-
}
|
|
114
|
-
function collectLocalConsts(ast) {
|
|
115
|
-
const localConsts = {};
|
|
116
|
-
(0, core_1.traverse)(ast, {
|
|
117
|
-
VariableDeclarator(path) {
|
|
118
|
-
const { node } = path;
|
|
119
|
-
if (t.isIdentifier(node.id) && node.init) {
|
|
120
|
-
if (t.isStringLiteral(node.init)) {
|
|
121
|
-
localConsts[node.id.name] = node.init.value;
|
|
122
|
-
}
|
|
123
|
-
else if (t.isObjectExpression(node.init)) {
|
|
124
|
-
localConsts[node.id.name] = objectExpressionToObject(node.init, localConsts, keyframesHashTable, viewTransitionHashTable, tokensTable);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
});
|
|
129
|
-
return localConsts;
|
|
130
|
-
}
|
|
131
|
-
function getPropertyKey(node, constTable) {
|
|
132
|
-
if (t.isIdentifier(node)) {
|
|
133
|
-
if (constTable[node.name] && typeof constTable[node.name] === 'string') {
|
|
134
|
-
return constTable[node.name];
|
|
135
|
-
}
|
|
136
|
-
return node.name;
|
|
137
|
-
}
|
|
138
|
-
if (t.isStringLiteral(node))
|
|
139
|
-
return node.value;
|
|
140
|
-
if (t.isMemberExpression(node)) {
|
|
141
|
-
const result = resolveConstTableMemberExpression(node, constTable);
|
|
142
|
-
if (typeof result === 'string')
|
|
143
|
-
return result;
|
|
144
|
-
throw new Error(`Resolved key is not a string: ${JSON.stringify(result)}`);
|
|
145
|
-
}
|
|
146
|
-
if (t.isTemplateLiteral(node)) {
|
|
147
|
-
return evaluateTemplateLiteral(node, constTable);
|
|
148
|
-
}
|
|
149
|
-
if (t.isBinaryExpression(node)) {
|
|
150
|
-
return evaluateBinaryExpression(node, constTable);
|
|
151
|
-
}
|
|
152
|
-
throw new Error(`Unsupported property key type: ${node.type}`);
|
|
153
|
-
}
|
|
154
|
-
function evaluateTemplateLiteral(node, constTable) {
|
|
155
|
-
let result = '';
|
|
156
|
-
for (let i = 0; i < node.quasis.length; i++) {
|
|
157
|
-
result += node.quasis[i].value.cooked || node.quasis[i].value.raw;
|
|
158
|
-
if (i < node.expressions.length) {
|
|
159
|
-
const expr = node.expressions[i];
|
|
160
|
-
const evaluatedExpr = evaluateExpression(expr, constTable);
|
|
161
|
-
result += String(evaluatedExpr);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return result;
|
|
165
|
-
}
|
|
166
|
-
function evaluateBinaryExpression(node, constTable) {
|
|
167
|
-
const left = evaluateExpression(node.left, constTable);
|
|
168
|
-
const right = evaluateExpression(node.right, constTable);
|
|
169
|
-
if (node.operator === '+') {
|
|
170
|
-
return String(left) + String(right);
|
|
171
|
-
}
|
|
172
|
-
throw new Error(`Unsupported binary operator: ${node.operator}`);
|
|
173
|
-
}
|
|
174
|
-
function evaluateExpression(node, constTable) {
|
|
175
|
-
if (t.isStringLiteral(node)) {
|
|
176
|
-
return node.value;
|
|
177
|
-
}
|
|
178
|
-
if (t.isNumericLiteral(node)) {
|
|
179
|
-
return node.value;
|
|
180
|
-
}
|
|
181
|
-
if (t.isBooleanLiteral(node)) {
|
|
182
|
-
return node.value;
|
|
183
|
-
}
|
|
184
|
-
if (t.isNullLiteral(node)) {
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
if (t.isIdentifier(node)) {
|
|
188
|
-
if (constTable[node.name] !== undefined) {
|
|
189
|
-
return constTable[node.name];
|
|
190
|
-
}
|
|
191
|
-
if (keyframesHashTable[node.name] !== undefined) {
|
|
192
|
-
return keyframesHashTable[node.name];
|
|
193
|
-
}
|
|
194
|
-
if (viewTransitionHashTable[node.name] !== undefined) {
|
|
195
|
-
return viewTransitionHashTable[node.name];
|
|
196
|
-
}
|
|
197
|
-
return `[unresolved: ${node.name}]`;
|
|
198
|
-
}
|
|
199
|
-
if (t.isMemberExpression(node)) {
|
|
200
|
-
const resolved = resolveConstTableMemberExpression(node, constTable);
|
|
201
|
-
if (resolved !== undefined) {
|
|
202
|
-
return resolved;
|
|
203
|
-
}
|
|
204
|
-
const resolvedTheme = resolveTokensTableMemberExpressionByNode(node, tokensTable);
|
|
205
|
-
if (resolvedTheme !== undefined) {
|
|
206
|
-
return resolvedTheme;
|
|
207
|
-
}
|
|
208
|
-
return `[unresolved member expression]`;
|
|
209
|
-
}
|
|
210
|
-
if (t.isBinaryExpression(node)) {
|
|
211
|
-
return evaluateBinaryExpression(node, constTable);
|
|
212
|
-
}
|
|
213
|
-
if (t.isTemplateLiteral(node)) {
|
|
214
|
-
return evaluateTemplateLiteral(node, constTable);
|
|
215
|
-
}
|
|
216
|
-
if (t.isUnaryExpression(node)) {
|
|
217
|
-
return evaluateUnaryExpression(node);
|
|
218
|
-
}
|
|
219
|
-
throw new Error(`Unsupported expression type: ${node.type}`);
|
|
220
|
-
}
|
|
221
|
-
function evaluateUnaryExpression(node) {
|
|
222
|
-
const arg = node.argument;
|
|
223
|
-
switch (node.operator) {
|
|
224
|
-
case '-':
|
|
225
|
-
if (t.isNumericLiteral(arg))
|
|
226
|
-
return -arg.value;
|
|
227
|
-
break;
|
|
228
|
-
case '+':
|
|
229
|
-
if (t.isNumericLiteral(arg))
|
|
230
|
-
return +arg.value;
|
|
231
|
-
break;
|
|
232
|
-
default:
|
|
233
|
-
throw new Error(`Unsupported unary operator: ${node.operator}`);
|
|
234
|
-
}
|
|
235
|
-
throw new Error(`Unsupported UnaryExpression argument type: ${arg.type}`);
|
|
236
|
-
}
|
|
237
|
-
function resolveKeyframesTableMemberExpression(node, keyframesHashTable) {
|
|
238
|
-
if (t.isIdentifier(node)) {
|
|
239
|
-
return keyframesHashTable[node.name];
|
|
240
|
-
}
|
|
241
|
-
if (t.isMemberExpression(node)) {
|
|
242
|
-
if (t.isIdentifier(node.object)) {
|
|
243
|
-
return keyframesHashTable[node.object.name];
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
function resolveViewTransitionTableMemberExpression(node, viewTransitionHashTable) {
|
|
248
|
-
if (t.isIdentifier(node)) {
|
|
249
|
-
return viewTransitionHashTable[node.name];
|
|
250
|
-
}
|
|
251
|
-
if (t.isMemberExpression(node)) {
|
|
252
|
-
if (t.isIdentifier(node.object)) {
|
|
253
|
-
return viewTransitionHashTable[node.object.name];
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
function resolveConstTableMemberExpression(node, constTable) {
|
|
258
|
-
if (t.isIdentifier(node.object) && t.isIdentifier(node.property)) {
|
|
259
|
-
const varName = node.object.name;
|
|
260
|
-
const key = node.property.name;
|
|
261
|
-
const tableValue = constTable[varName];
|
|
262
|
-
if (tableValue && typeof tableValue === 'object' && key in tableValue) {
|
|
263
|
-
return tableValue[key];
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
return undefined;
|
|
267
|
-
}
|
|
268
|
-
function resolveTokensTableMemberExpressionByNode(node, tokensTable) {
|
|
269
|
-
if (t.isMemberExpression(node) && t.isIdentifier(node.object)) {
|
|
270
|
-
const varName = node.object.name;
|
|
271
|
-
let key;
|
|
272
|
-
if (t.isIdentifier(node.property)) {
|
|
273
|
-
key = node.property.name;
|
|
274
|
-
}
|
|
275
|
-
else if (t.isStringLiteral(node.property)) {
|
|
276
|
-
key = node.property.value;
|
|
277
|
-
}
|
|
278
|
-
if (key &&
|
|
279
|
-
tokensTable[varName] &&
|
|
280
|
-
tokensTable[varName][key] !== undefined) {
|
|
281
|
-
const cssVarName = (0, zss_engine_1.camelToKebabCase)(key);
|
|
282
|
-
return `var(--${cssVarName})`;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return undefined;
|
|
286
|
-
}
|
|
287
|
-
function scanForKeyframes() {
|
|
288
|
-
const keyframesHashTableLocal = {};
|
|
289
|
-
const keyframesObjectTableLocal = {};
|
|
290
|
-
const files = fs_1.default.globSync(PATTERN_PATH, GLOB_OPTIONS);
|
|
291
|
-
for (const filePath of files) {
|
|
292
|
-
if (!isCSSDefineFile(filePath, 'keyframes'))
|
|
293
|
-
continue;
|
|
294
|
-
this.addDependency(filePath);
|
|
295
|
-
const source = fs_1.default.readFileSync(filePath, 'utf8');
|
|
296
|
-
const ast = (0, core_1.parseSync)(source, {
|
|
297
|
-
sourceType: 'module',
|
|
298
|
-
presets: [
|
|
299
|
-
['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
|
|
300
|
-
],
|
|
301
|
-
});
|
|
302
|
-
for (const node of ast?.program.body) {
|
|
303
|
-
let declarations = [];
|
|
304
|
-
if (t.isVariableDeclaration(node)) {
|
|
305
|
-
declarations = node.declarations;
|
|
306
|
-
}
|
|
307
|
-
else if (t.isExportNamedDeclaration(node) &&
|
|
308
|
-
node.declaration &&
|
|
309
|
-
t.isVariableDeclaration(node.declaration)) {
|
|
310
|
-
declarations = node.declaration.declarations;
|
|
311
|
-
}
|
|
312
|
-
for (const decl of declarations) {
|
|
313
|
-
if (t.isVariableDeclarator(decl) &&
|
|
314
|
-
t.isIdentifier(decl.id) &&
|
|
315
|
-
t.isCallExpression(decl.init) &&
|
|
316
|
-
t.isMemberExpression(decl.init.callee) &&
|
|
317
|
-
t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
|
|
318
|
-
t.isIdentifier(decl.init.callee.property, { name: 'keyframes' }) &&
|
|
319
|
-
t.isObjectExpression(decl.init.arguments[0])) {
|
|
320
|
-
const varName = decl.id.name;
|
|
321
|
-
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTableLocal, viewTransitionHashTable, tokensTable);
|
|
322
|
-
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
323
|
-
keyframesHashTableLocal[varName] = hash;
|
|
324
|
-
keyframesObjectTableLocal[hash] = obj;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
return {
|
|
330
|
-
keyframesHashTableLocal,
|
|
331
|
-
keyframesObjectTableLocal,
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
function scanForViewTransition() {
|
|
335
|
-
const viewTransitionHashTableLocal = {};
|
|
336
|
-
const viewTransitionObjectTableLocal = {};
|
|
337
|
-
const files = fs_1.default.globSync(PATTERN_PATH, GLOB_OPTIONS);
|
|
338
|
-
for (const filePath of files) {
|
|
339
|
-
if (!isCSSDefineFile(filePath, 'viewTransition'))
|
|
340
|
-
continue;
|
|
341
|
-
this.addDependency(filePath);
|
|
342
|
-
const source = fs_1.default.readFileSync(filePath, 'utf8');
|
|
343
|
-
const ast = (0, core_1.parseSync)(source, {
|
|
344
|
-
sourceType: 'module',
|
|
345
|
-
presets: [
|
|
346
|
-
['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
|
|
347
|
-
],
|
|
348
|
-
});
|
|
349
|
-
for (const node of ast?.program.body) {
|
|
350
|
-
let declarations = [];
|
|
351
|
-
if (t.isVariableDeclaration(node)) {
|
|
352
|
-
declarations = node.declarations;
|
|
353
|
-
}
|
|
354
|
-
else if (t.isExportNamedDeclaration(node) &&
|
|
355
|
-
node.declaration &&
|
|
356
|
-
t.isVariableDeclaration(node.declaration)) {
|
|
357
|
-
declarations = node.declaration.declarations;
|
|
358
|
-
}
|
|
359
|
-
for (const decl of declarations) {
|
|
360
|
-
if (t.isVariableDeclarator(decl) &&
|
|
361
|
-
t.isIdentifier(decl.id) &&
|
|
362
|
-
t.isCallExpression(decl.init) &&
|
|
363
|
-
t.isMemberExpression(decl.init.callee) &&
|
|
364
|
-
t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
|
|
365
|
-
t.isIdentifier(decl.init.callee.property, {
|
|
366
|
-
name: 'viewTransition',
|
|
367
|
-
}) &&
|
|
368
|
-
t.isObjectExpression(decl.init.arguments[0])) {
|
|
369
|
-
const varName = decl.id.name;
|
|
370
|
-
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable, viewTransitionHashTableLocal, tokensTable);
|
|
371
|
-
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
372
|
-
viewTransitionHashTableLocal[varName] = hash;
|
|
373
|
-
viewTransitionObjectTableLocal[hash] = obj;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
return {
|
|
379
|
-
viewTransitionHashTableLocal,
|
|
380
|
-
viewTransitionObjectTableLocal,
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
function scanForDefineConsts() {
|
|
384
|
-
const constTableLocal = {};
|
|
385
|
-
const files = fs_1.default.globSync(PATTERN_PATH, GLOB_OPTIONS);
|
|
386
|
-
for (const filePath of files) {
|
|
387
|
-
if (!isCSSDefineFile(filePath, 'defineConsts'))
|
|
388
|
-
continue;
|
|
389
|
-
this.addDependency(filePath);
|
|
390
|
-
const source = fs_1.default.readFileSync(filePath, 'utf8');
|
|
391
|
-
const ast = (0, core_1.parseSync)(source, {
|
|
392
|
-
sourceType: 'module',
|
|
393
|
-
presets: [
|
|
394
|
-
['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
|
|
395
|
-
],
|
|
396
|
-
});
|
|
397
|
-
for (const node of ast?.program.body) {
|
|
398
|
-
let declarations = [];
|
|
399
|
-
if (t.isVariableDeclaration(node)) {
|
|
400
|
-
declarations = node.declarations;
|
|
401
|
-
}
|
|
402
|
-
else if (t.isExportNamedDeclaration(node) &&
|
|
403
|
-
node.declaration &&
|
|
404
|
-
t.isVariableDeclaration(node.declaration)) {
|
|
405
|
-
declarations = node.declaration.declarations;
|
|
406
|
-
}
|
|
407
|
-
for (const decl of declarations) {
|
|
408
|
-
if (t.isVariableDeclarator(decl) &&
|
|
409
|
-
t.isIdentifier(decl.id) &&
|
|
410
|
-
t.isCallExpression(decl.init) &&
|
|
411
|
-
t.isMemberExpression(decl.init.callee) &&
|
|
412
|
-
t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
|
|
413
|
-
t.isIdentifier(decl.init.callee.property, { name: 'defineConsts' }) &&
|
|
414
|
-
t.isObjectExpression(decl.init.arguments[0])) {
|
|
415
|
-
const varName = decl.id.name;
|
|
416
|
-
const obj = objectExpressionToObject(decl.init.arguments[0], constTableLocal, keyframesHashTable, viewTransitionHashTable, tokensTable);
|
|
417
|
-
constTableLocal[varName] = obj;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
return constTableLocal;
|
|
423
|
-
}
|
|
424
|
-
function scanForDefineTokens() {
|
|
425
|
-
const tokensTableLocal = {};
|
|
426
|
-
const defineTokensObjectTableLocal = {};
|
|
427
|
-
const files = fs_1.default.globSync(PATTERN_PATH, GLOB_OPTIONS);
|
|
428
|
-
for (const filePath of files) {
|
|
429
|
-
if (!isCSSDefineFile(filePath, 'defineTokens'))
|
|
430
|
-
continue;
|
|
431
|
-
this.addDependency(filePath);
|
|
432
|
-
const source = fs_1.default.readFileSync(filePath, 'utf8');
|
|
433
|
-
const ast = (0, core_1.parseSync)(source, {
|
|
434
|
-
sourceType: 'module',
|
|
435
|
-
presets: [
|
|
436
|
-
['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
|
|
437
|
-
],
|
|
438
|
-
});
|
|
439
|
-
for (const node of ast?.program.body) {
|
|
440
|
-
let declarations = [];
|
|
441
|
-
if (t.isVariableDeclaration(node)) {
|
|
442
|
-
declarations = node.declarations;
|
|
443
|
-
}
|
|
444
|
-
else if (t.isExportNamedDeclaration(node) &&
|
|
445
|
-
node.declaration &&
|
|
446
|
-
t.isVariableDeclaration(node.declaration)) {
|
|
447
|
-
declarations = node.declaration.declarations;
|
|
448
|
-
}
|
|
449
|
-
for (const decl of declarations) {
|
|
450
|
-
if (t.isVariableDeclarator(decl) &&
|
|
451
|
-
t.isIdentifier(decl.id) &&
|
|
452
|
-
t.isCallExpression(decl.init) &&
|
|
453
|
-
t.isMemberExpression(decl.init.callee) &&
|
|
454
|
-
t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
|
|
455
|
-
t.isIdentifier(decl.init.callee.property, { name: 'defineTokens' }) &&
|
|
456
|
-
t.isObjectExpression(decl.init.arguments[0])) {
|
|
457
|
-
const varName = decl.id.name;
|
|
458
|
-
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable, viewTransitionHashTable, tokensTableLocal);
|
|
459
|
-
tokensTableLocal[varName] = obj;
|
|
460
|
-
defineTokensObjectTableLocal[varName] = obj;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
return { tokensTableLocal, defineTokensObjectTableLocal };
|
|
466
|
-
}
|
|
467
|
-
function isCSSDefineFile(filePath, target) {
|
|
468
|
-
if (fs_1.default.statSync(filePath).isDirectory())
|
|
469
|
-
return false;
|
|
470
|
-
const code = fs_1.default.readFileSync(filePath, 'utf8');
|
|
471
|
-
let ast;
|
|
472
|
-
try {
|
|
473
|
-
ast = (0, core_1.parseSync)(code, {
|
|
474
|
-
sourceType: 'module',
|
|
475
|
-
presets: [
|
|
476
|
-
['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
|
|
477
|
-
],
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
catch (err) {
|
|
481
|
-
console.log(err);
|
|
482
|
-
return false;
|
|
483
|
-
}
|
|
484
|
-
let found = false;
|
|
485
|
-
(0, core_1.traverse)(ast, {
|
|
486
|
-
CallExpression(path) {
|
|
487
|
-
const callee = path.node.callee;
|
|
488
|
-
if (callee.type === 'MemberExpression' &&
|
|
489
|
-
callee.object.type === 'Identifier' &&
|
|
490
|
-
callee.object.name === 'css' &&
|
|
491
|
-
callee.property.type === 'Identifier' &&
|
|
492
|
-
callee.property.name === target) {
|
|
493
|
-
found = true;
|
|
494
|
-
path.stop();
|
|
495
|
-
}
|
|
496
|
-
},
|
|
497
|
-
});
|
|
498
|
-
return found;
|
|
499
|
-
}
|
|
11
|
+
const utils_1 = require("@plumeria/utils");
|
|
500
12
|
function loader(source) {
|
|
501
13
|
const callback = this.async();
|
|
502
|
-
const useClientDirective = /^\s*['"]use client['"]/;
|
|
503
|
-
if (useClientDirective.test(source)) {
|
|
504
|
-
callback(null, source);
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
14
|
this.clearDependencies();
|
|
508
15
|
this.addDependency(this.resourcePath);
|
|
509
|
-
constTable = scanForDefineConsts.
|
|
510
|
-
const { keyframesHashTableLocal, keyframesObjectTableLocal } = scanForKeyframes.
|
|
511
|
-
keyframesHashTable = keyframesHashTableLocal;
|
|
512
|
-
keyframesObjectTable = keyframesObjectTableLocal;
|
|
513
|
-
const { viewTransitionHashTableLocal, viewTransitionObjectTableLocal } = scanForViewTransition.
|
|
514
|
-
viewTransitionHashTable = viewTransitionHashTableLocal;
|
|
515
|
-
viewTransitionObjectTable = viewTransitionObjectTableLocal;
|
|
516
|
-
const { tokensTableLocal, defineTokensObjectTableLocal } = scanForDefineTokens.
|
|
517
|
-
tokensTable = tokensTableLocal;
|
|
518
|
-
defineTokensObjectTable = defineTokensObjectTableLocal;
|
|
16
|
+
utils_1.tables.constTable = (0, utils_1.scanForDefineConsts)((path) => this.addDependency(path));
|
|
17
|
+
const { keyframesHashTableLocal, keyframesObjectTableLocal } = (0, utils_1.scanForKeyframes)((path) => this.addDependency(path));
|
|
18
|
+
utils_1.tables.keyframesHashTable = keyframesHashTableLocal;
|
|
19
|
+
utils_1.tables.keyframesObjectTable = keyframesObjectTableLocal;
|
|
20
|
+
const { viewTransitionHashTableLocal, viewTransitionObjectTableLocal } = (0, utils_1.scanForViewTransition)((path) => this.addDependency(path));
|
|
21
|
+
utils_1.tables.viewTransitionHashTable = viewTransitionHashTableLocal;
|
|
22
|
+
utils_1.tables.viewTransitionObjectTable = viewTransitionObjectTableLocal;
|
|
23
|
+
const { tokensTableLocal, defineTokensObjectTableLocal } = (0, utils_1.scanForDefineTokens)((path) => this.addDependency(path));
|
|
24
|
+
utils_1.tables.tokensTable = tokensTableLocal;
|
|
25
|
+
utils_1.tables.defineTokensObjectTable = defineTokensObjectTableLocal;
|
|
519
26
|
const extractedObjects = [];
|
|
520
27
|
let ast;
|
|
521
28
|
try {
|
|
522
29
|
ast = (0, core_1.parseSync)(source, {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
],
|
|
30
|
+
syntax: 'typescript',
|
|
31
|
+
tsx: true,
|
|
32
|
+
target: 'es2022',
|
|
527
33
|
});
|
|
528
34
|
}
|
|
529
35
|
catch (err) {
|
|
@@ -531,49 +37,44 @@ function loader(source) {
|
|
|
531
37
|
callback(null, source);
|
|
532
38
|
return;
|
|
533
39
|
}
|
|
534
|
-
const localConsts = collectLocalConsts(ast);
|
|
535
|
-
Object.assign(constTable, localConsts);
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
40
|
+
const localConsts = (0, utils_1.collectLocalConsts)(ast);
|
|
41
|
+
Object.assign(utils_1.tables.constTable, localConsts);
|
|
42
|
+
let hasCssCreate = false;
|
|
43
|
+
(0, utils_1.traverse)(ast, {
|
|
44
|
+
CallExpression({ node }) {
|
|
45
|
+
const callee = node.callee;
|
|
46
|
+
if (utils_1.t.isMemberExpression(callee) &&
|
|
47
|
+
utils_1.t.isIdentifier(callee.object, { name: 'css' }) &&
|
|
48
|
+
utils_1.t.isIdentifier(callee.property)) {
|
|
49
|
+
const args = node.arguments;
|
|
50
|
+
if (callee.property.value === 'create' &&
|
|
51
|
+
args.length === 1 &&
|
|
52
|
+
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
53
|
+
hasCssCreate = true;
|
|
54
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, utils_1.tables.constTable, utils_1.tables.keyframesHashTable, utils_1.tables.viewTransitionHashTable, utils_1.tables.tokensTable);
|
|
55
|
+
if (obj) {
|
|
56
|
+
extractedObjects.push(obj);
|
|
551
57
|
}
|
|
552
58
|
}
|
|
553
|
-
}
|
|
59
|
+
}
|
|
554
60
|
},
|
|
555
|
-
};
|
|
556
|
-
(0, core_1.transformFromAstSync)(ast, source, {
|
|
557
|
-
code: false,
|
|
558
|
-
plugins: [pluginAst],
|
|
559
|
-
configFile: false,
|
|
560
61
|
});
|
|
561
62
|
const fileStyles = {};
|
|
562
63
|
if (extractedObjects.length > 0) {
|
|
563
64
|
const combinedStyles = extractedObjects.reduce((acc, obj) => Object.assign(acc, obj), {});
|
|
564
|
-
const base = (0,
|
|
65
|
+
const base = (0, utils_1.createCSS)(combinedStyles);
|
|
565
66
|
if (base) {
|
|
566
67
|
fileStyles.baseStyles = base;
|
|
567
68
|
}
|
|
568
69
|
}
|
|
569
|
-
if (Object.keys(keyframesObjectTable).length > 0) {
|
|
570
|
-
fileStyles.keyframeStyles = Object.entries(keyframesObjectTable)
|
|
70
|
+
if (Object.keys(utils_1.tables.keyframesObjectTable).length > 0) {
|
|
71
|
+
fileStyles.keyframeStyles = Object.entries(utils_1.tables.keyframesObjectTable)
|
|
571
72
|
.map(([hash, obj]) => (0, zss_engine_1.transpile)({ [`@keyframes kf-${hash}`]: obj }, undefined, '--global')
|
|
572
73
|
.styleSheet)
|
|
573
74
|
.join('\n');
|
|
574
75
|
}
|
|
575
|
-
if (Object.keys(viewTransitionObjectTable).length > 0) {
|
|
576
|
-
fileStyles.viewTransitionStyles = Object.entries(viewTransitionObjectTable)
|
|
76
|
+
if (Object.keys(utils_1.tables.viewTransitionObjectTable).length > 0) {
|
|
77
|
+
fileStyles.viewTransitionStyles = Object.entries(utils_1.tables.viewTransitionObjectTable)
|
|
577
78
|
.map(([hash, obj]) => (0, zss_engine_1.transpile)({
|
|
578
79
|
[`::view-transition-group(vt-${hash})`]: obj.group,
|
|
579
80
|
[`::view-transition-image-pair(vt-${hash})`]: obj.imagePair,
|
|
@@ -582,9 +83,9 @@ function loader(source) {
|
|
|
582
83
|
}, undefined, '--global').styleSheet)
|
|
583
84
|
.join('\n');
|
|
584
85
|
}
|
|
585
|
-
if (Object.keys(defineTokensObjectTable).length > 0) {
|
|
586
|
-
fileStyles.tokenStyles = Object.values(defineTokensObjectTable)
|
|
587
|
-
.map((obj) => (0, zss_engine_1.transpile)((0,
|
|
86
|
+
if (Object.keys(utils_1.tables.defineTokensObjectTable).length > 0) {
|
|
87
|
+
fileStyles.tokenStyles = Object.values(utils_1.tables.defineTokensObjectTable)
|
|
88
|
+
.map((obj) => (0, zss_engine_1.transpile)((0, utils_1.createTokens)(obj), undefined, '--global')
|
|
588
89
|
.styleSheet)
|
|
589
90
|
.join('\n');
|
|
590
91
|
}
|
|
@@ -618,5 +119,69 @@ function loader(source) {
|
|
|
618
119
|
pluginInstance.registerFileStyles(fileKey, fileStyles);
|
|
619
120
|
}
|
|
620
121
|
}
|
|
621
|
-
|
|
122
|
+
let css = '';
|
|
123
|
+
css = fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../zero-virtual.css'), 'utf-8');
|
|
124
|
+
function generateOrderedCSS(styles) {
|
|
125
|
+
const sections = [];
|
|
126
|
+
if (styles.keyframeStyles?.trim()) {
|
|
127
|
+
if (!css.includes(styles.keyframeStyles))
|
|
128
|
+
sections.push(styles.keyframeStyles);
|
|
129
|
+
}
|
|
130
|
+
if (styles.viewTransitionStyles?.trim()) {
|
|
131
|
+
if (!css.includes(styles.viewTransitionStyles))
|
|
132
|
+
sections.push(styles.viewTransitionStyles);
|
|
133
|
+
}
|
|
134
|
+
if (styles.tokenStyles?.trim()) {
|
|
135
|
+
if (!css.includes(styles.tokenStyles))
|
|
136
|
+
sections.push(styles.tokenStyles);
|
|
137
|
+
}
|
|
138
|
+
if (styles.baseStyles?.trim()) {
|
|
139
|
+
sections.push(styles.baseStyles);
|
|
140
|
+
}
|
|
141
|
+
return sections.join('\n');
|
|
142
|
+
}
|
|
143
|
+
const orderedCSS = generateOrderedCSS(fileStyles);
|
|
144
|
+
const relativeId = path_1.default.relative(process.cwd(), this.resourcePath);
|
|
145
|
+
const hmrCode = `
|
|
146
|
+
if (module.hot) {
|
|
147
|
+
module.hot.accept(${virtualCssRequest});
|
|
148
|
+
|
|
149
|
+
const styleId = "plumeria-hmr";
|
|
150
|
+
const fileKey = ${JSON.stringify(relativeId)};
|
|
151
|
+
|
|
152
|
+
let styleEl = document.getElementById(styleId);
|
|
153
|
+
|
|
154
|
+
if (!styleEl) {
|
|
155
|
+
styleEl = document.createElement("style");
|
|
156
|
+
styleEl.id = styleId;
|
|
157
|
+
styleEl.setAttribute("data-plumeria-hmr", "");
|
|
158
|
+
document.head.prepend(styleEl);
|
|
159
|
+
styleEl.__plumeriaStyles = {};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
styleEl.__plumeriaStyles[fileKey] = ${JSON.stringify(orderedCSS)};
|
|
163
|
+
styleEl.textContent = Object.values(styleEl.__plumeriaStyles).join('\\n');
|
|
164
|
+
|
|
165
|
+
module.hot.dispose(() => {
|
|
166
|
+
if (styleEl && styleEl.__plumeriaStyles) {
|
|
167
|
+
delete styleEl.__plumeriaStyles[fileKey];
|
|
168
|
+
styleEl.textContent = Object.values(styleEl.__plumeriaStyles).join('\\n');
|
|
169
|
+
|
|
170
|
+
if (Object.keys(styleEl.__plumeriaStyles).length === 0 && styleEl.parentNode) {
|
|
171
|
+
styleEl.parentNode.removeChild(styleEl);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
`;
|
|
177
|
+
if (hasCssCreate) {
|
|
178
|
+
callback(null, source + hmrCode);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const useClientDirective = /^\s*['"]use client['"]/;
|
|
182
|
+
if (!useClientDirective.test(source)) {
|
|
183
|
+
callback(null, source + postfix);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
callback(null, source);
|
|
622
187
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/webpack-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Plumeria Webpack plugin",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,14 +16,12 @@
|
|
|
16
16
|
"zero-virtual.css"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@
|
|
20
|
-
"@babel/preset-typescript": "^7.27.1",
|
|
21
|
-
"@babel/types": "^7.28.2"
|
|
19
|
+
"@plumeria/utils": "^1.0.0"
|
|
22
20
|
},
|
|
23
21
|
"devDependencies": {
|
|
24
|
-
"@
|
|
25
|
-
"webpack": "
|
|
26
|
-
"zss-engine": "
|
|
22
|
+
"@swc/core": "1.15.2",
|
|
23
|
+
"webpack": "5.101.0",
|
|
24
|
+
"zss-engine": "1.0.0"
|
|
27
25
|
},
|
|
28
26
|
"publishConfig": {
|
|
29
27
|
"access": "public",
|
package/dist/create.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { CSSProperties, CreateStyleType, CreateTokens, CreateValues } from 'zss-engine';
|
|
2
|
-
declare function createCSS<T extends Record<string, CSSProperties>>(object: CreateStyleType<T>): string;
|
|
3
|
-
declare const createVars: <const T extends CreateValues>(object: T) => Record<string, CreateValues>;
|
|
4
|
-
declare const createTokens: <const T extends CreateTokens>(object: T) => Record<string, Record<string, string | number | object>>;
|
|
5
|
-
export { createCSS, createVars, createTokens };
|
package/dist/create.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTokens = exports.createVars = void 0;
|
|
4
|
-
exports.createCSS = createCSS;
|
|
5
|
-
const zss_engine_1 = require("zss-engine");
|
|
6
|
-
function compileToSingleCSS(object) {
|
|
7
|
-
const baseSheets = [];
|
|
8
|
-
const querySheets = [];
|
|
9
|
-
const processedHashes = new Set();
|
|
10
|
-
Object.entries(object).forEach(([key, styleObj]) => {
|
|
11
|
-
const flat = {};
|
|
12
|
-
const nonFlat = {};
|
|
13
|
-
(0, zss_engine_1.splitAtomicAndNested)(styleObj, flat, nonFlat);
|
|
14
|
-
const finalFlat = (0, zss_engine_1.overrideLonghand)(flat);
|
|
15
|
-
const records = [];
|
|
16
|
-
Object.entries(finalFlat).forEach(([prop, value]) => {
|
|
17
|
-
const hashes = new Set();
|
|
18
|
-
const sheets = new Set();
|
|
19
|
-
(0, zss_engine_1.processAtomicProps)({ [prop]: value }, hashes, sheets);
|
|
20
|
-
const hashArray = [...hashes];
|
|
21
|
-
const sheetArray = [...sheets];
|
|
22
|
-
const baseSheetParts = [];
|
|
23
|
-
const baseHashParts = [];
|
|
24
|
-
const querySheetParts = [];
|
|
25
|
-
const queryHashParts = [];
|
|
26
|
-
for (let i = 0; i < sheetArray.length; i++) {
|
|
27
|
-
const sheet = sheetArray[i];
|
|
28
|
-
const hash = hashArray[i];
|
|
29
|
-
if (sheet.includes('@media') || sheet.includes('@container')) {
|
|
30
|
-
querySheetParts.push(sheet);
|
|
31
|
-
queryHashParts.push(hash);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
baseSheetParts.push(sheet);
|
|
35
|
-
baseHashParts.push(hash);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (baseSheetParts.length > 0) {
|
|
39
|
-
records.push({
|
|
40
|
-
key: prop,
|
|
41
|
-
hash: baseHashParts.join(' '),
|
|
42
|
-
sheet: baseSheetParts.join(''),
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
if (querySheetParts.length > 0) {
|
|
46
|
-
records.push({
|
|
47
|
-
key: prop + '__queries__',
|
|
48
|
-
hash: queryHashParts.join(' '),
|
|
49
|
-
sheet: querySheetParts.join(''),
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
if (Object.keys(nonFlat).length > 0) {
|
|
54
|
-
const modNonFlat = (0, zss_engine_1.transformNestedSelectors)(nonFlat);
|
|
55
|
-
const nonFlatObj = { [key]: modNonFlat };
|
|
56
|
-
const nonFlatHash = (0, zss_engine_1.genBase36Hash)(nonFlatObj, 1, 7);
|
|
57
|
-
const { styleSheet } = (0, zss_engine_1.transpile)(nonFlatObj, nonFlatHash);
|
|
58
|
-
Object.entries(nonFlat).forEach(([atRule, nestedObj]) => {
|
|
59
|
-
Object.keys(nestedObj).forEach((prop) => {
|
|
60
|
-
records.push({
|
|
61
|
-
key: atRule + prop,
|
|
62
|
-
hash: nonFlatHash,
|
|
63
|
-
sheet: styleSheet,
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
records.forEach(({ hash, sheet }) => {
|
|
69
|
-
if (!processedHashes.has(hash)) {
|
|
70
|
-
processedHashes.add(hash);
|
|
71
|
-
if (sheet.includes('@media') || sheet.includes('@container')) {
|
|
72
|
-
querySheets.push(sheet);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
baseSheets.push(sheet);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
const baseLayer = baseSheets.length > 0 ? `@layer base {\n${baseSheets.join('')}}` : '';
|
|
81
|
-
return [baseLayer, ...querySheets].filter(Boolean).join('\n');
|
|
82
|
-
}
|
|
83
|
-
function createCSS(object) {
|
|
84
|
-
const compiledCSS = compileToSingleCSS(object);
|
|
85
|
-
return compiledCSS;
|
|
86
|
-
}
|
|
87
|
-
const createVars = (object) => {
|
|
88
|
-
const styles = {
|
|
89
|
-
':root': {},
|
|
90
|
-
};
|
|
91
|
-
Object.entries(object).forEach(([key, value]) => {
|
|
92
|
-
styles[':root'][`--${key}`] = value;
|
|
93
|
-
});
|
|
94
|
-
styles;
|
|
95
|
-
return styles;
|
|
96
|
-
};
|
|
97
|
-
exports.createVars = createVars;
|
|
98
|
-
const createTokens = (object) => {
|
|
99
|
-
const styles = {};
|
|
100
|
-
Object.entries(object).forEach(([key, value]) => {
|
|
101
|
-
const kebabKey = (0, zss_engine_1.camelToKebabCase)(key);
|
|
102
|
-
Object.entries(value).forEach(([subKey, subValue]) => {
|
|
103
|
-
if (subKey.startsWith('@media')) {
|
|
104
|
-
styles[':root'] ||= {};
|
|
105
|
-
styles[':root'][subKey] ||= {};
|
|
106
|
-
styles[':root'][subKey][`--${kebabKey}`] = subValue;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
const themeSelector = subKey === 'default' ? ':root' : `:root[data-theme="${subKey}"]`;
|
|
110
|
-
styles[themeSelector] ||= {};
|
|
111
|
-
styles[themeSelector][`--${kebabKey}`] = subValue;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
return styles;
|
|
116
|
-
};
|
|
117
|
-
exports.createTokens = createTokens;
|
package/dist/types.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
type CSSPrimitive = string | number | boolean | null;
|
|
2
|
-
type ParseErrorString = `[unresolved]` | `[unresolved identifier]` | `[unsupported value type]` | `[unresolved: ${string}]` | `[unresolved member expression]`;
|
|
3
|
-
export type CSSValue = CSSPrimitive | CSSObject | ParseErrorString;
|
|
4
|
-
export type CSSObject = {
|
|
5
|
-
[key: string]: CSSValue;
|
|
6
|
-
};
|
|
7
|
-
export type ConstTable = Record<string, CSSObject | string>;
|
|
8
|
-
export type VariableTable = Record<string, CSSObject>;
|
|
9
|
-
export type TokensTable = Record<string, CSSObject>;
|
|
10
|
-
export type KeyframesHashTable = Record<string, string>;
|
|
11
|
-
export type KeyframesObjectTable = Record<string, CSSObject>;
|
|
12
|
-
export type ViewTransitionHashTable = Record<string, string>;
|
|
13
|
-
export type ViewTransitionObjectTable = Record<string, CSSObject>;
|
|
14
|
-
export type DefineTokensObjectTable = Record<string, CSSObject>;
|
|
15
|
-
export {};
|
package/dist/types.js
DELETED