@plumeria/utils 5.0.0 → 6.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/parser.d.ts +4 -4
- package/dist/parser.js +164 -39
- 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, StaticTable, KeyframesHashTable,
|
|
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,20 +405,20 @@ function resolveThemeTableMemberExpressionByNode(node, themeTable) {
|
|
|
360
405
|
return undefined;
|
|
361
406
|
}
|
|
362
407
|
const fileCache = {};
|
|
363
|
-
function
|
|
364
|
-
const
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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
|
+
};
|
|
377
422
|
const files = fs_1.default.globSync(PATTERN_PATH, GLOB_OPTIONS);
|
|
378
423
|
for (const filePath of files) {
|
|
379
424
|
try {
|
|
@@ -381,24 +426,49 @@ function scanAll(addDependency) {
|
|
|
381
426
|
const cached = fileCache[filePath];
|
|
382
427
|
if (cached && cached.mtimeMs === stats.mtimeMs) {
|
|
383
428
|
if (cached.hasCssUsage) {
|
|
384
|
-
addDependency(filePath);
|
|
385
429
|
for (const key of Object.keys(cached.staticTable)) {
|
|
386
|
-
|
|
430
|
+
localTables.staticTable[`${filePath}-${key}`] =
|
|
431
|
+
cached.staticTable[key];
|
|
387
432
|
}
|
|
388
433
|
for (const key of Object.keys(cached.keyframesHashTable)) {
|
|
389
|
-
|
|
434
|
+
localTables.keyframesHashTable[`${filePath}-${key}`] =
|
|
435
|
+
cached.keyframesHashTable[key];
|
|
436
|
+
}
|
|
437
|
+
for (const key of Object.keys(cached.keyframesObjectTable)) {
|
|
438
|
+
localTables.keyframesObjectTable[key] =
|
|
439
|
+
cached.keyframesObjectTable[key];
|
|
390
440
|
}
|
|
391
441
|
for (const key of Object.keys(cached.viewTransitionHashTable)) {
|
|
392
|
-
|
|
442
|
+
localTables.viewTransitionHashTable[`${filePath}-${key}`] =
|
|
393
443
|
cached.viewTransitionHashTable[key];
|
|
394
444
|
}
|
|
445
|
+
for (const key of Object.keys(cached.viewTransitionObjectTable)) {
|
|
446
|
+
localTables.viewTransitionObjectTable[key] =
|
|
447
|
+
cached.viewTransitionObjectTable[key];
|
|
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
|
}
|
|
@@ -408,9 +478,15 @@ function scanAll(addDependency) {
|
|
|
408
478
|
mtimeMs: stats.mtimeMs,
|
|
409
479
|
staticTable: {},
|
|
410
480
|
keyframesHashTable: {},
|
|
481
|
+
keyframesObjectTable: {},
|
|
411
482
|
viewTransitionHashTable: {},
|
|
483
|
+
viewTransitionObjectTable: {},
|
|
412
484
|
themeTable: {},
|
|
413
485
|
createThemeObjectTable: {},
|
|
486
|
+
createHashTable: {},
|
|
487
|
+
createObjectTable: {},
|
|
488
|
+
variantsHashTable: {},
|
|
489
|
+
variantsObjectTable: {},
|
|
414
490
|
hasCssUsage: false,
|
|
415
491
|
};
|
|
416
492
|
continue;
|
|
@@ -420,12 +496,17 @@ function scanAll(addDependency) {
|
|
|
420
496
|
tsx: true,
|
|
421
497
|
target: 'es2022',
|
|
422
498
|
});
|
|
423
|
-
addDependency(filePath);
|
|
424
499
|
const localStaticTable = {};
|
|
425
500
|
const localKeyframesHashTable = {};
|
|
501
|
+
const localKeyframesObjectTable = {};
|
|
426
502
|
const localViewTransitionHashTable = {};
|
|
503
|
+
const localViewTransitionObjectTable = {};
|
|
427
504
|
const localThemeTable = {};
|
|
428
505
|
const localCreateThemeObjectTable = {};
|
|
506
|
+
const localCreateHashTable = {};
|
|
507
|
+
const localCreateObjectTable = {};
|
|
508
|
+
const localVariantsHashTable = {};
|
|
509
|
+
const localVariantsObjectTable = {};
|
|
429
510
|
for (const node of ast.body) {
|
|
430
511
|
let declarations = [];
|
|
431
512
|
if (exports.t.isVariableDeclaration(node)) {
|
|
@@ -448,31 +529,54 @@ function scanAll(addDependency) {
|
|
|
448
529
|
const method = decl.init.callee.property.value;
|
|
449
530
|
const name = decl.id.value;
|
|
450
531
|
const init = decl.init;
|
|
451
|
-
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);
|
|
452
540
|
const uniqueKey = `${filePath}-${name}`;
|
|
453
541
|
if (method === 'createStatic') {
|
|
454
542
|
localStaticTable[name] = obj;
|
|
455
|
-
|
|
543
|
+
localTables.staticTable[uniqueKey] = obj;
|
|
456
544
|
}
|
|
457
545
|
else if (method === 'keyframes') {
|
|
458
546
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
459
547
|
localKeyframesHashTable[name] = hash;
|
|
460
|
-
|
|
461
|
-
|
|
548
|
+
localTables.keyframesHashTable[uniqueKey] = hash;
|
|
549
|
+
localTables.keyframesObjectTable[hash] = obj;
|
|
550
|
+
localKeyframesObjectTable[hash] = obj;
|
|
462
551
|
}
|
|
463
552
|
else if (method === 'viewTransition') {
|
|
464
553
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
465
554
|
localViewTransitionHashTable[name] = hash;
|
|
466
|
-
|
|
467
|
-
|
|
555
|
+
localTables.viewTransitionHashTable[uniqueKey] = hash;
|
|
556
|
+
localTables.viewTransitionObjectTable[hash] = obj;
|
|
557
|
+
localViewTransitionObjectTable[hash] = obj;
|
|
468
558
|
}
|
|
469
559
|
else if (method === 'createTheme') {
|
|
470
560
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
471
561
|
localThemeTable[name] = obj;
|
|
472
|
-
|
|
473
|
-
|
|
562
|
+
localTables.themeTable[uniqueKey] = obj;
|
|
563
|
+
localTables.createThemeObjectTable[hash] = obj;
|
|
474
564
|
localCreateThemeObjectTable[hash] = obj;
|
|
475
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
|
+
}
|
|
476
580
|
}
|
|
477
581
|
}
|
|
478
582
|
}
|
|
@@ -480,23 +584,30 @@ function scanAll(addDependency) {
|
|
|
480
584
|
mtimeMs: stats.mtimeMs,
|
|
481
585
|
staticTable: localStaticTable,
|
|
482
586
|
keyframesHashTable: localKeyframesHashTable,
|
|
587
|
+
keyframesObjectTable: localKeyframesObjectTable,
|
|
483
588
|
viewTransitionHashTable: localViewTransitionHashTable,
|
|
589
|
+
viewTransitionObjectTable: localViewTransitionObjectTable,
|
|
484
590
|
themeTable: localThemeTable,
|
|
485
591
|
createThemeObjectTable: localCreateThemeObjectTable,
|
|
592
|
+
createHashTable: localCreateHashTable,
|
|
593
|
+
createObjectTable: localCreateObjectTable,
|
|
594
|
+
variantsHashTable: localVariantsHashTable,
|
|
595
|
+
variantsObjectTable: localVariantsObjectTable,
|
|
486
596
|
hasCssUsage: true,
|
|
487
597
|
};
|
|
488
598
|
}
|
|
489
599
|
catch (e) {
|
|
490
600
|
}
|
|
491
601
|
}
|
|
492
|
-
return
|
|
602
|
+
return localTables;
|
|
493
603
|
}
|
|
494
|
-
function extractOndemandStyles(obj, extractedSheets) {
|
|
604
|
+
function extractOndemandStyles(obj, extractedSheets, t = exports.tables) {
|
|
495
605
|
if (!obj || typeof obj !== 'object')
|
|
496
606
|
return;
|
|
497
607
|
const visited = new Set();
|
|
498
608
|
const keyframesHashes = new Set();
|
|
499
609
|
const viewTransitionHashes = new Set();
|
|
610
|
+
const createHashes = new Set();
|
|
500
611
|
let needsTheme = false;
|
|
501
612
|
function walk(n) {
|
|
502
613
|
if (!n || typeof n !== 'object' || visited.has(n))
|
|
@@ -510,6 +621,9 @@ function extractOndemandStyles(obj, extractedSheets) {
|
|
|
510
621
|
else if (val.startsWith('vt-')) {
|
|
511
622
|
viewTransitionHashes.add(val.slice(3));
|
|
512
623
|
}
|
|
624
|
+
else if (val.startsWith('cr-')) {
|
|
625
|
+
createHashes.add(val.slice(3));
|
|
626
|
+
}
|
|
513
627
|
else if (!needsTheme && val.includes('var(--')) {
|
|
514
628
|
needsTheme = true;
|
|
515
629
|
}
|
|
@@ -529,7 +643,7 @@ function extractOndemandStyles(obj, extractedSheets) {
|
|
|
529
643
|
};
|
|
530
644
|
if (keyframesHashes.size > 0) {
|
|
531
645
|
for (const hash of keyframesHashes) {
|
|
532
|
-
const definition =
|
|
646
|
+
const definition = t.keyframesObjectTable[hash];
|
|
533
647
|
if (definition) {
|
|
534
648
|
const { styleSheet } = (0, zss_engine_1.transpile)({ [`@keyframes kf-${hash}`]: definition }, undefined, '--global');
|
|
535
649
|
addSheet(styleSheet);
|
|
@@ -538,18 +652,29 @@ function extractOndemandStyles(obj, extractedSheets) {
|
|
|
538
652
|
}
|
|
539
653
|
if (viewTransitionHashes.size > 0) {
|
|
540
654
|
for (const hash of viewTransitionHashes) {
|
|
541
|
-
const obj =
|
|
655
|
+
const obj = t.viewTransitionObjectTable[hash];
|
|
542
656
|
if (obj) {
|
|
543
657
|
const { styleSheet } = (0, zss_engine_1.transpile)((0, viewTransition_1.createViewTransition)(obj, hash), undefined, '--global');
|
|
544
658
|
addSheet(styleSheet);
|
|
545
659
|
}
|
|
546
660
|
}
|
|
547
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
|
+
}
|
|
548
673
|
if (needsTheme) {
|
|
549
|
-
for (const themeVarName in
|
|
550
|
-
const themeObj =
|
|
674
|
+
for (const themeVarName in t.themeTable) {
|
|
675
|
+
const themeObj = t.themeTable[themeVarName];
|
|
551
676
|
const hash = (0, zss_engine_1.genBase36Hash)(themeObj, 1, 8);
|
|
552
|
-
const definition =
|
|
677
|
+
const definition = t.createThemeObjectTable[hash];
|
|
553
678
|
if (definition && typeof definition === 'object') {
|
|
554
679
|
const styles = (0, createTheme_1.createTheme)(definition);
|
|
555
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;
|