cool-admin-vue/build/.vite/deps/vue-codemirror.js
2022-07-29 01:43:56 +08:00

2896 lines
104 KiB
JavaScript

import {
autocompletion,
closeBrackets,
closeBracketsKeymap,
completionKeymap
} from "./chunk-VKPP6QDQ.js";
import {
Annotation,
ChangeDesc,
ChangeSet,
CharCategory,
Compartment,
Decoration,
Direction,
EditorSelection,
EditorState,
EditorView,
Facet,
GutterMarker,
IndentContext,
NodeProp,
Prec,
RangeSet,
RangeSetBuilder,
StateEffect,
StateField,
Text,
Transaction,
ViewPlugin,
WidgetType,
bracketMatching,
codePointAt,
codePointSize,
combineConfig,
countColumn,
crosshairCursor,
defaultHighlightStyle,
drawSelection,
dropCursor,
findClusterBreak,
foldGutter,
foldKeymap,
fromCodePoint,
getIndentUnit,
getIndentation,
getPanel,
gutter,
highlightActiveLine,
highlightActiveLineGutter,
highlightSpecialChars,
hoverTooltip,
indentOnInput,
indentString,
indentUnit,
keymap,
lineNumbers,
logException,
matchBrackets,
placeholder,
rectangularSelection,
runScopeHandlers,
showPanel,
showTooltip,
syntaxHighlighting,
syntaxTree
} from "./chunk-2LSZYZIP.js";
import "./chunk-WA3WP44A.js";
import {
computed2 as computed,
defineComponent,
h,
inject,
onBeforeUnmount,
onMounted,
shallowRef,
toRaw,
watch
} from "./chunk-S3Q6TDYU.js";
import "./chunk-QOVRSCHT.js";
// node_modules/@codemirror/commands/dist/index.js
var toggleComment = (target) => {
let config = getConfig(target.state);
return config.line ? toggleLineComment(target) : config.block ? toggleBlockCommentByLine(target) : false;
};
function command(f, option) {
return ({ state, dispatch }) => {
if (state.readOnly)
return false;
let tr = f(option, state);
if (!tr)
return false;
dispatch(state.update(tr));
return true;
};
}
var toggleLineComment = command(changeLineComment, 0);
var lineComment = command(changeLineComment, 1);
var lineUncomment = command(changeLineComment, 2);
var toggleBlockComment = command(changeBlockComment, 0);
var blockComment = command(changeBlockComment, 1);
var blockUncomment = command(changeBlockComment, 2);
var toggleBlockCommentByLine = command((o, s) => changeBlockComment(o, s, selectedLineRanges(s)), 0);
function getConfig(state, pos = state.selection.main.head) {
let data = state.languageDataAt("commentTokens", pos);
return data.length ? data[0] : {};
}
var SearchMargin = 50;
function findBlockComment(state, { open, close }, from, to) {
let textBefore = state.sliceDoc(from - SearchMargin, from);
let textAfter = state.sliceDoc(to, to + SearchMargin);
let spaceBefore = /\s*$/.exec(textBefore)[0].length, spaceAfter = /^\s*/.exec(textAfter)[0].length;
let beforeOff = textBefore.length - spaceBefore;
if (textBefore.slice(beforeOff - open.length, beforeOff) == open && textAfter.slice(spaceAfter, spaceAfter + close.length) == close) {
return {
open: { pos: from - spaceBefore, margin: spaceBefore && 1 },
close: { pos: to + spaceAfter, margin: spaceAfter && 1 }
};
}
let startText, endText;
if (to - from <= 2 * SearchMargin) {
startText = endText = state.sliceDoc(from, to);
} else {
startText = state.sliceDoc(from, from + SearchMargin);
endText = state.sliceDoc(to - SearchMargin, to);
}
let startSpace = /^\s*/.exec(startText)[0].length, endSpace = /\s*$/.exec(endText)[0].length;
let endOff = endText.length - endSpace - close.length;
if (startText.slice(startSpace, startSpace + open.length) == open && endText.slice(endOff, endOff + close.length) == close) {
return {
open: {
pos: from + startSpace + open.length,
margin: /\s/.test(startText.charAt(startSpace + open.length)) ? 1 : 0
},
close: {
pos: to - endSpace - close.length,
margin: /\s/.test(endText.charAt(endOff - 1)) ? 1 : 0
}
};
}
return null;
}
function selectedLineRanges(state) {
let ranges = [];
for (let r of state.selection.ranges) {
let fromLine = state.doc.lineAt(r.from);
let toLine = r.to <= fromLine.to ? fromLine : state.doc.lineAt(r.to);
let last = ranges.length - 1;
if (last >= 0 && ranges[last].to > fromLine.from)
ranges[last].to = toLine.to;
else
ranges.push({ from: fromLine.from, to: toLine.to });
}
return ranges;
}
function changeBlockComment(option, state, ranges = state.selection.ranges) {
let tokens = ranges.map((r) => getConfig(state, r.from).block);
if (!tokens.every((c) => c))
return null;
let comments = ranges.map((r, i) => findBlockComment(state, tokens[i], r.from, r.to));
if (option != 2 && !comments.every((c) => c)) {
return { changes: state.changes(ranges.map((range, i) => {
if (comments[i])
return [];
return [{ from: range.from, insert: tokens[i].open + " " }, { from: range.to, insert: " " + tokens[i].close }];
})) };
} else if (option != 1 && comments.some((c) => c)) {
let changes = [];
for (let i = 0, comment; i < comments.length; i++)
if (comment = comments[i]) {
let token = tokens[i], { open, close } = comment;
changes.push({ from: open.pos - token.open.length, to: open.pos + open.margin }, { from: close.pos - close.margin, to: close.pos + token.close.length });
}
return { changes };
}
return null;
}
function changeLineComment(option, state, ranges = state.selection.ranges) {
let lines = [];
let prevLine = -1;
for (let { from, to } of ranges) {
let startI = lines.length, minIndent = 1e9;
for (let pos = from; pos <= to; ) {
let line = state.doc.lineAt(pos);
if (line.from > prevLine && (from == to || to > line.from)) {
prevLine = line.from;
let token = getConfig(state, pos).line;
if (!token)
continue;
let indent = /^\s*/.exec(line.text)[0].length;
let empty2 = indent == line.length;
let comment = line.text.slice(indent, indent + token.length) == token ? indent : -1;
if (indent < line.text.length && indent < minIndent)
minIndent = indent;
lines.push({ line, comment, token, indent, empty: empty2, single: false });
}
pos = line.to + 1;
}
if (minIndent < 1e9) {
for (let i = startI; i < lines.length; i++)
if (lines[i].indent < lines[i].line.text.length)
lines[i].indent = minIndent;
}
if (lines.length == startI + 1)
lines[startI].single = true;
}
if (option != 2 && lines.some((l) => l.comment < 0 && (!l.empty || l.single))) {
let changes = [];
for (let { line, token, indent, empty: empty2, single } of lines)
if (single || !empty2)
changes.push({ from: line.from + indent, insert: token + " " });
let changeSet = state.changes(changes);
return { changes: changeSet, selection: state.selection.map(changeSet, 1) };
} else if (option != 1 && lines.some((l) => l.comment >= 0)) {
let changes = [];
for (let { line, comment, token } of lines)
if (comment >= 0) {
let from = line.from + comment, to = from + token.length;
if (line.text[to - line.from] == " ")
to++;
changes.push({ from, to });
}
return { changes };
}
return null;
}
var fromHistory = Annotation.define();
var isolateHistory = Annotation.define();
var invertedEffects = Facet.define();
var historyConfig = Facet.define({
combine(configs) {
return combineConfig(configs, {
minDepth: 100,
newGroupDelay: 500
}, { minDepth: Math.max, newGroupDelay: Math.min });
}
});
function changeEnd(changes) {
let end = 0;
changes.iterChangedRanges((_, to) => end = to);
return end;
}
var historyField_ = StateField.define({
create() {
return HistoryState.empty;
},
update(state, tr) {
let config = tr.state.facet(historyConfig);
let fromHist = tr.annotation(fromHistory);
if (fromHist) {
let selection = tr.docChanged ? EditorSelection.single(changeEnd(tr.changes)) : void 0;
let item = HistEvent.fromTransaction(tr, selection), from = fromHist.side;
let other = from == 0 ? state.undone : state.done;
if (item)
other = updateBranch(other, other.length, config.minDepth, item);
else
other = addSelection(other, tr.startState.selection);
return new HistoryState(from == 0 ? fromHist.rest : other, from == 0 ? other : fromHist.rest);
}
let isolate = tr.annotation(isolateHistory);
if (isolate == "full" || isolate == "before")
state = state.isolate();
if (tr.annotation(Transaction.addToHistory) === false)
return !tr.changes.empty ? state.addMapping(tr.changes.desc) : state;
let event = HistEvent.fromTransaction(tr);
let time = tr.annotation(Transaction.time), userEvent = tr.annotation(Transaction.userEvent);
if (event)
state = state.addChanges(event, time, userEvent, config.newGroupDelay, config.minDepth);
else if (tr.selection)
state = state.addSelection(tr.startState.selection, time, userEvent, config.newGroupDelay);
if (isolate == "full" || isolate == "after")
state = state.isolate();
return state;
},
toJSON(value) {
return { done: value.done.map((e) => e.toJSON()), undone: value.undone.map((e) => e.toJSON()) };
},
fromJSON(json) {
return new HistoryState(json.done.map(HistEvent.fromJSON), json.undone.map(HistEvent.fromJSON));
}
});
function history(config = {}) {
return [
historyField_,
historyConfig.of(config),
EditorView.domEventHandlers({
beforeinput(e, view) {
let command2 = e.inputType == "historyUndo" ? undo : e.inputType == "historyRedo" ? redo : null;
if (!command2)
return false;
e.preventDefault();
return command2(view);
}
})
];
}
function cmd(side, selection) {
return function({ state, dispatch }) {
if (!selection && state.readOnly)
return false;
let historyState = state.field(historyField_, false);
if (!historyState)
return false;
let tr = historyState.pop(side, state, selection);
if (!tr)
return false;
dispatch(tr);
return true;
};
}
var undo = cmd(0, false);
var redo = cmd(1, false);
var undoSelection = cmd(0, true);
var redoSelection = cmd(1, true);
function depth(side) {
return function(state) {
let histState = state.field(historyField_, false);
if (!histState)
return 0;
let branch = side == 0 ? histState.done : histState.undone;
return branch.length - (branch.length && !branch[0].changes ? 1 : 0);
};
}
var undoDepth = depth(0);
var redoDepth = depth(1);
var HistEvent = class {
constructor(changes, effects, mapped, startSelection, selectionsAfter) {
this.changes = changes;
this.effects = effects;
this.mapped = mapped;
this.startSelection = startSelection;
this.selectionsAfter = selectionsAfter;
}
setSelAfter(after) {
return new HistEvent(this.changes, this.effects, this.mapped, this.startSelection, after);
}
toJSON() {
var _a, _b, _c;
return {
changes: (_a = this.changes) === null || _a === void 0 ? void 0 : _a.toJSON(),
mapped: (_b = this.mapped) === null || _b === void 0 ? void 0 : _b.toJSON(),
startSelection: (_c = this.startSelection) === null || _c === void 0 ? void 0 : _c.toJSON(),
selectionsAfter: this.selectionsAfter.map((s) => s.toJSON())
};
}
static fromJSON(json) {
return new HistEvent(json.changes && ChangeSet.fromJSON(json.changes), [], json.mapped && ChangeDesc.fromJSON(json.mapped), json.startSelection && EditorSelection.fromJSON(json.startSelection), json.selectionsAfter.map(EditorSelection.fromJSON));
}
static fromTransaction(tr, selection) {
let effects = none;
for (let invert of tr.startState.facet(invertedEffects)) {
let result = invert(tr);
if (result.length)
effects = effects.concat(result);
}
if (!effects.length && tr.changes.empty)
return null;
return new HistEvent(tr.changes.invert(tr.startState.doc), effects, void 0, selection || tr.startState.selection, none);
}
static selection(selections) {
return new HistEvent(void 0, none, void 0, void 0, selections);
}
};
function updateBranch(branch, to, maxLen, newEvent) {
let start = to + 1 > maxLen + 20 ? to - maxLen - 1 : 0;
let newBranch = branch.slice(start, to);
newBranch.push(newEvent);
return newBranch;
}
function isAdjacent(a, b) {
let ranges = [], isAdjacent2 = false;
a.iterChangedRanges((f, t) => ranges.push(f, t));
b.iterChangedRanges((_f, _t, f, t) => {
for (let i = 0; i < ranges.length; ) {
let from = ranges[i++], to = ranges[i++];
if (t >= from && f <= to)
isAdjacent2 = true;
}
});
return isAdjacent2;
}
function eqSelectionShape(a, b) {
return a.ranges.length == b.ranges.length && a.ranges.filter((r, i) => r.empty != b.ranges[i].empty).length === 0;
}
function conc(a, b) {
return !a.length ? b : !b.length ? a : a.concat(b);
}
var none = [];
var MaxSelectionsPerEvent = 200;
function addSelection(branch, selection) {
if (!branch.length) {
return [HistEvent.selection([selection])];
} else {
let lastEvent = branch[branch.length - 1];
let sels = lastEvent.selectionsAfter.slice(Math.max(0, lastEvent.selectionsAfter.length - MaxSelectionsPerEvent));
if (sels.length && sels[sels.length - 1].eq(selection))
return branch;
sels.push(selection);
return updateBranch(branch, branch.length - 1, 1e9, lastEvent.setSelAfter(sels));
}
}
function popSelection(branch) {
let last = branch[branch.length - 1];
let newBranch = branch.slice();
newBranch[branch.length - 1] = last.setSelAfter(last.selectionsAfter.slice(0, last.selectionsAfter.length - 1));
return newBranch;
}
function addMappingToBranch(branch, mapping) {
if (!branch.length)
return branch;
let length = branch.length, selections = none;
while (length) {
let event = mapEvent(branch[length - 1], mapping, selections);
if (event.changes && !event.changes.empty || event.effects.length) {
let result = branch.slice(0, length);
result[length - 1] = event;
return result;
} else {
mapping = event.mapped;
length--;
selections = event.selectionsAfter;
}
}
return selections.length ? [HistEvent.selection(selections)] : none;
}
function mapEvent(event, mapping, extraSelections) {
let selections = conc(event.selectionsAfter.length ? event.selectionsAfter.map((s) => s.map(mapping)) : none, extraSelections);
if (!event.changes)
return HistEvent.selection(selections);
let mappedChanges = event.changes.map(mapping), before = mapping.mapDesc(event.changes, true);
let fullMapping = event.mapped ? event.mapped.composeDesc(before) : before;
return new HistEvent(mappedChanges, StateEffect.mapEffects(event.effects, mapping), fullMapping, event.startSelection.map(before), selections);
}
var joinableUserEvent = /^(input\.type|delete)($|\.)/;
var HistoryState = class {
constructor(done, undone, prevTime = 0, prevUserEvent = void 0) {
this.done = done;
this.undone = undone;
this.prevTime = prevTime;
this.prevUserEvent = prevUserEvent;
}
isolate() {
return this.prevTime ? new HistoryState(this.done, this.undone) : this;
}
addChanges(event, time, userEvent, newGroupDelay, maxLen) {
let done = this.done, lastEvent = done[done.length - 1];
if (lastEvent && lastEvent.changes && !lastEvent.changes.empty && event.changes && (!userEvent || joinableUserEvent.test(userEvent)) && (!lastEvent.selectionsAfter.length && time - this.prevTime < newGroupDelay && isAdjacent(lastEvent.changes, event.changes) || userEvent == "input.type.compose")) {
done = updateBranch(done, done.length - 1, maxLen, new HistEvent(event.changes.compose(lastEvent.changes), conc(event.effects, lastEvent.effects), lastEvent.mapped, lastEvent.startSelection, none));
} else {
done = updateBranch(done, done.length, maxLen, event);
}
return new HistoryState(done, none, time, userEvent);
}
addSelection(selection, time, userEvent, newGroupDelay) {
let last = this.done.length ? this.done[this.done.length - 1].selectionsAfter : none;
if (last.length > 0 && time - this.prevTime < newGroupDelay && userEvent == this.prevUserEvent && userEvent && /^select($|\.)/.test(userEvent) && eqSelectionShape(last[last.length - 1], selection))
return this;
return new HistoryState(addSelection(this.done, selection), this.undone, time, userEvent);
}
addMapping(mapping) {
return new HistoryState(addMappingToBranch(this.done, mapping), addMappingToBranch(this.undone, mapping), this.prevTime, this.prevUserEvent);
}
pop(side, state, selection) {
let branch = side == 0 ? this.done : this.undone;
if (branch.length == 0)
return null;
let event = branch[branch.length - 1];
if (selection && event.selectionsAfter.length) {
return state.update({
selection: event.selectionsAfter[event.selectionsAfter.length - 1],
annotations: fromHistory.of({ side, rest: popSelection(branch) }),
userEvent: side == 0 ? "select.undo" : "select.redo",
scrollIntoView: true
});
} else if (!event.changes) {
return null;
} else {
let rest = branch.length == 1 ? none : branch.slice(0, branch.length - 1);
if (event.mapped)
rest = addMappingToBranch(rest, event.mapped);
return state.update({
changes: event.changes,
selection: event.startSelection,
effects: event.effects,
annotations: fromHistory.of({ side, rest }),
filter: false,
userEvent: side == 0 ? "undo" : "redo",
scrollIntoView: true
});
}
}
};
HistoryState.empty = new HistoryState(none, none);
var historyKeymap = [
{ key: "Mod-z", run: undo, preventDefault: true },
{ key: "Mod-y", mac: "Mod-Shift-z", run: redo, preventDefault: true },
{ linux: "Ctrl-Shift-z", run: redo, preventDefault: true },
{ key: "Mod-u", run: undoSelection, preventDefault: true },
{ key: "Alt-u", mac: "Mod-Shift-u", run: redoSelection, preventDefault: true }
];
function updateSel(sel, by) {
return EditorSelection.create(sel.ranges.map(by), sel.mainIndex);
}
function setSel(state, selection) {
return state.update({ selection, scrollIntoView: true, userEvent: "select" });
}
function moveSel({ state, dispatch }, how) {
let selection = updateSel(state.selection, how);
if (selection.eq(state.selection))
return false;
dispatch(setSel(state, selection));
return true;
}
function rangeEnd(range, forward) {
return EditorSelection.cursor(forward ? range.to : range.from);
}
function cursorByChar(view, forward) {
return moveSel(view, (range) => range.empty ? view.moveByChar(range, forward) : rangeEnd(range, forward));
}
function ltrAtCursor(view) {
return view.textDirectionAt(view.state.selection.main.head) == Direction.LTR;
}
var cursorCharLeft = (view) => cursorByChar(view, !ltrAtCursor(view));
var cursorCharRight = (view) => cursorByChar(view, ltrAtCursor(view));
function cursorByGroup(view, forward) {
return moveSel(view, (range) => range.empty ? view.moveByGroup(range, forward) : rangeEnd(range, forward));
}
var cursorGroupLeft = (view) => cursorByGroup(view, !ltrAtCursor(view));
var cursorGroupRight = (view) => cursorByGroup(view, ltrAtCursor(view));
function interestingNode(state, node, bracketProp) {
if (node.type.prop(bracketProp))
return true;
let len = node.to - node.from;
return len && (len > 2 || /[^\s,.;:]/.test(state.sliceDoc(node.from, node.to))) || node.firstChild;
}
function moveBySyntax(state, start, forward) {
let pos = syntaxTree(state).resolveInner(start.head);
let bracketProp = forward ? NodeProp.closedBy : NodeProp.openedBy;
for (let at = start.head; ; ) {
let next = forward ? pos.childAfter(at) : pos.childBefore(at);
if (!next)
break;
if (interestingNode(state, next, bracketProp))
pos = next;
else
at = forward ? next.to : next.from;
}
let bracket = pos.type.prop(bracketProp), match, newPos;
if (bracket && (match = forward ? matchBrackets(state, pos.from, 1) : matchBrackets(state, pos.to, -1)) && match.matched)
newPos = forward ? match.end.to : match.end.from;
else
newPos = forward ? pos.to : pos.from;
return EditorSelection.cursor(newPos, forward ? -1 : 1);
}
var cursorSyntaxLeft = (view) => moveSel(view, (range) => moveBySyntax(view.state, range, !ltrAtCursor(view)));
var cursorSyntaxRight = (view) => moveSel(view, (range) => moveBySyntax(view.state, range, ltrAtCursor(view)));
function cursorByLine(view, forward) {
return moveSel(view, (range) => {
if (!range.empty)
return rangeEnd(range, forward);
let moved = view.moveVertically(range, forward);
return moved.head != range.head ? moved : view.moveToLineBoundary(range, forward);
});
}
var cursorLineUp = (view) => cursorByLine(view, false);
var cursorLineDown = (view) => cursorByLine(view, true);
function pageHeight(view) {
return Math.max(view.defaultLineHeight, Math.min(view.dom.clientHeight, innerHeight) - 5);
}
function cursorByPage(view, forward) {
let { state } = view, selection = updateSel(state.selection, (range) => {
return range.empty ? view.moveVertically(range, forward, pageHeight(view)) : rangeEnd(range, forward);
});
if (selection.eq(state.selection))
return false;
let startPos = view.coordsAtPos(state.selection.main.head);
let scrollRect = view.scrollDOM.getBoundingClientRect();
let effect;
if (startPos && startPos.top > scrollRect.top && startPos.bottom < scrollRect.bottom && startPos.top - scrollRect.top <= view.scrollDOM.scrollHeight - view.scrollDOM.scrollTop - view.scrollDOM.clientHeight)
effect = EditorView.scrollIntoView(selection.main.head, { y: "start", yMargin: startPos.top - scrollRect.top });
view.dispatch(setSel(state, selection), { effects: effect });
return true;
}
var cursorPageUp = (view) => cursorByPage(view, false);
var cursorPageDown = (view) => cursorByPage(view, true);
function moveByLineBoundary(view, start, forward) {
let line = view.lineBlockAt(start.head), moved = view.moveToLineBoundary(start, forward);
if (moved.head == start.head && moved.head != (forward ? line.to : line.from))
moved = view.moveToLineBoundary(start, forward, false);
if (!forward && moved.head == line.from && line.length) {
let space = /^\s*/.exec(view.state.sliceDoc(line.from, Math.min(line.from + 100, line.to)))[0].length;
if (space && start.head != line.from + space)
moved = EditorSelection.cursor(line.from + space);
}
return moved;
}
var cursorLineBoundaryForward = (view) => moveSel(view, (range) => moveByLineBoundary(view, range, true));
var cursorLineBoundaryBackward = (view) => moveSel(view, (range) => moveByLineBoundary(view, range, false));
var cursorLineStart = (view) => moveSel(view, (range) => EditorSelection.cursor(view.lineBlockAt(range.head).from, 1));
var cursorLineEnd = (view) => moveSel(view, (range) => EditorSelection.cursor(view.lineBlockAt(range.head).to, -1));
function toMatchingBracket(state, dispatch, extend) {
let found = false, selection = updateSel(state.selection, (range) => {
let matching = matchBrackets(state, range.head, -1) || matchBrackets(state, range.head, 1) || range.head > 0 && matchBrackets(state, range.head - 1, 1) || range.head < state.doc.length && matchBrackets(state, range.head + 1, -1);
if (!matching || !matching.end)
return range;
found = true;
let head = matching.start.from == range.head ? matching.end.to : matching.end.from;
return extend ? EditorSelection.range(range.anchor, head) : EditorSelection.cursor(head);
});
if (!found)
return false;
dispatch(setSel(state, selection));
return true;
}
var cursorMatchingBracket = ({ state, dispatch }) => toMatchingBracket(state, dispatch, false);
function extendSel(view, how) {
let selection = updateSel(view.state.selection, (range) => {
let head = how(range);
return EditorSelection.range(range.anchor, head.head, head.goalColumn);
});
if (selection.eq(view.state.selection))
return false;
view.dispatch(setSel(view.state, selection));
return true;
}
function selectByChar(view, forward) {
return extendSel(view, (range) => view.moveByChar(range, forward));
}
var selectCharLeft = (view) => selectByChar(view, !ltrAtCursor(view));
var selectCharRight = (view) => selectByChar(view, ltrAtCursor(view));
function selectByGroup(view, forward) {
return extendSel(view, (range) => view.moveByGroup(range, forward));
}
var selectGroupLeft = (view) => selectByGroup(view, !ltrAtCursor(view));
var selectGroupRight = (view) => selectByGroup(view, ltrAtCursor(view));
var selectSyntaxLeft = (view) => extendSel(view, (range) => moveBySyntax(view.state, range, !ltrAtCursor(view)));
var selectSyntaxRight = (view) => extendSel(view, (range) => moveBySyntax(view.state, range, ltrAtCursor(view)));
function selectByLine(view, forward) {
return extendSel(view, (range) => view.moveVertically(range, forward));
}
var selectLineUp = (view) => selectByLine(view, false);
var selectLineDown = (view) => selectByLine(view, true);
function selectByPage(view, forward) {
return extendSel(view, (range) => view.moveVertically(range, forward, pageHeight(view)));
}
var selectPageUp = (view) => selectByPage(view, false);
var selectPageDown = (view) => selectByPage(view, true);
var selectLineBoundaryForward = (view) => extendSel(view, (range) => moveByLineBoundary(view, range, true));
var selectLineBoundaryBackward = (view) => extendSel(view, (range) => moveByLineBoundary(view, range, false));
var selectLineStart = (view) => extendSel(view, (range) => EditorSelection.cursor(view.lineBlockAt(range.head).from));
var selectLineEnd = (view) => extendSel(view, (range) => EditorSelection.cursor(view.lineBlockAt(range.head).to));
var cursorDocStart = ({ state, dispatch }) => {
dispatch(setSel(state, { anchor: 0 }));
return true;
};
var cursorDocEnd = ({ state, dispatch }) => {
dispatch(setSel(state, { anchor: state.doc.length }));
return true;
};
var selectDocStart = ({ state, dispatch }) => {
dispatch(setSel(state, { anchor: state.selection.main.anchor, head: 0 }));
return true;
};
var selectDocEnd = ({ state, dispatch }) => {
dispatch(setSel(state, { anchor: state.selection.main.anchor, head: state.doc.length }));
return true;
};
var selectAll = ({ state, dispatch }) => {
dispatch(state.update({ selection: { anchor: 0, head: state.doc.length }, userEvent: "select" }));
return true;
};
var selectLine = ({ state, dispatch }) => {
let ranges = selectedLineBlocks(state).map(({ from, to }) => EditorSelection.range(from, Math.min(to + 1, state.doc.length)));
dispatch(state.update({ selection: EditorSelection.create(ranges), userEvent: "select" }));
return true;
};
var selectParentSyntax = ({ state, dispatch }) => {
let selection = updateSel(state.selection, (range) => {
var _a;
let context = syntaxTree(state).resolveInner(range.head, 1);
while (!(context.from < range.from && context.to >= range.to || context.to > range.to && context.from <= range.from || !((_a = context.parent) === null || _a === void 0 ? void 0 : _a.parent)))
context = context.parent;
return EditorSelection.range(context.to, context.from);
});
dispatch(setSel(state, selection));
return true;
};
var simplifySelection = ({ state, dispatch }) => {
let cur = state.selection, selection = null;
if (cur.ranges.length > 1)
selection = EditorSelection.create([cur.main]);
else if (!cur.main.empty)
selection = EditorSelection.create([EditorSelection.cursor(cur.main.head)]);
if (!selection)
return false;
dispatch(setSel(state, selection));
return true;
};
function deleteBy({ state, dispatch }, by) {
if (state.readOnly)
return false;
let event = "delete.selection";
let changes = state.changeByRange((range) => {
let { from, to } = range;
if (from == to) {
let towards = by(from);
if (towards < from)
event = "delete.backward";
else if (towards > from)
event = "delete.forward";
from = Math.min(from, towards);
to = Math.max(to, towards);
}
return from == to ? { range } : { changes: { from, to }, range: EditorSelection.cursor(from) };
});
if (changes.changes.empty)
return false;
dispatch(state.update(changes, {
scrollIntoView: true,
userEvent: event,
effects: event == "delete.selection" ? EditorView.announce.of(state.phrase("Selection deleted")) : void 0
}));
return true;
}
function skipAtomic(target, pos, forward) {
if (target instanceof EditorView)
for (let ranges of target.state.facet(EditorView.atomicRanges).map((f) => f(target)))
ranges.between(pos, pos, (from, to) => {
if (from < pos && to > pos)
pos = forward ? to : from;
});
return pos;
}
var deleteByChar = (target, forward) => deleteBy(target, (pos) => {
let { state } = target, line = state.doc.lineAt(pos), before, targetPos;
if (!forward && pos > line.from && pos < line.from + 200 && !/[^ \t]/.test(before = line.text.slice(0, pos - line.from))) {
if (before[before.length - 1] == " ")
return pos - 1;
let col = countColumn(before, state.tabSize), drop = col % getIndentUnit(state) || getIndentUnit(state);
for (let i = 0; i < drop && before[before.length - 1 - i] == " "; i++)
pos--;
targetPos = pos;
} else {
targetPos = findClusterBreak(line.text, pos - line.from, forward, forward) + line.from;
if (targetPos == pos && line.number != (forward ? state.doc.lines : 1))
targetPos += forward ? 1 : -1;
}
return skipAtomic(target, targetPos, forward);
});
var deleteCharBackward = (view) => deleteByChar(view, false);
var deleteCharForward = (view) => deleteByChar(view, true);
var deleteByGroup = (target, forward) => deleteBy(target, (start) => {
let pos = start, { state } = target, line = state.doc.lineAt(pos);
let categorize = state.charCategorizer(pos);
for (let cat = null; ; ) {
if (pos == (forward ? line.to : line.from)) {
if (pos == start && line.number != (forward ? state.doc.lines : 1))
pos += forward ? 1 : -1;
break;
}
let next = findClusterBreak(line.text, pos - line.from, forward) + line.from;
let nextChar = line.text.slice(Math.min(pos, next) - line.from, Math.max(pos, next) - line.from);
let nextCat = categorize(nextChar);
if (cat != null && nextCat != cat)
break;
if (nextChar != " " || pos != start)
cat = nextCat;
pos = next;
}
return skipAtomic(target, pos, forward);
});
var deleteGroupBackward = (target) => deleteByGroup(target, false);
var deleteGroupForward = (target) => deleteByGroup(target, true);
var deleteToLineEnd = (view) => deleteBy(view, (pos) => {
let lineEnd = view.lineBlockAt(pos).to;
return skipAtomic(view, pos < lineEnd ? lineEnd : Math.min(view.state.doc.length, pos + 1), true);
});
var deleteToLineStart = (view) => deleteBy(view, (pos) => {
let lineStart = view.lineBlockAt(pos).from;
return skipAtomic(view, pos > lineStart ? lineStart : Math.max(0, pos - 1), false);
});
var splitLine = ({ state, dispatch }) => {
if (state.readOnly)
return false;
let changes = state.changeByRange((range) => {
return {
changes: { from: range.from, to: range.to, insert: Text.of(["", ""]) },
range: EditorSelection.cursor(range.from)
};
});
dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" }));
return true;
};
var transposeChars = ({ state, dispatch }) => {
if (state.readOnly)
return false;
let changes = state.changeByRange((range) => {
if (!range.empty || range.from == 0 || range.from == state.doc.length)
return { range };
let pos = range.from, line = state.doc.lineAt(pos);
let from = pos == line.from ? pos - 1 : findClusterBreak(line.text, pos - line.from, false) + line.from;
let to = pos == line.to ? pos + 1 : findClusterBreak(line.text, pos - line.from, true) + line.from;
return {
changes: { from, to, insert: state.doc.slice(pos, to).append(state.doc.slice(from, pos)) },
range: EditorSelection.cursor(to)
};
});
if (changes.changes.empty)
return false;
dispatch(state.update(changes, { scrollIntoView: true, userEvent: "move.character" }));
return true;
};
function selectedLineBlocks(state) {
let blocks = [], upto = -1;
for (let range of state.selection.ranges) {
let startLine = state.doc.lineAt(range.from), endLine = state.doc.lineAt(range.to);
if (!range.empty && range.to == endLine.from)
endLine = state.doc.lineAt(range.to - 1);
if (upto >= startLine.number) {
let prev = blocks[blocks.length - 1];
prev.to = endLine.to;
prev.ranges.push(range);
} else {
blocks.push({ from: startLine.from, to: endLine.to, ranges: [range] });
}
upto = endLine.number + 1;
}
return blocks;
}
function moveLine(state, dispatch, forward) {
if (state.readOnly)
return false;
let changes = [], ranges = [];
for (let block of selectedLineBlocks(state)) {
if (forward ? block.to == state.doc.length : block.from == 0)
continue;
let nextLine = state.doc.lineAt(forward ? block.to + 1 : block.from - 1);
let size = nextLine.length + 1;
if (forward) {
changes.push({ from: block.to, to: nextLine.to }, { from: block.from, insert: nextLine.text + state.lineBreak });
for (let r of block.ranges)
ranges.push(EditorSelection.range(Math.min(state.doc.length, r.anchor + size), Math.min(state.doc.length, r.head + size)));
} else {
changes.push({ from: nextLine.from, to: block.from }, { from: block.to, insert: state.lineBreak + nextLine.text });
for (let r of block.ranges)
ranges.push(EditorSelection.range(r.anchor - size, r.head - size));
}
}
if (!changes.length)
return false;
dispatch(state.update({
changes,
scrollIntoView: true,
selection: EditorSelection.create(ranges, state.selection.mainIndex),
userEvent: "move.line"
}));
return true;
}
var moveLineUp = ({ state, dispatch }) => moveLine(state, dispatch, false);
var moveLineDown = ({ state, dispatch }) => moveLine(state, dispatch, true);
function copyLine(state, dispatch, forward) {
if (state.readOnly)
return false;
let changes = [];
for (let block of selectedLineBlocks(state)) {
if (forward)
changes.push({ from: block.from, insert: state.doc.slice(block.from, block.to) + state.lineBreak });
else
changes.push({ from: block.to, insert: state.lineBreak + state.doc.slice(block.from, block.to) });
}
dispatch(state.update({ changes, scrollIntoView: true, userEvent: "input.copyline" }));
return true;
}
var copyLineUp = ({ state, dispatch }) => copyLine(state, dispatch, false);
var copyLineDown = ({ state, dispatch }) => copyLine(state, dispatch, true);
var deleteLine = (view) => {
if (view.state.readOnly)
return false;
let { state } = view, changes = state.changes(selectedLineBlocks(state).map(({ from, to }) => {
if (from > 0)
from--;
else if (to < state.doc.length)
to++;
return { from, to };
}));
let selection = updateSel(state.selection, (range) => view.moveVertically(range, true)).map(changes);
view.dispatch({ changes, selection, scrollIntoView: true, userEvent: "delete.line" });
return true;
};
function isBetweenBrackets(state, pos) {
if (/\(\)|\[\]|\{\}/.test(state.sliceDoc(pos - 1, pos + 1)))
return { from: pos, to: pos };
let context = syntaxTree(state).resolveInner(pos);
let before = context.childBefore(pos), after = context.childAfter(pos), closedBy;
if (before && after && before.to <= pos && after.from >= pos && (closedBy = before.type.prop(NodeProp.closedBy)) && closedBy.indexOf(after.name) > -1 && state.doc.lineAt(before.to).from == state.doc.lineAt(after.from).from)
return { from: before.to, to: after.from };
return null;
}
var insertNewlineAndIndent = newlineAndIndent(false);
var insertBlankLine = newlineAndIndent(true);
function newlineAndIndent(atEof) {
return ({ state, dispatch }) => {
if (state.readOnly)
return false;
let changes = state.changeByRange((range) => {
let { from, to } = range, line = state.doc.lineAt(from);
let explode = !atEof && from == to && isBetweenBrackets(state, from);
if (atEof)
from = to = (to <= line.to ? line : state.doc.lineAt(to)).to;
let cx = new IndentContext(state, { simulateBreak: from, simulateDoubleBreak: !!explode });
let indent = getIndentation(cx, from);
if (indent == null)
indent = /^\s*/.exec(state.doc.lineAt(from).text)[0].length;
while (to < line.to && /\s/.test(line.text[to - line.from]))
to++;
if (explode)
({ from, to } = explode);
else if (from > line.from && from < line.from + 100 && !/\S/.test(line.text.slice(0, from)))
from = line.from;
let insert = ["", indentString(state, indent)];
if (explode)
insert.push(indentString(state, cx.lineIndent(line.from, -1)));
return {
changes: { from, to, insert: Text.of(insert) },
range: EditorSelection.cursor(from + 1 + insert[1].length)
};
});
dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" }));
return true;
};
}
function changeBySelectedLine(state, f) {
let atLine = -1;
return state.changeByRange((range) => {
let changes = [];
for (let pos = range.from; pos <= range.to; ) {
let line = state.doc.lineAt(pos);
if (line.number > atLine && (range.empty || range.to > line.from)) {
f(line, changes, range);
atLine = line.number;
}
pos = line.to + 1;
}
let changeSet = state.changes(changes);
return {
changes,
range: EditorSelection.range(changeSet.mapPos(range.anchor, 1), changeSet.mapPos(range.head, 1))
};
});
}
var indentSelection = ({ state, dispatch }) => {
if (state.readOnly)
return false;
let updated = /* @__PURE__ */ Object.create(null);
let context = new IndentContext(state, { overrideIndentation: (start) => {
let found = updated[start];
return found == null ? -1 : found;
} });
let changes = changeBySelectedLine(state, (line, changes2, range) => {
let indent = getIndentation(context, line.from);
if (indent == null)
return;
if (!/\S/.test(line.text))
indent = 0;
let cur = /^\s*/.exec(line.text)[0];
let norm = indentString(state, indent);
if (cur != norm || range.from < line.from + cur.length) {
updated[line.from] = indent;
changes2.push({ from: line.from, to: line.from + cur.length, insert: norm });
}
});
if (!changes.changes.empty)
dispatch(state.update(changes, { userEvent: "indent" }));
return true;
};
var indentMore = ({ state, dispatch }) => {
if (state.readOnly)
return false;
dispatch(state.update(changeBySelectedLine(state, (line, changes) => {
changes.push({ from: line.from, insert: state.facet(indentUnit) });
}), { userEvent: "input.indent" }));
return true;
};
var indentLess = ({ state, dispatch }) => {
if (state.readOnly)
return false;
dispatch(state.update(changeBySelectedLine(state, (line, changes) => {
let space = /^\s*/.exec(line.text)[0];
if (!space)
return;
let col = countColumn(space, state.tabSize), keep = 0;
let insert = indentString(state, Math.max(0, col - getIndentUnit(state)));
while (keep < space.length && keep < insert.length && space.charCodeAt(keep) == insert.charCodeAt(keep))
keep++;
changes.push({ from: line.from + keep, to: line.from + space.length, insert: insert.slice(keep) });
}), { userEvent: "delete.dedent" }));
return true;
};
var emacsStyleKeymap = [
{ key: "Ctrl-b", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true },
{ key: "Ctrl-f", run: cursorCharRight, shift: selectCharRight },
{ key: "Ctrl-p", run: cursorLineUp, shift: selectLineUp },
{ key: "Ctrl-n", run: cursorLineDown, shift: selectLineDown },
{ key: "Ctrl-a", run: cursorLineStart, shift: selectLineStart },
{ key: "Ctrl-e", run: cursorLineEnd, shift: selectLineEnd },
{ key: "Ctrl-d", run: deleteCharForward },
{ key: "Ctrl-h", run: deleteCharBackward },
{ key: "Ctrl-k", run: deleteToLineEnd },
{ key: "Ctrl-Alt-h", run: deleteGroupBackward },
{ key: "Ctrl-o", run: splitLine },
{ key: "Ctrl-t", run: transposeChars },
{ key: "Ctrl-v", run: cursorPageDown }
];
var standardKeymap = [
{ key: "ArrowLeft", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true },
{ key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: cursorGroupLeft, shift: selectGroupLeft },
{ mac: "Cmd-ArrowLeft", run: cursorLineBoundaryBackward, shift: selectLineBoundaryBackward },
{ key: "ArrowRight", run: cursorCharRight, shift: selectCharRight, preventDefault: true },
{ key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: cursorGroupRight, shift: selectGroupRight },
{ mac: "Cmd-ArrowRight", run: cursorLineBoundaryForward, shift: selectLineBoundaryForward },
{ key: "ArrowUp", run: cursorLineUp, shift: selectLineUp, preventDefault: true },
{ mac: "Cmd-ArrowUp", run: cursorDocStart, shift: selectDocStart },
{ mac: "Ctrl-ArrowUp", run: cursorPageUp, shift: selectPageUp },
{ key: "ArrowDown", run: cursorLineDown, shift: selectLineDown, preventDefault: true },
{ mac: "Cmd-ArrowDown", run: cursorDocEnd, shift: selectDocEnd },
{ mac: "Ctrl-ArrowDown", run: cursorPageDown, shift: selectPageDown },
{ key: "PageUp", run: cursorPageUp, shift: selectPageUp },
{ key: "PageDown", run: cursorPageDown, shift: selectPageDown },
{ key: "Home", run: cursorLineBoundaryBackward, shift: selectLineBoundaryBackward, preventDefault: true },
{ key: "Mod-Home", run: cursorDocStart, shift: selectDocStart },
{ key: "End", run: cursorLineBoundaryForward, shift: selectLineBoundaryForward, preventDefault: true },
{ key: "Mod-End", run: cursorDocEnd, shift: selectDocEnd },
{ key: "Enter", run: insertNewlineAndIndent },
{ key: "Mod-a", run: selectAll },
{ key: "Backspace", run: deleteCharBackward, shift: deleteCharBackward },
{ key: "Delete", run: deleteCharForward },
{ key: "Mod-Backspace", mac: "Alt-Backspace", run: deleteGroupBackward },
{ key: "Mod-Delete", mac: "Alt-Delete", run: deleteGroupForward },
{ mac: "Mod-Backspace", run: deleteToLineStart },
{ mac: "Mod-Delete", run: deleteToLineEnd }
].concat(emacsStyleKeymap.map((b) => ({ mac: b.key, run: b.run, shift: b.shift })));
var defaultKeymap = [
{ key: "Alt-ArrowLeft", mac: "Ctrl-ArrowLeft", run: cursorSyntaxLeft, shift: selectSyntaxLeft },
{ key: "Alt-ArrowRight", mac: "Ctrl-ArrowRight", run: cursorSyntaxRight, shift: selectSyntaxRight },
{ key: "Alt-ArrowUp", run: moveLineUp },
{ key: "Shift-Alt-ArrowUp", run: copyLineUp },
{ key: "Alt-ArrowDown", run: moveLineDown },
{ key: "Shift-Alt-ArrowDown", run: copyLineDown },
{ key: "Escape", run: simplifySelection },
{ key: "Mod-Enter", run: insertBlankLine },
{ key: "Alt-l", mac: "Ctrl-l", run: selectLine },
{ key: "Mod-i", run: selectParentSyntax, preventDefault: true },
{ key: "Mod-[", run: indentLess },
{ key: "Mod-]", run: indentMore },
{ key: "Mod-Alt-\\", run: indentSelection },
{ key: "Shift-Mod-k", run: deleteLine },
{ key: "Shift-Mod-\\", run: cursorMatchingBracket },
{ key: "Mod-/", run: toggleComment },
{ key: "Alt-A", run: toggleBlockComment }
].concat(standardKeymap);
var indentWithTab = { key: "Tab", run: indentMore, shift: indentLess };
// node_modules/crelt/index.es.js
function crelt() {
var elt = arguments[0];
if (typeof elt == "string")
elt = document.createElement(elt);
var i = 1, next = arguments[1];
if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) {
for (var name in next)
if (Object.prototype.hasOwnProperty.call(next, name)) {
var value = next[name];
if (typeof value == "string")
elt.setAttribute(name, value);
else if (value != null)
elt[name] = value;
}
i++;
}
for (; i < arguments.length; i++)
add(elt, arguments[i]);
return elt;
}
function add(elt, child) {
if (typeof child == "string") {
elt.appendChild(document.createTextNode(child));
} else if (child == null) {
} else if (child.nodeType != null) {
elt.appendChild(child);
} else if (Array.isArray(child)) {
for (var i = 0; i < child.length; i++)
add(elt, child[i]);
} else {
throw new RangeError("Unsupported child node: " + child);
}
}
// node_modules/@codemirror/search/dist/index.js
var basicNormalize = typeof String.prototype.normalize == "function" ? (x2) => x2.normalize("NFKD") : (x2) => x2;
var SearchCursor = class {
constructor(text, query, from = 0, to = text.length, normalize) {
this.value = { from: 0, to: 0 };
this.done = false;
this.matches = [];
this.buffer = "";
this.bufferPos = 0;
this.iter = text.iterRange(from, to);
this.bufferStart = from;
this.normalize = normalize ? (x2) => normalize(basicNormalize(x2)) : basicNormalize;
this.query = this.normalize(query);
}
peek() {
if (this.bufferPos == this.buffer.length) {
this.bufferStart += this.buffer.length;
this.iter.next();
if (this.iter.done)
return -1;
this.bufferPos = 0;
this.buffer = this.iter.value;
}
return codePointAt(this.buffer, this.bufferPos);
}
next() {
while (this.matches.length)
this.matches.pop();
return this.nextOverlapping();
}
nextOverlapping() {
for (; ; ) {
let next = this.peek();
if (next < 0) {
this.done = true;
return this;
}
let str = fromCodePoint(next), start = this.bufferStart + this.bufferPos;
this.bufferPos += codePointSize(next);
let norm = this.normalize(str);
for (let i = 0, pos = start; ; i++) {
let code = norm.charCodeAt(i);
let match = this.match(code, pos);
if (match) {
this.value = match;
return this;
}
if (i == norm.length - 1)
break;
if (pos == start && i < str.length && str.charCodeAt(i) == code)
pos++;
}
}
}
match(code, pos) {
let match = null;
for (let i = 0; i < this.matches.length; i += 2) {
let index = this.matches[i], keep = false;
if (this.query.charCodeAt(index) == code) {
if (index == this.query.length - 1) {
match = { from: this.matches[i + 1], to: pos + 1 };
} else {
this.matches[i]++;
keep = true;
}
}
if (!keep) {
this.matches.splice(i, 2);
i -= 2;
}
}
if (this.query.charCodeAt(0) == code) {
if (this.query.length == 1)
match = { from: pos, to: pos + 1 };
else
this.matches.push(1, pos);
}
return match;
}
};
if (typeof Symbol != "undefined")
SearchCursor.prototype[Symbol.iterator] = function() {
return this;
};
var empty = { from: -1, to: -1, match: /.*/.exec("") };
var baseFlags = "gm" + (/x/.unicode == null ? "" : "u");
var RegExpCursor = class {
constructor(text, query, options, from = 0, to = text.length) {
this.to = to;
this.curLine = "";
this.done = false;
this.value = empty;
if (/\\[sWDnr]|\n|\r|\[\^/.test(query))
return new MultilineRegExpCursor(text, query, options, from, to);
this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : ""));
this.iter = text.iter();
let startLine = text.lineAt(from);
this.curLineStart = startLine.from;
this.matchPos = from;
this.getLine(this.curLineStart);
}
getLine(skip) {
this.iter.next(skip);
if (this.iter.lineBreak) {
this.curLine = "";
} else {
this.curLine = this.iter.value;
if (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;
if (this.curLineStart > this.to)
this.curLine = "";
else
this.getLine(0);
}
next() {
for (let off = this.matchPos - this.curLineStart; ; ) {
this.re.lastIndex = off;
let match = this.matchPos <= this.to && this.re.exec(this.curLine);
if (match) {
let from = this.curLineStart + match.index, to = from + match[0].length;
this.matchPos = to + (from == to ? 1 : 0);
if (from == this.curLine.length)
this.nextLine();
if (from < to || from > this.value.to) {
this.value = { from, to, match };
return this;
}
off = this.matchPos - this.curLineStart;
} else if (this.curLineStart + this.curLine.length < this.to) {
this.nextLine();
off = 0;
} else {
this.done = true;
return this;
}
}
}
};
var flattened = /* @__PURE__ */ new WeakMap();
var FlattenedDoc = class {
constructor(from, text) {
this.from = from;
this.text = text;
}
get to() {
return this.from + this.text.length;
}
static get(doc, from, to) {
let cached = flattened.get(doc);
if (!cached || cached.from >= to || cached.to <= from) {
let flat = new FlattenedDoc(from, doc.sliceString(from, to));
flattened.set(doc, flat);
return flat;
}
if (cached.from == from && cached.to == to)
return cached;
let { text, from: cachedFrom } = cached;
if (cachedFrom > from) {
text = doc.sliceString(from, cachedFrom) + text;
cachedFrom = from;
}
if (cached.to < to)
text += doc.sliceString(cached.to, to);
flattened.set(doc, new FlattenedDoc(cachedFrom, text));
return new FlattenedDoc(from, text.slice(from - cachedFrom, to - cachedFrom));
}
};
var MultilineRegExpCursor = class {
constructor(text, query, options, from, to) {
this.text = text;
this.to = to;
this.done = false;
this.value = empty;
this.matchPos = from;
this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : ""));
this.flat = FlattenedDoc.get(text, from, this.chunkEnd(from + 5e3));
}
chunkEnd(pos) {
return pos >= this.to ? this.to : this.text.lineAt(pos).to;
}
next() {
for (; ; ) {
let off = this.re.lastIndex = this.matchPos - this.flat.from;
let match = this.re.exec(this.flat.text);
if (match && !match[0] && match.index == off) {
this.re.lastIndex = off + 1;
match = this.re.exec(this.flat.text);
}
if (match && this.flat.to < this.to && match.index + match[0].length > this.flat.text.length - 10)
match = null;
if (match) {
let from = this.flat.from + match.index, to = from + match[0].length;
this.value = { from, to, match };
this.matchPos = to + (from == to ? 1 : 0);
return this;
} else {
if (this.flat.to == this.to) {
this.done = true;
return this;
}
this.flat = FlattenedDoc.get(this.text, this.flat.from, this.chunkEnd(this.flat.from + this.flat.text.length * 2));
}
}
}
};
if (typeof Symbol != "undefined") {
RegExpCursor.prototype[Symbol.iterator] = MultilineRegExpCursor.prototype[Symbol.iterator] = function() {
return this;
};
}
function validRegExp(source) {
try {
new RegExp(source, baseFlags);
return true;
} catch (_a) {
return false;
}
}
function createLineDialog(view) {
let input = crelt("input", { class: "cm-textfield", name: "line" });
let dom = crelt("form", {
class: "cm-gotoLine",
onkeydown: (event) => {
if (event.keyCode == 27) {
event.preventDefault();
view.dispatch({ effects: dialogEffect.of(false) });
view.focus();
} else if (event.keyCode == 13) {
event.preventDefault();
go();
}
},
onsubmit: (event) => {
event.preventDefault();
go();
}
}, crelt("label", view.state.phrase("Go to line"), ": ", input), " ", crelt("button", { class: "cm-button", type: "submit" }, view.state.phrase("go")));
function go() {
let match = /^([+-])?(\d+)?(:\d+)?(%)?$/.exec(input.value);
if (!match)
return;
let { state } = view, startLine = state.doc.lineAt(state.selection.main.head);
let [, sign, ln, cl, percent] = match;
let col = cl ? +cl.slice(1) : 0;
let line = ln ? +ln : startLine.number;
if (ln && percent) {
let pc = line / 100;
if (sign)
pc = pc * (sign == "-" ? -1 : 1) + startLine.number / state.doc.lines;
line = Math.round(state.doc.lines * pc);
} else if (ln && sign) {
line = line * (sign == "-" ? -1 : 1) + startLine.number;
}
let docLine = state.doc.line(Math.max(1, Math.min(state.doc.lines, line)));
view.dispatch({
effects: dialogEffect.of(false),
selection: EditorSelection.cursor(docLine.from + Math.max(0, Math.min(col, docLine.length))),
scrollIntoView: true
});
view.focus();
}
return { dom };
}
var dialogEffect = StateEffect.define();
var dialogField = StateField.define({
create() {
return true;
},
update(value, tr) {
for (let e of tr.effects)
if (e.is(dialogEffect))
value = e.value;
return value;
},
provide: (f) => showPanel.from(f, (val) => val ? createLineDialog : null)
});
var gotoLine = (view) => {
let panel = getPanel(view, createLineDialog);
if (!panel) {
let effects = [dialogEffect.of(true)];
if (view.state.field(dialogField, false) == null)
effects.push(StateEffect.appendConfig.of([dialogField, baseTheme$1]));
view.dispatch({ effects });
panel = getPanel(view, createLineDialog);
}
if (panel)
panel.dom.querySelector("input").focus();
return true;
};
var baseTheme$1 = EditorView.baseTheme({
".cm-panel.cm-gotoLine": {
padding: "2px 6px 4px",
"& label": { fontSize: "80%" }
}
});
var defaultHighlightOptions = {
highlightWordAroundCursor: false,
minSelectionLength: 1,
maxMatches: 100,
wholeWords: false
};
var highlightConfig = Facet.define({
combine(options) {
return combineConfig(options, defaultHighlightOptions, {
highlightWordAroundCursor: (a, b) => a || b,
minSelectionLength: Math.min,
maxMatches: Math.min
});
}
});
function highlightSelectionMatches(options) {
let ext = [defaultTheme, matchHighlighter];
if (options)
ext.push(highlightConfig.of(options));
return ext;
}
var matchDeco = Decoration.mark({ class: "cm-selectionMatch" });
var mainMatchDeco = Decoration.mark({ class: "cm-selectionMatch cm-selectionMatch-main" });
function insideWordBoundaries(check, state, from, to) {
return (from == 0 || check(state.sliceDoc(from - 1, from)) != CharCategory.Word) && (to == state.doc.length || check(state.sliceDoc(to, to + 1)) != CharCategory.Word);
}
function insideWord(check, state, from, to) {
return check(state.sliceDoc(from, from + 1)) == CharCategory.Word && check(state.sliceDoc(to - 1, to)) == CharCategory.Word;
}
var matchHighlighter = ViewPlugin.fromClass(class {
constructor(view) {
this.decorations = this.getDeco(view);
}
update(update) {
if (update.selectionSet || update.docChanged || update.viewportChanged)
this.decorations = this.getDeco(update.view);
}
getDeco(view) {
let conf = view.state.facet(highlightConfig);
let { state } = view, sel = state.selection;
if (sel.ranges.length > 1)
return Decoration.none;
let range = sel.main, query, check = null;
if (range.empty) {
if (!conf.highlightWordAroundCursor)
return Decoration.none;
let word = state.wordAt(range.head);
if (!word)
return Decoration.none;
check = state.charCategorizer(range.head);
query = state.sliceDoc(word.from, word.to);
} else {
let len = range.to - range.from;
if (len < conf.minSelectionLength || len > 200)
return Decoration.none;
if (conf.wholeWords) {
query = state.sliceDoc(range.from, range.to);
check = state.charCategorizer(range.head);
if (!(insideWordBoundaries(check, state, range.from, range.to) && insideWord(check, state, range.from, range.to)))
return Decoration.none;
} else {
query = state.sliceDoc(range.from, range.to).trim();
if (!query)
return Decoration.none;
}
}
let deco = [];
for (let part of view.visibleRanges) {
let cursor = new SearchCursor(state.doc, query, part.from, part.to);
while (!cursor.next().done) {
let { from, to } = cursor.value;
if (!check || insideWordBoundaries(check, state, from, to)) {
if (range.empty && from <= range.from && to >= range.to)
deco.push(mainMatchDeco.range(from, to));
else if (from >= range.to || to <= range.from)
deco.push(matchDeco.range(from, to));
if (deco.length > conf.maxMatches)
return Decoration.none;
}
}
}
return Decoration.set(deco);
}
}, {
decorations: (v) => v.decorations
});
var defaultTheme = EditorView.baseTheme({
".cm-selectionMatch": { backgroundColor: "#99ff7780" },
".cm-searchMatch .cm-selectionMatch": { backgroundColor: "transparent" }
});
var selectWord = ({ state, dispatch }) => {
let { selection } = state;
let newSel = EditorSelection.create(selection.ranges.map((range) => state.wordAt(range.head) || EditorSelection.cursor(range.head)), selection.mainIndex);
if (newSel.eq(selection))
return false;
dispatch(state.update({ selection: newSel }));
return true;
};
function findNextOccurrence(state, query) {
let { main, ranges } = state.selection;
let word = state.wordAt(main.head), fullWord = word && word.from == main.from && word.to == main.to;
for (let cycled = false, cursor = new SearchCursor(state.doc, query, ranges[ranges.length - 1].to); ; ) {
cursor.next();
if (cursor.done) {
if (cycled)
return null;
cursor = new SearchCursor(state.doc, query, 0, Math.max(0, ranges[ranges.length - 1].from - 1));
cycled = true;
} else {
if (cycled && ranges.some((r) => r.from == cursor.value.from))
continue;
if (fullWord) {
let word2 = state.wordAt(cursor.value.from);
if (!word2 || word2.from != cursor.value.from || word2.to != cursor.value.to)
continue;
}
return cursor.value;
}
}
}
var selectNextOccurrence = ({ state, dispatch }) => {
let { ranges } = state.selection;
if (ranges.some((sel) => sel.from === sel.to))
return selectWord({ state, dispatch });
let searchedText = state.sliceDoc(ranges[0].from, ranges[0].to);
if (state.selection.ranges.some((r) => state.sliceDoc(r.from, r.to) != searchedText))
return false;
let range = findNextOccurrence(state, searchedText);
if (!range)
return false;
dispatch(state.update({
selection: state.selection.addRange(EditorSelection.range(range.from, range.to), false),
effects: EditorView.scrollIntoView(range.to)
}));
return true;
};
var searchConfigFacet = Facet.define({
combine(configs) {
var _a;
return {
top: configs.reduce((val, conf) => val !== null && val !== void 0 ? val : conf.top, void 0) || false,
caseSensitive: configs.reduce((val, conf) => val !== null && val !== void 0 ? val : conf.caseSensitive, void 0) || false,
createPanel: ((_a = configs.find((c) => c.createPanel)) === null || _a === void 0 ? void 0 : _a.createPanel) || ((view) => new SearchPanel(view))
};
}
});
var SearchQuery = class {
constructor(config) {
this.search = config.search;
this.caseSensitive = !!config.caseSensitive;
this.regexp = !!config.regexp;
this.replace = config.replace || "";
this.valid = !!this.search && (!this.regexp || validRegExp(this.search));
this.unquoted = config.literal ? this.search : this.search.replace(/\\([nrt\\])/g, (_, ch) => ch == "n" ? "\n" : ch == "r" ? "\r" : ch == "t" ? " " : "\\");
}
eq(other) {
return this.search == other.search && this.replace == other.replace && this.caseSensitive == other.caseSensitive && this.regexp == other.regexp;
}
create() {
return this.regexp ? new RegExpQuery(this) : new StringQuery(this);
}
getCursor(doc, from = 0, to = doc.length) {
return this.regexp ? regexpCursor(this, doc, from, to) : stringCursor(this, doc, from, to);
}
};
var QueryType = class {
constructor(spec) {
this.spec = spec;
}
};
function stringCursor(spec, doc, from, to) {
return new SearchCursor(doc, spec.unquoted, from, to, spec.caseSensitive ? void 0 : (x2) => x2.toLowerCase());
}
var StringQuery = class extends QueryType {
constructor(spec) {
super(spec);
}
nextMatch(doc, curFrom, curTo) {
let cursor = stringCursor(this.spec, doc, curTo, doc.length).nextOverlapping();
if (cursor.done)
cursor = stringCursor(this.spec, doc, 0, curFrom).nextOverlapping();
return cursor.done ? null : cursor.value;
}
prevMatchInRange(doc, from, to) {
for (let pos = to; ; ) {
let start = Math.max(from, pos - 1e4 - this.spec.unquoted.length);
let cursor = stringCursor(this.spec, doc, start, pos), range = null;
while (!cursor.nextOverlapping().done)
range = cursor.value;
if (range)
return range;
if (start == from)
return null;
pos -= 1e4;
}
}
prevMatch(doc, curFrom, curTo) {
return this.prevMatchInRange(doc, 0, curFrom) || this.prevMatchInRange(doc, curTo, doc.length);
}
getReplacement(_result) {
return this.spec.replace;
}
matchAll(doc, limit) {
let cursor = stringCursor(this.spec, doc, 0, doc.length), ranges = [];
while (!cursor.next().done) {
if (ranges.length >= limit)
return null;
ranges.push(cursor.value);
}
return ranges;
}
highlight(doc, from, to, add2) {
let cursor = stringCursor(this.spec, doc, Math.max(0, from - this.spec.unquoted.length), Math.min(to + this.spec.unquoted.length, doc.length));
while (!cursor.next().done)
add2(cursor.value.from, cursor.value.to);
}
};
function regexpCursor(spec, doc, from, to) {
return new RegExpCursor(doc, spec.search, spec.caseSensitive ? void 0 : { ignoreCase: true }, from, to);
}
var RegExpQuery = class extends QueryType {
nextMatch(doc, curFrom, curTo) {
let cursor = regexpCursor(this.spec, doc, curTo, doc.length).next();
if (cursor.done)
cursor = regexpCursor(this.spec, doc, 0, curFrom).next();
return cursor.done ? null : cursor.value;
}
prevMatchInRange(doc, from, to) {
for (let size = 1; ; size++) {
let start = Math.max(from, to - size * 1e4);
let cursor = regexpCursor(this.spec, doc, start, to), range = null;
while (!cursor.next().done)
range = cursor.value;
if (range && (start == from || range.from > start + 10))
return range;
if (start == from)
return null;
}
}
prevMatch(doc, curFrom, curTo) {
return this.prevMatchInRange(doc, 0, curFrom) || this.prevMatchInRange(doc, curTo, doc.length);
}
getReplacement(result) {
return this.spec.replace.replace(/\$([$&\d+])/g, (m, i) => i == "$" ? "$" : i == "&" ? result.match[0] : i != "0" && +i < result.match.length ? result.match[i] : m);
}
matchAll(doc, limit) {
let cursor = regexpCursor(this.spec, doc, 0, doc.length), ranges = [];
while (!cursor.next().done) {
if (ranges.length >= limit)
return null;
ranges.push(cursor.value);
}
return ranges;
}
highlight(doc, from, to, add2) {
let cursor = regexpCursor(this.spec, doc, Math.max(0, from - 250), Math.min(to + 250, doc.length));
while (!cursor.next().done)
add2(cursor.value.from, cursor.value.to);
}
};
var setSearchQuery = StateEffect.define();
var togglePanel = StateEffect.define();
var searchState = StateField.define({
create(state) {
return new SearchState(defaultQuery(state).create(), null);
},
update(value, tr) {
for (let effect of tr.effects) {
if (effect.is(setSearchQuery))
value = new SearchState(effect.value.create(), value.panel);
else if (effect.is(togglePanel))
value = new SearchState(value.query, effect.value ? createSearchPanel : null);
}
return value;
},
provide: (f) => showPanel.from(f, (val) => val.panel)
});
var SearchState = class {
constructor(query, panel) {
this.query = query;
this.panel = panel;
}
};
var matchMark = Decoration.mark({ class: "cm-searchMatch" });
var selectedMatchMark = Decoration.mark({ class: "cm-searchMatch cm-searchMatch-selected" });
var searchHighlighter = ViewPlugin.fromClass(class {
constructor(view) {
this.view = view;
this.decorations = this.highlight(view.state.field(searchState));
}
update(update) {
let state = update.state.field(searchState);
if (state != update.startState.field(searchState) || update.docChanged || update.selectionSet || update.viewportChanged)
this.decorations = this.highlight(state);
}
highlight({ query, panel }) {
if (!panel || !query.spec.valid)
return Decoration.none;
let { view } = this;
let builder = new RangeSetBuilder();
for (let i = 0, ranges = view.visibleRanges, l = ranges.length; i < l; i++) {
let { from, to } = ranges[i];
while (i < l - 1 && to > ranges[i + 1].from - 2 * 250)
to = ranges[++i].to;
query.highlight(view.state.doc, from, to, (from2, to2) => {
let selected = view.state.selection.ranges.some((r) => r.from == from2 && r.to == to2);
builder.add(from2, to2, selected ? selectedMatchMark : matchMark);
});
}
return builder.finish();
}
}, {
decorations: (v) => v.decorations
});
function searchCommand(f) {
return (view) => {
let state = view.state.field(searchState, false);
return state && state.query.spec.valid ? f(view, state) : openSearchPanel(view);
};
}
var findNext = searchCommand((view, { query }) => {
let { from, to } = view.state.selection.main;
let next = query.nextMatch(view.state.doc, from, to);
if (!next || next.from == from && next.to == to)
return false;
view.dispatch({
selection: { anchor: next.from, head: next.to },
scrollIntoView: true,
effects: announceMatch(view, next),
userEvent: "select.search"
});
return true;
});
var findPrevious = searchCommand((view, { query }) => {
let { state } = view, { from, to } = state.selection.main;
let range = query.prevMatch(state.doc, from, to);
if (!range)
return false;
view.dispatch({
selection: { anchor: range.from, head: range.to },
scrollIntoView: true,
effects: announceMatch(view, range),
userEvent: "select.search"
});
return true;
});
var selectMatches = searchCommand((view, { query }) => {
let ranges = query.matchAll(view.state.doc, 1e3);
if (!ranges || !ranges.length)
return false;
view.dispatch({
selection: EditorSelection.create(ranges.map((r) => EditorSelection.range(r.from, r.to))),
userEvent: "select.search.matches"
});
return true;
});
var selectSelectionMatches = ({ state, dispatch }) => {
let sel = state.selection;
if (sel.ranges.length > 1 || sel.main.empty)
return false;
let { from, to } = sel.main;
let ranges = [], main = 0;
for (let cur = new SearchCursor(state.doc, state.sliceDoc(from, to)); !cur.next().done; ) {
if (ranges.length > 1e3)
return false;
if (cur.value.from == from)
main = ranges.length;
ranges.push(EditorSelection.range(cur.value.from, cur.value.to));
}
dispatch(state.update({
selection: EditorSelection.create(ranges, main),
userEvent: "select.search.matches"
}));
return true;
};
var replaceNext = searchCommand((view, { query }) => {
let { state } = view, { from, to } = state.selection.main;
if (state.readOnly)
return false;
let next = query.nextMatch(state.doc, from, from);
if (!next)
return false;
let changes = [], selection, replacement;
let announce = [];
if (next.from == from && next.to == to) {
replacement = state.toText(query.getReplacement(next));
changes.push({ from: next.from, to: next.to, insert: replacement });
next = query.nextMatch(state.doc, next.from, next.to);
announce.push(EditorView.announce.of(state.phrase("replaced match on line $", state.doc.lineAt(from).number) + "."));
}
if (next) {
let off = changes.length == 0 || changes[0].from >= next.to ? 0 : next.to - next.from - replacement.length;
selection = { anchor: next.from - off, head: next.to - off };
announce.push(announceMatch(view, next));
}
view.dispatch({
changes,
selection,
scrollIntoView: !!selection,
effects: announce,
userEvent: "input.replace"
});
return true;
});
var replaceAll = searchCommand((view, { query }) => {
if (view.state.readOnly)
return false;
let changes = query.matchAll(view.state.doc, 1e9).map((match) => {
let { from, to } = match;
return { from, to, insert: query.getReplacement(match) };
});
if (!changes.length)
return false;
let announceText = view.state.phrase("replaced $ matches", changes.length) + ".";
view.dispatch({
changes,
effects: EditorView.announce.of(announceText),
userEvent: "input.replace.all"
});
return true;
});
function createSearchPanel(view) {
return view.state.facet(searchConfigFacet).createPanel(view);
}
function defaultQuery(state, fallback) {
var _a;
let sel = state.selection.main;
let selText = sel.empty || sel.to > sel.from + 100 ? "" : state.sliceDoc(sel.from, sel.to);
let caseSensitive = (_a = fallback === null || fallback === void 0 ? void 0 : fallback.caseSensitive) !== null && _a !== void 0 ? _a : state.facet(searchConfigFacet).caseSensitive;
return fallback && !selText ? fallback : new SearchQuery({ search: selText.replace(/\n/g, "\\n"), caseSensitive });
}
var openSearchPanel = (view) => {
let state = view.state.field(searchState, false);
if (state && state.panel) {
let panel = getPanel(view, createSearchPanel);
if (!panel)
return false;
let searchInput = panel.dom.querySelector("[main-field]");
if (searchInput && searchInput != view.root.activeElement) {
let query = defaultQuery(view.state, state.query.spec);
if (query.valid)
view.dispatch({ effects: setSearchQuery.of(query) });
searchInput.focus();
searchInput.select();
}
} else {
view.dispatch({ effects: [
togglePanel.of(true),
state ? setSearchQuery.of(defaultQuery(view.state, state.query.spec)) : StateEffect.appendConfig.of(searchExtensions)
] });
}
return true;
};
var closeSearchPanel = (view) => {
let state = view.state.field(searchState, false);
if (!state || !state.panel)
return false;
let panel = getPanel(view, createSearchPanel);
if (panel && panel.dom.contains(view.root.activeElement))
view.focus();
view.dispatch({ effects: togglePanel.of(false) });
return true;
};
var searchKeymap = [
{ key: "Mod-f", run: openSearchPanel, scope: "editor search-panel" },
{ key: "F3", run: findNext, shift: findPrevious, scope: "editor search-panel", preventDefault: true },
{ key: "Mod-g", run: findNext, shift: findPrevious, scope: "editor search-panel", preventDefault: true },
{ key: "Escape", run: closeSearchPanel, scope: "editor search-panel" },
{ key: "Mod-Shift-l", run: selectSelectionMatches },
{ key: "Alt-g", run: gotoLine },
{ key: "Mod-d", run: selectNextOccurrence, preventDefault: true }
];
var SearchPanel = class {
constructor(view) {
this.view = view;
let query = this.query = view.state.field(searchState).query.spec;
this.commit = this.commit.bind(this);
this.searchField = crelt("input", {
value: query.search,
placeholder: phrase(view, "Find"),
"aria-label": phrase(view, "Find"),
class: "cm-textfield",
name: "search",
"main-field": "true",
onchange: this.commit,
onkeyup: this.commit
});
this.replaceField = crelt("input", {
value: query.replace,
placeholder: phrase(view, "Replace"),
"aria-label": phrase(view, "Replace"),
class: "cm-textfield",
name: "replace",
onchange: this.commit,
onkeyup: this.commit
});
this.caseField = crelt("input", {
type: "checkbox",
name: "case",
checked: query.caseSensitive,
onchange: this.commit
});
this.reField = crelt("input", {
type: "checkbox",
name: "re",
checked: query.regexp,
onchange: this.commit
});
function button(name, onclick, content) {
return crelt("button", { class: "cm-button", name, onclick, type: "button" }, content);
}
this.dom = crelt("div", { onkeydown: (e) => this.keydown(e), class: "cm-search" }, [
this.searchField,
button("next", () => findNext(view), [phrase(view, "next")]),
button("prev", () => findPrevious(view), [phrase(view, "previous")]),
button("select", () => selectMatches(view), [phrase(view, "all")]),
crelt("label", null, [this.caseField, phrase(view, "match case")]),
crelt("label", null, [this.reField, phrase(view, "regexp")]),
...view.state.readOnly ? [] : [
crelt("br"),
this.replaceField,
button("replace", () => replaceNext(view), [phrase(view, "replace")]),
button("replaceAll", () => replaceAll(view), [phrase(view, "replace all")]),
crelt("button", {
name: "close",
onclick: () => closeSearchPanel(view),
"aria-label": phrase(view, "close"),
type: "button"
}, ["\xD7"])
]
]);
}
commit() {
let query = new SearchQuery({
search: this.searchField.value,
caseSensitive: this.caseField.checked,
regexp: this.reField.checked,
replace: this.replaceField.value
});
if (!query.eq(this.query)) {
this.query = query;
this.view.dispatch({ effects: setSearchQuery.of(query) });
}
}
keydown(e) {
if (runScopeHandlers(this.view, e, "search-panel")) {
e.preventDefault();
} else if (e.keyCode == 13 && e.target == this.searchField) {
e.preventDefault();
(e.shiftKey ? findPrevious : findNext)(this.view);
} else if (e.keyCode == 13 && e.target == this.replaceField) {
e.preventDefault();
replaceNext(this.view);
}
}
update(update) {
for (let tr of update.transactions)
for (let effect of tr.effects) {
if (effect.is(setSearchQuery) && !effect.value.eq(this.query))
this.setQuery(effect.value);
}
}
setQuery(query) {
this.query = query;
this.searchField.value = query.search;
this.replaceField.value = query.replace;
this.caseField.checked = query.caseSensitive;
this.reField.checked = query.regexp;
}
mount() {
this.searchField.select();
}
get pos() {
return 80;
}
get top() {
return this.view.state.facet(searchConfigFacet).top;
}
};
function phrase(view, phrase2) {
return view.state.phrase(phrase2);
}
var AnnounceMargin = 30;
var Break = /[\s\.,:;?!]/;
function announceMatch(view, { from, to }) {
let line = view.state.doc.lineAt(from), lineEnd = view.state.doc.lineAt(to).to;
let start = Math.max(line.from, from - AnnounceMargin), end = Math.min(lineEnd, to + AnnounceMargin);
let text = view.state.sliceDoc(start, end);
if (start != line.from) {
for (let i = 0; i < AnnounceMargin; i++)
if (!Break.test(text[i + 1]) && Break.test(text[i])) {
text = text.slice(i);
break;
}
}
if (end != lineEnd) {
for (let i = text.length - 1; i > text.length - AnnounceMargin; i--)
if (!Break.test(text[i - 1]) && Break.test(text[i])) {
text = text.slice(0, i);
break;
}
}
return EditorView.announce.of(`${view.state.phrase("current match")}. ${text} ${view.state.phrase("on line")} ${line.number}.`);
}
var baseTheme = EditorView.baseTheme({
".cm-panel.cm-search": {
padding: "2px 6px 4px",
position: "relative",
"& [name=close]": {
position: "absolute",
top: "0",
right: "4px",
backgroundColor: "inherit",
border: "none",
font: "inherit",
padding: 0,
margin: 0
},
"& input, & button, & label": {
margin: ".2em .6em .2em 0"
},
"& input[type=checkbox]": {
marginRight: ".2em"
},
"& label": {
fontSize: "80%",
whiteSpace: "pre"
}
},
"&light .cm-searchMatch": { backgroundColor: "#ffff0054" },
"&dark .cm-searchMatch": { backgroundColor: "#00ffff8a" },
"&light .cm-searchMatch-selected": { backgroundColor: "#ff6a0054" },
"&dark .cm-searchMatch-selected": { backgroundColor: "#ff00ff8a" }
});
var searchExtensions = [
searchState,
Prec.lowest(searchHighlighter),
baseTheme
];
// node_modules/@codemirror/lint/dist/index.js
var SelectedDiagnostic = class {
constructor(from, to, diagnostic) {
this.from = from;
this.to = to;
this.diagnostic = diagnostic;
}
};
var LintState = class {
constructor(diagnostics, panel, selected) {
this.diagnostics = diagnostics;
this.panel = panel;
this.selected = selected;
}
static init(diagnostics, panel, state) {
let markedDiagnostics = diagnostics;
let diagnosticFilter = state.facet(lintConfig).markerFilter;
if (diagnosticFilter)
markedDiagnostics = diagnosticFilter(markedDiagnostics);
let ranges = Decoration.set(markedDiagnostics.map((d) => {
return d.from == d.to || d.from == d.to - 1 && state.doc.lineAt(d.from).to == d.from ? Decoration.widget({
widget: new DiagnosticWidget(d),
diagnostic: d
}).range(d.from) : Decoration.mark({
attributes: { class: "cm-lintRange cm-lintRange-" + d.severity },
diagnostic: d
}).range(d.from, d.to);
}), true);
return new LintState(ranges, panel, findDiagnostic(ranges));
}
};
function findDiagnostic(diagnostics, diagnostic = null, after = 0) {
let found = null;
diagnostics.between(after, 1e9, (from, to, { spec }) => {
if (diagnostic && spec.diagnostic != diagnostic)
return;
found = new SelectedDiagnostic(from, to, spec.diagnostic);
return false;
});
return found;
}
function hideTooltip(tr, tooltip) {
return !!(tr.effects.some((e) => e.is(setDiagnosticsEffect)) || tr.changes.touchesRange(tooltip.pos));
}
function maybeEnableLint(state, effects) {
return state.field(lintState, false) ? effects : effects.concat(StateEffect.appendConfig.of([
lintState,
EditorView.decorations.compute([lintState], (state2) => {
let { selected, panel } = state2.field(lintState);
return !selected || !panel || selected.from == selected.to ? Decoration.none : Decoration.set([
activeMark.range(selected.from, selected.to)
]);
}),
hoverTooltip(lintTooltip, { hideOn: hideTooltip }),
baseTheme2
]));
}
function setDiagnostics(state, diagnostics) {
return {
effects: maybeEnableLint(state, [setDiagnosticsEffect.of(diagnostics)])
};
}
var setDiagnosticsEffect = StateEffect.define();
var togglePanel2 = StateEffect.define();
var movePanelSelection = StateEffect.define();
var lintState = StateField.define({
create() {
return new LintState(Decoration.none, null, null);
},
update(value, tr) {
if (tr.docChanged) {
let mapped = value.diagnostics.map(tr.changes), selected = null;
if (value.selected) {
let selPos = tr.changes.mapPos(value.selected.from, 1);
selected = findDiagnostic(mapped, value.selected.diagnostic, selPos) || findDiagnostic(mapped, null, selPos);
}
value = new LintState(mapped, value.panel, selected);
}
for (let effect of tr.effects) {
if (effect.is(setDiagnosticsEffect)) {
value = LintState.init(effect.value, value.panel, tr.state);
} else if (effect.is(togglePanel2)) {
value = new LintState(value.diagnostics, effect.value ? LintPanel.open : null, value.selected);
} else if (effect.is(movePanelSelection)) {
value = new LintState(value.diagnostics, value.panel, effect.value);
}
}
return value;
},
provide: (f) => [
showPanel.from(f, (val) => val.panel),
EditorView.decorations.from(f, (s) => s.diagnostics)
]
});
var activeMark = Decoration.mark({ class: "cm-lintRange cm-lintRange-active" });
function lintTooltip(view, pos, side) {
let { diagnostics } = view.state.field(lintState);
let found = [], stackStart = 2e8, stackEnd = 0;
diagnostics.between(pos - (side < 0 ? 1 : 0), pos + (side > 0 ? 1 : 0), (from, to, { spec }) => {
if (pos >= from && pos <= to && (from == to || (pos > from || side > 0) && (pos < to || side < 0))) {
found.push(spec.diagnostic);
stackStart = Math.min(from, stackStart);
stackEnd = Math.max(to, stackEnd);
}
});
let diagnosticFilter = view.state.facet(lintConfig).tooltipFilter;
if (diagnosticFilter)
found = diagnosticFilter(found);
if (!found.length)
return null;
return {
pos: stackStart,
end: stackEnd,
above: view.state.doc.lineAt(stackStart).to < stackEnd,
create() {
return { dom: diagnosticsTooltip(view, found) };
}
};
}
function diagnosticsTooltip(view, diagnostics) {
return crelt("ul", { class: "cm-tooltip-lint" }, diagnostics.map((d) => renderDiagnostic(view, d, false)));
}
var openLintPanel = (view) => {
let field = view.state.field(lintState, false);
if (!field || !field.panel)
view.dispatch({ effects: maybeEnableLint(view.state, [togglePanel2.of(true)]) });
let panel = getPanel(view, LintPanel.open);
if (panel)
panel.dom.querySelector(".cm-panel-lint ul").focus();
return true;
};
var closeLintPanel = (view) => {
let field = view.state.field(lintState, false);
if (!field || !field.panel)
return false;
view.dispatch({ effects: togglePanel2.of(false) });
return true;
};
var nextDiagnostic = (view) => {
let field = view.state.field(lintState, false);
if (!field)
return false;
let sel = view.state.selection.main, next = field.diagnostics.iter(sel.to + 1);
if (!next.value) {
next = field.diagnostics.iter(0);
if (!next.value || next.from == sel.from && next.to == sel.to)
return false;
}
view.dispatch({ selection: { anchor: next.from, head: next.to }, scrollIntoView: true });
return true;
};
var lintKeymap = [
{ key: "Mod-Shift-m", run: openLintPanel },
{ key: "F8", run: nextDiagnostic }
];
var lintPlugin = ViewPlugin.fromClass(class {
constructor(view) {
this.view = view;
this.timeout = -1;
this.set = true;
let { delay } = view.state.facet(lintConfig);
this.lintTime = Date.now() + delay;
this.run = this.run.bind(this);
this.timeout = setTimeout(this.run, delay);
}
run() {
let now = Date.now();
if (now < this.lintTime - 10) {
setTimeout(this.run, this.lintTime - now);
} else {
this.set = false;
let { state } = this.view, { sources } = state.facet(lintConfig);
Promise.all(sources.map((source) => Promise.resolve(source(this.view)))).then((annotations) => {
let all = annotations.reduce((a, b) => a.concat(b));
if (this.view.state.doc == state.doc)
this.view.dispatch(setDiagnostics(this.view.state, all));
}, (error) => {
logException(this.view.state, error);
});
}
}
update(update) {
let config = update.state.facet(lintConfig);
if (update.docChanged || config != update.startState.facet(lintConfig)) {
this.lintTime = Date.now() + config.delay;
if (!this.set) {
this.set = true;
this.timeout = setTimeout(this.run, config.delay);
}
}
}
force() {
if (this.set) {
this.lintTime = Date.now();
this.run();
}
}
destroy() {
clearTimeout(this.timeout);
}
});
var lintConfig = Facet.define({
combine(input) {
return Object.assign({ sources: input.map((i) => i.source) }, combineConfig(input.map((i) => i.config), {
delay: 750,
markerFilter: null,
tooltipFilter: null
}));
},
enables: lintPlugin
});
function assignKeys(actions) {
let assigned = [];
if (actions)
actions:
for (let { name } of actions) {
for (let i = 0; i < name.length; i++) {
let ch = name[i];
if (/[a-zA-Z]/.test(ch) && !assigned.some((c) => c.toLowerCase() == ch.toLowerCase())) {
assigned.push(ch);
continue actions;
}
}
assigned.push("");
}
return assigned;
}
function renderDiagnostic(view, diagnostic, inPanel) {
var _a;
let keys = inPanel ? assignKeys(diagnostic.actions) : [];
return crelt("li", { class: "cm-diagnostic cm-diagnostic-" + diagnostic.severity }, crelt("span", { class: "cm-diagnosticText" }, diagnostic.renderMessage ? diagnostic.renderMessage() : diagnostic.message), (_a = diagnostic.actions) === null || _a === void 0 ? void 0 : _a.map((action, i) => {
let click = (e) => {
e.preventDefault();
let found = findDiagnostic(view.state.field(lintState).diagnostics, diagnostic);
if (found)
action.apply(view, found.from, found.to);
};
let { name } = action, keyIndex = keys[i] ? name.indexOf(keys[i]) : -1;
let nameElt = keyIndex < 0 ? name : [
name.slice(0, keyIndex),
crelt("u", name.slice(keyIndex, keyIndex + 1)),
name.slice(keyIndex + 1)
];
return crelt("button", {
type: "button",
class: "cm-diagnosticAction",
onclick: click,
onmousedown: click,
"aria-label": ` Action: ${name}${keyIndex < 0 ? "" : ` (access key "${keys[i]})"`}.`
}, nameElt);
}), diagnostic.source && crelt("div", { class: "cm-diagnosticSource" }, diagnostic.source));
}
var DiagnosticWidget = class extends WidgetType {
constructor(diagnostic) {
super();
this.diagnostic = diagnostic;
}
eq(other) {
return other.diagnostic == this.diagnostic;
}
toDOM() {
return crelt("span", { class: "cm-lintPoint cm-lintPoint-" + this.diagnostic.severity });
}
};
var PanelItem = class {
constructor(view, diagnostic) {
this.diagnostic = diagnostic;
this.id = "item_" + Math.floor(Math.random() * 4294967295).toString(16);
this.dom = renderDiagnostic(view, diagnostic, true);
this.dom.id = this.id;
this.dom.setAttribute("role", "option");
}
};
var LintPanel = class {
constructor(view) {
this.view = view;
this.items = [];
let onkeydown = (event) => {
if (event.keyCode == 27) {
closeLintPanel(this.view);
this.view.focus();
} else if (event.keyCode == 38 || event.keyCode == 33) {
this.moveSelection((this.selectedIndex - 1 + this.items.length) % this.items.length);
} else if (event.keyCode == 40 || event.keyCode == 34) {
this.moveSelection((this.selectedIndex + 1) % this.items.length);
} else if (event.keyCode == 36) {
this.moveSelection(0);
} else if (event.keyCode == 35) {
this.moveSelection(this.items.length - 1);
} else if (event.keyCode == 13) {
this.view.focus();
} else if (event.keyCode >= 65 && event.keyCode <= 90 && this.selectedIndex >= 0) {
let { diagnostic } = this.items[this.selectedIndex], keys = assignKeys(diagnostic.actions);
for (let i = 0; i < keys.length; i++)
if (keys[i].toUpperCase().charCodeAt(0) == event.keyCode) {
let found = findDiagnostic(this.view.state.field(lintState).diagnostics, diagnostic);
if (found)
diagnostic.actions[i].apply(view, found.from, found.to);
}
} else {
return;
}
event.preventDefault();
};
let onclick = (event) => {
for (let i = 0; i < this.items.length; i++) {
if (this.items[i].dom.contains(event.target))
this.moveSelection(i);
}
};
this.list = crelt("ul", {
tabIndex: 0,
role: "listbox",
"aria-label": this.view.state.phrase("Diagnostics"),
onkeydown,
onclick
});
this.dom = crelt("div", { class: "cm-panel-lint" }, this.list, crelt("button", {
type: "button",
name: "close",
"aria-label": this.view.state.phrase("close"),
onclick: () => closeLintPanel(this.view)
}, "\xD7"));
this.update();
}
get selectedIndex() {
let selected = this.view.state.field(lintState).selected;
if (!selected)
return -1;
for (let i = 0; i < this.items.length; i++)
if (this.items[i].diagnostic == selected.diagnostic)
return i;
return -1;
}
update() {
let { diagnostics, selected } = this.view.state.field(lintState);
let i = 0, needsSync = false, newSelectedItem = null;
diagnostics.between(0, this.view.state.doc.length, (_start, _end, { spec }) => {
let found = -1, item;
for (let j2 = i; j2 < this.items.length; j2++)
if (this.items[j2].diagnostic == spec.diagnostic) {
found = j2;
break;
}
if (found < 0) {
item = new PanelItem(this.view, spec.diagnostic);
this.items.splice(i, 0, item);
needsSync = true;
} else {
item = this.items[found];
if (found > i) {
this.items.splice(i, found - i);
needsSync = true;
}
}
if (selected && item.diagnostic == selected.diagnostic) {
if (!item.dom.hasAttribute("aria-selected")) {
item.dom.setAttribute("aria-selected", "true");
newSelectedItem = item;
}
} else if (item.dom.hasAttribute("aria-selected")) {
item.dom.removeAttribute("aria-selected");
}
i++;
});
while (i < this.items.length && !(this.items.length == 1 && this.items[0].diagnostic.from < 0)) {
needsSync = true;
this.items.pop();
}
if (this.items.length == 0) {
this.items.push(new PanelItem(this.view, {
from: -1,
to: -1,
severity: "info",
message: this.view.state.phrase("No diagnostics")
}));
needsSync = true;
}
if (newSelectedItem) {
this.list.setAttribute("aria-activedescendant", newSelectedItem.id);
this.view.requestMeasure({
key: this,
read: () => ({ sel: newSelectedItem.dom.getBoundingClientRect(), panel: this.list.getBoundingClientRect() }),
write: ({ sel, panel }) => {
if (sel.top < panel.top)
this.list.scrollTop -= panel.top - sel.top;
else if (sel.bottom > panel.bottom)
this.list.scrollTop += sel.bottom - panel.bottom;
}
});
} else if (this.selectedIndex < 0) {
this.list.removeAttribute("aria-activedescendant");
}
if (needsSync)
this.sync();
}
sync() {
let domPos = this.list.firstChild;
function rm() {
let prev = domPos;
domPos = prev.nextSibling;
prev.remove();
}
for (let item of this.items) {
if (item.dom.parentNode == this.list) {
while (domPos != item.dom)
rm();
domPos = item.dom.nextSibling;
} else {
this.list.insertBefore(item.dom, domPos);
}
}
while (domPos)
rm();
}
moveSelection(selectedIndex) {
if (this.selectedIndex < 0)
return;
let field = this.view.state.field(lintState);
let selection = findDiagnostic(field.diagnostics, this.items[selectedIndex].diagnostic);
if (!selection)
return;
this.view.dispatch({
selection: { anchor: selection.from, head: selection.to },
scrollIntoView: true,
effects: movePanelSelection.of(selection)
});
}
static open(view) {
return new LintPanel(view);
}
};
function svg(content, attrs = `viewBox="0 0 40 40"`) {
return `url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${attrs}>${encodeURIComponent(content)}</svg>')`;
}
function underline(color) {
return svg(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${color}" fill="none" stroke-width=".7"/>`, `width="6" height="3"`);
}
var baseTheme2 = EditorView.baseTheme({
".cm-diagnostic": {
padding: "3px 6px 3px 8px",
marginLeft: "-1px",
display: "block",
whiteSpace: "pre-wrap"
},
".cm-diagnostic-error": { borderLeft: "5px solid #d11" },
".cm-diagnostic-warning": { borderLeft: "5px solid orange" },
".cm-diagnostic-info": { borderLeft: "5px solid #999" },
".cm-diagnosticAction": {
font: "inherit",
border: "none",
padding: "2px 4px",
backgroundColor: "#444",
color: "white",
borderRadius: "3px",
marginLeft: "8px"
},
".cm-diagnosticSource": {
fontSize: "70%",
opacity: 0.7
},
".cm-lintRange": {
backgroundPosition: "left bottom",
backgroundRepeat: "repeat-x",
paddingBottom: "0.7px"
},
".cm-lintRange-error": { backgroundImage: underline("#d11") },
".cm-lintRange-warning": { backgroundImage: underline("orange") },
".cm-lintRange-info": { backgroundImage: underline("#999") },
".cm-lintRange-active": { backgroundColor: "#ffdd9980" },
".cm-tooltip-lint": {
padding: 0,
margin: 0
},
".cm-lintPoint": {
position: "relative",
"&:after": {
content: '""',
position: "absolute",
bottom: 0,
left: "-2px",
borderLeft: "3px solid transparent",
borderRight: "3px solid transparent",
borderBottom: "4px solid #d11"
}
},
".cm-lintPoint-warning": {
"&:after": { borderBottomColor: "orange" }
},
".cm-lintPoint-info": {
"&:after": { borderBottomColor: "#999" }
},
".cm-panel.cm-panel-lint": {
position: "relative",
"& ul": {
maxHeight: "100px",
overflowY: "auto",
"& [aria-selected]": {
backgroundColor: "#ddd",
"& u": { textDecoration: "underline" }
},
"&:focus [aria-selected]": {
background_fallback: "#bdf",
backgroundColor: "Highlight",
color_fallback: "white",
color: "HighlightText"
},
"& u": { textDecoration: "none" },
padding: 0,
margin: 0
},
"& [name=close]": {
position: "absolute",
top: "0",
right: "2px",
background: "inherit",
border: "none",
font: "inherit",
padding: 0,
margin: 0
}
}
});
var LintGutterMarker = class extends GutterMarker {
constructor(diagnostics) {
super();
this.diagnostics = diagnostics;
this.severity = diagnostics.reduce((max, d) => {
let s = d.severity;
return s == "error" || s == "warning" && max == "info" ? s : max;
}, "info");
}
toDOM(view) {
let elt = document.createElement("div");
elt.className = "cm-lint-marker cm-lint-marker-" + this.severity;
let diagnostics = this.diagnostics;
let diagnosticsFilter = view.state.facet(lintGutterConfig).tooltipFilter;
if (diagnosticsFilter)
diagnostics = diagnosticsFilter(diagnostics);
if (diagnostics.length)
elt.onmouseover = () => gutterMarkerMouseOver(view, elt, diagnostics);
return elt;
}
};
function trackHoverOn(view, marker) {
let mousemove = (event) => {
let rect = marker.getBoundingClientRect();
if (event.clientX > rect.left - 10 && event.clientX < rect.right + 10 && event.clientY > rect.top - 10 && event.clientY < rect.bottom + 10)
return;
for (let target = event.target; target; target = target.parentNode) {
if (target.nodeType == 1 && target.classList.contains("cm-tooltip-lint"))
return;
}
window.removeEventListener("mousemove", mousemove);
if (view.state.field(lintGutterTooltip))
view.dispatch({ effects: setLintGutterTooltip.of(null) });
};
window.addEventListener("mousemove", mousemove);
}
function gutterMarkerMouseOver(view, marker, diagnostics) {
function hovered() {
let line = view.elementAtHeight(marker.getBoundingClientRect().top + 5 - view.documentTop);
const linePos = view.coordsAtPos(line.from);
if (linePos) {
view.dispatch({ effects: setLintGutterTooltip.of({
pos: line.from,
above: false,
create() {
return {
dom: diagnosticsTooltip(view, diagnostics),
getCoords: () => marker.getBoundingClientRect()
};
}
}) });
}
marker.onmouseout = marker.onmousemove = null;
trackHoverOn(view, marker);
}
let { hoverTime } = view.state.facet(lintGutterConfig);
let hoverTimeout = setTimeout(hovered, hoverTime);
marker.onmouseout = () => {
clearTimeout(hoverTimeout);
marker.onmouseout = marker.onmousemove = null;
};
marker.onmousemove = () => {
clearTimeout(hoverTimeout);
hoverTimeout = setTimeout(hovered, hoverTime);
};
}
function markersForDiagnostics(doc, diagnostics) {
let byLine = /* @__PURE__ */ Object.create(null);
for (let diagnostic of diagnostics) {
let line = doc.lineAt(diagnostic.from);
(byLine[line.from] || (byLine[line.from] = [])).push(diagnostic);
}
let markers = [];
for (let line in byLine) {
markers.push(new LintGutterMarker(byLine[line]).range(+line));
}
return RangeSet.of(markers, true);
}
var lintGutterExtension = gutter({
class: "cm-gutter-lint",
markers: (view) => view.state.field(lintGutterMarkers)
});
var lintGutterMarkers = StateField.define({
create() {
return RangeSet.empty;
},
update(markers, tr) {
markers = markers.map(tr.changes);
let diagnosticFilter = tr.state.facet(lintGutterConfig).markerFilter;
for (let effect of tr.effects) {
if (effect.is(setDiagnosticsEffect)) {
let diagnostics = effect.value;
if (diagnosticFilter)
diagnostics = diagnosticFilter(diagnostics || []);
markers = markersForDiagnostics(tr.state.doc, diagnostics.slice(0));
}
}
return markers;
}
});
var setLintGutterTooltip = StateEffect.define();
var lintGutterTooltip = StateField.define({
create() {
return null;
},
update(tooltip, tr) {
if (tooltip && tr.docChanged)
tooltip = hideTooltip(tr, tooltip) ? null : Object.assign(Object.assign({}, tooltip), { pos: tr.changes.mapPos(tooltip.pos) });
return tr.effects.reduce((t, e) => e.is(setLintGutterTooltip) ? e.value : t, tooltip);
},
provide: (field) => showTooltip.from(field)
});
var lintGutterTheme = EditorView.baseTheme({
".cm-gutter-lint": {
width: "1.4em",
"& .cm-gutterElement": {
padding: ".2em"
}
},
".cm-lint-marker": {
width: "1em",
height: "1em"
},
".cm-lint-marker-info": {
content: svg(`<path fill="#aaf" stroke="#77e" stroke-width="6" stroke-linejoin="round" d="M5 5L35 5L35 35L5 35Z"/>`)
},
".cm-lint-marker-warning": {
content: svg(`<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>`)
},
".cm-lint-marker-error:before": {
content: svg(`<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>`)
}
});
var lintGutterConfig = Facet.define({
combine(configs) {
return combineConfig(configs, {
hoverTime: 300,
markerFilter: null,
tooltipFilter: null
});
}
});
// node_modules/codemirror/dist/index.js
var basicSetup = (() => [
lineNumbers(),
highlightActiveLineGutter(),
highlightSpecialChars(),
history(),
foldGutter(),
drawSelection(),
dropCursor(),
EditorState.allowMultipleSelections.of(true),
indentOnInput(),
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
bracketMatching(),
closeBrackets(),
autocompletion(),
rectangularSelection(),
crosshairCursor(),
highlightActiveLine(),
highlightSelectionMatches(),
keymap.of([
...closeBracketsKeymap,
...defaultKeymap,
...searchKeymap,
...historyKeymap,
...foldKeymap,
...completionKeymap,
...lintKeymap
])
])();
var minimalSetup = (() => [
highlightSpecialChars(),
history(),
drawSelection(),
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
keymap.of([
...defaultKeymap,
...historyKeymap
])
])();
// node_modules/vue-codemirror/dist/vue-codemirror.esm.js
var y = Object.freeze({ autofocus: false, disabled: false, indentWithTab: true, tabSize: 2, placeholder: "", autoDestroy: true, extensions: [basicSetup] });
var h2 = Symbol("vue-codemirror-global-config");
var O;
var j = function(e) {
var t = e.onUpdate, n = e.onChange, o = e.onFocus, r = e.onBlur, i = function(e2, t2) {
var n2 = {};
for (var o2 in e2)
Object.prototype.hasOwnProperty.call(e2, o2) && t2.indexOf(o2) < 0 && (n2[o2] = e2[o2]);
if (null != e2 && "function" == typeof Object.getOwnPropertySymbols) {
var r2 = 0;
for (o2 = Object.getOwnPropertySymbols(e2); r2 < o2.length; r2++)
t2.indexOf(o2[r2]) < 0 && Object.prototype.propertyIsEnumerable.call(e2, o2[r2]) && (n2[o2[r2]] = e2[o2[r2]]);
}
return n2;
}(e, ["onUpdate", "onChange", "onFocus", "onBlur"]);
return EditorState.create({ doc: i.doc, selection: i.selection, extensions: (Array.isArray(i.extensions) ? i.extensions : [i.extensions]).concat([EditorView.updateListener.of(function(e2) {
t(e2), e2.docChanged && n(e2.state.doc.toString(), e2), e2.focusChanged && (e2.view.hasFocus ? o(e2) : r(e2));
})]) });
};
var S = function(e) {
var t = new Compartment();
return { compartment: t, run: function(n) {
t.get(e.state) ? e.dispatch({ effects: t.reconfigure(n) }) : e.dispatch({ effects: StateEffect.appendConfig.of(t.of(n)) });
} };
};
var x = function(e, t) {
var n = S(e), o = n.compartment, r = n.run;
return function(n2) {
var i = o.get(e.state);
r((null != n2 ? n2 : i !== t) ? t : []);
};
};
var C = { type: Boolean, default: void 0 };
var D = { autofocus: C, disabled: C, indentWithTab: C, tabSize: Number, placeholder: String, style: Object, autoDestroy: C, root: Object, extensions: Array, selection: Object };
var U = { modelValue: { type: String, default: "" } };
var w = Object.assign(Object.assign({}, D), U);
!function(e) {
e.Change = "change", e.Update = "update", e.Focus = "focus", e.Blur = "blur", e.Ready = "ready", e.ModelUpdate = "update:modelValue";
}(O || (O = {}));
var z = {};
z[O.Change] = function(e, t) {
return true;
}, z[O.Update] = function(e) {
return true;
}, z[O.Focus] = function(e) {
return true;
}, z[O.Blur] = function(e) {
return true;
}, z[O.Ready] = function(e) {
return true;
};
var B = {};
B[O.ModelUpdate] = z[O.Change];
var F = Object.assign(Object.assign({}, z), B);
var T = defineComponent({ name: "VueCodemirror", props: Object.assign({}, w), emits: Object.assign({}, F), setup: function(t, s) {
var f = shallowRef(), d = shallowRef(), C2 = shallowRef(), D2 = Object.assign(Object.assign({}, y), inject(h2, {})), U2 = computed(function() {
var e = {};
return Object.keys(toRaw(t)).forEach(function(n) {
var o;
"modelValue" !== n && (e[n] = null !== (o = t[n]) && void 0 !== o ? o : D2[n]);
}), e;
});
return onMounted(function() {
var e;
d.value = j({ doc: t.modelValue, selection: U2.value.selection, extensions: null !== (e = D2.extensions) && void 0 !== e ? e : [], onFocus: function(e2) {
return s.emit(O.Focus, e2);
}, onBlur: function(e2) {
return s.emit(O.Blur, e2);
}, onUpdate: function(e2) {
return s.emit(O.Update, e2);
}, onChange: function(e2, n2) {
e2 !== t.modelValue && (s.emit(O.Change, e2, n2), s.emit(O.ModelUpdate, e2, n2));
} }), C2.value = function(e2) {
return new EditorView(Object.assign({}, e2));
}({ state: d.value, parent: f.value, root: U2.value.root });
var n = function(e2) {
var t2 = function() {
return e2.state.doc.toString();
}, n2 = S(e2).run, o = x(e2, [EditorView.editable.of(false), EditorState.readOnly.of(true)]), r = x(e2, keymap.of([indentWithTab])), i = S(e2).run, u = S(e2).run, a = S(e2).run;
return { focus: function() {
return e2.focus();
}, getDoc: t2, setDoc: function(n3) {
n3 !== t2() && e2.dispatch({ changes: { from: 0, to: e2.state.doc.length, insert: n3 } });
}, reExtensions: n2, toggleDisabled: o, toggleIndentWithTab: r, setTabSize: function(e3) {
i([EditorState.tabSize.of(e3), indentUnit.of(" ".repeat(e3))]);
}, setPlaceholder: function(e3) {
u(placeholder(e3));
}, setStyle: function(e3) {
void 0 === e3 && (e3 = {}), a(EditorView.theme({ "&": Object.assign({}, e3) }));
} };
}(C2.value);
watch(function() {
return t.modelValue;
}, function(e2) {
e2 !== n.getDoc() && n.setDoc(e2);
}), watch(function() {
return t.extensions;
}, function(e2) {
return n.reExtensions(e2 || []);
}, { immediate: true }), watch(function() {
return U2.value.disabled;
}, function(e2) {
return n.toggleDisabled(e2);
}, { immediate: true }), watch(function() {
return U2.value.indentWithTab;
}, function(e2) {
return n.toggleIndentWithTab(e2);
}, { immediate: true }), watch(function() {
return U2.value.tabSize;
}, function(e2) {
return n.setTabSize(e2);
}, { immediate: true }), watch(function() {
return U2.value.placeholder;
}, function(e2) {
return n.setPlaceholder(e2);
}, { immediate: true }), watch(function() {
return U2.value.style;
}, function(e2) {
return n.setStyle(e2);
}, { immediate: true }), U2.value.autofocus && n.focus(), s.emit(O.Ready, { state: d.value, view: C2.value, container: f.value });
}), onBeforeUnmount(function() {
U2.value.autoDestroy && C2.value && function(e) {
e.destroy();
}(C2.value);
}), function() {
return h("div", { class: "v-codemirror", style: { display: "contents" }, ref: f });
};
} });
var V = T;
var P = function(e, t) {
e.component(T.name, T), function(e2, t2) {
e2.provide(h2, t2);
}(e, t);
};
var W = { Codemirror: V, install: P };
// dep:vue-codemirror
var vue_codemirror_default = W;
export {
V as Codemirror,
y as DEFAULT_CONFIG,
vue_codemirror_default as default,
P as install
};
/*!
* VueCodemirror v6.0.1
* Copyright (c) Surmon. All rights reserved.
* Released under the MIT License.
* Surmon <https://github.com/surmon-china>
*/
//# sourceMappingURL=vue-codemirror.js.map