import { __require as R } from "../../../../nanoid@3.3.8/node_modules/nanoid/non-secure/index.js";
import c from "../../../../../../_virtual/___vite-browser-external.js";
import { __require as _ } from "./css-syntax-error.js";
import { __require as x } from "./previous-map.js";
var C, F;
function U() {
  if (F) return C;
  F = 1;
  let { nanoid: q } = /* @__PURE__ */ R(), { isAbsolute: p, resolve: d } = c, { SourceMapConsumer: y, SourceMapGenerator: O } = c, { fileURLToPath: b, pathToFileURL: a } = c, v = _(), L = x(), g = c, S = Symbol("fromOffsetCache"), M = !!(y && O), w = !!(d && p);
  class m {
    get from() {
      return this.file || this.id;
    }
    constructor(t, e = {}) {
      if (t === null || typeof t > "u" || typeof t == "object" && !t.toString)
        throw new Error(`PostCSS received ${t} instead of CSS string`);
      if (this.css = t.toString(), this.css[0] === "\uFEFF" || this.css[0] === "" ? (this.hasBOM = !0, this.css = this.css.slice(1)) : this.hasBOM = !1, this.document = this.css, e.document && (this.document = e.document.toString()), e.from && (!w || /^\w+:\/\//.test(e.from) || p(e.from) ? this.file = e.from : this.file = d(e.from)), w && M) {
        let i = new L(this.css, e);
        if (i.text) {
          this.map = i;
          let n = i.consumer().file;
          !this.file && n && (this.file = this.mapResolve(n));
        }
      }
      this.file || (this.id = "<input css " + q(6) + ">"), this.map && (this.map.file = this.from);
    }
    error(t, e, i, n = {}) {
      let o, r, l;
      if (e && typeof e == "object") {
        let f = e, u = i;
        if (typeof f.offset == "number") {
          let h = this.fromOffset(f.offset);
          e = h.line, i = h.col;
        } else
          e = f.line, i = f.column;
        if (typeof u.offset == "number") {
          let h = this.fromOffset(u.offset);
          r = h.line, o = h.col;
        } else
          r = u.line, o = u.column;
      } else if (!i) {
        let f = this.fromOffset(e);
        e = f.line, i = f.col;
      }
      let s = this.origin(e, i, r, o);
      return s ? l = new v(
        t,
        s.endLine === void 0 ? s.line : { column: s.column, line: s.line },
        s.endLine === void 0 ? s.column : { column: s.endColumn, line: s.endLine },
        s.source,
        s.file,
        n.plugin
      ) : l = new v(
        t,
        r === void 0 ? e : { column: i, line: e },
        r === void 0 ? i : { column: o, line: r },
        this.css,
        this.file,
        n.plugin
      ), l.input = { column: i, endColumn: o, endLine: r, line: e, source: this.css }, this.file && (a && (l.input.url = a(this.file).toString()), l.input.file = this.file), l;
    }
    fromOffset(t) {
      let e, i;
      if (this[S])
        i = this[S];
      else {
        let o = this.css.split(`
`);
        i = new Array(o.length);
        let r = 0;
        for (let l = 0, s = o.length; l < s; l++)
          i[l] = r, r += o[l].length + 1;
        this[S] = i;
      }
      e = i[i.length - 1];
      let n = 0;
      if (t >= e)
        n = i.length - 1;
      else {
        let o = i.length - 2, r;
        for (; n < o; )
          if (r = n + (o - n >> 1), t < i[r])
            o = r - 1;
          else if (t >= i[r + 1])
            n = r + 1;
          else {
            n = r;
            break;
          }
      }
      return {
        col: t - i[n] + 1,
        line: n + 1
      };
    }
    mapResolve(t) {
      return /^\w+:\/\//.test(t) ? t : d(this.map.consumer().sourceRoot || this.map.root || ".", t);
    }
    origin(t, e, i, n) {
      if (!this.map) return !1;
      let o = this.map.consumer(), r = o.originalPositionFor({ column: e, line: t });
      if (!r.source) return !1;
      let l;
      typeof i == "number" && (l = o.originalPositionFor({ column: n, line: i }));
      let s;
      p(r.source) ? s = a(r.source) : s = new URL(
        r.source,
        this.map.consumer().sourceRoot || a(this.map.mapFile)
      );
      let f = {
        column: r.column,
        endColumn: l && l.column,
        endLine: l && l.line,
        line: r.line,
        url: s.toString()
      };
      if (s.protocol === "file:")
        if (b)
          f.file = b(s);
        else
          throw new Error("file: protocol is not available in this PostCSS build");
      let u = o.sourceContentFor(r.source);
      return u && (f.source = u), f;
    }
    toJSON() {
      let t = {};
      for (let e of ["hasBOM", "css", "file", "id"])
        this[e] != null && (t[e] = this[e]);
      return this.map && (t.map = { ...this.map }, t.map.consumerCache && (t.map.consumerCache = void 0)), t;
    }
  }
  return C = m, m.default = m, g && g.registerInput && g.registerInput(m), C;
}
export {
  U as __require
};
//# sourceMappingURL=input.js.map
