"use strict";
var He = Object.create;
var q = Object.defineProperty;
var $e = Object.getOwnPropertyDescriptor;
var je = Object.getOwnPropertyNames;
var Ve = Object.getPrototypeOf, Ge = Object.prototype.hasOwnProperty;
var l = (i, e) => q(i, "name", { value: e, configurable: !0 });
var Y = (i, e) => () => (e || i((e = { exports: {} }).exports, e), e.exports);
var Ue = (i, e, t, n) => {
  if (e && typeof e == "object" || typeof e == "function")
    for (let o of je(e))
      !Ge.call(i, o) && o !== t && q(i, o, { get: () => e[o], enumerable: !(n = $e(e, o)) || n.enumerable });
  return i;
};
var A = (i, e, t) => (t = i != null ? He(Ve(i)) : {}, Ue(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  e || !i || !i.__esModule ? q(t, "default", { value: i, enumerable: !0 }) : t,
  i
));

// ../node_modules/commander/index.js
var Ee = Y((O, Ae) => {
  var st = require("events").EventEmitter, X = require("child_process").spawn, C = require("path"), Z = require("fs"), P = class {
    static {
      l(this, "Option");
    }
    /**
     * Initialize a new `Option` with the given `flags` and `description`.
     *
     * @param {string} flags
     * @param {string} description
     * @api public
     */
    constructor(e, t) {
      this.flags = e, this.required = e.includes("<"), this.optional = e.includes("["), this.variadic = /\w\.\.\.[>\]]$/.test(e), this.mandatory =
      !1;
      let n = xe(e);
      this.short = n.shortFlag, this.long = n.longFlag, this.negate = !1, this.long && (this.negate = this.long.startsWith("--no-")), this.description =
      t || "", this.defaultValue = void 0;
    }
    /**
     * Return option name.
     *
     * @return {string}
     * @api private
     */
    name() {
      return this.long ? this.long.replace(/^--/, "") : this.short.replace(/^-/, "");
    }
    /**
     * Return option name, in a camelcase format that can be used
     * as a object attribute key.
     *
     * @return {string}
     * @api private
     */
    attributeName() {
      return rt(this.name().replace(/^no-/, ""));
    }
    /**
     * Check if `arg` matches the short or long flag.
     *
     * @param {string} arg
     * @return {boolean}
     * @api private
     */
    is(e) {
      return this.short === e || this.long === e;
    }
  }, S = class extends Error {
    static {
      l(this, "CommanderError");
    }
    /**
     * Constructs the CommanderError class
     * @param {number} exitCode suggested exit code which could be used with process.exit
     * @param {string} code an id string representing the error
     * @param {string} message human-readable description of the error
     * @constructor
     */
    constructor(e, t, n) {
      super(n), Error.captureStackTrace(this, this.constructor), this.name = this.constructor.name, this.code = t, this.exitCode = e, this.nestedError =
      void 0;
    }
  }, L = class i extends st {
    static {
      l(this, "Command");
    }
    /**
     * Initialize a new `Command`.
     *
     * @param {string} [name]
     * @api public
     */
    constructor(e) {
      super(), this.commands = [], this.options = [], this.parent = null, this._allowUnknownOption = !1, this._args = [], this.rawArgs = null,
      this._scriptPath = null, this._name = e || "", this._optionValues = {}, this._storeOptionsAsProperties = !0, this._storeOptionsAsPropertiesCalled =
      !1, this._passCommandToAction = !0, this._actionResults = [], this._actionHandler = null, this._executableHandler = !1, this._executableFile =
      null, this._defaultCommandName = null, this._exitCallback = null, this._aliases = [], this._combineFlagAndOptionalValue = !0, this._hidden =
      !1, this._hasHelpOption = !0, this._helpFlags = "-h, --help", this._helpDescription = "display help for command", this._helpShortFlag =
      "-h", this._helpLongFlag = "--help", this._hasImplicitHelpCommand = void 0, this._helpCommandName = "help", this._helpCommandnameAndArgs =
      "help [command]", this._helpCommandDescription = "display help for command";
    }
    /**
     * Define a command.
     *
     * There are two styles of command: pay attention to where to put the description.
     *
     * Examples:
     *
     *      // Command implemented using action handler (description is supplied separately to `.command`)
     *      program
     *        .command('clone <source> [destination]')
     *        .description('clone a repository into a newly created directory')
     *        .action((source, destination) => {
     *          console.log('clone command called');
     *        });
     *
     *      // Command implemented using separate executable file (description is second parameter to `.command`)
     *      program
     *        .command('start <service>', 'start named service')
     *        .command('stop [service]', 'stop named service, or all if no name supplied');
     *
     * @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
     * @param {Object|string} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
     * @param {Object} [execOpts] - configuration options (for executable)
     * @return {Command} returns new command for action handler, or `this` for executable command
     * @api public
     */
    command(e, t, n) {
      let o = t, s = n;
      typeof o == "object" && o !== null && (s = o, o = null), s = s || {};
      let a = e.split(/ +/), r = this.createCommand(a.shift());
      return o && (r.description(o), r._executableHandler = !0), s.isDefault && (this._defaultCommandName = r._name), r._hidden = !!(s.noHelp ||
      s.hidden), r._hasHelpOption = this._hasHelpOption, r._helpFlags = this._helpFlags, r._helpDescription = this._helpDescription, r._helpShortFlag =
      this._helpShortFlag, r._helpLongFlag = this._helpLongFlag, r._helpCommandName = this._helpCommandName, r._helpCommandnameAndArgs = this.
      _helpCommandnameAndArgs, r._helpCommandDescription = this._helpCommandDescription, r._exitCallback = this._exitCallback, r._storeOptionsAsProperties =
      this._storeOptionsAsProperties, r._passCommandToAction = this._passCommandToAction, r._combineFlagAndOptionalValue = this._combineFlagAndOptionalValue,
      r._executableFile = s.executableFile || null, this.commands.push(r), r._parseExpectedArgs(a), r.parent = this, o ? this : r;
    }
    /**
     * Factory routine to create a new unattached command.
     *
     * See .command() for creating an attached subcommand, which uses this routine to
     * create the command. You can override createCommand to customise subcommands.
     *
     * @param {string} [name]
     * @return {Command} new command
     * @api public
     */
    createCommand(e) {
      return new i(e);
    }
    /**
     * Add a prepared subcommand.
     *
     * See .command() for creating an attached subcommand which inherits settings from its parent.
     *
     * @param {Command} cmd - new subcommand
     * @param {Object} [opts] - configuration options
     * @return {Command} `this` command for chaining
     * @api public
     */
    addCommand(e, t) {
      if (!e._name) throw new Error("Command passed to .addCommand() must have a name");
      function n(o) {
        o.forEach((s) => {
          if (s._executableHandler && !s._executableFile)
            throw new Error(`Must specify executableFile for deeply nested executable: ${s.name()}`);
          n(s.commands);
        });
      }
      return l(n, "checkExplicitNames"), n(e.commands), t = t || {}, t.isDefault && (this._defaultCommandName = e._name), (t.noHelp || t.hidden) &&
      (e._hidden = !0), this.commands.push(e), e.parent = this, this;
    }
    /**
     * Define argument syntax for the command.
     *
     * @api public
     */
    arguments(e) {
      return this._parseExpectedArgs(e.split(/ +/));
    }
    /**
     * Override default decision whether to add implicit help command.
     *
     *    addHelpCommand() // force on
     *    addHelpCommand(false); // force off
     *    addHelpCommand('help [cmd]', 'display help for [cmd]'); // force on with custom details
     *
     * @return {Command} `this` command for chaining
     * @api public
     */
    addHelpCommand(e, t) {
      return e === !1 ? this._hasImplicitHelpCommand = !1 : (this._hasImplicitHelpCommand = !0, typeof e == "string" && (this._helpCommandName =
      e.split(" ")[0], this._helpCommandnameAndArgs = e), this._helpCommandDescription = t || this._helpCommandDescription), this;
    }
    /**
     * @return {boolean}
     * @api private
     */
    _lazyHasImplicitHelpCommand() {
      return this._hasImplicitHelpCommand === void 0 && (this._hasImplicitHelpCommand = this.commands.length && !this._actionHandler && !this.
      _findCommand("help")), this._hasImplicitHelpCommand;
    }
    /**
     * Parse expected `args`.
     *
     * For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`.
     *
     * @param {Array} args
     * @return {Command} `this` command for chaining
     * @api private
     */
    _parseExpectedArgs(e) {
      if (e.length)
        return e.forEach((t) => {
          let n = {
            required: !1,
            name: "",
            variadic: !1
          };
          switch (t[0]) {
            case "<":
              n.required = !0, n.name = t.slice(1, -1);
              break;
            case "[":
              n.name = t.slice(1, -1);
              break;
          }
          n.name.length > 3 && n.name.slice(-3) === "..." && (n.variadic = !0, n.name = n.name.slice(0, -3)), n.name && this._args.push(n);
        }), this._args.forEach((t, n) => {
          if (t.variadic && n < this._args.length - 1)
            throw new Error(`only the last argument can be variadic '${t.name}'`);
        }), this;
    }
    /**
     * Register callback to use as replacement for calling process.exit.
     *
     * @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
     * @return {Command} `this` command for chaining
     * @api public
     */
    exitOverride(e) {
      return e ? this._exitCallback = e : this._exitCallback = (t) => {
        if (t.code !== "commander.executeSubCommandAsync")
          throw t;
      }, this;
    }
    /**
     * Call process.exit, and _exitCallback if defined.
     *
     * @param {number} exitCode exit code for using with process.exit
     * @param {string} code an id string representing the error
     * @param {string} message human-readable description of the error
     * @return never
     * @api private
     */
    _exit(e, t, n) {
      this._exitCallback && this._exitCallback(new S(e, t, n)), process.exit(e);
    }
    /**
     * Register callback `fn` for the command.
     *
     * Examples:
     *
     *      program
     *        .command('help')
     *        .description('display verbose help')
     *        .action(function() {
     *           // output help here
     *        });
     *
     * @param {Function} fn
     * @return {Command} `this` command for chaining
     * @api public
     */
    action(e) {
      let t = /* @__PURE__ */ l((n) => {
        let o = this._args.length, s = n.slice(0, o);
        this._passCommandToAction ? s[o] = this : s[o] = this.opts(), n.length > o && s.push(n.slice(o));
        let a = e.apply(this, s), r = this;
        for (; r.parent; )
          r = r.parent;
        r._actionResults.push(a);
      }, "listener");
      return this._actionHandler = t, this;
    }
    /**
     * Internal routine to check whether there is a clash storing option value with a Command property.
     *
     * @param {Option} option
     * @api private
     */
    _checkForOptionNameClash(e) {
      if (!this._storeOptionsAsProperties || this._storeOptionsAsPropertiesCalled || e.name() === "help" || this._getOptionValue(e.attributeName()) ===
      void 0)
        return;
      let n = !0;
      if (e.negate) {
        let o = e.long.replace(/^--no-/, "--");
        n = !this._findOption(o);
      } else if (e.long) {
        let o = e.long.replace(/^--/, "--no-");
        n = !this._findOption(o);
      }
      if (n)
        throw new Error(`option '${e.name()}' clashes with existing property '${e.attributeName()}' on Command
- call storeOptionsAsProperties(false) to store option values safely,
- or call storeOptionsAsProperties(true) to suppress this check,
- or change option name

Read more on https://git.io/JJc0W`);
    }
    /**
     * Internal implementation shared by .option() and .requiredOption()
     *
     * @param {Object} config
     * @param {string} flags
     * @param {string} description
     * @param {Function|*} [fn] - custom option processing function or default value
     * @param {*} [defaultValue]
     * @return {Command} `this` command for chaining
     * @api private
     */
    _optionEx(e, t, n, o, s) {
      let a = new P(t, n), r = a.name(), c = a.attributeName();
      if (a.mandatory = !!e.mandatory, this._checkForOptionNameClash(a), typeof o != "function")
        if (o instanceof RegExp) {
          let h = o;
          o = /* @__PURE__ */ l((p, f) => {
            let u = h.exec(p);
            return u ? u[0] : f;
          }, "fn");
        } else
          s = o, o = null;
      if (a.negate || a.optional || a.required || typeof s == "boolean") {
        if (a.negate) {
          let h = a.long.replace(/^--no-/, "--");
          s = this._findOption(h) ? this._getOptionValue(c) : !0;
        }
        s !== void 0 && (this._setOptionValue(c, s), a.defaultValue = s);
      }
      return this.options.push(a), this.on("option:" + r, (h) => {
        let p = this._getOptionValue(c);
        h !== null && o ? h = o(h, p === void 0 ? s : p) : h !== null && a.variadic && (p === s || !Array.isArray(p) ? h = [h] : h = p.concat(
        h)), typeof p == "boolean" || typeof p > "u" ? h == null ? this._setOptionValue(c, a.negate ? !1 : s || !0) : this._setOptionValue(c,
        h) : h !== null && this._setOptionValue(c, a.negate ? !1 : h);
      }), this;
    }
    /**
     * Define option with `flags`, `description` and optional
     * coercion `fn`.
     *
     * The `flags` string should contain both the short and long flags,
     * separated by comma, a pipe or space. The following are all valid
     * all will output this way when `--help` is used.
     *
     *    "-p, --pepper"
     *    "-p|--pepper"
     *    "-p --pepper"
     *
     * Examples:
     *
     *     // simple boolean defaulting to undefined
     *     program.option('-p, --pepper', 'add pepper');
     *
     *     program.pepper
     *     // => undefined
     *
     *     --pepper
     *     program.pepper
     *     // => true
     *
     *     // simple boolean defaulting to true (unless non-negated option is also defined)
     *     program.option('-C, --no-cheese', 'remove cheese');
     *
     *     program.cheese
     *     // => true
     *
     *     --no-cheese
     *     program.cheese
     *     // => false
     *
     *     // required argument
     *     program.option('-C, --chdir <path>', 'change the working directory');
     *
     *     --chdir /tmp
     *     program.chdir
     *     // => "/tmp"
     *
     *     // optional argument
     *     program.option('-c, --cheese [type]', 'add cheese [marble]');
     *
     * @param {string} flags
     * @param {string} description
     * @param {Function|*} [fn] - custom option processing function or default value
     * @param {*} [defaultValue]
     * @return {Command} `this` command for chaining
     * @api public
     */
    option(e, t, n, o) {
      return this._optionEx({}, e, t, n, o);
    }
    /**
    * Add a required option which must have a value after parsing. This usually means
    * the option must be specified on the command line. (Otherwise the same as .option().)
    *
    * The `flags` string should contain both the short and long flags, separated by comma, a pipe or space.
    *
    * @param {string} flags
    * @param {string} description
    * @param {Function|*} [fn] - custom option processing function or default value
    * @param {*} [defaultValue]
    * @return {Command} `this` command for chaining
    * @api public
    */
    requiredOption(e, t, n, o) {
      return this._optionEx({ mandatory: !0 }, e, t, n, o);
    }
    /**
     * Alter parsing of short flags with optional values.
     *
     * Examples:
     *
     *    // for `.option('-f,--flag [value]'):
     *    .combineFlagAndOptionalValue(true)  // `-f80` is treated like `--flag=80`, this is the default behaviour
     *    .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
     *
     * @param {Boolean} [arg] - if `true` or omitted, an optional value can be specified directly after the flag.
     * @api public
     */
    combineFlagAndOptionalValue(e) {
      return this._combineFlagAndOptionalValue = e === void 0 || e, this;
    }
    /**
     * Allow unknown options on the command line.
     *
     * @param {Boolean} [arg] - if `true` or omitted, no error will be thrown
     * for unknown options.
     * @api public
     */
    allowUnknownOption(e) {
      return this._allowUnknownOption = e === void 0 || e, this;
    }
    /**
      * Whether to store option values as properties on command object,
      * or store separately (specify false). In both cases the option values can be accessed using .opts().
      *
      * @param {boolean} value
      * @return {Command} `this` command for chaining
      * @api public
      */
    storeOptionsAsProperties(e) {
      if (this._storeOptionsAsPropertiesCalled = !0, this._storeOptionsAsProperties = e === void 0 || e, this.options.length)
        throw new Error("call .storeOptionsAsProperties() before adding options");
      return this;
    }
    /**
      * Whether to pass command to action handler,
      * or just the options (specify false).
      *
      * @param {boolean} value
      * @return {Command} `this` command for chaining
      * @api public
      */
    passCommandToAction(e) {
      return this._passCommandToAction = e === void 0 || e, this;
    }
    /**
     * Store option value
     *
     * @param {string} key
     * @param {Object} value
     * @api private
     */
    _setOptionValue(e, t) {
      this._storeOptionsAsProperties ? this[e] = t : this._optionValues[e] = t;
    }
    /**
     * Retrieve option value
     *
     * @param {string} key
     * @return {Object} value
     * @api private
     */
    _getOptionValue(e) {
      return this._storeOptionsAsProperties ? this[e] : this._optionValues[e];
    }
    /**
     * Parse `argv`, setting options and invoking commands when defined.
     *
     * The default expectation is that the arguments are from node and have the application as argv[0]
     * and the script being run in argv[1], with user parameters after that.
     *
     * Examples:
     *
     *      program.parse(process.argv);
     *      program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
     *      program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
     *
     * @param {string[]} [argv] - optional, defaults to process.argv
     * @param {Object} [parseOptions] - optionally specify style of options with from: node/user/electron
     * @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
     * @return {Command} `this` command for chaining
     * @api public
     */
    parse(e, t) {
      if (e !== void 0 && !Array.isArray(e))
        throw new Error("first parameter to parse must be array or undefined");
      t = t || {}, e === void 0 && (e = process.argv, process.versions && process.versions.electron && (t.from = "electron")), this.rawArgs =
      e.slice();
      let n;
      switch (t.from) {
        case void 0:
        case "node":
          this._scriptPath = e[1], n = e.slice(2);
          break;
        case "electron":
          process.defaultApp ? (this._scriptPath = e[1], n = e.slice(2)) : n = e.slice(1);
          break;
        case "user":
          n = e.slice(0);
          break;
        default:
          throw new Error(`unexpected parse option { from: '${t.from}' }`);
      }
      return !this._scriptPath && process.mainModule && (this._scriptPath = process.mainModule.filename), this._name = this._name || this._scriptPath &&
      C.basename(this._scriptPath, C.extname(this._scriptPath)), this._parseCommand([], n), this;
    }
    /**
     * Parse `argv`, setting options and invoking commands when defined.
     *
     * Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
     *
     * The default expectation is that the arguments are from node and have the application as argv[0]
     * and the script being run in argv[1], with user parameters after that.
     *
     * Examples:
     *
     *      program.parseAsync(process.argv);
     *      program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
     *      program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
     *
     * @param {string[]} [argv]
     * @param {Object} [parseOptions]
     * @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
     * @return {Promise}
     * @api public
     */
    parseAsync(e, t) {
      return this.parse(e, t), Promise.all(this._actionResults).then(() => this);
    }
    /**
     * Execute a sub-command executable.
     *
     * @api private
     */
    _executeSubCommand(e, t) {
      t = t.slice();
      let n = !1, o = [".js", ".ts", ".tsx", ".mjs"];
      this._checkForMissingMandatoryOptions();
      let s = this._scriptPath;
      !s && process.mainModule && (s = process.mainModule.filename);
      let a;
      try {
        let u = Z.realpathSync(s);
        a = C.dirname(u);
      } catch {
        a = ".";
      }
      let r = C.basename(s, C.extname(s)) + "-" + e._name;
      e._executableFile && (r = e._executableFile);
      let c = C.join(a, r);
      Z.existsSync(c) ? r = c : o.forEach((u) => {
        Z.existsSync(`${c}${u}`) && (r = `${c}${u}`);
      }), n = o.includes(C.extname(r));
      let h;
      process.platform !== "win32" ? n ? (t.unshift(r), t = ve(process.execArgv).concat(t), h = X(process.argv[0], t, { stdio: "inherit" })) :
      h = X(r, t, { stdio: "inherit" }) : (t.unshift(r), t = ve(process.execArgv).concat(t), h = X(process.execPath, t, { stdio: "inherit" })),
      ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"].forEach((u) => {
        process.on(u, () => {
          h.killed === !1 && h.exitCode === null && h.kill(u);
        });
      });
      let f = this._exitCallback;
      f ? h.on("close", () => {
        f(new S(process.exitCode || 0, "commander.executeSubCommandAsync", "(close)"));
      }) : h.on("close", process.exit.bind(process)), h.on("error", (u) => {
        if (u.code === "ENOENT") {
          let x = `'${r}' does not exist
 - if '${e._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead\

 - if the default executable name is not suitable, use the executableFile option to supply a custom name`;
          throw new Error(x);
        } else if (u.code === "EACCES")
          throw new Error(`'${r}' not executable`);
        if (!f)
          process.exit(1);
        else {
          let x = new S(1, "commander.executeSubCommandAsync", "(error)");
          x.nestedError = u, f(x);
        }
      }), this.runningCommand = h;
    }
    /**
     * @api private
     */
    _dispatchSubcommand(e, t, n) {
      let o = this._findCommand(e);
      o || this._helpAndError(), o._executableHandler ? this._executeSubCommand(o, t.concat(n)) : o._parseCommand(t, n);
    }
    /**
     * Process arguments in context of this command.
     *
     * @api private
     */
    _parseCommand(e, t) {
      let n = this.parseOptions(t);
      if (e = e.concat(n.operands), t = n.unknown, this.args = e.concat(t), e && this._findCommand(e[0]))
        this._dispatchSubcommand(e[0], e.slice(1), t);
      else if (this._lazyHasImplicitHelpCommand() && e[0] === this._helpCommandName)
        e.length === 1 ? this.help() : this._dispatchSubcommand(e[1], [], [this._helpLongFlag]);
      else if (this._defaultCommandName)
        Ce(this, t), this._dispatchSubcommand(this._defaultCommandName, e, t);
      else if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName && this._helpAndError(), Ce(
      this, n.unknown), this._checkForMissingMandatoryOptions(), n.unknown.length > 0 && this.unknownOption(n.unknown[0]), this._actionHandler) {
        let o = this.args.slice();
        this._args.forEach((s, a) => {
          s.required && o[a] == null ? this.missingArgument(s.name) : s.variadic && (o[a] = o.splice(a));
        }), this._actionHandler(o), this.emit("command:" + this.name(), e, t);
      } else e.length ? this._findCommand("*") ? this._dispatchSubcommand("*", e, t) : this.listenerCount("command:*") ? this.emit("command:\
*", e, t) : this.commands.length && this.unknownCommand() : this.commands.length && this._helpAndError();
    }
    /**
     * Find matching command.
     *
     * @api private
     */
    _findCommand(e) {
      if (e)
        return this.commands.find((t) => t._name === e || t._aliases.includes(e));
    }
    /**
     * Return an option matching `arg` if any.
     *
     * @param {string} arg
     * @return {Option}
     * @api private
     */
    _findOption(e) {
      return this.options.find((t) => t.is(e));
    }
    /**
     * Display an error message if a mandatory option does not have a value.
     * Lazy calling after checking for help flags from leaf subcommand.
     *
     * @api private
     */
    _checkForMissingMandatoryOptions() {
      for (let e = this; e; e = e.parent)
        e.options.forEach((t) => {
          t.mandatory && e._getOptionValue(t.attributeName()) === void 0 && e.missingMandatoryOptionValue(t);
        });
    }
    /**
     * Parse options from `argv` removing known options,
     * and return argv split into operands and unknown arguments.
     *
     * Examples:
     *
     *    argv => operands, unknown
     *    --known kkk op => [op], []
     *    op --known kkk => [op], []
     *    sub --unknown uuu op => [sub], [--unknown uuu op]
     *    sub -- --unknown uuu op => [sub --unknown uuu op], []
     *
     * @param {String[]} argv
     * @return {{operands: String[], unknown: String[]}}
     * @api public
     */
    parseOptions(e) {
      let t = [], n = [], o = t, s = e.slice();
      function a(c) {
        return c.length > 1 && c[0] === "-";
      }
      l(a, "maybeOption");
      let r = null;
      for (; s.length; ) {
        let c = s.shift();
        if (c === "--") {
          o === n && o.push(c), o.push(...s);
          break;
        }
        if (r && !a(c)) {
          this.emit(`option:${r.name()}`, c);
          continue;
        }
        if (r = null, a(c)) {
          let h = this._findOption(c);
          if (h) {
            if (h.required) {
              let p = s.shift();
              p === void 0 && this.optionMissingArgument(h), this.emit(`option:${h.name()}`, p);
            } else if (h.optional) {
              let p = null;
              s.length > 0 && !a(s[0]) && (p = s.shift()), this.emit(`option:${h.name()}`, p);
            } else
              this.emit(`option:${h.name()}`);
            r = h.variadic ? h : null;
            continue;
          }
        }
        if (c.length > 2 && c[0] === "-" && c[1] !== "-") {
          let h = this._findOption(`-${c[1]}`);
          if (h) {
            h.required || h.optional && this._combineFlagAndOptionalValue ? this.emit(`option:${h.name()}`, c.slice(2)) : (this.emit(`option\
:${h.name()}`), s.unshift(`-${c.slice(2)}`));
            continue;
          }
        }
        if (/^--[^=]+=/.test(c)) {
          let h = c.indexOf("="), p = this._findOption(c.slice(0, h));
          if (p && (p.required || p.optional)) {
            this.emit(`option:${p.name()}`, c.slice(h + 1));
            continue;
          }
        }
        c.length > 1 && c[0] === "-" && (o = n), o.push(c);
      }
      return { operands: t, unknown: n };
    }
    /**
     * Return an object containing options as key-value pairs
     *
     * @return {Object}
     * @api public
     */
    opts() {
      if (this._storeOptionsAsProperties) {
        let e = {}, t = this.options.length;
        for (let n = 0; n < t; n++) {
          let o = this.options[n].attributeName();
          e[o] = o === this._versionOptionName ? this._version : this[o];
        }
        return e;
      }
      return this._optionValues;
    }
    /**
     * Argument `name` is missing.
     *
     * @param {string} name
     * @api private
     */
    missingArgument(e) {
      let t = `error: missing required argument '${e}'`;
      console.error(t), this._exit(1, "commander.missingArgument", t);
    }
    /**
     * `Option` is missing an argument, but received `flag` or nothing.
     *
     * @param {Option} option
     * @param {string} [flag]
     * @api private
     */
    optionMissingArgument(e, t) {
      let n;
      t ? n = `error: option '${e.flags}' argument missing, got '${t}'` : n = `error: option '${e.flags}' argument missing`, console.error(n),
      this._exit(1, "commander.optionMissingArgument", n);
    }
    /**
     * `Option` does not have a value, and is a mandatory option.
     *
     * @param {Option} option
     * @api private
     */
    missingMandatoryOptionValue(e) {
      let t = `error: required option '${e.flags}' not specified`;
      console.error(t), this._exit(1, "commander.missingMandatoryOptionValue", t);
    }
    /**
     * Unknown option `flag`.
     *
     * @param {string} flag
     * @api private
     */
    unknownOption(e) {
      if (this._allowUnknownOption) return;
      let t = `error: unknown option '${e}'`;
      console.error(t), this._exit(1, "commander.unknownOption", t);
    }
    /**
     * Unknown command.
     *
     * @api private
     */
    unknownCommand() {
      let e = [this.name()];
      for (let o = this.parent; o; o = o.parent)
        e.unshift(o.name());
      let t = e.join(" "), n = `error: unknown command '${this.args[0]}'.` + (this._hasHelpOption ? ` See '${t} ${this._helpLongFlag}'.` : "");
      console.error(n), this._exit(1, "commander.unknownCommand", n);
    }
    /**
     * Set the program version to `str`.
     *
     * This method auto-registers the "-V, --version" flag
     * which will print the version number when passed.
     *
     * You can optionally supply the  flags and description to override the defaults.
     *
     * @param {string} str
     * @param {string} [flags]
     * @param {string} [description]
     * @return {this | string} `this` command for chaining, or version string if no arguments
     * @api public
     */
    version(e, t, n) {
      if (e === void 0) return this._version;
      this._version = e, t = t || "-V, --version", n = n || "output the version number";
      let o = new P(t, n);
      return this._versionOptionName = o.attributeName(), this.options.push(o), this.on("option:" + o.name(), () => {
        process.stdout.write(e + `
`), this._exit(0, "commander.version", e);
      }), this;
    }
    /**
     * Set the description to `str`.
     *
     * @param {string} str
     * @param {Object} [argsDescription]
     * @return {string|Command}
     * @api public
     */
    description(e, t) {
      return e === void 0 && t === void 0 ? this._description : (this._description = e, this._argsDescription = t, this);
    }
    /**
     * Set an alias for the command.
     *
     * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
     *
     * @param {string} [alias]
     * @return {string|Command}
     * @api public
     */
    alias(e) {
      if (e === void 0) return this._aliases[0];
      let t = this;
      if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler && (t = this.commands[this.commands.length -
      1]), e === t._name) throw new Error("Command alias can't be the same as its name");
      return t._aliases.push(e), this;
    }
    /**
     * Set aliases for the command.
     *
     * Only the first alias is shown in the auto-generated help.
     *
     * @param {string[]} [aliases]
     * @return {string[]|Command}
     * @api public
     */
    aliases(e) {
      return e === void 0 ? this._aliases : (e.forEach((t) => this.alias(t)), this);
    }
    /**
     * Set / get the command usage `str`.
     *
     * @param {string} [str]
     * @return {String|Command}
     * @api public
     */
    usage(e) {
      if (e === void 0) {
        if (this._usage) return this._usage;
        let t = this._args.map((n) => Oe(n));
        return [].concat(
          this.options.length || this._hasHelpOption ? "[options]" : [],
          this.commands.length ? "[command]" : [],
          this._args.length ? t : []
        ).join(" ");
      }
      return this._usage = e, this;
    }
    /**
     * Get or set the name of the command
     *
     * @param {string} [str]
     * @return {String|Command}
     * @api public
     */
    name(e) {
      return e === void 0 ? this._name : (this._name = e, this);
    }
    /**
     * Return prepared commands.
     *
     * @return {Array}
     * @api private
     */
    prepareCommands() {
      let e = this.commands.filter((t) => !t._hidden).map((t) => {
        let n = t._args.map((o) => Oe(o)).join(" ");
        return [
          t._name + (t._aliases[0] ? "|" + t._aliases[0] : "") + (t.options.length ? " [options]" : "") + (n ? " " + n : ""),
          t._description
        ];
      });
      return this._lazyHasImplicitHelpCommand() && e.push([this._helpCommandnameAndArgs, this._helpCommandDescription]), e;
    }
    /**
     * Return the largest command length.
     *
     * @return {number}
     * @api private
     */
    largestCommandLength() {
      return this.prepareCommands().reduce((t, n) => Math.max(t, n[0].length), 0);
    }
    /**
     * Return the largest option length.
     *
     * @return {number}
     * @api private
     */
    largestOptionLength() {
      let e = [].slice.call(this.options);
      return e.push({
        flags: this._helpFlags
      }), e.reduce((t, n) => Math.max(t, n.flags.length), 0);
    }
    /**
     * Return the largest arg length.
     *
     * @return {number}
     * @api private
     */
    largestArgLength() {
      return this._args.reduce((e, t) => Math.max(e, t.name.length), 0);
    }
    /**
     * Return the pad width.
     *
     * @return {number}
     * @api private
     */
    padWidth() {
      let e = this.largestOptionLength();
      return this._argsDescription && this._args.length && this.largestArgLength() > e && (e = this.largestArgLength()), this.commands && this.
      commands.length && this.largestCommandLength() > e && (e = this.largestCommandLength()), e;
    }
    /**
     * Return help for options.
     *
     * @return {string}
     * @api private
     */
    optionHelp() {
      let e = this.padWidth(), n = (process.stdout.columns || 80) - e - 4;
      function o(c, h) {
        return ee(c, e) + "  " + ye(h, n, e + 2);
      }
      l(o, "padOptionDetails");
      let s = this.options.map((c) => {
        let h = c.description + (!c.negate && c.defaultValue !== void 0 ? " (default: " + JSON.stringify(c.defaultValue) + ")" : "");
        return o(c.flags, h);
      }), a = this._hasHelpOption && this._helpShortFlag && !this._findOption(this._helpShortFlag), r = this._hasHelpOption && !this._findOption(
      this._helpLongFlag);
      if (a || r) {
        let c = this._helpFlags;
        a ? r || (c = this._helpShortFlag) : c = this._helpLongFlag, s.push(o(c, this._helpDescription));
      }
      return s.join(`
`);
    }
    /**
     * Return command help documentation.
     *
     * @return {string}
     * @api private
     */
    commandHelp() {
      if (!this.commands.length && !this._lazyHasImplicitHelpCommand()) return "";
      let e = this.prepareCommands(), t = this.padWidth(), o = (process.stdout.columns || 80) - t - 4;
      return [
        "Commands:",
        e.map((s) => {
          let a = s[1] ? "  " + s[1] : "";
          return (a ? ee(s[0], t) : s[0]) + ye(a, o, t + 2);
        }).join(`
`).replace(/^/gm, "  "),
        ""
      ].join(`
`);
    }
    /**
     * Return program help documentation.
     *
     * @return {string}
     * @api public
     */
    helpInformation() {
      let e = [];
      if (this._description) {
        e = [
          this._description,
          ""
        ];
        let c = this._argsDescription;
        if (c && this._args.length) {
          let h = this.padWidth(), f = (process.stdout.columns || 80) - h - 5;
          e.push("Arguments:"), this._args.forEach((u) => {
            e.push("  " + ee(u.name, h) + "  " + we(c[u.name] || "", f, h + 4));
          }), e.push("");
        }
      }
      let t = this._name;
      this._aliases[0] && (t = t + "|" + this._aliases[0]);
      let n = "";
      for (let c = this.parent; c; c = c.parent)
        n = c.name() + " " + n;
      let o = [
        "Usage: " + n + t + " " + this.usage(),
        ""
      ], s = [], a = this.commandHelp();
      a && (s = [a]);
      let r = [];
      return (this._hasHelpOption || this.options.length > 0) && (r = [
        "Options:",
        "" + this.optionHelp().replace(/^/gm, "  "),
        ""
      ]), o.concat(e).concat(r).concat(s).join(`
`);
    }
    /**
     * Output help information for this command.
     *
     * When listener(s) are available for the helpLongFlag
     * those callbacks are invoked.
     *
     * @api public
     */
    outputHelp(e) {
      e || (e = /* @__PURE__ */ l((n) => n, "cb"));
      let t = e(this.helpInformation());
      if (typeof t != "string" && !Buffer.isBuffer(t))
        throw new Error("outputHelp callback must return a string or a Buffer");
      process.stdout.write(t), this.emit(this._helpLongFlag);
    }
    /**
     * You can pass in flags and a description to override the help
     * flags and help description for your command. Pass in false to
     * disable the built-in help option.
     *
     * @param {string | boolean} [flags]
     * @param {string} [description]
     * @return {Command} `this` command for chaining
     * @api public
     */
    helpOption(e, t) {
      if (typeof e == "boolean")
        return this._hasHelpOption = e, this;
      this._helpFlags = e || this._helpFlags, this._helpDescription = t || this._helpDescription;
      let n = xe(this._helpFlags);
      return this._helpShortFlag = n.shortFlag, this._helpLongFlag = n.longFlag, this;
    }
    /**
     * Output help information and exit.
     *
     * @param {Function} [cb]
     * @api public
     */
    help(e) {
      this.outputHelp(e), this._exit(process.exitCode || 0, "commander.help", "(outputHelp)");
    }
    /**
     * Output help information and exit. Display for error situations.
     *
     * @api private
     */
    _helpAndError() {
      this.outputHelp(), this._exit(1, "commander.help", "(outputHelp)");
    }
  };
  O = Ae.exports = new L();
  O.program = O;
  O.Command = L;
  O.Option = P;
  O.CommanderError = S;
  function rt(i) {
    return i.split("-").reduce((e, t) => e + t[0].toUpperCase() + t.slice(1));
  }
  l(rt, "camelcase");
  function ee(i, e) {
    let t = Math.max(0, e - i.length);
    return i + Array(t + 1).join(" ");
  }
  l(ee, "pad");
  function we(i, e, t) {
    let n = new RegExp(".{1," + (e - 1) + "}([\\s\u200B]|$)|[^\\s\u200B]+?([\\s\u200B]|$)", "g");
    return (i.match(n) || []).map((s, a) => (s.slice(-1) === `
` && (s = s.slice(0, s.length - 1)), (a > 0 && t ? Array(t + 1).join(" ") : "") + s.trimRight())).join(`
`);
  }
  l(we, "wrap");
  function ye(i, e, t) {
    return i.match(/[\n]\s+/) || e < 40 ? i : we(i, e, t);
  }
  l(ye, "optionalWrap");
  function Ce(i, e) {
    i._hasHelpOption && e.find((n) => n === i._helpLongFlag || n === i._helpShortFlag) && (i.outputHelp(), i._exit(0, "commander.helpDisplay\
ed", "(outputHelp)"));
  }
  l(Ce, "outputHelpIfRequested");
  function Oe(i) {
    let e = i.name + (i.variadic === !0 ? "..." : "");
    return i.required ? "<" + e + ">" : "[" + e + "]";
  }
  l(Oe, "humanReadableArgName");
  function xe(i) {
    let e, t, n = i.split(/[ |,]+/);
    return n.length > 1 && !/^[[<]/.test(n[1]) && (e = n.shift()), t = n.shift(), !e && /^-[^-]$/.test(t) && (e = t, t = void 0), { shortFlag: e,
    longFlag: t };
  }
  l(xe, "_parseOptionFlags");
  function ve(i) {
    return i.map((e) => {
      if (!e.startsWith("--inspect"))
        return e;
      let t, n = "127.0.0.1", o = "9229", s;
      return (s = e.match(/^(--inspect(-brk)?)$/)) !== null ? t = s[1] : (s = e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null ? (t =
      s[1], /^\d+$/.test(s[3]) ? o = s[3] : n = s[3]) : (s = e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null && (t = s[1], n =
      s[3], o = s[4]), t && o !== "0" ? `${t}=${n}:${parseInt(o) + 1}` : e;
    });
  }
  l(ve, "incrementNodeInspectorPort");
});

// ../node_modules/walk-up-path/dist/cjs/index.js
var Se = Y((H) => {
  "use strict";
  Object.defineProperty(H, "__esModule", { value: !0 });
  H.walkUp = void 0;
  var ke = require("path"), at = /* @__PURE__ */ l(function* (i) {
    for (i = (0, ke.resolve)(i); i; ) {
      yield i;
      let e = (0, ke.dirname)(i);
      if (e === i)
        break;
      i = e;
    }
  }, "walkUp");
  H.walkUp = at;
});

// ../node_modules/ts-dedent/dist/index.js
var Re = Y((I) => {
  "use strict";
  Object.defineProperty(I, "__esModule", { value: !0 });
  I.dedent = void 0;
  function Ie(i) {
    for (var e = [], t = 1; t < arguments.length; t++)
      e[t - 1] = arguments[t];
    var n = Array.from(typeof i == "string" ? [i] : i);
    n[n.length - 1] = n[n.length - 1].replace(/\r?\n([\t ]*)$/, "");
    var o = n.reduce(function(r, c) {
      var h = c.match(/\n([\t ]+|(?!\s).)/g);
      return h ? r.concat(h.map(function(p) {
        var f, u;
        return (u = (f = p.match(/[\t ]/g)) === null || f === void 0 ? void 0 : f.length) !== null && u !== void 0 ? u : 0;
      })) : r;
    }, []);
    if (o.length) {
      var s = new RegExp(`
[	 ]{` + Math.min.apply(Math, o) + "}", "g");
      n = n.map(function(r) {
        return r.replace(s, `
`);
      });
    }
    n[0] = n[0].replace(/^\r?\n/, "");
    var a = n[0];
    return e.forEach(function(r, c) {
      var h = a.match(/(?:^|\n)( *)$/), p = h ? h[1] : "", f = r;
      typeof r == "string" && r.includes(`
`) && (f = String(r).split(`
`).map(function(u, x) {
        return x === 0 ? u : "" + p + u;
      }).join(`
`)), a += f + n[c + 1];
    }), a;
  }
  l(Ie, "dedent");
  I.dedent = Ie;
  I.default = Ie;
});

// src/cli/bin/index.ts
var w = require("@storybook/core/common"), Be = require("@storybook/core/telemetry"), ae = require("@storybook/core/node-logger");

// node_modules/chalk/source/vendor/ansi-styles/index.js
var le = /* @__PURE__ */ l((i = 0) => (e) => `\x1B[${e + i}m`, "wrapAnsi16"), ce = /* @__PURE__ */ l((i = 0) => (e) => `\x1B[${38 + i};5;${e}\
m`, "wrapAnsi256"), he = /* @__PURE__ */ l((i = 0) => (e, t, n) => `\x1B[${38 + i};2;${e};${t};${n}m`, "wrapAnsi16m"), m = {
  modifier: {
    reset: [0, 0],
    // 21 isn't widely supported and 22 does the same thing
    bold: [1, 22],
    dim: [2, 22],
    italic: [3, 23],
    underline: [4, 24],
    overline: [53, 55],
    inverse: [7, 27],
    hidden: [8, 28],
    strikethrough: [9, 29]
  },
  color: {
    black: [30, 39],
    red: [31, 39],
    green: [32, 39],
    yellow: [33, 39],
    blue: [34, 39],
    magenta: [35, 39],
    cyan: [36, 39],
    white: [37, 39],
    // Bright color
    blackBright: [90, 39],
    gray: [90, 39],
    // Alias of `blackBright`
    grey: [90, 39],
    // Alias of `blackBright`
    redBright: [91, 39],
    greenBright: [92, 39],
    yellowBright: [93, 39],
    blueBright: [94, 39],
    magentaBright: [95, 39],
    cyanBright: [96, 39],
    whiteBright: [97, 39]
  },
  bgColor: {
    bgBlack: [40, 49],
    bgRed: [41, 49],
    bgGreen: [42, 49],
    bgYellow: [43, 49],
    bgBlue: [44, 49],
    bgMagenta: [45, 49],
    bgCyan: [46, 49],
    bgWhite: [47, 49],
    // Bright color
    bgBlackBright: [100, 49],
    bgGray: [100, 49],
    // Alias of `bgBlackBright`
    bgGrey: [100, 49],
    // Alias of `bgBlackBright`
    bgRedBright: [101, 49],
    bgGreenBright: [102, 49],
    bgYellowBright: [103, 49],
    bgBlueBright: [104, 49],
    bgMagentaBright: [105, 49],
    bgCyanBright: [106, 49],
    bgWhiteBright: [107, 49]
  }
}, ft = Object.keys(m.modifier), We = Object.keys(m.color), qe = Object.keys(m.bgColor), gt = [...We, ...qe];
function Ye() {
  let i = /* @__PURE__ */ new Map();
  for (let [e, t] of Object.entries(m)) {
    for (let [n, o] of Object.entries(t))
      m[n] = {
        open: `\x1B[${o[0]}m`,
        close: `\x1B[${o[1]}m`
      }, t[n] = m[n], i.set(o[0], o[1]);
    Object.defineProperty(m, e, {
      value: t,
      enumerable: !1
    });
  }
  return Object.defineProperty(m, "codes", {
    value: i,
    enumerable: !1
  }), m.color.close = "\x1B[39m", m.bgColor.close = "\x1B[49m", m.color.ansi = le(), m.color.ansi256 = ce(), m.color.ansi16m = he(), m.bgColor.
  ansi = le(10), m.bgColor.ansi256 = ce(10), m.bgColor.ansi16m = he(10), Object.defineProperties(m, {
    rgbToAnsi256: {
      value(e, t, n) {
        return e === t && t === n ? e < 8 ? 16 : e > 248 ? 231 : Math.round((e - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(e / 255 * 5) + 6 *
        Math.round(t / 255 * 5) + Math.round(n / 255 * 5);
      },
      enumerable: !1
    },
    hexToRgb: {
      value(e) {
        let t = /[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));
        if (!t)
          return [0, 0, 0];
        let [n] = t;
        n.length === 3 && (n = [...n].map((s) => s + s).join(""));
        let o = Number.parseInt(n, 16);
        return [
          /* eslint-disable no-bitwise */
          o >> 16 & 255,
          o >> 8 & 255,
          o & 255
          /* eslint-enable no-bitwise */
        ];
      },
      enumerable: !1
    },
    hexToAnsi256: {
      value: /* @__PURE__ */ l((e) => m.rgbToAnsi256(...m.hexToRgb(e)), "value"),
      enumerable: !1
    },
    ansi256ToAnsi: {
      value(e) {
        if (e < 8)
          return 30 + e;
        if (e < 16)
          return 90 + (e - 8);
        let t, n, o;
        if (e >= 232)
          t = ((e - 232) * 10 + 8) / 255, n = t, o = t;
        else {
          e -= 16;
          let r = e % 36;
          t = Math.floor(e / 36) / 5, n = Math.floor(r / 6) / 5, o = r % 6 / 5;
        }
        let s = Math.max(t, n, o) * 2;
        if (s === 0)
          return 30;
        let a = 30 + (Math.round(o) << 2 | Math.round(n) << 1 | Math.round(t));
        return s === 2 && (a += 60), a;
      },
      enumerable: !1
    },
    rgbToAnsi: {
      value: /* @__PURE__ */ l((e, t, n) => m.ansi256ToAnsi(m.rgbToAnsi256(e, t, n)), "value"),
      enumerable: !1
    },
    hexToAnsi: {
      value: /* @__PURE__ */ l((e) => m.ansi256ToAnsi(m.hexToAnsi256(e)), "value"),
      enumerable: !1
    }
  }), m;
}
l(Ye, "assembleStyles");
var Je = Ye(), _ = Je;

// node_modules/chalk/source/vendor/supports-color/index.js
var D = A(require("node:process"), 1), ue = A(require("node:os"), 1), J = A(require("node:tty"), 1);
function g(i, e = globalThis.Deno ? globalThis.Deno.args : D.default.argv) {
  let t = i.startsWith("-") ? "" : i.length === 1 ? "-" : "--", n = e.indexOf(t + i), o = e.indexOf("--");
  return n !== -1 && (o === -1 || n < o);
}
l(g, "hasFlag");
var { env: d } = D.default, R;
g("no-color") || g("no-colors") || g("color=false") || g("color=never") ? R = 0 : (g("color") || g("colors") || g("color=true") || g("color=\
always")) && (R = 1);
function Ke() {
  if ("FORCE_COLOR" in d)
    return d.FORCE_COLOR === "true" ? 1 : d.FORCE_COLOR === "false" ? 0 : d.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(d.FORCE_COLOR,
    10), 3);
}
l(Ke, "envForceColor");
function ze(i) {
  return i === 0 ? !1 : {
    level: i,
    hasBasic: !0,
    has256: i >= 2,
    has16m: i >= 3
  };
}
l(ze, "translateLevel");
function Qe(i, { streamIsTTY: e, sniffFlags: t = !0 } = {}) {
  let n = Ke();
  n !== void 0 && (R = n);
  let o = t ? R : n;
  if (o === 0)
    return 0;
  if (t) {
    if (g("color=16m") || g("color=full") || g("color=truecolor"))
      return 3;
    if (g("color=256"))
      return 2;
  }
  if ("TF_BUILD" in d && "AGENT_NAME" in d)
    return 1;
  if (i && !e && o === void 0)
    return 0;
  let s = o || 0;
  if (d.TERM === "dumb")
    return s;
  if (D.default.platform === "win32") {
    let a = ue.default.release().split(".");
    return Number(a[0]) >= 10 && Number(a[2]) >= 10586 ? Number(a[2]) >= 14931 ? 3 : 2 : 1;
  }
  if ("CI" in d)
    return "GITHUB_ACTIONS" in d || "GITEA_ACTIONS" in d ? 3 : ["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((a) => a in
    d) || d.CI_NAME === "codeship" ? 1 : s;
  if ("TEAMCITY_VERSION" in d)
    return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(d.TEAMCITY_VERSION) ? 1 : 0;
  if (d.COLORTERM === "truecolor" || d.TERM === "xterm-kitty")
    return 3;
  if ("TERM_PROGRAM" in d) {
    let a = Number.parseInt((d.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
    switch (d.TERM_PROGRAM) {
      case "iTerm.app":
        return a >= 3 ? 3 : 2;
      case "Apple_Terminal":
        return 2;
    }
  }
  return /-256(color)?$/i.test(d.TERM) ? 2 : /^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(d.TERM) || "COLORTERM" in d ?
  1 : s;
}
l(Qe, "_supportsColor");
function pe(i, e = {}) {
  let t = Qe(i, {
    streamIsTTY: i && i.isTTY,
    ...e
  });
  return ze(t);
}
l(pe, "createSupportsColor");
var Xe = {
  stdout: pe({ isTTY: J.default.isatty(1) }),
  stderr: pe({ isTTY: J.default.isatty(2) })
}, me = Xe;

// node_modules/chalk/source/utilities.js
function de(i, e, t) {
  let n = i.indexOf(e);
  if (n === -1)
    return i;
  let o = e.length, s = 0, a = "";
  do
    a += i.slice(s, n) + e + t, s = n + o, n = i.indexOf(e, s);
  while (n !== -1);
  return a += i.slice(s), a;
}
l(de, "stringReplaceAll");
function fe(i, e, t, n) {
  let o = 0, s = "";
  do {
    let a = i[n - 1] === "\r";
    s += i.slice(o, a ? n - 1 : n) + e + (a ? `\r
` : `
`) + t, o = n + 1, n = i.indexOf(`
`, o);
  } while (n !== -1);
  return s += i.slice(o), s;
}
l(fe, "stringEncaseCRLFWithFirstIndex");

// node_modules/chalk/source/index.js
var { stdout: ge, stderr: _e } = me, K = Symbol("GENERATOR"), E = Symbol("STYLER"), N = Symbol("IS_EMPTY"), be = [
  "ansi",
  "ansi",
  "ansi256",
  "ansi16m"
], k = /* @__PURE__ */ Object.create(null), Ze = /* @__PURE__ */ l((i, e = {}) => {
  if (e.level && !(Number.isInteger(e.level) && e.level >= 0 && e.level <= 3))
    throw new Error("The `level` option should be an integer from 0 to 3");
  let t = ge ? ge.level : 0;
  i.level = e.level === void 0 ? t : e.level;
}, "applyOptions");
var et = /* @__PURE__ */ l((i) => {
  let e = /* @__PURE__ */ l((...t) => t.join(" "), "chalk");
  return Ze(e, i), Object.setPrototypeOf(e, T.prototype), e;
}, "chalkFactory");
function T(i) {
  return et(i);
}
l(T, "createChalk");
Object.setPrototypeOf(T.prototype, Function.prototype);
for (let [i, e] of Object.entries(_))
  k[i] = {
    get() {
      let t = M(this, Q(e.open, e.close, this[E]), this[N]);
      return Object.defineProperty(this, i, { value: t }), t;
    }
  };
k.visible = {
  get() {
    let i = M(this, this[E], !0);
    return Object.defineProperty(this, "visible", { value: i }), i;
  }
};
var z = /* @__PURE__ */ l((i, e, t, ...n) => i === "rgb" ? e === "ansi16m" ? _[t].ansi16m(...n) : e === "ansi256" ? _[t].ansi256(_.rgbToAnsi256(
...n)) : _[t].ansi(_.rgbToAnsi(...n)) : i === "hex" ? z("rgb", e, t, ..._.hexToRgb(...n)) : _[t][i](...n), "getModelAnsi"), tt = ["rgb", "he\
x", "ansi256"];
for (let i of tt) {
  k[i] = {
    get() {
      let { level: t } = this;
      return function(...n) {
        let o = Q(z(i, be[t], "color", ...n), _.color.close, this[E]);
        return M(this, o, this[N]);
      };
    }
  };
  let e = "bg" + i[0].toUpperCase() + i.slice(1);
  k[e] = {
    get() {
      let { level: t } = this;
      return function(...n) {
        let o = Q(z(i, be[t], "bgColor", ...n), _.bgColor.close, this[E]);
        return M(this, o, this[N]);
      };
    }
  };
}
var nt = Object.defineProperties(() => {
}, {
  ...k,
  level: {
    enumerable: !0,
    get() {
      return this[K].level;
    },
    set(i) {
      this[K].level = i;
    }
  }
}), Q = /* @__PURE__ */ l((i, e, t) => {
  let n, o;
  return t === void 0 ? (n = i, o = e) : (n = t.openAll + i, o = e + t.closeAll), {
    open: i,
    close: e,
    openAll: n,
    closeAll: o,
    parent: t
  };
}, "createStyler"), M = /* @__PURE__ */ l((i, e, t) => {
  let n = /* @__PURE__ */ l((...o) => it(n, o.length === 1 ? "" + o[0] : o.join(" ")), "builder");
  return Object.setPrototypeOf(n, nt), n[K] = i, n[E] = e, n[N] = t, n;
}, "createBuilder"), it = /* @__PURE__ */ l((i, e) => {
  if (i.level <= 0 || !e)
    return i[N] ? "" : e;
  let t = i[E];
  if (t === void 0)
    return e;
  let { openAll: n, closeAll: o } = t;
  if (e.includes("\x1B"))
    for (; t !== void 0; )
      e = de(e, t.close, t.open), t = t.parent;
  let s = e.indexOf(`
`);
  return s !== -1 && (e = fe(e, o, n, s)), n + e + o;
}, "applyStyle");
Object.defineProperties(T.prototype, k);
var ot = T(), Et = T({ level: _e ? _e.level : 0 });
var B = ot;

// src/cli/bin/index.ts
var v = A(Ee(), 1);

// ../node_modules/fd-package-json/dist/esm/main.js
var te = A(Se(), 1), ne = require("node:path"), $ = require("node:fs/promises"), j = require("node:fs");
async function lt(i) {
  try {
    return (await (0, $.stat)(i)).isFile();
  } catch {
    return !1;
  }
}
l(lt, "fileExists");
function ct(i) {
  try {
    return (0, j.statSync)(i).isFile();
  } catch {
    return !1;
  }
}
l(ct, "fileExistsSync");
async function ht(i) {
  for (let e of (0, te.walkUp)(i)) {
    let t = (0, ne.resolve)(e, "package.json");
    if (await lt(t))
      return t;
  }
  return null;
}
l(ht, "findPackagePath");
async function V(i) {
  let e = await ht(i);
  if (!e)
    return null;
  try {
    let t = await (0, $.readFile)(e, { encoding: "utf8" });
    return JSON.parse(t);
  } catch {
    return null;
  }
}
l(V, "findPackage");
function pt(i) {
  for (let e of (0, te.walkUp)(i)) {
    let t = (0, ne.resolve)(e, "package.json");
    if (ct(t))
      return t;
  }
  return null;
}
l(pt, "findPackagePathSync");
function Fe(i) {
  let e = pt(i);
  if (!e)
    return null;
  try {
    let t = (0, j.readFileSync)(e, { encoding: "utf8" });
    return JSON.parse(t);
  } catch {
    return null;
  }
}
l(Fe, "findPackageSync");

// node_modules/leven/index.js
var ie = [], Ne = [];
function oe(i, e) {
  if (i === e)
    return 0;
  let t = i;
  i.length > e.length && (i = e, e = t);
  let n = i.length, o = e.length;
  for (; n > 0 && i.charCodeAt(~-n) === e.charCodeAt(~-o); )
    n--, o--;
  let s = 0;
  for (; s < n && i.charCodeAt(s) === e.charCodeAt(s); )
    s++;
  if (n -= s, o -= s, n === 0)
    return o;
  let a, r, c, h, p = 0, f = 0;
  for (; p < n; )
    Ne[p] = i.charCodeAt(s + p), ie[p] = ++p;
  for (; f < o; )
    for (a = e.charCodeAt(s + f), c = f++, r = f, p = 0; p < n; p++)
      h = a === Ne[p] ? c : c + 1, c = ie[p], r = ie[p] = c > r ? h > r ? r + 1 : h : h > c ? c + 1 : h;
  return r;
}
l(oe, "leven");

// ../node_modules/tiny-invariant/dist/esm/tiny-invariant.js
var ut = process.env.NODE_ENV === "production", se = "Invariant failed";
function F(i, e) {
  if (!i) {
    if (ut)
      throw new Error(se);
    var t = typeof e == "function" ? e() : e, n = t ? "".concat(se, ": ").concat(t) : se;
    throw new Error(n);
  }
}
l(F, "invariant");

// src/cli/build.ts
var Te = require("@storybook/core/common"), G = require("@storybook/core/core-server");
var Pe = /* @__PURE__ */ l(async (i) => {
  let e = await V(__dirname);
  F(e, "Failed to find the closest package.json file.");
  let t = {
    ...i,
    configDir: i.configDir || "./.storybook",
    outputDir: i.outputDir || "./storybook-static",
    ignorePreview: !!i.previewUrl && !i.forceBuildPreview,
    configType: "PRODUCTION",
    cache: Te.cache,
    packageJson: e
  };
  await (0, G.withTelemetry)(
    "build",
    { cliOptions: i, presetOptions: t },
    () => (0, G.buildStaticStandalone)(t)
  );
}, "build");

// src/cli/dev.ts
var De = require("@storybook/core/common"), U = require("@storybook/core/core-server"), b = require("@storybook/core/node-logger");
var re = A(Re(), 1);
function mt(i) {
  b.instance.heading = "", i instanceof Error ? i.error ? b.logger.error(i.error) : i.stats && i.stats.compilation.errors ? i.stats.compilation.
  errors.forEach((e) => b.logger.plain(e)) : b.logger.error(i) : i.compilation?.errors && i.compilation.errors.forEach((e) => b.logger.plain(
  e)), b.logger.line(), b.logger.warn(
    i.close ? re.dedent`
          FATAL broken build!, will close the process,
          Fix the error below and restart storybook.
        ` : re.dedent`
          Broken build, fix the error above.
          You may need to refresh the browser.
        `
  ), b.logger.line();
}
l(mt, "printError");
var Me = /* @__PURE__ */ l(async (i) => {
  process.env.NODE_ENV = process.env.NODE_ENV || "development";
  let e = await V(__dirname);
  F(e, "Failed to find the closest package.json file.");
  let t = {
    ...i,
    configDir: i.configDir || "./.storybook",
    configType: "DEVELOPMENT",
    ignorePreview: !!i.previewUrl && !i.forceBuildPreview,
    cache: De.cache,
    packageJson: e
  };
  await (0, U.withTelemetry)(
    "dev",
    {
      cliOptions: i,
      presetOptions: t,
      printError: mt
    },
    () => (0, U.buildDevStandalone)(t)
  );
}, "dev");

// src/cli/bin/index.ts
(0, Be.addToGlobalContext)("cliVersion", w.versions.storybook);
var y = Fe(__dirname);
F(y, "Failed to find the closest package.json file.");
var W = console, Le = /* @__PURE__ */ l((i) => v.default.command(i).option(
  "--disable-telemetry",
  "Disable sending telemetry data",
  // default value is false, but if the user sets STORYBOOK_DISABLE_TELEMETRY, it can be true
  process.env.STORYBOOK_DISABLE_TELEMETRY && process.env.STORYBOOK_DISABLE_TELEMETRY !== "false"
).option("--debug", "Get more logs in debug mode", !1).option("--enable-crash-reports", "Enable sending crash reports to telemetry data"), "\
command");
Le("dev").option("-p, --port <number>", "Port to run Storybook", (i) => parseInt(i, 10)).option("-h, --host <string>", "Host to run Storyboo\
k").option("-c, --config-dir <dir-name>", "Directory where to load Storybook configurations from").option(
  "--https",
  "Serve Storybook over HTTPS. Note: You must provide your own certificate information."
).option(
  "--ssl-ca <ca>",
  "Provide an SSL certificate authority. (Optional with --https, required if using a self-signed certificate)",
  w.parseList
).option("--ssl-cert <cert>", "Provide an SSL certificate. (Required with --https)").option("--ssl-key <key>", "Provide an SSL key. (Require\
d with --https)").option("--smoke-test", "Exit after successful start").option("--ci", "CI mode (skip interactive prompts, don't open browse\
r)").option("--no-open", "Do not open Storybook automatically in the browser").option("--loglevel <level>", "Control level of logging during\
 build").option("--quiet", "Suppress verbose build output").option("--no-version-updates", "Suppress update check", !0).option("--debug-webp\
ack", "Display final webpack configurations for debugging purposes").option(
  "--webpack-stats-json [directory]",
  "Write Webpack stats JSON to disk (synonym for `--stats-json`)"
).option("--stats-json [directory]", "Write stats JSON to disk").option(
  "--preview-url <string>",
  "Disables the default storybook preview and lets your use your own"
).option("--force-build-preview", "Build the preview iframe even if you are using --preview-url").option("--docs", "Build a documentation-on\
ly site using addon-docs").option("--exact-port", "Exit early if the desired port is not available").option(
  "--initial-path [path]",
  "URL path to be appended when visiting Storybook for the first time"
).action(async (i) => {
  ae.logger.setLevel(v.default.loglevel), W.log(B.bold(`${y.name} v${y.version}`) + B.reset(`
`)), (0, w.getEnvConfig)(i, {
    port: "SBCONFIG_PORT",
    host: "SBCONFIG_HOSTNAME",
    staticDir: "SBCONFIG_STATIC_DIR",
    configDir: "SBCONFIG_CONFIG_DIR",
    ci: "CI"
  }), parseInt(`${i.port}`, 10) && (i.port = parseInt(`${i.port}`, 10)), await Me({ ...i, packageJson: y }).catch(() => process.exit(1));
});
Le("build").option("-o, --output-dir <dir-name>", "Directory where to store built files").option("-c, --config-dir <dir-name>", "Directory w\
here to load Storybook configurations from").option("--quiet", "Suppress verbose build output").option("--loglevel <level>", "Control level \
of logging during build").option("--debug-webpack", "Display final webpack configurations for debugging purposes").option(
  "--webpack-stats-json [directory]",
  "Write Webpack stats JSON to disk (synonym for `--stats-json`)"
).option("--stats-json [directory]", "Write stats JSON to disk").option(
  "--preview-url <string>",
  "Disables the default storybook preview and lets your use your own"
).option("--force-build-preview", "Build the preview iframe even if you are using --preview-url").option("--docs", "Build a documentation-on\
ly site using addon-docs").option("--test", "Build stories optimized for testing purposes.").action(async (i) => {
  process.env.NODE_ENV = process.env.NODE_ENV || "production", ae.logger.setLevel(v.default.loglevel), W.log(B.bold(`${y.name} v${y.version}\

`)), (0, w.getEnvConfig)(i, {
    staticDir: "SBCONFIG_STATIC_DIR",
    outputDir: "SBCONFIG_OUTPUT_DIR",
    configDir: "SBCONFIG_CONFIG_DIR"
  }), await Pe({
    ...i,
    packageJson: y,
    test: !!i.test || process.env.SB_TESTBUILD === "true"
  }).catch(() => process.exit(1));
});
v.default.on("command:*", ([i]) => {
  W.error(
    ` Invalid command: %s.
 See --help for a list of available commands.`,
    i
  );
  let t = v.default.commands.map((n) => n._name).find((n) => oe(n, i) < 3);
  t && W.info(`
 Did you mean ${t}?`), process.exit(1);
});
v.default.usage("<command> [options]").version(String(y.version)).parse(process.argv);
