import "../../../../ansi-styles@4.3.0/node_modules/ansi-styles/index.js";
import j from "../../../../supports-color@7.2.0/node_modules/supports-color/browser.js";
import _ from "./util.js";
import { __require as C } from "./templates.js";
import { a as g } from "../../../../../../_virtual/index20.js";
const c = g.exports, { stdout: f, stderr: h } = j, {
  stringReplaceAll: k,
  stringEncaseCRLFWithFirstIndex: A
} = _, { isArray: i } = Array, v = [
  "ansi",
  "ansi",
  "ansi256",
  "ansi16m"
], n = /* @__PURE__ */ Object.create(null), E = (t, 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");
  const r = f ? f.level : 0;
  t.level = e.level === void 0 ? r : e.level;
};
class x {
  constructor(e) {
    return b(e);
  }
}
const b = (t) => {
  const e = {};
  return E(e, t), e.template = (...r) => w(e.template, ...r), Object.setPrototypeOf(e, a.prototype), Object.setPrototypeOf(e.template, e), e.template.constructor = () => {
    throw new Error("`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.");
  }, e.template.Instance = x, e.template;
};
function a(t) {
  return b(t);
}
for (const [t, e] of Object.entries(c))
  n[t] = {
    get() {
      const r = u(this, y(e.open, e.close, this._styler), this._isEmpty);
      return Object.defineProperty(this, t, { value: r }), r;
    }
  };
n.visible = {
  get() {
    const t = u(this, this._styler, !0);
    return Object.defineProperty(this, "visible", { value: t }), t;
  }
};
const O = ["rgb", "hex", "keyword", "hsl", "hsv", "hwb", "ansi", "ansi256"];
for (const t of O)
  n[t] = {
    get() {
      const { level: e } = this;
      return function(...r) {
        const l = y(c.color[v[e]][t](...r), c.color.close, this._styler);
        return u(this, l, this._isEmpty);
      };
    }
  };
for (const t of O) {
  const e = "bg" + t[0].toUpperCase() + t.slice(1);
  n[e] = {
    get() {
      const { level: r } = this;
      return function(...l) {
        const o = y(c.bgColor[v[r]][t](...l), c.bgColor.close, this._styler);
        return u(this, o, this._isEmpty);
      };
    }
  };
}
const P = Object.defineProperties(() => {
}, {
  ...n,
  level: {
    enumerable: !0,
    get() {
      return this._generator.level;
    },
    set(t) {
      this._generator.level = t;
    }
  }
}), y = (t, e, r) => {
  let l, o;
  return r === void 0 ? (l = t, o = e) : (l = r.openAll + t, o = e + r.closeAll), {
    open: t,
    close: e,
    openAll: l,
    closeAll: o,
    parent: r
  };
}, u = (t, e, r) => {
  const l = (...o) => i(o[0]) && i(o[0].raw) ? m(l, w(l, ...o)) : m(l, o.length === 1 ? "" + o[0] : o.join(" "));
  return Object.setPrototypeOf(l, P), l._generator = t, l._styler = e, l._isEmpty = r, l;
}, m = (t, e) => {
  if (t.level <= 0 || !e)
    return t._isEmpty ? "" : e;
  let r = t._styler;
  if (r === void 0)
    return e;
  const { openAll: l, closeAll: o } = r;
  if (e.indexOf("\x1B") !== -1)
    for (; r !== void 0; )
      e = k(e, r.close, r.open), r = r.parent;
  const s = e.indexOf(`
`);
  return s !== -1 && (e = A(e, o, l, s)), l + e + o;
};
let d;
const w = (t, ...e) => {
  const [r] = e;
  if (!i(r) || !i(r.raw))
    return e.join(" ");
  const l = e.slice(1), o = [r.raw[0]];
  for (let s = 1; s < r.length; s++)
    o.push(
      String(l[s - 1]).replace(/[{}\\]/g, "\\$&"),
      String(r.raw[s])
    );
  return d === void 0 && (d = C()), d(t, o.join(""));
};
Object.defineProperties(a.prototype, n);
const p = a();
p.supportsColor = f;
p.stderr = a({ level: h ? h.level : 0 });
p.stderr.supportsColor = h;
var q = p;
export {
  q as default
};
//# sourceMappingURL=index.js.map
