@hpcc-js/observablehq-compiler
Version:
hpcc-js - ObservableHQ Compiler (unoffical)
1,246 lines (1,245 loc) • 36.4 kB
JavaScript
import "./chunk-rwCFCtyI.js";
//#region ../../node_modules/@lezer/common/dist/index.js
var e = 1024, t = 0, Range = class {
constructor(e, t) {
this.from = e, this.to = t;
}
}, NodeProp = class {
constructor(e = {}) {
this.id = t++, this.perNode = !!e.perNode, this.deserialize = e.deserialize || (() => {
throw Error("This node type doesn't define a deserialize function");
}), this.combine = e.combine || null;
}
add(e) {
if (this.perNode) throw RangeError("Can't add per-node props to node types");
return typeof e != "function" && (e = r.match(e)), (t) => {
let n = e(t);
return n === void 0 ? null : [this, n];
};
}
};
NodeProp.closedBy = new NodeProp({ deserialize: (e) => e.split(" ") }), NodeProp.openedBy = new NodeProp({ deserialize: (e) => e.split(" ") }), NodeProp.group = new NodeProp({ deserialize: (e) => e.split(" ") }), NodeProp.isolate = new NodeProp({ deserialize: (e) => {
if (e && e != "rtl" && e != "ltr" && e != "auto") throw RangeError("Invalid value for isolate: " + e);
return e || "auto";
} }), NodeProp.contextHash = new NodeProp({ perNode: !0 }), NodeProp.lookAhead = new NodeProp({ perNode: !0 }), NodeProp.mounted = new NodeProp({ perNode: !0 });
var MountedTree = class {
constructor(e, t, n, r = !1) {
this.tree = e, this.overlay = t, this.parser = n, this.bracketed = r;
}
static get(e) {
return e && e.props && e.props[NodeProp.mounted.id];
}
}, n = Object.create(null), r = class NodeType {
constructor(e, t, n, r = 0) {
this.name = e, this.props = t, this.id = n, this.flags = r;
}
static define(e) {
let t = e.props && e.props.length ? Object.create(null) : n, r = !!e.top | (e.skipped ? 2 : 0) | (e.error ? 4 : 0) | (e.name == null ? 8 : 0), i = new NodeType(e.name || "", t, e.id, r);
if (e.props) {
for (let n of e.props) if (Array.isArray(n) || (n = n(i)), n) {
if (n[0].perNode) throw RangeError("Can't store a per-node prop on a node type");
t[n[0].id] = n[1];
}
}
return i;
}
prop(e) {
return this.props[e.id];
}
get isTop() {
return (this.flags & 1) > 0;
}
get isSkipped() {
return (this.flags & 2) > 0;
}
get isError() {
return (this.flags & 4) > 0;
}
get isAnonymous() {
return (this.flags & 8) > 0;
}
is(e) {
if (typeof e == "string") {
if (this.name == e) return !0;
let t = this.prop(NodeProp.group);
return t ? t.indexOf(e) > -1 : !1;
}
return this.id == e;
}
static match(e) {
let t = Object.create(null);
for (let n in e) for (let r of n.split(" ")) t[r] = e[n];
return (e) => {
for (let n = e.prop(NodeProp.group), r = -1; r < (n ? n.length : 0); r++) {
let i = t[r < 0 ? e.name : n[r]];
if (i) return i;
}
};
}
};
r.none = new r("", Object.create(null), 0, 8);
var i = class NodeSet {
constructor(e) {
this.types = e;
for (let t = 0; t < e.length; t++) if (e[t].id != t) throw RangeError("Node type ids should correspond to array positions when creating a node set");
}
extend(...e) {
let t = [];
for (let n of this.types) {
let i = null;
for (let t of e) {
let e = t(n);
if (e) {
i ||= Object.assign({}, n.props);
let t = e[1], r = e[0];
r.combine && r.id in i && (t = r.combine(i[r.id], t)), i[r.id] = t;
}
}
t.push(i ? new r(n.name, i, n.id, n.flags) : n);
}
return new NodeSet(t);
}
}, a = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new WeakMap(), s;
(function(e) {
e[e.ExcludeBuffers = 1] = "ExcludeBuffers", e[e.IncludeAnonymous = 2] = "IncludeAnonymous", e[e.IgnoreMounts = 4] = "IgnoreMounts", e[e.IgnoreOverlays = 8] = "IgnoreOverlays", e[e.EnterBracketed = 16] = "EnterBracketed";
})(s ||= {});
var c = class Tree {
constructor(e, t, n, r, i) {
if (this.type = e, this.children = t, this.positions = n, this.length = r, this.props = null, i && i.length) {
this.props = Object.create(null);
for (let [e, t] of i) this.props[typeof e == "number" ? e : e.id] = t;
}
}
toString() {
let e = MountedTree.get(this);
if (e && !e.overlay) return e.tree.toString();
let t = "";
for (let e of this.children) {
let n = e.toString();
n && (t && (t += ","), t += n);
}
return this.type.name ? (/\W/.test(this.type.name) && !this.type.isError ? JSON.stringify(this.type.name) : this.type.name) + (t.length ? "(" + t + ")" : "") : t;
}
cursor(e = 0) {
return new TreeCursor(this.topNode, e);
}
cursorAt(e, t = 0, n = 0) {
let r = new TreeCursor(a.get(this) || this.topNode);
return r.moveTo(e, t), a.set(this, r._tree), r;
}
get topNode() {
return new d(this, 0, 0, null);
}
resolve(e, t = 0) {
let n = resolveNode(a.get(this) || this.topNode, e, t, !1);
return a.set(this, n), n;
}
resolveInner(e, t = 0) {
let n = resolveNode(o.get(this) || this.topNode, e, t, !0);
return o.set(this, n), n;
}
resolveStack(e, t = 0) {
return stackIterator(this, e, t);
}
iterate(e) {
let { enter: t, leave: n, from: r = 0, to: i = this.length } = e, a = e.mode || 0, o = (a & s.IncludeAnonymous) > 0;
for (let e = this.cursor(a | s.IncludeAnonymous);;) {
let a = !1;
if (e.from <= i && e.to >= r && (!o && e.type.isAnonymous || t(e) !== !1)) {
if (e.firstChild()) continue;
a = !0;
}
for (; a && n && (o || !e.type.isAnonymous) && n(e), !e.nextSibling();) {
if (!e.parent()) return;
a = !0;
}
}
}
prop(e) {
return e.perNode ? this.props ? this.props[e.id] : void 0 : this.type.prop(e);
}
get propValues() {
let e = [];
if (this.props) for (let t in this.props) e.push([+t, this.props[t]]);
return e;
}
balance(e = {}) {
return this.children.length <= 8 ? this : balanceRange(r.none, this.children, this.positions, 0, this.children.length, 0, this.length, (e, t, n) => new Tree(this.type, e, t, n, this.propValues), e.makeTree || ((e, t, n) => new Tree(r.none, e, t, n)));
}
static build(e) {
return buildTree(e);
}
};
c.empty = new c(r.none, [], [], 0);
var l = class FlatBufferCursor {
constructor(e, t) {
this.buffer = e, this.index = t;
}
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);
}
}, u = class TreeBuffer {
constructor(e, t, n) {
this.buffer = e, this.length = t, this.set = n;
}
get type() {
return r.none;
}
toString() {
let e = [];
for (let t = 0; t < this.buffer.length;) e.push(this.childString(t)), t = this.buffer[t + 3];
return e.join(",");
}
childString(e) {
let t = this.buffer[e], n = this.buffer[e + 3], r = this.set.types[t], i = r.name;
if (/\W/.test(i) && !r.isError && (i = JSON.stringify(i)), e += 4, n == e) return i;
let a = [];
for (; e < n;) a.push(this.childString(e)), e = this.buffer[e + 3];
return i + "(" + a.join(",") + ")";
}
findChild(e, t, n, r, i) {
let { buffer: a } = this, o = -1;
for (let s = e; s != t && !(checkSide(i, r, a[s + 1], a[s + 2]) && (o = s, n > 0)); s = a[s + 3]);
return o;
}
slice(e, t, n) {
let r = this.buffer, i = new Uint16Array(t - e), a = 0;
for (let o = e, s = 0; o < t;) {
i[s++] = r[o++], i[s++] = r[o++] - n;
let t = i[s++] = r[o++] - n;
i[s++] = r[o++] - e, a = Math.max(a, t);
}
return new TreeBuffer(i, a, this.set);
}
};
function checkSide(e, t, n, r) {
switch (e) {
case -2: return n < t;
case -1: return r >= t && n < t;
case 0: return n < t && r > t;
case 1: return n <= t && r > t;
case 2: return r > t;
case 4: return !0;
}
}
function resolveNode(e, t, n, r) {
for (; e.from == e.to || (n < 1 ? e.from >= t : e.from > t) || (n > -1 ? e.to <= t : e.to < t);) {
let t = !r && e instanceof d && e.index < 0 ? null : e.parent;
if (!t) return e;
e = t;
}
let i = r ? 0 : s.IgnoreOverlays;
if (r) for (let r = e, a = r.parent; a; r = a, a = r.parent) r instanceof d && r.index < 0 && a.enter(t, n, i)?.from != r.from && (e = a);
for (;;) {
let r = e.enter(t, n, i);
if (!r) return e;
e = r;
}
}
var BaseNode = class {
cursor(e = 0) {
return new TreeCursor(this, e);
}
getChild(e, t = null, n = null) {
let r = getChildren(this, e, t, n);
return r.length ? r[0] : null;
}
getChildren(e, t = null, n = null) {
return getChildren(this, e, t, n);
}
resolve(e, t = 0) {
return resolveNode(this, e, t, !1);
}
resolveInner(e, t = 0) {
return resolveNode(this, e, t, !0);
}
matchContext(e) {
return matchNodeContext(this.parent, e);
}
enterUnfinishedNodesBefore(e) {
let t = this.childBefore(e), n = this;
for (; t;) {
let e = t.lastChild;
if (!e || e.to != t.to) break;
e.type.isError && e.from == e.to ? (n = t, t = e.prevSibling) : t = e;
}
return n;
}
get node() {
return this;
}
get next() {
return this.parent;
}
}, d = class TreeNode extends BaseNode {
constructor(e, t, n, r) {
super(), this._tree = e, this.from = t, this.index = n, this._parent = r;
}
get type() {
return this._tree.type;
}
get name() {
return this._tree.type.name;
}
get to() {
return this.from + this._tree.length;
}
nextChild(e, t, n, r, i = 0) {
for (let a = this;;) {
for (let { children: o, positions: l } = a._tree, d = t > 0 ? o.length : -1; e != d; e += t) {
let d = o[e], p = l[e] + a.from, m;
if (!(!(i & s.EnterBracketed && d instanceof c && (m = MountedTree.get(d)) && !m.overlay && m.bracketed && n >= p && n <= p + d.length) && !checkSide(r, n, p, p + d.length))) {
if (d instanceof u) {
if (i & s.ExcludeBuffers) continue;
let o = d.findChild(0, d.buffer.length, t, n - p, r);
if (o > -1) return new f(new BufferContext(a, d, e, p), null, o);
} else if (i & s.IncludeAnonymous || !d.type.isAnonymous || hasChild(d)) {
let o;
if (!(i & s.IgnoreMounts) && (o = MountedTree.get(d)) && !o.overlay) return new TreeNode(o.tree, p, e, a);
let c = new TreeNode(d, p, e, a);
return i & s.IncludeAnonymous || !c.type.isAnonymous ? c : c.nextChild(t < 0 ? d.children.length - 1 : 0, t, n, r, i);
}
}
}
if (i & s.IncludeAnonymous || !a.type.isAnonymous || (e = a.index >= 0 ? a.index + t : t < 0 ? -1 : a._parent._tree.children.length, a = a._parent, !a)) return null;
}
}
get firstChild() {
return this.nextChild(0, 1, 0, 4);
}
get lastChild() {
return this.nextChild(this._tree.children.length - 1, -1, 0, 4);
}
childAfter(e) {
return this.nextChild(0, 1, e, 2);
}
childBefore(e) {
return this.nextChild(this._tree.children.length - 1, -1, e, -2);
}
prop(e) {
return this._tree.prop(e);
}
enter(e, t, n = 0) {
let r;
if (!(n & s.IgnoreOverlays) && (r = MountedTree.get(this._tree)) && r.overlay) {
let i = e - this.from, a = n & s.EnterBracketed && r.bracketed;
for (let { from: e, to: n } of r.overlay) if ((t > 0 || a ? e <= i : e < i) && (t < 0 || a ? n >= i : n > i)) return new TreeNode(r.tree, r.overlay[0].from + this.from, -1, this);
}
return this.nextChild(0, 1, e, t, n);
}
nextSignificantParent() {
let e = this;
for (; e.type.isAnonymous && e._parent;) e = e._parent;
return e;
}
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) : null;
}
get prevSibling() {
return this._parent && this.index >= 0 ? this._parent.nextChild(this.index - 1, -1, 0, 4) : null;
}
get tree() {
return this._tree;
}
toTree() {
return this._tree;
}
toString() {
return this._tree.toString();
}
};
function getChildren(e, t, n, r) {
let i = e.cursor(), a = [];
if (!i.firstChild()) return a;
if (n != null) {
for (let e = !1; !e;) if (e = i.type.is(n), !i.nextSibling()) return a;
}
for (;;) {
if (r != null && i.type.is(r)) return a;
if (i.type.is(t) && a.push(i.node), !i.nextSibling()) return r == null ? a : [];
}
}
function matchNodeContext(e, t, n = t.length - 1) {
for (let r = e; n >= 0; r = r.parent) {
if (!r) return !1;
if (!r.type.isAnonymous) {
if (t[n] && t[n] != r.name) return !1;
n--;
}
}
return !0;
}
var BufferContext = class {
constructor(e, t, n, r) {
this.parent = e, this.buffer = t, this.index = n, this.start = r;
}
}, f = 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(e, t, n) {
super(), this.context = e, this._parent = t, this.index = n, this.type = e.buffer.set.types[e.buffer.buffer[n]];
}
child(e, t, n) {
let { buffer: r } = this.context, i = r.findChild(this.index + 4, r.buffer[this.index + 3], e, t - this.context.start, n);
return i < 0 ? null : new BufferNode(this.context, this, i);
}
get firstChild() {
return this.child(1, 0, 4);
}
get lastChild() {
return this.child(-1, 0, 4);
}
childAfter(e) {
return this.child(1, e, 2);
}
childBefore(e) {
return this.child(-1, e, -2);
}
prop(e) {
return this.type.prop(e);
}
enter(e, t, n = 0) {
if (n & s.ExcludeBuffers) return null;
let { buffer: r } = this.context, i = r.findChild(this.index + 4, r.buffer[this.index + 3], t > 0 ? 1 : -1, e - this.context.start, t);
return i < 0 ? null : new BufferNode(this.context, this, i);
}
get parent() {
return this._parent || this.context.parent.nextSignificantParent();
}
externalSibling(e) {
return this._parent ? null : this.context.parent.nextChild(this.context.index + e, e, 0, 4);
}
get nextSibling() {
let { buffer: e } = this.context, t = e.buffer[this.index + 3];
return t < (this._parent ? e.buffer[this._parent.index + 3] : e.buffer.length) ? new BufferNode(this.context, this._parent, t) : this.externalSibling(1);
}
get prevSibling() {
let { buffer: e } = this.context, t = this._parent ? this._parent.index + 4 : 0;
return this.index == t ? this.externalSibling(-1) : new BufferNode(this.context, this._parent, e.findChild(t, this.index, -1, 0, 4));
}
get tree() {
return null;
}
toTree() {
let e = [], t = [], { buffer: n } = this.context, r = this.index + 4, i = n.buffer[this.index + 3];
if (i > r) {
let a = n.buffer[this.index + 1];
e.push(n.slice(r, i, a)), t.push(0);
}
return new c(this.type, e, t, this.to - this.from);
}
toString() {
return this.context.buffer.childString(this.index);
}
};
function iterStack(e) {
if (!e.length) return null;
let t = 0, n = e[0];
for (let r = 1; r < e.length; r++) {
let i = e[r];
(i.from > n.from || i.to < n.to) && (n = i, t = r);
}
let r = n instanceof d && n.index < 0 ? null : n.parent, i = e.slice();
return r ? i[t] = r : i.splice(t, 1), new StackIterator(i, n);
}
var StackIterator = class {
constructor(e, t) {
this.heads = e, this.node = t;
}
get next() {
return iterStack(this.heads);
}
};
function stackIterator(e, t, n) {
let r = e.resolveInner(t, n), i = null;
for (let e = r instanceof d ? r : r.context.parent; e; e = e.parent) if (e.index < 0) {
let a = e.parent;
(i ||= [r]).push(a.resolve(t, n)), e = a;
} else {
let a = MountedTree.get(e.tree);
if (a && a.overlay && a.overlay[0].from <= t && a.overlay[a.overlay.length - 1].to >= t) {
let o = new d(a.tree, a.overlay[0].from + e.from, -1, e);
(i ||= [r]).push(resolveNode(o, t, n, !1));
}
}
return i ? iterStack(i) : r;
}
var TreeCursor = class {
get name() {
return this.type.name;
}
constructor(e, t = 0) {
if (this.buffer = null, this.stack = [], this.index = 0, this.bufferNode = null, this.mode = t & ~s.EnterBracketed, e instanceof d) this.yieldNode(e);
else {
this._tree = e.context.parent, this.buffer = e.context;
for (let t = e._parent; t; t = t._parent) this.stack.unshift(t.index);
this.bufferNode = e, this.yieldBuf(e.index);
}
}
yieldNode(e) {
return e ? (this._tree = e, this.type = e.type, this.from = e.from, this.to = e.to, !0) : !1;
}
yieldBuf(e, t) {
this.index = e;
let { start: n, buffer: r } = this.buffer;
return this.type = t || r.set.types[r.buffer[e]], this.from = n + r.buffer[e + 1], this.to = n + r.buffer[e + 2], !0;
}
yield(e) {
return e ? e instanceof d ? (this.buffer = null, this.yieldNode(e)) : (this.buffer = e.context, this.yieldBuf(e.index, e.type)) : !1;
}
toString() {
return this.buffer ? this.buffer.buffer.childString(this.index) : this._tree.toString();
}
enterChild(e, t, n) {
if (!this.buffer) return this.yield(this._tree.nextChild(e < 0 ? this._tree._tree.children.length - 1 : 0, e, t, n, this.mode));
let { buffer: r } = this.buffer, i = r.findChild(this.index + 4, r.buffer[this.index + 3], e, t - this.buffer.start, n);
return i < 0 ? !1 : (this.stack.push(this.index), this.yieldBuf(i));
}
firstChild() {
return this.enterChild(1, 0, 4);
}
lastChild() {
return this.enterChild(-1, 0, 4);
}
childAfter(e) {
return this.enterChild(1, e, 2);
}
childBefore(e) {
return this.enterChild(-1, e, -2);
}
enter(e, t, n = this.mode) {
return this.buffer ? n & s.ExcludeBuffers ? !1 : this.enterChild(1, e, t) : this.yield(this._tree.enter(e, t, n));
}
parent() {
if (!this.buffer) return this.yieldNode(this.mode & s.IncludeAnonymous ? this._tree._parent : this._tree.parent);
if (this.stack.length) return this.yieldBuf(this.stack.pop());
let e = this.mode & s.IncludeAnonymous ? this.buffer.parent : this.buffer.parent.nextSignificantParent();
return this.buffer = null, this.yieldNode(e);
}
sibling(e) {
if (!this.buffer) return this._tree._parent ? this.yield(this._tree.index < 0 ? null : this._tree._parent.nextChild(this._tree.index + e, e, 0, 4, this.mode)) : !1;
let { buffer: t } = this.buffer, n = this.stack.length - 1;
if (e < 0) {
let e = n < 0 ? 0 : this.stack[n] + 4;
if (this.index != e) return this.yieldBuf(t.findChild(e, this.index, -1, 0, 4));
} else {
let e = t.buffer[this.index + 3];
if (e < (n < 0 ? t.buffer.length : t.buffer[this.stack[n] + 3])) return this.yieldBuf(e);
}
return n < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + e, e, 0, 4, this.mode)) : !1;
}
nextSibling() {
return this.sibling(1);
}
prevSibling() {
return this.sibling(-1);
}
atLastNode(e) {
let t, n, { buffer: r } = this;
if (r) {
if (e > 0) {
if (this.index < r.buffer.buffer.length) return !1;
} else for (let e = 0; e < this.index; e++) if (r.buffer.buffer[e + 3] < this.index) return !1;
({index: t, parent: n} = r);
} else ({index: t, _parent: n} = this._tree);
for (; n; {index: t, _parent: n} = n) if (t > -1) for (let r = t + e, i = e < 0 ? -1 : n._tree.children.length; r != i; r += e) {
let e = n._tree.children[r];
if (this.mode & s.IncludeAnonymous || e instanceof u || !e.type.isAnonymous || hasChild(e)) return !1;
}
return !0;
}
move(e, t) {
if (t && this.enterChild(e, 0, 4)) return !0;
for (;;) {
if (this.sibling(e)) return !0;
if (this.atLastNode(e) || !this.parent()) return !1;
}
}
next(e = !0) {
return this.move(1, e);
}
prev(e = !0) {
return this.move(-1, e);
}
moveTo(e, t = 0) {
for (; (this.from == this.to || (t < 1 ? this.from >= e : this.from > e) || (t > -1 ? this.to <= e : this.to < e)) && this.parent(););
for (; this.enterChild(1, e, t););
return this;
}
get node() {
if (!this.buffer) return this._tree;
let e = this.bufferNode, t = null, n = 0;
if (e && e.context == this.buffer) scan: for (let r = this.index, i = this.stack.length; i >= 0;) {
for (let a = e; a; a = a._parent) if (a.index == r) {
if (r == this.index) return a;
t = a, n = i + 1;
break scan;
}
r = this.stack[--i];
}
for (let e = n; e < this.stack.length; e++) t = new f(this.buffer, t, this.stack[e]);
return this.bufferNode = new f(this.buffer, t, this.index);
}
get tree() {
return this.buffer ? null : this._tree._tree;
}
iterate(e, t) {
for (let n = 0;;) {
let r = !1;
if (this.type.isAnonymous || e(this) !== !1) {
if (this.firstChild()) {
n++;
continue;
}
this.type.isAnonymous || (r = !0);
}
for (;;) {
if (r && t && t(this), r = this.type.isAnonymous, !n) return;
if (this.nextSibling()) break;
this.parent(), n--, r = !0;
}
}
}
matchContext(e) {
if (!this.buffer) return matchNodeContext(this.node.parent, e);
let { buffer: t } = this.buffer, { types: n } = t.set;
for (let r = e.length - 1, i = this.stack.length - 1; r >= 0; i--) {
if (i < 0) return matchNodeContext(this._tree, e, r);
let a = n[t.buffer[this.stack[i]]];
if (!a.isAnonymous) {
if (e[r] && e[r] != a.name) return !1;
r--;
}
}
return !0;
}
};
function hasChild(e) {
return e.children.some((e) => e instanceof u || !e.type.isAnonymous || hasChild(e));
}
function buildTree(t) {
let { buffer: n, nodeSet: r, maxBufferLength: i = e, reused: a = [], minRepeatType: o = r.types.length } = t, s = Array.isArray(n) ? new l(n, n.length) : n, d = r.types, f = 0, p = 0;
function takeNode(e, t, n, c, l, m) {
let { id: h, start: g, end: _, size: v } = s, y = p, b = f;
if (v < 0) if (s.next(), v == -1) {
let t = a[h];
n.push(t), c.push(g - e);
return;
} else if (v == -3) {
f = h;
return;
} else if (v == -4) {
p = h;
return;
} else throw RangeError(`Unrecognized record size: ${v}`);
let x = d[h], S, C, w = g - e;
if (_ - g <= i && (C = findBufferSize(s.pos - t, l))) {
let t = new Uint16Array(C.size - C.skip), n = s.pos - C.size, i = t.length;
for (; s.pos > n;) i = copyToBuffer(C.start, t, i);
S = new u(t, _ - C.start, r), w = C.start - e;
} else {
let e = s.pos - v;
s.next();
let t = [], n = [], r = h >= o ? h : -1, a = 0, c = _;
for (; s.pos > e;) r >= 0 && s.id == r && s.size >= 0 ? (s.end <= c - i && (makeRepeatLeaf(t, n, g, a, s.end, c, r, y, b), a = t.length, c = s.end), s.next()) : m > 2500 ? takeFlatNode(g, e, t, n) : takeNode(g, e, t, n, r, m + 1);
if (r >= 0 && a > 0 && a < t.length && makeRepeatLeaf(t, n, g, a, g, c, r, y, b), t.reverse(), n.reverse(), r > -1 && a > 0) {
let e = makeBalanced(x, b);
S = balanceRange(x, t, n, 0, t.length, 0, _ - g, e, e);
} else S = makeTree(x, t, n, _ - g, y - _, b);
}
n.push(S), c.push(w);
}
function takeFlatNode(e, t, n, a) {
let o = [], c = 0, l = -1;
for (; s.pos > t;) {
let { id: e, start: t, end: n, size: r } = s;
if (r > 4) s.next();
else if (l > -1 && t < l) break;
else l < 0 && (l = n - i), o.push(e, t, n), c++, s.next();
}
if (c) {
let t = new Uint16Array(c * 4), i = o[o.length - 2];
for (let e = o.length - 3, n = 0; e >= 0; e -= 3) t[n++] = o[e], t[n++] = o[e + 1] - i, t[n++] = o[e + 2] - i, t[n++] = n;
n.push(new u(t, o[2] - i, r)), a.push(i - e);
}
}
function makeBalanced(e, t) {
return (n, r, i) => {
let a = 0, o = n.length - 1, s, l;
if (o >= 0 && (s = n[o]) instanceof c) {
if (!o && s.type == e && s.length == i) return s;
(l = s.prop(NodeProp.lookAhead)) && (a = r[o] + s.length + l);
}
return makeTree(e, n, r, i, a, t);
};
}
function makeRepeatLeaf(e, t, n, i, a, o, s, c, l) {
let u = [], d = [];
for (; e.length > i;) u.push(e.pop()), d.push(t.pop() + n - a);
e.push(makeTree(r.types[s], u, d, o - a, c - o, l)), t.push(a - n);
}
function makeTree(e, t, n, r, i, a, o) {
if (a) {
let e = [NodeProp.contextHash, a];
o = o ? [e].concat(o) : [e];
}
if (i > 25) {
let e = [NodeProp.lookAhead, i];
o = o ? [e].concat(o) : [e];
}
return new c(e, t, n, r, o);
}
function findBufferSize(e, t) {
let n = s.fork(), r = 0, a = 0, c = 0, l = n.end - i, u = {
size: 0,
start: 0,
skip: 0
};
scan: for (let i = n.pos - e; n.pos > i;) {
let e = n.size;
if (n.id == t && e >= 0) {
u.size = r, u.start = a, u.skip = c, c += 4, r += 4, n.next();
continue;
}
let s = n.pos - e;
if (e < 0 || s < i || n.start < l) break;
let d = n.id >= o ? 4 : 0, f = n.start;
for (n.next(); n.pos > s;) {
if (n.size < 0) if (n.size == -3 || n.size == -4) d += 4;
else break scan;
else n.id >= o && (d += 4);
n.next();
}
a = f, r += e, c += d;
}
return (t < 0 || r == e) && (u.size = r, u.start = a, u.skip = c), u.size > 4 ? u : void 0;
}
function copyToBuffer(e, t, n) {
let { id: r, start: i, end: a, size: c } = s;
if (s.next(), c >= 0 && r < o) {
let o = n;
if (c > 4) {
let r = s.pos - (c - 4);
for (; s.pos > r;) n = copyToBuffer(e, t, n);
}
t[--n] = o, t[--n] = a - e, t[--n] = i - e, t[--n] = r;
} else c == -3 ? f = r : c == -4 && (p = r);
return n;
}
let m = [], h = [];
for (; s.pos > 0;) takeNode(t.start || 0, t.bufferStart || 0, m, h, -1, 0);
let g = t.length ?? (m.length ? h[0] + m[0].length : 0);
return new c(d[t.topID], m.reverse(), h.reverse(), g);
}
var p = /* @__PURE__ */ new WeakMap();
function nodeSize(e, t) {
if (!e.isAnonymous || t instanceof u || t.type != e) return 1;
let n = p.get(t);
if (n == null) {
n = 1;
for (let r of t.children) {
if (r.type != e || !(r instanceof c)) {
n = 1;
break;
}
n += nodeSize(e, r);
}
p.set(t, n);
}
return n;
}
function balanceRange(e, t, n, r, i, a, o, s, c) {
let l = 0;
for (let n = r; n < i; n++) l += nodeSize(e, t[n]);
let u = Math.ceil(l * 1.5 / 8), d = [], f = [];
function divide(t, n, r, i, o) {
for (let s = r; s < i;) {
let r = s, l = n[s], p = nodeSize(e, t[s]);
for (s++; s < i; s++) {
let n = nodeSize(e, t[s]);
if (p + n >= u) break;
p += n;
}
if (s == r + 1) {
if (p > u) {
let e = t[r];
divide(e.children, e.positions, 0, e.children.length, n[r] + o);
continue;
}
d.push(t[r]);
} else {
let i = n[s - 1] + t[s - 1].length - l;
d.push(balanceRange(e, t, n, r, s, l, i, null, c));
}
f.push(l + o - a);
}
}
return divide(t, n, r, i, 0), (s || c)(d, f, o);
}
var Parser = class {
startParse(e, t, n) {
return typeof e == "string" && (e = new StringInput(e)), n = n ? n.length ? n.map((e) => new Range(e.from, e.to)) : [new Range(0, 0)] : [new Range(0, e.length)], this.createParse(e, t || [], n);
}
parse(e, t, n) {
let r = this.startParse(e, t, n);
for (;;) {
let e = r.advance();
if (e) return e;
}
}
}, StringInput = class {
constructor(e) {
this.string = e;
}
get length() {
return this.string.length;
}
chunk(e) {
return this.string.slice(e);
}
get lineChunks() {
return !1;
}
read(e, t) {
return this.string.slice(e, t);
}
};
new NodeProp({ perNode: !0 });
//#endregion
//#region ../../node_modules/@lezer/highlight/dist/index.js
var m = 0, h = class Tag {
constructor(e, t, n, r) {
this.name = e, this.set = t, this.base = n, this.modified = r, this.id = m++;
}
toString() {
let { name: e } = this;
for (let t of this.modified) t.name && (e = `${t.name}(${e})`);
return e;
}
static define(e, t) {
let n = typeof e == "string" ? e : "?";
if (e instanceof Tag && (t = e), t?.base) throw Error("Can not derive from a modified tag");
let r = new Tag(n, [], null, []);
if (r.set.push(r), t) for (let e of t.set) r.set.push(e);
return r;
}
static defineModifier(e) {
let t = new _(e);
return (e) => e.modified.indexOf(t) > -1 ? e : _.get(e.base || e, e.modified.concat(t).sort((e, t) => e.id - t.id));
}
}, g = 0, _ = class Modifier {
constructor(e) {
this.name = e, this.instances = [], this.id = g++;
}
static get(e, t) {
if (!t.length) return e;
let n = t[0].instances.find((n) => n.base == e && sameArray(t, n.modified));
if (n) return n;
let r = [], i = new h(e.name, r, e, t);
for (let e of t) e.instances.push(i);
let a = powerSet(t);
for (let t of e.set) if (!t.modified.length) for (let e of a) r.push(Modifier.get(t, e));
return i;
}
};
function sameArray(e, t) {
return e.length == t.length && e.every((e, n) => e == t[n]);
}
function powerSet(e) {
let t = [[]];
for (let n = 0; n < e.length; n++) for (let r = 0, i = t.length; r < i; r++) t.push(t[r].concat(e[n]));
return t.sort((e, t) => t.length - e.length);
}
function styleTags(e) {
let t = Object.create(null);
for (let n in e) {
let r = e[n];
Array.isArray(r) || (r = [r]);
for (let e of n.split(" ")) if (e) {
let n = [], i = 2, a = e;
for (let t = 0;;) {
if (a == "..." && t > 0 && t + 3 == e.length) {
i = 1;
break;
}
let r = /^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(a);
if (!r) throw RangeError("Invalid path: " + e);
if (n.push(r[0] == "*" ? "" : r[0][0] == "\"" ? JSON.parse(r[0]) : r[0]), t += r[0].length, t == e.length) break;
let o = e[t++];
if (t == e.length && o == "!") {
i = 0;
break;
}
if (o != "/") throw RangeError("Invalid path: " + e);
a = e.slice(t);
}
let o = n.length - 1, s = n[o];
if (!s) throw RangeError("Invalid path: " + e);
t[s] = new Rule(r, i, o > 0 ? n.slice(0, o) : null).sort(t[s]);
}
}
return v.add(t);
}
var v = new NodeProp({ combine(e, t) {
let n, r, i;
for (; e || t;) {
if (!e || t && e.depth >= t.depth ? (i = t, t = t.next) : (i = e, e = e.next), n && n.mode == i.mode && !i.context && !n.context) continue;
let a = new Rule(i.tags, i.mode, i.context);
n ? n.next = a : r = a, n = a;
}
return r;
} }), Rule = class {
constructor(e, t, n, r) {
this.tags = e, this.mode = t, this.context = n, this.next = r;
}
get opaque() {
return this.mode == 0;
}
get inherit() {
return this.mode == 1;
}
sort(e) {
return !e || e.depth < this.depth ? (this.next = e, this) : (e.next = this.sort(e.next), e);
}
get depth() {
return this.context ? this.context.length : 0;
}
};
Rule.empty = new Rule([], 2, null);
function tagHighlighter(e, t) {
let n = Object.create(null);
for (let t of e) if (!Array.isArray(t.tag)) n[t.tag.id] = t.class;
else for (let e of t.tag) n[e.id] = t.class;
let { scope: r, all: i = null } = t || {};
return {
style: (e) => {
let t = i;
for (let r of e) for (let e of r.set) {
let r = n[e.id];
if (r) {
t = t ? t + " " + r : r;
break;
}
}
return t;
},
scope: r
};
}
function highlightTags(e, t) {
let n = null;
for (let r of e) {
let e = r.style(t);
e && (n = n ? n + " " + e : e);
}
return n;
}
function highlightTree(e, t, n, r = 0, i = e.length) {
let a = new HighlightBuilder(r, Array.isArray(t) ? t : [t], n);
a.highlightRange(e.cursor(), r, i, "", a.highlighters), a.flush(i);
}
function highlightCode(e, t, n, r, i, a = 0, o = e.length) {
let s = a;
function writeTo(t, n) {
if (!(t <= s)) {
for (let a = e.slice(s, t), o = 0;;) {
let e = a.indexOf("\n", o), t = e < 0 ? a.length : e;
if (t > o && r(a.slice(o, t), n), e < 0) break;
i(), o = e + 1;
}
s = t;
}
}
highlightTree(t, n, (e, t, n) => {
writeTo(e, ""), writeTo(t, n);
}, a, o), writeTo(o, "");
}
var HighlightBuilder = class {
constructor(e, t, n) {
this.at = e, this.highlighters = t, this.span = n, this.class = "";
}
startSpan(e, t) {
t != this.class && (this.flush(e), e > this.at && (this.at = e), this.class = t);
}
flush(e) {
e > this.at && this.class && this.span(this.at, e, this.class);
}
highlightRange(e, t, n, r, i) {
let { type: a, from: o, to: s } = e;
if (o >= n || s <= t) return;
a.isTop && (i = this.highlighters.filter((e) => !e.scope || e.scope(a)));
let c = r, l = getStyleTags(e) || Rule.empty, u = highlightTags(i, l.tags);
if (u && (c && (c += " "), c += u, l.mode == 1 && (r += (r ? " " : "") + u)), this.startSpan(Math.max(t, o), c), l.opaque) return;
let d = e.tree && e.tree.prop(NodeProp.mounted);
if (d && d.overlay) {
let a = e.node.enter(d.overlay[0].from + o, 1), l = this.highlighters.filter((e) => !e.scope || e.scope(d.tree.type)), u = e.firstChild();
for (let f = 0, p = o;; f++) {
let m = f < d.overlay.length ? d.overlay[f] : null, h = m ? m.from + o : s, g = Math.max(t, p), _ = Math.min(n, h);
if (g < _ && u) for (; e.from < _ && (this.highlightRange(e, g, _, r, i), this.startSpan(Math.min(_, e.to), c), !(e.to >= h || !e.nextSibling())););
if (!m || h > n) break;
p = m.to + o, p > t && (this.highlightRange(a.cursor(), Math.max(t, m.from + o), Math.min(n, p), "", l), this.startSpan(Math.min(n, p), c));
}
u && e.parent();
} else if (e.firstChild()) {
d && (r = "");
do {
if (e.to <= t) continue;
if (e.from >= n) break;
this.highlightRange(e, t, n, r, i), this.startSpan(Math.min(n, e.to), c);
} while (e.nextSibling());
e.parent();
}
}
};
function getStyleTags(e) {
let t = e.type.prop(v);
for (; t && t.context && !e.matchContext(t.context);) t = t.next;
return t || null;
}
var y = h.define, b = y(), x = y(), S = y(x), C = y(x), w = y(), T = y(w), E = y(w), D = y(), O = y(D), k = y(), A = y(), j = y(), M = y(j), N = y(), P = {
comment: b,
lineComment: y(b),
blockComment: y(b),
docComment: y(b),
name: x,
variableName: y(x),
typeName: S,
tagName: y(S),
propertyName: C,
attributeName: y(C),
className: y(x),
labelName: y(x),
namespace: y(x),
macroName: y(x),
literal: w,
string: T,
docString: y(T),
character: y(T),
attributeValue: y(T),
number: E,
integer: y(E),
float: y(E),
bool: y(w),
regexp: y(w),
escape: y(w),
color: y(w),
url: y(w),
keyword: k,
self: y(k),
null: y(k),
atom: y(k),
unit: y(k),
modifier: y(k),
operatorKeyword: y(k),
controlKeyword: y(k),
definitionKeyword: y(k),
moduleKeyword: y(k),
operator: A,
derefOperator: y(A),
arithmeticOperator: y(A),
logicOperator: y(A),
bitwiseOperator: y(A),
compareOperator: y(A),
updateOperator: y(A),
definitionOperator: y(A),
typeOperator: y(A),
controlOperator: y(A),
punctuation: j,
separator: y(j),
bracket: M,
angleBracket: y(M),
squareBracket: y(M),
paren: y(M),
brace: y(M),
content: D,
heading: O,
heading1: y(O),
heading2: y(O),
heading3: y(O),
heading4: y(O),
heading5: y(O),
heading6: y(O),
contentSeparator: y(D),
list: y(D),
quote: y(D),
emphasis: y(D),
strong: y(D),
link: y(D),
monospace: y(D),
strikethrough: y(D),
inserted: y(),
deleted: y(),
changed: y(),
invalid: y(),
meta: N,
documentMeta: y(N),
annotation: y(N),
processingInstruction: y(N),
definition: h.defineModifier("definition"),
constant: h.defineModifier("constant"),
function: h.defineModifier("function"),
standard: h.defineModifier("standard"),
local: h.defineModifier("local"),
special: h.defineModifier("special")
};
for (let e in P) {
let t = P[e];
t instanceof h && (t.name = e);
}
tagHighlighter([
{
tag: P.link,
class: "tok-link"
},
{
tag: P.heading,
class: "tok-heading"
},
{
tag: P.emphasis,
class: "tok-emphasis"
},
{
tag: P.strong,
class: "tok-strong"
},
{
tag: P.keyword,
class: "tok-keyword"
},
{
tag: P.atom,
class: "tok-atom"
},
{
tag: P.bool,
class: "tok-bool"
},
{
tag: P.url,
class: "tok-url"
},
{
tag: P.labelName,
class: "tok-labelName"
},
{
tag: P.inserted,
class: "tok-inserted"
},
{
tag: P.deleted,
class: "tok-deleted"
},
{
tag: P.literal,
class: "tok-literal"
},
{
tag: P.string,
class: "tok-string"
},
{
tag: P.number,
class: "tok-number"
},
{
tag: [
P.regexp,
P.escape,
P.special(P.string)
],
class: "tok-string2"
},
{
tag: P.variableName,
class: "tok-variableName"
},
{
tag: P.local(P.variableName),
class: "tok-variableName tok-local"
},
{
tag: P.definition(P.variableName),
class: "tok-variableName tok-definition"
},
{
tag: P.special(P.variableName),
class: "tok-variableName2"
},
{
tag: P.definition(P.propertyName),
class: "tok-propertyName tok-definition"
},
{
tag: P.typeName,
class: "tok-typeName"
},
{
tag: P.namespace,
class: "tok-namespace"
},
{
tag: P.className,
class: "tok-className"
},
{
tag: P.macroName,
class: "tok-macroName"
},
{
tag: P.propertyName,
class: "tok-propertyName"
},
{
tag: P.operator,
class: "tok-operator"
},
{
tag: P.comment,
class: "tok-comment"
},
{
tag: P.meta,
class: "tok-meta"
},
{
tag: P.invalid,
class: "tok-invalid"
},
{
tag: P.punctuation,
class: "tok-punctuation"
}
]);
//#endregion
export { P as a, NodeProp as c, Parser as d, c as f, tagHighlighter as i, i as l, highlightCode as n, e as o, styleTags as r, s, h as t, r as u };
//# sourceMappingURL=dist-CecFOdLa.js.map