const { DateNow: _p_DateNow } = require('../../primordials/date.js')
const { TypeErrorCtor: _p_TypeErrorCtor } = require('../../primordials/error.js')

const { MathMax: _p_MathMax } = require('../../primordials/math.js')

"use strict";
/**
 * Bundled from @socketregistry/yocto-spinner
 * This is a zero-dependency bundle created by esbuild.
 */
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __commonJS = (cb, mod) => function __require() {
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};

// node_modules/.pnpm/yoctocolors-cjs@2.1.3/node_modules/yoctocolors-cjs/index.js
var require_yoctocolors_cjs = __commonJS({
  "node_modules/.pnpm/yoctocolors-cjs@2.1.3/node_modules/yoctocolors-cjs/index.js"(exports2, module2) {
    var tty = require("node:tty");
    var hasColors = tty?.WriteStream?.prototype?.hasColors?.() ?? false;
    var format = /* @__PURE__ */ __name((open, close) => {
      if (!hasColors) {
        return (input) => input;
      }
      const openCode = `\x1B[${open}m`;
      const closeCode = `\x1B[${close}m`;
      return (input) => {
        const string = input + "";
        let index = string.indexOf(closeCode);
        if (index === -1) {
          return openCode + string + closeCode;
        }
        let result = openCode;
        let lastIndex = 0;
        const reopenOnNestedClose = close === 22;
        const replaceCode = (reopenOnNestedClose ? closeCode : "") + openCode;
        while (index !== -1) {
          result += string.slice(lastIndex, index) + replaceCode;
          lastIndex = index + closeCode.length;
          index = string.indexOf(closeCode, lastIndex);
        }
        result += string.slice(lastIndex) + closeCode;
        return result;
      };
    }, "format");
    var colors = {};
    colors.reset = format(0, 0);
    colors.bold = format(1, 22);
    colors.dim = format(2, 22);
    colors.italic = format(3, 23);
    colors.underline = format(4, 24);
    colors.overline = format(53, 55);
    colors.inverse = format(7, 27);
    colors.hidden = format(8, 28);
    colors.strikethrough = format(9, 29);
    colors.black = format(30, 39);
    colors.red = format(31, 39);
    colors.green = format(32, 39);
    colors.yellow = format(33, 39);
    colors.blue = format(34, 39);
    colors.magenta = format(35, 39);
    colors.cyan = format(36, 39);
    colors.white = format(37, 39);
    colors.gray = format(90, 39);
    colors.bgBlack = format(40, 49);
    colors.bgRed = format(41, 49);
    colors.bgGreen = format(42, 49);
    colors.bgYellow = format(43, 49);
    colors.bgBlue = format(44, 49);
    colors.bgMagenta = format(45, 49);
    colors.bgCyan = format(46, 49);
    colors.bgWhite = format(47, 49);
    colors.bgGray = format(100, 49);
    colors.redBright = format(91, 39);
    colors.greenBright = format(92, 39);
    colors.yellowBright = format(93, 39);
    colors.blueBright = format(94, 39);
    colors.magentaBright = format(95, 39);
    colors.cyanBright = format(96, 39);
    colors.whiteBright = format(97, 39);
    colors.bgRedBright = format(101, 49);
    colors.bgGreenBright = format(102, 49);
    colors.bgYellowBright = format(103, 49);
    colors.bgBlueBright = format(104, 49);
    colors.bgMagentaBright = format(105, 49);
    colors.bgCyanBright = format(106, 49);
    colors.bgWhiteBright = format(107, 49);
    module2.exports = colors;
  }
});

