var B = Object.defineProperty;
var r = (e, t) => B(e, "name", { value: t, configurable: !0 });
import { parser as F } from "../../../../../@lezer_javascript@1.4.21/node_modules/@lezer/javascript/dist/index.js";
import { LanguageSupport as j, LRLanguage as L, sublanguageProp as C, defineLanguageFacet as N, indentNodeProp as O, foldNodeProp as P, continuedIndent as $, delimitedIndent as V, flatIndent as M, foldInside as _, syntaxTree as J } from "../../../../../@codemirror_language@6.11.0/node_modules/@codemirror/language/dist/index.js";
import { EditorSelection as R } from "../../../../../@codemirror_state@6.5.2/node_modules/@codemirror/state/dist/index.js";
import { EditorView as W } from "../../../../../@codemirror_view@6.36.4/node_modules/@codemirror/view/dist/index.js";
import { snippetCompletion as i, ifNotIn as H, completeFromList as K } from "../../../../../@codemirror_autocomplete@6.18.6/node_modules/@codemirror/autocomplete/dist/index.js";
import { NodeWeakMap as q, IterMode as z } from "../../../../../@lezer_common@1.2.3/node_modules/@lezer/common/dist/index.js";
const X = [
  /* @__PURE__ */ i("function ${name}(${params}) {\n	${}\n}", {
    label: "function",
    detail: "definition",
    type: "keyword"
  }),
  /* @__PURE__ */ i("for (let ${index} = 0; ${index} < ${bound}; ${index}++) {\n	${}\n}", {
    label: "for",
    detail: "loop",
    type: "keyword"
  }),
  /* @__PURE__ */ i("for (let ${name} of ${collection}) {\n	${}\n}", {
    label: "for",
    detail: "of loop",
    type: "keyword"
  }),
  /* @__PURE__ */ i("do {\n	${}\n} while (${})", {
    label: "do",
    detail: "loop",
    type: "keyword"
  }),
  /* @__PURE__ */ i("while (${}) {\n	${}\n}", {
    label: "while",
    detail: "loop",
    type: "keyword"
  }),
  /* @__PURE__ */ i(`try {
	\${}
} catch (\${error}) {
	\${}
}`, {
    label: "try",
    detail: "/ catch block",
    type: "keyword"
  }),
  /* @__PURE__ */ i("if (${}) {\n	${}\n}", {
    label: "if",
    detail: "block",
    type: "keyword"
  }),
  /* @__PURE__ */ i(`if (\${}) {
	\${}
} else {
	\${}
}`, {
    label: "if",
    detail: "/ else block",
    type: "keyword"
  }),
  /* @__PURE__ */ i(`class \${name} {
	constructor(\${params}) {
		\${}
	}
}`, {
    label: "class",
    detail: "definition",
    type: "keyword"
  }),
  /* @__PURE__ */ i('import {${names}} from "${module}"\n${}', {
    label: "import",
    detail: "named",
    type: "keyword"
  }),
  /* @__PURE__ */ i('import ${name} from "${module}"\n${}', {
    label: "import",
    detail: "default",
    type: "keyword"
  })
], G = /* @__PURE__ */ X.concat([
  /* @__PURE__ */ i("interface ${name} {\n	${}\n}", {
    label: "interface",
    detail: "definition",
    type: "keyword"
  }),
  /* @__PURE__ */ i("type ${name} = ${type}", {
    label: "type",
    detail: "definition",
    type: "keyword"
  }),
  /* @__PURE__ */ i("enum ${name} {\n	${}\n}", {
    label: "enum",
    detail: "definition",
    type: "keyword"
  })
]), k = /* @__PURE__ */ new q(), I = /* @__PURE__ */ new Set([
  "Script",
  "Block",
  "FunctionExpression",
  "FunctionDeclaration",
  "ArrowFunction",
  "MethodDeclaration",
  "ForStatement"
]);
function u(e) {
  return (t, o) => {
    let n = t.node.getChild("VariableDefinition");
    return n && o(n, e), !0;
  };
}
r(u, "defID");
const Q = ["FunctionDeclaration"], U = {
  FunctionDeclaration: /* @__PURE__ */ u("function"),
  ClassDeclaration: /* @__PURE__ */ u("class"),
  ClassExpression: /* @__PURE__ */ r(() => !0, "ClassExpression"),
  EnumDeclaration: /* @__PURE__ */ u("constant"),
  TypeAliasDeclaration: /* @__PURE__ */ u("type"),
  NamespaceDeclaration: /* @__PURE__ */ u("namespace"),
  VariableDefinition(e, t) {
    e.matchContext(Q) || t(e, "variable");
  },
  TypeDefinition(e, t) {
    t(e, "type");
  },
  __proto__: null
};
function D(e, t) {
  let o = k.get(t);
  if (o)
    return o;
  let n = [], s = !0;
  function y(a, p) {
    let m = e.sliceString(a.from, a.to);
    n.push({ label: m, type: p });
  }
  return r(y, "def"), t.cursor(z.IncludeAnonymous).iterate((a) => {
    if (s)
      s = !1;
    else if (a.name) {
      let p = U[a.name];
      if (p && p(a, y) || I.has(a.name))
        return !1;
    } else if (a.to - a.from > 8192) {
      for (let p of D(e, a.node))
        n.push(p);
      return !1;
    }
  }), k.set(t, n), n;
}
r(D, "getScope");
const w = /^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/, v = [
  "TemplateString",
  "String",
  "RegExp",
  "LineComment",
  "BlockComment",
  "VariableDefinition",
  "TypeDefinition",
  "Label",
  "PropertyDefinition",
  "PropertyName",
  "PrivatePropertyDefinition",
  "PrivatePropertyName",
  "JSXText",
  "JSXAttributeValue",
  "JSXOpenTag",
  "JSXCloseTag",
  "JSXSelfClosingTag",
  ".",
  "?."
];
function Y(e) {
  let t = J(e.state).resolveInner(e.pos, -1);
  if (v.indexOf(t.name) > -1)
    return null;
  let o = t.name == "VariableName" || t.to - t.from < 20 && w.test(e.state.sliceDoc(t.from, t.to));
  if (!o && !e.explicit)
    return null;
  let n = [];
  for (let s = t; s; s = s.parent)
    I.has(s.name) && (n = n.concat(D(e.state.doc, s)));
  return {
    options: n,
    from: o ? t.from : e.pos,
    validFor: w
  };
}
r(Y, "localCompletionSource");
const f = /* @__PURE__ */ L.define({
  name: "javascript",
  parser: /* @__PURE__ */ F.configure({
    props: [
      /* @__PURE__ */ O.add({
        IfStatement: /* @__PURE__ */ $({ except: /^\s*({|else\b)/ }),
        TryStatement: /* @__PURE__ */ $({ except: /^\s*({|catch\b|finally\b)/ }),
        LabeledStatement: M,
        SwitchBody: /* @__PURE__ */ r((e) => {
          let t = e.textAfter, o = /^\s*\}/.test(t), n = /^\s*(case|default)\b/.test(t);
          return e.baseIndent + (o ? 0 : n ? 1 : 2) * e.unit;
        }, "SwitchBody"),
        Block: /* @__PURE__ */ V({ closing: "}" }),
        ArrowFunction: /* @__PURE__ */ r((e) => e.baseIndent + e.unit, "ArrowFunction"),
        "TemplateString BlockComment": /* @__PURE__ */ r(() => null, "TemplateString BlockComment"),
        "Statement Property": /* @__PURE__ */ $({ except: /^{/ }),
        JSXElement(e) {
          let t = /^\s*<\//.test(e.textAfter);
          return e.lineIndent(e.node.from) + (t ? 0 : e.unit);
        },
        JSXEscape(e) {
          let t = /\s*\}/.test(e.textAfter);
          return e.lineIndent(e.node.from) + (t ? 0 : e.unit);
        },
        "JSXOpenTag JSXSelfClosingTag"(e) {
          return e.column(e.node.from) + e.unit;
        }
      }),
      /* @__PURE__ */ P.add({
        "Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType": _,
        BlockComment(e) {
          return { from: e.from + 2, to: e.to - 2 };
        }
      })
    ]
  }),
  languageData: {
    closeBrackets: { brackets: ["(", "[", "{", "'", '"', "`"] },
    commentTokens: { line: "//", block: { open: "/*", close: "*/" } },
    indentOnInput: /^\s*(?:case |default:|\{|\}|<\/)$/,
    wordChars: "$"
  }
}), A = {
  test: /* @__PURE__ */ r((e) => /^JSX/.test(e.name), "test"),
  facet: /* @__PURE__ */ N({ commentTokens: { block: { open: "{/*", close: "*/}" } } })
}, Z = /* @__PURE__ */ f.configure({ dialect: "ts" }, "typescript"), ee = /* @__PURE__ */ f.configure({
  dialect: "jsx",
  props: [/* @__PURE__ */ C.add((e) => e.isTop ? [A] : void 0)]
}), te = /* @__PURE__ */ f.configure({
  dialect: "jsx ts",
  props: [/* @__PURE__ */ C.add((e) => e.isTop ? [A] : void 0)]
}, "typescript");
let E = /* @__PURE__ */ r((e) => ({ label: e, type: "keyword" }), "kwCompletion");
const x = /* @__PURE__ */ "break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(E), ne = /* @__PURE__ */ x.concat(/* @__PURE__ */ ["declare", "implements", "private", "protected", "public"].map(E));
function de(e = {}) {
  let t = e.jsx ? e.typescript ? te : ee : e.typescript ? Z : f, o = e.typescript ? G.concat(ne) : X.concat(x);
  return new j(t, [
    f.data.of({
      autocomplete: H(v, K(o))
    }),
    f.data.of({
      autocomplete: Y
    }),
    e.jsx ? re : []
  ]);
}
r(de, "javascript");
function ae(e) {
  for (; ; ) {
    if (e.name == "JSXOpenTag" || e.name == "JSXSelfClosingTag" || e.name == "JSXFragmentTag")
      return e;
    if (e.name == "JSXEscape" || !e.parent)
      return null;
    e = e.parent;
  }
}
r(ae, "findOpenTag");
function T(e, t, o = e.length) {
  for (let n = t?.firstChild; n; n = n.nextSibling)
    if (n.name == "JSXIdentifier" || n.name == "JSXBuiltin" || n.name == "JSXNamespacedName" || n.name == "JSXMemberExpression")
      return e.sliceString(n.from, Math.min(n.to, o));
  return "";
}
r(T, "elementName");
const oe = typeof navigator == "object" && /* @__PURE__ */ /Android\b/.test(navigator.userAgent), re = /* @__PURE__ */ W.inputHandler.of((e, t, o, n, s) => {
  if ((oe ? e.composing : e.compositionStarted) || e.state.readOnly || t != o || n != ">" && n != "/" || !f.isActiveAt(e.state, t, -1))
    return !1;
  let y = s(), { state: a } = y, p = a.changeByRange((m) => {
    var S;
    let { head: l } = m, c = J(a).resolveInner(l - 1, -1), g;
    if (c.name == "JSXStartTag" && (c = c.parent), !(a.doc.sliceString(l - 1, l) != n || c.name == "JSXAttributeValue" && c.to > l)) {
      if (n == ">" && c.name == "JSXFragmentTag")
        return { range: m, changes: { from: l, insert: "</>" } };
      if (n == "/" && c.name == "JSXStartCloseTag") {
        let d = c.parent, b = d.parent;
        if (b && d.from == l - 2 && ((g = T(a.doc, b.firstChild, l)) || ((S = b.firstChild) === null || S === void 0 ? void 0 : S.name) == "JSXFragmentTag")) {
          let h = `${g}>`;
          return { range: R.cursor(l + h.length, -1), changes: { from: l, insert: h } };
        }
      } else if (n == ">") {
        let d = ae(c);
        if (d && d.name == "JSXOpenTag" && !/^\/?>|^<\//.test(a.doc.sliceString(l, l + 2)) && (g = T(a.doc, d, l)))
          return { range: m, changes: { from: l, insert: `</${g}>` } };
      }
    }
    return { range: m };
  });
  return p.changes.empty ? !1 : (e.dispatch([
    y,
    a.update(p, { userEvent: "input.complete", scrollIntoView: !0 })
  ]), !0);
});
export {
  re as autoCloseTags,
  de as javascript,
  f as javascriptLanguage,
  ee as jsxLanguage,
  Y as localCompletionSource,
  X as snippets,
  te as tsxLanguage,
  Z as typescriptLanguage,
  G as typescriptSnippets
};
