@iqmo/browser
Version:
Browser Stlite
747 lines (723 loc) • 26.2 kB
JavaScript
function V(o) {
return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
}
var D, B;
function Y() {
if (B) return D;
B = 1;
function o(l) {
if (typeof l != "string")
throw new TypeError("Path must be a string. Received " + JSON.stringify(l));
}
function c(l, e) {
for (var t = "", a = 0, n = -1, s = 0, r, i = 0; i <= l.length; ++i) {
if (i < l.length)
r = l.charCodeAt(i);
else {
if (r === 47)
break;
r = 47;
}
if (r === 47) {
if (!(n === i - 1 || s === 1)) if (n !== i - 1 && s === 2) {
if (t.length < 2 || a !== 2 || t.charCodeAt(t.length - 1) !== 46 || t.charCodeAt(t.length - 2) !== 46) {
if (t.length > 2) {
var f = t.lastIndexOf("/");
if (f !== t.length - 1) {
f === -1 ? (t = "", a = 0) : (t = t.slice(0, f), a = t.length - 1 - t.lastIndexOf("/")), n = i, s = 0;
continue;
}
} else if (t.length === 2 || t.length === 1) {
t = "", a = 0, n = i, s = 0;
continue;
}
}
e && (t.length > 0 ? t += "/.." : t = "..", a = 2);
} else
t.length > 0 ? t += "/" + l.slice(n + 1, i) : t = l.slice(n + 1, i), a = i - n - 1;
n = i, s = 0;
} else r === 46 && s !== -1 ? ++s : s = -1;
}
return t;
}
function u(l, e) {
var t = e.dir || e.root, a = e.base || (e.name || "") + (e.ext || "");
return t ? t === e.root ? t + a : t + l + a : a;
}
var d = {
// path.resolve([from ...], to)
resolve: function() {
for (var e = "", t = !1, a, n = arguments.length - 1; n >= -1 && !t; n--) {
var s;
n >= 0 ? s = arguments[n] : (a === void 0 && (a = process.cwd()), s = a), o(s), s.length !== 0 && (e = s + "/" + e, t = s.charCodeAt(0) === 47);
}
return e = c(e, !t), t ? e.length > 0 ? "/" + e : "/" : e.length > 0 ? e : ".";
},
normalize: function(e) {
if (o(e), e.length === 0) return ".";
var t = e.charCodeAt(0) === 47, a = e.charCodeAt(e.length - 1) === 47;
return e = c(e, !t), e.length === 0 && !t && (e = "."), e.length > 0 && a && (e += "/"), t ? "/" + e : e;
},
isAbsolute: function(e) {
return o(e), e.length > 0 && e.charCodeAt(0) === 47;
},
join: function() {
if (arguments.length === 0)
return ".";
for (var e, t = 0; t < arguments.length; ++t) {
var a = arguments[t];
o(a), a.length > 0 && (e === void 0 ? e = a : e += "/" + a);
}
return e === void 0 ? "." : d.normalize(e);
},
relative: function(e, t) {
if (o(e), o(t), e === t || (e = d.resolve(e), t = d.resolve(t), e === t)) return "";
for (var a = 1; a < e.length && e.charCodeAt(a) === 47; ++a)
;
for (var n = e.length, s = n - a, r = 1; r < t.length && t.charCodeAt(r) === 47; ++r)
;
for (var i = t.length, f = i - r, k = s < f ? s : f, v = -1, _ = 0; _ <= k; ++_) {
if (_ === k) {
if (f > k) {
if (t.charCodeAt(r + _) === 47)
return t.slice(r + _ + 1);
if (_ === 0)
return t.slice(r + _);
} else s > k && (e.charCodeAt(a + _) === 47 ? v = _ : _ === 0 && (v = 0));
break;
}
var F = e.charCodeAt(a + _), M = t.charCodeAt(r + _);
if (F !== M)
break;
F === 47 && (v = _);
}
var y = "";
for (_ = a + v + 1; _ <= n; ++_)
(_ === n || e.charCodeAt(_) === 47) && (y.length === 0 ? y += ".." : y += "/..");
return y.length > 0 ? y + t.slice(r + v) : (r += v, t.charCodeAt(r) === 47 && ++r, t.slice(r));
},
_makeLong: function(e) {
return e;
},
dirname: function(e) {
if (o(e), e.length === 0) return ".";
for (var t = e.charCodeAt(0), a = t === 47, n = -1, s = !0, r = e.length - 1; r >= 1; --r)
if (t = e.charCodeAt(r), t === 47) {
if (!s) {
n = r;
break;
}
} else
s = !1;
return n === -1 ? a ? "/" : "." : a && n === 1 ? "//" : e.slice(0, n);
},
basename: function(e, t) {
if (t !== void 0 && typeof t != "string") throw new TypeError('"ext" argument must be a string');
o(e);
var a = 0, n = -1, s = !0, r;
if (t !== void 0 && t.length > 0 && t.length <= e.length) {
if (t.length === e.length && t === e) return "";
var i = t.length - 1, f = -1;
for (r = e.length - 1; r >= 0; --r) {
var k = e.charCodeAt(r);
if (k === 47) {
if (!s) {
a = r + 1;
break;
}
} else
f === -1 && (s = !1, f = r + 1), i >= 0 && (k === t.charCodeAt(i) ? --i === -1 && (n = r) : (i = -1, n = f));
}
return a === n ? n = f : n === -1 && (n = e.length), e.slice(a, n);
} else {
for (r = e.length - 1; r >= 0; --r)
if (e.charCodeAt(r) === 47) {
if (!s) {
a = r + 1;
break;
}
} else n === -1 && (s = !1, n = r + 1);
return n === -1 ? "" : e.slice(a, n);
}
},
extname: function(e) {
o(e);
for (var t = -1, a = 0, n = -1, s = !0, r = 0, i = e.length - 1; i >= 0; --i) {
var f = e.charCodeAt(i);
if (f === 47) {
if (!s) {
a = i + 1;
break;
}
continue;
}
n === -1 && (s = !1, n = i + 1), f === 46 ? t === -1 ? t = i : r !== 1 && (r = 1) : t !== -1 && (r = -1);
}
return t === -1 || n === -1 || // We saw a non-dot character immediately before the dot
r === 0 || // The (right-most) trimmed path component is exactly '..'
r === 1 && t === n - 1 && t === a + 1 ? "" : e.slice(t, n);
},
format: function(e) {
if (e === null || typeof e != "object")
throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof e);
return u("/", e);
},
parse: function(e) {
o(e);
var t = { root: "", dir: "", base: "", ext: "", name: "" };
if (e.length === 0) return t;
var a = e.charCodeAt(0), n = a === 47, s;
n ? (t.root = "/", s = 1) : s = 0;
for (var r = -1, i = 0, f = -1, k = !0, v = e.length - 1, _ = 0; v >= s; --v) {
if (a = e.charCodeAt(v), a === 47) {
if (!k) {
i = v + 1;
break;
}
continue;
}
f === -1 && (k = !1, f = v + 1), a === 46 ? r === -1 ? r = v : _ !== 1 && (_ = 1) : r !== -1 && (_ = -1);
}
return r === -1 || f === -1 || // We saw a non-dot character immediately before the dot
_ === 0 || // The (right-most) trimmed path component is exactly '..'
_ === 1 && r === f - 1 && r === i + 1 ? f !== -1 && (i === 0 && n ? t.base = t.name = e.slice(1, f) : t.base = t.name = e.slice(i, f)) : (i === 0 && n ? (t.name = e.slice(1, r), t.base = e.slice(1, f)) : (t.name = e.slice(i, r), t.base = e.slice(i, f)), t.ext = e.slice(r, f)), i > 0 ? t.dir = e.slice(0, i - 1) : n && (t.dir = "/"), t;
},
sep: "/",
delimiter: ":",
win32: null,
posix: null
};
return d.posix = d, D = d, D;
}
var Z = Y(), T = /* @__PURE__ */ V(Z);
const W = "/home/pyodide", H = (o) => `${W}/${o}`, E = (o, c) => o == null ? T.resolve(W, c) : T.resolve(H(o), c);
function z(o, c) {
const u = T.normalize(c), l = T.dirname(u).split("/"), e = [];
for (const t of l) {
e.push(t);
const a = e.join("/");
if (o.FS.analyzePath(a).exists) {
if (o.FS.isDir(a))
throw new Error(`"${a}" already exists and is not a directory.`);
continue;
}
try {
o.FS.mkdir(a);
} catch (n) {
throw console.error(`Failed to create a directory "${a}"`), n;
}
}
}
function j(o, c, u, d) {
z(o, c), o.FS.writeFile(c, u, d);
}
function ee(o, c, u) {
z(o, u), o.FS.rename(c, u);
}
const te = "[", re = "(<=>!~", oe = ";", ne = "@", se = new RegExp(
`[${te + re + oe + ne}]`
);
function ae(o) {
return o.split(se)[0].trim();
}
function x(o) {
return o.forEach((u) => {
let d;
try {
d = new URL(u);
} catch {
return;
}
if (d.protocol === "emfs:" || d.protocol === "file:")
throw new Error(
`"emfs:" and "file:" protocols are not allowed for the requirement (${u})`
);
}), o.filter((u) => ae(u) === "streamlit" ? (console.warn(
`Streamlit is specified in the requirements ("${u}"), but it will be ignored. A built-in version of Streamlit will be used.`
), !1) : !0);
}
async function ie(o) {
var l;
const c = typeof process < "u" && ((l = process.versions) == null ? void 0 : l.node);
let u;
c ? u = (await import(
/* webpackIgnore: true */
"./__vite-browser-external-CPvbk0mb.js"
)).sep : u = "/";
const d = o.slice(0, o.lastIndexOf(u) + 1);
if (o.endsWith(".mjs")) {
if (c) {
const e = await import(
/* webpackIgnore: true */
"./__vite-browser-external-CPvbk0mb.js"
), t = await import(
/* webpackIgnore: true */
"./__vite-browser-external-CPvbk0mb.js"
);
!o.includes("://") && e.isAbsolute(o) && (o = t.pathToFileURL(o).href);
}
return {
scriptURL: o,
pyodideIndexURL: d,
isESModule: !0
};
} else
return {
scriptURL: o,
pyodideIndexURL: d,
isESModule: !1
};
}
async function le(o, c) {
const { scriptURL: u, pyodideIndexURL: d, isESModule: l } = await ie(o);
let e;
return l ? e = (await import(
/* webpackIgnore: true */
/* @vite-ignore */
u
)).loadPyodide : (importScripts(u), e = self.loadPyodide), e({ ...c, indexURL: d });
}
function ce(o) {
o.runPython(`
import micropip
micropip.add_mock_package(
"pyarrow", "0.0.1",
modules={
"pyarrow": """
__version__ = '0.0.1' # TODO: Update when releasing
class Table:
@classmethod
def from_pandas(*args, **kwargs):
raise NotImplementedError("stlite is not supporting this method.")
class Array:
def __init__(self, *args, **kwargs):
raise NotImplementedError("stlite is not supporting PyArrow.Array")
class ChunkedArray:
def __init__(self, *args, **kwargs):
raise NotImplementedError("stlite is not supporting PyArrow.ChunkedArray")
"""
}
)
`);
}
function de(o, c, u) {
const d = o.pyimport("pyodide"), l = (r) => d.code.find_imports(r).toJs(), e = u.map((r) => l(r)), n = Array.from(new Set(e.flat())).filter((r) => !o.runPython(`__import__('importlib').util.find_spec('${r}')`)).map((r) => o._api._import_name_to_package_name.get(r)).filter((r) => r);
if (n.length === 0)
return Promise.resolve();
const s = o.loadPackage(n);
return c(n, s), s.then();
}
function J(o, c, u) {
const d = de(o, c, u);
o.runPython(`
def __set_module_auto_load_promise__(promise):
from streamlit.runtime.scriptrunner import script_runner
script_runner.moduleAutoLoadPromise = promise
__set_module_auto_load_promise__`)(d);
}
async function ue(o, c, u) {
const { line: d, column: l } = u, e = o.Script(c);
if (d > e._code_lines.length)
return [];
const t = e.complete.callKwargs({
line: d,
column: l,
fuzzy: !1
}), a = [];
for (const n of t.toJs())
a.push({
name: n.name,
type: n.$type,
// PyProxy.type is overridden in Pyodide. We need to access it this way. Ref: https://github.com/pyodide/pyodide/issues/4032
docstring: n.docstring.callKwargs({ raw: !0 })
}), n.destroy();
return a;
}
let O = null;
async function fe(o, c, u, d, l) {
const { entrypoint: e, files: t, archives: a, requirements: n, prebuiltPackageNames: s, wheels: r, pyodideUrl: i = o, streamlitConfig: f, idbfsMountpoints: k, nodefsMountpoints: v, moduleAutoLoad: _, env: F, languageServer: M } = u, y = x(n);
if (O)
l("Pyodide is already loaded."), console.debug("Pyodide is already loaded.");
else {
l("Loading Pyodide."), console.debug("Loading Pyodide."), O = le(i, {
stdout: console.log,
stderr: console.error
});
const m = [];
r && (m.push(r.streamlit), m.push(r.stliteLib)), M && m.push("jedi"), y.unshift(...m), console.debug("Loaded Pyodide");
}
const g = (
// XXX: `{ FS: any }` is a temporary workaround to fix the type error.
await O
);
if (F) {
console.debug("Setting environment variables", F);
const m = g.pyimport("os");
m.environ.update(g.toPy(F)), console.debug("Set environment variables", m.environ);
}
let P = !1;
k && (P = !0, k.forEach((m) => {
g.FS.mkdir(m), g.FS.mount(g.FS.filesystems.IDBFS, {}, m);
}), await new Promise((m, b) => {
g.FS.syncfs(!0, (A) => {
A ? b(A) : m();
});
})), v && Object.entries(v).forEach(([m, b]) => {
g.FS.mkdir(m), g.FS.mount(g.FS.filesystems.NODEFS, { root: b }, m);
}), l("Mounting files.");
const p = [];
await Promise.all(Object.keys(t).map(async (m) => {
const b = t[m];
m = E(c, m);
let A;
"url" in b ? (console.debug(`Fetch a file from ${b.url}`), A = await fetch(b.url).then((L) => L.arrayBuffer()).then((L) => new Uint8Array(L))) : A = b.data, console.debug(`Write a file "${m}"`), j(g, m, A, t.opts), m.endsWith(".py") && p.push(m);
})), l("Unpacking archives."), await Promise.all(a.map(async (m) => {
let b;
"url" in m ? (console.debug(`Fetch an archive from ${m.url}`), b = await fetch(m.url).then((Q) => Q.arrayBuffer())) : b = m.buffer;
const { format: A, options: L } = m;
console.debug("Unpack an archive", { format: A, options: L }), g.unpackArchive(b, A, L);
})), await g.loadPackage("micropip");
const h = g.pyimport("micropip");
if (l("Mocking some packages."), console.debug("Mock pyarrow"), ce(g), console.debug("Mocked pyarrow"), l("Installing packages."), console.debug("Installing the prebuilt packages:", s), await g.loadPackage(s), console.debug("Installed the prebuilt packages"), console.debug("Installing the requirements:", y), await h.install.callKwargs(y, { keep_going: !0 }), console.debug("Installed the requirements"), _) {
const m = p.map((b) => g.FS.readFile(b, { encoding: "utf8" }));
J(g, d, m);
}
await g.runPythonAsync(`
import importlib
importlib.invalidate_caches()
`), l("Loading streamlit package."), console.debug("Loading the Streamlit package"), await g.runPythonAsync(`
import streamlit.runtime
`), console.debug("Loaded the Streamlit package"), l("Setting up the loggers."), console.debug("Setting the loggers"), await g.runPythonAsync(`
import logging
import streamlit.logger
streamlit.logger.get_logger = logging.getLogger
streamlit.logger.setup_formatter = None
streamlit.logger.update_formatter = lambda *a, **k: None
streamlit.logger.set_log_level = lambda *a, **k: None
for name in streamlit.logger._loggers.keys():
if name == "root":
name = "streamlit"
logger = logging.getLogger(name)
logger.propagate = True
logger.handlers.clear()
logger.setLevel(logging.NOTSET)
streamlit.logger._loggers = {}
`);
const S = (m, b) => {
m >= 40 ? console.error(b) : m >= 30 ? console.warn(b) : m >= 20 ? console.info(b) : console.debug(b);
}, w = g.runPython(`
def __setup_loggers__(streamlit_level, streamlit_message_format, callback):
class JsHandler(logging.Handler):
def emit(self, record):
msg = self.format(record)
callback(record.levelno, msg)
root_message_format = "%(levelname)s:%(name)s:%(message)s"
root_logger = logging.getLogger()
root_logger.handlers.clear()
root_formatter = logging.Formatter(root_message_format)
root_handler = JsHandler()
root_handler.setFormatter(root_formatter)
root_logger.addHandler(root_handler)
root_logger.setLevel(logging.DEBUG)
streamlit_logger = logging.getLogger("streamlit")
streamlit_logger.propagate = False
streamlit_logger.handlers.clear()
streamlit_formatter = logging.Formatter(streamlit_message_format)
streamlit_handler = JsHandler()
streamlit_handler.setFormatter(streamlit_formatter)
streamlit_logger.addHandler(streamlit_handler)
streamlit_logger.setLevel(streamlit_level.upper())
__setup_loggers__`), R = ((f == null ? void 0 : f["logger.level"]) ?? "INFO").toString(), C = (f == null ? void 0 : f["logger.messageFormat"]) ?? "%(asctime)s %(message)s";
if (w(R, C, S), console.debug("Set the loggers"), l("Mocking some Streamlit functions for the browser environment."), console.debug("Mocking some Streamlit functions"), await g.runPythonAsync(`
import streamlit
def is_cacheable_msg(msg):
return False
streamlit.runtime.runtime.is_cacheable_msg = is_cacheable_msg
`), console.debug("Mocked some Streamlit functions"), P) {
l("Setting up the IndexedDB filesystem synchronizer."), console.debug("Setting up the IndexedDB filesystem synchronizer");
let m = !1;
const b = () => {
console.debug("The script has finished. Syncing the filesystem."), m || (m = !0, g.FS.syncfs(!1, (L) => {
m = !1, L && console.error(L);
}));
};
(await g.runPython(`
def __setup_script_finished_callback__(callback):
from streamlit.runtime.app_session import AppSession
from streamlit.runtime.scriptrunner import ScriptRunnerEvent
def wrap_app_session_on_scriptrunner_event(original_method):
def wrapped(self, *args, **kwargs):
if "event" in kwargs:
event = kwargs["event"]
if event == ScriptRunnerEvent.SCRIPT_STOPPED_WITH_SUCCESS or event == ScriptRunnerEvent.SCRIPT_STOPPED_FOR_RERUN or event == ScriptRunnerEvent.SHUTDOWN:
callback()
return original_method(self, *args, **kwargs)
return wrapped
AppSession._on_scriptrunner_event = wrap_app_session_on_scriptrunner_event(AppSession._on_scriptrunner_event)
__setup_script_finished_callback__`))(b), console.debug("Set up the IndexedDB filesystem synchronizer");
}
l("Booting up the Streamlit server."), console.debug("Setting up the Streamlit configuration");
const I = await g.runPython(`
def __bootstrap__(main_script_path, flag_options, shared_worker_mode):
from stlite_lib.bootstrap import load_config_options, prepare
load_config_options(flag_options, shared_worker_mode)
prepare(main_script_path, [])
__bootstrap__`), N = E(c, e), G = {
// gatherUsageStats is disabled as default, but can be enabled explicitly by setting it to true.
"browser.gatherUsageStats": !1,
...f,
"runner.fastReruns": !1
// Fast reruns do not work well with the async script runner of stlite. See https://github.com/whitphx/stlite/pull/550#issuecomment-1505485865.
}, X = c != null;
I(N, g.toPy(G), X), console.debug("Set up the Streamlit configuration"), console.debug("Booting up the Streamlit server");
const q = g.pyimport("stlite_lib.server.Server")(N, c ? H(c) : null);
return await q.start(), console.debug("Booted up the Streamlit server"), {
pyodide: g,
httpServer: q,
micropip: h,
initData: u
};
}
function $(o, c, u, d) {
function l(n) {
c({
type: "event:progress",
data: {
message: n
}
});
}
const e = (n, s) => {
const r = new MessageChannel();
c({
type: "event:moduleAutoLoad",
data: {
packagesToLoad: n
}
}, [r.port2]), s.then((i) => {
r.port1.postMessage({
type: "moduleAutoLoad:success",
data: {
loadedPackages: i
}
}), r.port1.close();
}).catch((i) => {
throw r.port1.postMessage({
type: "moduleAutoLoad:error",
error: i
}), r.port1.close(), i;
});
};
let t = null;
const a = async (n) => {
const s = n.data;
if (s.type === "initData") {
const g = s.data, P = {
...u,
...g
};
console.debug("Initial data", P), t = fe(o, d, P, e, l), t.then(() => {
c({
type: "event:loaded"
});
}).catch((p) => {
console.error(p), c({
type: "event:error",
data: {
error: p
}
});
});
return;
}
if (!t)
throw new Error("Pyodide initialization has not been started yet.");
const r = await t, i = r.pyodide;
let f = r.httpServer;
const k = r.micropip, { moduleAutoLoad: v, languageServer: _ } = r.initData, F = _ ? await i.pyimport("jedi") : null, M = n.ports[0];
function y(g) {
M.postMessage(g);
}
try {
switch (s.type) {
case "reboot": {
console.debug("Reboot the Streamlit server", s.data);
const { entrypoint: p } = s.data;
f.stop(), console.debug("Booting up the Streamlit server");
const h = E(d, p);
f = i.pyimport("stlite_lib.server.Server")(h), f.start(), console.debug("Booted up the Streamlit server"), y({
type: "reply"
});
break;
}
case "websocket:connect": {
console.debug("websocket:connect", s.data);
const { path: p } = s.data;
f.start_websocket(p, (h, S) => {
if (S) {
const w = h;
try {
const R = w.toJs(), C = R.buffer.slice(R.byteOffset, R.byteOffset + R.byteLength);
c({
type: "websocket:message",
data: {
payload: C
}
}, [C]);
} finally {
w.destroy();
}
} else
c({
type: "websocket:message",
data: {
payload: h
}
});
}), y({
type: "reply"
});
break;
}
case "websocket:send": {
console.debug("websocket:send", s.data);
const { payload: p } = s.data;
f.receive_websocket_from_js(p);
break;
}
case "http:request": {
console.debug("http:request", s.data);
const { request: p } = s.data, h = (S, w, R) => {
const C = new Map(w.toJs()), I = R.toJs();
console.debug({ statusCode: S, headers: C, body: I }), y({
type: "http:response",
data: {
response: {
statusCode: S,
headers: C,
body: I
}
}
});
};
f.receive_http_from_js(p.method, decodeURIComponent(p.path), p.headers, p.body, h);
break;
}
case "file:write": {
const { path: p, data: h, opts: S } = s.data, w = E(d, p);
v && typeof h == "string" && w.endsWith(".py") && (console.debug(`Auto install the requirements in ${w}`), J(i, e, [h])), console.debug(`Write a file "${w}"`), j(i, w, h, S), y({
type: "reply"
});
break;
}
case "file:rename": {
const { oldPath: p, newPath: h } = s.data, S = E(d, p), w = E(d, h);
console.debug(`Rename "${S}" to ${w}`), ee(i, S, w), y({
type: "reply"
});
break;
}
case "file:unlink": {
const { path: p } = s.data, h = E(d, p);
console.debug(`Remove "${h}`), i.FS.unlink(h), y({
type: "reply"
});
break;
}
case "file:read": {
const { path: p, opts: h } = s.data;
console.debug(`Read "${p}"`);
const S = i.FS.readFile(p, h);
y({
type: "reply:file:read",
data: {
content: S
}
});
break;
}
case "install": {
const { requirements: p } = s.data, h = x(p);
console.debug("Install the requirements:", h), await k.install.callKwargs(h, { keep_going: !0 }).then(() => {
console.debug("Successfully installed"), y({
type: "reply"
});
});
break;
}
case "setEnv": {
const { env: p } = s.data;
i.pyimport("os").environ.update(i.toPy(p)), console.debug("Successfully set the environment variables", p), y({
type: "reply"
});
break;
}
case "code_completion": {
if (!F)
throw new Error("Jedi is not installed");
const { code: p, line: h, column: S } = s.data, w = await ue(F, p, {
line: h,
column: S
});
y({
type: "reply:code_completion",
data: {
codeCompletions: w
}
});
break;
}
case "execute":
const { code: g } = s.data, P = await i.runPythonAsync(g);
y({
type: "reply:execute",
data: {
result: P
}
});
break;
case "set-interrupt-buffer":
i.setInterruptBuffer(s.data.interruptBuffer), y({
type: "reply"
});
}
} catch (g) {
if (console.error(g), !(g instanceof Error))
throw g;
const P = new Error(g.message);
P.name = g.name, P.stack = g.stack, y({
type: "reply",
error: P
});
}
};
return c({
type: "event:start"
}), a;
}
const K = "abcdefghijklmnopqrstuvwxyz", ge = K.length;
function me(o) {
let c = "";
for (let u = 0; u < o; u++) {
const d = Math.floor(Math.random() * ge);
c += K[d];
}
return c;
}
const U = "https://cdn.jsdelivr.net/pyodide/v0.27.6/full/pyodide.mjs";
delete WebAssembly.Suspending;
if ("postMessage" in self)
self.onmessage = $(U, (o, c) => c ? self.postMessage(o, c) : self.postMessage(o));
else {
const o = [];
self.onconnect = (c) => {
let u;
do
u = me(4);
while (o.includes(u));
o.push(u), console.debug("SharedWorker mode.", { appId: u });
const d = c.ports[0];
d.onmessage = $(U, (l, e) => e ? d.postMessage(l, e) : d.postMessage(l), void 0, u), d.start();
};
}
//# sourceMappingURL=worker-BTKH-hni.js.map