// node_modules/.pnpm/@socketregistry+yocto-spinner@1.0.25/node_modules/@socketregistry/yocto-spinner/index.cjs
var require_yocto_spinner = __commonJS({
  "node_modules/.pnpm/@socketregistry+yocto-spinner@1.0.25/node_modules/@socketregistry/yocto-spinner/index.cjs"(exports2, module2) {
    "use strict";
    var { isArray: ArrayIsArray } = Array;
    var { defineProperty: ObjectDefineProperty } = Object;
    var defaultTtyColumns = 80;
    var _defaultSpinner;
    function getDefaultSpinner() {
      if (_defaultSpinner === void 0) {
        _defaultSpinner = {
          frames: isUnicodeSupported() ? ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"] : ["-", "\\", "|", "/"],
          interval: 80
        };
      }
      return _defaultSpinner;
    }
    __name(getDefaultSpinner, "getDefaultSpinner");
    var _logSymbols;
    function getLogSymbols() {
      if (_logSymbols === void 0) {
        const supported = isUnicodeSupported();
        const colors = getYoctocolors();
        _logSymbols = {
          error: colors.red(supported ? "✖" : "×"),
          info: colors.blue(supported ? "ℹ" : "i"),
          success: colors.green(supported ? "✔" : "√"),
          warning: colors.yellow(supported ? "⚠" : "‼")
        };
      }
      return _logSymbols;
    }
    __name(getLogSymbols, "getLogSymbols");
    var _process;
    function getProcess() {
      if (_process === void 0) {
        _process = require("node:process");
      }
      return _process;
    }
    __name(getProcess, "getProcess");
    var _yoctocolors;
    function getYoctocolors() {
      if (_yoctocolors === void 0) {
        _yoctocolors = { ...require_yoctocolors_cjs() };
      }
      return _yoctocolors;
    }
    __name(getYoctocolors, "getYoctocolors");
    var _processInteractive;
    function isProcessInteractive() {
      if (_processInteractive === void 0) {
        const { env } = getProcess();
        _processInteractive = env.TERM !== "dumb" && !("CI" in env);
      }
      return _processInteractive;
    }
    __name(isProcessInteractive, "isProcessInteractive");
    var _unicodeSupported;
    function isUnicodeSupported() {
      if (_unicodeSupported === void 0) {
        const process2 = getProcess();
        if (process2.platform !== "win32") {
          _unicodeSupported = process2.env.TERM !== "linux";
          return _unicodeSupported;
        }
        const { env } = process2;
        if (
          // Windows Terminal.
          env.WT_SESSION || // Terminus (<0.2.27).
          env.TERMINUS_SUBLIME || // ConEmu and cmder.
          env.ConEmuTask === "{cmd::Cmder}"
        ) {
          _unicodeSupported = true;
          return _unicodeSupported;
        }
        const { TERM, TERM_PROGRAM } = env;
        _unicodeSupported = TERM_PROGRAM === "Terminus-Sublime" || TERM_PROGRAM === "vscode" || TERM === "xterm-256color" || TERM === "alacritty" || TERM === "rxvt-unicode" || TERM === "rxvt-unicode-256color" || env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
      }
      return _unicodeSupported;
    }
    __name(isUnicodeSupported, "isUnicodeSupported");
    var _stripVTControlCharacters;
    function stripVTControlCharacters(string) {
      if (_stripVTControlCharacters === void 0) {
        const nodeUtil = require("node:util");
        _stripVTControlCharacters = nodeUtil.stripVTControlCharacters;
      }
      return _stripVTControlCharacters(string);
    }
    __name(stripVTControlCharacters, "stripVTControlCharacters");
    function getFrame(spinner, index) {
      const { frames } = spinner;
      const length = frames?.length ?? 0;
      return index > -1 && index < length ? frames[index] : "";
    }
    __name(getFrame, "getFrame");
    function getFrameCount(spinner) {
      const { frames } = spinner;
      const length = frames?.length ?? 0;
      return length < 1 ? 1 : length;
    }
    __name(getFrameCount, "getFrameCount");
    function normalizeText(value) {
      return typeof value === "string" ? value.trimStart() : "";
    }
    __name(normalizeText, "normalizeText");
    var YoctoSpinner2 = class _YoctoSpinner {
      static {
        __name(this, "YoctoSpinner");
      }
      #color;
      #currentFrame = -1;
      #exitHandlerBound;
      #indention = "";
      #isInteractive;
      #isSpinning = false;
      #lastSpinnerFrameTime = 0;
      #lines = 0;
      #onFrameUpdate;
      #onRenderFrame;
      #skipRender = false;
      #spinner;
      #stream;
      #text;
      #timer;
      static spinners = {
        get default() {
          return getDefaultSpinner();
        },
        set default(spinner) {
          ObjectDefineProperty(this, "default", {
            __proto__: null,
            configurable: true,
            enumerable: true,
            value: spinner,
            writable: true
          });
        },
        ci: {
          frames: [""],
          // The delay argument is converted to a signed 32-bit integer. This effectively
          // limits delay to 2147483647 ms, roughly 24.8 days, since it's specified as a
          // signed integer in the IDL.
          // https://developer.mozilla.org/en-US/docs/Web/API/Window/setInterval?utm_source=chatgpt.com#return_value
          interval: 2147483647
        }
      };
      constructor(options = {}) {
        const opts = { __proto__: null, ...options };
        const stream = opts.stream ?? getProcess().stderr;
        this.#spinner = opts.spinner ?? _YoctoSpinner.spinners.default ?? getDefaultSpinner();
        this.#text = normalizeText(options.text);
        this.#stream = stream ?? process.stderr;
        const color = options.color ?? "cyan";
        if (ArrayIsArray(color) && (color.length !== 3 || !color.every((n) => typeof n === "number" && n >= 0 && n <= 255))) {
          throw new _p_TypeErrorCtor(
            "RGB color must be an array of 3 numbers between 0 and 255"
          );
        }
        this.#color = color;
        this.#isInteractive = !!stream.isTTY && isProcessInteractive();
        this.#exitHandlerBound = this.#exitHandler.bind(this);
        this.#onFrameUpdate = options.onFrameUpdate;
        this.#onRenderFrame = options.onRenderFrame;
      }
      #exitHandler(signal) {
        if (this.isSpinning) {
          this.stop();
        }
        const exitCode = signal === "SIGINT" ? 130 : signal === "SIGTERM" ? 143 : 1;
        process.exit(exitCode);
      }
      #hideCursor() {
        if (this.#isInteractive) {
          this.#write("\x1B[?25l");
        }
      }
      #lineCount(text) {
        const width = this.#stream.columns ?? defaultTtyColumns;
        const lines = stripVTControlCharacters(text).split("\n");
        let lineCount = 0;
        for (const line of lines) {
          lineCount += _p_MathMax(1, Math.ceil(line.length / width));
        }
        return lineCount;
      }
      #render() {
        if (!this.#isSpinning) {
          return;
        }
        const now = _p_DateNow();
        let frameAdvanced = false;
        if (this.#currentFrame === -1 || now - this.#lastSpinnerFrameTime >= this.#spinner.interval) {
          frameAdvanced = true;
          this.#currentFrame = ++this.#currentFrame % getFrameCount(this.#spinner);
          this.#lastSpinnerFrameTime = now;
        }
        if (frameAdvanced && typeof this.#onFrameUpdate === "function") {
          this.#skipRender = true;
          try {
            this.#onFrameUpdate();
          } finally {
            this.#skipRender = false;
          }
        }
        const colors = getYoctocolors();
        const applyColor = ArrayIsArray(this.#color) ? (text) => `\x1B[38;2;${this.#color[0]};${this.#color[1]};${this.#color[2]}m${text}\x1B[39m` : colors[this.#color] ?? colors.cyan;
        const frame = getFrame(this.#spinner, this.#currentFrame);
        let string;
        if (typeof this.#onRenderFrame === "function") {
          string = this.#onRenderFrame(frame, this.#text, applyColor);
        } else {
          string = `${frame ? `${applyColor(frame)} ` : ""}${this.#text}`;
        }
        if (string) {
          if (this.#indention.length) {
            string = `${this.#indention}${string}`;
          }
          if (!this.#isInteractive) {
            string += "\n";
          }
        }
        if (this.#isInteractive) {
          this.clear();
        }
        if (string) {
          this.#write(string);
        }
        if (this.#isInteractive) {
          this.#lines = this.#lineCount(string);
        }
      }
      #showCursor() {
        if (this.#isInteractive) {
          this.#write("\x1B[?25h");
        }
      }
      #subscribeToProcessEvents() {
        process.once("SIGINT", this.#exitHandlerBound);
        process.once("SIGTERM", this.#exitHandlerBound);
      }
      #symbolStop(symbolType, text) {
        const symbols = getLogSymbols();
        return this.stop(`${symbols[symbolType]}  ${text ?? this.#text}`);
      }
      #write(text) {
        this.#stream.write(text);
      }
      #unsubscribeFromProcessEvents() {
        process.off("SIGINT", this.#exitHandlerBound);
        process.off("SIGTERM", this.#exitHandlerBound);
      }
      get color() {
        return this.#color;
      }
      set color(value) {
        this.#color = value;
        this.#render();
      }
      get isSpinning() {
        return this.#isSpinning;
      }
      get spinner() {
        return this.#spinner;
      }
      set spinner(spinner) {
        this.#spinner = spinner;
      }
      get text() {
        if (this._textMethod) {
          return this._textMethod;
        }
        return this.#text;
      }
      set text(value) {
        if (this._textMethod && !this._inTextSetter) {
          this._inTextSetter = true;
          try {
            this._textMethod(value);
          } finally {
            this._inTextSetter = false;
          }
          return;
        }
        this.#text = normalizeText(value);
        if (!this.#skipRender) {
          this.#render();
        }
      }
      clear() {
        if (!this.#isInteractive) {
          return this;
        }
        this.#stream.cursorTo(0);
        for (let index = 0; index < this.#lines; index += 1) {
          if (index > 0) {
            this.#stream.moveCursor(0, -1);
          }
          this.#stream.clearLine(1);
        }
        this.#lines = 0;
        return this;
      }
      dedent(spaces = 2) {
        this.#indention = this.#indention.slice(0, -spaces);
        return this;
      }
      error(text) {
        return this.#symbolStop("error", text);
      }
      indent(spaces = 2) {
        this.#indention += " ".repeat(spaces);
        return this;
      }
      info(text) {
        return this.#symbolStop("info", text);
      }
      resetIndent() {
        this.#indention = "";
        return this;
      }
      start(text) {
        const normalized = normalizeText(text);
        if (normalized) {
          this.#text = normalized;
        }
        if (this.isSpinning) {
          return this;
        }
        this.#isSpinning = true;
        this.#hideCursor();
        this.#render();
        this.#subscribeToProcessEvents();
        if (this.#isInteractive) {
          this.#timer = setInterval(() => {
            this.#render();
          }, this.#spinner.interval);
        }
        return this;
      }
      stop(finalText) {
        if (!this.isSpinning) {
          return this;
        }
        if (this.#timer) {
          clearInterval(this.#timer);
          this.#timer = void 0;
        }
        this.#isSpinning = false;
        this.#showCursor();
        this.clear();
        this.#unsubscribeFromProcessEvents();
        if (finalText) {
          this.#write(`${this.#indention}${finalText}
`);
        }
        return this;
      }
      success(text) {
        return this.#symbolStop("success", text);
      }
      warning(text) {
        return this.#symbolStop("warning", text);
      }
    };
    module2.exports = /* @__PURE__ */ __name(function yoctoSpinner(options) {
      return new YoctoSpinner2(options);
    }, "yoctoSpinner");
  }
});

// src/external/@socketregistry/yocto-spinner.js
var YoctoSpinner = require_yocto_spinner();
module.exports = YoctoSpinner;
module.exports.default = YoctoSpinner;
