// ==UserScript==
// @name yapi-create
// @namespace shiouhoo/yapi-create
// @version 1.1.1
// @author shiouhoo
// @description 这是一个用于yapi的插件,快捷生成ts类型以及axios请求
// @license MIT
// @icon https://vitejs.dev/logo.svg
// @match *://*.trscd.com.cn/project/*
// @require https://cdn.bootcdn.net/ajax/libs/vue/3.3.4/vue.global.prod.js
// @require data:application/javascript,window.Vue%3DVue%3B
// @require https://cdn.bootcdn.net/ajax/libs/element-plus/2.4.1/index.full.min.js
// @resource element-plus/dist/index.css https://cdn.bootcdn.net/ajax/libs/element-plus/2.4.1/index.min.css
// @grant GM_getResourceText
// @grant GM_getValue
// @grant GM_registerMenuCommand
// @grant GM_setValue
// ==/UserScript==
(e=>{const t=document.createElement("style");t.dataset.source="vite-plugin-monkey",t.textContent=e,document.head.append(t)})(" .menu[data-v-4f6c7ed9]{position:fixed;z-index:10;border:1px solid #ebeef5;box-shadow:0 2px 12px #0000001a;transition:display 0s}.input[data-v-ce9a698d]{margin-top:20px}.confirm[data-v-ce9a698d]{margin:20px auto;display:block}.bottom-line[data-v-ce9a698d]{display:flex;justify-content:start;align-items:center;gap:20px;margin-top:10px} ");
(function (vue, ElementPlus) {
'use strict';
var _GM_getValue = /* @__PURE__ */ (() => typeof GM_getValue != "undefined" ? GM_getValue : void 0)();
var _GM_registerMenuCommand = /* @__PURE__ */ (() => typeof GM_registerMenuCommand != "undefined" ? GM_registerMenuCommand : void 0)();
var _GM_setValue = /* @__PURE__ */ (() => typeof GM_setValue != "undefined" ? GM_setValue : void 0)();
function getTemplates(init2 = false) {
let _tabs2;
const tempalte = _GM_getValue("customAxiosTemplate", "");
try {
_tabs2 = JSON.parse(tempalte);
} catch (e) {
_tabs2 = [];
}
if (init2 || !_tabs2.length) {
_tabs2 = [
{
title: "默认格式",
name: 0,
content: `function (describtion,name,method,url,header,params){
const paramsType = params ? params : 'any';
const headerType = header.length ? \`,{headers:\${header} }\` : '';
return \`/** \${describtion} */
export const \${name} = <T = any>(params: \${paramsType}): Promise<T> => {
return axios.\${method}('\${url}', \${method === 'get' ? \`{ params\${headerType} }\` : \`params\${headerType}\`});
};\`
}`
},
{
title: "默认格式 try-catch",
name: 1,
content: `function (describtion,name,method,url,header,params){
const paramsType = params ? params : 'any';
const headerType = header.length ? \`,{headers:\${header} }\` : '';
return \`/** \${describtion} */
export const \${name} = async<T = any>(params: \${paramsType}): Promise<{ code: number; data: T[] }> => {
let res: any;
try {
res = await axios.\${method}('\${url}', \${method === 'get' ? \`{ params\${headerType} }\` : \`params\${headerType}\`});
} catch (e) {
res = {
code: 500,
data: [],
};
}
return res;
};\`
}`
},
{
title: "request格式",
name: 2,
content: `function (describtion,name,method,url,header,params){
const paramsType = params ? params : 'any';
const headerType = header.length ? \`headers:\${header}, \` : '';
return \`/** \${describtion} */
export const \${name} = <T = any>(params: \${paramsType}): Promise<T> => {
return request({
url: '\${url}',
method: '\${method.toUpperCase()}',
\${method === 'get' ? 'params' : 'data: params'},
\${headerType}
});
};\`
}`
},
{
title: "request格式 try-catch",
name: 3,
content: `function (describtion,name,method,url,header,params){
const paramsType = params ? params : 'any';
const headerType = header.length ? \`headers:\${header}, \` : '';
return \`/** \${describtion} */
export const \${name} = async<T = any>(params: \${paramsType}): Promise<{ code: number; data: T[] }> => {
let res: any;
try{
res = request({
url: '\${url}',
method: '\${method.toUpperCase()}',
\${method === 'get' ? 'params' : 'data: params'},
\${headerType}
});
}catch{
res = {
code: 500,
data: [],
};
}
return res;
};\`
}`
}
];
}
return _tabs2;
}
const responsetableIndex = {
name: -1,
type: -1,
required: -1,
description: -1,
other: -1
};
function updateIndex(panel) {
if (!panel)
return "";
panel == null ? void 0 : panel.querySelectorAll(".ant-table-body .ant-table-thead tr th").forEach((item, index) => {
var _a2, _b, _c, _d, _e;
if ((_a2 = item.textContent) == null ? void 0 : _a2.includes("名称")) {
responsetableIndex.name = index + 1;
} else if ((_b = item.textContent) == null ? void 0 : _b.includes("类型")) {
responsetableIndex.type = index + 1;
} else if ((_c = item.textContent) == null ? void 0 : _c.includes("是否必须")) {
responsetableIndex.required = index + 1;
} else if ((_d = item.textContent) == null ? void 0 : _d.includes("备注")) {
responsetableIndex.description = index + 1;
} else if ((_e = item.textContent) == null ? void 0 : _e.includes("其他")) {
responsetableIndex.other = index + 1;
}
});
}
function getRequestType(panel) {
if (!panel)
return "";
let obj = "{\r\n";
const trList = panel == null ? void 0 : panel.querySelectorAll(".ant-table-body table tbody tr");
Array.from(trList || []).forEach((tr) => {
var _a2, _b, _c, _d, _e, _f;
const name2 = ((_a2 = tr.querySelector(`td:nth-child(${responsetableIndex.name})`)) == null ? void 0 : _a2.textContent) || "";
let type = ((_b = tr.querySelector(`td:nth-child(${responsetableIndex.type})`)) == null ? void 0 : _b.textContent) || "any";
if (type == null ? void 0 : type.includes("文本")) {
type = "string";
}
const required = (_d = (_c = tr.querySelector(`td:nth-child(${responsetableIndex.required})`)) == null ? void 0 : _c.textContent) == null ? void 0 : _d.includes("是");
let description = (_f = (_e = tr.querySelector(`td:nth-child(${responsetableIndex.description})`)) == null ? void 0 : _e.textContent) == null ? void 0 : _f.trim();
const descBeforeEnter = (description == null ? void 0 : description.includes("\n")) ? "\r\n * " : " ";
const descEnter = (description == null ? void 0 : description.includes("\n")) ? "\r\n " : " ";
description = (description == null ? void 0 : description.trim()) ? ` /**${descBeforeEnter}${description == null ? void 0 : description.replaceAll("\n", "\n * ")}${descEnter}*/\r
` : "";
const item = `${description} ${name2}${required ? "" : "?"}: ${type};\r
`;
obj += item;
});
obj += "}";
return obj;
}
const _sfc_main$3 = /* @__PURE__ */ vue.defineComponent({
__name: "CreateAxios",
setup(__props) {
const dialogVisible = vue.inject("dialogVisible");
let _tabs = getTemplates();
const tabs = vue.ref(JSON.parse(JSON.stringify(_tabs)));
const activeKey = vue.ref(0);
vue.watch(dialogVisible, (val) => {
if (!val) {
_tabs = getTemplates();
tabs.value = JSON.parse(JSON.stringify(_tabs));
}
});
const btnRef = vue.ref();
function getHeaders() {
var _a2, _b, _c, _d, _e, _f, _g;
let domList = document.querySelectorAll(".interface-title");
let header2 = "{\r\n";
for (let i2 = 0; i2 < domList.length; i2++) {
if ((_a2 = domList[i2].textContent) == null ? void 0 : _a2.includes("请求参数")) {
const title = (_b = domList[i2].nextElementSibling) == null ? void 0 : _b.querySelector(".col-title");
if ((_c = title == null ? void 0 : title.textContent) == null ? void 0 : _c.toLowerCase().includes("headers")) {
const rows = ((_e = (_d = domList[i2]) == null ? void 0 : _d.nextElementSibling) == null ? void 0 : _e.querySelectorAll(".ant-table-row")) || [];
for (let j2 = 0; j2 < rows.length; j2++) {
const key = (_g = (_f = rows[j2].firstChild) == null ? void 0 : _f.textContent) == null ? void 0 : _g.trim();
if (key) {
header2 += ` '${key}': '${rows[j2].childNodes[1].textContent}',\r
`;
}
}
} else {
return "";
}
}
}
header2 += "}";
return header2;
}
const createTemplate = ({
method = "",
url = "",
name = "",
describtion = "",
header = "",
params = ""
}) => {
var _a2, _b;
const content = ((_b = (_a2 = tabs.value.find((item) => item.name === activeKey.value)) == null ? void 0 : _a2.content) == null ? void 0 : _b.trim()) || "";
const match = content.match(/^function\s*\(\s*describtion\s*,\s*name\s*,\s*method\s*,\s*url\s*,\s*header\s*,\s*params\s*\)\s*{(.*)}$/s);
if (!match) {
ElementPlus.ElMessage.error("模版格式错误");
return "";
}
let func = eval("(" + match[0] + ")");
let result = func(describtion, name, method, url, header, params);
return result == null ? void 0 : result.trim();
};
const handleClick = () => {
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
const panel = (_c = (_b = (_a2 = btnRef.value) == null ? void 0 : _a2.parentElement) == null ? void 0 : _b.parentElement) == null ? void 0 : _c.nextElementSibling;
if (panel) {
const methodDom = panel.querySelector(".ant-row .tag-method");
const method2 = (_d = methodDom == null ? void 0 : methodDom.textContent) == null ? void 0 : _d.toLowerCase();
const url2 = (_e = methodDom == null ? void 0 : methodDom.nextElementSibling) == null ? void 0 : _e.textContent;
const name2 = url2 == null ? void 0 : url2.split("/").slice(-1)[0];
const describtion2 = (_f = panel.querySelector(".ant-row .colName")) == null ? void 0 : _f.textContent;
const header2 = getHeaders();
const paramsPanel = (_i = (_h = (_g = document.querySelector(".copy-request-type-btn")) == null ? void 0 : _g.parentElement) == null ? void 0 : _h.parentElement) == null ? void 0 : _i.nextElementSibling;
updateIndex(paramsPanel);
const params2 = getRequestType(paramsPanel);
const template = createTemplate({
method: method2 || "",
url: url2 || "",
name: name2 || "",
describtion: describtion2 || "",
header: header2 || "",
params: params2 || ""
});
if (!template) {
return;
}
navigator.clipboard.writeText(template.trim());
ElementPlus.ElMessage.success("成功复制到剪切板");
}
};
return (_ctx, _cache) => {
const _component_el_dropdown_item = vue.resolveComponent("el-dropdown-item");
const _component_el_dropdown_menu = vue.resolveComponent("el-dropdown-menu");
const _component_el_dropdown = vue.resolveComponent("el-dropdown");
return vue.openBlock(), vue.createElementBlock("div", {
ref_key: "btnRef",
ref: btnRef
}, [
vue.createVNode(_component_el_dropdown, {
"split-button": "",
type: "primary",
onClick: handleClick
}, {
dropdown: vue.withCtx(() => [
vue.createVNode(_component_el_dropdown_menu, null, {
default: vue.withCtx(() => [
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(tabs.value, (item, index) => {
return vue.openBlock(), vue.createBlock(_component_el_dropdown_item, {
key: index,
onClick: ($event) => activeKey.value = item.name
}, {
default: vue.withCtx(() => [
vue.createTextVNode(vue.toDisplayString(item.title), 1)
]),
_: 2
}, 1032, ["onClick"]);
}), 128))
]),
_: 1
})
]),
default: vue.withCtx(() => {
var _a2;
return [
vue.createTextVNode(" 复制axios请求(" + vue.toDisplayString((_a2 = tabs.value.find((item) => item.name === activeKey.value)) == null ? void 0 : _a2.title) + ") ", 1)
];
}),
_: 1
})
], 512);
};
}
});
const _withScopeId$1 = (n) => (vue.pushScopeId("data-v-4f6c7ed9"), n = n(), vue.popScopeId(), n);
const _hoisted_1$1 = /* @__PURE__ */ _withScopeId$1(() => /* @__PURE__ */ vue.createElementVNode("span", null, "复制类型", -1));
const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
__name: "CreateTypes",
setup(__props2) {
const btnRef2 = vue.ref();
const type = vue.ref("request");
const msgMap = {
request: "请求参数",
response: "返回数据"
};
const targetDom = vue.ref();
function modifyDom(dom) {
dom.addEventListener("contextmenu", (e) => {
var _a2;
e.stopPropagation();
e.preventDefault();
targetDom.value = e.target;
const x2 = e.clientX;
const y2 = e.clientY;
const menuDom = (_a2 = btnRef2.value) == null ? void 0 : _a2.querySelector(".menu");
menuDom == null ? void 0 : menuDom.setAttribute("style", `left: ${x2 + 8}px; top: ${y2 - 25}px;`);
document.addEventListener("click", function() {
targetDom.value = null;
});
});
}
function getResponseTypes(panel, level = 0, tab = 0, start = 0, end = Infinity) {
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
let obj = "{\r\n";
let trList = Array.from((panel == null ? void 0 : panel.querySelectorAll(`tr.ant-table-row-level-${level}`)) || []);
trList = trList.filter((item) => {
const idx = Array.prototype.indexOf.call(item.parentElement.childNodes, item);
return idx >= start && idx <= end;
});
let isCanReturnType = false;
if ((!trList || !trList.length) && level === 0) {
trList = [panel];
isCanReturnType = true;
const match2 = panel == null ? void 0 : panel.className.match(/ant-table-row-level-(\d+)/);
if (match2) {
level = parseInt(match2[1]);
}
panel = panel == null ? void 0 : panel.parentElement;
}
if ((!trList || !trList.length) && level !== 0) {
return "{}";
}
for (let tr of trList) {
const name2 = (_a2 = tr.querySelector(`td:nth-child(${responsetableIndex.name})`)) == null ? void 0 : _a2.textContent;
let type2 = (_c = (_b = tr.querySelector(`td:nth-child(${responsetableIndex.type})`)) == null ? void 0 : _b.textContent) == null ? void 0 : _c.replaceAll(" ", "");
let nextDom = tr == null ? void 0 : tr.nextElementSibling;
while (nextDom) {
if (nextDom == null ? void 0 : nextDom.className.match(/ant-table-row-level-(\d+)/)) {
const _level = parseInt(nextDom.className.match(/ant-table-row-level-(\d+)/)[1]);
if (_level === level) {
end = Array.prototype.indexOf.call(tr.parentElement.childNodes, nextDom);
break;
}
}
nextDom = nextDom == null ? void 0 : nextDom.nextElementSibling;
}
if (type2 === "integer") {
type2 = "number";
isCanReturnType = false;
} else if (type2 === "object") {
type2 = getResponseTypes(panel, level + 1, isCanReturnType ? tab : tab + 1, Array.prototype.indexOf.call(tr.parentElement.childNodes, tr), end);
} else if (type2 === "object[]") {
type2 = getResponseTypes(panel, level + 1, isCanReturnType ? tab : tab + 1, Array.prototype.indexOf.call(tr.parentElement.childNodes, tr), end) + "[]";
} else {
isCanReturnType = false;
}
const otherInfoDom = tr.querySelector(`td:nth-child(${responsetableIndex.other})`);
if ((_d = otherInfoDom == null ? void 0 : otherInfoDom.textContent) == null ? void 0 : _d.includes("枚举")) {
let enumString = "";
const pNodeList = otherInfoDom.querySelectorAll("p");
for (const pNode of Array.from(pNodeList)) {
if ((_e = pNode.textContent) == null ? void 0 : _e.includes("枚举")) {
let txt = ((_f = pNode.lastChild) == null ? void 0 : _f.textContent) || "";
for (let item2 of txt.split(",")) {
if (Number.isNaN(Number(item2))) {
enumString += `'${item2.trim()}' | `;
} else {
enumString += `${item2.trim()} | `;
}
}
enumString = enumString.slice(0, -3) || type2 || "";
break;
}
}
type2 = enumString;
}
if (!name2 || isCanReturnType) {
return type2 || "";
}
let description = (_h = (_g = tr.querySelector(`td:nth-child(${responsetableIndex.description})`)) == null ? void 0 : _g.textContent) == null ? void 0 : _h.trim();
const tabString = " ".repeat(tab + 1);
const required = ((_j = (_i = tr.querySelector(`td:nth-child(${responsetableIndex.required})`)) == null ? void 0 : _i.textContent) == null ? void 0 : _j.trim()) === "必须";
const descEnter = (description == null ? void 0 : description.includes("\n")) ? `\r
${tabString}` : " ";
description = (description == null ? void 0 : description.trim()) ? `${tabString}/** ${description.replaceAll("\n", `
${tabString} * `)}${descEnter} */\r
` : "";
const item = `${description}${tabString}${name2}${required ? "" : "?"}: ${type2};\r
`;
obj += item;
}
obj += `${" ".repeat(tab)}}`;
return obj;
}
const handleClick2 = () => {
var _a2, _b, _c;
let panel = (_c = (_b = (_a2 = btnRef2.value) == null ? void 0 : _a2.parentElement) == null ? void 0 : _b.parentElement) == null ? void 0 : _c.nextElementSibling;
let obj = "{\r\n";
updateIndex(panel);
if (type.value === "request") {
obj = getRequestType(panel);
} else if (type.value === "response") {
obj = getResponseTypes(panel);
}
navigator.clipboard.writeText(obj);
ElementPlus.ElMessage.success("成功复制到剪切板");
};
const copyItemTypes = () => {
var _a2, _b, _c;
const panel = (_c = (_b = (_a2 = btnRef2.value) == null ? void 0 : _a2.parentElement) == null ? void 0 : _b.parentElement) == null ? void 0 : _c.nextElementSibling;
updateIndex(panel);
const start = Array.prototype.indexOf.call(targetDom.value.parentElement.parentElement.childNodes, targetDom.value.parentElement);
const obj = getResponseTypes(targetDom.value.parentElement, 0, 0, start);
navigator.clipboard.writeText(obj);
ElementPlus.ElMessage.success("成功复制到剪切板");
};
vue.onMounted(() => {
var _a2, _b, _c, _d, _e, _f, _g;
const text = (_c = (_b = (_a2 = btnRef2.value) == null ? void 0 : _a2.parentElement) == null ? void 0 : _b.parentElement) == null ? void 0 : _c.textContent;
if ((text == null ? void 0 : text.includes("Body")) || (text == null ? void 0 : text.includes("Query"))) {
type.value = "request";
} else if (text == null ? void 0 : text.includes("返回数据")) {
type.value = "response";
let tableDom = (_g = (_f = (_e = (_d = btnRef2.value) == null ? void 0 : _d.parentElement) == null ? void 0 : _e.parentElement) == null ? void 0 : _f.nextElementSibling) == null ? void 0 : _g.querySelector(".ant-table-tbody");
tableDom == null ? void 0 : tableDom.querySelectorAll("tr").forEach((item) => {
modifyDom(item.firstChild);
});
let observer = new MutationObserver((mutations) => {
for (let mutation of mutations) {
if (mutation.type === "childList") {
const target = mutation.addedNodes[0];
if (!target)
return;
modifyDom(target.firstChild);
}
}
});
tableDom && observer.observe(tableDom, {
childList: true,
subtree: true
});
vue.onBeforeUnmount(() => {
observer.disconnect();
});
}
});
return (_ctx, _cache) => {
const _component_el_button = vue.resolveComponent("el-button");
const _component_el_menu_item = vue.resolveComponent("el-menu-item");
const _component_el_menu = vue.resolveComponent("el-menu");
return vue.openBlock(), vue.createElementBlock("div", {
class: vue.normalizeClass({ "copy-request-type-btn": type.value === "request" }),
ref_key: "btnRef",
ref: btnRef2
}, [
vue.createVNode(_component_el_button, { onClick: handleClick2 }, {
default: vue.withCtx(() => [
vue.createTextVNode("复制" + vue.toDisplayString(msgMap[type.value]) + "类型", 1)
]),
_: 1
}),
vue.withDirectives(vue.createVNode(_component_el_menu, {
ref: "menuDom",
class: "menu"
}, {
default: vue.withCtx(() => [
vue.createVNode(_component_el_menu_item, {
index: "1",
onClick: copyItemTypes
}, {
default: vue.withCtx(() => [
_hoisted_1$1
]),
_: 1
})
]),
_: 1
}, 512), [
[vue.vShow, targetDom.value]
])
], 2);
};
}
});
const _export_sfc = (sfc, props) => {
const target = sfc.__vccOpts || sfc;
for (const [key, val] of props) {
target[key] = val;
}
return target;
};
const CreateTypes = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-4f6c7ed9"]]);
class Text {
/**
Get the line description around the given position.
*/
lineAt(pos) {
if (pos < 0 || pos > this.length)
throw new RangeError(`Invalid position ${pos} in document of length ${this.length}`);
return this.lineInner(pos, false, 1, 0);
}
/**
Get the description for the given (1-based) line number.
*/
line(n) {
if (n < 1 || n > this.lines)
throw new RangeError(`Invalid line number ${n} in ${this.lines}-line document`);
return this.lineInner(n, true, 1, 0);
}
/**
Replace a range of the text with the given content.
*/
replace(from, to, text) {
[from, to] = clip(this, from, to);
let parts = [];
this.decompose(
0,
from,
parts,
2
/* Open.To */
);
if (text.length)
text.decompose(
0,
text.length,
parts,
1 | 2
/* Open.To */
);
this.decompose(
to,
this.length,
parts,
1
/* Open.From */
);
return TextNode.from(parts, this.length - (to - from) + text.length);
}
/**
Append another document to this one.
*/
append(other) {
return this.replace(this.length, this.length, other);
}
/**
Retrieve the text between the given points.
*/
slice(from, to = this.length) {
[from, to] = clip(this, from, to);
let parts = [];
this.decompose(from, to, parts, 0);
return TextNode.from(parts, to - from);
}
/**
Test whether this text is equal to another instance.
*/
eq(other) {
if (other == this)
return true;
if (other.length != this.length || other.lines != this.lines)
return false;
let start = this.scanIdentical(other, 1), end = this.length - this.scanIdentical(other, -1);
let a = new RawTextCursor(this), b = new RawTextCursor(other);
for (let skip = start, pos = start; ; ) {
a.next(skip);
b.next(skip);
skip = 0;
if (a.lineBreak != b.lineBreak || a.done != b.done || a.value != b.value)
return false;
pos += a.value.length;
if (a.done || pos >= end)
return true;
}
}
/**
Iterate over the text. When `dir` is `-1`, iteration happens
from end to start. This will return lines and the breaks between
them as separate strings.
*/
iter(dir = 1) {
return new RawTextCursor(this, dir);
}
/**
Iterate over a range of the text. When `from` > `to`, the
iterator will run in reverse.
*/
iterRange(from, to = this.length) {
return new PartialTextCursor(this, from, to);
}
/**
Return a cursor that iterates over the given range of lines,
_without_ returning the line breaks between, and yielding empty
strings for empty lines.
When `from` and `to` are given, they should be 1-based line numbers.
*/
iterLines(from, to) {
let inner;
if (from == null) {
inner = this.iter();
} else {
if (to == null)
to = this.lines + 1;
let start = this.line(from).from;
inner = this.iterRange(start, Math.max(start, to == this.lines + 1 ? this.length : to <= 1 ? 0 : this.line(to - 1).to));
}
return new LineCursor(inner);
}
/**
Return the document as a string, using newline characters to
separate lines.
*/
toString() {
return this.sliceString(0);
}
/**
Convert the document to an array of lines (which can be
deserialized again via [`Text.of`](https://codemirror.net/6/docs/ref/#state.Text^of)).
*/
toJSON() {
let lines = [];
this.flatten(lines);
return lines;
}
/**
@internal
*/
constructor() {
}
/**
Create a `Text` instance for the given array of lines.
*/
static of(text) {
if (text.length == 0)
throw new RangeError("A document must have at least one line");
if (text.length == 1 && !text[0])
return Text.empty;
return text.length <= 32 ? new TextLeaf(text) : TextNode.from(TextLeaf.split(text, []));
}
}
class TextLeaf extends Text {
constructor(text, length = textLength(text)) {
super();
this.text = text;
this.length = length;
}
get lines() {
return this.text.length;
}
get children() {
return null;
}
lineInner(target, isLine, line, offset) {
for (let i2 = 0; ; i2++) {
let string2 = this.text[i2], end = offset + string2.length;
if ((isLine ? line : end) >= target)
return new Line(offset, end, line, string2);
offset = end + 1;
line++;
}
}
decompose(from, to, target, open) {
let text = from <= 0 && to >= this.length ? this : new TextLeaf(sliceText(this.text, from, to), Math.min(to, this.length) - Math.max(0, from));
if (open & 1) {
let prev = target.pop();
let joined = appendText(text.text, prev.text.slice(), 0, text.length);
if (joined.length <= 32) {
target.push(new TextLeaf(joined, prev.length + text.length));
} else {
let mid = joined.length >> 1;
target.push(new TextLeaf(joined.slice(0, mid)), new TextLeaf(joined.slice(mid)));
}
} else {
target.push(text);
}
}
replace(from, to, text) {
if (!(text instanceof TextLeaf))
return super.replace(from, to, text);
[from, to] = clip(this, from, to);
let lines = appendText(this.text, appendText(text.text, sliceText(this.text, 0, from)), to);
let newLen = this.length + text.length - (to - from);
if (lines.length <= 32)
return new TextLeaf(lines, newLen);
return TextNode.from(TextLeaf.split(lines, []), newLen);
}
sliceString(from, to = this.length, lineSep = "\n") {
[from, to] = clip(this, from, to);
let result2 = "";
for (let pos = 0, i2 = 0; pos <= to && i2 < this.text.length; i2++) {
let line = this.text[i2], end = pos + line.length;
if (pos > from && i2)
result2 += lineSep;
if (from < end && to > pos)
result2 += line.slice(Math.max(0, from - pos), to - pos);
pos = end + 1;
}
return result2;
}
flatten(target) {
for (let line of this.text)
target.push(line);
}
scanIdentical() {
return 0;
}
static split(text, target) {
let part = [], len = -1;
for (let line of text) {
part.push(line);
len += line.length + 1;
if (part.length == 32) {
target.push(new TextLeaf(part, len));
part = [];
len = -1;
}
}
if (len > -1)
target.push(new TextLeaf(part, len));
return target;
}
}
class TextNode extends Text {
constructor(children, length) {
super();
this.children = children;
this.length = length;
this.lines = 0;
for (let child of children)
this.lines += child.lines;
}
lineInner(target, isLine, line, offset) {
for (let i2 = 0; ; i2++) {
let child = this.children[i2], end = offset + child.length, endLine = line + child.lines - 1;
if ((isLine ? endLine : end) >= target)
return child.lineInner(target, isLine, line, offset);
offset = end + 1;
line = endLine + 1;
}
}
decompose(from, to, target, open) {
for (let i2 = 0, pos = 0; pos <= to && i2 < this.children.length; i2++) {
let child = this.children[i2], end = pos + child.length;
if (from <= end && to >= pos) {
let childOpen = open & ((pos <= from ? 1 : 0) | (end >= to ? 2 : 0));
if (pos >= from && end <= to && !childOpen)
target.push(child);
else
child.decompose(from - pos, to - pos, target, childOpen);
}
pos = end + 1;
}
}
replace(from, to, text) {
[from, to] = clip(this, from, to);
if (text.lines < this.lines)
for (let i2 = 0, pos = 0; i2 < this.children.length; i2++) {
let child = this.children[i2], end = pos + child.length;
if (from >= pos && to <= end) {
let updated = child.replace(from - pos, to - pos, text);
let totalLines = this.lines - child.lines + updated.lines;
if (updated.lines < totalLines >> 5 - 1 && updated.lines > totalLines >> 5 + 1) {
let copy = this.children.slice();
copy[i2] = updated;
return new TextNode(copy, this.length - (to - from) + text.length);
}
return super.replace(pos, end, updated);
}
pos = end + 1;
}
return super.replace(from, to, text);
}
sliceString(from, to = this.length, lineSep = "\n") {
[from, to] = clip(this, from, to);
let result2 = "";
for (let i2 = 0, pos = 0; i2 < this.children.length && pos <= to; i2++) {
let child = this.children[i2], end = pos + child.length;
if (pos > from && i2)
result2 += lineSep;
if (from < end && to > pos)
result2 += child.sliceString(from - pos, to - pos, lineSep);
pos = end + 1;
}
return result2;
}
flatten(target) {
for (let child of this.children)
child.flatten(target);
}
scanIdentical(other, dir) {
if (!(other instanceof TextNode))
return 0;
let length = 0;
let [iA, iB, eA, eB] = dir > 0 ? [0, 0, this.children.length, other.children.length] : [this.children.length - 1, other.children.length - 1, -1, -1];
for (; ; iA += dir, iB += dir) {
if (iA == eA || iB == eB)
return length;
let chA = this.children[iA], chB = other.children[iB];
if (chA != chB)
return length + chA.scanIdentical(chB, dir);
length += chA.length + 1;
}
}
static from(children, length = children.reduce((l, ch) => l + ch.length + 1, -1)) {
let lines = 0;
for (let ch of children)
lines += ch.lines;
if (lines < 32) {
let flat = [];
for (let ch of children)
ch.flatten(flat);
return new TextLeaf(flat, length);
}
let chunk = Math.max(
32,
lines >> 5
/* Tree.BranchShift */
), maxChunk = chunk << 1, minChunk = chunk >> 1;
let chunked = [], currentLines = 0, currentLen = -1, currentChunk = [];
function add2(child) {
let last;
if (child.lines > maxChunk && child instanceof TextNode) {
for (let node of child.children)
add2(node);
} else if (child.lines > minChunk && (currentLines > minChunk || !currentLines)) {
flush();
chunked.push(child);
} else if (child instanceof TextLeaf && currentLines && (last = currentChunk[currentChunk.length - 1]) instanceof TextLeaf && child.lines + last.lines <= 32) {
currentLines += child.lines;
currentLen += child.length + 1;
currentChunk[currentChunk.length - 1] = new TextLeaf(last.text.concat(child.text), last.length + 1 + child.length);
} else {
if (currentLines + child.lines > chunk)
flush();
currentLines += child.lines;
currentLen += child.length + 1;
currentChunk.push(child);
}
}
function flush() {
if (currentLines == 0)
return;
chunked.push(currentChunk.length == 1 ? currentChunk[0] : TextNode.from(currentChunk, currentLen));
currentLen = -1;
currentLines = currentChunk.length = 0;
}
for (let child of children)
add2(child);
flush();
return chunked.length == 1 ? chunked[0] : new TextNode(chunked, length);
}
}
Text.empty = /* @__PURE__ */ new TextLeaf([""], 0);
function textLength(text) {
let length = -1;
for (let line of text)
length += line.length + 1;
return length;
}
function appendText(text, target, from = 0, to = 1e9) {
for (let pos = 0, i2 = 0, first = true; i2 < text.length && pos <= to; i2++) {
let line = text[i2], end = pos + line.length;
if (end >= from) {
if (end > to)
line = line.slice(0, to - pos);
if (pos < from)
line = line.slice(from - pos);
if (first) {
target[target.length - 1] += line;
first = false;
} else
target.push(line);
}
pos = end + 1;
}
return target;
}
function sliceText(text, from, to) {
return appendText(text, [""], from, to);
}
class RawTextCursor {
constructor(text, dir = 1) {
this.dir = dir;
this.done = false;
this.lineBreak = false;
this.value = "";
this.nodes = [text];
this.offsets = [dir > 0 ? 1 : (text instanceof TextLeaf ? text.text.length : text.children.length) << 1];
}
nextInner(skip, dir) {
this.done = this.lineBreak = false;
for (; ; ) {
let last = this.nodes.length - 1;
let top2 = this.nodes[last], offsetValue = this.offsets[last], offset = offsetValue >> 1;
let size = top2 instanceof TextLeaf ? top2.text.length : top2.children.length;
if (offset == (dir > 0 ? size : 0)) {
if (last == 0) {
this.done = true;
this.value = "";
return this;
}
if (dir > 0)
this.offsets[last - 1]++;
this.nodes.pop();
this.offsets.pop();
} else if ((offsetValue & 1) == (dir > 0 ? 0 : 1)) {
this.offsets[last] += dir;
if (skip == 0) {
this.lineBreak = true;
this.value = "\n";
return this;
}
skip--;
} else if (top2 instanceof TextLeaf) {
let next = top2.text[offset + (dir < 0 ? -1 : 0)];
this.offsets[last] += dir;
if (next.length > Math.max(0, skip)) {
this.value = skip == 0 ? next : dir > 0 ? next.slice(skip) : next.slice(0, next.length - skip);
return this;
}
skip -= next.length;
} else {
let next = top2.children[offset + (dir < 0 ? -1 : 0)];
if (skip > next.length) {
skip -= next.length;
this.offsets[last] += dir;
} else {
if (dir < 0)
this.offsets[last]--;
this.nodes.push(next);
this.offsets.push(dir > 0 ? 1 : (next instanceof TextLeaf ? next.text.length : next.children.length) << 1);
}
}
}
}
next(skip = 0) {
if (skip < 0) {
this.nextInner(-skip, -this.dir);
skip = this.value.length;
}
return this.nextInner(skip, this.dir);
}
}
class PartialTextCursor {
constructor(text, start, end) {
this.value = "";
this.done = false;
this.cursor = new RawTextCursor(text, start > end ? -1 : 1);
this.pos = start > end ? text.length : 0;
this.from = Math.min(start, end);
this.to = Math.max(start, end);
}
nextInner(skip, dir) {
if (dir < 0 ? this.pos <= this.from : this.pos >= this.to) {
this.value = "";
this.done = true;
return this;
}
skip += Math.max(0, dir < 0 ? this.pos - this.to : this.from - this.pos);
let limit = dir < 0 ? this.pos - this.from : this.to - this.pos;
if (skip > limit)
skip = limit;
limit -= skip;
let { value } = this.cursor.next(skip);
this.pos += (value.length + skip) * dir;
this.value = value.length <= limit ? value : dir < 0 ? value.slice(value.length - limit) : value.slice(0, limit);
this.done = !this.value;
return this;
}
next(skip = 0) {
if (skip < 0)
skip = Math.max(skip, this.from - this.pos);
else if (skip > 0)
skip = Math.min(skip, this.to - this.pos);
return this.nextInner(skip, this.cursor.dir);
}
get lineBreak() {
return this.cursor.lineBreak && this.value != "";
}
}
class LineCursor {
constructor(inner) {
this.inner = inner;
this.afterBreak = true;
this.value = "";
this.done = false;
}
next(skip = 0) {
let { done, lineBreak, value } = this.inner.next(skip);
if (done && this.afterBreak) {
this.value = "";
this.afterBreak = false;
} else if (done) {
this.done = true;
this.value = "";
} else if (lineBreak) {
if (this.afterBreak) {
this.value = "";
} else {
this.afterBreak = true;
this.next();
}
} else {
this.value = value;
this.afterBreak = false;
}
return this;
}
get lineBreak() {
return false;
}
}
if (typeof Symbol != "undefined") {
Text.prototype[Symbol.iterator] = function() {
return this.iter();
};
RawTextCursor.prototype[Symbol.iterator] = PartialTextCursor.prototype[Symbol.iterator] = LineCursor.prototype[Symbol.iterator] = function() {
return this;
};
}
class Line {
/**
@internal
*/
constructor(from, to, number2, text) {
this.from = from;
this.to = to;
this.number = number2;
this.text = text;
}
/**
The length of the line (not including any line break after it).
*/
get length() {
return this.to - this.from;
}
}
function clip(text, from, to) {
from = Math.max(0, Math.min(text.length, from));
return [from, Math.max(from, Math.min(text.length, to))];
}
let extend = /* @__PURE__ */ "lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map((s) => s ? parseInt(s, 36) : 1);
for (let i2 = 1; i2 < extend.length; i2++)
extend[i2] += extend[i2 - 1];
function isExtendingChar(code2) {
for (let i2 = 1; i2 < extend.length; i2 += 2)
if (extend[i2] > code2)
return extend[i2 - 1] <= code2;
return false;
}
function isRegionalIndicator(code2) {
return code2 >= 127462 && code2 <= 127487;
}
const ZWJ = 8205;
function findClusterBreak(str, pos, forward = true, includeExtending = true) {
return (forward ? nextClusterBreak : prevClusterBreak)(str, pos, includeExtending);
}
function nextClusterBreak(str, pos, includeExtending) {
if (pos == str.length)
return pos;
if (pos && surrogateLow(str.charCodeAt(pos)) && surrogateHigh(str.charCodeAt(pos - 1)))
pos--;
let prev = codePointAt(str, pos);
pos += codePointSize(prev);
while (pos < str.length) {
let next = codePointAt(str, pos);
if (prev == ZWJ || next == ZWJ || includeExtending && isExtendingChar(next)) {
pos += codePointSize(next);
prev = next;
} else if (isRegionalIndicator(next)) {
let countBefore = 0, i2 = pos - 2;
while (i2 >= 0 && isRegionalIndicator(codePointAt(str, i2))) {
countBefore++;
i2 -= 2;
}
if (countBefore % 2 == 0)
break;
else
pos += 2;
} else {
break;
}
}
return pos;
}
function prevClusterBreak(str, pos, includeExtending) {
while (pos > 0) {
let found = nextClusterBreak(str, pos - 2, includeExtending);
if (found < pos)
return found;
pos--;
}
return 0;
}
function surrogateLow(ch) {
return ch >= 56320 && ch < 57344;
}
function surrogateHigh(ch) {
return ch >= 55296 && ch < 56320;
}
function codePointAt(str, pos) {
let code0 = str.charCodeAt(pos);
if (!surrogateHigh(code0) || pos + 1 == str.length)
return code0;
let code1 = str.charCodeAt(pos + 1);
if (!surrogateLow(code1))
return code0;
return (code0 - 55296 << 10) + (code1 - 56320) + 65536;
}
function fromCodePoint(code2) {
if (code2 <= 65535)
return String.fromCharCode(code2);
code2 -= 65536;
return String.fromCharCode((code2 >> 10) + 55296, (code2 & 1023) + 56320);
}
function codePointSize(code2) {
return code2 < 65536 ? 1 : 2;
}
const DefaultSplit = /\r\n?|\n/;
var MapMode = /* @__PURE__ */ function(MapMode2) {
MapMode2[MapMode2["Simple"] = 0] = "Simple";
MapMode2[MapMode2["TrackDel"] = 1] = "TrackDel";
MapMode2[MapMode2["TrackBefore"] = 2] = "TrackBefore";
MapMode2[MapMode2["TrackAfter"] = 3] = "TrackAfter";
return MapMode2;
}(MapMode || (MapMode = {}));
class ChangeDesc {
// Sections are encoded as pairs of integers. The first is the
// length in the current document, and the second is -1 for
// unaffected sections, and the length of the replacement content
// otherwise. So an insertion would be (0, n>0), a deletion (n>0,
// 0), and a replacement two positive numbers.
/**
@internal
*/
constructor(sections) {
this.sections = sections;
}
/**
The length of the document before the change.
*/
get length() {
let result2 = 0;
for (let i2 = 0; i2 < this.sections.length; i2 += 2)
result2 += this.sections[i2];
return result2;
}
/**
The length of the document after the change.
*/
get newLength() {
let result2 = 0;
for (let i2 = 0; i2 < this.sections.length; i2 += 2) {
let ins = this.sections[i2 + 1];
result2 += ins < 0 ? this.sections[i2] : ins;
}
return result2;
}
/**
False when there are actual changes in this set.
*/
get empty() {
return this.sections.length == 0 || this.sections.length == 2 && this.sections[1] < 0;
}
/**
Iterate over the unchanged parts left by these changes. `posA`
provides the position of the range in the old document, `posB`
the new position in the changed document.
*/
iterGaps(f) {
for (let i2 = 0, posA = 0, posB = 0; i2 < this.sections.length; ) {
let len = this.sections[i2++], ins = this.sections[i2++];
if (ins < 0) {
f(posA, posB, len);
posB += len;
} else {
posB += ins;
}
posA += len;
}
}
/**
Iterate over the ranges changed by these changes. (See
[`ChangeSet.iterChanges`](https://codemirror.net/6/docs/ref/#state.ChangeSet.iterChanges) for a
variant that also provides you with the inserted text.)
`fromA`/`toA` provides the extent of the change in the starting
document, `fromB`/`toB` the extent of the replacement in the
changed document.
When `individual` is true, adjacent changes (which are kept
separate for [position mapping](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) are
reported separately.
*/
iterChangedRanges(f, individual = false) {
iterChanges(this, f, individual);
}
/**
Get a description of the inverted form of these changes.
*/
get invertedDesc() {
let sections = [];
for (let i2 = 0; i2 < this.sections.length; ) {
let len = this.sections[i2++], ins = this.sections[i2++];
if (ins < 0)
sections.push(len, ins);
else
sections.push(ins, len);
}
return new ChangeDesc(sections);
}
/**
Compute the combined effect of applying another set of changes
after this one. The length of the document after this set should
match the length before `other`.
*/
composeDesc(other) {
return this.empty ? other : other.empty ? this : composeSets(this, other);
}
/**
Map this description, which should start with the same document
as `other`, over another set of changes, so that it can be
applied after it. When `before` is true, map as if the changes
in `other` happened before the ones in `this`.
*/
mapDesc(other, before = false) {
return other.empty ? this : mapSet(this, other, before);
}
mapPos(pos, assoc = -1, mode = MapMode.Simple) {
let posA = 0, posB = 0;
for (let i2 = 0; i2 < this.sections.length; ) {
let len = this.sections[i2++], ins = this.sections[i2++], endA = posA + len;
if (ins < 0) {
if (endA > pos)
return posB + (pos - posA);
posB += len;
} else {
if (mode != MapMode.Simple && endA >= pos && (mode == MapMode.TrackDel && posA < pos && endA > pos || mode == MapMode.TrackBefore && posA < pos || mode == MapMode.TrackAfter && endA > pos))
return null;
if (endA > pos || endA == pos && assoc < 0 && !len)
return pos == posA || assoc < 0 ? posB : posB + ins;
posB += ins;
}
posA = endA;
}
if (pos > posA)
throw new RangeError(`Position ${pos} is out of range for changeset of length ${posA}`);
return posB;
}
/**
Check whether these changes touch a given range. When one of the
changes entirely covers the range, the string `"cover"` is
returned.
*/
touchesRange(from, to = from) {
for (let i2 = 0, pos = 0; i2 < this.sections.length && pos <= to; ) {
let len = this.sections[i2++], ins = this.sections[i2++], end = pos + len;
if (ins >= 0 && pos <= to && end >= from)
return pos < from && end > to ? "cover" : true;
pos = end;
}
return false;
}
/**
@internal
*/
toString() {
let result2 = "";
for (let i2 = 0; i2 < this.sections.length; ) {
let len = this.sections[i2++], ins = this.sections[i2++];
result2 += (result2 ? " " : "") + len + (ins >= 0 ? ":" + ins : "");
}
return result2;
}
/**
Serialize this change desc to a JSON-representable value.
*/
toJSON() {
return this.sections;
}
/**
Create a change desc from its JSON representation (as produced
by [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeDesc.toJSON).
*/
static fromJSON(json) {
if (!Array.isArray(json) || json.length % 2 || json.some((a) => typeof a != "number"))
throw new RangeError("Invalid JSON representation of ChangeDesc");
return new ChangeDesc(json);
}
/**
@internal
*/
static create(sections) {
return new ChangeDesc(sections);
}
}
class ChangeSet extends ChangeDesc {
constructor(sections, inserted) {
super(sections);
this.inserted = inserted;
}
/**
Apply the changes to a document, returning the modified
document.
*/
apply(doc2) {
if (this.length != doc2.length)
throw new RangeError("Applying change set to a document with the wrong length");
iterChanges(this, (fromA, toA, fromB, _toB, text) => doc2 = doc2.replace(fromB, fromB + (toA - fromA), text), false);
return doc2;
}
mapDesc(other, before = false) {
return mapSet(this, other, before, true);
}
/**
Given the document as it existed _before_ the changes, return a
change set that represents the inverse of this set, which could
be used to go from the document created by the changes back to
the document as it existed before the changes.
*/
invert(doc2) {
let sections = this.sections.slice(), inserted = [];
for (let i2 = 0, pos = 0; i2 < sections.length; i2 += 2) {
let len = sections[i2], ins = sections[i2 + 1];
if (ins >= 0) {
sections[i2] = ins;
sections[i2 + 1] = len;
let index = i2 >> 1;
while (inserted.length < index)
inserted.push(Text.empty);
inserted.push(len ? doc2.slice(pos, pos + len) : Text.empty);
}
pos += len;
}
return new ChangeSet(sections, inserted);
}
/**
Combine two subsequent change sets into a single set. `other`
must start in the document produced by `this`. If `this` goes
`docA` → `docB` and `other` represents `docB` → `docC`, the
returned value will represent the change `docA` → `docC`.
*/
compose(other) {
return this.empty ? other : other.empty ? this : composeSets(this, other, true);
}
/**
Given another change set starting in the same document, maps this
change set over the other, producing a new change set that can be
applied to the document produced by applying `other`. When
`before` is `true`, order changes as if `this` comes before
`other`, otherwise (the default) treat `other` as coming first.
Given two changes `A` and `B`, `A.compose(B.map(A))` and
`B.compose(A.map(B, true))` will produce the same document. This
provides a basic form of [operational
transformation](https://en.wikipedia.org/wiki/Operational_transformation),
and can be used for collaborative editing.
*/
map(other, before = false) {
return other.empty ? this : mapSet(this, other, before, true);
}
/**
Iterate over the changed ranges in the document, calling `f` for
each, with the range in the original document (`fromA`-`toA`)
and the range that replaces it in the new document
(`fromB`-`toB`).
When `individual` is true, adjacent changes are reported
separately.
*/
iterChanges(f, individual = false) {
iterChanges(this, f, individual);
}
/**
Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change
set.
*/
get desc() {
return ChangeDesc.create(this.sections);
}
/**
@internal
*/
filter(ranges) {
let resultSections = [], resultInserted = [], filteredSections = [];
let iter = new SectionIter(this);
done:
for (let i2 = 0, pos = 0; ; ) {
let next = i2 == ranges.length ? 1e9 : ranges[i2++];
while (pos < next || pos == next && iter.len == 0) {
if (iter.done)
break done;
let len = Math.min(iter.len, next - pos);
addSection(filteredSections, len, -1);
let ins = iter.ins == -1 ? -1 : iter.off == 0 ? iter.ins : 0;
addSection(resultSections, len, ins);
if (ins > 0)
addInsert(resultInserted, resultSections, iter.text);
iter.forward(len);
pos += len;
}
let end = ranges[i2++];
while (pos < end) {
if (iter.done)
break done;
let len = Math.min(iter.len, end - pos);
addSection(resultSections, len, -1);
addSection(filteredSections, len, iter.ins == -1 ? -1 : iter.off == 0 ? iter.ins : 0);
iter.forward(len);
pos += len;
}
}
return {
changes: new ChangeSet(resultSections, resultInserted),
filtered: ChangeDesc.create(filteredSections)
};
}
/**
Serialize this change set to a JSON-representable value.
*/
toJSON() {
let parts = [];
for (let i2 = 0; i2 < this.sections.length; i2 += 2) {
let len = this.sections[i2], ins = this.sections[i2 + 1];
if (ins < 0)
parts.push(len);
else if (ins == 0)
parts.push([len]);
else
parts.push([len].concat(this.inserted[i2 >> 1].toJSON()));
}
return parts;
}
/**
Create a change set for the given changes, for a document of the
given length, using `lineSep` as line separator.
*/
static of(changes, length, lineSep) {
let sections = [], inserted = [], pos = 0;
let total = null;
function flush(force = false) {
if (!force && !sections.length)
return;
if (pos < length)
addSection(sections, length - pos, -1);
let set = new ChangeSet(sections, inserted);
total = total ? total.compose(set.map(total)) : set;
sections = [];
inserted = [];
pos = 0;
}
function process2(spec) {
if (Array.isArray(spec)) {
for (let sub of spec)
process2(sub);
} else if (spec instanceof ChangeSet) {
if (spec.length != length)
throw new RangeError(`Mismatched change set length (got ${spec.length}, expected ${length})`);
flush();
total = total ? total.compose(spec.map(total)) : spec;
} else {
let { from, to = from, insert: insert2 } = spec;
if (from > to || from < 0 || to > length)
throw new RangeError(`Invalid change range ${from} to ${to} (in doc of length ${length})`);
let insText = !insert2 ? Text.empty : typeof insert2 == "string" ? Text.of(insert2.split(lineSep || DefaultSplit)) : insert2;
let insLen = insText.length;
if (from == to && insLen == 0)
return;
if (from < pos)
flush();
if (from > pos)
addSection(sections, from - pos, -1);
addSection(sections, to - from, insLen);
addInsert(inserted, sections, insText);
pos = to;
}
}
process2(changes);
flush(!total);
return total;
}
/**
Create an empty changeset of the given length.
*/
static empty(length) {
return new ChangeSet(length ? [length, -1] : [], []);
}
/**
Create a changeset from its JSON representation (as produced by
[`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeSet.toJSON).
*/
static fromJSON(json) {
if (!Array.isArray(json))
throw new RangeError("Invalid JSON representation of ChangeSet");
let sections = [], inserted = [];
for (let i2 = 0; i2 < json.length; i2++) {
let part = json[i2];
if (typeof part == "number") {
sections.push(part, -1);
} else if (!Array.isArray(part) || typeof part[0] != "number" || part.some((e, i3) => i3 && typeof e != "string")) {
throw new RangeError("Invalid JSON representation of ChangeSet");
} else if (part.length == 1) {
sections.push(part[0], 0);
} else {
while (inserted.length < i2)
inserted.push(Text.empty);
inserted[i2] = Text.of(part.slice(1));
sections.push(part[0], inserted[i2].length);
}
}
return new ChangeSet(sections, inserted);
}
/**
@internal
*/
static createSet(sections, inserted) {
return new ChangeSet(sections, inserted);
}
}
function addSection(sections, len, ins, forceJoin = false) {
if (len == 0 && ins <= 0)
return;
let last = sections.length - 2;
if (last >= 0 && ins <= 0 && ins == sections[last + 1])
sections[last] += len;
else if (len == 0 && sections[last] == 0)
sections[last + 1] += ins;
else if (forceJoin) {
sections[last] += len;
sections[last + 1] += ins;
} else
sections.push(len, ins);
}
function addInsert(values, sections, value) {
if (value.length == 0)
return;
let index = sections.length - 2 >> 1;
if (index < values.length) {
values[values.length - 1] = values[values.length - 1].append(value);
} else {
while (values.length < index)
values.push(Text.empty);
values.push(value);
}
}
function iterChanges(desc, f, individual) {
let inserted = desc.inserted;
for (let posA = 0, posB = 0, i2 = 0; i2 < desc.sections.length; ) {
let len = desc.sections[i2++], ins = desc.sections[i2++];
if (ins < 0) {
posA += len;
posB += len;
} else {
let endA = posA, endB = posB, text = Text.empty;
for (; ; ) {
endA += len;
endB += ins;
if (ins && inserted)
text = text.append(inserted[i2 - 2 >> 1]);
if (individual || i2 == desc.sections.length || desc.sections[i2 + 1] < 0)
break;
len = desc.sections[i2++];
ins = desc.sections[i2++];
}
f(posA, endA, posB, endB, text);
posA = endA;
posB = endB;
}
}
}
function mapSet(setA, setB, before, mkSet = false) {
let sections = [], insert2 = mkSet ? [] : null;
let a = new SectionIter(setA), b = new SectionIter(setB);
for (let inserted = -1; ; ) {
if (a.ins == -1 && b.ins == -1) {
let len = Math.min(a.len, b.len);
addSection(sections, len, -1);
a.forward(len);
b.forward(len);
} else if (b.ins >= 0 && (a.ins < 0 || inserted == a.i || a.off == 0 && (b.len < a.len || b.len == a.len && !before))) {
let len = b.len;
addSection(sections, b.ins, -1);
while (len) {
let piece = Math.min(a.len, len);
if (a.ins >= 0 && inserted < a.i && a.len <= piece) {
addSection(sections, 0, a.ins);
if (insert2)
addInsert(insert2, sections, a.text);
inserted = a.i;
}
a.forward(piece);
len -= piece;
}
b.next();
} else if (a.ins >= 0) {
let len = 0, left = a.len;
while (left) {
if (b.ins == -1) {
let piece = Math.min(left, b.len);
len += piece;
left -= piece;
b.forward(piece);
} else if (b.ins == 0 && b.len < left) {
left -= b.len;
b.next();
} else {
break;
}
}
addSection(sections, len, inserted < a.i ? a.ins : 0);
if (insert2 && inserted < a.i)
addInsert(insert2, sections, a.text);
inserted = a.i;
a.forward(a.len - left);
} else if (a.done && b.done) {
return insert2 ? ChangeSet.createSet(sections, insert2) : ChangeDesc.create(sections);
} else {
throw new Error("Mismatched change set lengths");
}
}
}
function composeSets(setA, setB, mkSet = false) {
let sections = [];
let insert2 = mkSet ? [] : null;
let a = new SectionIter(setA), b = new SectionIter(setB);
for (let open = false; ; ) {
if (a.done && b.done) {
return insert2 ? ChangeSet.createSet(sections, insert2) : ChangeDesc.create(sections);
} else if (a.ins == 0) {
addSection(sections, a.len, 0, open);
a.next();
} else if (b.len == 0 && !b.done) {
addSection(sections, 0, b.ins, open);
if (insert2)
addInsert(insert2, sections, b.text);
b.next();
} else if (a.done || b.done) {
throw new Error("Mismatched change set lengths");
} else {
let len = Math.min(a.len2, b.len), sectionLen = sections.length;
if (a.ins == -1) {
let insB = b.ins == -1 ? -1 : b.off ? 0 : b.ins;
addSection(sections, len, insB, open);
if (insert2 && insB)
addInsert(insert2, sections, b.text);
} else if (b.ins == -1) {
addSection(sections, a.off ? 0 : a.len, len, open);
if (insert2)
addInsert(insert2, sections, a.textBit(len));
} else {
addSection(sections, a.off ? 0 : a.len, b.off ? 0 : b.ins, open);
if (insert2 && !b.off)
addInsert(insert2, sections, b.text);
}
open = (a.ins > len || b.ins >= 0 && b.len > len) && (open || sections.length > sectionLen);
a.forward2(len);
b.forward(len);
}
}
}
class SectionIter {
constructor(set) {
this.set = set;
this.i = 0;
this.next();
}
next() {
let { sections } = this.set;
if (this.i < sections.length) {
this.len = sections[this.i++];
this.ins = sections[this.i++];
} else {
this.len = 0;
this.ins = -2;
}
this.off = 0;
}
get done() {
return this.ins == -2;
}
get len2() {
return this.ins < 0 ? this.len : this.ins;
}
get text() {
let { inserted } = this.set, index = this.i - 2 >> 1;
return index >= inserted.length ? Text.empty : inserted[index];
}
textBit(len) {
let { inserted } = this.set, index = this.i - 2 >> 1;
return index >= inserted.length && !len ? Text.empty : inserted[index].slice(this.off, len == null ? void 0 : this.off + len);
}
forward(len) {
if (len == this.len)
this.next();
else {
this.len -= len;
this.off += len;
}
}
forward2(len) {
if (this.ins == -1)
this.forward(len);
else if (len == this.ins)
this.next();
else {
this.ins -= len;
this.off += len;
}
}
}
class SelectionRange {
constructor(from, to, flags) {
this.from = from;
this.to = to;
this.flags = flags;
}
/**
The anchor of the range—the side that doesn't move when you
extend it.
*/
get anchor() {
return this.flags & 32 ? this.to : this.from;
}
/**
The head of the range, which is moved when the range is
[extended](https://codemirror.net/6/docs/ref/#state.SelectionRange.extend).
*/
get head() {
return this.flags & 32 ? this.from : this.to;
}
/**
True when `anchor` and `head` are at the same position.
*/
get empty() {
return this.from == this.to;
}
/**
If this is a cursor that is explicitly associated with the
character on one of its sides, this returns the side. -1 means
the character before its position, 1 the character after, and 0
means no association.
*/
get assoc() {
return this.flags & 8 ? -1 : this.flags & 16 ? 1 : 0;
}
/**
The bidirectional text level associated with this cursor, if
any.
*/
get bidiLevel() {
let level = this.flags & 7;
return level == 7 ? null : level;
}
/**
The goal column (stored vertical offset) associated with a
cursor. This is used to preserve the vertical position when
[moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
lines of different length.
*/
get goalColumn() {
let value = this.flags >> 6;
return value == 16777215 ? void 0 : value;
}
/**
Map this range through a change, producing a valid range in the
updated document.
*/
map(change, assoc = -1) {
let from, to;
if (this.empty) {
from = to = change.mapPos(this.from, assoc);
} else {
from = change.mapPos(this.from, 1);
to = change.mapPos(this.to, -1);
}
return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags);
}
/**
Extend this range to cover at least `from` to `to`.
*/
extend(from, to = from) {
if (from <= this.anchor && to >= this.anchor)
return EditorSelection.range(from, to);
let head = Math.abs(from - this.anchor) > Math.abs(to - this.anchor) ? from : to;
return EditorSelection.range(this.anchor, head);
}
/**
Compare this range to another range.
*/
eq(other, includeAssoc = false) {
return this.anchor == other.anchor && this.head == other.head && (!includeAssoc || !this.empty || this.assoc == other.assoc);
}
/**
Return a JSON-serializable object representing the range.
*/
toJSON() {
return { anchor: this.anchor, head: this.head };
}
/**
Convert a JSON representation of a range to a `SelectionRange`
instance.
*/
static fromJSON(json) {
if (!json || typeof json.anchor != "number" || typeof json.head != "number")
throw new RangeError("Invalid JSON representation for SelectionRange");
return EditorSelection.range(json.anchor, json.head);
}
/**
@internal
*/
static create(from, to, flags) {
return new SelectionRange(from, to, flags);
}
}
class EditorSelection {
constructor(ranges, mainIndex) {
this.ranges = ranges;
this.mainIndex = mainIndex;
}
/**
Map a selection through a change. Used to adjust the selection
position for changes.
*/
map(change, assoc = -1) {
if (change.empty)
return this;
return EditorSelection.create(this.ranges.map((r) => r.map(change, assoc)), this.mainIndex);
}
/**
Compare this selection to another selection. By default, ranges
are compared only by position. When `includeAssoc` is true,
cursor ranges must also have the same
[`assoc`](https://codemirror.net/6/docs/ref/#state.SelectionRange.assoc) value.
*/
eq(other, includeAssoc = false) {
if (this.ranges.length != other.ranges.length || this.mainIndex != other.mainIndex)
return false;
for (let i2 = 0; i2 < this.ranges.length; i2++)
if (!this.ranges[i2].eq(other.ranges[i2], includeAssoc))
return false;
return true;
}
/**
Get the primary selection range. Usually, you should make sure
your code applies to _all_ ranges, by using methods like
[`changeByRange`](https://codemirror.net/6/docs/ref/#state.EditorState.changeByRange).
*/
get main() {
return this.ranges[this.mainIndex];
}
/**
Make sure the selection only has one range. Returns a selection
holding only the main range from this selection.
*/
asSingle() {
return this.ranges.length == 1 ? this : new EditorSelection([this.main], 0);
}
/**
Extend this selection with an extra range.
*/
addRange(range, main = true) {
return EditorSelection.create([range].concat(this.ranges), main ? 0 : this.mainIndex + 1);
}
/**
Replace a given range with another range, and then normalize the
selection to merge and sort ranges if necessary.
*/
replaceRange(range, which = this.mainIndex) {
let ranges = this.ranges.slice();
ranges[which] = range;
return EditorSelection.create(ranges, this.mainIndex);
}
/**
Convert this selection to an object that can be serialized to
JSON.
*/
toJSON() {
return { ranges: this.ranges.map((r) => r.toJSON()), main: this.mainIndex };
}
/**
Create a selection from a JSON representation.
*/
static fromJSON(json) {
if (!json || !Array.isArray(json.ranges) || typeof json.main != "number" || json.main >= json.ranges.length)
throw new RangeError("Invalid JSON representation for EditorSelection");
return new EditorSelection(json.ranges.map((r) => SelectionRange.fromJSON(r)), json.main);
}
/**
Create a selection holding a single range.
*/
static single(anchor, head = anchor) {
return new EditorSelection([EditorSelection.range(anchor, head)], 0);
}
/**
Sort and merge the given set of ranges, creating a valid
selection.
*/
static create(ranges, mainIndex = 0) {
if (ranges.length == 0)
throw new RangeError("A selection needs at least one range");
for (let pos = 0, i2 = 0; i2 < ranges.length; i2++) {
let range = ranges[i2];
if (range.empty ? range.from <= pos : range.from < pos)
return EditorSelection.normalized(ranges.slice(), mainIndex);
pos = range.to;
}
return new EditorSelection(ranges, mainIndex);
}
/**
Create a cursor selection range at the given position. You can
safely ignore the optional arguments in most situations.
*/
static cursor(pos, assoc = 0, bidiLevel, goalColumn) {
return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 8 : 16) | (bidiLevel == null ? 7 : Math.min(6, bidiLevel)) | (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215) << 6);
}
/**
Create a selection range.
*/
static range(anchor, head, goalColumn, bidiLevel) {
let flags = (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215) << 6 | (bidiLevel == null ? 7 : Math.min(6, bidiLevel));
return head < anchor ? SelectionRange.create(head, anchor, 32 | 16 | flags) : SelectionRange.create(anchor, head, (head > anchor ? 8 : 0) | flags);
}
/**
@internal
*/
static normalized(ranges, mainIndex = 0) {
let main = ranges[mainIndex];
ranges.sort((a, b) => a.from - b.from);
mainIndex = ranges.indexOf(main);
for (let i2 = 1; i2 < ranges.length; i2++) {
let range = ranges[i2], prev = ranges[i2 - 1];
if (range.empty ? range.from <= prev.to : range.from < prev.to) {
let from = prev.from, to = Math.max(range.to, prev.to);
if (i2 <= mainIndex)
mainIndex--;
ranges.splice(--i2, 2, range.anchor > range.head ? EditorSelection.range(to, from) : EditorSelection.range(from, to));
}
}
return new EditorSelection(ranges, mainIndex);
}
}
function checkSelection(selection, docLength) {
for (let range of selection.ranges)
if (range.to > docLength)
throw new RangeError("Selection points outside of document");
}
let nextID = 0;
class Facet {
constructor(combine, compareInput, compare2, isStatic, enables) {
this.combine = combine;
this.compareInput = compareInput;
this.compare = compare2;
this.isStatic = isStatic;
this.id = nextID++;
this.default = combine([]);
this.extensions = typeof enables == "function" ? enables(this) : enables;
}
/**
Returns a facet reader for this facet, which can be used to
[read](https://codemirror.net/6/docs/ref/#state.EditorState.facet) it but not to define values for it.
*/
get reader() {
return this;
}
/**
Define a new facet.
*/
static define(config2 = {}) {
return new Facet(config2.combine || ((a) => a), config2.compareInput || ((a, b) => a === b), config2.compare || (!config2.combine ? sameArray$1 : (a, b) => a === b), !!config2.static, config2.enables);
}
/**
Returns an extension that adds the given value to this facet.
*/
of(value) {
return new FacetProvider([], this, 0, value);
}
/**
Create an extension that computes a value for the facet from a
state. You must take care to declare the parts of the state that
this value depends on, since your function is only called again
for a new state when one of those parts changed.
In cases where your value depends only on a single field, you'll
want to use the [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method instead.
*/
compute(deps, get) {
if (this.isStatic)
throw new Error("Can't compute a static facet");
return new FacetProvider(deps, this, 1, get);
}
/**
Create an extension that computes zero or more values for this
facet from a state.
*/
computeN(deps, get) {
if (this.isStatic)
throw new Error("Can't compute a static facet");
return new FacetProvider(deps, this, 2, get);
}
from(field, get) {
if (!get)
get = (x2) => x2;
return this.compute([field], (state) => get(state.field(field)));
}
}
function sameArray$1(a, b) {
return a == b || a.length == b.length && a.every((e, i2) => e === b[i2]);
}
class FacetProvider {
constructor(dependencies, facet, type, value) {
this.dependencies = dependencies;
this.facet = facet;
this.type = type;
this.value = value;
this.id = nextID++;
}
dynamicSlot(addresses) {
var _a2;
let getter = this.value;
let compare2 = this.facet.compareInput;
let id2 = this.id, idx = addresses[id2] >> 1, multi = this.type == 2;
let depDoc = false, depSel = false, depAddrs = [];
for (let dep of this.dependencies) {
if (dep == "doc")
depDoc = true;
else if (dep == "selection")
depSel = true;
else if ((((_a2 = addresses[dep.id]) !== null && _a2 !== void 0 ? _a2 : 1) & 1) == 0)
depAddrs.push(addresses[dep.id]);
}
return {
create(state) {
state.values[idx] = getter(state);
return 1;
},
update(state, tr) {
if (depDoc && tr.docChanged || depSel && (tr.docChanged || tr.selection) || ensureAll(state, depAddrs)) {
let newVal = getter(state);
if (multi ? !compareArray(newVal, state.values[idx], compare2) : !compare2(newVal, state.values[idx])) {
state.values[idx] = newVal;
return 1;
}
}
return 0;
},
reconfigure: (state, oldState) => {
let newVal, oldAddr = oldState.config.address[id2];
if (oldAddr != null) {
let oldVal = getAddr(oldState, oldAddr);
if (this.dependencies.every((dep) => {
return dep instanceof Facet ? oldState.facet(dep) === state.facet(dep) : dep instanceof StateField ? oldState.field(dep, false) == state.field(dep, false) : true;
}) || (multi ? compareArray(newVal = getter(state), oldVal, compare2) : compare2(newVal = getter(state), oldVal))) {
state.values[idx] = oldVal;
return 0;
}
} else {
newVal = getter(state);
}
state.values[idx] = newVal;
return 1;
}
};
}
}
function compareArray(a, b, compare2) {
if (a.length != b.length)
return false;
for (let i2 = 0; i2 < a.length; i2++)
if (!compare2(a[i2], b[i2]))
return false;
return true;
}
function ensureAll(state, addrs) {
let changed = false;
for (let addr of addrs)
if (ensureAddr(state, addr) & 1)
changed = true;
return changed;
}
function dynamicFacetSlot(addresses, facet, providers) {
let providerAddrs = providers.map((p) => addresses[p.id]);
let providerTypes = providers.map((p) => p.type);
let dynamic = providerAddrs.filter((p) => !(p & 1));
let idx = addresses[facet.id] >> 1;
function get(state) {
let values = [];
for (let i2 = 0; i2 < providerAddrs.length; i2++) {
let value = getAddr(state, providerAddrs[i2]);
if (providerTypes[i2] == 2)
for (let val of value)
values.push(val);
else
values.push(value);
}
return facet.combine(values);
}
return {
create(state) {
for (let addr of providerAddrs)
ensureAddr(state, addr);
state.values[idx] = get(state);
return 1;
},
update(state, tr) {
if (!ensureAll(state, dynamic))
return 0;
let value = get(state);
if (facet.compare(value, state.values[idx]))
return 0;
state.values[idx] = value;
return 1;
},
reconfigure(state, oldState) {
let depChanged = ensureAll(state, providerAddrs);
let oldProviders = oldState.config.facets[facet.id], oldValue = oldState.facet(facet);
if (oldProviders && !depChanged && sameArray$1(providers, oldProviders)) {
state.values[idx] = oldValue;
return 0;
}
let value = get(state);
if (facet.compare(value, oldValue)) {
state.values[idx] = oldValue;
return 0;
}
state.values[idx] = value;
return 1;
}
};
}
const initField = /* @__PURE__ */ Facet.define({ static: true });
class StateField {
constructor(id2, createF, updateF, compareF, spec) {
this.id = id2;
this.createF = createF;
this.updateF = updateF;
this.compareF = compareF;
this.spec = spec;
this.provides = void 0;
}
/**
Define a state field.
*/
static define(config2) {
let field = new StateField(nextID++, config2.create, config2.update, config2.compare || ((a, b) => a === b), config2);
if (config2.provide)
field.provides = config2.provide(field);
return field;
}
create(state) {
let init2 = state.facet(initField).find((i2) => i2.field == this);
return ((init2 === null || init2 === void 0 ? void 0 : init2.create) || this.createF)(state);
}
/**
@internal
*/
slot(addresses) {
let idx = addresses[this.id] >> 1;
return {
create: (state) => {
state.values[idx] = this.create(state);
return 1;
},
update: (state, tr) => {
let oldVal = state.values[idx];
let value = this.updateF(oldVal, tr);
if (this.compareF(oldVal, value))
return 0;
state.values[idx] = value;
return 1;
},
reconfigure: (state, oldState) => {
if (oldState.config.address[this.id] != null) {
state.values[idx] = oldState.field(this);
return 0;
}
state.values[idx] = this.create(state);
return 1;
}
};
}
/**
Returns an extension that enables this field and overrides the
way it is initialized. Can be useful when you need to provide a
non-default starting value for the field.
*/
init(create) {
return [this, initField.of({ field: this, create })];
}
/**
State field instances can be used as
[`Extension`](https://codemirror.net/6/docs/ref/#state.Extension) values to enable the field in a
given state.
*/
get extension() {
return this;
}
}
const Prec_ = { lowest: 4, low: 3, default: 2, high: 1, highest: 0 };
function prec(value) {
return (ext) => new PrecExtension(ext, value);
}
const Prec = {
/**
The highest precedence level, for extensions that should end up
near the start of the precedence ordering.
*/
highest: /* @__PURE__ */ prec(Prec_.highest),
/**
A higher-than-default precedence, for extensions that should
come before those with default precedence.
*/
high: /* @__PURE__ */ prec(Prec_.high),
/**
The default precedence, which is also used for extensions
without an explicit precedence.
*/
default: /* @__PURE__ */ prec(Prec_.default),
/**
A lower-than-default precedence.
*/
low: /* @__PURE__ */ prec(Prec_.low),
/**
The lowest precedence level. Meant for things that should end up
near the end of the extension order.
*/
lowest: /* @__PURE__ */ prec(Prec_.lowest)
};
class PrecExtension {
constructor(inner, prec2) {
this.inner = inner;
this.prec = prec2;
}
}
class Compartment {
/**
Create an instance of this compartment to add to your [state
configuration](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions).
*/
of(ext) {
return new CompartmentInstance(this, ext);
}
/**
Create an [effect](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) that
reconfigures this compartment.
*/
reconfigure(content2) {
return Compartment.reconfigure.of({ compartment: this, extension: content2 });
}
/**
Get the current content of the compartment in the state, or
`undefined` if it isn't present.
*/
get(state) {
return state.config.compartments.get(this);
}
}
class CompartmentInstance {
constructor(compartment, inner) {
this.compartment = compartment;
this.inner = inner;
}
}
class Configuration {
constructor(base2, compartments, dynamicSlots, address, staticValues, facets) {
this.base = base2;
this.compartments = compartments;
this.dynamicSlots = dynamicSlots;
this.address = address;
this.staticValues = staticValues;
this.facets = facets;
this.statusTemplate = [];
while (this.statusTemplate.length < dynamicSlots.length)
this.statusTemplate.push(
0
/* SlotStatus.Unresolved */
);
}
staticFacet(facet) {
let addr = this.address[facet.id];
return addr == null ? facet.default : this.staticValues[addr >> 1];
}
static resolve(base2, compartments, oldState) {
let fields = [];
let facets = /* @__PURE__ */ Object.create(null);
let newCompartments = /* @__PURE__ */ new Map();
for (let ext of flatten(base2, compartments, newCompartments)) {
if (ext instanceof StateField)
fields.push(ext);
else
(facets[ext.facet.id] || (facets[ext.facet.id] = [])).push(ext);
}
let address = /* @__PURE__ */ Object.create(null);
let staticValues = [];
let dynamicSlots = [];
for (let field of fields) {
address[field.id] = dynamicSlots.length << 1;
dynamicSlots.push((a) => field.slot(a));
}
let oldFacets = oldState === null || oldState === void 0 ? void 0 : oldState.config.facets;
for (let id2 in facets) {
let providers = facets[id2], facet = providers[0].facet;
let oldProviders = oldFacets && oldFacets[id2] || [];
if (providers.every(
(p) => p.type == 0
/* Provider.Static */
)) {
address[facet.id] = staticValues.length << 1 | 1;
if (sameArray$1(oldProviders, providers)) {
staticValues.push(oldState.facet(facet));
} else {
let value = facet.combine(providers.map((p) => p.value));
staticValues.push(oldState && facet.compare(value, oldState.facet(facet)) ? oldState.facet(facet) : value);
}
} else {
for (let p of providers) {
if (p.type == 0) {
address[p.id] = staticValues.length << 1 | 1;
staticValues.push(p.value);
} else {
address[p.id] = dynamicSlots.length << 1;
dynamicSlots.push((a) => p.dynamicSlot(a));
}
}
address[facet.id] = dynamicSlots.length << 1;
dynamicSlots.push((a) => dynamicFacetSlot(a, facet, providers));
}
}
let dynamic = dynamicSlots.map((f) => f(address));
return new Configuration(base2, newCompartments, dynamic, address, staticValues, facets);
}
}
function flatten(extension, compartments, newCompartments) {
let result2 = [[], [], [], [], []];
let seen = /* @__PURE__ */ new Map();
function inner(ext, prec2) {
let known = seen.get(ext);
if (known != null) {
if (known <= prec2)
return;
let found = result2[known].indexOf(ext);
if (found > -1)
result2[known].splice(found, 1);
if (ext instanceof CompartmentInstance)
newCompartments.delete(ext.compartment);
}
seen.set(ext, prec2);
if (Array.isArray(ext)) {
for (let e of ext)
inner(e, prec2);
} else if (ext instanceof CompartmentInstance) {
if (newCompartments.has(ext.compartment))
throw new RangeError(`Duplicate use of compartment in extensions`);
let content2 = compartments.get(ext.compartment) || ext.inner;
newCompartments.set(ext.compartment, content2);
inner(content2, prec2);
} else if (ext instanceof PrecExtension) {
inner(ext.inner, ext.prec);
} else if (ext instanceof StateField) {
result2[prec2].push(ext);
if (ext.provides)
inner(ext.provides, prec2);
} else if (ext instanceof FacetProvider) {
result2[prec2].push(ext);
if (ext.facet.extensions)
inner(ext.facet.extensions, Prec_.default);
} else {
let content2 = ext.extension;
if (!content2)
throw new Error(`Unrecognized extension value in extension set (${ext}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);
inner(content2, prec2);
}
}
inner(extension, Prec_.default);
return result2.reduce((a, b) => a.concat(b));
}
function ensureAddr(state, addr) {
if (addr & 1)
return 2;
let idx = addr >> 1;
let status = state.status[idx];
if (status == 4)
throw new Error("Cyclic dependency between fields and/or facets");
if (status & 2)
return status;
state.status[idx] = 4;
let changed = state.computeSlot(state, state.config.dynamicSlots[idx]);
return state.status[idx] = 2 | changed;
}
function getAddr(state, addr) {
return addr & 1 ? state.config.staticValues[addr >> 1] : state.values[addr >> 1];
}
const languageData = /* @__PURE__ */ Facet.define();
const allowMultipleSelections = /* @__PURE__ */ Facet.define({
combine: (values) => values.some((v) => v),
static: true
});
const lineSeparator = /* @__PURE__ */ Facet.define({
combine: (values) => values.length ? values[0] : void 0,
static: true
});
const changeFilter = /* @__PURE__ */ Facet.define();
const transactionFilter = /* @__PURE__ */ Facet.define();
const transactionExtender = /* @__PURE__ */ Facet.define();
const readOnly = /* @__PURE__ */ Facet.define({
combine: (values) => values.length ? values[0] : false
});
class Annotation {
/**
@internal
*/
constructor(type, value) {
this.type = type;
this.value = value;
}
/**
Define a new type of annotation.
*/
static define() {
return new AnnotationType();
}
}
class AnnotationType {
/**
Create an instance of this annotation.
*/
of(value) {
return new Annotation(this, value);
}
}
class StateEffectType {
/**
@internal
*/
constructor(map) {
this.map = map;
}
/**
Create a [state effect](https://codemirror.net/6/docs/ref/#state.StateEffect) instance of this
type.
*/
of(value) {
return new StateEffect(this, value);
}
}
class StateEffect {
/**
@internal
*/
constructor(type, value) {
this.type = type;
this.value = value;
}
/**
Map this effect through a position mapping. Will return
`undefined` when that ends up deleting the effect.
*/
map(mapping) {
let mapped = this.type.map(this.value, mapping);
return mapped === void 0 ? void 0 : mapped == this.value ? this : new StateEffect(this.type, mapped);
}
/**
Tells you whether this effect object is of a given
[type](https://codemirror.net/6/docs/ref/#state.StateEffectType).
*/
is(type) {
return this.type == type;
}
/**
Define a new effect type. The type parameter indicates the type
of values that his effect holds. It should be a type that
doesn't include `undefined`, since that is used in
[mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is
removed.
*/
static define(spec = {}) {
return new StateEffectType(spec.map || ((v) => v));
}
/**
Map an array of effects through a change set.
*/
static mapEffects(effects, mapping) {
if (!effects.length)
return effects;
let result2 = [];
for (let effect of effects) {
let mapped = effect.map(mapping);
if (mapped)
result2.push(mapped);
}
return result2;
}
}
StateEffect.reconfigure = /* @__PURE__ */ StateEffect.define();
StateEffect.appendConfig = /* @__PURE__ */ StateEffect.define();
class Transaction {
constructor(startState, changes, selection, effects, annotations, scrollIntoView2) {
this.startState = startState;
this.changes = changes;
this.selection = selection;
this.effects = effects;
this.annotations = annotations;
this.scrollIntoView = scrollIntoView2;
this._doc = null;
this._state = null;
if (selection)
checkSelection(selection, changes.newLength);
if (!annotations.some((a) => a.type == Transaction.time))
this.annotations = annotations.concat(Transaction.time.of(Date.now()));
}
/**
@internal
*/
static create(startState, changes, selection, effects, annotations, scrollIntoView2) {
return new Transaction(startState, changes, selection, effects, annotations, scrollIntoView2);
}
/**
The new document produced by the transaction. Contrary to
[`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't
force the entire new state to be computed right away, so it is
recommended that [transaction
filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) use this getter
when they need to look at the new document.
*/
get newDoc() {
return this._doc || (this._doc = this.changes.apply(this.startState.doc));
}
/**
The new selection produced by the transaction. If
[`this.selection`](https://codemirror.net/6/docs/ref/#state.Transaction.selection) is undefined,
this will [map](https://codemirror.net/6/docs/ref/#state.EditorSelection.map) the start state's
current selection through the changes made by the transaction.
*/
get newSelection() {
return this.selection || this.startState.selection.map(this.changes);
}
/**
The new state created by the transaction. Computed on demand
(but retained for subsequent access), so it is recommended not to
access it in [transaction
filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) when possible.
*/
get state() {
if (!this._state)
this.startState.applyTransaction(this);
return this._state;
}
/**
Get the value of the given annotation type, if any.
*/
annotation(type) {
for (let ann of this.annotations)
if (ann.type == type)
return ann.value;
return void 0;
}
/**
Indicates whether the transaction changed the document.
*/
get docChanged() {
return !this.changes.empty;
}
/**
Indicates whether this transaction reconfigures the state
(through a [configuration compartment](https://codemirror.net/6/docs/ref/#state.Compartment) or
with a top-level configuration
[effect](https://codemirror.net/6/docs/ref/#state.StateEffect^reconfigure).
*/
get reconfigured() {
return this.startState.config != this.state.config;
}
/**
Returns true if the transaction has a [user
event](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent) annotation that is equal to
or more specific than `event`. For example, if the transaction
has `"select.pointer"` as user event, `"select"` and
`"select.pointer"` will match it.
*/
isUserEvent(event) {
let e = this.annotation(Transaction.userEvent);
return !!(e && (e == event || e.length > event.length && e.slice(0, event.length) == event && e[event.length] == "."));
}
}
Transaction.time = /* @__PURE__ */ Annotation.define();
Transaction.userEvent = /* @__PURE__ */ Annotation.define();
Transaction.addToHistory = /* @__PURE__ */ Annotation.define();
Transaction.remote = /* @__PURE__ */ Annotation.define();
function joinRanges(a, b) {
let result2 = [];
for (let iA = 0, iB = 0; ; ) {
let from, to;
if (iA < a.length && (iB == b.length || b[iB] >= a[iA])) {
from = a[iA++];
to = a[iA++];
} else if (iB < b.length) {
from = b[iB++];
to = b[iB++];
} else
return result2;
if (!result2.length || result2[result2.length - 1] < from)
result2.push(from, to);
else if (result2[result2.length - 1] < to)
result2[result2.length - 1] = to;
}
}
function mergeTransaction(a, b, sequential) {
var _a2;
let mapForA, mapForB, changes;
if (sequential) {
mapForA = b.changes;
mapForB = ChangeSet.empty(b.changes.length);
changes = a.changes.compose(b.changes);
} else {
mapForA = b.changes.map(a.changes);
mapForB = a.changes.mapDesc(b.changes, true);
changes = a.changes.compose(mapForA);
}
return {
changes,
selection: b.selection ? b.selection.map(mapForB) : (_a2 = a.selection) === null || _a2 === void 0 ? void 0 : _a2.map(mapForA),
effects: StateEffect.mapEffects(a.effects, mapForA).concat(StateEffect.mapEffects(b.effects, mapForB)),
annotations: a.annotations.length ? a.annotations.concat(b.annotations) : b.annotations,
scrollIntoView: a.scrollIntoView || b.scrollIntoView
};
}
function resolveTransactionInner(state, spec, docSize) {
let sel = spec.selection, annotations = asArray$1(spec.annotations);
if (spec.userEvent)
annotations = annotations.concat(Transaction.userEvent.of(spec.userEvent));
return {
changes: spec.changes instanceof ChangeSet ? spec.changes : ChangeSet.of(spec.changes || [], docSize, state.facet(lineSeparator)),
selection: sel && (sel instanceof EditorSelection ? sel : EditorSelection.single(sel.anchor, sel.head)),
effects: asArray$1(spec.effects),
annotations,
scrollIntoView: !!spec.scrollIntoView
};
}
function resolveTransaction(state, specs, filter) {
let s = resolveTransactionInner(state, specs.length ? specs[0] : {}, state.doc.length);
if (specs.length && specs[0].filter === false)
filter = false;
for (let i2 = 1; i2 < specs.length; i2++) {
if (specs[i2].filter === false)
filter = false;
let seq = !!specs[i2].sequential;
s = mergeTransaction(s, resolveTransactionInner(state, specs[i2], seq ? s.changes.newLength : state.doc.length), seq);
}
let tr = Transaction.create(state, s.changes, s.selection, s.effects, s.annotations, s.scrollIntoView);
return extendTransaction(filter ? filterTransaction(tr) : tr);
}
function filterTransaction(tr) {
let state = tr.startState;
let result2 = true;
for (let filter of state.facet(changeFilter)) {
let value = filter(tr);
if (value === false) {
result2 = false;
break;
}
if (Array.isArray(value))
result2 = result2 === true ? value : joinRanges(result2, value);
}
if (result2 !== true) {
let changes, back;
if (result2 === false) {
back = tr.changes.invertedDesc;
changes = ChangeSet.empty(state.doc.length);
} else {
let filtered = tr.changes.filter(result2);
changes = filtered.changes;
back = filtered.filtered.mapDesc(filtered.changes).invertedDesc;
}
tr = Transaction.create(state, changes, tr.selection && tr.selection.map(back), StateEffect.mapEffects(tr.effects, back), tr.annotations, tr.scrollIntoView);
}
let filters = state.facet(transactionFilter);
for (let i2 = filters.length - 1; i2 >= 0; i2--) {
let filtered = filters[i2](tr);
if (filtered instanceof Transaction)
tr = filtered;
else if (Array.isArray(filtered) && filtered.length == 1 && filtered[0] instanceof Transaction)
tr = filtered[0];
else
tr = resolveTransaction(state, asArray$1(filtered), false);
}
return tr;
}
function extendTransaction(tr) {
let state = tr.startState, extenders = state.facet(transactionExtender), spec = tr;
for (let i2 = extenders.length - 1; i2 >= 0; i2--) {
let extension = extenders[i2](tr);
if (extension && Object.keys(extension).length)
spec = mergeTransaction(spec, resolveTransactionInner(state, extension, tr.changes.newLength), true);
}
return spec == tr ? tr : Transaction.create(state, tr.changes, tr.selection, spec.effects, spec.annotations, spec.scrollIntoView);
}
const none$2 = [];
function asArray$1(value) {
return value == null ? none$2 : Array.isArray(value) ? value : [value];
}
var CharCategory = /* @__PURE__ */ function(CharCategory2) {
CharCategory2[CharCategory2["Word"] = 0] = "Word";
CharCategory2[CharCategory2["Space"] = 1] = "Space";
CharCategory2[CharCategory2["Other"] = 2] = "Other";
return CharCategory2;
}(CharCategory || (CharCategory = {}));
const nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
let wordChar;
try {
wordChar = /* @__PURE__ */ new RegExp("[\\p{Alphabetic}\\p{Number}_]", "u");
} catch (_) {
}
function hasWordChar(str) {
if (wordChar)
return wordChar.test(str);
for (let i2 = 0; i2 < str.length; i2++) {
let ch = str[i2];
if (/\w/.test(ch) || ch > "" && (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch)))
return true;
}
return false;
}
function makeCategorizer(wordChars) {
return (char) => {
if (!/\S/.test(char))
return CharCategory.Space;
if (hasWordChar(char))
return CharCategory.Word;
for (let i2 = 0; i2 < wordChars.length; i2++)
if (char.indexOf(wordChars[i2]) > -1)
return CharCategory.Word;
return CharCategory.Other;
};
}
class EditorState {
constructor(config2, doc2, selection, values, computeSlot, tr) {
this.config = config2;
this.doc = doc2;
this.selection = selection;
this.values = values;
this.status = config2.statusTemplate.slice();
this.computeSlot = computeSlot;
if (tr)
tr._state = this;
for (let i2 = 0; i2 < this.config.dynamicSlots.length; i2++)
ensureAddr(this, i2 << 1);
this.computeSlot = null;
}
field(field, require2 = true) {
let addr = this.config.address[field.id];
if (addr == null) {
if (require2)
throw new RangeError("Field is not present in this state");
return void 0;
}
ensureAddr(this, addr);
return getAddr(this, addr);
}
/**
Create a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction) that updates this
state. Any number of [transaction specs](https://codemirror.net/6/docs/ref/#state.TransactionSpec)
can be passed. Unless
[`sequential`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.sequential) is set, the
[changes](https://codemirror.net/6/docs/ref/#state.TransactionSpec.changes) (if any) of each spec
are assumed to start in the _current_ document (not the document
produced by previous specs), and its
[selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) and
[effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) are assumed to refer
to the document created by its _own_ changes. The resulting
transaction contains the combined effect of all the different
specs. For [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection), later
specs take precedence over earlier ones.
*/
update(...specs) {
return resolveTransaction(this, specs, true);
}
/**
@internal
*/
applyTransaction(tr) {
let conf = this.config, { base: base2, compartments } = conf;
for (let effect of tr.effects) {
if (effect.is(Compartment.reconfigure)) {
if (conf) {
compartments = /* @__PURE__ */ new Map();
conf.compartments.forEach((val, key) => compartments.set(key, val));
conf = null;
}
compartments.set(effect.value.compartment, effect.value.extension);
} else if (effect.is(StateEffect.reconfigure)) {
conf = null;
base2 = effect.value;
} else if (effect.is(StateEffect.appendConfig)) {
conf = null;
base2 = asArray$1(base2).concat(effect.value);
}
}
let startValues;
if (!conf) {
conf = Configuration.resolve(base2, compartments, this);
let intermediateState = new EditorState(conf, this.doc, this.selection, conf.dynamicSlots.map(() => null), (state, slot) => slot.reconfigure(state, this), null);
startValues = intermediateState.values;
} else {
startValues = tr.startState.values.slice();
}
let selection = tr.startState.facet(allowMultipleSelections) ? tr.newSelection : tr.newSelection.asSingle();
new EditorState(conf, tr.newDoc, selection, startValues, (state, slot) => slot.update(state, tr), tr);
}
/**
Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
replaces every selection range with the given content.
*/
replaceSelection(text) {
if (typeof text == "string")
text = this.toText(text);
return this.changeByRange((range) => ({
changes: { from: range.from, to: range.to, insert: text },
range: EditorSelection.cursor(range.from + text.length)
}));
}
/**
Create a set of changes and a new selection by running the given
function for each range in the active selection. The function
can return an optional set of changes (in the coordinate space
of the start document), plus an updated range (in the coordinate
space of the document produced by the call's own changes). This
method will merge all the changes and ranges into a single
changeset and selection, and return it as a [transaction
spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec), which can be passed to
[`update`](https://codemirror.net/6/docs/ref/#state.EditorState.update).
*/
changeByRange(f) {
let sel = this.selection;
let result1 = f(sel.ranges[0]);
let changes = this.changes(result1.changes), ranges = [result1.range];
let effects = asArray$1(result1.effects);
for (let i2 = 1; i2 < sel.ranges.length; i2++) {
let result2 = f(sel.ranges[i2]);
let newChanges = this.changes(result2.changes), newMapped = newChanges.map(changes);
for (let j2 = 0; j2 < i2; j2++)
ranges[j2] = ranges[j2].map(newMapped);
let mapBy = changes.mapDesc(newChanges, true);
ranges.push(result2.range.map(mapBy));
changes = changes.compose(newMapped);
effects = StateEffect.mapEffects(effects, newMapped).concat(StateEffect.mapEffects(asArray$1(result2.effects), mapBy));
}
return {
changes,
selection: EditorSelection.create(ranges, sel.mainIndex),
effects
};
}
/**
Create a [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet) from the given change
description, taking the state's document length and line
separator into account.
*/
changes(spec = []) {
if (spec instanceof ChangeSet)
return spec;
return ChangeSet.of(spec, this.doc.length, this.facet(EditorState.lineSeparator));
}
/**
Using the state's [line
separator](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator), create a
[`Text`](https://codemirror.net/6/docs/ref/#state.Text) instance from the given string.
*/
toText(string2) {
return Text.of(string2.split(this.facet(EditorState.lineSeparator) || DefaultSplit));
}
/**
Return the given range of the document as a string.
*/
sliceDoc(from = 0, to = this.doc.length) {
return this.doc.sliceString(from, to, this.lineBreak);
}
/**
Get the value of a state [facet](https://codemirror.net/6/docs/ref/#state.Facet).
*/
facet(facet) {
let addr = this.config.address[facet.id];
if (addr == null)
return facet.default;
ensureAddr(this, addr);
return getAddr(this, addr);
}
/**
Convert this state to a JSON-serializable object. When custom
fields should be serialized, you can pass them in as an object
mapping property names (in the resulting object, which should
not use `doc` or `selection`) to fields.
*/
toJSON(fields) {
let result2 = {
doc: this.sliceDoc(),
selection: this.selection.toJSON()
};
if (fields)
for (let prop in fields) {
let value = fields[prop];
if (value instanceof StateField && this.config.address[value.id] != null)
result2[prop] = value.spec.toJSON(this.field(fields[prop]), this);
}
return result2;
}
/**
Deserialize a state from its JSON representation. When custom
fields should be deserialized, pass the same object you passed
to [`toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) when serializing as
third argument.
*/
static fromJSON(json, config2 = {}, fields) {
if (!json || typeof json.doc != "string")
throw new RangeError("Invalid JSON representation for EditorState");
let fieldInit = [];
if (fields)
for (let prop in fields) {
if (Object.prototype.hasOwnProperty.call(json, prop)) {
let field = fields[prop], value = json[prop];
fieldInit.push(field.init((state) => field.spec.fromJSON(value, state)));
}
}
return EditorState.create({
doc: json.doc,
selection: EditorSelection.fromJSON(json.selection),
extensions: config2.extensions ? fieldInit.concat([config2.extensions]) : fieldInit
});
}
/**
Create a new state. You'll usually only need this when
initializing an editor—updated states are created by applying
transactions.
*/
static create(config2 = {}) {
let configuration = Configuration.resolve(config2.extensions || [], /* @__PURE__ */ new Map());
let doc2 = config2.doc instanceof Text ? config2.doc : Text.of((config2.doc || "").split(configuration.staticFacet(EditorState.lineSeparator) || DefaultSplit));
let selection = !config2.selection ? EditorSelection.single(0) : config2.selection instanceof EditorSelection ? config2.selection : EditorSelection.single(config2.selection.anchor, config2.selection.head);
checkSelection(selection, doc2.length);
if (!configuration.staticFacet(allowMultipleSelections))
selection = selection.asSingle();
return new EditorState(configuration, doc2, selection, configuration.dynamicSlots.map(() => null), (state, slot) => slot.create(state), null);
}
/**
The size (in columns) of a tab in the document, determined by
the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet.
*/
get tabSize() {
return this.facet(EditorState.tabSize);
}
/**
Get the proper [line-break](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator)
string for this state.
*/
get lineBreak() {
return this.facet(EditorState.lineSeparator) || "\n";
}
/**
Returns true when the editor is
[configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only.
*/
get readOnly() {
return this.facet(readOnly);
}
/**
Look up a translation for the given phrase (via the
[`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
original string if no translation is found.
If additional arguments are passed, they will be inserted in
place of markers like `$1` (for the first value) and `$2`, etc.
A single `$` is equivalent to `$1`, and `$$` will produce a
literal dollar sign.
*/
phrase(phrase2, ...insert2) {
for (let map of this.facet(EditorState.phrases))
if (Object.prototype.hasOwnProperty.call(map, phrase2)) {
phrase2 = map[phrase2];
break;
}
if (insert2.length)
phrase2 = phrase2.replace(/\$(\$|\d*)/g, (m, i2) => {
if (i2 == "$")
return "$";
let n = +(i2 || 1);
return !n || n > insert2.length ? m : insert2[n - 1];
});
return phrase2;
}
/**
Find the values for a given language data field, provided by the
the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
Examples of language data fields are...
- [`"commentTokens"`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) for specifying
comment syntax.
- [`"autocomplete"`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.override)
for providing language-specific completion sources.
- [`"wordChars"`](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) for adding
characters that should be considered part of words in this
language.
- [`"closeBrackets"`](https://codemirror.net/6/docs/ref/#autocomplete.CloseBracketConfig) controls
bracket closing behavior.
*/
languageDataAt(name2, pos, side = -1) {
let values = [];
for (let provider of this.facet(languageData)) {
for (let result2 of provider(this, pos, side)) {
if (Object.prototype.hasOwnProperty.call(result2, name2))
values.push(result2[name2]);
}
}
return values;
}
/**
Return a function that can categorize strings (expected to
represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak))
into one of:
- Word (contains an alphanumeric character or a character
explicitly listed in the local language's `"wordChars"`
language data, which should be a string)
- Space (contains only whitespace)
- Other (anything else)
*/
charCategorizer(at) {
return makeCategorizer(this.languageDataAt("wordChars", at).join(""));
}
/**
Find the word at the given position, meaning the range
containing all [word](https://codemirror.net/6/docs/ref/#state.CharCategory.Word) characters
around it. If no word characters are adjacent to the position,
this returns null.
*/
wordAt(pos) {
let { text, from, length } = this.doc.lineAt(pos);
let cat = this.charCategorizer(pos);
let start = pos - from, end = pos - from;
while (start > 0) {
let prev = findClusterBreak(text, start, false);
if (cat(text.slice(prev, start)) != CharCategory.Word)
break;
start = prev;
}
while (end < length) {
let next = findClusterBreak(text, end);
if (cat(text.slice(end, next)) != CharCategory.Word)
break;
end = next;
}
return start == end ? null : EditorSelection.range(start + from, end + from);
}
}
EditorState.allowMultipleSelections = allowMultipleSelections;
EditorState.tabSize = /* @__PURE__ */ Facet.define({
combine: (values) => values.length ? values[0] : 4
});
EditorState.lineSeparator = lineSeparator;
EditorState.readOnly = readOnly;
EditorState.phrases = /* @__PURE__ */ Facet.define({
compare(a, b) {
let kA = Object.keys(a), kB = Object.keys(b);
return kA.length == kB.length && kA.every((k) => a[k] == b[k]);
}
});
EditorState.languageData = languageData;
EditorState.changeFilter = changeFilter;
EditorState.transactionFilter = transactionFilter;
EditorState.transactionExtender = transactionExtender;
Compartment.reconfigure = /* @__PURE__ */ StateEffect.define();
function combineConfig(configs, defaults2, combine = {}) {
let result2 = {};
for (let config2 of configs)
for (let key of Object.keys(config2)) {
let value = config2[key], current = result2[key];
if (current === void 0)
result2[key] = value;
else if (current === value || value === void 0)
;
else if (Object.hasOwnProperty.call(combine, key))
result2[key] = combine[key](current, value);
else
throw new Error("Config merge conflict for field " + key);
}
for (let key in defaults2)
if (result2[key] === void 0)
result2[key] = defaults2[key];
return result2;
}
class RangeValue {
/**
Compare this value with another value. Used when comparing
rangesets. The default implementation compares by identity.
Unless you are only creating a fixed number of unique instances
of your value type, it is a good idea to implement this
properly.
*/
eq(other) {
return this == other;
}
/**
Create a [range](https://codemirror.net/6/docs/ref/#state.Range) with this value.
*/
range(from, to = from) {
return Range$1.create(from, to, this);
}
}
RangeValue.prototype.startSide = RangeValue.prototype.endSide = 0;
RangeValue.prototype.point = false;
RangeValue.prototype.mapMode = MapMode.TrackDel;
let Range$1 = class Range2 {
constructor(from, to, value) {
this.from = from;
this.to = to;
this.value = value;
}
/**
@internal
*/
static create(from, to, value) {
return new Range2(from, to, value);
}
};
function cmpRange(a, b) {
return a.from - b.from || a.value.startSide - b.value.startSide;
}
class Chunk {
constructor(from, to, value, maxPoint) {
this.from = from;
this.to = to;
this.value = value;
this.maxPoint = maxPoint;
}
get length() {
return this.to[this.to.length - 1];
}
// Find the index of the given position and side. Use the ranges'
// `from` pos when `end == false`, `to` when `end == true`.
findIndex(pos, side, end, startAt = 0) {
let arr = end ? this.to : this.from;
for (let lo = startAt, hi = arr.length; ; ) {
if (lo == hi)
return lo;
let mid = lo + hi >> 1;
let diff = arr[mid] - pos || (end ? this.value[mid].endSide : this.value[mid].startSide) - side;
if (mid == lo)
return diff >= 0 ? lo : hi;
if (diff >= 0)
hi = mid;
else
lo = mid + 1;
}
}
between(offset, from, to, f) {
for (let i2 = this.findIndex(from, -1e9, true), e = this.findIndex(to, 1e9, false, i2); i2 < e; i2++)
if (f(this.from[i2] + offset, this.to[i2] + offset, this.value[i2]) === false)
return false;
}
map(offset, changes) {
let value = [], from = [], to = [], newPos = -1, maxPoint = -1;
for (let i2 = 0; i2 < this.value.length; i2++) {
let val = this.value[i2], curFrom = this.from[i2] + offset, curTo = this.to[i2] + offset, newFrom, newTo;
if (curFrom == curTo) {
let mapped = changes.mapPos(curFrom, val.startSide, val.mapMode);
if (mapped == null)
continue;
newFrom = newTo = mapped;
if (val.startSide != val.endSide) {
newTo = changes.mapPos(curFrom, val.endSide);
if (newTo < newFrom)
continue;
}
} else {
newFrom = changes.mapPos(curFrom, val.startSide);
newTo = changes.mapPos(curTo, val.endSide);
if (newFrom > newTo || newFrom == newTo && val.startSide > 0 && val.endSide <= 0)
continue;
}
if ((newTo - newFrom || val.endSide - val.startSide) < 0)
continue;
if (newPos < 0)
newPos = newFrom;
if (val.point)
maxPoint = Math.max(maxPoint, newTo - newFrom);
value.push(val);
from.push(newFrom - newPos);
to.push(newTo - newPos);
}
return { mapped: value.length ? new Chunk(from, to, value, maxPoint) : null, pos: newPos };
}
}
class RangeSet {
constructor(chunkPos, chunk, nextLayer, maxPoint) {
this.chunkPos = chunkPos;
this.chunk = chunk;
this.nextLayer = nextLayer;
this.maxPoint = maxPoint;
}
/**
@internal
*/
static create(chunkPos, chunk, nextLayer, maxPoint) {
return new RangeSet(chunkPos, chunk, nextLayer, maxPoint);
}
/**
@internal
*/
get length() {
let last = this.chunk.length - 1;
return last < 0 ? 0 : Math.max(this.chunkEnd(last), this.nextLayer.length);
}
/**
The number of ranges in the set.
*/
get size() {
if (this.isEmpty)
return 0;
let size = this.nextLayer.size;
for (let chunk of this.chunk)
size += chunk.value.length;
return size;
}
/**
@internal
*/
chunkEnd(index) {
return this.chunkPos[index] + this.chunk[index].length;
}
/**
Update the range set, optionally adding new ranges or filtering
out existing ones.
(Note: The type parameter is just there as a kludge to work
around TypeScript variance issues that prevented `RangeSet<X>`
from being a subtype of `RangeSet<Y>` when `X` is a subtype of
`Y`.)
*/
update(updateSpec) {
let { add: add2 = [], sort = false, filterFrom = 0, filterTo = this.length } = updateSpec;
let filter = updateSpec.filter;
if (add2.length == 0 && !filter)
return this;
if (sort)
add2 = add2.slice().sort(cmpRange);
if (this.isEmpty)
return add2.length ? RangeSet.of(add2) : this;
let cur2 = new LayerCursor(this, null, -1).goto(0), i2 = 0, spill = [];
let builder = new RangeSetBuilder();
while (cur2.value || i2 < add2.length) {
if (i2 < add2.length && (cur2.from - add2[i2].from || cur2.startSide - add2[i2].value.startSide) >= 0) {
let range = add2[i2++];
if (!builder.addInner(range.from, range.to, range.value))
spill.push(range);
} else if (cur2.rangeIndex == 1 && cur2.chunkIndex < this.chunk.length && (i2 == add2.length || this.chunkEnd(cur2.chunkIndex) < add2[i2].from) && (!filter || filterFrom > this.chunkEnd(cur2.chunkIndex) || filterTo < this.chunkPos[cur2.chunkIndex]) && builder.addChunk(this.chunkPos[cur2.chunkIndex], this.chunk[cur2.chunkIndex])) {
cur2.nextChunk();
} else {
if (!filter || filterFrom > cur2.to || filterTo < cur2.from || filter(cur2.from, cur2.to, cur2.value)) {
if (!builder.addInner(cur2.from, cur2.to, cur2.value))
spill.push(Range$1.create(cur2.from, cur2.to, cur2.value));
}
cur2.next();
}
}
return builder.finishInner(this.nextLayer.isEmpty && !spill.length ? RangeSet.empty : this.nextLayer.update({ add: spill, filter, filterFrom, filterTo }));
}
/**
Map this range set through a set of changes, return the new set.
*/
map(changes) {
if (changes.empty || this.isEmpty)
return this;
let chunks = [], chunkPos = [], maxPoint = -1;
for (let i2 = 0; i2 < this.chunk.length; i2++) {
let start = this.chunkPos[i2], chunk = this.chunk[i2];
let touch = changes.touchesRange(start, start + chunk.length);
if (touch === false) {
maxPoint = Math.max(maxPoint, chunk.maxPoint);
chunks.push(chunk);
chunkPos.push(changes.mapPos(start));
} else if (touch === true) {
let { mapped, pos } = chunk.map(start, changes);
if (mapped) {
maxPoint = Math.max(maxPoint, mapped.maxPoint);
chunks.push(mapped);
chunkPos.push(pos);
}
}
}
let next = this.nextLayer.map(changes);
return chunks.length == 0 ? next : new RangeSet(chunkPos, chunks, next || RangeSet.empty, maxPoint);
}
/**
Iterate over the ranges that touch the region `from` to `to`,
calling `f` for each. There is no guarantee that the ranges will
be reported in any specific order. When the callback returns
`false`, iteration stops.
*/
between(from, to, f) {
if (this.isEmpty)
return;
for (let i2 = 0; i2 < this.chunk.length; i2++) {
let start = this.chunkPos[i2], chunk = this.chunk[i2];
if (to >= start && from <= start + chunk.length && chunk.between(start, from - start, to - start, f) === false)
return;
}
this.nextLayer.between(from, to, f);
}
/**
Iterate over the ranges in this set, in order, including all
ranges that end at or after `from`.
*/
iter(from = 0) {
return HeapCursor.from([this]).goto(from);
}
/**
@internal
*/
get isEmpty() {
return this.nextLayer == this;
}
/**
Iterate over the ranges in a collection of sets, in order,
starting from `from`.
*/
static iter(sets, from = 0) {
return HeapCursor.from(sets).goto(from);
}
/**
Iterate over two groups of sets, calling methods on `comparator`
to notify it of possible differences.
*/
static compare(oldSets, newSets, textDiff, comparator, minPointSize = -1) {
let a = oldSets.filter((set) => set.maxPoint > 0 || !set.isEmpty && set.maxPoint >= minPointSize);
let b = newSets.filter((set) => set.maxPoint > 0 || !set.isEmpty && set.maxPoint >= minPointSize);
let sharedChunks = findSharedChunks(a, b, textDiff);
let sideA = new SpanCursor(a, sharedChunks, minPointSize);
let sideB = new SpanCursor(b, sharedChunks, minPointSize);
textDiff.iterGaps((fromA, fromB, length) => compare(sideA, fromA, sideB, fromB, length, comparator));
if (textDiff.empty && textDiff.length == 0)
compare(sideA, 0, sideB, 0, 0, comparator);
}
/**
Compare the contents of two groups of range sets, returning true
if they are equivalent in the given range.
*/
static eq(oldSets, newSets, from = 0, to) {
if (to == null)
to = 1e9 - 1;
let a = oldSets.filter((set) => !set.isEmpty && newSets.indexOf(set) < 0);
let b = newSets.filter((set) => !set.isEmpty && oldSets.indexOf(set) < 0);
if (a.length != b.length)
return false;
if (!a.length)
return true;
let sharedChunks = findSharedChunks(a, b);
let sideA = new SpanCursor(a, sharedChunks, 0).goto(from), sideB = new SpanCursor(b, sharedChunks, 0).goto(from);
for (; ; ) {
if (sideA.to != sideB.to || !sameValues(sideA.active, sideB.active) || sideA.point && (!sideB.point || !sideA.point.eq(sideB.point)))
return false;
if (sideA.to > to)
return true;
sideA.next();
sideB.next();
}
}
/**
Iterate over a group of range sets at the same time, notifying
the iterator about the ranges covering every given piece of
content. Returns the open count (see
[`SpanIterator.span`](https://codemirror.net/6/docs/ref/#state.SpanIterator.span)) at the end
of the iteration.
*/
static spans(sets, from, to, iterator, minPointSize = -1) {
let cursor = new SpanCursor(sets, null, minPointSize).goto(from), pos = from;
let openRanges = cursor.openStart;
for (; ; ) {
let curTo = Math.min(cursor.to, to);
if (cursor.point) {
let active = cursor.activeForPoint(cursor.to);
let openCount = cursor.pointFrom < from ? active.length + 1 : cursor.point.startSide < 0 ? active.length : Math.min(active.length, openRanges);
iterator.point(pos, curTo, cursor.point, active, openCount, cursor.pointRank);
openRanges = Math.min(cursor.openEnd(curTo), active.length);
} else if (curTo > pos) {
iterator.span(pos, curTo, cursor.active, openRanges);
openRanges = cursor.openEnd(curTo);
}
if (cursor.to > to)
return openRanges + (cursor.point && cursor.to > to ? 1 : 0);
pos = cursor.to;
cursor.next();
}
}
/**
Create a range set for the given range or array of ranges. By
default, this expects the ranges to be _sorted_ (by start
position and, if two start at the same position,
`value.startSide`). You can pass `true` as second argument to
cause the method to sort them.
*/
static of(ranges, sort = false) {
let build = new RangeSetBuilder();
for (let range of ranges instanceof Range$1 ? [ranges] : sort ? lazySort(ranges) : ranges)
build.add(range.from, range.to, range.value);
return build.finish();
}
/**
Join an array of range sets into a single set.
*/
static join(sets) {
if (!sets.length)
return RangeSet.empty;
let result2 = sets[sets.length - 1];
for (let i2 = sets.length - 2; i2 >= 0; i2--) {
for (let layer2 = sets[i2]; layer2 != RangeSet.empty; layer2 = layer2.nextLayer)
result2 = new RangeSet(layer2.chunkPos, layer2.chunk, result2, Math.max(layer2.maxPoint, result2.maxPoint));
}
return result2;
}
}
RangeSet.empty = /* @__PURE__ */ new RangeSet([], [], null, -1);
function lazySort(ranges) {
if (ranges.length > 1)
for (let prev = ranges[0], i2 = 1; i2 < ranges.length; i2++) {
let cur2 = ranges[i2];
if (cmpRange(prev, cur2) > 0)
return ranges.slice().sort(cmpRange);
prev = cur2;
}
return ranges;
}
RangeSet.empty.nextLayer = RangeSet.empty;
class RangeSetBuilder {
finishChunk(newArrays) {
this.chunks.push(new Chunk(this.from, this.to, this.value, this.maxPoint));
this.chunkPos.push(this.chunkStart);
this.chunkStart = -1;
this.setMaxPoint = Math.max(this.setMaxPoint, this.maxPoint);
this.maxPoint = -1;
if (newArrays) {
this.from = [];
this.to = [];
this.value = [];
}
}
/**
Create an empty builder.
*/
constructor() {
this.chunks = [];
this.chunkPos = [];
this.chunkStart = -1;
this.last = null;
this.lastFrom = -1e9;
this.lastTo = -1e9;
this.from = [];
this.to = [];
this.value = [];
this.maxPoint = -1;
this.setMaxPoint = -1;
this.nextLayer = null;
}
/**
Add a range. Ranges should be added in sorted (by `from` and
`value.startSide`) order.
*/
add(from, to, value) {
if (!this.addInner(from, to, value))
(this.nextLayer || (this.nextLayer = new RangeSetBuilder())).add(from, to, value);
}
/**
@internal
*/
addInner(from, to, value) {
let diff = from - this.lastTo || value.startSide - this.last.endSide;
if (diff <= 0 && (from - this.lastFrom || value.startSide - this.last.startSide) < 0)
throw new Error("Ranges must be added sorted by `from` position and `startSide`");
if (diff < 0)
return false;
if (this.from.length == 250)
this.finishChunk(true);
if (this.chunkStart < 0)
this.chunkStart = from;
this.from.push(from - this.chunkStart);
this.to.push(to - this.chunkStart);
this.last = value;
this.lastFrom = from;
this.lastTo = to;
this.value.push(value);
if (value.point)
this.maxPoint = Math.max(this.maxPoint, to - from);
return true;
}
/**
@internal
*/
addChunk(from, chunk) {
if ((from - this.lastTo || chunk.value[0].startSide - this.last.endSide) < 0)
return false;
if (this.from.length)
this.finishChunk(true);
this.setMaxPoint = Math.max(this.setMaxPoint, chunk.maxPoint);
this.chunks.push(chunk);
this.chunkPos.push(from);
let last = chunk.value.length - 1;
this.last = chunk.value[last];
this.lastFrom = chunk.from[last] + from;
this.lastTo = chunk.to[last] + from;
return true;
}
/**
Finish the range set. Returns the new set. The builder can't be
used anymore after this has been called.
*/
finish() {
return this.finishInner(RangeSet.empty);
}
/**
@internal
*/
finishInner(next) {
if (this.from.length)
this.finishChunk(false);
if (this.chunks.length == 0)
return next;
let result2 = RangeSet.create(this.chunkPos, this.chunks, this.nextLayer ? this.nextLayer.finishInner(next) : next, this.setMaxPoint);
this.from = null;
return result2;
}
}
function findSharedChunks(a, b, textDiff) {
let inA = /* @__PURE__ */ new Map();
for (let set of a)
for (let i2 = 0; i2 < set.chunk.length; i2++)
if (set.chunk[i2].maxPoint <= 0)
inA.set(set.chunk[i2], set.chunkPos[i2]);
let shared = /* @__PURE__ */ new Set();
for (let set of b)
for (let i2 = 0; i2 < set.chunk.length; i2++) {
let known = inA.get(set.chunk[i2]);
if (known != null && (textDiff ? textDiff.mapPos(known) : known) == set.chunkPos[i2] && !(textDiff === null || textDiff === void 0 ? void 0 : textDiff.touchesRange(known, known + set.chunk[i2].length)))
shared.add(set.chunk[i2]);
}
return shared;
}
class LayerCursor {
constructor(layer2, skip, minPoint, rank = 0) {
this.layer = layer2;
this.skip = skip;
this.minPoint = minPoint;
this.rank = rank;
}
get startSide() {
return this.value ? this.value.startSide : 0;
}
get endSide() {
return this.value ? this.value.endSide : 0;
}
goto(pos, side = -1e9) {
this.chunkIndex = this.rangeIndex = 0;
this.gotoInner(pos, side, false);
return this;
}
gotoInner(pos, side, forward) {
while (this.chunkIndex < this.layer.chunk.length) {
let next = this.layer.chunk[this.chunkIndex];
if (!(this.skip && this.skip.has(next) || this.layer.chunkEnd(this.chunkIndex) < pos || next.maxPoint < this.minPoint))
break;
this.chunkIndex++;
forward = false;
}
if (this.chunkIndex < this.layer.chunk.length) {
let rangeIndex = this.layer.chunk[this.chunkIndex].findIndex(pos - this.layer.chunkPos[this.chunkIndex], side, true);
if (!forward || this.rangeIndex < rangeIndex)
this.setRangeIndex(rangeIndex);
}
this.next();
}
forward(pos, side) {
if ((this.to - pos || this.endSide - side) < 0)
this.gotoInner(pos, side, true);
}
next() {
for (; ; ) {
if (this.chunkIndex == this.layer.chunk.length) {
this.from = this.to = 1e9;
this.value = null;
break;
} else {
let chunkPos = this.layer.chunkPos[this.chunkIndex], chunk = this.layer.chunk[this.chunkIndex];
let from = chunkPos + chunk.from[this.rangeIndex];
this.from = from;
this.to = chunkPos + chunk.to[this.rangeIndex];
this.value = chunk.value[this.rangeIndex];
this.setRangeIndex(this.rangeIndex + 1);
if (this.minPoint < 0 || this.value.point && this.to - this.from >= this.minPoint)
break;
}
}
}
setRangeIndex(index) {
if (index == this.layer.chunk[this.chunkIndex].value.length) {
this.chunkIndex++;
if (this.skip) {
while (this.chunkIndex < this.layer.chunk.length && this.skip.has(this.layer.chunk[this.chunkIndex]))
this.chunkIndex++;
}
this.rangeIndex = 0;
} else {
this.rangeIndex = index;
}
}
nextChunk() {
this.chunkIndex++;
this.rangeIndex = 0;
this.next();
}
compare(other) {
return this.from - other.from || this.startSide - other.startSide || this.rank - other.rank || this.to - other.to || this.endSide - other.endSide;
}
}
class HeapCursor {
constructor(heap) {
this.heap = heap;
}
static from(sets, skip = null, minPoint = -1) {
let heap = [];
for (let i2 = 0; i2 < sets.length; i2++) {
for (let cur2 = sets[i2]; !cur2.isEmpty; cur2 = cur2.nextLayer) {
if (cur2.maxPoint >= minPoint)
heap.push(new LayerCursor(cur2, skip, minPoint, i2));
}
}
return heap.length == 1 ? heap[0] : new HeapCursor(heap);
}
get startSide() {
return this.value ? this.value.startSide : 0;
}
goto(pos, side = -1e9) {
for (let cur2 of this.heap)
cur2.goto(pos, side);
for (let i2 = this.heap.length >> 1; i2 >= 0; i2--)
heapBubble(this.heap, i2);
this.next();
return this;
}
forward(pos, side) {
for (let cur2 of this.heap)
cur2.forward(pos, side);
for (let i2 = this.heap.length >> 1; i2 >= 0; i2--)
heapBubble(this.heap, i2);
if ((this.to - pos || this.value.endSide - side) < 0)
this.next();
}
next() {
if (this.heap.length == 0) {
this.from = this.to = 1e9;
this.value = null;
this.rank = -1;
} else {
let top2 = this.heap[0];
this.from = top2.from;
this.to = top2.to;
this.value = top2.value;
this.rank = top2.rank;
if (top2.value)
top2.next();
heapBubble(this.heap, 0);
}
}
}
function heapBubble(heap, index) {
for (let cur2 = heap[index]; ; ) {
let childIndex = (index << 1) + 1;
if (childIndex >= heap.length)
break;
let child = heap[childIndex];
if (childIndex + 1 < heap.length && child.compare(heap[childIndex + 1]) >= 0) {
child = heap[childIndex + 1];
childIndex++;
}
if (cur2.compare(child) < 0)
break;
heap[childIndex] = cur2;
heap[index] = child;
index = childIndex;
}
}
class SpanCursor {
constructor(sets, skip, minPoint) {
this.minPoint = minPoint;
this.active = [];
this.activeTo = [];
this.activeRank = [];
this.minActive = -1;
this.point = null;
this.pointFrom = 0;
this.pointRank = 0;
this.to = -1e9;
this.endSide = 0;
this.openStart = -1;
this.cursor = HeapCursor.from(sets, skip, minPoint);
}
goto(pos, side = -1e9) {
this.cursor.goto(pos, side);
this.active.length = this.activeTo.length = this.activeRank.length = 0;
this.minActive = -1;
this.to = pos;
this.endSide = side;
this.openStart = -1;
this.next();
return this;
}
forward(pos, side) {
while (this.minActive > -1 && (this.activeTo[this.minActive] - pos || this.active[this.minActive].endSide - side) < 0)
this.removeActive(this.minActive);
this.cursor.forward(pos, side);
}
removeActive(index) {
remove(this.active, index);
remove(this.activeTo, index);
remove(this.activeRank, index);
this.minActive = findMinIndex(this.active, this.activeTo);
}
addActive(trackOpen) {
let i2 = 0, { value, to, rank } = this.cursor;
while (i2 < this.activeRank.length && (rank - this.activeRank[i2] || to - this.activeTo[i2]) > 0)
i2++;
insert(this.active, i2, value);
insert(this.activeTo, i2, to);
insert(this.activeRank, i2, rank);
if (trackOpen)
insert(trackOpen, i2, this.cursor.from);
this.minActive = findMinIndex(this.active, this.activeTo);
}
// After calling this, if `this.point` != null, the next range is a
// point. Otherwise, it's a regular range, covered by `this.active`.
next() {
let from = this.to, wasPoint = this.point;
this.point = null;
let trackOpen = this.openStart < 0 ? [] : null;
for (; ; ) {
let a = this.minActive;
if (a > -1 && (this.activeTo[a] - this.cursor.from || this.active[a].endSide - this.cursor.startSide) < 0) {
if (this.activeTo[a] > from) {
this.to = this.activeTo[a];
this.endSide = this.active[a].endSide;
break;
}
this.removeActive(a);
if (trackOpen)
remove(trackOpen, a);
} else if (!this.cursor.value) {
this.to = this.endSide = 1e9;
break;
} else if (this.cursor.from > from) {
this.to = this.cursor.from;
this.endSide = this.cursor.startSide;
break;
} else {
let nextVal = this.cursor.value;
if (!nextVal.point) {
this.addActive(trackOpen);
this.cursor.next();
} else if (wasPoint && this.cursor.to == this.to && this.cursor.from < this.cursor.to) {
this.cursor.next();
} else {
this.point = nextVal;
this.pointFrom = this.cursor.from;
this.pointRank = this.cursor.rank;
this.to = this.cursor.to;
this.endSide = nextVal.endSide;
this.cursor.next();
this.forward(this.to, this.endSide);
break;
}
}
}
if (trackOpen) {
this.openStart = 0;
for (let i2 = trackOpen.length - 1; i2 >= 0 && trackOpen[i2] < from; i2--)
this.openStart++;
}
}
activeForPoint(to) {
if (!this.active.length)
return this.active;
let active = [];
for (let i2 = this.active.length - 1; i2 >= 0; i2--) {
if (this.activeRank[i2] < this.pointRank)
break;
if (this.activeTo[i2] > to || this.activeTo[i2] == to && this.active[i2].endSide >= this.point.endSide)
active.push(this.active[i2]);
}
return active.reverse();
}
openEnd(to) {
let open = 0;
for (let i2 = this.activeTo.length - 1; i2 >= 0 && this.activeTo[i2] > to; i2--)
open++;
return open;
}
}
function compare(a, startA, b, startB, length, comparator) {
a.goto(startA);
b.goto(startB);
let endB = startB + length;
let pos = startB, dPos = startB - startA;
for (; ; ) {
let diff = a.to + dPos - b.to || a.endSide - b.endSide;
let end = diff < 0 ? a.to + dPos : b.to, clipEnd = Math.min(end, endB);
if (a.point || b.point) {
if (!(a.point && b.point && (a.point == b.point || a.point.eq(b.point)) && sameValues(a.activeForPoint(a.to), b.activeForPoint(b.to))))
comparator.comparePoint(pos, clipEnd, a.point, b.point);
} else {
if (clipEnd > pos && !sameValues(a.active, b.active))
comparator.compareRange(pos, clipEnd, a.active, b.active);
}
if (end > endB)
break;
pos = end;
if (diff <= 0)
a.next();
if (diff >= 0)
b.next();
}
}
function sameValues(a, b) {
if (a.length != b.length)
return false;
for (let i2 = 0; i2 < a.length; i2++)
if (a[i2] != b[i2] && !a[i2].eq(b[i2]))
return false;
return true;
}
function remove(array, index) {
for (let i2 = index, e = array.length - 1; i2 < e; i2++)
array[i2] = array[i2 + 1];
array.pop();
}
function insert(array, index, value) {
for (let i2 = array.length - 1; i2 >= index; i2--)
array[i2 + 1] = array[i2];
array[index] = value;
}
function findMinIndex(value, array) {
let found = -1, foundPos = 1e9;
for (let i2 = 0; i2 < array.length; i2++)
if ((array[i2] - foundPos || value[i2].endSide - value[found].endSide) < 0) {
found = i2;
foundPos = array[i2];
}
return found;
}
function countColumn(string2, tabSize, to = string2.length) {
let n = 0;
for (let i2 = 0; i2 < to; ) {
if (string2.charCodeAt(i2) == 9) {
n += tabSize - n % tabSize;
i2++;
} else {
n++;
i2 = findClusterBreak(string2, i2);
}
}
return n;
}
function findColumn(string2, col, tabSize, strict) {
for (let i2 = 0, n = 0; ; ) {
if (n >= col)
return i2;
if (i2 == string2.length)
break;
n += string2.charCodeAt(i2) == 9 ? tabSize - n % tabSize : 1;
i2 = findClusterBreak(string2, i2);
}
return strict === true ? -1 : string2.length;
}
const C$1 = "ͼ";
const COUNT = typeof Symbol == "undefined" ? "__" + C$1 : Symbol.for(C$1);
const SET = typeof Symbol == "undefined" ? "__styleSet" + Math.floor(Math.random() * 1e8) : Symbol("styleSet");
const top = typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : {};
class StyleModule {
// :: (Object<Style>, ?{finish: ?(string) → string})
// Create a style module from the given spec.
//
// When `finish` is given, it is called on regular (non-`@`)
// selectors (after `&` expansion) to compute the final selector.
constructor(spec, options) {
this.rules = [];
let { finish } = options || {};
function splitSelector(selector) {
return /^@/.test(selector) ? [selector] : selector.split(/,\s*/);
}
function render(selectors, spec2, target, isKeyframes) {
let local = [], isAt = /^@(\w+)\b/.exec(selectors[0]), keyframes = isAt && isAt[1] == "keyframes";
if (isAt && spec2 == null)
return target.push(selectors[0] + ";");
for (let prop in spec2) {
let value = spec2[prop];
if (/&/.test(prop)) {
render(
prop.split(/,\s*/).map((part) => selectors.map((sel) => part.replace(/&/, sel))).reduce((a, b) => a.concat(b)),
value,
target
);
} else if (value && typeof value == "object") {
if (!isAt)
throw new RangeError("The value of a property (" + prop + ") should be a primitive value.");
render(splitSelector(prop), value, local, keyframes);
} else if (value != null) {
local.push(prop.replace(/_.*/, "").replace(/[A-Z]/g, (l) => "-" + l.toLowerCase()) + ": " + value + ";");
}
}
if (local.length || keyframes) {
target.push((finish && !isAt && !isKeyframes ? selectors.map(finish) : selectors).join(", ") + " {" + local.join(" ") + "}");
}
}
for (let prop in spec)
render(splitSelector(prop), spec[prop], this.rules);
}
// :: () → string
// Returns a string containing the module's CSS rules.
getRules() {
return this.rules.join("\n");
}
// :: () → string
// Generate a new unique CSS class name.
static newName() {
let id2 = top[COUNT] || 1;
top[COUNT] = id2 + 1;
return C$1 + id2.toString(36);
}
// :: (union<Document, ShadowRoot>, union<[StyleModule], StyleModule>, ?{nonce: ?string})
//
// Mount the given set of modules in the given DOM root, which ensures
// that the CSS rules defined by the module are available in that
// context.
//
// Rules are only added to the document once per root.
//
// Rule order will follow the order of the modules, so that rules from
// modules later in the array take precedence of those from earlier
// modules. If you call this function multiple times for the same root
// in a way that changes the order of already mounted modules, the old
// order will be changed.
//
// If a Content Security Policy nonce is provided, it is added to
// the `<style>` tag generated by the library.
static mount(root, modules, options) {
let set = root[SET], nonce = options && options.nonce;
if (!set)
set = new StyleSet(root, nonce);
else if (nonce)
set.setNonce(nonce);
set.mount(Array.isArray(modules) ? modules : [modules]);
}
}
let adoptedSet = /* @__PURE__ */ new Map();
class StyleSet {
constructor(root, nonce) {
this.root = root;
let doc2 = root.ownerDocument || root, win = doc2.defaultView;
if (!root.head && root.adoptedStyleSheets && win.CSSStyleSheet) {
let adopted = adoptedSet.get(doc2);
if (adopted)
return root[SET] = adopted;
this.sheet = new win.CSSStyleSheet();
adoptedSet.set(doc2, this);
} else {
this.styleTag = doc2.createElement("style");
if (nonce)
this.styleTag.setAttribute("nonce", nonce);
}
this.modules = [];
root[SET] = this;
}
mount(modules) {
let sheet = this.sheet;
let pos = 0, j2 = 0;
for (let i2 = 0; i2 < modules.length; i2++) {
let mod = modules[i2], index = this.modules.indexOf(mod);
if (index < j2 && index > -1) {
this.modules.splice(index, 1);
j2--;
index = -1;
}
if (index == -1) {
this.modules.splice(j2++, 0, mod);
if (sheet)
for (let k = 0; k < mod.rules.length; k++)
sheet.insertRule(mod.rules[k], pos++);
} else {
while (j2 < index)
pos += this.modules[j2++].rules.length;
pos += mod.rules.length;
j2++;
}
}
if (sheet) {
if (this.root.adoptedStyleSheets.indexOf(this.sheet) < 0)
this.root.adoptedStyleSheets = [this.sheet, ...this.root.adoptedStyleSheets];
} else {
let text = "";
for (let i2 = 0; i2 < this.modules.length; i2++)
text += this.modules[i2].getRules() + "\n";
this.styleTag.textContent = text;
let target = this.root.head || this.root;
if (this.styleTag.parentNode != target)
target.insertBefore(this.styleTag, target.firstChild);
}
}
setNonce(nonce) {
if (this.styleTag && this.styleTag.getAttribute("nonce") != nonce)
this.styleTag.setAttribute("nonce", nonce);
}
}
var base = {
8: "Backspace",
9: "Tab",
10: "Enter",
12: "NumLock",
13: "Enter",
16: "Shift",
17: "Control",
18: "Alt",
20: "CapsLock",
27: "Escape",
32: " ",
33: "PageUp",
34: "PageDown",
35: "End",
36: "Home",
37: "ArrowLeft",
38: "ArrowUp",
39: "ArrowRight",
40: "ArrowDown",
44: "PrintScreen",
45: "Insert",
46: "Delete",
59: ";",
61: "=",
91: "Meta",
92: "Meta",
106: "*",
107: "+",
108: ",",
109: "-",
110: ".",
111: "/",
144: "NumLock",
145: "ScrollLock",
160: "Shift",
161: "Shift",
162: "Control",
163: "Control",
164: "Alt",
165: "Alt",
173: "-",
186: ";",
187: "=",
188: ",",
189: "-",
190: ".",
191: "/",
192: "`",
219: "[",
220: "\\",
221: "]",
222: "'"
};
var shift = {
48: ")",
49: "!",
50: "@",
51: "#",
52: "$",
53: "%",
54: "^",
55: "&",
56: "*",
57: "(",
59: ":",
61: "+",
173: "_",
186: ":",
187: "+",
188: "<",
189: "_",
190: ">",
191: "?",
192: "~",
219: "{",
220: "|",
221: "}",
222: '"'
};
var mac = typeof navigator != "undefined" && /Mac/.test(navigator.platform);
var ie$1 = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
for (var i = 0; i < 10; i++)
base[48 + i] = base[96 + i] = String(i);
for (var i = 1; i <= 24; i++)
base[i + 111] = "F" + i;
for (var i = 65; i <= 90; i++) {
base[i] = String.fromCharCode(i + 32);
shift[i] = String.fromCharCode(i);
}
for (var code in base)
if (!shift.hasOwnProperty(code))
shift[code] = base[code];
function keyName(event) {
var ignoreKey = mac && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey || ie$1 && event.shiftKey && event.key && event.key.length == 1 || event.key == "Unidentified";
var name2 = !ignoreKey && event.key || (event.shiftKey ? shift : base)[event.keyCode] || event.key || "Unidentified";
if (name2 == "Esc")
name2 = "Escape";
if (name2 == "Del")
name2 = "Delete";
if (name2 == "Left")
name2 = "ArrowLeft";
if (name2 == "Up")
name2 = "ArrowUp";
if (name2 == "Right")
name2 = "ArrowRight";
if (name2 == "Down")
name2 = "ArrowDown";
return name2;
}
function getSelection(root) {
let target;
if (root.nodeType == 11) {
target = root.getSelection ? root : root.ownerDocument;
} else {
target = root;
}
return target.getSelection();
}
function contains(dom, node) {
return node ? dom == node || dom.contains(node.nodeType != 1 ? node.parentNode : node) : false;
}
function deepActiveElement(doc2) {
let elt = doc2.activeElement;
while (elt && elt.shadowRoot)
elt = elt.shadowRoot.activeElement;
return elt;
}
function hasSelection(dom, selection) {
if (!selection.anchorNode)
return false;
try {
return contains(dom, selection.anchorNode);
} catch (_) {
return false;
}
}
function clientRectsFor(dom) {
if (dom.nodeType == 3)
return textRange(dom, 0, dom.nodeValue.length).getClientRects();
else if (dom.nodeType == 1)
return dom.getClientRects();
else
return [];
}
function isEquivalentPosition(node, off, targetNode, targetOff) {
return targetNode ? scanFor(node, off, targetNode, targetOff, -1) || scanFor(node, off, targetNode, targetOff, 1) : false;
}
function domIndex(node) {
for (var index = 0; ; index++) {
node = node.previousSibling;
if (!node)
return index;
}
}
function scanFor(node, off, targetNode, targetOff, dir) {
for (; ; ) {
if (node == targetNode && off == targetOff)
return true;
if (off == (dir < 0 ? 0 : maxOffset(node))) {
if (node.nodeName == "DIV")
return false;
let parent = node.parentNode;
if (!parent || parent.nodeType != 1)
return false;
off = domIndex(node) + (dir < 0 ? 0 : 1);
node = parent;
} else if (node.nodeType == 1) {
node = node.childNodes[off + (dir < 0 ? -1 : 0)];
if (node.nodeType == 1 && node.contentEditable == "false")
return false;
off = dir < 0 ? maxOffset(node) : 0;
} else {
return false;
}
}
}
function maxOffset(node) {
return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;
}
function flattenRect(rect, left) {
let x2 = left ? rect.left : rect.right;
return { left: x2, right: x2, top: rect.top, bottom: rect.bottom };
}
function windowRect(win) {
return {
left: 0,
right: win.innerWidth,
top: 0,
bottom: win.innerHeight
};
}
function getScale(elt, rect) {
let scaleX = rect.width / elt.offsetWidth;
let scaleY = rect.height / elt.offsetHeight;
if (scaleX > 0.995 && scaleX < 1.005 || !isFinite(scaleX) || Math.abs(rect.width - elt.offsetWidth) < 1)
scaleX = 1;
if (scaleY > 0.995 && scaleY < 1.005 || !isFinite(scaleY) || Math.abs(rect.height - elt.offsetHeight) < 1)
scaleY = 1;
return { scaleX, scaleY };
}
function scrollRectIntoView(dom, rect, side, x2, y2, xMargin, yMargin, ltr) {
let doc2 = dom.ownerDocument, win = doc2.defaultView || window;
for (let cur2 = dom, stop = false; cur2 && !stop; ) {
if (cur2.nodeType == 1) {
let bounding, top2 = cur2 == doc2.body;
let scaleX = 1, scaleY = 1;
if (top2) {
bounding = windowRect(win);
} else {
if (/^(fixed|sticky)$/.test(getComputedStyle(cur2).position))
stop = true;
if (cur2.scrollHeight <= cur2.clientHeight && cur2.scrollWidth <= cur2.clientWidth) {
cur2 = cur2.assignedSlot || cur2.parentNode;
continue;
}
let rect2 = cur2.getBoundingClientRect();
({ scaleX, scaleY } = getScale(cur2, rect2));
bounding = {
left: rect2.left,
right: rect2.left + cur2.clientWidth * scaleX,
top: rect2.top,
bottom: rect2.top + cur2.clientHeight * scaleY
};
}
let moveX = 0, moveY = 0;
if (y2 == "nearest") {
if (rect.top < bounding.top) {
moveY = -(bounding.top - rect.top + yMargin);
if (side > 0 && rect.bottom > bounding.bottom + moveY)
moveY = rect.bottom - bounding.bottom + moveY + yMargin;
} else if (rect.bottom > bounding.bottom) {
moveY = rect.bottom - bounding.bottom + yMargin;
if (side < 0 && rect.top - moveY < bounding.top)
moveY = -(bounding.top + moveY - rect.top + yMargin);
}
} else {
let rectHeight = rect.bottom - rect.top, boundingHeight = bounding.bottom - bounding.top;
let targetTop = y2 == "center" && rectHeight <= boundingHeight ? rect.top + rectHeight / 2 - boundingHeight / 2 : y2 == "start" || y2 == "center" && side < 0 ? rect.top - yMargin : rect.bottom - boundingHeight + yMargin;
moveY = targetTop - bounding.top;
}
if (x2 == "nearest") {
if (rect.left < bounding.left) {
moveX = -(bounding.left - rect.left + xMargin);
if (side > 0 && rect.right > bounding.right + moveX)
moveX = rect.right - bounding.right + moveX + xMargin;
} else if (rect.right > bounding.right) {
moveX = rect.right - bounding.right + xMargin;
if (side < 0 && rect.left < bounding.left + moveX)
moveX = -(bounding.left + moveX - rect.left + xMargin);
}
} else {
let targetLeft = x2 == "center" ? rect.left + (rect.right - rect.left) / 2 - (bounding.right - bounding.left) / 2 : x2 == "start" == ltr ? rect.left - xMargin : rect.right - (bounding.right - bounding.left) + xMargin;
moveX = targetLeft - bounding.left;
}
if (moveX || moveY) {
if (top2) {
win.scrollBy(moveX, moveY);
} else {
let movedX = 0, movedY = 0;
if (moveY) {
let start = cur2.scrollTop;
cur2.scrollTop += moveY / scaleY;
movedY = (cur2.scrollTop - start) * scaleY;
}
if (moveX) {
let start = cur2.scrollLeft;
cur2.scrollLeft += moveX / scaleX;
movedX = (cur2.scrollLeft - start) * scaleX;
}
rect = {
left: rect.left - movedX,
top: rect.top - movedY,
right: rect.right - movedX,
bottom: rect.bottom - movedY
};
if (movedX && Math.abs(movedX - moveX) < 1)
x2 = "nearest";
if (movedY && Math.abs(movedY - moveY) < 1)
y2 = "nearest";
}
}
if (top2)
break;
cur2 = cur2.assignedSlot || cur2.parentNode;
} else if (cur2.nodeType == 11) {
cur2 = cur2.host;
} else {
break;
}
}
}
function scrollableParent(dom) {
let doc2 = dom.ownerDocument;
for (let cur2 = dom.parentNode; cur2; ) {
if (cur2 == doc2.body) {
break;
} else if (cur2.nodeType == 1) {
if (cur2.scrollHeight > cur2.clientHeight || cur2.scrollWidth > cur2.clientWidth)
return cur2;
cur2 = cur2.assignedSlot || cur2.parentNode;
} else if (cur2.nodeType == 11) {
cur2 = cur2.host;
} else {
break;
}
}
return null;
}
class DOMSelectionState {
constructor() {
this.anchorNode = null;
this.anchorOffset = 0;
this.focusNode = null;
this.focusOffset = 0;
}
eq(domSel) {
return this.anchorNode == domSel.anchorNode && this.anchorOffset == domSel.anchorOffset && this.focusNode == domSel.focusNode && this.focusOffset == domSel.focusOffset;
}
setRange(range) {
let { anchorNode, focusNode } = range;
this.set(anchorNode, Math.min(range.anchorOffset, anchorNode ? maxOffset(anchorNode) : 0), focusNode, Math.min(range.focusOffset, focusNode ? maxOffset(focusNode) : 0));
}
set(anchorNode, anchorOffset, focusNode, focusOffset) {
this.anchorNode = anchorNode;
this.anchorOffset = anchorOffset;
this.focusNode = focusNode;
this.focusOffset = focusOffset;
}
}
let preventScrollSupported = null;
function focusPreventScroll(dom) {
if (dom.setActive)
return dom.setActive();
if (preventScrollSupported)
return dom.focus(preventScrollSupported);
let stack = [];
for (let cur2 = dom; cur2; cur2 = cur2.parentNode) {
stack.push(cur2, cur2.scrollTop, cur2.scrollLeft);
if (cur2 == cur2.ownerDocument)
break;
}
dom.focus(preventScrollSupported == null ? {
get preventScroll() {
preventScrollSupported = { preventScroll: true };
return true;
}
} : void 0);
if (!preventScrollSupported) {
preventScrollSupported = false;
for (let i2 = 0; i2 < stack.length; ) {
let elt = stack[i2++], top2 = stack[i2++], left = stack[i2++];
if (elt.scrollTop != top2)
elt.scrollTop = top2;
if (elt.scrollLeft != left)
elt.scrollLeft = left;
}
}
}
let scratchRange;
function textRange(node, from, to = from) {
let range = scratchRange || (scratchRange = document.createRange());
range.setEnd(node, to);
range.setStart(node, from);
return range;
}
function dispatchKey(elt, name2, code2) {
let options = { key: name2, code: name2, keyCode: code2, which: code2, cancelable: true };
let down = new KeyboardEvent("keydown", options);
down.synthetic = true;
elt.dispatchEvent(down);
let up = new KeyboardEvent("keyup", options);
up.synthetic = true;
elt.dispatchEvent(up);
return down.defaultPrevented || up.defaultPrevented;
}
function getRoot(node) {
while (node) {
if (node && (node.nodeType == 9 || node.nodeType == 11 && node.host))
return node;
node = node.assignedSlot || node.parentNode;
}
return null;
}
function clearAttributes(node) {
while (node.attributes.length)
node.removeAttributeNode(node.attributes[0]);
}
function atElementStart(doc2, selection) {
let node = selection.focusNode, offset = selection.focusOffset;
if (!node || selection.anchorNode != node || selection.anchorOffset != offset)
return false;
offset = Math.min(offset, maxOffset(node));
for (; ; ) {
if (offset) {
if (node.nodeType != 1)
return false;
let prev = node.childNodes[offset - 1];
if (prev.contentEditable == "false")
offset--;
else {
node = prev;
offset = maxOffset(node);
}
} else if (node == doc2) {
return true;
} else {
offset = domIndex(node);
node = node.parentNode;
}
}
}
function isScrolledToBottom(elt) {
return elt.scrollTop > Math.max(1, elt.scrollHeight - elt.clientHeight - 4);
}
class DOMPos {
constructor(node, offset, precise = true) {
this.node = node;
this.offset = offset;
this.precise = precise;
}
static before(dom, precise) {
return new DOMPos(dom.parentNode, domIndex(dom), precise);
}
static after(dom, precise) {
return new DOMPos(dom.parentNode, domIndex(dom) + 1, precise);
}
}
const noChildren = [];
class ContentView {
constructor() {
this.parent = null;
this.dom = null;
this.flags = 2;
}
get overrideDOMText() {
return null;
}
get posAtStart() {
return this.parent ? this.parent.posBefore(this) : 0;
}
get posAtEnd() {
return this.posAtStart + this.length;
}
posBefore(view) {
let pos = this.posAtStart;
for (let child of this.children) {
if (child == view)
return pos;
pos += child.length + child.breakAfter;
}
throw new RangeError("Invalid child in posBefore");
}
posAfter(view) {
return this.posBefore(view) + view.length;
}
sync(view, track) {
if (this.flags & 2) {
let parent = this.dom;
let prev = null, next;
for (let child of this.children) {
if (child.flags & 7) {
if (!child.dom && (next = prev ? prev.nextSibling : parent.firstChild)) {
let contentView = ContentView.get(next);
if (!contentView || !contentView.parent && contentView.canReuseDOM(child))
child.reuseDOM(next);
}
child.sync(view, track);
child.flags &= ~7;
}
next = prev ? prev.nextSibling : parent.firstChild;
if (track && !track.written && track.node == parent && next != child.dom)
track.written = true;
if (child.dom.parentNode == parent) {
while (next && next != child.dom)
next = rm$1(next);
} else {
parent.insertBefore(child.dom, next);
}
prev = child.dom;
}
next = prev ? prev.nextSibling : parent.firstChild;
if (next && track && track.node == parent)
track.written = true;
while (next)
next = rm$1(next);
} else if (this.flags & 1) {
for (let child of this.children)
if (child.flags & 7) {
child.sync(view, track);
child.flags &= ~7;
}
}
}
reuseDOM(_dom) {
}
localPosFromDOM(node, offset) {
let after;
if (node == this.dom) {
after = this.dom.childNodes[offset];
} else {
let bias = maxOffset(node) == 0 ? 0 : offset == 0 ? -1 : 1;
for (; ; ) {
let parent = node.parentNode;
if (parent == this.dom)
break;
if (bias == 0 && parent.firstChild != parent.lastChild) {
if (node == parent.firstChild)
bias = -1;
else
bias = 1;
}
node = parent;
}
if (bias < 0)
after = node;
else
after = node.nextSibling;
}
if (after == this.dom.firstChild)
return 0;
while (after && !ContentView.get(after))
after = after.nextSibling;
if (!after)
return this.length;
for (let i2 = 0, pos = 0; ; i2++) {
let child = this.children[i2];
if (child.dom == after)
return pos;
pos += child.length + child.breakAfter;
}
}
domBoundsAround(from, to, offset = 0) {
let fromI = -1, fromStart = -1, toI = -1, toEnd = -1;
for (let i2 = 0, pos = offset, prevEnd = offset; i2 < this.children.length; i2++) {
let child = this.children[i2], end = pos + child.length;
if (pos < from && end > to)
return child.domBoundsAround(from, to, pos);
if (end >= from && fromI == -1) {
fromI = i2;
fromStart = pos;
}
if (pos > to && child.dom.parentNode == this.dom) {
toI = i2;
toEnd = prevEnd;
break;
}
prevEnd = end;
pos = end + child.breakAfter;
}
return {
from: fromStart,
to: toEnd < 0 ? offset + this.length : toEnd,
startDOM: (fromI ? this.children[fromI - 1].dom.nextSibling : null) || this.dom.firstChild,
endDOM: toI < this.children.length && toI >= 0 ? this.children[toI].dom : null
};
}
markDirty(andParent = false) {
this.flags |= 2;
this.markParentsDirty(andParent);
}
markParentsDirty(childList) {
for (let parent = this.parent; parent; parent = parent.parent) {
if (childList)
parent.flags |= 2;
if (parent.flags & 1)
return;
parent.flags |= 1;
childList = false;
}
}
setParent(parent) {
if (this.parent != parent) {
this.parent = parent;
if (this.flags & 7)
this.markParentsDirty(true);
}
}
setDOM(dom) {
if (this.dom == dom)
return;
if (this.dom)
this.dom.cmView = null;
this.dom = dom;
dom.cmView = this;
}
get rootView() {
for (let v = this; ; ) {
let parent = v.parent;
if (!parent)
return v;
v = parent;
}
}
replaceChildren(from, to, children = noChildren) {
this.markDirty();
for (let i2 = from; i2 < to; i2++) {
let child = this.children[i2];
if (child.parent == this && children.indexOf(child) < 0)
child.destroy();
}
this.children.splice(from, to - from, ...children);
for (let i2 = 0; i2 < children.length; i2++)
children[i2].setParent(this);
}
ignoreMutation(_rec) {
return false;
}
ignoreEvent(_event) {
return false;
}
childCursor(pos = this.length) {
return new ChildCursor(this.children, pos, this.children.length);
}
childPos(pos, bias = 1) {
return this.childCursor().findPos(pos, bias);
}
toString() {
let name2 = this.constructor.name.replace("View", "");
return name2 + (this.children.length ? "(" + this.children.join() + ")" : this.length ? "[" + (name2 == "Text" ? this.text : this.length) + "]" : "") + (this.breakAfter ? "#" : "");
}
static get(node) {
return node.cmView;
}
get isEditable() {
return true;
}
get isWidget() {
return false;
}
get isHidden() {
return false;
}
merge(from, to, source, hasStart, openStart, openEnd) {
return false;
}
become(other) {
return false;
}
canReuseDOM(other) {
return other.constructor == this.constructor && !((this.flags | other.flags) & 8);
}
// When this is a zero-length view with a side, this should return a
// number <= 0 to indicate it is before its position, or a
// number > 0 when after its position.
getSide() {
return 0;
}
destroy() {
for (let child of this.children)
if (child.parent == this)
child.destroy();
this.parent = null;
}
}
ContentView.prototype.breakAfter = 0;
function rm$1(dom) {
let next = dom.nextSibling;
dom.parentNode.removeChild(dom);
return next;
}
class ChildCursor {
constructor(children, pos, i2) {
this.children = children;
this.pos = pos;
this.i = i2;
this.off = 0;
}
findPos(pos, bias = 1) {
for (; ; ) {
if (pos > this.pos || pos == this.pos && (bias > 0 || this.i == 0 || this.children[this.i - 1].breakAfter)) {
this.off = pos - this.pos;
return this;
}
let next = this.children[--this.i];
this.pos -= next.length + next.breakAfter;
}
}
}
function replaceRange(parent, fromI, fromOff, toI, toOff, insert2, breakAtStart, openStart, openEnd) {
let { children } = parent;
let before = children.length ? children[fromI] : null;
let last = insert2.length ? insert2[insert2.length - 1] : null;
let breakAtEnd = last ? last.breakAfter : breakAtStart;
if (fromI == toI && before && !breakAtStart && !breakAtEnd && insert2.length < 2 && before.merge(fromOff, toOff, insert2.length ? last : null, fromOff == 0, openStart, openEnd))
return;
if (toI < children.length) {
let after = children[toI];
if (after && (toOff < after.length || after.breakAfter && (last === null || last === void 0 ? void 0 : last.breakAfter))) {
if (fromI == toI) {
after = after.split(toOff);
toOff = 0;
}
if (!breakAtEnd && last && after.merge(0, toOff, last, true, 0, openEnd)) {
insert2[insert2.length - 1] = after;
} else {
if (toOff || after.children.length && !after.children[0].length)
after.merge(0, toOff, null, false, 0, openEnd);
insert2.push(after);
}
} else if (after === null || after === void 0 ? void 0 : after.breakAfter) {
if (last)
last.breakAfter = 1;
else
breakAtStart = 1;
}
toI++;
}
if (before) {
before.breakAfter = breakAtStart;
if (fromOff > 0) {
if (!breakAtStart && insert2.length && before.merge(fromOff, before.length, insert2[0], false, openStart, 0)) {
before.breakAfter = insert2.shift().breakAfter;
} else if (fromOff < before.length || before.children.length && before.children[before.children.length - 1].length == 0) {
before.merge(fromOff, before.length, null, false, openStart, 0);
}
fromI++;
}
}
while (fromI < toI && insert2.length) {
if (children[toI - 1].become(insert2[insert2.length - 1])) {
toI--;
insert2.pop();
openEnd = insert2.length ? 0 : openStart;
} else if (children[fromI].become(insert2[0])) {
fromI++;
insert2.shift();
openStart = insert2.length ? 0 : openEnd;
} else {
break;
}
}
if (!insert2.length && fromI && toI < children.length && !children[fromI - 1].breakAfter && children[toI].merge(0, 0, children[fromI - 1], false, openStart, openEnd))
fromI--;
if (fromI < toI || insert2.length)
parent.replaceChildren(fromI, toI, insert2);
}
function mergeChildrenInto(parent, from, to, insert2, openStart, openEnd) {
let cur2 = parent.childCursor();
let { i: toI, off: toOff } = cur2.findPos(to, 1);
let { i: fromI, off: fromOff } = cur2.findPos(from, -1);
let dLen = from - to;
for (let view of insert2)
dLen += view.length;
parent.length += dLen;
replaceRange(parent, fromI, fromOff, toI, toOff, insert2, 0, openStart, openEnd);
}
let nav = typeof navigator != "undefined" ? navigator : { userAgent: "", vendor: "", platform: "" };
let doc = typeof document != "undefined" ? document : { documentElement: { style: {} } };
const ie_edge = /* @__PURE__ */ /Edge\/(\d+)/.exec(nav.userAgent);
const ie_upto10 = /* @__PURE__ */ /MSIE \d/.test(nav.userAgent);
const ie_11up = /* @__PURE__ */ /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(nav.userAgent);
const ie = !!(ie_upto10 || ie_11up || ie_edge);
const gecko = !ie && /* @__PURE__ */ /gecko\/(\d+)/i.test(nav.userAgent);
const chrome = !ie && /* @__PURE__ */ /Chrome\/(\d+)/.exec(nav.userAgent);
const webkit = "webkitFontSmoothing" in doc.documentElement.style;
const safari = !ie && /* @__PURE__ */ /Apple Computer/.test(nav.vendor);
const ios = safari && (/* @__PURE__ */ /Mobile\/\w+/.test(nav.userAgent) || nav.maxTouchPoints > 2);
var browser = {
mac: ios || /* @__PURE__ */ /Mac/.test(nav.platform),
windows: /* @__PURE__ */ /Win/.test(nav.platform),
linux: /* @__PURE__ */ /Linux|X11/.test(nav.platform),
ie,
ie_version: ie_upto10 ? doc.documentMode || 6 : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0,
gecko,
gecko_version: gecko ? +(/* @__PURE__ */ /Firefox\/(\d+)/.exec(nav.userAgent) || [0, 0])[1] : 0,
chrome: !!chrome,
chrome_version: chrome ? +chrome[1] : 0,
ios,
android: /* @__PURE__ */ /Android\b/.test(nav.userAgent),
webkit,
safari,
webkit_version: webkit ? +(/* @__PURE__ */ /\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0,
tabSize: doc.documentElement.style.tabSize != null ? "tab-size" : "-moz-tab-size"
};
const MaxJoinLen = 256;
class TextView extends ContentView {
constructor(text) {
super();
this.text = text;
}
get length() {
return this.text.length;
}
createDOM(textDOM) {
this.setDOM(textDOM || document.createTextNode(this.text));
}
sync(view, track) {
if (!this.dom)
this.createDOM();
if (this.dom.nodeValue != this.text) {
if (track && track.node == this.dom)
track.written = true;
this.dom.nodeValue = this.text;
}
}
reuseDOM(dom) {
if (dom.nodeType == 3)
this.createDOM(dom);
}
merge(from, to, source) {
if (this.flags & 8 || source && (!(source instanceof TextView) || this.length - (to - from) + source.length > MaxJoinLen || source.flags & 8))
return false;
this.text = this.text.slice(0, from) + (source ? source.text : "") + this.text.slice(to);
this.markDirty();
return true;
}
split(from) {
let result2 = new TextView(this.text.slice(from));
this.text = this.text.slice(0, from);
this.markDirty();
result2.flags |= this.flags & 8;
return result2;
}
localPosFromDOM(node, offset) {
return node == this.dom ? offset : offset ? this.text.length : 0;
}
domAtPos(pos) {
return new DOMPos(this.dom, pos);
}
domBoundsAround(_from, _to, offset) {
return { from: offset, to: offset + this.length, startDOM: this.dom, endDOM: this.dom.nextSibling };
}
coordsAt(pos, side) {
return textCoords(this.dom, pos, side);
}
}
class MarkView extends ContentView {
constructor(mark, children = [], length = 0) {
super();
this.mark = mark;
this.children = children;
this.length = length;
for (let ch of children)
ch.setParent(this);
}
setAttrs(dom) {
clearAttributes(dom);
if (this.mark.class)
dom.className = this.mark.class;
if (this.mark.attrs)
for (let name2 in this.mark.attrs)
dom.setAttribute(name2, this.mark.attrs[name2]);
return dom;
}
canReuseDOM(other) {
return super.canReuseDOM(other) && !((this.flags | other.flags) & 8);
}
reuseDOM(node) {
if (node.nodeName == this.mark.tagName.toUpperCase()) {
this.setDOM(node);
this.flags |= 4 | 2;
}
}
sync(view, track) {
if (!this.dom)
this.setDOM(this.setAttrs(document.createElement(this.mark.tagName)));
else if (this.flags & 4)
this.setAttrs(this.dom);
super.sync(view, track);
}
merge(from, to, source, _hasStart, openStart, openEnd) {
if (source && (!(source instanceof MarkView && source.mark.eq(this.mark)) || from && openStart <= 0 || to < this.length && openEnd <= 0))
return false;
mergeChildrenInto(this, from, to, source ? source.children.slice() : [], openStart - 1, openEnd - 1);
this.markDirty();
return true;
}
split(from) {
let result2 = [], off = 0, detachFrom = -1, i2 = 0;
for (let elt of this.children) {
let end = off + elt.length;
if (end > from)
result2.push(off < from ? elt.split(from - off) : elt);
if (detachFrom < 0 && off >= from)
detachFrom = i2;
off = end;
i2++;
}
let length = this.length - from;
this.length = from;
if (detachFrom > -1) {
this.children.length = detachFrom;
this.markDirty();
}
return new MarkView(this.mark, result2, length);
}
domAtPos(pos) {
return inlineDOMAtPos(this, pos);
}
coordsAt(pos, side) {
return coordsInChildren(this, pos, side);
}
}
function textCoords(text, pos, side) {
let length = text.nodeValue.length;
if (pos > length)
pos = length;
let from = pos, to = pos, flatten2 = 0;
if (pos == 0 && side < 0 || pos == length && side >= 0) {
if (!(browser.chrome || browser.gecko)) {
if (pos) {
from--;
flatten2 = 1;
} else if (to < length) {
to++;
flatten2 = -1;
}
}
} else {
if (side < 0)
from--;
else if (to < length)
to++;
}
let rects = textRange(text, from, to).getClientRects();
if (!rects.length)
return null;
let rect = rects[(flatten2 ? flatten2 < 0 : side >= 0) ? 0 : rects.length - 1];
if (browser.safari && !flatten2 && rect.width == 0)
rect = Array.prototype.find.call(rects, (r) => r.width) || rect;
return flatten2 ? flattenRect(rect, flatten2 < 0) : rect || null;
}
class WidgetView extends ContentView {
static create(widget, length, side) {
return new WidgetView(widget, length, side);
}
constructor(widget, length, side) {
super();
this.widget = widget;
this.length = length;
this.side = side;
this.prevWidget = null;
}
split(from) {
let result2 = WidgetView.create(this.widget, this.length - from, this.side);
this.length -= from;
return result2;
}
sync(view) {
if (!this.dom || !this.widget.updateDOM(this.dom, view)) {
if (this.dom && this.prevWidget)
this.prevWidget.destroy(this.dom);
this.prevWidget = null;
this.setDOM(this.widget.toDOM(view));
if (!this.widget.editable)
this.dom.contentEditable = "false";
}
}
getSide() {
return this.side;
}
merge(from, to, source, hasStart, openStart, openEnd) {
if (source && (!(source instanceof WidgetView) || !this.widget.compare(source.widget) || from > 0 && openStart <= 0 || to < this.length && openEnd <= 0))
return false;
this.length = from + (source ? source.length : 0) + (this.length - to);
return true;
}
become(other) {
if (other instanceof WidgetView && other.side == this.side && this.widget.constructor == other.widget.constructor) {
if (!this.widget.compare(other.widget))
this.markDirty(true);
if (this.dom && !this.prevWidget)
this.prevWidget = this.widget;
this.widget = other.widget;
this.length = other.length;
return true;
}
return false;
}
ignoreMutation() {
return true;
}
ignoreEvent(event) {
return this.widget.ignoreEvent(event);
}
get overrideDOMText() {
if (this.length == 0)
return Text.empty;
let top2 = this;
while (top2.parent)
top2 = top2.parent;
let { view } = top2, text = view && view.state.doc, start = this.posAtStart;
return text ? text.slice(start, start + this.length) : Text.empty;
}
domAtPos(pos) {
return (this.length ? pos == 0 : this.side > 0) ? DOMPos.before(this.dom) : DOMPos.after(this.dom, pos == this.length);
}
domBoundsAround() {
return null;
}
coordsAt(pos, side) {
let custom = this.widget.coordsAt(this.dom, pos, side);
if (custom)
return custom;
let rects = this.dom.getClientRects(), rect = null;
if (!rects.length)
return null;
let fromBack = this.side ? this.side < 0 : pos > 0;
for (let i2 = fromBack ? rects.length - 1 : 0; ; i2 += fromBack ? -1 : 1) {
rect = rects[i2];
if (pos > 0 ? i2 == 0 : i2 == rects.length - 1 || rect.top < rect.bottom)
break;
}
return flattenRect(rect, !fromBack);
}
get isEditable() {
return false;
}
get isWidget() {
return true;
}
get isHidden() {
return this.widget.isHidden;
}
destroy() {
super.destroy();
if (this.dom)
this.widget.destroy(this.dom);
}
}
class WidgetBufferView extends ContentView {
constructor(side) {
super();
this.side = side;
}
get length() {
return 0;
}
merge() {
return false;
}
become(other) {
return other instanceof WidgetBufferView && other.side == this.side;
}
split() {
return new WidgetBufferView(this.side);
}
sync() {
if (!this.dom) {
let dom = document.createElement("img");
dom.className = "cm-widgetBuffer";
dom.setAttribute("aria-hidden", "true");
this.setDOM(dom);
}
}
getSide() {
return this.side;
}
domAtPos(pos) {
return this.side > 0 ? DOMPos.before(this.dom) : DOMPos.after(this.dom);
}
localPosFromDOM() {
return 0;
}
domBoundsAround() {
return null;
}
coordsAt(pos) {
return this.dom.getBoundingClientRect();
}
get overrideDOMText() {
return Text.empty;
}
get isHidden() {
return true;
}
}
TextView.prototype.children = WidgetView.prototype.children = WidgetBufferView.prototype.children = noChildren;
function inlineDOMAtPos(parent, pos) {
let dom = parent.dom, { children } = parent, i2 = 0;
for (let off = 0; i2 < children.length; i2++) {
let child = children[i2], end = off + child.length;
if (end == off && child.getSide() <= 0)
continue;
if (pos > off && pos < end && child.dom.parentNode == dom)
return child.domAtPos(pos - off);
if (pos <= off)
break;
off = end;
}
for (let j2 = i2; j2 > 0; j2--) {
let prev = children[j2 - 1];
if (prev.dom.parentNode == dom)
return prev.domAtPos(prev.length);
}
for (let j2 = i2; j2 < children.length; j2++) {
let next = children[j2];
if (next.dom.parentNode == dom)
return next.domAtPos(0);
}
return new DOMPos(dom, 0);
}
function joinInlineInto(parent, view, open) {
let last, { children } = parent;
if (open > 0 && view instanceof MarkView && children.length && (last = children[children.length - 1]) instanceof MarkView && last.mark.eq(view.mark)) {
joinInlineInto(last, view.children[0], open - 1);
} else {
children.push(view);
view.setParent(parent);
}
parent.length += view.length;
}
function coordsInChildren(view, pos, side) {
let before = null, beforePos = -1, after = null, afterPos = -1;
function scan(view2, pos2) {
for (let i2 = 0, off = 0; i2 < view2.children.length && off <= pos2; i2++) {
let child = view2.children[i2], end = off + child.length;
if (end >= pos2) {
if (child.children.length) {
scan(child, pos2 - off);
} else if ((!after || after.isHidden && side > 0) && (end > pos2 || off == end && child.getSide() > 0)) {
after = child;
afterPos = pos2 - off;
} else if (off < pos2 || off == end && child.getSide() < 0 && !child.isHidden) {
before = child;
beforePos = pos2 - off;
}
}
off = end;
}
}
scan(view, pos);
let target = (side < 0 ? before : after) || before || after;
if (target)
return target.coordsAt(Math.max(0, target == before ? beforePos : afterPos), side);
return fallbackRect(view);
}
function fallbackRect(view) {
let last = view.dom.lastChild;
if (!last)
return view.dom.getBoundingClientRect();
let rects = clientRectsFor(last);
return rects[rects.length - 1] || null;
}
function combineAttrs(source, target) {
for (let name2 in source) {
if (name2 == "class" && target.class)
target.class += " " + source.class;
else if (name2 == "style" && target.style)
target.style += ";" + source.style;
else
target[name2] = source[name2];
}
return target;
}
const noAttrs = /* @__PURE__ */ Object.create(null);
function attrsEq(a, b, ignore) {
if (a == b)
return true;
if (!a)
a = noAttrs;
if (!b)
b = noAttrs;
let keysA = Object.keys(a), keysB = Object.keys(b);
if (keysA.length - (ignore && keysA.indexOf(ignore) > -1 ? 1 : 0) != keysB.length - (ignore && keysB.indexOf(ignore) > -1 ? 1 : 0))
return false;
for (let key of keysA) {
if (key != ignore && (keysB.indexOf(key) == -1 || a[key] !== b[key]))
return false;
}
return true;
}
function updateAttrs(dom, prev, attrs) {
let changed = false;
if (prev) {
for (let name2 in prev)
if (!(attrs && name2 in attrs)) {
changed = true;
if (name2 == "style")
dom.style.cssText = "";
else
dom.removeAttribute(name2);
}
}
if (attrs) {
for (let name2 in attrs)
if (!(prev && prev[name2] == attrs[name2])) {
changed = true;
if (name2 == "style")
dom.style.cssText = attrs[name2];
else
dom.setAttribute(name2, attrs[name2]);
}
}
return changed;
}
function getAttrs(dom) {
let attrs = /* @__PURE__ */ Object.create(null);
for (let i2 = 0; i2 < dom.attributes.length; i2++) {
let attr = dom.attributes[i2];
attrs[attr.name] = attr.value;
}
return attrs;
}
class LineView extends ContentView {
constructor() {
super(...arguments);
this.children = [];
this.length = 0;
this.prevAttrs = void 0;
this.attrs = null;
this.breakAfter = 0;
}
// Consumes source
merge(from, to, source, hasStart, openStart, openEnd) {
if (source) {
if (!(source instanceof LineView))
return false;
if (!this.dom)
source.transferDOM(this);
}
if (hasStart)
this.setDeco(source ? source.attrs : null);
mergeChildrenInto(this, from, to, source ? source.children.slice() : [], openStart, openEnd);
return true;
}
split(at) {
let end = new LineView();
end.breakAfter = this.breakAfter;
if (this.length == 0)
return end;
let { i: i2, off } = this.childPos(at);
if (off) {
end.append(this.children[i2].split(off), 0);
this.children[i2].merge(off, this.children[i2].length, null, false, 0, 0);
i2++;
}
for (let j2 = i2; j2 < this.children.length; j2++)
end.append(this.children[j2], 0);
while (i2 > 0 && this.children[i2 - 1].length == 0)
this.children[--i2].destroy();
this.children.length = i2;
this.markDirty();
this.length = at;
return end;
}
transferDOM(other) {
if (!this.dom)
return;
this.markDirty();
other.setDOM(this.dom);
other.prevAttrs = this.prevAttrs === void 0 ? this.attrs : this.prevAttrs;
this.prevAttrs = void 0;
this.dom = null;
}
setDeco(attrs) {
if (!attrsEq(this.attrs, attrs)) {
if (this.dom) {
this.prevAttrs = this.attrs;
this.markDirty();
}
this.attrs = attrs;
}
}
append(child, openStart) {
joinInlineInto(this, child, openStart);
}
// Only called when building a line view in ContentBuilder
addLineDeco(deco) {
let attrs = deco.spec.attributes, cls = deco.spec.class;
if (attrs)
this.attrs = combineAttrs(attrs, this.attrs || {});
if (cls)
this.attrs = combineAttrs({ class: cls }, this.attrs || {});
}
domAtPos(pos) {
return inlineDOMAtPos(this, pos);
}
reuseDOM(node) {
if (node.nodeName == "DIV") {
this.setDOM(node);
this.flags |= 4 | 2;
}
}
sync(view, track) {
var _a2;
if (!this.dom) {
this.setDOM(document.createElement("div"));
this.dom.className = "cm-line";
this.prevAttrs = this.attrs ? null : void 0;
} else if (this.flags & 4) {
clearAttributes(this.dom);
this.dom.className = "cm-line";
this.prevAttrs = this.attrs ? null : void 0;
}
if (this.prevAttrs !== void 0) {
updateAttrs(this.dom, this.prevAttrs, this.attrs);
this.dom.classList.add("cm-line");
this.prevAttrs = void 0;
}
super.sync(view, track);
let last = this.dom.lastChild;
while (last && ContentView.get(last) instanceof MarkView)
last = last.lastChild;
if (!last || !this.length || last.nodeName != "BR" && ((_a2 = ContentView.get(last)) === null || _a2 === void 0 ? void 0 : _a2.isEditable) == false && (!browser.ios || !this.children.some((ch) => ch instanceof TextView))) {
let hack = document.createElement("BR");
hack.cmIgnore = true;
this.dom.appendChild(hack);
}
}
measureTextSize() {
if (this.children.length == 0 || this.length > 20)
return null;
let totalWidth = 0, textHeight;
for (let child of this.children) {
if (!(child instanceof TextView) || /[^ -~]/.test(child.text))
return null;
let rects = clientRectsFor(child.dom);
if (rects.length != 1)
return null;
totalWidth += rects[0].width;
textHeight = rects[0].height;
}
return !totalWidth ? null : {
lineHeight: this.dom.getBoundingClientRect().height,
charWidth: totalWidth / this.length,
textHeight
};
}
coordsAt(pos, side) {
let rect = coordsInChildren(this, pos, side);
if (!this.children.length && rect && this.parent) {
let { heightOracle } = this.parent.view.viewState, height = rect.bottom - rect.top;
if (Math.abs(height - heightOracle.lineHeight) < 2 && heightOracle.textHeight < height) {
let dist2 = (height - heightOracle.textHeight) / 2;
return { top: rect.top + dist2, bottom: rect.bottom - dist2, left: rect.left, right: rect.left };
}
}
return rect;
}
become(_other) {
return false;
}
covers() {
return true;
}
static find(docView, pos) {
for (let i2 = 0, off = 0; i2 < docView.children.length; i2++) {
let block = docView.children[i2], end = off + block.length;
if (end >= pos) {
if (block instanceof LineView)
return block;
if (end > pos)
break;
}
off = end + block.breakAfter;
}
return null;
}
}
class BlockWidgetView extends ContentView {
constructor(widget, length, deco) {
super();
this.widget = widget;
this.length = length;
this.deco = deco;
this.breakAfter = 0;
this.prevWidget = null;
}
merge(from, to, source, _takeDeco, openStart, openEnd) {
if (source && (!(source instanceof BlockWidgetView) || !this.widget.compare(source.widget) || from > 0 && openStart <= 0 || to < this.length && openEnd <= 0))
return false;
this.length = from + (source ? source.length : 0) + (this.length - to);
return true;
}
domAtPos(pos) {
return pos == 0 ? DOMPos.before(this.dom) : DOMPos.after(this.dom, pos == this.length);
}
split(at) {
let len = this.length - at;
this.length = at;
let end = new BlockWidgetView(this.widget, len, this.deco);
end.breakAfter = this.breakAfter;
return end;
}
get children() {
return noChildren;
}
sync(view) {
if (!this.dom || !this.widget.updateDOM(this.dom, view)) {
if (this.dom && this.prevWidget)
this.prevWidget.destroy(this.dom);
this.prevWidget = null;
this.setDOM(this.widget.toDOM(view));
if (!this.widget.editable)
this.dom.contentEditable = "false";
}
}
get overrideDOMText() {
return this.parent ? this.parent.view.state.doc.slice(this.posAtStart, this.posAtEnd) : Text.empty;
}
domBoundsAround() {
return null;
}
become(other) {
if (other instanceof BlockWidgetView && other.widget.constructor == this.widget.constructor) {
if (!other.widget.compare(this.widget))
this.markDirty(true);
if (this.dom && !this.prevWidget)
this.prevWidget = this.widget;
this.widget = other.widget;
this.length = other.length;
this.deco = other.deco;
this.breakAfter = other.breakAfter;
return true;
}
return false;
}
ignoreMutation() {
return true;
}
ignoreEvent(event) {
return this.widget.ignoreEvent(event);
}
get isEditable() {
return false;
}
get isWidget() {
return true;
}
coordsAt(pos, side) {
return this.widget.coordsAt(this.dom, pos, side);
}
destroy() {
super.destroy();
if (this.dom)
this.widget.destroy(this.dom);
}
covers(side) {
let { startSide, endSide } = this.deco;
return startSide == endSide ? false : side < 0 ? startSide < 0 : endSide > 0;
}
}
class WidgetType {
/**
Compare this instance to another instance of the same type.
(TypeScript can't express this, but only instances of the same
specific class will be passed to this method.) This is used to
avoid redrawing widgets when they are replaced by a new
decoration of the same type. The default implementation just
returns `false`, which will cause new instances of the widget to
always be redrawn.
*/
eq(widget) {
return false;
}
/**
Update a DOM element created by a widget of the same type (but
different, non-`eq` content) to reflect this widget. May return
true to indicate that it could update, false to indicate it
couldn't (in which case the widget will be redrawn). The default
implementation just returns false.
*/
updateDOM(dom, view) {
return false;
}
/**
@internal
*/
compare(other) {
return this == other || this.constructor == other.constructor && this.eq(other);
}
/**
The estimated height this widget will have, to be used when
estimating the height of content that hasn't been drawn. May
return -1 to indicate you don't know. The default implementation
returns -1.
*/
get estimatedHeight() {
return -1;
}
/**
For inline widgets that are displayed inline (as opposed to
`inline-block`) and introduce line breaks (through `<br>` tags
or textual newlines), this must indicate the amount of line
breaks they introduce. Defaults to 0.
*/
get lineBreaks() {
return 0;
}
/**
Can be used to configure which kinds of events inside the widget
should be ignored by the editor. The default is to ignore all
events.
*/
ignoreEvent(event) {
return true;
}
/**
Override the way screen coordinates for positions at/in the
widget are found. `pos` will be the offset into the widget, and
`side` the side of the position that is being queried—less than
zero for before, greater than zero for after, and zero for
directly at that position.
*/
coordsAt(dom, pos, side) {
return null;
}
/**
@internal
*/
get isHidden() {
return false;
}
/**
@internal
*/
get editable() {
return false;
}
/**
This is called when the an instance of the widget is removed
from the editor view.
*/
destroy(dom) {
}
}
var BlockType = /* @__PURE__ */ function(BlockType2) {
BlockType2[BlockType2["Text"] = 0] = "Text";
BlockType2[BlockType2["WidgetBefore"] = 1] = "WidgetBefore";
BlockType2[BlockType2["WidgetAfter"] = 2] = "WidgetAfter";
BlockType2[BlockType2["WidgetRange"] = 3] = "WidgetRange";
return BlockType2;
}(BlockType || (BlockType = {}));
class Decoration extends RangeValue {
constructor(startSide, endSide, widget, spec) {
super();
this.startSide = startSide;
this.endSide = endSide;
this.widget = widget;
this.spec = spec;
}
/**
@internal
*/
get heightRelevant() {
return false;
}
/**
Create a mark decoration, which influences the styling of the
content in its range. Nested mark decorations will cause nested
DOM elements to be created. Nesting order is determined by
precedence of the [facet](https://codemirror.net/6/docs/ref/#view.EditorView^decorations), with
the higher-precedence decorations creating the inner DOM nodes.
Such elements are split on line boundaries and on the boundaries
of lower-precedence decorations.
*/
static mark(spec) {
return new MarkDecoration(spec);
}
/**
Create a widget decoration, which displays a DOM element at the
given position.
*/
static widget(spec) {
let side = Math.max(-1e4, Math.min(1e4, spec.side || 0)), block = !!spec.block;
side += block && !spec.inlineOrder ? side > 0 ? 3e8 : -4e8 : side > 0 ? 1e8 : -1e8;
return new PointDecoration(spec, side, side, block, spec.widget || null, false);
}
/**
Create a replace decoration which replaces the given range with
a widget, or simply hides it.
*/
static replace(spec) {
let block = !!spec.block, startSide, endSide;
if (spec.isBlockGap) {
startSide = -5e8;
endSide = 4e8;
} else {
let { start, end } = getInclusive(spec, block);
startSide = (start ? block ? -3e8 : -1 : 5e8) - 1;
endSide = (end ? block ? 2e8 : 1 : -6e8) + 1;
}
return new PointDecoration(spec, startSide, endSide, block, spec.widget || null, true);
}
/**
Create a line decoration, which can add DOM attributes to the
line starting at the given position.
*/
static line(spec) {
return new LineDecoration(spec);
}
/**
Build a [`DecorationSet`](https://codemirror.net/6/docs/ref/#view.DecorationSet) from the given
decorated range or ranges. If the ranges aren't already sorted,
pass `true` for `sort` to make the library sort them for you.
*/
static set(of, sort = false) {
return RangeSet.of(of, sort);
}
/**
@internal
*/
hasHeight() {
return this.widget ? this.widget.estimatedHeight > -1 : false;
}
}
Decoration.none = RangeSet.empty;
class MarkDecoration extends Decoration {
constructor(spec) {
let { start, end } = getInclusive(spec);
super(start ? -1 : 5e8, end ? 1 : -6e8, null, spec);
this.tagName = spec.tagName || "span";
this.class = spec.class || "";
this.attrs = spec.attributes || null;
}
eq(other) {
var _a2, _b;
return this == other || other instanceof MarkDecoration && this.tagName == other.tagName && (this.class || ((_a2 = this.attrs) === null || _a2 === void 0 ? void 0 : _a2.class)) == (other.class || ((_b = other.attrs) === null || _b === void 0 ? void 0 : _b.class)) && attrsEq(this.attrs, other.attrs, "class");
}
range(from, to = from) {
if (from >= to)
throw new RangeError("Mark decorations may not be empty");
return super.range(from, to);
}
}
MarkDecoration.prototype.point = false;
class LineDecoration extends Decoration {
constructor(spec) {
super(-2e8, -2e8, null, spec);
}
eq(other) {
return other instanceof LineDecoration && this.spec.class == other.spec.class && attrsEq(this.spec.attributes, other.spec.attributes);
}
range(from, to = from) {
if (to != from)
throw new RangeError("Line decoration ranges must be zero-length");
return super.range(from, to);
}
}
LineDecoration.prototype.mapMode = MapMode.TrackBefore;
LineDecoration.prototype.point = true;
class PointDecoration extends Decoration {
constructor(spec, startSide, endSide, block, widget, isReplace) {
super(startSide, endSide, widget, spec);
this.block = block;
this.isReplace = isReplace;
this.mapMode = !block ? MapMode.TrackDel : startSide <= 0 ? MapMode.TrackBefore : MapMode.TrackAfter;
}
// Only relevant when this.block == true
get type() {
return this.startSide != this.endSide ? BlockType.WidgetRange : this.startSide <= 0 ? BlockType.WidgetBefore : BlockType.WidgetAfter;
}
get heightRelevant() {
return this.block || !!this.widget && (this.widget.estimatedHeight >= 5 || this.widget.lineBreaks > 0);
}
eq(other) {
return other instanceof PointDecoration && widgetsEq(this.widget, other.widget) && this.block == other.block && this.startSide == other.startSide && this.endSide == other.endSide;
}
range(from, to = from) {
if (this.isReplace && (from > to || from == to && this.startSide > 0 && this.endSide <= 0))
throw new RangeError("Invalid range for replacement decoration");
if (!this.isReplace && to != from)
throw new RangeError("Widget decorations can only have zero-length ranges");
return super.range(from, to);
}
}
PointDecoration.prototype.point = true;
function getInclusive(spec, block = false) {
let { inclusiveStart: start, inclusiveEnd: end } = spec;
if (start == null)
start = spec.inclusive;
if (end == null)
end = spec.inclusive;
return { start: start !== null && start !== void 0 ? start : block, end: end !== null && end !== void 0 ? end : block };
}
function widgetsEq(a, b) {
return a == b || !!(a && b && a.compare(b));
}
function addRange(from, to, ranges, margin = 0) {
let last = ranges.length - 1;
if (last >= 0 && ranges[last] + margin >= from)
ranges[last] = Math.max(ranges[last], to);
else
ranges.push(from, to);
}
class ContentBuilder {
constructor(doc2, pos, end, disallowBlockEffectsFor) {
this.doc = doc2;
this.pos = pos;
this.end = end;
this.disallowBlockEffectsFor = disallowBlockEffectsFor;
this.content = [];
this.curLine = null;
this.breakAtStart = 0;
this.pendingBuffer = 0;
this.bufferMarks = [];
this.atCursorPos = true;
this.openStart = -1;
this.openEnd = -1;
this.text = "";
this.textOff = 0;
this.cursor = doc2.iter();
this.skip = pos;
}
posCovered() {
if (this.content.length == 0)
return !this.breakAtStart && this.doc.lineAt(this.pos).from != this.pos;
let last = this.content[this.content.length - 1];
return !(last.breakAfter || last instanceof BlockWidgetView && last.deco.endSide < 0);
}
getLine() {
if (!this.curLine) {
this.content.push(this.curLine = new LineView());
this.atCursorPos = true;
}
return this.curLine;
}
flushBuffer(active = this.bufferMarks) {
if (this.pendingBuffer) {
this.curLine.append(wrapMarks(new WidgetBufferView(-1), active), active.length);
this.pendingBuffer = 0;
}
}
addBlockWidget(view) {
this.flushBuffer();
this.curLine = null;
this.content.push(view);
}
finish(openEnd) {
if (this.pendingBuffer && openEnd <= this.bufferMarks.length)
this.flushBuffer();
else
this.pendingBuffer = 0;
if (!this.posCovered() && !(openEnd && this.content.length && this.content[this.content.length - 1] instanceof BlockWidgetView))
this.getLine();
}
buildText(length, active, openStart) {
while (length > 0) {
if (this.textOff == this.text.length) {
let { value, lineBreak, done } = this.cursor.next(this.skip);
this.skip = 0;
if (done)
throw new Error("Ran out of text content when drawing inline views");
if (lineBreak) {
if (!this.posCovered())
this.getLine();
if (this.content.length)
this.content[this.content.length - 1].breakAfter = 1;
else
this.breakAtStart = 1;
this.flushBuffer();
this.curLine = null;
this.atCursorPos = true;
length--;
continue;
} else {
this.text = value;
this.textOff = 0;
}
}
let take = Math.min(
this.text.length - this.textOff,
length,
512
/* T.Chunk */
);
this.flushBuffer(active.slice(active.length - openStart));
this.getLine().append(wrapMarks(new TextView(this.text.slice(this.textOff, this.textOff + take)), active), openStart);
this.atCursorPos = true;
this.textOff += take;
length -= take;
openStart = 0;
}
}
span(from, to, active, openStart) {
this.buildText(to - from, active, openStart);
this.pos = to;
if (this.openStart < 0)
this.openStart = openStart;
}
point(from, to, deco, active, openStart, index) {
if (this.disallowBlockEffectsFor[index] && deco instanceof PointDecoration) {
if (deco.block)
throw new RangeError("Block decorations may not be specified via plugins");
if (to > this.doc.lineAt(this.pos).to)
throw new RangeError("Decorations that replace line breaks may not be specified via plugins");
}
let len = to - from;
if (deco instanceof PointDecoration) {
if (deco.block) {
if (deco.startSide > 0 && !this.posCovered())
this.getLine();
this.addBlockWidget(new BlockWidgetView(deco.widget || new NullWidget("div"), len, deco));
} else {
let view = WidgetView.create(deco.widget || new NullWidget("span"), len, len ? 0 : deco.startSide);
let cursorBefore = this.atCursorPos && !view.isEditable && openStart <= active.length && (from < to || deco.startSide > 0);
let cursorAfter = !view.isEditable && (from < to || openStart > active.length || deco.startSide <= 0);
let line = this.getLine();
if (this.pendingBuffer == 2 && !cursorBefore && !view.isEditable)
this.pendingBuffer = 0;
this.flushBuffer(active);
if (cursorBefore) {
line.append(wrapMarks(new WidgetBufferView(1), active), openStart);
openStart = active.length + Math.max(0, openStart - active.length);
}
line.append(wrapMarks(view, active), openStart);
this.atCursorPos = cursorAfter;
this.pendingBuffer = !cursorAfter ? 0 : from < to || openStart > active.length ? 1 : 2;
if (this.pendingBuffer)
this.bufferMarks = active.slice();
}
} else if (this.doc.lineAt(this.pos).from == this.pos) {
this.getLine().addLineDeco(deco);
}
if (len) {
if (this.textOff + len <= this.text.length) {
this.textOff += len;
} else {
this.skip += len - (this.text.length - this.textOff);
this.text = "";
this.textOff = 0;
}
this.pos = to;
}
if (this.openStart < 0)
this.openStart = openStart;
}
static build(text, from, to, decorations2, dynamicDecorationMap) {
let builder = new ContentBuilder(text, from, to, dynamicDecorationMap);
builder.openEnd = RangeSet.spans(decorations2, from, to, builder);
if (builder.openStart < 0)
builder.openStart = builder.openEnd;
builder.finish(builder.openEnd);
return builder;
}
}
function wrapMarks(view, active) {
for (let mark of active)
view = new MarkView(mark, [view], view.length);
return view;
}
class NullWidget extends WidgetType {
constructor(tag) {
super();
this.tag = tag;
}
eq(other) {
return other.tag == this.tag;
}
toDOM() {
return document.createElement(this.tag);
}
updateDOM(elt) {
return elt.nodeName.toLowerCase() == this.tag;
}
get isHidden() {
return true;
}
}
var Direction = /* @__PURE__ */ function(Direction2) {
Direction2[Direction2["LTR"] = 0] = "LTR";
Direction2[Direction2["RTL"] = 1] = "RTL";
return Direction2;
}(Direction || (Direction = {}));
const LTR = Direction.LTR, RTL = Direction.RTL;
function dec(str) {
let result2 = [];
for (let i2 = 0; i2 < str.length; i2++)
result2.push(1 << +str[i2]);
return result2;
}
const LowTypes = /* @__PURE__ */ dec("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008");
const ArabicTypes = /* @__PURE__ */ dec("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333");
const Brackets = /* @__PURE__ */ Object.create(null), BracketStack = [];
for (let p of ["()", "[]", "{}"]) {
let l = /* @__PURE__ */ p.charCodeAt(0), r = /* @__PURE__ */ p.charCodeAt(1);
Brackets[l] = r;
Brackets[r] = -l;
}
function charType(ch) {
return ch <= 247 ? LowTypes[ch] : 1424 <= ch && ch <= 1524 ? 2 : 1536 <= ch && ch <= 1785 ? ArabicTypes[ch - 1536] : 1774 <= ch && ch <= 2220 ? 4 : 8192 <= ch && ch <= 8204 ? 256 : 64336 <= ch && ch <= 65023 ? 4 : 1;
}
const BidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;
class BidiSpan {
/**
The direction of this span.
*/
get dir() {
return this.level % 2 ? RTL : LTR;
}
/**
@internal
*/
constructor(from, to, level) {
this.from = from;
this.to = to;
this.level = level;
}
/**
@internal
*/
side(end, dir) {
return this.dir == dir == end ? this.to : this.from;
}
/**
@internal
*/
forward(forward, dir) {
return forward == (this.dir == dir);
}
/**
@internal
*/
static find(order, index, level, assoc) {
let maybe = -1;
for (let i2 = 0; i2 < order.length; i2++) {
let span = order[i2];
if (span.from <= index && span.to >= index) {
if (span.level == level)
return i2;
if (maybe < 0 || (assoc != 0 ? assoc < 0 ? span.from < index : span.to > index : order[maybe].level > span.level))
maybe = i2;
}
}
if (maybe < 0)
throw new RangeError("Index out of range");
return maybe;
}
}
function isolatesEq(a, b) {
if (a.length != b.length)
return false;
for (let i2 = 0; i2 < a.length; i2++) {
let iA = a[i2], iB = b[i2];
if (iA.from != iB.from || iA.to != iB.to || iA.direction != iB.direction || !isolatesEq(iA.inner, iB.inner))
return false;
}
return true;
}
const types = [];
function computeCharTypes(line, rFrom, rTo, isolates, outerType) {
for (let iI = 0; iI <= isolates.length; iI++) {
let from = iI ? isolates[iI - 1].to : rFrom, to = iI < isolates.length ? isolates[iI].from : rTo;
let prevType = iI ? 256 : outerType;
for (let i2 = from, prev = prevType, prevStrong = prevType; i2 < to; i2++) {
let type = charType(line.charCodeAt(i2));
if (type == 512)
type = prev;
else if (type == 8 && prevStrong == 4)
type = 16;
types[i2] = type == 4 ? 2 : type;
if (type & 7)
prevStrong = type;
prev = type;
}
for (let i2 = from, prev = prevType, prevStrong = prevType; i2 < to; i2++) {
let type = types[i2];
if (type == 128) {
if (i2 < to - 1 && prev == types[i2 + 1] && prev & 24)
type = types[i2] = prev;
else
types[i2] = 256;
} else if (type == 64) {
let end = i2 + 1;
while (end < to && types[end] == 64)
end++;
let replace = i2 && prev == 8 || end < rTo && types[end] == 8 ? prevStrong == 1 ? 1 : 8 : 256;
for (let j2 = i2; j2 < end; j2++)
types[j2] = replace;
i2 = end - 1;
} else if (type == 8 && prevStrong == 1) {
types[i2] = 1;
}
prev = type;
if (type & 7)
prevStrong = type;
}
}
}
function processBracketPairs(line, rFrom, rTo, isolates, outerType) {
let oppositeType = outerType == 1 ? 2 : 1;
for (let iI = 0, sI = 0, context = 0; iI <= isolates.length; iI++) {
let from = iI ? isolates[iI - 1].to : rFrom, to = iI < isolates.length ? isolates[iI].from : rTo;
for (let i2 = from, ch, br, type; i2 < to; i2++) {
if (br = Brackets[ch = line.charCodeAt(i2)]) {
if (br < 0) {
for (let sJ = sI - 3; sJ >= 0; sJ -= 3) {
if (BracketStack[sJ + 1] == -br) {
let flags = BracketStack[sJ + 2];
let type2 = flags & 2 ? outerType : !(flags & 4) ? 0 : flags & 1 ? oppositeType : outerType;
if (type2)
types[i2] = types[BracketStack[sJ]] = type2;
sI = sJ;
break;
}
}
} else if (BracketStack.length == 189) {
break;
} else {
BracketStack[sI++] = i2;
BracketStack[sI++] = ch;
BracketStack[sI++] = context;
}
} else if ((type = types[i2]) == 2 || type == 1) {
let embed = type == outerType;
context = embed ? 0 : 1;
for (let sJ = sI - 3; sJ >= 0; sJ -= 3) {
let cur2 = BracketStack[sJ + 2];
if (cur2 & 2)
break;
if (embed) {
BracketStack[sJ + 2] |= 2;
} else {
if (cur2 & 4)
break;
BracketStack[sJ + 2] |= 4;
}
}
}
}
}
}
function processNeutrals(rFrom, rTo, isolates, outerType) {
for (let iI = 0, prev = outerType; iI <= isolates.length; iI++) {
let from = iI ? isolates[iI - 1].to : rFrom, to = iI < isolates.length ? isolates[iI].from : rTo;
for (let i2 = from; i2 < to; ) {
let type = types[i2];
if (type == 256) {
let end = i2 + 1;
for (; ; ) {
if (end == to) {
if (iI == isolates.length)
break;
end = isolates[iI++].to;
to = iI < isolates.length ? isolates[iI].from : rTo;
} else if (types[end] == 256) {
end++;
} else {
break;
}
}
let beforeL = prev == 1;
let afterL = (end < rTo ? types[end] : outerType) == 1;
let replace = beforeL == afterL ? beforeL ? 1 : 2 : outerType;
for (let j2 = end, jI = iI, fromJ = jI ? isolates[jI - 1].to : rFrom; j2 > i2; ) {
if (j2 == fromJ) {
j2 = isolates[--jI].from;
fromJ = jI ? isolates[jI - 1].to : rFrom;
}
types[--j2] = replace;
}
i2 = end;
} else {
prev = type;
i2++;
}
}
}
}
function emitSpans(line, from, to, level, baseLevel, isolates, order) {
let ourType = level % 2 ? 2 : 1;
if (level % 2 == baseLevel % 2) {
for (let iCh = from, iI = 0; iCh < to; ) {
let sameDir = true, isNum = false;
if (iI == isolates.length || iCh < isolates[iI].from) {
let next = types[iCh];
if (next != ourType) {
sameDir = false;
isNum = next == 16;
}
}
let recurse = !sameDir && ourType == 1 ? [] : null;
let localLevel = sameDir ? level : level + 1;
let iScan = iCh;
run:
for (; ; ) {
if (iI < isolates.length && iScan == isolates[iI].from) {
if (isNum)
break run;
let iso = isolates[iI];
if (!sameDir)
for (let upto = iso.to, jI = iI + 1; ; ) {
if (upto == to)
break run;
if (jI < isolates.length && isolates[jI].from == upto)
upto = isolates[jI++].to;
else if (types[upto] == ourType)
break run;
else
break;
}
iI++;
if (recurse) {
recurse.push(iso);
} else {
if (iso.from > iCh)
order.push(new BidiSpan(iCh, iso.from, localLevel));
let dirSwap = iso.direction == LTR != !(localLevel % 2);
computeSectionOrder(line, dirSwap ? level + 1 : level, baseLevel, iso.inner, iso.from, iso.to, order);
iCh = iso.to;
}
iScan = iso.to;
} else if (iScan == to || (sameDir ? types[iScan] != ourType : types[iScan] == ourType)) {
break;
} else {
iScan++;
}
}
if (recurse)
emitSpans(line, iCh, iScan, level + 1, baseLevel, recurse, order);
else if (iCh < iScan)
order.push(new BidiSpan(iCh, iScan, localLevel));
iCh = iScan;
}
} else {
for (let iCh = to, iI = isolates.length; iCh > from; ) {
let sameDir = true, isNum = false;
if (!iI || iCh > isolates[iI - 1].to) {
let next = types[iCh - 1];
if (next != ourType) {
sameDir = false;
isNum = next == 16;
}
}
let recurse = !sameDir && ourType == 1 ? [] : null;
let localLevel = sameDir ? level : level + 1;
let iScan = iCh;
run:
for (; ; ) {
if (iI && iScan == isolates[iI - 1].to) {
if (isNum)
break run;
let iso = isolates[--iI];
if (!sameDir)
for (let upto = iso.from, jI = iI; ; ) {
if (upto == from)
break run;
if (jI && isolates[jI - 1].to == upto)
upto = isolates[--jI].from;
else if (types[upto - 1] == ourType)
break run;
else
break;
}
if (recurse) {
recurse.push(iso);
} else {
if (iso.to < iCh)
order.push(new BidiSpan(iso.to, iCh, localLevel));
let dirSwap = iso.direction == LTR != !(localLevel % 2);
computeSectionOrder(line, dirSwap ? level + 1 : level, baseLevel, iso.inner, iso.from, iso.to, order);
iCh = iso.from;
}
iScan = iso.from;
} else if (iScan == from || (sameDir ? types[iScan - 1] != ourType : types[iScan - 1] == ourType)) {
break;
} else {
iScan--;
}
}
if (recurse)
emitSpans(line, iScan, iCh, level + 1, baseLevel, recurse, order);
else if (iScan < iCh)
order.push(new BidiSpan(iScan, iCh, localLevel));
iCh = iScan;
}
}
}
function computeSectionOrder(line, level, baseLevel, isolates, from, to, order) {
let outerType = level % 2 ? 2 : 1;
computeCharTypes(line, from, to, isolates, outerType);
processBracketPairs(line, from, to, isolates, outerType);
processNeutrals(from, to, isolates, outerType);
emitSpans(line, from, to, level, baseLevel, isolates, order);
}
function computeOrder(line, direction, isolates) {
if (!line)
return [new BidiSpan(0, 0, direction == RTL ? 1 : 0)];
if (direction == LTR && !isolates.length && !BidiRE.test(line))
return trivialOrder(line.length);
if (isolates.length)
while (line.length > types.length)
types[types.length] = 256;
let order = [], level = direction == LTR ? 0 : 1;
computeSectionOrder(line, level, level, isolates, 0, line.length, order);
return order;
}
function trivialOrder(length) {
return [new BidiSpan(0, length, 0)];
}
let movedOver = "";
function moveVisually(line, order, dir, start, forward) {
var _a2;
let startIndex = start.head - line.from;
let spanI = BidiSpan.find(order, startIndex, (_a2 = start.bidiLevel) !== null && _a2 !== void 0 ? _a2 : -1, start.assoc);
let span = order[spanI], spanEnd = span.side(forward, dir);
if (startIndex == spanEnd) {
let nextI = spanI += forward ? 1 : -1;
if (nextI < 0 || nextI >= order.length)
return null;
span = order[spanI = nextI];
startIndex = span.side(!forward, dir);
spanEnd = span.side(forward, dir);
}
let nextIndex = findClusterBreak(line.text, startIndex, span.forward(forward, dir));
if (nextIndex < span.from || nextIndex > span.to)
nextIndex = spanEnd;
movedOver = line.text.slice(Math.min(startIndex, nextIndex), Math.max(startIndex, nextIndex));
let nextSpan = spanI == (forward ? order.length - 1 : 0) ? null : order[spanI + (forward ? 1 : -1)];
if (nextSpan && nextIndex == spanEnd && nextSpan.level + (forward ? 0 : 1) < span.level)
return EditorSelection.cursor(nextSpan.side(!forward, dir) + line.from, nextSpan.forward(forward, dir) ? 1 : -1, nextSpan.level);
return EditorSelection.cursor(nextIndex + line.from, span.forward(forward, dir) ? -1 : 1, span.level);
}
function autoDirection(text, from, to) {
for (let i2 = from; i2 < to; i2++) {
let type = charType(text.charCodeAt(i2));
if (type == 1)
return LTR;
if (type == 2 || type == 4)
return RTL;
}
return LTR;
}
const clickAddsSelectionRange = /* @__PURE__ */ Facet.define();
const dragMovesSelection$1 = /* @__PURE__ */ Facet.define();
const mouseSelectionStyle = /* @__PURE__ */ Facet.define();
const exceptionSink = /* @__PURE__ */ Facet.define();
const updateListener = /* @__PURE__ */ Facet.define();
const inputHandler$1 = /* @__PURE__ */ Facet.define();
const focusChangeEffect = /* @__PURE__ */ Facet.define();
const perLineTextDirection = /* @__PURE__ */ Facet.define({
combine: (values) => values.some((x2) => x2)
});
const nativeSelectionHidden = /* @__PURE__ */ Facet.define({
combine: (values) => values.some((x2) => x2)
});
class ScrollTarget {
constructor(range, y2 = "nearest", x2 = "nearest", yMargin = 5, xMargin = 5, isSnapshot = false) {
this.range = range;
this.y = y2;
this.x = x2;
this.yMargin = yMargin;
this.xMargin = xMargin;
this.isSnapshot = isSnapshot;
}
map(changes) {
return changes.empty ? this : new ScrollTarget(this.range.map(changes), this.y, this.x, this.yMargin, this.xMargin, this.isSnapshot);
}
clip(state) {
return this.range.to <= state.doc.length ? this : new ScrollTarget(EditorSelection.cursor(state.doc.length), this.y, this.x, this.yMargin, this.xMargin, this.isSnapshot);
}
}
const scrollIntoView$1 = /* @__PURE__ */ StateEffect.define({ map: (t2, ch) => t2.map(ch) });
function logException(state, exception, context) {
let handler = state.facet(exceptionSink);
if (handler.length)
handler[0](exception);
else if (window.onerror)
window.onerror(String(exception), context, void 0, void 0, exception);
else if (context)
console.error(context + ":", exception);
else
console.error(exception);
}
const editable = /* @__PURE__ */ Facet.define({ combine: (values) => values.length ? values[0] : true });
let nextPluginID = 0;
const viewPlugin = /* @__PURE__ */ Facet.define();
class ViewPlugin {
constructor(id2, create, domEventHandlers, domEventObservers, buildExtensions) {
this.id = id2;
this.create = create;
this.domEventHandlers = domEventHandlers;
this.domEventObservers = domEventObservers;
this.extension = buildExtensions(this);
}
/**
Define a plugin from a constructor function that creates the
plugin's value, given an editor view.
*/
static define(create, spec) {
const { eventHandlers, eventObservers, provide, decorations: deco } = spec || {};
return new ViewPlugin(nextPluginID++, create, eventHandlers, eventObservers, (plugin) => {
let ext = [viewPlugin.of(plugin)];
if (deco)
ext.push(decorations.of((view) => {
let pluginInst = view.plugin(plugin);
return pluginInst ? deco(pluginInst) : Decoration.none;
}));
if (provide)
ext.push(provide(plugin));
return ext;
});
}
/**
Create a plugin for a class whose constructor takes a single
editor view as argument.
*/
static fromClass(cls, spec) {
return ViewPlugin.define((view) => new cls(view), spec);
}
}
class PluginInstance {
constructor(spec) {
this.spec = spec;
this.mustUpdate = null;
this.value = null;
}
update(view) {
if (!this.value) {
if (this.spec) {
try {
this.value = this.spec.create(view);
} catch (e) {
logException(view.state, e, "CodeMirror plugin crashed");
this.deactivate();
}
}
} else if (this.mustUpdate) {
let update = this.mustUpdate;
this.mustUpdate = null;
if (this.value.update) {
try {
this.value.update(update);
} catch (e) {
logException(update.state, e, "CodeMirror plugin crashed");
if (this.value.destroy)
try {
this.value.destroy();
} catch (_) {
}
this.deactivate();
}
}
}
return this;
}
destroy(view) {
var _a2;
if ((_a2 = this.value) === null || _a2 === void 0 ? void 0 : _a2.destroy) {
try {
this.value.destroy();
} catch (e) {
logException(view.state, e, "CodeMirror plugin crashed");
}
}
}
deactivate() {
this.spec = this.value = null;
}
}
const editorAttributes = /* @__PURE__ */ Facet.define();
const contentAttributes = /* @__PURE__ */ Facet.define();
const decorations = /* @__PURE__ */ Facet.define();
const outerDecorations = /* @__PURE__ */ Facet.define();
const atomicRanges = /* @__PURE__ */ Facet.define();
const bidiIsolatedRanges = /* @__PURE__ */ Facet.define();
function getIsolatedRanges(view, line) {
let isolates = view.state.facet(bidiIsolatedRanges);
if (!isolates.length)
return isolates;
let sets = isolates.map((i2) => i2 instanceof Function ? i2(view) : i2);
let result2 = [];
RangeSet.spans(sets, line.from, line.to, {
point() {
},
span(fromDoc, toDoc, active, open) {
let from = fromDoc - line.from, to = toDoc - line.from;
let level = result2;
for (let i2 = active.length - 1; i2 >= 0; i2--, open--) {
let direction = active[i2].spec.bidiIsolate, update;
if (direction == null)
direction = autoDirection(line.text, from, to);
if (open > 0 && level.length && (update = level[level.length - 1]).to == from && update.direction == direction) {
update.to = to;
level = update.inner;
} else {
let add2 = { from, to, direction, inner: [] };
level.push(add2);
level = add2.inner;
}
}
}
});
return result2;
}
const scrollMargins = /* @__PURE__ */ Facet.define();
function getScrollMargins(view) {
let left = 0, right = 0, top2 = 0, bottom = 0;
for (let source of view.state.facet(scrollMargins)) {
let m = source(view);
if (m) {
if (m.left != null)
left = Math.max(left, m.left);
if (m.right != null)
right = Math.max(right, m.right);
if (m.top != null)
top2 = Math.max(top2, m.top);
if (m.bottom != null)
bottom = Math.max(bottom, m.bottom);
}
}
return { left, right, top: top2, bottom };
}
const styleModule = /* @__PURE__ */ Facet.define();
class ChangedRange {
constructor(fromA, toA, fromB, toB) {
this.fromA = fromA;
this.toA = toA;
this.fromB = fromB;
this.toB = toB;
}
join(other) {
return new ChangedRange(Math.min(this.fromA, other.fromA), Math.max(this.toA, other.toA), Math.min(this.fromB, other.fromB), Math.max(this.toB, other.toB));
}
addToSet(set) {
let i2 = set.length, me = this;
for (; i2 > 0; i2--) {
let range = set[i2 - 1];
if (range.fromA > me.toA)
continue;
if (range.toA < me.fromA)
break;
me = me.join(range);
set.splice(i2 - 1, 1);
}
set.splice(i2, 0, me);
return set;
}
static extendWithRanges(diff, ranges) {
if (ranges.length == 0)
return diff;
let result2 = [];
for (let dI = 0, rI = 0, posA = 0, posB = 0; ; dI++) {
let next = dI == diff.length ? null : diff[dI], off = posA - posB;
let end = next ? next.fromB : 1e9;
while (rI < ranges.length && ranges[rI] < end) {
let from = ranges[rI], to = ranges[rI + 1];
let fromB = Math.max(posB, from), toB = Math.min(end, to);
if (fromB <= toB)
new ChangedRange(fromB + off, toB + off, fromB, toB).addToSet(result2);
if (to > end)
break;
else
rI += 2;
}
if (!next)
return result2;
new ChangedRange(next.fromA, next.toA, next.fromB, next.toB).addToSet(result2);
posA = next.toA;
posB = next.toB;
}
}
}
class ViewUpdate {
constructor(view, state, transactions) {
this.view = view;
this.state = state;
this.transactions = transactions;
this.flags = 0;
this.startState = view.state;
this.changes = ChangeSet.empty(this.startState.doc.length);
for (let tr of transactions)
this.changes = this.changes.compose(tr.changes);
let changedRanges = [];
this.changes.iterChangedRanges((fromA, toA, fromB, toB) => changedRanges.push(new ChangedRange(fromA, toA, fromB, toB)));
this.changedRanges = changedRanges;
}
/**
@internal
*/
static create(view, state, transactions) {
return new ViewUpdate(view, state, transactions);
}
/**
Tells you whether the [viewport](https://codemirror.net/6/docs/ref/#view.EditorView.viewport) or
[visible ranges](https://codemirror.net/6/docs/ref/#view.EditorView.visibleRanges) changed in this
update.
*/
get viewportChanged() {
return (this.flags & 4) > 0;
}
/**
Indicates whether the height of a block element in the editor
changed in this update.
*/
get heightChanged() {
return (this.flags & 2) > 0;
}
/**
Returns true when the document was modified or the size of the
editor, or elements within the editor, changed.
*/
get geometryChanged() {
return this.docChanged || (this.flags & (8 | 2)) > 0;
}
/**
True when this update indicates a focus change.
*/
get focusChanged() {
return (this.flags & 1) > 0;
}
/**
Whether the document changed in this update.
*/
get docChanged() {
return !this.changes.empty;
}
/**
Whether the selection was explicitly set in this update.
*/
get selectionSet() {
return this.transactions.some((tr) => tr.selection);
}
/**
@internal
*/
get empty() {
return this.flags == 0 && this.transactions.length == 0;
}
}
class DocView extends ContentView {
get length() {
return this.view.state.doc.length;
}
constructor(view) {
super();
this.view = view;
this.decorations = [];
this.dynamicDecorationMap = [];
this.domChanged = null;
this.hasComposition = null;
this.markedForComposition = /* @__PURE__ */ new Set();
this.minWidth = 0;
this.minWidthFrom = 0;
this.minWidthTo = 0;
this.impreciseAnchor = null;
this.impreciseHead = null;
this.forceSelection = false;
this.lastUpdate = Date.now();
this.setDOM(view.contentDOM);
this.children = [new LineView()];
this.children[0].setParent(this);
this.updateDeco();
this.updateInner([new ChangedRange(0, 0, 0, view.state.doc.length)], 0, null);
}
// Update the document view to a given state.
update(update) {
var _a2;
let changedRanges = update.changedRanges;
if (this.minWidth > 0 && changedRanges.length) {
if (!changedRanges.every(({ fromA, toA }) => toA < this.minWidthFrom || fromA > this.minWidthTo)) {
this.minWidth = this.minWidthFrom = this.minWidthTo = 0;
} else {
this.minWidthFrom = update.changes.mapPos(this.minWidthFrom, 1);
this.minWidthTo = update.changes.mapPos(this.minWidthTo, 1);
}
}
let readCompositionAt = -1;
if (this.view.inputState.composing >= 0) {
if ((_a2 = this.domChanged) === null || _a2 === void 0 ? void 0 : _a2.newSel)
readCompositionAt = this.domChanged.newSel.head;
else if (!touchesComposition(update.changes, this.hasComposition) && !update.selectionSet)
readCompositionAt = update.state.selection.main.head;
}
let composition = readCompositionAt > -1 ? findCompositionRange(this.view, update.changes, readCompositionAt) : null;
this.domChanged = null;
if (this.hasComposition) {
this.markedForComposition.clear();
let { from, to } = this.hasComposition;
changedRanges = new ChangedRange(from, to, update.changes.mapPos(from, -1), update.changes.mapPos(to, 1)).addToSet(changedRanges.slice());
}
this.hasComposition = composition ? { from: composition.range.fromB, to: composition.range.toB } : null;
if ((browser.ie || browser.chrome) && !composition && update && update.state.doc.lines != update.startState.doc.lines)
this.forceSelection = true;
let prevDeco = this.decorations, deco = this.updateDeco();
let decoDiff = findChangedDeco(prevDeco, deco, update.changes);
changedRanges = ChangedRange.extendWithRanges(changedRanges, decoDiff);
if (!(this.flags & 7) && changedRanges.length == 0) {
return false;
} else {
this.updateInner(changedRanges, update.startState.doc.length, composition);
if (update.transactions.length)
this.lastUpdate = Date.now();
return true;
}
}
// Used by update and the constructor do perform the actual DOM
// update
updateInner(changes, oldLength, composition) {
this.view.viewState.mustMeasureContent = true;
this.updateChildren(changes, oldLength, composition);
let { observer } = this.view;
observer.ignore(() => {
this.dom.style.height = this.view.viewState.contentHeight / this.view.scaleY + "px";
this.dom.style.flexBasis = this.minWidth ? this.minWidth + "px" : "";
let track = browser.chrome || browser.ios ? { node: observer.selectionRange.focusNode, written: false } : void 0;
this.sync(this.view, track);
this.flags &= ~7;
if (track && (track.written || observer.selectionRange.focusNode != track.node))
this.forceSelection = true;
this.dom.style.height = "";
});
this.markedForComposition.forEach(
(cView) => cView.flags &= ~8
/* ViewFlag.Composition */
);
let gaps = [];
if (this.view.viewport.from || this.view.viewport.to < this.view.state.doc.length) {
for (let child of this.children)
if (child instanceof BlockWidgetView && child.widget instanceof BlockGapWidget)
gaps.push(child.dom);
}
observer.updateGaps(gaps);
}
updateChildren(changes, oldLength, composition) {
let ranges = composition ? composition.range.addToSet(changes.slice()) : changes;
let cursor = this.childCursor(oldLength);
for (let i2 = ranges.length - 1; ; i2--) {
let next = i2 >= 0 ? ranges[i2] : null;
if (!next)
break;
let { fromA, toA, fromB, toB } = next, content2, breakAtStart, openStart, openEnd;
if (composition && composition.range.fromB < toB && composition.range.toB > fromB) {
let before = ContentBuilder.build(this.view.state.doc, fromB, composition.range.fromB, this.decorations, this.dynamicDecorationMap);
let after = ContentBuilder.build(this.view.state.doc, composition.range.toB, toB, this.decorations, this.dynamicDecorationMap);
breakAtStart = before.breakAtStart;
openStart = before.openStart;
openEnd = after.openEnd;
let compLine = this.compositionView(composition);
if (after.breakAtStart) {
compLine.breakAfter = 1;
} else if (after.content.length && compLine.merge(compLine.length, compLine.length, after.content[0], false, after.openStart, 0)) {
compLine.breakAfter = after.content[0].breakAfter;
after.content.shift();
}
if (before.content.length && compLine.merge(0, 0, before.content[before.content.length - 1], true, 0, before.openEnd)) {
before.content.pop();
}
content2 = before.content.concat(compLine).concat(after.content);
} else {
({ content: content2, breakAtStart, openStart, openEnd } = ContentBuilder.build(this.view.state.doc, fromB, toB, this.decorations, this.dynamicDecorationMap));
}
let { i: toI, off: toOff } = cursor.findPos(toA, 1);
let { i: fromI, off: fromOff } = cursor.findPos(fromA, -1);
replaceRange(this, fromI, fromOff, toI, toOff, content2, breakAtStart, openStart, openEnd);
}
if (composition)
this.fixCompositionDOM(composition);
}
compositionView(composition) {
let cur2 = new TextView(composition.text.nodeValue);
cur2.flags |= 8;
for (let { deco } of composition.marks)
cur2 = new MarkView(deco, [cur2], cur2.length);
let line = new LineView();
line.append(cur2, 0);
return line;
}
fixCompositionDOM(composition) {
let fix = (dom, cView2) => {
cView2.flags |= 8 | (cView2.children.some(
(c) => c.flags & 7
/* ViewFlag.Dirty */
) ? 1 : 0);
this.markedForComposition.add(cView2);
let prev = ContentView.get(dom);
if (prev && prev != cView2)
prev.dom = null;
cView2.setDOM(dom);
};
let pos = this.childPos(composition.range.fromB, 1);
let cView = this.children[pos.i];
fix(composition.line, cView);
for (let i2 = composition.marks.length - 1; i2 >= -1; i2--) {
pos = cView.childPos(pos.off, 1);
cView = cView.children[pos.i];
fix(i2 >= 0 ? composition.marks[i2].node : composition.text, cView);
}
}
// Sync the DOM selection to this.state.selection
updateSelection(mustRead = false, fromPointer = false) {
if (mustRead || !this.view.observer.selectionRange.focusNode)
this.view.observer.readSelectionRange();
let activeElt = this.view.root.activeElement, focused = activeElt == this.dom;
let selectionNotFocus = !focused && hasSelection(this.dom, this.view.observer.selectionRange) && !(activeElt && this.dom.contains(activeElt));
if (!(focused || fromPointer || selectionNotFocus))
return;
let force = this.forceSelection;
this.forceSelection = false;
let main = this.view.state.selection.main;
let anchor = this.moveToLine(this.domAtPos(main.anchor));
let head = main.empty ? anchor : this.moveToLine(this.domAtPos(main.head));
if (browser.gecko && main.empty && !this.hasComposition && betweenUneditable(anchor)) {
let dummy = document.createTextNode("");
this.view.observer.ignore(() => anchor.node.insertBefore(dummy, anchor.node.childNodes[anchor.offset] || null));
anchor = head = new DOMPos(dummy, 0);
force = true;
}
let domSel = this.view.observer.selectionRange;
if (force || !domSel.focusNode || (!isEquivalentPosition(anchor.node, anchor.offset, domSel.anchorNode, domSel.anchorOffset) || !isEquivalentPosition(head.node, head.offset, domSel.focusNode, domSel.focusOffset)) && !this.suppressWidgetCursorChange(domSel, main)) {
this.view.observer.ignore(() => {
if (browser.android && browser.chrome && this.dom.contains(domSel.focusNode) && inUneditable(domSel.focusNode, this.dom)) {
this.dom.blur();
this.dom.focus({ preventScroll: true });
}
let rawSel = getSelection(this.view.root);
if (!rawSel)
;
else if (main.empty) {
if (browser.gecko) {
let nextTo = nextToUneditable(anchor.node, anchor.offset);
if (nextTo && nextTo != (1 | 2)) {
let text = nearbyTextNode(anchor.node, anchor.offset, nextTo == 1 ? 1 : -1);
if (text)
anchor = new DOMPos(text.node, text.offset);
}
}
rawSel.collapse(anchor.node, anchor.offset);
if (main.bidiLevel != null && rawSel.caretBidiLevel !== void 0)
rawSel.caretBidiLevel = main.bidiLevel;
} else if (rawSel.extend) {
rawSel.collapse(anchor.node, anchor.offset);
try {
rawSel.extend(head.node, head.offset);
} catch (_) {
}
} else {
let range = document.createRange();
if (main.anchor > main.head)
[anchor, head] = [head, anchor];
range.setEnd(head.node, head.offset);
range.setStart(anchor.node, anchor.offset);
rawSel.removeAllRanges();
rawSel.addRange(range);
}
if (selectionNotFocus && this.view.root.activeElement == this.dom) {
this.dom.blur();
if (activeElt)
activeElt.focus();
}
});
this.view.observer.setSelectionRange(anchor, head);
}
this.impreciseAnchor = anchor.precise ? null : new DOMPos(domSel.anchorNode, domSel.anchorOffset);
this.impreciseHead = head.precise ? null : new DOMPos(domSel.focusNode, domSel.focusOffset);
}
// If a zero-length widget is inserted next to the cursor during
// composition, avoid moving it across it and disrupting the
// composition.
suppressWidgetCursorChange(sel, cursor) {
return this.hasComposition && cursor.empty && isEquivalentPosition(sel.focusNode, sel.focusOffset, sel.anchorNode, sel.anchorOffset) && this.posFromDOM(sel.focusNode, sel.focusOffset) == cursor.head;
}
enforceCursorAssoc() {
if (this.hasComposition)
return;
let { view } = this, cursor = view.state.selection.main;
let sel = getSelection(view.root);
let { anchorNode, anchorOffset } = view.observer.selectionRange;
if (!sel || !cursor.empty || !cursor.assoc || !sel.modify)
return;
let line = LineView.find(this, cursor.head);
if (!line)
return;
let lineStart = line.posAtStart;
if (cursor.head == lineStart || cursor.head == lineStart + line.length)
return;
let before = this.coordsAt(cursor.head, -1), after = this.coordsAt(cursor.head, 1);
if (!before || !after || before.bottom > after.top)
return;
let dom = this.domAtPos(cursor.head + cursor.assoc);
sel.collapse(dom.node, dom.offset);
sel.modify("move", cursor.assoc < 0 ? "forward" : "backward", "lineboundary");
view.observer.readSelectionRange();
let newRange = view.observer.selectionRange;
if (view.docView.posFromDOM(newRange.anchorNode, newRange.anchorOffset) != cursor.from)
sel.collapse(anchorNode, anchorOffset);
}
// If a position is in/near a block widget, move it to a nearby text
// line, since we don't want the cursor inside a block widget.
moveToLine(pos) {
let dom = this.dom, newPos;
if (pos.node != dom)
return pos;
for (let i2 = pos.offset; !newPos && i2 < dom.childNodes.length; i2++) {
let view = ContentView.get(dom.childNodes[i2]);
if (view instanceof LineView)
newPos = view.domAtPos(0);
}
for (let i2 = pos.offset - 1; !newPos && i2 >= 0; i2--) {
let view = ContentView.get(dom.childNodes[i2]);
if (view instanceof LineView)
newPos = view.domAtPos(view.length);
}
return newPos ? new DOMPos(newPos.node, newPos.offset, true) : pos;
}
nearest(dom) {
for (let cur2 = dom; cur2; ) {
let domView = ContentView.get(cur2);
if (domView && domView.rootView == this)
return domView;
cur2 = cur2.parentNode;
}
return null;
}
posFromDOM(node, offset) {
let view = this.nearest(node);
if (!view)
throw new RangeError("Trying to find position for a DOM position outside of the document");
return view.localPosFromDOM(node, offset) + view.posAtStart;
}
domAtPos(pos) {
let { i: i2, off } = this.childCursor().findPos(pos, -1);
for (; i2 < this.children.length - 1; ) {
let child = this.children[i2];
if (off < child.length || child instanceof LineView)
break;
i2++;
off = 0;
}
return this.children[i2].domAtPos(off);
}
coordsAt(pos, side) {
let best = null, bestPos = 0;
for (let off = this.length, i2 = this.children.length - 1; i2 >= 0; i2--) {
let child = this.children[i2], end = off - child.breakAfter, start = end - child.length;
if (end < pos)
break;
if (start <= pos && (start < pos || child.covers(-1)) && (end > pos || child.covers(1)) && (!best || child instanceof LineView && !(best instanceof LineView && side >= 0))) {
best = child;
bestPos = start;
}
off = start;
}
return best ? best.coordsAt(pos - bestPos, side) : null;
}
coordsForChar(pos) {
let { i: i2, off } = this.childPos(pos, 1), child = this.children[i2];
if (!(child instanceof LineView))
return null;
while (child.children.length) {
let { i: i3, off: childOff } = child.childPos(off, 1);
for (; ; i3++) {
if (i3 == child.children.length)
return null;
if ((child = child.children[i3]).length)
break;
}
off = childOff;
}
if (!(child instanceof TextView))
return null;
let end = findClusterBreak(child.text, off);
if (end == off)
return null;
let rects = textRange(child.dom, off, end).getClientRects();
for (let i3 = 0; i3 < rects.length; i3++) {
let rect = rects[i3];
if (i3 == rects.length - 1 || rect.top < rect.bottom && rect.left < rect.right)
return rect;
}
return null;
}
measureVisibleLineHeights(viewport) {
let result2 = [], { from, to } = viewport;
let contentWidth = this.view.contentDOM.clientWidth;
let isWider = contentWidth > Math.max(this.view.scrollDOM.clientWidth, this.minWidth) + 1;
let widest = -1, ltr = this.view.textDirection == Direction.LTR;
for (let pos = 0, i2 = 0; i2 < this.children.length; i2++) {
let child = this.children[i2], end = pos + child.length;
if (end > to)
break;
if (pos >= from) {
let childRect = child.dom.getBoundingClientRect();
result2.push(childRect.height);
if (isWider) {
let last = child.dom.lastChild;
let rects = last ? clientRectsFor(last) : [];
if (rects.length) {
let rect = rects[rects.length - 1];
let width = ltr ? rect.right - childRect.left : childRect.right - rect.left;
if (width > widest) {
widest = width;
this.minWidth = contentWidth;
this.minWidthFrom = pos;
this.minWidthTo = end;
}
}
}
}
pos = end + child.breakAfter;
}
return result2;
}
textDirectionAt(pos) {
let { i: i2 } = this.childPos(pos, 1);
return getComputedStyle(this.children[i2].dom).direction == "rtl" ? Direction.RTL : Direction.LTR;
}
measureTextSize() {
for (let child of this.children) {
if (child instanceof LineView) {
let measure = child.measureTextSize();
if (measure)
return measure;
}
}
let dummy = document.createElement("div"), lineHeight, charWidth, textHeight;
dummy.className = "cm-line";
dummy.style.width = "99999px";
dummy.style.position = "absolute";
dummy.textContent = "abc def ghi jkl mno pqr stu";
this.view.observer.ignore(() => {
this.dom.appendChild(dummy);
let rect = clientRectsFor(dummy.firstChild)[0];
lineHeight = dummy.getBoundingClientRect().height;
charWidth = rect ? rect.width / 27 : 7;
textHeight = rect ? rect.height : lineHeight;
dummy.remove();
});
return { lineHeight, charWidth, textHeight };
}
childCursor(pos = this.length) {
let i2 = this.children.length;
if (i2)
pos -= this.children[--i2].length;
return new ChildCursor(this.children, pos, i2);
}
computeBlockGapDeco() {
let deco = [], vs = this.view.viewState;
for (let pos = 0, i2 = 0; ; i2++) {
let next = i2 == vs.viewports.length ? null : vs.viewports[i2];
let end = next ? next.from - 1 : this.length;
if (end > pos) {
let height = (vs.lineBlockAt(end).bottom - vs.lineBlockAt(pos).top) / this.view.scaleY;
deco.push(Decoration.replace({
widget: new BlockGapWidget(height),
block: true,
inclusive: true,
isBlockGap: true
}).range(pos, end));
}
if (!next)
break;
pos = next.to + 1;
}
return Decoration.set(deco);
}
updateDeco() {
let allDeco = this.view.state.facet(decorations).map((d, i2) => {
let dynamic = this.dynamicDecorationMap[i2] = typeof d == "function";
return dynamic ? d(this.view) : d;
});
let dynamicOuter = false, outerDeco = this.view.state.facet(outerDecorations).map((d, i2) => {
let dynamic = typeof d == "function";
if (dynamic)
dynamicOuter = true;
return dynamic ? d(this.view) : d;
});
if (outerDeco.length) {
this.dynamicDecorationMap[allDeco.length] = dynamicOuter;
allDeco.push(RangeSet.join(outerDeco));
}
for (let i2 = allDeco.length; i2 < allDeco.length + 3; i2++)
this.dynamicDecorationMap[i2] = false;
return this.decorations = [
...allDeco,
this.computeBlockGapDeco(),
this.view.viewState.lineGapDeco
];
}
scrollIntoView(target) {
if (target.isSnapshot) {
let ref2 = this.view.viewState.lineBlockAt(target.range.head);
this.view.scrollDOM.scrollTop = ref2.top - target.yMargin;
this.view.scrollDOM.scrollLeft = target.xMargin;
return;
}
let { range } = target;
let rect = this.coordsAt(range.head, range.empty ? range.assoc : range.head > range.anchor ? -1 : 1), other;
if (!rect)
return;
if (!range.empty && (other = this.coordsAt(range.anchor, range.anchor > range.head ? -1 : 1)))
rect = {
left: Math.min(rect.left, other.left),
top: Math.min(rect.top, other.top),
right: Math.max(rect.right, other.right),
bottom: Math.max(rect.bottom, other.bottom)
};
let margins = getScrollMargins(this.view);
let targetRect = {
left: rect.left - margins.left,
top: rect.top - margins.top,
right: rect.right + margins.right,
bottom: rect.bottom + margins.bottom
};
let { offsetWidth, offsetHeight } = this.view.scrollDOM;
scrollRectIntoView(this.view.scrollDOM, targetRect, range.head < range.anchor ? -1 : 1, target.x, target.y, Math.max(Math.min(target.xMargin, offsetWidth), -offsetWidth), Math.max(Math.min(target.yMargin, offsetHeight), -offsetHeight), this.view.textDirection == Direction.LTR);
}
}
function betweenUneditable(pos) {
return pos.node.nodeType == 1 && pos.node.firstChild && (pos.offset == 0 || pos.node.childNodes[pos.offset - 1].contentEditable == "false") && (pos.offset == pos.node.childNodes.length || pos.node.childNodes[pos.offset].contentEditable == "false");
}
class BlockGapWidget extends WidgetType {
constructor(height) {
super();
this.height = height;
}
toDOM() {
let elt = document.createElement("div");
elt.className = "cm-gap";
this.updateDOM(elt);
return elt;
}
eq(other) {
return other.height == this.height;
}
updateDOM(elt) {
elt.style.height = this.height + "px";
return true;
}
get editable() {
return true;
}
get estimatedHeight() {
return this.height;
}
ignoreEvent() {
return false;
}
}
function findCompositionNode(view, headPos) {
let sel = view.observer.selectionRange;
let textNode = sel.focusNode && nearbyTextNode(sel.focusNode, sel.focusOffset, 0);
if (!textNode)
return null;
let from = headPos - textNode.offset;
return { from, to: from + textNode.node.nodeValue.length, node: textNode.node };
}
function findCompositionRange(view, changes, headPos) {
let found = findCompositionNode(view, headPos);
if (!found)
return null;
let { node: textNode, from, to } = found, text = textNode.nodeValue;
if (/[\n\r]/.test(text))
return null;
if (view.state.doc.sliceString(found.from, found.to) != text)
return null;
let inv = changes.invertedDesc;
let range = new ChangedRange(inv.mapPos(from), inv.mapPos(to), from, to);
let marks = [];
for (let parent = textNode.parentNode; ; parent = parent.parentNode) {
let parentView = ContentView.get(parent);
if (parentView instanceof MarkView)
marks.push({ node: parent, deco: parentView.mark });
else if (parentView instanceof LineView || parent.nodeName == "DIV" && parent.parentNode == view.contentDOM)
return { range, text: textNode, marks, line: parent };
else if (parent != view.contentDOM)
marks.push({ node: parent, deco: new MarkDecoration({
inclusive: true,
attributes: getAttrs(parent),
tagName: parent.tagName.toLowerCase()
}) });
else
return null;
}
}
function nearbyTextNode(startNode, startOffset, side) {
if (side <= 0)
for (let node = startNode, offset = startOffset; ; ) {
if (node.nodeType == 3)
return { node, offset };
if (node.nodeType == 1 && offset > 0) {
node = node.childNodes[offset - 1];
offset = maxOffset(node);
} else {
break;
}
}
if (side >= 0)
for (let node = startNode, offset = startOffset; ; ) {
if (node.nodeType == 3)
return { node, offset };
if (node.nodeType == 1 && offset < node.childNodes.length && side >= 0) {
node = node.childNodes[offset];
offset = 0;
} else {
break;
}
}
return null;
}
function nextToUneditable(node, offset) {
if (node.nodeType != 1)
return 0;
return (offset && node.childNodes[offset - 1].contentEditable == "false" ? 1 : 0) | (offset < node.childNodes.length && node.childNodes[offset].contentEditable == "false" ? 2 : 0);
}
let DecorationComparator$1 = class DecorationComparator2 {
constructor() {
this.changes = [];
}
compareRange(from, to) {
addRange(from, to, this.changes);
}
comparePoint(from, to) {
addRange(from, to, this.changes);
}
};
function findChangedDeco(a, b, diff) {
let comp = new DecorationComparator$1();
RangeSet.compare(a, b, diff, comp);
return comp.changes;
}
function inUneditable(node, inside2) {
for (let cur2 = node; cur2 && cur2 != inside2; cur2 = cur2.assignedSlot || cur2.parentNode) {
if (cur2.nodeType == 1 && cur2.contentEditable == "false") {
return true;
}
}
return false;
}
function touchesComposition(changes, composition) {
let touched = false;
if (composition)
changes.iterChangedRanges((from, to) => {
if (from < composition.to && to > composition.from)
touched = true;
});
return touched;
}
function groupAt(state, pos, bias = 1) {
let categorize = state.charCategorizer(pos);
let line = state.doc.lineAt(pos), linePos = pos - line.from;
if (line.length == 0)
return EditorSelection.cursor(pos);
if (linePos == 0)
bias = 1;
else if (linePos == line.length)
bias = -1;
let from = linePos, to = linePos;
if (bias < 0)
from = findClusterBreak(line.text, linePos, false);
else
to = findClusterBreak(line.text, linePos);
let cat = categorize(line.text.slice(from, to));
while (from > 0) {
let prev = findClusterBreak(line.text, from, false);
if (categorize(line.text.slice(prev, from)) != cat)
break;
from = prev;
}
while (to < line.length) {
let next = findClusterBreak(line.text, to);
if (categorize(line.text.slice(to, next)) != cat)
break;
to = next;
}
return EditorSelection.range(from + line.from, to + line.from);
}
function getdx(x2, rect) {
return rect.left > x2 ? rect.left - x2 : Math.max(0, x2 - rect.right);
}
function getdy(y2, rect) {
return rect.top > y2 ? rect.top - y2 : Math.max(0, y2 - rect.bottom);
}
function yOverlap(a, b) {
return a.top < b.bottom - 1 && a.bottom > b.top + 1;
}
function upTop(rect, top2) {
return top2 < rect.top ? { top: top2, left: rect.left, right: rect.right, bottom: rect.bottom } : rect;
}
function upBot(rect, bottom) {
return bottom > rect.bottom ? { top: rect.top, left: rect.left, right: rect.right, bottom } : rect;
}
function domPosAtCoords(parent, x2, y2) {
let closest, closestRect, closestX, closestY, closestOverlap = false;
let above, below, aboveRect, belowRect;
for (let child = parent.firstChild; child; child = child.nextSibling) {
let rects = clientRectsFor(child);
for (let i2 = 0; i2 < rects.length; i2++) {
let rect = rects[i2];
if (closestRect && yOverlap(closestRect, rect))
rect = upTop(upBot(rect, closestRect.bottom), closestRect.top);
let dx = getdx(x2, rect), dy = getdy(y2, rect);
if (dx == 0 && dy == 0)
return child.nodeType == 3 ? domPosInText(child, x2, y2) : domPosAtCoords(child, x2, y2);
if (!closest || closestY > dy || closestY == dy && closestX > dx) {
closest = child;
closestRect = rect;
closestX = dx;
closestY = dy;
let side = dy ? y2 < rect.top ? -1 : 1 : dx ? x2 < rect.left ? -1 : 1 : 0;
closestOverlap = !side || (side > 0 ? i2 < rects.length - 1 : i2 > 0);
}
if (dx == 0) {
if (y2 > rect.bottom && (!aboveRect || aboveRect.bottom < rect.bottom)) {
above = child;
aboveRect = rect;
} else if (y2 < rect.top && (!belowRect || belowRect.top > rect.top)) {
below = child;
belowRect = rect;
}
} else if (aboveRect && yOverlap(aboveRect, rect)) {
aboveRect = upBot(aboveRect, rect.bottom);
} else if (belowRect && yOverlap(belowRect, rect)) {
belowRect = upTop(belowRect, rect.top);
}
}
}
if (aboveRect && aboveRect.bottom >= y2) {
closest = above;
closestRect = aboveRect;
} else if (belowRect && belowRect.top <= y2) {
closest = below;
closestRect = belowRect;
}
if (!closest)
return { node: parent, offset: 0 };
let clipX = Math.max(closestRect.left, Math.min(closestRect.right, x2));
if (closest.nodeType == 3)
return domPosInText(closest, clipX, y2);
if (closestOverlap && closest.contentEditable != "false")
return domPosAtCoords(closest, clipX, y2);
let offset = Array.prototype.indexOf.call(parent.childNodes, closest) + (x2 >= (closestRect.left + closestRect.right) / 2 ? 1 : 0);
return { node: parent, offset };
}
function domPosInText(node, x2, y2) {
let len = node.nodeValue.length;
let closestOffset = -1, closestDY = 1e9, generalSide = 0;
for (let i2 = 0; i2 < len; i2++) {
let rects = textRange(node, i2, i2 + 1).getClientRects();
for (let j2 = 0; j2 < rects.length; j2++) {
let rect = rects[j2];
if (rect.top == rect.bottom)
continue;
if (!generalSide)
generalSide = x2 - rect.left;
let dy = (rect.top > y2 ? rect.top - y2 : y2 - rect.bottom) - 1;
if (rect.left - 1 <= x2 && rect.right + 1 >= x2 && dy < closestDY) {
let right = x2 >= (rect.left + rect.right) / 2, after = right;
if (browser.chrome || browser.gecko) {
let rectBefore = textRange(node, i2).getBoundingClientRect();
if (rectBefore.left == rect.right)
after = !right;
}
if (dy <= 0)
return { node, offset: i2 + (after ? 1 : 0) };
closestOffset = i2 + (after ? 1 : 0);
closestDY = dy;
}
}
}
return { node, offset: closestOffset > -1 ? closestOffset : generalSide > 0 ? node.nodeValue.length : 0 };
}
function posAtCoords(view, coords, precise, bias = -1) {
var _a2, _b;
let content2 = view.contentDOM.getBoundingClientRect(), docTop = content2.top + view.viewState.paddingTop;
let block, { docHeight } = view.viewState;
let { x: x2, y: y2 } = coords, yOffset = y2 - docTop;
if (yOffset < 0)
return 0;
if (yOffset > docHeight)
return view.state.doc.length;
for (let halfLine = view.viewState.heightOracle.textHeight / 2, bounced = false; ; ) {
block = view.elementAtHeight(yOffset);
if (block.type == BlockType.Text)
break;
for (; ; ) {
yOffset = bias > 0 ? block.bottom + halfLine : block.top - halfLine;
if (yOffset >= 0 && yOffset <= docHeight)
break;
if (bounced)
return precise ? null : 0;
bounced = true;
bias = -bias;
}
}
y2 = docTop + yOffset;
let lineStart = block.from;
if (lineStart < view.viewport.from)
return view.viewport.from == 0 ? 0 : precise ? null : posAtCoordsImprecise(view, content2, block, x2, y2);
if (lineStart > view.viewport.to)
return view.viewport.to == view.state.doc.length ? view.state.doc.length : precise ? null : posAtCoordsImprecise(view, content2, block, x2, y2);
let doc2 = view.dom.ownerDocument;
let root = view.root.elementFromPoint ? view.root : doc2;
let element = root.elementFromPoint(x2, y2);
if (element && !view.contentDOM.contains(element))
element = null;
if (!element) {
x2 = Math.max(content2.left + 1, Math.min(content2.right - 1, x2));
element = root.elementFromPoint(x2, y2);
if (element && !view.contentDOM.contains(element))
element = null;
}
let node, offset = -1;
if (element && ((_a2 = view.docView.nearest(element)) === null || _a2 === void 0 ? void 0 : _a2.isEditable) != false) {
if (doc2.caretPositionFromPoint) {
let pos = doc2.caretPositionFromPoint(x2, y2);
if (pos)
({ offsetNode: node, offset } = pos);
} else if (doc2.caretRangeFromPoint) {
let range = doc2.caretRangeFromPoint(x2, y2);
if (range) {
({ startContainer: node, startOffset: offset } = range);
if (!view.contentDOM.contains(node) || browser.safari && isSuspiciousSafariCaretResult(node, offset, x2) || browser.chrome && isSuspiciousChromeCaretResult(node, offset, x2))
node = void 0;
}
}
}
if (!node || !view.docView.dom.contains(node)) {
let line = LineView.find(view.docView, lineStart);
if (!line)
return yOffset > block.top + block.height / 2 ? block.to : block.from;
({ node, offset } = domPosAtCoords(line.dom, x2, y2));
}
let nearest = view.docView.nearest(node);
if (!nearest)
return null;
if (nearest.isWidget && ((_b = nearest.dom) === null || _b === void 0 ? void 0 : _b.nodeType) == 1) {
let rect = nearest.dom.getBoundingClientRect();
return coords.y < rect.top || coords.y <= rect.bottom && coords.x <= (rect.left + rect.right) / 2 ? nearest.posAtStart : nearest.posAtEnd;
} else {
return nearest.localPosFromDOM(node, offset) + nearest.posAtStart;
}
}
function posAtCoordsImprecise(view, contentRect, block, x2, y2) {
let into = Math.round((x2 - contentRect.left) * view.defaultCharacterWidth);
if (view.lineWrapping && block.height > view.defaultLineHeight * 1.5) {
let textHeight = view.viewState.heightOracle.textHeight;
let line = Math.floor((y2 - block.top - (view.defaultLineHeight - textHeight) * 0.5) / textHeight);
into += line * view.viewState.heightOracle.lineLength;
}
let content2 = view.state.sliceDoc(block.from, block.to);
return block.from + findColumn(content2, into, view.state.tabSize);
}
function isSuspiciousSafariCaretResult(node, offset, x2) {
let len;
if (node.nodeType != 3 || offset != (len = node.nodeValue.length))
return false;
for (let next = node.nextSibling; next; next = next.nextSibling)
if (next.nodeType != 1 || next.nodeName != "BR")
return false;
return textRange(node, len - 1, len).getBoundingClientRect().left > x2;
}
function isSuspiciousChromeCaretResult(node, offset, x2) {
if (offset != 0)
return false;
for (let cur2 = node; ; ) {
let parent = cur2.parentNode;
if (!parent || parent.nodeType != 1 || parent.firstChild != cur2)
return false;
if (parent.classList.contains("cm-line"))
break;
cur2 = parent;
}
let rect = node.nodeType == 1 ? node.getBoundingClientRect() : textRange(node, 0, Math.max(node.nodeValue.length, 1)).getBoundingClientRect();
return x2 - rect.left > 5;
}
function blockAt(view, pos) {
let line = view.lineBlockAt(pos);
if (Array.isArray(line.type))
for (let l of line.type) {
if (l.to > pos || l.to == pos && (l.to == line.to || l.type == BlockType.Text))
return l;
}
return line;
}
function moveToLineBoundary(view, start, forward, includeWrap) {
let line = blockAt(view, start.head);
let coords = !includeWrap || line.type != BlockType.Text || !(view.lineWrapping || line.widgetLineBreaks) ? null : view.coordsAtPos(start.assoc < 0 && start.head > line.from ? start.head - 1 : start.head);
if (coords) {
let editorRect = view.dom.getBoundingClientRect();
let direction = view.textDirectionAt(line.from);
let pos = view.posAtCoords({
x: forward == (direction == Direction.LTR) ? editorRect.right - 1 : editorRect.left + 1,
y: (coords.top + coords.bottom) / 2
});
if (pos != null)
return EditorSelection.cursor(pos, forward ? -1 : 1);
}
return EditorSelection.cursor(forward ? line.to : line.from, forward ? -1 : 1);
}
function moveByChar(view, start, forward, by) {
let line = view.state.doc.lineAt(start.head), spans = view.bidiSpans(line);
let direction = view.textDirectionAt(line.from);
for (let cur2 = start, check = null; ; ) {
let next = moveVisually(line, spans, direction, cur2, forward), char = movedOver;
if (!next) {
if (line.number == (forward ? view.state.doc.lines : 1))
return cur2;
char = "\n";
line = view.state.doc.line(line.number + (forward ? 1 : -1));
spans = view.bidiSpans(line);
next = view.visualLineSide(line, !forward);
}
if (!check) {
if (!by)
return next;
check = by(char);
} else if (!check(char)) {
return cur2;
}
cur2 = next;
}
}
function byGroup(view, pos, start) {
let categorize = view.state.charCategorizer(pos);
let cat = categorize(start);
return (next) => {
let nextCat = categorize(next);
if (cat == CharCategory.Space)
cat = nextCat;
return cat == nextCat;
};
}
function moveVertically(view, start, forward, distance) {
let startPos = start.head, dir = forward ? 1 : -1;
if (startPos == (forward ? view.state.doc.length : 0))
return EditorSelection.cursor(startPos, start.assoc);
let goal = start.goalColumn, startY;
let rect = view.contentDOM.getBoundingClientRect();
let startCoords = view.coordsAtPos(startPos, start.assoc || -1), docTop = view.documentTop;
if (startCoords) {
if (goal == null)
goal = startCoords.left - rect.left;
startY = dir < 0 ? startCoords.top : startCoords.bottom;
} else {
let line = view.viewState.lineBlockAt(startPos);
if (goal == null)
goal = Math.min(rect.right - rect.left, view.defaultCharacterWidth * (startPos - line.from));
startY = (dir < 0 ? line.top : line.bottom) + docTop;
}
let resolvedGoal = rect.left + goal;
let dist2 = distance !== null && distance !== void 0 ? distance : view.viewState.heightOracle.textHeight >> 1;
for (let extra = 0; ; extra += 10) {
let curY = startY + (dist2 + extra) * dir;
let pos = posAtCoords(view, { x: resolvedGoal, y: curY }, false, dir);
if (curY < rect.top || curY > rect.bottom || (dir < 0 ? pos < startPos : pos > startPos)) {
let charRect = view.docView.coordsForChar(pos);
let assoc = !charRect || curY < charRect.top ? -1 : 1;
return EditorSelection.cursor(pos, assoc, void 0, goal);
}
}
}
function skipAtomicRanges(atoms, pos, bias) {
for (; ; ) {
let moved = 0;
for (let set of atoms) {
set.between(pos - 1, pos + 1, (from, to, value) => {
if (pos > from && pos < to) {
let side = moved || bias || (pos - from < to - pos ? -1 : 1);
pos = side < 0 ? from : to;
moved = side;
}
});
}
if (!moved)
return pos;
}
}
function skipAtoms(view, oldPos, pos) {
let newPos = skipAtomicRanges(view.state.facet(atomicRanges).map((f) => f(view)), pos.from, oldPos.head > pos.from ? -1 : 1);
return newPos == pos.from ? pos : EditorSelection.cursor(newPos, newPos < pos.from ? 1 : -1);
}
class InputState {
setSelectionOrigin(origin) {
this.lastSelectionOrigin = origin;
this.lastSelectionTime = Date.now();
}
constructor(view) {
this.view = view;
this.lastKeyCode = 0;
this.lastKeyTime = 0;
this.lastTouchTime = 0;
this.lastFocusTime = 0;
this.lastScrollTop = 0;
this.lastScrollLeft = 0;
this.pendingIOSKey = void 0;
this.lastSelectionOrigin = null;
this.lastSelectionTime = 0;
this.lastEscPress = 0;
this.lastContextMenu = 0;
this.scrollHandlers = [];
this.handlers = /* @__PURE__ */ Object.create(null);
this.composing = -1;
this.compositionFirstChange = null;
this.compositionEndedAt = 0;
this.compositionPendingKey = false;
this.compositionPendingChange = false;
this.mouseSelection = null;
this.draggedContent = null;
this.handleEvent = this.handleEvent.bind(this);
this.notifiedFocused = view.hasFocus;
if (browser.safari)
view.contentDOM.addEventListener("input", () => null);
if (browser.gecko)
firefoxCopyCutHack(view.contentDOM.ownerDocument);
}
handleEvent(event) {
if (!eventBelongsToEditor(this.view, event) || this.ignoreDuringComposition(event))
return;
if (event.type == "keydown" && this.keydown(event))
return;
this.runHandlers(event.type, event);
}
runHandlers(type, event) {
let handlers2 = this.handlers[type];
if (handlers2) {
for (let observer of handlers2.observers)
observer(this.view, event);
for (let handler of handlers2.handlers) {
if (event.defaultPrevented)
break;
if (handler(this.view, event)) {
event.preventDefault();
break;
}
}
}
}
ensureHandlers(plugins) {
let handlers2 = computeHandlers(plugins), prev = this.handlers, dom = this.view.contentDOM;
for (let type in handlers2)
if (type != "scroll") {
let passive = !handlers2[type].handlers.length;
let exists = prev[type];
if (exists && passive != !exists.handlers.length) {
dom.removeEventListener(type, this.handleEvent);
exists = null;
}
if (!exists)
dom.addEventListener(type, this.handleEvent, { passive });
}
for (let type in prev)
if (type != "scroll" && !handlers2[type])
dom.removeEventListener(type, this.handleEvent);
this.handlers = handlers2;
}
keydown(event) {
this.lastKeyCode = event.keyCode;
this.lastKeyTime = Date.now();
if (event.keyCode == 9 && Date.now() < this.lastEscPress + 2e3)
return true;
if (event.keyCode != 27 && modifierCodes.indexOf(event.keyCode) < 0)
this.view.inputState.lastEscPress = 0;
if (browser.android && browser.chrome && !event.synthetic && (event.keyCode == 13 || event.keyCode == 8)) {
this.view.observer.delayAndroidKey(event.key, event.keyCode);
return true;
}
let pending;
if (browser.ios && !event.synthetic && !event.altKey && !event.metaKey && ((pending = PendingKeys.find((key) => key.keyCode == event.keyCode)) && !event.ctrlKey || EmacsyPendingKeys.indexOf(event.key) > -1 && event.ctrlKey && !event.shiftKey)) {
this.pendingIOSKey = pending || event;
setTimeout(() => this.flushIOSKey(), 250);
return true;
}
if (event.keyCode != 229)
this.view.observer.forceFlush();
return false;
}
flushIOSKey() {
let key = this.pendingIOSKey;
if (!key)
return false;
this.pendingIOSKey = void 0;
return dispatchKey(this.view.contentDOM, key.key, key.keyCode);
}
ignoreDuringComposition(event) {
if (!/^key/.test(event.type))
return false;
if (this.composing > 0)
return true;
if (browser.safari && !browser.ios && this.compositionPendingKey && Date.now() - this.compositionEndedAt < 100) {
this.compositionPendingKey = false;
return true;
}
return false;
}
startMouseSelection(mouseSelection) {
if (this.mouseSelection)
this.mouseSelection.destroy();
this.mouseSelection = mouseSelection;
}
update(update) {
if (this.mouseSelection)
this.mouseSelection.update(update);
if (this.draggedContent && update.docChanged)
this.draggedContent = this.draggedContent.map(update.changes);
if (update.transactions.length)
this.lastKeyCode = this.lastSelectionTime = 0;
}
destroy() {
if (this.mouseSelection)
this.mouseSelection.destroy();
}
}
function bindHandler(plugin, handler) {
return (view, event) => {
try {
return handler.call(plugin, event, view);
} catch (e) {
logException(view.state, e);
}
};
}
function computeHandlers(plugins) {
let result2 = /* @__PURE__ */ Object.create(null);
function record(type) {
return result2[type] || (result2[type] = { observers: [], handlers: [] });
}
for (let plugin of plugins) {
let spec = plugin.spec;
if (spec && spec.domEventHandlers)
for (let type in spec.domEventHandlers) {
let f = spec.domEventHandlers[type];
if (f)
record(type).handlers.push(bindHandler(plugin.value, f));
}
if (spec && spec.domEventObservers)
for (let type in spec.domEventObservers) {
let f = spec.domEventObservers[type];
if (f)
record(type).observers.push(bindHandler(plugin.value, f));
}
}
for (let type in handlers)
record(type).handlers.push(handlers[type]);
for (let type in observers)
record(type).observers.push(observers[type]);
return result2;
}
const PendingKeys = [
{ key: "Backspace", keyCode: 8, inputType: "deleteContentBackward" },
{ key: "Enter", keyCode: 13, inputType: "insertParagraph" },
{ key: "Enter", keyCode: 13, inputType: "insertLineBreak" },
{ key: "Delete", keyCode: 46, inputType: "deleteContentForward" }
];
const EmacsyPendingKeys = "dthko";
const modifierCodes = [16, 17, 18, 20, 91, 92, 224, 225];
const dragScrollMargin = 6;
function dragScrollSpeed(dist2) {
return Math.max(0, dist2) * 0.7 + 8;
}
function dist(a, b) {
return Math.max(Math.abs(a.clientX - b.clientX), Math.abs(a.clientY - b.clientY));
}
class MouseSelection {
constructor(view, startEvent, style, mustSelect) {
this.view = view;
this.startEvent = startEvent;
this.style = style;
this.mustSelect = mustSelect;
this.scrollSpeed = { x: 0, y: 0 };
this.scrolling = -1;
this.lastEvent = startEvent;
this.scrollParent = scrollableParent(view.contentDOM);
this.atoms = view.state.facet(atomicRanges).map((f) => f(view));
let doc2 = view.contentDOM.ownerDocument;
doc2.addEventListener("mousemove", this.move = this.move.bind(this));
doc2.addEventListener("mouseup", this.up = this.up.bind(this));
this.extend = startEvent.shiftKey;
this.multiple = view.state.facet(EditorState.allowMultipleSelections) && addsSelectionRange(view, startEvent);
this.dragging = isInPrimarySelection(view, startEvent) && getClickType(startEvent) == 1 ? null : false;
}
start(event) {
if (this.dragging === false)
this.select(event);
}
move(event) {
var _a2;
if (event.buttons == 0)
return this.destroy();
if (this.dragging || this.dragging == null && dist(this.startEvent, event) < 10)
return;
this.select(this.lastEvent = event);
let sx = 0, sy = 0;
let rect = ((_a2 = this.scrollParent) === null || _a2 === void 0 ? void 0 : _a2.getBoundingClientRect()) || { left: 0, top: 0, right: this.view.win.innerWidth, bottom: this.view.win.innerHeight };
let margins = getScrollMargins(this.view);
if (event.clientX - margins.left <= rect.left + dragScrollMargin)
sx = -dragScrollSpeed(rect.left - event.clientX);
else if (event.clientX + margins.right >= rect.right - dragScrollMargin)
sx = dragScrollSpeed(event.clientX - rect.right);
if (event.clientY - margins.top <= rect.top + dragScrollMargin)
sy = -dragScrollSpeed(rect.top - event.clientY);
else if (event.clientY + margins.bottom >= rect.bottom - dragScrollMargin)
sy = dragScrollSpeed(event.clientY - rect.bottom);
this.setScrollSpeed(sx, sy);
}
up(event) {
if (this.dragging == null)
this.select(this.lastEvent);
if (!this.dragging)
event.preventDefault();
this.destroy();
}
destroy() {
this.setScrollSpeed(0, 0);
let doc2 = this.view.contentDOM.ownerDocument;
doc2.removeEventListener("mousemove", this.move);
doc2.removeEventListener("mouseup", this.up);
this.view.inputState.mouseSelection = this.view.inputState.draggedContent = null;
}
setScrollSpeed(sx, sy) {
this.scrollSpeed = { x: sx, y: sy };
if (sx || sy) {
if (this.scrolling < 0)
this.scrolling = setInterval(() => this.scroll(), 50);
} else if (this.scrolling > -1) {
clearInterval(this.scrolling);
this.scrolling = -1;
}
}
scroll() {
if (this.scrollParent) {
this.scrollParent.scrollLeft += this.scrollSpeed.x;
this.scrollParent.scrollTop += this.scrollSpeed.y;
} else {
this.view.win.scrollBy(this.scrollSpeed.x, this.scrollSpeed.y);
}
if (this.dragging === false)
this.select(this.lastEvent);
}
skipAtoms(sel) {
let ranges = null;
for (let i2 = 0; i2 < sel.ranges.length; i2++) {
let range = sel.ranges[i2], updated = null;
if (range.empty) {
let pos = skipAtomicRanges(this.atoms, range.from, 0);
if (pos != range.from)
updated = EditorSelection.cursor(pos, -1);
} else {
let from = skipAtomicRanges(this.atoms, range.from, -1);
let to = skipAtomicRanges(this.atoms, range.to, 1);
if (from != range.from || to != range.to)
updated = EditorSelection.range(range.from == range.anchor ? from : to, range.from == range.head ? from : to);
}
if (updated) {
if (!ranges)
ranges = sel.ranges.slice();
ranges[i2] = updated;
}
}
return ranges ? EditorSelection.create(ranges, sel.mainIndex) : sel;
}
select(event) {
let { view } = this, selection = this.skipAtoms(this.style.get(event, this.extend, this.multiple));
if (this.mustSelect || !selection.eq(view.state.selection, this.dragging === false))
this.view.dispatch({
selection,
userEvent: "select.pointer"
});
this.mustSelect = false;
}
update(update) {
if (this.style.update(update))
setTimeout(() => this.select(this.lastEvent), 20);
}
}
function addsSelectionRange(view, event) {
let facet = view.state.facet(clickAddsSelectionRange);
return facet.length ? facet[0](event) : browser.mac ? event.metaKey : event.ctrlKey;
}
function dragMovesSelection(view, event) {
let facet = view.state.facet(dragMovesSelection$1);
return facet.length ? facet[0](event) : browser.mac ? !event.altKey : !event.ctrlKey;
}
function isInPrimarySelection(view, event) {
let { main } = view.state.selection;
if (main.empty)
return false;
let sel = getSelection(view.root);
if (!sel || sel.rangeCount == 0)
return true;
let rects = sel.getRangeAt(0).getClientRects();
for (let i2 = 0; i2 < rects.length; i2++) {
let rect = rects[i2];
if (rect.left <= event.clientX && rect.right >= event.clientX && rect.top <= event.clientY && rect.bottom >= event.clientY)
return true;
}
return false;
}
function eventBelongsToEditor(view, event) {
if (!event.bubbles)
return true;
if (event.defaultPrevented)
return false;
for (let node = event.target, cView; node != view.contentDOM; node = node.parentNode)
if (!node || node.nodeType == 11 || (cView = ContentView.get(node)) && cView.ignoreEvent(event))
return false;
return true;
}
const handlers = /* @__PURE__ */ Object.create(null);
const observers = /* @__PURE__ */ Object.create(null);
const brokenClipboardAPI = browser.ie && browser.ie_version < 15 || browser.ios && browser.webkit_version < 604;
function capturePaste(view) {
let parent = view.dom.parentNode;
if (!parent)
return;
let target = parent.appendChild(document.createElement("textarea"));
target.style.cssText = "position: fixed; left: -10000px; top: 10px";
target.focus();
setTimeout(() => {
view.focus();
target.remove();
doPaste(view, target.value);
}, 50);
}
function doPaste(view, input) {
let { state } = view, changes, i2 = 1, text = state.toText(input);
let byLine = text.lines == state.selection.ranges.length;
let linewise = lastLinewiseCopy != null && state.selection.ranges.every((r) => r.empty) && lastLinewiseCopy == text.toString();
if (linewise) {
let lastLine = -1;
changes = state.changeByRange((range) => {
let line = state.doc.lineAt(range.from);
if (line.from == lastLine)
return { range };
lastLine = line.from;
let insert2 = state.toText((byLine ? text.line(i2++).text : input) + state.lineBreak);
return {
changes: { from: line.from, insert: insert2 },
range: EditorSelection.cursor(range.from + insert2.length)
};
});
} else if (byLine) {
changes = state.changeByRange((range) => {
let line = text.line(i2++);
return {
changes: { from: range.from, to: range.to, insert: line.text },
range: EditorSelection.cursor(range.from + line.length)
};
});
} else {
changes = state.replaceSelection(text);
}
view.dispatch(changes, {
userEvent: "input.paste",
scrollIntoView: true
});
}
observers.scroll = (view) => {
view.inputState.lastScrollTop = view.scrollDOM.scrollTop;
view.inputState.lastScrollLeft = view.scrollDOM.scrollLeft;
};
handlers.keydown = (view, event) => {
view.inputState.setSelectionOrigin("select");
if (event.keyCode == 27)
view.inputState.lastEscPress = Date.now();
return false;
};
observers.touchstart = (view, e) => {
view.inputState.lastTouchTime = Date.now();
view.inputState.setSelectionOrigin("select.pointer");
};
observers.touchmove = (view) => {
view.inputState.setSelectionOrigin("select.pointer");
};
handlers.mousedown = (view, event) => {
view.observer.flush();
if (view.inputState.lastTouchTime > Date.now() - 2e3)
return false;
let style = null;
for (let makeStyle of view.state.facet(mouseSelectionStyle)) {
style = makeStyle(view, event);
if (style)
break;
}
if (!style && event.button == 0)
style = basicMouseSelection(view, event);
if (style) {
let mustFocus = !view.hasFocus;
view.inputState.startMouseSelection(new MouseSelection(view, event, style, mustFocus));
if (mustFocus)
view.observer.ignore(() => focusPreventScroll(view.contentDOM));
let mouseSel = view.inputState.mouseSelection;
if (mouseSel) {
mouseSel.start(event);
return mouseSel.dragging === false;
}
}
return false;
};
function rangeForClick(view, pos, bias, type) {
if (type == 1) {
return EditorSelection.cursor(pos, bias);
} else if (type == 2) {
return groupAt(view.state, pos, bias);
} else {
let visual = LineView.find(view.docView, pos), line = view.state.doc.lineAt(visual ? visual.posAtEnd : pos);
let from = visual ? visual.posAtStart : line.from, to = visual ? visual.posAtEnd : line.to;
if (to < view.state.doc.length && to == line.to)
to++;
return EditorSelection.range(from, to);
}
}
let insideY = (y2, rect) => y2 >= rect.top && y2 <= rect.bottom;
let inside = (x2, y2, rect) => insideY(y2, rect) && x2 >= rect.left && x2 <= rect.right;
function findPositionSide(view, pos, x2, y2) {
let line = LineView.find(view.docView, pos);
if (!line)
return 1;
let off = pos - line.posAtStart;
if (off == 0)
return 1;
if (off == line.length)
return -1;
let before = line.coordsAt(off, -1);
if (before && inside(x2, y2, before))
return -1;
let after = line.coordsAt(off, 1);
if (after && inside(x2, y2, after))
return 1;
return before && insideY(y2, before) ? -1 : 1;
}
function queryPos(view, event) {
let pos = view.posAtCoords({ x: event.clientX, y: event.clientY }, false);
return { pos, bias: findPositionSide(view, pos, event.clientX, event.clientY) };
}
const BadMouseDetail = browser.ie && browser.ie_version <= 11;
let lastMouseDown = null, lastMouseDownCount = 0, lastMouseDownTime = 0;
function getClickType(event) {
if (!BadMouseDetail)
return event.detail;
let last = lastMouseDown, lastTime = lastMouseDownTime;
lastMouseDown = event;
lastMouseDownTime = Date.now();
return lastMouseDownCount = !last || lastTime > Date.now() - 400 && Math.abs(last.clientX - event.clientX) < 2 && Math.abs(last.clientY - event.clientY) < 2 ? (lastMouseDownCount + 1) % 3 : 1;
}
function basicMouseSelection(view, event) {
let start = queryPos(view, event), type = getClickType(event);
let startSel = view.state.selection;
return {
update(update) {
if (update.docChanged) {
start.pos = update.changes.mapPos(start.pos);
startSel = startSel.map(update.changes);
}
},
get(event2, extend2, multiple) {
let cur2 = queryPos(view, event2), removed;
let range = rangeForClick(view, cur2.pos, cur2.bias, type);
if (start.pos != cur2.pos && !extend2) {
let startRange = rangeForClick(view, start.pos, start.bias, type);
let from = Math.min(startRange.from, range.from), to = Math.max(startRange.to, range.to);
range = from < range.from ? EditorSelection.range(from, to) : EditorSelection.range(to, from);
}
if (extend2)
return startSel.replaceRange(startSel.main.extend(range.from, range.to));
else if (multiple && type == 1 && startSel.ranges.length > 1 && (removed = removeRangeAround(startSel, cur2.pos)))
return removed;
else if (multiple)
return startSel.addRange(range);
else
return EditorSelection.create([range]);
}
};
}
function removeRangeAround(sel, pos) {
for (let i2 = 0; i2 < sel.ranges.length; i2++) {
let { from, to } = sel.ranges[i2];
if (from <= pos && to >= pos)
return EditorSelection.create(sel.ranges.slice(0, i2).concat(sel.ranges.slice(i2 + 1)), sel.mainIndex == i2 ? 0 : sel.mainIndex - (sel.mainIndex > i2 ? 1 : 0));
}
return null;
}
handlers.dragstart = (view, event) => {
let { selection: { main: range } } = view.state;
if (event.target.draggable) {
let cView = view.docView.nearest(event.target);
if (cView && cView.isWidget) {
let from = cView.posAtStart, to = from + cView.length;
if (from >= range.to || to <= range.from)
range = EditorSelection.range(from, to);
}
}
let { inputState } = view;
if (inputState.mouseSelection)
inputState.mouseSelection.dragging = true;
inputState.draggedContent = range;
if (event.dataTransfer) {
event.dataTransfer.setData("Text", view.state.sliceDoc(range.from, range.to));
event.dataTransfer.effectAllowed = "copyMove";
}
return false;
};
handlers.dragend = (view) => {
view.inputState.draggedContent = null;
return false;
};
function dropText(view, event, text, direct) {
if (!text)
return;
let dropPos = view.posAtCoords({ x: event.clientX, y: event.clientY }, false);
let { draggedContent } = view.inputState;
let del = direct && draggedContent && dragMovesSelection(view, event) ? { from: draggedContent.from, to: draggedContent.to } : null;
let ins = { from: dropPos, insert: text };
let changes = view.state.changes(del ? [del, ins] : ins);
view.focus();
view.dispatch({
changes,
selection: { anchor: changes.mapPos(dropPos, -1), head: changes.mapPos(dropPos, 1) },
userEvent: del ? "move.drop" : "input.drop"
});
view.inputState.draggedContent = null;
}
handlers.drop = (view, event) => {
if (!event.dataTransfer)
return false;
if (view.state.readOnly)
return true;
let files = event.dataTransfer.files;
if (files && files.length) {
let text = Array(files.length), read = 0;
let finishFile = () => {
if (++read == files.length)
dropText(view, event, text.filter((s) => s != null).join(view.state.lineBreak), false);
};
for (let i2 = 0; i2 < files.length; i2++) {
let reader = new FileReader();
reader.onerror = finishFile;
reader.onload = () => {
if (!/[\x00-\x08\x0e-\x1f]{2}/.test(reader.result))
text[i2] = reader.result;
finishFile();
};
reader.readAsText(files[i2]);
}
return true;
} else {
let text = event.dataTransfer.getData("Text");
if (text) {
dropText(view, event, text, true);
return true;
}
}
return false;
};
handlers.paste = (view, event) => {
if (view.state.readOnly)
return true;
view.observer.flush();
let data = brokenClipboardAPI ? null : event.clipboardData;
if (data) {
doPaste(view, data.getData("text/plain") || data.getData("text/uri-text"));
return true;
} else {
capturePaste(view);
return false;
}
};
function captureCopy(view, text) {
let parent = view.dom.parentNode;
if (!parent)
return;
let target = parent.appendChild(document.createElement("textarea"));
target.style.cssText = "position: fixed; left: -10000px; top: 10px";
target.value = text;
target.focus();
target.selectionEnd = text.length;
target.selectionStart = 0;
setTimeout(() => {
target.remove();
view.focus();
}, 50);
}
function copiedRange(state) {
let content2 = [], ranges = [], linewise = false;
for (let range of state.selection.ranges)
if (!range.empty) {
content2.push(state.sliceDoc(range.from, range.to));
ranges.push(range);
}
if (!content2.length) {
let upto = -1;
for (let { from } of state.selection.ranges) {
let line = state.doc.lineAt(from);
if (line.number > upto) {
content2.push(line.text);
ranges.push({ from: line.from, to: Math.min(state.doc.length, line.to + 1) });
}
upto = line.number;
}
linewise = true;
}
return { text: content2.join(state.lineBreak), ranges, linewise };
}
let lastLinewiseCopy = null;
handlers.copy = handlers.cut = (view, event) => {
let { text, ranges, linewise } = copiedRange(view.state);
if (!text && !linewise)
return false;
lastLinewiseCopy = linewise ? text : null;
if (event.type == "cut" && !view.state.readOnly)
view.dispatch({
changes: ranges,
scrollIntoView: true,
userEvent: "delete.cut"
});
let data = brokenClipboardAPI ? null : event.clipboardData;
if (data) {
data.clearData();
data.setData("text/plain", text);
return true;
} else {
captureCopy(view, text);
return false;
}
};
const isFocusChange = /* @__PURE__ */ Annotation.define();
function focusChangeTransaction(state, focus) {
let effects = [];
for (let getEffect of state.facet(focusChangeEffect)) {
let effect = getEffect(state, focus);
if (effect)
effects.push(effect);
}
return effects ? state.update({ effects, annotations: isFocusChange.of(true) }) : null;
}
function updateForFocusChange(view) {
setTimeout(() => {
let focus = view.hasFocus;
if (focus != view.inputState.notifiedFocused) {
let tr = focusChangeTransaction(view.state, focus);
if (tr)
view.dispatch(tr);
else
view.update([]);
}
}, 10);
}
observers.focus = (view) => {
view.inputState.lastFocusTime = Date.now();
if (!view.scrollDOM.scrollTop && (view.inputState.lastScrollTop || view.inputState.lastScrollLeft)) {
view.scrollDOM.scrollTop = view.inputState.lastScrollTop;
view.scrollDOM.scrollLeft = view.inputState.lastScrollLeft;
}
updateForFocusChange(view);
};
observers.blur = (view) => {
view.observer.clearSelectionRange();
updateForFocusChange(view);
};
observers.compositionstart = observers.compositionupdate = (view) => {
if (view.inputState.compositionFirstChange == null)
view.inputState.compositionFirstChange = true;
if (view.inputState.composing < 0) {
view.inputState.composing = 0;
}
};
observers.compositionend = (view) => {
view.inputState.composing = -1;
view.inputState.compositionEndedAt = Date.now();
view.inputState.compositionPendingKey = true;
view.inputState.compositionPendingChange = view.observer.pendingRecords().length > 0;
view.inputState.compositionFirstChange = null;
if (browser.chrome && browser.android) {
view.observer.flushSoon();
} else if (view.inputState.compositionPendingChange) {
Promise.resolve().then(() => view.observer.flush());
} else {
setTimeout(() => {
if (view.inputState.composing < 0 && view.docView.hasComposition)
view.update([]);
}, 50);
}
};
observers.contextmenu = (view) => {
view.inputState.lastContextMenu = Date.now();
};
handlers.beforeinput = (view, event) => {
var _a2;
let pending;
if (browser.chrome && browser.android && (pending = PendingKeys.find((key) => key.inputType == event.inputType))) {
view.observer.delayAndroidKey(pending.key, pending.keyCode);
if (pending.key == "Backspace" || pending.key == "Delete") {
let startViewHeight = ((_a2 = window.visualViewport) === null || _a2 === void 0 ? void 0 : _a2.height) || 0;
setTimeout(() => {
var _a3;
if ((((_a3 = window.visualViewport) === null || _a3 === void 0 ? void 0 : _a3.height) || 0) > startViewHeight + 10 && view.hasFocus) {
view.contentDOM.blur();
view.focus();
}
}, 100);
}
}
return false;
};
const appliedFirefoxHack = /* @__PURE__ */ new Set();
function firefoxCopyCutHack(doc2) {
if (!appliedFirefoxHack.has(doc2)) {
appliedFirefoxHack.add(doc2);
doc2.addEventListener("copy", () => {
});
doc2.addEventListener("cut", () => {
});
}
}
const wrappingWhiteSpace = ["pre-wrap", "normal", "pre-line", "break-spaces"];
class HeightOracle {
constructor(lineWrapping) {
this.lineWrapping = lineWrapping;
this.doc = Text.empty;
this.heightSamples = {};
this.lineHeight = 14;
this.charWidth = 7;
this.textHeight = 14;
this.lineLength = 30;
this.heightChanged = false;
}
heightForGap(from, to) {
let lines = this.doc.lineAt(to).number - this.doc.lineAt(from).number + 1;
if (this.lineWrapping)
lines += Math.max(0, Math.ceil((to - from - lines * this.lineLength * 0.5) / this.lineLength));
return this.lineHeight * lines;
}
heightForLine(length) {
if (!this.lineWrapping)
return this.lineHeight;
let lines = 1 + Math.max(0, Math.ceil((length - this.lineLength) / (this.lineLength - 5)));
return lines * this.lineHeight;
}
setDoc(doc2) {
this.doc = doc2;
return this;
}
mustRefreshForWrapping(whiteSpace) {
return wrappingWhiteSpace.indexOf(whiteSpace) > -1 != this.lineWrapping;
}
mustRefreshForHeights(lineHeights) {
let newHeight = false;
for (let i2 = 0; i2 < lineHeights.length; i2++) {
let h2 = lineHeights[i2];
if (h2 < 0) {
i2++;
} else if (!this.heightSamples[Math.floor(h2 * 10)]) {
newHeight = true;
this.heightSamples[Math.floor(h2 * 10)] = true;
}
}
return newHeight;
}
refresh(whiteSpace, lineHeight, charWidth, textHeight, lineLength, knownHeights) {
let lineWrapping = wrappingWhiteSpace.indexOf(whiteSpace) > -1;
let changed = Math.round(lineHeight) != Math.round(this.lineHeight) || this.lineWrapping != lineWrapping;
this.lineWrapping = lineWrapping;
this.lineHeight = lineHeight;
this.charWidth = charWidth;
this.textHeight = textHeight;
this.lineLength = lineLength;
if (changed) {
this.heightSamples = {};
for (let i2 = 0; i2 < knownHeights.length; i2++) {
let h2 = knownHeights[i2];
if (h2 < 0)
i2++;
else
this.heightSamples[Math.floor(h2 * 10)] = true;
}
}
return changed;
}
}
class MeasuredHeights {
constructor(from, heights) {
this.from = from;
this.heights = heights;
this.index = 0;
}
get more() {
return this.index < this.heights.length;
}
}
class BlockInfo {
/**
@internal
*/
constructor(from, length, top2, height, _content) {
this.from = from;
this.length = length;
this.top = top2;
this.height = height;
this._content = _content;
}
/**
The type of element this is. When querying lines, this may be
an array of all the blocks that make up the line.
*/
get type() {
return typeof this._content == "number" ? BlockType.Text : Array.isArray(this._content) ? this._content : this._content.type;
}
/**
The end of the element as a document position.
*/
get to() {
return this.from + this.length;
}
/**
The bottom position of the element.
*/
get bottom() {
return this.top + this.height;
}
/**
If this is a widget block, this will return the widget
associated with it.
*/
get widget() {
return this._content instanceof PointDecoration ? this._content.widget : null;
}
/**
If this is a textblock, this holds the number of line breaks
that appear in widgets inside the block.
*/
get widgetLineBreaks() {
return typeof this._content == "number" ? this._content : 0;
}
/**
@internal
*/
join(other) {
let content2 = (Array.isArray(this._content) ? this._content : [this]).concat(Array.isArray(other._content) ? other._content : [other]);
return new BlockInfo(this.from, this.length + other.length, this.top, this.height + other.height, content2);
}
}
var QueryType$1 = /* @__PURE__ */ function(QueryType2) {
QueryType2[QueryType2["ByPos"] = 0] = "ByPos";
QueryType2[QueryType2["ByHeight"] = 1] = "ByHeight";
QueryType2[QueryType2["ByPosNoHeight"] = 2] = "ByPosNoHeight";
return QueryType2;
}(QueryType$1 || (QueryType$1 = {}));
const Epsilon = 1e-3;
class HeightMap {
constructor(length, height, flags = 2) {
this.length = length;
this.height = height;
this.flags = flags;
}
get outdated() {
return (this.flags & 2) > 0;
}
set outdated(value) {
this.flags = (value ? 2 : 0) | this.flags & ~2;
}
setHeight(oracle, height) {
if (this.height != height) {
if (Math.abs(this.height - height) > Epsilon)
oracle.heightChanged = true;
this.height = height;
}
}
// Base case is to replace a leaf node, which simply builds a tree
// from the new nodes and returns that (HeightMapBranch and
// HeightMapGap override this to actually use from/to)
replace(_from, _to, nodes) {
return HeightMap.of(nodes);
}
// Again, these are base cases, and are overridden for branch and gap nodes.
decomposeLeft(_to, result2) {
result2.push(this);
}
decomposeRight(_from, result2) {
result2.push(this);
}
applyChanges(decorations2, oldDoc, oracle, changes) {
let me = this, doc2 = oracle.doc;
for (let i2 = changes.length - 1; i2 >= 0; i2--) {
let { fromA, toA, fromB, toB } = changes[i2];
let start = me.lineAt(fromA, QueryType$1.ByPosNoHeight, oracle.setDoc(oldDoc), 0, 0);
let end = start.to >= toA ? start : me.lineAt(toA, QueryType$1.ByPosNoHeight, oracle, 0, 0);
toB += end.to - toA;
toA = end.to;
while (i2 > 0 && start.from <= changes[i2 - 1].toA) {
fromA = changes[i2 - 1].fromA;
fromB = changes[i2 - 1].fromB;
i2--;
if (fromA < start.from)
start = me.lineAt(fromA, QueryType$1.ByPosNoHeight, oracle, 0, 0);
}
fromB += start.from - fromA;
fromA = start.from;
let nodes = NodeBuilder.build(oracle.setDoc(doc2), decorations2, fromB, toB);
me = me.replace(fromA, toA, nodes);
}
return me.updateHeight(oracle, 0);
}
static empty() {
return new HeightMapText(0, 0);
}
// nodes uses null values to indicate the position of line breaks.
// There are never line breaks at the start or end of the array, or
// two line breaks next to each other, and the array isn't allowed
// to be empty (same restrictions as return value from the builder).
static of(nodes) {
if (nodes.length == 1)
return nodes[0];
let i2 = 0, j2 = nodes.length, before = 0, after = 0;
for (; ; ) {
if (i2 == j2) {
if (before > after * 2) {
let split = nodes[i2 - 1];
if (split.break)
nodes.splice(--i2, 1, split.left, null, split.right);
else
nodes.splice(--i2, 1, split.left, split.right);
j2 += 1 + split.break;
before -= split.size;
} else if (after > before * 2) {
let split = nodes[j2];
if (split.break)
nodes.splice(j2, 1, split.left, null, split.right);
else
nodes.splice(j2, 1, split.left, split.right);
j2 += 2 + split.break;
after -= split.size;
} else {
break;
}
} else if (before < after) {
let next = nodes[i2++];
if (next)
before += next.size;
} else {
let next = nodes[--j2];
if (next)
after += next.size;
}
}
let brk = 0;
if (nodes[i2 - 1] == null) {
brk = 1;
i2--;
} else if (nodes[i2] == null) {
brk = 1;
j2++;
}
return new HeightMapBranch(HeightMap.of(nodes.slice(0, i2)), brk, HeightMap.of(nodes.slice(j2)));
}
}
HeightMap.prototype.size = 1;
class HeightMapBlock extends HeightMap {
constructor(length, height, deco) {
super(length, height);
this.deco = deco;
}
blockAt(_height, _oracle, top2, offset) {
return new BlockInfo(offset, this.length, top2, this.height, this.deco || 0);
}
lineAt(_value, _type, oracle, top2, offset) {
return this.blockAt(0, oracle, top2, offset);
}
forEachLine(from, to, oracle, top2, offset, f) {
if (from <= offset + this.length && to >= offset)
f(this.blockAt(0, oracle, top2, offset));
}
updateHeight(oracle, offset = 0, _force = false, measured) {
if (measured && measured.from <= offset && measured.more)
this.setHeight(oracle, measured.heights[measured.index++]);
this.outdated = false;
return this;
}
toString() {
return `block(${this.length})`;
}
}
class HeightMapText extends HeightMapBlock {
constructor(length, height) {
super(length, height, null);
this.collapsed = 0;
this.widgetHeight = 0;
this.breaks = 0;
}
blockAt(_height, _oracle, top2, offset) {
return new BlockInfo(offset, this.length, top2, this.height, this.breaks);
}
replace(_from, _to, nodes) {
let node = nodes[0];
if (nodes.length == 1 && (node instanceof HeightMapText || node instanceof HeightMapGap && node.flags & 4) && Math.abs(this.length - node.length) < 10) {
if (node instanceof HeightMapGap)
node = new HeightMapText(node.length, this.height);
else
node.height = this.height;
if (!this.outdated)
node.outdated = false;
return node;
} else {
return HeightMap.of(nodes);
}
}
updateHeight(oracle, offset = 0, force = false, measured) {
if (measured && measured.from <= offset && measured.more)
this.setHeight(oracle, measured.heights[measured.index++]);
else if (force || this.outdated)
this.setHeight(oracle, Math.max(this.widgetHeight, oracle.heightForLine(this.length - this.collapsed)) + this.breaks * oracle.lineHeight);
this.outdated = false;
return this;
}
toString() {
return `line(${this.length}${this.collapsed ? -this.collapsed : ""}${this.widgetHeight ? ":" + this.widgetHeight : ""})`;
}
}
class HeightMapGap extends HeightMap {
constructor(length) {
super(length, 0);
}
heightMetrics(oracle, offset) {
let firstLine = oracle.doc.lineAt(offset).number, lastLine = oracle.doc.lineAt(offset + this.length).number;
let lines = lastLine - firstLine + 1;
let perLine, perChar = 0;
if (oracle.lineWrapping) {
let totalPerLine = Math.min(this.height, oracle.lineHeight * lines);
perLine = totalPerLine / lines;
if (this.length > lines + 1)
perChar = (this.height - totalPerLine) / (this.length - lines - 1);
} else {
perLine = this.height / lines;
}
return { firstLine, lastLine, perLine, perChar };
}
blockAt(height, oracle, top2, offset) {
let { firstLine, lastLine, perLine, perChar } = this.heightMetrics(oracle, offset);
if (oracle.lineWrapping) {
let guess = offset + Math.round(Math.max(0, Math.min(1, (height - top2) / this.height)) * this.length);
let line = oracle.doc.lineAt(guess), lineHeight = perLine + line.length * perChar;
let lineTop = Math.max(top2, height - lineHeight / 2);
return new BlockInfo(line.from, line.length, lineTop, lineHeight, 0);
} else {
let line = Math.max(0, Math.min(lastLine - firstLine, Math.floor((height - top2) / perLine)));
let { from, length } = oracle.doc.line(firstLine + line);
return new BlockInfo(from, length, top2 + perLine * line, perLine, 0);
}
}
lineAt(value, type, oracle, top2, offset) {
if (type == QueryType$1.ByHeight)
return this.blockAt(value, oracle, top2, offset);
if (type == QueryType$1.ByPosNoHeight) {
let { from, to } = oracle.doc.lineAt(value);
return new BlockInfo(from, to - from, 0, 0, 0);
}
let { firstLine, perLine, perChar } = this.heightMetrics(oracle, offset);
let line = oracle.doc.lineAt(value), lineHeight = perLine + line.length * perChar;
let linesAbove = line.number - firstLine;
let lineTop = top2 + perLine * linesAbove + perChar * (line.from - offset - linesAbove);
return new BlockInfo(line.from, line.length, Math.max(top2, Math.min(lineTop, top2 + this.height - lineHeight)), lineHeight, 0);
}
forEachLine(from, to, oracle, top2, offset, f) {
from = Math.max(from, offset);
to = Math.min(to, offset + this.length);
let { firstLine, perLine, perChar } = this.heightMetrics(oracle, offset);
for (let pos = from, lineTop = top2; pos <= to; ) {
let line = oracle.doc.lineAt(pos);
if (pos == from) {
let linesAbove = line.number - firstLine;
lineTop += perLine * linesAbove + perChar * (from - offset - linesAbove);
}
let lineHeight = perLine + perChar * line.length;
f(new BlockInfo(line.from, line.length, lineTop, lineHeight, 0));
lineTop += lineHeight;
pos = line.to + 1;
}
}
replace(from, to, nodes) {
let after = this.length - to;
if (after > 0) {
let last = nodes[nodes.length - 1];
if (last instanceof HeightMapGap)
nodes[nodes.length - 1] = new HeightMapGap(last.length + after);
else
nodes.push(null, new HeightMapGap(after - 1));
}
if (from > 0) {
let first = nodes[0];
if (first instanceof HeightMapGap)
nodes[0] = new HeightMapGap(from + first.length);
else
nodes.unshift(new HeightMapGap(from - 1), null);
}
return HeightMap.of(nodes);
}
decomposeLeft(to, result2) {
result2.push(new HeightMapGap(to - 1), null);
}
decomposeRight(from, result2) {
result2.push(null, new HeightMapGap(this.length - from - 1));
}
updateHeight(oracle, offset = 0, force = false, measured) {
let end = offset + this.length;
if (measured && measured.from <= offset + this.length && measured.more) {
let nodes = [], pos = Math.max(offset, measured.from), singleHeight = -1;
if (measured.from > offset)
nodes.push(new HeightMapGap(measured.from - offset - 1).updateHeight(oracle, offset));
while (pos <= end && measured.more) {
let len = oracle.doc.lineAt(pos).length;
if (nodes.length)
nodes.push(null);
let height = measured.heights[measured.index++];
if (singleHeight == -1)
singleHeight = height;
else if (Math.abs(height - singleHeight) >= Epsilon)
singleHeight = -2;
let line = new HeightMapText(len, height);
line.outdated = false;
nodes.push(line);
pos += len + 1;
}
if (pos <= end)
nodes.push(null, new HeightMapGap(end - pos).updateHeight(oracle, pos));
let result2 = HeightMap.of(nodes);
if (singleHeight < 0 || Math.abs(result2.height - this.height) >= Epsilon || Math.abs(singleHeight - this.heightMetrics(oracle, offset).perLine) >= Epsilon)
oracle.heightChanged = true;
return result2;
} else if (force || this.outdated) {
this.setHeight(oracle, oracle.heightForGap(offset, offset + this.length));
this.outdated = false;
}
return this;
}
toString() {
return `gap(${this.length})`;
}
}
class HeightMapBranch extends HeightMap {
constructor(left, brk, right) {
super(left.length + brk + right.length, left.height + right.height, brk | (left.outdated || right.outdated ? 2 : 0));
this.left = left;
this.right = right;
this.size = left.size + right.size;
}
get break() {
return this.flags & 1;
}
blockAt(height, oracle, top2, offset) {
let mid = top2 + this.left.height;
return height < mid ? this.left.blockAt(height, oracle, top2, offset) : this.right.blockAt(height, oracle, mid, offset + this.left.length + this.break);
}
lineAt(value, type, oracle, top2, offset) {
let rightTop = top2 + this.left.height, rightOffset = offset + this.left.length + this.break;
let left = type == QueryType$1.ByHeight ? value < rightTop : value < rightOffset;
let base2 = left ? this.left.lineAt(value, type, oracle, top2, offset) : this.right.lineAt(value, type, oracle, rightTop, rightOffset);
if (this.break || (left ? base2.to < rightOffset : base2.from > rightOffset))
return base2;
let subQuery = type == QueryType$1.ByPosNoHeight ? QueryType$1.ByPosNoHeight : QueryType$1.ByPos;
if (left)
return base2.join(this.right.lineAt(rightOffset, subQuery, oracle, rightTop, rightOffset));
else
return this.left.lineAt(rightOffset, subQuery, oracle, top2, offset).join(base2);
}
forEachLine(from, to, oracle, top2, offset, f) {
let rightTop = top2 + this.left.height, rightOffset = offset + this.left.length + this.break;
if (this.break) {
if (from < rightOffset)
this.left.forEachLine(from, to, oracle, top2, offset, f);
if (to >= rightOffset)
this.right.forEachLine(from, to, oracle, rightTop, rightOffset, f);
} else {
let mid = this.lineAt(rightOffset, QueryType$1.ByPos, oracle, top2, offset);
if (from < mid.from)
this.left.forEachLine(from, mid.from - 1, oracle, top2, offset, f);
if (mid.to >= from && mid.from <= to)
f(mid);
if (to > mid.to)
this.right.forEachLine(mid.to + 1, to, oracle, rightTop, rightOffset, f);
}
}
replace(from, to, nodes) {
let rightStart = this.left.length + this.break;
if (to < rightStart)
return this.balanced(this.left.replace(from, to, nodes), this.right);
if (from > this.left.length)
return this.balanced(this.left, this.right.replace(from - rightStart, to - rightStart, nodes));
let result2 = [];
if (from > 0)
this.decomposeLeft(from, result2);
let left = result2.length;
for (let node of nodes)
result2.push(node);
if (from > 0)
mergeGaps(result2, left - 1);
if (to < this.length) {
let right = result2.length;
this.decomposeRight(to, result2);
mergeGaps(result2, right);
}
return HeightMap.of(result2);
}
decomposeLeft(to, result2) {
let left = this.left.length;
if (to <= left)
return this.left.decomposeLeft(to, result2);
result2.push(this.left);
if (this.break) {
left++;
if (to >= left)
result2.push(null);
}
if (to > left)
this.right.decomposeLeft(to - left, result2);
}
decomposeRight(from, result2) {
let left = this.left.length, right = left + this.break;
if (from >= right)
return this.right.decomposeRight(from - right, result2);
if (from < left)
this.left.decomposeRight(from, result2);
if (this.break && from < right)
result2.push(null);
result2.push(this.right);
}
balanced(left, right) {
if (left.size > 2 * right.size || right.size > 2 * left.size)
return HeightMap.of(this.break ? [left, null, right] : [left, right]);
this.left = left;
this.right = right;
this.height = left.height + right.height;
this.outdated = left.outdated || right.outdated;
this.size = left.size + right.size;
this.length = left.length + this.break + right.length;
return this;
}
updateHeight(oracle, offset = 0, force = false, measured) {
let { left, right } = this, rightStart = offset + left.length + this.break, rebalance = null;
if (measured && measured.from <= offset + left.length && measured.more)
rebalance = left = left.updateHeight(oracle, offset, force, measured);
else
left.updateHeight(oracle, offset, force);
if (measured && measured.from <= rightStart + right.length && measured.more)
rebalance = right = right.updateHeight(oracle, rightStart, force, measured);
else
right.updateHeight(oracle, rightStart, force);
if (rebalance)
return this.balanced(left, right);
this.height = this.left.height + this.right.height;
this.outdated = false;
return this;
}
toString() {
return this.left + (this.break ? " " : "-") + this.right;
}
}
function mergeGaps(nodes, around) {
let before, after;
if (nodes[around] == null && (before = nodes[around - 1]) instanceof HeightMapGap && (after = nodes[around + 1]) instanceof HeightMapGap)
nodes.splice(around - 1, 3, new HeightMapGap(before.length + 1 + after.length));
}
const relevantWidgetHeight = 5;
class NodeBuilder {
constructor(pos, oracle) {
this.pos = pos;
this.oracle = oracle;
this.nodes = [];
this.lineStart = -1;
this.lineEnd = -1;
this.covering = null;
this.writtenTo = pos;
}
get isCovered() {
return this.covering && this.nodes[this.nodes.length - 1] == this.covering;
}
span(_from, to) {
if (this.lineStart > -1) {
let end = Math.min(to, this.lineEnd), last = this.nodes[this.nodes.length - 1];
if (last instanceof HeightMapText)
last.length += end - this.pos;
else if (end > this.pos || !this.isCovered)
this.nodes.push(new HeightMapText(end - this.pos, -1));
this.writtenTo = end;
if (to > end) {
this.nodes.push(null);
this.writtenTo++;
this.lineStart = -1;
}
}
this.pos = to;
}
point(from, to, deco) {
if (from < to || deco.heightRelevant) {
let height = deco.widget ? deco.widget.estimatedHeight : 0;
let breaks = deco.widget ? deco.widget.lineBreaks : 0;
if (height < 0)
height = this.oracle.lineHeight;
let len = to - from;
if (deco.block) {
this.addBlock(new HeightMapBlock(len, height, deco));
} else if (len || breaks || height >= relevantWidgetHeight) {
this.addLineDeco(height, breaks, len);
}
} else if (to > from) {
this.span(from, to);
}
if (this.lineEnd > -1 && this.lineEnd < this.pos)
this.lineEnd = this.oracle.doc.lineAt(this.pos).to;
}
enterLine() {
if (this.lineStart > -1)
return;
let { from, to } = this.oracle.doc.lineAt(this.pos);
this.lineStart = from;
this.lineEnd = to;
if (this.writtenTo < from) {
if (this.writtenTo < from - 1 || this.nodes[this.nodes.length - 1] == null)
this.nodes.push(this.blankContent(this.writtenTo, from - 1));
this.nodes.push(null);
}
if (this.pos > from)
this.nodes.push(new HeightMapText(this.pos - from, -1));
this.writtenTo = this.pos;
}
blankContent(from, to) {
let gap = new HeightMapGap(to - from);
if (this.oracle.doc.lineAt(from).to == to)
gap.flags |= 4;
return gap;
}
ensureLine() {
this.enterLine();
let last = this.nodes.length ? this.nodes[this.nodes.length - 1] : null;
if (last instanceof HeightMapText)
return last;
let line = new HeightMapText(0, -1);
this.nodes.push(line);
return line;
}
addBlock(block) {
this.enterLine();
let deco = block.deco;
if (deco && deco.startSide > 0 && !this.isCovered)
this.ensureLine();
this.nodes.push(block);
this.writtenTo = this.pos = this.pos + block.length;
if (deco && deco.endSide > 0)
this.covering = block;
}
addLineDeco(height, breaks, length) {
let line = this.ensureLine();
line.length += length;
line.collapsed += length;
line.widgetHeight = Math.max(line.widgetHeight, height);
line.breaks += breaks;
this.writtenTo = this.pos = this.pos + length;
}
finish(from) {
let last = this.nodes.length == 0 ? null : this.nodes[this.nodes.length - 1];
if (this.lineStart > -1 && !(last instanceof HeightMapText) && !this.isCovered)
this.nodes.push(new HeightMapText(0, -1));
else if (this.writtenTo < this.pos || last == null)
this.nodes.push(this.blankContent(this.writtenTo, this.pos));
let pos = from;
for (let node of this.nodes) {
if (node instanceof HeightMapText)
node.updateHeight(this.oracle, pos);
pos += node ? node.length : 1;
}
return this.nodes;
}
// Always called with a region that on both sides either stretches
// to a line break or the end of the document.
// The returned array uses null to indicate line breaks, but never
// starts or ends in a line break, or has multiple line breaks next
// to each other.
static build(oracle, decorations2, from, to) {
let builder = new NodeBuilder(from, oracle);
RangeSet.spans(decorations2, from, to, builder, 0);
return builder.finish(from);
}
}
function heightRelevantDecoChanges(a, b, diff) {
let comp = new DecorationComparator();
RangeSet.compare(a, b, diff, comp, 0);
return comp.changes;
}
class DecorationComparator {
constructor() {
this.changes = [];
}
compareRange() {
}
comparePoint(from, to, a, b) {
if (from < to || a && a.heightRelevant || b && b.heightRelevant)
addRange(from, to, this.changes, 5);
}
}
function visiblePixelRange(dom, paddingTop) {
let rect = dom.getBoundingClientRect();
let doc2 = dom.ownerDocument, win = doc2.defaultView || window;
let left = Math.max(0, rect.left), right = Math.min(win.innerWidth, rect.right);
let top2 = Math.max(0, rect.top), bottom = Math.min(win.innerHeight, rect.bottom);
for (let parent = dom.parentNode; parent && parent != doc2.body; ) {
if (parent.nodeType == 1) {
let elt = parent;
let style = window.getComputedStyle(elt);
if ((elt.scrollHeight > elt.clientHeight || elt.scrollWidth > elt.clientWidth) && style.overflow != "visible") {
let parentRect = elt.getBoundingClientRect();
left = Math.max(left, parentRect.left);
right = Math.min(right, parentRect.right);
top2 = Math.max(top2, parentRect.top);
bottom = parent == dom.parentNode ? parentRect.bottom : Math.min(bottom, parentRect.bottom);
}
parent = style.position == "absolute" || style.position == "fixed" ? elt.offsetParent : elt.parentNode;
} else if (parent.nodeType == 11) {
parent = parent.host;
} else {
break;
}
}
return {
left: left - rect.left,
right: Math.max(left, right) - rect.left,
top: top2 - (rect.top + paddingTop),
bottom: Math.max(top2, bottom) - (rect.top + paddingTop)
};
}
function fullPixelRange(dom, paddingTop) {
let rect = dom.getBoundingClientRect();
return {
left: 0,
right: rect.right - rect.left,
top: paddingTop,
bottom: rect.bottom - (rect.top + paddingTop)
};
}
class LineGap {
constructor(from, to, size) {
this.from = from;
this.to = to;
this.size = size;
}
static same(a, b) {
if (a.length != b.length)
return false;
for (let i2 = 0; i2 < a.length; i2++) {
let gA = a[i2], gB = b[i2];
if (gA.from != gB.from || gA.to != gB.to || gA.size != gB.size)
return false;
}
return true;
}
draw(viewState, wrapping) {
return Decoration.replace({
widget: new LineGapWidget(this.size * (wrapping ? viewState.scaleY : viewState.scaleX), wrapping)
}).range(this.from, this.to);
}
}
class LineGapWidget extends WidgetType {
constructor(size, vertical) {
super();
this.size = size;
this.vertical = vertical;
}
eq(other) {
return other.size == this.size && other.vertical == this.vertical;
}
toDOM() {
let elt = document.createElement("div");
if (this.vertical) {
elt.style.height = this.size + "px";
} else {
elt.style.width = this.size + "px";
elt.style.height = "2px";
elt.style.display = "inline-block";
}
return elt;
}
get estimatedHeight() {
return this.vertical ? this.size : -1;
}
}
class ViewState {
constructor(state) {
this.state = state;
this.pixelViewport = { left: 0, right: window.innerWidth, top: 0, bottom: 0 };
this.inView = true;
this.paddingTop = 0;
this.paddingBottom = 0;
this.contentDOMWidth = 0;
this.contentDOMHeight = 0;
this.editorHeight = 0;
this.editorWidth = 0;
this.scrollTop = 0;
this.scrolledToBottom = true;
this.scaleX = 1;
this.scaleY = 1;
this.scrollAnchorPos = 0;
this.scrollAnchorHeight = -1;
this.scaler = IdScaler;
this.scrollTarget = null;
this.printing = false;
this.mustMeasureContent = true;
this.defaultTextDirection = Direction.LTR;
this.visibleRanges = [];
this.mustEnforceCursorAssoc = false;
let guessWrapping = state.facet(contentAttributes).some((v) => typeof v != "function" && v.class == "cm-lineWrapping");
this.heightOracle = new HeightOracle(guessWrapping);
this.stateDeco = state.facet(decorations).filter((d) => typeof d != "function");
this.heightMap = HeightMap.empty().applyChanges(this.stateDeco, Text.empty, this.heightOracle.setDoc(state.doc), [new ChangedRange(0, 0, 0, state.doc.length)]);
this.viewport = this.getViewport(0, null);
this.updateViewportLines();
this.updateForViewport();
this.lineGaps = this.ensureLineGaps([]);
this.lineGapDeco = Decoration.set(this.lineGaps.map((gap) => gap.draw(this, false)));
this.computeVisibleRanges();
}
updateForViewport() {
let viewports = [this.viewport], { main } = this.state.selection;
for (let i2 = 0; i2 <= 1; i2++) {
let pos = i2 ? main.head : main.anchor;
if (!viewports.some(({ from, to }) => pos >= from && pos <= to)) {
let { from, to } = this.lineBlockAt(pos);
viewports.push(new Viewport(from, to));
}
}
this.viewports = viewports.sort((a, b) => a.from - b.from);
this.scaler = this.heightMap.height <= 7e6 ? IdScaler : new BigScaler(this.heightOracle, this.heightMap, this.viewports);
}
updateViewportLines() {
this.viewportLines = [];
this.heightMap.forEachLine(this.viewport.from, this.viewport.to, this.heightOracle.setDoc(this.state.doc), 0, 0, (block) => {
this.viewportLines.push(this.scaler.scale == 1 ? block : scaleBlock(block, this.scaler));
});
}
update(update, scrollTarget = null) {
this.state = update.state;
let prevDeco = this.stateDeco;
this.stateDeco = this.state.facet(decorations).filter((d) => typeof d != "function");
let contentChanges = update.changedRanges;
let heightChanges = ChangedRange.extendWithRanges(contentChanges, heightRelevantDecoChanges(prevDeco, this.stateDeco, update ? update.changes : ChangeSet.empty(this.state.doc.length)));
let prevHeight = this.heightMap.height;
let scrollAnchor = this.scrolledToBottom ? null : this.scrollAnchorAt(this.scrollTop);
this.heightMap = this.heightMap.applyChanges(this.stateDeco, update.startState.doc, this.heightOracle.setDoc(this.state.doc), heightChanges);
if (this.heightMap.height != prevHeight)
update.flags |= 2;
if (scrollAnchor) {
this.scrollAnchorPos = update.changes.mapPos(scrollAnchor.from, -1);
this.scrollAnchorHeight = scrollAnchor.top;
} else {
this.scrollAnchorPos = -1;
this.scrollAnchorHeight = this.heightMap.height;
}
let viewport = heightChanges.length ? this.mapViewport(this.viewport, update.changes) : this.viewport;
if (scrollTarget && (scrollTarget.range.head < viewport.from || scrollTarget.range.head > viewport.to) || !this.viewportIsAppropriate(viewport))
viewport = this.getViewport(0, scrollTarget);
let updateLines = !update.changes.empty || update.flags & 2 || viewport.from != this.viewport.from || viewport.to != this.viewport.to;
this.viewport = viewport;
this.updateForViewport();
if (updateLines)
this.updateViewportLines();
if (this.lineGaps.length || this.viewport.to - this.viewport.from > 2e3 << 1)
this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps, update.changes)));
update.flags |= this.computeVisibleRanges();
if (scrollTarget)
this.scrollTarget = scrollTarget;
if (!this.mustEnforceCursorAssoc && update.selectionSet && update.view.lineWrapping && update.state.selection.main.empty && update.state.selection.main.assoc && !update.state.facet(nativeSelectionHidden))
this.mustEnforceCursorAssoc = true;
}
measure(view) {
let dom = view.contentDOM, style = window.getComputedStyle(dom);
let oracle = this.heightOracle;
let whiteSpace = style.whiteSpace;
this.defaultTextDirection = style.direction == "rtl" ? Direction.RTL : Direction.LTR;
let refresh = this.heightOracle.mustRefreshForWrapping(whiteSpace);
let domRect = dom.getBoundingClientRect();
let measureContent = refresh || this.mustMeasureContent || this.contentDOMHeight != domRect.height;
this.contentDOMHeight = domRect.height;
this.mustMeasureContent = false;
let result2 = 0, bias = 0;
if (domRect.width && domRect.height) {
let { scaleX, scaleY } = getScale(dom, domRect);
if (this.scaleX != scaleX || this.scaleY != scaleY) {
this.scaleX = scaleX;
this.scaleY = scaleY;
result2 |= 8;
refresh = measureContent = true;
}
}
let paddingTop = (parseInt(style.paddingTop) || 0) * this.scaleY;
let paddingBottom = (parseInt(style.paddingBottom) || 0) * this.scaleY;
if (this.paddingTop != paddingTop || this.paddingBottom != paddingBottom) {
this.paddingTop = paddingTop;
this.paddingBottom = paddingBottom;
result2 |= 8 | 2;
}
if (this.editorWidth != view.scrollDOM.clientWidth) {
if (oracle.lineWrapping)
measureContent = true;
this.editorWidth = view.scrollDOM.clientWidth;
result2 |= 8;
}
let scrollTop = view.scrollDOM.scrollTop * this.scaleY;
if (this.scrollTop != scrollTop) {
this.scrollAnchorHeight = -1;
this.scrollTop = scrollTop;
}
this.scrolledToBottom = isScrolledToBottom(view.scrollDOM);
let pixelViewport = (this.printing ? fullPixelRange : visiblePixelRange)(dom, this.paddingTop);
let dTop = pixelViewport.top - this.pixelViewport.top, dBottom = pixelViewport.bottom - this.pixelViewport.bottom;
this.pixelViewport = pixelViewport;
let inView = this.pixelViewport.bottom > this.pixelViewport.top && this.pixelViewport.right > this.pixelViewport.left;
if (inView != this.inView) {
this.inView = inView;
if (inView)
measureContent = true;
}
if (!this.inView && !this.scrollTarget)
return 0;
let contentWidth = domRect.width;
if (this.contentDOMWidth != contentWidth || this.editorHeight != view.scrollDOM.clientHeight) {
this.contentDOMWidth = domRect.width;
this.editorHeight = view.scrollDOM.clientHeight;
result2 |= 8;
}
if (measureContent) {
let lineHeights = view.docView.measureVisibleLineHeights(this.viewport);
if (oracle.mustRefreshForHeights(lineHeights))
refresh = true;
if (refresh || oracle.lineWrapping && Math.abs(contentWidth - this.contentDOMWidth) > oracle.charWidth) {
let { lineHeight, charWidth, textHeight } = view.docView.measureTextSize();
refresh = lineHeight > 0 && oracle.refresh(whiteSpace, lineHeight, charWidth, textHeight, contentWidth / charWidth, lineHeights);
if (refresh) {
view.docView.minWidth = 0;
result2 |= 8;
}
}
if (dTop > 0 && dBottom > 0)
bias = Math.max(dTop, dBottom);
else if (dTop < 0 && dBottom < 0)
bias = Math.min(dTop, dBottom);
oracle.heightChanged = false;
for (let vp of this.viewports) {
let heights = vp.from == this.viewport.from ? lineHeights : view.docView.measureVisibleLineHeights(vp);
this.heightMap = (refresh ? HeightMap.empty().applyChanges(this.stateDeco, Text.empty, this.heightOracle, [new ChangedRange(0, 0, 0, view.state.doc.length)]) : this.heightMap).updateHeight(oracle, 0, refresh, new MeasuredHeights(vp.from, heights));
}
if (oracle.heightChanged)
result2 |= 2;
}
let viewportChange = !this.viewportIsAppropriate(this.viewport, bias) || this.scrollTarget && (this.scrollTarget.range.head < this.viewport.from || this.scrollTarget.range.head > this.viewport.to);
if (viewportChange)
this.viewport = this.getViewport(bias, this.scrollTarget);
this.updateForViewport();
if (result2 & 2 || viewportChange)
this.updateViewportLines();
if (this.lineGaps.length || this.viewport.to - this.viewport.from > 2e3 << 1)
this.updateLineGaps(this.ensureLineGaps(refresh ? [] : this.lineGaps, view));
result2 |= this.computeVisibleRanges();
if (this.mustEnforceCursorAssoc) {
this.mustEnforceCursorAssoc = false;
view.docView.enforceCursorAssoc();
}
return result2;
}
get visibleTop() {
return this.scaler.fromDOM(this.pixelViewport.top);
}
get visibleBottom() {
return this.scaler.fromDOM(this.pixelViewport.bottom);
}
getViewport(bias, scrollTarget) {
let marginTop = 0.5 - Math.max(-0.5, Math.min(0.5, bias / 1e3 / 2));
let map = this.heightMap, oracle = this.heightOracle;
let { visibleTop, visibleBottom } = this;
let viewport = new Viewport(map.lineAt(visibleTop - marginTop * 1e3, QueryType$1.ByHeight, oracle, 0, 0).from, map.lineAt(visibleBottom + (1 - marginTop) * 1e3, QueryType$1.ByHeight, oracle, 0, 0).to);
if (scrollTarget) {
let { head } = scrollTarget.range;
if (head < viewport.from || head > viewport.to) {
let viewHeight = Math.min(this.editorHeight, this.pixelViewport.bottom - this.pixelViewport.top);
let block = map.lineAt(head, QueryType$1.ByPos, oracle, 0, 0), topPos;
if (scrollTarget.y == "center")
topPos = (block.top + block.bottom) / 2 - viewHeight / 2;
else if (scrollTarget.y == "start" || scrollTarget.y == "nearest" && head < viewport.from)
topPos = block.top;
else
topPos = block.bottom - viewHeight;
viewport = new Viewport(map.lineAt(topPos - 1e3 / 2, QueryType$1.ByHeight, oracle, 0, 0).from, map.lineAt(topPos + viewHeight + 1e3 / 2, QueryType$1.ByHeight, oracle, 0, 0).to);
}
}
return viewport;
}
mapViewport(viewport, changes) {
let from = changes.mapPos(viewport.from, -1), to = changes.mapPos(viewport.to, 1);
return new Viewport(this.heightMap.lineAt(from, QueryType$1.ByPos, this.heightOracle, 0, 0).from, this.heightMap.lineAt(to, QueryType$1.ByPos, this.heightOracle, 0, 0).to);
}
// Checks if a given viewport covers the visible part of the
// document and not too much beyond that.
viewportIsAppropriate({ from, to }, bias = 0) {
if (!this.inView)
return true;
let { top: top2 } = this.heightMap.lineAt(from, QueryType$1.ByPos, this.heightOracle, 0, 0);
let { bottom } = this.heightMap.lineAt(to, QueryType$1.ByPos, this.heightOracle, 0, 0);
let { visibleTop, visibleBottom } = this;
return (from == 0 || top2 <= visibleTop - Math.max(10, Math.min(
-bias,
250
/* VP.MaxCoverMargin */
))) && (to == this.state.doc.length || bottom >= visibleBottom + Math.max(10, Math.min(
bias,
250
/* VP.MaxCoverMargin */
))) && (top2 > visibleTop - 2 * 1e3 && bottom < visibleBottom + 2 * 1e3);
}
mapLineGaps(gaps, changes) {
if (!gaps.length || changes.empty)
return gaps;
let mapped = [];
for (let gap of gaps)
if (!changes.touchesRange(gap.from, gap.to))
mapped.push(new LineGap(changes.mapPos(gap.from), changes.mapPos(gap.to), gap.size));
return mapped;
}
// Computes positions in the viewport where the start or end of a
// line should be hidden, trying to reuse existing line gaps when
// appropriate to avoid unneccesary redraws.
// Uses crude character-counting for the positioning and sizing,
// since actual DOM coordinates aren't always available and
// predictable. Relies on generous margins (see LG.Margin) to hide
// the artifacts this might produce from the user.
ensureLineGaps(current, mayMeasure) {
let wrapping = this.heightOracle.lineWrapping;
let margin = wrapping ? 1e4 : 2e3, halfMargin = margin >> 1, doubleMargin = margin << 1;
if (this.defaultTextDirection != Direction.LTR && !wrapping)
return [];
let gaps = [];
let addGap = (from, to, line, structure) => {
if (to - from < halfMargin)
return;
let sel = this.state.selection.main, avoid = [sel.from];
if (!sel.empty)
avoid.push(sel.to);
for (let pos of avoid) {
if (pos > from && pos < to) {
addGap(from, pos - 10, line, structure);
addGap(pos + 10, to, line, structure);
return;
}
}
let gap = find(current, (gap2) => gap2.from >= line.from && gap2.to <= line.to && Math.abs(gap2.from - from) < halfMargin && Math.abs(gap2.to - to) < halfMargin && !avoid.some((pos) => gap2.from < pos && gap2.to > pos));
if (!gap) {
if (to < line.to && mayMeasure && wrapping && mayMeasure.visibleRanges.some((r) => r.from <= to && r.to >= to)) {
let lineStart = mayMeasure.moveToLineBoundary(EditorSelection.cursor(to), false, true).head;
if (lineStart > from)
to = lineStart;
}
gap = new LineGap(from, to, this.gapSize(line, from, to, structure));
}
gaps.push(gap);
};
for (let line of this.viewportLines) {
if (line.length < doubleMargin)
continue;
let structure = lineStructure(line.from, line.to, this.stateDeco);
if (structure.total < doubleMargin)
continue;
let target = this.scrollTarget ? this.scrollTarget.range.head : null;
let viewFrom, viewTo;
if (wrapping) {
let marginHeight = margin / this.heightOracle.lineLength * this.heightOracle.lineHeight;
let top2, bot;
if (target != null) {
let targetFrac = findFraction(structure, target);
let spaceFrac = ((this.visibleBottom - this.visibleTop) / 2 + marginHeight) / line.height;
top2 = targetFrac - spaceFrac;
bot = targetFrac + spaceFrac;
} else {
top2 = (this.visibleTop - line.top - marginHeight) / line.height;
bot = (this.visibleBottom - line.top + marginHeight) / line.height;
}
viewFrom = findPosition(structure, top2);
viewTo = findPosition(structure, bot);
} else {
let totalWidth = structure.total * this.heightOracle.charWidth;
let marginWidth = margin * this.heightOracle.charWidth;
let left, right;
if (target != null) {
let targetFrac = findFraction(structure, target);
let spaceFrac = ((this.pixelViewport.right - this.pixelViewport.left) / 2 + marginWidth) / totalWidth;
left = targetFrac - spaceFrac;
right = targetFrac + spaceFrac;
} else {
left = (this.pixelViewport.left - marginWidth) / totalWidth;
right = (this.pixelViewport.right + marginWidth) / totalWidth;
}
viewFrom = findPosition(structure, left);
viewTo = findPosition(structure, right);
}
if (viewFrom > line.from)
addGap(line.from, viewFrom, line, structure);
if (viewTo < line.to)
addGap(viewTo, line.to, line, structure);
}
return gaps;
}
gapSize(line, from, to, structure) {
let fraction = findFraction(structure, to) - findFraction(structure, from);
if (this.heightOracle.lineWrapping) {
return line.height * fraction;
} else {
return structure.total * this.heightOracle.charWidth * fraction;
}
}
updateLineGaps(gaps) {
if (!LineGap.same(gaps, this.lineGaps)) {
this.lineGaps = gaps;
this.lineGapDeco = Decoration.set(gaps.map((gap) => gap.draw(this, this.heightOracle.lineWrapping)));
}
}
computeVisibleRanges() {
let deco = this.stateDeco;
if (this.lineGaps.length)
deco = deco.concat(this.lineGapDeco);
let ranges = [];
RangeSet.spans(deco, this.viewport.from, this.viewport.to, {
span(from, to) {
ranges.push({ from, to });
},
point() {
}
}, 20);
let changed = ranges.length != this.visibleRanges.length || this.visibleRanges.some((r, i2) => r.from != ranges[i2].from || r.to != ranges[i2].to);
this.visibleRanges = ranges;
return changed ? 4 : 0;
}
lineBlockAt(pos) {
return pos >= this.viewport.from && pos <= this.viewport.to && this.viewportLines.find((b) => b.from <= pos && b.to >= pos) || scaleBlock(this.heightMap.lineAt(pos, QueryType$1.ByPos, this.heightOracle, 0, 0), this.scaler);
}
lineBlockAtHeight(height) {
return scaleBlock(this.heightMap.lineAt(this.scaler.fromDOM(height), QueryType$1.ByHeight, this.heightOracle, 0, 0), this.scaler);
}
scrollAnchorAt(scrollTop) {
let block = this.lineBlockAtHeight(scrollTop + 8);
return block.from >= this.viewport.from || this.viewportLines[0].top - scrollTop > 200 ? block : this.viewportLines[0];
}
elementAtHeight(height) {
return scaleBlock(this.heightMap.blockAt(this.scaler.fromDOM(height), this.heightOracle, 0, 0), this.scaler);
}
get docHeight() {
return this.scaler.toDOM(this.heightMap.height);
}
get contentHeight() {
return this.docHeight + this.paddingTop + this.paddingBottom;
}
}
class Viewport {
constructor(from, to) {
this.from = from;
this.to = to;
}
}
function lineStructure(from, to, stateDeco) {
let ranges = [], pos = from, total = 0;
RangeSet.spans(stateDeco, from, to, {
span() {
},
point(from2, to2) {
if (from2 > pos) {
ranges.push({ from: pos, to: from2 });
total += from2 - pos;
}
pos = to2;
}
}, 20);
if (pos < to) {
ranges.push({ from: pos, to });
total += to - pos;
}
return { total, ranges };
}
function findPosition({ total, ranges }, ratio) {
if (ratio <= 0)
return ranges[0].from;
if (ratio >= 1)
return ranges[ranges.length - 1].to;
let dist2 = Math.floor(total * ratio);
for (let i2 = 0; ; i2++) {
let { from, to } = ranges[i2], size = to - from;
if (dist2 <= size)
return from + dist2;
dist2 -= size;
}
}
function findFraction(structure, pos) {
let counted = 0;
for (let { from, to } of structure.ranges) {
if (pos <= to) {
counted += pos - from;
break;
}
counted += to - from;
}
return counted / structure.total;
}
function find(array, f) {
for (let val of array)
if (f(val))
return val;
return void 0;
}
const IdScaler = {
toDOM(n) {
return n;
},
fromDOM(n) {
return n;
},
scale: 1
};
class BigScaler {
constructor(oracle, heightMap, viewports) {
let vpHeight = 0, base2 = 0, domBase = 0;
this.viewports = viewports.map(({ from, to }) => {
let top2 = heightMap.lineAt(from, QueryType$1.ByPos, oracle, 0, 0).top;
let bottom = heightMap.lineAt(to, QueryType$1.ByPos, oracle, 0, 0).bottom;
vpHeight += bottom - top2;
return { from, to, top: top2, bottom, domTop: 0, domBottom: 0 };
});
this.scale = (7e6 - vpHeight) / (heightMap.height - vpHeight);
for (let obj of this.viewports) {
obj.domTop = domBase + (obj.top - base2) * this.scale;
domBase = obj.domBottom = obj.domTop + (obj.bottom - obj.top);
base2 = obj.bottom;
}
}
toDOM(n) {
for (let i2 = 0, base2 = 0, domBase = 0; ; i2++) {
let vp = i2 < this.viewports.length ? this.viewports[i2] : null;
if (!vp || n < vp.top)
return domBase + (n - base2) * this.scale;
if (n <= vp.bottom)
return vp.domTop + (n - vp.top);
base2 = vp.bottom;
domBase = vp.domBottom;
}
}
fromDOM(n) {
for (let i2 = 0, base2 = 0, domBase = 0; ; i2++) {
let vp = i2 < this.viewports.length ? this.viewports[i2] : null;
if (!vp || n < vp.domTop)
return base2 + (n - domBase) / this.scale;
if (n <= vp.domBottom)
return vp.top + (n - vp.domTop);
base2 = vp.bottom;
domBase = vp.domBottom;
}
}
}
function scaleBlock(block, scaler) {
if (scaler.scale == 1)
return block;
let bTop = scaler.toDOM(block.top), bBottom = scaler.toDOM(block.bottom);
return new BlockInfo(block.from, block.length, bTop, bBottom - bTop, Array.isArray(block._content) ? block._content.map((b) => scaleBlock(b, scaler)) : block._content);
}
const theme = /* @__PURE__ */ Facet.define({ combine: (strs) => strs.join(" ") });
const darkTheme = /* @__PURE__ */ Facet.define({ combine: (values) => values.indexOf(true) > -1 });
const baseThemeID = /* @__PURE__ */ StyleModule.newName(), baseLightID = /* @__PURE__ */ StyleModule.newName(), baseDarkID = /* @__PURE__ */ StyleModule.newName();
const lightDarkIDs = { "&light": "." + baseLightID, "&dark": "." + baseDarkID };
function buildTheme(main, spec, scopes) {
return new StyleModule(spec, {
finish(sel) {
return /&/.test(sel) ? sel.replace(/&\w*/, (m) => {
if (m == "&")
return main;
if (!scopes || !scopes[m])
throw new RangeError(`Unsupported selector: ${m}`);
return scopes[m];
}) : main + " " + sel;
}
});
}
const baseTheme$1$3 = /* @__PURE__ */ buildTheme("." + baseThemeID, {
"&": {
position: "relative !important",
boxSizing: "border-box",
"&.cm-focused": {
// Provide a simple default outline to make sure a focused
// editor is visually distinct. Can't leave the default behavior
// because that will apply to the content element, which is
// inside the scrollable container and doesn't include the
// gutters. We also can't use an 'auto' outline, since those
// are, for some reason, drawn behind the element content, which
// will cause things like the active line background to cover
// the outline (#297).
outline: "1px dotted #212121"
},
display: "flex !important",
flexDirection: "column"
},
".cm-scroller": {
display: "flex !important",
alignItems: "flex-start !important",
fontFamily: "monospace",
lineHeight: 1.4,
height: "100%",
overflowX: "auto",
position: "relative",
zIndex: 0
},
".cm-content": {
margin: 0,
flexGrow: 2,
flexShrink: 0,
display: "block",
whiteSpace: "pre",
wordWrap: "normal",
// https://github.com/codemirror/dev/issues/456
boxSizing: "border-box",
minHeight: "100%",
padding: "4px 0",
outline: "none",
"&[contenteditable=true]": {
WebkitUserModify: "read-write-plaintext-only"
}
},
".cm-lineWrapping": {
whiteSpace_fallback: "pre-wrap",
// For IE
whiteSpace: "break-spaces",
wordBreak: "break-word",
// For Safari, which doesn't support overflow-wrap: anywhere
overflowWrap: "anywhere",
flexShrink: 1
},
"&light .cm-content": { caretColor: "black" },
"&dark .cm-content": { caretColor: "white" },
".cm-line": {
display: "block",
padding: "0 2px 0 6px"
},
".cm-layer": {
position: "absolute",
left: 0,
top: 0,
contain: "size style",
"& > *": {
position: "absolute"
}
},
"&light .cm-selectionBackground": {
background: "#d9d9d9"
},
"&dark .cm-selectionBackground": {
background: "#222"
},
"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
background: "#d7d4f0"
},
"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
background: "#233"
},
".cm-cursorLayer": {
pointerEvents: "none"
},
"&.cm-focused > .cm-scroller > .cm-cursorLayer": {
animation: "steps(1) cm-blink 1.2s infinite"
},
// Two animations defined so that we can switch between them to
// restart the animation without forcing another style
// recomputation.
"@keyframes cm-blink": { "0%": {}, "50%": { opacity: 0 }, "100%": {} },
"@keyframes cm-blink2": { "0%": {}, "50%": { opacity: 0 }, "100%": {} },
".cm-cursor, .cm-dropCursor": {
borderLeft: "1.2px solid black",
marginLeft: "-0.6px",
pointerEvents: "none"
},
".cm-cursor": {
display: "none"
},
"&dark .cm-cursor": {
borderLeftColor: "#444"
},
".cm-dropCursor": {
position: "absolute"
},
"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor": {
display: "block"
},
".cm-iso": {
unicodeBidi: "isolate"
},
".cm-announced": {
position: "fixed",
top: "-10000px"
},
"@media print": {
".cm-announced": { display: "none" }
},
"&light .cm-activeLine": { backgroundColor: "#cceeff44" },
"&dark .cm-activeLine": { backgroundColor: "#99eeff33" },
"&light .cm-specialChar": { color: "red" },
"&dark .cm-specialChar": { color: "#f78" },
".cm-gutters": {
flexShrink: 0,
display: "flex",
height: "100%",
boxSizing: "border-box",
insetInlineStart: 0,
zIndex: 200
},
"&light .cm-gutters": {
backgroundColor: "#f5f5f5",
color: "#6c6c6c",
borderRight: "1px solid #ddd"
},
"&dark .cm-gutters": {
backgroundColor: "#333338",
color: "#ccc"
},
".cm-gutter": {
display: "flex !important",
// Necessary -- prevents margin collapsing
flexDirection: "column",
flexShrink: 0,
boxSizing: "border-box",
minHeight: "100%",
overflow: "hidden"
},
".cm-gutterElement": {
boxSizing: "border-box"
},
".cm-lineNumbers .cm-gutterElement": {
padding: "0 3px 0 5px",
minWidth: "20px",
textAlign: "right",
whiteSpace: "nowrap"
},
"&light .cm-activeLineGutter": {
backgroundColor: "#e2f2ff"
},
"&dark .cm-activeLineGutter": {
backgroundColor: "#222227"
},
".cm-panels": {
boxSizing: "border-box",
position: "sticky",
left: 0,
right: 0
},
"&light .cm-panels": {
backgroundColor: "#f5f5f5",
color: "black"
},
"&light .cm-panels-top": {
borderBottom: "1px solid #ddd"
},
"&light .cm-panels-bottom": {
borderTop: "1px solid #ddd"
},
"&dark .cm-panels": {
backgroundColor: "#333338",
color: "white"
},
".cm-tab": {
display: "inline-block",
overflow: "hidden",
verticalAlign: "bottom"
},
".cm-widgetBuffer": {
verticalAlign: "text-top",
height: "1em",
width: 0,
display: "inline"
},
".cm-placeholder": {
color: "#888",
display: "inline-block",
verticalAlign: "top"
},
".cm-highlightSpace:before": {
content: "attr(data-display)",
position: "absolute",
pointerEvents: "none",
color: "#888"
},
".cm-highlightTab": {
backgroundImage: `url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,
backgroundSize: "auto 100%",
backgroundPosition: "right 90%",
backgroundRepeat: "no-repeat"
},
".cm-trailingSpace": {
backgroundColor: "#ff332255"
},
".cm-button": {
verticalAlign: "middle",
color: "inherit",
fontSize: "70%",
padding: ".2em 1em",
borderRadius: "1px"
},
"&light .cm-button": {
backgroundImage: "linear-gradient(#eff1f5, #d9d9df)",
border: "1px solid #888",
"&:active": {
backgroundImage: "linear-gradient(#b4b4b4, #d0d3d6)"
}
},
"&dark .cm-button": {
backgroundImage: "linear-gradient(#393939, #111)",
border: "1px solid #888",
"&:active": {
backgroundImage: "linear-gradient(#111, #333)"
}
},
".cm-textfield": {
verticalAlign: "middle",
color: "inherit",
fontSize: "70%",
border: "1px solid silver",
padding: ".2em .5em"
},
"&light .cm-textfield": {
backgroundColor: "white"
},
"&dark .cm-textfield": {
border: "1px solid #555",
backgroundColor: "inherit"
}
}, lightDarkIDs);
const LineBreakPlaceholder = "";
class DOMReader {
constructor(points, state) {
this.points = points;
this.text = "";
this.lineSeparator = state.facet(EditorState.lineSeparator);
}
append(text) {
this.text += text;
}
lineBreak() {
this.text += LineBreakPlaceholder;
}
readRange(start, end) {
if (!start)
return this;
let parent = start.parentNode;
for (let cur2 = start; ; ) {
this.findPointBefore(parent, cur2);
let oldLen = this.text.length;
this.readNode(cur2);
let next = cur2.nextSibling;
if (next == end)
break;
let view = ContentView.get(cur2), nextView = ContentView.get(next);
if (view && nextView ? view.breakAfter : (view ? view.breakAfter : isBlockElement(cur2)) || isBlockElement(next) && (cur2.nodeName != "BR" || cur2.cmIgnore) && this.text.length > oldLen)
this.lineBreak();
cur2 = next;
}
this.findPointBefore(parent, end);
return this;
}
readTextNode(node) {
let text = node.nodeValue;
for (let point of this.points)
if (point.node == node)
point.pos = this.text.length + Math.min(point.offset, text.length);
for (let off = 0, re = this.lineSeparator ? null : /\r\n?|\n/g; ; ) {
let nextBreak = -1, breakSize = 1, m;
if (this.lineSeparator) {
nextBreak = text.indexOf(this.lineSeparator, off);
breakSize = this.lineSeparator.length;
} else if (m = re.exec(text)) {
nextBreak = m.index;
breakSize = m[0].length;
}
this.append(text.slice(off, nextBreak < 0 ? text.length : nextBreak));
if (nextBreak < 0)
break;
this.lineBreak();
if (breakSize > 1) {
for (let point of this.points)
if (point.node == node && point.pos > this.text.length)
point.pos -= breakSize - 1;
}
off = nextBreak + breakSize;
}
}
readNode(node) {
if (node.cmIgnore)
return;
let view = ContentView.get(node);
let fromView = view && view.overrideDOMText;
if (fromView != null) {
this.findPointInside(node, fromView.length);
for (let i2 = fromView.iter(); !i2.next().done; ) {
if (i2.lineBreak)
this.lineBreak();
else
this.append(i2.value);
}
} else if (node.nodeType == 3) {
this.readTextNode(node);
} else if (node.nodeName == "BR") {
if (node.nextSibling)
this.lineBreak();
} else if (node.nodeType == 1) {
this.readRange(node.firstChild, null);
}
}
findPointBefore(node, next) {
for (let point of this.points)
if (point.node == node && node.childNodes[point.offset] == next)
point.pos = this.text.length;
}
findPointInside(node, length) {
for (let point of this.points)
if (node.nodeType == 3 ? point.node == node : node.contains(point.node))
point.pos = this.text.length + (isAtEnd(node, point.node, point.offset) ? length : 0);
}
}
function isAtEnd(parent, node, offset) {
for (; ; ) {
if (!node || offset < maxOffset(node))
return false;
if (node == parent)
return true;
offset = domIndex(node) + 1;
node = node.parentNode;
}
}
function isBlockElement(node) {
return node.nodeType == 1 && /^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(node.nodeName);
}
class DOMPoint {
constructor(node, offset) {
this.node = node;
this.offset = offset;
this.pos = -1;
}
}
class DOMChange {
constructor(view, start, end, typeOver) {
this.typeOver = typeOver;
this.bounds = null;
this.text = "";
let { impreciseHead: iHead, impreciseAnchor: iAnchor } = view.docView;
if (view.state.readOnly && start > -1) {
this.newSel = null;
} else if (start > -1 && (this.bounds = view.docView.domBoundsAround(start, end, 0))) {
let selPoints = iHead || iAnchor ? [] : selectionPoints(view);
let reader = new DOMReader(selPoints, view.state);
reader.readRange(this.bounds.startDOM, this.bounds.endDOM);
this.text = reader.text;
this.newSel = selectionFromPoints(selPoints, this.bounds.from);
} else {
let domSel = view.observer.selectionRange;
let head = iHead && iHead.node == domSel.focusNode && iHead.offset == domSel.focusOffset || !contains(view.contentDOM, domSel.focusNode) ? view.state.selection.main.head : view.docView.posFromDOM(domSel.focusNode, domSel.focusOffset);
let anchor = iAnchor && iAnchor.node == domSel.anchorNode && iAnchor.offset == domSel.anchorOffset || !contains(view.contentDOM, domSel.anchorNode) ? view.state.selection.main.anchor : view.docView.posFromDOM(domSel.anchorNode, domSel.anchorOffset);
let vp = view.viewport;
if ((browser.ios || browser.chrome) && view.state.selection.main.empty && head != anchor && (vp.from > 0 || vp.to < view.state.doc.length)) {
let from = Math.min(head, anchor), to = Math.max(head, anchor);
let offFrom = vp.from - from, offTo = vp.to - to;
if ((offFrom == 0 || offFrom == 1 || from == 0) && (offTo == 0 || offTo == -1 || to == view.state.doc.length)) {
head = 0;
anchor = view.state.doc.length;
}
}
this.newSel = EditorSelection.single(anchor, head);
}
}
}
function applyDOMChange(view, domChange) {
let change;
let { newSel } = domChange, sel = view.state.selection.main;
let lastKey = view.inputState.lastKeyTime > Date.now() - 100 ? view.inputState.lastKeyCode : -1;
if (domChange.bounds) {
let { from, to } = domChange.bounds;
let preferredPos = sel.from, preferredSide = null;
if (lastKey === 8 || browser.android && domChange.text.length < to - from) {
preferredPos = sel.to;
preferredSide = "end";
}
let diff = findDiff(view.state.doc.sliceString(from, to, LineBreakPlaceholder), domChange.text, preferredPos - from, preferredSide);
if (diff) {
if (browser.chrome && lastKey == 13 && diff.toB == diff.from + 2 && domChange.text.slice(diff.from, diff.toB) == LineBreakPlaceholder + LineBreakPlaceholder)
diff.toB--;
change = {
from: from + diff.from,
to: from + diff.toA,
insert: Text.of(domChange.text.slice(diff.from, diff.toB).split(LineBreakPlaceholder))
};
}
} else if (newSel && (!view.hasFocus && view.state.facet(editable) || newSel.main.eq(sel))) {
newSel = null;
}
if (!change && !newSel)
return false;
if (!change && domChange.typeOver && !sel.empty && newSel && newSel.main.empty) {
change = { from: sel.from, to: sel.to, insert: view.state.doc.slice(sel.from, sel.to) };
} else if (change && change.from >= sel.from && change.to <= sel.to && (change.from != sel.from || change.to != sel.to) && sel.to - sel.from - (change.to - change.from) <= 4) {
change = {
from: sel.from,
to: sel.to,
insert: view.state.doc.slice(sel.from, change.from).append(change.insert).append(view.state.doc.slice(change.to, sel.to))
};
} else if ((browser.mac || browser.android) && change && change.from == change.to && change.from == sel.head - 1 && /^\. ?$/.test(change.insert.toString()) && view.contentDOM.getAttribute("autocorrect") == "off") {
if (newSel && change.insert.length == 2)
newSel = EditorSelection.single(newSel.main.anchor - 1, newSel.main.head - 1);
change = { from: sel.from, to: sel.to, insert: Text.of([" "]) };
} else if (browser.chrome && change && change.from == change.to && change.from == sel.head && change.insert.toString() == "\n " && view.lineWrapping) {
if (newSel)
newSel = EditorSelection.single(newSel.main.anchor - 1, newSel.main.head - 1);
change = { from: sel.from, to: sel.to, insert: Text.of([" "]) };
}
if (change) {
if (browser.ios && view.inputState.flushIOSKey())
return true;
if (browser.android && (change.from == sel.from && change.to == sel.to && change.insert.length == 1 && change.insert.lines == 2 && dispatchKey(view.contentDOM, "Enter", 13) || (change.from == sel.from - 1 && change.to == sel.to && change.insert.length == 0 || lastKey == 8 && change.insert.length < change.to - change.from && change.to > sel.head) && dispatchKey(view.contentDOM, "Backspace", 8) || change.from == sel.from && change.to == sel.to + 1 && change.insert.length == 0 && dispatchKey(view.contentDOM, "Delete", 46)))
return true;
let text = change.insert.toString();
if (view.inputState.composing >= 0)
view.inputState.composing++;
let defaultTr;
let defaultInsert = () => defaultTr || (defaultTr = applyDefaultInsert(view, change, newSel));
if (!view.state.facet(inputHandler$1).some((h2) => h2(view, change.from, change.to, text, defaultInsert)))
view.dispatch(defaultInsert());
return true;
} else if (newSel && !newSel.main.eq(sel)) {
let scrollIntoView2 = false, userEvent = "select";
if (view.inputState.lastSelectionTime > Date.now() - 50) {
if (view.inputState.lastSelectionOrigin == "select")
scrollIntoView2 = true;
userEvent = view.inputState.lastSelectionOrigin;
}
view.dispatch({ selection: newSel, scrollIntoView: scrollIntoView2, userEvent });
return true;
} else {
return false;
}
}
function applyDefaultInsert(view, change, newSel) {
let tr, startState = view.state, sel = startState.selection.main;
if (change.from >= sel.from && change.to <= sel.to && change.to - change.from >= (sel.to - sel.from) / 3 && (!newSel || newSel.main.empty && newSel.main.from == change.from + change.insert.length) && view.inputState.composing < 0) {
let before = sel.from < change.from ? startState.sliceDoc(sel.from, change.from) : "";
let after = sel.to > change.to ? startState.sliceDoc(change.to, sel.to) : "";
tr = startState.replaceSelection(view.state.toText(before + change.insert.sliceString(0, void 0, view.state.lineBreak) + after));
} else {
let changes = startState.changes(change);
let mainSel = newSel && newSel.main.to <= changes.newLength ? newSel.main : void 0;
if (startState.selection.ranges.length > 1 && view.inputState.composing >= 0 && change.to <= sel.to && change.to >= sel.to - 10) {
let replaced = view.state.sliceDoc(change.from, change.to);
let compositionRange, composition = newSel && findCompositionNode(view, newSel.main.head);
if (composition) {
let dLen = change.insert.length - (change.to - change.from);
compositionRange = { from: composition.from, to: composition.to - dLen };
} else {
compositionRange = view.state.doc.lineAt(sel.head);
}
let offset = sel.to - change.to, size = sel.to - sel.from;
tr = startState.changeByRange((range) => {
if (range.from == sel.from && range.to == sel.to)
return { changes, range: mainSel || range.map(changes) };
let to = range.to - offset, from = to - replaced.length;
if (range.to - range.from != size || view.state.sliceDoc(from, to) != replaced || // Unfortunately, there's no way to make multiple
// changes in the same node work without aborting
// composition, so cursors in the composition range are
// ignored.
range.to >= compositionRange.from && range.from <= compositionRange.to)
return { range };
let rangeChanges = startState.changes({ from, to, insert: change.insert }), selOff = range.to - sel.to;
return {
changes: rangeChanges,
range: !mainSel ? range.map(rangeChanges) : EditorSelection.range(Math.max(0, mainSel.anchor + selOff), Math.max(0, mainSel.head + selOff))
};
});
} else {
tr = {
changes,
selection: mainSel && startState.selection.replaceRange(mainSel)
};
}
}
let userEvent = "input.type";
if (view.composing || view.inputState.compositionPendingChange && view.inputState.compositionEndedAt > Date.now() - 50) {
view.inputState.compositionPendingChange = false;
userEvent += ".compose";
if (view.inputState.compositionFirstChange) {
userEvent += ".start";
view.inputState.compositionFirstChange = false;
}
}
return startState.update(tr, { userEvent, scrollIntoView: true });
}
function findDiff(a, b, preferredPos, preferredSide) {
let minLen = Math.min(a.length, b.length);
let from = 0;
while (from < minLen && a.charCodeAt(from) == b.charCodeAt(from))
from++;
if (from == minLen && a.length == b.length)
return null;
let toA = a.length, toB = b.length;
while (toA > 0 && toB > 0 && a.charCodeAt(toA - 1) == b.charCodeAt(toB - 1)) {
toA--;
toB--;
}
if (preferredSide == "end") {
let adjust = Math.max(0, from - Math.min(toA, toB));
preferredPos -= toA + adjust - from;
}
if (toA < from && a.length < b.length) {
let move = preferredPos <= from && preferredPos >= toA ? from - preferredPos : 0;
from -= move;
toB = from + (toB - toA);
toA = from;
} else if (toB < from) {
let move = preferredPos <= from && preferredPos >= toB ? from - preferredPos : 0;
from -= move;
toA = from + (toA - toB);
toB = from;
}
return { from, toA, toB };
}
function selectionPoints(view) {
let result2 = [];
if (view.root.activeElement != view.contentDOM)
return result2;
let { anchorNode, anchorOffset, focusNode, focusOffset } = view.observer.selectionRange;
if (anchorNode) {
result2.push(new DOMPoint(anchorNode, anchorOffset));
if (focusNode != anchorNode || focusOffset != anchorOffset)
result2.push(new DOMPoint(focusNode, focusOffset));
}
return result2;
}
function selectionFromPoints(points, base2) {
if (points.length == 0)
return null;
let anchor = points[0].pos, head = points.length == 2 ? points[1].pos : anchor;
return anchor > -1 && head > -1 ? EditorSelection.single(anchor + base2, head + base2) : null;
}
const observeOptions = {
childList: true,
characterData: true,
subtree: true,
attributes: true,
characterDataOldValue: true
};
const useCharData = browser.ie && browser.ie_version <= 11;
class DOMObserver {
constructor(view) {
this.view = view;
this.active = false;
this.selectionRange = new DOMSelectionState();
this.selectionChanged = false;
this.delayedFlush = -1;
this.resizeTimeout = -1;
this.queue = [];
this.delayedAndroidKey = null;
this.flushingAndroidKey = -1;
this.lastChange = 0;
this.scrollTargets = [];
this.intersection = null;
this.resizeScroll = null;
this.intersecting = false;
this.gapIntersection = null;
this.gaps = [];
this.parentCheck = -1;
this.dom = view.contentDOM;
this.observer = new MutationObserver((mutations) => {
for (let mut of mutations)
this.queue.push(mut);
if ((browser.ie && browser.ie_version <= 11 || browser.ios && view.composing) && mutations.some((m) => m.type == "childList" && m.removedNodes.length || m.type == "characterData" && m.oldValue.length > m.target.nodeValue.length))
this.flushSoon();
else
this.flush();
});
if (useCharData)
this.onCharData = (event) => {
this.queue.push({
target: event.target,
type: "characterData",
oldValue: event.prevValue
});
this.flushSoon();
};
this.onSelectionChange = this.onSelectionChange.bind(this);
this.onResize = this.onResize.bind(this);
this.onPrint = this.onPrint.bind(this);
this.onScroll = this.onScroll.bind(this);
if (typeof ResizeObserver == "function") {
this.resizeScroll = new ResizeObserver(() => {
var _a2;
if (((_a2 = this.view.docView) === null || _a2 === void 0 ? void 0 : _a2.lastUpdate) < Date.now() - 75)
this.onResize();
});
this.resizeScroll.observe(view.scrollDOM);
}
this.addWindowListeners(this.win = view.win);
this.start();
if (typeof IntersectionObserver == "function") {
this.intersection = new IntersectionObserver((entries) => {
if (this.parentCheck < 0)
this.parentCheck = setTimeout(this.listenForScroll.bind(this), 1e3);
if (entries.length > 0 && entries[entries.length - 1].intersectionRatio > 0 != this.intersecting) {
this.intersecting = !this.intersecting;
if (this.intersecting != this.view.inView)
this.onScrollChanged(document.createEvent("Event"));
}
}, { threshold: [0, 1e-3] });
this.intersection.observe(this.dom);
this.gapIntersection = new IntersectionObserver((entries) => {
if (entries.length > 0 && entries[entries.length - 1].intersectionRatio > 0)
this.onScrollChanged(document.createEvent("Event"));
}, {});
}
this.listenForScroll();
this.readSelectionRange();
}
onScrollChanged(e) {
this.view.inputState.runHandlers("scroll", e);
if (this.intersecting)
this.view.measure();
}
onScroll(e) {
if (this.intersecting)
this.flush(false);
this.onScrollChanged(e);
}
onResize() {
if (this.resizeTimeout < 0)
this.resizeTimeout = setTimeout(() => {
this.resizeTimeout = -1;
this.view.requestMeasure();
}, 50);
}
onPrint() {
this.view.viewState.printing = true;
this.view.measure();
setTimeout(() => {
this.view.viewState.printing = false;
this.view.requestMeasure();
}, 500);
}
updateGaps(gaps) {
if (this.gapIntersection && (gaps.length != this.gaps.length || this.gaps.some((g, i2) => g != gaps[i2]))) {
this.gapIntersection.disconnect();
for (let gap of gaps)
this.gapIntersection.observe(gap);
this.gaps = gaps;
}
}
onSelectionChange(event) {
let wasChanged = this.selectionChanged;
if (!this.readSelectionRange() || this.delayedAndroidKey)
return;
let { view } = this, sel = this.selectionRange;
if (view.state.facet(editable) ? view.root.activeElement != this.dom : !hasSelection(view.dom, sel))
return;
let context = sel.anchorNode && view.docView.nearest(sel.anchorNode);
if (context && context.ignoreEvent(event)) {
if (!wasChanged)
this.selectionChanged = false;
return;
}
if ((browser.ie && browser.ie_version <= 11 || browser.android && browser.chrome) && !view.state.selection.main.empty && // (Selection.isCollapsed isn't reliable on IE)
sel.focusNode && isEquivalentPosition(sel.focusNode, sel.focusOffset, sel.anchorNode, sel.anchorOffset))
this.flushSoon();
else
this.flush(false);
}
readSelectionRange() {
let { view } = this;
let range = browser.safari && view.root.nodeType == 11 && deepActiveElement(this.dom.ownerDocument) == this.dom && safariSelectionRangeHack(this.view) || getSelection(view.root);
if (!range || this.selectionRange.eq(range))
return false;
let local = hasSelection(this.dom, range);
if (local && !this.selectionChanged && view.inputState.lastFocusTime > Date.now() - 200 && view.inputState.lastTouchTime < Date.now() - 300 && atElementStart(this.dom, range)) {
this.view.inputState.lastFocusTime = 0;
view.docView.updateSelection();
return false;
}
this.selectionRange.setRange(range);
if (local)
this.selectionChanged = true;
return true;
}
setSelectionRange(anchor, head) {
this.selectionRange.set(anchor.node, anchor.offset, head.node, head.offset);
this.selectionChanged = false;
}
clearSelectionRange() {
this.selectionRange.set(null, 0, null, 0);
}
listenForScroll() {
this.parentCheck = -1;
let i2 = 0, changed = null;
for (let dom = this.dom; dom; ) {
if (dom.nodeType == 1) {
if (!changed && i2 < this.scrollTargets.length && this.scrollTargets[i2] == dom)
i2++;
else if (!changed)
changed = this.scrollTargets.slice(0, i2);
if (changed)
changed.push(dom);
dom = dom.assignedSlot || dom.parentNode;
} else if (dom.nodeType == 11) {
dom = dom.host;
} else {
break;
}
}
if (i2 < this.scrollTargets.length && !changed)
changed = this.scrollTargets.slice(0, i2);
if (changed) {
for (let dom of this.scrollTargets)
dom.removeEventListener("scroll", this.onScroll);
for (let dom of this.scrollTargets = changed)
dom.addEventListener("scroll", this.onScroll);
}
}
ignore(f) {
if (!this.active)
return f();
try {
this.stop();
return f();
} finally {
this.start();
this.clear();
}
}
start() {
if (this.active)
return;
this.observer.observe(this.dom, observeOptions);
if (useCharData)
this.dom.addEventListener("DOMCharacterDataModified", this.onCharData);
this.active = true;
}
stop() {
if (!this.active)
return;
this.active = false;
this.observer.disconnect();
if (useCharData)
this.dom.removeEventListener("DOMCharacterDataModified", this.onCharData);
}
// Throw away any pending changes
clear() {
this.processRecords();
this.queue.length = 0;
this.selectionChanged = false;
}
// Chrome Android, especially in combination with GBoard, not only
// doesn't reliably fire regular key events, but also often
// surrounds the effect of enter or backspace with a bunch of
// composition events that, when interrupted, cause text duplication
// or other kinds of corruption. This hack makes the editor back off
// from handling DOM changes for a moment when such a key is
// detected (via beforeinput or keydown), and then tries to flush
// them or, if that has no effect, dispatches the given key.
delayAndroidKey(key, keyCode) {
var _a2;
if (!this.delayedAndroidKey) {
let flush = () => {
let key2 = this.delayedAndroidKey;
if (key2) {
this.clearDelayedAndroidKey();
this.view.inputState.lastKeyCode = key2.keyCode;
this.view.inputState.lastKeyTime = Date.now();
let flushed = this.flush();
if (!flushed && key2.force)
dispatchKey(this.dom, key2.key, key2.keyCode);
}
};
this.flushingAndroidKey = this.view.win.requestAnimationFrame(flush);
}
if (!this.delayedAndroidKey || key == "Enter")
this.delayedAndroidKey = {
key,
keyCode,
// Only run the key handler when no changes are detected if
// this isn't coming right after another change, in which case
// it is probably part of a weird chain of updates, and should
// be ignored if it returns the DOM to its previous state.
force: this.lastChange < Date.now() - 50 || !!((_a2 = this.delayedAndroidKey) === null || _a2 === void 0 ? void 0 : _a2.force)
};
}
clearDelayedAndroidKey() {
this.win.cancelAnimationFrame(this.flushingAndroidKey);
this.delayedAndroidKey = null;
this.flushingAndroidKey = -1;
}
flushSoon() {
if (this.delayedFlush < 0)
this.delayedFlush = this.view.win.requestAnimationFrame(() => {
this.delayedFlush = -1;
this.flush();
});
}
forceFlush() {
if (this.delayedFlush >= 0) {
this.view.win.cancelAnimationFrame(this.delayedFlush);
this.delayedFlush = -1;
}
this.flush();
}
pendingRecords() {
for (let mut of this.observer.takeRecords())
this.queue.push(mut);
return this.queue;
}
processRecords() {
let records = this.pendingRecords();
if (records.length)
this.queue = [];
let from = -1, to = -1, typeOver = false;
for (let record of records) {
let range = this.readMutation(record);
if (!range)
continue;
if (range.typeOver)
typeOver = true;
if (from == -1) {
({ from, to } = range);
} else {
from = Math.min(range.from, from);
to = Math.max(range.to, to);
}
}
return { from, to, typeOver };
}
readChange() {
let { from, to, typeOver } = this.processRecords();
let newSel = this.selectionChanged && hasSelection(this.dom, this.selectionRange);
if (from < 0 && !newSel)
return null;
if (from > -1)
this.lastChange = Date.now();
this.view.inputState.lastFocusTime = 0;
this.selectionChanged = false;
let change = new DOMChange(this.view, from, to, typeOver);
this.view.docView.domChanged = { newSel: change.newSel ? change.newSel.main : null };
return change;
}
// Apply pending changes, if any
flush(readSelection = true) {
if (this.delayedFlush >= 0 || this.delayedAndroidKey)
return false;
if (readSelection)
this.readSelectionRange();
let domChange = this.readChange();
if (!domChange) {
this.view.requestMeasure();
return false;
}
let startState = this.view.state;
let handled = applyDOMChange(this.view, domChange);
if (this.view.state == startState)
this.view.update([]);
return handled;
}
readMutation(rec) {
let cView = this.view.docView.nearest(rec.target);
if (!cView || cView.ignoreMutation(rec))
return null;
cView.markDirty(rec.type == "attributes");
if (rec.type == "attributes")
cView.flags |= 4;
if (rec.type == "childList") {
let childBefore = findChild(cView, rec.previousSibling || rec.target.previousSibling, -1);
let childAfter = findChild(cView, rec.nextSibling || rec.target.nextSibling, 1);
return {
from: childBefore ? cView.posAfter(childBefore) : cView.posAtStart,
to: childAfter ? cView.posBefore(childAfter) : cView.posAtEnd,
typeOver: false
};
} else if (rec.type == "characterData") {
return { from: cView.posAtStart, to: cView.posAtEnd, typeOver: rec.target.nodeValue == rec.oldValue };
} else {
return null;
}
}
setWindow(win) {
if (win != this.win) {
this.removeWindowListeners(this.win);
this.win = win;
this.addWindowListeners(this.win);
}
}
addWindowListeners(win) {
win.addEventListener("resize", this.onResize);
win.addEventListener("beforeprint", this.onPrint);
win.addEventListener("scroll", this.onScroll);
win.document.addEventListener("selectionchange", this.onSelectionChange);
}
removeWindowListeners(win) {
win.removeEventListener("scroll", this.onScroll);
win.removeEventListener("resize", this.onResize);
win.removeEventListener("beforeprint", this.onPrint);
win.document.removeEventListener("selectionchange", this.onSelectionChange);
}
destroy() {
var _a2, _b, _c;
this.stop();
(_a2 = this.intersection) === null || _a2 === void 0 ? void 0 : _a2.disconnect();
(_b = this.gapIntersection) === null || _b === void 0 ? void 0 : _b.disconnect();
(_c = this.resizeScroll) === null || _c === void 0 ? void 0 : _c.disconnect();
for (let dom of this.scrollTargets)
dom.removeEventListener("scroll", this.onScroll);
this.removeWindowListeners(this.win);
clearTimeout(this.parentCheck);
clearTimeout(this.resizeTimeout);
this.win.cancelAnimationFrame(this.delayedFlush);
this.win.cancelAnimationFrame(this.flushingAndroidKey);
}
}
function findChild(cView, dom, dir) {
while (dom) {
let curView = ContentView.get(dom);
if (curView && curView.parent == cView)
return curView;
let parent = dom.parentNode;
dom = parent != cView.dom ? parent : dir > 0 ? dom.nextSibling : dom.previousSibling;
}
return null;
}
function safariSelectionRangeHack(view) {
let found = null;
function read(event) {
event.preventDefault();
event.stopImmediatePropagation();
found = event.getTargetRanges()[0];
}
view.contentDOM.addEventListener("beforeinput", read, true);
view.dom.ownerDocument.execCommand("indent");
view.contentDOM.removeEventListener("beforeinput", read, true);
if (!found)
return null;
let anchorNode = found.startContainer, anchorOffset = found.startOffset;
let focusNode = found.endContainer, focusOffset = found.endOffset;
let curAnchor = view.docView.domAtPos(view.state.selection.main.anchor);
if (isEquivalentPosition(curAnchor.node, curAnchor.offset, focusNode, focusOffset))
[anchorNode, anchorOffset, focusNode, focusOffset] = [focusNode, focusOffset, anchorNode, anchorOffset];
return { anchorNode, anchorOffset, focusNode, focusOffset };
}
class EditorView {
/**
The current editor state.
*/
get state() {
return this.viewState.state;
}
/**
To be able to display large documents without consuming too much
memory or overloading the browser, CodeMirror only draws the
code that is visible (plus a margin around it) to the DOM. This
property tells you the extent of the current drawn viewport, in
document positions.
*/
get viewport() {
return this.viewState.viewport;
}
/**
When there are, for example, large collapsed ranges in the
viewport, its size can be a lot bigger than the actual visible
content. Thus, if you are doing something like styling the
content in the viewport, it is preferable to only do so for
these ranges, which are the subset of the viewport that is
actually drawn.
*/
get visibleRanges() {
return this.viewState.visibleRanges;
}
/**
Returns false when the editor is entirely scrolled out of view
or otherwise hidden.
*/
get inView() {
return this.viewState.inView;
}
/**
Indicates whether the user is currently composing text via
[IME](https://en.wikipedia.org/wiki/Input_method), and at least
one change has been made in the current composition.
*/
get composing() {
return this.inputState.composing > 0;
}
/**
Indicates whether the user is currently in composing state. Note
that on some platforms, like Android, this will be the case a
lot, since just putting the cursor on a word starts a
composition there.
*/
get compositionStarted() {
return this.inputState.composing >= 0;
}
/**
The document or shadow root that the view lives in.
*/
get root() {
return this._root;
}
/**
@internal
*/
get win() {
return this.dom.ownerDocument.defaultView || window;
}
/**
Construct a new view. You'll want to either provide a `parent`
option, or put `view.dom` into your document after creating a
view, so that the user can see the editor.
*/
constructor(config2 = {}) {
this.plugins = [];
this.pluginMap = /* @__PURE__ */ new Map();
this.editorAttrs = {};
this.contentAttrs = {};
this.bidiCache = [];
this.destroyed = false;
this.updateState = 2;
this.measureScheduled = -1;
this.measureRequests = [];
this.contentDOM = document.createElement("div");
this.scrollDOM = document.createElement("div");
this.scrollDOM.tabIndex = -1;
this.scrollDOM.className = "cm-scroller";
this.scrollDOM.appendChild(this.contentDOM);
this.announceDOM = document.createElement("div");
this.announceDOM.className = "cm-announced";
this.announceDOM.setAttribute("aria-live", "polite");
this.dom = document.createElement("div");
this.dom.appendChild(this.announceDOM);
this.dom.appendChild(this.scrollDOM);
if (config2.parent)
config2.parent.appendChild(this.dom);
let { dispatch } = config2;
this.dispatchTransactions = config2.dispatchTransactions || dispatch && ((trs) => trs.forEach((tr) => dispatch(tr, this))) || ((trs) => this.update(trs));
this.dispatch = this.dispatch.bind(this);
this._root = config2.root || getRoot(config2.parent) || document;
this.viewState = new ViewState(config2.state || EditorState.create(config2));
if (config2.scrollTo && config2.scrollTo.is(scrollIntoView$1))
this.viewState.scrollTarget = config2.scrollTo.value.clip(this.viewState.state);
this.plugins = this.state.facet(viewPlugin).map((spec) => new PluginInstance(spec));
for (let plugin of this.plugins)
plugin.update(this);
this.observer = new DOMObserver(this);
this.inputState = new InputState(this);
this.inputState.ensureHandlers(this.plugins);
this.docView = new DocView(this);
this.mountStyles();
this.updateAttrs();
this.updateState = 0;
this.requestMeasure();
}
dispatch(...input) {
let trs = input.length == 1 && input[0] instanceof Transaction ? input : input.length == 1 && Array.isArray(input[0]) ? input[0] : [this.state.update(...input)];
this.dispatchTransactions(trs, this);
}
/**
Update the view for the given array of transactions. This will
update the visible document and selection to match the state
produced by the transactions, and notify view plugins of the
change. You should usually call
[`dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch) instead, which uses this
as a primitive.
*/
update(transactions) {
if (this.updateState != 0)
throw new Error("Calls to EditorView.update are not allowed while an update is in progress");
let redrawn = false, attrsChanged = false, update;
let state = this.state;
for (let tr of transactions) {
if (tr.startState != state)
throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");
state = tr.state;
}
if (this.destroyed) {
this.viewState.state = state;
return;
}
let focus = this.hasFocus, focusFlag = 0, dispatchFocus = null;
if (transactions.some((tr) => tr.annotation(isFocusChange))) {
this.inputState.notifiedFocused = focus;
focusFlag = 1;
} else if (focus != this.inputState.notifiedFocused) {
this.inputState.notifiedFocused = focus;
dispatchFocus = focusChangeTransaction(state, focus);
if (!dispatchFocus)
focusFlag = 1;
}
let pendingKey = this.observer.delayedAndroidKey, domChange = null;
if (pendingKey) {
this.observer.clearDelayedAndroidKey();
domChange = this.observer.readChange();
if (domChange && !this.state.doc.eq(state.doc) || !this.state.selection.eq(state.selection))
domChange = null;
} else {
this.observer.clear();
}
if (state.facet(EditorState.phrases) != this.state.facet(EditorState.phrases))
return this.setState(state);
update = ViewUpdate.create(this, state, transactions);
update.flags |= focusFlag;
let scrollTarget = this.viewState.scrollTarget;
try {
this.updateState = 2;
for (let tr of transactions) {
if (scrollTarget)
scrollTarget = scrollTarget.map(tr.changes);
if (tr.scrollIntoView) {
let { main } = tr.state.selection;
scrollTarget = new ScrollTarget(main.empty ? main : EditorSelection.cursor(main.head, main.head > main.anchor ? -1 : 1));
}
for (let e of tr.effects)
if (e.is(scrollIntoView$1))
scrollTarget = e.value.clip(this.state);
}
this.viewState.update(update, scrollTarget);
this.bidiCache = CachedOrder.update(this.bidiCache, update.changes);
if (!update.empty) {
this.updatePlugins(update);
this.inputState.update(update);
}
redrawn = this.docView.update(update);
if (this.state.facet(styleModule) != this.styleModules)
this.mountStyles();
attrsChanged = this.updateAttrs();
this.showAnnouncements(transactions);
this.docView.updateSelection(redrawn, transactions.some((tr) => tr.isUserEvent("select.pointer")));
} finally {
this.updateState = 0;
}
if (update.startState.facet(theme) != update.state.facet(theme))
this.viewState.mustMeasureContent = true;
if (redrawn || attrsChanged || scrollTarget || this.viewState.mustEnforceCursorAssoc || this.viewState.mustMeasureContent)
this.requestMeasure();
if (!update.empty)
for (let listener of this.state.facet(updateListener)) {
try {
listener(update);
} catch (e) {
logException(this.state, e, "update listener");
}
}
if (dispatchFocus || domChange)
Promise.resolve().then(() => {
if (dispatchFocus && this.state == dispatchFocus.startState)
this.dispatch(dispatchFocus);
if (domChange) {
if (!applyDOMChange(this, domChange) && pendingKey.force)
dispatchKey(this.contentDOM, pendingKey.key, pendingKey.keyCode);
}
});
}
/**
Reset the view to the given state. (This will cause the entire
document to be redrawn and all view plugins to be reinitialized,
so you should probably only use it when the new state isn't
derived from the old state. Otherwise, use
[`dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch) instead.)
*/
setState(newState) {
if (this.updateState != 0)
throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");
if (this.destroyed) {
this.viewState.state = newState;
return;
}
this.updateState = 2;
let hadFocus = this.hasFocus;
try {
for (let plugin of this.plugins)
plugin.destroy(this);
this.viewState = new ViewState(newState);
this.plugins = newState.facet(viewPlugin).map((spec) => new PluginInstance(spec));
this.pluginMap.clear();
for (let plugin of this.plugins)
plugin.update(this);
this.docView.destroy();
this.docView = new DocView(this);
this.inputState.ensureHandlers(this.plugins);
this.mountStyles();
this.updateAttrs();
this.bidiCache = [];
} finally {
this.updateState = 0;
}
if (hadFocus)
this.focus();
this.requestMeasure();
}
updatePlugins(update) {
let prevSpecs = update.startState.facet(viewPlugin), specs = update.state.facet(viewPlugin);
if (prevSpecs != specs) {
let newPlugins = [];
for (let spec of specs) {
let found = prevSpecs.indexOf(spec);
if (found < 0) {
newPlugins.push(new PluginInstance(spec));
} else {
let plugin = this.plugins[found];
plugin.mustUpdate = update;
newPlugins.push(plugin);
}
}
for (let plugin of this.plugins)
if (plugin.mustUpdate != update)
plugin.destroy(this);
this.plugins = newPlugins;
this.pluginMap.clear();
} else {
for (let p of this.plugins)
p.mustUpdate = update;
}
for (let i2 = 0; i2 < this.plugins.length; i2++)
this.plugins[i2].update(this);
if (prevSpecs != specs)
this.inputState.ensureHandlers(this.plugins);
}
/**
@internal
*/
measure(flush = true) {
if (this.destroyed)
return;
if (this.measureScheduled > -1)
this.win.cancelAnimationFrame(this.measureScheduled);
if (this.observer.delayedAndroidKey) {
this.measureScheduled = -1;
this.requestMeasure();
return;
}
this.measureScheduled = 0;
if (flush)
this.observer.forceFlush();
let updated = null;
let sDOM = this.scrollDOM, scrollTop = sDOM.scrollTop * this.scaleY;
let { scrollAnchorPos, scrollAnchorHeight } = this.viewState;
if (Math.abs(scrollTop - this.viewState.scrollTop) > 1)
scrollAnchorHeight = -1;
this.viewState.scrollAnchorHeight = -1;
try {
for (let i2 = 0; ; i2++) {
if (scrollAnchorHeight < 0) {
if (isScrolledToBottom(sDOM)) {
scrollAnchorPos = -1;
scrollAnchorHeight = this.viewState.heightMap.height;
} else {
let block = this.viewState.scrollAnchorAt(scrollTop);
scrollAnchorPos = block.from;
scrollAnchorHeight = block.top;
}
}
this.updateState = 1;
let changed = this.viewState.measure(this);
if (!changed && !this.measureRequests.length && this.viewState.scrollTarget == null)
break;
if (i2 > 5) {
console.warn(this.measureRequests.length ? "Measure loop restarted more than 5 times" : "Viewport failed to stabilize");
break;
}
let measuring = [];
if (!(changed & 4))
[this.measureRequests, measuring] = [measuring, this.measureRequests];
let measured = measuring.map((m) => {
try {
return m.read(this);
} catch (e) {
logException(this.state, e);
return BadMeasure;
}
});
let update = ViewUpdate.create(this, this.state, []), redrawn = false;
update.flags |= changed;
if (!updated)
updated = update;
else
updated.flags |= changed;
this.updateState = 2;
if (!update.empty) {
this.updatePlugins(update);
this.inputState.update(update);
this.updateAttrs();
redrawn = this.docView.update(update);
}
for (let i3 = 0; i3 < measuring.length; i3++)
if (measured[i3] != BadMeasure) {
try {
let m = measuring[i3];
if (m.write)
m.write(measured[i3], this);
} catch (e) {
logException(this.state, e);
}
}
if (redrawn)
this.docView.updateSelection(true);
if (!update.viewportChanged && this.measureRequests.length == 0) {
if (this.viewState.editorHeight) {
if (this.viewState.scrollTarget) {
this.docView.scrollIntoView(this.viewState.scrollTarget);
this.viewState.scrollTarget = null;
scrollAnchorHeight = -1;
continue;
} else {
let newAnchorHeight = scrollAnchorPos < 0 ? this.viewState.heightMap.height : this.viewState.lineBlockAt(scrollAnchorPos).top;
let diff = newAnchorHeight - scrollAnchorHeight;
if (diff > 1 || diff < -1) {
scrollTop = scrollTop + diff;
sDOM.scrollTop = scrollTop / this.scaleY;
scrollAnchorHeight = -1;
continue;
}
}
}
break;
}
}
} finally {
this.updateState = 0;
this.measureScheduled = -1;
}
if (updated && !updated.empty)
for (let listener of this.state.facet(updateListener))
listener(updated);
}
/**
Get the CSS classes for the currently active editor themes.
*/
get themeClasses() {
return baseThemeID + " " + (this.state.facet(darkTheme) ? baseDarkID : baseLightID) + " " + this.state.facet(theme);
}
updateAttrs() {
let editorAttrs = attrsFromFacet(this, editorAttributes, {
class: "cm-editor" + (this.hasFocus ? " cm-focused " : " ") + this.themeClasses
});
let contentAttrs = {
spellcheck: "false",
autocorrect: "off",
autocapitalize: "off",
translate: "no",
contenteditable: !this.state.facet(editable) ? "false" : "true",
class: "cm-content",
style: `${browser.tabSize}: ${this.state.tabSize}`,
role: "textbox",
"aria-multiline": "true"
};
if (this.state.readOnly)
contentAttrs["aria-readonly"] = "true";
attrsFromFacet(this, contentAttributes, contentAttrs);
let changed = this.observer.ignore(() => {
let changedContent = updateAttrs(this.contentDOM, this.contentAttrs, contentAttrs);
let changedEditor = updateAttrs(this.dom, this.editorAttrs, editorAttrs);
return changedContent || changedEditor;
});
this.editorAttrs = editorAttrs;
this.contentAttrs = contentAttrs;
return changed;
}
showAnnouncements(trs) {
let first = true;
for (let tr of trs)
for (let effect of tr.effects)
if (effect.is(EditorView.announce)) {
if (first)
this.announceDOM.textContent = "";
first = false;
let div = this.announceDOM.appendChild(document.createElement("div"));
div.textContent = effect.value;
}
}
mountStyles() {
this.styleModules = this.state.facet(styleModule);
let nonce = this.state.facet(EditorView.cspNonce);
StyleModule.mount(this.root, this.styleModules.concat(baseTheme$1$3).reverse(), nonce ? { nonce } : void 0);
}
readMeasured() {
if (this.updateState == 2)
throw new Error("Reading the editor layout isn't allowed during an update");
if (this.updateState == 0 && this.measureScheduled > -1)
this.measure(false);
}
/**
Schedule a layout measurement, optionally providing callbacks to
do custom DOM measuring followed by a DOM write phase. Using
this is preferable reading DOM layout directly from, for
example, an event handler, because it'll make sure measuring and
drawing done by other components is synchronized, avoiding
unnecessary DOM layout computations.
*/
requestMeasure(request) {
if (this.measureScheduled < 0)
this.measureScheduled = this.win.requestAnimationFrame(() => this.measure());
if (request) {
if (this.measureRequests.indexOf(request) > -1)
return;
if (request.key != null)
for (let i2 = 0; i2 < this.measureRequests.length; i2++) {
if (this.measureRequests[i2].key === request.key) {
this.measureRequests[i2] = request;
return;
}
}
this.measureRequests.push(request);
}
}
/**
Get the value of a specific plugin, if present. Note that
plugins that crash can be dropped from a view, so even when you
know you registered a given plugin, it is recommended to check
the return value of this method.
*/
plugin(plugin) {
let known = this.pluginMap.get(plugin);
if (known === void 0 || known && known.spec != plugin)
this.pluginMap.set(plugin, known = this.plugins.find((p) => p.spec == plugin) || null);
return known && known.update(this).value;
}
/**
The top position of the document, in screen coordinates. This
may be negative when the editor is scrolled down. Points
directly to the top of the first line, not above the padding.
*/
get documentTop() {
return this.contentDOM.getBoundingClientRect().top + this.viewState.paddingTop;
}
/**
Reports the padding above and below the document.
*/
get documentPadding() {
return { top: this.viewState.paddingTop, bottom: this.viewState.paddingBottom };
}
/**
If the editor is transformed with CSS, this provides the scale
along the X axis. Otherwise, it will just be 1. Note that
transforms other than translation and scaling are not supported.
*/
get scaleX() {
return this.viewState.scaleX;
}
/**
Provide the CSS transformed scale along the Y axis.
*/
get scaleY() {
return this.viewState.scaleY;
}
/**
Find the text line or block widget at the given vertical
position (which is interpreted as relative to the [top of the
document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop)).
*/
elementAtHeight(height) {
this.readMeasured();
return this.viewState.elementAtHeight(height);
}
/**
Find the line block (see
[`lineBlockAt`](https://codemirror.net/6/docs/ref/#view.EditorView.lineBlockAt) at the given
height, again interpreted relative to the [top of the
document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop).
*/
lineBlockAtHeight(height) {
this.readMeasured();
return this.viewState.lineBlockAtHeight(height);
}
/**
Get the extent and vertical position of all [line
blocks](https://codemirror.net/6/docs/ref/#view.EditorView.lineBlockAt) in the viewport. Positions
are relative to the [top of the
document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop);
*/
get viewportLineBlocks() {
return this.viewState.viewportLines;
}
/**
Find the line block around the given document position. A line
block is a range delimited on both sides by either a
non-[hidden](https://codemirror.net/6/docs/ref/#view.Decoration^replace) line breaks, or the
start/end of the document. It will usually just hold a line of
text, but may be broken into multiple textblocks by block
widgets.
*/
lineBlockAt(pos) {
return this.viewState.lineBlockAt(pos);
}
/**
The editor's total content height.
*/
get contentHeight() {
return this.viewState.contentHeight;
}
/**
Move a cursor position by [grapheme
cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak). `forward` determines whether
the motion is away from the line start, or towards it. In
bidirectional text, the line is traversed in visual order, using
the editor's [text direction](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection).
When the start position was the last one on the line, the
returned position will be across the line break. If there is no
further line, the original position is returned.
By default, this method moves over a single cluster. The
optional `by` argument can be used to move across more. It will
be called with the first cluster as argument, and should return
a predicate that determines, for each subsequent cluster,
whether it should also be moved over.
*/
moveByChar(start, forward, by) {
return skipAtoms(this, start, moveByChar(this, start, forward, by));
}
/**
Move a cursor position across the next group of either
[letters](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) or non-letter
non-whitespace characters.
*/
moveByGroup(start, forward) {
return skipAtoms(this, start, moveByChar(this, start, forward, (initial) => byGroup(this, start.head, initial)));
}
/**
Get the cursor position visually at the start or end of a line.
Note that this may differ from the _logical_ position at its
start or end (which is simply at `line.from`/`line.to`) if text
at the start or end goes against the line's base text direction.
*/
visualLineSide(line, end) {
let order = this.bidiSpans(line), dir = this.textDirectionAt(line.from);
let span = order[end ? order.length - 1 : 0];
return EditorSelection.cursor(span.side(end, dir) + line.from, span.forward(!end, dir) ? 1 : -1);
}
/**
Move to the next line boundary in the given direction. If
`includeWrap` is true, line wrapping is on, and there is a
further wrap point on the current line, the wrap point will be
returned. Otherwise this function will return the start or end
of the line.
*/
moveToLineBoundary(start, forward, includeWrap = true) {
return moveToLineBoundary(this, start, forward, includeWrap);
}
/**
Move a cursor position vertically. When `distance` isn't given,
it defaults to moving to the next line (including wrapped
lines). Otherwise, `distance` should provide a positive distance
in pixels.
When `start` has a
[`goalColumn`](https://codemirror.net/6/docs/ref/#state.SelectionRange.goalColumn), the vertical
motion will use that as a target horizontal position. Otherwise,
the cursor's own horizontal position is used. The returned
cursor will have its goal column set to whichever column was
used.
*/
moveVertically(start, forward, distance) {
return skipAtoms(this, start, moveVertically(this, start, forward, distance));
}
/**
Find the DOM parent node and offset (child offset if `node` is
an element, character offset when it is a text node) at the
given document position.
Note that for positions that aren't currently in
`visibleRanges`, the resulting DOM position isn't necessarily
meaningful (it may just point before or after a placeholder
element).
*/
domAtPos(pos) {
return this.docView.domAtPos(pos);
}
/**
Find the document position at the given DOM node. Can be useful
for associating positions with DOM events. Will raise an error
when `node` isn't part of the editor content.
*/
posAtDOM(node, offset = 0) {
return this.docView.posFromDOM(node, offset);
}
posAtCoords(coords, precise = true) {
this.readMeasured();
return posAtCoords(this, coords, precise);
}
/**
Get the screen coordinates at the given document position.
`side` determines whether the coordinates are based on the
element before (-1) or after (1) the position (if no element is
available on the given side, the method will transparently use
another strategy to get reasonable coordinates).
*/
coordsAtPos(pos, side = 1) {
this.readMeasured();
let rect = this.docView.coordsAt(pos, side);
if (!rect || rect.left == rect.right)
return rect;
let line = this.state.doc.lineAt(pos), order = this.bidiSpans(line);
let span = order[BidiSpan.find(order, pos - line.from, -1, side)];
return flattenRect(rect, span.dir == Direction.LTR == side > 0);
}
/**
Return the rectangle around a given character. If `pos` does not
point in front of a character that is in the viewport and
rendered (i.e. not replaced, not a line break), this will return
null. For space characters that are a line wrap point, this will
return the position before the line break.
*/
coordsForChar(pos) {
this.readMeasured();
return this.docView.coordsForChar(pos);
}
/**
The default width of a character in the editor. May not
accurately reflect the width of all characters (given variable
width fonts or styling of invididual ranges).
*/
get defaultCharacterWidth() {
return this.viewState.heightOracle.charWidth;
}
/**
The default height of a line in the editor. May not be accurate
for all lines.
*/
get defaultLineHeight() {
return this.viewState.heightOracle.lineHeight;
}
/**
The text direction
([`direction`](https://developer.mozilla.org/en-US/docs/Web/CSS/direction)
CSS property) of the editor's content element.
*/
get textDirection() {
return this.viewState.defaultTextDirection;
}
/**
Find the text direction of the block at the given position, as
assigned by CSS. If
[`perLineTextDirection`](https://codemirror.net/6/docs/ref/#view.EditorView^perLineTextDirection)
isn't enabled, or the given position is outside of the viewport,
this will always return the same as
[`textDirection`](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection). Note that
this may trigger a DOM layout.
*/
textDirectionAt(pos) {
let perLine = this.state.facet(perLineTextDirection);
if (!perLine || pos < this.viewport.from || pos > this.viewport.to)
return this.textDirection;
this.readMeasured();
return this.docView.textDirectionAt(pos);
}
/**
Whether this editor [wraps lines](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping)
(as determined by the
[`white-space`](https://developer.mozilla.org/en-US/docs/Web/CSS/white-space)
CSS property of its content element).
*/
get lineWrapping() {
return this.viewState.heightOracle.lineWrapping;
}
/**
Returns the bidirectional text structure of the given line
(which should be in the current document) as an array of span
objects. The order of these spans matches the [text
direction](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection)—if that is
left-to-right, the leftmost spans come first, otherwise the
rightmost spans come first.
*/
bidiSpans(line) {
if (line.length > MaxBidiLine)
return trivialOrder(line.length);
let dir = this.textDirectionAt(line.from), isolates;
for (let entry of this.bidiCache) {
if (entry.from == line.from && entry.dir == dir && (entry.fresh || isolatesEq(entry.isolates, isolates = getIsolatedRanges(this, line))))
return entry.order;
}
if (!isolates)
isolates = getIsolatedRanges(this, line);
let order = computeOrder(line.text, dir, isolates);
this.bidiCache.push(new CachedOrder(line.from, line.to, dir, isolates, true, order));
return order;
}
/**
Check whether the editor has focus.
*/
get hasFocus() {
var _a2;
return (this.dom.ownerDocument.hasFocus() || browser.safari && ((_a2 = this.inputState) === null || _a2 === void 0 ? void 0 : _a2.lastContextMenu) > Date.now() - 3e4) && this.root.activeElement == this.contentDOM;
}
/**
Put focus on the editor.
*/
focus() {
this.observer.ignore(() => {
focusPreventScroll(this.contentDOM);
this.docView.updateSelection();
});
}
/**
Update the [root](https://codemirror.net/6/docs/ref/##view.EditorViewConfig.root) in which the editor lives. This is only
necessary when moving the editor's existing DOM to a new window or shadow root.
*/
setRoot(root) {
if (this._root != root) {
this._root = root;
this.observer.setWindow((root.nodeType == 9 ? root : root.ownerDocument).defaultView || window);
this.mountStyles();
}
}
/**
Clean up this editor view, removing its element from the
document, unregistering event handlers, and notifying
plugins. The view instance can no longer be used after
calling this.
*/
destroy() {
for (let plugin of this.plugins)
plugin.destroy(this);
this.plugins = [];
this.inputState.destroy();
this.docView.destroy();
this.dom.remove();
this.observer.destroy();
if (this.measureScheduled > -1)
this.win.cancelAnimationFrame(this.measureScheduled);
this.destroyed = true;
}
/**
Returns an effect that can be
[added](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) to a transaction to
cause it to scroll the given position or range into view.
*/
static scrollIntoView(pos, options = {}) {
return scrollIntoView$1.of(new ScrollTarget(typeof pos == "number" ? EditorSelection.cursor(pos) : pos, options.y, options.x, options.yMargin, options.xMargin));
}
/**
Return an effect that resets the editor to its current (at the
time this method was called) scroll position. Note that this
only affects the editor's own scrollable element, not parents.
See also
[`EditorViewConfig.scrollTo`](https://codemirror.net/6/docs/ref/#view.EditorViewConfig.scrollTo).
The effect should be used with a document identical to the one
it was created for. Failing to do so is not an error, but may
not scroll to the expected position. You can
[map](https://codemirror.net/6/docs/ref/#state.StateEffect.map) the effect to account for changes.
*/
scrollSnapshot() {
let { scrollTop, scrollLeft } = this.scrollDOM;
let ref2 = this.viewState.scrollAnchorAt(scrollTop);
return scrollIntoView$1.of(new ScrollTarget(EditorSelection.cursor(ref2.from), "start", "start", ref2.top - scrollTop, scrollLeft, true));
}
/**
Returns an extension that can be used to add DOM event handlers.
The value should be an object mapping event names to handler
functions. For any given event, such functions are ordered by
extension precedence, and the first handler to return true will
be assumed to have handled that event, and no other handlers or
built-in behavior will be activated for it. These are registered
on the [content element](https://codemirror.net/6/docs/ref/#view.EditorView.contentDOM), except
for `scroll` handlers, which will be called any time the
editor's [scroll element](https://codemirror.net/6/docs/ref/#view.EditorView.scrollDOM) or one of
its parent nodes is scrolled.
*/
static domEventHandlers(handlers2) {
return ViewPlugin.define(() => ({}), { eventHandlers: handlers2 });
}
/**
Create an extension that registers DOM event observers. Contrary
to event [handlers](https://codemirror.net/6/docs/ref/#view.EditorView^domEventHandlers),
observers can't be prevented from running by a higher-precedence
handler returning true. They also don't prevent other handlers
and observers from running when they return true, and should not
call `preventDefault`.
*/
static domEventObservers(observers2) {
return ViewPlugin.define(() => ({}), { eventObservers: observers2 });
}
/**
Create a theme extension. The first argument can be a
[`style-mod`](https://github.com/marijnh/style-mod#documentation)
style spec providing the styles for the theme. These will be
prefixed with a generated class for the style.
Because the selectors will be prefixed with a scope class, rule
that directly match the editor's [wrapper
element](https://codemirror.net/6/docs/ref/#view.EditorView.dom)—to which the scope class will be
added—need to be explicitly differentiated by adding an `&` to
the selector for that element—for example
`&.cm-focused`.
When `dark` is set to true, the theme will be marked as dark,
which will cause the `&dark` rules from [base
themes](https://codemirror.net/6/docs/ref/#view.EditorView^baseTheme) to be used (as opposed to
`&light` when a light theme is active).
*/
static theme(spec, options) {
let prefix = StyleModule.newName();
let result2 = [theme.of(prefix), styleModule.of(buildTheme(`.${prefix}`, spec))];
if (options && options.dark)
result2.push(darkTheme.of(true));
return result2;
}
/**
Create an extension that adds styles to the base theme. Like
with [`theme`](https://codemirror.net/6/docs/ref/#view.EditorView^theme), use `&` to indicate the
place of the editor wrapper element when directly targeting
that. You can also use `&dark` or `&light` instead to only
target editors with a dark or light theme.
*/
static baseTheme(spec) {
return Prec.lowest(styleModule.of(buildTheme("." + baseThemeID, spec, lightDarkIDs)));
}
/**
Retrieve an editor view instance from the view's DOM
representation.
*/
static findFromDOM(dom) {
var _a2;
let content2 = dom.querySelector(".cm-content");
let cView = content2 && ContentView.get(content2) || ContentView.get(dom);
return ((_a2 = cView === null || cView === void 0 ? void 0 : cView.rootView) === null || _a2 === void 0 ? void 0 : _a2.view) || null;
}
}
EditorView.styleModule = styleModule;
EditorView.inputHandler = inputHandler$1;
EditorView.focusChangeEffect = focusChangeEffect;
EditorView.perLineTextDirection = perLineTextDirection;
EditorView.exceptionSink = exceptionSink;
EditorView.updateListener = updateListener;
EditorView.editable = editable;
EditorView.mouseSelectionStyle = mouseSelectionStyle;
EditorView.dragMovesSelection = dragMovesSelection$1;
EditorView.clickAddsSelectionRange = clickAddsSelectionRange;
EditorView.decorations = decorations;
EditorView.outerDecorations = outerDecorations;
EditorView.atomicRanges = atomicRanges;
EditorView.bidiIsolatedRanges = bidiIsolatedRanges;
EditorView.scrollMargins = scrollMargins;
EditorView.darkTheme = darkTheme;
EditorView.cspNonce = /* @__PURE__ */ Facet.define({ combine: (values) => values.length ? values[0] : "" });
EditorView.contentAttributes = contentAttributes;
EditorView.editorAttributes = editorAttributes;
EditorView.lineWrapping = /* @__PURE__ */ EditorView.contentAttributes.of({ "class": "cm-lineWrapping" });
EditorView.announce = /* @__PURE__ */ StateEffect.define();
const MaxBidiLine = 4096;
const BadMeasure = {};
class CachedOrder {
constructor(from, to, dir, isolates, fresh, order) {
this.from = from;
this.to = to;
this.dir = dir;
this.isolates = isolates;
this.fresh = fresh;
this.order = order;
}
static update(cache2, changes) {
if (changes.empty && !cache2.some((c) => c.fresh))
return cache2;
let result2 = [], lastDir = cache2.length ? cache2[cache2.length - 1].dir : Direction.LTR;
for (let i2 = Math.max(0, cache2.length - 10); i2 < cache2.length; i2++) {
let entry = cache2[i2];
if (entry.dir == lastDir && !changes.touchesRange(entry.from, entry.to))
result2.push(new CachedOrder(changes.mapPos(entry.from, 1), changes.mapPos(entry.to, -1), entry.dir, entry.isolates, false, entry.order));
}
return result2;
}
}
function attrsFromFacet(view, facet, base2) {
for (let sources = view.state.facet(facet), i2 = sources.length - 1; i2 >= 0; i2--) {
let source = sources[i2], value = typeof source == "function" ? source(view) : source;
if (value)
combineAttrs(value, base2);
}
return base2;
}
const currentPlatform = browser.mac ? "mac" : browser.windows ? "win" : browser.linux ? "linux" : "key";
function normalizeKeyName(name2, platform) {
const parts = name2.split(/-(?!$)/);
let result2 = parts[parts.length - 1];
if (result2 == "Space")
result2 = " ";
let alt, ctrl, shift2, meta2;
for (let i2 = 0; i2 < parts.length - 1; ++i2) {
const mod = parts[i2];
if (/^(cmd|meta|m)$/i.test(mod))
meta2 = true;
else if (/^a(lt)?$/i.test(mod))
alt = true;
else if (/^(c|ctrl|control)$/i.test(mod))
ctrl = true;
else if (/^s(hift)?$/i.test(mod))
shift2 = true;
else if (/^mod$/i.test(mod)) {
if (platform == "mac")
meta2 = true;
else
ctrl = true;
} else
throw new Error("Unrecognized modifier name: " + mod);
}
if (alt)
result2 = "Alt-" + result2;
if (ctrl)
result2 = "Ctrl-" + result2;
if (meta2)
result2 = "Meta-" + result2;
if (shift2)
result2 = "Shift-" + result2;
return result2;
}
function modifiers(name2, event, shift2) {
if (event.altKey)
name2 = "Alt-" + name2;
if (event.ctrlKey)
name2 = "Ctrl-" + name2;
if (event.metaKey)
name2 = "Meta-" + name2;
if (shift2 !== false && event.shiftKey)
name2 = "Shift-" + name2;
return name2;
}
const handleKeyEvents = /* @__PURE__ */ Prec.default(/* @__PURE__ */ EditorView.domEventHandlers({
keydown(event, view) {
return runHandlers(getKeymap(view.state), event, view, "editor");
}
}));
const keymap = /* @__PURE__ */ Facet.define({ enables: handleKeyEvents });
const Keymaps = /* @__PURE__ */ new WeakMap();
function getKeymap(state) {
let bindings = state.facet(keymap);
let map = Keymaps.get(bindings);
if (!map)
Keymaps.set(bindings, map = buildKeymap(bindings.reduce((a, b) => a.concat(b), [])));
return map;
}
function runScopeHandlers(view, event, scope) {
return runHandlers(getKeymap(view.state), event, view, scope);
}
let storedPrefix = null;
const PrefixTimeout = 4e3;
function buildKeymap(bindings, platform = currentPlatform) {
let bound = /* @__PURE__ */ Object.create(null);
let isPrefix = /* @__PURE__ */ Object.create(null);
let checkPrefix = (name2, is) => {
let current = isPrefix[name2];
if (current == null)
isPrefix[name2] = is;
else if (current != is)
throw new Error("Key binding " + name2 + " is used both as a regular binding and as a multi-stroke prefix");
};
let add2 = (scope, key, command2, preventDefault, stopPropagation) => {
var _a2, _b;
let scopeObj = bound[scope] || (bound[scope] = /* @__PURE__ */ Object.create(null));
let parts = key.split(/ (?!$)/).map((k) => normalizeKeyName(k, platform));
for (let i2 = 1; i2 < parts.length; i2++) {
let prefix = parts.slice(0, i2).join(" ");
checkPrefix(prefix, true);
if (!scopeObj[prefix])
scopeObj[prefix] = {
preventDefault: true,
stopPropagation: false,
run: [(view) => {
let ourObj = storedPrefix = { view, prefix, scope };
setTimeout(() => {
if (storedPrefix == ourObj)
storedPrefix = null;
}, PrefixTimeout);
return true;
}]
};
}
let full = parts.join(" ");
checkPrefix(full, false);
let binding = scopeObj[full] || (scopeObj[full] = {
preventDefault: false,
stopPropagation: false,
run: ((_b = (_a2 = scopeObj._any) === null || _a2 === void 0 ? void 0 : _a2.run) === null || _b === void 0 ? void 0 : _b.slice()) || []
});
if (command2)
binding.run.push(command2);
if (preventDefault)
binding.preventDefault = true;
if (stopPropagation)
binding.stopPropagation = true;
};
for (let b of bindings) {
let scopes = b.scope ? b.scope.split(" ") : ["editor"];
if (b.any)
for (let scope of scopes) {
let scopeObj = bound[scope] || (bound[scope] = /* @__PURE__ */ Object.create(null));
if (!scopeObj._any)
scopeObj._any = { preventDefault: false, stopPropagation: false, run: [] };
for (let key in scopeObj)
scopeObj[key].run.push(b.any);
}
let name2 = b[platform] || b.key;
if (!name2)
continue;
for (let scope of scopes) {
add2(scope, name2, b.run, b.preventDefault, b.stopPropagation);
if (b.shift)
add2(scope, "Shift-" + name2, b.shift, b.preventDefault, b.stopPropagation);
}
}
return bound;
}
function runHandlers(map, event, view, scope) {
let name2 = keyName(event);
let charCode = codePointAt(name2, 0), isChar = codePointSize(charCode) == name2.length && name2 != " ";
let prefix = "", handled = false, prevented = false, stopPropagation = false;
if (storedPrefix && storedPrefix.view == view && storedPrefix.scope == scope) {
prefix = storedPrefix.prefix + " ";
if (modifierCodes.indexOf(event.keyCode) < 0) {
prevented = true;
storedPrefix = null;
}
}
let ran = /* @__PURE__ */ new Set();
let runFor = (binding) => {
if (binding) {
for (let cmd2 of binding.run)
if (!ran.has(cmd2)) {
ran.add(cmd2);
if (cmd2(view, event)) {
if (binding.stopPropagation)
stopPropagation = true;
return true;
}
}
if (binding.preventDefault) {
if (binding.stopPropagation)
stopPropagation = true;
prevented = true;
}
}
return false;
};
let scopeObj = map[scope], baseName, shiftName;
if (scopeObj) {
if (runFor(scopeObj[prefix + modifiers(name2, event, !isChar)])) {
handled = true;
} else if (isChar && (event.altKey || event.metaKey || event.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows
!(browser.windows && event.ctrlKey && event.altKey) && (baseName = base[event.keyCode]) && baseName != name2) {
if (runFor(scopeObj[prefix + modifiers(baseName, event, true)])) {
handled = true;
} else if (event.shiftKey && (shiftName = shift[event.keyCode]) != name2 && shiftName != baseName && runFor(scopeObj[prefix + modifiers(shiftName, event, false)])) {
handled = true;
}
} else if (isChar && event.shiftKey && runFor(scopeObj[prefix + modifiers(name2, event, true)])) {
handled = true;
}
if (!handled && runFor(scopeObj._any))
handled = true;
}
if (prevented)
handled = true;
if (handled && stopPropagation)
event.stopPropagation();
return handled;
}
class RectangleMarker {
/**
Create a marker with the given class and dimensions. If `width`
is null, the DOM element will get no width style.
*/
constructor(className, left, top2, width, height) {
this.className = className;
this.left = left;
this.top = top2;
this.width = width;
this.height = height;
}
draw() {
let elt = document.createElement("div");
elt.className = this.className;
this.adjust(elt);
return elt;
}
update(elt, prev) {
if (prev.className != this.className)
return false;
this.adjust(elt);
return true;
}
adjust(elt) {
elt.style.left = this.left + "px";
elt.style.top = this.top + "px";
if (this.width != null)
elt.style.width = this.width + "px";
elt.style.height = this.height + "px";
}
eq(p) {
return this.left == p.left && this.top == p.top && this.width == p.width && this.height == p.height && this.className == p.className;
}
/**
Create a set of rectangles for the given selection range,
assigning them theclass`className`. Will create a single
rectangle for empty ranges, and a set of selection-style
rectangles covering the range's content (in a bidi-aware
way) for non-empty ones.
*/
static forRange(view, className, range) {
if (range.empty) {
let pos = view.coordsAtPos(range.head, range.assoc || 1);
if (!pos)
return [];
let base2 = getBase(view);
return [new RectangleMarker(className, pos.left - base2.left, pos.top - base2.top, null, pos.bottom - pos.top)];
} else {
return rectanglesForRange(view, className, range);
}
}
}
function getBase(view) {
let rect = view.scrollDOM.getBoundingClientRect();
let left = view.textDirection == Direction.LTR ? rect.left : rect.right - view.scrollDOM.clientWidth * view.scaleX;
return { left: left - view.scrollDOM.scrollLeft * view.scaleX, top: rect.top - view.scrollDOM.scrollTop * view.scaleY };
}
function wrappedLine(view, pos, inside2) {
let range = EditorSelection.cursor(pos);
return {
from: Math.max(inside2.from, view.moveToLineBoundary(range, false, true).from),
to: Math.min(inside2.to, view.moveToLineBoundary(range, true, true).from),
type: BlockType.Text
};
}
function rectanglesForRange(view, className, range) {
if (range.to <= view.viewport.from || range.from >= view.viewport.to)
return [];
let from = Math.max(range.from, view.viewport.from), to = Math.min(range.to, view.viewport.to);
let ltr = view.textDirection == Direction.LTR;
let content2 = view.contentDOM, contentRect = content2.getBoundingClientRect(), base2 = getBase(view);
let lineElt = content2.querySelector(".cm-line"), lineStyle = lineElt && window.getComputedStyle(lineElt);
let leftSide = contentRect.left + (lineStyle ? parseInt(lineStyle.paddingLeft) + Math.min(0, parseInt(lineStyle.textIndent)) : 0);
let rightSide = contentRect.right - (lineStyle ? parseInt(lineStyle.paddingRight) : 0);
let startBlock = blockAt(view, from), endBlock = blockAt(view, to);
let visualStart = startBlock.type == BlockType.Text ? startBlock : null;
let visualEnd = endBlock.type == BlockType.Text ? endBlock : null;
if (visualStart && (view.lineWrapping || startBlock.widgetLineBreaks))
visualStart = wrappedLine(view, from, visualStart);
if (visualEnd && (view.lineWrapping || endBlock.widgetLineBreaks))
visualEnd = wrappedLine(view, to, visualEnd);
if (visualStart && visualEnd && visualStart.from == visualEnd.from) {
return pieces(drawForLine(range.from, range.to, visualStart));
} else {
let top2 = visualStart ? drawForLine(range.from, null, visualStart) : drawForWidget(startBlock, false);
let bottom = visualEnd ? drawForLine(null, range.to, visualEnd) : drawForWidget(endBlock, true);
let between = [];
if ((visualStart || startBlock).to < (visualEnd || endBlock).from - (visualStart && visualEnd ? 1 : 0) || startBlock.widgetLineBreaks > 1 && top2.bottom + view.defaultLineHeight / 2 < bottom.top)
between.push(piece(leftSide, top2.bottom, rightSide, bottom.top));
else if (top2.bottom < bottom.top && view.elementAtHeight((top2.bottom + bottom.top) / 2).type == BlockType.Text)
top2.bottom = bottom.top = (top2.bottom + bottom.top) / 2;
return pieces(top2).concat(between).concat(pieces(bottom));
}
function piece(left, top2, right, bottom) {
return new RectangleMarker(
className,
left - base2.left,
top2 - base2.top - 0.01,
right - left,
bottom - top2 + 0.01
/* C.Epsilon */
);
}
function pieces({ top: top2, bottom, horizontal }) {
let pieces2 = [];
for (let i2 = 0; i2 < horizontal.length; i2 += 2)
pieces2.push(piece(horizontal[i2], top2, horizontal[i2 + 1], bottom));
return pieces2;
}
function drawForLine(from2, to2, line) {
let top2 = 1e9, bottom = -1e9, horizontal = [];
function addSpan(from3, fromOpen, to3, toOpen, dir) {
let fromCoords = view.coordsAtPos(from3, from3 == line.to ? -2 : 2);
let toCoords = view.coordsAtPos(to3, to3 == line.from ? 2 : -2);
if (!fromCoords || !toCoords)
return;
top2 = Math.min(fromCoords.top, toCoords.top, top2);
bottom = Math.max(fromCoords.bottom, toCoords.bottom, bottom);
if (dir == Direction.LTR)
horizontal.push(ltr && fromOpen ? leftSide : fromCoords.left, ltr && toOpen ? rightSide : toCoords.right);
else
horizontal.push(!ltr && toOpen ? leftSide : toCoords.left, !ltr && fromOpen ? rightSide : fromCoords.right);
}
let start = from2 !== null && from2 !== void 0 ? from2 : line.from, end = to2 !== null && to2 !== void 0 ? to2 : line.to;
for (let r of view.visibleRanges)
if (r.to > start && r.from < end) {
for (let pos = Math.max(r.from, start), endPos = Math.min(r.to, end); ; ) {
let docLine = view.state.doc.lineAt(pos);
for (let span of view.bidiSpans(docLine)) {
let spanFrom = span.from + docLine.from, spanTo = span.to + docLine.from;
if (spanFrom >= endPos)
break;
if (spanTo > pos)
addSpan(Math.max(spanFrom, pos), from2 == null && spanFrom <= start, Math.min(spanTo, endPos), to2 == null && spanTo >= end, span.dir);
}
pos = docLine.to + 1;
if (pos >= endPos)
break;
}
}
if (horizontal.length == 0)
addSpan(start, from2 == null, end, to2 == null, view.textDirection);
return { top: top2, bottom, horizontal };
}
function drawForWidget(block, top2) {
let y2 = contentRect.top + (top2 ? block.top : block.bottom);
return { top: y2, bottom: y2, horizontal: [] };
}
}
function sameMarker(a, b) {
return a.constructor == b.constructor && a.eq(b);
}
class LayerView {
constructor(view, layer2) {
this.view = view;
this.layer = layer2;
this.drawn = [];
this.scaleX = 1;
this.scaleY = 1;
this.measureReq = { read: this.measure.bind(this), write: this.draw.bind(this) };
this.dom = view.scrollDOM.appendChild(document.createElement("div"));
this.dom.classList.add("cm-layer");
if (layer2.above)
this.dom.classList.add("cm-layer-above");
if (layer2.class)
this.dom.classList.add(layer2.class);
this.scale();
this.dom.setAttribute("aria-hidden", "true");
this.setOrder(view.state);
view.requestMeasure(this.measureReq);
if (layer2.mount)
layer2.mount(this.dom, view);
}
update(update) {
if (update.startState.facet(layerOrder) != update.state.facet(layerOrder))
this.setOrder(update.state);
if (this.layer.update(update, this.dom) || update.geometryChanged) {
this.scale();
update.view.requestMeasure(this.measureReq);
}
}
setOrder(state) {
let pos = 0, order = state.facet(layerOrder);
while (pos < order.length && order[pos] != this.layer)
pos++;
this.dom.style.zIndex = String((this.layer.above ? 150 : -1) - pos);
}
measure() {
return this.layer.markers(this.view);
}
scale() {
let { scaleX, scaleY } = this.view;
if (scaleX != this.scaleX || scaleY != this.scaleY) {
this.scaleX = scaleX;
this.scaleY = scaleY;
this.dom.style.transform = `scale(${1 / scaleX}, ${1 / scaleY})`;
}
}
draw(markers) {
if (markers.length != this.drawn.length || markers.some((p, i2) => !sameMarker(p, this.drawn[i2]))) {
let old = this.dom.firstChild, oldI = 0;
for (let marker of markers) {
if (marker.update && old && marker.constructor && this.drawn[oldI].constructor && marker.update(old, this.drawn[oldI])) {
old = old.nextSibling;
oldI++;
} else {
this.dom.insertBefore(marker.draw(), old);
}
}
while (old) {
let next = old.nextSibling;
old.remove();
old = next;
}
this.drawn = markers;
}
}
destroy() {
if (this.layer.destroy)
this.layer.destroy(this.dom, this.view);
this.dom.remove();
}
}
const layerOrder = /* @__PURE__ */ Facet.define();
function layer(config2) {
return [
ViewPlugin.define((v) => new LayerView(v, config2)),
layerOrder.of(config2)
];
}
const CanHidePrimary = !browser.ios;
const selectionConfig = /* @__PURE__ */ Facet.define({
combine(configs) {
return combineConfig(configs, {
cursorBlinkRate: 1200,
drawRangeCursor: true
}, {
cursorBlinkRate: (a, b) => Math.min(a, b),
drawRangeCursor: (a, b) => a || b
});
}
});
function drawSelection(config2 = {}) {
return [
selectionConfig.of(config2),
cursorLayer,
selectionLayer,
hideNativeSelection,
nativeSelectionHidden.of(true)
];
}
function configChanged(update) {
return update.startState.facet(selectionConfig) != update.state.facet(selectionConfig);
}
const cursorLayer = /* @__PURE__ */ layer({
above: true,
markers(view) {
let { state } = view, conf = state.facet(selectionConfig);
let cursors = [];
for (let r of state.selection.ranges) {
let prim = r == state.selection.main;
if (r.empty ? !prim || CanHidePrimary : conf.drawRangeCursor) {
let className = prim ? "cm-cursor cm-cursor-primary" : "cm-cursor cm-cursor-secondary";
let cursor = r.empty ? r : EditorSelection.cursor(r.head, r.head > r.anchor ? -1 : 1);
for (let piece of RectangleMarker.forRange(view, className, cursor))
cursors.push(piece);
}
}
return cursors;
},
update(update, dom) {
if (update.transactions.some((tr) => tr.selection))
dom.style.animationName = dom.style.animationName == "cm-blink" ? "cm-blink2" : "cm-blink";
let confChange = configChanged(update);
if (confChange)
setBlinkRate(update.state, dom);
return update.docChanged || update.selectionSet || confChange;
},
mount(dom, view) {
setBlinkRate(view.state, dom);
},
class: "cm-cursorLayer"
});
function setBlinkRate(state, dom) {
dom.style.animationDuration = state.facet(selectionConfig).cursorBlinkRate + "ms";
}
const selectionLayer = /* @__PURE__ */ layer({
above: false,
markers(view) {
return view.state.selection.ranges.map((r) => r.empty ? [] : RectangleMarker.forRange(view, "cm-selectionBackground", r)).reduce((a, b) => a.concat(b));
},
update(update, dom) {
return update.docChanged || update.selectionSet || update.viewportChanged || configChanged(update);
},
class: "cm-selectionLayer"
});
const themeSpec = {
".cm-line": {
"& ::selection": { backgroundColor: "transparent !important" },
"&::selection": { backgroundColor: "transparent !important" }
}
};
if (CanHidePrimary) {
themeSpec[".cm-line"].caretColor = "transparent !important";
themeSpec[".cm-content"] = { caretColor: "transparent !important" };
}
const hideNativeSelection = /* @__PURE__ */ Prec.highest(/* @__PURE__ */ EditorView.theme(themeSpec));
const setDropCursorPos = /* @__PURE__ */ StateEffect.define({
map(pos, mapping) {
return pos == null ? null : mapping.mapPos(pos);
}
});
const dropCursorPos = /* @__PURE__ */ StateField.define({
create() {
return null;
},
update(pos, tr) {
if (pos != null)
pos = tr.changes.mapPos(pos);
return tr.effects.reduce((pos2, e) => e.is(setDropCursorPos) ? e.value : pos2, pos);
}
});
const drawDropCursor = /* @__PURE__ */ ViewPlugin.fromClass(class {
constructor(view) {
this.view = view;
this.cursor = null;
this.measureReq = { read: this.readPos.bind(this), write: this.drawCursor.bind(this) };
}
update(update) {
var _a2;
let cursorPos = update.state.field(dropCursorPos);
if (cursorPos == null) {
if (this.cursor != null) {
(_a2 = this.cursor) === null || _a2 === void 0 ? void 0 : _a2.remove();
this.cursor = null;
}
} else {
if (!this.cursor) {
this.cursor = this.view.scrollDOM.appendChild(document.createElement("div"));
this.cursor.className = "cm-dropCursor";
}
if (update.startState.field(dropCursorPos) != cursorPos || update.docChanged || update.geometryChanged)
this.view.requestMeasure(this.measureReq);
}
}
readPos() {
let { view } = this;
let pos = view.state.field(dropCursorPos);
let rect = pos != null && view.coordsAtPos(pos);
if (!rect)
return null;
let outer = view.scrollDOM.getBoundingClientRect();
return {
left: rect.left - outer.left + view.scrollDOM.scrollLeft * view.scaleX,
top: rect.top - outer.top + view.scrollDOM.scrollTop * view.scaleY,
height: rect.bottom - rect.top
};
}
drawCursor(pos) {
if (this.cursor) {
let { scaleX, scaleY } = this.view;
if (pos) {
this.cursor.style.left = pos.left / scaleX + "px";
this.cursor.style.top = pos.top / scaleY + "px";
this.cursor.style.height = pos.height / scaleY + "px";
} else {
this.cursor.style.left = "-100000px";
}
}
}
destroy() {
if (this.cursor)
this.cursor.remove();
}
setDropPos(pos) {
if (this.view.state.field(dropCursorPos) != pos)
this.view.dispatch({ effects: setDropCursorPos.of(pos) });
}
}, {
eventObservers: {
dragover(event) {
this.setDropPos(this.view.posAtCoords({ x: event.clientX, y: event.clientY }));
},
dragleave(event) {
if (event.target == this.view.contentDOM || !this.view.contentDOM.contains(event.relatedTarget))
this.setDropPos(null);
},
dragend() {
this.setDropPos(null);
},
drop() {
this.setDropPos(null);
}
}
});
function dropCursor() {
return [dropCursorPos, drawDropCursor];
}
function iterMatches(doc2, re, from, to, f) {
re.lastIndex = 0;
for (let cursor = doc2.iterRange(from, to), pos = from, m; !cursor.next().done; pos += cursor.value.length) {
if (!cursor.lineBreak)
while (m = re.exec(cursor.value))
f(pos + m.index, m);
}
}
function matchRanges(view, maxLength) {
let visible = view.visibleRanges;
if (visible.length == 1 && visible[0].from == view.viewport.from && visible[0].to == view.viewport.to)
return visible;
let result2 = [];
for (let { from, to } of visible) {
from = Math.max(view.state.doc.lineAt(from).from, from - maxLength);
to = Math.min(view.state.doc.lineAt(to).to, to + maxLength);
if (result2.length && result2[result2.length - 1].to >= from)
result2[result2.length - 1].to = to;
else
result2.push({ from, to });
}
return result2;
}
class MatchDecorator {
/**
Create a decorator.
*/
constructor(config2) {
const { regexp, decoration, decorate, boundary, maxLength = 1e3 } = config2;
if (!regexp.global)
throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");
this.regexp = regexp;
if (decorate) {
this.addMatch = (match2, view, from, add2) => decorate(add2, from, from + match2[0].length, match2, view);
} else if (typeof decoration == "function") {
this.addMatch = (match2, view, from, add2) => {
let deco = decoration(match2, view, from);
if (deco)
add2(from, from + match2[0].length, deco);
};
} else if (decoration) {
this.addMatch = (match2, _view, from, add2) => add2(from, from + match2[0].length, decoration);
} else {
throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");
}
this.boundary = boundary;
this.maxLength = maxLength;
}
/**
Compute the full set of decorations for matches in the given
view's viewport. You'll want to call this when initializing your
plugin.
*/
createDeco(view) {
let build = new RangeSetBuilder(), add2 = build.add.bind(build);
for (let { from, to } of matchRanges(view, this.maxLength))
iterMatches(view.state.doc, this.regexp, from, to, (from2, m) => this.addMatch(m, view, from2, add2));
return build.finish();
}
/**
Update a set of decorations for a view update. `deco` _must_ be
the set of decorations produced by _this_ `MatchDecorator` for
the view state before the update.
*/
updateDeco(update, deco) {
let changeFrom = 1e9, changeTo = -1;
if (update.docChanged)
update.changes.iterChanges((_f, _t, from, to) => {
if (to > update.view.viewport.from && from < update.view.viewport.to) {
changeFrom = Math.min(from, changeFrom);
changeTo = Math.max(to, changeTo);
}
});
if (update.viewportChanged || changeTo - changeFrom > 1e3)
return this.createDeco(update.view);
if (changeTo > -1)
return this.updateRange(update.view, deco.map(update.changes), changeFrom, changeTo);
return deco;
}
updateRange(view, deco, updateFrom, updateTo) {
for (let r of view.visibleRanges) {
let from = Math.max(r.from, updateFrom), to = Math.min(r.to, updateTo);
if (to > from) {
let fromLine = view.state.doc.lineAt(from), toLine = fromLine.to < to ? view.state.doc.lineAt(to) : fromLine;
let start = Math.max(r.from, fromLine.from), end = Math.min(r.to, toLine.to);
if (this.boundary) {
for (; from > fromLine.from; from--)
if (this.boundary.test(fromLine.text[from - 1 - fromLine.from])) {
start = from;
break;
}
for (; to < toLine.to; to++)
if (this.boundary.test(toLine.text[to - toLine.from])) {
end = to;
break;
}
}
let ranges = [], m;
let add2 = (from2, to2, deco2) => ranges.push(deco2.range(from2, to2));
if (fromLine == toLine) {
this.regexp.lastIndex = start - fromLine.from;
while ((m = this.regexp.exec(fromLine.text)) && m.index < end - fromLine.from)
this.addMatch(m, view, m.index + fromLine.from, add2);
} else {
iterMatches(view.state.doc, this.regexp, start, end, (from2, m2) => this.addMatch(m2, view, from2, add2));
}
deco = deco.update({ filterFrom: start, filterTo: end, filter: (from2, to2) => from2 < start || to2 > end, add: ranges });
}
}
return deco;
}
}
const UnicodeRegexpSupport = /x/.unicode != null ? "gu" : "g";
const Specials = /* @__PURE__ */ new RegExp("[\0-\b\n--\u2028\u2029\uFEFF-]", UnicodeRegexpSupport);
const Names = {
0: "null",
7: "bell",
8: "backspace",
10: "newline",
11: "vertical tab",
13: "carriage return",
27: "escape",
8203: "zero width space",
8204: "zero width non-joiner",
8205: "zero width joiner",
8206: "left-to-right mark",
8207: "right-to-left mark",
8232: "line separator",
8237: "left-to-right override",
8238: "right-to-left override",
8294: "left-to-right isolate",
8295: "right-to-left isolate",
8297: "pop directional isolate",
8233: "paragraph separator",
65279: "zero width no-break space",
65532: "object replacement"
};
let _supportsTabSize = null;
function supportsTabSize() {
var _a2;
if (_supportsTabSize == null && typeof document != "undefined" && document.body) {
let styles = document.body.style;
_supportsTabSize = ((_a2 = styles.tabSize) !== null && _a2 !== void 0 ? _a2 : styles.MozTabSize) != null;
}
return _supportsTabSize || false;
}
const specialCharConfig = /* @__PURE__ */ Facet.define({
combine(configs) {
let config2 = combineConfig(configs, {
render: null,
specialChars: Specials,
addSpecialChars: null
});
if (config2.replaceTabs = !supportsTabSize())
config2.specialChars = new RegExp(" |" + config2.specialChars.source, UnicodeRegexpSupport);
if (config2.addSpecialChars)
config2.specialChars = new RegExp(config2.specialChars.source + "|" + config2.addSpecialChars.source, UnicodeRegexpSupport);
return config2;
}
});
function highlightSpecialChars(config2 = {}) {
return [specialCharConfig.of(config2), specialCharPlugin()];
}
let _plugin = null;
function specialCharPlugin() {
return _plugin || (_plugin = ViewPlugin.fromClass(class {
constructor(view) {
this.view = view;
this.decorations = Decoration.none;
this.decorationCache = /* @__PURE__ */ Object.create(null);
this.decorator = this.makeDecorator(view.state.facet(specialCharConfig));
this.decorations = this.decorator.createDeco(view);
}
makeDecorator(conf) {
return new MatchDecorator({
regexp: conf.specialChars,
decoration: (m, view, pos) => {
let { doc: doc2 } = view.state;
let code2 = codePointAt(m[0], 0);
if (code2 == 9) {
let line = doc2.lineAt(pos);
let size = view.state.tabSize, col = countColumn(line.text, size, pos - line.from);
return Decoration.replace({
widget: new TabWidget((size - col % size) * this.view.defaultCharacterWidth / this.view.scaleX)
});
}
return this.decorationCache[code2] || (this.decorationCache[code2] = Decoration.replace({ widget: new SpecialCharWidget(conf, code2) }));
},
boundary: conf.replaceTabs ? void 0 : /[^]/
});
}
update(update) {
let conf = update.state.facet(specialCharConfig);
if (update.startState.facet(specialCharConfig) != conf) {
this.decorator = this.makeDecorator(conf);
this.decorations = this.decorator.createDeco(update.view);
} else {
this.decorations = this.decorator.updateDeco(update, this.decorations);
}
}
}, {
decorations: (v) => v.decorations
}));
}
const DefaultPlaceholder = "•";
function placeholder$1(code2) {
if (code2 >= 32)
return DefaultPlaceholder;
if (code2 == 10)
return "";
return String.fromCharCode(9216 + code2);
}
class SpecialCharWidget extends WidgetType {
constructor(options, code2) {
super();
this.options = options;
this.code = code2;
}
eq(other) {
return other.code == this.code;
}
toDOM(view) {
let ph = placeholder$1(this.code);
let desc = view.state.phrase("Control character") + " " + (Names[this.code] || "0x" + this.code.toString(16));
let custom = this.options.render && this.options.render(this.code, desc, ph);
if (custom)
return custom;
let span = document.createElement("span");
span.textContent = ph;
span.title = desc;
span.setAttribute("aria-label", desc);
span.className = "cm-specialChar";
return span;
}
ignoreEvent() {
return false;
}
}
class TabWidget extends WidgetType {
constructor(width) {
super();
this.width = width;
}
eq(other) {
return other.width == this.width;
}
toDOM() {
let span = document.createElement("span");
span.textContent = " ";
span.className = "cm-tab";
span.style.width = this.width + "px";
return span;
}
ignoreEvent() {
return false;
}
}
function highlightActiveLine() {
return activeLineHighlighter;
}
const lineDeco = /* @__PURE__ */ Decoration.line({ class: "cm-activeLine" });
const activeLineHighlighter = /* @__PURE__ */ ViewPlugin.fromClass(class {
constructor(view) {
this.decorations = this.getDeco(view);
}
update(update) {
if (update.docChanged || update.selectionSet)
this.decorations = this.getDeco(update.view);
}
getDeco(view) {
let lastLineStart = -1, deco = [];
for (let r of view.state.selection.ranges) {
let line = view.lineBlockAt(r.head);
if (line.from > lastLineStart) {
deco.push(lineDeco.range(line.from));
lastLineStart = line.from;
}
}
return Decoration.set(deco);
}
}, {
decorations: (v) => v.decorations
});
class Placeholder extends WidgetType {
constructor(content2) {
super();
this.content = content2;
}
toDOM() {
let wrap = document.createElement("span");
wrap.className = "cm-placeholder";
wrap.style.pointerEvents = "none";
wrap.appendChild(typeof this.content == "string" ? document.createTextNode(this.content) : this.content);
if (typeof this.content == "string")
wrap.setAttribute("aria-label", "placeholder " + this.content);
else
wrap.setAttribute("aria-hidden", "true");
return wrap;
}
coordsAt(dom) {
let rects = dom.firstChild ? clientRectsFor(dom.firstChild) : [];
if (!rects.length)
return null;
let style = window.getComputedStyle(dom.parentNode);
let rect = flattenRect(rects[0], style.direction != "rtl");
let lineHeight = parseInt(style.lineHeight);
if (rect.bottom - rect.top > lineHeight * 1.5)
return { left: rect.left, right: rect.right, top: rect.top, bottom: rect.top + lineHeight };
return rect;
}
ignoreEvent() {
return false;
}
}
function placeholder(content2) {
return ViewPlugin.fromClass(class {
constructor(view) {
this.view = view;
this.placeholder = content2 ? Decoration.set([Decoration.widget({ widget: new Placeholder(content2), side: 1 }).range(0)]) : Decoration.none;
}
get decorations() {
return this.view.state.doc.length ? Decoration.none : this.placeholder;
}
}, { decorations: (v) => v.decorations });
}
const MaxOff = 2e3;
function rectangleFor(state, a, b) {
let startLine = Math.min(a.line, b.line), endLine = Math.max(a.line, b.line);
let ranges = [];
if (a.off > MaxOff || b.off > MaxOff || a.col < 0 || b.col < 0) {
let startOff = Math.min(a.off, b.off), endOff = Math.max(a.off, b.off);
for (let i2 = startLine; i2 <= endLine; i2++) {
let line = state.doc.line(i2);
if (line.length <= endOff)
ranges.push(EditorSelection.range(line.from + startOff, line.to + endOff));
}
} else {
let startCol = Math.min(a.col, b.col), endCol = Math.max(a.col, b.col);
for (let i2 = startLine; i2 <= endLine; i2++) {
let line = state.doc.line(i2);
let start = findColumn(line.text, startCol, state.tabSize, true);
if (start < 0) {
ranges.push(EditorSelection.cursor(line.to));
} else {
let end = findColumn(line.text, endCol, state.tabSize);
ranges.push(EditorSelection.range(line.from + start, line.from + end));
}
}
}
return ranges;
}
function absoluteColumn(view, x2) {
let ref2 = view.coordsAtPos(view.viewport.from);
return ref2 ? Math.round(Math.abs((ref2.left - x2) / view.defaultCharacterWidth)) : -1;
}
function getPos(view, event) {
let offset = view.posAtCoords({ x: event.clientX, y: event.clientY }, false);
let line = view.state.doc.lineAt(offset), off = offset - line.from;
let col = off > MaxOff ? -1 : off == line.length ? absoluteColumn(view, event.clientX) : countColumn(line.text, view.state.tabSize, offset - line.from);
return { line: line.number, col, off };
}
function rectangleSelectionStyle(view, event) {
let start = getPos(view, event), startSel = view.state.selection;
if (!start)
return null;
return {
update(update) {
if (update.docChanged) {
let newStart = update.changes.mapPos(update.startState.doc.line(start.line).from);
let newLine = update.state.doc.lineAt(newStart);
start = { line: newLine.number, col: start.col, off: Math.min(start.off, newLine.length) };
startSel = startSel.map(update.changes);
}
},
get(event2, _extend, multiple) {
let cur2 = getPos(view, event2);
if (!cur2)
return startSel;
let ranges = rectangleFor(view.state, start, cur2);
if (!ranges.length)
return startSel;
if (multiple)
return EditorSelection.create(ranges.concat(startSel.ranges));
else
return EditorSelection.create(ranges);
}
};
}
function rectangularSelection(options) {
let filter = (options === null || options === void 0 ? void 0 : options.eventFilter) || ((e) => e.altKey && e.button == 0);
return EditorView.mouseSelectionStyle.of((view, event) => filter(event) ? rectangleSelectionStyle(view, event) : null);
}
const keys = {
Alt: [18, (e) => !!e.altKey],
Control: [17, (e) => !!e.ctrlKey],
Shift: [16, (e) => !!e.shiftKey],
Meta: [91, (e) => !!e.metaKey]
};
const showCrosshair = { style: "cursor: crosshair" };
function crosshairCursor(options = {}) {
let [code2, getter] = keys[options.key || "Alt"];
let plugin = ViewPlugin.fromClass(class {
constructor(view) {
this.view = view;
this.isDown = false;
}
set(isDown) {
if (this.isDown != isDown) {
this.isDown = isDown;
this.view.update([]);
}
}
}, {
eventObservers: {
keydown(e) {
this.set(e.keyCode == code2 || getter(e));
},
keyup(e) {
if (e.keyCode == code2 || !getter(e))
this.set(false);
},
mousemove(e) {
this.set(getter(e));
}
}
});
return [
plugin,
EditorView.contentAttributes.of((view) => {
var _a2;
return ((_a2 = view.plugin(plugin)) === null || _a2 === void 0 ? void 0 : _a2.isDown) ? showCrosshair : null;
})
];
}
const Outside = "-10000px";
class TooltipViewManager {
constructor(view, facet, createTooltipView, removeTooltipView) {
this.facet = facet;
this.createTooltipView = createTooltipView;
this.removeTooltipView = removeTooltipView;
this.input = view.state.facet(facet);
this.tooltips = this.input.filter((t2) => t2);
let prev = null;
this.tooltipViews = this.tooltips.map((t2) => prev = createTooltipView(t2, prev));
}
update(update, above) {
var _a2;
let input = update.state.facet(this.facet);
let tooltips = input.filter((x2) => x2);
if (input === this.input) {
for (let t2 of this.tooltipViews)
if (t2.update)
t2.update(update);
return false;
}
let tooltipViews = [], newAbove = above ? [] : null;
for (let i2 = 0; i2 < tooltips.length; i2++) {
let tip = tooltips[i2], known = -1;
if (!tip)
continue;
for (let i3 = 0; i3 < this.tooltips.length; i3++) {
let other = this.tooltips[i3];
if (other && other.create == tip.create)
known = i3;
}
if (known < 0) {
tooltipViews[i2] = this.createTooltipView(tip, i2 ? tooltipViews[i2 - 1] : null);
if (newAbove)
newAbove[i2] = !!tip.above;
} else {
let tooltipView = tooltipViews[i2] = this.tooltipViews[known];
if (newAbove)
newAbove[i2] = above[known];
if (tooltipView.update)
tooltipView.update(update);
}
}
for (let t2 of this.tooltipViews)
if (tooltipViews.indexOf(t2) < 0) {
this.removeTooltipView(t2);
(_a2 = t2.destroy) === null || _a2 === void 0 ? void 0 : _a2.call(t2);
}
if (above) {
newAbove.forEach((val, i2) => above[i2] = val);
above.length = newAbove.length;
}
this.input = input;
this.tooltips = tooltips;
this.tooltipViews = tooltipViews;
return true;
}
}
function windowSpace(view) {
let { win } = view;
return { top: 0, left: 0, bottom: win.innerHeight, right: win.innerWidth };
}
const tooltipConfig = /* @__PURE__ */ Facet.define({
combine: (values) => {
var _a2, _b, _c;
return {
position: browser.ios ? "absolute" : ((_a2 = values.find((conf) => conf.position)) === null || _a2 === void 0 ? void 0 : _a2.position) || "fixed",
parent: ((_b = values.find((conf) => conf.parent)) === null || _b === void 0 ? void 0 : _b.parent) || null,
tooltipSpace: ((_c = values.find((conf) => conf.tooltipSpace)) === null || _c === void 0 ? void 0 : _c.tooltipSpace) || windowSpace
};
}
});
const knownHeight = /* @__PURE__ */ new WeakMap();
const tooltipPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
constructor(view) {
this.view = view;
this.above = [];
this.inView = true;
this.madeAbsolute = false;
this.lastTransaction = 0;
this.measureTimeout = -1;
let config2 = view.state.facet(tooltipConfig);
this.position = config2.position;
this.parent = config2.parent;
this.classes = view.themeClasses;
this.createContainer();
this.measureReq = { read: this.readMeasure.bind(this), write: this.writeMeasure.bind(this), key: this };
this.resizeObserver = typeof ResizeObserver == "function" ? new ResizeObserver(() => this.measureSoon()) : null;
this.manager = new TooltipViewManager(view, showTooltip, (t2, p) => this.createTooltip(t2, p), (t2) => {
if (this.resizeObserver)
this.resizeObserver.unobserve(t2.dom);
t2.dom.remove();
});
this.above = this.manager.tooltips.map((t2) => !!t2.above);
this.intersectionObserver = typeof IntersectionObserver == "function" ? new IntersectionObserver((entries) => {
if (Date.now() > this.lastTransaction - 50 && entries.length > 0 && entries[entries.length - 1].intersectionRatio < 1)
this.measureSoon();
}, { threshold: [1] }) : null;
this.observeIntersection();
view.win.addEventListener("resize", this.measureSoon = this.measureSoon.bind(this));
this.maybeMeasure();
}
createContainer() {
if (this.parent) {
this.container = document.createElement("div");
this.container.style.position = "relative";
this.container.className = this.view.themeClasses;
this.parent.appendChild(this.container);
} else {
this.container = this.view.dom;
}
}
observeIntersection() {
if (this.intersectionObserver) {
this.intersectionObserver.disconnect();
for (let tooltip of this.manager.tooltipViews)
this.intersectionObserver.observe(tooltip.dom);
}
}
measureSoon() {
if (this.measureTimeout < 0)
this.measureTimeout = setTimeout(() => {
this.measureTimeout = -1;
this.maybeMeasure();
}, 50);
}
update(update) {
if (update.transactions.length)
this.lastTransaction = Date.now();
let updated = this.manager.update(update, this.above);
if (updated)
this.observeIntersection();
let shouldMeasure = updated || update.geometryChanged;
let newConfig = update.state.facet(tooltipConfig);
if (newConfig.position != this.position && !this.madeAbsolute) {
this.position = newConfig.position;
for (let t2 of this.manager.tooltipViews)
t2.dom.style.position = this.position;
shouldMeasure = true;
}
if (newConfig.parent != this.parent) {
if (this.parent)
this.container.remove();
this.parent = newConfig.parent;
this.createContainer();
for (let t2 of this.manager.tooltipViews)
this.container.appendChild(t2.dom);
shouldMeasure = true;
} else if (this.parent && this.view.themeClasses != this.classes) {
this.classes = this.container.className = this.view.themeClasses;
}
if (shouldMeasure)
this.maybeMeasure();
}
createTooltip(tooltip, prev) {
let tooltipView = tooltip.create(this.view);
let before = prev ? prev.dom : null;
tooltipView.dom.classList.add("cm-tooltip");
if (tooltip.arrow && !tooltipView.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")) {
let arrow = document.createElement("div");
arrow.className = "cm-tooltip-arrow";
tooltipView.dom.insertBefore(arrow, before);
}
tooltipView.dom.style.position = this.position;
tooltipView.dom.style.top = Outside;
tooltipView.dom.style.left = "0px";
this.container.insertBefore(tooltipView.dom, before);
if (tooltipView.mount)
tooltipView.mount(this.view);
if (this.resizeObserver)
this.resizeObserver.observe(tooltipView.dom);
return tooltipView;
}
destroy() {
var _a2, _b, _c;
this.view.win.removeEventListener("resize", this.measureSoon);
for (let tooltipView of this.manager.tooltipViews) {
tooltipView.dom.remove();
(_a2 = tooltipView.destroy) === null || _a2 === void 0 ? void 0 : _a2.call(tooltipView);
}
if (this.parent)
this.container.remove();
(_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
(_c = this.intersectionObserver) === null || _c === void 0 ? void 0 : _c.disconnect();
clearTimeout(this.measureTimeout);
}
readMeasure() {
let editor = this.view.dom.getBoundingClientRect();
let scaleX = 1, scaleY = 1, makeAbsolute = false;
if (this.position == "fixed" && this.manager.tooltipViews.length) {
let { dom } = this.manager.tooltipViews[0];
if (browser.gecko) {
makeAbsolute = dom.offsetParent != this.container.ownerDocument.body;
} else if (dom.style.top == Outside && dom.style.left == "0px") {
let rect = dom.getBoundingClientRect();
makeAbsolute = Math.abs(rect.top + 1e4) > 1 || Math.abs(rect.left) > 1;
}
}
if (makeAbsolute || this.position == "absolute") {
if (this.parent) {
let rect = this.parent.getBoundingClientRect();
if (rect.width && rect.height) {
scaleX = rect.width / this.parent.offsetWidth;
scaleY = rect.height / this.parent.offsetHeight;
}
} else {
({ scaleX, scaleY } = this.view.viewState);
}
}
return {
editor,
parent: this.parent ? this.container.getBoundingClientRect() : editor,
pos: this.manager.tooltips.map((t2, i2) => {
let tv = this.manager.tooltipViews[i2];
return tv.getCoords ? tv.getCoords(t2.pos) : this.view.coordsAtPos(t2.pos);
}),
size: this.manager.tooltipViews.map(({ dom }) => dom.getBoundingClientRect()),
space: this.view.state.facet(tooltipConfig).tooltipSpace(this.view),
scaleX,
scaleY,
makeAbsolute
};
}
writeMeasure(measured) {
var _a2;
if (measured.makeAbsolute) {
this.madeAbsolute = true;
this.position = "absolute";
for (let t2 of this.manager.tooltipViews)
t2.dom.style.position = "absolute";
}
let { editor, space: space2, scaleX, scaleY } = measured;
let others = [];
for (let i2 = 0; i2 < this.manager.tooltips.length; i2++) {
let tooltip = this.manager.tooltips[i2], tView = this.manager.tooltipViews[i2], { dom } = tView;
let pos = measured.pos[i2], size = measured.size[i2];
if (!pos || pos.bottom <= Math.max(editor.top, space2.top) || pos.top >= Math.min(editor.bottom, space2.bottom) || pos.right < Math.max(editor.left, space2.left) - 0.1 || pos.left > Math.min(editor.right, space2.right) + 0.1) {
dom.style.top = Outside;
continue;
}
let arrow = tooltip.arrow ? tView.dom.querySelector(".cm-tooltip-arrow") : null;
let arrowHeight = arrow ? 7 : 0;
let width = size.right - size.left, height = (_a2 = knownHeight.get(tView)) !== null && _a2 !== void 0 ? _a2 : size.bottom - size.top;
let offset = tView.offset || noOffset, ltr = this.view.textDirection == Direction.LTR;
let left = size.width > space2.right - space2.left ? ltr ? space2.left : space2.right - size.width : ltr ? Math.min(pos.left - (arrow ? 14 : 0) + offset.x, space2.right - width) : Math.max(space2.left, pos.left - width + (arrow ? 14 : 0) - offset.x);
let above = this.above[i2];
if (!tooltip.strictSide && (above ? pos.top - (size.bottom - size.top) - offset.y < space2.top : pos.bottom + (size.bottom - size.top) + offset.y > space2.bottom) && above == space2.bottom - pos.bottom > pos.top - space2.top)
above = this.above[i2] = !above;
let spaceVert = (above ? pos.top - space2.top : space2.bottom - pos.bottom) - arrowHeight;
if (spaceVert < height && tView.resize !== false) {
if (spaceVert < this.view.defaultLineHeight) {
dom.style.top = Outside;
continue;
}
knownHeight.set(tView, height);
dom.style.height = (height = spaceVert) / scaleY + "px";
} else if (dom.style.height) {
dom.style.height = "";
}
let top2 = above ? pos.top - height - arrowHeight - offset.y : pos.bottom + arrowHeight + offset.y;
let right = left + width;
if (tView.overlap !== true) {
for (let r of others)
if (r.left < right && r.right > left && r.top < top2 + height && r.bottom > top2)
top2 = above ? r.top - height - 2 - arrowHeight : r.bottom + arrowHeight + 2;
}
if (this.position == "absolute") {
dom.style.top = (top2 - measured.parent.top) / scaleY + "px";
dom.style.left = (left - measured.parent.left) / scaleX + "px";
} else {
dom.style.top = top2 / scaleY + "px";
dom.style.left = left / scaleX + "px";
}
if (arrow) {
let arrowLeft = pos.left + (ltr ? offset.x : -offset.x) - (left + 14 - 7);
arrow.style.left = arrowLeft / scaleX + "px";
}
if (tView.overlap !== true)
others.push({ left, top: top2, right, bottom: top2 + height });
dom.classList.toggle("cm-tooltip-above", above);
dom.classList.toggle("cm-tooltip-below", !above);
if (tView.positioned)
tView.positioned(measured.space);
}
}
maybeMeasure() {
if (this.manager.tooltips.length) {
if (this.view.inView)
this.view.requestMeasure(this.measureReq);
if (this.inView != this.view.inView) {
this.inView = this.view.inView;
if (!this.inView)
for (let tv of this.manager.tooltipViews)
tv.dom.style.top = Outside;
}
}
}
}, {
eventObservers: {
scroll() {
this.maybeMeasure();
}
}
});
const baseTheme$4 = /* @__PURE__ */ EditorView.baseTheme({
".cm-tooltip": {
zIndex: 100,
boxSizing: "border-box"
},
"&light .cm-tooltip": {
border: "1px solid #bbb",
backgroundColor: "#f5f5f5"
},
"&light .cm-tooltip-section:not(:first-child)": {
borderTop: "1px solid #bbb"
},
"&dark .cm-tooltip": {
backgroundColor: "#333338",
color: "white"
},
".cm-tooltip-arrow": {
height: `${7}px`,
width: `${7 * 2}px`,
position: "absolute",
zIndex: -1,
overflow: "hidden",
"&:before, &:after": {
content: "''",
position: "absolute",
width: 0,
height: 0,
borderLeft: `${7}px solid transparent`,
borderRight: `${7}px solid transparent`
},
".cm-tooltip-above &": {
bottom: `-${7}px`,
"&:before": {
borderTop: `${7}px solid #bbb`
},
"&:after": {
borderTop: `${7}px solid #f5f5f5`,
bottom: "1px"
}
},
".cm-tooltip-below &": {
top: `-${7}px`,
"&:before": {
borderBottom: `${7}px solid #bbb`
},
"&:after": {
borderBottom: `${7}px solid #f5f5f5`,
top: "1px"
}
}
},
"&dark .cm-tooltip .cm-tooltip-arrow": {
"&:before": {
borderTopColor: "#333338",
borderBottomColor: "#333338"
},
"&:after": {
borderTopColor: "transparent",
borderBottomColor: "transparent"
}
}
});
const noOffset = { x: 0, y: 0 };
const showTooltip = /* @__PURE__ */ Facet.define({
enables: [tooltipPlugin, baseTheme$4]
});
const showHoverTooltip = /* @__PURE__ */ Facet.define({
combine: (inputs) => inputs.reduce((a, i2) => a.concat(i2), [])
});
class HoverTooltipHost {
// Needs to be static so that host tooltip instances always match
static create(view) {
return new HoverTooltipHost(view);
}
constructor(view) {
this.view = view;
this.mounted = false;
this.dom = document.createElement("div");
this.dom.classList.add("cm-tooltip-hover");
this.manager = new TooltipViewManager(view, showHoverTooltip, (t2, p) => this.createHostedView(t2, p), (t2) => t2.dom.remove());
}
createHostedView(tooltip, prev) {
let hostedView = tooltip.create(this.view);
hostedView.dom.classList.add("cm-tooltip-section");
this.dom.insertBefore(hostedView.dom, prev ? prev.dom.nextSibling : this.dom.firstChild);
if (this.mounted && hostedView.mount)
hostedView.mount(this.view);
return hostedView;
}
mount(view) {
for (let hostedView of this.manager.tooltipViews) {
if (hostedView.mount)
hostedView.mount(view);
}
this.mounted = true;
}
positioned(space2) {
for (let hostedView of this.manager.tooltipViews) {
if (hostedView.positioned)
hostedView.positioned(space2);
}
}
update(update) {
this.manager.update(update);
}
destroy() {
var _a2;
for (let t2 of this.manager.tooltipViews)
(_a2 = t2.destroy) === null || _a2 === void 0 ? void 0 : _a2.call(t2);
}
passProp(name2) {
let value = void 0;
for (let view of this.manager.tooltipViews) {
let given = view[name2];
if (given !== void 0) {
if (value === void 0)
value = given;
else if (value !== given)
return void 0;
}
}
return value;
}
get offset() {
return this.passProp("offset");
}
get getCoords() {
return this.passProp("getCoords");
}
get overlap() {
return this.passProp("overlap");
}
get resize() {
return this.passProp("resize");
}
}
const showHoverTooltipHost = /* @__PURE__ */ showTooltip.compute([showHoverTooltip], (state) => {
let tooltips = state.facet(showHoverTooltip);
if (tooltips.length === 0)
return null;
return {
pos: Math.min(...tooltips.map((t2) => t2.pos)),
end: Math.max(...tooltips.map((t2) => {
var _a2;
return (_a2 = t2.end) !== null && _a2 !== void 0 ? _a2 : t2.pos;
})),
create: HoverTooltipHost.create,
above: tooltips[0].above,
arrow: tooltips.some((t2) => t2.arrow)
};
});
class HoverPlugin {
constructor(view, source, field, setHover, hoverTime) {
this.view = view;
this.source = source;
this.field = field;
this.setHover = setHover;
this.hoverTime = hoverTime;
this.hoverTimeout = -1;
this.restartTimeout = -1;
this.pending = null;
this.lastMove = { x: 0, y: 0, target: view.dom, time: 0 };
this.checkHover = this.checkHover.bind(this);
view.dom.addEventListener("mouseleave", this.mouseleave = this.mouseleave.bind(this));
view.dom.addEventListener("mousemove", this.mousemove = this.mousemove.bind(this));
}
update() {
if (this.pending) {
this.pending = null;
clearTimeout(this.restartTimeout);
this.restartTimeout = setTimeout(() => this.startHover(), 20);
}
}
get active() {
return this.view.state.field(this.field);
}
checkHover() {
this.hoverTimeout = -1;
if (this.active.length)
return;
let hovered = Date.now() - this.lastMove.time;
if (hovered < this.hoverTime)
this.hoverTimeout = setTimeout(this.checkHover, this.hoverTime - hovered);
else
this.startHover();
}
startHover() {
clearTimeout(this.restartTimeout);
let { view, lastMove } = this;
let desc = view.docView.nearest(lastMove.target);
if (!desc)
return;
let pos, side = 1;
if (desc instanceof WidgetView) {
pos = desc.posAtStart;
} else {
pos = view.posAtCoords(lastMove);
if (pos == null)
return;
let posCoords = view.coordsAtPos(pos);
if (!posCoords || lastMove.y < posCoords.top || lastMove.y > posCoords.bottom || lastMove.x < posCoords.left - view.defaultCharacterWidth || lastMove.x > posCoords.right + view.defaultCharacterWidth)
return;
let bidi = view.bidiSpans(view.state.doc.lineAt(pos)).find((s) => s.from <= pos && s.to >= pos);
let rtl = bidi && bidi.dir == Direction.RTL ? -1 : 1;
side = lastMove.x < posCoords.left ? -rtl : rtl;
}
let open = this.source(view, pos, side);
if (open === null || open === void 0 ? void 0 : open.then) {
let pending = this.pending = { pos };
open.then((result2) => {
if (this.pending == pending) {
this.pending = null;
if (result2 && !(Array.isArray(result2) && !result2.length))
view.dispatch({ effects: this.setHover.of(Array.isArray(result2) ? result2 : [result2]) });
}
}, (e) => logException(view.state, e, "hover tooltip"));
} else if (open && !(Array.isArray(open) && !open.length)) {
view.dispatch({ effects: this.setHover.of(Array.isArray(open) ? open : [open]) });
}
}
get tooltip() {
let plugin = this.view.plugin(tooltipPlugin);
let index = plugin ? plugin.manager.tooltips.findIndex((t2) => t2.create == HoverTooltipHost.create) : -1;
return index > -1 ? plugin.manager.tooltipViews[index] : null;
}
mousemove(event) {
var _a2, _b;
this.lastMove = { x: event.clientX, y: event.clientY, target: event.target, time: Date.now() };
if (this.hoverTimeout < 0)
this.hoverTimeout = setTimeout(this.checkHover, this.hoverTime);
let { active, tooltip } = this;
if (active.length && tooltip && !isInTooltip(tooltip.dom, event) || this.pending) {
let { pos } = active[0] || this.pending, end = (_b = (_a2 = active[0]) === null || _a2 === void 0 ? void 0 : _a2.end) !== null && _b !== void 0 ? _b : pos;
if (pos == end ? this.view.posAtCoords(this.lastMove) != pos : !isOverRange(this.view, pos, end, event.clientX, event.clientY)) {
this.view.dispatch({ effects: this.setHover.of([]) });
this.pending = null;
}
}
}
mouseleave(event) {
clearTimeout(this.hoverTimeout);
this.hoverTimeout = -1;
let { active } = this;
if (active.length) {
let { tooltip } = this;
let inTooltip = tooltip && tooltip.dom.contains(event.relatedTarget);
if (!inTooltip)
this.view.dispatch({ effects: this.setHover.of([]) });
else
this.watchTooltipLeave(tooltip.dom);
}
}
watchTooltipLeave(tooltip) {
let watch2 = (event) => {
tooltip.removeEventListener("mouseleave", watch2);
if (this.active.length && !this.view.dom.contains(event.relatedTarget))
this.view.dispatch({ effects: this.setHover.of([]) });
};
tooltip.addEventListener("mouseleave", watch2);
}
destroy() {
clearTimeout(this.hoverTimeout);
this.view.dom.removeEventListener("mouseleave", this.mouseleave);
this.view.dom.removeEventListener("mousemove", this.mousemove);
}
}
const tooltipMargin = 4;
function isInTooltip(tooltip, event) {
let rect = tooltip.getBoundingClientRect();
return event.clientX >= rect.left - tooltipMargin && event.clientX <= rect.right + tooltipMargin && event.clientY >= rect.top - tooltipMargin && event.clientY <= rect.bottom + tooltipMargin;
}
function isOverRange(view, from, to, x2, y2, margin) {
let rect = view.scrollDOM.getBoundingClientRect();
let docBottom = view.documentTop + view.documentPadding.top + view.contentHeight;
if (rect.left > x2 || rect.right < x2 || rect.top > y2 || Math.min(rect.bottom, docBottom) < y2)
return false;
let pos = view.posAtCoords({ x: x2, y: y2 }, false);
return pos >= from && pos <= to;
}
function hoverTooltip(source, options = {}) {
let setHover = StateEffect.define();
let hoverState = StateField.define({
create() {
return [];
},
update(value, tr) {
if (value.length) {
if (options.hideOnChange && (tr.docChanged || tr.selection))
value = [];
else if (options.hideOn)
value = value.filter((v) => !options.hideOn(tr, v));
if (tr.docChanged) {
let mapped = [];
for (let tooltip of value) {
let newPos = tr.changes.mapPos(tooltip.pos, -1, MapMode.TrackDel);
if (newPos != null) {
let copy = Object.assign(/* @__PURE__ */ Object.create(null), tooltip);
copy.pos = newPos;
if (copy.end != null)
copy.end = tr.changes.mapPos(copy.end);
mapped.push(copy);
}
}
value = mapped;
}
}
for (let effect of tr.effects) {
if (effect.is(setHover))
value = effect.value;
if (effect.is(closeHoverTooltipEffect))
value = [];
}
return value;
},
provide: (f) => showHoverTooltip.from(f)
});
return [
hoverState,
ViewPlugin.define((view) => new HoverPlugin(
view,
source,
hoverState,
setHover,
options.hoverTime || 300
/* Hover.Time */
)),
showHoverTooltipHost
];
}
function getTooltip(view, tooltip) {
let plugin = view.plugin(tooltipPlugin);
if (!plugin)
return null;
let found = plugin.manager.tooltips.indexOf(tooltip);
return found < 0 ? null : plugin.manager.tooltipViews[found];
}
const closeHoverTooltipEffect = /* @__PURE__ */ StateEffect.define();
const panelConfig = /* @__PURE__ */ Facet.define({
combine(configs) {
let topContainer, bottomContainer;
for (let c of configs) {
topContainer = topContainer || c.topContainer;
bottomContainer = bottomContainer || c.bottomContainer;
}
return { topContainer, bottomContainer };
}
});
function getPanel(view, panel) {
let plugin = view.plugin(panelPlugin);
let index = plugin ? plugin.specs.indexOf(panel) : -1;
return index > -1 ? plugin.panels[index] : null;
}
const panelPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
constructor(view) {
this.input = view.state.facet(showPanel);
this.specs = this.input.filter((s) => s);
this.panels = this.specs.map((spec) => spec(view));
let conf = view.state.facet(panelConfig);
this.top = new PanelGroup(view, true, conf.topContainer);
this.bottom = new PanelGroup(view, false, conf.bottomContainer);
this.top.sync(this.panels.filter((p) => p.top));
this.bottom.sync(this.panels.filter((p) => !p.top));
for (let p of this.panels) {
p.dom.classList.add("cm-panel");
if (p.mount)
p.mount();
}
}
update(update) {
let conf = update.state.facet(panelConfig);
if (this.top.container != conf.topContainer) {
this.top.sync([]);
this.top = new PanelGroup(update.view, true, conf.topContainer);
}
if (this.bottom.container != conf.bottomContainer) {
this.bottom.sync([]);
this.bottom = new PanelGroup(update.view, false, conf.bottomContainer);
}
this.top.syncClasses();
this.bottom.syncClasses();
let input = update.state.facet(showPanel);
if (input != this.input) {
let specs = input.filter((x2) => x2);
let panels = [], top2 = [], bottom = [], mount = [];
for (let spec of specs) {
let known = this.specs.indexOf(spec), panel;
if (known < 0) {
panel = spec(update.view);
mount.push(panel);
} else {
panel = this.panels[known];
if (panel.update)
panel.update(update);
}
panels.push(panel);
(panel.top ? top2 : bottom).push(panel);
}
this.specs = specs;
this.panels = panels;
this.top.sync(top2);
this.bottom.sync(bottom);
for (let p of mount) {
p.dom.classList.add("cm-panel");
if (p.mount)
p.mount();
}
} else {
for (let p of this.panels)
if (p.update)
p.update(update);
}
}
destroy() {
this.top.sync([]);
this.bottom.sync([]);
}
}, {
provide: (plugin) => EditorView.scrollMargins.of((view) => {
let value = view.plugin(plugin);
return value && { top: value.top.scrollMargin(), bottom: value.bottom.scrollMargin() };
})
});
class PanelGroup {
constructor(view, top2, container) {
this.view = view;
this.top = top2;
this.container = container;
this.dom = void 0;
this.classes = "";
this.panels = [];
this.syncClasses();
}
sync(panels) {
for (let p of this.panels)
if (p.destroy && panels.indexOf(p) < 0)
p.destroy();
this.panels = panels;
this.syncDOM();
}
syncDOM() {
if (this.panels.length == 0) {
if (this.dom) {
this.dom.remove();
this.dom = void 0;
}
return;
}
if (!this.dom) {
this.dom = document.createElement("div");
this.dom.className = this.top ? "cm-panels cm-panels-top" : "cm-panels cm-panels-bottom";
this.dom.style[this.top ? "top" : "bottom"] = "0";
let parent = this.container || this.view.dom;
parent.insertBefore(this.dom, this.top ? parent.firstChild : null);
}
let curDOM = this.dom.firstChild;
for (let panel of this.panels) {
if (panel.dom.parentNode == this.dom) {
while (curDOM != panel.dom)
curDOM = rm(curDOM);
curDOM = curDOM.nextSibling;
} else {
this.dom.insertBefore(panel.dom, curDOM);
}
}
while (curDOM)
curDOM = rm(curDOM);
}
scrollMargin() {
return !this.dom || this.container ? 0 : Math.max(0, this.top ? this.dom.getBoundingClientRect().bottom - Math.max(0, this.view.scrollDOM.getBoundingClientRect().top) : Math.min(innerHeight, this.view.scrollDOM.getBoundingClientRect().bottom) - this.dom.getBoundingClientRect().top);
}
syncClasses() {
if (!this.container || this.classes == this.view.themeClasses)
return;
for (let cls of this.classes.split(" "))
if (cls)
this.container.classList.remove(cls);
for (let cls of (this.classes = this.view.themeClasses).split(" "))
if (cls)
this.container.classList.add(cls);
}
}
function rm(node) {
let next = node.nextSibling;
node.remove();
return next;
}
const showPanel = /* @__PURE__ */ Facet.define({
enables: panelPlugin
});
class GutterMarker extends RangeValue {
/**
@internal
*/
compare(other) {
return this == other || this.constructor == other.constructor && this.eq(other);
}
/**
Compare this marker to another marker of the same type.
*/
eq(other) {
return false;
}
/**
Called if the marker has a `toDOM` method and its representation
was removed from a gutter.
*/
destroy(dom) {
}
}
GutterMarker.prototype.elementClass = "";
GutterMarker.prototype.toDOM = void 0;
GutterMarker.prototype.mapMode = MapMode.TrackBefore;
GutterMarker.prototype.startSide = GutterMarker.prototype.endSide = -1;
GutterMarker.prototype.point = true;
const gutterLineClass = /* @__PURE__ */ Facet.define();
const defaults$1 = {
class: "",
renderEmptyElements: false,
elementStyle: "",
markers: () => RangeSet.empty,
lineMarker: () => null,
widgetMarker: () => null,
lineMarkerChange: null,
initialSpacer: null,
updateSpacer: null,
domEventHandlers: {}
};
const activeGutters = /* @__PURE__ */ Facet.define();
function gutter(config2) {
return [gutters(), activeGutters.of(Object.assign(Object.assign({}, defaults$1), config2))];
}
const unfixGutters = /* @__PURE__ */ Facet.define({
combine: (values) => values.some((x2) => x2)
});
function gutters(config2) {
let result2 = [
gutterView
];
if (config2 && config2.fixed === false)
result2.push(unfixGutters.of(true));
return result2;
}
const gutterView = /* @__PURE__ */ ViewPlugin.fromClass(class {
constructor(view) {
this.view = view;
this.prevViewport = view.viewport;
this.dom = document.createElement("div");
this.dom.className = "cm-gutters";
this.dom.setAttribute("aria-hidden", "true");
this.dom.style.minHeight = this.view.contentHeight / this.view.scaleY + "px";
this.gutters = view.state.facet(activeGutters).map((conf) => new SingleGutterView(view, conf));
for (let gutter2 of this.gutters)
this.dom.appendChild(gutter2.dom);
this.fixed = !view.state.facet(unfixGutters);
if (this.fixed) {
this.dom.style.position = "sticky";
}
this.syncGutters(false);
view.scrollDOM.insertBefore(this.dom, view.contentDOM);
}
update(update) {
if (this.updateGutters(update)) {
let vpA = this.prevViewport, vpB = update.view.viewport;
let vpOverlap = Math.min(vpA.to, vpB.to) - Math.max(vpA.from, vpB.from);
this.syncGutters(vpOverlap < (vpB.to - vpB.from) * 0.8);
}
if (update.geometryChanged)
this.dom.style.minHeight = this.view.contentHeight + "px";
if (this.view.state.facet(unfixGutters) != !this.fixed) {
this.fixed = !this.fixed;
this.dom.style.position = this.fixed ? "sticky" : "";
}
this.prevViewport = update.view.viewport;
}
syncGutters(detach) {
let after = this.dom.nextSibling;
if (detach)
this.dom.remove();
let lineClasses = RangeSet.iter(this.view.state.facet(gutterLineClass), this.view.viewport.from);
let classSet = [];
let contexts = this.gutters.map((gutter2) => new UpdateContext(gutter2, this.view.viewport, -this.view.documentPadding.top));
for (let line of this.view.viewportLineBlocks) {
if (classSet.length)
classSet = [];
if (Array.isArray(line.type)) {
let first = true;
for (let b of line.type) {
if (b.type == BlockType.Text && first) {
advanceCursor(lineClasses, classSet, b.from);
for (let cx of contexts)
cx.line(this.view, b, classSet);
first = false;
} else if (b.widget) {
for (let cx of contexts)
cx.widget(this.view, b);
}
}
} else if (line.type == BlockType.Text) {
advanceCursor(lineClasses, classSet, line.from);
for (let cx of contexts)
cx.line(this.view, line, classSet);
} else if (line.widget) {
for (let cx of contexts)
cx.widget(this.view, line);
}
}
for (let cx of contexts)
cx.finish();
if (detach)
this.view.scrollDOM.insertBefore(this.dom, after);
}
updateGutters(update) {
let prev = update.startState.facet(activeGutters), cur2 = update.state.facet(activeGutters);
let change = update.docChanged || update.heightChanged || update.viewportChanged || !RangeSet.eq(update.startState.facet(gutterLineClass), update.state.facet(gutterLineClass), update.view.viewport.from, update.view.viewport.to);
if (prev == cur2) {
for (let gutter2 of this.gutters)
if (gutter2.update(update))
change = true;
} else {
change = true;
let gutters2 = [];
for (let conf of cur2) {
let known = prev.indexOf(conf);
if (known < 0) {
gutters2.push(new SingleGutterView(this.view, conf));
} else {
this.gutters[known].update(update);
gutters2.push(this.gutters[known]);
}
}
for (let g of this.gutters) {
g.dom.remove();
if (gutters2.indexOf(g) < 0)
g.destroy();
}
for (let g of gutters2)
this.dom.appendChild(g.dom);
this.gutters = gutters2;
}
return change;
}
destroy() {
for (let view of this.gutters)
view.destroy();
this.dom.remove();
}
}, {
provide: (plugin) => EditorView.scrollMargins.of((view) => {
let value = view.plugin(plugin);
if (!value || value.gutters.length == 0 || !value.fixed)
return null;
return view.textDirection == Direction.LTR ? { left: value.dom.offsetWidth * view.scaleX } : { right: value.dom.offsetWidth * view.scaleX };
})
});
function asArray(val) {
return Array.isArray(val) ? val : [val];
}
function advanceCursor(cursor, collect, pos) {
while (cursor.value && cursor.from <= pos) {
if (cursor.from == pos)
collect.push(cursor.value);
cursor.next();
}
}
class UpdateContext {
constructor(gutter2, viewport, height) {
this.gutter = gutter2;
this.height = height;
this.i = 0;
this.cursor = RangeSet.iter(gutter2.markers, viewport.from);
}
addElement(view, block, markers) {
let { gutter: gutter2 } = this, above = (block.top - this.height) / view.scaleY, height = block.height / view.scaleY;
if (this.i == gutter2.elements.length) {
let newElt = new GutterElement(view, height, above, markers);
gutter2.elements.push(newElt);
gutter2.dom.appendChild(newElt.dom);
} else {
gutter2.elements[this.i].update(view, height, above, markers);
}
this.height = block.bottom;
this.i++;
}
line(view, line, extraMarkers) {
let localMarkers = [];
advanceCursor(this.cursor, localMarkers, line.from);
if (extraMarkers.length)
localMarkers = localMarkers.concat(extraMarkers);
let forLine = this.gutter.config.lineMarker(view, line, localMarkers);
if (forLine)
localMarkers.unshift(forLine);
let gutter2 = this.gutter;
if (localMarkers.length == 0 && !gutter2.config.renderEmptyElements)
return;
this.addElement(view, line, localMarkers);
}
widget(view, block) {
let marker = this.gutter.config.widgetMarker(view, block.widget, block);
if (marker)
this.addElement(view, block, [marker]);
}
finish() {
let gutter2 = this.gutter;
while (gutter2.elements.length > this.i) {
let last = gutter2.elements.pop();
gutter2.dom.removeChild(last.dom);
last.destroy();
}
}
}
class SingleGutterView {
constructor(view, config2) {
this.view = view;
this.config = config2;
this.elements = [];
this.spacer = null;
this.dom = document.createElement("div");
this.dom.className = "cm-gutter" + (this.config.class ? " " + this.config.class : "");
for (let prop in config2.domEventHandlers) {
this.dom.addEventListener(prop, (event) => {
let target = event.target, y2;
if (target != this.dom && this.dom.contains(target)) {
while (target.parentNode != this.dom)
target = target.parentNode;
let rect = target.getBoundingClientRect();
y2 = (rect.top + rect.bottom) / 2;
} else {
y2 = event.clientY;
}
let line = view.lineBlockAtHeight(y2 - view.documentTop);
if (config2.domEventHandlers[prop](view, line, event))
event.preventDefault();
});
}
this.markers = asArray(config2.markers(view));
if (config2.initialSpacer) {
this.spacer = new GutterElement(view, 0, 0, [config2.initialSpacer(view)]);
this.dom.appendChild(this.spacer.dom);
this.spacer.dom.style.cssText += "visibility: hidden; pointer-events: none";
}
}
update(update) {
let prevMarkers = this.markers;
this.markers = asArray(this.config.markers(update.view));
if (this.spacer && this.config.updateSpacer) {
let updated = this.config.updateSpacer(this.spacer.markers[0], update);
if (updated != this.spacer.markers[0])
this.spacer.update(update.view, 0, 0, [updated]);
}
let vp = update.view.viewport;
return !RangeSet.eq(this.markers, prevMarkers, vp.from, vp.to) || (this.config.lineMarkerChange ? this.config.lineMarkerChange(update) : false);
}
destroy() {
for (let elt of this.elements)
elt.destroy();
}
}
class GutterElement {
constructor(view, height, above, markers) {
this.height = -1;
this.above = 0;
this.markers = [];
this.dom = document.createElement("div");
this.dom.className = "cm-gutterElement";
this.update(view, height, above, markers);
}
update(view, height, above, markers) {
if (this.height != height) {
this.height = height;
this.dom.style.height = height + "px";
}
if (this.above != above)
this.dom.style.marginTop = (this.above = above) ? above + "px" : "";
if (!sameMarkers(this.markers, markers))
this.setMarkers(view, markers);
}
setMarkers(view, markers) {
let cls = "cm-gutterElement", domPos = this.dom.firstChild;
for (let iNew = 0, iOld = 0; ; ) {
let skipTo = iOld, marker = iNew < markers.length ? markers[iNew++] : null, matched = false;
if (marker) {
let c = marker.elementClass;
if (c)
cls += " " + c;
for (let i2 = iOld; i2 < this.markers.length; i2++)
if (this.markers[i2].compare(marker)) {
skipTo = i2;
matched = true;
break;
}
} else {
skipTo = this.markers.length;
}
while (iOld < skipTo) {
let next = this.markers[iOld++];
if (next.toDOM) {
next.destroy(domPos);
let after = domPos.nextSibling;
domPos.remove();
domPos = after;
}
}
if (!marker)
break;
if (marker.toDOM) {
if (matched)
domPos = domPos.nextSibling;
else
this.dom.insertBefore(marker.toDOM(view), domPos);
}
if (matched)
iOld++;
}
this.dom.className = cls;
this.markers = markers;
}
destroy() {
this.setMarkers(null, []);
}
}
function sameMarkers(a, b) {
if (a.length != b.length)
return false;
for (let i2 = 0; i2 < a.length; i2++)
if (!a[i2].compare(b[i2]))
return false;
return true;
}
const lineNumberMarkers = /* @__PURE__ */ Facet.define();
const lineNumberConfig = /* @__PURE__ */ Facet.define({
combine(values) {
return combineConfig(values, { formatNumber: String, domEventHandlers: {} }, {
domEventHandlers(a, b) {
let result2 = Object.assign({}, a);
for (let event in b) {
let exists = result2[event], add2 = b[event];
result2[event] = exists ? (view, line, event2) => exists(view, line, event2) || add2(view, line, event2) : add2;
}
return result2;
}
});
}
});
class NumberMarker extends GutterMarker {
constructor(number2) {
super();
this.number = number2;
}
eq(other) {
return this.number == other.number;
}
toDOM() {
return document.createTextNode(this.number);
}
}
function formatNumber(view, number2) {
return view.state.facet(lineNumberConfig).formatNumber(number2, view.state);
}
const lineNumberGutter = /* @__PURE__ */ activeGutters.compute([lineNumberConfig], (state) => ({
class: "cm-lineNumbers",
renderEmptyElements: false,
markers(view) {
return view.state.facet(lineNumberMarkers);
},
lineMarker(view, line, others) {
if (others.some((m) => m.toDOM))
return null;
return new NumberMarker(formatNumber(view, view.state.doc.lineAt(line.from).number));
},
widgetMarker: () => null,
lineMarkerChange: (update) => update.startState.facet(lineNumberConfig) != update.state.facet(lineNumberConfig),
initialSpacer(view) {
return new NumberMarker(formatNumber(view, maxLineNumber(view.state.doc.lines)));
},
updateSpacer(spacer, update) {
let max = formatNumber(update.view, maxLineNumber(update.view.state.doc.lines));
return max == spacer.number ? spacer : new NumberMarker(max);
},
domEventHandlers: state.facet(lineNumberConfig).domEventHandlers
}));
function lineNumbers(config2 = {}) {
return [
lineNumberConfig.of(config2),
gutters(),
lineNumberGutter
];
}
function maxLineNumber(lines) {
let last = 9;
while (last < lines)
last = last * 10 + 9;
return last;
}
const activeLineGutterMarker = /* @__PURE__ */ new class extends GutterMarker {
constructor() {
super(...arguments);
this.elementClass = "cm-activeLineGutter";
}
}();
const activeLineGutterHighlighter = /* @__PURE__ */ gutterLineClass.compute(["selection"], (state) => {
let marks = [], last = -1;
for (let range of state.selection.ranges) {
let linePos = state.doc.lineAt(range.head).from;
if (linePos > last) {
last = linePos;
marks.push(activeLineGutterMarker.range(linePos));
}
}
return RangeSet.of(marks);
});
function highlightActiveLineGutter() {
return activeLineGutterHighlighter;
}
const DefaultBufferLength = 1024;
let nextPropID = 0;
class Range {
constructor(from, to) {
this.from = from;
this.to = to;
}
}
class NodeProp {
/**
Create a new node prop type.
*/
constructor(config2 = {}) {
this.id = nextPropID++;
this.perNode = !!config2.perNode;
this.deserialize = config2.deserialize || (() => {
throw new Error("This node type doesn't define a deserialize function");
});
}
/**
This is meant to be used with
[`NodeSet.extend`](#common.NodeSet.extend) or
[`LRParser.configure`](#lr.ParserConfig.props) to compute
prop values for each node type in the set. Takes a [match
object](#common.NodeType^match) or function that returns undefined
if the node type doesn't get this prop, and the prop's value if
it does.
*/
add(match2) {
if (this.perNode)
throw new RangeError("Can't add per-node props to node types");
if (typeof match2 != "function")
match2 = NodeType.match(match2);
return (type) => {
let result2 = match2(type);
return result2 === void 0 ? null : [this, result2];
};
}
}
NodeProp.closedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
NodeProp.openedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
NodeProp.group = new NodeProp({ deserialize: (str) => str.split(" ") });
NodeProp.isolate = new NodeProp({ deserialize: (value) => {
if (value && value != "rtl" && value != "ltr" && value != "auto")
throw new RangeError("Invalid value for isolate: " + value);
return value || "auto";
} });
NodeProp.contextHash = new NodeProp({ perNode: true });
NodeProp.lookAhead = new NodeProp({ perNode: true });
NodeProp.mounted = new NodeProp({ perNode: true });
class MountedTree {
constructor(tree, overlay, parser2) {
this.tree = tree;
this.overlay = overlay;
this.parser = parser2;
}
/**
@internal
*/
static get(tree) {
return tree && tree.props && tree.props[NodeProp.mounted.id];
}
}
const noProps = /* @__PURE__ */ Object.create(null);
class NodeType {
/**
@internal
*/
constructor(name2, props, id2, flags = 0) {
this.name = name2;
this.props = props;
this.id = id2;
this.flags = flags;
}
/**
Define a node type.
*/
static define(spec) {
let props = spec.props && spec.props.length ? /* @__PURE__ */ Object.create(null) : noProps;
let flags = (spec.top ? 1 : 0) | (spec.skipped ? 2 : 0) | (spec.error ? 4 : 0) | (spec.name == null ? 8 : 0);
let type = new NodeType(spec.name || "", props, spec.id, flags);
if (spec.props)
for (let src of spec.props) {
if (!Array.isArray(src))
src = src(type);
if (src) {
if (src[0].perNode)
throw new RangeError("Can't store a per-node prop on a node type");
props[src[0].id] = src[1];
}
}
return type;
}
/**
Retrieves a node prop for this type. Will return `undefined` if
the prop isn't present on this node.
*/
prop(prop) {
return this.props[prop.id];
}
/**
True when this is the top node of a grammar.
*/
get isTop() {
return (this.flags & 1) > 0;
}
/**
True when this node is produced by a skip rule.
*/
get isSkipped() {
return (this.flags & 2) > 0;
}
/**
Indicates whether this is an error node.
*/
get isError() {
return (this.flags & 4) > 0;
}
/**
When true, this node type doesn't correspond to a user-declared
named node, for example because it is used to cache repetition.
*/
get isAnonymous() {
return (this.flags & 8) > 0;
}
/**
Returns true when this node's name or one of its
[groups](#common.NodeProp^group) matches the given string.
*/
is(name2) {
if (typeof name2 == "string") {
if (this.name == name2)
return true;
let group = this.prop(NodeProp.group);
return group ? group.indexOf(name2) > -1 : false;
}
return this.id == name2;
}
/**
Create a function from node types to arbitrary values by
specifying an object whose property names are node or
[group](#common.NodeProp^group) names. Often useful with
[`NodeProp.add`](#common.NodeProp.add). You can put multiple
names, separated by spaces, in a single property name to map
multiple node names to a single value.
*/
static match(map) {
let direct = /* @__PURE__ */ Object.create(null);
for (let prop in map)
for (let name2 of prop.split(" "))
direct[name2] = map[prop];
return (node) => {
for (let groups = node.prop(NodeProp.group), i2 = -1; i2 < (groups ? groups.length : 0); i2++) {
let found = direct[i2 < 0 ? node.name : groups[i2]];
if (found)
return found;
}
};
}
}
NodeType.none = new NodeType(
"",
/* @__PURE__ */ Object.create(null),
0,
8
/* NodeFlag.Anonymous */
);
class NodeSet {
/**
Create a set with the given types. The `id` property of each
type should correspond to its position within the array.
*/
constructor(types2) {
this.types = types2;
for (let i2 = 0; i2 < types2.length; i2++)
if (types2[i2].id != i2)
throw new RangeError("Node type ids should correspond to array positions when creating a node set");
}
/**
Create a copy of this set with some node properties added. The
arguments to this method can be created with
[`NodeProp.add`](#common.NodeProp.add).
*/
extend(...props) {
let newTypes = [];
for (let type of this.types) {
let newProps = null;
for (let source of props) {
let add2 = source(type);
if (add2) {
if (!newProps)
newProps = Object.assign({}, type.props);
newProps[add2[0].id] = add2[1];
}
}
newTypes.push(newProps ? new NodeType(type.name, newProps, type.id, type.flags) : type);
}
return new NodeSet(newTypes);
}
}
const CachedNode = /* @__PURE__ */ new WeakMap(), CachedInnerNode = /* @__PURE__ */ new WeakMap();
var IterMode;
(function(IterMode2) {
IterMode2[IterMode2["ExcludeBuffers"] = 1] = "ExcludeBuffers";
IterMode2[IterMode2["IncludeAnonymous"] = 2] = "IncludeAnonymous";
IterMode2[IterMode2["IgnoreMounts"] = 4] = "IgnoreMounts";
IterMode2[IterMode2["IgnoreOverlays"] = 8] = "IgnoreOverlays";
})(IterMode || (IterMode = {}));
class Tree {
/**
Construct a new tree. See also [`Tree.build`](#common.Tree^build).
*/
constructor(type, children, positions, length, props) {
this.type = type;
this.children = children;
this.positions = positions;
this.length = length;
this.props = null;
if (props && props.length) {
this.props = /* @__PURE__ */ Object.create(null);
for (let [prop, value] of props)
this.props[typeof prop == "number" ? prop : prop.id] = value;
}
}
/**
@internal
*/
toString() {
let mounted = MountedTree.get(this);
if (mounted && !mounted.overlay)
return mounted.tree.toString();
let children = "";
for (let ch of this.children) {
let str = ch.toString();
if (str) {
if (children)
children += ",";
children += str;
}
}
return !this.type.name ? children : (/\W/.test(this.type.name) && !this.type.isError ? JSON.stringify(this.type.name) : this.type.name) + (children.length ? "(" + children + ")" : "");
}
/**
Get a [tree cursor](#common.TreeCursor) positioned at the top of
the tree. Mode can be used to [control](#common.IterMode) which
nodes the cursor visits.
*/
cursor(mode = 0) {
return new TreeCursor(this.topNode, mode);
}
/**
Get a [tree cursor](#common.TreeCursor) pointing into this tree
at the given position and side (see
[`moveTo`](#common.TreeCursor.moveTo).
*/
cursorAt(pos, side = 0, mode = 0) {
let scope = CachedNode.get(this) || this.topNode;
let cursor = new TreeCursor(scope);
cursor.moveTo(pos, side);
CachedNode.set(this, cursor._tree);
return cursor;
}
/**
Get a [syntax node](#common.SyntaxNode) object for the top of the
tree.
*/
get topNode() {
return new TreeNode(this, 0, 0, null);
}
/**
Get the [syntax node](#common.SyntaxNode) at the given position.
If `side` is -1, this will move into nodes that end at the
position. If 1, it'll move into nodes that start at the
position. With 0, it'll only enter nodes that cover the position
from both sides.
Note that this will not enter
[overlays](#common.MountedTree.overlay), and you often want
[`resolveInner`](#common.Tree.resolveInner) instead.
*/
resolve(pos, side = 0) {
let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
CachedNode.set(this, node);
return node;
}
/**
Like [`resolve`](#common.Tree.resolve), but will enter
[overlaid](#common.MountedTree.overlay) nodes, producing a syntax node
pointing into the innermost overlaid tree at the given position
(with parent links going through all parent structure, including
the host trees).
*/
resolveInner(pos, side = 0) {
let node = resolveNode(CachedInnerNode.get(this) || this.topNode, pos, side, true);
CachedInnerNode.set(this, node);
return node;
}
/**
In some situations, it can be useful to iterate through all
nodes around a position, including those in overlays that don't
directly cover the position. This method gives you an iterator
that will produce all nodes, from small to big, around the given
position.
*/
resolveStack(pos, side = 0) {
return stackIterator(this, pos, side);
}
/**
Iterate over the tree and its children, calling `enter` for any
node that touches the `from`/`to` region (if given) before
running over such a node's children, and `leave` (if given) when
leaving the node. When `enter` returns `false`, that node will
not have its children iterated over (or `leave` called).
*/
iterate(spec) {
let { enter, leave, from = 0, to = this.length } = spec;
let mode = spec.mode || 0, anon = (mode & IterMode.IncludeAnonymous) > 0;
for (let c = this.cursor(mode | IterMode.IncludeAnonymous); ; ) {
let entered = false;
if (c.from <= to && c.to >= from && (!anon && c.type.isAnonymous || enter(c) !== false)) {
if (c.firstChild())
continue;
entered = true;
}
for (; ; ) {
if (entered && leave && (anon || !c.type.isAnonymous))
leave(c);
if (c.nextSibling())
break;
if (!c.parent())
return;
entered = true;
}
}
}
/**
Get the value of the given [node prop](#common.NodeProp) for this
node. Works with both per-node and per-type props.
*/
prop(prop) {
return !prop.perNode ? this.type.prop(prop) : this.props ? this.props[prop.id] : void 0;
}
/**
Returns the node's [per-node props](#common.NodeProp.perNode) in a
format that can be passed to the [`Tree`](#common.Tree)
constructor.
*/
get propValues() {
let result2 = [];
if (this.props)
for (let id2 in this.props)
result2.push([+id2, this.props[id2]]);
return result2;
}
/**
Balance the direct children of this tree, producing a copy of
which may have children grouped into subtrees with type
[`NodeType.none`](#common.NodeType^none).
*/
balance(config2 = {}) {
return this.children.length <= 8 ? this : balanceRange(NodeType.none, this.children, this.positions, 0, this.children.length, 0, this.length, (children, positions, length) => new Tree(this.type, children, positions, length, this.propValues), config2.makeTree || ((children, positions, length) => new Tree(NodeType.none, children, positions, length)));
}
/**
Build a tree from a postfix-ordered buffer of node information,
or a cursor over such a buffer.
*/
static build(data) {
return buildTree(data);
}
}
Tree.empty = new Tree(NodeType.none, [], [], 0);
class FlatBufferCursor {
constructor(buffer, index) {
this.buffer = buffer;
this.index = index;
}
get id() {
return this.buffer[this.index - 4];
}
get start() {
return this.buffer[this.index - 3];
}
get end() {
return this.buffer[this.index - 2];
}
get size() {
return this.buffer[this.index - 1];
}
get pos() {
return this.index;
}
next() {
this.index -= 4;
}
fork() {
return new FlatBufferCursor(this.buffer, this.index);
}
}
class TreeBuffer {
/**
Create a tree buffer.
*/
constructor(buffer, length, set) {
this.buffer = buffer;
this.length = length;
this.set = set;
}
/**
@internal
*/
get type() {
return NodeType.none;
}
/**
@internal
*/
toString() {
let result2 = [];
for (let index = 0; index < this.buffer.length; ) {
result2.push(this.childString(index));
index = this.buffer[index + 3];
}
return result2.join(",");
}
/**
@internal
*/
childString(index) {
let id2 = this.buffer[index], endIndex = this.buffer[index + 3];
let type = this.set.types[id2], result2 = type.name;
if (/\W/.test(result2) && !type.isError)
result2 = JSON.stringify(result2);
index += 4;
if (endIndex == index)
return result2;
let children = [];
while (index < endIndex) {
children.push(this.childString(index));
index = this.buffer[index + 3];
}
return result2 + "(" + children.join(",") + ")";
}
/**
@internal
*/
findChild(startIndex, endIndex, dir, pos, side) {
let { buffer } = this, pick = -1;
for (let i2 = startIndex; i2 != endIndex; i2 = buffer[i2 + 3]) {
if (checkSide(side, pos, buffer[i2 + 1], buffer[i2 + 2])) {
pick = i2;
if (dir > 0)
break;
}
}
return pick;
}
/**
@internal
*/
slice(startI, endI, from) {
let b = this.buffer;
let copy = new Uint16Array(endI - startI), len = 0;
for (let i2 = startI, j2 = 0; i2 < endI; ) {
copy[j2++] = b[i2++];
copy[j2++] = b[i2++] - from;
let to = copy[j2++] = b[i2++] - from;
copy[j2++] = b[i2++] - startI;
len = Math.max(len, to);
}
return new TreeBuffer(copy, len, this.set);
}
}
function checkSide(side, pos, from, to) {
switch (side) {
case -2:
return from < pos;
case -1:
return to >= pos && from < pos;
case 0:
return from < pos && to > pos;
case 1:
return from <= pos && to > pos;
case 2:
return to > pos;
case 4:
return true;
}
}
function resolveNode(node, pos, side, overlays) {
var _a2;
while (node.from == node.to || (side < 1 ? node.from >= pos : node.from > pos) || (side > -1 ? node.to <= pos : node.to < pos)) {
let parent = !overlays && node instanceof TreeNode && node.index < 0 ? null : node.parent;
if (!parent)
return node;
node = parent;
}
let mode = overlays ? 0 : IterMode.IgnoreOverlays;
if (overlays)
for (let scan = node, parent = scan.parent; parent; scan = parent, parent = scan.parent) {
if (scan instanceof TreeNode && scan.index < 0 && ((_a2 = parent.enter(pos, side, mode)) === null || _a2 === void 0 ? void 0 : _a2.from) != scan.from)
node = parent;
}
for (; ; ) {
let inner = node.enter(pos, side, mode);
if (!inner)
return node;
node = inner;
}
}
class BaseNode {
cursor(mode = 0) {
return new TreeCursor(this, mode);
}
getChild(type, before = null, after = null) {
let r = getChildren(this, type, before, after);
return r.length ? r[0] : null;
}
getChildren(type, before = null, after = null) {
return getChildren(this, type, before, after);
}
resolve(pos, side = 0) {
return resolveNode(this, pos, side, false);
}
resolveInner(pos, side = 0) {
return resolveNode(this, pos, side, true);
}
matchContext(context) {
return matchNodeContext(this, context);
}
enterUnfinishedNodesBefore(pos) {
let scan = this.childBefore(pos), node = this;
while (scan) {
let last = scan.lastChild;
if (!last || last.to != scan.to)
break;
if (last.type.isError && last.from == last.to) {
node = scan;
scan = last.prevSibling;
} else {
scan = last;
}
}
return node;
}
get node() {
return this;
}
get next() {
return this.parent;
}
}
class TreeNode extends BaseNode {
constructor(_tree, from, index, _parent) {
super();
this._tree = _tree;
this.from = from;
this.index = index;
this._parent = _parent;
}
get type() {
return this._tree.type;
}
get name() {
return this._tree.type.name;
}
get to() {
return this.from + this._tree.length;
}
nextChild(i2, dir, pos, side, mode = 0) {
for (let parent = this; ; ) {
for (let { children, positions } = parent._tree, e = dir > 0 ? children.length : -1; i2 != e; i2 += dir) {
let next = children[i2], start = positions[i2] + parent.from;
if (!checkSide(side, pos, start, start + next.length))
continue;
if (next instanceof TreeBuffer) {
if (mode & IterMode.ExcludeBuffers)
continue;
let index = next.findChild(0, next.buffer.length, dir, pos - start, side);
if (index > -1)
return new BufferNode(new BufferContext(parent, next, i2, start), null, index);
} else if (mode & IterMode.IncludeAnonymous || (!next.type.isAnonymous || hasChild(next))) {
let mounted;
if (!(mode & IterMode.IgnoreMounts) && (mounted = MountedTree.get(next)) && !mounted.overlay)
return new TreeNode(mounted.tree, start, i2, parent);
let inner = new TreeNode(next, start, i2, parent);
return mode & IterMode.IncludeAnonymous || !inner.type.isAnonymous ? inner : inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, pos, side);
}
}
if (mode & IterMode.IncludeAnonymous || !parent.type.isAnonymous)
return null;
if (parent.index >= 0)
i2 = parent.index + dir;
else
i2 = dir < 0 ? -1 : parent._parent._tree.children.length;
parent = parent._parent;
if (!parent)
return null;
}
}
get firstChild() {
return this.nextChild(
0,
1,
0,
4
/* Side.DontCare */
);
}
get lastChild() {
return this.nextChild(
this._tree.children.length - 1,
-1,
0,
4
/* Side.DontCare */
);
}
childAfter(pos) {
return this.nextChild(
0,
1,
pos,
2
/* Side.After */
);
}
childBefore(pos) {
return this.nextChild(
this._tree.children.length - 1,
-1,
pos,
-2
/* Side.Before */
);
}
enter(pos, side, mode = 0) {
let mounted;
if (!(mode & IterMode.IgnoreOverlays) && (mounted = MountedTree.get(this._tree)) && mounted.overlay) {
let rPos = pos - this.from;
for (let { from, to } of mounted.overlay) {
if ((side > 0 ? from <= rPos : from < rPos) && (side < 0 ? to >= rPos : to > rPos))
return new TreeNode(mounted.tree, mounted.overlay[0].from + this.from, -1, this);
}
}
return this.nextChild(0, 1, pos, side, mode);
}
nextSignificantParent() {
let val = this;
while (val.type.isAnonymous && val._parent)
val = val._parent;
return val;
}
get parent() {
return this._parent ? this._parent.nextSignificantParent() : null;
}
get nextSibling() {
return this._parent && this.index >= 0 ? this._parent.nextChild(
this.index + 1,
1,
0,
4
/* Side.DontCare */
) : null;
}
get prevSibling() {
return this._parent && this.index >= 0 ? this._parent.nextChild(
this.index - 1,
-1,
0,
4
/* Side.DontCare */
) : null;
}
get tree() {
return this._tree;
}
toTree() {
return this._tree;
}
/**
@internal
*/
toString() {
return this._tree.toString();
}
}
function getChildren(node, type, before, after) {
let cur2 = node.cursor(), result2 = [];
if (!cur2.firstChild())
return result2;
if (before != null)
for (let found = false; !found; ) {
found = cur2.type.is(before);
if (!cur2.nextSibling())
return result2;
}
for (; ; ) {
if (after != null && cur2.type.is(after))
return result2;
if (cur2.type.is(type))
result2.push(cur2.node);
if (!cur2.nextSibling())
return after == null ? result2 : [];
}
}
function matchNodeContext(node, context, i2 = context.length - 1) {
for (let p = node.parent; i2 >= 0; p = p.parent) {
if (!p)
return false;
if (!p.type.isAnonymous) {
if (context[i2] && context[i2] != p.name)
return false;
i2--;
}
}
return true;
}
class BufferContext {
constructor(parent, buffer, index, start) {
this.parent = parent;
this.buffer = buffer;
this.index = index;
this.start = start;
}
}
class BufferNode extends BaseNode {
get name() {
return this.type.name;
}
get from() {
return this.context.start + this.context.buffer.buffer[this.index + 1];
}
get to() {
return this.context.start + this.context.buffer.buffer[this.index + 2];
}
constructor(context, _parent, index) {
super();
this.context = context;
this._parent = _parent;
this.index = index;
this.type = context.buffer.set.types[context.buffer.buffer[index]];
}
child(dir, pos, side) {
let { buffer } = this.context;
let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.context.start, side);
return index < 0 ? null : new BufferNode(this.context, this, index);
}
get firstChild() {
return this.child(
1,
0,
4
/* Side.DontCare */
);
}
get lastChild() {
return this.child(
-1,
0,
4
/* Side.DontCare */
);
}
childAfter(pos) {
return this.child(
1,
pos,
2
/* Side.After */
);
}
childBefore(pos) {
return this.child(
-1,
pos,
-2
/* Side.Before */
);
}
enter(pos, side, mode = 0) {
if (mode & IterMode.ExcludeBuffers)
return null;
let { buffer } = this.context;
let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], side > 0 ? 1 : -1, pos - this.context.start, side);
return index < 0 ? null : new BufferNode(this.context, this, index);
}
get parent() {
return this._parent || this.context.parent.nextSignificantParent();
}
externalSibling(dir) {
return this._parent ? null : this.context.parent.nextChild(
this.context.index + dir,
dir,
0,
4
/* Side.DontCare */
);
}
get nextSibling() {
let { buffer } = this.context;
let after = buffer.buffer[this.index + 3];
if (after < (this._parent ? buffer.buffer[this._parent.index + 3] : buffer.buffer.length))
return new BufferNode(this.context, this._parent, after);
return this.externalSibling(1);
}
get prevSibling() {
let { buffer } = this.context;
let parentStart = this._parent ? this._parent.index + 4 : 0;
if (this.index == parentStart)
return this.externalSibling(-1);
return new BufferNode(this.context, this._parent, buffer.findChild(
parentStart,
this.index,
-1,
0,
4
/* Side.DontCare */
));
}
get tree() {
return null;
}
toTree() {
let children = [], positions = [];
let { buffer } = this.context;
let startI = this.index + 4, endI = buffer.buffer[this.index + 3];
if (endI > startI) {
let from = buffer.buffer[this.index + 1];
children.push(buffer.slice(startI, endI, from));
positions.push(0);
}
return new Tree(this.type, children, positions, this.to - this.from);
}
/**
@internal
*/
toString() {
return this.context.buffer.childString(this.index);
}
}
function iterStack(heads) {
if (!heads.length)
return null;
let pick = 0, picked = heads[0];
for (let i2 = 1; i2 < heads.length; i2++) {
let node = heads[i2];
if (node.from > picked.from || node.to < picked.to) {
picked = node;
pick = i2;
}
}
let next = picked instanceof TreeNode && picked.index < 0 ? null : picked.parent;
let newHeads = heads.slice();
if (next)
newHeads[pick] = next;
else
newHeads.splice(pick, 1);
return new StackIterator(newHeads, picked);
}
class StackIterator {
constructor(heads, node) {
this.heads = heads;
this.node = node;
}
get next() {
return iterStack(this.heads);
}
}
function stackIterator(tree, pos, side) {
let inner = tree.resolveInner(pos, side), layers = null;
for (let scan = inner instanceof TreeNode ? inner : inner.context.parent; scan; scan = scan.parent) {
if (scan.index < 0) {
let parent = scan.parent;
(layers || (layers = [inner])).push(parent.resolve(pos, side));
scan = parent;
} else {
let mount = MountedTree.get(scan.tree);
if (mount && mount.overlay && mount.overlay[0].from <= pos && mount.overlay[mount.overlay.length - 1].to >= pos) {
let root = new TreeNode(mount.tree, mount.overlay[0].from + scan.from, -1, scan);
(layers || (layers = [inner])).push(resolveNode(root, pos, side, false));
}
}
}
return layers ? iterStack(layers) : inner;
}
class TreeCursor {
/**
Shorthand for `.type.name`.
*/
get name() {
return this.type.name;
}
/**
@internal
*/
constructor(node, mode = 0) {
this.mode = mode;
this.buffer = null;
this.stack = [];
this.index = 0;
this.bufferNode = null;
if (node instanceof TreeNode) {
this.yieldNode(node);
} else {
this._tree = node.context.parent;
this.buffer = node.context;
for (let n = node._parent; n; n = n._parent)
this.stack.unshift(n.index);
this.bufferNode = node;
this.yieldBuf(node.index);
}
}
yieldNode(node) {
if (!node)
return false;
this._tree = node;
this.type = node.type;
this.from = node.from;
this.to = node.to;
return true;
}
yieldBuf(index, type) {
this.index = index;
let { start, buffer } = this.buffer;
this.type = type || buffer.set.types[buffer.buffer[index]];
this.from = start + buffer.buffer[index + 1];
this.to = start + buffer.buffer[index + 2];
return true;
}
/**
@internal
*/
yield(node) {
if (!node)
return false;
if (node instanceof TreeNode) {
this.buffer = null;
return this.yieldNode(node);
}
this.buffer = node.context;
return this.yieldBuf(node.index, node.type);
}
/**
@internal
*/
toString() {
return this.buffer ? this.buffer.buffer.childString(this.index) : this._tree.toString();
}
/**
@internal
*/
enterChild(dir, pos, side) {
if (!this.buffer)
return this.yield(this._tree.nextChild(dir < 0 ? this._tree._tree.children.length - 1 : 0, dir, pos, side, this.mode));
let { buffer } = this.buffer;
let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.buffer.start, side);
if (index < 0)
return false;
this.stack.push(this.index);
return this.yieldBuf(index);
}
/**
Move the cursor to this node's first child. When this returns
false, the node has no child, and the cursor has not been moved.
*/
firstChild() {
return this.enterChild(
1,
0,
4
/* Side.DontCare */
);
}
/**
Move the cursor to this node's last child.
*/
lastChild() {
return this.enterChild(
-1,
0,
4
/* Side.DontCare */
);
}
/**
Move the cursor to the first child that ends after `pos`.
*/
childAfter(pos) {
return this.enterChild(
1,
pos,
2
/* Side.After */
);
}
/**
Move to the last child that starts before `pos`.
*/
childBefore(pos) {
return this.enterChild(
-1,
pos,
-2
/* Side.Before */
);
}
/**
Move the cursor to the child around `pos`. If side is -1 the
child may end at that position, when 1 it may start there. This
will also enter [overlaid](#common.MountedTree.overlay)
[mounted](#common.NodeProp^mounted) trees unless `overlays` is
set to false.
*/
enter(pos, side, mode = this.mode) {
if (!this.buffer)
return this.yield(this._tree.enter(pos, side, mode));
return mode & IterMode.ExcludeBuffers ? false : this.enterChild(1, pos, side);
}
/**
Move to the node's parent node, if this isn't the top node.
*/
parent() {
if (!this.buffer)
return this.yieldNode(this.mode & IterMode.IncludeAnonymous ? this._tree._parent : this._tree.parent);
if (this.stack.length)
return this.yieldBuf(this.stack.pop());
let parent = this.mode & IterMode.IncludeAnonymous ? this.buffer.parent : this.buffer.parent.nextSignificantParent();
this.buffer = null;
return this.yieldNode(parent);
}
/**
@internal
*/
sibling(dir) {
if (!this.buffer)
return !this._tree._parent ? false : this.yield(this._tree.index < 0 ? null : this._tree._parent.nextChild(this._tree.index + dir, dir, 0, 4, this.mode));
let { buffer } = this.buffer, d = this.stack.length - 1;
if (dir < 0) {
let parentStart = d < 0 ? 0 : this.stack[d] + 4;
if (this.index != parentStart)
return this.yieldBuf(buffer.findChild(
parentStart,
this.index,
-1,
0,
4
/* Side.DontCare */
));
} else {
let after = buffer.buffer[this.index + 3];
if (after < (d < 0 ? buffer.buffer.length : buffer.buffer[this.stack[d] + 3]))
return this.yieldBuf(after);
}
return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4, this.mode)) : false;
}
/**
Move to this node's next sibling, if any.
*/
nextSibling() {
return this.sibling(1);
}
/**
Move to this node's previous sibling, if any.
*/
prevSibling() {
return this.sibling(-1);
}
atLastNode(dir) {
let index, parent, { buffer } = this;
if (buffer) {
if (dir > 0) {
if (this.index < buffer.buffer.buffer.length)
return false;
} else {
for (let i2 = 0; i2 < this.index; i2++)
if (buffer.buffer.buffer[i2 + 3] < this.index)
return false;
}
({ index, parent } = buffer);
} else {
({ index, _parent: parent } = this._tree);
}
for (; parent; { index, _parent: parent } = parent) {
if (index > -1)
for (let i2 = index + dir, e = dir < 0 ? -1 : parent._tree.children.length; i2 != e; i2 += dir) {
let child = parent._tree.children[i2];
if (this.mode & IterMode.IncludeAnonymous || child instanceof TreeBuffer || !child.type.isAnonymous || hasChild(child))
return false;
}
}
return true;
}
move(dir, enter) {
if (enter && this.enterChild(
dir,
0,
4
/* Side.DontCare */
))
return true;
for (; ; ) {
if (this.sibling(dir))
return true;
if (this.atLastNode(dir) || !this.parent())
return false;
}
}
/**
Move to the next node in a
[pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
traversal, going from a node to its first child or, if the
current node is empty or `enter` is false, its next sibling or
the next sibling of the first parent node that has one.
*/
next(enter = true) {
return this.move(1, enter);
}
/**
Move to the next node in a last-to-first pre-order traveral. A
node is followed by its last child or, if it has none, its
previous sibling or the previous sibling of the first parent
node that has one.
*/
prev(enter = true) {
return this.move(-1, enter);
}
/**
Move the cursor to the innermost node that covers `pos`. If
`side` is -1, it will enter nodes that end at `pos`. If it is 1,
it will enter nodes that start at `pos`.
*/
moveTo(pos, side = 0) {
while (this.from == this.to || (side < 1 ? this.from >= pos : this.from > pos) || (side > -1 ? this.to <= pos : this.to < pos))
if (!this.parent())
break;
while (this.enterChild(1, pos, side)) {
}
return this;
}
/**
Get a [syntax node](#common.SyntaxNode) at the cursor's current
position.
*/
get node() {
if (!this.buffer)
return this._tree;
let cache2 = this.bufferNode, result2 = null, depth = 0;
if (cache2 && cache2.context == this.buffer) {
scan:
for (let index = this.index, d = this.stack.length; d >= 0; ) {
for (let c = cache2; c; c = c._parent)
if (c.index == index) {
if (index == this.index)
return c;
result2 = c;
depth = d + 1;
break scan;
}
index = this.stack[--d];
}
}
for (let i2 = depth; i2 < this.stack.length; i2++)
result2 = new BufferNode(this.buffer, result2, this.stack[i2]);
return this.bufferNode = new BufferNode(this.buffer, result2, this.index);
}
/**
Get the [tree](#common.Tree) that represents the current node, if
any. Will return null when the node is in a [tree
buffer](#common.TreeBuffer).
*/
get tree() {
return this.buffer ? null : this._tree._tree;
}
/**
Iterate over the current node and all its descendants, calling
`enter` when entering a node and `leave`, if given, when leaving
one. When `enter` returns `false`, any children of that node are
skipped, and `leave` isn't called for it.
*/
iterate(enter, leave) {
for (let depth = 0; ; ) {
let mustLeave = false;
if (this.type.isAnonymous || enter(this) !== false) {
if (this.firstChild()) {
depth++;
continue;
}
if (!this.type.isAnonymous)
mustLeave = true;
}
for (; ; ) {
if (mustLeave && leave)
leave(this);
mustLeave = this.type.isAnonymous;
if (this.nextSibling())
break;
if (!depth)
return;
this.parent();
depth--;
mustLeave = true;
}
}
}
/**
Test whether the current node matches a given context—a sequence
of direct parent node names. Empty strings in the context array
are treated as wildcards.
*/
matchContext(context) {
if (!this.buffer)
return matchNodeContext(this.node, context);
let { buffer } = this.buffer, { types: types2 } = buffer.set;
for (let i2 = context.length - 1, d = this.stack.length - 1; i2 >= 0; d--) {
if (d < 0)
return matchNodeContext(this.node, context, i2);
let type = types2[buffer.buffer[this.stack[d]]];
if (!type.isAnonymous) {
if (context[i2] && context[i2] != type.name)
return false;
i2--;
}
}
return true;
}
}
function hasChild(tree) {
return tree.children.some((ch) => ch instanceof TreeBuffer || !ch.type.isAnonymous || hasChild(ch));
}
function buildTree(data) {
var _a2;
let { buffer, nodeSet, maxBufferLength = DefaultBufferLength, reused = [], minRepeatType = nodeSet.types.length } = data;
let cursor = Array.isArray(buffer) ? new FlatBufferCursor(buffer, buffer.length) : buffer;
let types2 = nodeSet.types;
let contextHash = 0, lookAhead = 0;
function takeNode(parentStart, minPos, children2, positions2, inRepeat, depth) {
let { id: id2, start, end, size } = cursor;
let lookAheadAtStart = lookAhead;
while (size < 0) {
cursor.next();
if (size == -1) {
let node2 = reused[id2];
children2.push(node2);
positions2.push(start - parentStart);
return;
} else if (size == -3) {
contextHash = id2;
return;
} else if (size == -4) {
lookAhead = id2;
return;
} else {
throw new RangeError(`Unrecognized record size: ${size}`);
}
}
let type = types2[id2], node, buffer2;
let startPos = start - parentStart;
if (end - start <= maxBufferLength && (buffer2 = findBufferSize(cursor.pos - minPos, inRepeat))) {
let data2 = new Uint16Array(buffer2.size - buffer2.skip);
let endPos = cursor.pos - buffer2.size, index = data2.length;
while (cursor.pos > endPos)
index = copyToBuffer(buffer2.start, data2, index);
node = new TreeBuffer(data2, end - buffer2.start, nodeSet);
startPos = buffer2.start - parentStart;
} else {
let endPos = cursor.pos - size;
cursor.next();
let localChildren = [], localPositions = [];
let localInRepeat = id2 >= minRepeatType ? id2 : -1;
let lastGroup = 0, lastEnd = end;
while (cursor.pos > endPos) {
if (localInRepeat >= 0 && cursor.id == localInRepeat && cursor.size >= 0) {
if (cursor.end <= lastEnd - maxBufferLength) {
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, cursor.end, lastEnd, localInRepeat, lookAheadAtStart);
lastGroup = localChildren.length;
lastEnd = cursor.end;
}
cursor.next();
} else if (depth > 2500) {
takeFlatNode(start, endPos, localChildren, localPositions);
} else {
takeNode(start, endPos, localChildren, localPositions, localInRepeat, depth + 1);
}
}
if (localInRepeat >= 0 && lastGroup > 0 && lastGroup < localChildren.length)
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, start, lastEnd, localInRepeat, lookAheadAtStart);
localChildren.reverse();
localPositions.reverse();
if (localInRepeat > -1 && lastGroup > 0) {
let make = makeBalanced(type);
node = balanceRange(type, localChildren, localPositions, 0, localChildren.length, 0, end - start, make, make);
} else {
node = makeTree(type, localChildren, localPositions, end - start, lookAheadAtStart - end);
}
}
children2.push(node);
positions2.push(startPos);
}
function takeFlatNode(parentStart, minPos, children2, positions2) {
let nodes = [];
let nodeCount = 0, stopAt = -1;
while (cursor.pos > minPos) {
let { id: id2, start, end, size } = cursor;
if (size > 4) {
cursor.next();
} else if (stopAt > -1 && start < stopAt) {
break;
} else {
if (stopAt < 0)
stopAt = end - maxBufferLength;
nodes.push(id2, start, end);
nodeCount++;
cursor.next();
}
}
if (nodeCount) {
let buffer2 = new Uint16Array(nodeCount * 4);
let start = nodes[nodes.length - 2];
for (let i2 = nodes.length - 3, j2 = 0; i2 >= 0; i2 -= 3) {
buffer2[j2++] = nodes[i2];
buffer2[j2++] = nodes[i2 + 1] - start;
buffer2[j2++] = nodes[i2 + 2] - start;
buffer2[j2++] = j2;
}
children2.push(new TreeBuffer(buffer2, nodes[2] - start, nodeSet));
positions2.push(start - parentStart);
}
}
function makeBalanced(type) {
return (children2, positions2, length2) => {
let lookAhead2 = 0, lastI = children2.length - 1, last, lookAheadProp;
if (lastI >= 0 && (last = children2[lastI]) instanceof Tree) {
if (!lastI && last.type == type && last.length == length2)
return last;
if (lookAheadProp = last.prop(NodeProp.lookAhead))
lookAhead2 = positions2[lastI] + last.length + lookAheadProp;
}
return makeTree(type, children2, positions2, length2, lookAhead2);
};
}
function makeRepeatLeaf(children2, positions2, base2, i2, from, to, type, lookAhead2) {
let localChildren = [], localPositions = [];
while (children2.length > i2) {
localChildren.push(children2.pop());
localPositions.push(positions2.pop() + base2 - from);
}
children2.push(makeTree(nodeSet.types[type], localChildren, localPositions, to - from, lookAhead2 - to));
positions2.push(from - base2);
}
function makeTree(type, children2, positions2, length2, lookAhead2 = 0, props) {
if (contextHash) {
let pair2 = [NodeProp.contextHash, contextHash];
props = props ? [pair2].concat(props) : [pair2];
}
if (lookAhead2 > 25) {
let pair2 = [NodeProp.lookAhead, lookAhead2];
props = props ? [pair2].concat(props) : [pair2];
}
return new Tree(type, children2, positions2, length2, props);
}
function findBufferSize(maxSize, inRepeat) {
let fork = cursor.fork();
let size = 0, start = 0, skip = 0, minStart = fork.end - maxBufferLength;
let result2 = { size: 0, start: 0, skip: 0 };
scan:
for (let minPos = fork.pos - maxSize; fork.pos > minPos; ) {
let nodeSize2 = fork.size;
if (fork.id == inRepeat && nodeSize2 >= 0) {
result2.size = size;
result2.start = start;
result2.skip = skip;
skip += 4;
size += 4;
fork.next();
continue;
}
let startPos = fork.pos - nodeSize2;
if (nodeSize2 < 0 || startPos < minPos || fork.start < minStart)
break;
let localSkipped = fork.id >= minRepeatType ? 4 : 0;
let nodeStart2 = fork.start;
fork.next();
while (fork.pos > startPos) {
if (fork.size < 0) {
if (fork.size == -3)
localSkipped += 4;
else
break scan;
} else if (fork.id >= minRepeatType) {
localSkipped += 4;
}
fork.next();
}
start = nodeStart2;
size += nodeSize2;
skip += localSkipped;
}
if (inRepeat < 0 || size == maxSize) {
result2.size = size;
result2.start = start;
result2.skip = skip;
}
return result2.size > 4 ? result2 : void 0;
}
function copyToBuffer(bufferStart, buffer2, index) {
let { id: id2, start, end, size } = cursor;
cursor.next();
if (size >= 0 && id2 < minRepeatType) {
let startIndex = index;
if (size > 4) {
let endPos = cursor.pos - (size - 4);
while (cursor.pos > endPos)
index = copyToBuffer(bufferStart, buffer2, index);
}
buffer2[--index] = startIndex;
buffer2[--index] = end - bufferStart;
buffer2[--index] = start - bufferStart;
buffer2[--index] = id2;
} else if (size == -3) {
contextHash = id2;
} else if (size == -4) {
lookAhead = id2;
}
return index;
}
let children = [], positions = [];
while (cursor.pos > 0)
takeNode(data.start || 0, data.bufferStart || 0, children, positions, -1, 0);
let length = (_a2 = data.length) !== null && _a2 !== void 0 ? _a2 : children.length ? positions[0] + children[0].length : 0;
return new Tree(types2[data.topID], children.reverse(), positions.reverse(), length);
}
const nodeSizeCache = /* @__PURE__ */ new WeakMap();
function nodeSize(balanceType, node) {
if (!balanceType.isAnonymous || node instanceof TreeBuffer || node.type != balanceType)
return 1;
let size = nodeSizeCache.get(node);
if (size == null) {
size = 1;
for (let child of node.children) {
if (child.type != balanceType || !(child instanceof Tree)) {
size = 1;
break;
}
size += nodeSize(balanceType, child);
}
nodeSizeCache.set(node, size);
}
return size;
}
function balanceRange(balanceType, children, positions, from, to, start, length, mkTop, mkTree) {
let total = 0;
for (let i2 = from; i2 < to; i2++)
total += nodeSize(balanceType, children[i2]);
let maxChild = Math.ceil(
total * 1.5 / 8
/* Balance.BranchFactor */
);
let localChildren = [], localPositions = [];
function divide(children2, positions2, from2, to2, offset) {
for (let i2 = from2; i2 < to2; ) {
let groupFrom = i2, groupStart = positions2[i2], groupSize = nodeSize(balanceType, children2[i2]);
i2++;
for (; i2 < to2; i2++) {
let nextSize = nodeSize(balanceType, children2[i2]);
if (groupSize + nextSize >= maxChild)
break;
groupSize += nextSize;
}
if (i2 == groupFrom + 1) {
if (groupSize > maxChild) {
let only = children2[groupFrom];
divide(only.children, only.positions, 0, only.children.length, positions2[groupFrom] + offset);
continue;
}
localChildren.push(children2[groupFrom]);
} else {
let length2 = positions2[i2 - 1] + children2[i2 - 1].length - groupStart;
localChildren.push(balanceRange(balanceType, children2, positions2, groupFrom, i2, groupStart, length2, null, mkTree));
}
localPositions.push(groupStart + offset - start);
}
}
divide(children, positions, from, to, 0);
return (mkTop || mkTree)(localChildren, localPositions, length);
}
class NodeWeakMap {
constructor() {
this.map = /* @__PURE__ */ new WeakMap();
}
setBuffer(buffer, index, value) {
let inner = this.map.get(buffer);
if (!inner)
this.map.set(buffer, inner = /* @__PURE__ */ new Map());
inner.set(index, value);
}
getBuffer(buffer, index) {
let inner = this.map.get(buffer);
return inner && inner.get(index);
}
/**
Set the value for this syntax node.
*/
set(node, value) {
if (node instanceof BufferNode)
this.setBuffer(node.context.buffer, node.index, value);
else if (node instanceof TreeNode)
this.map.set(node.tree, value);
}
/**
Retrieve value for this syntax node, if it exists in the map.
*/
get(node) {
return node instanceof BufferNode ? this.getBuffer(node.context.buffer, node.index) : node instanceof TreeNode ? this.map.get(node.tree) : void 0;
}
/**
Set the value for the node that a cursor currently points to.
*/
cursorSet(cursor, value) {
if (cursor.buffer)
this.setBuffer(cursor.buffer.buffer, cursor.index, value);
else
this.map.set(cursor.tree, value);
}
/**
Retrieve the value for the node that a cursor currently points
to.
*/
cursorGet(cursor) {
return cursor.buffer ? this.getBuffer(cursor.buffer.buffer, cursor.index) : this.map.get(cursor.tree);
}
}
class TreeFragment {
/**
Construct a tree fragment. You'll usually want to use
[`addTree`](#common.TreeFragment^addTree) and
[`applyChanges`](#common.TreeFragment^applyChanges) instead of
calling this directly.
*/
constructor(from, to, tree, offset, openStart = false, openEnd = false) {
this.from = from;
this.to = to;
this.tree = tree;
this.offset = offset;
this.open = (openStart ? 1 : 0) | (openEnd ? 2 : 0);
}
/**
Whether the start of the fragment represents the start of a
parse, or the end of a change. (In the second case, it may not
be safe to reuse some nodes at the start, depending on the
parsing algorithm.)
*/
get openStart() {
return (this.open & 1) > 0;
}
/**
Whether the end of the fragment represents the end of a
full-document parse, or the start of a change.
*/
get openEnd() {
return (this.open & 2) > 0;
}
/**
Create a set of fragments from a freshly parsed tree, or update
an existing set of fragments by replacing the ones that overlap
with a tree with content from the new tree. When `partial` is
true, the parse is treated as incomplete, and the resulting
fragment has [`openEnd`](#common.TreeFragment.openEnd) set to
true.
*/
static addTree(tree, fragments = [], partial = false) {
let result2 = [new TreeFragment(0, tree.length, tree, 0, false, partial)];
for (let f of fragments)
if (f.to > tree.length)
result2.push(f);
return result2;
}
/**
Apply a set of edits to an array of fragments, removing or
splitting fragments as necessary to remove edited ranges, and
adjusting offsets for fragments that moved.
*/
static applyChanges(fragments, changes, minGap = 128) {
if (!changes.length)
return fragments;
let result2 = [];
let fI = 1, nextF = fragments.length ? fragments[0] : null;
for (let cI = 0, pos = 0, off = 0; ; cI++) {
let nextC = cI < changes.length ? changes[cI] : null;
let nextPos = nextC ? nextC.fromA : 1e9;
if (nextPos - pos >= minGap)
while (nextF && nextF.from < nextPos) {
let cut = nextF;
if (pos >= cut.from || nextPos <= cut.to || off) {
let fFrom = Math.max(cut.from, pos) - off, fTo = Math.min(cut.to, nextPos) - off;
cut = fFrom >= fTo ? null : new TreeFragment(fFrom, fTo, cut.tree, cut.offset + off, cI > 0, !!nextC);
}
if (cut)
result2.push(cut);
if (nextF.to > nextPos)
break;
nextF = fI < fragments.length ? fragments[fI++] : null;
}
if (!nextC)
break;
pos = nextC.toA;
off = nextC.toA - nextC.toB;
}
return result2;
}
}
class Parser {
/**
Start a parse, returning a [partial parse](#common.PartialParse)
object. [`fragments`](#common.TreeFragment) can be passed in to
make the parse incremental.
By default, the entire input is parsed. You can pass `ranges`,
which should be a sorted array of non-empty, non-overlapping
ranges, to parse only those ranges. The tree returned in that
case will start at `ranges[0].from`.
*/
startParse(input, fragments, ranges) {
if (typeof input == "string")
input = new StringInput(input);
ranges = !ranges ? [new Range(0, input.length)] : ranges.length ? ranges.map((r) => new Range(r.from, r.to)) : [new Range(0, 0)];
return this.createParse(input, fragments || [], ranges);
}
/**
Run a full parse, returning the resulting tree.
*/
parse(input, fragments, ranges) {
let parse = this.startParse(input, fragments, ranges);
for (; ; ) {
let done = parse.advance();
if (done)
return done;
}
}
}
class StringInput {
constructor(string2) {
this.string = string2;
}
get length() {
return this.string.length;
}
chunk(from) {
return this.string.slice(from);
}
get lineChunks() {
return false;
}
read(from, to) {
return this.string.slice(from, to);
}
}
new NodeProp({ perNode: true });
let nextTagID = 0;
class Tag {
/**
@internal
*/
constructor(set, base2, modified) {
this.set = set;
this.base = base2;
this.modified = modified;
this.id = nextTagID++;
}
/**
Define a new tag. If `parent` is given, the tag is treated as a
sub-tag of that parent, and
[highlighters](#highlight.tagHighlighter) that don't mention
this tag will try to fall back to the parent tag (or grandparent
tag, etc).
*/
static define(parent) {
if (parent === null || parent === void 0 ? void 0 : parent.base)
throw new Error("Can not derive from a modified tag");
let tag = new Tag([], null, []);
tag.set.push(tag);
if (parent)
for (let t2 of parent.set)
tag.set.push(t2);
return tag;
}
/**
Define a tag _modifier_, which is a function that, given a tag,
will return a tag that is a subtag of the original. Applying the
same modifier to a twice tag will return the same value (`m1(t1)
== m1(t1)`) and applying multiple modifiers will, regardless or
order, produce the same tag (`m1(m2(t1)) == m2(m1(t1))`).
When multiple modifiers are applied to a given base tag, each
smaller set of modifiers is registered as a parent, so that for
example `m1(m2(m3(t1)))` is a subtype of `m1(m2(t1))`,
`m1(m3(t1)`, and so on.
*/
static defineModifier() {
let mod = new Modifier();
return (tag) => {
if (tag.modified.indexOf(mod) > -1)
return tag;
return Modifier.get(tag.base || tag, tag.modified.concat(mod).sort((a, b) => a.id - b.id));
};
}
}
let nextModifierID = 0;
class Modifier {
constructor() {
this.instances = [];
this.id = nextModifierID++;
}
static get(base2, mods) {
if (!mods.length)
return base2;
let exists = mods[0].instances.find((t2) => t2.base == base2 && sameArray(mods, t2.modified));
if (exists)
return exists;
let set = [], tag = new Tag(set, base2, mods);
for (let m of mods)
m.instances.push(tag);
let configs = powerSet(mods);
for (let parent of base2.set)
if (!parent.modified.length)
for (let config2 of configs)
set.push(Modifier.get(parent, config2));
return tag;
}
}
function sameArray(a, b) {
return a.length == b.length && a.every((x2, i2) => x2 == b[i2]);
}
function powerSet(array) {
let sets = [[]];
for (let i2 = 0; i2 < array.length; i2++) {
for (let j2 = 0, e = sets.length; j2 < e; j2++) {
sets.push(sets[j2].concat(array[i2]));
}
}
return sets.sort((a, b) => b.length - a.length);
}
function styleTags(spec) {
let byName = /* @__PURE__ */ Object.create(null);
for (let prop in spec) {
let tags2 = spec[prop];
if (!Array.isArray(tags2))
tags2 = [tags2];
for (let part of prop.split(" "))
if (part) {
let pieces = [], mode = 2, rest = part;
for (let pos = 0; ; ) {
if (rest == "..." && pos > 0 && pos + 3 == part.length) {
mode = 1;
break;
}
let m = /^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(rest);
if (!m)
throw new RangeError("Invalid path: " + part);
pieces.push(m[0] == "*" ? "" : m[0][0] == '"' ? JSON.parse(m[0]) : m[0]);
pos += m[0].length;
if (pos == part.length)
break;
let next = part[pos++];
if (pos == part.length && next == "!") {
mode = 0;
break;
}
if (next != "/")
throw new RangeError("Invalid path: " + part);
rest = part.slice(pos);
}
let last = pieces.length - 1, inner = pieces[last];
if (!inner)
throw new RangeError("Invalid path: " + part);
let rule = new Rule(tags2, mode, last > 0 ? pieces.slice(0, last) : null);
byName[inner] = rule.sort(byName[inner]);
}
}
return ruleNodeProp.add(byName);
}
const ruleNodeProp = new NodeProp();
class Rule {
constructor(tags2, mode, context, next) {
this.tags = tags2;
this.mode = mode;
this.context = context;
this.next = next;
}
get opaque() {
return this.mode == 0;
}
get inherit() {
return this.mode == 1;
}
sort(other) {
if (!other || other.depth < this.depth) {
this.next = other;
return this;
}
other.next = this.sort(other.next);
return other;
}
get depth() {
return this.context ? this.context.length : 0;
}
}
Rule.empty = new Rule([], 2, null);
function tagHighlighter(tags2, options) {
let map = /* @__PURE__ */ Object.create(null);
for (let style of tags2) {
if (!Array.isArray(style.tag))
map[style.tag.id] = style.class;
else
for (let tag of style.tag)
map[tag.id] = style.class;
}
let { scope, all = null } = options || {};
return {
style: (tags3) => {
let cls = all;
for (let tag of tags3) {
for (let sub of tag.set) {
let tagClass = map[sub.id];
if (tagClass) {
cls = cls ? cls + " " + tagClass : tagClass;
break;
}
}
}
return cls;
},
scope
};
}
function highlightTags(highlighters, tags2) {
let result2 = null;
for (let highlighter of highlighters) {
let value = highlighter.style(tags2);
if (value)
result2 = result2 ? result2 + " " + value : value;
}
return result2;
}
function highlightTree(tree, highlighter, putStyle, from = 0, to = tree.length) {
let builder = new HighlightBuilder(from, Array.isArray(highlighter) ? highlighter : [highlighter], putStyle);
builder.highlightRange(tree.cursor(), from, to, "", builder.highlighters);
builder.flush(to);
}
class HighlightBuilder {
constructor(at, highlighters, span) {
this.at = at;
this.highlighters = highlighters;
this.span = span;
this.class = "";
}
startSpan(at, cls) {
if (cls != this.class) {
this.flush(at);
if (at > this.at)
this.at = at;
this.class = cls;
}
}
flush(to) {
if (to > this.at && this.class)
this.span(this.at, to, this.class);
}
highlightRange(cursor, from, to, inheritedClass, highlighters) {
let { type, from: start, to: end } = cursor;
if (start >= to || end <= from)
return;
if (type.isTop)
highlighters = this.highlighters.filter((h2) => !h2.scope || h2.scope(type));
let cls = inheritedClass;
let rule = getStyleTags(cursor) || Rule.empty;
let tagCls = highlightTags(highlighters, rule.tags);
if (tagCls) {
if (cls)
cls += " ";
cls += tagCls;
if (rule.mode == 1)
inheritedClass += (inheritedClass ? " " : "") + tagCls;
}
this.startSpan(Math.max(from, start), cls);
if (rule.opaque)
return;
let mounted = cursor.tree && cursor.tree.prop(NodeProp.mounted);
if (mounted && mounted.overlay) {
let inner = cursor.node.enter(mounted.overlay[0].from + start, 1);
let innerHighlighters = this.highlighters.filter((h2) => !h2.scope || h2.scope(mounted.tree.type));
let hasChild2 = cursor.firstChild();
for (let i2 = 0, pos = start; ; i2++) {
let next = i2 < mounted.overlay.length ? mounted.overlay[i2] : null;
let nextPos = next ? next.from + start : end;
let rangeFrom = Math.max(from, pos), rangeTo = Math.min(to, nextPos);
if (rangeFrom < rangeTo && hasChild2) {
while (cursor.from < rangeTo) {
this.highlightRange(cursor, rangeFrom, rangeTo, inheritedClass, highlighters);
this.startSpan(Math.min(rangeTo, cursor.to), cls);
if (cursor.to >= nextPos || !cursor.nextSibling())
break;
}
}
if (!next || nextPos > to)
break;
pos = next.to + start;
if (pos > from) {
this.highlightRange(inner.cursor(), Math.max(from, next.from + start), Math.min(to, pos), "", innerHighlighters);
this.startSpan(Math.min(to, pos), cls);
}
}
if (hasChild2)
cursor.parent();
} else if (cursor.firstChild()) {
if (mounted)
inheritedClass = "";
do {
if (cursor.to <= from)
continue;
if (cursor.from >= to)
break;
this.highlightRange(cursor, from, to, inheritedClass, highlighters);
this.startSpan(Math.min(to, cursor.to), cls);
} while (cursor.nextSibling());
cursor.parent();
}
}
}
function getStyleTags(node) {
let rule = node.type.prop(ruleNodeProp);
while (rule && rule.context && !node.matchContext(rule.context))
rule = rule.next;
return rule || null;
}
const t = Tag.define;
const comment = t(), name = t(), typeName = t(name), propertyName = t(name), literal = t(), string = t(literal), number = t(literal), content = t(), heading = t(content), keyword = t(), operator = t(), punctuation = t(), bracket = t(punctuation), meta = t();
const tags = {
/**
A comment.
*/
comment,
/**
A line [comment](#highlight.tags.comment).
*/
lineComment: t(comment),
/**
A block [comment](#highlight.tags.comment).
*/
blockComment: t(comment),
/**
A documentation [comment](#highlight.tags.comment).
*/
docComment: t(comment),
/**
Any kind of identifier.
*/
name,
/**
The [name](#highlight.tags.name) of a variable.
*/
variableName: t(name),
/**
A type [name](#highlight.tags.name).
*/
typeName,
/**
A tag name (subtag of [`typeName`](#highlight.tags.typeName)).
*/
tagName: t(typeName),
/**
A property or field [name](#highlight.tags.name).
*/
propertyName,
/**
An attribute name (subtag of [`propertyName`](#highlight.tags.propertyName)).
*/
attributeName: t(propertyName),
/**
The [name](#highlight.tags.name) of a class.
*/
className: t(name),
/**
A label [name](#highlight.tags.name).
*/
labelName: t(name),
/**
A namespace [name](#highlight.tags.name).
*/
namespace: t(name),
/**
The [name](#highlight.tags.name) of a macro.
*/
macroName: t(name),
/**
A literal value.
*/
literal,
/**
A string [literal](#highlight.tags.literal).
*/
string,
/**
A documentation [string](#highlight.tags.string).
*/
docString: t(string),
/**
A character literal (subtag of [string](#highlight.tags.string)).
*/
character: t(string),
/**
An attribute value (subtag of [string](#highlight.tags.string)).
*/
attributeValue: t(string),
/**
A number [literal](#highlight.tags.literal).
*/
number,
/**
An integer [number](#highlight.tags.number) literal.
*/
integer: t(number),
/**
A floating-point [number](#highlight.tags.number) literal.
*/
float: t(number),
/**
A boolean [literal](#highlight.tags.literal).
*/
bool: t(literal),
/**
Regular expression [literal](#highlight.tags.literal).
*/
regexp: t(literal),
/**
An escape [literal](#highlight.tags.literal), for example a
backslash escape in a string.
*/
escape: t(literal),
/**
A color [literal](#highlight.tags.literal).
*/
color: t(literal),
/**
A URL [literal](#highlight.tags.literal).
*/
url: t(literal),
/**
A language keyword.
*/
keyword,
/**
The [keyword](#highlight.tags.keyword) for the self or this
object.
*/
self: t(keyword),
/**
The [keyword](#highlight.tags.keyword) for null.
*/
null: t(keyword),
/**
A [keyword](#highlight.tags.keyword) denoting some atomic value.
*/
atom: t(keyword),
/**
A [keyword](#highlight.tags.keyword) that represents a unit.
*/
unit: t(keyword),
/**
A modifier [keyword](#highlight.tags.keyword).
*/
modifier: t(keyword),
/**
A [keyword](#highlight.tags.keyword) that acts as an operator.
*/
operatorKeyword: t(keyword),
/**
A control-flow related [keyword](#highlight.tags.keyword).
*/
controlKeyword: t(keyword),
/**
A [keyword](#highlight.tags.keyword) that defines something.
*/
definitionKeyword: t(keyword),
/**
A [keyword](#highlight.tags.keyword) related to defining or
interfacing with modules.
*/
moduleKeyword: t(keyword),
/**
An operator.
*/
operator,
/**
An [operator](#highlight.tags.operator) that dereferences something.
*/
derefOperator: t(operator),
/**
Arithmetic-related [operator](#highlight.tags.operator).
*/
arithmeticOperator: t(operator),
/**
Logical [operator](#highlight.tags.operator).
*/
logicOperator: t(operator),
/**
Bit [operator](#highlight.tags.operator).
*/
bitwiseOperator: t(operator),
/**
Comparison [operator](#highlight.tags.operator).
*/
compareOperator: t(operator),
/**
[Operator](#highlight.tags.operator) that updates its operand.
*/
updateOperator: t(operator),
/**
[Operator](#highlight.tags.operator) that defines something.
*/
definitionOperator: t(operator),
/**
Type-related [operator](#highlight.tags.operator).
*/
typeOperator: t(operator),
/**
Control-flow [operator](#highlight.tags.operator).
*/
controlOperator: t(operator),
/**
Program or markup punctuation.
*/
punctuation,
/**
[Punctuation](#highlight.tags.punctuation) that separates
things.
*/
separator: t(punctuation),
/**
Bracket-style [punctuation](#highlight.tags.punctuation).
*/
bracket,
/**
Angle [brackets](#highlight.tags.bracket) (usually `<` and `>`
tokens).
*/
angleBracket: t(bracket),
/**
Square [brackets](#highlight.tags.bracket) (usually `[` and `]`
tokens).
*/
squareBracket: t(bracket),
/**
Parentheses (usually `(` and `)` tokens). Subtag of
[bracket](#highlight.tags.bracket).
*/
paren: t(bracket),
/**
Braces (usually `{` and `}` tokens). Subtag of
[bracket](#highlight.tags.bracket).
*/
brace: t(bracket),
/**
Content, for example plain text in XML or markup documents.
*/
content,
/**
[Content](#highlight.tags.content) that represents a heading.
*/
heading,
/**
A level 1 [heading](#highlight.tags.heading).
*/
heading1: t(heading),
/**
A level 2 [heading](#highlight.tags.heading).
*/
heading2: t(heading),
/**
A level 3 [heading](#highlight.tags.heading).
*/
heading3: t(heading),
/**
A level 4 [heading](#highlight.tags.heading).
*/
heading4: t(heading),
/**
A level 5 [heading](#highlight.tags.heading).
*/
heading5: t(heading),
/**
A level 6 [heading](#highlight.tags.heading).
*/
heading6: t(heading),
/**
A prose separator (such as a horizontal rule).
*/
contentSeparator: t(content),
/**
[Content](#highlight.tags.content) that represents a list.
*/
list: t(content),
/**
[Content](#highlight.tags.content) that represents a quote.
*/
quote: t(content),
/**
[Content](#highlight.tags.content) that is emphasized.
*/
emphasis: t(content),
/**
[Content](#highlight.tags.content) that is styled strong.
*/
strong: t(content),
/**
[Content](#highlight.tags.content) that is part of a link.
*/
link: t(content),
/**
[Content](#highlight.tags.content) that is styled as code or
monospace.
*/
monospace: t(content),
/**
[Content](#highlight.tags.content) that has a strike-through
style.
*/
strikethrough: t(content),
/**
Inserted text in a change-tracking format.
*/
inserted: t(),
/**
Deleted text.
*/
deleted: t(),
/**
Changed text.
*/
changed: t(),
/**
An invalid or unsyntactic element.
*/
invalid: t(),
/**
Metadata or meta-instruction.
*/
meta,
/**
[Metadata](#highlight.tags.meta) that applies to the entire
document.
*/
documentMeta: t(meta),
/**
[Metadata](#highlight.tags.meta) that annotates or adds
attributes to a given syntactic element.
*/
annotation: t(meta),
/**
Processing instruction or preprocessor directive. Subtag of
[meta](#highlight.tags.meta).
*/
processingInstruction: t(meta),
/**
[Modifier](#highlight.Tag^defineModifier) that indicates that a
given element is being defined. Expected to be used with the
various [name](#highlight.tags.name) tags.
*/
definition: Tag.defineModifier(),
/**
[Modifier](#highlight.Tag^defineModifier) that indicates that
something is constant. Mostly expected to be used with
[variable names](#highlight.tags.variableName).
*/
constant: Tag.defineModifier(),
/**
[Modifier](#highlight.Tag^defineModifier) used to indicate that
a [variable](#highlight.tags.variableName) or [property
name](#highlight.tags.propertyName) is being called or defined
as a function.
*/
function: Tag.defineModifier(),
/**
[Modifier](#highlight.Tag^defineModifier) that can be applied to
[names](#highlight.tags.name) to indicate that they belong to
the language's standard environment.
*/
standard: Tag.defineModifier(),
/**
[Modifier](#highlight.Tag^defineModifier) that indicates a given
[names](#highlight.tags.name) is local to some scope.
*/
local: Tag.defineModifier(),
/**
A generic variant [modifier](#highlight.Tag^defineModifier) that
can be used to tag language-specific alternative variants of
some common tag. It is recommended for themes to define special
forms of at least the [string](#highlight.tags.string) and
[variable name](#highlight.tags.variableName) tags, since those
come up a lot.
*/
special: Tag.defineModifier()
};
tagHighlighter([
{ tag: tags.link, class: "tok-link" },
{ tag: tags.heading, class: "tok-heading" },
{ tag: tags.emphasis, class: "tok-emphasis" },
{ tag: tags.strong, class: "tok-strong" },
{ tag: tags.keyword, class: "tok-keyword" },
{ tag: tags.atom, class: "tok-atom" },
{ tag: tags.bool, class: "tok-bool" },
{ tag: tags.url, class: "tok-url" },
{ tag: tags.labelName, class: "tok-labelName" },
{ tag: tags.inserted, class: "tok-inserted" },
{ tag: tags.deleted, class: "tok-deleted" },
{ tag: tags.literal, class: "tok-literal" },
{ tag: tags.string, class: "tok-string" },
{ tag: tags.number, class: "tok-number" },
{ tag: [tags.regexp, tags.escape, tags.special(tags.string)], class: "tok-string2" },
{ tag: tags.variableName, class: "tok-variableName" },
{ tag: tags.local(tags.variableName), class: "tok-variableName tok-local" },
{ tag: tags.definition(tags.variableName), class: "tok-variableName tok-definition" },
{ tag: tags.special(tags.variableName), class: "tok-variableName2" },
{ tag: tags.definition(tags.propertyName), class: "tok-propertyName tok-definition" },
{ tag: tags.typeName, class: "tok-typeName" },
{ tag: tags.namespace, class: "tok-namespace" },
{ tag: tags.className, class: "tok-className" },
{ tag: tags.macroName, class: "tok-macroName" },
{ tag: tags.propertyName, class: "tok-propertyName" },
{ tag: tags.operator, class: "tok-operator" },
{ tag: tags.comment, class: "tok-comment" },
{ tag: tags.meta, class: "tok-meta" },
{ tag: tags.invalid, class: "tok-invalid" },
{ tag: tags.punctuation, class: "tok-punctuation" }
]);
var _a;
const languageDataProp = /* @__PURE__ */ new NodeProp();
function defineLanguageFacet(baseData) {
return Facet.define({
combine: baseData ? (values) => values.concat(baseData) : void 0
});
}
const sublanguageProp = /* @__PURE__ */ new NodeProp();
class Language {
/**
Construct a language object. If you need to invoke this
directly, first define a data facet with
[`defineLanguageFacet`](https://codemirror.net/6/docs/ref/#language.defineLanguageFacet), and then
configure your parser to [attach](https://codemirror.net/6/docs/ref/#language.languageDataProp) it
to the language's outer syntax node.
*/
constructor(data, parser2, extraExtensions = [], name2 = "") {
this.data = data;
this.name = name2;
if (!EditorState.prototype.hasOwnProperty("tree"))
Object.defineProperty(EditorState.prototype, "tree", { get() {
return syntaxTree(this);
} });
this.parser = parser2;
this.extension = [
language.of(this),
EditorState.languageData.of((state, pos, side) => {
let top2 = topNodeAt(state, pos, side), data2 = top2.type.prop(languageDataProp);
if (!data2)
return [];
let base2 = state.facet(data2), sub = top2.type.prop(sublanguageProp);
if (sub) {
let innerNode = top2.resolve(pos - top2.from, side);
for (let sublang of sub)
if (sublang.test(innerNode, state)) {
let data3 = state.facet(sublang.facet);
return sublang.type == "replace" ? data3 : data3.concat(base2);
}
}
return base2;
})
].concat(extraExtensions);
}
/**
Query whether this language is active at the given position.
*/
isActiveAt(state, pos, side = -1) {
return topNodeAt(state, pos, side).type.prop(languageDataProp) == this.data;
}
/**
Find the document regions that were parsed using this language.
The returned regions will _include_ any nested languages rooted
in this language, when those exist.
*/
findRegions(state) {
let lang = state.facet(language);
if ((lang === null || lang === void 0 ? void 0 : lang.data) == this.data)
return [{ from: 0, to: state.doc.length }];
if (!lang || !lang.allowsNesting)
return [];
let result2 = [];
let explore = (tree, from) => {
if (tree.prop(languageDataProp) == this.data) {
result2.push({ from, to: from + tree.length });
return;
}
let mount = tree.prop(NodeProp.mounted);
if (mount) {
if (mount.tree.prop(languageDataProp) == this.data) {
if (mount.overlay)
for (let r of mount.overlay)
result2.push({ from: r.from + from, to: r.to + from });
else
result2.push({ from, to: from + tree.length });
return;
} else if (mount.overlay) {
let size = result2.length;
explore(mount.tree, mount.overlay[0].from + from);
if (result2.length > size)
return;
}
}
for (let i2 = 0; i2 < tree.children.length; i2++) {
let ch = tree.children[i2];
if (ch instanceof Tree)
explore(ch, tree.positions[i2] + from);
}
};
explore(syntaxTree(state), 0);
return result2;
}
/**
Indicates whether this language allows nested languages. The
default implementation returns true.
*/
get allowsNesting() {
return true;
}
}
Language.setState = /* @__PURE__ */ StateEffect.define();
function topNodeAt(state, pos, side) {
let topLang = state.facet(language), tree = syntaxTree(state).topNode;
if (!topLang || topLang.allowsNesting) {
for (let node = tree; node; node = node.enter(pos, side, IterMode.ExcludeBuffers))
if (node.type.isTop)
tree = node;
}
return tree;
}
class LRLanguage extends Language {
constructor(data, parser2, name2) {
super(data, parser2, [], name2);
this.parser = parser2;
}
/**
Define a language from a parser.
*/
static define(spec) {
let data = defineLanguageFacet(spec.languageData);
return new LRLanguage(data, spec.parser.configure({
props: [languageDataProp.add((type) => type.isTop ? data : void 0)]
}), spec.name);
}
/**
Create a new instance of this language with a reconfigured
version of its parser and optionally a new name.
*/
configure(options, name2) {
return new LRLanguage(this.data, this.parser.configure(options), name2 || this.name);
}
get allowsNesting() {
return this.parser.hasWrappers();
}
}
function syntaxTree(state) {
let field = state.field(Language.state, false);
return field ? field.tree : Tree.empty;
}
class DocInput {
/**
Create an input object for the given document.
*/
constructor(doc2) {
this.doc = doc2;
this.cursorPos = 0;
this.string = "";
this.cursor = doc2.iter();
}
get length() {
return this.doc.length;
}
syncTo(pos) {
this.string = this.cursor.next(pos - this.cursorPos).value;
this.cursorPos = pos + this.string.length;
return this.cursorPos - this.string.length;
}
chunk(pos) {
this.syncTo(pos);
return this.string;
}
get lineChunks() {
return true;
}
read(from, to) {
let stringStart = this.cursorPos - this.string.length;
if (from < stringStart || to >= this.cursorPos)
return this.doc.sliceString(from, to);
else
return this.string.slice(from - stringStart, to - stringStart);
}
}
let currentContext = null;
class ParseContext {
constructor(parser2, state, fragments = [], tree, treeLen, viewport, skipped, scheduleOn) {
this.parser = parser2;
this.state = state;
this.fragments = fragments;
this.tree = tree;
this.treeLen = treeLen;
this.viewport = viewport;
this.skipped = skipped;
this.scheduleOn = scheduleOn;
this.parse = null;
this.tempSkipped = [];
}
/**
@internal
*/
static create(parser2, state, viewport) {
return new ParseContext(parser2, state, [], Tree.empty, 0, viewport, [], null);
}
startParse() {
return this.parser.startParse(new DocInput(this.state.doc), this.fragments);
}
/**
@internal
*/
work(until, upto) {
if (upto != null && upto >= this.state.doc.length)
upto = void 0;
if (this.tree != Tree.empty && this.isDone(upto !== null && upto !== void 0 ? upto : this.state.doc.length)) {
this.takeTree();
return true;
}
return this.withContext(() => {
var _a2;
if (typeof until == "number") {
let endTime = Date.now() + until;
until = () => Date.now() > endTime;
}
if (!this.parse)
this.parse = this.startParse();
if (upto != null && (this.parse.stoppedAt == null || this.parse.stoppedAt > upto) && upto < this.state.doc.length)
this.parse.stopAt(upto);
for (; ; ) {
let done = this.parse.advance();
if (done) {
this.fragments = this.withoutTempSkipped(TreeFragment.addTree(done, this.fragments, this.parse.stoppedAt != null));
this.treeLen = (_a2 = this.parse.stoppedAt) !== null && _a2 !== void 0 ? _a2 : this.state.doc.length;
this.tree = done;
this.parse = null;
if (this.treeLen < (upto !== null && upto !== void 0 ? upto : this.state.doc.length))
this.parse = this.startParse();
else
return true;
}
if (until())
return false;
}
});
}
/**
@internal
*/
takeTree() {
let pos, tree;
if (this.parse && (pos = this.parse.parsedPos) >= this.treeLen) {
if (this.parse.stoppedAt == null || this.parse.stoppedAt > pos)
this.parse.stopAt(pos);
this.withContext(() => {
while (!(tree = this.parse.advance())) {
}
});
this.treeLen = pos;
this.tree = tree;
this.fragments = this.withoutTempSkipped(TreeFragment.addTree(this.tree, this.fragments, true));
this.parse = null;
}
}
withContext(f) {
let prev = currentContext;
currentContext = this;
try {
return f();
} finally {
currentContext = prev;
}
}
withoutTempSkipped(fragments) {
for (let r; r = this.tempSkipped.pop(); )
fragments = cutFragments(fragments, r.from, r.to);
return fragments;
}
/**
@internal
*/
changes(changes, newState) {
let { fragments, tree, treeLen, viewport, skipped } = this;
this.takeTree();
if (!changes.empty) {
let ranges = [];
changes.iterChangedRanges((fromA, toA, fromB, toB) => ranges.push({ fromA, toA, fromB, toB }));
fragments = TreeFragment.applyChanges(fragments, ranges);
tree = Tree.empty;
treeLen = 0;
viewport = { from: changes.mapPos(viewport.from, -1), to: changes.mapPos(viewport.to, 1) };
if (this.skipped.length) {
skipped = [];
for (let r of this.skipped) {
let from = changes.mapPos(r.from, 1), to = changes.mapPos(r.to, -1);
if (from < to)
skipped.push({ from, to });
}
}
}
return new ParseContext(this.parser, newState, fragments, tree, treeLen, viewport, skipped, this.scheduleOn);
}
/**
@internal
*/
updateViewport(viewport) {
if (this.viewport.from == viewport.from && this.viewport.to == viewport.to)
return false;
this.viewport = viewport;
let startLen = this.skipped.length;
for (let i2 = 0; i2 < this.skipped.length; i2++) {
let { from, to } = this.skipped[i2];
if (from < viewport.to && to > viewport.from) {
this.fragments = cutFragments(this.fragments, from, to);
this.skipped.splice(i2--, 1);
}
}
if (this.skipped.length >= startLen)
return false;
this.reset();
return true;
}
/**
@internal
*/
reset() {
if (this.parse) {
this.takeTree();
this.parse = null;
}
}
/**
Notify the parse scheduler that the given region was skipped
because it wasn't in view, and the parse should be restarted
when it comes into view.
*/
skipUntilInView(from, to) {
this.skipped.push({ from, to });
}
/**
Returns a parser intended to be used as placeholder when
asynchronously loading a nested parser. It'll skip its input and
mark it as not-really-parsed, so that the next update will parse
it again.
When `until` is given, a reparse will be scheduled when that
promise resolves.
*/
static getSkippingParser(until) {
return new class extends Parser {
createParse(input, fragments, ranges) {
let from = ranges[0].from, to = ranges[ranges.length - 1].to;
let parser2 = {
parsedPos: from,
advance() {
let cx = currentContext;
if (cx) {
for (let r of ranges)
cx.tempSkipped.push(r);
if (until)
cx.scheduleOn = cx.scheduleOn ? Promise.all([cx.scheduleOn, until]) : until;
}
this.parsedPos = to;
return new Tree(NodeType.none, [], [], to - from);
},
stoppedAt: null,
stopAt() {
}
};
return parser2;
}
}();
}
/**
@internal
*/
isDone(upto) {
upto = Math.min(upto, this.state.doc.length);
let frags = this.fragments;
return this.treeLen >= upto && frags.length && frags[0].from == 0 && frags[0].to >= upto;
}
/**
Get the context for the current parse, or `null` if no editor
parse is in progress.
*/
static get() {
return currentContext;
}
}
function cutFragments(fragments, from, to) {
return TreeFragment.applyChanges(fragments, [{ fromA: from, toA: to, fromB: from, toB: to }]);
}
class LanguageState {
constructor(context) {
this.context = context;
this.tree = context.tree;
}
apply(tr) {
if (!tr.docChanged && this.tree == this.context.tree)
return this;
let newCx = this.context.changes(tr.changes, tr.state);
let upto = this.context.treeLen == tr.startState.doc.length ? void 0 : Math.max(tr.changes.mapPos(this.context.treeLen), newCx.viewport.to);
if (!newCx.work(20, upto))
newCx.takeTree();
return new LanguageState(newCx);
}
static init(state) {
let vpTo = Math.min(3e3, state.doc.length);
let parseState = ParseContext.create(state.facet(language).parser, state, { from: 0, to: vpTo });
if (!parseState.work(20, vpTo))
parseState.takeTree();
return new LanguageState(parseState);
}
}
Language.state = /* @__PURE__ */ StateField.define({
create: LanguageState.init,
update(value, tr) {
for (let e of tr.effects)
if (e.is(Language.setState))
return e.value;
if (tr.startState.facet(language) != tr.state.facet(language))
return LanguageState.init(tr.state);
return value.apply(tr);
}
});
let requestIdle = (callback) => {
let timeout = setTimeout(
() => callback(),
500
/* Work.MaxPause */
);
return () => clearTimeout(timeout);
};
if (typeof requestIdleCallback != "undefined")
requestIdle = (callback) => {
let idle = -1, timeout = setTimeout(
() => {
idle = requestIdleCallback(callback, {
timeout: 500 - 100
/* Work.MinPause */
});
},
100
/* Work.MinPause */
);
return () => idle < 0 ? clearTimeout(timeout) : cancelIdleCallback(idle);
};
const isInputPending = typeof navigator != "undefined" && ((_a = navigator.scheduling) === null || _a === void 0 ? void 0 : _a.isInputPending) ? () => navigator.scheduling.isInputPending() : null;
const parseWorker = /* @__PURE__ */ ViewPlugin.fromClass(class ParseWorker {
constructor(view) {
this.view = view;
this.working = null;
this.workScheduled = 0;
this.chunkEnd = -1;
this.chunkBudget = -1;
this.work = this.work.bind(this);
this.scheduleWork();
}
update(update) {
let cx = this.view.state.field(Language.state).context;
if (cx.updateViewport(update.view.viewport) || this.view.viewport.to > cx.treeLen)
this.scheduleWork();
if (update.docChanged || update.selectionSet) {
if (this.view.hasFocus)
this.chunkBudget += 50;
this.scheduleWork();
}
this.checkAsyncSchedule(cx);
}
scheduleWork() {
if (this.working)
return;
let { state } = this.view, field = state.field(Language.state);
if (field.tree != field.context.tree || !field.context.isDone(state.doc.length))
this.working = requestIdle(this.work);
}
work(deadline) {
this.working = null;
let now = Date.now();
if (this.chunkEnd < now && (this.chunkEnd < 0 || this.view.hasFocus)) {
this.chunkEnd = now + 3e4;
this.chunkBudget = 3e3;
}
if (this.chunkBudget <= 0)
return;
let { state, viewport: { to: vpTo } } = this.view, field = state.field(Language.state);
if (field.tree == field.context.tree && field.context.isDone(
vpTo + 1e5
/* Work.MaxParseAhead */
))
return;
let endTime = Date.now() + Math.min(this.chunkBudget, 100, deadline && !isInputPending ? Math.max(25, deadline.timeRemaining() - 5) : 1e9);
let viewportFirst = field.context.treeLen < vpTo && state.doc.length > vpTo + 1e3;
let done = field.context.work(() => {
return isInputPending && isInputPending() || Date.now() > endTime;
}, vpTo + (viewportFirst ? 0 : 1e5));
this.chunkBudget -= Date.now() - now;
if (done || this.chunkBudget <= 0) {
field.context.takeTree();
this.view.dispatch({ effects: Language.setState.of(new LanguageState(field.context)) });
}
if (this.chunkBudget > 0 && !(done && !viewportFirst))
this.scheduleWork();
this.checkAsyncSchedule(field.context);
}
checkAsyncSchedule(cx) {
if (cx.scheduleOn) {
this.workScheduled++;
cx.scheduleOn.then(() => this.scheduleWork()).catch((err) => logException(this.view.state, err)).then(() => this.workScheduled--);
cx.scheduleOn = null;
}
}
destroy() {
if (this.working)
this.working();
}
isWorking() {
return !!(this.working || this.workScheduled > 0);
}
}, {
eventHandlers: { focus() {
this.scheduleWork();
} }
});
const language = /* @__PURE__ */ Facet.define({
combine(languages) {
return languages.length ? languages[0] : null;
},
enables: (language2) => [
Language.state,
parseWorker,
EditorView.contentAttributes.compute([language2], (state) => {
let lang = state.facet(language2);
return lang && lang.name ? { "data-language": lang.name } : {};
})
]
});
class LanguageSupport {
/**
Create a language support object.
*/
constructor(language2, support = []) {
this.language = language2;
this.support = support;
this.extension = [language2, support];
}
}
const indentService = /* @__PURE__ */ Facet.define();
const indentUnit = /* @__PURE__ */ Facet.define({
combine: (values) => {
if (!values.length)
return " ";
let unit = values[0];
if (!unit || /\S/.test(unit) || Array.from(unit).some((e) => e != unit[0]))
throw new Error("Invalid indent unit: " + JSON.stringify(values[0]));
return unit;
}
});
function getIndentUnit(state) {
let unit = state.facet(indentUnit);
return unit.charCodeAt(0) == 9 ? state.tabSize * unit.length : unit.length;
}
function indentString(state, cols) {
let result2 = "", ts = state.tabSize, ch = state.facet(indentUnit)[0];
if (ch == " ") {
while (cols >= ts) {
result2 += " ";
cols -= ts;
}
ch = " ";
}
for (let i2 = 0; i2 < cols; i2++)
result2 += ch;
return result2;
}
function getIndentation(context, pos) {
if (context instanceof EditorState)
context = new IndentContext(context);
for (let service of context.state.facet(indentService)) {
let result2 = service(context, pos);
if (result2 !== void 0)
return result2;
}
let tree = syntaxTree(context.state);
return tree.length >= pos ? syntaxIndentation(context, tree, pos) : null;
}
class IndentContext {
/**
Create an indent context.
*/
constructor(state, options = {}) {
this.state = state;
this.options = options;
this.unit = getIndentUnit(state);
}
/**
Get a description of the line at the given position, taking
[simulated line
breaks](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
into account. If there is such a break at `pos`, the `bias`
argument determines whether the part of the line line before or
after the break is used.
*/
lineAt(pos, bias = 1) {
let line = this.state.doc.lineAt(pos);
let { simulateBreak, simulateDoubleBreak } = this.options;
if (simulateBreak != null && simulateBreak >= line.from && simulateBreak <= line.to) {
if (simulateDoubleBreak && simulateBreak == pos)
return { text: "", from: pos };
else if (bias < 0 ? simulateBreak < pos : simulateBreak <= pos)
return { text: line.text.slice(simulateBreak - line.from), from: simulateBreak };
else
return { text: line.text.slice(0, simulateBreak - line.from), from: line.from };
}
return line;
}
/**
Get the text directly after `pos`, either the entire line
or the next 100 characters, whichever is shorter.
*/
textAfterPos(pos, bias = 1) {
if (this.options.simulateDoubleBreak && pos == this.options.simulateBreak)
return "";
let { text, from } = this.lineAt(pos, bias);
return text.slice(pos - from, Math.min(text.length, pos + 100 - from));
}
/**
Find the column for the given position.
*/
column(pos, bias = 1) {
let { text, from } = this.lineAt(pos, bias);
let result2 = this.countColumn(text, pos - from);
let override = this.options.overrideIndentation ? this.options.overrideIndentation(from) : -1;
if (override > -1)
result2 += override - this.countColumn(text, text.search(/\S|$/));
return result2;
}
/**
Find the column position (taking tabs into account) of the given
position in the given string.
*/
countColumn(line, pos = line.length) {
return countColumn(line, this.state.tabSize, pos);
}
/**
Find the indentation column of the line at the given point.
*/
lineIndent(pos, bias = 1) {
let { text, from } = this.lineAt(pos, bias);
let override = this.options.overrideIndentation;
if (override) {
let overriden = override(from);
if (overriden > -1)
return overriden;
}
return this.countColumn(text, text.search(/\S|$/));
}
/**
Returns the [simulated line
break](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
for this context, if any.
*/
get simulatedBreak() {
return this.options.simulateBreak || null;
}
}
const indentNodeProp = /* @__PURE__ */ new NodeProp();
function syntaxIndentation(cx, ast, pos) {
let stack = ast.resolveStack(pos);
let inner = stack.node.enterUnfinishedNodesBefore(pos);
if (inner != stack.node) {
let add2 = [];
for (let cur2 = inner; cur2 != stack.node; cur2 = cur2.parent)
add2.push(cur2);
for (let i2 = add2.length - 1; i2 >= 0; i2--)
stack = { node: add2[i2], next: stack };
}
return indentFor(stack, cx, pos);
}
function indentFor(stack, cx, pos) {
for (let cur2 = stack; cur2; cur2 = cur2.next) {
let strategy = indentStrategy(cur2.node);
if (strategy)
return strategy(TreeIndentContext.create(cx, pos, cur2));
}
return 0;
}
function ignoreClosed(cx) {
return cx.pos == cx.options.simulateBreak && cx.options.simulateDoubleBreak;
}
function indentStrategy(tree) {
let strategy = tree.type.prop(indentNodeProp);
if (strategy)
return strategy;
let first = tree.firstChild, close;
if (first && (close = first.type.prop(NodeProp.closedBy))) {
let last = tree.lastChild, closed = last && close.indexOf(last.name) > -1;
return (cx) => delimitedStrategy(cx, true, 1, void 0, closed && !ignoreClosed(cx) ? last.from : void 0);
}
return tree.parent == null ? topIndent : null;
}
function topIndent() {
return 0;
}
class TreeIndentContext extends IndentContext {
constructor(base2, pos, context) {
super(base2.state, base2.options);
this.base = base2;
this.pos = pos;
this.context = context;
}
/**
The syntax tree node to which the indentation strategy
applies.
*/
get node() {
return this.context.node;
}
/**
@internal
*/
static create(base2, pos, context) {
return new TreeIndentContext(base2, pos, context);
}
/**
Get the text directly after `this.pos`, either the entire line
or the next 100 characters, whichever is shorter.
*/
get textAfter() {
return this.textAfterPos(this.pos);
}
/**
Get the indentation at the reference line for `this.node`, which
is the line on which it starts, unless there is a node that is
_not_ a parent of this node covering the start of that line. If
so, the line at the start of that node is tried, again skipping
on if it is covered by another such node.
*/
get baseIndent() {
return this.baseIndentFor(this.node);
}
/**
Get the indentation for the reference line of the given node
(see [`baseIndent`](https://codemirror.net/6/docs/ref/#language.TreeIndentContext.baseIndent)).
*/
baseIndentFor(node) {
let line = this.state.doc.lineAt(node.from);
for (; ; ) {
let atBreak = node.resolve(line.from);
while (atBreak.parent && atBreak.parent.from == atBreak.from)
atBreak = atBreak.parent;
if (isParent(atBreak, node))
break;
line = this.state.doc.lineAt(atBreak.from);
}
return this.lineIndent(line.from);
}
/**
Continue looking for indentations in the node's parent nodes,
and return the result of that.
*/
continue() {
return indentFor(this.context.next, this.base, this.pos);
}
}
function isParent(parent, of) {
for (let cur2 = of; cur2; cur2 = cur2.parent)
if (parent == cur2)
return true;
return false;
}
function bracketedAligned(context) {
let tree = context.node;
let openToken = tree.childAfter(tree.from), last = tree.lastChild;
if (!openToken)
return null;
let sim = context.options.simulateBreak;
let openLine = context.state.doc.lineAt(openToken.from);
let lineEnd = sim == null || sim <= openLine.from ? openLine.to : Math.min(openLine.to, sim);
for (let pos = openToken.to; ; ) {
let next = tree.childAfter(pos);
if (!next || next == last)
return null;
if (!next.type.isSkipped)
return next.from < lineEnd ? openToken : null;
pos = next.to;
}
}
function delimitedIndent({ closing: closing2, align = true, units = 1 }) {
return (context) => delimitedStrategy(context, align, units, closing2);
}
function delimitedStrategy(context, align, units, closing2, closedAt) {
let after = context.textAfter, space2 = after.match(/^\s*/)[0].length;
let closed = closing2 && after.slice(space2, space2 + closing2.length) == closing2 || closedAt == context.pos + space2;
let aligned = align ? bracketedAligned(context) : null;
if (aligned)
return closed ? context.column(aligned.from) : context.column(aligned.to);
return context.baseIndent + (closed ? 0 : context.unit * units);
}
const flatIndent = (context) => context.baseIndent;
function continuedIndent({ except, units = 1 } = {}) {
return (context) => {
let matchExcept = except && except.test(context.textAfter);
return context.baseIndent + (matchExcept ? 0 : units * context.unit);
};
}
const DontIndentBeyond = 200;
function indentOnInput() {
return EditorState.transactionFilter.of((tr) => {
if (!tr.docChanged || !tr.isUserEvent("input.type") && !tr.isUserEvent("input.complete"))
return tr;
let rules = tr.startState.languageDataAt("indentOnInput", tr.startState.selection.main.head);
if (!rules.length)
return tr;
let doc2 = tr.newDoc, { head } = tr.newSelection.main, line = doc2.lineAt(head);
if (head > line.from + DontIndentBeyond)
return tr;
let lineStart = doc2.sliceString(line.from, head);
if (!rules.some((r) => r.test(lineStart)))
return tr;
let { state } = tr, last = -1, changes = [];
for (let { head: head2 } of state.selection.ranges) {
let line2 = state.doc.lineAt(head2);
if (line2.from == last)
continue;
last = line2.from;
let indent = getIndentation(state, line2.from);
if (indent == null)
continue;
let cur2 = /^\s*/.exec(line2.text)[0];
let norm = indentString(state, indent);
if (cur2 != norm)
changes.push({ from: line2.from, to: line2.from + cur2.length, insert: norm });
}
return changes.length ? [tr, { changes, sequential: true }] : tr;
});
}
const foldService = /* @__PURE__ */ Facet.define();
const foldNodeProp = /* @__PURE__ */ new NodeProp();
function foldInside(node) {
let first = node.firstChild, last = node.lastChild;
return first && first.to < last.from ? { from: first.to, to: last.type.isError ? node.to : last.from } : null;
}
function syntaxFolding(state, start, end) {
let tree = syntaxTree(state);
if (tree.length < end)
return null;
let stack = tree.resolveStack(end, 1);
let found = null;
for (let iter = stack; iter; iter = iter.next) {
let cur2 = iter.node;
if (cur2.to <= end || cur2.from > end)
continue;
if (found && cur2.from < start)
break;
let prop = cur2.type.prop(foldNodeProp);
if (prop && (cur2.to < tree.length - 50 || tree.length == state.doc.length || !isUnfinished(cur2))) {
let value = prop(cur2, state);
if (value && value.from <= end && value.from >= start && value.to > end)
found = value;
}
}
return found;
}
function isUnfinished(node) {
let ch = node.lastChild;
return ch && ch.to == node.to && ch.type.isError;
}
function foldable(state, lineStart, lineEnd) {
for (let service of state.facet(foldService)) {
let result2 = service(state, lineStart, lineEnd);
if (result2)
return result2;
}
return syntaxFolding(state, lineStart, lineEnd);
}
function mapRange(range, mapping) {
let from = mapping.mapPos(range.from, 1), to = mapping.mapPos(range.to, -1);
return from >= to ? void 0 : { from, to };
}
const foldEffect = /* @__PURE__ */ StateEffect.define({ map: mapRange });
const unfoldEffect = /* @__PURE__ */ StateEffect.define({ map: mapRange });
function selectedLines(view) {
let lines = [];
for (let { head } of view.state.selection.ranges) {
if (lines.some((l) => l.from <= head && l.to >= head))
continue;
lines.push(view.lineBlockAt(head));
}
return lines;
}
const foldState = /* @__PURE__ */ StateField.define({
create() {
return Decoration.none;
},
update(folded, tr) {
folded = folded.map(tr.changes);
for (let e of tr.effects) {
if (e.is(foldEffect) && !foldExists(folded, e.value.from, e.value.to)) {
let { preparePlaceholder } = tr.state.facet(foldConfig);
let widget = !preparePlaceholder ? foldWidget : Decoration.replace({ widget: new PreparedFoldWidget(preparePlaceholder(tr.state, e.value)) });
folded = folded.update({ add: [widget.range(e.value.from, e.value.to)] });
} else if (e.is(unfoldEffect)) {
folded = folded.update({
filter: (from, to) => e.value.from != from || e.value.to != to,
filterFrom: e.value.from,
filterTo: e.value.to
});
}
}
if (tr.selection) {
let onSelection = false, { head } = tr.selection.main;
folded.between(head, head, (a, b) => {
if (a < head && b > head)
onSelection = true;
});
if (onSelection)
folded = folded.update({
filterFrom: head,
filterTo: head,
filter: (a, b) => b <= head || a >= head
});
}
return folded;
},
provide: (f) => EditorView.decorations.from(f),
toJSON(folded, state) {
let ranges = [];
folded.between(0, state.doc.length, (from, to) => {
ranges.push(from, to);
});
return ranges;
},
fromJSON(value) {
if (!Array.isArray(value) || value.length % 2)
throw new RangeError("Invalid JSON for fold state");
let ranges = [];
for (let i2 = 0; i2 < value.length; ) {
let from = value[i2++], to = value[i2++];
if (typeof from != "number" || typeof to != "number")
throw new RangeError("Invalid JSON for fold state");
ranges.push(foldWidget.range(from, to));
}
return Decoration.set(ranges, true);
}
});
function findFold(state, from, to) {
var _a2;
let found = null;
(_a2 = state.field(foldState, false)) === null || _a2 === void 0 ? void 0 : _a2.between(from, to, (from2, to2) => {
if (!found || found.from > from2)
found = { from: from2, to: to2 };
});
return found;
}
function foldExists(folded, from, to) {
let found = false;
folded.between(from, from, (a, b) => {
if (a == from && b == to)
found = true;
});
return found;
}
function maybeEnable(state, other) {
return state.field(foldState, false) ? other : other.concat(StateEffect.appendConfig.of(codeFolding()));
}
const foldCode = (view) => {
for (let line of selectedLines(view)) {
let range = foldable(view.state, line.from, line.to);
if (range) {
view.dispatch({ effects: maybeEnable(view.state, [foldEffect.of(range), announceFold(view, range)]) });
return true;
}
}
return false;
};
const unfoldCode = (view) => {
if (!view.state.field(foldState, false))
return false;
let effects = [];
for (let line of selectedLines(view)) {
let folded = findFold(view.state, line.from, line.to);
if (folded)
effects.push(unfoldEffect.of(folded), announceFold(view, folded, false));
}
if (effects.length)
view.dispatch({ effects });
return effects.length > 0;
};
function announceFold(view, range, fold = true) {
let lineFrom = view.state.doc.lineAt(range.from).number, lineTo = view.state.doc.lineAt(range.to).number;
return EditorView.announce.of(`${view.state.phrase(fold ? "Folded lines" : "Unfolded lines")} ${lineFrom} ${view.state.phrase("to")} ${lineTo}.`);
}
const foldAll = (view) => {
let { state } = view, effects = [];
for (let pos = 0; pos < state.doc.length; ) {
let line = view.lineBlockAt(pos), range = foldable(state, line.from, line.to);
if (range)
effects.push(foldEffect.of(range));
pos = (range ? view.lineBlockAt(range.to) : line).to + 1;
}
if (effects.length)
view.dispatch({ effects: maybeEnable(view.state, effects) });
return !!effects.length;
};
const unfoldAll = (view) => {
let field = view.state.field(foldState, false);
if (!field || !field.size)
return false;
let effects = [];
field.between(0, view.state.doc.length, (from, to) => {
effects.push(unfoldEffect.of({ from, to }));
});
view.dispatch({ effects });
return true;
};
const foldKeymap = [
{ key: "Ctrl-Shift-[", mac: "Cmd-Alt-[", run: foldCode },
{ key: "Ctrl-Shift-]", mac: "Cmd-Alt-]", run: unfoldCode },
{ key: "Ctrl-Alt-[", run: foldAll },
{ key: "Ctrl-Alt-]", run: unfoldAll }
];
const defaultConfig = {
placeholderDOM: null,
preparePlaceholder: null,
placeholderText: "…"
};
const foldConfig = /* @__PURE__ */ Facet.define({
combine(values) {
return combineConfig(values, defaultConfig);
}
});
function codeFolding(config2) {
let result2 = [foldState, baseTheme$1$2];
if (config2)
result2.push(foldConfig.of(config2));
return result2;
}
function widgetToDOM(view, prepared) {
let { state } = view, conf = state.facet(foldConfig);
let onclick = (event) => {
let line = view.lineBlockAt(view.posAtDOM(event.target));
let folded = findFold(view.state, line.from, line.to);
if (folded)
view.dispatch({ effects: unfoldEffect.of(folded) });
event.preventDefault();
};
if (conf.placeholderDOM)
return conf.placeholderDOM(view, onclick, prepared);
let element = document.createElement("span");
element.textContent = conf.placeholderText;
element.setAttribute("aria-label", state.phrase("folded code"));
element.title = state.phrase("unfold");
element.className = "cm-foldPlaceholder";
element.onclick = onclick;
return element;
}
const foldWidget = /* @__PURE__ */ Decoration.replace({ widget: /* @__PURE__ */ new class extends WidgetType {
toDOM(view) {
return widgetToDOM(view, null);
}
}() });
class PreparedFoldWidget extends WidgetType {
constructor(value) {
super();
this.value = value;
}
eq(other) {
return this.value == other.value;
}
toDOM(view) {
return widgetToDOM(view, this.value);
}
}
const foldGutterDefaults = {
openText: "⌄",
closedText: "›",
markerDOM: null,
domEventHandlers: {},
foldingChanged: () => false
};
class FoldMarker extends GutterMarker {
constructor(config2, open) {
super();
this.config = config2;
this.open = open;
}
eq(other) {
return this.config == other.config && this.open == other.open;
}
toDOM(view) {
if (this.config.markerDOM)
return this.config.markerDOM(this.open);
let span = document.createElement("span");
span.textContent = this.open ? this.config.openText : this.config.closedText;
span.title = view.state.phrase(this.open ? "Fold line" : "Unfold line");
return span;
}
}
function foldGutter(config2 = {}) {
let fullConfig = Object.assign(Object.assign({}, foldGutterDefaults), config2);
let canFold = new FoldMarker(fullConfig, true), canUnfold = new FoldMarker(fullConfig, false);
let markers = ViewPlugin.fromClass(class {
constructor(view) {
this.from = view.viewport.from;
this.markers = this.buildMarkers(view);
}
update(update) {
if (update.docChanged || update.viewportChanged || update.startState.facet(language) != update.state.facet(language) || update.startState.field(foldState, false) != update.state.field(foldState, false) || syntaxTree(update.startState) != syntaxTree(update.state) || fullConfig.foldingChanged(update))
this.markers = this.buildMarkers(update.view);
}
buildMarkers(view) {
let builder = new RangeSetBuilder();
for (let line of view.viewportLineBlocks) {
let mark = findFold(view.state, line.from, line.to) ? canUnfold : foldable(view.state, line.from, line.to) ? canFold : null;
if (mark)
builder.add(line.from, line.from, mark);
}
return builder.finish();
}
});
let { domEventHandlers } = fullConfig;
return [
markers,
gutter({
class: "cm-foldGutter",
markers(view) {
var _a2;
return ((_a2 = view.plugin(markers)) === null || _a2 === void 0 ? void 0 : _a2.markers) || RangeSet.empty;
},
initialSpacer() {
return new FoldMarker(fullConfig, false);
},
domEventHandlers: Object.assign(Object.assign({}, domEventHandlers), { click: (view, line, event) => {
if (domEventHandlers.click && domEventHandlers.click(view, line, event))
return true;
let folded = findFold(view.state, line.from, line.to);
if (folded) {
view.dispatch({ effects: unfoldEffect.of(folded) });
return true;
}
let range = foldable(view.state, line.from, line.to);
if (range) {
view.dispatch({ effects: foldEffect.of(range) });
return true;
}
return false;
} })
}),
codeFolding()
];
}
const baseTheme$1$2 = /* @__PURE__ */ EditorView.baseTheme({
".cm-foldPlaceholder": {
backgroundColor: "#eee",
border: "1px solid #ddd",
color: "#888",
borderRadius: ".2em",
margin: "0 1px",
padding: "0 1px",
cursor: "pointer"
},
".cm-foldGutter span": {
padding: "0 1px",
cursor: "pointer"
}
});
class HighlightStyle {
constructor(specs, options) {
this.specs = specs;
let modSpec;
function def(spec) {
let cls = StyleModule.newName();
(modSpec || (modSpec = /* @__PURE__ */ Object.create(null)))["." + cls] = spec;
return cls;
}
const all = typeof options.all == "string" ? options.all : options.all ? def(options.all) : void 0;
const scopeOpt = options.scope;
this.scope = scopeOpt instanceof Language ? (type) => type.prop(languageDataProp) == scopeOpt.data : scopeOpt ? (type) => type == scopeOpt : void 0;
this.style = tagHighlighter(specs.map((style) => ({
tag: style.tag,
class: style.class || def(Object.assign({}, style, { tag: null }))
})), {
all
}).style;
this.module = modSpec ? new StyleModule(modSpec) : null;
this.themeType = options.themeType;
}
/**
Create a highlighter style that associates the given styles to
the given tags. The specs must be objects that hold a style tag
or array of tags in their `tag` property, and either a single
`class` property providing a static CSS class (for highlighter
that rely on external styling), or a
[`style-mod`](https://github.com/marijnh/style-mod#documentation)-style
set of CSS properties (which define the styling for those tags).
The CSS rules created for a highlighter will be emitted in the
order of the spec's properties. That means that for elements that
have multiple tags associated with them, styles defined further
down in the list will have a higher CSS precedence than styles
defined earlier.
*/
static define(specs, options) {
return new HighlightStyle(specs, options || {});
}
}
const highlighterFacet = /* @__PURE__ */ Facet.define();
const fallbackHighlighter = /* @__PURE__ */ Facet.define({
combine(values) {
return values.length ? [values[0]] : null;
}
});
function getHighlighters(state) {
let main = state.facet(highlighterFacet);
return main.length ? main : state.facet(fallbackHighlighter);
}
function syntaxHighlighting(highlighter, options) {
let ext = [treeHighlighter], themeType;
if (highlighter instanceof HighlightStyle) {
if (highlighter.module)
ext.push(EditorView.styleModule.of(highlighter.module));
themeType = highlighter.themeType;
}
if (options === null || options === void 0 ? void 0 : options.fallback)
ext.push(fallbackHighlighter.of(highlighter));
else if (themeType)
ext.push(highlighterFacet.computeN([EditorView.darkTheme], (state) => {
return state.facet(EditorView.darkTheme) == (themeType == "dark") ? [highlighter] : [];
}));
else
ext.push(highlighterFacet.of(highlighter));
return ext;
}
class TreeHighlighter {
constructor(view) {
this.markCache = /* @__PURE__ */ Object.create(null);
this.tree = syntaxTree(view.state);
this.decorations = this.buildDeco(view, getHighlighters(view.state));
this.decoratedTo = view.viewport.to;
}
update(update) {
let tree = syntaxTree(update.state), highlighters = getHighlighters(update.state);
let styleChange = highlighters != getHighlighters(update.startState);
let { viewport } = update.view, decoratedToMapped = update.changes.mapPos(this.decoratedTo, 1);
if (tree.length < viewport.to && !styleChange && tree.type == this.tree.type && decoratedToMapped >= viewport.to) {
this.decorations = this.decorations.map(update.changes);
this.decoratedTo = decoratedToMapped;
} else if (tree != this.tree || update.viewportChanged || styleChange) {
this.tree = tree;
this.decorations = this.buildDeco(update.view, highlighters);
this.decoratedTo = viewport.to;
}
}
buildDeco(view, highlighters) {
if (!highlighters || !this.tree.length)
return Decoration.none;
let builder = new RangeSetBuilder();
for (let { from, to } of view.visibleRanges) {
highlightTree(this.tree, highlighters, (from2, to2, style) => {
builder.add(from2, to2, this.markCache[style] || (this.markCache[style] = Decoration.mark({ class: style })));
}, from, to);
}
return builder.finish();
}
}
const treeHighlighter = /* @__PURE__ */ Prec.high(/* @__PURE__ */ ViewPlugin.fromClass(TreeHighlighter, {
decorations: (v) => v.decorations
}));
const defaultHighlightStyle = /* @__PURE__ */ HighlightStyle.define([
{
tag: tags.meta,
color: "#404740"
},
{
tag: tags.link,
textDecoration: "underline"
},
{
tag: tags.heading,
textDecoration: "underline",
fontWeight: "bold"
},
{
tag: tags.emphasis,
fontStyle: "italic"
},
{
tag: tags.strong,
fontWeight: "bold"
},
{
tag: tags.strikethrough,
textDecoration: "line-through"
},
{
tag: tags.keyword,
color: "#708"
},
{
tag: [tags.atom, tags.bool, tags.url, tags.contentSeparator, tags.labelName],
color: "#219"
},
{
tag: [tags.literal, tags.inserted],
color: "#164"
},
{
tag: [tags.string, tags.deleted],
color: "#a11"
},
{
tag: [tags.regexp, tags.escape, /* @__PURE__ */ tags.special(tags.string)],
color: "#e40"
},
{
tag: /* @__PURE__ */ tags.definition(tags.variableName),
color: "#00f"
},
{
tag: /* @__PURE__ */ tags.local(tags.variableName),
color: "#30a"
},
{
tag: [tags.typeName, tags.namespace],
color: "#085"
},
{
tag: tags.className,
color: "#167"
},
{
tag: [/* @__PURE__ */ tags.special(tags.variableName), tags.macroName],
color: "#256"
},
{
tag: /* @__PURE__ */ tags.definition(tags.propertyName),
color: "#00c"
},
{
tag: tags.comment,
color: "#940"
},
{
tag: tags.invalid,
color: "#f00"
}
]);
const baseTheme$3 = /* @__PURE__ */ EditorView.baseTheme({
"&.cm-focused .cm-matchingBracket": { backgroundColor: "#328c8252" },
"&.cm-focused .cm-nonmatchingBracket": { backgroundColor: "#bb555544" }
});
const DefaultScanDist = 1e4, DefaultBrackets = "()[]{}";
const bracketMatchingConfig = /* @__PURE__ */ Facet.define({
combine(configs) {
return combineConfig(configs, {
afterCursor: true,
brackets: DefaultBrackets,
maxScanDistance: DefaultScanDist,
renderMatch: defaultRenderMatch
});
}
});
const matchingMark = /* @__PURE__ */ Decoration.mark({ class: "cm-matchingBracket" }), nonmatchingMark = /* @__PURE__ */ Decoration.mark({ class: "cm-nonmatchingBracket" });
function defaultRenderMatch(match2) {
let decorations2 = [];
let mark = match2.matched ? matchingMark : nonmatchingMark;
decorations2.push(mark.range(match2.start.from, match2.start.to));
if (match2.end)
decorations2.push(mark.range(match2.end.from, match2.end.to));
return decorations2;
}
const bracketMatchingState = /* @__PURE__ */ StateField.define({
create() {
return Decoration.none;
},
update(deco, tr) {
if (!tr.docChanged && !tr.selection)
return deco;
let decorations2 = [];
let config2 = tr.state.facet(bracketMatchingConfig);
for (let range of tr.state.selection.ranges) {
if (!range.empty)
continue;
let match2 = matchBrackets(tr.state, range.head, -1, config2) || range.head > 0 && matchBrackets(tr.state, range.head - 1, 1, config2) || config2.afterCursor && (matchBrackets(tr.state, range.head, 1, config2) || range.head < tr.state.doc.length && matchBrackets(tr.state, range.head + 1, -1, config2));
if (match2)
decorations2 = decorations2.concat(config2.renderMatch(match2, tr.state));
}
return Decoration.set(decorations2, true);
},
provide: (f) => EditorView.decorations.from(f)
});
const bracketMatchingUnique = [
bracketMatchingState,
baseTheme$3
];
function bracketMatching(config2 = {}) {
return [bracketMatchingConfig.of(config2), bracketMatchingUnique];
}
const bracketMatchingHandle = /* @__PURE__ */ new NodeProp();
function matchingNodes(node, dir, brackets) {
let byProp = node.prop(dir < 0 ? NodeProp.openedBy : NodeProp.closedBy);
if (byProp)
return byProp;
if (node.name.length == 1) {
let index = brackets.indexOf(node.name);
if (index > -1 && index % 2 == (dir < 0 ? 1 : 0))
return [brackets[index + dir]];
}
return null;
}
function findHandle(node) {
let hasHandle = node.type.prop(bracketMatchingHandle);
return hasHandle ? hasHandle(node.node) : node;
}
function matchBrackets(state, pos, dir, config2 = {}) {
let maxScanDistance = config2.maxScanDistance || DefaultScanDist, brackets = config2.brackets || DefaultBrackets;
let tree = syntaxTree(state), node = tree.resolveInner(pos, dir);
for (let cur2 = node; cur2; cur2 = cur2.parent) {
let matches = matchingNodes(cur2.type, dir, brackets);
if (matches && cur2.from < cur2.to) {
let handle = findHandle(cur2);
if (handle && (dir > 0 ? pos >= handle.from && pos < handle.to : pos > handle.from && pos <= handle.to))
return matchMarkedBrackets(state, pos, dir, cur2, handle, matches, brackets);
}
}
return matchPlainBrackets(state, pos, dir, tree, node.type, maxScanDistance, brackets);
}
function matchMarkedBrackets(_state, _pos, dir, token, handle, matching, brackets) {
let parent = token.parent, firstToken = { from: handle.from, to: handle.to };
let depth = 0, cursor = parent === null || parent === void 0 ? void 0 : parent.cursor();
if (cursor && (dir < 0 ? cursor.childBefore(token.from) : cursor.childAfter(token.to)))
do {
if (dir < 0 ? cursor.to <= token.from : cursor.from >= token.to) {
if (depth == 0 && matching.indexOf(cursor.type.name) > -1 && cursor.from < cursor.to) {
let endHandle = findHandle(cursor);
return { start: firstToken, end: endHandle ? { from: endHandle.from, to: endHandle.to } : void 0, matched: true };
} else if (matchingNodes(cursor.type, dir, brackets)) {
depth++;
} else if (matchingNodes(cursor.type, -dir, brackets)) {
if (depth == 0) {
let endHandle = findHandle(cursor);
return {
start: firstToken,
end: endHandle && endHandle.from < endHandle.to ? { from: endHandle.from, to: endHandle.to } : void 0,
matched: false
};
}
depth--;
}
}
} while (dir < 0 ? cursor.prevSibling() : cursor.nextSibling());
return { start: firstToken, matched: false };
}
function matchPlainBrackets(state, pos, dir, tree, tokenType, maxScanDistance, brackets) {
let startCh = dir < 0 ? state.sliceDoc(pos - 1, pos) : state.sliceDoc(pos, pos + 1);
let bracket2 = brackets.indexOf(startCh);
if (bracket2 < 0 || bracket2 % 2 == 0 != dir > 0)
return null;
let startToken = { from: dir < 0 ? pos - 1 : pos, to: dir > 0 ? pos + 1 : pos };
let iter = state.doc.iterRange(pos, dir > 0 ? state.doc.length : 0), depth = 0;
for (let distance = 0; !iter.next().done && distance <= maxScanDistance; ) {
let text = iter.value;
if (dir < 0)
distance += text.length;
let basePos = pos + distance * dir;
for (let pos2 = dir > 0 ? 0 : text.length - 1, end = dir > 0 ? text.length : -1; pos2 != end; pos2 += dir) {
let found = brackets.indexOf(text[pos2]);
if (found < 0 || tree.resolveInner(basePos + pos2, 1).type != tokenType)
continue;
if (found % 2 == 0 == dir > 0) {
depth++;
} else if (depth == 1) {
return { start: startToken, end: { from: basePos + pos2, to: basePos + pos2 + 1 }, matched: found >> 1 == bracket2 >> 1 };
} else {
depth--;
}
}
if (dir > 0)
distance += text.length;
}
return iter.done ? { start: startToken, matched: false } : null;
}
const noTokens = /* @__PURE__ */ Object.create(null);
const typeArray = [NodeType.none];
const warned = [];
const byTag = /* @__PURE__ */ Object.create(null);
const defaultTable = /* @__PURE__ */ Object.create(null);
for (let [legacyName, name2] of [
["variable", "variableName"],
["variable-2", "variableName.special"],
["string-2", "string.special"],
["def", "variableName.definition"],
["tag", "tagName"],
["attribute", "attributeName"],
["type", "typeName"],
["builtin", "variableName.standard"],
["qualifier", "modifier"],
["error", "invalid"],
["header", "heading"],
["property", "propertyName"]
])
defaultTable[legacyName] = /* @__PURE__ */ createTokenType(noTokens, name2);
function warnForPart(part, msg) {
if (warned.indexOf(part) > -1)
return;
warned.push(part);
console.warn(msg);
}
function createTokenType(extra, tagStr) {
let tags$1 = [];
for (let name3 of tagStr.split(" ")) {
let found = [];
for (let part of name3.split(".")) {
let value = extra[part] || tags[part];
if (!value) {
warnForPart(part, `Unknown highlighting tag ${part}`);
} else if (typeof value == "function") {
if (!found.length)
warnForPart(part, `Modifier ${part} used at start of tag`);
else
found = found.map(value);
} else {
if (found.length)
warnForPart(part, `Tag ${part} used as modifier`);
else
found = Array.isArray(value) ? value : [value];
}
}
for (let tag of found)
tags$1.push(tag);
}
if (!tags$1.length)
return 0;
let name2 = tagStr.replace(/ /g, "_"), key = name2 + " " + tags$1.map((t2) => t2.id);
let known = byTag[key];
if (known)
return known.id;
let type = byTag[key] = NodeType.define({
id: typeArray.length,
name: name2,
props: [styleTags({ [name2]: tags$1 })]
});
typeArray.push(type);
return type.id;
}
({
rtl: /* @__PURE__ */ Decoration.mark({ class: "cm-iso", inclusive: true, attributes: { dir: "rtl" }, bidiIsolate: Direction.RTL }),
ltr: /* @__PURE__ */ Decoration.mark({ class: "cm-iso", inclusive: true, attributes: { dir: "ltr" }, bidiIsolate: Direction.LTR }),
auto: /* @__PURE__ */ Decoration.mark({ class: "cm-iso", inclusive: true, attributes: { dir: "auto" }, bidiIsolate: null })
});
const toggleComment = (target) => {
let { state } = target, line = state.doc.lineAt(state.selection.main.from), config2 = getConfig(target.state, line.from);
return config2.line ? toggleLineComment(target) : config2.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;
};
}
const toggleLineComment = /* @__PURE__ */ command(
changeLineComment,
0
/* CommentOption.Toggle */
);
const toggleBlockComment = /* @__PURE__ */ command(
changeBlockComment,
0
/* CommentOption.Toggle */
);
const toggleBlockCommentByLine = /* @__PURE__ */ command(
(o, s) => changeBlockComment(o, s, selectedLineRanges(s)),
0
/* CommentOption.Toggle */
);
function getConfig(state, pos) {
let data = state.languageDataAt("commentTokens", pos);
return data.length ? data[0] : {};
}
const 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 + /^\s*/.exec(fromLine.text)[0].length, 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, i2) => findBlockComment(state, tokens[i2], r.from, r.to));
if (option != 2 && !comments.every((c) => c)) {
return { changes: state.changes(ranges.map((range, i2) => {
if (comments[i2])
return [];
return [{ from: range.from, insert: tokens[i2].open + " " }, { from: range.to, insert: " " + tokens[i2].close }];
})) };
} else if (option != 1 && comments.some((c) => c)) {
let changes = [];
for (let i2 = 0, comment2; i2 < comments.length; i2++)
if (comment2 = comments[i2]) {
let token = tokens[i2], { open, close } = comment2;
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;
let token = getConfig(state, from).line;
if (!token)
continue;
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 indent = /^\s*/.exec(line.text)[0].length;
let empty2 = indent == line.length;
let comment2 = line.text.slice(indent, indent + token.length) == token ? indent : -1;
if (indent < line.text.length && indent < minIndent)
minIndent = indent;
lines.push({ line, comment: comment2, token, indent, empty: empty2, single: false });
}
pos = line.to + 1;
}
if (minIndent < 1e9) {
for (let i2 = startI; i2 < lines.length; i2++)
if (lines[i2].indent < lines[i2].line.text.length)
lines[i2].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: comment2, token } of lines)
if (comment2 >= 0) {
let from = line.from + comment2, to = from + token.length;
if (line.text[to - line.from] == " ")
to++;
changes.push({ from, to });
}
return { changes };
}
return null;
}
const fromHistory = /* @__PURE__ */ Annotation.define();
const isolateHistory = /* @__PURE__ */ Annotation.define();
const invertedEffects = /* @__PURE__ */ Facet.define();
const historyConfig = /* @__PURE__ */ Facet.define({
combine(configs) {
return combineConfig(configs, {
minDepth: 100,
newGroupDelay: 500,
joinToEvent: (_t, isAdjacent2) => isAdjacent2
}, {
minDepth: Math.max,
newGroupDelay: Math.min,
joinToEvent: (a, b) => (tr, adj) => a(tr, adj) || b(tr, adj)
});
}
});
const historyField_ = /* @__PURE__ */ StateField.define({
create() {
return HistoryState.empty;
},
update(state, tr) {
let config2 = tr.state.facet(historyConfig);
let fromHist = tr.annotation(fromHistory);
if (fromHist) {
let item = HistEvent.fromTransaction(tr, fromHist.selection), from = fromHist.side;
let other = from == 0 ? state.undone : state.done;
if (item)
other = updateBranch(other, other.length, config2.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, config2, tr);
else if (tr.selection)
state = state.addSelection(tr.startState.selection, time, userEvent, config2.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$1(config2 = {}) {
return [
historyField_,
historyConfig.of(config2),
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;
};
}
const undo = /* @__PURE__ */ cmd(0, false);
const redo = /* @__PURE__ */ cmd(1, false);
const undoSelection = /* @__PURE__ */ cmd(0, true);
const redoSelection = /* @__PURE__ */ cmd(1, true);
class HistEvent {
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 _a2, _b, _c;
return {
changes: (_a2 = this.changes) === null || _a2 === void 0 ? void 0 : _a2.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));
}
// This does not check `addToHistory` and such, it assumes the
// transaction needs to be converted to an item. Returns null when
// there are no changes or effects in the transaction.
static fromTransaction(tr, selection) {
let effects = none$1;
for (let invert of tr.startState.facet(invertedEffects)) {
let result2 = invert(tr);
if (result2.length)
effects = effects.concat(result2);
}
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$1);
}
static selection(selections) {
return new HistEvent(void 0, none$1, 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, t2) => ranges.push(f, t2));
b.iterChangedRanges((_f, _t, f, t2) => {
for (let i2 = 0; i2 < ranges.length; ) {
let from = ranges[i2++], to = ranges[i2++];
if (t2 >= from && f <= to)
isAdjacent2 = true;
}
});
return isAdjacent2;
}
function eqSelectionShape(a, b) {
return a.ranges.length == b.ranges.length && a.ranges.filter((r, i2) => r.empty != b.ranges[i2].empty).length === 0;
}
function conc(a, b) {
return !a.length ? b : !b.length ? a : a.concat(b);
}
const none$1 = [];
const 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$1;
while (length) {
let event = mapEvent(branch[length - 1], mapping, selections);
if (event.changes && !event.changes.empty || event.effects.length) {
let result2 = branch.slice(0, length);
result2[length - 1] = event;
return result2;
} else {
mapping = event.mapped;
length--;
selections = event.selectionsAfter;
}
}
return selections.length ? [HistEvent.selection(selections)] : none$1;
}
function mapEvent(event, mapping, extraSelections) {
let selections = conc(event.selectionsAfter.length ? event.selectionsAfter.map((s) => s.map(mapping)) : none$1, 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);
}
const joinableUserEvent = /^(input\.type|delete)($|\.)/;
class HistoryState {
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, config2, tr) {
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 < config2.newGroupDelay && config2.joinToEvent(tr, isAdjacent(lastEvent.changes, event.changes)) || // For compose (but not compose.start) events, always join with previous event
userEvent == "input.type.compose")) {
done = updateBranch(done, done.length - 1, config2.minDepth, new HistEvent(event.changes.compose(lastEvent.changes), conc(event.effects, lastEvent.effects), lastEvent.mapped, lastEvent.startSelection, none$1));
} else {
done = updateBranch(done, done.length, config2.minDepth, event);
}
return new HistoryState(done, none$1, time, userEvent);
}
addSelection(selection, time, userEvent, newGroupDelay) {
let last = this.done.length ? this.done[this.done.length - 1].selectionsAfter : none$1;
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, onlySelection) {
let branch = side == 0 ? this.done : this.undone;
if (branch.length == 0)
return null;
let event = branch[branch.length - 1], selection = event.selectionsAfter[0] || state.selection;
if (onlySelection && event.selectionsAfter.length) {
return state.update({
selection: event.selectionsAfter[event.selectionsAfter.length - 1],
annotations: fromHistory.of({ side, rest: popSelection(branch), selection }),
userEvent: side == 0 ? "select.undo" : "select.redo",
scrollIntoView: true
});
} else if (!event.changes) {
return null;
} else {
let rest = branch.length == 1 ? none$1 : 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, selection }),
filter: false,
userEvent: side == 0 ? "undo" : "redo",
scrollIntoView: true
});
}
}
}
HistoryState.empty = /* @__PURE__ */ new HistoryState(none$1, none$1);
const 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, true))
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;
}
const cursorCharLeft = (view) => cursorByChar(view, !ltrAtCursor(view));
const cursorCharRight = (view) => cursorByChar(view, ltrAtCursor(view));
function cursorByGroup(view, forward) {
return moveSel(view, (range) => range.empty ? view.moveByGroup(range, forward) : rangeEnd(range, forward));
}
const cursorGroupLeft = (view) => cursorByGroup(view, !ltrAtCursor(view));
const 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 bracket2 = pos.type.prop(bracketProp), match2, newPos;
if (bracket2 && (match2 = forward ? matchBrackets(state, pos.from, 1) : matchBrackets(state, pos.to, -1)) && match2.matched)
newPos = forward ? match2.end.to : match2.end.from;
else
newPos = forward ? pos.to : pos.from;
return EditorSelection.cursor(newPos, forward ? -1 : 1);
}
const cursorSyntaxLeft = (view) => moveSel(view, (range) => moveBySyntax(view.state, range, !ltrAtCursor(view)));
const 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);
});
}
const cursorLineUp = (view) => cursorByLine(view, false);
const cursorLineDown = (view) => cursorByLine(view, true);
function pageInfo(view) {
let selfScroll = view.scrollDOM.clientHeight < view.scrollDOM.scrollHeight - 2;
let marginTop = 0, marginBottom = 0, height;
if (selfScroll) {
for (let source of view.state.facet(EditorView.scrollMargins)) {
let margins = source(view);
if (margins === null || margins === void 0 ? void 0 : margins.top)
marginTop = Math.max(margins === null || margins === void 0 ? void 0 : margins.top, marginTop);
if (margins === null || margins === void 0 ? void 0 : margins.bottom)
marginBottom = Math.max(margins === null || margins === void 0 ? void 0 : margins.bottom, marginBottom);
}
height = view.scrollDOM.clientHeight - marginTop - marginBottom;
} else {
height = (view.dom.ownerDocument.defaultView || window).innerHeight;
}
return {
marginTop,
marginBottom,
selfScroll,
height: Math.max(view.defaultLineHeight, height - 5)
};
}
function cursorByPage(view, forward) {
let page = pageInfo(view);
let { state } = view, selection = updateSel(state.selection, (range) => {
return range.empty ? view.moveVertically(range, forward, page.height) : rangeEnd(range, forward);
});
if (selection.eq(state.selection))
return false;
let effect;
if (page.selfScroll) {
let startPos = view.coordsAtPos(state.selection.main.head);
let scrollRect = view.scrollDOM.getBoundingClientRect();
let scrollTop = scrollRect.top + page.marginTop, scrollBottom = scrollRect.bottom - page.marginBottom;
if (startPos && startPos.top > scrollTop && startPos.bottom < scrollBottom)
effect = EditorView.scrollIntoView(selection.main.head, { y: "start", yMargin: startPos.top - scrollTop });
}
view.dispatch(setSel(state, selection), { effects: effect });
return true;
}
const cursorPageUp = (view) => cursorByPage(view, false);
const 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 space2 = /^\s*/.exec(view.state.sliceDoc(line.from, Math.min(line.from + 100, line.to)))[0].length;
if (space2 && start.head != line.from + space2)
moved = EditorSelection.cursor(line.from + space2);
}
return moved;
}
const cursorLineBoundaryForward = (view) => moveSel(view, (range) => moveByLineBoundary(view, range, true));
const cursorLineBoundaryBackward = (view) => moveSel(view, (range) => moveByLineBoundary(view, range, false));
const cursorLineBoundaryLeft = (view) => moveSel(view, (range) => moveByLineBoundary(view, range, !ltrAtCursor(view)));
const cursorLineBoundaryRight = (view) => moveSel(view, (range) => moveByLineBoundary(view, range, ltrAtCursor(view)));
const cursorLineStart = (view) => moveSel(view, (range) => EditorSelection.cursor(view.lineBlockAt(range.head).from, 1));
const cursorLineEnd = (view) => moveSel(view, (range) => EditorSelection.cursor(view.lineBlockAt(range.head).to, -1));
function toMatchingBracket(state, dispatch, extend2) {
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 extend2 ? EditorSelection.range(range.anchor, head) : EditorSelection.cursor(head);
});
if (!found)
return false;
dispatch(setSel(state, selection));
return true;
}
const 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, head.bidiLevel || void 0);
});
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));
}
const selectCharLeft = (view) => selectByChar(view, !ltrAtCursor(view));
const selectCharRight = (view) => selectByChar(view, ltrAtCursor(view));
function selectByGroup(view, forward) {
return extendSel(view, (range) => view.moveByGroup(range, forward));
}
const selectGroupLeft = (view) => selectByGroup(view, !ltrAtCursor(view));
const selectGroupRight = (view) => selectByGroup(view, ltrAtCursor(view));
const selectSyntaxLeft = (view) => extendSel(view, (range) => moveBySyntax(view.state, range, !ltrAtCursor(view)));
const selectSyntaxRight = (view) => extendSel(view, (range) => moveBySyntax(view.state, range, ltrAtCursor(view)));
function selectByLine(view, forward) {
return extendSel(view, (range) => view.moveVertically(range, forward));
}
const selectLineUp = (view) => selectByLine(view, false);
const selectLineDown = (view) => selectByLine(view, true);
function selectByPage(view, forward) {
return extendSel(view, (range) => view.moveVertically(range, forward, pageInfo(view).height));
}
const selectPageUp = (view) => selectByPage(view, false);
const selectPageDown = (view) => selectByPage(view, true);
const selectLineBoundaryForward = (view) => extendSel(view, (range) => moveByLineBoundary(view, range, true));
const selectLineBoundaryBackward = (view) => extendSel(view, (range) => moveByLineBoundary(view, range, false));
const selectLineBoundaryLeft = (view) => extendSel(view, (range) => moveByLineBoundary(view, range, !ltrAtCursor(view)));
const selectLineBoundaryRight = (view) => extendSel(view, (range) => moveByLineBoundary(view, range, ltrAtCursor(view)));
const selectLineStart = (view) => extendSel(view, (range) => EditorSelection.cursor(view.lineBlockAt(range.head).from));
const selectLineEnd = (view) => extendSel(view, (range) => EditorSelection.cursor(view.lineBlockAt(range.head).to));
const cursorDocStart = ({ state, dispatch }) => {
dispatch(setSel(state, { anchor: 0 }));
return true;
};
const cursorDocEnd = ({ state, dispatch }) => {
dispatch(setSel(state, { anchor: state.doc.length }));
return true;
};
const selectDocStart = ({ state, dispatch }) => {
dispatch(setSel(state, { anchor: state.selection.main.anchor, head: 0 }));
return true;
};
const selectDocEnd = ({ state, dispatch }) => {
dispatch(setSel(state, { anchor: state.selection.main.anchor, head: state.doc.length }));
return true;
};
const selectAll = ({ state, dispatch }) => {
dispatch(state.update({ selection: { anchor: 0, head: state.doc.length }, userEvent: "select" }));
return true;
};
const 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;
};
const selectParentSyntax = ({ state, dispatch }) => {
let selection = updateSel(state.selection, (range) => {
var _a2;
let stack = syntaxTree(state).resolveStack(range.from, 1);
for (let cur2 = stack; cur2; cur2 = cur2.next) {
let { node } = cur2;
if ((node.from < range.from && node.to >= range.to || node.to > range.to && node.from <= range.from) && ((_a2 = node.parent) === null || _a2 === void 0 ? void 0 : _a2.parent))
return EditorSelection.range(node.to, node.from);
}
return range;
});
dispatch(setSel(state, selection));
return true;
};
const simplifySelection = ({ state, dispatch }) => {
let cur2 = state.selection, selection = null;
if (cur2.ranges.length > 1)
selection = EditorSelection.create([cur2.main]);
else if (!cur2.main.empty)
selection = EditorSelection.create([EditorSelection.cursor(cur2.main.head)]);
if (!selection)
return false;
dispatch(setSel(state, selection));
return true;
};
function deleteBy(target, by) {
if (target.state.readOnly)
return false;
let event = "delete.selection", { state } = target;
let changes = state.changeByRange((range) => {
let { from, to } = range;
if (from == to) {
let towards = by(range);
if (towards < from) {
event = "delete.backward";
towards = skipAtomic(target, towards, false);
} else if (towards > from) {
event = "delete.forward";
towards = skipAtomic(target, towards, true);
}
from = Math.min(from, towards);
to = Math.max(to, towards);
} else {
from = skipAtomic(target, from, false);
to = skipAtomic(target, to, true);
}
return from == to ? { range } : { changes: { from, to }, range: EditorSelection.cursor(from, from < range.head ? -1 : 1) };
});
if (changes.changes.empty)
return false;
target.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;
}
const deleteByChar = (target, forward) => deleteBy(target, (range) => {
let pos = range.from, { 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 i2 = 0; i2 < drop && before[before.length - 1 - i2] == " "; i2++)
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;
else if (!forward && /[\ufe00-\ufe0f]/.test(line.text.slice(targetPos - line.from, pos - line.from)))
targetPos = findClusterBreak(line.text, targetPos - line.from, false, false) + line.from;
}
return targetPos;
});
const deleteCharBackward = (view) => deleteByChar(view, false);
const deleteCharForward = (view) => deleteByChar(view, true);
const deleteByGroup = (target, forward) => deleteBy(target, (range) => {
let pos = range.head, { 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 == range.head && line.number != (forward ? state.doc.lines : 1))
pos += forward ? 1 : -1;
break;
}
let next = findClusterBreak(line.text, pos - line.from, forward) + line.from;
let nextChar2 = line.text.slice(Math.min(pos, next) - line.from, Math.max(pos, next) - line.from);
let nextCat = categorize(nextChar2);
if (cat != null && nextCat != cat)
break;
if (nextChar2 != " " || pos != range.head)
cat = nextCat;
pos = next;
}
return pos;
});
const deleteGroupBackward = (target) => deleteByGroup(target, false);
const deleteGroupForward = (target) => deleteByGroup(target, true);
const deleteToLineEnd = (view) => deleteBy(view, (range) => {
let lineEnd = view.lineBlockAt(range.head).to;
return range.head < lineEnd ? lineEnd : Math.min(view.state.doc.length, range.head + 1);
});
const deleteLineBoundaryBackward = (view) => deleteBy(view, (range) => {
let lineStart = view.moveToLineBoundary(range, false).head;
return range.head > lineStart ? lineStart : Math.max(0, range.head - 1);
});
const deleteLineBoundaryForward = (view) => deleteBy(view, (range) => {
let lineStart = view.moveToLineBoundary(range, true).head;
return range.head < lineStart ? lineStart : Math.min(view.state.doc.length, range.head + 1);
});
const 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;
};
const 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;
}
const moveLineUp = ({ state, dispatch }) => moveLine(state, dispatch, false);
const 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;
}
const copyLineUp = ({ state, dispatch }) => copyLine(state, dispatch, false);
const copyLineDown = ({ state, dispatch }) => copyLine(state, dispatch, true);
const 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 && !/\S/.test(state.sliceDoc(before.to, after.from)))
return { from: before.to, to: after.from };
return null;
}
const insertNewlineAndIndent = /* @__PURE__ */ newlineAndIndent(false);
const insertBlankLine = /* @__PURE__ */ 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 = countColumn(/^\s*/.exec(state.doc.lineAt(from).text)[0], state.tabSize);
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 insert2 = ["", indentString(state, indent)];
if (explode)
insert2.push(indentString(state, cx.lineIndent(line.from, -1)));
return {
changes: { from, to, insert: Text.of(insert2) },
range: EditorSelection.cursor(from + 1 + insert2[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))
};
});
}
const 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 cur2 = /^\s*/.exec(line.text)[0];
let norm = indentString(state, indent);
if (cur2 != norm || range.from < line.from + cur2.length) {
updated[line.from] = indent;
changes2.push({ from: line.from, to: line.from + cur2.length, insert: norm });
}
});
if (!changes.changes.empty)
dispatch(state.update(changes, { userEvent: "indent" }));
return true;
};
const 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;
};
const indentLess = ({ state, dispatch }) => {
if (state.readOnly)
return false;
dispatch(state.update(changeBySelectedLine(state, (line, changes) => {
let space2 = /^\s*/.exec(line.text)[0];
if (!space2)
return;
let col = countColumn(space2, state.tabSize), keep = 0;
let insert2 = indentString(state, Math.max(0, col - getIndentUnit(state)));
while (keep < space2.length && keep < insert2.length && space2.charCodeAt(keep) == insert2.charCodeAt(keep))
keep++;
changes.push({ from: line.from + keep, to: line.from + space2.length, insert: insert2.slice(keep) });
}), { userEvent: "delete.dedent" }));
return true;
};
const 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 }
];
const standardKeymap = /* @__PURE__ */ [
{ key: "ArrowLeft", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true },
{ key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: cursorGroupLeft, shift: selectGroupLeft, preventDefault: true },
{ mac: "Cmd-ArrowLeft", run: cursorLineBoundaryLeft, shift: selectLineBoundaryLeft, preventDefault: true },
{ key: "ArrowRight", run: cursorCharRight, shift: selectCharRight, preventDefault: true },
{ key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: cursorGroupRight, shift: selectGroupRight, preventDefault: true },
{ mac: "Cmd-ArrowRight", run: cursorLineBoundaryRight, shift: selectLineBoundaryRight, preventDefault: true },
{ 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: deleteLineBoundaryBackward },
{ mac: "Mod-Delete", run: deleteLineBoundaryForward }
].concat(/* @__PURE__ */ emacsStyleKeymap.map((b) => ({ mac: b.key, run: b.run, shift: b.shift })));
const defaultKeymap = /* @__PURE__ */ [
{ 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);
const indentWithTab = { key: "Tab", run: indentMore, shift: indentLess };
function crelt() {
var elt = arguments[0];
if (typeof elt == "string")
elt = document.createElement(elt);
var i2 = 1, next = arguments[1];
if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) {
for (var name2 in next)
if (Object.prototype.hasOwnProperty.call(next, name2)) {
var value = next[name2];
if (typeof value == "string")
elt.setAttribute(name2, value);
else if (value != null)
elt[name2] = value;
}
i2++;
}
for (; i2 < arguments.length; i2++)
add(elt, arguments[i2]);
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 i2 = 0; i2 < child.length; i2++)
add(elt, child[i2]);
} else {
throw new RangeError("Unsupported child node: " + child);
}
}
const basicNormalize = typeof String.prototype.normalize == "function" ? (x2) => x2.normalize("NFKD") : (x2) => x2;
class SearchCursor {
/**
Create a text cursor. The query is the search string, `from` to
`to` provides the region to search.
When `normalize` is given, it will be called, on both the query
string and the content it is matched against, before comparing.
You can, for example, create a case-insensitive search by
passing `s => s.toLowerCase()`.
Text is always normalized with
[`.normalize("NFKD")`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
(when supported).
*/
constructor(text, query, from = 0, to = text.length, normalize, test) {
this.test = test;
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);
}
/**
Look for the next match. Updates the iterator's
[`value`](https://codemirror.net/6/docs/ref/#search.SearchCursor.value) and
[`done`](https://codemirror.net/6/docs/ref/#search.SearchCursor.done) properties. Should be called
at least once before using the cursor.
*/
next() {
while (this.matches.length)
this.matches.pop();
return this.nextOverlapping();
}
/**
The `next` method will ignore matches that partially overlap a
previous match. This method behaves like `next`, but includes
such matches.
*/
nextOverlapping() {
for (; ; ) {
let 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 i2 = 0, pos = start; ; i2++) {
let code2 = norm.charCodeAt(i2);
let match2 = this.match(code2, pos, this.bufferPos + this.bufferStart);
if (i2 == norm.length - 1) {
if (match2) {
this.value = match2;
return this;
}
break;
}
if (pos == start && i2 < str.length && str.charCodeAt(i2) == code2)
pos++;
}
}
}
match(code2, pos, end) {
let match2 = null;
for (let i2 = 0; i2 < this.matches.length; i2 += 2) {
let index = this.matches[i2], keep = false;
if (this.query.charCodeAt(index) == code2) {
if (index == this.query.length - 1) {
match2 = { from: this.matches[i2 + 1], to: end };
} else {
this.matches[i2]++;
keep = true;
}
}
if (!keep) {
this.matches.splice(i2, 2);
i2 -= 2;
}
}
if (this.query.charCodeAt(0) == code2) {
if (this.query.length == 1)
match2 = { from: pos, to: end };
else
this.matches.push(1, pos);
}
if (match2 && this.test && !this.test(match2.from, match2.to, this.buffer, this.bufferStart))
match2 = null;
return match2;
}
}
if (typeof Symbol != "undefined")
SearchCursor.prototype[Symbol.iterator] = function() {
return this;
};
const empty = { from: -1, to: -1, match: /* @__PURE__ */ /.*/.exec("") };
const baseFlags = "gm" + (/x/.unicode == null ? "" : "u");
class RegExpCursor {
/**
Create a cursor that will search the given range in the given
document. `query` should be the raw pattern (as you'd pass it to
`new RegExp`).
*/
constructor(text, query, options, from = 0, to = text.length) {
this.text = text;
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.test = options === null || options === void 0 ? void 0 : options.test;
this.iter = text.iter();
let startLine = text.lineAt(from);
this.curLineStart = startLine.from;
this.matchPos = toCharEnd(text, 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);
}
/**
Move to the next match, if there is one.
*/
next() {
for (let off = this.matchPos - this.curLineStart; ; ) {
this.re.lastIndex = off;
let match2 = this.matchPos <= this.to && this.re.exec(this.curLine);
if (match2) {
let from = this.curLineStart + match2.index, to = from + match2[0].length;
this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0));
if (from == this.curLineStart + this.curLine.length)
this.nextLine();
if ((from < to || from > this.value.to) && (!this.test || this.test(from, to, match2))) {
this.value = { from, to, match: match2 };
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;
}
}
}
}
const flattened = /* @__PURE__ */ new WeakMap();
class FlattenedDoc {
constructor(from, text) {
this.from = from;
this.text = text;
}
get to() {
return this.from + this.text.length;
}
static get(doc2, from, to) {
let cached = flattened.get(doc2);
if (!cached || cached.from >= to || cached.to <= from) {
let flat = new FlattenedDoc(from, doc2.sliceString(from, to));
flattened.set(doc2, flat);
return flat;
}
if (cached.from == from && cached.to == to)
return cached;
let { text, from: cachedFrom } = cached;
if (cachedFrom > from) {
text = doc2.sliceString(from, cachedFrom) + text;
cachedFrom = from;
}
if (cached.to < to)
text += doc2.sliceString(cached.to, to);
flattened.set(doc2, new FlattenedDoc(cachedFrom, text));
return new FlattenedDoc(from, text.slice(from - cachedFrom, to - cachedFrom));
}
}
class MultilineRegExpCursor {
constructor(text, query, options, from, to) {
this.text = text;
this.to = to;
this.done = false;
this.value = empty;
this.matchPos = toCharEnd(text, from);
this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : ""));
this.test = options === null || options === void 0 ? void 0 : options.test;
this.flat = FlattenedDoc.get(text, from, this.chunkEnd(
from + 5e3
/* Chunk.Base */
));
}
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 match2 = this.re.exec(this.flat.text);
if (match2 && !match2[0] && match2.index == off) {
this.re.lastIndex = off + 1;
match2 = this.re.exec(this.flat.text);
}
if (match2) {
let from = this.flat.from + match2.index, to = from + match2[0].length;
if ((this.flat.to >= this.to || match2.index + match2[0].length <= this.flat.text.length - 10) && (!this.test || this.test(from, to, match2))) {
this.value = { from, to, match: match2 };
this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0));
return this;
}
}
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 (_a2) {
return false;
}
}
function toCharEnd(text, pos) {
if (pos >= text.length)
return pos;
let line = text.lineAt(pos), next;
while (pos < line.to && (next = line.text.charCodeAt(pos - line.from)) >= 56320 && next < 57344)
pos++;
return pos;
}
function createLineDialog(view) {
let line = String(view.state.doc.lineAt(view.state.selection.main.head).number);
let input = crelt("input", { class: "cm-textfield", name: "line", value: 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 match2 = /^([+-])?(\d+)?(:\d+)?(%)?$/.exec(input.value);
if (!match2)
return;
let { state } = view, startLine = state.doc.lineAt(state.selection.main.head);
let [, sign, ln, cl, percent] = match2;
let col = cl ? +cl.slice(1) : 0;
let line2 = ln ? +ln : startLine.number;
if (ln && percent) {
let pc = line2 / 100;
if (sign)
pc = pc * (sign == "-" ? -1 : 1) + startLine.number / state.doc.lines;
line2 = Math.round(state.doc.lines * pc);
} else if (ln && sign) {
line2 = line2 * (sign == "-" ? -1 : 1) + startLine.number;
}
let docLine = state.doc.line(Math.max(1, Math.min(state.doc.lines, line2)));
let selection = EditorSelection.cursor(docLine.from + Math.max(0, Math.min(col, docLine.length)));
view.dispatch({
effects: [dialogEffect.of(false), EditorView.scrollIntoView(selection.from, { y: "center" })],
selection
});
view.focus();
}
return { dom };
}
const dialogEffect = /* @__PURE__ */ StateEffect.define();
const dialogField = /* @__PURE__ */ 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)
});
const 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$1]));
view.dispatch({ effects });
panel = getPanel(view, createLineDialog);
}
if (panel)
panel.dom.querySelector("input").select();
return true;
};
const baseTheme$1$1 = /* @__PURE__ */ EditorView.baseTheme({
".cm-panel.cm-gotoLine": {
padding: "2px 6px 4px",
"& label": { fontSize: "80%" }
}
});
const defaultHighlightOptions = {
highlightWordAroundCursor: false,
minSelectionLength: 1,
maxMatches: 100,
wholeWords: false
};
const highlightConfig = /* @__PURE__ */ 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;
}
const matchDeco = /* @__PURE__ */ Decoration.mark({ class: "cm-selectionMatch" });
const mainMatchDeco = /* @__PURE__ */ 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;
}
const matchHighlighter = /* @__PURE__ */ 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);
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
});
const defaultTheme = /* @__PURE__ */ EditorView.baseTheme({
".cm-selectionMatch": { backgroundColor: "#99ff7780" },
".cm-searchMatch .cm-selectionMatch": { backgroundColor: "transparent" }
});
const 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;
}
}
}
const 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;
};
const searchConfigFacet = /* @__PURE__ */ Facet.define({
combine(configs) {
return combineConfig(configs, {
top: false,
caseSensitive: false,
literal: false,
regexp: false,
wholeWord: false,
createPanel: (view) => new SearchPanel(view),
scrollToMatch: (range) => EditorView.scrollIntoView(range)
});
}
});
class SearchQuery {
/**
Create a query object.
*/
constructor(config2) {
this.search = config2.search;
this.caseSensitive = !!config2.caseSensitive;
this.literal = !!config2.literal;
this.regexp = !!config2.regexp;
this.replace = config2.replace || "";
this.valid = !!this.search && (!this.regexp || validRegExp(this.search));
this.unquoted = this.unquote(this.search);
this.wholeWord = !!config2.wholeWord;
}
/**
@internal
*/
unquote(text) {
return this.literal ? text : text.replace(/\\([nrt\\])/g, (_, ch) => ch == "n" ? "\n" : ch == "r" ? "\r" : ch == "t" ? " " : "\\");
}
/**
Compare this query to another query.
*/
eq(other) {
return this.search == other.search && this.replace == other.replace && this.caseSensitive == other.caseSensitive && this.regexp == other.regexp && this.wholeWord == other.wholeWord;
}
/**
@internal
*/
create() {
return this.regexp ? new RegExpQuery(this) : new StringQuery(this);
}
/**
Get a search cursor for this query, searching through the given
range in the given state.
*/
getCursor(state, from = 0, to) {
let st = state.doc ? state : EditorState.create({ doc: state });
if (to == null)
to = st.doc.length;
return this.regexp ? regexpCursor(this, st, from, to) : stringCursor(this, st, from, to);
}
}
class QueryType {
constructor(spec) {
this.spec = spec;
}
}
function stringCursor(spec, state, from, to) {
return new SearchCursor(state.doc, spec.unquoted, from, to, spec.caseSensitive ? void 0 : (x2) => x2.toLowerCase(), spec.wholeWord ? stringWordTest(state.doc, state.charCategorizer(state.selection.main.head)) : void 0);
}
function stringWordTest(doc2, categorizer) {
return (from, to, buf, bufPos) => {
if (bufPos > from || bufPos + buf.length < to) {
bufPos = Math.max(0, from - 2);
buf = doc2.sliceString(bufPos, Math.min(doc2.length, to + 2));
}
return (categorizer(charBefore(buf, from - bufPos)) != CharCategory.Word || categorizer(charAfter(buf, from - bufPos)) != CharCategory.Word) && (categorizer(charAfter(buf, to - bufPos)) != CharCategory.Word || categorizer(charBefore(buf, to - bufPos)) != CharCategory.Word);
};
}
class StringQuery extends QueryType {
constructor(spec) {
super(spec);
}
nextMatch(state, curFrom, curTo) {
let cursor = stringCursor(this.spec, state, curTo, state.doc.length).nextOverlapping();
if (cursor.done)
cursor = stringCursor(this.spec, state, 0, curFrom).nextOverlapping();
return cursor.done ? null : cursor.value;
}
// Searching in reverse is, rather than implementing an inverted search
// cursor, done by scanning chunk after chunk forward.
prevMatchInRange(state, from, to) {
for (let pos = to; ; ) {
let start = Math.max(from, pos - 1e4 - this.spec.unquoted.length);
let cursor = stringCursor(this.spec, state, start, pos), range = null;
while (!cursor.nextOverlapping().done)
range = cursor.value;
if (range)
return range;
if (start == from)
return null;
pos -= 1e4;
}
}
prevMatch(state, curFrom, curTo) {
return this.prevMatchInRange(state, 0, curFrom) || this.prevMatchInRange(state, curTo, state.doc.length);
}
getReplacement(_result) {
return this.spec.unquote(this.spec.replace);
}
matchAll(state, limit) {
let cursor = stringCursor(this.spec, state, 0, state.doc.length), ranges = [];
while (!cursor.next().done) {
if (ranges.length >= limit)
return null;
ranges.push(cursor.value);
}
return ranges;
}
highlight(state, from, to, add2) {
let cursor = stringCursor(this.spec, state, Math.max(0, from - this.spec.unquoted.length), Math.min(to + this.spec.unquoted.length, state.doc.length));
while (!cursor.next().done)
add2(cursor.value.from, cursor.value.to);
}
}
function regexpCursor(spec, state, from, to) {
return new RegExpCursor(state.doc, spec.search, {
ignoreCase: !spec.caseSensitive,
test: spec.wholeWord ? regexpWordTest(state.charCategorizer(state.selection.main.head)) : void 0
}, from, to);
}
function charBefore(str, index) {
return str.slice(findClusterBreak(str, index, false), index);
}
function charAfter(str, index) {
return str.slice(index, findClusterBreak(str, index));
}
function regexpWordTest(categorizer) {
return (_from, _to, match2) => !match2[0].length || (categorizer(charBefore(match2.input, match2.index)) != CharCategory.Word || categorizer(charAfter(match2.input, match2.index)) != CharCategory.Word) && (categorizer(charAfter(match2.input, match2.index + match2[0].length)) != CharCategory.Word || categorizer(charBefore(match2.input, match2.index + match2[0].length)) != CharCategory.Word);
}
class RegExpQuery extends QueryType {
nextMatch(state, curFrom, curTo) {
let cursor = regexpCursor(this.spec, state, curTo, state.doc.length).next();
if (cursor.done)
cursor = regexpCursor(this.spec, state, 0, curFrom).next();
return cursor.done ? null : cursor.value;
}
prevMatchInRange(state, from, to) {
for (let size = 1; ; size++) {
let start = Math.max(
from,
to - size * 1e4
/* FindPrev.ChunkSize */
);
let cursor = regexpCursor(this.spec, state, 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(state, curFrom, curTo) {
return this.prevMatchInRange(state, 0, curFrom) || this.prevMatchInRange(state, curTo, state.doc.length);
}
getReplacement(result2) {
return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g, (m, i2) => i2 == "$" ? "$" : i2 == "&" ? result2.match[0] : i2 != "0" && +i2 < result2.match.length ? result2.match[i2] : m);
}
matchAll(state, limit) {
let cursor = regexpCursor(this.spec, state, 0, state.doc.length), ranges = [];
while (!cursor.next().done) {
if (ranges.length >= limit)
return null;
ranges.push(cursor.value);
}
return ranges;
}
highlight(state, from, to, add2) {
let cursor = regexpCursor(this.spec, state, Math.max(
0,
from - 250
/* RegExp.HighlightMargin */
), Math.min(to + 250, state.doc.length));
while (!cursor.next().done)
add2(cursor.value.from, cursor.value.to);
}
}
const setSearchQuery = /* @__PURE__ */ StateEffect.define();
const togglePanel$1 = /* @__PURE__ */ StateEffect.define();
const searchState = /* @__PURE__ */ 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$1))
value = new SearchState(value.query, effect.value ? createSearchPanel : null);
}
return value;
},
provide: (f) => showPanel.from(f, (val) => val.panel)
});
class SearchState {
constructor(query, panel) {
this.query = query;
this.panel = panel;
}
}
const matchMark = /* @__PURE__ */ Decoration.mark({ class: "cm-searchMatch" }), selectedMatchMark = /* @__PURE__ */ Decoration.mark({ class: "cm-searchMatch cm-searchMatch-selected" });
const searchHighlighter = /* @__PURE__ */ 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 i2 = 0, ranges = view.visibleRanges, l = ranges.length; i2 < l; i2++) {
let { from, to } = ranges[i2];
while (i2 < l - 1 && to > ranges[i2 + 1].from - 2 * 250)
to = ranges[++i2].to;
query.highlight(view.state, 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);
};
}
const findNext = /* @__PURE__ */ searchCommand((view, { query }) => {
let { to } = view.state.selection.main;
let next = query.nextMatch(view.state, to, to);
if (!next)
return false;
let selection = EditorSelection.single(next.from, next.to);
let config2 = view.state.facet(searchConfigFacet);
view.dispatch({
selection,
effects: [announceMatch(view, next), config2.scrollToMatch(selection.main, view)],
userEvent: "select.search"
});
selectSearchInput(view);
return true;
});
const findPrevious = /* @__PURE__ */ searchCommand((view, { query }) => {
let { state } = view, { from } = state.selection.main;
let prev = query.prevMatch(state, from, from);
if (!prev)
return false;
let selection = EditorSelection.single(prev.from, prev.to);
let config2 = view.state.facet(searchConfigFacet);
view.dispatch({
selection,
effects: [announceMatch(view, prev), config2.scrollToMatch(selection.main, view)],
userEvent: "select.search"
});
selectSearchInput(view);
return true;
});
const selectMatches = /* @__PURE__ */ searchCommand((view, { query }) => {
let ranges = query.matchAll(view.state, 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;
});
const 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 cur2 = new SearchCursor(state.doc, state.sliceDoc(from, to)); !cur2.next().done; ) {
if (ranges.length > 1e3)
return false;
if (cur2.value.from == from)
main = ranges.length;
ranges.push(EditorSelection.range(cur2.value.from, cur2.value.to));
}
dispatch(state.update({
selection: EditorSelection.create(ranges, main),
userEvent: "select.search.matches"
}));
return true;
};
const replaceNext = /* @__PURE__ */ searchCommand((view, { query }) => {
let { state } = view, { from, to } = state.selection.main;
if (state.readOnly)
return false;
let next = query.nextMatch(state, from, from);
if (!next)
return false;
let changes = [], selection, replacement;
let effects = [];
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, next.from, next.to);
effects.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 = EditorSelection.single(next.from - off, next.to - off);
effects.push(announceMatch(view, next));
effects.push(state.facet(searchConfigFacet).scrollToMatch(selection.main, view));
}
view.dispatch({
changes,
selection,
effects,
userEvent: "input.replace"
});
return true;
});
const replaceAll = /* @__PURE__ */ searchCommand((view, { query }) => {
if (view.state.readOnly)
return false;
let changes = query.matchAll(view.state, 1e9).map((match2) => {
let { from, to } = match2;
return { from, to, insert: query.getReplacement(match2) };
});
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 _a2, _b, _c, _d, _e;
let sel = state.selection.main;
let selText = sel.empty || sel.to > sel.from + 100 ? "" : state.sliceDoc(sel.from, sel.to);
if (fallback && !selText)
return fallback;
let config2 = state.facet(searchConfigFacet);
return new SearchQuery({
search: ((_a2 = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _a2 !== void 0 ? _a2 : config2.literal) ? selText : selText.replace(/\n/g, "\\n"),
caseSensitive: (_b = fallback === null || fallback === void 0 ? void 0 : fallback.caseSensitive) !== null && _b !== void 0 ? _b : config2.caseSensitive,
literal: (_c = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _c !== void 0 ? _c : config2.literal,
regexp: (_d = fallback === null || fallback === void 0 ? void 0 : fallback.regexp) !== null && _d !== void 0 ? _d : config2.regexp,
wholeWord: (_e = fallback === null || fallback === void 0 ? void 0 : fallback.wholeWord) !== null && _e !== void 0 ? _e : config2.wholeWord
});
}
function getSearchInput(view) {
let panel = getPanel(view, createSearchPanel);
return panel && panel.dom.querySelector("[main-field]");
}
function selectSearchInput(view) {
let input = getSearchInput(view);
if (input && input == view.root.activeElement)
input.select();
}
const openSearchPanel = (view) => {
let state = view.state.field(searchState, false);
if (state && state.panel) {
let searchInput = getSearchInput(view);
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$1.of(true),
state ? setSearchQuery.of(defaultQuery(view.state, state.query.spec)) : StateEffect.appendConfig.of(searchExtensions)
] });
}
return true;
};
const 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$1.of(false) });
return true;
};
const 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: "Mod-Alt-g", run: gotoLine },
{ key: "Mod-d", run: selectNextOccurrence, preventDefault: true }
];
class SearchPanel {
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",
form: "",
"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",
form: "",
onchange: this.commit,
onkeyup: this.commit
});
this.caseField = crelt("input", {
type: "checkbox",
name: "case",
form: "",
checked: query.caseSensitive,
onchange: this.commit
});
this.reField = crelt("input", {
type: "checkbox",
name: "re",
form: "",
checked: query.regexp,
onchange: this.commit
});
this.wordField = crelt("input", {
type: "checkbox",
name: "word",
form: "",
checked: query.wholeWord,
onchange: this.commit
});
function button(name2, onclick, content2) {
return crelt("button", { class: "cm-button", name: name2, onclick, type: "button" }, content2);
}
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")]),
crelt("label", null, [this.wordField, phrase(view, "by word")]),
...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"
}, ["×"])
]);
}
commit() {
let query = new SearchQuery({
search: this.searchField.value,
caseSensitive: this.caseField.checked,
regexp: this.reField.checked,
wholeWord: this.wordField.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;
this.wordField.checked = query.wholeWord;
}
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);
}
const AnnounceMargin = 30;
const 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 i2 = 0; i2 < AnnounceMargin; i2++)
if (!Break.test(text[i2 + 1]) && Break.test(text[i2])) {
text = text.slice(i2);
break;
}
}
if (end != lineEnd) {
for (let i2 = text.length - 1; i2 > text.length - AnnounceMargin; i2--)
if (!Break.test(text[i2 - 1]) && Break.test(text[i2])) {
text = text.slice(0, i2);
break;
}
}
return EditorView.announce.of(`${view.state.phrase("current match")}. ${text} ${view.state.phrase("on line")} ${line.number}.`);
}
const baseTheme$2 = /* @__PURE__ */ 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" }
});
const searchExtensions = [
searchState,
/* @__PURE__ */ Prec.low(searchHighlighter),
baseTheme$2
];
class CompletionContext {
/**
Create a new completion context. (Mostly useful for testing
completion sources—in the editor, the extension will create
these for you.)
*/
constructor(state, pos, explicit) {
this.state = state;
this.pos = pos;
this.explicit = explicit;
this.abortListeners = [];
}
/**
Get the extent, content, and (if there is a token) type of the
token before `this.pos`.
*/
tokenBefore(types2) {
let token = syntaxTree(this.state).resolveInner(this.pos, -1);
while (token && types2.indexOf(token.name) < 0)
token = token.parent;
return token ? {
from: token.from,
to: this.pos,
text: this.state.sliceDoc(token.from, this.pos),
type: token.type
} : null;
}
/**
Get the match of the given expression directly before the
cursor.
*/
matchBefore(expr) {
let line = this.state.doc.lineAt(this.pos);
let start = Math.max(line.from, this.pos - 250);
let str = line.text.slice(start - line.from, this.pos - line.from);
let found = str.search(ensureAnchor(expr, false));
return found < 0 ? null : { from: start + found, to: this.pos, text: str.slice(found) };
}
/**
Yields true when the query has been aborted. Can be useful in
asynchronous queries to avoid doing work that will be ignored.
*/
get aborted() {
return this.abortListeners == null;
}
/**
Allows you to register abort handlers, which will be called when
the query is
[aborted](https://codemirror.net/6/docs/ref/#autocomplete.CompletionContext.aborted).
*/
addEventListener(type, listener) {
if (type == "abort" && this.abortListeners)
this.abortListeners.push(listener);
}
}
function toSet(chars) {
let flat = Object.keys(chars).join("");
let words = /\w/.test(flat);
if (words)
flat = flat.replace(/\w/g, "");
return `[${words ? "\\w" : ""}${flat.replace(/[^\w\s]/g, "\\$&")}]`;
}
function prefixMatch(options) {
let first = /* @__PURE__ */ Object.create(null), rest = /* @__PURE__ */ Object.create(null);
for (let { label } of options) {
first[label[0]] = true;
for (let i2 = 1; i2 < label.length; i2++)
rest[label[i2]] = true;
}
let source = toSet(first) + toSet(rest) + "*$";
return [new RegExp("^" + source), new RegExp(source)];
}
function completeFromList(list) {
let options = list.map((o) => typeof o == "string" ? { label: o } : o);
let [validFor, match2] = options.every((o) => /^\w+$/.test(o.label)) ? [/\w*$/, /\w+$/] : prefixMatch(options);
return (context) => {
let token = context.matchBefore(match2);
return token || context.explicit ? { from: token ? token.from : context.pos, options, validFor } : null;
};
}
function ifNotIn(nodes, source) {
return (context) => {
for (let pos = syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent) {
if (nodes.indexOf(pos.name) > -1)
return null;
if (pos.type.isTop)
break;
}
return source(context);
};
}
class Option {
constructor(completion, source, match2, score2) {
this.completion = completion;
this.source = source;
this.match = match2;
this.score = score2;
}
}
function cur(state) {
return state.selection.main.from;
}
function ensureAnchor(expr, start) {
var _a2;
let { source } = expr;
let addStart = start && source[0] != "^", addEnd = source[source.length - 1] != "$";
if (!addStart && !addEnd)
return expr;
return new RegExp(`${addStart ? "^" : ""}(?:${source})${addEnd ? "$" : ""}`, (_a2 = expr.flags) !== null && _a2 !== void 0 ? _a2 : expr.ignoreCase ? "i" : "");
}
const pickedCompletion = /* @__PURE__ */ Annotation.define();
function insertCompletionText(state, text, from, to) {
let { main } = state.selection, fromOff = from - main.from, toOff = to - main.from;
return Object.assign(Object.assign({}, state.changeByRange((range) => {
if (range != main && from != to && state.sliceDoc(range.from + fromOff, range.from + toOff) != state.sliceDoc(from, to))
return { range };
return {
changes: { from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert: text },
range: EditorSelection.cursor(range.from + fromOff + text.length)
};
})), { scrollIntoView: true, userEvent: "input.complete" });
}
const SourceCache = /* @__PURE__ */ new WeakMap();
function asSource(source) {
if (!Array.isArray(source))
return source;
let known = SourceCache.get(source);
if (!known)
SourceCache.set(source, known = completeFromList(source));
return known;
}
const startCompletionEffect = /* @__PURE__ */ StateEffect.define();
const closeCompletionEffect = /* @__PURE__ */ StateEffect.define();
class FuzzyMatcher {
constructor(pattern) {
this.pattern = pattern;
this.chars = [];
this.folded = [];
this.any = [];
this.precise = [];
this.byWord = [];
this.score = 0;
this.matched = [];
for (let p = 0; p < pattern.length; ) {
let char = codePointAt(pattern, p), size = codePointSize(char);
this.chars.push(char);
let part = pattern.slice(p, p + size), upper = part.toUpperCase();
this.folded.push(codePointAt(upper == part ? part.toLowerCase() : upper, 0));
p += size;
}
this.astral = pattern.length != this.chars.length;
}
ret(score2, matched) {
this.score = score2;
this.matched = matched;
return true;
}
// Matches a given word (completion) against the pattern (input).
// Will return a boolean indicating whether there was a match and,
// on success, set `this.score` to the score, `this.matched` to an
// array of `from, to` pairs indicating the matched parts of `word`.
//
// The score is a number that is more negative the worse the match
// is. See `Penalty` above.
match(word) {
if (this.pattern.length == 0)
return this.ret(-100, []);
if (word.length < this.pattern.length)
return false;
let { chars, folded, any, precise, byWord } = this;
if (chars.length == 1) {
let first = codePointAt(word, 0), firstSize = codePointSize(first);
let score2 = firstSize == word.length ? 0 : -100;
if (first == chars[0])
;
else if (first == folded[0])
score2 += -200;
else
return false;
return this.ret(score2, [0, firstSize]);
}
let direct = word.indexOf(this.pattern);
if (direct == 0)
return this.ret(word.length == this.pattern.length ? 0 : -100, [0, this.pattern.length]);
let len = chars.length, anyTo = 0;
if (direct < 0) {
for (let i2 = 0, e = Math.min(word.length, 200); i2 < e && anyTo < len; ) {
let next = codePointAt(word, i2);
if (next == chars[anyTo] || next == folded[anyTo])
any[anyTo++] = i2;
i2 += codePointSize(next);
}
if (anyTo < len)
return false;
}
let preciseTo = 0;
let byWordTo = 0, byWordFolded = false;
let adjacentTo = 0, adjacentStart = -1, adjacentEnd = -1;
let hasLower = /[a-z]/.test(word), wordAdjacent = true;
for (let i2 = 0, e = Math.min(word.length, 200), prevType = 0; i2 < e && byWordTo < len; ) {
let next = codePointAt(word, i2);
if (direct < 0) {
if (preciseTo < len && next == chars[preciseTo])
precise[preciseTo++] = i2;
if (adjacentTo < len) {
if (next == chars[adjacentTo] || next == folded[adjacentTo]) {
if (adjacentTo == 0)
adjacentStart = i2;
adjacentEnd = i2 + 1;
adjacentTo++;
} else {
adjacentTo = 0;
}
}
}
let ch, type = next < 255 ? next >= 48 && next <= 57 || next >= 97 && next <= 122 ? 2 : next >= 65 && next <= 90 ? 1 : 0 : (ch = fromCodePoint(next)) != ch.toLowerCase() ? 1 : ch != ch.toUpperCase() ? 2 : 0;
if (!i2 || type == 1 && hasLower || prevType == 0 && type != 0) {
if (chars[byWordTo] == next || folded[byWordTo] == next && (byWordFolded = true))
byWord[byWordTo++] = i2;
else if (byWord.length)
wordAdjacent = false;
}
prevType = type;
i2 += codePointSize(next);
}
if (byWordTo == len && byWord[0] == 0 && wordAdjacent)
return this.result(-100 + (byWordFolded ? -200 : 0), byWord, word);
if (adjacentTo == len && adjacentStart == 0)
return this.ret(-200 - word.length + (adjacentEnd == word.length ? 0 : -100), [0, adjacentEnd]);
if (direct > -1)
return this.ret(-700 - word.length, [direct, direct + this.pattern.length]);
if (adjacentTo == len)
return this.ret(-200 + -700 - word.length, [adjacentStart, adjacentEnd]);
if (byWordTo == len)
return this.result(-100 + (byWordFolded ? -200 : 0) + -700 + (wordAdjacent ? 0 : -1100), byWord, word);
return chars.length == 2 ? false : this.result((any[0] ? -700 : 0) + -200 + -1100, any, word);
}
result(score2, positions, word) {
let result2 = [], i2 = 0;
for (let pos of positions) {
let to = pos + (this.astral ? codePointSize(codePointAt(word, pos)) : 1);
if (i2 && result2[i2 - 1] == pos)
result2[i2 - 1] = to;
else {
result2[i2++] = pos;
result2[i2++] = to;
}
}
return this.ret(score2 - word.length, result2);
}
}
const completionConfig = /* @__PURE__ */ Facet.define({
combine(configs) {
return combineConfig(configs, {
activateOnTyping: true,
activateOnTypingDelay: 100,
selectOnOpen: true,
override: null,
closeOnBlur: true,
maxRenderedOptions: 100,
defaultKeymap: true,
tooltipClass: () => "",
optionClass: () => "",
aboveCursor: false,
icons: true,
addToOptions: [],
positionInfo: defaultPositionInfo,
compareCompletions: (a, b) => a.label.localeCompare(b.label),
interactionDelay: 75,
updateSyncTime: 100
}, {
defaultKeymap: (a, b) => a && b,
closeOnBlur: (a, b) => a && b,
icons: (a, b) => a && b,
tooltipClass: (a, b) => (c) => joinClass(a(c), b(c)),
optionClass: (a, b) => (c) => joinClass(a(c), b(c)),
addToOptions: (a, b) => a.concat(b)
});
}
});
function joinClass(a, b) {
return a ? b ? a + " " + b : a : b;
}
function defaultPositionInfo(view, list, option, info, space2, tooltip) {
let rtl = view.textDirection == Direction.RTL, left = rtl, narrow = false;
let side = "top", offset, maxWidth;
let spaceLeft = list.left - space2.left, spaceRight = space2.right - list.right;
let infoWidth = info.right - info.left, infoHeight = info.bottom - info.top;
if (left && spaceLeft < Math.min(infoWidth, spaceRight))
left = false;
else if (!left && spaceRight < Math.min(infoWidth, spaceLeft))
left = true;
if (infoWidth <= (left ? spaceLeft : spaceRight)) {
offset = Math.max(space2.top, Math.min(option.top, space2.bottom - infoHeight)) - list.top;
maxWidth = Math.min(400, left ? spaceLeft : spaceRight);
} else {
narrow = true;
maxWidth = Math.min(
400,
(rtl ? list.right : space2.right - list.left) - 30
/* Info.Margin */
);
let spaceBelow = space2.bottom - list.bottom;
if (spaceBelow >= infoHeight || spaceBelow > list.top) {
offset = option.bottom - list.top;
} else {
side = "bottom";
offset = list.bottom - option.top;
}
}
let scaleY = (list.bottom - list.top) / tooltip.offsetHeight;
let scaleX = (list.right - list.left) / tooltip.offsetWidth;
return {
style: `${side}: ${offset / scaleY}px; max-width: ${maxWidth / scaleX}px`,
class: "cm-completionInfo-" + (narrow ? rtl ? "left-narrow" : "right-narrow" : left ? "left" : "right")
};
}
function optionContent(config2) {
let content2 = config2.addToOptions.slice();
if (config2.icons)
content2.push({
render(completion) {
let icon = document.createElement("div");
icon.classList.add("cm-completionIcon");
if (completion.type)
icon.classList.add(...completion.type.split(/\s+/g).map((cls) => "cm-completionIcon-" + cls));
icon.setAttribute("aria-hidden", "true");
return icon;
},
position: 20
});
content2.push({
render(completion, _s, _v, match2) {
let labelElt = document.createElement("span");
labelElt.className = "cm-completionLabel";
let label = completion.displayLabel || completion.label, off = 0;
for (let j2 = 0; j2 < match2.length; ) {
let from = match2[j2++], to = match2[j2++];
if (from > off)
labelElt.appendChild(document.createTextNode(label.slice(off, from)));
let span = labelElt.appendChild(document.createElement("span"));
span.appendChild(document.createTextNode(label.slice(from, to)));
span.className = "cm-completionMatchedText";
off = to;
}
if (off < label.length)
labelElt.appendChild(document.createTextNode(label.slice(off)));
return labelElt;
},
position: 50
}, {
render(completion) {
if (!completion.detail)
return null;
let detailElt = document.createElement("span");
detailElt.className = "cm-completionDetail";
detailElt.textContent = completion.detail;
return detailElt;
},
position: 80
});
return content2.sort((a, b) => a.position - b.position).map((a) => a.render);
}
function rangeAroundSelected(total, selected, max) {
if (total <= max)
return { from: 0, to: total };
if (selected < 0)
selected = 0;
if (selected <= total >> 1) {
let off2 = Math.floor(selected / max);
return { from: off2 * max, to: (off2 + 1) * max };
}
let off = Math.floor((total - selected) / max);
return { from: total - (off + 1) * max, to: total - off * max };
}
class CompletionTooltip {
constructor(view, stateField, applyCompletion2) {
this.view = view;
this.stateField = stateField;
this.applyCompletion = applyCompletion2;
this.info = null;
this.infoDestroy = null;
this.placeInfoReq = {
read: () => this.measureInfo(),
write: (pos) => this.placeInfo(pos),
key: this
};
this.space = null;
this.currentClass = "";
let cState = view.state.field(stateField);
let { options, selected } = cState.open;
let config2 = view.state.facet(completionConfig);
this.optionContent = optionContent(config2);
this.optionClass = config2.optionClass;
this.tooltipClass = config2.tooltipClass;
this.range = rangeAroundSelected(options.length, selected, config2.maxRenderedOptions);
this.dom = document.createElement("div");
this.dom.className = "cm-tooltip-autocomplete";
this.updateTooltipClass(view.state);
this.dom.addEventListener("mousedown", (e) => {
let { options: options2 } = view.state.field(stateField).open;
for (let dom = e.target, match2; dom && dom != this.dom; dom = dom.parentNode) {
if (dom.nodeName == "LI" && (match2 = /-(\d+)$/.exec(dom.id)) && +match2[1] < options2.length) {
this.applyCompletion(view, options2[+match2[1]]);
e.preventDefault();
return;
}
}
});
this.dom.addEventListener("focusout", (e) => {
let state = view.state.field(this.stateField, false);
if (state && state.tooltip && view.state.facet(completionConfig).closeOnBlur && e.relatedTarget != view.contentDOM)
view.dispatch({ effects: closeCompletionEffect.of(null) });
});
this.showOptions(options, cState.id);
}
mount() {
this.updateSel();
}
showOptions(options, id2) {
if (this.list)
this.list.remove();
this.list = this.dom.appendChild(this.createListBox(options, id2, this.range));
this.list.addEventListener("scroll", () => {
if (this.info)
this.view.requestMeasure(this.placeInfoReq);
});
}
update(update) {
var _a2;
let cState = update.state.field(this.stateField);
let prevState = update.startState.field(this.stateField);
this.updateTooltipClass(update.state);
if (cState != prevState) {
let { options, selected, disabled } = cState.open;
if (!prevState.open || prevState.open.options != options) {
this.range = rangeAroundSelected(options.length, selected, update.state.facet(completionConfig).maxRenderedOptions);
this.showOptions(options, cState.id);
}
this.updateSel();
if (disabled != ((_a2 = prevState.open) === null || _a2 === void 0 ? void 0 : _a2.disabled))
this.dom.classList.toggle("cm-tooltip-autocomplete-disabled", !!disabled);
}
}
updateTooltipClass(state) {
let cls = this.tooltipClass(state);
if (cls != this.currentClass) {
for (let c of this.currentClass.split(" "))
if (c)
this.dom.classList.remove(c);
for (let c of cls.split(" "))
if (c)
this.dom.classList.add(c);
this.currentClass = cls;
}
}
positioned(space2) {
this.space = space2;
if (this.info)
this.view.requestMeasure(this.placeInfoReq);
}
updateSel() {
let cState = this.view.state.field(this.stateField), open = cState.open;
if (open.selected > -1 && open.selected < this.range.from || open.selected >= this.range.to) {
this.range = rangeAroundSelected(open.options.length, open.selected, this.view.state.facet(completionConfig).maxRenderedOptions);
this.showOptions(open.options, cState.id);
}
if (this.updateSelectedOption(open.selected)) {
this.destroyInfo();
let { completion } = open.options[open.selected];
let { info } = completion;
if (!info)
return;
let infoResult = typeof info === "string" ? document.createTextNode(info) : info(completion);
if (!infoResult)
return;
if ("then" in infoResult) {
infoResult.then((obj) => {
if (obj && this.view.state.field(this.stateField, false) == cState)
this.addInfoPane(obj, completion);
}).catch((e) => logException(this.view.state, e, "completion info"));
} else {
this.addInfoPane(infoResult, completion);
}
}
}
addInfoPane(content2, completion) {
this.destroyInfo();
let wrap = this.info = document.createElement("div");
wrap.className = "cm-tooltip cm-completionInfo";
if (content2.nodeType != null) {
wrap.appendChild(content2);
this.infoDestroy = null;
} else {
let { dom, destroy } = content2;
wrap.appendChild(dom);
this.infoDestroy = destroy || null;
}
this.dom.appendChild(wrap);
this.view.requestMeasure(this.placeInfoReq);
}
updateSelectedOption(selected) {
let set = null;
for (let opt = this.list.firstChild, i2 = this.range.from; opt; opt = opt.nextSibling, i2++) {
if (opt.nodeName != "LI" || !opt.id) {
i2--;
} else if (i2 == selected) {
if (!opt.hasAttribute("aria-selected")) {
opt.setAttribute("aria-selected", "true");
set = opt;
}
} else {
if (opt.hasAttribute("aria-selected"))
opt.removeAttribute("aria-selected");
}
}
if (set)
scrollIntoView(this.list, set);
return set;
}
measureInfo() {
let sel = this.dom.querySelector("[aria-selected]");
if (!sel || !this.info)
return null;
let listRect = this.dom.getBoundingClientRect();
let infoRect = this.info.getBoundingClientRect();
let selRect = sel.getBoundingClientRect();
let space2 = this.space;
if (!space2) {
let win = this.dom.ownerDocument.defaultView || window;
space2 = { left: 0, top: 0, right: win.innerWidth, bottom: win.innerHeight };
}
if (selRect.top > Math.min(space2.bottom, listRect.bottom) - 10 || selRect.bottom < Math.max(space2.top, listRect.top) + 10)
return null;
return this.view.state.facet(completionConfig).positionInfo(this.view, listRect, selRect, infoRect, space2, this.dom);
}
placeInfo(pos) {
if (this.info) {
if (pos) {
if (pos.style)
this.info.style.cssText = pos.style;
this.info.className = "cm-tooltip cm-completionInfo " + (pos.class || "");
} else {
this.info.style.cssText = "top: -1e6px";
}
}
}
createListBox(options, id2, range) {
const ul = document.createElement("ul");
ul.id = id2;
ul.setAttribute("role", "listbox");
ul.setAttribute("aria-expanded", "true");
ul.setAttribute("aria-label", this.view.state.phrase("Completions"));
let curSection = null;
for (let i2 = range.from; i2 < range.to; i2++) {
let { completion, match: match2 } = options[i2], { section } = completion;
if (section) {
let name2 = typeof section == "string" ? section : section.name;
if (name2 != curSection && (i2 > range.from || range.from == 0)) {
curSection = name2;
if (typeof section != "string" && section.header) {
ul.appendChild(section.header(section));
} else {
let header2 = ul.appendChild(document.createElement("completion-section"));
header2.textContent = name2;
}
}
}
const li = ul.appendChild(document.createElement("li"));
li.id = id2 + "-" + i2;
li.setAttribute("role", "option");
let cls = this.optionClass(completion);
if (cls)
li.className = cls;
for (let source of this.optionContent) {
let node = source(completion, this.view.state, this.view, match2);
if (node)
li.appendChild(node);
}
}
if (range.from)
ul.classList.add("cm-completionListIncompleteTop");
if (range.to < options.length)
ul.classList.add("cm-completionListIncompleteBottom");
return ul;
}
destroyInfo() {
if (this.info) {
if (this.infoDestroy)
this.infoDestroy();
this.info.remove();
this.info = null;
}
}
destroy() {
this.destroyInfo();
}
}
function completionTooltip(stateField, applyCompletion2) {
return (view) => new CompletionTooltip(view, stateField, applyCompletion2);
}
function scrollIntoView(container, element) {
let parent = container.getBoundingClientRect();
let self = element.getBoundingClientRect();
let scaleY = parent.height / container.offsetHeight;
if (self.top < parent.top)
container.scrollTop -= (parent.top - self.top) / scaleY;
else if (self.bottom > parent.bottom)
container.scrollTop += (self.bottom - parent.bottom) / scaleY;
}
function score(option) {
return (option.boost || 0) * 100 + (option.apply ? 10 : 0) + (option.info ? 5 : 0) + (option.type ? 1 : 0);
}
function sortOptions(active, state) {
let options = [];
let sections = null;
let addOption = (option) => {
options.push(option);
let { section } = option.completion;
if (section) {
if (!sections)
sections = [];
let name2 = typeof section == "string" ? section : section.name;
if (!sections.some((s) => s.name == name2))
sections.push(typeof section == "string" ? { name: name2 } : section);
}
};
for (let a of active)
if (a.hasResult()) {
let getMatch = a.result.getMatch;
if (a.result.filter === false) {
for (let option of a.result.options) {
addOption(new Option(option, a.source, getMatch ? getMatch(option) : [], 1e9 - options.length));
}
} else {
let matcher = new FuzzyMatcher(state.sliceDoc(a.from, a.to));
for (let option of a.result.options)
if (matcher.match(option.label)) {
let matched = !option.displayLabel ? matcher.matched : getMatch ? getMatch(option, matcher.matched) : [];
addOption(new Option(option, a.source, matched, matcher.score + (option.boost || 0)));
}
}
}
if (sections) {
let sectionOrder = /* @__PURE__ */ Object.create(null), pos = 0;
let cmp = (a, b) => {
var _a2, _b;
return ((_a2 = a.rank) !== null && _a2 !== void 0 ? _a2 : 1e9) - ((_b = b.rank) !== null && _b !== void 0 ? _b : 1e9) || (a.name < b.name ? -1 : 1);
};
for (let s of sections.sort(cmp)) {
pos -= 1e5;
sectionOrder[s.name] = pos;
}
for (let option of options) {
let { section } = option.completion;
if (section)
option.score += sectionOrder[typeof section == "string" ? section : section.name];
}
}
let result2 = [], prev = null;
let compare2 = state.facet(completionConfig).compareCompletions;
for (let opt of options.sort((a, b) => b.score - a.score || compare2(a.completion, b.completion))) {
let cur2 = opt.completion;
if (!prev || prev.label != cur2.label || prev.detail != cur2.detail || prev.type != null && cur2.type != null && prev.type != cur2.type || prev.apply != cur2.apply || prev.boost != cur2.boost)
result2.push(opt);
else if (score(opt.completion) > score(prev))
result2[result2.length - 1] = opt;
prev = opt.completion;
}
return result2;
}
class CompletionDialog {
constructor(options, attrs, tooltip, timestamp, selected, disabled) {
this.options = options;
this.attrs = attrs;
this.tooltip = tooltip;
this.timestamp = timestamp;
this.selected = selected;
this.disabled = disabled;
}
setSelected(selected, id2) {
return selected == this.selected || selected >= this.options.length ? this : new CompletionDialog(this.options, makeAttrs(id2, selected), this.tooltip, this.timestamp, selected, this.disabled);
}
static build(active, state, id2, prev, conf) {
let options = sortOptions(active, state);
if (!options.length) {
return prev && active.some(
(a) => a.state == 1
/* State.Pending */
) ? new CompletionDialog(prev.options, prev.attrs, prev.tooltip, prev.timestamp, prev.selected, true) : null;
}
let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
if (prev && prev.selected != selected && prev.selected != -1) {
let selectedValue = prev.options[prev.selected].completion;
for (let i2 = 0; i2 < options.length; i2++)
if (options[i2].completion == selectedValue) {
selected = i2;
break;
}
}
return new CompletionDialog(options, makeAttrs(id2, selected), {
pos: active.reduce((a, b) => b.hasResult() ? Math.min(a, b.from) : a, 1e8),
create: createTooltip,
above: conf.aboveCursor
}, prev ? prev.timestamp : Date.now(), selected, false);
}
map(changes) {
return new CompletionDialog(this.options, this.attrs, Object.assign(Object.assign({}, this.tooltip), { pos: changes.mapPos(this.tooltip.pos) }), this.timestamp, this.selected, this.disabled);
}
}
class CompletionState {
constructor(active, id2, open) {
this.active = active;
this.id = id2;
this.open = open;
}
static start() {
return new CompletionState(none, "cm-ac-" + Math.floor(Math.random() * 2e6).toString(36), null);
}
update(tr) {
let { state } = tr, conf = state.facet(completionConfig);
let sources = conf.override || state.languageDataAt("autocomplete", cur(state)).map(asSource);
let active = sources.map((source) => {
let value = this.active.find((s) => s.source == source) || new ActiveSource(
source,
this.active.some(
(a) => a.state != 0
/* State.Inactive */
) ? 1 : 0
/* State.Inactive */
);
return value.update(tr, conf);
});
if (active.length == this.active.length && active.every((a, i2) => a == this.active[i2]))
active = this.active;
let open = this.open;
if (open && tr.docChanged)
open = open.map(tr.changes);
if (tr.selection || active.some((a) => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) || !sameResults(active, this.active))
open = CompletionDialog.build(active, state, this.id, open, conf);
else if (open && open.disabled && !active.some(
(a) => a.state == 1
/* State.Pending */
))
open = null;
if (!open && active.every(
(a) => a.state != 1
/* State.Pending */
) && active.some((a) => a.hasResult()))
active = active.map((a) => a.hasResult() ? new ActiveSource(
a.source,
0
/* State.Inactive */
) : a);
for (let effect of tr.effects)
if (effect.is(setSelectedEffect))
open = open && open.setSelected(effect.value, this.id);
return active == this.active && open == this.open ? this : new CompletionState(active, this.id, open);
}
get tooltip() {
return this.open ? this.open.tooltip : null;
}
get attrs() {
return this.open ? this.open.attrs : baseAttrs;
}
}
function sameResults(a, b) {
if (a == b)
return true;
for (let iA = 0, iB = 0; ; ) {
while (iA < a.length && !a[iA].hasResult)
iA++;
while (iB < b.length && !b[iB].hasResult)
iB++;
let endA = iA == a.length, endB = iB == b.length;
if (endA || endB)
return endA == endB;
if (a[iA++].result != b[iB++].result)
return false;
}
}
const baseAttrs = {
"aria-autocomplete": "list"
};
function makeAttrs(id2, selected) {
let result2 = {
"aria-autocomplete": "list",
"aria-haspopup": "listbox",
"aria-controls": id2
};
if (selected > -1)
result2["aria-activedescendant"] = id2 + "-" + selected;
return result2;
}
const none = [];
function getUserEvent(tr) {
return tr.isUserEvent("input.type") ? "input" : tr.isUserEvent("delete.backward") ? "delete" : null;
}
class ActiveSource {
constructor(source, state, explicitPos = -1) {
this.source = source;
this.state = state;
this.explicitPos = explicitPos;
}
hasResult() {
return false;
}
update(tr, conf) {
let event = getUserEvent(tr), value = this;
if (event)
value = value.handleUserEvent(tr, event, conf);
else if (tr.docChanged)
value = value.handleChange(tr);
else if (tr.selection && value.state != 0)
value = new ActiveSource(
value.source,
0
/* State.Inactive */
);
for (let effect of tr.effects) {
if (effect.is(startCompletionEffect))
value = new ActiveSource(value.source, 1, effect.value ? cur(tr.state) : -1);
else if (effect.is(closeCompletionEffect))
value = new ActiveSource(
value.source,
0
/* State.Inactive */
);
else if (effect.is(setActiveEffect)) {
for (let active of effect.value)
if (active.source == value.source)
value = active;
}
}
return value;
}
handleUserEvent(tr, type, conf) {
return type == "delete" || !conf.activateOnTyping ? this.map(tr.changes) : new ActiveSource(
this.source,
1
/* State.Pending */
);
}
handleChange(tr) {
return tr.changes.touchesRange(cur(tr.startState)) ? new ActiveSource(
this.source,
0
/* State.Inactive */
) : this.map(tr.changes);
}
map(changes) {
return changes.empty || this.explicitPos < 0 ? this : new ActiveSource(this.source, this.state, changes.mapPos(this.explicitPos));
}
}
class ActiveResult extends ActiveSource {
constructor(source, explicitPos, result2, from, to) {
super(source, 2, explicitPos);
this.result = result2;
this.from = from;
this.to = to;
}
hasResult() {
return true;
}
handleUserEvent(tr, type, conf) {
var _a2;
let from = tr.changes.mapPos(this.from), to = tr.changes.mapPos(this.to, 1);
let pos = cur(tr.state);
if ((this.explicitPos < 0 ? pos <= from : pos < this.from) || pos > to || type == "delete" && cur(tr.startState) == this.from)
return new ActiveSource(
this.source,
type == "input" && conf.activateOnTyping ? 1 : 0
/* State.Inactive */
);
let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos), updated;
if (checkValid(this.result.validFor, tr.state, from, to))
return new ActiveResult(this.source, explicitPos, this.result, from, to);
if (this.result.update && (updated = this.result.update(this.result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0))))
return new ActiveResult(this.source, explicitPos, updated, updated.from, (_a2 = updated.to) !== null && _a2 !== void 0 ? _a2 : cur(tr.state));
return new ActiveSource(this.source, 1, explicitPos);
}
handleChange(tr) {
return tr.changes.touchesRange(this.from, this.to) ? new ActiveSource(
this.source,
0
/* State.Inactive */
) : this.map(tr.changes);
}
map(mapping) {
return mapping.empty ? this : new ActiveResult(this.source, this.explicitPos < 0 ? -1 : mapping.mapPos(this.explicitPos), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
}
}
function checkValid(validFor, state, from, to) {
if (!validFor)
return false;
let text = state.sliceDoc(from, to);
return typeof validFor == "function" ? validFor(text, from, to, state) : ensureAnchor(validFor, true).test(text);
}
const setActiveEffect = /* @__PURE__ */ StateEffect.define({
map(sources, mapping) {
return sources.map((s) => s.map(mapping));
}
});
const setSelectedEffect = /* @__PURE__ */ StateEffect.define();
const completionState = /* @__PURE__ */ StateField.define({
create() {
return CompletionState.start();
},
update(value, tr) {
return value.update(tr);
},
provide: (f) => [
showTooltip.from(f, (val) => val.tooltip),
EditorView.contentAttributes.from(f, (state) => state.attrs)
]
});
function applyCompletion(view, option) {
const apply = option.completion.apply || option.completion.label;
let result2 = view.state.field(completionState).active.find((a) => a.source == option.source);
if (!(result2 instanceof ActiveResult))
return false;
if (typeof apply == "string")
view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, apply, result2.from, result2.to)), { annotations: pickedCompletion.of(option.completion) }));
else
apply(view, option.completion, result2.from, result2.to);
return true;
}
const createTooltip = /* @__PURE__ */ completionTooltip(completionState, applyCompletion);
function moveCompletionSelection(forward, by = "option") {
return (view) => {
let cState = view.state.field(completionState, false);
if (!cState || !cState.open || cState.open.disabled || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
return false;
let step = 1, tooltip;
if (by == "page" && (tooltip = getTooltip(view, cState.open.tooltip)))
step = Math.max(2, Math.floor(tooltip.dom.offsetHeight / tooltip.dom.querySelector("li").offsetHeight) - 1);
let { length } = cState.open.options;
let selected = cState.open.selected > -1 ? cState.open.selected + step * (forward ? 1 : -1) : forward ? 0 : length - 1;
if (selected < 0)
selected = by == "page" ? 0 : length - 1;
else if (selected >= length)
selected = by == "page" ? length - 1 : 0;
view.dispatch({ effects: setSelectedEffect.of(selected) });
return true;
};
}
const acceptCompletion = (view) => {
let cState = view.state.field(completionState, false);
if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 || cState.open.disabled || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
return false;
return applyCompletion(view, cState.open.options[cState.open.selected]);
};
const startCompletion = (view) => {
let cState = view.state.field(completionState, false);
if (!cState)
return false;
view.dispatch({ effects: startCompletionEffect.of(true) });
return true;
};
const closeCompletion = (view) => {
let cState = view.state.field(completionState, false);
if (!cState || !cState.active.some(
(a) => a.state != 0
/* State.Inactive */
))
return false;
view.dispatch({ effects: closeCompletionEffect.of(null) });
return true;
};
class RunningQuery {
constructor(active, context) {
this.active = active;
this.context = context;
this.time = Date.now();
this.updates = [];
this.done = void 0;
}
}
const MaxUpdateCount = 50, MinAbortTime = 1e3;
const completionPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
constructor(view) {
this.view = view;
this.debounceUpdate = -1;
this.running = [];
this.debounceAccept = -1;
this.pendingStart = false;
this.composing = 0;
for (let active of view.state.field(completionState).active)
if (active.state == 1)
this.startQuery(active);
}
update(update) {
let cState = update.state.field(completionState);
if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState)
return;
let doesReset = update.transactions.some((tr) => {
return (tr.selection || tr.docChanged) && !getUserEvent(tr);
});
for (let i2 = 0; i2 < this.running.length; i2++) {
let query = this.running[i2];
if (doesReset || query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
for (let handler of query.context.abortListeners) {
try {
handler();
} catch (e) {
logException(this.view.state, e);
}
}
query.context.abortListeners = null;
this.running.splice(i2--, 1);
} else {
query.updates.push(...update.transactions);
}
}
if (this.debounceUpdate > -1)
clearTimeout(this.debounceUpdate);
if (update.transactions.some((tr) => tr.effects.some((e) => e.is(startCompletionEffect))))
this.pendingStart = true;
let delay = this.pendingStart ? 50 : update.state.facet(completionConfig).activateOnTypingDelay;
this.debounceUpdate = cState.active.some((a) => a.state == 1 && !this.running.some((q) => q.active.source == a.source)) ? setTimeout(() => this.startUpdate(), delay) : -1;
if (this.composing != 0)
for (let tr of update.transactions) {
if (getUserEvent(tr) == "input")
this.composing = 2;
else if (this.composing == 2 && tr.selection)
this.composing = 3;
}
}
startUpdate() {
this.debounceUpdate = -1;
this.pendingStart = false;
let { state } = this.view, cState = state.field(completionState);
for (let active of cState.active) {
if (active.state == 1 && !this.running.some((r) => r.active.source == active.source))
this.startQuery(active);
}
}
startQuery(active) {
let { state } = this.view, pos = cur(state);
let context = new CompletionContext(state, pos, active.explicitPos == pos);
let pending = new RunningQuery(active, context);
this.running.push(pending);
Promise.resolve(active.source(context)).then((result2) => {
if (!pending.context.aborted) {
pending.done = result2 || null;
this.scheduleAccept();
}
}, (err) => {
this.view.dispatch({ effects: closeCompletionEffect.of(null) });
logException(this.view.state, err);
});
}
scheduleAccept() {
if (this.running.every((q) => q.done !== void 0))
this.accept();
else if (this.debounceAccept < 0)
this.debounceAccept = setTimeout(() => this.accept(), this.view.state.facet(completionConfig).updateSyncTime);
}
// For each finished query in this.running, try to create a result
// or, if appropriate, restart the query.
accept() {
var _a2;
if (this.debounceAccept > -1)
clearTimeout(this.debounceAccept);
this.debounceAccept = -1;
let updated = [];
let conf = this.view.state.facet(completionConfig);
for (let i2 = 0; i2 < this.running.length; i2++) {
let query = this.running[i2];
if (query.done === void 0)
continue;
this.running.splice(i2--, 1);
if (query.done) {
let active = new ActiveResult(query.active.source, query.active.explicitPos, query.done, query.done.from, (_a2 = query.done.to) !== null && _a2 !== void 0 ? _a2 : cur(query.updates.length ? query.updates[0].startState : this.view.state));
for (let tr of query.updates)
active = active.update(tr, conf);
if (active.hasResult()) {
updated.push(active);
continue;
}
}
let current = this.view.state.field(completionState).active.find((a) => a.source == query.active.source);
if (current && current.state == 1) {
if (query.done == null) {
let active = new ActiveSource(
query.active.source,
0
/* State.Inactive */
);
for (let tr of query.updates)
active = active.update(tr, conf);
if (active.state != 1)
updated.push(active);
} else {
this.startQuery(current);
}
}
}
if (updated.length)
this.view.dispatch({ effects: setActiveEffect.of(updated) });
}
}, {
eventHandlers: {
blur(event) {
let state = this.view.state.field(completionState, false);
if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur) {
let dialog = state.open && getTooltip(this.view, state.open.tooltip);
if (!dialog || !dialog.dom.contains(event.relatedTarget))
setTimeout(() => this.view.dispatch({ effects: closeCompletionEffect.of(null) }), 10);
}
},
compositionstart() {
this.composing = 1;
},
compositionend() {
if (this.composing == 3) {
setTimeout(() => this.view.dispatch({ effects: startCompletionEffect.of(false) }), 20);
}
this.composing = 0;
}
}
});
const windows = typeof navigator == "object" && /* @__PURE__ */ /Win/.test(navigator.platform);
const commitCharacters = /* @__PURE__ */ Prec.highest(/* @__PURE__ */ EditorView.domEventHandlers({
keydown(event, view) {
let field = view.state.field(completionState, false);
if (!field || !field.open || field.open.disabled || field.open.selected < 0 || event.key.length > 1 || event.ctrlKey && !(windows && event.altKey) || event.metaKey)
return false;
let option = field.open.options[field.open.selected];
let result2 = field.active.find((a) => a.source == option.source);
let commitChars = option.completion.commitCharacters || result2.result.commitCharacters;
if (commitChars && commitChars.indexOf(event.key) > -1)
applyCompletion(view, option);
return false;
}
}));
const baseTheme$1 = /* @__PURE__ */ EditorView.baseTheme({
".cm-tooltip.cm-tooltip-autocomplete": {
"& > ul": {
fontFamily: "monospace",
whiteSpace: "nowrap",
overflow: "hidden auto",
maxWidth_fallback: "700px",
maxWidth: "min(700px, 95vw)",
minWidth: "250px",
maxHeight: "10em",
height: "100%",
listStyle: "none",
margin: 0,
padding: 0,
"& > li, & > completion-section": {
padding: "1px 3px",
lineHeight: 1.2
},
"& > li": {
overflowX: "hidden",
textOverflow: "ellipsis",
cursor: "pointer"
},
"& > completion-section": {
display: "list-item",
borderBottom: "1px solid silver",
paddingLeft: "0.5em",
opacity: 0.7
}
}
},
"&light .cm-tooltip-autocomplete ul li[aria-selected]": {
background: "#17c",
color: "white"
},
"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]": {
background: "#777"
},
"&dark .cm-tooltip-autocomplete ul li[aria-selected]": {
background: "#347",
color: "white"
},
"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]": {
background: "#444"
},
".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after": {
content: '"···"',
opacity: 0.5,
display: "block",
textAlign: "center"
},
".cm-tooltip.cm-completionInfo": {
position: "absolute",
padding: "3px 9px",
width: "max-content",
maxWidth: `${400}px`,
boxSizing: "border-box"
},
".cm-completionInfo.cm-completionInfo-left": { right: "100%" },
".cm-completionInfo.cm-completionInfo-right": { left: "100%" },
".cm-completionInfo.cm-completionInfo-left-narrow": { right: `${30}px` },
".cm-completionInfo.cm-completionInfo-right-narrow": { left: `${30}px` },
"&light .cm-snippetField": { backgroundColor: "#00000022" },
"&dark .cm-snippetField": { backgroundColor: "#ffffff22" },
".cm-snippetFieldPosition": {
verticalAlign: "text-top",
width: 0,
height: "1.15em",
display: "inline-block",
margin: "0 -0.7px -.7em",
borderLeft: "1.4px dotted #888"
},
".cm-completionMatchedText": {
textDecoration: "underline"
},
".cm-completionDetail": {
marginLeft: "0.5em",
fontStyle: "italic"
},
".cm-completionIcon": {
fontSize: "90%",
width: ".8em",
display: "inline-block",
textAlign: "center",
paddingRight: ".6em",
opacity: "0.6",
boxSizing: "content-box"
},
".cm-completionIcon-function, .cm-completionIcon-method": {
"&:after": { content: "'ƒ'" }
},
".cm-completionIcon-class": {
"&:after": { content: "'○'" }
},
".cm-completionIcon-interface": {
"&:after": { content: "'◌'" }
},
".cm-completionIcon-variable": {
"&:after": { content: "'𝑥'" }
},
".cm-completionIcon-constant": {
"&:after": { content: "'𝐶'" }
},
".cm-completionIcon-type": {
"&:after": { content: "'𝑡'" }
},
".cm-completionIcon-enum": {
"&:after": { content: "'∪'" }
},
".cm-completionIcon-property": {
"&:after": { content: "'□'" }
},
".cm-completionIcon-keyword": {
"&:after": { content: "'🔑︎'" }
// Disable emoji rendering
},
".cm-completionIcon-namespace": {
"&:after": { content: "'▢'" }
},
".cm-completionIcon-text": {
"&:after": { content: "'abc'", fontSize: "50%", verticalAlign: "middle" }
}
});
class FieldPos {
constructor(field, line, from, to) {
this.field = field;
this.line = line;
this.from = from;
this.to = to;
}
}
class FieldRange {
constructor(field, from, to) {
this.field = field;
this.from = from;
this.to = to;
}
map(changes) {
let from = changes.mapPos(this.from, -1, MapMode.TrackDel);
let to = changes.mapPos(this.to, 1, MapMode.TrackDel);
return from == null || to == null ? null : new FieldRange(this.field, from, to);
}
}
class Snippet {
constructor(lines, fieldPositions) {
this.lines = lines;
this.fieldPositions = fieldPositions;
}
instantiate(state, pos) {
let text = [], lineStart = [pos];
let lineObj = state.doc.lineAt(pos), baseIndent = /^\s*/.exec(lineObj.text)[0];
for (let line of this.lines) {
if (text.length) {
let indent = baseIndent, tabs2 = /^\t*/.exec(line)[0].length;
for (let i2 = 0; i2 < tabs2; i2++)
indent += state.facet(indentUnit);
lineStart.push(pos + indent.length - tabs2);
line = indent + line.slice(tabs2);
}
text.push(line);
pos += line.length + 1;
}
let ranges = this.fieldPositions.map((pos2) => new FieldRange(pos2.field, lineStart[pos2.line] + pos2.from, lineStart[pos2.line] + pos2.to));
return { text, ranges };
}
static parse(template) {
let fields = [];
let lines = [], positions = [], m;
for (let line of template.split(/\r\n?|\n/)) {
while (m = /[#$]\{(?:(\d+)(?::([^}]*))?|([^}]*))\}/.exec(line)) {
let seq = m[1] ? +m[1] : null, name2 = m[2] || m[3] || "", found = -1;
for (let i2 = 0; i2 < fields.length; i2++) {
if (seq != null ? fields[i2].seq == seq : name2 ? fields[i2].name == name2 : false)
found = i2;
}
if (found < 0) {
let i2 = 0;
while (i2 < fields.length && (seq == null || fields[i2].seq != null && fields[i2].seq < seq))
i2++;
fields.splice(i2, 0, { seq, name: name2 });
found = i2;
for (let pos of positions)
if (pos.field >= found)
pos.field++;
}
positions.push(new FieldPos(found, lines.length, m.index, m.index + name2.length));
line = line.slice(0, m.index) + name2 + line.slice(m.index + m[0].length);
}
for (let esc; esc = /\\([{}])/.exec(line); ) {
line = line.slice(0, esc.index) + esc[1] + line.slice(esc.index + esc[0].length);
for (let pos of positions)
if (pos.line == lines.length && pos.from > esc.index) {
pos.from--;
pos.to--;
}
}
lines.push(line);
}
return new Snippet(lines, positions);
}
}
let fieldMarker = /* @__PURE__ */ Decoration.widget({ widget: /* @__PURE__ */ new class extends WidgetType {
toDOM() {
let span = document.createElement("span");
span.className = "cm-snippetFieldPosition";
return span;
}
ignoreEvent() {
return false;
}
}() });
let fieldRange = /* @__PURE__ */ Decoration.mark({ class: "cm-snippetField" });
class ActiveSnippet {
constructor(ranges, active) {
this.ranges = ranges;
this.active = active;
this.deco = Decoration.set(ranges.map((r) => (r.from == r.to ? fieldMarker : fieldRange).range(r.from, r.to)));
}
map(changes) {
let ranges = [];
for (let r of this.ranges) {
let mapped = r.map(changes);
if (!mapped)
return null;
ranges.push(mapped);
}
return new ActiveSnippet(ranges, this.active);
}
selectionInsideField(sel) {
return sel.ranges.every((range) => this.ranges.some((r) => r.field == this.active && r.from <= range.from && r.to >= range.to));
}
}
const setActive = /* @__PURE__ */ StateEffect.define({
map(value, changes) {
return value && value.map(changes);
}
});
const moveToField = /* @__PURE__ */ StateEffect.define();
const snippetState = /* @__PURE__ */ StateField.define({
create() {
return null;
},
update(value, tr) {
for (let effect of tr.effects) {
if (effect.is(setActive))
return effect.value;
if (effect.is(moveToField) && value)
return new ActiveSnippet(value.ranges, effect.value);
}
if (value && tr.docChanged)
value = value.map(tr.changes);
if (value && tr.selection && !value.selectionInsideField(tr.selection))
value = null;
return value;
},
provide: (f) => EditorView.decorations.from(f, (val) => val ? val.deco : Decoration.none)
});
function fieldSelection(ranges, field) {
return EditorSelection.create(ranges.filter((r) => r.field == field).map((r) => EditorSelection.range(r.from, r.to)));
}
function snippet(template) {
let snippet2 = Snippet.parse(template);
return (editor, completion, from, to) => {
let { text, ranges } = snippet2.instantiate(editor.state, from);
let spec = {
changes: { from, to, insert: Text.of(text) },
scrollIntoView: true,
annotations: completion ? [pickedCompletion.of(completion), Transaction.userEvent.of("input.complete")] : void 0
};
if (ranges.length)
spec.selection = fieldSelection(ranges, 0);
if (ranges.some((r) => r.field > 0)) {
let active = new ActiveSnippet(ranges, 0);
let effects = spec.effects = [setActive.of(active)];
if (editor.state.field(snippetState, false) === void 0)
effects.push(StateEffect.appendConfig.of([snippetState, addSnippetKeymap, snippetPointerHandler, baseTheme$1]));
}
editor.dispatch(editor.state.update(spec));
};
}
function moveField(dir) {
return ({ state, dispatch }) => {
let active = state.field(snippetState, false);
if (!active || dir < 0 && active.active == 0)
return false;
let next = active.active + dir, last = dir > 0 && !active.ranges.some((r) => r.field == next + dir);
dispatch(state.update({
selection: fieldSelection(active.ranges, next),
effects: setActive.of(last ? null : new ActiveSnippet(active.ranges, next)),
scrollIntoView: true
}));
return true;
};
}
const clearSnippet = ({ state, dispatch }) => {
let active = state.field(snippetState, false);
if (!active)
return false;
dispatch(state.update({ effects: setActive.of(null) }));
return true;
};
const nextSnippetField = /* @__PURE__ */ moveField(1);
const prevSnippetField = /* @__PURE__ */ moveField(-1);
const defaultSnippetKeymap = [
{ key: "Tab", run: nextSnippetField, shift: prevSnippetField },
{ key: "Escape", run: clearSnippet }
];
const snippetKeymap = /* @__PURE__ */ Facet.define({
combine(maps) {
return maps.length ? maps[0] : defaultSnippetKeymap;
}
});
const addSnippetKeymap = /* @__PURE__ */ Prec.highest(/* @__PURE__ */ keymap.compute([snippetKeymap], (state) => state.facet(snippetKeymap)));
function snippetCompletion(template, completion) {
return Object.assign(Object.assign({}, completion), { apply: snippet(template) });
}
const snippetPointerHandler = /* @__PURE__ */ EditorView.domEventHandlers({
mousedown(event, view) {
let active = view.state.field(snippetState, false), pos;
if (!active || (pos = view.posAtCoords({ x: event.clientX, y: event.clientY })) == null)
return false;
let match2 = active.ranges.find((r) => r.from <= pos && r.to >= pos);
if (!match2 || match2.field == active.active)
return false;
view.dispatch({
selection: fieldSelection(active.ranges, match2.field),
effects: setActive.of(active.ranges.some((r) => r.field > match2.field) ? new ActiveSnippet(active.ranges, match2.field) : null),
scrollIntoView: true
});
return true;
}
});
const defaults = {
brackets: ["(", "[", "{", "'", '"'],
before: ")]}:;>",
stringPrefixes: []
};
const closeBracketEffect = /* @__PURE__ */ StateEffect.define({
map(value, mapping) {
let mapped = mapping.mapPos(value, -1, MapMode.TrackAfter);
return mapped == null ? void 0 : mapped;
}
});
const closedBracket = /* @__PURE__ */ new class extends RangeValue {
}();
closedBracket.startSide = 1;
closedBracket.endSide = -1;
const bracketState = /* @__PURE__ */ StateField.define({
create() {
return RangeSet.empty;
},
update(value, tr) {
value = value.map(tr.changes);
if (tr.selection) {
let line = tr.state.doc.lineAt(tr.selection.main.head);
value = value.update({ filter: (from) => from >= line.from && from <= line.to });
}
for (let effect of tr.effects)
if (effect.is(closeBracketEffect))
value = value.update({ add: [closedBracket.range(effect.value, effect.value + 1)] });
return value;
}
});
function closeBrackets() {
return [inputHandler, bracketState];
}
const definedClosing = "()[]{}<>";
function closing(ch) {
for (let i2 = 0; i2 < definedClosing.length; i2 += 2)
if (definedClosing.charCodeAt(i2) == ch)
return definedClosing.charAt(i2 + 1);
return fromCodePoint(ch < 128 ? ch : ch + 1);
}
function config(state, pos) {
return state.languageDataAt("closeBrackets", pos)[0] || defaults;
}
const android$1 = typeof navigator == "object" && /* @__PURE__ */ /Android\b/.test(navigator.userAgent);
const inputHandler = /* @__PURE__ */ EditorView.inputHandler.of((view, from, to, insert2) => {
if ((android$1 ? view.composing : view.compositionStarted) || view.state.readOnly)
return false;
let sel = view.state.selection.main;
if (insert2.length > 2 || insert2.length == 2 && codePointSize(codePointAt(insert2, 0)) == 1 || from != sel.from || to != sel.to)
return false;
let tr = insertBracket(view.state, insert2);
if (!tr)
return false;
view.dispatch(tr);
return true;
});
const deleteBracketPair = ({ state, dispatch }) => {
if (state.readOnly)
return false;
let conf = config(state, state.selection.main.head);
let tokens = conf.brackets || defaults.brackets;
let dont = null, changes = state.changeByRange((range) => {
if (range.empty) {
let before = prevChar(state.doc, range.head);
for (let token of tokens) {
if (token == before && nextChar(state.doc, range.head) == closing(codePointAt(token, 0)))
return {
changes: { from: range.head - token.length, to: range.head + token.length },
range: EditorSelection.cursor(range.head - token.length)
};
}
}
return { range: dont = range };
});
if (!dont)
dispatch(state.update(changes, { scrollIntoView: true, userEvent: "delete.backward" }));
return !dont;
};
const closeBracketsKeymap = [
{ key: "Backspace", run: deleteBracketPair }
];
function insertBracket(state, bracket2) {
let conf = config(state, state.selection.main.head);
let tokens = conf.brackets || defaults.brackets;
for (let tok of tokens) {
let closed = closing(codePointAt(tok, 0));
if (bracket2 == tok)
return closed == tok ? handleSame(state, tok, tokens.indexOf(tok + tok + tok) > -1, conf) : handleOpen(state, tok, closed, conf.before || defaults.before);
if (bracket2 == closed && closedBracketAt(state, state.selection.main.from))
return handleClose(state, tok, closed);
}
return null;
}
function closedBracketAt(state, pos) {
let found = false;
state.field(bracketState).between(0, state.doc.length, (from) => {
if (from == pos)
found = true;
});
return found;
}
function nextChar(doc2, pos) {
let next = doc2.sliceString(pos, pos + 2);
return next.slice(0, codePointSize(codePointAt(next, 0)));
}
function prevChar(doc2, pos) {
let prev = doc2.sliceString(pos - 2, pos);
return codePointSize(codePointAt(prev, 0)) == prev.length ? prev : prev.slice(1);
}
function handleOpen(state, open, close, closeBefore) {
let dont = null, changes = state.changeByRange((range) => {
if (!range.empty)
return {
changes: [{ insert: open, from: range.from }, { insert: close, from: range.to }],
effects: closeBracketEffect.of(range.to + open.length),
range: EditorSelection.range(range.anchor + open.length, range.head + open.length)
};
let next = nextChar(state.doc, range.head);
if (!next || /\s/.test(next) || closeBefore.indexOf(next) > -1)
return {
changes: { insert: open + close, from: range.head },
effects: closeBracketEffect.of(range.head + open.length),
range: EditorSelection.cursor(range.head + open.length)
};
return { range: dont = range };
});
return dont ? null : state.update(changes, {
scrollIntoView: true,
userEvent: "input.type"
});
}
function handleClose(state, _open, close) {
let dont = null, changes = state.changeByRange((range) => {
if (range.empty && nextChar(state.doc, range.head) == close)
return {
changes: { from: range.head, to: range.head + close.length, insert: close },
range: EditorSelection.cursor(range.head + close.length)
};
return dont = { range };
});
return dont ? null : state.update(changes, {
scrollIntoView: true,
userEvent: "input.type"
});
}
function handleSame(state, token, allowTriple, config2) {
let stringPrefixes = config2.stringPrefixes || defaults.stringPrefixes;
let dont = null, changes = state.changeByRange((range) => {
if (!range.empty)
return {
changes: [{ insert: token, from: range.from }, { insert: token, from: range.to }],
effects: closeBracketEffect.of(range.to + token.length),
range: EditorSelection.range(range.anchor + token.length, range.head + token.length)
};
let pos = range.head, next = nextChar(state.doc, pos), start;
if (next == token) {
if (nodeStart(state, pos)) {
return {
changes: { insert: token + token, from: pos },
effects: closeBracketEffect.of(pos + token.length),
range: EditorSelection.cursor(pos + token.length)
};
} else if (closedBracketAt(state, pos)) {
let isTriple = allowTriple && state.sliceDoc(pos, pos + token.length * 3) == token + token + token;
let content2 = isTriple ? token + token + token : token;
return {
changes: { from: pos, to: pos + content2.length, insert: content2 },
range: EditorSelection.cursor(pos + content2.length)
};
}
} else if (allowTriple && state.sliceDoc(pos - 2 * token.length, pos) == token + token && (start = canStartStringAt(state, pos - 2 * token.length, stringPrefixes)) > -1 && nodeStart(state, start)) {
return {
changes: { insert: token + token + token + token, from: pos },
effects: closeBracketEffect.of(pos + token.length),
range: EditorSelection.cursor(pos + token.length)
};
} else if (state.charCategorizer(pos)(next) != CharCategory.Word) {
if (canStartStringAt(state, pos, stringPrefixes) > -1 && !probablyInString(state, pos, token, stringPrefixes))
return {
changes: { insert: token + token, from: pos },
effects: closeBracketEffect.of(pos + token.length),
range: EditorSelection.cursor(pos + token.length)
};
}
return { range: dont = range };
});
return dont ? null : state.update(changes, {
scrollIntoView: true,
userEvent: "input.type"
});
}
function nodeStart(state, pos) {
let tree = syntaxTree(state).resolveInner(pos + 1);
return tree.parent && tree.from == pos;
}
function probablyInString(state, pos, quoteToken, prefixes) {
let node = syntaxTree(state).resolveInner(pos, -1);
let maxPrefix = prefixes.reduce((m, p) => Math.max(m, p.length), 0);
for (let i2 = 0; i2 < 5; i2++) {
let start = state.sliceDoc(node.from, Math.min(node.to, node.from + quoteToken.length + maxPrefix));
let quotePos = start.indexOf(quoteToken);
if (!quotePos || quotePos > -1 && prefixes.indexOf(start.slice(0, quotePos)) > -1) {
let first = node.firstChild;
while (first && first.from == node.from && first.to - first.from > quoteToken.length + quotePos) {
if (state.sliceDoc(first.to - quoteToken.length, first.to) == quoteToken)
return false;
first = first.firstChild;
}
return true;
}
let parent = node.to == pos && node.parent;
if (!parent)
break;
node = parent;
}
return false;
}
function canStartStringAt(state, pos, prefixes) {
let charCat = state.charCategorizer(pos);
if (charCat(state.sliceDoc(pos - 1, pos)) != CharCategory.Word)
return pos;
for (let prefix of prefixes) {
let start = pos - prefix.length;
if (state.sliceDoc(start, pos) == prefix && charCat(state.sliceDoc(start - 1, start)) != CharCategory.Word)
return start;
}
return -1;
}
function autocompletion(config2 = {}) {
return [
commitCharacters,
completionState,
completionConfig.of(config2),
completionPlugin,
completionKeymapExt,
baseTheme$1
];
}
const completionKeymap = [
{ key: "Ctrl-Space", run: startCompletion },
{ key: "Escape", run: closeCompletion },
{ key: "ArrowDown", run: /* @__PURE__ */ moveCompletionSelection(true) },
{ key: "ArrowUp", run: /* @__PURE__ */ moveCompletionSelection(false) },
{ key: "PageDown", run: /* @__PURE__ */ moveCompletionSelection(true, "page") },
{ key: "PageUp", run: /* @__PURE__ */ moveCompletionSelection(false, "page") },
{ key: "Enter", run: acceptCompletion }
];
const completionKeymapExt = /* @__PURE__ */ Prec.highest(/* @__PURE__ */ keymap.computeN([completionConfig], (state) => state.facet(completionConfig).defaultKeymap ? [completionKeymap] : []));
class SelectedDiagnostic {
constructor(from, to, diagnostic) {
this.from = from;
this.to = to;
this.diagnostic = diagnostic;
}
}
class LintState {
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, state);
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 + (d.markClass ? " " + d.markClass : "") },
diagnostic: d,
inclusive: true
}).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) {
let line = tr.startState.doc.lineAt(tooltip.pos);
return !!(tr.effects.some((e) => e.is(setDiagnosticsEffect)) || tr.changes.touchesRange(line.from, line.to));
}
function maybeEnableLint(state, effects) {
return state.field(lintState, false) ? effects : effects.concat(StateEffect.appendConfig.of(lintExtensions));
}
const setDiagnosticsEffect = /* @__PURE__ */ StateEffect.define();
const togglePanel = /* @__PURE__ */ StateEffect.define();
const movePanelSelection = /* @__PURE__ */ StateEffect.define();
const lintState = /* @__PURE__ */ 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(togglePanel)) {
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)
]
});
const activeMark = /* @__PURE__ */ Decoration.mark({ class: "cm-lintRange cm-lintRange-active", inclusive: true });
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, view.state);
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)));
}
const openLintPanel = (view) => {
let field = view.state.field(lintState, false);
if (!field || !field.panel)
view.dispatch({ effects: maybeEnableLint(view.state, [togglePanel.of(true)]) });
let panel = getPanel(view, LintPanel.open);
if (panel)
panel.dom.querySelector(".cm-panel-lint ul").focus();
return true;
};
const closeLintPanel = (view) => {
let field = view.state.field(lintState, false);
if (!field || !field.panel)
return false;
view.dispatch({ effects: togglePanel.of(false) });
return true;
};
const 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;
};
const lintKeymap = [
{ key: "Mod-Shift-m", run: openLintPanel, preventDefault: true },
{ key: "F8", run: nextDiagnostic }
];
const lintConfig = /* @__PURE__ */ Facet.define({
combine(input) {
return Object.assign({ sources: input.map((i2) => i2.source).filter((x2) => x2 != null) }, combineConfig(input.map((i2) => i2.config), {
delay: 750,
markerFilter: null,
tooltipFilter: null,
needsRefresh: null
}, {
needsRefresh: (a, b) => !a ? b : !b ? a : (u) => a(u) || b(u)
}));
}
});
function assignKeys(actions) {
let assigned = [];
if (actions)
actions:
for (let { name: name2 } of actions) {
for (let i2 = 0; i2 < name2.length; i2++) {
let ch = name2[i2];
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 _a2;
let keys2 = 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), (_a2 = diagnostic.actions) === null || _a2 === void 0 ? void 0 : _a2.map((action, i2) => {
let fired = false, click = (e) => {
e.preventDefault();
if (fired)
return;
fired = true;
let found = findDiagnostic(view.state.field(lintState).diagnostics, diagnostic);
if (found)
action.apply(view, found.from, found.to);
};
let { name: name2 } = action, keyIndex = keys2[i2] ? name2.indexOf(keys2[i2]) : -1;
let nameElt = keyIndex < 0 ? name2 : [
name2.slice(0, keyIndex),
crelt("u", name2.slice(keyIndex, keyIndex + 1)),
name2.slice(keyIndex + 1)
];
return crelt("button", {
type: "button",
class: "cm-diagnosticAction",
onclick: click,
onmousedown: click,
"aria-label": ` Action: ${name2}${keyIndex < 0 ? "" : ` (access key "${keys2[i2]})"`}.`
}, nameElt);
}), diagnostic.source && crelt("div", { class: "cm-diagnosticSource" }, diagnostic.source));
}
class DiagnosticWidget 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 });
}
}
class PanelItem {
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");
}
}
class LintPanel {
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], keys2 = assignKeys(diagnostic.actions);
for (let i2 = 0; i2 < keys2.length; i2++)
if (keys2[i2].toUpperCase().charCodeAt(0) == event.keyCode) {
let found = findDiagnostic(this.view.state.field(lintState).diagnostics, diagnostic);
if (found)
diagnostic.actions[i2].apply(view, found.from, found.to);
}
} else {
return;
}
event.preventDefault();
};
let onclick = (event) => {
for (let i2 = 0; i2 < this.items.length; i2++) {
if (this.items[i2].dom.contains(event.target))
this.moveSelection(i2);
}
};
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)
}, "×"));
this.update();
}
get selectedIndex() {
let selected = this.view.state.field(lintState).selected;
if (!selected)
return -1;
for (let i2 = 0; i2 < this.items.length; i2++)
if (this.items[i2].diagnostic == selected.diagnostic)
return i2;
return -1;
}
update() {
let { diagnostics, selected } = this.view.state.field(lintState);
let i2 = 0, needsSync = false, newSelectedItem = null;
diagnostics.between(0, this.view.state.doc.length, (_start, _end, { spec }) => {
let found = -1, item;
for (let j2 = i2; 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(i2, 0, item);
needsSync = true;
} else {
item = this.items[found];
if (found > i2) {
this.items.splice(i2, found - i2);
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");
}
i2++;
});
while (i2 < 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 }) => {
let scaleY = panel.height / this.list.offsetHeight;
if (sel.top < panel.top)
this.list.scrollTop -= (panel.top - sel.top) / scaleY;
else if (sel.bottom > panel.bottom)
this.list.scrollTop += (sel.bottom - panel.bottom) / scaleY;
}
});
} else if (this.selectedIndex < 0) {
this.list.removeAttribute("aria-activedescendant");
}
if (needsSync)
this.sync();
}
sync() {
let domPos = this.list.firstChild;
function rm2() {
let prev = domPos;
domPos = prev.nextSibling;
prev.remove();
}
for (let item of this.items) {
if (item.dom.parentNode == this.list) {
while (domPos != item.dom)
rm2();
domPos = item.dom.nextSibling;
} else {
this.list.insertBefore(item.dom, domPos);
}
}
while (domPos)
rm2();
}
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(content2, attrs = `viewBox="0 0 40 40"`) {
return `url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${attrs}>${encodeURIComponent(content2)}</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"`);
}
const baseTheme = /* @__PURE__ */ 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-diagnostic-hint": { borderLeft: "5px solid #66d" },
".cm-diagnosticAction": {
font: "inherit",
border: "none",
padding: "2px 4px",
backgroundColor: "#444",
color: "white",
borderRadius: "3px",
marginLeft: "8px",
cursor: "pointer"
},
".cm-diagnosticSource": {
fontSize: "70%",
opacity: 0.7
},
".cm-lintRange": {
backgroundPosition: "left bottom",
backgroundRepeat: "repeat-x",
paddingBottom: "0.7px"
},
".cm-lintRange-error": { backgroundImage: /* @__PURE__ */ underline("#d11") },
".cm-lintRange-warning": { backgroundImage: /* @__PURE__ */ underline("orange") },
".cm-lintRange-info": { backgroundImage: /* @__PURE__ */ underline("#999") },
".cm-lintRange-hint": { backgroundImage: /* @__PURE__ */ underline("#66d") },
".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-lintPoint-hint": {
"&:after": { borderBottomColor: "#66d" }
},
".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
}
}
});
const lintExtensions = [
lintState,
/* @__PURE__ */ EditorView.decorations.compute([lintState], (state) => {
let { selected, panel } = state.field(lintState);
return !selected || !panel || selected.from == selected.to ? Decoration.none : Decoration.set([
activeMark.range(selected.from, selected.to)
]);
}),
/* @__PURE__ */ hoverTooltip(lintTooltip, { hideOn: hideTooltip }),
baseTheme
];
const basicSetup = /* @__PURE__ */ (() => [
lineNumbers(),
highlightActiveLineGutter(),
highlightSpecialChars(),
history$1(),
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
])
])();
/*!
* VueCodemirror v6.1.1
* Copyright (c) Surmon. All rights reserved.
* Released under the MIT License.
* Surmon
*/
var h = Object.freeze({ autofocus: false, disabled: false, indentWithTab: true, tabSize: 2, placeholder: "", autoDestroy: true, extensions: [basicSetup] }), y = Symbol("vue-codemirror-global-config");
var O, j = function(e) {
var t2 = e.onUpdate, n = e.onChange, o = e.onFocus, r = e.onBlur, u = function(e2, t3) {
var n2 = {};
for (var o2 in e2)
Object.prototype.hasOwnProperty.call(e2, o2) && t3.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++)
t3.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: u.doc, selection: u.selection, extensions: (Array.isArray(u.extensions) ? u.extensions : [u.extensions]).concat([EditorView.updateListener.of(function(e2) {
t2(e2), e2.docChanged && n(e2.state.doc.toString(), e2), e2.focusChanged && (e2.view.hasFocus ? o(e2) : r(e2));
})]) });
}, S = function(e) {
var t2 = new Compartment();
return { compartment: t2, run: function(n) {
t2.get(e.state) ? e.dispatch({ effects: t2.reconfigure(n) }) : e.dispatch({ effects: StateEffect.appendConfig.of(t2.of(n)) });
} };
}, x = function(e, t2) {
var n = S(e), o = n.compartment, r = n.run;
return function(n2) {
var u = o.get(e.state);
r((null != n2 ? n2 : u !== t2) ? t2 : []);
};
}, C = { type: Boolean, default: void 0 }, D = { autofocus: C, disabled: C, indentWithTab: C, tabSize: Number, placeholder: String, style: Object, autoDestroy: C, phrases: Object, root: Object, extensions: Array, selection: Object }, U = { modelValue: { type: String, default: "" } }, 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, t2) {
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), P = vue.defineComponent({ name: "VueCodemirror", props: Object.assign({}, w), emits: Object.assign({}, F), setup: function(t2, s) {
var f = vue.shallowRef(), d = vue.shallowRef(), C2 = vue.shallowRef(), D2 = Object.assign(Object.assign({}, h), vue.inject(y, {})), U2 = vue.computed(function() {
var e = {};
return Object.keys(vue.toRaw(t2)).forEach(function(n) {
var o;
"modelValue" !== n && (e[n] = null !== (o = t2[n]) && void 0 !== o ? o : D2[n]);
}), e;
});
return vue.onMounted(function() {
var e;
d.value = j({ doc: t2.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 !== t2.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 t3 = 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])), u = S(e2).run, a = S(e2).run, i2 = S(e2).run, c = S(e2).run;
return { focus: function() {
return e2.focus();
}, getDoc: t3, setDoc: function(n3) {
n3 !== t3() && e2.dispatch({ changes: { from: 0, to: e2.state.doc.length, insert: n3 } });
}, reExtensions: n2, toggleDisabled: o, toggleIndentWithTab: r, setTabSize: function(e3) {
u([EditorState.tabSize.of(e3), indentUnit.of(" ".repeat(e3))]);
}, setPhrases: function(e3) {
a([EditorState.phrases.of(e3)]);
}, setPlaceholder: function(e3) {
i2(placeholder(e3));
}, setStyle: function(e3) {
void 0 === e3 && (e3 = {}), c(EditorView.theme({ "&": Object.assign({}, e3) }));
} };
}(C2.value);
vue.watch(function() {
return t2.modelValue;
}, function(e2) {
e2 !== n.getDoc() && n.setDoc(e2);
}), vue.watch(function() {
return t2.extensions;
}, function(e2) {
return n.reExtensions(e2 || []);
}, { immediate: true }), vue.watch(function() {
return U2.value.disabled;
}, function(e2) {
return n.toggleDisabled(e2);
}, { immediate: true }), vue.watch(function() {
return U2.value.indentWithTab;
}, function(e2) {
return n.toggleIndentWithTab(e2);
}, { immediate: true }), vue.watch(function() {
return U2.value.tabSize;
}, function(e2) {
return n.setTabSize(e2);
}, { immediate: true }), vue.watch(function() {
return U2.value.phrases;
}, function(e2) {
return n.setPhrases(e2 || {});
}, { immediate: true }), vue.watch(function() {
return U2.value.placeholder;
}, function(e2) {
return n.setPlaceholder(e2);
}, { immediate: true }), vue.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 });
}), vue.onBeforeUnmount(function() {
U2.value.autoDestroy && C2.value && function(e) {
e.destroy();
}(C2.value);
}), function() {
return vue.h("div", { class: "v-codemirror", style: { display: "contents" }, ref: f });
};
} }), T = P;
class Stack {
/**
@internal
*/
constructor(p, stack, state, reducePos, pos, score2, buffer, bufferBase, curContext, lookAhead = 0, parent) {
this.p = p;
this.stack = stack;
this.state = state;
this.reducePos = reducePos;
this.pos = pos;
this.score = score2;
this.buffer = buffer;
this.bufferBase = bufferBase;
this.curContext = curContext;
this.lookAhead = lookAhead;
this.parent = parent;
}
/**
@internal
*/
toString() {
return `[${this.stack.filter((_, i2) => i2 % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
}
// Start an empty stack
/**
@internal
*/
static start(p, state, pos = 0) {
let cx = p.parser.context;
return new Stack(p, [], state, pos, pos, 0, [], 0, cx ? new StackContext(cx, cx.start) : null, 0, null);
}
/**
The stack's current [context](#lr.ContextTracker) value, if
any. Its type will depend on the context tracker's type
parameter, or it will be `null` if there is no context
tracker.
*/
get context() {
return this.curContext ? this.curContext.context : null;
}
// Push a state onto the stack, tracking its start position as well
// as the buffer base at that point.
/**
@internal
*/
pushState(state, start) {
this.stack.push(this.state, start, this.bufferBase + this.buffer.length);
this.state = state;
}
// Apply a reduce action
/**
@internal
*/
reduce(action) {
var _a2;
let depth = action >> 19, type = action & 65535;
let { parser: parser2 } = this.p;
let dPrec = parser2.dynamicPrecedence(type);
if (dPrec)
this.score += dPrec;
if (depth == 0) {
this.pushState(parser2.getGoto(this.state, type, true), this.reducePos);
if (type < parser2.minRepeatTerm)
this.storeNode(type, this.reducePos, this.reducePos, 4, true);
this.reduceContext(type, this.reducePos);
return;
}
let base2 = this.stack.length - (depth - 1) * 3 - (action & 262144 ? 6 : 0);
let start = base2 ? this.stack[base2 - 2] : this.p.ranges[0].from, size = this.reducePos - start;
if (size >= 2e3 && !((_a2 = this.p.parser.nodeSet.types[type]) === null || _a2 === void 0 ? void 0 : _a2.isAnonymous)) {
if (start == this.p.lastBigReductionStart) {
this.p.bigReductionCount++;
this.p.lastBigReductionSize = size;
} else if (this.p.lastBigReductionSize < size) {
this.p.bigReductionCount = 1;
this.p.lastBigReductionStart = start;
this.p.lastBigReductionSize = size;
}
}
let bufferBase = base2 ? this.stack[base2 - 1] : 0, count = this.bufferBase + this.buffer.length - bufferBase;
if (type < parser2.minRepeatTerm || action & 131072) {
let pos = parser2.stateFlag(
this.state,
1
/* StateFlag.Skipped */
) ? this.pos : this.reducePos;
this.storeNode(type, start, pos, count + 4, true);
}
if (action & 262144) {
this.state = this.stack[base2];
} else {
let baseStateID = this.stack[base2 - 3];
this.state = parser2.getGoto(baseStateID, type, true);
}
while (this.stack.length > base2)
this.stack.pop();
this.reduceContext(type, start);
}
// Shift a value into the buffer
/**
@internal
*/
storeNode(term, start, end, size = 4, isReduce = false) {
if (term == 0 && (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) {
let cur2 = this, top2 = this.buffer.length;
if (top2 == 0 && cur2.parent) {
top2 = cur2.bufferBase - cur2.parent.bufferBase;
cur2 = cur2.parent;
}
if (top2 > 0 && cur2.buffer[top2 - 4] == 0 && cur2.buffer[top2 - 1] > -1) {
if (start == end)
return;
if (cur2.buffer[top2 - 2] >= start) {
cur2.buffer[top2 - 2] = end;
return;
}
}
}
if (!isReduce || this.pos == end) {
this.buffer.push(term, start, end, size);
} else {
let index = this.buffer.length;
if (index > 0 && this.buffer[index - 4] != 0)
while (index > 0 && this.buffer[index - 2] > end) {
this.buffer[index] = this.buffer[index - 4];
this.buffer[index + 1] = this.buffer[index - 3];
this.buffer[index + 2] = this.buffer[index - 2];
this.buffer[index + 3] = this.buffer[index - 1];
index -= 4;
if (size > 4)
size -= 4;
}
this.buffer[index] = term;
this.buffer[index + 1] = start;
this.buffer[index + 2] = end;
this.buffer[index + 3] = size;
}
}
// Apply a shift action
/**
@internal
*/
shift(action, type, start, end) {
if (action & 131072) {
this.pushState(action & 65535, this.pos);
} else if ((action & 262144) == 0) {
let nextState = action, { parser: parser2 } = this.p;
if (end > this.pos || type <= parser2.maxNode) {
this.pos = end;
if (!parser2.stateFlag(
nextState,
1
/* StateFlag.Skipped */
))
this.reducePos = end;
}
this.pushState(nextState, start);
this.shiftContext(type, start);
if (type <= parser2.maxNode)
this.buffer.push(type, start, end, 4);
} else {
this.pos = end;
this.shiftContext(type, start);
if (type <= this.p.parser.maxNode)
this.buffer.push(type, start, end, 4);
}
}
// Apply an action
/**
@internal
*/
apply(action, next, nextStart, nextEnd) {
if (action & 65536)
this.reduce(action);
else
this.shift(action, next, nextStart, nextEnd);
}
// Add a prebuilt (reused) node into the buffer.
/**
@internal
*/
useNode(value, next) {
let index = this.p.reused.length - 1;
if (index < 0 || this.p.reused[index] != value) {
this.p.reused.push(value);
index++;
}
let start = this.pos;
this.reducePos = this.pos = start + value.length;
this.pushState(next, start);
this.buffer.push(
index,
start,
this.reducePos,
-1
/* size == -1 means this is a reused value */
);
if (this.curContext)
this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this, this.p.stream.reset(this.pos - value.length)));
}
// Split the stack. Due to the buffer sharing and the fact
// that `this.stack` tends to stay quite shallow, this isn't very
// expensive.
/**
@internal
*/
split() {
let parent = this;
let off = parent.buffer.length;
while (off > 0 && parent.buffer[off - 2] > parent.reducePos)
off -= 4;
let buffer = parent.buffer.slice(off), base2 = parent.bufferBase + off;
while (parent && base2 == parent.bufferBase)
parent = parent.parent;
return new Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base2, this.curContext, this.lookAhead, parent);
}
// Try to recover from an error by 'deleting' (ignoring) one token.
/**
@internal
*/
recoverByDelete(next, nextEnd) {
let isNode = next <= this.p.parser.maxNode;
if (isNode)
this.storeNode(next, this.pos, nextEnd, 4);
this.storeNode(0, this.pos, nextEnd, isNode ? 8 : 4);
this.pos = this.reducePos = nextEnd;
this.score -= 190;
}
/**
Check if the given term would be able to be shifted (optionally
after some reductions) on this stack. This can be useful for
external tokenizers that want to make sure they only provide a
given token when it applies.
*/
canShift(term) {
for (let sim = new SimulatedStack(this); ; ) {
let action = this.p.parser.stateSlot(
sim.state,
4
/* ParseState.DefaultReduce */
) || this.p.parser.hasAction(sim.state, term);
if (action == 0)
return false;
if ((action & 65536) == 0)
return true;
sim.reduce(action);
}
}
// Apply up to Recover.MaxNext recovery actions that conceptually
// inserts some missing token or rule.
/**
@internal
*/
recoverByInsert(next) {
if (this.stack.length >= 300)
return [];
let nextStates = this.p.parser.nextStates(this.state);
if (nextStates.length > 4 << 1 || this.stack.length >= 120) {
let best = [];
for (let i2 = 0, s; i2 < nextStates.length; i2 += 2) {
if ((s = nextStates[i2 + 1]) != this.state && this.p.parser.hasAction(s, next))
best.push(nextStates[i2], s);
}
if (this.stack.length < 120)
for (let i2 = 0; best.length < 4 << 1 && i2 < nextStates.length; i2 += 2) {
let s = nextStates[i2 + 1];
if (!best.some((v, i3) => i3 & 1 && v == s))
best.push(nextStates[i2], s);
}
nextStates = best;
}
let result2 = [];
for (let i2 = 0; i2 < nextStates.length && result2.length < 4; i2 += 2) {
let s = nextStates[i2 + 1];
if (s == this.state)
continue;
let stack = this.split();
stack.pushState(s, this.pos);
stack.storeNode(0, stack.pos, stack.pos, 4, true);
stack.shiftContext(nextStates[i2], this.pos);
stack.reducePos = this.pos;
stack.score -= 200;
result2.push(stack);
}
return result2;
}
// Force a reduce, if possible. Return false if that can't
// be done.
/**
@internal
*/
forceReduce() {
let { parser: parser2 } = this.p;
let reduce = parser2.stateSlot(
this.state,
5
/* ParseState.ForcedReduce */
);
if ((reduce & 65536) == 0)
return false;
if (!parser2.validAction(this.state, reduce)) {
let depth = reduce >> 19, term = reduce & 65535;
let target = this.stack.length - depth * 3;
if (target < 0 || parser2.getGoto(this.stack[target], term, false) < 0) {
let backup = this.findForcedReduction();
if (backup == null)
return false;
reduce = backup;
}
this.storeNode(0, this.pos, this.pos, 4, true);
this.score -= 100;
}
this.reducePos = this.pos;
this.reduce(reduce);
return true;
}
/**
Try to scan through the automaton to find some kind of reduction
that can be applied. Used when the regular ForcedReduce field
isn't a valid action. @internal
*/
findForcedReduction() {
let { parser: parser2 } = this.p, seen = [];
let explore = (state, depth) => {
if (seen.includes(state))
return;
seen.push(state);
return parser2.allActions(state, (action) => {
if (action & (262144 | 131072))
;
else if (action & 65536) {
let rDepth = (action >> 19) - depth;
if (rDepth > 1) {
let term = action & 65535, target = this.stack.length - rDepth * 3;
if (target >= 0 && parser2.getGoto(this.stack[target], term, false) >= 0)
return rDepth << 19 | 65536 | term;
}
} else {
let found = explore(action, depth + 1);
if (found != null)
return found;
}
});
};
return explore(this.state, 0);
}
/**
@internal
*/
forceAll() {
while (!this.p.parser.stateFlag(
this.state,
2
/* StateFlag.Accepting */
)) {
if (!this.forceReduce()) {
this.storeNode(0, this.pos, this.pos, 4, true);
break;
}
}
return this;
}
/**
Check whether this state has no further actions (assumed to be a direct descendant of the
top state, since any other states must be able to continue
somehow). @internal
*/
get deadEnd() {
if (this.stack.length != 3)
return false;
let { parser: parser2 } = this.p;
return parser2.data[parser2.stateSlot(
this.state,
1
/* ParseState.Actions */
)] == 65535 && !parser2.stateSlot(
this.state,
4
/* ParseState.DefaultReduce */
);
}
/**
Restart the stack (put it back in its start state). Only safe
when this.stack.length == 3 (state is directly below the top
state). @internal
*/
restart() {
this.storeNode(0, this.pos, this.pos, 4, true);
this.state = this.stack[0];
this.stack.length = 0;
}
/**
@internal
*/
sameState(other) {
if (this.state != other.state || this.stack.length != other.stack.length)
return false;
for (let i2 = 0; i2 < this.stack.length; i2 += 3)
if (this.stack[i2] != other.stack[i2])
return false;
return true;
}
/**
Get the parser used by this stack.
*/
get parser() {
return this.p.parser;
}
/**
Test whether a given dialect (by numeric ID, as exported from
the terms file) is enabled.
*/
dialectEnabled(dialectID) {
return this.p.parser.dialect.flags[dialectID];
}
shiftContext(term, start) {
if (this.curContext)
this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this, this.p.stream.reset(start)));
}
reduceContext(term, start) {
if (this.curContext)
this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this, this.p.stream.reset(start)));
}
/**
@internal
*/
emitContext() {
let last = this.buffer.length - 1;
if (last < 0 || this.buffer[last] != -3)
this.buffer.push(this.curContext.hash, this.pos, this.pos, -3);
}
/**
@internal
*/
emitLookAhead() {
let last = this.buffer.length - 1;
if (last < 0 || this.buffer[last] != -4)
this.buffer.push(this.lookAhead, this.pos, this.pos, -4);
}
updateContext(context) {
if (context != this.curContext.context) {
let newCx = new StackContext(this.curContext.tracker, context);
if (newCx.hash != this.curContext.hash)
this.emitContext();
this.curContext = newCx;
}
}
/**
@internal
*/
setLookAhead(lookAhead) {
if (lookAhead > this.lookAhead) {
this.emitLookAhead();
this.lookAhead = lookAhead;
}
}
/**
@internal
*/
close() {
if (this.curContext && this.curContext.tracker.strict)
this.emitContext();
if (this.lookAhead > 0)
this.emitLookAhead();
}
}
class StackContext {
constructor(tracker, context) {
this.tracker = tracker;
this.context = context;
this.hash = tracker.strict ? tracker.hash(context) : 0;
}
}
class SimulatedStack {
constructor(start) {
this.start = start;
this.state = start.state;
this.stack = start.stack;
this.base = this.stack.length;
}
reduce(action) {
let term = action & 65535, depth = action >> 19;
if (depth == 0) {
if (this.stack == this.start.stack)
this.stack = this.stack.slice();
this.stack.push(this.state, 0, 0);
this.base += 3;
} else {
this.base -= (depth - 1) * 3;
}
let goto = this.start.p.parser.getGoto(this.stack[this.base - 3], term, true);
this.state = goto;
}
}
class StackBufferCursor {
constructor(stack, pos, index) {
this.stack = stack;
this.pos = pos;
this.index = index;
this.buffer = stack.buffer;
if (this.index == 0)
this.maybeNext();
}
static create(stack, pos = stack.bufferBase + stack.buffer.length) {
return new StackBufferCursor(stack, pos, pos - stack.bufferBase);
}
maybeNext() {
let next = this.stack.parent;
if (next != null) {
this.index = this.stack.bufferBase - next.bufferBase;
this.stack = next;
this.buffer = next.buffer;
}
}
get id() {
return this.buffer[this.index - 4];
}
get start() {
return this.buffer[this.index - 3];
}
get end() {
return this.buffer[this.index - 2];
}
get size() {
return this.buffer[this.index - 1];
}
next() {
this.index -= 4;
this.pos -= 4;
if (this.index == 0)
this.maybeNext();
}
fork() {
return new StackBufferCursor(this.stack, this.pos, this.index);
}
}
function decodeArray(input, Type = Uint16Array) {
if (typeof input != "string")
return input;
let array = null;
for (let pos = 0, out = 0; pos < input.length; ) {
let value = 0;
for (; ; ) {
let next = input.charCodeAt(pos++), stop = false;
if (next == 126) {
value = 65535;
break;
}
if (next >= 92)
next--;
if (next >= 34)
next--;
let digit = next - 32;
if (digit >= 46) {
digit -= 46;
stop = true;
}
value += digit;
if (stop)
break;
value *= 46;
}
if (array)
array[out++] = value;
else
array = new Type(value);
}
return array;
}
class CachedToken {
constructor() {
this.start = -1;
this.value = -1;
this.end = -1;
this.extended = -1;
this.lookAhead = 0;
this.mask = 0;
this.context = 0;
}
}
const nullToken = new CachedToken();
class InputStream {
/**
@internal
*/
constructor(input, ranges) {
this.input = input;
this.ranges = ranges;
this.chunk = "";
this.chunkOff = 0;
this.chunk2 = "";
this.chunk2Pos = 0;
this.next = -1;
this.token = nullToken;
this.rangeIndex = 0;
this.pos = this.chunkPos = ranges[0].from;
this.range = ranges[0];
this.end = ranges[ranges.length - 1].to;
this.readNext();
}
/**
@internal
*/
resolveOffset(offset, assoc) {
let range = this.range, index = this.rangeIndex;
let pos = this.pos + offset;
while (pos < range.from) {
if (!index)
return null;
let next = this.ranges[--index];
pos -= range.from - next.to;
range = next;
}
while (assoc < 0 ? pos > range.to : pos >= range.to) {
if (index == this.ranges.length - 1)
return null;
let next = this.ranges[++index];
pos += next.from - range.to;
range = next;
}
return pos;
}
/**
@internal
*/
clipPos(pos) {
if (pos >= this.range.from && pos < this.range.to)
return pos;
for (let range of this.ranges)
if (range.to > pos)
return Math.max(pos, range.from);
return this.end;
}
/**
Look at a code unit near the stream position. `.peek(0)` equals
`.next`, `.peek(-1)` gives you the previous character, and so
on.
Note that looking around during tokenizing creates dependencies
on potentially far-away content, which may reduce the
effectiveness incremental parsing—when looking forward—or even
cause invalid reparses when looking backward more than 25 code
units, since the library does not track lookbehind.
*/
peek(offset) {
let idx = this.chunkOff + offset, pos, result2;
if (idx >= 0 && idx < this.chunk.length) {
pos = this.pos + offset;
result2 = this.chunk.charCodeAt(idx);
} else {
let resolved = this.resolveOffset(offset, 1);
if (resolved == null)
return -1;
pos = resolved;
if (pos >= this.chunk2Pos && pos < this.chunk2Pos + this.chunk2.length) {
result2 = this.chunk2.charCodeAt(pos - this.chunk2Pos);
} else {
let i2 = this.rangeIndex, range = this.range;
while (range.to <= pos)
range = this.ranges[++i2];
this.chunk2 = this.input.chunk(this.chunk2Pos = pos);
if (pos + this.chunk2.length > range.to)
this.chunk2 = this.chunk2.slice(0, range.to - pos);
result2 = this.chunk2.charCodeAt(0);
}
}
if (pos >= this.token.lookAhead)
this.token.lookAhead = pos + 1;
return result2;
}
/**
Accept a token. By default, the end of the token is set to the
current stream position, but you can pass an offset (relative to
the stream position) to change that.
*/
acceptToken(token, endOffset = 0) {
let end = endOffset ? this.resolveOffset(endOffset, -1) : this.pos;
if (end == null || end < this.token.start)
throw new RangeError("Token end out of bounds");
this.token.value = token;
this.token.end = end;
}
/**
Accept a token ending at a specific given position.
*/
acceptTokenTo(token, endPos) {
this.token.value = token;
this.token.end = endPos;
}
getChunk() {
if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) {
let { chunk, chunkPos } = this;
this.chunk = this.chunk2;
this.chunkPos = this.chunk2Pos;
this.chunk2 = chunk;
this.chunk2Pos = chunkPos;
this.chunkOff = this.pos - this.chunkPos;
} else {
this.chunk2 = this.chunk;
this.chunk2Pos = this.chunkPos;
let nextChunk = this.input.chunk(this.pos);
let end = this.pos + nextChunk.length;
this.chunk = end > this.range.to ? nextChunk.slice(0, this.range.to - this.pos) : nextChunk;
this.chunkPos = this.pos;
this.chunkOff = 0;
}
}
readNext() {
if (this.chunkOff >= this.chunk.length) {
this.getChunk();
if (this.chunkOff == this.chunk.length)
return this.next = -1;
}
return this.next = this.chunk.charCodeAt(this.chunkOff);
}
/**
Move the stream forward N (defaults to 1) code units. Returns
the new value of [`next`](#lr.InputStream.next).
*/
advance(n = 1) {
this.chunkOff += n;
while (this.pos + n >= this.range.to) {
if (this.rangeIndex == this.ranges.length - 1)
return this.setDone();
n -= this.range.to - this.pos;
this.range = this.ranges[++this.rangeIndex];
this.pos = this.range.from;
}
this.pos += n;
if (this.pos >= this.token.lookAhead)
this.token.lookAhead = this.pos + 1;
return this.readNext();
}
setDone() {
this.pos = this.chunkPos = this.end;
this.range = this.ranges[this.rangeIndex = this.ranges.length - 1];
this.chunk = "";
return this.next = -1;
}
/**
@internal
*/
reset(pos, token) {
if (token) {
this.token = token;
token.start = pos;
token.lookAhead = pos + 1;
token.value = token.extended = -1;
} else {
this.token = nullToken;
}
if (this.pos != pos) {
this.pos = pos;
if (pos == this.end) {
this.setDone();
return this;
}
while (pos < this.range.from)
this.range = this.ranges[--this.rangeIndex];
while (pos >= this.range.to)
this.range = this.ranges[++this.rangeIndex];
if (pos >= this.chunkPos && pos < this.chunkPos + this.chunk.length) {
this.chunkOff = pos - this.chunkPos;
} else {
this.chunk = "";
this.chunkOff = 0;
}
this.readNext();
}
return this;
}
/**
@internal
*/
read(from, to) {
if (from >= this.chunkPos && to <= this.chunkPos + this.chunk.length)
return this.chunk.slice(from - this.chunkPos, to - this.chunkPos);
if (from >= this.chunk2Pos && to <= this.chunk2Pos + this.chunk2.length)
return this.chunk2.slice(from - this.chunk2Pos, to - this.chunk2Pos);
if (from >= this.range.from && to <= this.range.to)
return this.input.read(from, to);
let result2 = "";
for (let r of this.ranges) {
if (r.from >= to)
break;
if (r.to > from)
result2 += this.input.read(Math.max(r.from, from), Math.min(r.to, to));
}
return result2;
}
}
class TokenGroup {
constructor(data, id2) {
this.data = data;
this.id = id2;
}
token(input, stack) {
let { parser: parser2 } = stack.p;
readToken(this.data, input, stack, this.id, parser2.data, parser2.tokenPrecTable);
}
}
TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
class LocalTokenGroup {
constructor(data, precTable, elseToken) {
this.precTable = precTable;
this.elseToken = elseToken;
this.data = typeof data == "string" ? decodeArray(data) : data;
}
token(input, stack) {
let start = input.pos, skipped = 0;
for (; ; ) {
let atEof = input.next < 0, nextPos = input.resolveOffset(1, 1);
readToken(this.data, input, stack, 0, this.data, this.precTable);
if (input.token.value > -1)
break;
if (this.elseToken == null)
return;
if (!atEof)
skipped++;
if (nextPos == null)
break;
input.reset(nextPos, input.token);
}
if (skipped) {
input.reset(start, input.token);
input.acceptToken(this.elseToken, skipped);
}
}
}
LocalTokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
class ExternalTokenizer {
/**
Create a tokenizer. The first argument is the function that,
given an input stream, scans for the types of tokens it
recognizes at the stream's position, and calls
[`acceptToken`](#lr.InputStream.acceptToken) when it finds
one.
*/
constructor(token, options = {}) {
this.token = token;
this.contextual = !!options.contextual;
this.fallback = !!options.fallback;
this.extend = !!options.extend;
}
}
function readToken(data, input, stack, group, precTable, precOffset) {
let state = 0, groupMask = 1 << group, { dialect } = stack.p.parser;
scan:
for (; ; ) {
if ((groupMask & data[state]) == 0)
break;
let accEnd = data[state + 1];
for (let i2 = state + 3; i2 < accEnd; i2 += 2)
if ((data[i2 + 1] & groupMask) > 0) {
let term = data[i2];
if (dialect.allows(term) && (input.token.value == -1 || input.token.value == term || overrides(term, input.token.value, precTable, precOffset))) {
input.acceptToken(term);
break;
}
}
let next = input.next, low = 0, high = data[state + 2];
if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535) {
state = data[accEnd + high * 3 - 1];
continue scan;
}
for (; low < high; ) {
let mid = low + high >> 1;
let index = accEnd + mid + (mid << 1);
let from = data[index], to = data[index + 1] || 65536;
if (next < from)
high = mid;
else if (next >= to)
low = mid + 1;
else {
state = data[index + 2];
input.advance();
continue scan;
}
}
break;
}
}
function findOffset(data, start, term) {
for (let i2 = start, next; (next = data[i2]) != 65535; i2++)
if (next == term)
return i2 - start;
return -1;
}
function overrides(token, prev, tableData, tableOffset) {
let iPrev = findOffset(tableData, tableOffset, prev);
return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev;
}
const verbose = typeof process != "undefined" && process.env && /\bparse\b/.test({}.LOG);
let stackIDs = null;
function cutAt(tree, pos, side) {
let cursor = tree.cursor(IterMode.IncludeAnonymous);
cursor.moveTo(pos);
for (; ; ) {
if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos)))
for (; ; ) {
if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError)
return side < 0 ? Math.max(0, Math.min(
cursor.to - 1,
pos - 25
/* Safety.Margin */
)) : Math.min(tree.length, Math.max(
cursor.from + 1,
pos + 25
/* Safety.Margin */
));
if (side < 0 ? cursor.prevSibling() : cursor.nextSibling())
break;
if (!cursor.parent())
return side < 0 ? 0 : tree.length;
}
}
}
class FragmentCursor {
constructor(fragments, nodeSet) {
this.fragments = fragments;
this.nodeSet = nodeSet;
this.i = 0;
this.fragment = null;
this.safeFrom = -1;
this.safeTo = -1;
this.trees = [];
this.start = [];
this.index = [];
this.nextFragment();
}
nextFragment() {
let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
if (fr) {
this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from;
this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to;
while (this.trees.length) {
this.trees.pop();
this.start.pop();
this.index.pop();
}
this.trees.push(fr.tree);
this.start.push(-fr.offset);
this.index.push(0);
this.nextStart = this.safeFrom;
} else {
this.nextStart = 1e9;
}
}
// `pos` must be >= any previously given `pos` for this cursor
nodeAt(pos) {
if (pos < this.nextStart)
return null;
while (this.fragment && this.safeTo <= pos)
this.nextFragment();
if (!this.fragment)
return null;
for (; ; ) {
let last = this.trees.length - 1;
if (last < 0) {
this.nextFragment();
return null;
}
let top2 = this.trees[last], index = this.index[last];
if (index == top2.children.length) {
this.trees.pop();
this.start.pop();
this.index.pop();
continue;
}
let next = top2.children[index];
let start = this.start[last] + top2.positions[index];
if (start > pos) {
this.nextStart = start;
return null;
}
if (next instanceof Tree) {
if (start == pos) {
if (start < this.safeFrom)
return null;
let end = start + next.length;
if (end <= this.safeTo) {
let lookAhead = next.prop(NodeProp.lookAhead);
if (!lookAhead || end + lookAhead < this.fragment.to)
return next;
}
}
this.index[last]++;
if (start + next.length >= Math.max(this.safeFrom, pos)) {
this.trees.push(next);
this.start.push(start);
this.index.push(0);
}
} else {
this.index[last]++;
this.nextStart = start + next.length;
}
}
}
}
class TokenCache {
constructor(parser2, stream) {
this.stream = stream;
this.tokens = [];
this.mainToken = null;
this.actions = [];
this.tokens = parser2.tokenizers.map((_) => new CachedToken());
}
getActions(stack) {
let actionIndex = 0;
let main = null;
let { parser: parser2 } = stack.p, { tokenizers } = parser2;
let mask = parser2.stateSlot(
stack.state,
3
/* ParseState.TokenizerMask */
);
let context = stack.curContext ? stack.curContext.hash : 0;
let lookAhead = 0;
for (let i2 = 0; i2 < tokenizers.length; i2++) {
if ((1 << i2 & mask) == 0)
continue;
let tokenizer = tokenizers[i2], token = this.tokens[i2];
if (main && !tokenizer.fallback)
continue;
if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) {
this.updateCachedToken(token, tokenizer, stack);
token.mask = mask;
token.context = context;
}
if (token.lookAhead > token.end + 25)
lookAhead = Math.max(token.lookAhead, lookAhead);
if (token.value != 0) {
let startIndex = actionIndex;
if (token.extended > -1)
actionIndex = this.addActions(stack, token.extended, token.end, actionIndex);
actionIndex = this.addActions(stack, token.value, token.end, actionIndex);
if (!tokenizer.extend) {
main = token;
if (actionIndex > startIndex)
break;
}
}
}
while (this.actions.length > actionIndex)
this.actions.pop();
if (lookAhead)
stack.setLookAhead(lookAhead);
if (!main && stack.pos == this.stream.end) {
main = new CachedToken();
main.value = stack.p.parser.eofTerm;
main.start = main.end = stack.pos;
actionIndex = this.addActions(stack, main.value, main.end, actionIndex);
}
this.mainToken = main;
return this.actions;
}
getMainToken(stack) {
if (this.mainToken)
return this.mainToken;
let main = new CachedToken(), { pos, p } = stack;
main.start = pos;
main.end = Math.min(pos + 1, p.stream.end);
main.value = pos == p.stream.end ? p.parser.eofTerm : 0;
return main;
}
updateCachedToken(token, tokenizer, stack) {
let start = this.stream.clipPos(stack.pos);
tokenizer.token(this.stream.reset(start, token), stack);
if (token.value > -1) {
let { parser: parser2 } = stack.p;
for (let i2 = 0; i2 < parser2.specialized.length; i2++)
if (parser2.specialized[i2] == token.value) {
let result2 = parser2.specializers[i2](this.stream.read(token.start, token.end), stack);
if (result2 >= 0 && stack.p.parser.dialect.allows(result2 >> 1)) {
if ((result2 & 1) == 0)
token.value = result2 >> 1;
else
token.extended = result2 >> 1;
break;
}
}
} else {
token.value = 0;
token.end = this.stream.clipPos(start + 1);
}
}
putAction(action, token, end, index) {
for (let i2 = 0; i2 < index; i2 += 3)
if (this.actions[i2] == action)
return index;
this.actions[index++] = action;
this.actions[index++] = token;
this.actions[index++] = end;
return index;
}
addActions(stack, token, end, index) {
let { state } = stack, { parser: parser2 } = stack.p, { data } = parser2;
for (let set = 0; set < 2; set++) {
for (let i2 = parser2.stateSlot(
state,
set ? 2 : 1
/* ParseState.Actions */
); ; i2 += 3) {
if (data[i2] == 65535) {
if (data[i2 + 1] == 1) {
i2 = pair(data, i2 + 2);
} else {
if (index == 0 && data[i2 + 1] == 2)
index = this.putAction(pair(data, i2 + 2), token, end, index);
break;
}
}
if (data[i2] == token)
index = this.putAction(pair(data, i2 + 1), token, end, index);
}
}
return index;
}
}
class Parse {
constructor(parser2, input, fragments, ranges) {
this.parser = parser2;
this.input = input;
this.ranges = ranges;
this.recovering = 0;
this.nextStackID = 9812;
this.minStackPos = 0;
this.reused = [];
this.stoppedAt = null;
this.lastBigReductionStart = -1;
this.lastBigReductionSize = 0;
this.bigReductionCount = 0;
this.stream = new InputStream(input, ranges);
this.tokens = new TokenCache(parser2, this.stream);
this.topTerm = parser2.top[1];
let { from } = ranges[0];
this.stacks = [Stack.start(this, parser2.top[0], from)];
this.fragments = fragments.length && this.stream.end - from > parser2.bufferLength * 4 ? new FragmentCursor(fragments, parser2.nodeSet) : null;
}
get parsedPos() {
return this.minStackPos;
}
// Move the parser forward. This will process all parse stacks at
// `this.pos` and try to advance them to a further position. If no
// stack for such a position is found, it'll start error-recovery.
//
// When the parse is finished, this will return a syntax tree. When
// not, it returns `null`.
advance() {
let stacks = this.stacks, pos = this.minStackPos;
let newStacks = this.stacks = [];
let stopped, stoppedTokens;
if (this.bigReductionCount > 300 && stacks.length == 1) {
let [s] = stacks;
while (s.forceReduce() && s.stack.length && s.stack[s.stack.length - 2] >= this.lastBigReductionStart) {
}
this.bigReductionCount = this.lastBigReductionSize = 0;
}
for (let i2 = 0; i2 < stacks.length; i2++) {
let stack = stacks[i2];
for (; ; ) {
this.tokens.mainToken = null;
if (stack.pos > pos) {
newStacks.push(stack);
} else if (this.advanceStack(stack, newStacks, stacks)) {
continue;
} else {
if (!stopped) {
stopped = [];
stoppedTokens = [];
}
stopped.push(stack);
let tok = this.tokens.getMainToken(stack);
stoppedTokens.push(tok.value, tok.end);
}
break;
}
}
if (!newStacks.length) {
let finished = stopped && findFinished(stopped);
if (finished) {
if (verbose)
console.log("Finish with " + this.stackID(finished));
return this.stackToTree(finished);
}
if (this.parser.strict) {
if (verbose && stopped)
console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none"));
throw new SyntaxError("No parse at " + pos);
}
if (!this.recovering)
this.recovering = 5;
}
if (this.recovering && stopped) {
let finished = this.stoppedAt != null && stopped[0].pos > this.stoppedAt ? stopped[0] : this.runRecovery(stopped, stoppedTokens, newStacks);
if (finished) {
if (verbose)
console.log("Force-finish " + this.stackID(finished));
return this.stackToTree(finished.forceAll());
}
}
if (this.recovering) {
let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3;
if (newStacks.length > maxRemaining) {
newStacks.sort((a, b) => b.score - a.score);
while (newStacks.length > maxRemaining)
newStacks.pop();
}
if (newStacks.some((s) => s.reducePos > pos))
this.recovering--;
} else if (newStacks.length > 1) {
outer:
for (let i2 = 0; i2 < newStacks.length - 1; i2++) {
let stack = newStacks[i2];
for (let j2 = i2 + 1; j2 < newStacks.length; j2++) {
let other = newStacks[j2];
if (stack.sameState(other) || stack.buffer.length > 500 && other.buffer.length > 500) {
if ((stack.score - other.score || stack.buffer.length - other.buffer.length) > 0) {
newStacks.splice(j2--, 1);
} else {
newStacks.splice(i2--, 1);
continue outer;
}
}
}
}
if (newStacks.length > 12)
newStacks.splice(
12,
newStacks.length - 12
/* Rec.MaxStackCount */
);
}
this.minStackPos = newStacks[0].pos;
for (let i2 = 1; i2 < newStacks.length; i2++)
if (newStacks[i2].pos < this.minStackPos)
this.minStackPos = newStacks[i2].pos;
return null;
}
stopAt(pos) {
if (this.stoppedAt != null && this.stoppedAt < pos)
throw new RangeError("Can't move stoppedAt forward");
this.stoppedAt = pos;
}
// Returns an updated version of the given stack, or null if the
// stack can't advance normally. When `split` and `stacks` are
// given, stacks split off by ambiguous operations will be pushed to
// `split`, or added to `stacks` if they move `pos` forward.
advanceStack(stack, stacks, split) {
let start = stack.pos, { parser: parser2 } = this;
let base2 = verbose ? this.stackID(stack) + " -> " : "";
if (this.stoppedAt != null && start > this.stoppedAt)
return stack.forceReduce() ? stack : null;
if (this.fragments) {
let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0;
for (let cached = this.fragments.nodeAt(start); cached; ) {
let match2 = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser2.getGoto(stack.state, cached.type.id) : -1;
if (match2 > -1 && cached.length && (!strictCx || (cached.prop(NodeProp.contextHash) || 0) == cxHash)) {
stack.useNode(cached, match2);
if (verbose)
console.log(base2 + this.stackID(stack) + ` (via reuse of ${parser2.getName(cached.type.id)})`);
return true;
}
if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0)
break;
let inner = cached.children[0];
if (inner instanceof Tree && cached.positions[0] == 0)
cached = inner;
else
break;
}
}
let defaultReduce = parser2.stateSlot(
stack.state,
4
/* ParseState.DefaultReduce */
);
if (defaultReduce > 0) {
stack.reduce(defaultReduce);
if (verbose)
console.log(base2 + this.stackID(stack) + ` (via always-reduce ${parser2.getName(
defaultReduce & 65535
/* Action.ValueMask */
)})`);
return true;
}
if (stack.stack.length >= 8400) {
while (stack.stack.length > 6e3 && stack.forceReduce()) {
}
}
let actions = this.tokens.getActions(stack);
for (let i2 = 0; i2 < actions.length; ) {
let action = actions[i2++], term = actions[i2++], end = actions[i2++];
let last = i2 == actions.length || !split;
let localStack = last ? stack : stack.split();
let main = this.tokens.mainToken;
localStack.apply(action, term, main ? main.start : localStack.pos, end);
if (verbose)
console.log(base2 + this.stackID(localStack) + ` (via ${(action & 65536) == 0 ? "shift" : `reduce of ${parser2.getName(
action & 65535
/* Action.ValueMask */
)}`} for ${parser2.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`);
if (last)
return true;
else if (localStack.pos > start)
stacks.push(localStack);
else
split.push(localStack);
}
return false;
}
// Advance a given stack forward as far as it will go. Returns the
// (possibly updated) stack if it got stuck, or null if it moved
// forward and was given to `pushStackDedup`.
advanceFully(stack, newStacks) {
let pos = stack.pos;
for (; ; ) {
if (!this.advanceStack(stack, null, null))
return false;
if (stack.pos > pos) {
pushStackDedup(stack, newStacks);
return true;
}
}
}
runRecovery(stacks, tokens, newStacks) {
let finished = null, restarted = false;
for (let i2 = 0; i2 < stacks.length; i2++) {
let stack = stacks[i2], token = tokens[i2 << 1], tokenEnd = tokens[(i2 << 1) + 1];
let base2 = verbose ? this.stackID(stack) + " -> " : "";
if (stack.deadEnd) {
if (restarted)
continue;
restarted = true;
stack.restart();
if (verbose)
console.log(base2 + this.stackID(stack) + " (restarted)");
let done = this.advanceFully(stack, newStacks);
if (done)
continue;
}
let force = stack.split(), forceBase = base2;
for (let j2 = 0; force.forceReduce() && j2 < 10; j2++) {
if (verbose)
console.log(forceBase + this.stackID(force) + " (via force-reduce)");
let done = this.advanceFully(force, newStacks);
if (done)
break;
if (verbose)
forceBase = this.stackID(force) + " -> ";
}
for (let insert2 of stack.recoverByInsert(token)) {
if (verbose)
console.log(base2 + this.stackID(insert2) + " (via recover-insert)");
this.advanceFully(insert2, newStacks);
}
if (this.stream.end > stack.pos) {
if (tokenEnd == stack.pos) {
tokenEnd++;
token = 0;
}
stack.recoverByDelete(token, tokenEnd);
if (verbose)
console.log(base2 + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`);
pushStackDedup(stack, newStacks);
} else if (!finished || finished.score < stack.score) {
finished = stack;
}
}
return finished;
}
// Convert the stack's buffer to a syntax tree.
stackToTree(stack) {
stack.close();
return Tree.build({
buffer: StackBufferCursor.create(stack),
nodeSet: this.parser.nodeSet,
topID: this.topTerm,
maxBufferLength: this.parser.bufferLength,
reused: this.reused,
start: this.ranges[0].from,
length: stack.pos - this.ranges[0].from,
minRepeatType: this.parser.minRepeatTerm
});
}
stackID(stack) {
let id2 = (stackIDs || (stackIDs = /* @__PURE__ */ new WeakMap())).get(stack);
if (!id2)
stackIDs.set(stack, id2 = String.fromCodePoint(this.nextStackID++));
return id2 + stack;
}
}
function pushStackDedup(stack, newStacks) {
for (let i2 = 0; i2 < newStacks.length; i2++) {
let other = newStacks[i2];
if (other.pos == stack.pos && other.sameState(stack)) {
if (newStacks[i2].score < stack.score)
newStacks[i2] = stack;
return;
}
}
newStacks.push(stack);
}
class Dialect {
constructor(source, flags, disabled) {
this.source = source;
this.flags = flags;
this.disabled = disabled;
}
allows(term) {
return !this.disabled || this.disabled[term] == 0;
}
}
const id = (x2) => x2;
class ContextTracker {
/**
Define a context tracker.
*/
constructor(spec) {
this.start = spec.start;
this.shift = spec.shift || id;
this.reduce = spec.reduce || id;
this.reuse = spec.reuse || id;
this.hash = spec.hash || (() => 0);
this.strict = spec.strict !== false;
}
}
class LRParser extends Parser {
/**
@internal
*/
constructor(spec) {
super();
this.wrappers = [];
if (spec.version != 14)
throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (${14})`);
let nodeNames = spec.nodeNames.split(" ");
this.minRepeatTerm = nodeNames.length;
for (let i2 = 0; i2 < spec.repeatNodeCount; i2++)
nodeNames.push("");
let topTerms = Object.keys(spec.topRules).map((r) => spec.topRules[r][1]);
let nodeProps = [];
for (let i2 = 0; i2 < nodeNames.length; i2++)
nodeProps.push([]);
function setProp(nodeID, prop, value) {
nodeProps[nodeID].push([prop, prop.deserialize(String(value))]);
}
if (spec.nodeProps)
for (let propSpec of spec.nodeProps) {
let prop = propSpec[0];
if (typeof prop == "string")
prop = NodeProp[prop];
for (let i2 = 1; i2 < propSpec.length; ) {
let next = propSpec[i2++];
if (next >= 0) {
setProp(next, prop, propSpec[i2++]);
} else {
let value = propSpec[i2 + -next];
for (let j2 = -next; j2 > 0; j2--)
setProp(propSpec[i2++], prop, value);
i2++;
}
}
}
this.nodeSet = new NodeSet(nodeNames.map((name2, i2) => NodeType.define({
name: i2 >= this.minRepeatTerm ? void 0 : name2,
id: i2,
props: nodeProps[i2],
top: topTerms.indexOf(i2) > -1,
error: i2 == 0,
skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i2) > -1
})));
if (spec.propSources)
this.nodeSet = this.nodeSet.extend(...spec.propSources);
this.strict = false;
this.bufferLength = DefaultBufferLength;
let tokenArray = decodeArray(spec.tokenData);
this.context = spec.context;
this.specializerSpecs = spec.specialized || [];
this.specialized = new Uint16Array(this.specializerSpecs.length);
for (let i2 = 0; i2 < this.specializerSpecs.length; i2++)
this.specialized[i2] = this.specializerSpecs[i2].term;
this.specializers = this.specializerSpecs.map(getSpecializer);
this.states = decodeArray(spec.states, Uint32Array);
this.data = decodeArray(spec.stateData);
this.goto = decodeArray(spec.goto);
this.maxTerm = spec.maxTerm;
this.tokenizers = spec.tokenizers.map((value) => typeof value == "number" ? new TokenGroup(tokenArray, value) : value);
this.topRules = spec.topRules;
this.dialects = spec.dialects || {};
this.dynamicPrecedences = spec.dynamicPrecedences || null;
this.tokenPrecTable = spec.tokenPrec;
this.termNames = spec.termNames || null;
this.maxNode = this.nodeSet.types.length - 1;
this.dialect = this.parseDialect();
this.top = this.topRules[Object.keys(this.topRules)[0]];
}
createParse(input, fragments, ranges) {
let parse = new Parse(this, input, fragments, ranges);
for (let w2 of this.wrappers)
parse = w2(parse, input, fragments, ranges);
return parse;
}
/**
Get a goto table entry @internal
*/
getGoto(state, term, loose = false) {
let table = this.goto;
if (term >= table[0])
return -1;
for (let pos = table[term + 1]; ; ) {
let groupTag = table[pos++], last = groupTag & 1;
let target = table[pos++];
if (last && loose)
return target;
for (let end = pos + (groupTag >> 1); pos < end; pos++)
if (table[pos] == state)
return target;
if (last)
return -1;
}
}
/**
Check if this state has an action for a given terminal @internal
*/
hasAction(state, terminal) {
let data = this.data;
for (let set = 0; set < 2; set++) {
for (let i2 = this.stateSlot(
state,
set ? 2 : 1
/* ParseState.Actions */
), next; ; i2 += 3) {
if ((next = data[i2]) == 65535) {
if (data[i2 + 1] == 1)
next = data[i2 = pair(data, i2 + 2)];
else if (data[i2 + 1] == 2)
return pair(data, i2 + 2);
else
break;
}
if (next == terminal || next == 0)
return pair(data, i2 + 1);
}
}
return 0;
}
/**
@internal
*/
stateSlot(state, slot) {
return this.states[state * 6 + slot];
}
/**
@internal
*/
stateFlag(state, flag) {
return (this.stateSlot(
state,
0
/* ParseState.Flags */
) & flag) > 0;
}
/**
@internal
*/
validAction(state, action) {
return !!this.allActions(state, (a) => a == action ? true : null);
}
/**
@internal
*/
allActions(state, action) {
let deflt = this.stateSlot(
state,
4
/* ParseState.DefaultReduce */
);
let result2 = deflt ? action(deflt) : void 0;
for (let i2 = this.stateSlot(
state,
1
/* ParseState.Actions */
); result2 == null; i2 += 3) {
if (this.data[i2] == 65535) {
if (this.data[i2 + 1] == 1)
i2 = pair(this.data, i2 + 2);
else
break;
}
result2 = action(pair(this.data, i2 + 1));
}
return result2;
}
/**
Get the states that can follow this one through shift actions or
goto jumps. @internal
*/
nextStates(state) {
let result2 = [];
for (let i2 = this.stateSlot(
state,
1
/* ParseState.Actions */
); ; i2 += 3) {
if (this.data[i2] == 65535) {
if (this.data[i2 + 1] == 1)
i2 = pair(this.data, i2 + 2);
else
break;
}
if ((this.data[i2 + 2] & 65536 >> 16) == 0) {
let value = this.data[i2 + 1];
if (!result2.some((v, i3) => i3 & 1 && v == value))
result2.push(this.data[i2], value);
}
}
return result2;
}
/**
Configure the parser. Returns a new parser instance that has the
given settings modified. Settings not provided in `config` are
kept from the original parser.
*/
configure(config2) {
let copy = Object.assign(Object.create(LRParser.prototype), this);
if (config2.props)
copy.nodeSet = this.nodeSet.extend(...config2.props);
if (config2.top) {
let info = this.topRules[config2.top];
if (!info)
throw new RangeError(`Invalid top rule name ${config2.top}`);
copy.top = info;
}
if (config2.tokenizers)
copy.tokenizers = this.tokenizers.map((t2) => {
let found = config2.tokenizers.find((r) => r.from == t2);
return found ? found.to : t2;
});
if (config2.specializers) {
copy.specializers = this.specializers.slice();
copy.specializerSpecs = this.specializerSpecs.map((s, i2) => {
let found = config2.specializers.find((r) => r.from == s.external);
if (!found)
return s;
let spec = Object.assign(Object.assign({}, s), { external: found.to });
copy.specializers[i2] = getSpecializer(spec);
return spec;
});
}
if (config2.contextTracker)
copy.context = config2.contextTracker;
if (config2.dialect)
copy.dialect = this.parseDialect(config2.dialect);
if (config2.strict != null)
copy.strict = config2.strict;
if (config2.wrap)
copy.wrappers = copy.wrappers.concat(config2.wrap);
if (config2.bufferLength != null)
copy.bufferLength = config2.bufferLength;
return copy;
}
/**
Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
are registered for this parser.
*/
hasWrappers() {
return this.wrappers.length > 0;
}
/**
Returns the name associated with a given term. This will only
work for all terms when the parser was generated with the
`--names` option. By default, only the names of tagged terms are
stored.
*/
getName(term) {
return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term);
}
/**
The eof term id is always allocated directly after the node
types. @internal
*/
get eofTerm() {
return this.maxNode + 1;
}
/**
The type of top node produced by the parser.
*/
get topNode() {
return this.nodeSet.types[this.top[1]];
}
/**
@internal
*/
dynamicPrecedence(term) {
let prec2 = this.dynamicPrecedences;
return prec2 == null ? 0 : prec2[term] || 0;
}
/**
@internal
*/
parseDialect(dialect) {
let values = Object.keys(this.dialects), flags = values.map(() => false);
if (dialect)
for (let part of dialect.split(" ")) {
let id2 = values.indexOf(part);
if (id2 >= 0)
flags[id2] = true;
}
let disabled = null;
for (let i2 = 0; i2 < values.length; i2++)
if (!flags[i2]) {
for (let j2 = this.dialects[values[i2]], id2; (id2 = this.data[j2++]) != 65535; )
(disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id2] = 1;
}
return new Dialect(dialect, flags, disabled);
}
/**
Used by the output of the parser generator. Not available to
user code. @hide
*/
static deserialize(spec) {
return new LRParser(spec);
}
}
function pair(data, off) {
return data[off] | data[off + 1] << 16;
}
function findFinished(stacks) {
let best = null;
for (let stack of stacks) {
let stopped = stack.p.stoppedAt;
if ((stack.pos == stack.p.stream.end || stopped != null && stack.pos > stopped) && stack.p.parser.stateFlag(
stack.state,
2
/* StateFlag.Accepting */
) && (!best || best.score < stack.score))
best = stack;
}
return best;
}
function getSpecializer(spec) {
if (spec.external) {
let mask = spec.extend ? 1 : 0;
return (value, stack) => spec.external(value, stack) << 1 | mask;
}
return spec.get;
}
const noSemi = 309, incdec = 1, incdecPrefix = 2, JSXStartTag = 3, insertSemi = 310, spaces = 312, newline = 313, LineComment = 4, BlockComment = 5, Dialect_jsx = 0;
const space = [
9,
10,
11,
12,
13,
32,
133,
160,
5760,
8192,
8193,
8194,
8195,
8196,
8197,
8198,
8199,
8200,
8201,
8202,
8232,
8233,
8239,
8287,
12288
];
const braceR = 125, semicolon = 59, slash = 47, star = 42, plus = 43, minus = 45, lt = 60, comma = 44;
const trackNewline = new ContextTracker({
start: false,
shift(context, term) {
return term == LineComment || term == BlockComment || term == spaces ? context : term == newline;
},
strict: false
});
const insertSemicolon = new ExternalTokenizer((input, stack) => {
let { next } = input;
if (next == braceR || next == -1 || stack.context)
input.acceptToken(insertSemi);
}, { contextual: true, fallback: true });
const noSemicolon = new ExternalTokenizer((input, stack) => {
let { next } = input, after;
if (space.indexOf(next) > -1)
return;
if (next == slash && ((after = input.peek(1)) == slash || after == star))
return;
if (next != braceR && next != semicolon && next != -1 && !stack.context)
input.acceptToken(noSemi);
}, { contextual: true });
const incdecToken = new ExternalTokenizer((input, stack) => {
let { next } = input;
if (next == plus || next == minus) {
input.advance();
if (next == input.next) {
input.advance();
let mayPostfix = !stack.context && stack.canShift(incdec);
input.acceptToken(mayPostfix ? incdec : incdecPrefix);
}
}
}, { contextual: true });
function identifierChar(ch, start) {
return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch == 95 || ch >= 192 || !start && ch >= 48 && ch <= 57;
}
const jsx = new ExternalTokenizer((input, stack) => {
if (input.next != lt || !stack.dialectEnabled(Dialect_jsx))
return;
input.advance();
if (input.next == slash)
return;
let back = 0;
while (space.indexOf(input.next) > -1) {
input.advance();
back++;
}
if (identifierChar(input.next, true)) {
input.advance();
back++;
while (identifierChar(input.next, false)) {
input.advance();
back++;
}
while (space.indexOf(input.next) > -1) {
input.advance();
back++;
}
if (input.next == comma)
return;
for (let i2 = 0; ; i2++) {
if (i2 == 7) {
if (!identifierChar(input.next, true))
return;
break;
}
if (input.next != "extends".charCodeAt(i2))
break;
input.advance();
back++;
}
}
input.acceptToken(JSXStartTag, -back);
});
const jsHighlight = styleTags({
"get set async static": tags.modifier,
"for while do if else switch try catch finally return throw break continue default case": tags.controlKeyword,
"in of await yield void typeof delete instanceof": tags.operatorKeyword,
"let var const using function class extends": tags.definitionKeyword,
"import export from": tags.moduleKeyword,
"with debugger as new": tags.keyword,
TemplateString: tags.special(tags.string),
super: tags.atom,
BooleanLiteral: tags.bool,
this: tags.self,
null: tags.null,
Star: tags.modifier,
VariableName: tags.variableName,
"CallExpression/VariableName TaggedTemplateExpression/VariableName": tags.function(tags.variableName),
VariableDefinition: tags.definition(tags.variableName),
Label: tags.labelName,
PropertyName: tags.propertyName,
PrivatePropertyName: tags.special(tags.propertyName),
"CallExpression/MemberExpression/PropertyName": tags.function(tags.propertyName),
"FunctionDeclaration/VariableDefinition": tags.function(tags.definition(tags.variableName)),
"ClassDeclaration/VariableDefinition": tags.definition(tags.className),
PropertyDefinition: tags.definition(tags.propertyName),
PrivatePropertyDefinition: tags.definition(tags.special(tags.propertyName)),
UpdateOp: tags.updateOperator,
"LineComment Hashbang": tags.lineComment,
BlockComment: tags.blockComment,
Number: tags.number,
String: tags.string,
Escape: tags.escape,
ArithOp: tags.arithmeticOperator,
LogicOp: tags.logicOperator,
BitOp: tags.bitwiseOperator,
CompareOp: tags.compareOperator,
RegExp: tags.regexp,
Equals: tags.definitionOperator,
Arrow: tags.function(tags.punctuation),
": Spread": tags.punctuation,
"( )": tags.paren,
"[ ]": tags.squareBracket,
"{ }": tags.brace,
"InterpolationStart InterpolationEnd": tags.special(tags.brace),
".": tags.derefOperator,
", ;": tags.separator,
"@": tags.meta,
TypeName: tags.typeName,
TypeDefinition: tags.definition(tags.typeName),
"type enum interface implements namespace module declare": tags.definitionKeyword,
"abstract global Privacy readonly override": tags.modifier,
"is keyof unique infer": tags.operatorKeyword,
JSXAttributeValue: tags.attributeValue,
JSXText: tags.content,
"JSXStartTag JSXStartCloseTag JSXSelfCloseEndTag JSXEndTag": tags.angleBracket,
"JSXIdentifier JSXNameSpacedName": tags.tagName,
"JSXAttribute/JSXIdentifier JSXAttribute/JSXNameSpacedName": tags.attributeName,
"JSXBuiltin/JSXIdentifier": tags.standard(tags.tagName)
});
const spec_identifier = { __proto__: null, export: 18, as: 23, from: 31, default: 34, async: 39, function: 40, extends: 52, this: 56, true: 64, false: 64, null: 76, void: 80, typeof: 84, super: 102, new: 136, delete: 152, yield: 161, await: 165, class: 170, public: 227, private: 227, protected: 227, readonly: 229, instanceof: 248, satisfies: 251, in: 252, const: 254, import: 286, keyof: 339, unique: 343, infer: 349, is: 385, abstract: 405, implements: 407, type: 409, let: 412, var: 414, using: 417, interface: 423, enum: 427, namespace: 433, module: 435, declare: 439, global: 443, for: 462, of: 471, while: 474, with: 478, do: 482, if: 486, else: 488, switch: 492, case: 498, try: 504, catch: 508, finally: 512, return: 516, throw: 520, break: 524, continue: 528, debugger: 532 };
const spec_word = { __proto__: null, async: 123, get: 125, set: 127, declare: 187, public: 189, private: 189, protected: 189, static: 191, abstract: 193, override: 195, readonly: 201, accessor: 203, new: 389 };
const spec_LessThan = { __proto__: null, "<": 143 };
const parser = LRParser.deserialize({
version: 14,
states: "$<UO%TQ^OOO%[Q^OOO'_Q`OOP(lOWOOO*zQ08SO'#ChO+RO!bO'#CiO+aO#tO'#CiO+oO?MpO'#D^O.QQ^O'#Dd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eS#_W%eS(O#V(WS(T#Y+QS-P'S+RT-s'}-xT'X!e%fQ$kfR)s$pT)h$k)iR3r.zT*X$x*ZR*a${Q0g+]Q2z.ZQ5`1^Q6h3OQ7z5cQ8k6gQ9Y7yQ9l8jQ9}9[Q:V9nQ:[:OR:_:WnqOXst!Z#c%j&m&o&p&r,h,m1w1zQ&g!VR,]&dtmOXst!U!V!Z#c%j&d&m&o&p&r,h,m1w1zR,d&jT%im,dR1W+|R,[&bQ&Q|R+t&RR+j%{T&k!W&nT&l!W&nT1y,m1z",
nodeNames: "⚠ ArithOp ArithOp JSXStartTag LineComment BlockComment Script Hashbang ExportDeclaration export Star as VariableName String Escape from ; default FunctionDeclaration async function VariableDefinition > < TypeParamList TypeDefinition extends ThisType this LiteralType ArithOp Number BooleanLiteral TemplateType InterpolationEnd Interpolation InterpolationStart NullType null VoidType void TypeofType typeof MemberExpression . ?. PropertyName [ TemplateString Escape Interpolation super RegExp ] ArrayExpression Spread , } { ObjectExpression Property async get set PropertyDefinition Block : NewExpression new TypeArgList CompareOp < ) ( ArgList UnaryExpression delete LogicOp BitOp YieldExpression yield AwaitExpression await ParenthesizedExpression ClassExpression class ClassBody MethodDeclaration Decorator @ MemberExpression PrivatePropertyName CallExpression declare Privacy static abstract override PrivatePropertyDefinition PropertyDeclaration readonly accessor Optional TypeAnnotation Equals StaticBlock FunctionExpression ArrowFunction ParamList ParamList ArrayPattern ObjectPattern PatternProperty Privacy readonly Arrow MemberExpression BinaryExpression ArithOp ArithOp ArithOp ArithOp BitOp CompareOp instanceof satisfies in const CompareOp BitOp BitOp BitOp LogicOp LogicOp ConditionalExpression LogicOp LogicOp AssignmentExpression UpdateOp PostfixExpression CallExpression TaggedTemplateExpression DynamicImport import ImportMeta JSXElement JSXSelfCloseEndTag JSXSelfClosingTag JSXIdentifier JSXBuiltin JSXIdentifier JSXNamespacedName JSXMemberExpression JSXSpreadAttribute JSXAttribute JSXAttributeValue JSXEscape JSXEndTag JSXOpenTag JSXFragmentTag JSXText JSXEscape JSXStartCloseTag JSXCloseTag PrefixCast ArrowFunction TypeParamList SequenceExpression KeyofType keyof UniqueType unique ImportType InferredType infer TypeName ParenthesizedType FunctionSignature ParamList NewSignature IndexedType TupleType Label ArrayType ReadonlyType ObjectType MethodType PropertyType IndexSignature PropertyDefinition CallSignature TypePredicate is NewSignature new UnionType LogicOp IntersectionType LogicOp ConditionalType ParameterizedType ClassDeclaration abstract implements type VariableDeclaration let var using TypeAliasDeclaration InterfaceDeclaration interface EnumDeclaration enum EnumBody NamespaceDeclaration namespace module AmbientDeclaration declare GlobalDeclaration global ClassDeclaration ClassBody AmbientFunctionDeclaration ExportGroup VariableName VariableName ImportDeclaration ImportGroup ForStatement for ForSpec ForInSpec ForOfSpec of WhileStatement while WithStatement with DoStatement do IfStatement if else SwitchStatement switch SwitchBody CaseLabel case DefaultLabel TryStatement try CatchClause catch FinallyClause finally ReturnStatement return ThrowStatement throw BreakStatement break ContinueStatement continue DebuggerStatement debugger LabeledStatement ExpressionStatement SingleExpression SingleClassItem",
maxTerm: 371,
context: trackNewline,
nodeProps: [
["isolate", -8, 4, 5, 13, 33, 35, 48, 50, 52, ""],
["group", -26, 8, 16, 18, 65, 201, 205, 209, 210, 212, 215, 218, 228, 230, 236, 238, 240, 242, 245, 251, 257, 259, 261, 263, 265, 267, 268, "Statement", -32, 12, 13, 28, 31, 32, 38, 48, 51, 52, 54, 59, 67, 75, 79, 81, 83, 84, 106, 107, 116, 117, 134, 137, 139, 140, 141, 142, 144, 145, 164, 165, 167, "Expression", -23, 27, 29, 33, 37, 39, 41, 168, 170, 172, 173, 175, 176, 177, 179, 180, 181, 183, 184, 185, 195, 197, 199, 200, "Type", -3, 87, 99, 105, "ClassItem"],
["openedBy", 22, "<", 34, "InterpolationStart", 53, "[", 57, "{", 72, "(", 157, "JSXStartCloseTag"],
["closedBy", 23, ">", 36, "InterpolationEnd", 47, "]", 58, "}", 73, ")", 162, "JSXEndTag"]
],
propSources: [jsHighlight],
sk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+g[p%Zpq+gqr%Zrs&}st%ZtuEruw%Zwx(rx}%Z}!OGv!O!Q%Z!Q![Er![!^%Z!^!_*g!_!c%Z!c!}Er!}#O%Z#O#P&c#P#R%Z#R#SEr#S#T%Z#T#oEr#o#p*g#p$f%Z$f$g+g$g#BYEr#BY#BZ$AX#BZ$ISEr$IS$I_$AX$I_$JTEr$JT$JU$AX$JU$KVEr$KV$KW$AX$KW&FUEr&FU&FV$AX&FV;'SEr;'S;=`I|<%l?HTEr?HT?HU$AX?HUOEr(CS$Duk$f&j(Op(R!b'u(;d$Y#t'{&;d([!LYOY%ZYZ&cZr%Zrs&}st%ZtuEruw%Zwx(rx}%Z}!OGv!O!Q%Z!Q![Er![!^%Z!^!_*g!_!c%Z!c!}Er!}#O%Z#O#P&c#P#R%Z#R#SEr#S#T%Z#T#oEr#o#p*g#p$g%Z$g;'SEr;'S;=`I|<%lOEr",
tokenizers: [noSemicolon, incdecToken, jsx, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, insertSemicolon, new LocalTokenGroup("$S~RRtu[#O#Pg#S#T#|~_P#o#pb~gOt~~jVO#i!P#i#j!U#j#l!P#l#m!q#m;'S!P;'S;=`#v<%lO!P~!UO!R~~!XS!Q![!e!c!i!e#T#Z!e#o#p#Z~!hR!Q![!q!c!i!q#T#Z!q~!tR!Q![!}!c!i!}#T#Z!}~#QR!Q![!P!c!i!P#T#Z!P~#^R!Q![#g!c!i#g#T#Z#g~#jS!Q![#g!c!i#g#T#Z#g#q#r!P~#yP;=`<%l!P~$RO(Z~~", 141, 332), new LocalTokenGroup("j~RQYZXz{^~^O'x~~aP!P!Qd~iO'y~~", 25, 315)],
topRules: { "Script": [0, 6], "SingleExpression": [1, 269], "SingleClassItem": [2, 270] },
dialects: { jsx: 0, ts: 14614 },
dynamicPrecedences: { "69": 1, "79": 1, "81": 1, "165": 1, "193": 1 },
specialized: [{ term: 319, get: (value) => spec_identifier[value] || -1 }, { term: 334, get: (value) => spec_word[value] || -1 }, { term: 70, get: (value) => spec_LessThan[value] || -1 }],
tokenPrec: 14638
});
const snippets = [
/* @__PURE__ */ snippetCompletion("function ${name}(${params}) {\n ${}\n}", {
label: "function",
detail: "definition",
type: "keyword"
}),
/* @__PURE__ */ snippetCompletion("for (let ${index} = 0; ${index} < ${bound}; ${index}++) {\n ${}\n}", {
label: "for",
detail: "loop",
type: "keyword"
}),
/* @__PURE__ */ snippetCompletion("for (let ${name} of ${collection}) {\n ${}\n}", {
label: "for",
detail: "of loop",
type: "keyword"
}),
/* @__PURE__ */ snippetCompletion("do {\n ${}\n} while (${})", {
label: "do",
detail: "loop",
type: "keyword"
}),
/* @__PURE__ */ snippetCompletion("while (${}) {\n ${}\n}", {
label: "while",
detail: "loop",
type: "keyword"
}),
/* @__PURE__ */ snippetCompletion("try {\n ${}\n} catch (${error}) {\n ${}\n}", {
label: "try",
detail: "/ catch block",
type: "keyword"
}),
/* @__PURE__ */ snippetCompletion("if (${}) {\n ${}\n}", {
label: "if",
detail: "block",
type: "keyword"
}),
/* @__PURE__ */ snippetCompletion("if (${}) {\n ${}\n} else {\n ${}\n}", {
label: "if",
detail: "/ else block",
type: "keyword"
}),
/* @__PURE__ */ snippetCompletion("class ${name} {\n constructor(${params}) {\n ${}\n }\n}", {
label: "class",
detail: "definition",
type: "keyword"
}),
/* @__PURE__ */ snippetCompletion('import {${names}} from "${module}"\n${}', {
label: "import",
detail: "named",
type: "keyword"
}),
/* @__PURE__ */ snippetCompletion('import ${name} from "${module}"\n${}', {
label: "import",
detail: "default",
type: "keyword"
})
];
const typescriptSnippets = /* @__PURE__ */ snippets.concat([
/* @__PURE__ */ snippetCompletion("interface ${name} {\n ${}\n}", {
label: "interface",
detail: "definition",
type: "keyword"
}),
/* @__PURE__ */ snippetCompletion("type ${name} = ${type}", {
label: "type",
detail: "definition",
type: "keyword"
}),
/* @__PURE__ */ snippetCompletion("enum ${name} {\n ${}\n}", {
label: "enum",
detail: "definition",
type: "keyword"
})
]);
const cache = /* @__PURE__ */ new NodeWeakMap();
const ScopeNodes = /* @__PURE__ */ new Set([
"Script",
"Block",
"FunctionExpression",
"FunctionDeclaration",
"ArrowFunction",
"MethodDeclaration",
"ForStatement"
]);
function defID(type) {
return (node, def) => {
let id2 = node.node.getChild("VariableDefinition");
if (id2)
def(id2, type);
return true;
};
}
const functionContext = ["FunctionDeclaration"];
const gatherCompletions = {
FunctionDeclaration: /* @__PURE__ */ defID("function"),
ClassDeclaration: /* @__PURE__ */ defID("class"),
ClassExpression: () => true,
EnumDeclaration: /* @__PURE__ */ defID("constant"),
TypeAliasDeclaration: /* @__PURE__ */ defID("type"),
NamespaceDeclaration: /* @__PURE__ */ defID("namespace"),
VariableDefinition(node, def) {
if (!node.matchContext(functionContext))
def(node, "variable");
},
TypeDefinition(node, def) {
def(node, "type");
},
__proto__: null
};
function getScope(doc2, node) {
let cached = cache.get(node);
if (cached)
return cached;
let completions = [], top2 = true;
function def(node2, type) {
let name2 = doc2.sliceString(node2.from, node2.to);
completions.push({ label: name2, type });
}
node.cursor(IterMode.IncludeAnonymous).iterate((node2) => {
if (top2) {
top2 = false;
} else if (node2.name) {
let gather = gatherCompletions[node2.name];
if (gather && gather(node2, def) || ScopeNodes.has(node2.name))
return false;
} else if (node2.to - node2.from > 8192) {
for (let c of getScope(doc2, node2.node))
completions.push(c);
return false;
}
});
cache.set(node, completions);
return completions;
}
const Identifier = /^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/;
const dontComplete = [
"TemplateString",
"String",
"RegExp",
"LineComment",
"BlockComment",
"VariableDefinition",
"TypeDefinition",
"Label",
"PropertyDefinition",
"PropertyName",
"PrivatePropertyDefinition",
"PrivatePropertyName",
".",
"?."
];
function localCompletionSource(context) {
let inner = syntaxTree(context.state).resolveInner(context.pos, -1);
if (dontComplete.indexOf(inner.name) > -1)
return null;
let isWord = inner.name == "VariableName" || inner.to - inner.from < 20 && Identifier.test(context.state.sliceDoc(inner.from, inner.to));
if (!isWord && !context.explicit)
return null;
let options = [];
for (let pos = inner; pos; pos = pos.parent) {
if (ScopeNodes.has(pos.name))
options = options.concat(getScope(context.state.doc, pos));
}
return {
options,
from: isWord ? inner.from : context.pos,
validFor: Identifier
};
}
const javascriptLanguage = /* @__PURE__ */ LRLanguage.define({
name: "javascript",
parser: /* @__PURE__ */ parser.configure({
props: [
/* @__PURE__ */ indentNodeProp.add({
IfStatement: /* @__PURE__ */ continuedIndent({ except: /^\s*({|else\b)/ }),
TryStatement: /* @__PURE__ */ continuedIndent({ except: /^\s*({|catch\b|finally\b)/ }),
LabeledStatement: flatIndent,
SwitchBody: (context) => {
let after = context.textAfter, closed = /^\s*\}/.test(after), isCase = /^\s*(case|default)\b/.test(after);
return context.baseIndent + (closed ? 0 : isCase ? 1 : 2) * context.unit;
},
Block: /* @__PURE__ */ delimitedIndent({ closing: "}" }),
ArrowFunction: (cx) => cx.baseIndent + cx.unit,
"TemplateString BlockComment": () => null,
"Statement Property": /* @__PURE__ */ continuedIndent({ except: /^{/ }),
JSXElement(context) {
let closed = /^\s*<\//.test(context.textAfter);
return context.lineIndent(context.node.from) + (closed ? 0 : context.unit);
},
JSXEscape(context) {
let closed = /\s*\}/.test(context.textAfter);
return context.lineIndent(context.node.from) + (closed ? 0 : context.unit);
},
"JSXOpenTag JSXSelfClosingTag"(context) {
return context.column(context.node.from) + context.unit;
}
}),
/* @__PURE__ */ foldNodeProp.add({
"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType": foldInside,
BlockComment(tree) {
return { from: tree.from + 2, to: tree.to - 2 };
}
})
]
}),
languageData: {
closeBrackets: { brackets: ["(", "[", "{", "'", '"', "`"] },
commentTokens: { line: "//", block: { open: "/*", close: "*/" } },
indentOnInput: /^\s*(?:case |default:|\{|\}|<\/)$/,
wordChars: "$"
}
});
const jsxSublanguage = {
test: (node) => /^JSX/.test(node.name),
facet: /* @__PURE__ */ defineLanguageFacet({ commentTokens: { block: { open: "{/*", close: "*/}" } } })
};
const typescriptLanguage = /* @__PURE__ */ javascriptLanguage.configure({ dialect: "ts" }, "typescript");
const jsxLanguage = /* @__PURE__ */ javascriptLanguage.configure({
dialect: "jsx",
props: [/* @__PURE__ */ sublanguageProp.add((n) => n.isTop ? [jsxSublanguage] : void 0)]
});
const tsxLanguage = /* @__PURE__ */ javascriptLanguage.configure({
dialect: "jsx ts",
props: [/* @__PURE__ */ sublanguageProp.add((n) => n.isTop ? [jsxSublanguage] : void 0)]
}, "typescript");
let kwCompletion = (name2) => ({ label: name2, type: "keyword" });
const keywords = /* @__PURE__ */ "break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(kwCompletion);
const typescriptKeywords = /* @__PURE__ */ keywords.concat(/* @__PURE__ */ ["declare", "implements", "private", "protected", "public"].map(kwCompletion));
function javascript(config2 = {}) {
let lang = config2.jsx ? config2.typescript ? tsxLanguage : jsxLanguage : config2.typescript ? typescriptLanguage : javascriptLanguage;
let completions = config2.typescript ? typescriptSnippets.concat(typescriptKeywords) : snippets.concat(keywords);
return new LanguageSupport(lang, [
javascriptLanguage.data.of({
autocomplete: ifNotIn(dontComplete, completeFromList(completions))
}),
javascriptLanguage.data.of({
autocomplete: localCompletionSource
}),
config2.jsx ? autoCloseTags : []
]);
}
function findOpenTag(node) {
for (; ; ) {
if (node.name == "JSXOpenTag" || node.name == "JSXSelfClosingTag" || node.name == "JSXFragmentTag")
return node;
if (node.name == "JSXEscape" || !node.parent)
return null;
node = node.parent;
}
}
function elementName(doc2, tree, max = doc2.length) {
for (let ch = tree === null || tree === void 0 ? void 0 : tree.firstChild; ch; ch = ch.nextSibling) {
if (ch.name == "JSXIdentifier" || ch.name == "JSXBuiltin" || ch.name == "JSXNamespacedName" || ch.name == "JSXMemberExpression")
return doc2.sliceString(ch.from, Math.min(ch.to, max));
}
return "";
}
const android = typeof navigator == "object" && /* @__PURE__ */ /Android\b/.test(navigator.userAgent);
const autoCloseTags = /* @__PURE__ */ EditorView.inputHandler.of((view, from, to, text, defaultInsert) => {
if ((android ? view.composing : view.compositionStarted) || view.state.readOnly || from != to || text != ">" && text != "/" || !javascriptLanguage.isActiveAt(view.state, from, -1))
return false;
let base2 = defaultInsert(), { state } = base2;
let closeTags = state.changeByRange((range) => {
var _a2;
let { head } = range, around = syntaxTree(state).resolveInner(head - 1, -1), name2;
if (around.name == "JSXStartTag")
around = around.parent;
if (state.doc.sliceString(head - 1, head) != text || around.name == "JSXAttributeValue" && around.to > head)
;
else if (text == ">" && around.name == "JSXFragmentTag") {
return { range, changes: { from: head, insert: `</>` } };
} else if (text == "/" && around.name == "JSXStartCloseTag") {
let empty2 = around.parent, base3 = empty2.parent;
if (base3 && empty2.from == head - 2 && ((name2 = elementName(state.doc, base3.firstChild, head)) || ((_a2 = base3.firstChild) === null || _a2 === void 0 ? void 0 : _a2.name) == "JSXFragmentTag")) {
let insert2 = `${name2}>`;
return { range: EditorSelection.cursor(head + insert2.length, -1), changes: { from: head, insert: insert2 } };
}
} else if (text == ">") {
let openTag = findOpenTag(around);
if (openTag && openTag.name == "JSXOpenTag" && !/^\/?>|^<\//.test(state.doc.sliceString(head, head + 2)) && (name2 = elementName(state.doc, openTag, head)))
return { range, changes: { from: head, insert: `</${name2}>` } };
}
return { range };
});
if (closeTags.changes.empty)
return false;
view.dispatch([
base2,
state.update(closeTags, { userEvent: "input.complete", scrollIntoView: true })
]);
return true;
});
const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
__name: "CodeInput",
props: {
code: { default: "" }
},
emits: ["update:code"],
setup(__props2, { emit }) {
const extensions = [javascript()];
const view = vue.shallowRef();
const handleReady = (payload) => {
view.value = payload.view;
};
return (_ctx, _cache) => {
return vue.openBlock(), vue.createBlock(vue.unref(T), {
"model-value": _ctx.code,
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => emit("update:code", $event)),
placeholder: "Code goes here...",
style: { height: "400px", "font-size": "16px" },
autofocus: true,
"indent-with-tab": true,
"tab-size": 4,
extensions,
onReady: handleReady
}, null, 8, ["model-value"]);
};
}
});
const _withScopeId = (n) => (vue.pushScopeId("data-v-ce9a698d"), n = n(), vue.popScopeId(), n);
const _hoisted_1 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ vue.createElementVNode("p", null, "在下方输入框中输入你的axios模版,采用es6的模版方式解析,提供了6个变量,describtion,name,method,url,header,params(均为字符串) :", -1));
const _hoisted_2 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ vue.createElementVNode("p", { style: { "margin-bottom": "15px" } }, [
/* @__PURE__ */ vue.createTextVNode("保证你的代码是在 "),
/* @__PURE__ */ vue.createElementVNode("span", { style: { "font-size": "20px" } }, "function (describtion,name,method,url,header,params){ }"),
/* @__PURE__ */ vue.createTextVNode(" 里面 ")
], -1));
const _hoisted_3 = { class: "custom-tabs-label" };
const _hoisted_4 = ["onUpdate:modelValue"];
const _hoisted_5 = { class: "bottom-line" };
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
__name: "CustomAxiosDialog",
setup(__props2) {
const dialogVisible2 = vue.inject("dialogVisible");
let _tabs2 = getTemplates();
vue.watch(dialogVisible2, (val) => {
if (!val) {
_tabs2 = getTemplates();
tabs2.value = JSON.parse(JSON.stringify(_tabs2));
}
});
function save() {
_GM_setValue("customAxiosTemplate", JSON.stringify(tabs2.value));
ElementPlus.ElMessage.success("保存成功");
}
const activeKey2 = vue.ref(0);
const tabs2 = vue.ref(JSON.parse(JSON.stringify(_tabs2)));
let tabIndex = tabs2.value.length - 1;
const handleTabsEdit = (targetName, action) => {
if (action === "add") {
const newTabName = +`${++tabIndex}`;
tabs2.value.push({
title: `默认格式${newTabName}`,
name: newTabName,
content: 'function (describtion,name,method,url,header,params){\n /** 这是你的代码 */\n return "";\n}'
});
activeKey2.value = newTabName;
} else if (action === "remove") {
let activeName = activeKey2.value;
if (activeName === targetName) {
tabs2.value.forEach((tab, index) => {
if (tab.name === targetName) {
const nextTab = tabs2.value[index + 1] || tabs2.value[index - 1];
if (nextTab) {
activeName = nextTab.name;
}
}
});
}
activeKey2.value = activeName;
tabs2.value = tabs2.value.filter((tab) => tab.name !== targetName);
}
};
function restore() {
_tabs2 = getTemplates(true);
activeKey2.value = 0;
tabs2.value = JSON.parse(JSON.stringify(_tabs2));
}
return (_ctx, _cache) => {
const _component_el_tab_pane = vue.resolveComponent("el-tab-pane");
const _component_el_tabs = vue.resolveComponent("el-tabs");
const _component_el_button = vue.resolveComponent("el-button");
const _component_el_dialog = vue.resolveComponent("el-dialog");
return vue.openBlock(), vue.createBlock(_component_el_dialog, {
modelValue: vue.unref(dialogVisible2),
"onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => vue.isRef(dialogVisible2) ? dialogVisible2.value = $event : null),
title: "自定义axios模版"
}, {
default: vue.withCtx(() => [
_hoisted_1,
_hoisted_2,
vue.createVNode(_component_el_tabs, {
modelValue: activeKey2.value,
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => activeKey2.value = $event),
type: "card",
editable: "",
onEdit: handleTabsEdit
}, {
default: vue.withCtx(() => [
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(tabs2.value, (item) => {
return vue.openBlock(), vue.createBlock(_component_el_tab_pane, {
key: item.name,
name: item.name
}, {
label: vue.withCtx(() => [
vue.createElementVNode("span", _hoisted_3, [
vue.withDirectives(vue.createElementVNode("input", {
type: "text",
"onUpdate:modelValue": ($event) => item.title = $event,
onKeydown: _cache[0] || (_cache[0] = vue.withModifiers(() => {
}, ["stop"])),
style: { "outline": "0 !important", "border": "0 !important" }
}, null, 40, _hoisted_4), [
[vue.vModelText, item.title]
])
])
]),
default: vue.withCtx(() => [
vue.createVNode(_sfc_main$1, {
code: item.content,
"onUpdate:code": ($event) => item.content = $event
}, null, 8, ["code", "onUpdate:code"])
]),
_: 2
}, 1032, ["name"]);
}), 128))
]),
_: 1
}, 8, ["modelValue"]),
vue.createElementVNode("div", _hoisted_5, [
vue.createVNode(_component_el_button, { onClick: restore }, {
default: vue.withCtx(() => [
vue.createTextVNode("复原默认模版")
]),
_: 1
}),
vue.createVNode(_component_el_button, {
style: { "margin": "20px 0" },
onClick: save
}, {
default: vue.withCtx(() => [
vue.createTextVNode("保存")
]),
_: 1
})
])
]),
_: 1
}, 8, ["modelValue"]);
};
}
});
const CustomAxiosDialog = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-ce9a698d"]]);
const cssLoader = (e) => {
const t2 = GM_getResourceText(e), o = document.createElement("style");
return o.innerText = t2, document.head.append(o), t2;
};
cssLoader("element-plus/dist/index.css");
function wrapState(action) {
const raw = history[action];
return function(...args) {
const urlBefore = window.location.href;
const wrapper = raw.apply(this, args);
const urlAfter = window.location.href;
if (urlBefore === urlAfter) {
return;
}
const e = new Event(action);
e.stateInfo = args;
window.dispatchEvent(e);
return wrapper;
};
}
const historyWatch = (pushStateCallback, replaceStateCallback) => {
history.pushState = wrapState("pushState");
history.replaceState = wrapState("replaceState");
pushStateCallback && window.addEventListener("pushState", function(e) {
pushStateCallback(e.stateInfo);
});
replaceStateCallback && window.addEventListener("replaceState", function(e) {
replaceStateCallback(e.stateInfo);
});
};
const dialogVisible = vue.ref(false);
async function init() {
let domList = document.querySelectorAll(".interface-title");
while (!domList.length) {
await new Promise((resolve) => {
setTimeout(() => {
domList = document.querySelectorAll(".interface-title");
resolve();
}, 10);
});
}
domList.forEach((el) => {
var _a2, _b, _c, _d;
let list = [];
let com = null;
switch (el.textContent) {
case "基本信息":
com = _sfc_main$3;
list = [el];
break;
case "请求参数":
com = CreateTypes;
while (el) {
if (!el.innerHTML.includes("button")) {
if (((_b = (_a2 = el == null ? void 0 : el.firstChild) == null ? void 0 : _a2.textContent) == null ? void 0 : _b.startsWith("Query")) || ((_d = (_c = el == null ? void 0 : el.firstChild) == null ? void 0 : _c.textContent) == null ? void 0 : _d.startsWith("Body"))) {
list.push(el == null ? void 0 : el.firstChild);
}
}
el = el.nextElementSibling;
if (!el)
break;
}
break;
case "返回数据":
list = [el];
com = CreateTypes;
}
if (!com)
return;
for (let i2 = 0; i2 < list.length; i2++) {
vue.createApp(com).use(ElementPlus).provide("dialogVisible", dialogVisible).mount(
(() => {
const app = document.createElement("div");
app.style.display = "inline-block";
app.style.marginLeft = "20px";
list[i2].append(app);
return app;
})()
);
}
});
}
init();
historyWatch(() => {
setTimeout(() => {
init();
}, 100);
});
setTimeout(() => {
const tabsList = document.querySelectorAll(".ant-tabs-tab");
for (const tab of Array.from(tabsList)) {
if (tab.textContent === "预览") {
tab.addEventListener("click", () => {
setTimeout(() => {
init();
}, 100);
});
}
}
});
vue.createApp(CustomAxiosDialog).provide("dialogVisible", dialogVisible).use(ElementPlus).mount(
(() => {
const app = document.createElement("div");
app.id = "custom-axios-dialog";
document.body.appendChild(app);
return app;
})()
);
_GM_registerMenuCommand("自定义axios模版", function() {
dialogVisible.value = true;
});
})(Vue, ElementPlus);