@plumeria/utils 6.2.0 → 6.3.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 +2 -1
- package/dist/index.js +3 -1
- package/dist/parser.d.ts +3 -4
- package/dist/parser.js +393 -291
- package/dist/resolver.js +2 -2
- package/dist/types.d.ts +6 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export type { CSSObject, FileStyles, StaticTable,
|
|
1
|
+
export type { CSSObject, FileStyles, StaticTable, KeyframesHashTable, KeyframesObjectTable, ViewTransitionHashTable, ViewTransitionObjectTable, CreateThemeObjectTable, CreateHashTable, CreateObjectTable, VariantsHashTable, VariantsObjectTable, CreateThemeHashTable, CreateStaticHashTable, CreateStaticObjectTable, } from './types';
|
|
2
2
|
export { objectExpressionToObject, collectLocalConsts, traverse, t, extractOndemandStyles, deepMerge, scanAll, } from './parser';
|
|
3
3
|
export { getStyleRecords } from './create';
|
|
4
|
+
export { createTheme } from './createTheme';
|
|
4
5
|
export type { StyleRecord } from './create';
|
|
5
6
|
export { resolveImportPath } from './resolver';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveImportPath = exports.getStyleRecords = exports.scanAll = exports.deepMerge = exports.extractOndemandStyles = exports.t = exports.traverse = exports.collectLocalConsts = exports.objectExpressionToObject = void 0;
|
|
3
|
+
exports.resolveImportPath = exports.createTheme = exports.getStyleRecords = exports.scanAll = exports.deepMerge = exports.extractOndemandStyles = exports.t = exports.traverse = exports.collectLocalConsts = exports.objectExpressionToObject = void 0;
|
|
4
4
|
var parser_1 = require("./parser");
|
|
5
5
|
Object.defineProperty(exports, "objectExpressionToObject", { enumerable: true, get: function () { return parser_1.objectExpressionToObject; } });
|
|
6
6
|
Object.defineProperty(exports, "collectLocalConsts", { enumerable: true, get: function () { return parser_1.collectLocalConsts; } });
|
|
@@ -11,5 +11,7 @@ Object.defineProperty(exports, "deepMerge", { enumerable: true, get: function ()
|
|
|
11
11
|
Object.defineProperty(exports, "scanAll", { enumerable: true, get: function () { return parser_1.scanAll; } });
|
|
12
12
|
var create_1 = require("./create");
|
|
13
13
|
Object.defineProperty(exports, "getStyleRecords", { enumerable: true, get: function () { return create_1.getStyleRecords; } });
|
|
14
|
+
var createTheme_1 = require("./createTheme");
|
|
15
|
+
Object.defineProperty(exports, "createTheme", { enumerable: true, get: function () { return createTheme_1.createTheme; } });
|
|
14
16
|
var resolver_1 = require("./resolver");
|
|
15
17
|
Object.defineProperty(exports, "resolveImportPath", { enumerable: true, get: function () { return resolver_1.resolveImportPath; } });
|
package/dist/parser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CSSObject,
|
|
1
|
+
import type { CSSObject, Tables, StaticTable, KeyframesHashTable, ViewTransitionHashTable, CreateThemeObjectTable, CreateHashTable, VariantsHashTable, CreateThemeHashTable, CreateStaticHashTable, CreateStaticObjectTable } from './types';
|
|
2
2
|
import { Module, CallExpression, Identifier, KeyValueProperty, StringLiteral, NumericLiteral, BooleanLiteral, ObjectExpression, MemberExpression, TemplateLiteral, BinaryExpression, UnaryExpression, VariableDeclaration, VariableDeclarator, ExportDeclaration, ConditionalExpression } from '@swc/core';
|
|
3
3
|
export declare const t: {
|
|
4
4
|
isObjectExpression: (node: any) => node is ObjectExpression;
|
|
@@ -26,9 +26,8 @@ export declare function traverse(node: Module, visitor: {
|
|
|
26
26
|
stop: () => void;
|
|
27
27
|
}) => void;
|
|
28
28
|
}): void;
|
|
29
|
-
export declare
|
|
30
|
-
export declare function objectExpressionToObject(node: ObjectExpression, staticTable: StaticTable, keyframesHashTable: KeyframesHashTable, viewTransitionHashTable: ViewTransitionHashTable, themeTable: ThemeTable, createHashTable: CreateHashTable, variantsHashTable: VariantsHashTable, resolveVariable?: (name: string) => any): CSSObject;
|
|
29
|
+
export declare function objectExpressionToObject(node: ObjectExpression, staticTable: StaticTable, keyframesHashTable: KeyframesHashTable, viewTransitionHashTable: ViewTransitionHashTable, createThemeHashTable: CreateThemeHashTable, createThemeObjectTable: CreateThemeObjectTable, createHashTable: CreateHashTable, createStaticHashTable: CreateStaticHashTable, createStaticObjectTable: CreateStaticObjectTable, variantsHashTable: VariantsHashTable, resolveVariable?: (name: string) => any): CSSObject;
|
|
31
30
|
export declare function collectLocalConsts(ast: Module): Record<string, any>;
|
|
32
31
|
export declare function scanAll(): Tables;
|
|
33
|
-
export declare function extractOndemandStyles(obj: any, extractedSheets: string[], t
|
|
32
|
+
export declare function extractOndemandStyles(obj: any, extractedSheets: string[], t: Tables): void;
|
|
34
33
|
export declare function deepMerge(target: Record<string, any>, source: Record<string, any>): Record<string, any>;
|
package/dist/parser.js
CHANGED
|
@@ -3,7 +3,7 @@ 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
|
-
exports.
|
|
6
|
+
exports.t = void 0;
|
|
7
7
|
exports.traverse = traverse;
|
|
8
8
|
exports.objectExpressionToObject = objectExpressionToObject;
|
|
9
9
|
exports.collectLocalConsts = collectLocalConsts;
|
|
@@ -17,6 +17,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
17
17
|
const zss_engine_1 = require("zss-engine");
|
|
18
18
|
const viewTransition_1 = require("./viewTransition");
|
|
19
19
|
const create_1 = require("./create");
|
|
20
|
+
const resolver_1 = require("./resolver");
|
|
20
21
|
exports.t = {
|
|
21
22
|
isObjectExpression: (node) => node?.type === 'ObjectExpression',
|
|
22
23
|
isObjectProperty: (node) => node?.type === 'KeyValueProperty',
|
|
@@ -76,26 +77,12 @@ const GLOB_OPTIONS = {
|
|
|
76
77
|
exclude: ['**/node_modules/**', '**/dist/**', '**/build/**', '**/.next/**'],
|
|
77
78
|
cwd: PROJECT_ROOT,
|
|
78
79
|
};
|
|
79
|
-
|
|
80
|
-
staticTable: {},
|
|
81
|
-
themeTable: {},
|
|
82
|
-
keyframesHashTable: {},
|
|
83
|
-
keyframesObjectTable: {},
|
|
84
|
-
viewTransitionHashTable: {},
|
|
85
|
-
viewTransitionObjectTable: {},
|
|
86
|
-
createThemeObjectTable: {},
|
|
87
|
-
createHashTable: {},
|
|
88
|
-
createObjectTable: {},
|
|
89
|
-
createAtomicMapTable: {},
|
|
90
|
-
variantsHashTable: {},
|
|
91
|
-
variantsObjectTable: {},
|
|
92
|
-
};
|
|
93
|
-
function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTransitionHashTable, themeTable, createHashTable, variantsHashTable, resolveVariable) {
|
|
80
|
+
function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createHashTable, createStaticHashTable, createStaticObjectTable, variantsHashTable, resolveVariable) {
|
|
94
81
|
const obj = {};
|
|
95
82
|
node.properties.forEach((prop) => {
|
|
96
83
|
if (!exports.t.isObjectProperty(prop))
|
|
97
84
|
return;
|
|
98
|
-
const key = getPropertyKey(prop.key, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
85
|
+
const key = getPropertyKey(prop.key, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
99
86
|
if (!key)
|
|
100
87
|
return;
|
|
101
88
|
const val = prop.value;
|
|
@@ -125,11 +112,16 @@ function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTra
|
|
|
125
112
|
obj[key] = 'cr-' + resolvedCreate;
|
|
126
113
|
return;
|
|
127
114
|
}
|
|
128
|
-
const resolvedTheme =
|
|
115
|
+
const resolvedTheme = resolveCreateThemeTableMemberExpressionByNode(val, createThemeHashTable, createThemeObjectTable);
|
|
129
116
|
if (resolvedTheme !== undefined) {
|
|
130
117
|
obj[key] = resolvedTheme;
|
|
131
118
|
return;
|
|
132
119
|
}
|
|
120
|
+
const resolvedStatic = resolveCreateStaticTableMemberExpression(val, createStaticHashTable, createStaticObjectTable);
|
|
121
|
+
if (resolvedStatic !== undefined) {
|
|
122
|
+
obj[key] = resolvedStatic;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
133
125
|
const resolvedVariants = resolveVariantsTableMemberExpression(val, variantsHashTable);
|
|
134
126
|
if (resolvedVariants !== undefined) {
|
|
135
127
|
obj[key] = 'vr-' + resolvedVariants;
|
|
@@ -145,7 +137,7 @@ function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTra
|
|
|
145
137
|
obj[key] = evaluateUnaryExpression(val);
|
|
146
138
|
}
|
|
147
139
|
else if (exports.t.isObjectExpression(val)) {
|
|
148
|
-
obj[key] = objectExpressionToObject(val, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
140
|
+
obj[key] = objectExpressionToObject(val, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createHashTable, createStaticHashTable, createStaticObjectTable, variantsHashTable, resolveVariable);
|
|
149
141
|
}
|
|
150
142
|
else if (exports.t.isMemberExpression(val)) {
|
|
151
143
|
const resolved = resolveStaticTableMemberExpression(val, staticTable);
|
|
@@ -197,7 +189,7 @@ function collectLocalConsts(ast) {
|
|
|
197
189
|
result = init.value;
|
|
198
190
|
}
|
|
199
191
|
else if (exports.t.isObjectExpression(init)) {
|
|
200
|
-
result = objectExpressionToObject(init, localConsts,
|
|
192
|
+
result = objectExpressionToObject(init, localConsts, {}, {}, {}, {}, {}, {}, {}, {}, resolveValue);
|
|
201
193
|
}
|
|
202
194
|
visiting.delete(name);
|
|
203
195
|
if (result !== undefined) {
|
|
@@ -210,7 +202,7 @@ function collectLocalConsts(ast) {
|
|
|
210
202
|
}
|
|
211
203
|
return localConsts;
|
|
212
204
|
}
|
|
213
|
-
function getPropertyKey(node, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
205
|
+
function getPropertyKey(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable) {
|
|
214
206
|
if (exports.t.isIdentifier(node)) {
|
|
215
207
|
return node.value;
|
|
216
208
|
}
|
|
@@ -232,44 +224,50 @@ function getPropertyKey(node, staticTable, keyframesHashTable, viewTransitionHas
|
|
|
232
224
|
const result = resolveStaticTableMemberExpression(expr, staticTable);
|
|
233
225
|
if (typeof result === 'string')
|
|
234
226
|
return result;
|
|
227
|
+
const staticResult = resolveCreateStaticTableMemberExpression(expr, createStaticHashTable, createStaticObjectTable);
|
|
228
|
+
if (typeof staticResult === 'string')
|
|
229
|
+
return staticResult;
|
|
230
|
+
const themeResult = resolveCreateThemeTableMemberExpressionByNode(expr, createThemeHashTable, createThemeObjectTable);
|
|
231
|
+
if (typeof themeResult === 'string')
|
|
232
|
+
return themeResult;
|
|
235
233
|
}
|
|
236
234
|
if (exports.t.isTemplateLiteral(expr)) {
|
|
237
|
-
return evaluateTemplateLiteral(expr, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
235
|
+
return evaluateTemplateLiteral(expr, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
238
236
|
}
|
|
239
237
|
if (exports.t.isBinaryExpression(expr)) {
|
|
240
|
-
return evaluateBinaryExpression(expr, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
238
|
+
return evaluateBinaryExpression(expr, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
241
239
|
}
|
|
242
240
|
return '';
|
|
243
241
|
}
|
|
244
242
|
if (exports.t.isTemplateLiteral(node)) {
|
|
245
|
-
return evaluateTemplateLiteral(node, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
243
|
+
return evaluateTemplateLiteral(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
246
244
|
}
|
|
247
245
|
if (exports.t.isBinaryExpression(node)) {
|
|
248
|
-
return evaluateBinaryExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
246
|
+
return evaluateBinaryExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
249
247
|
}
|
|
250
248
|
return '';
|
|
251
249
|
}
|
|
252
|
-
function evaluateTemplateLiteral(node, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
250
|
+
function evaluateTemplateLiteral(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable) {
|
|
253
251
|
let result = '';
|
|
254
252
|
for (let i = 0; i < node.quasis.length; i++) {
|
|
255
253
|
result += node.quasis[i].cooked || node.quasis[i].raw;
|
|
256
254
|
if (i < node.expressions.length) {
|
|
257
255
|
const expr = node.expressions[i];
|
|
258
|
-
const evaluatedExpr = evaluateExpression(expr, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
256
|
+
const evaluatedExpr = evaluateExpression(expr, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
259
257
|
result += String(evaluatedExpr);
|
|
260
258
|
}
|
|
261
259
|
}
|
|
262
260
|
return result;
|
|
263
261
|
}
|
|
264
|
-
function evaluateBinaryExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
265
|
-
const left = evaluateExpression(node.left, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
266
|
-
const right = evaluateExpression(node.right, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
262
|
+
function evaluateBinaryExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable) {
|
|
263
|
+
const left = evaluateExpression(node.left, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
264
|
+
const right = evaluateExpression(node.right, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
267
265
|
if (node.operator === '+') {
|
|
268
266
|
return String(left) + String(right);
|
|
269
267
|
}
|
|
270
268
|
throw new Error(`Unsupported binary operator: ${node.operator}`);
|
|
271
269
|
}
|
|
272
|
-
function evaluateExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
270
|
+
function evaluateExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable) {
|
|
273
271
|
if (exports.t.isStringLiteral(node)) {
|
|
274
272
|
return node.value;
|
|
275
273
|
}
|
|
@@ -299,17 +297,21 @@ function evaluateExpression(node, staticTable, keyframesHashTable, viewTransitio
|
|
|
299
297
|
if (resolved !== undefined) {
|
|
300
298
|
return resolved;
|
|
301
299
|
}
|
|
302
|
-
const resolvedTheme =
|
|
300
|
+
const resolvedTheme = resolveCreateThemeTableMemberExpressionByNode(node, createThemeHashTable, createThemeObjectTable);
|
|
303
301
|
if (resolvedTheme !== undefined) {
|
|
304
302
|
return resolvedTheme;
|
|
305
303
|
}
|
|
304
|
+
const resolvedStatic = resolveCreateStaticTableMemberExpression(node, createStaticHashTable, createStaticObjectTable);
|
|
305
|
+
if (resolvedStatic !== undefined) {
|
|
306
|
+
return resolvedStatic;
|
|
307
|
+
}
|
|
306
308
|
return `[unresolved member expression]`;
|
|
307
309
|
}
|
|
308
310
|
if (exports.t.isBinaryExpression(node)) {
|
|
309
|
-
return evaluateBinaryExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
311
|
+
return evaluateBinaryExpression(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
310
312
|
}
|
|
311
313
|
if (exports.t.isTemplateLiteral(node)) {
|
|
312
|
-
return evaluateTemplateLiteral(node, staticTable, keyframesHashTable, viewTransitionHashTable,
|
|
314
|
+
return evaluateTemplateLiteral(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
|
|
313
315
|
}
|
|
314
316
|
if (exports.t.isUnaryExpression(node)) {
|
|
315
317
|
return evaluateUnaryExpression(node);
|
|
@@ -383,20 +385,49 @@ function resolveStaticTableMemberExpression(node, staticTable) {
|
|
|
383
385
|
}
|
|
384
386
|
return undefined;
|
|
385
387
|
}
|
|
386
|
-
function
|
|
388
|
+
function resolveCreateThemeTableMemberExpressionByNode(node, createThemeHashTable, createThemeObjectTable) {
|
|
387
389
|
if (exports.t.isMemberExpression(node) && exports.t.isIdentifier(node.object)) {
|
|
388
390
|
const varName = node.object.value;
|
|
389
|
-
|
|
390
|
-
if (
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
391
|
+
const hash = createThemeHashTable[varName];
|
|
392
|
+
if (hash) {
|
|
393
|
+
const themeObj = createThemeObjectTable[hash];
|
|
394
|
+
if (themeObj) {
|
|
395
|
+
let key;
|
|
396
|
+
if (exports.t.isIdentifier(node.property)) {
|
|
397
|
+
key = node.property.value;
|
|
398
|
+
}
|
|
399
|
+
else if (node.property.type === 'Computed' &&
|
|
400
|
+
exports.t.isStringLiteral(node.property.expression)) {
|
|
401
|
+
key = node.property.expression.value;
|
|
402
|
+
}
|
|
403
|
+
if (key && themeObj[key] !== undefined) {
|
|
404
|
+
const cssVarName = (0, zss_engine_1.camelToKebabCase)(key);
|
|
405
|
+
return `var(--${cssVarName})`;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
396
408
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
409
|
+
}
|
|
410
|
+
return undefined;
|
|
411
|
+
}
|
|
412
|
+
function resolveCreateStaticTableMemberExpression(node, createStaticHashTable, createStaticObjectTable) {
|
|
413
|
+
if (exports.t.isMemberExpression(node) && exports.t.isIdentifier(node.object)) {
|
|
414
|
+
const varName = node.object.value;
|
|
415
|
+
const hash = createStaticHashTable[varName];
|
|
416
|
+
if (hash) {
|
|
417
|
+
const staticObj = createStaticObjectTable[hash];
|
|
418
|
+
if (staticObj) {
|
|
419
|
+
let key;
|
|
420
|
+
if (exports.t.isIdentifier(node.property)) {
|
|
421
|
+
key = node.property.value;
|
|
422
|
+
}
|
|
423
|
+
else if (node.property.type === 'Computed' &&
|
|
424
|
+
exports.t.isStringLiteral(node.property.expression)) {
|
|
425
|
+
key = node.property.expression.value;
|
|
426
|
+
}
|
|
427
|
+
if (key && staticObj[key] !== undefined) {
|
|
428
|
+
return staticObj[key];
|
|
429
|
+
}
|
|
430
|
+
}
|
|
400
431
|
}
|
|
401
432
|
}
|
|
402
433
|
return undefined;
|
|
@@ -409,7 +440,6 @@ function scanAll() {
|
|
|
409
440
|
}
|
|
410
441
|
const localTables = {
|
|
411
442
|
staticTable: {},
|
|
412
|
-
themeTable: {},
|
|
413
443
|
keyframesHashTable: {},
|
|
414
444
|
keyframesObjectTable: {},
|
|
415
445
|
viewTransitionHashTable: {},
|
|
@@ -420,276 +450,349 @@ function scanAll() {
|
|
|
420
450
|
createAtomicMapTable: {},
|
|
421
451
|
variantsHashTable: {},
|
|
422
452
|
variantsObjectTable: {},
|
|
453
|
+
createThemeHashTable: {},
|
|
454
|
+
createStaticHashTable: {},
|
|
455
|
+
createStaticObjectTable: {},
|
|
423
456
|
extractedSheet: '',
|
|
424
457
|
};
|
|
425
458
|
const files = fs_1.default.globSync(PATTERN_PATH, GLOB_OPTIONS);
|
|
426
459
|
const totalExtractedSheets = [];
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
460
|
+
const currentScanThemeObjectTable = {};
|
|
461
|
+
for (let passNumber = 1; passNumber <= 2; passNumber++) {
|
|
462
|
+
const isFirstPass = passNumber === 1;
|
|
463
|
+
for (const filePath of files) {
|
|
464
|
+
try {
|
|
465
|
+
const stats = fs_1.default.statSync(filePath);
|
|
466
|
+
const cached = fileCache[filePath];
|
|
467
|
+
if (cached && cached.mtimeMs === stats.mtimeMs) {
|
|
468
|
+
if (cached.hasCssUsage) {
|
|
469
|
+
for (const key of Object.keys(cached.staticTable)) {
|
|
470
|
+
localTables.staticTable[`${filePath}-${key}`] =
|
|
471
|
+
cached.staticTable[key];
|
|
472
|
+
}
|
|
473
|
+
for (const key of Object.keys(cached.keyframesHashTable)) {
|
|
474
|
+
localTables.keyframesHashTable[`${filePath}-${key}`] =
|
|
475
|
+
cached.keyframesHashTable[key];
|
|
476
|
+
}
|
|
477
|
+
for (const key of Object.keys(cached.keyframesObjectTable)) {
|
|
478
|
+
localTables.keyframesObjectTable[key] =
|
|
479
|
+
cached.keyframesObjectTable[key];
|
|
480
|
+
}
|
|
481
|
+
for (const key of Object.keys(cached.viewTransitionHashTable)) {
|
|
482
|
+
localTables.viewTransitionHashTable[`${filePath}-${key}`] =
|
|
483
|
+
cached.viewTransitionHashTable[key];
|
|
484
|
+
}
|
|
485
|
+
for (const key of Object.keys(cached.viewTransitionObjectTable)) {
|
|
486
|
+
localTables.viewTransitionObjectTable[key] =
|
|
487
|
+
cached.viewTransitionObjectTable[key];
|
|
488
|
+
}
|
|
489
|
+
for (const key of Object.keys(cached.createThemeHashTable)) {
|
|
490
|
+
localTables.createThemeHashTable[`${filePath}-${key}`] =
|
|
491
|
+
cached.createThemeHashTable[key];
|
|
492
|
+
}
|
|
493
|
+
for (const key of Object.keys(cached.createThemeObjectTable)) {
|
|
494
|
+
localTables.createThemeObjectTable[key] =
|
|
495
|
+
cached.createThemeObjectTable[key];
|
|
496
|
+
currentScanThemeObjectTable[key] =
|
|
497
|
+
cached.createThemeObjectTable[key];
|
|
498
|
+
}
|
|
499
|
+
for (const key of Object.keys(cached.createStaticHashTable)) {
|
|
500
|
+
localTables.createStaticHashTable[`${filePath}-${key}`] =
|
|
501
|
+
cached.createStaticHashTable[key];
|
|
502
|
+
}
|
|
503
|
+
for (const key of Object.keys(cached.createStaticObjectTable)) {
|
|
504
|
+
localTables.createStaticObjectTable[key] =
|
|
505
|
+
cached.createStaticObjectTable[key];
|
|
506
|
+
}
|
|
507
|
+
for (const key of Object.keys(cached.createHashTable)) {
|
|
508
|
+
localTables.createHashTable[`${filePath}-${key}`] =
|
|
509
|
+
cached.createHashTable[key];
|
|
510
|
+
}
|
|
511
|
+
for (const key of Object.keys(cached.createObjectTable)) {
|
|
512
|
+
localTables.createObjectTable[key] =
|
|
513
|
+
cached.createObjectTable[key];
|
|
514
|
+
}
|
|
515
|
+
for (const key of Object.keys(cached.createAtomicMapTable)) {
|
|
516
|
+
localTables.createAtomicMapTable[key] =
|
|
517
|
+
cached.createAtomicMapTable[key];
|
|
518
|
+
}
|
|
519
|
+
for (const key of Object.keys(cached.variantsHashTable)) {
|
|
520
|
+
localTables.variantsHashTable[`${filePath}-${key}`] =
|
|
521
|
+
cached.variantsHashTable[key];
|
|
522
|
+
}
|
|
523
|
+
for (const key of Object.keys(cached.variantsObjectTable)) {
|
|
524
|
+
localTables.variantsObjectTable[key] =
|
|
525
|
+
cached.variantsObjectTable[key];
|
|
526
|
+
}
|
|
527
|
+
if (cached.extractedSheet) {
|
|
528
|
+
totalExtractedSheets.push(cached.extractedSheet);
|
|
529
|
+
}
|
|
482
530
|
}
|
|
531
|
+
continue;
|
|
483
532
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
if (
|
|
531
|
-
node.
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
533
|
+
const source = fs_1.default.readFileSync(filePath, 'utf8');
|
|
534
|
+
if (!source.includes('@plumeria/core')) {
|
|
535
|
+
fileCache[filePath] = {
|
|
536
|
+
mtimeMs: stats.mtimeMs,
|
|
537
|
+
staticTable: {},
|
|
538
|
+
keyframesHashTable: {},
|
|
539
|
+
keyframesObjectTable: {},
|
|
540
|
+
viewTransitionHashTable: {},
|
|
541
|
+
viewTransitionObjectTable: {},
|
|
542
|
+
createThemeHashTable: {},
|
|
543
|
+
createThemeObjectTable: {},
|
|
544
|
+
createHashTable: {},
|
|
545
|
+
createObjectTable: {},
|
|
546
|
+
createAtomicMapTable: {},
|
|
547
|
+
variantsHashTable: {},
|
|
548
|
+
variantsObjectTable: {},
|
|
549
|
+
createStaticHashTable: {},
|
|
550
|
+
createStaticObjectTable: {},
|
|
551
|
+
hasCssUsage: false,
|
|
552
|
+
extractedSheet: '',
|
|
553
|
+
};
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
const ast = (0, core_1.parseSync)(source, {
|
|
557
|
+
syntax: 'typescript',
|
|
558
|
+
tsx: true,
|
|
559
|
+
target: 'es2022',
|
|
560
|
+
});
|
|
561
|
+
const localStaticTable = {};
|
|
562
|
+
const localKeyframesHashTable = {};
|
|
563
|
+
const localKeyframesObjectTable = {};
|
|
564
|
+
const localViewTransitionHashTable = {};
|
|
565
|
+
const localViewTransitionObjectTable = {};
|
|
566
|
+
const localCreateThemeObjectTable = {};
|
|
567
|
+
const localCreateHashTable = {};
|
|
568
|
+
const localCreateObjectTable = {};
|
|
569
|
+
const localCreateAtomicMapTable = {};
|
|
570
|
+
const localVariantsHashTable = {};
|
|
571
|
+
const localVariantsObjectTable = {};
|
|
572
|
+
const localCreateThemeHashTable = {};
|
|
573
|
+
const localCreateStaticHashTable = {};
|
|
574
|
+
const localCreateStaticObjectTable = {};
|
|
575
|
+
const plumeriaAliases = {};
|
|
576
|
+
const fileExtractedSheets = [];
|
|
577
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
578
|
+
for (const node of ast.body) {
|
|
579
|
+
if (node.type === 'ImportDeclaration') {
|
|
580
|
+
const sourceValue = node.source.value;
|
|
581
|
+
if (sourceValue === '@plumeria/core') {
|
|
582
|
+
node.specifiers.forEach((specifier) => {
|
|
583
|
+
if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
584
|
+
if (specifier.local) {
|
|
585
|
+
plumeriaAliases[specifier.local.value] = 'NAMESPACE';
|
|
586
|
+
}
|
|
535
587
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
plumeriaAliases[localName] = importedName;
|
|
543
|
-
}
|
|
544
|
-
else if (specifier.type === 'ImportDefaultSpecifier') {
|
|
545
|
-
if (specifier.local) {
|
|
546
|
-
plumeriaAliases[specifier.local.value] = 'NAMESPACE';
|
|
588
|
+
else if (specifier.type === 'ImportSpecifier') {
|
|
589
|
+
const importedName = specifier.imported
|
|
590
|
+
? specifier.imported.value
|
|
591
|
+
: specifier.local.value;
|
|
592
|
+
const localName = specifier.local.value;
|
|
593
|
+
plumeriaAliases[localName] = importedName;
|
|
547
594
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
let declarations = [];
|
|
555
|
-
if (exports.t.isVariableDeclaration(node)) {
|
|
556
|
-
declarations = node.declarations;
|
|
557
|
-
}
|
|
558
|
-
else if (exports.t.isExportDeclaration(node) &&
|
|
559
|
-
exports.t.isVariableDeclaration(node.declaration)) {
|
|
560
|
-
declarations = node.declaration.declarations;
|
|
561
|
-
}
|
|
562
|
-
for (const decl of declarations) {
|
|
563
|
-
if (exports.t.isVariableDeclarator(decl) &&
|
|
564
|
-
exports.t.isIdentifier(decl.id) &&
|
|
565
|
-
decl.init &&
|
|
566
|
-
exports.t.isCallExpression(decl.init) &&
|
|
567
|
-
exports.t.isCallExpression(decl.init)) {
|
|
568
|
-
const callee = decl.init.callee;
|
|
569
|
-
let method;
|
|
570
|
-
if (exports.t.isMemberExpression(callee) &&
|
|
571
|
-
exports.t.isIdentifier(callee.object) &&
|
|
572
|
-
exports.t.isIdentifier(callee.property)) {
|
|
573
|
-
const objectName = callee.object.value;
|
|
574
|
-
const propertyName = callee.property.value;
|
|
575
|
-
const alias = plumeriaAliases[objectName];
|
|
576
|
-
if (alias === 'NAMESPACE' || objectName === 'css') {
|
|
577
|
-
method = propertyName;
|
|
578
|
-
}
|
|
595
|
+
else if (specifier.type === 'ImportDefaultSpecifier') {
|
|
596
|
+
if (specifier.local) {
|
|
597
|
+
plumeriaAliases[specifier.local.value] = 'NAMESPACE';
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
});
|
|
579
601
|
}
|
|
580
|
-
else
|
|
581
|
-
const
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
602
|
+
else {
|
|
603
|
+
const actualPath = (0, resolver_1.resolveImportPath)(sourceValue, filePath);
|
|
604
|
+
if (actualPath) {
|
|
605
|
+
node.specifiers.forEach((specifier) => {
|
|
606
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
607
|
+
const importedName = specifier.imported
|
|
608
|
+
? specifier.imported.value
|
|
609
|
+
: specifier.local.value;
|
|
610
|
+
const localName = specifier.local.value;
|
|
611
|
+
const uniqueKey = `${actualPath}-${importedName}`;
|
|
612
|
+
if (localTables.createStaticHashTable[uniqueKey]) {
|
|
613
|
+
const hash = localTables.createStaticHashTable[uniqueKey];
|
|
614
|
+
localCreateStaticHashTable[localName] = hash;
|
|
615
|
+
if (localTables.createStaticObjectTable[hash]) {
|
|
616
|
+
localCreateStaticObjectTable[hash] =
|
|
617
|
+
localTables.createStaticObjectTable[hash];
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
if (localTables.createThemeHashTable[uniqueKey]) {
|
|
621
|
+
const hash = localTables.createThemeHashTable[uniqueKey];
|
|
622
|
+
localCreateThemeHashTable[localName] = hash;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
});
|
|
585
626
|
}
|
|
586
627
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
for (const node of ast.body) {
|
|
631
|
+
let declarations = [];
|
|
632
|
+
if (exports.t.isVariableDeclaration(node)) {
|
|
633
|
+
declarations = node.declarations;
|
|
634
|
+
}
|
|
635
|
+
else if (exports.t.isExportDeclaration(node) &&
|
|
636
|
+
exports.t.isVariableDeclaration(node.declaration)) {
|
|
637
|
+
declarations = node.declaration.declarations;
|
|
638
|
+
}
|
|
639
|
+
for (const decl of declarations) {
|
|
640
|
+
if (exports.t.isVariableDeclarator(decl) &&
|
|
641
|
+
exports.t.isIdentifier(decl.id) &&
|
|
642
|
+
decl.init &&
|
|
643
|
+
exports.t.isCallExpression(decl.init) &&
|
|
644
|
+
exports.t.isCallExpression(decl.init)) {
|
|
645
|
+
const callee = decl.init.callee;
|
|
646
|
+
let method;
|
|
647
|
+
if (exports.t.isMemberExpression(callee) &&
|
|
648
|
+
exports.t.isIdentifier(callee.object) &&
|
|
649
|
+
exports.t.isIdentifier(callee.property)) {
|
|
650
|
+
const objectName = callee.object.value;
|
|
651
|
+
const propertyName = callee.property.value;
|
|
652
|
+
const alias = plumeriaAliases[objectName];
|
|
653
|
+
if (alias === 'NAMESPACE' || objectName === 'css') {
|
|
654
|
+
method = propertyName;
|
|
596
655
|
}
|
|
597
|
-
return undefined;
|
|
598
|
-
};
|
|
599
|
-
const obj = objectExpressionToObject(init.arguments[0].expression, localStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localThemeTable, localCreateHashTable, localVariantsHashTable, resolveVariable);
|
|
600
|
-
const uniqueKey = `${filePath}-${name}`;
|
|
601
|
-
if (method === 'createStatic') {
|
|
602
|
-
localStaticTable[name] = obj;
|
|
603
|
-
localTables.staticTable[uniqueKey] = obj;
|
|
604
656
|
}
|
|
605
|
-
else if (
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
localTables.keyframesObjectTable[hash] = obj;
|
|
611
|
-
localKeyframesObjectTable[hash] = obj;
|
|
612
|
-
if (!isProduction) {
|
|
613
|
-
extractOndemandStyles({ kf: `kf-${hash}` }, fileExtractedSheets, localTables);
|
|
657
|
+
else if (exports.t.isIdentifier(callee)) {
|
|
658
|
+
const calleeName = callee.value;
|
|
659
|
+
const originalName = plumeriaAliases[calleeName];
|
|
660
|
+
if (originalName) {
|
|
661
|
+
method = originalName;
|
|
614
662
|
}
|
|
615
663
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
664
|
+
if (method &&
|
|
665
|
+
decl.init.arguments.length > 0 &&
|
|
666
|
+
exports.t.isObjectExpression(decl.init.arguments[0].expression)) {
|
|
667
|
+
const name = decl.id.value;
|
|
668
|
+
const init = decl.init;
|
|
669
|
+
const resolveVariable = (name) => {
|
|
670
|
+
const hash = localCreateHashTable[name];
|
|
671
|
+
if (hash && localCreateObjectTable[hash]) {
|
|
672
|
+
return localCreateObjectTable[hash];
|
|
673
|
+
}
|
|
674
|
+
return undefined;
|
|
675
|
+
};
|
|
676
|
+
const obj = objectExpressionToObject(init.arguments[0].expression, localStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localCreateThemeHashTable, localCreateThemeObjectTable, localCreateHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, localVariantsHashTable, resolveVariable);
|
|
677
|
+
const uniqueKey = `${filePath}-${name}`;
|
|
678
|
+
const isPassOneMethod = method === 'createStatic' || method === 'createTheme';
|
|
679
|
+
if (isFirstPass && !isPassOneMethod)
|
|
680
|
+
continue;
|
|
681
|
+
if (method === 'createStatic') {
|
|
682
|
+
localStaticTable[name] = obj;
|
|
683
|
+
localTables.staticTable[uniqueKey] = obj;
|
|
684
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
685
|
+
localCreateStaticHashTable[name] = hash;
|
|
686
|
+
localTables.createStaticHashTable[uniqueKey] = hash;
|
|
687
|
+
localTables.createStaticObjectTable[hash] = obj;
|
|
688
|
+
localCreateStaticObjectTable[hash] = obj;
|
|
689
|
+
const hashMap = {
|
|
690
|
+
__static: {},
|
|
691
|
+
};
|
|
692
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
693
|
+
if (typeof value === 'string') {
|
|
694
|
+
hashMap.__static[key] = value;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
localTables.createAtomicMapTable[hash] = hashMap;
|
|
626
698
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
}
|
|
635
|
-
else if (method === 'create') {
|
|
636
|
-
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
637
|
-
localCreateHashTable[name] = hash;
|
|
638
|
-
localTables.createHashTable[uniqueKey] = hash;
|
|
639
|
-
localTables.createObjectTable[hash] = obj;
|
|
640
|
-
localCreateObjectTable[hash] = obj;
|
|
641
|
-
const hashMap = {};
|
|
642
|
-
Object.entries(obj).forEach(([key, style]) => {
|
|
643
|
-
const records = (0, create_1.getStyleRecords)(key, style, 2);
|
|
644
|
-
const atomMap = {};
|
|
645
|
-
records.forEach((r) => (atomMap[r.key] = r.hash));
|
|
646
|
-
hashMap[key] = atomMap;
|
|
699
|
+
else if (method === 'keyframes') {
|
|
700
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
701
|
+
localKeyframesHashTable[name] = hash;
|
|
702
|
+
localTables.keyframesHashTable[uniqueKey] = hash;
|
|
703
|
+
localTables.keyframesObjectTable[hash] = obj;
|
|
704
|
+
localTables.keyframesObjectTable[hash] = obj;
|
|
705
|
+
localKeyframesObjectTable[hash] = obj;
|
|
647
706
|
if (!isProduction) {
|
|
707
|
+
extractOndemandStyles({ kf: `kf-${hash}` }, fileExtractedSheets, localTables);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
else if (method === 'viewTransition') {
|
|
711
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
712
|
+
localViewTransitionHashTable[name] = hash;
|
|
713
|
+
localTables.viewTransitionHashTable[uniqueKey] = hash;
|
|
714
|
+
localTables.viewTransitionObjectTable[hash] = obj;
|
|
715
|
+
localTables.viewTransitionObjectTable[hash] = obj;
|
|
716
|
+
localViewTransitionObjectTable[hash] = obj;
|
|
717
|
+
if (!isProduction) {
|
|
718
|
+
extractOndemandStyles({ vt: `vt-${hash}` }, fileExtractedSheets, localTables);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
else if (method === 'createTheme') {
|
|
722
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
723
|
+
localTables.createThemeObjectTable[hash] = obj;
|
|
724
|
+
localCreateThemeObjectTable[hash] = obj;
|
|
725
|
+
localCreateThemeHashTable[name] = hash;
|
|
726
|
+
localTables.createThemeHashTable[uniqueKey] = hash;
|
|
727
|
+
currentScanThemeObjectTable[hash] = obj;
|
|
728
|
+
const hashMap = {};
|
|
729
|
+
for (const [key] of Object.entries(obj)) {
|
|
730
|
+
const cssVarName = (0, zss_engine_1.camelToKebabCase)(key);
|
|
731
|
+
hashMap[key] = `var(--${cssVarName})`;
|
|
732
|
+
}
|
|
733
|
+
localTables.createAtomicMapTable[hash] = hashMap;
|
|
734
|
+
}
|
|
735
|
+
else if (method === 'create') {
|
|
736
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
737
|
+
localCreateHashTable[name] = hash;
|
|
738
|
+
localTables.createHashTable[uniqueKey] = hash;
|
|
739
|
+
localTables.createObjectTable[hash] = obj;
|
|
740
|
+
localCreateObjectTable[hash] = obj;
|
|
741
|
+
const hashMap = {};
|
|
742
|
+
Object.entries(obj).forEach(([key, style]) => {
|
|
743
|
+
const records = (0, create_1.getStyleRecords)(key, style, 2);
|
|
744
|
+
const atomMap = {};
|
|
745
|
+
records.forEach((r) => (atomMap[r.key] = r.hash));
|
|
746
|
+
hashMap[key] = atomMap;
|
|
648
747
|
extractOndemandStyles(style, fileExtractedSheets, localTables);
|
|
649
748
|
records.forEach((r) => {
|
|
650
749
|
if (!fileExtractedSheets.includes(r.sheet)) {
|
|
651
750
|
fileExtractedSheets.push(r.sheet);
|
|
652
751
|
}
|
|
653
752
|
});
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
753
|
+
});
|
|
754
|
+
localCreateAtomicMapTable[hash] = hashMap;
|
|
755
|
+
localTables.createAtomicMapTable[hash] = hashMap;
|
|
756
|
+
}
|
|
757
|
+
else if (method === 'variants') {
|
|
758
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
759
|
+
localVariantsHashTable[name] = hash;
|
|
760
|
+
localTables.variantsHashTable[uniqueKey] = hash;
|
|
761
|
+
localTables.variantsObjectTable[hash] = obj;
|
|
762
|
+
localVariantsObjectTable[hash] = obj;
|
|
763
|
+
}
|
|
665
764
|
}
|
|
666
765
|
}
|
|
667
766
|
}
|
|
668
767
|
}
|
|
768
|
+
if (!isFirstPass) {
|
|
769
|
+
fileCache[filePath] = {
|
|
770
|
+
mtimeMs: stats.mtimeMs,
|
|
771
|
+
staticTable: localStaticTable,
|
|
772
|
+
keyframesHashTable: localKeyframesHashTable,
|
|
773
|
+
keyframesObjectTable: localKeyframesObjectTable,
|
|
774
|
+
viewTransitionHashTable: localViewTransitionHashTable,
|
|
775
|
+
viewTransitionObjectTable: localViewTransitionObjectTable,
|
|
776
|
+
createThemeHashTable: localCreateThemeHashTable,
|
|
777
|
+
createThemeObjectTable: localCreateThemeObjectTable,
|
|
778
|
+
createHashTable: localCreateHashTable,
|
|
779
|
+
createObjectTable: localCreateObjectTable,
|
|
780
|
+
createAtomicMapTable: localCreateAtomicMapTable,
|
|
781
|
+
variantsHashTable: localVariantsHashTable,
|
|
782
|
+
variantsObjectTable: localVariantsObjectTable,
|
|
783
|
+
createStaticHashTable: localCreateStaticHashTable,
|
|
784
|
+
createStaticObjectTable: localCreateStaticObjectTable,
|
|
785
|
+
hasCssUsage: true,
|
|
786
|
+
extractedSheet: fileExtractedSheets.join(''),
|
|
787
|
+
};
|
|
788
|
+
if (fileExtractedSheets.length > 0) {
|
|
789
|
+
totalExtractedSheets.push(fileExtractedSheets.join(''));
|
|
790
|
+
}
|
|
791
|
+
}
|
|
669
792
|
}
|
|
670
|
-
|
|
671
|
-
mtimeMs: stats.mtimeMs,
|
|
672
|
-
staticTable: localStaticTable,
|
|
673
|
-
keyframesHashTable: localKeyframesHashTable,
|
|
674
|
-
keyframesObjectTable: localKeyframesObjectTable,
|
|
675
|
-
viewTransitionHashTable: localViewTransitionHashTable,
|
|
676
|
-
viewTransitionObjectTable: localViewTransitionObjectTable,
|
|
677
|
-
themeTable: localThemeTable,
|
|
678
|
-
createThemeObjectTable: localCreateThemeObjectTable,
|
|
679
|
-
createHashTable: localCreateHashTable,
|
|
680
|
-
createObjectTable: localCreateObjectTable,
|
|
681
|
-
createAtomicMapTable: localCreateAtomicMapTable,
|
|
682
|
-
variantsHashTable: localVariantsHashTable,
|
|
683
|
-
variantsObjectTable: localVariantsObjectTable,
|
|
684
|
-
hasCssUsage: true,
|
|
685
|
-
extractedSheet: fileExtractedSheets.join(''),
|
|
686
|
-
};
|
|
687
|
-
if (fileExtractedSheets.length > 0) {
|
|
688
|
-
totalExtractedSheets.push(fileExtractedSheets.join(''));
|
|
793
|
+
catch (e) {
|
|
689
794
|
}
|
|
690
795
|
}
|
|
691
|
-
catch (e) {
|
|
692
|
-
}
|
|
693
796
|
}
|
|
694
797
|
localTables.extractedSheet = totalExtractedSheets.join('');
|
|
695
798
|
if (process.env.NODE_ENV === 'production') {
|
|
@@ -697,7 +800,7 @@ function scanAll() {
|
|
|
697
800
|
}
|
|
698
801
|
return localTables;
|
|
699
802
|
}
|
|
700
|
-
function extractOndemandStyles(obj, extractedSheets, t
|
|
803
|
+
function extractOndemandStyles(obj, extractedSheets, t) {
|
|
701
804
|
if (!obj || typeof obj !== 'object')
|
|
702
805
|
return;
|
|
703
806
|
const visited = new Set();
|
|
@@ -720,7 +823,7 @@ function extractOndemandStyles(obj, extractedSheets, t = exports.tables) {
|
|
|
720
823
|
else if (val.startsWith('cr-')) {
|
|
721
824
|
createHashes.add(val.slice(3));
|
|
722
825
|
}
|
|
723
|
-
else if (
|
|
826
|
+
else if (val.includes('var(--')) {
|
|
724
827
|
needsTheme = true;
|
|
725
828
|
}
|
|
726
829
|
}
|
|
@@ -767,9 +870,8 @@ function extractOndemandStyles(obj, extractedSheets, t = exports.tables) {
|
|
|
767
870
|
}
|
|
768
871
|
}
|
|
769
872
|
if (needsTheme) {
|
|
770
|
-
for (const themeVarName in t.
|
|
771
|
-
const
|
|
772
|
-
const hash = (0, zss_engine_1.genBase36Hash)(themeObj, 1, 8);
|
|
873
|
+
for (const themeVarName in t.createThemeHashTable) {
|
|
874
|
+
const hash = t.createThemeHashTable[themeVarName];
|
|
773
875
|
const definition = t.createThemeObjectTable[hash];
|
|
774
876
|
if (definition && typeof definition === 'object') {
|
|
775
877
|
const styles = (0, createTheme_1.createTheme)(definition);
|
package/dist/resolver.js
CHANGED
|
@@ -20,7 +20,7 @@ function getTsConfig(startDir) {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
while (currentDir !== path_1.default.parse(currentDir).root) {
|
|
23
|
-
const tsConfigPath = path_1.default.join(
|
|
23
|
+
const tsConfigPath = path_1.default.join(process.cwd(), 'tsconfig.json');
|
|
24
24
|
if (fs_1.default.existsSync(tsConfigPath)) {
|
|
25
25
|
if (!tsConfigCache.has(tsConfigPath)) {
|
|
26
26
|
try {
|
|
@@ -34,7 +34,7 @@ function getTsConfig(startDir) {
|
|
|
34
34
|
tsConfigPathCache.set(startDir, tsConfigPath);
|
|
35
35
|
return {
|
|
36
36
|
config: tsConfigCache.get(tsConfigPath) ?? null,
|
|
37
|
-
basePath:
|
|
37
|
+
basePath: path_1.default.dirname(tsConfigPath),
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
currentDir = path_1.default.dirname(currentDir);
|
package/dist/types.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export type CSSObject = {
|
|
|
5
5
|
[key: string]: CSSValue;
|
|
6
6
|
};
|
|
7
7
|
export type StaticTable = Record<string, CSSValue>;
|
|
8
|
-
export type ThemeTable = Record<string, CSSObject>;
|
|
9
8
|
export type KeyframesHashTable = Record<string, string>;
|
|
10
9
|
export type KeyframesObjectTable = Record<string, CSSObject>;
|
|
11
10
|
export type ViewTransitionHashTable = Record<string, string>;
|
|
@@ -16,17 +15,22 @@ export type CreateObjectTable = Record<string, CSSObject>;
|
|
|
16
15
|
export type VariantsHashTable = Record<string, string>;
|
|
17
16
|
export type VariantsObjectTable = Record<string, CSSObject>;
|
|
18
17
|
export type CreateAtomicMapTable = Record<string, Record<string, Record<string, string>>>;
|
|
18
|
+
export type CreateStaticHashTable = Record<string, string>;
|
|
19
|
+
export type CreateStaticObjectTable = Record<string, CSSObject>;
|
|
20
|
+
export type CreateThemeHashTable = Record<string, string>;
|
|
19
21
|
export interface Tables {
|
|
20
22
|
staticTable: StaticTable;
|
|
21
|
-
themeTable: ThemeTable;
|
|
22
23
|
keyframesHashTable: KeyframesHashTable;
|
|
23
24
|
keyframesObjectTable: KeyframesObjectTable;
|
|
24
25
|
viewTransitionHashTable: ViewTransitionHashTable;
|
|
25
26
|
viewTransitionObjectTable: ViewTransitionObjectTable;
|
|
27
|
+
createThemeHashTable: CreateThemeHashTable;
|
|
26
28
|
createThemeObjectTable: CreateThemeObjectTable;
|
|
27
29
|
createHashTable: CreateHashTable;
|
|
28
30
|
createObjectTable: CreateObjectTable;
|
|
29
31
|
createAtomicMapTable: CreateAtomicMapTable;
|
|
32
|
+
createStaticHashTable: CreateStaticHashTable;
|
|
33
|
+
createStaticObjectTable: CreateStaticObjectTable;
|
|
30
34
|
variantsHashTable: VariantsHashTable;
|
|
31
35
|
variantsObjectTable: VariantsObjectTable;
|
|
32
36
|
extractedSheet?: string;
|