@yamada-ui/cli 1.1.2-dev-20240920162115 → 1.2.0-dev-20240921041020

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.
@@ -48,7 +48,6 @@ init_cjs_shims();
48
48
  var import_promises = require("fs/promises");
49
49
  var import_path3 = __toESM(require("path"));
50
50
  var p = __toESM(require("@clack/prompts"));
51
- var import_bundle_n_require = require("bundle-n-require");
52
51
 
53
52
  // ../../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/index.js
54
53
  init_cjs_shims();
@@ -548,12 +547,8 @@ var source_default = chalk;
548
547
  // src/command/tokens/index.ts
549
548
  var import_chokidar = __toESM(require("chokidar"));
550
549
 
551
- // src/command/tokens/create-theme-typings.ts
552
- init_cjs_shims();
553
-
554
550
  // src/utils/assertion.ts
555
551
  init_cjs_shims();
556
- var isString = (value) => Object.prototype.toString.call(value) === "[object String]";
557
552
  var isObject = (obj) => obj !== null && (typeof obj === "object" || typeof obj === "function") && !isArray(obj);
558
553
  var isArray = (value) => Array.isArray(value);
559
554
 
@@ -578,21 +573,54 @@ var prettier = async (content, options) => {
578
573
 
579
574
  // src/utils/object.ts
580
575
  init_cjs_shims();
581
- var omitObject = (obj, keys) => {
582
- const result = {};
583
- Object.keys(obj).forEach((key) => {
584
- if (keys.includes(key)) return;
585
- result[key] = obj[key];
576
+ var getObject = (obj, path4) => {
577
+ const keys = path4.split(".");
578
+ return keys.reduce((obj2, key) => obj2[key] ?? {}, obj);
579
+ };
580
+
581
+ // src/utils/module.ts
582
+ init_cjs_shims();
583
+ var import_fs = require("fs");
584
+ var import_vm = require("vm");
585
+ var import_esbuild = require("esbuild");
586
+ var import_node_eval = __toESM(require("node-eval"));
587
+ var getModule = async (file, cwd) => {
588
+ const result = await (0, import_esbuild.build)({
589
+ platform: "node",
590
+ format: "cjs",
591
+ mainFields: ["module", "main"],
592
+ absWorkingDir: cwd,
593
+ entryPoints: [file],
594
+ outfile: "out.js",
595
+ write: false,
596
+ bundle: true,
597
+ sourcemap: false,
598
+ metafile: true
586
599
  });
587
- return result;
600
+ const { text: code } = result.outputFiles[0];
601
+ const dependencies = result.metafile ? Object.keys(result.metafile.inputs) : [];
602
+ try {
603
+ const realFileName = import_fs.realpathSync.native(file);
604
+ const script = new import_vm.Script(code, { filename: realFileName });
605
+ const mod = { exports: {} };
606
+ const require2 = (id) => id === realFileName ? mod.exports : require2(id);
607
+ script.runInThisContext()(mod.exports, require2, mod);
608
+ return { mod, code, dependencies };
609
+ } catch {
610
+ const mod = (0, import_node_eval.default)(code);
611
+ return { mod, code, dependencies };
612
+ }
588
613
  };
589
614
 
615
+ // src/command/tokens/create-theme-typings.ts
616
+ init_cjs_shims();
617
+
590
618
  // src/command/tokens/config.ts
591
619
  init_cjs_shims();
592
620
  var config = [
593
621
  { key: "borders" },
594
- { key: "breakpoints", filter: (value) => Number.isNaN(Number(value)) },
595
- { key: "colors", maxScanDepth: 3 },
622
+ { key: "breakpoints" },
623
+ { key: "colors" },
596
624
  { key: "fonts" },
597
625
  { key: "fontSizes" },
598
626
  { key: "fontWeights" },
@@ -601,11 +629,14 @@ var config = [
601
629
  { key: "radii" },
602
630
  { key: "shadows" },
603
631
  { key: "blurs" },
604
- { key: "sizes", maxScanDepth: 2 },
632
+ { key: "sizes" },
605
633
  { key: "spaces", flatMap: (value) => [value, `-${value}`] },
606
634
  { key: "zIndices" },
607
635
  { key: "animations", omitScanKeys: ["keyframes"] },
608
- { key: "gradients" }
636
+ { key: "gradients" },
637
+ { key: "transitions.property", replaceKey: "transitionProperty" },
638
+ { key: "transitions.duration", replaceKey: "transitionDuration" },
639
+ { key: "transitions.easing", replaceKey: "transitionEasing" }
609
640
  ];
610
641
 
611
642
  // src/command/tokens/create-theme-typings.ts
@@ -631,31 +662,6 @@ var extractComponents = ({ components = {} }) => Object.entries(components).redu
631
662
  },
632
663
  {}
633
664
  );
634
- var extractTransitions = (theme) => {
635
- let transitionProperty = [];
636
- let transitionDuration = [];
637
- let transitionEasing = [];
638
- const { transitions, semantics } = theme;
639
- if (!isObject(transitions))
640
- return { transitionProperty, transitionDuration, transitionEasing };
641
- const { property, duration, easing } = semantics.transitions ?? {};
642
- Object.entries(transitions).forEach(([key, value]) => {
643
- switch (key) {
644
- case "property":
645
- transitionProperty = [...extractPaths(value), ...extractPaths(property)];
646
- break;
647
- case "duration":
648
- transitionDuration = [...extractPaths(value), ...extractPaths(duration)];
649
- break;
650
- case "easing":
651
- transitionEasing = [...extractPaths(value), ...extractPaths(easing)];
652
- break;
653
- default:
654
- return;
655
- }
656
- });
657
- return { transitionProperty, transitionDuration, transitionEasing };
658
- };
659
665
  var isTone = (value) => {
660
666
  if (!isObject(value)) return false;
661
667
  const keys = Object.keys(value);
@@ -663,75 +669,90 @@ var isTone = (value) => {
663
669
  };
664
670
  var extractColorSchemes = (theme) => {
665
671
  const { colors, semantics } = theme;
666
- const results = {
667
- colorSchemes: [],
668
- colorSchemeColors: []
669
- };
670
- if (!isObject(colors)) return results;
672
+ let colorSchemes = [];
673
+ let colorSchemeColors = [];
674
+ if (!isObject(colors)) return { colorSchemes, colorSchemeColors };
671
675
  Object.entries(colors).forEach(([key, value]) => {
672
676
  if (!isTone(value)) return;
673
- results.colorSchemes.push(key);
677
+ colorSchemes.push(key);
674
678
  });
675
- if (!isObject(semantics?.colorSchemes)) return results;
679
+ if (!isObject(semantics?.colorSchemes))
680
+ return { colorSchemes, colorSchemeColors };
676
681
  Object.entries(semantics.colorSchemes).forEach(([key, value]) => {
677
682
  if (isTone(value)) {
678
- results.colorSchemes.push(key);
679
- results.colorSchemeColors.push(...TONES.map((tone) => `${key}.${tone}`));
683
+ colorSchemes.push(key);
684
+ colorSchemeColors.push(...TONES.map((tone) => `${key}.${tone}`));
680
685
  } else {
681
- const hasColorScheme = isArray(value) ? value.every(
682
- (key2) => isString(key2) && Object.keys(colors).includes(key2)
683
- ) : Object.keys(colors).some((key2) => key2 === value);
686
+ const hasColorScheme = isArray(value) ? value.every((key2) => Object.keys(colors).includes(String(key2))) : Object.keys(colors).includes(String(value));
684
687
  if (!hasColorScheme) return;
685
- results.colorSchemes.push(key);
686
- results.colorSchemeColors.push(...TONES.map((tone) => `${key}.${tone}`));
688
+ colorSchemes.push(key);
689
+ colorSchemeColors.push(...TONES.map((tone) => `${key}.${tone}`));
687
690
  }
688
691
  });
689
- return results;
692
+ return { colorSchemes, colorSchemeColors };
690
693
  };
691
694
  var extractThemeSchemes = (theme) => {
692
695
  const { themeSchemes } = theme;
693
696
  if (!isObject(themeSchemes)) return ["base"];
694
697
  return ["base", ...Object.keys(themeSchemes)];
695
698
  };
696
- var extractPaths = (target, maxDepth = 3, omitKeys = []) => {
699
+ var extractPaths = (target, maxDepth = 3, omitKeys = [], shouldProcess) => {
697
700
  if (!isObject(target) && !isArray(target) || !maxDepth) return [];
698
- return Object.entries(target).reduce((array, [key, value]) => {
699
- if (isObject(value) && !Object.keys(value).some((key2) => omitKeys.includes(key2))) {
700
- extractPaths(value, maxDepth - 1, omitKeys).forEach(
701
- (nestedKey) => array.push(`${key}.${nestedKey}`)
701
+ return Object.entries(target).reduce((prev, [key, value]) => {
702
+ if (isObject(value) && !Object.keys(value).some((key2) => omitKeys.includes(key2)) && (!shouldProcess || shouldProcess(value))) {
703
+ extractPaths(value, maxDepth - 1, omitKeys, shouldProcess).forEach(
704
+ (nestedKey) => prev.push(`${key}.${nestedKey}`)
702
705
  );
703
706
  } else {
704
- array.push(key);
707
+ prev.push(key);
705
708
  }
706
- return array;
709
+ return prev;
707
710
  }, []);
708
711
  };
709
- var extractKeys = (theme, key) => {
710
- const keys = key.split(".");
711
- const property = keys.reduce((obj, key2) => obj[key2] ?? {}, theme);
712
+ var extractKeys = (obj, key) => {
713
+ const property = getObject(obj, key);
712
714
  if (!isObject(property)) return [];
713
715
  return Object.keys(property);
714
716
  };
715
- var createThemeTypings = async (theme) => {
717
+ var createThemeTypings = async (theme, { responsive = false }) => {
718
+ let shouldProcess = void 0;
719
+ if (responsive && isObject(theme.breakpoints)) {
720
+ const keys = ["base", ...Object.keys(theme.breakpoints)];
721
+ const isResponsive = (obj) => {
722
+ const providedKeys = Object.keys(obj);
723
+ if (!providedKeys.length) return false;
724
+ if (!providedKeys.includes("base")) return false;
725
+ return providedKeys.every((key) => keys.includes(key));
726
+ };
727
+ shouldProcess = (obj) => !isResponsive(obj);
728
+ }
716
729
  const tokens = config.reduce(
717
730
  (prev, {
718
731
  key,
732
+ replaceKey,
719
733
  maxScanDepth,
720
734
  omitScanKeys,
721
- filter = () => true,
722
735
  flatMap = (value) => value
723
736
  }) => {
724
- const target = theme[key];
725
- prev[key] = [];
737
+ const target = getObject(theme, key);
738
+ prev[replaceKey ?? key] = [];
726
739
  if (isObject(target) || isArray(target)) {
727
- prev[key] = extractPaths(target, maxScanDepth, omitScanKeys).filter(filter).flatMap(flatMap);
740
+ prev[replaceKey ?? key] = extractPaths(
741
+ target,
742
+ maxScanDepth,
743
+ omitScanKeys,
744
+ shouldProcess
745
+ ).flatMap(flatMap);
728
746
  }
729
747
  if (isObject(theme.semantics)) {
730
- const semanticKeys = extractKeys(
731
- omitObject(theme.semantics, ["colorSchemes"]),
732
- key
733
- ).filter(filter).flatMap(flatMap);
734
- prev[key].push(...semanticKeys);
748
+ const target2 = getObject(theme.semantics, key);
749
+ const semanticKeys = extractPaths(
750
+ target2,
751
+ maxScanDepth,
752
+ omitScanKeys,
753
+ shouldProcess
754
+ ).flatMap(flatMap);
755
+ prev[replaceKey ?? key].push(...semanticKeys);
735
756
  }
736
757
  return prev;
737
758
  },
@@ -741,24 +762,23 @@ var createThemeTypings = async (theme) => {
741
762
  const layerStyles = extractKeys(theme, "styles.layerStyles");
742
763
  const { colorSchemes, colorSchemeColors } = extractColorSchemes(theme);
743
764
  const themeSchemes = extractThemeSchemes(theme);
744
- const { transitionProperty, transitionDuration, transitionEasing } = extractTransitions(theme);
745
- const componentTypes = extractComponents(theme);
765
+ const components = extractComponents(theme);
746
766
  tokens.colors = [...tokens.colors, ...colorSchemeColors];
747
767
  return prettier(
748
- `import type { UITheme } from './ui-theme.types'
749
-
750
- export interface GeneratedTheme extends UITheme { ${print(
751
- {
768
+ [
769
+ `import type { UITheme } from './ui-theme.types'`,
770
+ ``,
771
+ `export interface GeneratedTheme extends UITheme {`,
772
+ print({
752
773
  ...tokens,
753
774
  textStyles,
754
775
  layerStyles,
755
776
  colorSchemes,
756
- themeSchemes,
757
- transitionProperty,
758
- transitionDuration,
759
- transitionEasing
760
- }
761
- )} ${printComponent(componentTypes)} }`
777
+ themeSchemes
778
+ }),
779
+ printComponent(components),
780
+ `}`
781
+ ].join("\n")
762
782
  );
763
783
  };
764
784
 
@@ -804,6 +824,7 @@ var resolveOutputPath = async (outPath) => {
804
824
  // src/command/tokens/index.ts
805
825
  var generateThemeTypings = async ({
806
826
  theme,
827
+ config: config2,
807
828
  outFile
808
829
  }) => {
809
830
  p.intro(source_default.magenta(`Generating Yamada UI theme typings`));
@@ -811,7 +832,7 @@ var generateThemeTypings = async ({
811
832
  try {
812
833
  const start = process.hrtime.bigint();
813
834
  s.start(`Parsing the theme`);
814
- const generatedTheme = await createThemeTypings(theme);
835
+ const generatedTheme = await createThemeTypings(theme, config2.theme ?? {});
815
836
  s.stop(`Parsed the theme`);
816
837
  s.start(`Resolving the output path`);
817
838
  const outPath = await resolveOutputPath(outFile);
@@ -829,19 +850,22 @@ var generateThemeTypings = async ({
829
850
  p.cancel(source_default.red(e instanceof Error ? e.message : "Message is missing"));
830
851
  }
831
852
  };
832
- var actionTokens = async (themePath2, { out: outFile, watch: watchFile }) => {
853
+ var actionTokens = async (themePath2, { cwd = import_path3.default.resolve(), out: outFile, watch: watchFile }) => {
833
854
  const readFile = async () => {
834
855
  const filePath = import_path3.default.resolve(themePath2);
835
- const { mod: theme, dependencies } = await (0, import_bundle_n_require.bundleNRequire)(filePath);
836
- return { theme, dependencies };
856
+ const { mod, dependencies: dependencies2 } = await getModule(filePath, cwd);
857
+ const theme2 = mod?.default ?? mod?.theme ?? mod?.customTheme ?? mod?.defaultTheme ?? {};
858
+ const config3 = mod?.config ?? mod?.customConfig ?? mod?.defaultConfig ?? {};
859
+ return { theme: theme2, config: config3, dependencies: dependencies2 };
837
860
  };
838
861
  let file = await readFile();
862
+ const { theme, config: config2, dependencies } = file;
839
863
  const buildFile = async () => {
840
- await generateThemeTypings({ theme: file.theme, outFile });
864
+ await generateThemeTypings({ theme, config: config2, outFile });
841
865
  if (watchFile) console.log("\n", "\u231B\uFE0F Watching for changes...");
842
866
  };
843
867
  if (watchFile) {
844
- const watchPath = typeof watchFile === "string" ? watchFile : file.dependencies;
868
+ const watchPath = typeof watchFile === "string" ? watchFile : dependencies;
845
869
  import_chokidar.default.watch(watchPath).on("ready", buildFile).on("change", async (filePath) => {
846
870
  console.log("\u{1F4E6} File changed", filePath);
847
871
  file = await readFile();