import {
  a as p,
  c as I
} from "./chunk-IO47FP3U.js";

// ../node_modules/refractor/lang/js-templates.js
var N = I((U, O) => {
  O.exports = T;
  T.displayName = "jsTemplates";
  T.aliases = [];
  function T(C) {
    (function(a) {
      var h = a.languages.javascript["template-string"], E = h.pattern.source, b = h.inside.interpolation, S = b.inside["interpolation-punctuation"], L = b.pattern.source;
      function y(t, n) {
        if (a.languages[t])
          return {
            pattern: RegExp("((?:" + n + ")\\s*)" + E),
            lookbehind: !0,
            greedy: !0,
            inside: {
              "template-punctuation": {
                pattern: /^`|`$/,
                alias: "string"
              },
              "embedded-code": {
                pattern: /[\s\S]+/,
                alias: t
              }
            }
          };
      }
      p(y, "createTemplate"), a.languages.javascript["template-string"] = [
        // styled-jsx:
        //   css`a { color: #25F; }`
        // styled-components:
        //   styled.h1`color: red;`
        y(
          "css",
          /\b(?:styled(?:\([^)]*\))?(?:\s*\.\s*\w+(?:\([^)]*\))*)*|css(?:\s*\.\s*(?:global|resolve))?|createGlobalStyle|keyframes)/.source
        ),
        // html`<p></p>`
        // div.innerHTML = `<p></p>`
        y("html", /\bhtml|\.\s*(?:inner|outer)HTML\s*\+?=/.source),
        // svg`<path fill="#fff" d="M55.37 ..."/>`
        y("svg", /\bsvg/.source),
        // md`# h1`, markdown`## h2`
        y("markdown", /\b(?:markdown|md)/.source),
        // gql`...`, graphql`...`, graphql.experimental`...`
        y(
          "graphql",
          /\b(?:gql|graphql(?:\s*\.\s*experimental)?)/.source
        ),
        // sql`...`
        y("sql", /\bsql/.source),
        // vanilla template string
        h
      ].filter(Boolean);
      function G(t, n) {
        return "___" + n.toUpperCase() + "_" + t + "___";
      }
      p(G, "getPlaceholder");
      function _(t, n, r) {
        var e = {
          code: t,
          grammar: n,
          language: r
        };
        return a.hooks.run("before-tokenize", e), e.tokens = a.tokenize(e.code, e.grammar), a.hooks.run("after-tokenize", e), e.tokens;
      }
      p(_, "tokenizeWithHooks");
      function H(t) {
        var n = {};
        n["interpolation-punctuation"] = S;
        var r = a.tokenize(t, n);
        if (r.length === 3) {
          var e = [1, 1];
          e.push.apply(
            e,
            _(r[1], a.languages.javascript, "javascript")
          ), r.splice.apply(r, e);
        }
        return new a.Token(
          "interpolation",
          r,
          b.alias,
          t
        );
      }
      p(H, "tokenizeInterpolationExpression");
      function M(t, n, r) {
        var e = a.tokenize(t, {
          interpolation: {
            pattern: RegExp(L),
            lookbehind: !0
          }
        }), f = 0, g = {}, u = e.map(function(s) {
          if (typeof s == "string")
            return s;
          for (var o = s.content, i; t.indexOf(
            i = G(f++, r)
          ) !== -1; )
            ;
          return g[i] = o, i;
        }).join(""), v = _(u, n, r), d = Object.keys(g);
        f = 0;
        function l(s) {
          for (var o = 0; o < s.length; o++) {
            if (f >= d.length)
              return;
            var i = s[o];
            if (typeof i == "string" || typeof i.content == "string") {
              var k = d[f], m = typeof i == "string" ? i : (
                /** @type {string} */
                i.content
              ), z = m.indexOf(k);
              if (z !== -1) {
                ++f;
                var w = m.substring(0, z), B = H(
                  g[k]
                ), x = m.substring(z + k.length), c = [];
                if (w && c.push(w), c.push(B), x) {
                  var q = [x];
                  l(q), c.push.apply(c, q);
                }
                typeof i == "string" ? (s.splice.apply(s, [o, 1].concat(c)), o += c.length - 1) : i.content = c;
              }
            } else {
              var A = i.content;
              Array.isArray(A) ? l(A) : l([A]);
            }
          }
        }
        return p(l, "walkTokens"), l(v), new a.Token(
          r,
          v,
          "language-" + r,
          t
        );
      }
      p(M, "tokenizeEmbedded");
      var R = {
        javascript: !0,
        js: !0,
        typescript: !0,
        ts: !0,
        jsx: !0,
        tsx: !0
      };
      a.hooks.add("after-tokenize", function(t) {
        if (!(t.language in R))
          return;
        function n(r) {
          for (var e = 0, f = r.length; e < f; e++) {
            var g = r[e];
            if (typeof g != "string") {
              var u = g.content;
              if (!Array.isArray(u)) {
                typeof u != "string" && n([u]);
                continue;
              }
              if (g.type === "template-string") {
                var v = u[1];
                if (u.length === 3 && typeof v != "string" && v.type === "embedded-code") {
                  var d = j(v), l = v.alias, s = Array.isArray(l) ? l[0] : l, o = a.languages[s];
                  if (!o)
                    continue;
                  u[1] = M(d, o, s);
                }
              } else
                n(u);
            }
          }
        }
        p(n, "findTemplateStrings"), n(t.tokens);
      });
      function j(t) {
        return typeof t == "string" ? t : Array.isArray(t) ? t.map(j).join("") : j(t.content);
      }
      p(j, "stringContent");
    })(C);
  }
  p(T, "jsTemplates");
});

export {
  N as a
};
