@yamada-ui/cli 1.2.4 → 2.0.0-dev-20250626070331

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.
@@ -1,1117 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
- };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
-
33
- // ../../node_modules/.pnpm/tsup@8.3.6_@swc+core@1.10.18_jiti@2.4.2_tsx@4.19.3_typescript@5.7.3/node_modules/tsup/assets/cjs_shims.js
34
- var init_cjs_shims = __esm({
35
- "../../node_modules/.pnpm/tsup@8.3.6_@swc+core@1.10.18_jiti@2.4.2_tsx@4.19.3_typescript@5.7.3/node_modules/tsup/assets/cjs_shims.js"() {
36
- "use strict";
37
- }
38
- });
39
-
40
- // src/command/index.ts
41
- var command_exports = {};
42
- __export(command_exports, {
43
- actionTheme: () => actionTheme,
44
- actionTokens: () => actionTokens,
45
- themePath: () => themePath
46
- });
47
- module.exports = __toCommonJS(command_exports);
48
- init_cjs_shims();
49
-
50
- // src/command/theme/index.ts
51
- init_cjs_shims();
52
- var p = __toESM(require("@clack/prompts"));
53
-
54
- // ../../node_modules/.pnpm/chalk@5.4.1/node_modules/chalk/source/index.js
55
- init_cjs_shims();
56
-
57
- // ../../node_modules/.pnpm/chalk@5.4.1/node_modules/chalk/source/vendor/ansi-styles/index.js
58
- init_cjs_shims();
59
- var ANSI_BACKGROUND_OFFSET = 10;
60
- var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
61
- var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
62
- var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
63
- var styles = {
64
- modifier: {
65
- reset: [0, 0],
66
- // 21 isn't widely supported and 22 does the same thing
67
- bold: [1, 22],
68
- dim: [2, 22],
69
- italic: [3, 23],
70
- underline: [4, 24],
71
- overline: [53, 55],
72
- inverse: [7, 27],
73
- hidden: [8, 28],
74
- strikethrough: [9, 29]
75
- },
76
- color: {
77
- black: [30, 39],
78
- red: [31, 39],
79
- green: [32, 39],
80
- yellow: [33, 39],
81
- blue: [34, 39],
82
- magenta: [35, 39],
83
- cyan: [36, 39],
84
- white: [37, 39],
85
- // Bright color
86
- blackBright: [90, 39],
87
- gray: [90, 39],
88
- // Alias of `blackBright`
89
- grey: [90, 39],
90
- // Alias of `blackBright`
91
- redBright: [91, 39],
92
- greenBright: [92, 39],
93
- yellowBright: [93, 39],
94
- blueBright: [94, 39],
95
- magentaBright: [95, 39],
96
- cyanBright: [96, 39],
97
- whiteBright: [97, 39]
98
- },
99
- bgColor: {
100
- bgBlack: [40, 49],
101
- bgRed: [41, 49],
102
- bgGreen: [42, 49],
103
- bgYellow: [43, 49],
104
- bgBlue: [44, 49],
105
- bgMagenta: [45, 49],
106
- bgCyan: [46, 49],
107
- bgWhite: [47, 49],
108
- // Bright color
109
- bgBlackBright: [100, 49],
110
- bgGray: [100, 49],
111
- // Alias of `bgBlackBright`
112
- bgGrey: [100, 49],
113
- // Alias of `bgBlackBright`
114
- bgRedBright: [101, 49],
115
- bgGreenBright: [102, 49],
116
- bgYellowBright: [103, 49],
117
- bgBlueBright: [104, 49],
118
- bgMagentaBright: [105, 49],
119
- bgCyanBright: [106, 49],
120
- bgWhiteBright: [107, 49]
121
- }
122
- };
123
- var modifierNames = Object.keys(styles.modifier);
124
- var foregroundColorNames = Object.keys(styles.color);
125
- var backgroundColorNames = Object.keys(styles.bgColor);
126
- var colorNames = [...foregroundColorNames, ...backgroundColorNames];
127
- function assembleStyles() {
128
- const codes = /* @__PURE__ */ new Map();
129
- for (const [groupName, group] of Object.entries(styles)) {
130
- for (const [styleName, style] of Object.entries(group)) {
131
- styles[styleName] = {
132
- open: `\x1B[${style[0]}m`,
133
- close: `\x1B[${style[1]}m`
134
- };
135
- group[styleName] = styles[styleName];
136
- codes.set(style[0], style[1]);
137
- }
138
- Object.defineProperty(styles, groupName, {
139
- value: group,
140
- enumerable: false
141
- });
142
- }
143
- Object.defineProperty(styles, "codes", {
144
- value: codes,
145
- enumerable: false
146
- });
147
- styles.color.close = "\x1B[39m";
148
- styles.bgColor.close = "\x1B[49m";
149
- styles.color.ansi = wrapAnsi16();
150
- styles.color.ansi256 = wrapAnsi256();
151
- styles.color.ansi16m = wrapAnsi16m();
152
- styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
153
- styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
154
- styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
155
- Object.defineProperties(styles, {
156
- rgbToAnsi256: {
157
- value(red, green, blue) {
158
- if (red === green && green === blue) {
159
- if (red < 8) {
160
- return 16;
161
- }
162
- if (red > 248) {
163
- return 231;
164
- }
165
- return Math.round((red - 8) / 247 * 24) + 232;
166
- }
167
- return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
168
- },
169
- enumerable: false
170
- },
171
- hexToRgb: {
172
- value(hex) {
173
- const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
174
- if (!matches) {
175
- return [0, 0, 0];
176
- }
177
- let [colorString] = matches;
178
- if (colorString.length === 3) {
179
- colorString = [...colorString].map((character) => character + character).join("");
180
- }
181
- const integer = Number.parseInt(colorString, 16);
182
- return [
183
- /* eslint-disable no-bitwise */
184
- integer >> 16 & 255,
185
- integer >> 8 & 255,
186
- integer & 255
187
- /* eslint-enable no-bitwise */
188
- ];
189
- },
190
- enumerable: false
191
- },
192
- hexToAnsi256: {
193
- value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
194
- enumerable: false
195
- },
196
- ansi256ToAnsi: {
197
- value(code) {
198
- if (code < 8) {
199
- return 30 + code;
200
- }
201
- if (code < 16) {
202
- return 90 + (code - 8);
203
- }
204
- let red;
205
- let green;
206
- let blue;
207
- if (code >= 232) {
208
- red = ((code - 232) * 10 + 8) / 255;
209
- green = red;
210
- blue = red;
211
- } else {
212
- code -= 16;
213
- const remainder = code % 36;
214
- red = Math.floor(code / 36) / 5;
215
- green = Math.floor(remainder / 6) / 5;
216
- blue = remainder % 6 / 5;
217
- }
218
- const value = Math.max(red, green, blue) * 2;
219
- if (value === 0) {
220
- return 30;
221
- }
222
- let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
223
- if (value === 2) {
224
- result += 60;
225
- }
226
- return result;
227
- },
228
- enumerable: false
229
- },
230
- rgbToAnsi: {
231
- value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
232
- enumerable: false
233
- },
234
- hexToAnsi: {
235
- value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
236
- enumerable: false
237
- }
238
- });
239
- return styles;
240
- }
241
- var ansiStyles = assembleStyles();
242
- var ansi_styles_default = ansiStyles;
243
-
244
- // ../../node_modules/.pnpm/chalk@5.4.1/node_modules/chalk/source/vendor/supports-color/index.js
245
- init_cjs_shims();
246
- var import_node_process = __toESM(require("process"), 1);
247
- var import_node_os = __toESM(require("os"), 1);
248
- var import_node_tty = __toESM(require("tty"), 1);
249
- function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) {
250
- const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
251
- const position = argv.indexOf(prefix + flag);
252
- const terminatorPosition = argv.indexOf("--");
253
- return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
254
- }
255
- var { env } = import_node_process.default;
256
- var flagForceColor;
257
- if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
258
- flagForceColor = 0;
259
- } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
260
- flagForceColor = 1;
261
- }
262
- function envForceColor() {
263
- if ("FORCE_COLOR" in env) {
264
- if (env.FORCE_COLOR === "true") {
265
- return 1;
266
- }
267
- if (env.FORCE_COLOR === "false") {
268
- return 0;
269
- }
270
- return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
271
- }
272
- }
273
- function translateLevel(level) {
274
- if (level === 0) {
275
- return false;
276
- }
277
- return {
278
- level,
279
- hasBasic: true,
280
- has256: level >= 2,
281
- has16m: level >= 3
282
- };
283
- }
284
- function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
285
- const noFlagForceColor = envForceColor();
286
- if (noFlagForceColor !== void 0) {
287
- flagForceColor = noFlagForceColor;
288
- }
289
- const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
290
- if (forceColor === 0) {
291
- return 0;
292
- }
293
- if (sniffFlags) {
294
- if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
295
- return 3;
296
- }
297
- if (hasFlag("color=256")) {
298
- return 2;
299
- }
300
- }
301
- if ("TF_BUILD" in env && "AGENT_NAME" in env) {
302
- return 1;
303
- }
304
- if (haveStream && !streamIsTTY && forceColor === void 0) {
305
- return 0;
306
- }
307
- const min = forceColor || 0;
308
- if (env.TERM === "dumb") {
309
- return min;
310
- }
311
- if (import_node_process.default.platform === "win32") {
312
- const osRelease = import_node_os.default.release().split(".");
313
- if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
314
- return Number(osRelease[2]) >= 14931 ? 3 : 2;
315
- }
316
- return 1;
317
- }
318
- if ("CI" in env) {
319
- if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
320
- return 3;
321
- }
322
- if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
323
- return 1;
324
- }
325
- return min;
326
- }
327
- if ("TEAMCITY_VERSION" in env) {
328
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
329
- }
330
- if (env.COLORTERM === "truecolor") {
331
- return 3;
332
- }
333
- if (env.TERM === "xterm-kitty") {
334
- return 3;
335
- }
336
- if ("TERM_PROGRAM" in env) {
337
- const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
338
- switch (env.TERM_PROGRAM) {
339
- case "iTerm.app": {
340
- return version >= 3 ? 3 : 2;
341
- }
342
- case "Apple_Terminal": {
343
- return 2;
344
- }
345
- }
346
- }
347
- if (/-256(color)?$/i.test(env.TERM)) {
348
- return 2;
349
- }
350
- if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
351
- return 1;
352
- }
353
- if ("COLORTERM" in env) {
354
- return 1;
355
- }
356
- return min;
357
- }
358
- function createSupportsColor(stream, options = {}) {
359
- const level = _supportsColor(stream, {
360
- streamIsTTY: stream && stream.isTTY,
361
- ...options
362
- });
363
- return translateLevel(level);
364
- }
365
- var supportsColor = {
366
- stdout: createSupportsColor({ isTTY: import_node_tty.default.isatty(1) }),
367
- stderr: createSupportsColor({ isTTY: import_node_tty.default.isatty(2) })
368
- };
369
- var supports_color_default = supportsColor;
370
-
371
- // ../../node_modules/.pnpm/chalk@5.4.1/node_modules/chalk/source/utilities.js
372
- init_cjs_shims();
373
- function stringReplaceAll(string, substring, replacer) {
374
- let index = string.indexOf(substring);
375
- if (index === -1) {
376
- return string;
377
- }
378
- const substringLength = substring.length;
379
- let endIndex = 0;
380
- let returnValue = "";
381
- do {
382
- returnValue += string.slice(endIndex, index) + substring + replacer;
383
- endIndex = index + substringLength;
384
- index = string.indexOf(substring, endIndex);
385
- } while (index !== -1);
386
- returnValue += string.slice(endIndex);
387
- return returnValue;
388
- }
389
- function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
390
- let endIndex = 0;
391
- let returnValue = "";
392
- do {
393
- const gotCR = string[index - 1] === "\r";
394
- returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
395
- endIndex = index + 1;
396
- index = string.indexOf("\n", endIndex);
397
- } while (index !== -1);
398
- returnValue += string.slice(endIndex);
399
- return returnValue;
400
- }
401
-
402
- // ../../node_modules/.pnpm/chalk@5.4.1/node_modules/chalk/source/index.js
403
- var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
404
- var GENERATOR = Symbol("GENERATOR");
405
- var STYLER = Symbol("STYLER");
406
- var IS_EMPTY = Symbol("IS_EMPTY");
407
- var levelMapping = [
408
- "ansi",
409
- "ansi",
410
- "ansi256",
411
- "ansi16m"
412
- ];
413
- var styles2 = /* @__PURE__ */ Object.create(null);
414
- var applyOptions = (object, options = {}) => {
415
- if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
416
- throw new Error("The `level` option should be an integer from 0 to 3");
417
- }
418
- const colorLevel = stdoutColor ? stdoutColor.level : 0;
419
- object.level = options.level === void 0 ? colorLevel : options.level;
420
- };
421
- var chalkFactory = (options) => {
422
- const chalk2 = (...strings) => strings.join(" ");
423
- applyOptions(chalk2, options);
424
- Object.setPrototypeOf(chalk2, createChalk.prototype);
425
- return chalk2;
426
- };
427
- function createChalk(options) {
428
- return chalkFactory(options);
429
- }
430
- Object.setPrototypeOf(createChalk.prototype, Function.prototype);
431
- for (const [styleName, style] of Object.entries(ansi_styles_default)) {
432
- styles2[styleName] = {
433
- get() {
434
- const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
435
- Object.defineProperty(this, styleName, { value: builder });
436
- return builder;
437
- }
438
- };
439
- }
440
- styles2.visible = {
441
- get() {
442
- const builder = createBuilder(this, this[STYLER], true);
443
- Object.defineProperty(this, "visible", { value: builder });
444
- return builder;
445
- }
446
- };
447
- var getModelAnsi = (model, level, type, ...arguments_) => {
448
- if (model === "rgb") {
449
- if (level === "ansi16m") {
450
- return ansi_styles_default[type].ansi16m(...arguments_);
451
- }
452
- if (level === "ansi256") {
453
- return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
454
- }
455
- return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
456
- }
457
- if (model === "hex") {
458
- return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
459
- }
460
- return ansi_styles_default[type][model](...arguments_);
461
- };
462
- var usedModels = ["rgb", "hex", "ansi256"];
463
- for (const model of usedModels) {
464
- styles2[model] = {
465
- get() {
466
- const { level } = this;
467
- return function(...arguments_) {
468
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
469
- return createBuilder(this, styler, this[IS_EMPTY]);
470
- };
471
- }
472
- };
473
- const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
474
- styles2[bgModel] = {
475
- get() {
476
- const { level } = this;
477
- return function(...arguments_) {
478
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
479
- return createBuilder(this, styler, this[IS_EMPTY]);
480
- };
481
- }
482
- };
483
- }
484
- var proto = Object.defineProperties(() => {
485
- }, {
486
- ...styles2,
487
- level: {
488
- enumerable: true,
489
- get() {
490
- return this[GENERATOR].level;
491
- },
492
- set(level) {
493
- this[GENERATOR].level = level;
494
- }
495
- }
496
- });
497
- var createStyler = (open, close, parent) => {
498
- let openAll;
499
- let closeAll;
500
- if (parent === void 0) {
501
- openAll = open;
502
- closeAll = close;
503
- } else {
504
- openAll = parent.openAll + open;
505
- closeAll = close + parent.closeAll;
506
- }
507
- return {
508
- open,
509
- close,
510
- openAll,
511
- closeAll,
512
- parent
513
- };
514
- };
515
- var createBuilder = (self, _styler, _isEmpty) => {
516
- const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
517
- Object.setPrototypeOf(builder, proto);
518
- builder[GENERATOR] = self;
519
- builder[STYLER] = _styler;
520
- builder[IS_EMPTY] = _isEmpty;
521
- return builder;
522
- };
523
- var applyStyle = (self, string) => {
524
- if (self.level <= 0 || !string) {
525
- return self[IS_EMPTY] ? "" : string;
526
- }
527
- let styler = self[STYLER];
528
- if (styler === void 0) {
529
- return string;
530
- }
531
- const { openAll, closeAll } = styler;
532
- if (string.includes("\x1B")) {
533
- while (styler !== void 0) {
534
- string = stringReplaceAll(string, styler.close, styler.open);
535
- styler = styler.parent;
536
- }
537
- }
538
- const lfIndex = string.indexOf("\n");
539
- if (lfIndex !== -1) {
540
- string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
541
- }
542
- return openAll + string + closeAll;
543
- };
544
- Object.defineProperties(createChalk.prototype, styles2);
545
- var chalk = createChalk();
546
- var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
547
- var source_default = chalk;
548
-
549
- // src/command/theme/index.ts
550
- var import_dns = __toESM(require("dns"));
551
- var import_fs3 = require("fs");
552
- var import_promises = require("fs/promises");
553
- var import_node_stream = require("stream");
554
- var import_promises2 = require("stream/promises");
555
- var import_path2 = __toESM(require("path"));
556
- var import_tar = require("tar");
557
- var import_typescript = require("typescript");
558
-
559
- // src/utils/assertion.ts
560
- init_cjs_shims();
561
- var isObject = (obj) => obj !== null && (typeof obj === "object" || typeof obj === "function") && !isArray(obj);
562
- var isArray = (value) => Array.isArray(value);
563
-
564
- // src/utils/fs.ts
565
- init_cjs_shims();
566
- var import_fs = __toESM(require("fs"));
567
- var isWriteable = async (directory) => {
568
- try {
569
- await import_fs.default.promises.access(
570
- directory,
571
- ("constants" in import_fs.default ? import_fs.default.constants : import_fs.default).W_OK
572
- );
573
- return true;
574
- } catch {
575
- return false;
576
- }
577
- };
578
-
579
- // src/utils/module.ts
580
- init_cjs_shims();
581
- var import_esbuild = require("esbuild");
582
- var import_fs2 = require("fs");
583
- var import_node_eval = __toESM(require("node-eval"));
584
- var import_vm = require("vm");
585
- var getModule = async (file, cwd) => {
586
- const result = await (0, import_esbuild.build)({
587
- absWorkingDir: cwd,
588
- bundle: true,
589
- entryPoints: [file],
590
- format: "cjs",
591
- mainFields: ["module", "main"],
592
- metafile: true,
593
- outfile: "out.js",
594
- platform: "node",
595
- sourcemap: false,
596
- write: false
597
- });
598
- const { text: code } = result.outputFiles[0] ?? {};
599
- const dependencies = isObject(result.metafile) ? Object.keys(result.metafile.inputs) : [];
600
- try {
601
- const realFileName = import_fs2.realpathSync.native(file);
602
- if (!code) throw new Error("code is undefined");
603
- const script = new import_vm.Script(code, { filename: realFileName });
604
- const mod = { exports: {} };
605
- const require2 = (id) => id === realFileName ? mod.exports : require2(id);
606
- script.runInThisContext()(mod.exports, require2, mod);
607
- return { code, dependencies, mod };
608
- } catch {
609
- const mod = (0, import_node_eval.default)(code);
610
- return { code, dependencies, mod };
611
- }
612
- };
613
-
614
- // src/utils/object.ts
615
- init_cjs_shims();
616
- var getObject = (obj, path5) => {
617
- const keys = path5.split(".");
618
- return keys.reduce((obj2, key) => obj2[key] ?? {}, obj);
619
- };
620
-
621
- // src/utils/prettier.ts
622
- init_cjs_shims();
623
- var import_path = __toESM(require("path"));
624
- var import_prettier = require("prettier");
625
- var prettier = async (content, options) => {
626
- const prettierConfig = await (0, import_prettier.resolveConfig)(
627
- import_path.default.join(process.cwd(), ".prettierrc")
628
- );
629
- try {
630
- return (0, import_prettier.format)(content, {
631
- ...prettierConfig,
632
- parser: "typescript",
633
- ...options
634
- });
635
- } catch {
636
- return content;
637
- }
638
- };
639
-
640
- // src/command/theme/index.ts
641
- var ORG_NAME = "yamada-ui";
642
- var REPO_NAME = "yamada-ui";
643
- var DEFAULT_BRANCH_NAME = "main";
644
- var isOnline = async () => {
645
- return new Promise((resolve) => {
646
- import_dns.default.lookup("github.com", (err) => {
647
- if (err && err.code === "ENOTFOUND") {
648
- resolve(false);
649
- } else {
650
- resolve(true);
651
- }
652
- });
653
- });
654
- };
655
- var checkHasReact = async (cwd) => {
656
- try {
657
- const packageJson = await (0, import_promises.readFile)(import_path2.default.join(cwd, "package.json"), "utf-8");
658
- const { dependencies, devDependencies } = JSON.parse(packageJson);
659
- return !!dependencies?.["@yamada-ui/react"] || !!devDependencies?.["@yamada-ui/react"];
660
- } catch {
661
- return false;
662
- }
663
- };
664
- var getSource = async (branch) => {
665
- if (!await isOnline()) {
666
- throw new Error(
667
- "No internet connection, please check your connection and try again."
668
- );
669
- }
670
- const url = `https://codeload.github.com/${ORG_NAME}/${REPO_NAME}/tar.gz/${branch}`;
671
- const { body } = await fetch(url);
672
- if (!body) throw new Error(`Failed to download: ${url}`);
673
- return import_node_stream.Readable.fromWeb(body);
674
- };
675
- var getFileMap = async (cwd, branch) => {
676
- const source = await getSource(branch);
677
- const fileMap = /* @__PURE__ */ new Map();
678
- const targetPath = `${REPO_NAME}-${branch.replace("/", "-")}/packages/theme/src`;
679
- const filter = (path5) => {
680
- return path5.startsWith(targetPath);
681
- };
682
- const onReadEntry = (entry) => {
683
- if (entry.type !== "Directory") {
684
- const filePath = entry.path.replace(`${targetPath}/`, "");
685
- let content = "";
686
- entry.on("data", (chunk) => {
687
- content += chunk.toString();
688
- });
689
- entry.on("end", () => {
690
- fileMap.set(filePath, content);
691
- });
692
- }
693
- };
694
- await (0, import_promises2.pipeline)(
695
- source,
696
- (0, import_tar.t)({
697
- cwd,
698
- filter,
699
- newer: true,
700
- strip: 4,
701
- onReadEntry
702
- })
703
- );
704
- return fileMap;
705
- };
706
- var transformSourceFile = (sourceFile) => {
707
- const ImportDeclarations = [];
708
- const ImportTypeDeclarations = [];
709
- const transformer = (context) => (sourceFile2) => {
710
- const visitor = (node) => {
711
- if ((0, import_typescript.isImportDeclaration)(node)) {
712
- const moduleSpecifier = node.moduleSpecifier.getText().slice(1, -1);
713
- if (moduleSpecifier.startsWith("@yamada-ui/")) {
714
- if (node.importClause?.isTypeOnly) {
715
- ImportTypeDeclarations.push(node);
716
- } else {
717
- ImportDeclarations.push(node);
718
- }
719
- return import_typescript.factory.createEmptyStatement();
720
- }
721
- }
722
- return (0, import_typescript.visitEachChild)(node, visitor, context);
723
- };
724
- return (0, import_typescript.visitNode)(sourceFile2, visitor);
725
- };
726
- const { transformed } = (0, import_typescript.transform)(sourceFile, [transformer]);
727
- const transformedSourceFile = transformed[0];
728
- return { ImportDeclarations, ImportTypeDeclarations, transformedSourceFile };
729
- };
730
- var createImportDeclaration = (isTypeOnly, declarations) => {
731
- const elements = declarations.flatMap(
732
- ({ importClause: importClause2 }) => importClause2?.namedBindings && (0, import_typescript.isNamedImports)(importClause2.namedBindings) ? importClause2.namedBindings.elements : []
733
- );
734
- const namedBindings = import_typescript.factory.createNamedImports(elements);
735
- const importClause = import_typescript.factory.createImportClause(
736
- isTypeOnly,
737
- void 0,
738
- namedBindings
739
- );
740
- return import_typescript.factory.createImportDeclaration(
741
- void 0,
742
- importClause,
743
- import_typescript.factory.createStringLiteral("@yamada-ui/react")
744
- );
745
- };
746
- var replaceContent = (content) => {
747
- const sourceFile = (0, import_typescript.createSourceFile)(
748
- "temp.ts",
749
- content,
750
- import_typescript.ScriptTarget.Latest,
751
- true
752
- );
753
- const printer = (0, import_typescript.createPrinter)({ newLine: import_typescript.NewLineKind.LineFeed });
754
- const { ImportDeclarations, ImportTypeDeclarations, transformedSourceFile } = transformSourceFile(sourceFile);
755
- const statements = [...transformedSourceFile.statements];
756
- if (ImportTypeDeclarations.length) {
757
- const newImportTypeDeclarations = createImportDeclaration(
758
- true,
759
- ImportTypeDeclarations
760
- );
761
- statements.unshift(newImportTypeDeclarations);
762
- }
763
- if (ImportDeclarations.length) {
764
- const newImportDeclarations = createImportDeclaration(
765
- false,
766
- ImportDeclarations
767
- );
768
- statements.unshift(newImportDeclarations);
769
- }
770
- const updatedSourceFile = import_typescript.factory.updateSourceFile(
771
- transformedSourceFile,
772
- statements
773
- );
774
- let printedContent = printer.printFile(updatedSourceFile);
775
- printedContent = printedContent.replace(/^;$/gm, "");
776
- printedContent = printedContent.replace(/\s\n*(?=import)/g, "");
777
- printedContent = printedContent.replace(/(import .*\n)+(?!import)/, "$&\n");
778
- return printedContent;
779
- };
780
- var replaceIndex = (content) => {
781
- const index = content.indexOf("export const baseTheme");
782
- content = content.slice(0, index);
783
- content = content.replace(/export const baseTheme/, "export const theme");
784
- content = content.replace(/\nimport { config } from ".\/config"/, "");
785
- content += "\nexport { config } from './config'";
786
- return content;
787
- };
788
- var generateTheme = async (outPath, fileMap, isReactReplace, isForceReplace) => {
789
- if (!await isWriteable(import_path2.default.dirname(outPath))) {
790
- throw new Error(
791
- "The provided path is not writable, please check folder permissions and try again. It is likely you do not have write permissions for this folder."
792
- );
793
- }
794
- await (0, import_promises.mkdir)(outPath, { recursive: true });
795
- await Promise.all(
796
- [...fileMap.entries()].map(async ([filePath, _content]) => {
797
- const targetPath = import_path2.default.join(outPath, filePath);
798
- let content = _content;
799
- if (filePath === "index.ts") {
800
- content = replaceIndex(content);
801
- } else {
802
- if (isReactReplace) content = replaceContent(content);
803
- }
804
- const formattedContent = await prettier(content);
805
- try {
806
- if (!isForceReplace && (0, import_fs3.existsSync)(targetPath)) return;
807
- await (0, import_promises.writeFile)(targetPath, formattedContent, "utf-8");
808
- } catch (e) {
809
- if (e instanceof Error && "code" in e && e.code === "ENOENT") {
810
- const dirPath = import_path2.default.dirname(targetPath);
811
- await (0, import_promises.mkdir)(dirPath, { recursive: true });
812
- if (!isForceReplace && (0, import_fs3.existsSync)(targetPath)) return;
813
- await (0, import_promises.writeFile)(targetPath, formattedContent, "utf-8");
814
- }
815
- }
816
- })
817
- );
818
- };
819
- var actionTheme = async (_outPath, { branch = DEFAULT_BRANCH_NAME, cwd, replace = false }) => {
820
- p.intro(source_default.magenta(`Generating Yamada UI theme`));
821
- const s = p.spinner();
822
- try {
823
- const start = process.hrtime.bigint();
824
- cwd ??= import_path2.default.resolve();
825
- const outPath = import_path2.default.join(cwd, _outPath);
826
- s.start(`Checking "package.json"`);
827
- const hasReact = await checkHasReact(cwd);
828
- s.stop(`Checked "package.json"`);
829
- s.start(`Downloading the theme`);
830
- const fileMap = await getFileMap(outPath, branch);
831
- s.stop(`Downloaded the theme`);
832
- s.start(`Writing the theme "${outPath}"`);
833
- await generateTheme(outPath, fileMap, hasReact, replace);
834
- s.stop(`Wrote the theme`);
835
- const end = process.hrtime.bigint();
836
- const duration = (Number(end - start) / 1e9).toFixed(2);
837
- p.outro(`${source_default.green(`Done`)} in ${source_default.dim(`${duration}s`)}
838
- `);
839
- } catch (e) {
840
- s.stop(`An error occurred`, 500);
841
- p.cancel(source_default.red(e instanceof Error ? e.message : "Message is missing"));
842
- }
843
- };
844
-
845
- // src/command/tokens/index.ts
846
- init_cjs_shims();
847
- var p2 = __toESM(require("@clack/prompts"));
848
- var import_chokidar = __toESM(require("chokidar"));
849
- var import_promises3 = require("fs/promises");
850
- var import_path4 = __toESM(require("path"));
851
-
852
- // src/command/tokens/create-theme-typings.ts
853
- init_cjs_shims();
854
-
855
- // src/command/tokens/config.ts
856
- init_cjs_shims();
857
- var config = [
858
- { key: "borders" },
859
- { key: "breakpoints" },
860
- { key: "colors" },
861
- { key: "fonts" },
862
- { key: "fontSizes" },
863
- { key: "fontWeights" },
864
- { key: "letterSpacings" },
865
- { key: "lineHeights" },
866
- { key: "radii" },
867
- { key: "shadows" },
868
- { key: "blurs" },
869
- { key: "sizes" },
870
- { key: "spaces", flatMap: (value) => [value, `-${value}`] },
871
- { key: "zIndices" },
872
- { key: "animations", omitScanKeys: ["keyframes"] },
873
- { key: "gradients" },
874
- { key: "transitions.property", replaceKey: "transitionProperty" },
875
- { key: "transitions.duration", replaceKey: "transitionDuration" },
876
- { key: "transitions.easing", replaceKey: "transitionEasing" }
877
- ];
878
-
879
- // src/command/tokens/create-theme-typings.ts
880
- var TONES = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
881
- var printComponent = (components) => `components: { ${Object.entries(components).map(
882
- ([key, unions]) => `${key.match(/^[a-zA-Z0-9\-_]+$/) ? key : `"${key}"`}: { ${print(
883
- unions
884
- )}}`
885
- ).join(`
886
- `)} }`;
887
- var print = (unions) => Object.entries(unions).sort(([a], [b]) => a.localeCompare(b)).map(
888
- ([key, union]) => `${key}: ${union.map((value) => `"${value}"`).concat(["(string & {})"]).join(" | ")};`
889
- ).join("\n");
890
- var extractComponents = ({ components = {} }) => Object.entries(components).reduce((obj, [key, { sizes, variants }]) => {
891
- if (sizes || variants) {
892
- obj[key] = {
893
- sizes: Object.keys(sizes ?? {}),
894
- variants: Object.keys(variants ?? {})
895
- };
896
- }
897
- return obj;
898
- }, {});
899
- var isTone = (value) => {
900
- if (!isObject(value)) return false;
901
- const keys = Object.keys(value);
902
- return TONES.every((key) => keys.includes(key.toString()));
903
- };
904
- var extractColorSchemes = (theme) => {
905
- const { colors, semantics } = theme;
906
- let colorSchemes = [];
907
- let colorSchemeColors = [];
908
- if (!isObject(colors)) return { colorSchemeColors, colorSchemes };
909
- Object.entries(colors).forEach(([key, value]) => {
910
- if (!isTone(value)) return;
911
- colorSchemes.push(key);
912
- });
913
- if (!isObject(semantics?.colorSchemes))
914
- return { colorSchemeColors, colorSchemes };
915
- Object.entries(semantics.colorSchemes).forEach(([key, value]) => {
916
- if (isTone(value)) {
917
- colorSchemes.push(key);
918
- colorSchemeColors.push(...TONES.map((tone) => `${key}.${tone}`));
919
- } else {
920
- const hasColorScheme = isArray(value) ? value.every((key2) => Object.keys(colors).includes(String(key2))) : Object.keys(colors).includes(String(value));
921
- if (!hasColorScheme) return;
922
- colorSchemes.push(key);
923
- colorSchemeColors.push(...TONES.map((tone) => `${key}.${tone}`));
924
- }
925
- });
926
- return { colorSchemeColors, colorSchemes };
927
- };
928
- var extractThemeSchemes = (theme) => {
929
- const { themeSchemes } = theme;
930
- if (!isObject(themeSchemes)) return ["base"];
931
- return ["base", ...Object.keys(themeSchemes)];
932
- };
933
- var extractPaths = (target, maxDepth = 3, omitKeys = [], shouldProcess) => {
934
- if (!isObject(target) && !isArray(target) || !maxDepth) return [];
935
- return Object.entries(target).reduce((prev, [key, value]) => {
936
- if (isObject(value) && !Object.keys(value).some((key2) => omitKeys.includes(key2)) && (!shouldProcess || shouldProcess(value))) {
937
- extractPaths(value, maxDepth - 1, omitKeys, shouldProcess).forEach(
938
- (nestedKey) => prev.push(`${key}.${nestedKey}`)
939
- );
940
- } else {
941
- prev.push(key);
942
- }
943
- return prev;
944
- }, []);
945
- };
946
- var extractKeys = (obj, key) => {
947
- const property = getObject(obj, key);
948
- if (!isObject(property)) return [];
949
- return Object.keys(property);
950
- };
951
- var createThemeTypings = async (theme, { responsive = false }) => {
952
- let shouldProcess = void 0;
953
- if (responsive && isObject(theme.breakpoints)) {
954
- const keys = ["base", ...Object.keys(theme.breakpoints)];
955
- const isResponsive = (obj) => {
956
- const providedKeys = Object.keys(obj);
957
- if (!providedKeys.length) return false;
958
- if (!providedKeys.includes("base")) return false;
959
- return providedKeys.every((key) => keys.includes(key));
960
- };
961
- shouldProcess = (obj) => !isResponsive(obj);
962
- }
963
- const tokens = config.reduce(
964
- (prev, {
965
- key,
966
- flatMap = (value) => value,
967
- maxScanDepth,
968
- omitScanKeys,
969
- replaceKey
970
- }) => {
971
- const target = getObject(theme, key);
972
- prev[replaceKey ?? key] = [];
973
- if (isObject(target) || isArray(target)) {
974
- prev[replaceKey ?? key] = extractPaths(
975
- target,
976
- maxScanDepth,
977
- omitScanKeys,
978
- shouldProcess
979
- ).flatMap(flatMap);
980
- }
981
- if (isObject(theme.semantics)) {
982
- const target2 = getObject(theme.semantics, key);
983
- const semanticKeys = extractPaths(
984
- target2,
985
- maxScanDepth,
986
- omitScanKeys,
987
- shouldProcess
988
- ).flatMap(flatMap);
989
- prev[replaceKey ?? key]?.push(...semanticKeys);
990
- }
991
- return prev;
992
- },
993
- {}
994
- );
995
- const textStyles = extractKeys(theme, "styles.textStyles");
996
- const layerStyles = extractKeys(theme, "styles.layerStyles");
997
- const { colorSchemeColors, colorSchemes } = extractColorSchemes(theme);
998
- const themeSchemes = extractThemeSchemes(theme);
999
- const components = extractComponents(theme);
1000
- tokens.colors = [...tokens.colors ?? [], ...colorSchemeColors];
1001
- return prettier(
1002
- [
1003
- `import type { UITheme } from './ui-theme.types'`,
1004
- ``,
1005
- `export interface GeneratedTheme extends UITheme {`,
1006
- print({
1007
- ...tokens,
1008
- colorSchemes,
1009
- layerStyles,
1010
- textStyles,
1011
- themeSchemes
1012
- }),
1013
- printComponent(components),
1014
- `}`
1015
- ].join("\n")
1016
- );
1017
- };
1018
-
1019
- // src/command/tokens/resolve-output-path.ts
1020
- init_cjs_shims();
1021
- var import_glob = require("glob");
1022
- var import_path3 = __toESM(require("path"));
1023
- var themePath = [
1024
- "node_modules",
1025
- "@yamada-ui",
1026
- "core",
1027
- "dist",
1028
- "generated-theme.types.d.ts"
1029
- ];
1030
- var resolveThemePath = async () => {
1031
- const paths = [
1032
- import_path3.default.join("node_modules", ".pnpm", "@yamada-ui+core@*", ...themePath),
1033
- import_path3.default.join(...themePath),
1034
- import_path3.default.posix.join("node_modules", ".pnpm", "@yamada-ui+core@*", ...themePath),
1035
- import_path3.default.posix.join(...themePath)
1036
- ];
1037
- const triedPaths = await Promise.all(
1038
- paths.map(async (possiblePath) => {
1039
- const paths2 = await (0, import_glob.glob)(possiblePath);
1040
- if (paths2.length) return paths2[0];
1041
- return "";
1042
- })
1043
- );
1044
- const resolvedPath = triedPaths.find(Boolean);
1045
- if (!resolvedPath) return;
1046
- return import_path3.default.resolve(process.cwd(), resolvedPath);
1047
- };
1048
- var resolveOutputPath = async (outPath) => {
1049
- if (outPath) return import_path3.default.resolve(process.cwd(), outPath);
1050
- const themePath2 = await resolveThemePath();
1051
- if (!themePath2)
1052
- throw new Error(
1053
- "Could not find @yamada-ui/core in node_modules. Please provide `--out` parameter."
1054
- );
1055
- return themePath2;
1056
- };
1057
-
1058
- // src/command/tokens/index.ts
1059
- var generateThemeTypings = async ({
1060
- config: config2,
1061
- outFile,
1062
- theme
1063
- }) => {
1064
- p2.intro(source_default.magenta(`Generating Yamada UI theme typings`));
1065
- const s = p2.spinner();
1066
- try {
1067
- const start = process.hrtime.bigint();
1068
- s.start(`Parsing the theme`);
1069
- const generatedTheme = await createThemeTypings(theme, config2.theme ?? {});
1070
- s.stop(`Parsed the theme`);
1071
- s.start(`Resolving the output path`);
1072
- const outPath = await resolveOutputPath(outFile);
1073
- s.stop(`Resolved the output path`);
1074
- s.start(`Writing file "${outPath}"`);
1075
- await (0, import_promises3.writeFile)(outPath, generatedTheme, "utf8");
1076
- s.stop(`Wrote file`);
1077
- p2.note(outPath, "Output path");
1078
- const end = process.hrtime.bigint();
1079
- const duration = (Number(end - start) / 1e9).toFixed(2);
1080
- p2.outro(`${source_default.green(`Done`)} in ${source_default.dim(`${duration}s`)}
1081
- `);
1082
- } catch (e) {
1083
- s.stop(`An error occurred`, 500);
1084
- p2.cancel(source_default.red(e instanceof Error ? e.message : "Message is missing"));
1085
- }
1086
- };
1087
- var actionTokens = async (themePath2, { cwd = import_path4.default.resolve(), out: outFile, watch: watchFile }) => {
1088
- const readFile2 = async () => {
1089
- const filePath = import_path4.default.resolve(themePath2);
1090
- const { dependencies: dependencies2, mod } = await getModule(filePath, cwd);
1091
- const theme2 = mod?.default ?? mod?.theme ?? mod?.customTheme ?? mod?.defaultTheme ?? {};
1092
- const config3 = mod?.config ?? mod?.customConfig ?? mod?.defaultConfig ?? {};
1093
- return { config: config3, dependencies: dependencies2, theme: theme2 };
1094
- };
1095
- let file = await readFile2();
1096
- const { config: config2, dependencies, theme } = file;
1097
- const buildFile = async () => {
1098
- await generateThemeTypings({ config: config2, outFile, theme });
1099
- if (watchFile) console.log("\n", "\u231B\uFE0F Watching for changes...");
1100
- };
1101
- if (watchFile) {
1102
- const watchPath = typeof watchFile === "string" ? watchFile : dependencies;
1103
- import_chokidar.default.watch(watchPath).on("ready", buildFile).on("change", async (filePath) => {
1104
- console.log("\u{1F4E6} File changed", filePath);
1105
- file = await readFile2();
1106
- return buildFile();
1107
- });
1108
- } else {
1109
- await buildFile();
1110
- }
1111
- };
1112
- // Annotate the CommonJS export names for ESM import in node:
1113
- 0 && (module.exports = {
1114
- actionTheme,
1115
- actionTokens,
1116
- themePath
1117
- });