@replit/extensions
Version:
The Replit Extensions client is a module that allows you to easily interact with the Workspace.
1,493 lines (1,477 loc) • 251 kB
JavaScript
"use strict";
var replit = (() => {
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined")
return require.apply(this, arguments);
throw new Error('Dynamic require of "' + x + '" is not supported');
});
var __commonJS = (cb, mod2) => function __require2() {
return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
mod2
));
var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
// ../../node_modules/.pnpm/@root+encoding@1.0.1/node_modules/@root/encoding/browser/bytes.js
var require_bytes = __commonJS({
"../../node_modules/.pnpm/@root+encoding@1.0.1/node_modules/@root/encoding/browser/bytes.js"(exports, module) {
"use strict";
var Enc = module.exports;
Enc.bufToBin = function(buf) {
var bin = "";
buf.forEach(function(ch) {
bin += String.fromCharCode(ch);
});
return bin;
};
Enc.strToBin = function(str) {
var escstr = encodeURIComponent(str);
var binstr = escstr.replace(/%([0-9A-F]{2})/g, function(_, p1) {
return String.fromCharCode("0x" + p1);
});
return binstr;
};
Enc.binToBuf = function(bin) {
var arr = bin.split("").map(function(ch) {
return ch.charCodeAt(0);
});
return "undefined" !== typeof Uint8Array ? new Uint8Array(arr) : arr;
};
Enc.strToBuf = function(str) {
return Enc.binToBuf(Enc.strToBin(str));
};
Enc.binToStr = function(binstr) {
var escstr = binstr.replace(/(.)/g, function(m, p) {
var code = p.charCodeAt(0).toString(16).toUpperCase();
if (code.length < 2) {
code = "0" + code;
}
return "%" + code;
});
return decodeURIComponent(escstr);
};
Enc.bufToStr = function(buf) {
return Enc.binToStr(Enc.bufToBin(buf));
};
Enc.base64ToHex = function(b64) {
return Enc.bufToHex(Enc.base64ToBuf(b64));
};
Enc.hexToBase64 = function(hex) {
return btoa(Enc._hexToBin(hex));
};
}
});
// ../../node_modules/.pnpm/@root+encoding@1.0.1/node_modules/@root/encoding/browser/hex.js
var require_hex = __commonJS({
"../../node_modules/.pnpm/@root+encoding@1.0.1/node_modules/@root/encoding/browser/hex.js"(exports, module) {
"use strict";
var Enc = require_bytes();
Enc.bufToHex = function(u8) {
var hex = [];
var i, h;
var len = u8.byteLength || u8.length;
for (i = 0; i < len; i += 1) {
h = u8[i].toString(16);
if (2 !== h.length) {
h = "0" + h;
}
hex.push(h);
}
return hex.join("").toLowerCase();
};
Enc.numToHex = function(d) {
d = d.toString(16);
if (d.length % 2) {
return "0" + d;
}
return d;
};
Enc.strToHex = function(str) {
return Enc._binToHex(Enc.strToBin(str));
};
Enc._binToHex = function(bin) {
return bin.split("").map(function(ch) {
var h = ch.charCodeAt(0).toString(16);
if (2 !== h.length) {
h = "0" + h;
}
return h;
}).join("");
};
Enc.hexToBuf = function(hex) {
var arr = [];
hex.match(/.{2}/g).forEach(function(h) {
arr.push(parseInt(h, 16));
});
return "undefined" !== typeof Uint8Array ? new Uint8Array(arr) : arr;
};
Enc.hexToStr = function(hex) {
return Enc.binToStr(_hexToBin(hex));
};
function _hexToBin(hex) {
return hex.replace(/([0-9A-F]{2})/gi, function(_, p1) {
return String.fromCharCode("0x" + p1);
});
}
Enc._hexToBin = _hexToBin;
module.exports = Enc;
}
});
// ../../node_modules/.pnpm/@root+asn1@1.0.0/node_modules/@root/asn1/packer.js
var require_packer = __commonJS({
"../../node_modules/.pnpm/@root+asn1@1.0.0/node_modules/@root/asn1/packer.js"(exports, module) {
"use strict";
var ASN1 = module.exports;
var Enc = require_hex();
function Any() {
var args = Array.prototype.slice.call(arguments);
var typ = args.shift();
var str = args.join("").replace(/\s+/g, "").toLowerCase();
var len = str.length / 2;
var lenlen = 0;
var hex = typ;
if ("number" === typeof hex) {
hex = Enc.numToHex(hex);
}
if (len !== Math.round(len)) {
throw new Error("invalid hex");
}
if (len > 127) {
lenlen += 1;
while (len > 255) {
lenlen += 1;
len = len >> 8;
}
}
if (lenlen) {
hex += Enc.numToHex(128 + lenlen);
}
return hex + Enc.numToHex(str.length / 2) + str;
}
ASN1.Any = Any;
ASN1.UInt = function UINT() {
var str = Array.prototype.slice.call(arguments).join("");
var first = parseInt(str.slice(0, 2), 16);
if (128 & first) {
str = "00" + str;
}
return Any("02", str);
};
ASN1.BitStr = function BITSTR() {
var str = Array.prototype.slice.call(arguments).join("");
return Any("03", "00" + str);
};
ASN1._toArray = function toArray(next, opts) {
var typ = opts.json ? Enc.numToHex(next.type) : next.type;
var val = next.value;
if (val) {
if ("string" !== typeof val && opts.json) {
val = Enc.bufToHex(val);
}
return [typ, val];
}
return [
typ,
next.children.map(function(child) {
return toArray(child, opts);
})
];
};
ASN1._pack = function(arr) {
var typ = arr[0];
if ("number" === typeof arr[0]) {
typ = Enc.numToHex(arr[0]);
}
var str = "";
if (Array.isArray(arr[1])) {
arr[1].forEach(function(a) {
str += ASN1._pack(a);
});
} else if ("string" === typeof arr[1]) {
str = arr[1];
} else if (arr[1].byteLength) {
str = Enc.bufToHex(arr[1]);
} else {
throw new Error("unexpected array");
}
if ("03" === typ) {
return ASN1.BitStr(str);
} else if ("02" === typ) {
return ASN1.UInt(str);
} else {
return Any(typ, str);
}
};
ASN1.pack = function(asn12, opts) {
if (!opts) {
opts = {};
}
if (!Array.isArray(asn12)) {
asn12 = ASN1._toArray(asn12, { json: true });
}
var result = ASN1._pack(asn12);
if (opts.json) {
return result;
}
return Enc.hexToBuf(result);
};
}
});
// ../../node_modules/.pnpm/@root+asn1@1.0.0/node_modules/@root/asn1/parser.js
var require_parser = __commonJS({
"../../node_modules/.pnpm/@root+asn1@1.0.0/node_modules/@root/asn1/parser.js"(exports, module) {
"use strict";
var ASN1 = module.exports;
var Enc = require_hex();
ASN1.ELOOPN = 102;
ASN1.ELOOP = "uASN1.js Error: iterated over " + ASN1.ELOOPN + "+ elements (probably a malformed file)";
ASN1.EDEEPN = 60;
ASN1.EDEEP = "uASN1.js Error: element nested " + ASN1.EDEEPN + "+ layers deep (probably a malformed file)";
ASN1.CTYPES = [48, 49, 160, 161];
ASN1.VTYPES = [1, 2, 5, 6, 12, 130];
ASN1.parseVerbose = function parseAsn1Helper(buf, opts) {
if (!opts) {
opts = {};
}
function parseAsn1(buf2, depth, eager) {
if (depth.length >= ASN1.EDEEPN) {
throw new Error(ASN1.EDEEP);
}
var index = 2;
var asn13 = { type: buf2[0], lengthSize: 0, length: buf2[1] };
var child;
var iters = 0;
var adjust = 0;
var adjustedLen;
if (128 & asn13.length) {
asn13.lengthSize = 127 & asn13.length;
asn13.length = parseInt(
Enc.bufToHex(buf2.slice(index, index + asn13.lengthSize)),
16
);
index += asn13.lengthSize;
}
if (0 === buf2[index] && (2 === asn13.type || 3 === asn13.type)) {
if (asn13.length > 1) {
index += 1;
adjust = -1;
}
}
adjustedLen = asn13.length + adjust;
function parseChildren(eager2) {
asn13.children = [];
while (iters < ASN1.ELOOPN && index < 2 + asn13.length + asn13.lengthSize) {
iters += 1;
depth.length += 1;
child = parseAsn1(
buf2.slice(index, index + adjustedLen),
depth,
eager2
);
depth.length -= 1;
index += 2 + child.lengthSize + child.length;
if (index > 2 + asn13.lengthSize + asn13.length) {
if (!eager2) {
console.error(JSON.stringify(asn13, ASN1._replacer, 2));
}
throw new Error(
"Parse error: child value length (" + child.length + ") is greater than remaining parent length (" + (asn13.length - index) + " = " + asn13.length + " - " + index + ")"
);
}
asn13.children.push(child);
}
if (index !== 2 + asn13.lengthSize + asn13.length) {
throw new Error("premature end-of-file");
}
if (iters >= ASN1.ELOOPN) {
throw new Error(ASN1.ELOOP);
}
delete asn13.value;
return asn13;
}
if (-1 !== ASN1.CTYPES.indexOf(asn13.type)) {
return parseChildren(eager);
}
asn13.value = buf2.slice(index, index + adjustedLen);
if (opts.json) {
asn13.value = Enc.bufToHex(asn13.value);
}
if (-1 !== ASN1.VTYPES.indexOf(asn13.type)) {
return asn13;
}
try {
return parseChildren(true);
} catch (e2) {
asn13.children.length = 0;
return asn13;
}
}
var asn12 = parseAsn1(buf, []);
var len = buf.byteLength || buf.length;
if (len !== 2 + asn12.lengthSize + asn12.length) {
throw new Error(
"Length of buffer does not match length of ASN.1 sequence."
);
}
return asn12;
};
ASN1._toArray = function toArray(next, opts) {
var typ = opts.json ? Enc.numToHex(next.type) : next.type;
var val = next.value;
if (val) {
if ("string" !== typeof val && opts.json) {
val = Enc.bufToHex(val);
}
return [typ, val];
}
return [
typ,
next.children.map(function(child) {
return toArray(child, opts);
})
];
};
ASN1.parse = function(opts) {
var opts2 = { json: false !== opts.json };
var verbose = ASN1.parseVerbose(opts.der, opts2);
if (opts.verbose) {
return verbose;
}
return ASN1._toArray(verbose, opts2);
};
ASN1._replacer = function(k, v) {
if ("type" === k) {
return "0x" + Enc.numToHex(v);
}
if (v && "value" === k) {
return "0x" + Enc.bufToHex(v.data || v);
}
return v;
};
}
});
// ../../node_modules/.pnpm/@root+asn1@1.0.0/node_modules/@root/asn1/index.js
var require_asn1 = __commonJS({
"../../node_modules/.pnpm/@root+asn1@1.0.0/node_modules/@root/asn1/index.js"(exports, module) {
"use strict";
var ASN1 = module.exports;
var packer = require_packer();
var parser = require_parser();
Object.keys(parser).forEach(function(key) {
ASN1[key] = parser[key];
});
Object.keys(packer).forEach(function(key) {
ASN1[key] = packer[key];
});
}
});
// src/index.ts
var src_exports = {};
__export(src_exports, {
ChangeEventType: () => ChangeEventType,
ColorScheme: () => ColorScheme,
Command: () => Command,
CommandSymbol: () => CommandSymbol,
ContributionType: () => ContributionType,
FsNodeType: () => FsNodeType,
HandshakeStatus: () => HandshakeStatus,
UserSocialType: () => UserSocialType,
commands: () => commands_exports,
copyFile: () => copyFile,
createDir: () => createDir,
data: () => data_exports,
debug: () => debug_exports,
deleteDir: () => deleteDir,
deleteFile: () => deleteFile,
exec: () => exec_exports,
experimental: () => experimental_exports,
extensionPort: () => extensionPort,
fs: () => fs_exports,
init: () => init,
internal: () => internal_exports,
isCommandProxy: () => isCommandProxy,
me: () => me_exports,
messages: () => messages_exports,
move: () => move,
proxy: () => proxy2,
readDir: () => readDir,
readFile: () => readFile,
replDb: () => replDb_exports,
session: () => session_exports,
themes: () => theme_exports,
version: () => version,
watchDir: () => watchDir,
watchFile: () => watchFile,
watchTextFile: () => watchTextFile,
writeFile: () => writeFile
});
// src/types/fs.ts
var FsNodeType = /* @__PURE__ */ ((FsNodeType2) => {
FsNodeType2["File"] = "FILE";
FsNodeType2["Directory"] = "DIRECTORY";
return FsNodeType2;
})(FsNodeType || {});
var ChangeEventType = /* @__PURE__ */ ((ChangeEventType2) => {
ChangeEventType2["Create"] = "CREATE";
ChangeEventType2["Move"] = "MOVE";
ChangeEventType2["Delete"] = "DELETE";
ChangeEventType2["Modify"] = "MODIFY";
return ChangeEventType2;
})(ChangeEventType || {});
// src/types/themes.ts
var ColorScheme = /* @__PURE__ */ ((ColorScheme2) => {
ColorScheme2["Light"] = "light";
ColorScheme2["Dark"] = "dark";
return ColorScheme2;
})(ColorScheme || {});
// src/types/data.ts
var UserSocialType = /* @__PURE__ */ ((UserSocialType2) => {
UserSocialType2["twitter"] = "twitter";
UserSocialType2["github"] = "github";
UserSocialType2["linkedin"] = "linkedin";
UserSocialType2["website"] = "website";
UserSocialType2["youtube"] = "youtube";
UserSocialType2["twitch"] = "twitch";
UserSocialType2["facebook"] = "facebook";
UserSocialType2["discord"] = "discord";
return UserSocialType2;
})(UserSocialType || {});
// src/types/index.ts
var HandshakeStatus = /* @__PURE__ */ ((HandshakeStatus2) => {
HandshakeStatus2["Ready"] = "ready";
HandshakeStatus2["Error"] = "error";
HandshakeStatus2["Loading"] = "loading";
return HandshakeStatus2;
})(HandshakeStatus || {});
// ../../node_modules/.pnpm/comlink@4.4.1/node_modules/comlink/dist/esm/comlink.mjs
var proxyMarker = Symbol("Comlink.proxy");
var createEndpoint = Symbol("Comlink.endpoint");
var releaseProxy = Symbol("Comlink.releaseProxy");
var finalizer = Symbol("Comlink.finalizer");
var throwMarker = Symbol("Comlink.thrown");
var isObject = (val) => typeof val === "object" && val !== null || typeof val === "function";
var proxyTransferHandler = {
canHandle: (val) => isObject(val) && val[proxyMarker],
serialize(obj) {
const { port1, port2 } = new MessageChannel();
expose(obj, port1);
return [port2, [port2]];
},
deserialize(port) {
port.start();
return wrap(port);
}
};
var throwTransferHandler = {
canHandle: (value) => isObject(value) && throwMarker in value,
serialize({ value }) {
let serialized;
if (value instanceof Error) {
serialized = {
isError: true,
value: {
message: value.message,
name: value.name,
stack: value.stack
}
};
} else {
serialized = { isError: false, value };
}
return [serialized, []];
},
deserialize(serialized) {
if (serialized.isError) {
throw Object.assign(new Error(serialized.value.message), serialized.value);
}
throw serialized.value;
}
};
var transferHandlers = /* @__PURE__ */ new Map([
["proxy", proxyTransferHandler],
["throw", throwTransferHandler]
]);
function isAllowedOrigin(allowedOrigins, origin) {
for (const allowedOrigin of allowedOrigins) {
if (origin === allowedOrigin || allowedOrigin === "*") {
return true;
}
if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {
return true;
}
}
return false;
}
function expose(obj, ep = globalThis, allowedOrigins = ["*"]) {
ep.addEventListener("message", function callback(ev) {
if (!ev || !ev.data) {
return;
}
if (!isAllowedOrigin(allowedOrigins, ev.origin)) {
console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);
return;
}
const { id, type, path } = Object.assign({ path: [] }, ev.data);
const argumentList = (ev.data.argumentList || []).map(fromWireValue);
let returnValue;
try {
const parent = path.slice(0, -1).reduce((obj2, prop) => obj2[prop], obj);
const rawValue = path.reduce((obj2, prop) => obj2[prop], obj);
switch (type) {
case "GET":
{
returnValue = rawValue;
}
break;
case "SET":
{
parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);
returnValue = true;
}
break;
case "APPLY":
{
returnValue = rawValue.apply(parent, argumentList);
}
break;
case "CONSTRUCT":
{
const value = new rawValue(...argumentList);
returnValue = proxy(value);
}
break;
case "ENDPOINT":
{
const { port1, port2 } = new MessageChannel();
expose(obj, port2);
returnValue = transfer(port1, [port1]);
}
break;
case "RELEASE":
{
returnValue = void 0;
}
break;
default:
return;
}
} catch (value) {
returnValue = { value, [throwMarker]: 0 };
}
Promise.resolve(returnValue).catch((value) => {
return { value, [throwMarker]: 0 };
}).then((returnValue2) => {
const [wireValue, transferables] = toWireValue(returnValue2);
ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);
if (type === "RELEASE") {
ep.removeEventListener("message", callback);
closeEndPoint(ep);
if (finalizer in obj && typeof obj[finalizer] === "function") {
obj[finalizer]();
}
}
}).catch((error2) => {
const [wireValue, transferables] = toWireValue({
value: new TypeError("Unserializable return value"),
[throwMarker]: 0
});
ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);
});
});
if (ep.start) {
ep.start();
}
}
function isMessagePort(endpoint) {
return endpoint.constructor.name === "MessagePort";
}
function closeEndPoint(endpoint) {
if (isMessagePort(endpoint))
endpoint.close();
}
function wrap(ep, target) {
return createProxy(ep, [], target);
}
function throwIfProxyReleased(isReleased) {
if (isReleased) {
throw new Error("Proxy has been released and is not useable");
}
}
function releaseEndpoint(ep) {
return requestResponseMessage(ep, {
type: "RELEASE"
}).then(() => {
closeEndPoint(ep);
});
}
var proxyCounter = /* @__PURE__ */ new WeakMap();
var proxyFinalizers = "FinalizationRegistry" in globalThis && new FinalizationRegistry((ep) => {
const newCount = (proxyCounter.get(ep) || 0) - 1;
proxyCounter.set(ep, newCount);
if (newCount === 0) {
releaseEndpoint(ep);
}
});
function registerProxy(proxy3, ep) {
const newCount = (proxyCounter.get(ep) || 0) + 1;
proxyCounter.set(ep, newCount);
if (proxyFinalizers) {
proxyFinalizers.register(proxy3, ep, proxy3);
}
}
function unregisterProxy(proxy3) {
if (proxyFinalizers) {
proxyFinalizers.unregister(proxy3);
}
}
function createProxy(ep, path = [], target = function() {
}) {
let isProxyReleased = false;
const proxy3 = new Proxy(target, {
get(_target, prop) {
throwIfProxyReleased(isProxyReleased);
if (prop === releaseProxy) {
return () => {
unregisterProxy(proxy3);
releaseEndpoint(ep);
isProxyReleased = true;
};
}
if (prop === "then") {
if (path.length === 0) {
return { then: () => proxy3 };
}
const r2 = requestResponseMessage(ep, {
type: "GET",
path: path.map((p) => p.toString())
}).then(fromWireValue);
return r2.then.bind(r2);
}
return createProxy(ep, [...path, prop]);
},
set(_target, prop, rawValue) {
throwIfProxyReleased(isProxyReleased);
const [value, transferables] = toWireValue(rawValue);
return requestResponseMessage(ep, {
type: "SET",
path: [...path, prop].map((p) => p.toString()),
value
}, transferables).then(fromWireValue);
},
apply(_target, _thisArg, rawArgumentList) {
throwIfProxyReleased(isProxyReleased);
const last = path[path.length - 1];
if (last === createEndpoint) {
return requestResponseMessage(ep, {
type: "ENDPOINT"
}).then(fromWireValue);
}
if (last === "bind") {
return createProxy(ep, path.slice(0, -1));
}
const [argumentList, transferables] = processArguments(rawArgumentList);
return requestResponseMessage(ep, {
type: "APPLY",
path: path.map((p) => p.toString()),
argumentList
}, transferables).then(fromWireValue);
},
construct(_target, rawArgumentList) {
throwIfProxyReleased(isProxyReleased);
const [argumentList, transferables] = processArguments(rawArgumentList);
return requestResponseMessage(ep, {
type: "CONSTRUCT",
path: path.map((p) => p.toString()),
argumentList
}, transferables).then(fromWireValue);
}
});
registerProxy(proxy3, ep);
return proxy3;
}
function myFlat(arr) {
return Array.prototype.concat.apply([], arr);
}
function processArguments(argumentList) {
const processed = argumentList.map(toWireValue);
return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];
}
var transferCache = /* @__PURE__ */ new WeakMap();
function transfer(obj, transfers) {
transferCache.set(obj, transfers);
return obj;
}
function proxy(obj) {
return Object.assign(obj, { [proxyMarker]: true });
}
function windowEndpoint(w, context = globalThis, targetOrigin = "*") {
return {
postMessage: (msg, transferables) => w.postMessage(msg, targetOrigin, transferables),
addEventListener: context.addEventListener.bind(context),
removeEventListener: context.removeEventListener.bind(context)
};
}
function toWireValue(value) {
for (const [name, handler] of transferHandlers) {
if (handler.canHandle(value)) {
const [serializedValue, transferables] = handler.serialize(value);
return [
{
type: "HANDLER",
name,
value: serializedValue
},
transferables
];
}
}
return [
{
type: "RAW",
value
},
transferCache.get(value) || []
];
}
function fromWireValue(value) {
switch (value.type) {
case "HANDLER":
return transferHandlers.get(value.name).deserialize(value.value);
case "RAW":
return value.value;
}
}
function requestResponseMessage(ep, msg, transfers) {
return new Promise((resolve) => {
const id = generateUUID();
ep.addEventListener("message", function l2(ev) {
if (!ev.data || !ev.data.id || ev.data.id !== id) {
return;
}
ep.removeEventListener("message", l2);
resolve(ev.data);
});
if (ep.start) {
ep.start();
}
ep.postMessage(Object.assign({ id }, msg), transfers);
});
}
function generateUUID() {
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
}
// src/util/comlink.ts
var extensionPort = (() => typeof window !== "undefined" ? wrap(
windowEndpoint(self.parent, self, "*")
) : null)();
var proxy2 = proxy;
// src/util/handshake.ts
var handshakeStatus = "loading" /* Loading */;
var setHandshakeStatus = (status) => {
handshakeStatus = status;
};
var getHandshakeStatus = () => handshakeStatus;
// src/api/fs/index.ts
var fs_exports = {};
__export(fs_exports, {
copyFile: () => copyFile,
createDir: () => createDir,
deleteDir: () => deleteDir,
deleteFile: () => deleteFile,
move: () => move,
readDir: () => readDir,
readFile: () => readFile,
watchDir: () => watchDir,
watchFile: () => watchFile,
watchTextFile: () => watchTextFile,
writeFile: () => writeFile
});
// ../../node_modules/.pnpm/@codemirror+state@6.2.0/node_modules/@codemirror/state/dist/index.js
var Text = class {
/**
@internal
*/
constructor() {
}
/**
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(n2) {
if (n2 < 1 || n2 > this.lines)
throw new RangeError(`Invalid line number ${n2} in ${this.lines}-line document`);
return this.lineInner(n2, true, 1, 0);
}
/**
Replace a range of the text with the given content.
*/
replace(from, to, text) {
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) {
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);
}
/**
@internal
*/
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;
}
/**
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, []));
}
};
var TextLeaf = class 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 i = 0; ; i++) {
let string = this.text[i], end = offset + string.length;
if ((isLine ? line : end) >= target)
return new Line(offset, end, line, string);
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);
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") {
let result = "";
for (let pos = 0, i = 0; pos <= to && i < this.text.length; i++) {
let line = this.text[i], end = pos + line.length;
if (pos > from && i)
result += lineSep;
if (from < end && to > pos)
result += line.slice(Math.max(0, from - pos), to - pos);
pos = end + 1;
}
return result;
}
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;
}
};
var TextNode = class 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 i = 0; ; i++) {
let child = this.children[i], 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 i = 0, pos = 0; pos <= to && i < this.children.length; i++) {
let child = this.children[i], 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) {
if (text.lines < this.lines)
for (let i = 0, pos = 0; i < this.children.length; i++) {
let child = this.children[i], 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[i] = 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") {
let result = "";
for (let i = 0, pos = 0; i < this.children.length && pos <= to; i++) {
let child = this.children[i], end = pos + child.length;
if (pos > from && i)
result += lineSep;
if (from < end && to > pos)
result += child.sliceString(from - pos, to - pos, lineSep);
pos = end + 1;
}
return result;
}
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((l2, ch) => l2 + 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 add3(child) {
let last;
if (child.lines > maxChunk && child instanceof TextNode) {
for (let node of child.children)
add3(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)
add3(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, i = 0, first = true; i < text.length && pos <= to; i++) {
let line = text[i], 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);
}
var RawTextCursor = class {
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 top = this.nodes[last], offsetValue = this.offsets[last], offset = offsetValue >> 1;
let size = top instanceof TextLeaf ? top.text.length : top.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 (top instanceof TextLeaf) {
let next = top.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 = top.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);
}
};
var PartialTextCursor = class {
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 != "";
}
};
var LineCursor = class {
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.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;
};
}
var Line = class {
/**
@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;
}
};
var 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 i = 1; i < extend.length; i++)
extend[i] += extend[i - 1];
function isExtendingChar(code) {
for (let i = 1; i < extend.length; i += 2)
if (extend[i] > code)
return extend[i - 1] <= code;
return false;
}
function isRegionalIndicator(code) {
return code >= 127462 && code <= 127487;
}
var 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, i = pos - 2;
while (i >= 0 && isRegionalIndicator(codePointAt(str, i))) {
countBefore++;
i -= 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 codePointSize(code) {
return code < 65536 ? 1 : 2;
}
var 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 = {}));
var ChangeDesc = class {
// 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 result = 0;
for (let i = 0; i < this.sections.length; i += 2)
result += this.sections[i];
return result;
}
/**
The length of the document after the change.
*/
get newLength() {
let result = 0;
for (let i = 0; i < this.sections.length; i += 2) {
let ins = this.sections[i + 1];
result += ins < 0 ? this.sections[i] : ins;
}
return result;
}
/**
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 i = 0, posA = 0, posB = 0; i < this.sections.length; ) {
let len = this.sections[i++], ins = this.sections[i++];
if (ins < 0) {
f(posA, posB, len);
posB +