import { __exports as V } from "../../../../../../../_virtual/attribute.js";
import D from "../../../../../cssesc@3.0.0/node_modules/cssesc/cssesc.js";
import "../util/unesc.js";
import "./namespace.js";
import "./types.js";
import I from "../../../../../util-deprecate@1.0.2/node_modules/util-deprecate/browser.js";
import { __exports as N } from "../../../../../../../_virtual/types.js";
import { u as R } from "../../../../../../../_virtual/unesc.js";
import { n as C } from "../../../../../../../_virtual/namespace.js";
(function(v) {
  v.__esModule = !0, v.unescapeValue = k, v.default = void 0;
  var o = g(D), q = g(R.exports), y = g(C.exports), Q = N, _;
  function g(a) {
    return a && a.__esModule ? a : { default: a };
  }
  function w(a, i) {
    for (var u = 0; u < i.length; u++) {
      var r = i[u];
      r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(a, r.key, r);
    }
  }
  function m(a, i, u) {
    return i && w(a.prototype, i), u && w(a, u), a;
  }
  function E(a, i) {
    a.prototype = Object.create(i.prototype), a.prototype.constructor = a, p(a, i);
  }
  function p(a, i) {
    return p = Object.setPrototypeOf || function(r, e) {
      return r.__proto__ = e, r;
    }, p(a, i);
  }
  var l = I, S = /^('|")([^]*)\1$/, U = l(function() {
  }, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. Call attribute.setValue() instead."), T = l(function() {
  }, "Assigning attr.quoted is deprecated and has no effect. Assign to attr.quoteMark instead."), F = l(function() {
  }, "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now.");
  function k(a) {
    var i = !1, u = null, r = a, e = r.match(S);
    return e && (u = e[1], r = e[2]), r = (0, q.default)(r), r !== a && (i = !0), {
      deprecatedUsage: i,
      unescaped: r,
      quoteMark: u
    };
  }
  function A(a) {
    if (a.quoteMark !== void 0 || a.value === void 0)
      return a;
    F();
    var i = k(a.value), u = i.quoteMark, r = i.unescaped;
    return a.raws || (a.raws = {}), a.raws.value === void 0 && (a.raws.value = a.value), a.value = r, a.quoteMark = u, a;
  }
  var d = /* @__PURE__ */ function(a) {
    E(i, a);
    function i(r) {
      var e;
      return r === void 0 && (r = {}), e = a.call(this, A(r)) || this, e.type = Q.ATTRIBUTE, e.raws = e.raws || {}, Object.defineProperty(e.raws, "unquoted", {
        get: l(function() {
          return e.value;
        }, "attr.raws.unquoted is deprecated. Call attr.value instead."),
        set: l(function() {
          return e.value;
        }, "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now.")
      }), e._constructed = !0, e;
    }
    var u = i.prototype;
    return u.getQuotedValue = function(e) {
      e === void 0 && (e = {});
      var t = this._determineQuoteMark(e), n = M[t], s = (0, o.default)(this._value, n);
      return s;
    }, u._determineQuoteMark = function(e) {
      return e.smart ? this.smartQuoteMark(e) : this.preferredQuoteMark(e);
    }, u.setValue = function(e, t) {
      t === void 0 && (t = {}), this._value = e, this._quoteMark = this._determineQuoteMark(t), this._syncRawValue();
    }, u.smartQuoteMark = function(e) {
      var t = this.value, n = t.replace(/[^']/g, "").length, s = t.replace(/[^"]/g, "").length;
      if (n + s === 0) {
        var f = (0, o.default)(t, {
          isIdentifier: !0
        });
        if (f === t)
          return i.NO_QUOTE;
        var c = this.preferredQuoteMark(e);
        if (c === i.NO_QUOTE) {
          var h = this.quoteMark || e.quoteMark || i.DOUBLE_QUOTE, b = M[h], P = (0, o.default)(t, b);
          if (P.length < f.length)
            return h;
        }
        return c;
      } else
        return s === n ? this.preferredQuoteMark(e) : s < n ? i.DOUBLE_QUOTE : i.SINGLE_QUOTE;
    }, u.preferredQuoteMark = function(e) {
      var t = e.preferCurrentQuoteMark ? this.quoteMark : e.quoteMark;
      return t === void 0 && (t = e.preferCurrentQuoteMark ? e.quoteMark : this.quoteMark), t === void 0 && (t = i.DOUBLE_QUOTE), t;
    }, u._syncRawValue = function() {
      var e = (0, o.default)(this._value, M[this.quoteMark]);
      e === this._value ? this.raws && delete this.raws.value : this.raws.value = e;
    }, u._handleEscapes = function(e, t) {
      if (this._constructed) {
        var n = (0, o.default)(t, {
          isIdentifier: !0
        });
        n !== t ? this.raws[e] = n : delete this.raws[e];
      }
    }, u._spacesFor = function(e) {
      var t = {
        before: "",
        after: ""
      }, n = this.spaces[e] || {}, s = this.raws.spaces && this.raws.spaces[e] || {};
      return Object.assign(t, n, s);
    }, u._stringFor = function(e, t, n) {
      t === void 0 && (t = e), n === void 0 && (n = O);
      var s = this._spacesFor(t);
      return n(this.stringifyProperty(e), s);
    }, u.offsetOf = function(e) {
      var t = 1, n = this._spacesFor("attribute");
      if (t += n.before.length, e === "namespace" || e === "ns")
        return this.namespace ? t : -1;
      if (e === "attributeNS" || (t += this.namespaceString.length, this.namespace && (t += 1), e === "attribute"))
        return t;
      t += this.stringifyProperty("attribute").length, t += n.after.length;
      var s = this._spacesFor("operator");
      t += s.before.length;
      var f = this.stringifyProperty("operator");
      if (e === "operator")
        return f ? t : -1;
      t += f.length, t += s.after.length;
      var c = this._spacesFor("value");
      t += c.before.length;
      var h = this.stringifyProperty("value");
      if (e === "value")
        return h ? t : -1;
      t += h.length, t += c.after.length;
      var b = this._spacesFor("insensitive");
      return t += b.before.length, e === "insensitive" && this.insensitive ? t : -1;
    }, u.toString = function() {
      var e = this, t = [this.rawSpaceBefore, "["];
      return t.push(this._stringFor("qualifiedAttribute", "attribute")), this.operator && (this.value || this.value === "") && (t.push(this._stringFor("operator")), t.push(this._stringFor("value")), t.push(this._stringFor("insensitiveFlag", "insensitive", function(n, s) {
        return n.length > 0 && !e.quoted && s.before.length === 0 && !(e.spaces.value && e.spaces.value.after) && (s.before = " "), O(n, s);
      }))), t.push("]"), t.push(this.rawSpaceAfter), t.join("");
    }, m(i, [{
      key: "quoted",
      get: function() {
        var e = this.quoteMark;
        return e === "'" || e === '"';
      },
      set: function(e) {
        T();
      }
    }, {
      key: "quoteMark",
      get: function() {
        return this._quoteMark;
      },
      set: function(e) {
        if (!this._constructed) {
          this._quoteMark = e;
          return;
        }
        this._quoteMark !== e && (this._quoteMark = e, this._syncRawValue());
      }
    }, {
      key: "qualifiedAttribute",
      get: function() {
        return this.qualifiedName(this.raws.attribute || this.attribute);
      }
    }, {
      key: "insensitiveFlag",
      get: function() {
        return this.insensitive ? "i" : "";
      }
    }, {
      key: "value",
      get: function() {
        return this._value;
      },
      set: function(e) {
        if (this._constructed) {
          var t = k(e), n = t.deprecatedUsage, s = t.unescaped, f = t.quoteMark;
          if (n && U(), s === this._value && f === this._quoteMark)
            return;
          this._value = s, this._quoteMark = f, this._syncRawValue();
        } else
          this._value = e;
      }
    }, {
      key: "attribute",
      get: function() {
        return this._attribute;
      },
      set: function(e) {
        this._handleEscapes("attribute", e), this._attribute = e;
      }
    }]), i;
  }(y.default);
  v.default = d, d.NO_QUOTE = null, d.SINGLE_QUOTE = "'", d.DOUBLE_QUOTE = '"';
  var M = (_ = {
    "'": {
      quotes: "single",
      wrap: !0
    },
    '"': {
      quotes: "double",
      wrap: !0
    }
  }, _[null] = {
    isIdentifier: !0
  }, _);
  function O(a, i) {
    return "" + i.before + a + i.after;
  }
})(V);
//# sourceMappingURL=attribute.js.map
