@plumeria/utils 6.1.0 → 6.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -2
- package/dist/parser.js +48 -4
- package/dist/types.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { CSSObject, FileStyles, StaticTable, ThemeTable, KeyframesHashTable, KeyframesObjectTable, ViewTransitionHashTable, ViewTransitionObjectTable, CreateThemeObjectTable, CreateHashTable, CreateObjectTable, VariantsHashTable, VariantsObjectTable, } from './types';
|
|
2
|
-
export { objectExpressionToObject, collectLocalConsts, traverse, t,
|
|
2
|
+
export { objectExpressionToObject, collectLocalConsts, traverse, t, extractOndemandStyles, deepMerge, scanAll, } from './parser';
|
|
3
3
|
export { getStyleRecords } from './create';
|
|
4
4
|
export type { StyleRecord } from './create';
|
|
5
5
|
export { resolveImportPath } from './resolver';
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveImportPath = exports.getStyleRecords = exports.scanAll = exports.deepMerge = exports.extractOndemandStyles = exports.
|
|
3
|
+
exports.resolveImportPath = 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; } });
|
|
7
7
|
Object.defineProperty(exports, "traverse", { enumerable: true, get: function () { return parser_1.traverse; } });
|
|
8
8
|
Object.defineProperty(exports, "t", { enumerable: true, get: function () { return parser_1.t; } });
|
|
9
|
-
Object.defineProperty(exports, "tables", { enumerable: true, get: function () { return parser_1.tables; } });
|
|
10
9
|
Object.defineProperty(exports, "extractOndemandStyles", { enumerable: true, get: function () { return parser_1.extractOndemandStyles; } });
|
|
11
10
|
Object.defineProperty(exports, "deepMerge", { enumerable: true, get: function () { return parser_1.deepMerge; } });
|
|
12
11
|
Object.defineProperty(exports, "scanAll", { enumerable: true, get: function () { return parser_1.scanAll; } });
|
package/dist/parser.js
CHANGED
|
@@ -86,6 +86,7 @@ exports.tables = {
|
|
|
86
86
|
createThemeObjectTable: {},
|
|
87
87
|
createHashTable: {},
|
|
88
88
|
createObjectTable: {},
|
|
89
|
+
createAtomicMapTable: {},
|
|
89
90
|
variantsHashTable: {},
|
|
90
91
|
variantsObjectTable: {},
|
|
91
92
|
};
|
|
@@ -211,10 +212,6 @@ function collectLocalConsts(ast) {
|
|
|
211
212
|
}
|
|
212
213
|
function getPropertyKey(node, staticTable, keyframesHashTable, viewTransitionHashTable, themeTable) {
|
|
213
214
|
if (exports.t.isIdentifier(node)) {
|
|
214
|
-
if (staticTable[node.value] &&
|
|
215
|
-
typeof staticTable[node.value] === 'string') {
|
|
216
|
-
return staticTable[node.value];
|
|
217
|
-
}
|
|
218
215
|
return node.value;
|
|
219
216
|
}
|
|
220
217
|
if (exports.t.isStringLiteral(node)) {
|
|
@@ -416,10 +413,13 @@ function scanAll() {
|
|
|
416
413
|
createThemeObjectTable: {},
|
|
417
414
|
createHashTable: {},
|
|
418
415
|
createObjectTable: {},
|
|
416
|
+
createAtomicMapTable: {},
|
|
419
417
|
variantsHashTable: {},
|
|
420
418
|
variantsObjectTable: {},
|
|
419
|
+
extractedSheet: '',
|
|
421
420
|
};
|
|
422
421
|
const files = fs_1.default.globSync(PATTERN_PATH, GLOB_OPTIONS);
|
|
422
|
+
const totalExtractedSheets = [];
|
|
423
423
|
for (const filePath of files) {
|
|
424
424
|
try {
|
|
425
425
|
const stats = fs_1.default.statSync(filePath);
|
|
@@ -461,6 +461,10 @@ function scanAll() {
|
|
|
461
461
|
for (const key of Object.keys(cached.createObjectTable)) {
|
|
462
462
|
localTables.createObjectTable[key] = cached.createObjectTable[key];
|
|
463
463
|
}
|
|
464
|
+
for (const key of Object.keys(cached.createAtomicMapTable)) {
|
|
465
|
+
localTables.createAtomicMapTable[key] =
|
|
466
|
+
cached.createAtomicMapTable[key];
|
|
467
|
+
}
|
|
464
468
|
for (const key of Object.keys(cached.variantsHashTable)) {
|
|
465
469
|
localTables.variantsHashTable[`${filePath}-${key}`] =
|
|
466
470
|
cached.variantsHashTable[key];
|
|
@@ -469,6 +473,9 @@ function scanAll() {
|
|
|
469
473
|
localTables.variantsObjectTable[key] =
|
|
470
474
|
cached.variantsObjectTable[key];
|
|
471
475
|
}
|
|
476
|
+
if (cached.extractedSheet) {
|
|
477
|
+
totalExtractedSheets.push(cached.extractedSheet);
|
|
478
|
+
}
|
|
472
479
|
}
|
|
473
480
|
continue;
|
|
474
481
|
}
|
|
@@ -485,9 +492,11 @@ function scanAll() {
|
|
|
485
492
|
createThemeObjectTable: {},
|
|
486
493
|
createHashTable: {},
|
|
487
494
|
createObjectTable: {},
|
|
495
|
+
createAtomicMapTable: {},
|
|
488
496
|
variantsHashTable: {},
|
|
489
497
|
variantsObjectTable: {},
|
|
490
498
|
hasCssUsage: false,
|
|
499
|
+
extractedSheet: '',
|
|
491
500
|
};
|
|
492
501
|
continue;
|
|
493
502
|
}
|
|
@@ -505,9 +514,12 @@ function scanAll() {
|
|
|
505
514
|
const localCreateThemeObjectTable = {};
|
|
506
515
|
const localCreateHashTable = {};
|
|
507
516
|
const localCreateObjectTable = {};
|
|
517
|
+
const localCreateAtomicMapTable = {};
|
|
508
518
|
const localVariantsHashTable = {};
|
|
509
519
|
const localVariantsObjectTable = {};
|
|
510
520
|
const plumeriaAliases = {};
|
|
521
|
+
const fileExtractedSheets = [];
|
|
522
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
511
523
|
for (const node of ast.body) {
|
|
512
524
|
if (node.type === 'ImportDeclaration') {
|
|
513
525
|
const sourceValue = node.source.value;
|
|
@@ -591,14 +603,23 @@ function scanAll() {
|
|
|
591
603
|
localKeyframesHashTable[name] = hash;
|
|
592
604
|
localTables.keyframesHashTable[uniqueKey] = hash;
|
|
593
605
|
localTables.keyframesObjectTable[hash] = obj;
|
|
606
|
+
localTables.keyframesObjectTable[hash] = obj;
|
|
594
607
|
localKeyframesObjectTable[hash] = obj;
|
|
608
|
+
if (!isProduction) {
|
|
609
|
+
extractOndemandStyles({ kf: `kf-${hash}` }, fileExtractedSheets, localTables);
|
|
610
|
+
}
|
|
595
611
|
}
|
|
596
612
|
else if (method === 'viewTransition') {
|
|
597
613
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
598
614
|
localViewTransitionHashTable[name] = hash;
|
|
599
615
|
localTables.viewTransitionHashTable[uniqueKey] = hash;
|
|
600
616
|
localTables.viewTransitionObjectTable[hash] = obj;
|
|
617
|
+
localTables.viewTransitionObjectTable[hash] = obj;
|
|
601
618
|
localViewTransitionObjectTable[hash] = obj;
|
|
619
|
+
if (!isProduction) {
|
|
620
|
+
extractOndemandStyles(obj, fileExtractedSheets, localTables);
|
|
621
|
+
extractOndemandStyles({ vt: `vt-${hash}` }, fileExtractedSheets, localTables);
|
|
622
|
+
}
|
|
602
623
|
}
|
|
603
624
|
else if (method === 'createTheme') {
|
|
604
625
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
@@ -613,6 +634,23 @@ function scanAll() {
|
|
|
613
634
|
localTables.createHashTable[uniqueKey] = hash;
|
|
614
635
|
localTables.createObjectTable[hash] = obj;
|
|
615
636
|
localCreateObjectTable[hash] = obj;
|
|
637
|
+
const hashMap = {};
|
|
638
|
+
Object.entries(obj).forEach(([key, style]) => {
|
|
639
|
+
const records = (0, create_1.getStyleRecords)(key, style, 2);
|
|
640
|
+
const atomMap = {};
|
|
641
|
+
records.forEach((r) => (atomMap[r.key] = r.hash));
|
|
642
|
+
hashMap[key] = atomMap;
|
|
643
|
+
if (!isProduction) {
|
|
644
|
+
extractOndemandStyles(style, fileExtractedSheets, localTables);
|
|
645
|
+
records.forEach((r) => {
|
|
646
|
+
if (!fileExtractedSheets.includes(r.sheet)) {
|
|
647
|
+
fileExtractedSheets.push(r.sheet);
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
localCreateAtomicMapTable[hash] = hashMap;
|
|
653
|
+
localTables.createAtomicMapTable[hash] = hashMap;
|
|
616
654
|
}
|
|
617
655
|
else if (method === 'variants') {
|
|
618
656
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
@@ -636,14 +674,20 @@ function scanAll() {
|
|
|
636
674
|
createThemeObjectTable: localCreateThemeObjectTable,
|
|
637
675
|
createHashTable: localCreateHashTable,
|
|
638
676
|
createObjectTable: localCreateObjectTable,
|
|
677
|
+
createAtomicMapTable: localCreateAtomicMapTable,
|
|
639
678
|
variantsHashTable: localVariantsHashTable,
|
|
640
679
|
variantsObjectTable: localVariantsObjectTable,
|
|
641
680
|
hasCssUsage: true,
|
|
681
|
+
extractedSheet: fileExtractedSheets.join(''),
|
|
642
682
|
};
|
|
683
|
+
if (fileExtractedSheets.length > 0) {
|
|
684
|
+
totalExtractedSheets.push(fileExtractedSheets.join(''));
|
|
685
|
+
}
|
|
643
686
|
}
|
|
644
687
|
catch (e) {
|
|
645
688
|
}
|
|
646
689
|
}
|
|
690
|
+
localTables.extractedSheet = totalExtractedSheets.join('');
|
|
647
691
|
return localTables;
|
|
648
692
|
}
|
|
649
693
|
function extractOndemandStyles(obj, extractedSheets, t = exports.tables) {
|
package/dist/types.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type CreateHashTable = Record<string, string>;
|
|
|
15
15
|
export type CreateObjectTable = Record<string, CSSObject>;
|
|
16
16
|
export type VariantsHashTable = Record<string, string>;
|
|
17
17
|
export type VariantsObjectTable = Record<string, CSSObject>;
|
|
18
|
+
export type CreateAtomicMapTable = Record<string, Record<string, Record<string, string>>>;
|
|
18
19
|
export interface Tables {
|
|
19
20
|
staticTable: StaticTable;
|
|
20
21
|
themeTable: ThemeTable;
|
|
@@ -25,8 +26,10 @@ export interface Tables {
|
|
|
25
26
|
createThemeObjectTable: CreateThemeObjectTable;
|
|
26
27
|
createHashTable: CreateHashTable;
|
|
27
28
|
createObjectTable: CreateObjectTable;
|
|
29
|
+
createAtomicMapTable: CreateAtomicMapTable;
|
|
28
30
|
variantsHashTable: VariantsHashTable;
|
|
29
31
|
variantsObjectTable: VariantsObjectTable;
|
|
32
|
+
extractedSheet?: string;
|
|
30
33
|
}
|
|
31
34
|
export interface FileStyles {
|
|
32
35
|
baseStyles?: string;
|