@plumeria/utils 5.0.1 → 6.0.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 +1 -1
- package/dist/parser.d.ts +4 -4
- package/dist/parser.js +151 -34
- package/dist/resolver.js +30 -15
- package/dist/types.d.ts +9 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { CSSObject, FileStyles } from './types';
|
|
1
|
+
export type { CSSObject, FileStyles, StaticTable, ThemeTable, KeyframesHashTable, KeyframesObjectTable, ViewTransitionHashTable, ViewTransitionObjectTable, CreateThemeObjectTable, CreateHashTable, CreateObjectTable, VariantsHashTable, VariantsObjectTable, } from './types';
|
|
2
2
|
export { objectExpressionToObject, collectLocalConsts, traverse, t, tables, extractOndemandStyles, deepMerge, scanAll, } from './parser';
|
|
3
3
|
export { getStyleRecords } from './create';
|
|
4
4
|
export type { StyleRecord } from './create';
|
package/dist/parser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CSSObject, ThemeTable, Tables, StaticTable, KeyframesHashTable, ViewTransitionHashTable } from './types';
|
|
1
|
+
import type { CSSObject, ThemeTable, Tables, StaticTable, KeyframesHashTable, ViewTransitionHashTable, CreateHashTable, VariantsHashTable } 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;
|
|
@@ -27,8 +27,8 @@ export declare function traverse(node: Module, visitor: {
|
|
|
27
27
|
}) => void;
|
|
28
28
|
}): void;
|
|
29
29
|
export declare const tables: Tables;
|
|
30
|
-
export declare function objectExpressionToObject(node: ObjectExpression, staticTable: StaticTable, keyframesHashTable: KeyframesHashTable, viewTransitionHashTable: ViewTransitionHashTable, themeTable: ThemeTable, resolveVariable?: (name: string) => any): CSSObject;
|
|
30
|
+
export declare function objectExpressionToObject(node: ObjectExpression, staticTable: StaticTable, keyframesHashTable: KeyframesHashTable, viewTransitionHashTable: ViewTransitionHashTable, themeTable: ThemeTable, createHashTable: CreateHashTable, variantsHashTable: VariantsHashTable, resolveVariable?: (name: string) => any): CSSObject;
|
|
31
31
|
export declare function collectLocalConsts(ast: Module): Record<string, any>;
|
|
32
|
-
export declare function scanAll(
|
|
33
|
-
export declare function extractOndemandStyles(obj: any, extractedSheets: string[]): void;
|
|
32
|
+
export declare function scanAll(): Tables;
|
|
33
|
+
export declare function extractOndemandStyles(obj: any, extractedSheets: string[], t?: Tables): void;
|
|
34
34
|
export declare function deepMerge(target: Record<string, any>, source: Record<string, any>): Record<string, any>;
|
package/dist/parser.js
CHANGED
|
@@ -16,6 +16,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
16
16
|
const fs_1 = __importDefault(require("fs"));
|
|
17
17
|
const zss_engine_1 = require("zss-engine");
|
|
18
18
|
const viewTransition_1 = require("./viewTransition");
|
|
19
|
+
const create_1 = require("./create");
|
|
19
20
|
exports.t = {
|
|
20
21
|
isObjectExpression: (node) => node?.type === 'ObjectExpression',
|
|
21
22
|
isObjectProperty: (node) => node?.type === 'KeyValueProperty',
|
|
@@ -83,8 +84,12 @@ exports.tables = {
|
|
|
83
84
|
viewTransitionHashTable: {},
|
|
84
85
|
viewTransitionObjectTable: {},
|
|
85
86
|
createThemeObjectTable: {},
|
|
87
|
+
createHashTable: {},
|
|
88
|
+
createObjectTable: {},
|
|
89
|
+
variantsHashTable: {},
|
|
90
|
+
variantsObjectTable: {},
|
|
86
91
|
};
|
|
87
|
-
function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTransitionHashTable, themeTable, resolveVariable) {
|
|
92
|
+
function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTransitionHashTable, themeTable, createHashTable, variantsHashTable, resolveVariable) {
|
|
88
93
|
const obj = {};
|
|
89
94
|
node.properties.forEach((prop) => {
|
|
90
95
|
if (!exports.t.isObjectProperty(prop))
|
|
@@ -94,6 +99,16 @@ function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTra
|
|
|
94
99
|
return;
|
|
95
100
|
const val = prop.value;
|
|
96
101
|
if (exports.t.isIdentifier(val) || exports.t.isMemberExpression(val)) {
|
|
102
|
+
if (resolveVariable && exports.t.isMemberExpression(val)) {
|
|
103
|
+
if (exports.t.isIdentifier(val.object) && exports.t.isIdentifier(val.property)) {
|
|
104
|
+
const resolved = resolveVariable(val.object.value);
|
|
105
|
+
const prop = val.property.value;
|
|
106
|
+
if (resolved && resolved[prop]) {
|
|
107
|
+
obj[key] = resolved[prop];
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
97
112
|
const resolvedKeyframe = resolveKeyframesTableMemberExpression(val, keyframesHashTable);
|
|
98
113
|
if (resolvedKeyframe !== undefined) {
|
|
99
114
|
obj[key] = 'kf-' + resolvedKeyframe;
|
|
@@ -104,11 +119,21 @@ function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTra
|
|
|
104
119
|
obj[key] = 'vt-' + resolvedViewTransitioin;
|
|
105
120
|
return;
|
|
106
121
|
}
|
|
122
|
+
const resolvedCreate = resolveCreateTableMemberExpression(val, createHashTable);
|
|
123
|
+
if (resolvedCreate !== undefined) {
|
|
124
|
+
obj[key] = 'cr-' + resolvedCreate;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
107
127
|
const resolvedTheme = resolveThemeTableMemberExpressionByNode(val, themeTable);
|
|
108
128
|
if (resolvedTheme !== undefined) {
|
|
109
129
|
obj[key] = resolvedTheme;
|
|
110
130
|
return;
|
|
111
131
|
}
|
|
132
|
+
const resolvedVariants = resolveVariantsTableMemberExpression(val, variantsHashTable);
|
|
133
|
+
if (resolvedVariants !== undefined) {
|
|
134
|
+
obj[key] = 'vr-' + resolvedVariants;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
112
137
|
}
|
|
113
138
|
if (exports.t.isStringLiteral(val) ||
|
|
114
139
|
exports.t.isNumericLiteral(val) ||
|
|
@@ -119,7 +144,7 @@ function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTra
|
|
|
119
144
|
obj[key] = evaluateUnaryExpression(val);
|
|
120
145
|
}
|
|
121
146
|
else if (exports.t.isObjectExpression(val)) {
|
|
122
|
-
obj[key] = objectExpressionToObject(val, staticTable, keyframesHashTable, viewTransitionHashTable, themeTable, resolveVariable);
|
|
147
|
+
obj[key] = objectExpressionToObject(val, staticTable, keyframesHashTable, viewTransitionHashTable, themeTable, createHashTable, variantsHashTable, resolveVariable);
|
|
123
148
|
}
|
|
124
149
|
else if (exports.t.isMemberExpression(val)) {
|
|
125
150
|
const resolved = resolveStaticTableMemberExpression(val, staticTable);
|
|
@@ -171,7 +196,7 @@ function collectLocalConsts(ast) {
|
|
|
171
196
|
result = init.value;
|
|
172
197
|
}
|
|
173
198
|
else if (exports.t.isObjectExpression(init)) {
|
|
174
|
-
result = objectExpressionToObject(init, localConsts, exports.tables.keyframesHashTable, exports.tables.viewTransitionHashTable, exports.tables.themeTable, resolveValue);
|
|
199
|
+
result = objectExpressionToObject(init, localConsts, exports.tables.keyframesHashTable, exports.tables.viewTransitionHashTable, exports.tables.themeTable, exports.tables.createHashTable, exports.tables.variantsHashTable, resolveValue);
|
|
175
200
|
}
|
|
176
201
|
visiting.delete(name);
|
|
177
202
|
if (result !== undefined) {
|
|
@@ -330,6 +355,26 @@ function resolveViewTransitionTableMemberExpression(node, viewTransitionHashTabl
|
|
|
330
355
|
}
|
|
331
356
|
}
|
|
332
357
|
}
|
|
358
|
+
function resolveCreateTableMemberExpression(node, createHashTable) {
|
|
359
|
+
if (exports.t.isIdentifier(node)) {
|
|
360
|
+
return createHashTable[node.value];
|
|
361
|
+
}
|
|
362
|
+
if (exports.t.isMemberExpression(node)) {
|
|
363
|
+
if (exports.t.isIdentifier(node.object)) {
|
|
364
|
+
return createHashTable[node.object.value];
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function resolveVariantsTableMemberExpression(node, variantsHashTable) {
|
|
369
|
+
if (exports.t.isIdentifier(node)) {
|
|
370
|
+
return variantsHashTable[node.value];
|
|
371
|
+
}
|
|
372
|
+
if (exports.t.isMemberExpression(node)) {
|
|
373
|
+
if (exports.t.isIdentifier(node.object)) {
|
|
374
|
+
return variantsHashTable[node.object.value];
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
333
378
|
function resolveStaticTableMemberExpression(node, staticTable) {
|
|
334
379
|
if (exports.t.isIdentifier(node.object) && exports.t.isIdentifier(node.property)) {
|
|
335
380
|
const varName = node.object.value;
|
|
@@ -360,13 +405,20 @@ function resolveThemeTableMemberExpressionByNode(node, themeTable) {
|
|
|
360
405
|
return undefined;
|
|
361
406
|
}
|
|
362
407
|
const fileCache = {};
|
|
363
|
-
function scanAll(
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
|
|
408
|
+
function scanAll() {
|
|
409
|
+
const localTables = {
|
|
410
|
+
staticTable: {},
|
|
411
|
+
themeTable: {},
|
|
412
|
+
keyframesHashTable: {},
|
|
413
|
+
keyframesObjectTable: {},
|
|
414
|
+
viewTransitionHashTable: {},
|
|
415
|
+
viewTransitionObjectTable: {},
|
|
416
|
+
createThemeObjectTable: {},
|
|
417
|
+
createHashTable: {},
|
|
418
|
+
createObjectTable: {},
|
|
419
|
+
variantsHashTable: {},
|
|
420
|
+
variantsObjectTable: {},
|
|
421
|
+
};
|
|
370
422
|
const files = fs_1.default.globSync(PATTERN_PATH, GLOB_OPTIONS);
|
|
371
423
|
for (const filePath of files) {
|
|
372
424
|
try {
|
|
@@ -374,31 +426,49 @@ function scanAll(addDependency) {
|
|
|
374
426
|
const cached = fileCache[filePath];
|
|
375
427
|
if (cached && cached.mtimeMs === stats.mtimeMs) {
|
|
376
428
|
if (cached.hasCssUsage) {
|
|
377
|
-
addDependency(filePath);
|
|
378
429
|
for (const key of Object.keys(cached.staticTable)) {
|
|
379
|
-
|
|
430
|
+
localTables.staticTable[`${filePath}-${key}`] =
|
|
431
|
+
cached.staticTable[key];
|
|
380
432
|
}
|
|
381
433
|
for (const key of Object.keys(cached.keyframesHashTable)) {
|
|
382
|
-
|
|
434
|
+
localTables.keyframesHashTable[`${filePath}-${key}`] =
|
|
435
|
+
cached.keyframesHashTable[key];
|
|
383
436
|
}
|
|
384
437
|
for (const key of Object.keys(cached.keyframesObjectTable)) {
|
|
385
|
-
|
|
438
|
+
localTables.keyframesObjectTable[key] =
|
|
439
|
+
cached.keyframesObjectTable[key];
|
|
386
440
|
}
|
|
387
441
|
for (const key of Object.keys(cached.viewTransitionHashTable)) {
|
|
388
|
-
|
|
442
|
+
localTables.viewTransitionHashTable[`${filePath}-${key}`] =
|
|
389
443
|
cached.viewTransitionHashTable[key];
|
|
390
444
|
}
|
|
391
445
|
for (const key of Object.keys(cached.viewTransitionObjectTable)) {
|
|
392
|
-
|
|
446
|
+
localTables.viewTransitionObjectTable[key] =
|
|
393
447
|
cached.viewTransitionObjectTable[key];
|
|
394
448
|
}
|
|
395
449
|
for (const key of Object.keys(cached.themeTable)) {
|
|
396
|
-
|
|
450
|
+
localTables.themeTable[`${filePath}-${key}`] =
|
|
451
|
+
cached.themeTable[key];
|
|
397
452
|
}
|
|
398
453
|
for (const key of Object.keys(cached.createThemeObjectTable)) {
|
|
399
|
-
|
|
454
|
+
localTables.createThemeObjectTable[key] =
|
|
400
455
|
cached.createThemeObjectTable[key];
|
|
401
456
|
}
|
|
457
|
+
for (const key of Object.keys(cached.createHashTable)) {
|
|
458
|
+
localTables.createHashTable[`${filePath}-${key}`] =
|
|
459
|
+
cached.createHashTable[key];
|
|
460
|
+
}
|
|
461
|
+
for (const key of Object.keys(cached.createObjectTable)) {
|
|
462
|
+
localTables.createObjectTable[key] = cached.createObjectTable[key];
|
|
463
|
+
}
|
|
464
|
+
for (const key of Object.keys(cached.variantsHashTable)) {
|
|
465
|
+
localTables.variantsHashTable[`${filePath}-${key}`] =
|
|
466
|
+
cached.variantsHashTable[key];
|
|
467
|
+
}
|
|
468
|
+
for (const key of Object.keys(cached.variantsObjectTable)) {
|
|
469
|
+
localTables.variantsObjectTable[key] =
|
|
470
|
+
cached.variantsObjectTable[key];
|
|
471
|
+
}
|
|
402
472
|
}
|
|
403
473
|
continue;
|
|
404
474
|
}
|
|
@@ -413,6 +483,10 @@ function scanAll(addDependency) {
|
|
|
413
483
|
viewTransitionObjectTable: {},
|
|
414
484
|
themeTable: {},
|
|
415
485
|
createThemeObjectTable: {},
|
|
486
|
+
createHashTable: {},
|
|
487
|
+
createObjectTable: {},
|
|
488
|
+
variantsHashTable: {},
|
|
489
|
+
variantsObjectTable: {},
|
|
416
490
|
hasCssUsage: false,
|
|
417
491
|
};
|
|
418
492
|
continue;
|
|
@@ -422,7 +496,6 @@ function scanAll(addDependency) {
|
|
|
422
496
|
tsx: true,
|
|
423
497
|
target: 'es2022',
|
|
424
498
|
});
|
|
425
|
-
addDependency(filePath);
|
|
426
499
|
const localStaticTable = {};
|
|
427
500
|
const localKeyframesHashTable = {};
|
|
428
501
|
const localKeyframesObjectTable = {};
|
|
@@ -430,6 +503,10 @@ function scanAll(addDependency) {
|
|
|
430
503
|
const localViewTransitionObjectTable = {};
|
|
431
504
|
const localThemeTable = {};
|
|
432
505
|
const localCreateThemeObjectTable = {};
|
|
506
|
+
const localCreateHashTable = {};
|
|
507
|
+
const localCreateObjectTable = {};
|
|
508
|
+
const localVariantsHashTable = {};
|
|
509
|
+
const localVariantsObjectTable = {};
|
|
433
510
|
for (const node of ast.body) {
|
|
434
511
|
let declarations = [];
|
|
435
512
|
if (exports.t.isVariableDeclaration(node)) {
|
|
@@ -452,33 +529,54 @@ function scanAll(addDependency) {
|
|
|
452
529
|
const method = decl.init.callee.property.value;
|
|
453
530
|
const name = decl.id.value;
|
|
454
531
|
const init = decl.init;
|
|
455
|
-
const
|
|
532
|
+
const resolveVariable = (name) => {
|
|
533
|
+
const hash = localCreateHashTable[name];
|
|
534
|
+
if (hash && localCreateObjectTable[hash]) {
|
|
535
|
+
return localCreateObjectTable[hash];
|
|
536
|
+
}
|
|
537
|
+
return undefined;
|
|
538
|
+
};
|
|
539
|
+
const obj = objectExpressionToObject(init.arguments[0].expression, localStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localThemeTable, localCreateHashTable, localVariantsHashTable, resolveVariable);
|
|
456
540
|
const uniqueKey = `${filePath}-${name}`;
|
|
457
541
|
if (method === 'createStatic') {
|
|
458
542
|
localStaticTable[name] = obj;
|
|
459
|
-
|
|
543
|
+
localTables.staticTable[uniqueKey] = obj;
|
|
460
544
|
}
|
|
461
545
|
else if (method === 'keyframes') {
|
|
462
546
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
463
547
|
localKeyframesHashTable[name] = hash;
|
|
464
|
-
|
|
465
|
-
|
|
548
|
+
localTables.keyframesHashTable[uniqueKey] = hash;
|
|
549
|
+
localTables.keyframesObjectTable[hash] = obj;
|
|
466
550
|
localKeyframesObjectTable[hash] = obj;
|
|
467
551
|
}
|
|
468
552
|
else if (method === 'viewTransition') {
|
|
469
553
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
470
554
|
localViewTransitionHashTable[name] = hash;
|
|
471
|
-
|
|
472
|
-
|
|
555
|
+
localTables.viewTransitionHashTable[uniqueKey] = hash;
|
|
556
|
+
localTables.viewTransitionObjectTable[hash] = obj;
|
|
473
557
|
localViewTransitionObjectTable[hash] = obj;
|
|
474
558
|
}
|
|
475
559
|
else if (method === 'createTheme') {
|
|
476
560
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
477
561
|
localThemeTable[name] = obj;
|
|
478
|
-
|
|
479
|
-
|
|
562
|
+
localTables.themeTable[uniqueKey] = obj;
|
|
563
|
+
localTables.createThemeObjectTable[hash] = obj;
|
|
480
564
|
localCreateThemeObjectTable[hash] = obj;
|
|
481
565
|
}
|
|
566
|
+
else if (method === 'create') {
|
|
567
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
568
|
+
localCreateHashTable[name] = hash;
|
|
569
|
+
localTables.createHashTable[uniqueKey] = hash;
|
|
570
|
+
localTables.createObjectTable[hash] = obj;
|
|
571
|
+
localCreateObjectTable[hash] = obj;
|
|
572
|
+
}
|
|
573
|
+
else if (method === 'variants') {
|
|
574
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
575
|
+
localVariantsHashTable[name] = hash;
|
|
576
|
+
localTables.variantsHashTable[uniqueKey] = hash;
|
|
577
|
+
localTables.variantsObjectTable[hash] = obj;
|
|
578
|
+
localVariantsObjectTable[hash] = obj;
|
|
579
|
+
}
|
|
482
580
|
}
|
|
483
581
|
}
|
|
484
582
|
}
|
|
@@ -491,20 +589,25 @@ function scanAll(addDependency) {
|
|
|
491
589
|
viewTransitionObjectTable: localViewTransitionObjectTable,
|
|
492
590
|
themeTable: localThemeTable,
|
|
493
591
|
createThemeObjectTable: localCreateThemeObjectTable,
|
|
592
|
+
createHashTable: localCreateHashTable,
|
|
593
|
+
createObjectTable: localCreateObjectTable,
|
|
594
|
+
variantsHashTable: localVariantsHashTable,
|
|
595
|
+
variantsObjectTable: localVariantsObjectTable,
|
|
494
596
|
hasCssUsage: true,
|
|
495
597
|
};
|
|
496
598
|
}
|
|
497
599
|
catch (e) {
|
|
498
600
|
}
|
|
499
601
|
}
|
|
500
|
-
return
|
|
602
|
+
return localTables;
|
|
501
603
|
}
|
|
502
|
-
function extractOndemandStyles(obj, extractedSheets) {
|
|
604
|
+
function extractOndemandStyles(obj, extractedSheets, t = exports.tables) {
|
|
503
605
|
if (!obj || typeof obj !== 'object')
|
|
504
606
|
return;
|
|
505
607
|
const visited = new Set();
|
|
506
608
|
const keyframesHashes = new Set();
|
|
507
609
|
const viewTransitionHashes = new Set();
|
|
610
|
+
const createHashes = new Set();
|
|
508
611
|
let needsTheme = false;
|
|
509
612
|
function walk(n) {
|
|
510
613
|
if (!n || typeof n !== 'object' || visited.has(n))
|
|
@@ -518,6 +621,9 @@ function extractOndemandStyles(obj, extractedSheets) {
|
|
|
518
621
|
else if (val.startsWith('vt-')) {
|
|
519
622
|
viewTransitionHashes.add(val.slice(3));
|
|
520
623
|
}
|
|
624
|
+
else if (val.startsWith('cr-')) {
|
|
625
|
+
createHashes.add(val.slice(3));
|
|
626
|
+
}
|
|
521
627
|
else if (!needsTheme && val.includes('var(--')) {
|
|
522
628
|
needsTheme = true;
|
|
523
629
|
}
|
|
@@ -537,7 +643,7 @@ function extractOndemandStyles(obj, extractedSheets) {
|
|
|
537
643
|
};
|
|
538
644
|
if (keyframesHashes.size > 0) {
|
|
539
645
|
for (const hash of keyframesHashes) {
|
|
540
|
-
const definition =
|
|
646
|
+
const definition = t.keyframesObjectTable[hash];
|
|
541
647
|
if (definition) {
|
|
542
648
|
const { styleSheet } = (0, zss_engine_1.transpile)({ [`@keyframes kf-${hash}`]: definition }, undefined, '--global');
|
|
543
649
|
addSheet(styleSheet);
|
|
@@ -546,18 +652,29 @@ function extractOndemandStyles(obj, extractedSheets) {
|
|
|
546
652
|
}
|
|
547
653
|
if (viewTransitionHashes.size > 0) {
|
|
548
654
|
for (const hash of viewTransitionHashes) {
|
|
549
|
-
const obj =
|
|
655
|
+
const obj = t.viewTransitionObjectTable[hash];
|
|
550
656
|
if (obj) {
|
|
551
657
|
const { styleSheet } = (0, zss_engine_1.transpile)((0, viewTransition_1.createViewTransition)(obj, hash), undefined, '--global');
|
|
552
658
|
addSheet(styleSheet);
|
|
553
659
|
}
|
|
554
660
|
}
|
|
555
661
|
}
|
|
662
|
+
if (createHashes.size > 0) {
|
|
663
|
+
for (const hash of createHashes) {
|
|
664
|
+
const obj = t.createObjectTable[hash];
|
|
665
|
+
if (obj) {
|
|
666
|
+
Object.entries(obj).forEach(([key, style]) => {
|
|
667
|
+
const records = (0, create_1.getStyleRecords)(key, style, 2);
|
|
668
|
+
records.forEach((r) => addSheet(r.sheet));
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
556
673
|
if (needsTheme) {
|
|
557
|
-
for (const themeVarName in
|
|
558
|
-
const themeObj =
|
|
674
|
+
for (const themeVarName in t.themeTable) {
|
|
675
|
+
const themeObj = t.themeTable[themeVarName];
|
|
559
676
|
const hash = (0, zss_engine_1.genBase36Hash)(themeObj, 1, 8);
|
|
560
|
-
const definition =
|
|
677
|
+
const definition = t.createThemeObjectTable[hash];
|
|
561
678
|
if (definition && typeof definition === 'object') {
|
|
562
679
|
const styles = (0, createTheme_1.createTheme)(definition);
|
|
563
680
|
const { styleSheet } = (0, zss_engine_1.transpile)(styles, undefined, '--global');
|
package/dist/resolver.js
CHANGED
|
@@ -6,26 +6,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.resolveImportPath = resolveImportPath;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const tsConfigCache = new Map();
|
|
10
|
+
const tsConfigPathCache = new Map();
|
|
11
|
+
function getTsConfig(startDir) {
|
|
12
|
+
let currentDir = startDir;
|
|
13
|
+
if (tsConfigPathCache.has(currentDir)) {
|
|
14
|
+
const cachedPath = tsConfigPathCache.get(currentDir);
|
|
15
|
+
if (cachedPath === null)
|
|
16
|
+
return null;
|
|
17
|
+
return {
|
|
18
|
+
config: tsConfigCache.get(cachedPath) ?? null,
|
|
19
|
+
basePath: path_1.default.dirname(cachedPath),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
14
22
|
while (currentDir !== path_1.default.parse(currentDir).root) {
|
|
15
23
|
const tsConfigPath = path_1.default.join(currentDir, 'tsconfig.json');
|
|
16
24
|
if (fs_1.default.existsSync(tsConfigPath)) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
if (!tsConfigCache.has(tsConfigPath)) {
|
|
26
|
+
try {
|
|
27
|
+
const config = require(tsConfigPath);
|
|
28
|
+
tsConfigCache.set(tsConfigPath, config.compilerOptions || null);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
tsConfigCache.set(tsConfigPath, null);
|
|
32
|
+
}
|
|
24
33
|
}
|
|
34
|
+
tsConfigPathCache.set(startDir, tsConfigPath);
|
|
35
|
+
return {
|
|
36
|
+
config: tsConfigCache.get(tsConfigPath) ?? null,
|
|
37
|
+
basePath: currentDir,
|
|
38
|
+
};
|
|
25
39
|
}
|
|
26
40
|
currentDir = path_1.default.dirname(currentDir);
|
|
27
41
|
}
|
|
28
|
-
|
|
42
|
+
tsConfigPathCache.set(startDir, null);
|
|
29
43
|
return null;
|
|
30
44
|
}
|
|
31
45
|
const extensions = [
|
|
@@ -52,9 +66,10 @@ function resolveImportPath(importPath, importerPath) {
|
|
|
52
66
|
if (importPath.startsWith('.')) {
|
|
53
67
|
return resolveWithExtension(path_1.default.resolve(path_1.default.dirname(importerPath), importPath));
|
|
54
68
|
}
|
|
55
|
-
const
|
|
69
|
+
const tsConfig = getTsConfig(path_1.default.dirname(importerPath));
|
|
70
|
+
const config = tsConfig?.config;
|
|
56
71
|
if (config?.paths) {
|
|
57
|
-
const root =
|
|
72
|
+
const root = tsConfig.basePath;
|
|
58
73
|
for (const [alias, targets] of Object.entries(config.paths)) {
|
|
59
74
|
const prefix = alias.replace(/\*$/, '');
|
|
60
75
|
if (importPath.startsWith(prefix)) {
|
package/dist/types.d.ts
CHANGED
|
@@ -4,13 +4,17 @@ export type CSSValue = CSSPrimitive | CSSObject | ParseErrorString;
|
|
|
4
4
|
export type CSSObject = {
|
|
5
5
|
[key: string]: CSSValue;
|
|
6
6
|
};
|
|
7
|
-
export type StaticTable = Record<string,
|
|
7
|
+
export type StaticTable = Record<string, CSSValue>;
|
|
8
8
|
export type ThemeTable = Record<string, CSSObject>;
|
|
9
9
|
export type KeyframesHashTable = Record<string, string>;
|
|
10
10
|
export type KeyframesObjectTable = Record<string, CSSObject>;
|
|
11
11
|
export type ViewTransitionHashTable = Record<string, string>;
|
|
12
12
|
export type ViewTransitionObjectTable = Record<string, CSSObject>;
|
|
13
13
|
export type CreateThemeObjectTable = Record<string, CSSObject>;
|
|
14
|
+
export type CreateHashTable = Record<string, string>;
|
|
15
|
+
export type CreateObjectTable = Record<string, CSSObject>;
|
|
16
|
+
export type VariantsHashTable = Record<string, string>;
|
|
17
|
+
export type VariantsObjectTable = Record<string, CSSObject>;
|
|
14
18
|
export interface Tables {
|
|
15
19
|
staticTable: StaticTable;
|
|
16
20
|
themeTable: ThemeTable;
|
|
@@ -19,6 +23,10 @@ export interface Tables {
|
|
|
19
23
|
viewTransitionHashTable: ViewTransitionHashTable;
|
|
20
24
|
viewTransitionObjectTable: ViewTransitionObjectTable;
|
|
21
25
|
createThemeObjectTable: CreateThemeObjectTable;
|
|
26
|
+
createHashTable: CreateHashTable;
|
|
27
|
+
createObjectTable: CreateObjectTable;
|
|
28
|
+
variantsHashTable: VariantsHashTable;
|
|
29
|
+
variantsObjectTable: VariantsObjectTable;
|
|
22
30
|
}
|
|
23
31
|
export interface FileStyles {
|
|
24
32
|
baseStyles?: string;
|