py_sandpack
Version:
PySandpack is a React library designed to provide a sandbox environment for executing Python code directly in the browser. It is ideal for educational purposes, quick experiments, or running Python scripts without requiring a local Python installation.
1,520 lines (1,514 loc) • 738 kB
JavaScript
import * as rp from "react";
import N, { useState as br, useEffect as di, forwardRef as op, useRef as lp, useImperativeHandle as ap } from "react";
function hp(n) {
return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
}
function cp(n) {
if (n.__esModule) return n;
var e = n.default;
if (typeof e == "function") {
var t = function i() {
return this instanceof i ? Reflect.construct(e, arguments, this.constructor) : e.apply(this, arguments);
};
t.prototype = e.prototype;
} else t = {};
return Object.defineProperty(t, "__esModule", { value: !0 }), Object.keys(n).forEach(function(i) {
var s = Object.getOwnPropertyDescriptor(n, i);
Object.defineProperty(t, i, s.get ? s : {
enumerable: !0,
get: function() {
return n[i];
}
});
}), t;
}
var zn = { exports: {} }, _i = {};
const hc = /* @__PURE__ */ cp(rp);
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Zl;
function fp() {
if (Zl) return _i;
Zl = 1;
var n = hc, e = Symbol.for("react.element"), t = Symbol.for("react.fragment"), i = Object.prototype.hasOwnProperty, s = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, r = { key: !0, ref: !0, __self: !0, __source: !0 };
function o(l, a, h) {
var c, f = {}, u = null, d = null;
h !== void 0 && (u = "" + h), a.key !== void 0 && (u = "" + a.key), a.ref !== void 0 && (d = a.ref);
for (c in a) i.call(a, c) && !r.hasOwnProperty(c) && (f[c] = a[c]);
if (l && l.defaultProps) for (c in a = l.defaultProps, a) f[c] === void 0 && (f[c] = a[c]);
return { $$typeof: e, type: l, key: u, ref: d, props: f, _owner: s.current };
}
return _i.Fragment = t, _i.jsx = o, _i.jsxs = o, _i;
}
var Ni = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Kl;
function up() {
return Kl || (Kl = 1, process.env.NODE_ENV !== "production" && function() {
var n = hc, e = Symbol.for("react.element"), t = Symbol.for("react.portal"), i = Symbol.for("react.fragment"), s = Symbol.for("react.strict_mode"), r = Symbol.for("react.profiler"), o = Symbol.for("react.provider"), l = Symbol.for("react.context"), a = Symbol.for("react.forward_ref"), h = Symbol.for("react.suspense"), c = Symbol.for("react.suspense_list"), f = Symbol.for("react.memo"), u = Symbol.for("react.lazy"), d = Symbol.for("react.offscreen"), p = Symbol.iterator, O = "@@iterator";
function m(g) {
if (g === null || typeof g != "object")
return null;
var A = p && g[p] || g[O];
return typeof A == "function" ? A : null;
}
var y = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function S(g) {
{
for (var A = arguments.length, E = new Array(A > 1 ? A - 1 : 0), z = 1; z < A; z++)
E[z - 1] = arguments[z];
C("error", g, E);
}
}
function C(g, A, E) {
{
var z = y.ReactDebugCurrentFrame, K = z.getStackAddendum();
K !== "" && (A += "%s", E = E.concat([K]));
var ee = E.map(function(G) {
return String(G);
});
ee.unshift("Warning: " + A), Function.prototype.apply.call(console[g], console, ee);
}
}
var k = !1, w = !1, b = !1, v = !1, Q = !1, L;
L = Symbol.for("react.module.reference");
function j(g) {
return !!(typeof g == "string" || typeof g == "function" || g === i || g === r || Q || g === s || g === h || g === c || v || g === d || k || w || b || typeof g == "object" && g !== null && (g.$$typeof === u || g.$$typeof === f || g.$$typeof === o || g.$$typeof === l || g.$$typeof === a || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
g.$$typeof === L || g.getModuleId !== void 0));
}
function W(g, A, E) {
var z = g.displayName;
if (z)
return z;
var K = A.displayName || A.name || "";
return K !== "" ? E + "(" + K + ")" : E;
}
function B(g) {
return g.displayName || "Context";
}
function _(g) {
if (g == null)
return null;
if (typeof g.tag == "number" && S("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof g == "function")
return g.displayName || g.name || null;
if (typeof g == "string")
return g;
switch (g) {
case i:
return "Fragment";
case t:
return "Portal";
case r:
return "Profiler";
case s:
return "StrictMode";
case h:
return "Suspense";
case c:
return "SuspenseList";
}
if (typeof g == "object")
switch (g.$$typeof) {
case l:
var A = g;
return B(A) + ".Consumer";
case o:
var E = g;
return B(E._context) + ".Provider";
case a:
return W(g, g.render, "ForwardRef");
case f:
var z = g.displayName || null;
return z !== null ? z : _(g.type) || "Memo";
case u: {
var K = g, ee = K._payload, G = K._init;
try {
return _(G(ee));
} catch {
return null;
}
}
}
return null;
}
var V = Object.assign, H = 0, le, J, me, se, ve, Ue, Me;
function Ne() {
}
Ne.__reactDisabledLog = !0;
function vt() {
{
if (H === 0) {
le = console.log, J = console.info, me = console.warn, se = console.error, ve = console.group, Ue = console.groupCollapsed, Me = console.groupEnd;
var g = {
configurable: !0,
enumerable: !0,
value: Ne,
writable: !0
};
Object.defineProperties(console, {
info: g,
log: g,
warn: g,
error: g,
group: g,
groupCollapsed: g,
groupEnd: g
});
}
H++;
}
}
function Dt() {
{
if (H--, H === 0) {
var g = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: V({}, g, {
value: le
}),
info: V({}, g, {
value: J
}),
warn: V({}, g, {
value: me
}),
error: V({}, g, {
value: se
}),
group: V({}, g, {
value: ve
}),
groupCollapsed: V({}, g, {
value: Ue
}),
groupEnd: V({}, g, {
value: Me
})
});
}
H < 0 && S("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var qt = y.ReactCurrentDispatcher, ci;
function Bn(g, A, E) {
{
if (ci === void 0)
try {
throw Error();
} catch (K) {
var z = K.stack.trim().match(/\n( *(at )?)/);
ci = z && z[1] || "";
}
return `
` + ci + g;
}
}
var ur = !1, $n;
{
var qd = typeof WeakMap == "function" ? WeakMap : Map;
$n = new qd();
}
function Ll(g, A) {
if (!g || ur)
return "";
{
var E = $n.get(g);
if (E !== void 0)
return E;
}
var z;
ur = !0;
var K = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var ee;
ee = qt.current, qt.current = null, vt();
try {
if (A) {
var G = function() {
throw Error();
};
if (Object.defineProperty(G.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(G, []);
} catch (Be) {
z = Be;
}
Reflect.construct(g, [], G);
} else {
try {
G.call();
} catch (Be) {
z = Be;
}
g.call(G.prototype);
}
} else {
try {
throw Error();
} catch (Be) {
z = Be;
}
g();
}
} catch (Be) {
if (Be && z && typeof Be.stack == "string") {
for (var X = Be.stack.split(`
`), Ee = z.stack.split(`
`), he = X.length - 1, ue = Ee.length - 1; he >= 1 && ue >= 0 && X[he] !== Ee[ue]; )
ue--;
for (; he >= 1 && ue >= 0; he--, ue--)
if (X[he] !== Ee[ue]) {
if (he !== 1 || ue !== 1)
do
if (he--, ue--, ue < 0 || X[he] !== Ee[ue]) {
var He = `
` + X[he].replace(" at new ", " at ");
return g.displayName && He.includes("<anonymous>") && (He = He.replace("<anonymous>", g.displayName)), typeof g == "function" && $n.set(g, He), He;
}
while (he >= 1 && ue >= 0);
break;
}
}
} finally {
ur = !1, qt.current = ee, Dt(), Error.prepareStackTrace = K;
}
var ui = g ? g.displayName || g.name : "", Yt = ui ? Bn(ui) : "";
return typeof g == "function" && $n.set(g, Yt), Yt;
}
function Bd(g, A, E) {
return Ll(g, !1);
}
function $d(g) {
var A = g.prototype;
return !!(A && A.isReactComponent);
}
function Ln(g, A, E) {
if (g == null)
return "";
if (typeof g == "function")
return Ll(g, $d(g));
if (typeof g == "string")
return Bn(g);
switch (g) {
case h:
return Bn("Suspense");
case c:
return Bn("SuspenseList");
}
if (typeof g == "object")
switch (g.$$typeof) {
case a:
return Bd(g.render);
case f:
return Ln(g.type, A, E);
case u: {
var z = g, K = z._payload, ee = z._init;
try {
return Ln(ee(K), A, E);
} catch {
}
}
}
return "";
}
var zi = Object.prototype.hasOwnProperty, Wl = {}, zl = y.ReactDebugCurrentFrame;
function Wn(g) {
if (g) {
var A = g._owner, E = Ln(g.type, g._source, A ? A.type : null);
zl.setExtraStackFrame(E);
} else
zl.setExtraStackFrame(null);
}
function Ld(g, A, E, z, K) {
{
var ee = Function.call.bind(zi);
for (var G in g)
if (ee(g, G)) {
var X = void 0;
try {
if (typeof g[G] != "function") {
var Ee = Error((z || "React class") + ": " + E + " type `" + G + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof g[G] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw Ee.name = "Invariant Violation", Ee;
}
X = g[G](A, G, z, E, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (he) {
X = he;
}
X && !(X instanceof Error) && (Wn(K), S("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", z || "React class", E, G, typeof X), Wn(null)), X instanceof Error && !(X.message in Wl) && (Wl[X.message] = !0, Wn(K), S("Failed %s type: %s", E, X.message), Wn(null));
}
}
}
var Wd = Array.isArray;
function dr(g) {
return Wd(g);
}
function zd(g) {
{
var A = typeof Symbol == "function" && Symbol.toStringTag, E = A && g[Symbol.toStringTag] || g.constructor.name || "Object";
return E;
}
}
function Id(g) {
try {
return Il(g), !1;
} catch {
return !0;
}
}
function Il(g) {
return "" + g;
}
function _l(g) {
if (Id(g))
return S("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", zd(g)), Il(g);
}
var Ii = y.ReactCurrentOwner, _d = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, Nl, Vl, pr;
pr = {};
function Nd(g) {
if (zi.call(g, "ref")) {
var A = Object.getOwnPropertyDescriptor(g, "ref").get;
if (A && A.isReactWarning)
return !1;
}
return g.ref !== void 0;
}
function Vd(g) {
if (zi.call(g, "key")) {
var A = Object.getOwnPropertyDescriptor(g, "key").get;
if (A && A.isReactWarning)
return !1;
}
return g.key !== void 0;
}
function jd(g, A) {
if (typeof g.ref == "string" && Ii.current && A && Ii.current.stateNode !== A) {
var E = _(Ii.current.type);
pr[E] || (S('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', _(Ii.current.type), g.ref), pr[E] = !0);
}
}
function Fd(g, A) {
{
var E = function() {
Nl || (Nl = !0, S("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", A));
};
E.isReactWarning = !0, Object.defineProperty(g, "key", {
get: E,
configurable: !0
});
}
}
function Xd(g, A) {
{
var E = function() {
Vl || (Vl = !0, S("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", A));
};
E.isReactWarning = !0, Object.defineProperty(g, "ref", {
get: E,
configurable: !0
});
}
}
var Ud = function(g, A, E, z, K, ee, G) {
var X = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: e,
// Built-in properties that belong on the element
type: g,
key: A,
ref: E,
props: G,
// Record the component responsible for creating this element.
_owner: ee
};
return X._store = {}, Object.defineProperty(X._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(X, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: z
}), Object.defineProperty(X, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: K
}), Object.freeze && (Object.freeze(X.props), Object.freeze(X)), X;
};
function Hd(g, A, E, z, K) {
{
var ee, G = {}, X = null, Ee = null;
E !== void 0 && (_l(E), X = "" + E), Vd(A) && (_l(A.key), X = "" + A.key), Nd(A) && (Ee = A.ref, jd(A, K));
for (ee in A)
zi.call(A, ee) && !_d.hasOwnProperty(ee) && (G[ee] = A[ee]);
if (g && g.defaultProps) {
var he = g.defaultProps;
for (ee in he)
G[ee] === void 0 && (G[ee] = he[ee]);
}
if (X || Ee) {
var ue = typeof g == "function" ? g.displayName || g.name || "Unknown" : g;
X && Fd(G, ue), Ee && Xd(G, ue);
}
return Ud(g, X, Ee, K, z, Ii.current, G);
}
}
var gr = y.ReactCurrentOwner, jl = y.ReactDebugCurrentFrame;
function fi(g) {
if (g) {
var A = g._owner, E = Ln(g.type, g._source, A ? A.type : null);
jl.setExtraStackFrame(E);
} else
jl.setExtraStackFrame(null);
}
var mr;
mr = !1;
function Or(g) {
return typeof g == "object" && g !== null && g.$$typeof === e;
}
function Fl() {
{
if (gr.current) {
var g = _(gr.current.type);
if (g)
return `
Check the render method of \`` + g + "`.";
}
return "";
}
}
function Gd(g) {
return "";
}
var Xl = {};
function Yd(g) {
{
var A = Fl();
if (!A) {
var E = typeof g == "string" ? g : g.displayName || g.name;
E && (A = `
Check the top-level render call using <` + E + ">.");
}
return A;
}
}
function Ul(g, A) {
{
if (!g._store || g._store.validated || g.key != null)
return;
g._store.validated = !0;
var E = Yd(A);
if (Xl[E])
return;
Xl[E] = !0;
var z = "";
g && g._owner && g._owner !== gr.current && (z = " It was passed a child from " + _(g._owner.type) + "."), fi(g), S('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', E, z), fi(null);
}
}
function Hl(g, A) {
{
if (typeof g != "object")
return;
if (dr(g))
for (var E = 0; E < g.length; E++) {
var z = g[E];
Or(z) && Ul(z, A);
}
else if (Or(g))
g._store && (g._store.validated = !0);
else if (g) {
var K = m(g);
if (typeof K == "function" && K !== g.entries)
for (var ee = K.call(g), G; !(G = ee.next()).done; )
Or(G.value) && Ul(G.value, A);
}
}
}
function Zd(g) {
{
var A = g.type;
if (A == null || typeof A == "string")
return;
var E;
if (typeof A == "function")
E = A.propTypes;
else if (typeof A == "object" && (A.$$typeof === a || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
A.$$typeof === f))
E = A.propTypes;
else
return;
if (E) {
var z = _(A);
Ld(E, g.props, "prop", z, g);
} else if (A.PropTypes !== void 0 && !mr) {
mr = !0;
var K = _(A);
S("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", K || "Unknown");
}
typeof A.getDefaultProps == "function" && !A.getDefaultProps.isReactClassApproved && S("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function Kd(g) {
{
for (var A = Object.keys(g.props), E = 0; E < A.length; E++) {
var z = A[E];
if (z !== "children" && z !== "key") {
fi(g), S("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", z), fi(null);
break;
}
}
g.ref !== null && (fi(g), S("Invalid attribute `ref` supplied to `React.Fragment`."), fi(null));
}
}
var Gl = {};
function Yl(g, A, E, z, K, ee) {
{
var G = j(g);
if (!G) {
var X = "";
(g === void 0 || typeof g == "object" && g !== null && Object.keys(g).length === 0) && (X += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var Ee = Gd();
Ee ? X += Ee : X += Fl();
var he;
g === null ? he = "null" : dr(g) ? he = "array" : g !== void 0 && g.$$typeof === e ? (he = "<" + (_(g.type) || "Unknown") + " />", X = " Did you accidentally export a JSX literal instead of a component?") : he = typeof g, S("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", he, X);
}
var ue = Hd(g, A, E, K, ee);
if (ue == null)
return ue;
if (G) {
var He = A.children;
if (He !== void 0)
if (z)
if (dr(He)) {
for (var ui = 0; ui < He.length; ui++)
Hl(He[ui], g);
Object.freeze && Object.freeze(He);
} else
S("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
Hl(He, g);
}
if (zi.call(A, "key")) {
var Yt = _(g), Be = Object.keys(A).filter(function(sp) {
return sp !== "key";
}), yr = Be.length > 0 ? "{key: someKey, " + Be.join(": ..., ") + ": ...}" : "{key: someKey}";
if (!Gl[Yt + yr]) {
var np = Be.length > 0 ? "{" + Be.join(": ..., ") + ": ...}" : "{}";
S(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`, yr, Yt, np, Yt), Gl[Yt + yr] = !0;
}
}
return g === i ? Kd(ue) : Zd(ue), ue;
}
}
function Jd(g, A, E) {
return Yl(g, A, E, !0);
}
function ep(g, A, E) {
return Yl(g, A, E, !1);
}
var tp = ep, ip = Jd;
Ni.Fragment = i, Ni.jsx = tp, Ni.jsxs = ip;
}()), Ni;
}
var Jl;
function dp() {
return Jl || (Jl = 1, process.env.NODE_ENV === "production" ? zn.exports = fp() : zn.exports = up()), zn.exports;
}
var P = dp();
function Zr() {
return Zr = Object.assign ? Object.assign.bind() : function(n) {
for (var e = 1; e < arguments.length; e++) {
var t = arguments[e];
for (var i in t) ({}).hasOwnProperty.call(t, i) && (n[i] = t[i]);
}
return n;
}, Zr.apply(null, arguments);
}
function pp(n, e) {
if (n == null) return {};
var t = {};
for (var i in n) if ({}.hasOwnProperty.call(n, i)) {
if (e.includes(i)) continue;
t[i] = n[i];
}
return t;
}
class Z {
/**
Get the line description around the given position.
*/
lineAt(e) {
if (e < 0 || e > this.length)
throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);
return this.lineInner(e, !1, 1, 0);
}
/**
Get the description for the given (1-based) line number.
*/
line(e) {
if (e < 1 || e > this.lines)
throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);
return this.lineInner(e, !0, 1, 0);
}
/**
Replace a range of the text with the given content.
*/
replace(e, t, i) {
[e, t] = Pi(this, e, t);
let s = [];
return this.decompose(
0,
e,
s,
2
/* Open.To */
), i.length && i.decompose(
0,
i.length,
s,
3
/* Open.To */
), this.decompose(
t,
this.length,
s,
1
/* Open.From */
), ft.from(s, this.length - (t - e) + i.length);
}
/**
Append another document to this one.
*/
append(e) {
return this.replace(this.length, this.length, e);
}
/**
Retrieve the text between the given points.
*/
slice(e, t = this.length) {
[e, t] = Pi(this, e, t);
let i = [];
return this.decompose(e, t, i, 0), ft.from(i, t - e);
}
/**
Test whether this text is equal to another instance.
*/
eq(e) {
if (e == this)
return !0;
if (e.length != this.length || e.lines != this.lines)
return !1;
let t = this.scanIdentical(e, 1), i = this.length - this.scanIdentical(e, -1), s = new en(this), r = new en(e);
for (let o = t, l = t; ; ) {
if (s.next(o), r.next(o), o = 0, s.lineBreak != r.lineBreak || s.done != r.done || s.value != r.value)
return !1;
if (l += s.value.length, s.done || l >= i)
return !0;
}
}
/**
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(e = 1) {
return new en(this, e);
}
/**
Iterate over a range of the text. When `from` > `to`, the
iterator will run in reverse.
*/
iterRange(e, t = this.length) {
return new cc(this, e, t);
}
/**
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(e, t) {
let i;
if (e == null)
i = this.iter();
else {
t == null && (t = this.lines + 1);
let s = this.line(e).from;
i = this.iterRange(s, Math.max(s, t == this.lines + 1 ? this.length : t <= 1 ? 0 : this.line(t - 1).to));
}
return new fc(i);
}
/**
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 e = [];
return this.flatten(e), e;
}
/**
@internal
*/
constructor() {
}
/**
Create a `Text` instance for the given array of lines.
*/
static of(e) {
if (e.length == 0)
throw new RangeError("A document must have at least one line");
return e.length == 1 && !e[0] ? Z.empty : e.length <= 32 ? new ce(e) : ft.from(ce.split(e, []));
}
}
class ce extends Z {
constructor(e, t = gp(e)) {
super(), this.text = e, this.length = t;
}
get lines() {
return this.text.length;
}
get children() {
return null;
}
lineInner(e, t, i, s) {
for (let r = 0; ; r++) {
let o = this.text[r], l = s + o.length;
if ((t ? i : l) >= e)
return new mp(s, l, i, o);
s = l + 1, i++;
}
}
decompose(e, t, i, s) {
let r = e <= 0 && t >= this.length ? this : new ce(ea(this.text, e, t), Math.min(t, this.length) - Math.max(0, e));
if (s & 1) {
let o = i.pop(), l = cs(r.text, o.text.slice(), 0, r.length);
if (l.length <= 32)
i.push(new ce(l, o.length + r.length));
else {
let a = l.length >> 1;
i.push(new ce(l.slice(0, a)), new ce(l.slice(a)));
}
} else
i.push(r);
}
replace(e, t, i) {
if (!(i instanceof ce))
return super.replace(e, t, i);
[e, t] = Pi(this, e, t);
let s = cs(this.text, cs(i.text, ea(this.text, 0, e)), t), r = this.length + i.length - (t - e);
return s.length <= 32 ? new ce(s, r) : ft.from(ce.split(s, []), r);
}
sliceString(e, t = this.length, i = `
`) {
[e, t] = Pi(this, e, t);
let s = "";
for (let r = 0, o = 0; r <= t && o < this.text.length; o++) {
let l = this.text[o], a = r + l.length;
r > e && o && (s += i), e < a && t > r && (s += l.slice(Math.max(0, e - r), t - r)), r = a + 1;
}
return s;
}
flatten(e) {
for (let t of this.text)
e.push(t);
}
scanIdentical() {
return 0;
}
static split(e, t) {
let i = [], s = -1;
for (let r of e)
i.push(r), s += r.length + 1, i.length == 32 && (t.push(new ce(i, s)), i = [], s = -1);
return s > -1 && t.push(new ce(i, s)), t;
}
}
class ft extends Z {
constructor(e, t) {
super(), this.children = e, this.length = t, this.lines = 0;
for (let i of e)
this.lines += i.lines;
}
lineInner(e, t, i, s) {
for (let r = 0; ; r++) {
let o = this.children[r], l = s + o.length, a = i + o.lines - 1;
if ((t ? a : l) >= e)
return o.lineInner(e, t, i, s);
s = l + 1, i = a + 1;
}
}
decompose(e, t, i, s) {
for (let r = 0, o = 0; o <= t && r < this.children.length; r++) {
let l = this.children[r], a = o + l.length;
if (e <= a && t >= o) {
let h = s & ((o <= e ? 1 : 0) | (a >= t ? 2 : 0));
o >= e && a <= t && !h ? i.push(l) : l.decompose(e - o, t - o, i, h);
}
o = a + 1;
}
}
replace(e, t, i) {
if ([e, t] = Pi(this, e, t), i.lines < this.lines)
for (let s = 0, r = 0; s < this.children.length; s++) {
let o = this.children[s], l = r + o.length;
if (e >= r && t <= l) {
let a = o.replace(e - r, t - r, i), h = this.lines - o.lines + a.lines;
if (a.lines < h >> 4 && a.lines > h >> 6) {
let c = this.children.slice();
return c[s] = a, new ft(c, this.length - (t - e) + i.length);
}
return super.replace(r, l, a);
}
r = l + 1;
}
return super.replace(e, t, i);
}
sliceString(e, t = this.length, i = `
`) {
[e, t] = Pi(this, e, t);
let s = "";
for (let r = 0, o = 0; r < this.children.length && o <= t; r++) {
let l = this.children[r], a = o + l.length;
o > e && r && (s += i), e < a && t > o && (s += l.sliceString(e - o, t - o, i)), o = a + 1;
}
return s;
}
flatten(e) {
for (let t of this.children)
t.flatten(e);
}
scanIdentical(e, t) {
if (!(e instanceof ft))
return 0;
let i = 0, [s, r, o, l] = t > 0 ? [0, 0, this.children.length, e.children.length] : [this.children.length - 1, e.children.length - 1, -1, -1];
for (; ; s += t, r += t) {
if (s == o || r == l)
return i;
let a = this.children[s], h = e.children[r];
if (a != h)
return i + a.scanIdentical(h, t);
i += a.length + 1;
}
}
static from(e, t = e.reduce((i, s) => i + s.length + 1, -1)) {
let i = 0;
for (let d of e)
i += d.lines;
if (i < 32) {
let d = [];
for (let p of e)
p.flatten(d);
return new ce(d, t);
}
let s = Math.max(
32,
i >> 5
/* Tree.BranchShift */
), r = s << 1, o = s >> 1, l = [], a = 0, h = -1, c = [];
function f(d) {
let p;
if (d.lines > r && d instanceof ft)
for (let O of d.children)
f(O);
else d.lines > o && (a > o || !a) ? (u(), l.push(d)) : d instanceof ce && a && (p = c[c.length - 1]) instanceof ce && d.lines + p.lines <= 32 ? (a += d.lines, h += d.length + 1, c[c.length - 1] = new ce(p.text.concat(d.text), p.length + 1 + d.length)) : (a + d.lines > s && u(), a += d.lines, h += d.length + 1, c.push(d));
}
function u() {
a != 0 && (l.push(c.length == 1 ? c[0] : ft.from(c, h)), h = -1, a = c.length = 0);
}
for (let d of e)
f(d);
return u(), l.length == 1 ? l[0] : new ft(l, t);
}
}
Z.empty = /* @__PURE__ */ new ce([""], 0);
function gp(n) {
let e = -1;
for (let t of n)
e += t.length + 1;
return e;
}
function cs(n, e, t = 0, i = 1e9) {
for (let s = 0, r = 0, o = !0; r < n.length && s <= i; r++) {
let l = n[r], a = s + l.length;
a >= t && (a > i && (l = l.slice(0, i - s)), s < t && (l = l.slice(t - s)), o ? (e[e.length - 1] += l, o = !1) : e.push(l)), s = a + 1;
}
return e;
}
function ea(n, e, t) {
return cs(n, [""], e, t);
}
class en {
constructor(e, t = 1) {
this.dir = t, this.done = !1, this.lineBreak = !1, this.value = "", this.nodes = [e], this.offsets = [t > 0 ? 1 : (e instanceof ce ? e.text.length : e.children.length) << 1];
}
nextInner(e, t) {
for (this.done = this.lineBreak = !1; ; ) {
let i = this.nodes.length - 1, s = this.nodes[i], r = this.offsets[i], o = r >> 1, l = s instanceof ce ? s.text.length : s.children.length;
if (o == (t > 0 ? l : 0)) {
if (i == 0)
return this.done = !0, this.value = "", this;
t > 0 && this.offsets[i - 1]++, this.nodes.pop(), this.offsets.pop();
} else if ((r & 1) == (t > 0 ? 0 : 1)) {
if (this.offsets[i] += t, e == 0)
return this.lineBreak = !0, this.value = `
`, this;
e--;
} else if (s instanceof ce) {
let a = s.text[o + (t < 0 ? -1 : 0)];
if (this.offsets[i] += t, a.length > Math.max(0, e))
return this.value = e == 0 ? a : t > 0 ? a.slice(e) : a.slice(0, a.length - e), this;
e -= a.length;
} else {
let a = s.children[o + (t < 0 ? -1 : 0)];
e > a.length ? (e -= a.length, this.offsets[i] += t) : (t < 0 && this.offsets[i]--, this.nodes.push(a), this.offsets.push(t > 0 ? 1 : (a instanceof ce ? a.text.length : a.children.length) << 1));
}
}
}
next(e = 0) {
return e < 0 && (this.nextInner(-e, -this.dir), e = this.value.length), this.nextInner(e, this.dir);
}
}
class cc {
constructor(e, t, i) {
this.value = "", this.done = !1, this.cursor = new en(e, t > i ? -1 : 1), this.pos = t > i ? e.length : 0, this.from = Math.min(t, i), this.to = Math.max(t, i);
}
nextInner(e, t) {
if (t < 0 ? this.pos <= this.from : this.pos >= this.to)
return this.value = "", this.done = !0, this;
e += Math.max(0, t < 0 ? this.pos - this.to : this.from - this.pos);
let i = t < 0 ? this.pos - this.from : this.to - this.pos;
e > i && (e = i), i -= e;
let { value: s } = this.cursor.next(e);
return this.pos += (s.length + e) * t, this.value = s.length <= i ? s : t < 0 ? s.slice(s.length - i) : s.slice(0, i), this.done = !this.value, this;
}
next(e = 0) {
return e < 0 ? e = Math.max(e, this.from - this.pos) : e > 0 && (e = Math.min(e, this.to - this.pos)), this.nextInner(e, this.cursor.dir);
}
get lineBreak() {
return this.cursor.lineBreak && this.value != "";
}
}
class fc {
constructor(e) {
this.inner = e, this.afterBreak = !0, this.value = "", this.done = !1;
}
next(e = 0) {
let { done: t, lineBreak: i, value: s } = this.inner.next(e);
return t && this.afterBreak ? (this.value = "", this.afterBreak = !1) : t ? (this.done = !0, this.value = "") : i ? this.afterBreak ? this.value = "" : (this.afterBreak = !0, this.next()) : (this.value = s, this.afterBreak = !1), this;
}
get lineBreak() {
return !1;
}
}
typeof Symbol < "u" && (Z.prototype[Symbol.iterator] = function() {
return this.iter();
}, en.prototype[Symbol.iterator] = cc.prototype[Symbol.iterator] = fc.prototype[Symbol.iterator] = function() {
return this;
});
class mp {
/**
@internal
*/
constructor(e, t, i, s) {
this.from = e, this.to = t, this.number = i, this.text = s;
}
/**
The length of the line (not including any line break after it).
*/
get length() {
return this.to - this.from;
}
}
function Pi(n, e, t) {
return e = Math.max(0, Math.min(n.length, e)), [e, Math.max(e, Math.min(n.length, t))];
}
let xi = /* @__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((n) => n ? parseInt(n, 36) : 1);
for (let n = 1; n < xi.length; n++)
xi[n] += xi[n - 1];
function Op(n) {
for (let e = 1; e < xi.length; e += 2)
if (xi[e] > n)
return xi[e - 1] <= n;
return !1;
}
function ta(n) {
return n >= 127462 && n <= 127487;
}
const ia = 8205;
function Pe(n, e, t = !0, i = !0) {
return (t ? uc : yp)(n, e, i);
}
function uc(n, e, t) {
if (e == n.length)
return e;
e && dc(n.charCodeAt(e)) && pc(n.charCodeAt(e - 1)) && e--;
let i = ke(n, e);
for (e += Ye(i); e < n.length; ) {
let s = ke(n, e);
if (i == ia || s == ia || t && Op(s))
e += Ye(s), i = s;
else if (ta(s)) {
let r = 0, o = e - 2;
for (; o >= 0 && ta(ke(n, o)); )
r++, o -= 2;
if (r % 2 == 0)
break;
e += 2;
} else
break;
}
return e;
}
function yp(n, e, t) {
for (; e > 0; ) {
let i = uc(n, e - 2, t);
if (i < e)
return i;
e--;
}
return 0;
}
function dc(n) {
return n >= 56320 && n < 57344;
}
function pc(n) {
return n >= 55296 && n < 56320;
}
function ke(n, e) {
let t = n.charCodeAt(e);
if (!pc(t) || e + 1 == n.length)
return t;
let i = n.charCodeAt(e + 1);
return dc(i) ? (t - 55296 << 10) + (i - 56320) + 65536 : t;
}
function Yo(n) {
return n <= 65535 ? String.fromCharCode(n) : (n -= 65536, String.fromCharCode((n >> 10) + 55296, (n & 1023) + 56320));
}
function Ye(n) {
return n < 65536 ? 1 : 2;
}
const Kr = /\r\n?|\n/;
var Ce = /* @__PURE__ */ function(n) {
return n[n.Simple = 0] = "Simple", n[n.TrackDel = 1] = "TrackDel", n[n.TrackBefore = 2] = "TrackBefore", n[n.TrackAfter = 3] = "TrackAfter", n;
}(Ce || (Ce = {}));
class mt {
// 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(e) {
this.sections = e;
}
/**
The length of the document before the change.
*/
get length() {
let e = 0;
for (let t = 0; t < this.sections.length; t += 2)
e += this.sections[t];
return e;
}
/**
The length of the document after the change.
*/
get newLength() {
let e = 0;
for (let t = 0; t < this.sections.length; t += 2) {
let i = this.sections[t + 1];
e += i < 0 ? this.sections[t] : i;
}
return e;
}
/**
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(e) {
for (let t = 0, i = 0, s = 0; t < this.sections.length; ) {
let r = this.sections[t++], o = this.sections[t++];
o < 0 ? (e(i, s, r), s += r) : s += o, i += r;
}
}
/**
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(e, t = !1) {
Jr(this, e, t);
}
/**
Get a description of the inverted form of these changes.
*/
get invertedDesc() {
let e = [];
for (let t = 0; t < this.sections.length; ) {
let i = this.sections[t++], s = this.sections[t++];
s < 0 ? e.push(i, s) : e.push(s, i);
}
return new mt(e);
}
/**
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(e) {
return this.empty ? e : e.empty ? this : gc(this, e);
}
/**
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(e, t = !1) {
return e.empty ? this : eo(this, e, t);
}
mapPos(e, t = -1, i = Ce.Simple) {
let s = 0, r = 0;
for (let o = 0; o < this.sections.length; ) {
let l = this.sections[o++], a = this.sections[o++], h = s + l;
if (a < 0) {
if (h > e)
return r + (e - s);
r += l;
} else {
if (i != Ce.Simple && h >= e && (i == Ce.TrackDel && s < e && h > e || i == Ce.TrackBefore && s < e || i == Ce.TrackAfter && h > e))
return null;
if (h > e || h == e && t < 0 && !l)
return e == s || t < 0 ? r : r + a;
r += a;
}
s = h;
}
if (e > s)
throw new RangeError(`Position ${e} is out of range for changeset of length ${s}`);
return r;
}
/**
Check whether these changes touch a given range. When one of the
changes entirely covers the range, the string `"cover"` is
returned.
*/
touchesRange(e, t = e) {
for (let i = 0, s = 0; i < this.sections.length && s <= t; ) {
let r = this.sections[i++], o = this.sections[i++], l = s + r;
if (o >= 0 && s <= t && l >= e)
return s < e && l > t ? "cover" : !0;
s = l;
}
return !1;
}
/**
@internal
*/
toString() {
let e = "";
for (let t = 0; t < this.sections.length; ) {
let i = this.sections[t++], s = this.sections[t++];
e += (e ? " " : "") + i + (s >= 0 ? ":" + s : "");
}
return e;
}
/**
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(e) {
if (!Array.isArray(e) || e.length % 2 || e.some((t) => typeof t != "number"))
throw new RangeError("Invalid JSON representation of ChangeDesc");
return new mt(e);
}
/**
@internal
*/
static create(e) {
return new mt(e);
}
}
class Oe extends mt {
constructor(e, t) {
super(e), this.inserted = t;
}
/**
Apply the changes to a document, returning the modified
document.
*/
apply(e) {
if (this.length != e.length)
throw new RangeError("Applying change set to a document with the wrong length");
return Jr(this, (t, i, s, r, o) => e = e.replace(s, s + (i - t), o), !1), e;
}
mapDesc(e, t = !1) {
return eo(this, e, t, !0);
}
/**
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(e) {
let t = this.sections.slice(), i = [];
for (let s = 0, r = 0; s < t.length; s += 2) {
let o = t[s], l = t[s + 1];
if (l >= 0) {
t[s] = l, t[s + 1] = o;
let a = s >> 1;
for (; i.length < a; )
i.push(Z.empty);
i.push(o ? e.slice(r, r + o) : Z.empty);
}
r += o;
}
return new Oe(t, i);
}
/**
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(e) {
return this.empty ? e : e.empty ? this : gc(this, e, !0);
}
/**
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(e, t = !1) {
return e.empty ? this : eo(this, e, t, !0);
}
/**
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(e, t = !1) {
Jr(this, e, t);
}
/**
Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change
set.
*/
get desc() {
return mt.create(this.sections);
}
/**
@internal
*/
filter(e) {
let t = [], i = [], s = [], r = new on(this);
e: for (let o = 0, l = 0; ; ) {
let a = o == e.length ? 1e9 : e[o++];
for (; l < a || l == a && r.len == 0; ) {
if (r.done)
break e;
let c = Math.min(r.len, a - l);
Qe(s, c, -1);
let f = r.ins == -1 ? -1 : r.off == 0 ? r.ins : 0;
Qe(t, c, f), f > 0 && zt(i, t, r.text), r.forward(c), l += c;
}
let h = e[o++];
for (; l < h; ) {
if (r.done)
break e;
let c = Math.min(r.len, h - l);
Qe(t, c, -1), Qe(s, c, r.ins == -1 ? -1 : r.off == 0 ? r.ins : 0), r.forward(c), l += c;
}
}
return {
changes: new Oe(t, i),
filtered: mt.create(s)
};
}
/**
Serialize this change set to a JSON-representable value.
*/
toJSON() {
let e = [];
for (let t = 0; t < this.sections.length; t += 2) {
let i = this.sections[t], s = this.sections[t + 1];
s < 0 ? e.push(i) : s == 0 ? e.push([i]) : e.push([i].concat(this.inserted[t >> 1].toJSON()));
}
return e;
}
/**
Create a change set for the given changes, for a document of the
given length, using `lineSep` as line separator.
*/
static of(e, t, i) {
let s = [], r = [], o = 0, l = null;
function a(c = !1) {
if (!c && !s.length)
return;
o < t && Qe(s, t - o, -1);
let f = new Oe(s, r);
l = l ? l.compose(f.map(l)) : f, s = [], r = [], o = 0;
}
function h(c) {
if (Array.isArray(c))
for (let f of c)
h(f);
else if (c instanceof Oe) {
if (c.length != t)
throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);
a(), l = l ? l.compose(c.map(l)) : c;
} else {
let { from: f, to: u = f, insert: d } = c;
if (f > u || f < 0 || u > t)
throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${t})`);
let p = d ? typeof d == "string" ? Z.of(d.split(i || Kr)) : d : Z.empty, O = p.length;
if (f == u && O == 0)
return;
f < o && a(), f > o && Qe(s, f - o, -1), Qe(s, u - f, O), zt(r, s, p), o = u;
}
}
return h(e), a(!l), l;
}
/**
Create an empty changeset of the given length.
*/
static empty(e) {
return new Oe(e ? [e, -1] : [], []);
}
/**
Create a changeset from its JSON representation (as produced by
[`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeSet.toJSON).
*/
static fromJSON(e) {
if (!Array.isArray(e))
throw new RangeError("Invalid JSON representation of ChangeSet");
let t = [], i = [];
for (let s = 0; s < e.length; s++) {
let r = e[s];
if (typeof r == "number")
t.push(r, -1);
else {
if (!Array.isArray(r) || typeof r[0] != "number" || r.some((o, l) => l && typeof o != "string"))
throw new RangeError("Invalid JSON representation of ChangeSet");
if (r.length == 1)
t.push(r[0], 0);
else {
for (; i.length < s; )
i.push(Z.empty);
i[s] = Z.of(r.slice(1)), t.push(r[0], i[s].length);
}
}
}
return new Oe(t, i);
}
/**
@internal
*/
static createSet(e, t) {
return new Oe(e, t);
}
}
function Qe(n, e, t, i = !1) {
if (e == 0 && t <= 0)
return;
let s = n.length - 2;
s >= 0 && t <= 0 && t == n[s + 1] ? n[s] += e : e == 0 && n[s] == 0 ? n[s + 1] += t : i ? (n[s] += e, n[s + 1] += t) : n.push(e, t);
}
function zt(n, e, t) {
if (t.length == 0)
return;
let i = e.length - 2 >> 1;
if (i < n.length)
n[n.length - 1] = n[n.length - 1].append(t);
else {
for (; n.length < i; )
n.push(Z.empty);
n.push(t);
}
}
function Jr(n, e, t) {
let i = n.inserted;
for (let s = 0, r = 0, o = 0; o < n.sections.length; ) {
let l = n.sections[o++], a = n.sections[o++];
if (a < 0)
s += l, r += l;
else {
let h = s, c = r, f = Z.empty;
for (; h += l, c += a, a && i && (f = f.append(i[o - 2 >> 1])