var w = "(".charCodeAt(0), g = ")".charCodeAt(0), A = "'".charCodeAt(0), y = '"'.charCodeAt(0), I = "\\".charCodeAt(0), C = "/".charCodeAt(0), b = ",".charCodeAt(0), m = ":".charCodeAt(0), P = "*".charCodeAt(0), q = function(O) {
  for (var t = [], s = O, e, i, f, o, d, c, l, a = 0, r = s.charCodeAt(a), k = s.length, h = [{ nodes: t }], n = 0, v, u = "", p = "", x = ""; a < k; )
    if (r <= 32) {
      e = a;
      do
        e += 1, r = s.charCodeAt(e);
      while (r <= 32);
      o = s.slice(a, e), f = t[t.length - 1], r === g && n ? x = o : f && f.type === "div" ? f.after = o : r === b || r === m || r === C && s.charCodeAt(e + 1) !== P ? p = o : t.push({
        type: "space",
        sourceIndex: a,
        value: o
      }), a = e;
    } else if (r === A || r === y) {
      e = a, i = r === A ? "'" : '"', o = {
        type: "string",
        sourceIndex: a,
        quote: i
      };
      do
        if (d = !1, e = s.indexOf(i, e + 1), ~e)
          for (c = e; s.charCodeAt(c - 1) === I; )
            c -= 1, d = !d;
        else
          s += i, e = s.length - 1, o.unclosed = !0;
      while (d);
      o.value = s.slice(a + 1, e), t.push(o), a = e + 1, r = s.charCodeAt(a);
    } else if (r === C && s.charCodeAt(a + 1) === P)
      o = {
        type: "comment",
        sourceIndex: a
      }, e = s.indexOf("*/", a), e === -1 && (o.unclosed = !0, e = s.length), o.value = s.slice(a + 2, e), t.push(o), a = e + 2, r = s.charCodeAt(a);
    else if (r === C || r === b || r === m)
      o = s[a], t.push({
        type: "div",
        sourceIndex: a - p.length,
        value: o,
        before: p,
        after: ""
      }), p = "", a += 1, r = s.charCodeAt(a);
    else if (w === r) {
      e = a;
      do
        e += 1, r = s.charCodeAt(e);
      while (r <= 32);
      if (o = {
        type: "function",
        sourceIndex: a - u.length,
        value: u,
        before: s.slice(a + 1, e)
      }, a = e, u === "url" && r !== A && r !== y) {
        e -= 1;
        do
          if (d = !1, e = s.indexOf(")", e + 1), ~e)
            for (c = e; s.charCodeAt(c - 1) === I; )
              c -= 1, d = !d;
          else
            s += ")", e = s.length - 1, o.unclosed = !0;
        while (d);
        l = e;
        do
          l -= 1, r = s.charCodeAt(l);
        while (r <= 32);
        a !== l + 1 ? o.nodes = [
          {
            type: "word",
            sourceIndex: a,
            value: s.slice(a, l + 1)
          }
        ] : o.nodes = [], o.unclosed && l + 1 !== e ? (o.after = "", o.nodes.push({
          type: "space",
          sourceIndex: l + 1,
          value: s.slice(l + 1, e)
        })) : o.after = s.slice(l + 1, e), a = e + 1, r = s.charCodeAt(a), t.push(o);
      } else
        n += 1, o.after = "", t.push(o), h.push(o), t = o.nodes = [], v = o;
      u = "";
    } else if (g === r && n)
      a += 1, r = s.charCodeAt(a), v.after = x, x = "", n -= 1, h.pop(), v = h[n], t = v.nodes;
    else {
      e = a;
      do
        r === I && (e += 1), e += 1, r = s.charCodeAt(e);
      while (e < k && !(r <= 32 || r === A || r === y || r === b || r === m || r === C || r === w || r === g && n));
      o = s.slice(a, e), w === r ? u = o : t.push({
        type: "word",
        sourceIndex: a,
        value: o
      }), a = e;
    }
  for (a = h.length - 1; a; a -= 1)
    h[a].unclosed = !0;
  return h[0].nodes;
};
export {
  q as default
};
//# sourceMappingURL=parse.js.map
