import { __require as g } from "./css-syntax-error.js";
import { __require as O } from "./stringifier.js";
import { __require as S } from "./stringify.js";
import { __require as I } from "./symbols.js";
var d, m;
function b() {
  if (m) return d;
  m = 1;
  let p = g(), y = O(), x = S(), { isClean: a, my: w } = I();
  function c(o, e) {
    let t = new o.constructor();
    for (let i in o) {
      if (!Object.prototype.hasOwnProperty.call(o, i) || i === "proxyCache") continue;
      let n = o[i], r = typeof n;
      i === "parent" && r === "object" ? e && (t[i] = e) : i === "source" ? t[i] = n : Array.isArray(n) ? t[i] = n.map((s) => c(s, t)) : (r === "object" && n !== null && (n = c(n)), t[i] = n);
    }
    return t;
  }
  function f(o, e) {
    if (e && typeof e.offset < "u")
      return e.offset;
    let t = 1, i = 1, n = 0;
    for (let r = 0; r < o.length; r++) {
      if (i === e.line && t === e.column) {
        n = r;
        break;
      }
      o[r] === `
` ? (t = 1, i += 1) : t += 1;
    }
    return n;
  }
  class h {
    get proxyOf() {
      return this;
    }
    constructor(e = {}) {
      this.raws = {}, this[a] = !1, this[w] = !0;
      for (let t in e)
        if (t === "nodes") {
          this.nodes = [];
          for (let i of e[t])
            typeof i.clone == "function" ? this.append(i.clone()) : this.append(i);
        } else
          this[t] = e[t];
    }
    addToError(e) {
      if (e.postcssNode = this, e.stack && this.source && /\n\s{4}at /.test(e.stack)) {
        let t = this.source;
        e.stack = e.stack.replace(
          /\n\s{4}at /,
          `$&${t.input.from}:${t.start.line}:${t.start.column}$&`
        );
      }
      return e;
    }
    after(e) {
      return this.parent.insertAfter(this, e), this;
    }
    assign(e = {}) {
      for (let t in e)
        this[t] = e[t];
      return this;
    }
    before(e) {
      return this.parent.insertBefore(this, e), this;
    }
    cleanRaws(e) {
      delete this.raws.before, delete this.raws.after, e || delete this.raws.between;
    }
    clone(e = {}) {
      let t = c(this);
      for (let i in e)
        t[i] = e[i];
      return t;
    }
    cloneAfter(e = {}) {
      let t = this.clone(e);
      return this.parent.insertAfter(this, t), t;
    }
    cloneBefore(e = {}) {
      let t = this.clone(e);
      return this.parent.insertBefore(this, t), t;
    }
    error(e, t = {}) {
      if (this.source) {
        let { end: i, start: n } = this.rangeBy(t);
        return this.source.input.error(
          e,
          { column: n.column, line: n.line },
          { column: i.column, line: i.line },
          t
        );
      }
      return new p(e);
    }
    getProxyProcessor() {
      return {
        get(e, t) {
          return t === "proxyOf" ? e : t === "root" ? () => e.root().toProxy() : e[t];
        },
        set(e, t, i) {
          return e[t] === i || (e[t] = i, (t === "prop" || t === "value" || t === "name" || t === "params" || t === "important" || /* c8 ignore next */
          t === "text") && e.markDirty()), !0;
        }
      };
    }
    /* c8 ignore next 3 */
    markClean() {
      this[a] = !0;
    }
    markDirty() {
      if (this[a]) {
        this[a] = !1;
        let e = this;
        for (; e = e.parent; )
          e[a] = !1;
      }
    }
    next() {
      if (!this.parent) return;
      let e = this.parent.index(this);
      return this.parent.nodes[e + 1];
    }
    positionBy(e) {
      let t = this.source.start;
      if (e.index)
        t = this.positionInside(e.index);
      else if (e.word) {
        let i = "document" in this.source.input ? this.source.input.document : this.source.input.css, r = i.slice(
          f(i, this.source.start),
          f(i, this.source.end)
        ).indexOf(e.word);
        r !== -1 && (t = this.positionInside(r));
      }
      return t;
    }
    positionInside(e) {
      let t = this.source.start.column, i = this.source.start.line, n = "document" in this.source.input ? this.source.input.document : this.source.input.css, r = f(n, this.source.start), s = r + e;
      for (let l = r; l < s; l++)
        n[l] === `
` ? (t = 1, i += 1) : t += 1;
      return { column: t, line: i };
    }
    prev() {
      if (!this.parent) return;
      let e = this.parent.index(this);
      return this.parent.nodes[e - 1];
    }
    rangeBy(e) {
      let t = {
        column: this.source.start.column,
        line: this.source.start.line
      }, i = this.source.end ? {
        column: this.source.end.column + 1,
        line: this.source.end.line
      } : {
        column: t.column + 1,
        line: t.line
      };
      if (e.word) {
        let n = "document" in this.source.input ? this.source.input.document : this.source.input.css, s = n.slice(
          f(n, this.source.start),
          f(n, this.source.end)
        ).indexOf(e.word);
        s !== -1 && (t = this.positionInside(s), i = this.positionInside(
          s + e.word.length
        ));
      } else
        e.start ? t = {
          column: e.start.column,
          line: e.start.line
        } : e.index && (t = this.positionInside(e.index)), e.end ? i = {
          column: e.end.column,
          line: e.end.line
        } : typeof e.endIndex == "number" ? i = this.positionInside(e.endIndex) : e.index && (i = this.positionInside(e.index + 1));
      return (i.line < t.line || i.line === t.line && i.column <= t.column) && (i = { column: t.column + 1, line: t.line }), { end: i, start: t };
    }
    raw(e, t) {
      return new y().raw(this, e, t);
    }
    remove() {
      return this.parent && this.parent.removeChild(this), this.parent = void 0, this;
    }
    replaceWith(...e) {
      if (this.parent) {
        let t = this, i = !1;
        for (let n of e)
          n === this ? i = !0 : i ? (this.parent.insertAfter(t, n), t = n) : this.parent.insertBefore(t, n);
        i || this.remove();
      }
      return this;
    }
    root() {
      let e = this;
      for (; e.parent && e.parent.type !== "document"; )
        e = e.parent;
      return e;
    }
    toJSON(e, t) {
      let i = {}, n = t == null;
      t = t || /* @__PURE__ */ new Map();
      let r = 0;
      for (let s in this) {
        if (!Object.prototype.hasOwnProperty.call(this, s) || s === "parent" || s === "proxyCache") continue;
        let l = this[s];
        if (Array.isArray(l))
          i[s] = l.map((u) => typeof u == "object" && u.toJSON ? u.toJSON(null, t) : u);
        else if (typeof l == "object" && l.toJSON)
          i[s] = l.toJSON(null, t);
        else if (s === "source") {
          let u = t.get(l.input);
          u == null && (u = r, t.set(l.input, r), r++), i[s] = {
            end: l.end,
            inputId: u,
            start: l.start
          };
        } else
          i[s] = l;
      }
      return n && (i.inputs = [...t.keys()].map((s) => s.toJSON())), i;
    }
    toProxy() {
      return this.proxyCache || (this.proxyCache = new Proxy(this, this.getProxyProcessor())), this.proxyCache;
    }
    toString(e = x) {
      e.stringify && (e = e.stringify);
      let t = "";
      return e(this, (i) => {
        t += i;
      }), t;
    }
    warn(e, t, i) {
      let n = { node: this };
      for (let r in i) n[r] = i[r];
      return e.warn(t, n);
    }
  }
  return d = h, h.default = h, d;
}
export {
  b as __require
};
//# sourceMappingURL=node.js.map
