@plumeria/utils 6.0.2 → 6.1.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 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, tables, extractOndemandStyles, deepMerge, scanAll, } from './parser';
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.tables = exports.t = exports.traverse = exports.collectLocalConsts = exports.objectExpressionToObject = void 0;
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,11 +473,14 @@ 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
  }
475
482
  const source = fs_1.default.readFileSync(filePath, 'utf8');
476
- if (!source.includes('css.')) {
483
+ if (!source.includes('@plumeria/core')) {
477
484
  fileCache[filePath] = {
478
485
  mtimeMs: stats.mtimeMs,
479
486
  staticTable: {},
@@ -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,8 +514,38 @@ 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 = {};
520
+ const plumeriaAliases = {};
521
+ const fileExtractedSheets = [];
522
+ const isProduction = process.env.NODE_ENV === 'production';
523
+ for (const node of ast.body) {
524
+ if (node.type === 'ImportDeclaration') {
525
+ const sourceValue = node.source.value;
526
+ if (sourceValue === '@plumeria/core') {
527
+ node.specifiers.forEach((specifier) => {
528
+ if (specifier.type === 'ImportNamespaceSpecifier') {
529
+ if (specifier.local) {
530
+ plumeriaAliases[specifier.local.value] = 'NAMESPACE';
531
+ }
532
+ }
533
+ else if (specifier.type === 'ImportSpecifier') {
534
+ const importedName = specifier.imported
535
+ ? specifier.imported.value
536
+ : specifier.local.value;
537
+ const localName = specifier.local.value;
538
+ plumeriaAliases[localName] = importedName;
539
+ }
540
+ else if (specifier.type === 'ImportDefaultSpecifier') {
541
+ if (specifier.local) {
542
+ plumeriaAliases[specifier.local.value] = 'NAMESPACE';
543
+ }
544
+ }
545
+ });
546
+ }
547
+ }
548
+ }
510
549
  for (const node of ast.body) {
511
550
  let declarations = [];
512
551
  if (exports.t.isVariableDeclaration(node)) {
@@ -521,61 +560,105 @@ function scanAll() {
521
560
  exports.t.isIdentifier(decl.id) &&
522
561
  decl.init &&
523
562
  exports.t.isCallExpression(decl.init) &&
524
- exports.t.isMemberExpression(decl.init.callee) &&
525
- exports.t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
526
- exports.t.isIdentifier(decl.init.callee.property) &&
527
- decl.init.arguments.length > 0 &&
528
- exports.t.isObjectExpression(decl.init.arguments[0].expression)) {
529
- const method = decl.init.callee.property.value;
530
- const name = decl.id.value;
531
- const init = decl.init;
532
- const resolveVariable = (name) => {
533
- const hash = localCreateHashTable[name];
534
- if (hash && localCreateObjectTable[hash]) {
535
- return localCreateObjectTable[hash];
563
+ exports.t.isCallExpression(decl.init)) {
564
+ const callee = decl.init.callee;
565
+ let method;
566
+ if (exports.t.isMemberExpression(callee) &&
567
+ exports.t.isIdentifier(callee.object) &&
568
+ exports.t.isIdentifier(callee.property)) {
569
+ const objectName = callee.object.value;
570
+ const propertyName = callee.property.value;
571
+ const alias = plumeriaAliases[objectName];
572
+ if (alias === 'NAMESPACE' || objectName === 'css') {
573
+ method = propertyName;
536
574
  }
537
- return undefined;
538
- };
539
- const obj = objectExpressionToObject(init.arguments[0].expression, localStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localThemeTable, localCreateHashTable, localVariantsHashTable, resolveVariable);
540
- const uniqueKey = `${filePath}-${name}`;
541
- if (method === 'createStatic') {
542
- localStaticTable[name] = obj;
543
- localTables.staticTable[uniqueKey] = obj;
544
575
  }
545
- else if (method === 'keyframes') {
546
- const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
547
- localKeyframesHashTable[name] = hash;
548
- localTables.keyframesHashTable[uniqueKey] = hash;
549
- localTables.keyframesObjectTable[hash] = obj;
550
- localKeyframesObjectTable[hash] = obj;
551
- }
552
- else if (method === 'viewTransition') {
553
- const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
554
- localViewTransitionHashTable[name] = hash;
555
- localTables.viewTransitionHashTable[uniqueKey] = hash;
556
- localTables.viewTransitionObjectTable[hash] = obj;
557
- localViewTransitionObjectTable[hash] = obj;
558
- }
559
- else if (method === 'createTheme') {
560
- const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
561
- localThemeTable[name] = obj;
562
- localTables.themeTable[uniqueKey] = obj;
563
- localTables.createThemeObjectTable[hash] = obj;
564
- localCreateThemeObjectTable[hash] = obj;
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;
576
+ else if (exports.t.isIdentifier(callee)) {
577
+ const calleeName = callee.value;
578
+ const originalName = plumeriaAliases[calleeName];
579
+ if (originalName) {
580
+ method = originalName;
581
+ }
572
582
  }
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;
583
+ if (method &&
584
+ decl.init.arguments.length > 0 &&
585
+ exports.t.isObjectExpression(decl.init.arguments[0].expression)) {
586
+ const name = decl.id.value;
587
+ const init = decl.init;
588
+ const resolveVariable = (name) => {
589
+ const hash = localCreateHashTable[name];
590
+ if (hash && localCreateObjectTable[hash]) {
591
+ return localCreateObjectTable[hash];
592
+ }
593
+ return undefined;
594
+ };
595
+ const obj = objectExpressionToObject(init.arguments[0].expression, localStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localThemeTable, localCreateHashTable, localVariantsHashTable, resolveVariable);
596
+ const uniqueKey = `${filePath}-${name}`;
597
+ if (method === 'createStatic') {
598
+ localStaticTable[name] = obj;
599
+ localTables.staticTable[uniqueKey] = obj;
600
+ }
601
+ else if (method === 'keyframes') {
602
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
603
+ localKeyframesHashTable[name] = hash;
604
+ localTables.keyframesHashTable[uniqueKey] = hash;
605
+ localTables.keyframesObjectTable[hash] = obj;
606
+ localTables.keyframesObjectTable[hash] = obj;
607
+ localKeyframesObjectTable[hash] = obj;
608
+ if (!isProduction) {
609
+ extractOndemandStyles({ kf: `kf-${hash}` }, fileExtractedSheets, localTables);
610
+ }
611
+ }
612
+ else if (method === 'viewTransition') {
613
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
614
+ localViewTransitionHashTable[name] = hash;
615
+ localTables.viewTransitionHashTable[uniqueKey] = hash;
616
+ localTables.viewTransitionObjectTable[hash] = obj;
617
+ localTables.viewTransitionObjectTable[hash] = obj;
618
+ localViewTransitionObjectTable[hash] = obj;
619
+ if (!isProduction) {
620
+ extractOndemandStyles(obj, fileExtractedSheets, localTables);
621
+ extractOndemandStyles({ vt: `vt-${hash}` }, fileExtractedSheets, localTables);
622
+ }
623
+ }
624
+ else if (method === 'createTheme') {
625
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
626
+ localThemeTable[name] = obj;
627
+ localTables.themeTable[uniqueKey] = obj;
628
+ localTables.createThemeObjectTable[hash] = obj;
629
+ localCreateThemeObjectTable[hash] = obj;
630
+ }
631
+ else if (method === 'create') {
632
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
633
+ localCreateHashTable[name] = hash;
634
+ localTables.createHashTable[uniqueKey] = hash;
635
+ localTables.createObjectTable[hash] = obj;
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;
654
+ }
655
+ else if (method === 'variants') {
656
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
657
+ localVariantsHashTable[name] = hash;
658
+ localTables.variantsHashTable[uniqueKey] = hash;
659
+ localTables.variantsObjectTable[hash] = obj;
660
+ localVariantsObjectTable[hash] = obj;
661
+ }
579
662
  }
580
663
  }
581
664
  }
@@ -591,14 +674,20 @@ function scanAll() {
591
674
  createThemeObjectTable: localCreateThemeObjectTable,
592
675
  createHashTable: localCreateHashTable,
593
676
  createObjectTable: localCreateObjectTable,
677
+ createAtomicMapTable: localCreateAtomicMapTable,
594
678
  variantsHashTable: localVariantsHashTable,
595
679
  variantsObjectTable: localVariantsObjectTable,
596
680
  hasCssUsage: true,
681
+ extractedSheet: fileExtractedSheets.join(''),
597
682
  };
683
+ if (fileExtractedSheets.length > 0) {
684
+ totalExtractedSheets.push(fileExtractedSheets.join(''));
685
+ }
598
686
  }
599
687
  catch (e) {
600
688
  }
601
689
  }
690
+ localTables.extractedSheet = totalExtractedSheets.join('');
602
691
  return localTables;
603
692
  }
604
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/utils",
3
- "version": "6.0.2",
3
+ "version": "6.1.1",
4
4
  "description": "Plumeria Utils",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",