UNPKG

ghost

Version:

The professional publishing platform

1,287 lines (1,285 loc) 86.4 kB
import { b as G, p as Vn, g as K, f as Wt, cm as zn, d as Ft, cn as Un, o as $n, j as _, co as Gn, l as Kn, R as Jn, z as jn, n as Qn, H as Yn, m as Zn } from "./index-BVxh86CD.mjs"; import { q as d, v as Nt, w as _t, x as Ae, y as qt, S as Re, F as pe, E as p, z as ie, g as ot, b as je, A as it, B as ze, C as Ie, G as Xn, H as er, J as tr, K as T, M as re, O as Ht, Q as Qe, R as Vt, U as nr, V as de, W as zt, X as st, Y as rr, Z as or, _ as ir, $ as x, a0 as me, a1 as sr, a2 as D, a3 as lr, a4 as ar, a5 as cr, a6 as ur, a7 as hr, a8 as fr, a9 as dr, aa as mr, ab as gr, ac as pr, ad as yr, ae as xr, af as kr, ag as Ut, ah as br, ai as Sr, aj as Cr, ak as vr, al as Ar, am as Mr, an as $t, ao as Lr, ap as Dr, t as f, aq as Br } from "./index-o4Q9MNrB.mjs"; const Er = (t) => { let { state: e } = t, r = e.doc.lineAt(e.selection.main.from), n = at(t.state, r.from); return n.line ? wr(t) : n.block ? Rr(t) : !1; }; function lt(t, e) { return ({ state: r, dispatch: n }) => { if (r.readOnly) return !1; let o = t(e, r); return o ? (n(r.update(o)), !0) : !1; }; } const wr = /* @__PURE__ */ lt( Pr, 0 /* CommentOption.Toggle */ ), Tr = /* @__PURE__ */ lt( Gt, 0 /* CommentOption.Toggle */ ), Rr = /* @__PURE__ */ lt( (t, e) => Gt(t, e, Or(e)), 0 /* CommentOption.Toggle */ ); function at(t, e) { let r = t.languageDataAt("commentTokens", e); return r.length ? r[0] : {}; } const fe = 50; function Ir(t, { open: e, close: r }, n, o) { let i = t.sliceDoc(n - fe, n), s = t.sliceDoc(o, o + fe), l = /\s*$/.exec(i)[0].length, a = /^\s*/.exec(s)[0].length, c = i.length - l; if (i.slice(c - e.length, c) == e && s.slice(a, a + r.length) == r) return { open: { pos: n - l, margin: l && 1 }, close: { pos: o + a, margin: a && 1 } }; let u, h; o - n <= 2 * fe ? u = h = t.sliceDoc(n, o) : (u = t.sliceDoc(n, n + fe), h = t.sliceDoc(o - fe, o)); let m = /^\s*/.exec(u)[0].length, k = /\s*$/.exec(h)[0].length, C = h.length - k - r.length; return u.slice(m, m + e.length) == e && h.slice(C, C + r.length) == r ? { open: { pos: n + m + e.length, margin: /\s/.test(u.charAt(m + e.length)) ? 1 : 0 }, close: { pos: o - k - r.length, margin: /\s/.test(h.charAt(C - 1)) ? 1 : 0 } } : null; } function Or(t) { let e = []; for (let r of t.selection.ranges) { let n = t.doc.lineAt(r.from), o = r.to <= n.to ? n : t.doc.lineAt(r.to), i = e.length - 1; i >= 0 && e[i].to > n.from ? e[i].to = o.to : e.push({ from: n.from + /^\s*/.exec(n.text)[0].length, to: o.to }); } return e; } function Gt(t, e, r = e.selection.ranges) { let n = r.map((i) => at(e, i.from).block); if (!n.every((i) => i)) return null; let o = r.map((i, s) => Ir(e, n[s], i.from, i.to)); if (t != 2 && !o.every((i) => i)) return { changes: e.changes(r.map((i, s) => o[s] ? [] : [{ from: i.from, insert: n[s].open + " " }, { from: i.to, insert: " " + n[s].close }])) }; if (t != 1 && o.some((i) => i)) { let i = []; for (let s = 0, l; s < o.length; s++) if (l = o[s]) { let a = n[s], { open: c, close: u } = l; i.push({ from: c.pos - a.open.length, to: c.pos + c.margin }, { from: u.pos - u.margin, to: u.pos + a.close.length }); } return { changes: i }; } return null; } function Pr(t, e, r = e.selection.ranges) { let n = [], o = -1; for (let { from: i, to: s } of r) { let l = n.length, a = 1e9, c = at(e, i).line; if (c) { for (let u = i; u <= s; ) { let h = e.doc.lineAt(u); if (h.from > o && (i == s || s > h.from)) { o = h.from; let m = /^\s*/.exec(h.text)[0].length, k = m == h.length, C = h.text.slice(m, m + c.length) == c ? m : -1; m < h.text.length && m < a && (a = m), n.push({ line: h, comment: C, token: c, indent: m, empty: k, single: !1 }); } u = h.to + 1; } if (a < 1e9) for (let u = l; u < n.length; u++) n[u].indent < n[u].line.text.length && (n[u].indent = a); n.length == l + 1 && (n[l].single = !0); } } if (t != 2 && n.some((i) => i.comment < 0 && (!i.empty || i.single))) { let i = []; for (let { line: l, token: a, indent: c, empty: u, single: h } of n) (h || !u) && i.push({ from: l.from + c, insert: a + " " }); let s = e.changes(i); return { changes: s, selection: e.selection.map(s, 1) }; } else if (t != 1 && n.some((i) => i.comment >= 0)) { let i = []; for (let { line: s, comment: l, token: a } of n) if (l >= 0) { let c = s.from + l, u = c + a.length; s.text[u - s.from] == " " && u++, i.push({ from: c, to: u }); } return { changes: i }; } return null; } const Ye = /* @__PURE__ */ it.define(), Wr = /* @__PURE__ */ it.define(), Fr = /* @__PURE__ */ pe.define(), Kt = /* @__PURE__ */ pe.define({ combine(t) { return Ie(t, { minDepth: 100, newGroupDelay: 500, joinToEvent: (e, r) => r }, { minDepth: Math.max, newGroupDelay: Math.min, joinToEvent: (e, r) => (n, o) => e(n, o) || r(n, o) }); } }); function Nr(t) { let e = 0; return t.iterChangedRanges((r, n) => e = n), e; } const Jt = /* @__PURE__ */ Re.define({ create() { return O.empty; }, update(t, e) { let r = e.state.facet(Kt), n = e.annotation(Ye); if (n) { let a = e.docChanged ? d.single(Nr(e.changes)) : void 0, c = v.fromTransaction(e, a), u = n.side, h = u == 0 ? t.undone : t.done; return c ? h = Me(h, h.length, r.minDepth, c) : h = Yt(h, e.startState.selection), new O(u == 0 ? n.rest : h, u == 0 ? h : n.rest); } let o = e.annotation(Wr); if ((o == "full" || o == "before") && (t = t.isolate()), e.annotation(ze.addToHistory) === !1) return e.changes.empty ? t : t.addMapping(e.changes.desc); let i = v.fromTransaction(e), s = e.annotation(ze.time), l = e.annotation(ze.userEvent); return i ? t = t.addChanges(i, s, l, r, e) : e.selection && (t = t.addSelection(e.startState.selection, s, l, r.newGroupDelay)), (o == "full" || o == "after") && (t = t.isolate()), t; }, toJSON(t) { return { done: t.done.map((e) => e.toJSON()), undone: t.undone.map((e) => e.toJSON()) }; }, fromJSON(t) { return new O(t.done.map(v.fromJSON), t.undone.map(v.fromJSON)); } }); function _r(t = {}) { return [ Jt, Kt.of(t), p.domEventHandlers({ beforeinput(e, r) { let n = e.inputType == "historyUndo" ? jt : e.inputType == "historyRedo" ? Ze : null; return n ? (e.preventDefault(), n(r)) : !1; } }) ]; } function Oe(t, e) { return function({ state: r, dispatch: n }) { if (!e && r.readOnly) return !1; let o = r.field(Jt, !1); if (!o) return !1; let i = o.pop(t, r, e); return i ? (n(i), !0) : !1; }; } const jt = /* @__PURE__ */ Oe(0, !1), Ze = /* @__PURE__ */ Oe(1, !1), qr = /* @__PURE__ */ Oe(0, !0), Hr = /* @__PURE__ */ Oe(1, !0); class v { constructor(e, r, n, o, i) { this.changes = e, this.effects = r, this.mapped = n, this.startSelection = o, this.selectionsAfter = i; } setSelAfter(e) { return new v(this.changes, this.effects, this.mapped, this.startSelection, e); } toJSON() { var e, r, n; return { changes: (e = this.changes) === null || e === void 0 ? void 0 : e.toJSON(), mapped: (r = this.mapped) === null || r === void 0 ? void 0 : r.toJSON(), startSelection: (n = this.startSelection) === null || n === void 0 ? void 0 : n.toJSON(), selectionsAfter: this.selectionsAfter.map((o) => o.toJSON()) }; } static fromJSON(e) { return new v(e.changes && er.fromJSON(e.changes), [], e.mapped && tr.fromJSON(e.mapped), e.startSelection && d.fromJSON(e.startSelection), e.selectionsAfter.map(d.fromJSON)); } // This does not check `addToHistory` and such, it assumes the // transaction needs to be converted to an item. Returns null when // there are no changes or effects in the transaction. static fromTransaction(e, r) { let n = B; for (let o of e.startState.facet(Fr)) { let i = o(e); i.length && (n = n.concat(i)); } return !n.length && e.changes.empty ? null : new v(e.changes.invert(e.startState.doc), n, void 0, r || e.startState.selection, B); } static selection(e) { return new v(void 0, B, void 0, void 0, e); } } function Me(t, e, r, n) { let o = e + 1 > r + 20 ? e - r - 1 : 0, i = t.slice(o, e); return i.push(n), i; } function Vr(t, e) { let r = [], n = !1; return t.iterChangedRanges((o, i) => r.push(o, i)), e.iterChangedRanges((o, i, s, l) => { for (let a = 0; a < r.length; ) { let c = r[a++], u = r[a++]; l >= c && s <= u && (n = !0); } }), n; } function zr(t, e) { return t.ranges.length == e.ranges.length && t.ranges.filter((r, n) => r.empty != e.ranges[n].empty).length === 0; } function Qt(t, e) { return t.length ? e.length ? t.concat(e) : t : e; } const B = [], Ur = 200; function Yt(t, e) { if (t.length) { let r = t[t.length - 1], n = r.selectionsAfter.slice(Math.max(0, r.selectionsAfter.length - Ur)); return n.length && n[n.length - 1].eq(e) ? t : (n.push(e), Me(t, t.length - 1, 1e9, r.setSelAfter(n))); } else return [v.selection([e])]; } function $r(t) { let e = t[t.length - 1], r = t.slice(); return r[t.length - 1] = e.setSelAfter(e.selectionsAfter.slice(0, e.selectionsAfter.length - 1)), r; } function Ue(t, e) { if (!t.length) return t; let r = t.length, n = B; for (; r; ) { let o = Gr(t[r - 1], e, n); if (o.changes && !o.changes.empty || o.effects.length) { let i = t.slice(0, r); return i[r - 1] = o, i; } else e = o.mapped, r--, n = o.selectionsAfter; } return n.length ? [v.selection(n)] : B; } function Gr(t, e, r) { let n = Qt(t.selectionsAfter.length ? t.selectionsAfter.map((l) => l.map(e)) : B, r); if (!t.changes) return v.selection(n); let o = t.changes.map(e), i = e.mapDesc(t.changes, !0), s = t.mapped ? t.mapped.composeDesc(i) : i; return new v(o, T.mapEffects(t.effects, e), s, t.startSelection.map(i), n); } const Kr = /^(input\.type|delete)($|\.)/; class O { constructor(e, r, n = 0, o = void 0) { this.done = e, this.undone = r, this.prevTime = n, this.prevUserEvent = o; } isolate() { return this.prevTime ? new O(this.done, this.undone) : this; } addChanges(e, r, n, o, i) { let s = this.done, l = s[s.length - 1]; return l && l.changes && !l.changes.empty && e.changes && (!n || Kr.test(n)) && (!l.selectionsAfter.length && r - this.prevTime < o.newGroupDelay && o.joinToEvent(i, Vr(l.changes, e.changes)) || // For compose (but not compose.start) events, always join with previous event n == "input.type.compose") ? s = Me(s, s.length - 1, o.minDepth, new v(e.changes.compose(l.changes), Qt(e.effects, l.effects), l.mapped, l.startSelection, B)) : s = Me(s, s.length, o.minDepth, e), new O(s, B, r, n); } addSelection(e, r, n, o) { let i = this.done.length ? this.done[this.done.length - 1].selectionsAfter : B; return i.length > 0 && r - this.prevTime < o && n == this.prevUserEvent && n && /^select($|\.)/.test(n) && zr(i[i.length - 1], e) ? this : new O(Yt(this.done, e), this.undone, r, n); } addMapping(e) { return new O(Ue(this.done, e), Ue(this.undone, e), this.prevTime, this.prevUserEvent); } pop(e, r, n) { let o = e == 0 ? this.done : this.undone; if (o.length == 0) return null; let i = o[o.length - 1]; if (n && i.selectionsAfter.length) return r.update({ selection: i.selectionsAfter[i.selectionsAfter.length - 1], annotations: Ye.of({ side: e, rest: $r(o) }), userEvent: e == 0 ? "select.undo" : "select.redo", scrollIntoView: !0 }); if (i.changes) { let s = o.length == 1 ? B : o.slice(0, o.length - 1); return i.mapped && (s = Ue(s, i.mapped)), r.update({ changes: i.changes, selection: i.startSelection, effects: i.effects, annotations: Ye.of({ side: e, rest: s }), filter: !1, userEvent: e == 0 ? "undo" : "redo", scrollIntoView: !0 }); } else return null; } } O.empty = /* @__PURE__ */ new O(B, B); const Jr = [ { key: "Mod-z", run: jt, preventDefault: !0 }, { key: "Mod-y", mac: "Mod-Shift-z", run: Ze, preventDefault: !0 }, { linux: "Ctrl-Shift-z", run: Ze, preventDefault: !0 }, { key: "Mod-u", run: qr, preventDefault: !0 }, { key: "Alt-u", mac: "Mod-Shift-u", run: Hr, preventDefault: !0 } ]; function ae(t, e) { return d.create(t.ranges.map(e), t.mainIndex); } function P(t, e) { return t.update({ selection: e, scrollIntoView: !0, userEvent: "select" }); } function R({ state: t, dispatch: e }, r) { let n = ae(t.selection, r); return n.eq(t.selection) ? !1 : (e(P(t, n)), !0); } function Pe(t, e) { return d.cursor(e ? t.to : t.from); } function Zt(t, e) { return R(t, (r) => r.empty ? t.moveByChar(r, e) : Pe(r, e)); } function S(t) { return t.textDirectionAt(t.state.selection.main.head) == Xn.LTR; } const Xt = (t) => Zt(t, !S(t)), en = (t) => Zt(t, S(t)); function tn(t, e) { return R(t, (r) => r.empty ? t.moveByGroup(r, e) : Pe(r, e)); } const jr = (t) => tn(t, !S(t)), Qr = (t) => tn(t, S(t)); function Yr(t, e, r) { if (e.type.prop(r)) return !0; let n = e.to - e.from; return n && (n > 2 || /[^\s,.;:]/.test(t.sliceDoc(e.from, e.to))) || e.firstChild; } function We(t, e, r) { let n = ot(t).resolveInner(e.head), o = r ? je.closedBy : je.openedBy; for (let a = e.head; ; ) { let c = r ? n.childAfter(a) : n.childBefore(a); if (!c) break; Yr(t, c, o) ? n = c : a = r ? c.to : c.from; } let i = n.type.prop(o), s, l; return i && (s = r ? re(t, n.from, 1) : re(t, n.to, -1)) && s.matched ? l = r ? s.end.to : s.end.from : l = r ? n.to : n.from, d.cursor(l, r ? -1 : 1); } const Zr = (t) => R(t, (e) => We(t.state, e, !S(t))), Xr = (t) => R(t, (e) => We(t.state, e, S(t))); function nn(t, e) { return R(t, (r) => { if (!r.empty) return Pe(r, e); let n = t.moveVertically(r, e); return n.head != r.head ? n : t.moveToLineBoundary(r, e); }); } const rn = (t) => nn(t, !1), on = (t) => nn(t, !0); function sn(t) { let e = t.scrollDOM.clientHeight < t.scrollDOM.scrollHeight - 2, r = 0, n = 0, o; if (e) { for (let i of t.state.facet(p.scrollMargins)) { let s = i(t); s != null && s.top && (r = Math.max(s == null ? void 0 : s.top, r)), s != null && s.bottom && (n = Math.max(s == null ? void 0 : s.bottom, n)); } o = t.scrollDOM.clientHeight - r - n; } else o = (t.dom.ownerDocument.defaultView || window).innerHeight; return { marginTop: r, marginBottom: n, selfScroll: e, height: Math.max(t.defaultLineHeight, o - 5) }; } function ln(t, e) { let r = sn(t), { state: n } = t, o = ae(n.selection, (s) => s.empty ? t.moveVertically(s, e, r.height) : Pe(s, e)); if (o.eq(n.selection)) return !1; let i; if (r.selfScroll) { let s = t.coordsAtPos(n.selection.main.head), l = t.scrollDOM.getBoundingClientRect(), a = l.top + r.marginTop, c = l.bottom - r.marginBottom; s && s.top > a && s.bottom < c && (i = p.scrollIntoView(o.main.head, { y: "start", yMargin: s.top - a })); } return t.dispatch(P(n, o), { effects: i }), !0; } const gt = (t) => ln(t, !1), Xe = (t) => ln(t, !0); function H(t, e, r) { let n = t.lineBlockAt(e.head), o = t.moveToLineBoundary(e, r); if (o.head == e.head && o.head != (r ? n.to : n.from) && (o = t.moveToLineBoundary(e, r, !1)), !r && o.head == n.from && n.length) { let i = /^\s*/.exec(t.state.sliceDoc(n.from, Math.min(n.from + 100, n.to)))[0].length; i && e.head != n.from + i && (o = d.cursor(n.from + i)); } return o; } const eo = (t) => R(t, (e) => H(t, e, !0)), to = (t) => R(t, (e) => H(t, e, !1)), no = (t) => R(t, (e) => H(t, e, !S(t))), ro = (t) => R(t, (e) => H(t, e, S(t))), oo = (t) => R(t, (e) => d.cursor(t.lineBlockAt(e.head).from, 1)), io = (t) => R(t, (e) => d.cursor(t.lineBlockAt(e.head).to, -1)); function so(t, e, r) { let n = !1, o = ae(t.selection, (i) => { let s = re(t, i.head, -1) || re(t, i.head, 1) || i.head > 0 && re(t, i.head - 1, 1) || i.head < t.doc.length && re(t, i.head + 1, -1); if (!s || !s.end) return i; n = !0; let l = s.start.from == i.head ? s.end.to : s.end.from; return d.cursor(l); }); return n ? (e(P(t, o)), !0) : !1; } const lo = ({ state: t, dispatch: e }) => so(t, e); function E(t, e) { let r = ae(t.state.selection, (n) => { let o = e(n); return d.range(n.anchor, o.head, o.goalColumn, o.bidiLevel || void 0); }); return r.eq(t.state.selection) ? !1 : (t.dispatch(P(t.state, r)), !0); } function an(t, e) { return E(t, (r) => t.moveByChar(r, e)); } const cn = (t) => an(t, !S(t)), un = (t) => an(t, S(t)); function hn(t, e) { return E(t, (r) => t.moveByGroup(r, e)); } const ao = (t) => hn(t, !S(t)), co = (t) => hn(t, S(t)), uo = (t) => E(t, (e) => We(t.state, e, !S(t))), ho = (t) => E(t, (e) => We(t.state, e, S(t))); function fn(t, e) { return E(t, (r) => t.moveVertically(r, e)); } const dn = (t) => fn(t, !1), mn = (t) => fn(t, !0); function gn(t, e) { return E(t, (r) => t.moveVertically(r, e, sn(t).height)); } const pt = (t) => gn(t, !1), yt = (t) => gn(t, !0), fo = (t) => E(t, (e) => H(t, e, !0)), mo = (t) => E(t, (e) => H(t, e, !1)), go = (t) => E(t, (e) => H(t, e, !S(t))), po = (t) => E(t, (e) => H(t, e, S(t))), yo = (t) => E(t, (e) => d.cursor(t.lineBlockAt(e.head).from)), xo = (t) => E(t, (e) => d.cursor(t.lineBlockAt(e.head).to)), xt = ({ state: t, dispatch: e }) => (e(P(t, { anchor: 0 })), !0), kt = ({ state: t, dispatch: e }) => (e(P(t, { anchor: t.doc.length })), !0), bt = ({ state: t, dispatch: e }) => (e(P(t, { anchor: t.selection.main.anchor, head: 0 })), !0), St = ({ state: t, dispatch: e }) => (e(P(t, { anchor: t.selection.main.anchor, head: t.doc.length })), !0), ko = ({ state: t, dispatch: e }) => (e(t.update({ selection: { anchor: 0, head: t.doc.length }, userEvent: "select" })), !0), bo = ({ state: t, dispatch: e }) => { let r = Ne(t).map(({ from: n, to: o }) => d.range(n, Math.min(o + 1, t.doc.length))); return e(t.update({ selection: d.create(r), userEvent: "select" })), !0; }, So = ({ state: t, dispatch: e }) => { let r = ae(t.selection, (n) => { var o; let i = ot(t).resolveInner(n.head, 1); for (; !(i.from < n.from && i.to >= n.to || i.to > n.to && i.from <= n.from || !(!((o = i.parent) === null || o === void 0) && o.parent)); ) i = i.parent; return d.range(i.to, i.from); }); return e(P(t, r)), !0; }, Co = ({ state: t, dispatch: e }) => { let r = t.selection, n = null; return r.ranges.length > 1 ? n = d.create([r.main]) : r.main.empty || (n = d.create([d.cursor(r.main.head)])), n ? (e(P(t, n)), !0) : !1; }; function Fe(t, e) { if (t.state.readOnly) return !1; let r = "delete.selection", { state: n } = t, o = n.changeByRange((i) => { let { from: s, to: l } = i; if (s == l) { let a = e(s); a < s ? (r = "delete.backward", a = ke(t, a, !1)) : a > s && (r = "delete.forward", a = ke(t, a, !0)), s = Math.min(s, a), l = Math.max(l, a); } else s = ke(t, s, !1), l = ke(t, l, !0); return s == l ? { range: i } : { changes: { from: s, to: l }, range: d.cursor(s) }; }); return o.changes.empty ? !1 : (t.dispatch(n.update(o, { scrollIntoView: !0, userEvent: r, effects: r == "delete.selection" ? p.announce.of(n.phrase("Selection deleted")) : void 0 })), !0); } function ke(t, e, r) { if (t instanceof p) for (let n of t.state.facet(p.atomicRanges).map((o) => o(t))) n.between(e, e, (o, i) => { o < e && i > e && (e = r ? i : o); }); return e; } const pn = (t, e) => Fe(t, (r) => { let { state: n } = t, o = n.doc.lineAt(r), i, s; if (!e && r > o.from && r < o.from + 200 && !/[^ \t]/.test(i = o.text.slice(0, r - o.from))) { if (i[i.length - 1] == " ") return r - 1; let l = Ht(i, n.tabSize), a = l % Qe(n) || Qe(n); for (let c = 0; c < a && i[i.length - 1 - c] == " "; c++) r--; s = r; } else s = ie(o.text, r - o.from, e, e) + o.from, s == r && o.number != (e ? n.doc.lines : 1) && (s += e ? 1 : -1); return s; }), et = (t) => pn(t, !1), yn = (t) => pn(t, !0), xn = (t, e) => Fe(t, (r) => { let n = r, { state: o } = t, i = o.doc.lineAt(n), s = o.charCategorizer(n); for (let l = null; ; ) { if (n == (e ? i.to : i.from)) { n == r && i.number != (e ? o.doc.lines : 1) && (n += e ? 1 : -1); break; } let a = ie(i.text, n - i.from, e) + i.from, c = i.text.slice(Math.min(n, a) - i.from, Math.max(n, a) - i.from), u = s(c); if (l != null && u != l) break; (c != " " || n != r) && (l = u), n = a; } return n; }), kn = (t) => xn(t, !1), vo = (t) => xn(t, !0), bn = (t) => Fe(t, (e) => { let r = t.lineBlockAt(e).to; return e < r ? r : Math.min(t.state.doc.length, e + 1); }), Ao = (t) => Fe(t, (e) => { let r = t.lineBlockAt(e).from; return e > r ? r : Math.max(0, e - 1); }), Mo = ({ state: t, dispatch: e }) => { if (t.readOnly) return !1; let r = t.changeByRange((n) => ({ changes: { from: n.from, to: n.to, insert: qt.of(["", ""]) }, range: d.cursor(n.from) })); return e(t.update(r, { scrollIntoView: !0, userEvent: "input" })), !0; }, Lo = ({ state: t, dispatch: e }) => { if (t.readOnly) return !1; let r = t.changeByRange((n) => { if (!n.empty || n.from == 0 || n.from == t.doc.length) return { range: n }; let o = n.from, i = t.doc.lineAt(o), s = o == i.from ? o - 1 : ie(i.text, o - i.from, !1) + i.from, l = o == i.to ? o + 1 : ie(i.text, o - i.from, !0) + i.from; return { changes: { from: s, to: l, insert: t.doc.slice(o, l).append(t.doc.slice(s, o)) }, range: d.cursor(l) }; }); return r.changes.empty ? !1 : (e(t.update(r, { scrollIntoView: !0, userEvent: "move.character" })), !0); }; function Ne(t) { let e = [], r = -1; for (let n of t.selection.ranges) { let o = t.doc.lineAt(n.from), i = t.doc.lineAt(n.to); if (!n.empty && n.to == i.from && (i = t.doc.lineAt(n.to - 1)), r >= o.number) { let s = e[e.length - 1]; s.to = i.to, s.ranges.push(n); } else e.push({ from: o.from, to: i.to, ranges: [n] }); r = i.number + 1; } return e; } function Sn(t, e, r) { if (t.readOnly) return !1; let n = [], o = []; for (let i of Ne(t)) { if (r ? i.to == t.doc.length : i.from == 0) continue; let s = t.doc.lineAt(r ? i.to + 1 : i.from - 1), l = s.length + 1; if (r) { n.push({ from: i.to, to: s.to }, { from: i.from, insert: s.text + t.lineBreak }); for (let a of i.ranges) o.push(d.range(Math.min(t.doc.length, a.anchor + l), Math.min(t.doc.length, a.head + l))); } else { n.push({ from: s.from, to: i.from }, { from: i.to, insert: t.lineBreak + s.text }); for (let a of i.ranges) o.push(d.range(a.anchor - l, a.head - l)); } } return n.length ? (e(t.update({ changes: n, scrollIntoView: !0, selection: d.create(o, t.selection.mainIndex), userEvent: "move.line" })), !0) : !1; } const Do = ({ state: t, dispatch: e }) => Sn(t, e, !1), Bo = ({ state: t, dispatch: e }) => Sn(t, e, !0); function Cn(t, e, r) { if (t.readOnly) return !1; let n = []; for (let o of Ne(t)) r ? n.push({ from: o.from, insert: t.doc.slice(o.from, o.to) + t.lineBreak }) : n.push({ from: o.to, insert: t.lineBreak + t.doc.slice(o.from, o.to) }); return e(t.update({ changes: n, scrollIntoView: !0, userEvent: "input.copyline" })), !0; } const Eo = ({ state: t, dispatch: e }) => Cn(t, e, !1), wo = ({ state: t, dispatch: e }) => Cn(t, e, !0), To = (t) => { if (t.state.readOnly) return !1; let { state: e } = t, r = e.changes(Ne(e).map(({ from: o, to: i }) => (o > 0 ? o-- : i < e.doc.length && i++, { from: o, to: i }))), n = ae(e.selection, (o) => t.moveVertically(o, !0)).map(r); return t.dispatch({ changes: r, selection: n, scrollIntoView: !0, userEvent: "delete.line" }), !0; }; function Ro(t, e) { if (/\(\)|\[\]|\{\}/.test(t.sliceDoc(e - 1, e + 1))) return { from: e, to: e }; let r = ot(t).resolveInner(e), n = r.childBefore(e), o = r.childAfter(e), i; return n && o && n.to <= e && o.from >= e && (i = n.type.prop(je.closedBy)) && i.indexOf(o.name) > -1 && t.doc.lineAt(n.to).from == t.doc.lineAt(o.from).from ? { from: n.to, to: o.from } : null; } const Io = /* @__PURE__ */ vn(!1), Oo = /* @__PURE__ */ vn(!0); function vn(t) { return ({ state: e, dispatch: r }) => { if (e.readOnly) return !1; let n = e.changeByRange((o) => { let { from: i, to: s } = o, l = e.doc.lineAt(i), a = !t && i == s && Ro(e, i); t && (i = s = (s <= l.to ? l : e.doc.lineAt(s)).to); let c = new Nt(e, { simulateBreak: i, simulateDoubleBreak: !!a }), u = _t(c, i); for (u == null && (u = /^\s*/.exec(e.doc.lineAt(i).text)[0].length); s < l.to && /\s/.test(l.text[s - l.from]); ) s++; a ? { from: i, to: s } = a : i > l.from && i < l.from + 100 && !/\S/.test(l.text.slice(0, i)) && (i = l.from); let h = ["", Ae(e, u)]; return a && h.push(Ae(e, c.lineIndent(l.from, -1))), { changes: { from: i, to: s, insert: qt.of(h) }, range: d.cursor(i + 1 + h[1].length) }; }); return r(e.update(n, { scrollIntoView: !0, userEvent: "input" })), !0; }; } function ct(t, e) { let r = -1; return t.changeByRange((n) => { let o = []; for (let s = n.from; s <= n.to; ) { let l = t.doc.lineAt(s); l.number > r && (n.empty || n.to > l.from) && (e(l, o, n), r = l.number), s = l.to + 1; } let i = t.changes(o); return { changes: o, range: d.range(i.mapPos(n.anchor, 1), i.mapPos(n.head, 1)) }; }); } const Po = ({ state: t, dispatch: e }) => { if (t.readOnly) return !1; let r = /* @__PURE__ */ Object.create(null), n = new Nt(t, { overrideIndentation: (i) => { let s = r[i]; return s ?? -1; } }), o = ct(t, (i, s, l) => { let a = _t(n, i.from); if (a == null) return; /\S/.test(i.text) || (a = 0); let c = /^\s*/.exec(i.text)[0], u = Ae(t, a); (c != u || l.from < i.from + c.length) && (r[i.from] = a, s.push({ from: i.from, to: i.from + c.length, insert: u })); }); return o.changes.empty || e(t.update(o, { userEvent: "indent" })), !0; }, An = ({ state: t, dispatch: e }) => t.readOnly ? !1 : (e(t.update(ct(t, (r, n) => { n.push({ from: r.from, insert: t.facet(Vt) }); }), { userEvent: "input.indent" })), !0), Mn = ({ state: t, dispatch: e }) => t.readOnly ? !1 : (e(t.update(ct(t, (r, n) => { let o = /^\s*/.exec(r.text)[0]; if (!o) return; let i = Ht(o, t.tabSize), s = 0, l = Ae(t, Math.max(0, i - Qe(t))); for (; s < o.length && s < l.length && o.charCodeAt(s) == l.charCodeAt(s); ) s++; n.push({ from: r.from + s, to: r.from + o.length, insert: l.slice(s) }); }), { userEvent: "delete.dedent" })), !0), Wo = [ { key: "Ctrl-b", run: Xt, shift: cn, preventDefault: !0 }, { key: "Ctrl-f", run: en, shift: un }, { key: "Ctrl-p", run: rn, shift: dn }, { key: "Ctrl-n", run: on, shift: mn }, { key: "Ctrl-a", run: oo, shift: yo }, { key: "Ctrl-e", run: io, shift: xo }, { key: "Ctrl-d", run: yn }, { key: "Ctrl-h", run: et }, { key: "Ctrl-k", run: bn }, { key: "Ctrl-Alt-h", run: kn }, { key: "Ctrl-o", run: Mo }, { key: "Ctrl-t", run: Lo }, { key: "Ctrl-v", run: Xe } ], Fo = /* @__PURE__ */ [ { key: "ArrowLeft", run: Xt, shift: cn, preventDefault: !0 }, { key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: jr, shift: ao, preventDefault: !0 }, { mac: "Cmd-ArrowLeft", run: no, shift: go, preventDefault: !0 }, { key: "ArrowRight", run: en, shift: un, preventDefault: !0 }, { key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: Qr, shift: co, preventDefault: !0 }, { mac: "Cmd-ArrowRight", run: ro, shift: po, preventDefault: !0 }, { key: "ArrowUp", run: rn, shift: dn, preventDefault: !0 }, { mac: "Cmd-ArrowUp", run: xt, shift: bt }, { mac: "Ctrl-ArrowUp", run: gt, shift: pt }, { key: "ArrowDown", run: on, shift: mn, preventDefault: !0 }, { mac: "Cmd-ArrowDown", run: kt, shift: St }, { mac: "Ctrl-ArrowDown", run: Xe, shift: yt }, { key: "PageUp", run: gt, shift: pt }, { key: "PageDown", run: Xe, shift: yt }, { key: "Home", run: to, shift: mo, preventDefault: !0 }, { key: "Mod-Home", run: xt, shift: bt }, { key: "End", run: eo, shift: fo, preventDefault: !0 }, { key: "Mod-End", run: kt, shift: St }, { key: "Enter", run: Io }, { key: "Mod-a", run: ko }, { key: "Backspace", run: et, shift: et }, { key: "Delete", run: yn }, { key: "Mod-Backspace", mac: "Alt-Backspace", run: kn }, { key: "Mod-Delete", mac: "Alt-Delete", run: vo }, { mac: "Mod-Backspace", run: Ao }, { mac: "Mod-Delete", run: bn } ].concat(/* @__PURE__ */ Wo.map((t) => ({ mac: t.key, run: t.run, shift: t.shift }))), No = /* @__PURE__ */ [ { key: "Alt-ArrowLeft", mac: "Ctrl-ArrowLeft", run: Zr, shift: uo }, { key: "Alt-ArrowRight", mac: "Ctrl-ArrowRight", run: Xr, shift: ho }, { key: "Alt-ArrowUp", run: Do }, { key: "Shift-Alt-ArrowUp", run: Eo }, { key: "Alt-ArrowDown", run: Bo }, { key: "Shift-Alt-ArrowDown", run: wo }, { key: "Escape", run: Co }, { key: "Mod-Enter", run: Oo }, { key: "Alt-l", mac: "Ctrl-l", run: bo }, { key: "Mod-i", run: So, preventDefault: !0 }, { key: "Mod-[", run: Mn }, { key: "Mod-]", run: An }, { key: "Mod-Alt-\\", run: Po }, { key: "Shift-Mod-k", run: To }, { key: "Shift-Mod-\\", run: lo }, { key: "Mod-/", run: Er }, { key: "Alt-A", run: Tr } ].concat(Fo), _o = { key: "Tab", run: An, shift: Mn }; function g() { var t = arguments[0]; typeof t == "string" && (t = document.createElement(t)); var e = 1, r = arguments[1]; if (r && typeof r == "object" && r.nodeType == null && !Array.isArray(r)) { for (var n in r) if (Object.prototype.hasOwnProperty.call(r, n)) { var o = r[n]; typeof o == "string" ? t.setAttribute(n, o) : o != null && (t[n] = o); } e++; } for (; e < arguments.length; e++) Ln(t, arguments[e]); return t; } function Ln(t, e) { if (typeof e == "string") t.appendChild(document.createTextNode(e)); else if (e != null) if (e.nodeType != null) t.appendChild(e); else if (Array.isArray(e)) for (var r = 0; r < e.length; r++) Ln(t, e[r]); else throw new RangeError("Unsupported child node: " + e); } const Ct = typeof String.prototype.normalize == "function" ? (t) => t.normalize("NFKD") : (t) => t; class se { /** Create a text cursor. The query is the search string, `from` to `to` provides the region to search. When `normalize` is given, it will be called, on both the query string and the content it is matched against, before comparing. You can, for example, create a case-insensitive search by passing `s => s.toLowerCase()`. Text is always normalized with [`.normalize("NFKD")`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize) (when supported). */ constructor(e, r, n = 0, o = e.length, i, s) { this.test = s, this.value = { from: 0, to: 0 }, this.done = !1, this.matches = [], this.buffer = "", this.bufferPos = 0, this.iter = e.iterRange(n, o), this.bufferStart = n, this.normalize = i ? (l) => i(Ct(l)) : Ct, this.query = this.normalize(r); } peek() { if (this.bufferPos == this.buffer.length) { if (this.bufferStart += this.buffer.length, this.iter.next(), this.iter.done) return -1; this.bufferPos = 0, this.buffer = this.iter.value; } return rr(this.buffer, this.bufferPos); } /** Look for the next match. Updates the iterator's [`value`](https://codemirror.net/6/docs/ref/#search.SearchCursor.value) and [`done`](https://codemirror.net/6/docs/ref/#search.SearchCursor.done) properties. Should be called at least once before using the cursor. */ next() { for (; this.matches.length; ) this.matches.pop(); return this.nextOverlapping(); } /** The `next` method will ignore matches that partially overlap a previous match. This method behaves like `next`, but includes such matches. */ nextOverlapping() { for (; ; ) { let e = this.peek(); if (e < 0) return this.done = !0, this; let r = ir(e), n = this.bufferStart + this.bufferPos; this.bufferPos += or(e); let o = this.normalize(r); for (let i = 0, s = n; ; i++) { let l = o.charCodeAt(i), a = this.match(l, s); if (i == o.length - 1) { if (a) return this.value = a, this; break; } s == n && i < r.length && r.charCodeAt(i) == l && s++; } } } match(e, r) { let n = null; for (let o = 0; o < this.matches.length; o += 2) { let i = this.matches[o], s = !1; this.query.charCodeAt(i) == e && (i == this.query.length - 1 ? n = { from: this.matches[o + 1], to: r + 1 } : (this.matches[o]++, s = !0)), s || (this.matches.splice(o, 2), o -= 2); } return this.query.charCodeAt(0) == e && (this.query.length == 1 ? n = { from: r, to: r + 1 } : this.matches.push(1, r)), n && this.test && !this.test(n.from, n.to, this.buffer, this.bufferPos) && (n = null), n; } } typeof Symbol < "u" && (se.prototype[Symbol.iterator] = function() { return this; }); const Dn = { from: -1, to: -1, match: /* @__PURE__ */ /.*/.exec("") }, ut = "gm" + (/x/.unicode == null ? "" : "u"); class Bn { /** Create a cursor that will search the given range in the given document. `query` should be the raw pattern (as you'd pass it to `new RegExp`). */ constructor(e, r, n, o = 0, i = e.length) { if (this.text = e, this.to = i, this.curLine = "", this.done = !1, this.value = Dn, /\\[sWDnr]|\n|\r|\[\^/.test(r)) return new En(e, r, n, o, i); this.re = new RegExp(r, ut + (n != null && n.ignoreCase ? "i" : "")), this.test = n == null ? void 0 : n.test, this.iter = e.iter(); let s = e.lineAt(o); this.curLineStart = s.from, this.matchPos = Le(e, o), this.getLine(this.curLineStart); } getLine(e) { this.iter.next(e), this.iter.lineBreak ? this.curLine = "" : (this.curLine = this.iter.value, this.curLineStart + this.curLine.length > this.to && (this.curLine = this.curLine.slice(0, this.to - this.curLineStart)), this.iter.next()); } nextLine() { this.curLineStart = this.curLineStart + this.curLine.length + 1, this.curLineStart > this.to ? this.curLine = "" : this.getLine(0); } /** Move to the next match, if there is one. */ next() { for (let e = this.matchPos - this.curLineStart; ; ) { this.re.lastIndex = e; let r = this.matchPos <= this.to && this.re.exec(this.curLine); if (r) { let n = this.curLineStart + r.index, o = n + r[0].length; if (this.matchPos = Le(this.text, o + (n == o ? 1 : 0)), n == this.curLineStart + this.curLine.length && this.nextLine(), (n < o || n > this.value.to) && (!this.test || this.test(n, o, r))) return this.value = { from: n, to: o, match: r }, this; e = this.matchPos - this.curLineStart; } else if (this.curLineStart + this.curLine.length < this.to) this.nextLine(), e = 0; else return this.done = !0, this; } } } const $e = /* @__PURE__ */ new WeakMap(); class oe { constructor(e, r) { this.from = e, this.text = r; } get to() { return this.from + this.text.length; } static get(e, r, n) { let o = $e.get(e); if (!o || o.from >= n || o.to <= r) { let l = new oe(r, e.sliceString(r, n)); return $e.set(e, l), l; } if (o.from == r && o.to == n) return o; let { text: i, from: s } = o; return s > r && (i = e.sliceString(r, s) + i, s = r), o.to < n && (i += e.sliceString(o.to, n)), $e.set(e, new oe(s, i)), new oe(r, i.slice(r - s, n - s)); } } class En { constructor(e, r, n, o, i) { this.text = e, this.to = i, this.done = !1, this.value = Dn, this.matchPos = Le(e, o), this.re = new RegExp(r, ut + (n != null && n.ignoreCase ? "i" : "")), this.test = n == null ? void 0 : n.test, this.flat = oe.get(e, o, this.chunkEnd( o + 5e3 /* Base */ )); } chunkEnd(e) { return e >= this.to ? this.to : this.text.lineAt(e).to; } next() { for (; ; ) { let e = this.re.lastIndex = this.matchPos - this.flat.from, r = this.re.exec(this.flat.text); if (r && !r[0] && r.index == e && (this.re.lastIndex = e + 1, r = this.re.exec(this.flat.text)), r) { let n = this.flat.from + r.index, o = n + r[0].length; if ((this.flat.to >= this.to || r.index + r[0].length <= this.flat.text.length - 10) && (!this.test || this.test(n, o, r))) return this.value = { from: n, to: o, match: r }, this.matchPos = Le(this.text, o + (n == o ? 1 : 0)), this; } if (this.flat.to == this.to) return this.done = !0, this; this.flat = oe.get(this.text, this.flat.from, this.chunkEnd(this.flat.from + this.flat.text.length * 2)); } } } typeof Symbol < "u" && (Bn.prototype[Symbol.iterator] = En.prototype[Symbol.iterator] = function() { return this; }); function qo(t) { try { return new RegExp(t, ut), !0; } catch { return !1; } } function Le(t, e) { if (e >= t.length) return e; let r = t.lineAt(e), n; for (; e < r.to && (n = r.text.charCodeAt(e - r.from)) >= 56320 && n < 57344; ) e++; return e; } function tt(t) { let e = g("input", { class: "cm-textfield", name: "line" }), r = g("form", { class: "cm-gotoLine", onkeydown: (o) => { o.keyCode == 27 ? (o.preventDefault(), t.dispatch({ effects: De.of(!1) }), t.focus()) : o.keyCode == 13 && (o.preventDefault(), n()); }, onsubmit: (o) => { o.preventDefault(), n(); } }, g("label", t.state.phrase("Go to line"), ": ", e), " ", g("button", { class: "cm-button", type: "submit" }, t.state.phrase("go"))); function n() { let o = /^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value); if (!o) return; let { state: i } = t, s = i.doc.lineAt(i.selection.main.head), [, l, a, c, u] = o, h = c ? +c.slice(1) : 0, m = a ? +a : s.number; if (a && u) { let w = m / 100; l && (w = w * (l == "-" ? -1 : 1) + s.number / i.doc.lines), m = Math.round(i.doc.lines * w); } else a && l && (m = m * (l == "-" ? -1 : 1) + s.number); let k = i.doc.line(Math.max(1, Math.min(i.doc.lines, m))), C = d.cursor(k.from + Math.max(0, Math.min(h, k.length))); t.dispatch({ effects: [De.of(!1), p.scrollIntoView(C.from, { y: "center" })], selection: C }), t.focus(); } return { dom: r }; } const De = /* @__PURE__ */ T.define(), vt = /* @__PURE__ */ Re.define({ create() { return !0; }, update(t, e) { for (let r of e.effects) r.is(De) && (t = r.value); return t; }, provide: (t) => st.from(t, (e) => e ? tt : null) }), Ho = (t) => { let e = de(t, tt); if (!e) { let r = [De.of(!0)]; t.state.field(vt, !1) == null && r.push(T.appendConfig.of([vt, Vo])), t.dispatch({ effects: r }), e = de(t, tt); } return e && e.dom.querySelector("input").focus(), !0; }, Vo = /* @__PURE__ */ p.baseTheme({ ".cm-panel.cm-gotoLine": { padding: "2px 6px 4px", "& label": { fontSize: "80%" } } }), zo = { highlightWordAroundCursor: !1, minSelectionLength: 1, maxMatches: 100, wholeWords: !1 }, Uo = /* @__PURE__ */ pe.define({ combine(t) { return Ie(t, zo, { highlightWordAroundCursor: (e, r) => e || r, minSelectionLength: Math.min, maxMatches: Math.min }); } }); function $o(t) { return [Qo, jo]; } const Go = /* @__PURE__ */ x.mark({ class: "cm-selectionMatch" }), Ko = /* @__PURE__ */ x.mark({ class: "cm-selectionMatch cm-selectionMatch-main" }); function At(t, e, r, n) { return (r == 0 || t(e.sliceDoc(r - 1, r)) != D.Word) && (n == e.doc.length || t(e.sliceDoc(n, n + 1)) != D.Word); } function Jo(t, e, r, n) { return t(e.sliceDoc(r, r + 1)) == D.Word && t(e.sliceDoc(n - 1, n)) == D.Word; } const jo = /* @__PURE__ */ zt.fromClass(class { constructor(t) { this.decorations = this.getDeco(t); } update(t) { (t.selectionSet || t.docChanged || t.viewportChanged) && (this.decorations = this.getDeco(t.view)); } getDeco(t) { let e = t.state.facet(Uo), { state: r } = t, n = r.selection; if (n.ranges.length > 1) return x.none; let o = n.main, i, s = null; if (o.empty) { if (!e.highlightWordAroundCursor) return x.none; let a = r.wordAt(o.head); if (!a) return x.none; s = r.charCategorizer(o.head), i = r.sliceDoc(a.from, a.to); } else { let a = o.to - o.from; if (a < e.minSelectionLength || a > 200) return x.none; if (e.wholeWords) { if (i = r.sliceDoc(o.from, o.to), s = r.charCategorizer(o.head), !(At(s, r, o.from, o.to) && Jo(s, r, o.from, o.to))) return x.none; } else if (i = r.sliceDoc(o.from, o.to).trim(), !i) return x.none; } let l = []; for (let a of t.visibleRanges) { let c = new se(r.doc, i, a.from, a.to); for (; !c.next().done; ) { let { from: u, to: h } = c.value; if ((!s || At(s, r, u, h)) && (o.empty && u <= o.from && h >= o.to ? l.push(Ko.range(u, h)) : (u >= o.to || h <= o.from) && l.push(Go.range(u, h)), l.length > e.maxMatches)) return x.none; } } return x.set(l); } }, { decorations: (t) => t.decorations }), Qo = /* @__PURE__ */ p.baseTheme({ ".cm-selectionMatch": { backgroundColor: "#99ff7780" }, ".cm-searchMatch .cm-selectionMatch": { backgroundColor: "transparent" } }), Yo = ({ state: t, dispatch: e }) => { let { selection: r } = t, n = d.create(r.ranges.map((o) => t.wordAt(o.head) || d.cursor(o.head)), r.mainIndex); return n.eq(r) ? !1 : (e(t.update({ selection: n })), !0); }; function Zo(t, e) { let { main: r, ranges: n } = t.selection, o = t.wordAt(r.head), i = o && o.from == r.from && o.to == r.to; for (let s = !1, l = new se(t.doc, e, n[n.length - 1].to); ; ) if (l.next(), l.done) { if (s) return null; l = new se(t.doc, e, 0, Math.max(0, n[n.length - 1].from - 1)), s = !0; } else { if (s && n.some((a) => a.from == l.value.from)) continue; if (i) { let a = t.wordAt(l.value.from); if (!a || a.from != l.value.from || a.to != l.value.to) continue; } return l.value; } } const Xo = ({ state: t, dispatch: e }) => { let { ranges: r } = t.selection; if (r.some((i) => i.from === i.to)) return Yo({ state: t, dispatch: e }); let n = t.sliceDoc(r[0].from, r[0].to); if (t.selection.ranges.some((i) => t.sliceDoc(i.from, i.to) != n)) return !1; let o = Zo(t, n); return o ? (e(t.update({ selection: t.selection.addRange(d.range(o.from, o.to), !1), effects: p.scrollIntoView(o.to) })), !0) : !1; }, ce = /* @__PURE__ */ pe.define({ combine(t) { return Ie(t, { top: !1, caseSensitive: !1, literal: !1, regexp: !1, wholeWord: !1, createPanel: (e) => new hi(e), scrollToMatch: (e) => p.scrollIntoView(e) }); } }); class wn { /** Create a query object. */ constructor(e) { this.search = e.search, this.caseSensitive = !!e.caseSensitive, this.literal = !!e.literal, this.regexp = !!e.regexp, this.replace = e.replace || "", this.valid = !!this.search && (!this.regexp || qo(this.search)), this.unquoted = this.unquote(this.search), this.wholeWord = !!e.wholeWord; } /** @internal */ unquote(e) { return this.literal ? e : e.replace(/\\([nrt\\])/g, (r, n) => n == "n" ? ` ` : n == "r" ? "\r" : n == "t" ? " " : "\\"); } /** Compare this query to another query. */ eq(e) { return this.search == e.search && this.replace == e.replace && this.caseSensitive == e.caseSensitive && this.regexp == e.regexp && this.wholeWord == e.wholeWord; } /** @internal */ create() { return this.regexp ? new ri(this) : new ti(this); } /** Get a search cursor for this query, searching through the given range in the given state. */ getCursor(e, r = 0, n) { let o = e.doc ? e : me.create({ doc: e }); return n == null && (n = o.doc.length), this.regexp ? ne(this, o, r, n) : te(this, o, r, n); } } class Tn { constructor(e) { this.spec = e; } } function te(t, e, r, n) { return new se(e.doc, t.unquoted, r, n, t.caseSensitive ? void 0 : (o) => o.toLowerCase(), t.wholeWord ? ei(e.doc, e.charCategorizer(e.selection.main.head)) : void 0); } function ei(t, e) { return (r, n, o, i) => ((i > r || i + o.length < n) && (i = Math.max(0, r - 2), o = t.sliceString(i, Math.min(t.length, n + 2))), (e(Be(o, r - i)) != D.Word || e(Ee(o, r - i)) != D.Word) && (e(Ee(o, n - i)) != D.Word || e(Be(o, n - i)) != D.Word)); } class ti extends Tn { constructor(e) { super(e); } nextMatch(e, r, n) { let o = te(this.spec, e, n, e.doc.length).nextOverlapping(); return o.done && (o = te(this.spec, e, 0, r).nextOverlapping()), o.done ? null : o.value; } // Searching in reverse is, rather than implementing an inverted search // cursor, done by scanning chunk after chunk forward. prevMatchInRange(e, r, n) { for (let o = n; ; ) { let i = Math.max(r, o - 1e4 - this.spec.unquoted.length), s = te(this.spec, e, i, o), l = null; for (; !s.nextOverlapping().done; ) l = s.value; if (l) return l; if (i == r) return null; o -= 1e4; } } prevMatch(e, r, n) { return this.prevMatchInRange(e, 0, r) || this.prevMatchInRange(e, n, e.doc.length); } getReplacement(e) { return this.spec.unquote(this.spec.replace); } matchAll(e, r) { let n = te(this.spec, e, 0, e.doc.length), o = []; for (; !n.next().done; ) { if (o.length >= r) return null; o.push(n.value); } return o; } highlight(e, r, n, o) { let i = te(this.spec, e, Math.max(0, r - this.spec.unquoted.length), Math.min(n + this.spec.unquoted.length, e.doc.length)); for (; !i.next().done; ) o(i.value.from, i.value.to); } } function ne(t, e, r, n) { return new Bn(e.doc, t.search, { ignoreCase: !t.caseSensitive, test: t.wholeWord ? ni(e.charCategorizer(e.selection.main.head)) : void 0 }, r, n); } function Be(t, e) { return t.slice(ie(t, e, !1), e); } function Ee(t, e) { return t.slice(e, ie(t, e)); } function ni(t) { return (e, r, n) => !n[0].length || (t(Be(n.input, n.index)) != D.Word || t(Ee(n.input, n.index)) != D.Word) && (t(Ee(n.input, n.index + n[0].length)) != D.Word || t(Be(n.input, n.index + n[0].length)) != D.Word); } class ri extends Tn { nextMatch(e, r, n) { let o = ne(this.spec, e, n, e.doc.length).next(); return o.done && (o = ne(this.spec, e, 0, r).next()), o.done ? null : o.value; } prevMatchInRange(e, r, n) { for (let o = 1; ; o++) { let i = Math.max( r, n - o * 1e4 /* ChunkSize */ ), s = ne(this.spec, e, i, n), l = null; for (; !s.next().done; ) l = s.value; if (l && (i == r || l.from > i + 10)) return l; if (i == r) return null; } } prevMatch(e, r, n) { return this.prevMatchInRange(e, 0, r) || this.prevMatchInRange(e, n, e.doc.length); } getReplacement(e) { return this.spec.unquote(this.spec.replace.replace(/\$([$&\d+])/g, (r, n) => n == "$" ? "$" : n == "&" ? e.match[0] : n != "0" && +n < e.match.length ? e.match[n] : r)); } matchAll(e, r) { let n = ne(this.spec, e, 0, e.doc.length), o = []; for (; !n.next().done; ) { if (o.length >= r) return null; o.push(n.value); } return o; } highlight(e, r, n, o) { let i = ne(this.spec, e, Math.max( 0, r - 250 /* HighlightMargin */ ), Math.min(n + 250, e.doc.length)); for (; !i.next().done; ) o(i.value.from, i.value.to); } } const ge = /* @__PURE__ */ T.define(), ht = /* @__PURE__ */ T.define(), q = /* @__PURE__ */ Re.define({ create(t) { return new Ge(nt(t).create(), null); }, update(t, e) { for (let r of e.effects) r.is(ge) ? t = new Ge(r.value.create(), t.panel) : r.is(ht) && (t = new Ge(t.query, r.value ? ft : null)); return t; }, provide: (t) => st.from(t, (e) => e.panel) }); class Ge { constructor(e, r) { this.query = e, this.panel = r; } } const oi = /* @__PURE__ */ x.mark({ class: "cm-searchMatch" }), ii = /* @__PURE__ */ x.mark({ class: "cm-searchMatch cm-searchMatch-selected" }), si = /* @__PURE__ */ zt.fromClass(class { constructor(t) { this.view = t, this.decorations = this.highlight(t.state.field(q)); } update(t) { let e = t.state.field(q); (e != t.startState.field(q) || t.docChanged || t.selectionSet || t.viewportChanged) && (this.decorations = this.highlight(e)); } highlight({ query: t, panel: e }) { if (!e || !t.spec.valid) return x.none; let { view: r } = this, n = new sr(); for (let o = 0, i = r.visibleRanges, s = i.length; o < s; o++) { let { from: l, to: a } = i[o]; for (; o < s - 1 && a > i[o + 1].from - 2 * 250; ) a = i[++o].to; t.highlight(r.state, l, a, (c, u) => { let h = r.state.selection.ranges.some((m) => m.from == c && m.to == u); n.add(c, u, h ? ii : oi); }); } return n.finish(); } }, { decorations: (t) => t.decorations }); function ye(t) { return (e) => { let r = e.state.field(q, !1); return r && r.query.spec.valid ? t(e, r) : On(e); }; } const we = /* @__PURE__ */ ye((t, { query: e }) => { let { to: r } = t.state.selection.main, n = e.nextMatch(t.state, r, r); if (!n) return !1; let o = d.single(n.from, n.to), i = t.state.facet(ce); return t.dispatch({ selection: o, effects