@x-python/core
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -91,2 +91,3 @@ export declare type ActionCallbacks = Callbacks<ActionReturnValue>; | ||
code: string; | ||
options?: Record<string, unknown>; | ||
}; | ||
@@ -93,0 +94,0 @@ |
@@ -9,3 +9,3 @@ function h(I, g, C) { | ||
} | ||
function a(I, g) { | ||
function X(I, g) { | ||
var C = Object.keys(I); | ||
@@ -20,8 +20,8 @@ if (Object.getOwnPropertySymbols) { | ||
} | ||
function V(I) { | ||
function a(I) { | ||
for (var g = 1; g < arguments.length; g++) { | ||
var C = arguments[g] != null ? arguments[g] : {}; | ||
g % 2 ? a(Object(C), !0).forEach(function(A) { | ||
g % 2 ? X(Object(C), !0).forEach(function(A) { | ||
h(I, A, C[A]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(I, Object.getOwnPropertyDescriptors(C)) : a(Object(C)).forEach(function(A) { | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(I, Object.getOwnPropertyDescriptors(C)) : X(Object(C)).forEach(function(A) { | ||
Object.defineProperty(I, A, Object.getOwnPropertyDescriptor(C, A)); | ||
@@ -41,3 +41,3 @@ }); | ||
} | ||
function s(I) { | ||
function u(I) { | ||
return function g() { | ||
@@ -47,4 +47,4 @@ for (var C = this, A = arguments.length, i = new Array(A), l = 0; l < A; l++) | ||
return i.length >= I.length ? I.apply(this, i) : function() { | ||
for (var b = arguments.length, c = new Array(b), Z = 0; Z < b; Z++) | ||
c[Z] = arguments[Z]; | ||
for (var b = arguments.length, c = new Array(b), G = 0; G < b; G++) | ||
c[G] = arguments[G]; | ||
return g.apply(C, [].concat(i, c)); | ||
@@ -54,3 +54,3 @@ }; | ||
} | ||
function p(I) { | ||
function S(I) { | ||
return {}.toString.call(I).includes("Object"); | ||
@@ -61,3 +61,3 @@ } | ||
} | ||
function u(I) { | ||
function n(I) { | ||
return typeof I == "function"; | ||
@@ -69,3 +69,3 @@ } | ||
function R(I, g) { | ||
return p(g) || d("changeType"), Object.keys(g).some(function(C) { | ||
return S(g) || d("changeType"), Object.keys(g).some(function(C) { | ||
return !t(I, C); | ||
@@ -75,16 +75,16 @@ }) && d("changeField"), g; | ||
function J(I) { | ||
u(I) || d("selectorType"); | ||
n(I) || d("selectorType"); | ||
} | ||
function F(I) { | ||
u(I) || p(I) || d("handlerType"), p(I) && Object.values(I).some(function(g) { | ||
return !u(g); | ||
function L(I) { | ||
n(I) || S(I) || d("handlerType"), S(I) && Object.values(I).some(function(g) { | ||
return !n(g); | ||
}) && d("handlersType"); | ||
} | ||
function L(I) { | ||
I || d("initialIsRequired"), p(I) || d("initialType"), k(I) && d("initialContent"); | ||
function v(I) { | ||
I || d("initialIsRequired"), S(I) || d("initialType"), k(I) && d("initialContent"); | ||
} | ||
function v(I, g) { | ||
function F(I, g) { | ||
throw new Error(I[g] || I.default); | ||
} | ||
var r = { | ||
var U = { | ||
initialIsRequired: "initial state is required", | ||
@@ -99,33 +99,33 @@ initialType: "initial state should be an object", | ||
default: "an unknown error accured in `state-local` package" | ||
}, d = s(v)(r), n = { | ||
}, d = u(F)(U), W = { | ||
changes: R, | ||
selector: J, | ||
handler: F, | ||
initial: L | ||
handler: L, | ||
initial: v | ||
}; | ||
function N(I) { | ||
function r(I) { | ||
var g = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; | ||
n.initial(I), n.handler(g); | ||
W.initial(I), W.handler(g); | ||
var C = { | ||
current: I | ||
}, A = s(z)(C, g), i = s(Q)(C), l = s(n.changes)(I), b = s(U)(C); | ||
}, A = u(z)(C, g), i = u(Q)(C), l = u(W.changes)(I), b = u(N)(C); | ||
function c() { | ||
var G = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : function(S) { | ||
return S; | ||
var Z = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : function(s) { | ||
return s; | ||
}; | ||
return n.selector(G), G(C.current); | ||
return W.selector(Z), Z(C.current); | ||
} | ||
function Z(G) { | ||
e(A, i, l, b)(G); | ||
function G(Z) { | ||
e(A, i, l, b)(Z); | ||
} | ||
return [c, Z]; | ||
return [c, G]; | ||
} | ||
function U(I, g) { | ||
return u(g) ? g(I.current) : g; | ||
function N(I, g) { | ||
return n(g) ? g(I.current) : g; | ||
} | ||
function Q(I, g) { | ||
return I.current = V(V({}, I.current), g), g; | ||
return I.current = a(a({}, I.current), g), g; | ||
} | ||
function z(I, g, C) { | ||
return u(g) ? g(I.current) : Object.keys(C).forEach(function(A) { | ||
return n(g) ? g(I.current) : Object.keys(C).forEach(function(A) { | ||
var i; | ||
@@ -135,30 +135,30 @@ return (i = g[A]) === null || i === void 0 ? void 0 : i.call(g, I.current[A]); | ||
} | ||
var T = { | ||
create: N | ||
var j = { | ||
create: r | ||
}; | ||
const f = { | ||
const O = { | ||
loadPyodideOptions: { | ||
indexURL: "https://cdn.jsdelivr.net/pyodide/v0.23.0/full/" | ||
indexURL: "https://cdn.jsdelivr.net/pyodide/v0.23.2/full/" | ||
} | ||
}; | ||
var X = /* @__PURE__ */ ((I) => (I[I.READY = 0] = "READY", I))(X || {}), m = /* @__PURE__ */ ((I) => (I[I.EXEC = 0] = "EXEC", I[I.COMPLETE = 1] = "COMPLETE", I[I.INSTALL = 2] = "INSTALL", I[I.FORMAT = 3] = "FORMAT", I[I.JS_FN_CALL = 4] = "JS_FN_CALL", I))(m || {}), H = /* @__PURE__ */ ((I) => (I.FN = "__function__", I))(H || {}); | ||
function j(I) { | ||
var H = /* @__PURE__ */ ((I) => (I[I.READY = 0] = "READY", I))(H || {}), m = /* @__PURE__ */ ((I) => (I[I.EXEC = 0] = "EXEC", I[I.COMPLETE = 1] = "COMPLETE", I[I.INSTALL = 2] = "INSTALL", I[I.FORMAT = 3] = "FORMAT", I[I.JS_FN_CALL = 4] = "JS_FN_CALL", I))(m || {}), V = /* @__PURE__ */ ((I) => (I.FN = "__function__", I))(V || {}); | ||
function T(I) { | ||
let g; | ||
return () => (g || (g = I()), g); | ||
} | ||
function O(I, g) { | ||
function f(I, g) { | ||
if (!g) | ||
throw new Error(`a wrong id is provided from worker - callback with ${I} id doesn't exist`); | ||
} | ||
function M(I, g) { | ||
function P(I, g) { | ||
const { [g]: C, ...A } = I; | ||
return A; | ||
} | ||
function W(I, g, C) { | ||
function y(I, g, C) { | ||
return { ...I, [g]: C }; | ||
} | ||
function P(I, g, C) { | ||
function D(I, g, C) { | ||
return { ...I, [g]: C }; | ||
} | ||
const w = "dmFyIGIsIE0sIGssICQsIEIgPSB7IGV4cG9ydHM6IHt9IH07CkIuZXhwb3J0cyA9IGZ1bmN0aW9uKCkgewogIGZ1bmN0aW9uIGUoZCkgewogICAgcmV0dXJuICFpc05hTihwYXJzZUZsb2F0KGQpKSAmJiBpc0Zpbml0ZShkKTsKICB9CiAgZnVuY3Rpb24gdChkKSB7CiAgICByZXR1cm4gZC5jaGFyQXQoMCkudG9VcHBlckNhc2UoKSArIGQuc3Vic3RyaW5nKDEpOwogIH0KICBmdW5jdGlvbiBpKGQpIHsKICAgIHJldHVybiBmdW5jdGlvbigpIHsKICAgICAgcmV0dXJuIHRoaXNbZF07CiAgICB9OwogIH0KICB2YXIgciA9IFsiaXNDb25zdHJ1Y3RvciIsICJpc0V2YWwiLCAiaXNOYXRpdmUiLCAiaXNUb3BsZXZlbCJdLCBuID0gWyJjb2x1bW5OdW1iZXIiLCAibGluZU51bWJlciJdLCBhID0gWyJmaWxlTmFtZSIsICJmdW5jdGlvbk5hbWUiLCAic291cmNlIl0sIGwgPSBbImFyZ3MiXSwgdSA9IFsiZXZhbE9yaWdpbiJdLCBzID0gci5jb25jYXQobiwgYSwgbCwgdSk7CiAgZnVuY3Rpb24gbyhkKSB7CiAgICBpZiAoZCkKICAgICAgZm9yICh2YXIgbSA9IDA7IG0gPCBzLmxlbmd0aDsgbSsrKQogICAgICAgIGRbc1ttXV0gIT09IHZvaWQgMCAmJiB0aGlzWyJzZXQiICsgdChzW21dKV0oZFtzW21dXSk7CiAgfQogIG8ucHJvdG90eXBlID0geyBnZXRBcmdzO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aS5jYWxsKGUpIDogKGUgPSB0ZShlKSwgdCA9IHt9LCByKCJuZXh0IiksIHIoInRocm93IiksIHIoInJldHVybiIpLCB0W1N5bWJvbC5hc3luY0l0ZXJhdG9yXSA9IGZ1bmN0aW9uKCkgewogICAgcmV0dXJuIHRoaXM7CiAgfSwgdCk7CiAgZnVuY3Rpb24gcihuKSB7CiAgICB0W25dID0gZVtuXSAmJiBmdW5jdGlvbihhKSB7CiAgICAgIHJldHVybiBuZXcgUHJvbWlzZShmdW5jdGlvbihsLCB1KSB7CiAgICAgICAgKGZ1bmN0aW9uKHMsIG8sIGMsIHApIHsKICAgICAgICAgIFByb21pc2UucmVzb2x2ZShwKS50aGVuKGZ1bmN0aW9uKGYpIHsKICAgICAgICAgICAgcyh7IHZhbHVlOiBmLCBkb25lOiBjIH0pOwogICAgICAgICAgfSwgbyk7CiAgICAgICAgfSkobCwgdSwgKGEgPSBlW25dKGEpKS5kb25lLCBhLnZhbHVlKTsKICAgICAgfSk7CiAgICB9OwogIH0KfQpjb25zdCBuZSA9IGFzeW5jIChlKSA9PiB7CiAgY29uc3QgdCA9IFtdOwogIGF3YWl0IGFzeW5jIGZ1bmN0aW9uIHIobikgewogICAgdmFyIGEsIGw7CiAgICB0cnkgewogICAgICBmb3IgKHZhciB1LCBzID0gcmUobi52YWx1ZXMoKSk7ICEodSA9IGF3YWl0IHMubmV4dCgpKS5kb25lOyApIHsKICAgICAgICBjb25zdCBvID0gdS52YWx1ZTsKICAgICAgICB0LnB1c2gobyksIG8ua2luZCA9PT0gImRpcmVjdG9yeSIgJiYgYXdhaXQgcihvKTsKICAgICAgfQogICAgfSBjYXRjaCAobykgewogICAgICBhID0geyBlcnJvcjogbyB9OwogICAgfSBmaW5hbGx5IHsKICAgICAgdHJ5IHsKICAgICAgICB1ICYmICF1LmRvbmUgJiYgKGwgPSBzLnJldHVybikgJiYgYXdhaXQgbC5jYWxsKHMpOwogICAgICB9IGZpbmFsbHkgewogICAgICAgIGlmIChhKQogIC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VudHMpOwogICAgfSwgc3luY2ZzOiBhc3luYyAocywgbywgYykgPT4gewogICAgICB0cnkgewogICAgICAgIGNvbnN0IHAgPSB1LmdldExvY2FsU2V0KHMpLCBmID0gYXdhaXQgdS5nZXRSZW1vdGVTZXQocyksIGQgPSBvID8gZiA6IHAsIG0gPSBvID8gcCA6IGY7CiAgICAgICAgYXdhaXQgdS5yZWNvbmNpbGUocywgZCwgbSksIGMobnVsbCk7CiAgICAgIH0gY2F0Y2ggKHApIHsKICAgICAgICBjKHApOwogICAgICB9CiAgICB9LCBnZXRMb2NhbFNldDogKHMpID0+IHsKICAgICAgbGV0IG8gPSAvKiBAX19QVVJFX18gKi8gT2JqZWN0LmNyZWF0ZShudWxsKTsKICAgICAgZnVuY3Rpb24gYyhkKSB7CiAgICAgICAgcmV0dXJuIGQgIT09ICIuIiAmJiBkICE9PSAiLi4iOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHAoZCkgewogICAgICAgIHJldHVybiAobSkgPT4gbC5qb2luMihkLCBtKTsKICAgICAgfQogICAgICBsZXQgZiA9IG4ucmVhZGRpcihzLm1vdW50cG9pbnQpLmZpbHRlcihjKS5tYXAocChzLm1vdW50cG9pbnQpKTsKICAgICAgZm9yICg7IGYubGVuZ3RoOyApIHsKICAgICAgICBsZXQgZCA9IGYucG9wKCksIG0gPSBuLnN0YXQoZCk7CiAgICAgICAgbi5pc0RpcihtLm1vZGUpICYmIGYucHVzaC5hcHBseShmLCBuLnJlYWRkaXIoZCkuZmlsdGVyKGMpLm1hcChwKGQpKSksIG9bZF0gPSB7IHRpbWVzdGFtcDogbS5tdGltZSwgbW9kZTogbS5tb2RlIH07CiAgICAgIH0KICAgICAgcmV0dXJuIHsgdHlwZTogImxvY2FsIiwgZW50cmllczogbyB9OwogICAgfSwgZ2V0UmVtb3RlU2V0OiBhc3luYyAocykgPT4gewogICAgICBjb25zdCBvID0gLyogQF9fUFVSRV9fICovIE9iamVjdC5jcmVhdGUobnVsbCksIGMgPSBh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yOiBudWxsCiAgICAgICAgfTsKICAgICAgfSBjYXRjaCAocykgewogICAgICAgIHJldHVybiB7CiAgICAgICAgICByZXN1bHQ6IG51bGwsCiAgICAgICAgICBzdGRvdXQ6IG51bGwsCiAgICAgICAgICBzdGRlcnI6IG51bGwsCiAgICAgICAgICBlcnJvcjogRmUocy5tZXNzYWdlKQogICAgICAgIH07CiAgICAgIH0gZmluYWxseSB7CiAgICAgICAgY29uc3QgeyBjYWxsYmFja3M6IHMgfSA9IEQoKTsKICAgICAgICBPYmplY3QuZW50cmllcyhsKS5mb3JFYWNoKChbb10pID0+IHsKICAgICAgICAgIHZhciBjOwogICAgICAgICAgZS5nbG9iYWxzLnNldChvLCAoYyA9IGUudG9QeShudWxsKSkgPT0gbnVsbCA/IHZvaWQgMCA6IGMudG9TdHJpbmcoKSk7CiAgICAgICAgfSksIHUuZm9yRWFjaCgobykgPT4gewogICAgICAgICAgZGVsZXRlIHNbb107CiAgICAgICAgfSk7CiAgICAgIH0KICAgIH0sCiAgICBbaC5DT01QTEVURV06IGFzeW5jICh7CiAgICAgIGNvZGU6IGEsCiAgICAgIGxpbmU6IGwsCiAgICAgIGNvbHVtbjogdQogICAgfSkgPT4gewogICAgICBhd2FpdCBlLmxvYWRQYWNrYWdlc0Zyb21JbXBvcnRzKGEpOwogICAgICBjb25zdCBzID0gZS5nbG9iYWxzLmdldCgiZ2V0X2F1dG9jb21wbGV0aW9uIikoYSwgbCwgdSk7CiAgICAgIHJldHVybiB7IHJlc3VsdDogdihzLCBlKSwgZXJyb3I6IG51bGwgfTsKICAgIH0sCiAgICBbaC5JTlNUQUxMXTogYXN5bmMgKHsgcGFja2FnZXM6IGEgfSkgPT4gewogICAgICBjb25zdCBsID0gYXdhaXQgZS5nbG9iYWxzLmdldCgiaW5zdGFsbF9wYWNha2dlIikoYVswXSk7CiAgICAgIHJldHVybiB2KGwsIGUpOwogICAgfSwKICAgIFtoLkZPUk1BVF06IGFzeW5jICh7IGNvZGU6IGEgfSkgPT4gewogICAgICBjb25zdCBsID0gZS5nbG9iYWxzLmdldCgiZm9ybWF0X2NvZGUiKShhKTsKICAgICAgcmV0dXJuIHsgcmVzdWx0OiB2KGwsIGUpLCBlcnJvcjogbnVsbCB9OwogICAgfQogIH07CiAgb25tZXNzYWdlID0gYXN5bmMgZnVuY3Rpb24obCkgewogICAgY29uc3QgeyBpZDogdSwgYWN0aW9uOiBzID0gaC5FWEVDLCBkYXRhOiBvIH0gPSBsLmRhdGE7CiAgICBpZiAocyA9PT0gaC5KU19GTl9DQUxMKQogICAgICByKG8sIHUpOwogICAgZWxzZSB7CiAgICAgIGxldCBjOwogICAgICBzd2l0Y2ggKHMpIHsKICAgICAgICBjYXNlIGguRVhFQzoKICAgICAgICAgIGMgPSBhd2FpdCBpW2guRVhFQ10obyk7CiAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIGguQ09NUExFVEU6CiAgICAgICAgICBjID0gYXdhaXQgaVtoLkNPTVBMRVRFXShvKTsKICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgaC5JTlNUQUxMOgogICAgICAgICAgYyA9IGF3YWl0IGlbaC5JTlNUQUxMXShvKTsKICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgaC5GT1JNQVQ6CiAgICAgICAgICBjID0gYXdhaXQgaVtoLkZPUk1BVF0obyk7CiAgICAgICAgICBicmVhazsKICAgICAgfQogICAgICBwb3N0TWVzc2FnZSh7CiAgICAgICAgZGF0YTogYywKICAgICAgICBpZDogdSwKICAgICAgICBhY3Rpb246IHMKICAgICAgfSk7CiAgICB9CiAgfTsKICBmdW5jdGlvbiByKGEsIGwpIHsKICAgIGNvbnN0IHsgcmVzdWx0OiB1LCBlcnJvcjogcyB9ID0gYSwgeyBjYWxsYmFja3M6IG8gfSA9IEQoKTsKICAgIHMgJiYgb1tsXS5yZWplY3QocyksIG9bbF0ucmVzb2x2ZSh1KTsKICB9CiAgZnVuY3Rpb24gbihhLCBsKSB7CiAgICByZXR1cm4gYXN5bmMgKC4uLnUpID0+IG5ldyBQcm9taXNlKChzLCBvKSA9PiB7CiAgICAgIGNvbnN0IHsgY2FsbGJhY2tzOiBjLCBjb21tYW5kVW5pcXVlSWQ6IHAgfSA9IEQoKTsKICAgICAgcG9zdE1lc3NhZ2UoewogICAgICAgIGFjdGlvbjogaC5KU19GTl9DQUxMLAogICAgICAgIGRhdGE6IHsKICAgICAgICAgIGFyZ3M6IHUsCiAgICAgICAgICBuYW1lOiBhCiAgICAgICAgfSwKICAgICAgICBpZDogcAogICAgICB9KSwgbC5wdXNoKHApLCBOZSh7CiAgICAgICAgY2FsbGJhY2tzOiBMZShjLCBwLCB7CiAgICAgICAgICByZXNvbHZlOiBzLAogICAgICAgICAgcmVqZWN0OiBvCiAgICAgICAgfSksCiAgICAgICAgY29tbWFuZFVuaXF1ZUlkOiBwICsgMQogICAgICB9KTsKICAgIH0pOwogIH0KfQp4ZSgpOwo=", Y = typeof window < "u" && window.Blob && new Blob([atob(w)], { type: "text/javascript;charset=utf-8" }); | ||
const w = "dmFyIGIsIE0sIGssICQsIEIgPSB7IGV4cG9ydHM6IHt9IH07CkIuZXhwb3J0cyA9IGZ1bmN0aW9uKCkgewogIGZ1bmN0aW9uIGUoZCkgewogICAgcmV0dXJuICFpc05hTihwYXJzZUZsb2F0KGQpKSAmJiBpc0Zpbml0ZShkKTsKICB9CiAgZnVuY3Rpb24gdChkKSB7CiAgICByZXR1cm4gZC5jaGFyQXQoMCkudG9VcHBlckNhc2UoKSArIGQuc3Vic3RyaW5nKDEpOwogIH0KICBmdW5jdGlvbiBvKGQpIHsKICAgIHJldHVybiBmdW5jdGlvbigpIHsKICAgICAgcmV0dXJuIHRoaXNbZF07CiAgICB9OwogIH0KICB2YXIgciA9IFsiaXNDb25zdHJ1Y3RvciIsICJpc0V2YWwiLCAiaXNOYXRpdmUiLCAiaXNUb3BsZXZlbCJdLCBuID0gWyJjb2x1bW5OdW1iZXIiLCAibGluZU51bWJlciJdLCBhID0gWyJ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bihkKSB7CiAgICAgIHJldHVybiBmdW5jdGlvbihtKSB7CiAgICAgICAgdGhpc1tkXSA9IEJvb2xlYW4obSk7CiAgICAgIH07CiAgICB9KHJbY10pOwogIGZvciAodmFyIHAgPSAwOyBwIDwgbi5sZW5ndGg7IHArKykKICAgIGkucHJvdG90eXBlWyJnZXQiICsgdChuW3BdKV0gPSBvKG5bcF0pLCBpLnByb3RvdHlwZVsic2V0IiArIHQobltwXSldID0gZnVuY3Rpb24oZCkgewogICAgICByZXR1cm4gZnVuY3Rpb24obSkgewogICAgICAgIGlmICghZShtKSkKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoZCArICIgbXVzdCBiZSBhIE51bWJlciIpOwogICAgICAgIHRoaXNbZF0gPSBOdW1iZXIobSk7CiAgICAgIH07CiAgICB9KG5bcF0pOwogIGZvciAodmFyIGYgPSAwOyBmIDwgYS5sZW5ndGg7IGYrKykKICAgIGkucHJvdG90eXBlWyJnZXQiICsgdChhW2ZdKV0gPSBvKGFbZl0pLCBpLnByb3RvdHlwZVsic2V0IiArIHQoYVtmXSldID0gZnVuY3Rpb24oZCkgewogICAgICByZXR1cm4gZnVuY3Rpb24obSkgewogICAgICAgIHRoaXNbZF0gPSBTdHJpbmcobSk7CiAgICAgIH07CiAgICB9KGFbZl0pOwogIHJldHVybiBpOwp9KCk7CnZhciBlZSA9IChiID0gQi5leHBvcnRzLCBNID0gLyhefEApXFMrOlxkKy8sIGsgPSAvXlxzKmF0IC4qKFxTKzpcZCt8XChuYXRpdmVcKSkvbSwgJCA9IC9eKGV2YWxAKT8oXFtuYXRpdmUgY29kZV0pPyQvLCB7IHBhcnNlOiBmdW5jdGlvbihlKSB7CiAgaWYgKGUuc3RhY2t0cmFjZSAhPT0gdm9pZCAwIHx8IGVbIm9wZXJhI3NvdXJjZWxvYyJdICE9PSB2b2lkIDApCiAgICByZXR1cm4gdGhpcy5wYXJzZU9wZXJhKGUpOwogIGlmIChlLnN0YWNrICYmIGUuc3RhY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RyeSB7CiAgICAgIGZvciAodmFyIHUsIHMgPSByZShuLnZhbHVlcygpKTsgISh1ID0gYXdhaXQgcy5uZXh0KCkpLmRvbmU7ICkgewogICAgICAgIGNvbnN0IGkgPSB1LnZhbHVlOwogICAgICAgIHQucHVzaChpKSwgaS5raW5kID09PSAiZGlyZWN0b3J5IiAmJiBhd2FpdCByKGkpOwogICAgICB9CiAgICB9IGNhdGNoIChpKSB7CiAgICAgIGEgPSB7IGVycm9yOiBpIH07CiAgICB9IGZpbmFsbHkgewogICAgICB0cnkgewogICAgICAgIHUgJiYgIXUuZG9uZSAmJiAobCA9IHMucmV0dXJuKSAmJiBhd2FpdCBsLmNhbGwocyk7CiAgICAgIH0gZmluYWxseSB7CiAgICAgICAgaWYgKGEpCiAgICAgICAgICB0aHJvdyBhLmVycm9yOwogICAgICB9CiAgICB9CiAgfShlKTsKICBjb25zdCBvID0gLyogQF9fUFVSRV9fICovIG5ldyBNYXAoKTsKICBvLnNldCgiLiIsIGUpOwogIGZvciAoY29uc3QgciBvZiB0KSB7CiAgICBjb25zdCBuID0gKGF3YWl0IGUucmVzb2x2ZShyKSkuam9pbigiLyIpOwogICAgby5zZXQobiwgcik7CiAgfQogIHJldHVybiBvOwp9OwpmdW5jdGlvbiBvZShlLCB0KSB7CiAgbGV0IG87CiAgbyA9IHQuc3RkTGliVVJMICE9IG51bGwgPyB0LnN0ZExpYlVSTCA6IHQuaW5kZXhVUkwgKyAicHl0aG9uX3N0ZGxpYi56aXAiLCBmdW5jdGlvbihyLCBuKSB7CiAgICBjb25zdCBhID0gVihuKTsKICAgIHIucHJlUnVuLnB1c2goKCkgPT4gewogICAgICBjb25zdCBsID0gci5fcHlfdmVyc2lvbl9tYWpvcigpLCB1ID0gci5fcHlfdmVyc2lvbl9taW5vcigpOwogICAgICByLkZTLm1rZGlyVHJlZSgiL2xpYiIpLCByLkZTLm1rZGlyVHJlZShgL2xpYi9weXRob24ke2x9LiR7dX0vc2l0ZS1wYWNrYWdlc2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wgdC5fbm9kZV9tb3VudHMpLCBlLnByZVJ1bi5wdXNoKCgpID0+IGZ1bmN0aW9uKHIpIHsKICAgIGNvbnN0IG4gPSByLkZTLCBhID0gci5GUy5maWxlc3lzdGVtcy5NRU1GUywgbCA9IHIuUEFUSCwgdSA9IHsgRElSX01PREU6IDE2ODk1LCBGSUxFX01PREU6IDMzMjc5LCBtb3VudDogZnVuY3Rpb24ocykgewogICAgICBpZiAoIXMub3B0cy5maWxlU3lzdGVtSGFuZGxlKQogICAgICAgIHRocm93IG5ldyBFcnJvcigib3B0cy5maWxlU3lzdGVtSGFuZGxlIGlzIHJlcXVpcmVkIik7CiAgICAgIHJldHVybiBhLm1vdW50LmFwcGx5KG51bGwsIGFyZ3VtZW50cyk7CiAgICB9LCBzeW5jZnM6IGFzeW5jIChzLCBpLCBjKSA9PiB7CiAgICAgIHRyeSB7CiAgICAgICAgY29uc3QgcCA9IHUuZ2V0TG9jYWxTZXQocyksIGYgPSBhd2FpdCB1LmdldFJlbW90ZVNldChzKSwgZCA9IGkgPyBmIDogcCwgbSA9IGkgPyBwIDogZjsKICAgICAgICBhd2FpdCB1LnJlY29uY2lsZShzLCBkLCBtKSwgYyhudWxsKTsKICAgICAgfSBjYXRjaCAocCkgewogICAgICAgIGMocCk7CiAgICAgIH0KICAgIH0sIGdldExvY2FsU2V0OiAocykgPT4gewogICAgICBsZXQgaSA9IC8qIEBfX1BVUkVfXyAqLyBPYmplY3QuY3JlYXRlKG51bGwpOwogICAgICBmdW5jdGlvbiBjKGQpIHsKICAgICAgICByZXR1cm4gZCAhPT0gIi4iICYmIGQgIT09ICIuLiI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcChkKSB7CiAgICAgICAgcmV0dXJuIChtKSA9PiBsLmpvaW4yKGQsIG0pOwogICAgICB9CiAgICAgIGxldCBmID0gbi5yZWFkZGlyKHMubW91bnRwb2ludCkuZmlsdGVyKGMpLm1hcChwKHMubW91bnRwb2ludCkpOwogICAgICBmb3IgKDs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AgICAgIGlmIChzLmtpbmQgPT09ICJkaXJlY3RvcnkiKQogICAgICAgIHJldHVybiB7IG1vZGU6IHUuRElSX01PREUsIHRpbWVzdGFtcDogbmV3IERhdGUoKSB9OwogICAgICB0aHJvdyBuZXcgRXJyb3IoInVua25vd24ga2luZDogIiArIHMua2luZCk7CiAgICB9LCBzdG9yZVJlbW90ZUVudHJ5OiBhc3luYyAocywgaSwgYykgPT4gewogICAgICBjb25zdCBwID0gcy5nZXQobC5kaXJuYW1lKGkpKSwgZiA9IG4uaXNGaWxlKGMubW9kZSkgPyBhd2FpdCBwLmdldEZpbGVIYW5kbGUobC5iYXNlbmFtZShpKSwgeyBjcmVhdGU6ICEwIH0pIDogYXdhaXQgcC5nZXREaXJlY3RvcnlIYW5kbGUobC5iYXNlbmFtZShpKSwgeyBjcmVhdGU6ICEwIH0pOwogICAgICBpZiAoZi5raW5kID09PSAiZmlsZSIpIHsKICAgICAgICBjb25zdCBkID0gYXdhaXQgZi5jcmVhdGVXcml0YWJsZSgpOwogICAgICAgIGF3YWl0IGQud3JpdGUoYy5jb250ZW50cyksIGF3YWl0IGQuY2xvc2UoKTsKICAgICAgfQogICAgICBzLnNldChpLCBmKTsKICAgIH0sIHJlbW92ZVJlbW90ZUVudHJ5OiBhc3luYyAocywgaSkgPT4gewogICAgICBhd2FpdCBzLmdldChsLmRpcm5hbWUoaSkpLnJlbW92ZUVudHJ5KGwuYmFzZW5hbWUoaSkpLCBzLmRlbGV0ZShpKTsKICAgIH0sIHJlY29uY2lsZTogYXN5bmMgKHMsIGksIGMpID0+IHsKICAgICAgbGV0IHAgPSAwOwogICAgICBjb25zdCBmID0gW107CiAgICAgIE9iamVjdC5rZXlzKGkuZW50cmllcykuZm9yRWFjaChmdW5jdGlvbih5KSB7CiAgICAgICAgY29uc3QgZyA9IGkuZW50cmllc1t5XSwgdyA9IGMuZW50cmllc1t5XTsKICAgICAgICAoIXcgfHwgbi5pc0ZpbGUoZy5tb2RlKSAmJiBnLnRpbWVzdGFtcC5nZXRUaW1lKCkgPiB3LnRpbWVzdGFtcC5nZXRUaW1lKCkpICYmIChmLnB1c2goeSksIHArKyk7CiAgICAgIH0pLCBmLnNvcnQoKTsKICAgICAgY29uc3QgZCA9IFtdOwogICAgICBpZiAoT2JqZWN0LmtleXMoYy5lbnRyaWVzKS5mb3JFYWNoKGZ1bmN0aW9uKHkpIHsKICAgICAgICBpLmVudHJpZXNbeV0gfHwgKGQucHVzaCh5KSwgcCsrKTsKICAgICAgfSksIGQuc29ydCgpLnJldmVyc2UoKSwgIXApCiAgICAgICAgcmV0dXJuOwogICAgICBjb25zdCBtID0gaS50eXBlID09PSAicmVtb3RlIiA/IGkuaGFuZGxlcyA6IGMuaGFuZGxlczsKICAgICAgZm9yIChjb25zdCB5IG9mIGYpIHsKICAgICAgICBjb25zdCBnID0gbC5ub3JtYWxpemUoeS5yZXBsYWNlKHMubW91bnRwb2ludCwgIi8iKSkuc3Vic3RyaW5nKDEpOwogICAgICAgIGlmIChjLnR5cGUgPT09ICJsb2NhbCIpIHsKICAgICAgICAgIGNvbnN0IHcgPSBtLmdldChnKSwgRiA9IGF3YWl0IHUubG9hZFJlbW90ZUVudHJ5KHcpOwogICAgICAgICAgdS5zdG9yZUxvY2FsRW50cnkoeSwgRik7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGNvbnN0IHcgPSB1LmxvYWRMb2NhbEVudHJ5KHkpOwogICAgICAgICAgYXdhaXQgdS5zdG9yZVJlbW90ZUVudHJ5KG0sIGcsIHcpOwogICAgICAgIH0KICAgICAgfQogICAgICBmb3IgKGNvbnN0IHkgb2YgZCkKICAgICAgICBpZiAoYy50eXBlID09PSAibG9jYWwiKQogICAgICAgICAgdS5yZW1vdmVMb2NhbEVudHJ5KHkpOwogICAgICAgIGVsc2UgewogICAgICAgICAgY29uc3QgZyA9IGwubm9ybWFsaXplKHkucmVwbGFjZShzLm1vdW50cG9pbnQsICIvIikpLnN1YnN0cmluZygxKTsKICAgICAgICA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GVycHJldGVyKGNvZGUsIFtnbG9iYWxzKCksIGxvY2FscygpXSkKCiAgICBjb21wbGV0aW9ucyA9IHJlc3VsdC5jb21wbGV0ZShsaW5lLCBjb2x1bW4pCgogICAgbWF0Y2hlcyA9IFtdCiAgICBmb3IgY29tcCBpbiBjb21wbGV0aW9uczoKICAgICAgICBtYXRjaGVzLmFwcGVuZChkaWN0KAogICAgICAgICAgICBuYW1lPWNvbXAubmFtZSwKICAgICAgICAgICAgdHlwZT1jb21wLnR5cGUsCiAgICAgICAgICAgIGRlc2NyaXB0aW9uPWNvbXAuZGVzY3JpcHRpb24sCiAgICAgICAgICAgIGZ1bGxfbmFtZT1jb21wLmZ1bGxfbmFtZQogICAgICAgICkpCgogICAgcmV0dXJuIHsKICAgICAgICAibWF0Y2hlcyI6IG1hdGNoZXMKICAgIH0KCgphc3luYyBkZWYgaW5zdGFsbF9wYWNha2dlKHBhY2thZ2UpOgogICAgdHJ5OgogICAgICAgIGF3YWl0IG1pY3JvcGlwLmluc3RhbGwocGFja2FnZSwga2VlcF9nb2luZz1UcnVlKQogICAgICAgIHJldHVybiB7CiAgICAgICAgICAgICJzdWNjZXNzIjogVHJ1ZQogICAgICAgIH0KICAgIGV4Y2VwdCBFeGNlcHRpb24gYXMgZToKICAgICAgICByZXR1cm4gewogICAgICAgICAgICAic3VjY2VzcyI6IEZhbHNlLAogICAgICAgICAgICAiZXJyb3IiOiBzdHIoZSkKICAgICAgICB9CgoKZGVmIGZvcm1hdF9jb2RlKGNvZGUsIG9wdGlvbnMpOgogICAgaWYgb3B0aW9uczoKICAgICAgICBtb2RlID0gRmlsZU1vZGUoKipvcHRpb25zKQogICAgICAgIHJldHVybiBmb3JtYXRfc3RyKGNvZGUsIG1vZGU9bW9kZSkKICAgIHJldHVybiBmb3JtYXRfc3RyKGNvZGUsIG1vZGU9RmlsZU1vZGUoKSkKYDsKZnVuY3Rpb24gbGUoZSwgdCwgbykgewogIHJldHVybiB0IGluIGUgPyBPYmplY3QuZ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gdHJ5IHsKICAgICAgICBhd2FpdCBlLmxvYWRQYWNrYWdlc0Zyb21JbXBvcnRzKGEpLCBlLnJ1blB5dGhvbigiaW1wb3J0IHN5cywgaW87IHN5cy5zdGRvdXQgPSBpby5TdHJpbmdJTygpOyBzeXMuc3RkZXJyID0gaW8uU3RyaW5nSU8oKSIpOwogICAgICAgIGNvbnN0IHMgPSBhd2FpdCBlLnJ1blB5dGhvbkFzeW5jKGEpLCBpID0gZS5ydW5QeXRob24oImltcG9ydCBzeXM7IHN5cy5zdGRvdXQuZ2V0dmFsdWUoKSIpLnRyaW0oKSwgYyA9IGUucnVuUHl0aG9uKCJpbXBvcnQgc3lzOyBzeXMuc3RkZXJyLmdldHZhbHVlKCkiKS50cmltKCk7CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIHJlc3VsdDogdihzLCBlKSwKICAgICAgICAgIHN0ZG91dDogdihpLCBlKSwKICAgICAgICAgIHN0ZGVycjogYywKICAgICAgICAgIGVycm9yOiBudWxsCiAgICAgICAgfTsKICAgICAgfSBjYXRjaCAocykgewogICAgICAgIHJldHVybiB7CiAgICAgICAgICByZXN1bHQ6IG51bGwsCiAgICAgICAgICBzdGRvdXQ6IG51bGwsCiAgICAgICAgICBzdGRlcnI6IG51bGwsCiAgICAgICAgICBlcnJvcjogRmUocy5tZXNzYWdlKQogICAgICAgIH07CiAgICAgIH0gZmluYWxseSB7CiAgICAgICAgY29uc3QgeyBjYWxsYmFja3M6IHMgfSA9IEQoKTsKICAgICAgICBPYmplY3QuZW50cmllcyhsKS5mb3JFYWNoKChbaV0pID0+IHsKICAgICAgICAgIHZhciBjOwogICAgICAgICAgZS5nbG9iYWxzLnNldChpLCAoYyA9IGUudG9QeShudWxsKSkgPT0gbnVsbCA/IHZvaWQgMCA6IGMudG9TdHJpbmcoKSk7CiAgICAgICAgfSksIHUuZm9yRWFjaCgoaSkgPT4gewogICAgICAgICAgZGVsZXRlIHNbaV07CiAgICAgICAgfSk7CiAgICAgIH0KICAgIH0sCiAgICBbaC5DT01QTEVURV06IGFzeW5jICh7CiAgICAgIGNvZGU6IGEsCiAgICAgIGxpbmU6IGwsCiAgICAgIGNvbHVtbjogdQogICAgfSkgPT4gewogICAgICBhd2FpdCBlLmxvYWRQYWNrYWdlc0Zyb21JbXBvcnRzKGEpOwogICAgICBjb25zdCBzID0gZS5nbG9iYWxzLmdldCgiZ2V0X2F1dG9jb21wbGV0aW9uIikoYSwgbCwgdSk7CiAgICAgIHJldHVybiB7IHJlc3VsdDogdihzLCBlKSwgZXJyb3I6IG51bGwgfTsKICAgIH0sCiAgICBbaC5JTlNUQUxMXTogYXN5bmMgKHsgcGFja2FnZXM6IGEgfSkgPT4gewogICAgICBjb25zdCBsID0gYXdhaXQgZS5nbG9iYWxzLmdldCgiaW5zdGFsbF9wYWNha2dlIikoYVswXSk7CiAgICAgIHJldHVybiB2KGwsIGUpOwogICAgfSwKICAgIFtoLkZPUk1BVF06IGFzeW5jICh7CiAgICAgIGNvZGU6IGEsCiAgICAgIG9wdGlvbnM6IGwgPSB7fQogICAgfSkgPT4gewogICAgICBjb25zdCB1ID0gZS5nbG9iYWxzLmdldCgiZm9ybWF0X2NvZGUiKShhLCBlLnRvUHkobCkpOwogICAgICByZXR1cm4geyByZXN1bHQ6IHYodSwgZSksIGVycm9yOiBudWxsIH07CiAgICB9CiAgfTsKICBvbm1lc3NhZ2UgPSBhc3luYyBmdW5jdGlvbihsKSB7CiAgICBjb25zdCB7IGlkOiB1LCBhY3Rpb246IHMgPSBoLkVYRUMsIGRhdGE6IGkgfSA9IGwuZGF0YTsKICAgIGlmIChzID09PSBoLkpTX0ZOX0NBTEwpCiAgICAgIHIoaSwgdSk7CiAgICBlbHNlIHsKICAgICAgbGV0IGM7CiAgICAgIHN3aXRjaCAocykgewogICAgICAgIGNhc2UgaC5FWEVDOgogICAgICAgICAgYyA9IGF3YWl0IG9baC5FWEVDXShpKTsKICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgaC5DT01QTEVURToKICAgICAgICAgIGMgPSBhd2FpdCBvW2guQ09NUExFVEVdKGkpOwogICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBoLklOU1RBTEw6CiAgICAgICAgICBjID0gYXdhaXQgb1toLklOU1RBTExdKGkpOwogICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBoLkZPUk1BVDoKICAgICAgICAgIGMgPSBhd2FpdCBvW2guRk9STUFUXShpKTsKICAgICAgICAgIGJyZWFrOwogICAgICB9CiAgICAgIHBvc3RNZXNzYWdlKHsKICAgICAgICBkYXRhOiBjLAogICAgICAgIGlkOiB1LAogICAgICAgIGFjdGlvbjogcwogICAgICB9KTsKICAgIH0KICB9OwogIGZ1bmN0aW9uIHIoYSwgbCkgewogICAgY29uc3QgeyByZXN1bHQ6IHUsIGVycm9yOiBzIH0gPSBhLCB7IGNhbGxiYWNrczogaSB9ID0gRCgpOwogICAgcyAmJiBpW2xdLnJlamVjdChzKSwgaVtsXS5yZXNvbHZlKHUpOwogIH0KICBmdW5jdGlvbiBuKGEsIGwpIHsKICAgIHJldHVybiBhc3luYyAoLi4udSkgPT4gbmV3IFByb21pc2UoKHMsIGkpID0+IHsKICAgICAgY29uc3QgeyBjYWxsYmFja3M6IGMsIGNvbW1hbmRVbmlxdWVJZDogcCB9ID0gRCgpOwogICAgICBwb3N0TWVzc2FnZSh7CiAgICAgICAgYWN0aW9uOiBoLkpTX0ZOX0NBTEwsCiAgICAgICAgZGF0YTogewogICAgICAgICAgYXJnczogdSwKICAgICAgICAgIG5hbWU6IGEKICAgICAgICB9LAogICAgICAgIGlkOiBwCiAgICAgIH0pLCBsLnB1c2gocCksIE5lKHsKICAgICAgICBjYWxsYmFja3M6IExlKGMsIHAsIHsKICAgICAgICAgIHJlc29sdmU6IHMsCiAgICAgICAgICByZWplY3Q6IGkKICAgICAgICB9KSwKICAgICAgICBjb21tYW5kVW5pcXVlSWQ6IHAgKyAxCiAgICAgIH0pOwogICAgfSk7CiAgfQp9CnhlKCk7Cg==", Y = typeof window < "u" && window.Blob && new Blob([atob(w)], { type: "text/javascript;charset=utf-8" }); | ||
function x() { | ||
@@ -172,4 +172,4 @@ const I = Y && (window.URL || window.webkitURL).createObjectURL(Y); | ||
} | ||
const D = Boolean(globalThis.Worker), [B, o] = T.create({ | ||
config: f, | ||
const M = Boolean(globalThis.Worker), [B, o] = j.create({ | ||
config: O, | ||
pyodideWorker: null, | ||
@@ -190,5 +190,5 @@ callbacks: {}, | ||
} | ||
}, E = j(function() { | ||
}, E = T(function() { | ||
return new Promise((g, C) => { | ||
D || C(new Error(`your browser does | ||
M || C(new Error(`your browser does | ||
t support web workers!`)); | ||
@@ -198,10 +198,10 @@ const A = new x(); | ||
var b; | ||
((b = l.data) == null ? void 0 : b.status) === X.READY ? (o({ pyodideWorker: A, interruptBuffer: l.data.interruptBuffer }), A.onmessage = function(Z) { | ||
const { action: G, id: S, data: y } = Z.data; | ||
switch (G) { | ||
((b = l.data) == null ? void 0 : b.status) === H.READY ? (o({ pyodideWorker: A, interruptBuffer: l.data.interruptBuffer }), A.onmessage = function(G) { | ||
const { action: Z, id: s, data: p } = G.data; | ||
switch (Z) { | ||
case m.JS_FN_CALL: | ||
_(S, y); | ||
_(s, p); | ||
break; | ||
default: | ||
q(S, y); | ||
q(s, p); | ||
break; | ||
@@ -219,3 +219,3 @@ } | ||
K.command(II(I), m.EXEC), o({ | ||
callbacks: W(A, i, { resolve: g, reject: C }) | ||
callbacks: y(A, i, { resolve: g, reject: C }) | ||
}); | ||
@@ -228,7 +228,7 @@ }); | ||
const { commandUniqueId: A, callbacks: i } = B(), { code: l, line: b, column: c } = I; | ||
let Z = b, G = c; | ||
b || (Z = l.split(` | ||
`).length), G || (G = l.split(` | ||
`)[Z - 1].length), K.command({ code: l, line: Z, column: G }, m.COMPLETE), o({ | ||
callbacks: W(i, A, { | ||
let G = b, Z = c; | ||
b || (G = l.split(` | ||
`).length), Z || (Z = l.split(` | ||
`)[G - 1].length), K.command({ code: l, line: G, column: Z }, m.COMPLETE), o({ | ||
callbacks: y(i, A, { | ||
resolve: g, | ||
@@ -245,3 +245,3 @@ reject: C | ||
K.command({ packages: I }, m.INSTALL), o({ | ||
callbacks: W(A, i, { | ||
callbacks: y(A, i, { | ||
resolve: g, | ||
@@ -257,3 +257,3 @@ reject: C | ||
K.command(I, m.FORMAT), o({ | ||
callbacks: W(A, i, { | ||
callbacks: y(A, i, { | ||
resolve: g, | ||
@@ -276,6 +276,6 @@ reject: C | ||
const { callbacks: C } = B(); | ||
O(I, Boolean(C[I])); | ||
f(I, Boolean(C[I])); | ||
const { resolve: A, reject: i } = C[I]; | ||
if (o({ | ||
callbacks: M(C, I) | ||
callbacks: P(C, I) | ||
}), g.error) { | ||
@@ -301,6 +301,6 @@ i == null || i(g.error); | ||
return Object.entries(I).reduce((C, [A, i]) => (typeof i == "function" ? (C[A] = { | ||
type: H.FN, | ||
type: V.FN, | ||
name: i.name | ||
}, o({ | ||
jsFunctions: P(g, i.name, i) | ||
jsFunctions: D(g, i.name, i) | ||
})) : C[A] = i, C), {}); | ||
@@ -316,4 +316,4 @@ } | ||
m as ActionType, | ||
X as ChannelSetupStatus, | ||
H as PayloadType, | ||
H as ChannelSetupStatus, | ||
V as PayloadType, | ||
CI as complete, | ||
@@ -320,0 +320,0 @@ gI as exec, |
@@ -1,7 +0,7 @@ | ||
(function(b,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(b=typeof globalThis<"u"?globalThis:b||self,u(b.xPython={}))})(this,function(b){"use strict";function u(I,g,C){return g in I?Object.defineProperty(I,g,{value:C,enumerable:!0,configurable:!0,writable:!0}):I[g]=C,I}function X(I,g){var C=Object.keys(I);if(Object.getOwnPropertySymbols){var A=Object.getOwnPropertySymbols(I);g&&(A=A.filter(function(i){return Object.getOwnPropertyDescriptor(I,i).enumerable})),C.push.apply(C,A)}return C}function H(I){for(var g=1;g<arguments.length;g++){var C=arguments[g]!=null?arguments[g]:{};g%2?X(Object(C),!0).forEach(function(A){u(I,A,C[A])}):Object.getOwnPropertyDescriptors?Object.defineProperties(I,Object.getOwnPropertyDescriptors(C)):X(Object(C)).forEach(function(A){Object.defineProperty(I,A,Object.getOwnPropertyDescriptor(C,A))})}return I}function k(){for(var I=arguments.length,g=new Array(I),C=0;C<I;C++)g[C]=arguments[C];return function(A){return g.reduceRight(function(i,l){return l(i)},A)}}function s(I){return function g(){for(var C=this,A=arguments.length,i=new Array(A),l=0;l<A;l++)i[l]=arguments[l];return i.length>=I.length?I.apply(this,i):function(){for(var Z=arguments.length,d=new Array(Z),G=0;G<Z;G++)d[G]=arguments[G];return g.apply(C,[].concat(i,d))}}}function p(I){return{}.toString.call(I).includes("Object")}function R(I){return!Object.keys(I).length}function S(I){return typeof I=="function"}function J(I,g){return Object.prototype.hasOwnProperty.call(I,g)}function F(I,g){return p(g)||o("changeType"),Object.keys(g).some(function(C){return!J(I,C)})&&o("changeField"),g}function L(I){S(I)||o("selectorType")}function v(I){S(I)||p(I)||o("handlerType"),p(I)&&Object.values(I).some(function(g){return!S(g)})&&o("handlersType")}function r(I){I||o("initialIsRequired"),p(I)||o("initialType"),R(I)&&o("initialContent")}function N(I,g){throw new Error(I[g]||I.default)}var U={initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"},o=s(N)(U),W={changes:F,selector:L,handler:v,initial:r};function Q(I){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};W.initial(I),W.handler(g);var C={current:I},A=s(T)(C,g),i=s(f)(C),l=s(W.changes)(I),Z=s(z)(C);function d(){var c=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(a){return a};return W.selector(c),c(C.current)}function G(c){k(A,i,l,Z)(c)}return[d,G]}function z(I,g){return S(g)?g(I.current):g}function f(I,g){return I.current=H(H({},I.current),g),g}function T(I,g,C){return S(g)?g(I.current):Object.keys(C).forEach(function(A){var i;return(i=g[A])===null||i===void 0?void 0:i.call(g,I.current[A])}),C}var j={create:Q};const O={loadPyodideOptions:{indexURL:"https://cdn.jsdelivr.net/pyodide/v0.23.0/full/"}};var V=(I=>(I[I.READY=0]="READY",I))(V||{}),m=(I=>(I[I.EXEC=0]="EXEC",I[I.COMPLETE=1]="COMPLETE",I[I.INSTALL=2]="INSTALL",I[I.FORMAT=3]="FORMAT",I[I.JS_FN_CALL=4]="JS_FN_CALL",I))(m||{}),Y=(I=>(I.FN="__function__",I))(Y||{});function M(I){let g;return()=>(g||(g=I()),g)}function P(I,g){if(!g)throw new Error(`a wrong id is provided from worker - callback with ${I} id doesn't exist`)}function x(I,g){const{[g]:C,...A}=I;return A}function y(I,g,C){return{...I,[g]:C}}function D(I,g,C){return{...I,[g]:C}}const h="dmFyIGIsIE0sIGssICQsIEIgPSB7IGV4cG9ydHM6IHt9IH07CkIuZXhwb3J0cyA9IGZ1bmN0aW9uKCkgewogIGZ1bmN0aW9uIGUoZCkgewogICAgcmV0dXJuICFpc05hTihwYXJzZUZsb2F0KGQpKSAmJiBpc0Zpbml0ZShkKTsKICB9CiAgZnVuY3Rpb24gdChkKSB7CiAgICByZXR1cm4gZC5jaGFyQXQoMCkudG9VcHBlckNhc2UoKSArIGQuc3Vic3RyaW5nKDEpOwogIH0KICBmdW5jdGlvbiBpKGQpIHsKICAgIHJldHVybiBmdW5jdGlvbigpIHsKICAgICAgcmV0dXJuIHRoaXNbZF07CiAgICB9OwogIH0KICB2YXIgciA9IFsiaXNDb25zdHJ1Y3RvciIsICJpc0V2YWwiLCAiaXNOYXRpdmUiLCAiaXNUb3BsZXZlbCJdLCBuID0gWyJjb2x1bW5OdW1iZXIiLCAibGluZU51bWJlciJdLCBhID0gWyJmaWxlTmFtZSIsICJmdW5jdGlvbk5hbWUiLCAic291cmNlIl0sIGw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A9PiB7CiAgICB0cnkgewogICAgICBnbG9iYWxUaGlzLmltcG9ydFNjcmlwdHMoZSk7CiAgICB9IGNhdGNoICh0KSB7CiAgICAgIGlmICghKHQgaW5zdGFuY2VvZiBUeXBlRXJyb3IpKQogICAgICAgIHRocm93IHQ7CiAgICAgIGF3YWl0IGltcG9ydCgKICAgICAgICAvKiB3ZWJwYWNrSWdub3JlOiB0cnVlICovCiAgICAgICAgZQogICAgICApOwogICAgfQogIH07CmVsc2UgewogIGlmICghRSkKICAgIHRocm93IG5ldyBFcnJvcigiQ2Fubm90IGRldGVybWluZSBydW50aW1lIGVudmlyb25tZW50Iik7CiAgTiA9IGFzeW5jIGZ1bmN0aW9uKGUpIHsKICAgIGUuc3RhcnRzV2l0aCgiZmlsZTovLyIpICYmIChlID0gZS5zbGljZSg3KSksIGUuaW5jbHVkZXMoIjovLyIpID8gWC5ydW5JblRoaXNDb250ZXh0KGF3YWl0IChhd2FpdCBDKGUpKS50ZXh0KCkpIDogYXdhaXQgaW1wb3J0KAogICAgICAvKiB3ZWJwYWNrSWdub3JlOiB0cnVlICovCiAgICAgIHEucGF0aFRvRmlsZVVSTChlKS5ocmVmCiAgICApOwogIH07Cn0KZnVuY3Rpb24gdGUoZSkgewogIHZhciB0ID0gdHlwZW9mIFN5bWJvbCA9PSAiZnVuY3Rpb24iICYmIFN5bWJvbC5pdGVyYXRvciwgaSA9IHQgJiYgZVt0XSwgciA9IDA7CiAgaWYgKGkpCiAgICByZXR1cm4gaS5jYWxsKGUpOwogIGlmIChlICYmIHR5cGVvZiBlLmxlbmd0aCA9PSAibnVtYmVyIikKICAgIHJldHVybiB7IG5leHQ6IGZ1bmN0aW9uKCkgewogICAgICByZXR1cm4gZSAmJiByID49IGUubGVuZ3RoICYmIChlID0gdm9pZCAwKSwgeyB2YWx1ZTogZSAmJiBlW3IrK10sIGRvbmU6ICFlIH07CiAgICB9IH07CiAgdGhyb3cgbmV3IFR5cGVFcnJvcih0ID8gIk9iamVjdCBpc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YWx1ZTsKICAgICAgICB0LnB1c2gobyksIG8ua2luZCA9PT0gImRpcmVjdG9yeSIgJiYgYXdhaXQgcihvKTsKICAgICAgfQogICAgfSBjYXRjaCAobykgewogICAgICBhID0geyBlcnJvcjogbyB9OwogICAgfSBmaW5hbGx5IHsKICAgICAgdHJ5IHsKICAgICAgICB1ICYmICF1LmRvbmUgJiYgKGwgPSBzLnJldHVybikgJiYgYXdhaXQgbC5jYWxsKHMpOwogICAgICB9IGZpbmFsbHkgewogICAgICAgIGlmIChhKQogICAgICAgICAgdGhyb3cgYS5lcnJvcjsKICAgICAgfQogICAgfQogIH0oZSk7CiAgY29uc3QgaSA9IC8qIEBfX1BVUkVfXyAqLyBuZXcgTWFwKCk7CiAgaS5zZXQoIi4iLCBlKTsKICBmb3IgKGNvbnN0IHIgb2YgdCkgewogICAgY29uc3QgbiA9IChhd2FpdCBlLnJlc29sdmUocikpLmpvaW4oIi8iKTsKICAgIGkuc2V0KG4sIHIpOwogIH0KICByZXR1cm4gaTsKfTsKZnVuY3Rpb24gaWUoZSwgdCkgewogIGxldCBpOwogIGkgPSB0LnN0ZExpYlVSTCAhPSBudWxsID8gdC5zdGRMaWJVUkwgOiB0LmluZGV4VVJMICsgInB5dGhvbl9zdGRsaWIuemlwIiwgZnVuY3Rpb24ociwgbikgewogICAgY29uc3QgYSA9IFYobik7CiAgICByLnByZVJ1bi5wdXNoKCgpID0+IHsKICAgICAgY29uc3QgbCA9IHIuX3B5X3ZlcnNpb25fbWFqb3IoKSwgdSA9IHIuX3B5X3ZlcnNpb25fbWlub3IoKTsKICAgICAgci5GUy5ta2RpclRyZWUoIi9saWIiKSwgci5GUy5ta2RpclRyZWUoYC9saWIvcHl0aG9uJHtsfS4ke3V9L3NpdGUtcGFja2FnZXNgKSwgci5hZGRSdW5EZXBlbmRlbmN5KCJpbnN0YWxsLXN0ZGxpYiIpLCBhLnRoZW4oKHMpID0+IHsKICAgICAgICByLkZTLndyaXRlRmlsZShgL2xpYi9weXR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TUVNRlMsIGwgPSByLlBBVEgsIHUgPSB7IERJUl9NT0RFOiAxNjg5NSwgRklMRV9NT0RFOiAzMzI3OSwgbW91bnQ6IGZ1bmN0aW9uKHMpIHsKICAgICAgaWYgKCFzLm9wdHMuZmlsZVN5c3RlbUhhbmRsZSkKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoIm9wdHMuZmlsZVN5c3RlbUhhbmRsZSBpcyByZXF1aXJlZCIpOwogICAgICByZXR1cm4gYS5tb3VudC5hcHBseShudWxsLCBhcmd1bWVudHMpOwogICAgfSwgc3luY2ZzOiBhc3luYyAocywgbywgYykgPT4gewogICAgICB0cnkgewogICAgICAgIGNvbnN0IHAgPSB1LmdldExvY2FsU2V0KHMpLCBmID0gYXdhaXQgdS5nZXRSZW1vdGVTZXQocyksIGQgPSBvID8gZiA6IHAsIG0gPSBvID8gcCA6IGY7CiAgICAgICAgYXdhaXQgdS5yZWNvbmNpbGUocywgZCwgbSksIGMobnVsbCk7CiAgICAgIH0gY2F0Y2ggKHApIHsKICAgICAgICBjKHApOwogICAgICB9CiAgICB9LCBnZXRMb2NhbFNldDogKHMpID0+IHsKICAgICAgbGV0IG8gPSAvKiBAX19QVVJFX18gKi8gT2JqZWN0LmNyZWF0ZShudWxsKTsKICAgICAgZnVuY3Rpb24gYyhkKSB7CiAgICAgICAgcmV0dXJuIGQgIT09ICIuIiAmJiBkICE9PSAiLi4iOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHAoZCkgewogICAgICAgIHJldHVybiAobSkgPT4gbC5qb2luMihkLCBtKTsKICAgICAgfQogICAgICBsZXQgZiA9IG4ucmVhZGRpcihzLm1vdW50cG9pbnQpLmZpbHRlcihjKS5tYXAocChzLm1vdW50cG9pbnQpKTsKICAgICAgZm9yICg7IGYubGVuZ3RoOyApIHsKICAgICAgICBsZXQgZCA9IGYucG9wKCksIG0gPSBuLnN0YXQoZCk7CiAgICAgICAgbi5pc0RpcihtLm1vZGUpICYmIGYucHVzaC5hcHBseSh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czogby5jb250ZW50cyB9OwogICAgICB0aHJvdyBuZXcgRXJyb3IoIm5vZGUgdHlwZSBub3Qgc3VwcG9ydGVkIik7CiAgICB9LCBzdG9yZUxvY2FsRW50cnk6IChzLCBvKSA9PiB7CiAgICAgIGlmIChuLmlzRGlyKG8ubW9kZSkpCiAgICAgICAgbi5ta2RpclRyZWUocywgby5tb2RlKTsKICAgICAgZWxzZSB7CiAgICAgICAgaWYgKCFuLmlzRmlsZShvLm1vZGUpKQogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJub2RlIHR5cGUgbm90IHN1cHBvcnRlZCIpOwogICAgICAgIG4ud3JpdGVGaWxlKHMsIG8uY29udGVudHMsIHsgY2FuT3duOiAhMCB9KTsKICAgICAgfQogICAgICBuLmNobW9kKHMsIG8ubW9kZSksIG4udXRpbWUocywgby50aW1lc3RhbXAsIG8udGltZXN0YW1wKTsKICAgIH0sIHJlbW92ZUxvY2FsRW50cnk6IChzKSA9PiB7CiAgICAgIHZhciBvID0gbi5zdGF0KHMpOwogICAgICBuLmlzRGlyKG8ubW9kZSkgPyBuLnJtZGlyKHMpIDogbi5pc0ZpbGUoby5tb2RlKSAmJiBuLnVubGluayhzKTsKICAgIH0sIGxvYWRSZW1vdGVFbnRyeTogYXN5bmMgKHMpID0+IHsKICAgICAgaWYgKHMua2luZCA9PT0gImZpbGUiKSB7CiAgICAgICAgY29uc3QgbyA9IGF3YWl0IHMuZ2V0RmlsZSgpOwogICAgICAgIHJldHVybiB7IGNvbnRlbnRzOiBuZXcgVWludDhBcnJheShhd2FpdCBvLmFycmF5QnVmZmVyKCkpLCBtb2RlOiB1LkZJTEVfTU9ERSwgdGltZXN0YW1wOiBvLmxhc3RNb2RpZmllZERhdGUgfTsKICAgICAgfQogICAgICBpZiAocy5raW5kID09PSAiZGlyZWN0b3J5IikKICAgICAgICByZXR1cm4geyBtb2RlOiB1LkRJUl9NT0RFLCB0aW1lc3RhbXA6IG5ldyBEYXRlKCkgfTsKICAgICAgdG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KQoKICAgIG1hdGNoZXMgPSBbXQogICAgZm9yIGNvbXAgaW4gY29tcGxldGlvbnM6CiAgICAgICAgbWF0Y2hlcy5hcHBlbmQoZGljdCgKICAgICAgICAgICAgbmFtZT1jb21wLm5hbWUsCiAgICAgICAgICAgIHR5cGU9Y29tcC50eXBlLAogICAgICAgICAgICBkZXNjcmlwdGlvbj1jb21wLmRlc2NyaXB0aW9uLAogICAgICAgICAgICBmdWxsX25hbWU9Y29tcC5mdWxsX25hbWUKICAgICAgICApKQoKICAgIHJldHVybiB7CiAgICAgICAgIm1hdGNoZXMiOiBtYXRjaGVzCiAgICB9CgoKYXN5bmMgZGVmIGluc3RhbGxfcGFjYWtnZShwYWNrYWdlKToKICAgIHRyeToKICAgICAgICBhd2FpdCBtaWNyb3BpcC5pbnN0YWxsKHBhY2thZ2UsIGtlZXBfZ29pbmc9VHJ1ZSkKICAgICAgICByZXR1cm4gewogICAgICAgICAgICAic3VjY2VzcyI6IFRydWUKICAgICAgICB9CiAgICBleGNlcHQgRXhjZXB0aW9uIGFzIGU6CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgInN1Y2Nlc3MiOiBGYWxzZSwKICAgICAgICAgICAgImVycm9yIjogc3RyKGUpCiAgICAgICAgfQoKCmRlZiBmb3JtYXRfY29kZShjb2RlKToKICAgIHJldHVybiBmb3JtYXRfc3RyKGNvZGUsIG1vZGU9RmlsZU1vZGUoKSkKYDsKZnVuY3Rpb24gbGUoZSwgdCwgaSkgewogIHJldHVybiB0IGluIGUgPyBPYmplY3QuZGVmaW5lUHJvcGVydHkoZSwgdCwgewogICAgdmFsdWU6IGksCiAgICBlbnVtZXJhYmxlOiAhMCwKICAgIGNvbmZpZ3VyYWJsZTogITAsCiAgICB3cml0YWJsZTogITAKICB9KSA6IGVbdF0gPSBpLCBlOwp9CmZ1bmN0aW9uIEEoZSwgdCkgewogIHZhciBpID0gT2JqZWN0LmtleXMoZSk7CiAgaWYgKE9iamVjdC5nZXRPd25Qcm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ID0gZS5ydW5QeXRob24oImltcG9ydCBzeXM7IHN5cy5zdGRvdXQuZ2V0dmFsdWUoKSIpLnRyaW0oKSwgYyA9IGUucnVuUHl0aG9uKCJpbXBvcnQgc3lzOyBzeXMuc3RkZXJyLmdldHZhbHVlKCkiKS50cmltKCk7CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIHJlc3VsdDogdihzLCBlKSwKICAgICAgICAgIHN0ZG91dDogdihvLCBlKSwKICAgICAgICAgIHN0ZGVycjogYywKICAgICAgICAgIGVycm9yOiBudWxsCiAgICAgICAgfTsKICAgICAgfSBjYXRjaCAocykgewogICAgICAgIHJldHVybiB7CiAgICAgICAgICByZXN1bHQ6IG51bGwsCiAgICAgICAgICBzdGRvdXQ6IG51bGwsCiAgICAgICAgICBzdGRlcnI6IG51bGwsCiAgICAgICAgICBlcnJvcjogRmUocy5tZXNzYWdlKQogICAgICAgIH07CiAgICAgIH0gZmluYWxseSB7CiAgICAgICAgY29uc3QgeyBjYWxsYmFja3M6IHMgfSA9IEQoKTsKICAgICAgICBPYmplY3QuZW50cmllcyhsKS5mb3JFYWNoKChbb10pID0+IHsKICAgICAgICAgIHZhciBjOwogICAgICAgICAgZS5nbG9iYWxzLnNldChvLCAoYyA9IGUudG9QeShudWxsKSkgPT0gbnVsbCA/IHZvaWQgMCA6IGMudG9TdHJpbmcoKSk7CiAgICAgICAgfSksIHUuZm9yRWFjaCgobykgPT4gewogICAgICAgICAgZGVsZXRlIHNbb107CiAgICAgICAgfSk7CiAgICAgIH0KICAgIH0sCiAgICBbaC5DT01QTEVURV06IGFzeW5jICh7CiAgICAgIGNvZGU6IGEsCiAgICAgIGxpbmU6IGwsCiAgICAgIGNvbHVtbjogdQogICAgfSkgPT4gewogICAgICBhd2FpdCBlLmxvYWRQYWNrYWdlc0Zyb21JbXBvcnRzKGEpOwogICAgICBjb25zdCBzID0gZS5nbG9iYWxzLmdldCgiZ2V0X2F1dG9jb21wbGV0aW9uIikoYSwgbCwgdSk7CiAgICAgIHJldHVybiB7IHJlc3VsdDogdihzLCBlKSwgZXJyb3I6IG51bGwgfTsKICAgIH0sCiAgICBbaC5JTlNUQUxMXTogYXN5bmMgKHsgcGFja2FnZXM6IGEgfSkgPT4gewogICAgICBjb25zdCBsID0gYXdhaXQgZS5nbG9iYWxzLmdldCgiaW5zdGFsbF9wYWNha2dlIikoYVswXSk7CiAgICAgIHJldHVybiB2KGwsIGUpOwogICAgfSwKICAgIFtoLkZPUk1BVF06IGFzeW5jICh7IGNvZGU6IGEgfSkgPT4gewogICAgICBjb25zdCBsID0gZS5nbG9iYWxzLmdldCgiZm9ybWF0X2NvZGUiKShhKTsKICAgICAgcmV0dXJuIHsgcmVzdWx0OiB2KGwsIGUpLCBlcnJvcjogbnVsbCB9OwogICAgfQogIH07CiAgb25tZXNzYWdlID0gYXN5bmMgZnVuY3Rpb24obCkgewogICAgY29uc3QgeyBpZDogdSwgYWN0aW9uOiBzID0gaC5FWEVDLCBkYXRhOiBvIH0gPSBsLmRhdGE7CiAgICBpZiAocyA9PT0gaC5KU19GTl9DQUxMKQogICAgICByKG8sIHUpOwogICAgZWxzZSB7CiAgICAgIGxldCBjOwogICAgICBzd2l0Y2ggKHMpIHsKICAgICAgICBjYXNlIGguRVhFQzoKICAgICAgICAgIGMgPSBhd2FpdCBpW2guRVhFQ10obyk7CiAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIGguQ09NUExFVEU6CiAgICAgICAgICBjID0gYXdhaXQgaVtoLkNPTVBMRVRFXShvKTsKICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgaC5JTlNUQUxMOgogICAgICAgICAgYyA9IGF3YWl0IGlbaC5JTlNUQUxMXShvKTsKICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgaC5GT1JNQVQ6CiAgICAgICAgICBjID0gYXdhaXQgaVtoLkZPUk1BVF0obyk7CiAgICAgICAgICBicmVhazsKICAgICAgfQogICAgICBwb3N0TWVzc2FnZSh7CiAgICAgICAgZGF0YTogYywKICAgICAgICBpZDogdSwKICAgICAgICBhY3Rpb246IHMKICAgICAgfSk7CiAgICB9CiAgfTsKICBmdW5jdGlvbiByKGEsIGwpIHsKICAgIGNvbnN0IHsgcmVzdWx0OiB1LCBlcnJvcjogcyB9ID0gYSwgeyBjYWxsYmFja3M6IG8gfSA9IEQoKTsKICAgIHMgJiYgb1tsXS5yZWplY3QocyksIG9bbF0ucmVzb2x2ZSh1KTsKICB9CiAgZnVuY3Rpb24gbihhLCBsKSB7CiAgICByZXR1cm4gYXN5bmMgKC4uLnUpID0+IG5ldyBQcm9taXNlKChzLCBvKSA9PiB7CiAgICAgIGNvbnN0IHsgY2FsbGJhY2tzOiBjLCBjb21tYW5kVW5pcXVlSWQ6IHAgfSA9IEQoKTsKICAgICAgcG9zdE1lc3NhZ2UoewogICAgICAgIGFjdGlvbjogaC5KU19GTl9DQUxMLAogICAgICAgIGRhdGE6IHsKICAgICAgICAgIGFyZ3M6IHUsCiAgICAgICAgICBuYW1lOiBhCiAgICAgICAgfSwKICAgICAgICBpZDogcAogICAgICB9KSwgbC5wdXNoKHApLCBOZSh7CiAgICAgICAgY2FsbGJhY2tzOiBMZShjLCBwLCB7CiAgICAgICAgICByZXNvbHZlOiBzLAogICAgICAgICAgcmVqZWN0OiBvCiAgICAgICAgfSksCiAgICAgICAgY29tbWFuZFVuaXF1ZUlkOiBwICsgMQogICAgICB9KTsKICAgIH0pOwogIH0KfQp4ZSgpOwo=",w=typeof window<"u"&&window.Blob&&new Blob([atob(h)],{type:"text/javascript;charset=utf-8"});function E(){const I=w&&(window.URL||window.webkitURL).createObjectURL(w);try{return I?new Worker(I):new Worker("data:application/javascript;base64,"+h,{type:"module"})}finally{I&&(window.URL||window.webkitURL).revokeObjectURL(I)}}const q=Boolean(globalThis.Worker),[B,K]=j.create({config:O,pyodideWorker:null,callbacks:{},commandUniqueId:0,jsFunctions:{},interruptBuffer:null}),n={async ensureWorkerIsSetup(){const{pyodideWorker:I}=B();I||await e()},async command(I,g,C){await n.ensureWorkerIsSetup();const{commandUniqueId:A,pyodideWorker:i,interruptBuffer:l}=B();l&&(l[0]=0),C||K({commandUniqueId:A+1}),i==null||i.postMessage({data:I,id:C??A,action:g})}},e=M(function(){return new Promise((g,C)=>{q||C(new Error(`your browser does | ||
t support web workers!`));const A=new E;A.onmessage=function(l){var Z;((Z=l.data)==null?void 0:Z.status)===V.READY?(K({pyodideWorker:A,interruptBuffer:l.data.interruptBuffer}),A.onmessage=function(G){const{action:c,id:a,data:t}=G.data;switch(c){case m.JS_FN_CALL:iI(a,t);break;default:AI(a,t);break}},g(A)):C(new Error("unexpected error in setup process"))},A.onerror=function(l){C(l.message)}})});async function _(I){return new Promise((g,C)=>{const{callbacks:A,commandUniqueId:i}=B();n.command(bI(I),m.EXEC),K({callbacks:y(A,i,{resolve:g,reject:C})})})}const $={async repl(I){return new Promise((g,C)=>{const{commandUniqueId:A,callbacks:i}=B(),{code:l,line:Z,column:d}=I;let G=Z,c=d;Z||(G=l.split(` | ||
`).length),c||(c=l.split(` | ||
`)[G-1].length),n.command({code:l,line:G,column:c},m.COMPLETE),K({callbacks:y(i,A,{resolve:g,reject:C})})})}};async function II(I){return new Promise((g,C)=>{const{callbacks:A,commandUniqueId:i}=B();n.command({packages:I},m.INSTALL),K({callbacks:y(A,i,{resolve:g,reject:C})})})}async function gI(I){return new Promise((g,C)=>{const{callbacks:A,commandUniqueId:i}=B();n.command(I,m.FORMAT),K({callbacks:y(A,i,{resolve:g,reject:C})})})}function CI(){const{interruptBuffer:I}=B();if(!globalThis.SharedArrayBuffer)throw new Error(` | ||
(function(b,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(b=typeof globalThis<"u"?globalThis:b||self,u(b.xPython={}))})(this,function(b){"use strict";function u(I,g,C){return g in I?Object.defineProperty(I,g,{value:C,enumerable:!0,configurable:!0,writable:!0}):I[g]=C,I}function H(I,g){var C=Object.keys(I);if(Object.getOwnPropertySymbols){var A=Object.getOwnPropertySymbols(I);g&&(A=A.filter(function(i){return Object.getOwnPropertyDescriptor(I,i).enumerable})),C.push.apply(C,A)}return C}function V(I){for(var g=1;g<arguments.length;g++){var C=arguments[g]!=null?arguments[g]:{};g%2?H(Object(C),!0).forEach(function(A){u(I,A,C[A])}):Object.getOwnPropertyDescriptors?Object.defineProperties(I,Object.getOwnPropertyDescriptors(C)):H(Object(C)).forEach(function(A){Object.defineProperty(I,A,Object.getOwnPropertyDescriptor(C,A))})}return I}function t(){for(var I=arguments.length,g=new Array(I),C=0;C<I;C++)g[C]=arguments[C];return function(A){return g.reduceRight(function(i,l){return l(i)},A)}}function s(I){return function g(){for(var C=this,A=arguments.length,i=new Array(A),l=0;l<A;l++)i[l]=arguments[l];return i.length>=I.length?I.apply(this,i):function(){for(var G=arguments.length,d=new Array(G),Z=0;Z<G;Z++)d[Z]=arguments[Z];return g.apply(C,[].concat(i,d))}}}function S(I){return{}.toString.call(I).includes("Object")}function R(I){return!Object.keys(I).length}function W(I){return typeof I=="function"}function J(I,g){return Object.prototype.hasOwnProperty.call(I,g)}function L(I,g){return S(g)||o("changeType"),Object.keys(g).some(function(C){return!J(I,C)})&&o("changeField"),g}function v(I){W(I)||o("selectorType")}function F(I){W(I)||S(I)||o("handlerType"),S(I)&&Object.values(I).some(function(g){return!W(g)})&&o("handlersType")}function U(I){I||o("initialIsRequired"),S(I)||o("initialType"),R(I)&&o("initialContent")}function r(I,g){throw new Error(I[g]||I.default)}var N={initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"},o=s(r)(N),y={changes:L,selector:v,handler:F,initial:U};function Q(I){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};y.initial(I),y.handler(g);var C={current:I},A=s(T)(C,g),i=s(j)(C),l=s(y.changes)(I),G=s(z)(C);function d(){var B=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(X){return X};return y.selector(B),B(C.current)}function Z(B){t(A,i,l,G)(B)}return[d,Z]}function z(I,g){return W(g)?g(I.current):g}function j(I,g){return I.current=V(V({},I.current),g),g}function T(I,g,C){return W(g)?g(I.current):Object.keys(C).forEach(function(A){var i;return(i=g[A])===null||i===void 0?void 0:i.call(g,I.current[A])}),C}var f={create:Q};const O={loadPyodideOptions:{indexURL:"https://cdn.jsdelivr.net/pyodide/v0.23.2/full/"}};var a=(I=>(I[I.READY=0]="READY",I))(a||{}),m=(I=>(I[I.EXEC=0]="EXEC",I[I.COMPLETE=1]="COMPLETE",I[I.INSTALL=2]="INSTALL",I[I.FORMAT=3]="FORMAT",I[I.JS_FN_CALL=4]="JS_FN_CALL",I))(m||{}),Y=(I=>(I.FN="__function__",I))(Y||{});function P(I){let g;return()=>(g||(g=I()),g)}function D(I,g){if(!g)throw new Error(`a wrong id is provided from worker - callback with ${I} id doesn't exist`)}function M(I,g){const{[g]:C,...A}=I;return A}function p(I,g,C){return{...I,[g]:C}}function x(I,g,C){return{...I,[g]:C}}const w="dmFyIGIsIE0sIGssICQsIEIgPSB7IGV4cG9ydHM6IHt9IH07CkIuZXhwb3J0cyA9IGZ1bmN0aW9uKCkgewogIGZ1bmN0aW9uIGUoZCkgewogICAgcmV0dXJuICFpc05hTihwYXJzZUZsb2F0KGQpKSAmJiBpc0Zpbml0ZShkKTsKICB9CiAgZnVuY3Rpb24gdChkKSB7CiAgICByZXR1cm4gZC5jaGFyQXQoMCkudG9VcHBlckNhc2UoKSArIGQuc3Vic3RyaW5nKDEpOwogIH0KICBmdW5jdGlvbiBvKGQpIHsKICAgIHJldHVybiBmdW5jdGlvbigpIHsKICAgICAgcmV0dXJuIHRoaXNbZF07CiAgICB9OwogIH0KICB2YXIgciA9IFsiaXNDb25zdHJ1Y3RvciIsICJpc0V2YWwiLCAiaXNOYXR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dldCIgKyB0KHJbY10pXSA9IG8ocltjXSksIGkucHJvdG90eXBlWyJzZXQiICsgdChyW2NdKV0gPSBmdW5jdGlvbihkKSB7CiAgICAgIHJldHVybiBmdW5jdGlvbihtKSB7CiAgICAgICAgdGhpc1tkXSA9IEJvb2xlYW4obSk7CiAgICAgIH07CiAgICB9KHJbY10pOwogIGZvciAodmFyIHAgPSAwOyBwIDwgbi5sZW5ndGg7IHArKykKICAgIGkucHJvdG90eXBlWyJnZXQiICsgdChuW3BdKV0gPSBvKG5bcF0pLCBpLnByb3RvdHlwZVsic2V0IiArIHQobltwXSldID0gZnVuY3Rpb24oZCkgewogICAgICByZXR1cm4gZnVuY3Rpb24obSkgewogICAgICAgIGlmICghZShtKSkKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoZCArICIgbXVzdCBiZSBhIE51bWJlciIpOwogICAgICAgIHRoaXNbZF0gPSBOdW1iZXIobSk7CiAgICAgIH07CiAgICB9KG5bcF0pOwogIGZvciAodmFyIGYgPSAwOyBmIDwgYS5sZW5ndGg7IGYrKykKICAgIGkucHJvdG90eXBlWyJnZXQiICsgdChhW2ZdKV0gPSBvKGFbZl0pLCBpLnByb3RvdHlwZVsic2V0IiArIHQoYVtmXSldID0gZnVuY3Rpb24oZCkgewogICAgICByZXR1cm4gZnVuY3Rpb24obSkgewogICAgICAgIHRoaXNbZF0gPSBTdHJpbmcobSk7CiAgICAgIH07CiAgICB9KGFbZl0pOwogIHJldHVybiBpOwp9KCk7CnZhciBlZSA9IChiID0gQi5leHBvcnRzLCBNID0gLyhefEApXFMrOlxkKy8sIGsgPSAvXlxzKmF0IC4qKFxTKzpcZCt8XChuYXRpdmVcKSkvbSwgJCA9IC9eKGV2YWxAKT8oXFtuYXRpdmUgY29kZV0pPyQvLCB7IHBhcnNlOiBmdW5jdGlvbihlKSB7CiAgaWYgKGUuc3RhY2t0cmFjZSAhPT0gdm9pZCAwIHx8IGVbIm9wZXJhI3NvdXJjZWxvYyJdICE9P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Bjb25zdCB0ID0gW107CiAgYXdhaXQgYXN5bmMgZnVuY3Rpb24gcihuKSB7CiAgICB2YXIgYSwgbDsKICAgIHRyeSB7CiAgICAgIGZvciAodmFyIHUsIHMgPSByZShuLnZhbHVlcygpKTsgISh1ID0gYXdhaXQgcy5uZXh0KCkpLmRvbmU7ICkgewogICAgICAgIGNvbnN0IGkgPSB1LnZhbHVlOwogICAgICAgIHQucHVzaChpKSwgaS5raW5kID09PSAiZGlyZWN0b3J5IiAmJiBhd2FpdCByKGkpOwogICAgICB9CiAgICB9IGNhdGNoIChpKSB7CiAgICAgIGEgPSB7IGVycm9yOiBpIH07CiAgICB9IGZpbmFsbHkgewogICAgICB0cnkgewogICAgICAgIHUgJiYgIXUuZG9uZSAmJiAobCA9IHMucmV0dXJuKSAmJiBhd2FpdCBsLmNhbGwocyk7CiAgICAgIH0gZmluYWxseSB7CiAgICAgICAgaWYgKGEpCiAgICAgICAgICB0aHJvdyBhLmVycm9yOwogICAgICB9CiAgICB9CiAgfShlKTsKICBjb25zdCBvID0gLyogQF9fUFVSRV9fICovIG5ldyBNYXAoKTsKICBvLnNldCgiLiIsIGUpOwogIGZvciAoY29uc3QgciBvZiB0KSB7CiAgICBjb25zdCBuID0gKGF3YWl0IGUucmVzb2x2ZShyKSkuam9pbigiLyIpOwogICAgby5zZXQobiwgcik7CiAgfQogIHJldHVybiBvOwp9OwpmdW5jdGlvbiBvZShlLCB0KSB7CiAgbGV0IG87CiAgbyA9IHQuc3RkTGliVVJMICE9IG51bGwgPyB0LnN0ZExpYlVSTCA6IHQuaW5kZXhVUkwgKyAicHl0aG9uX3N0ZGxpYi56aXAiLCBmdW5jdGlvbihyLCBuKSB7CiAgICBjb25zdCBhID0gVihuKTsKICAgIHIucHJlUnVuLnB1c2goKCkgPT4gewogICAgICBjb25zdCBsID0gci5fcHlfdmVyc2lvbl9tYWpvcigpLCB1ID0gci5fcHlfdmVyc2lvbl9taW5vcigpOwogICAgICByLkZTLm1rZGlyVHJlZ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IG1vZGU6IHUuRklMRV9NT0RFLCB0aW1lc3RhbXA6IGkubGFzdE1vZGlmaWVkRGF0ZSB9OwogICAgICB9CiAgICAgIGlmIChzLmtpbmQgPT09ICJkaXJlY3RvcnkiKQogICAgICAgIHJldHVybiB7IG1vZGU6IHUuRElSX01PREUsIHRpbWVzdGFtcDogbmV3IERhdGUoKSB9OwogICAgICB0aHJvdyBuZXcgRXJyb3IoInVua25vd24ga2luZDogIiArIHMua2luZCk7CiAgICB9LCBzdG9yZVJlbW90ZUVudHJ5OiBhc3luYyAocywgaSwgYykgPT4gewogICAgICBjb25zdCBwID0gcy5nZXQobC5kaXJuYW1lKGkpKSwgZiA9IG4uaXNGaWxlKGMubW9kZSkgPyBhd2FpdCBwLmdldEZpbGVIYW5kbGUobC5iYXNlbmFtZShpKSwgeyBjcmVhdGU6ICEwIH0pIDogYXdhaXQgcC5nZXREaXJlY3RvcnlIYW5kbGUobC5iYXNlbmFtZShpKSwgeyBjcmVhdGU6ICEwIH0pOwogICAgICBpZiAoZi5raW5kID09PSAiZmlsZSIpIHsKICAgICAgICBjb25zdCBkID0gYXdhaXQgZi5jcmVhdGVXcml0YWJsZSgpOwogICAgICAgIGF3YWl0IGQud3JpdGUoYy5jb250ZW50cyksIGF3YWl0IGQuY2xvc2UoKTsKICAgICAgfQogICAgICBzLnNldChpLCBmKTsKICAgIH0sIHJlbW92ZVJlbW90ZUVudHJ5OiBhc3luYyAocywgaSkgPT4gewogICAgICBhd2FpdCBzLmdldChsLmRpcm5hbWUoaSkpLnJlbW92ZUVudHJ5KGwuYmFzZW5hbWUoaSkpLCBzLmRlbGV0ZShpKTsKICAgIH0sIHJlY29uY2lsZTogYXN5bmMgKHMsIGksIGMpID0+IHsKICAgICAgbGV0IHAgPSAwOwogICAgICBjb25zdCBmID0gW107CiAgICAgIE9iamVjdC5rZXlzKGkuZW50cmllcykuZm9yRWFjaChmdW5jdGlvbih5KSB7CiAgICAgICAgY29uc3QgZyA9IGkuZW50cmllc1t5XSwgdyA9IGMuZW50cmllc1t5XTsKICAgICAgICAoIXcgfHwgbi5pc0ZpbGUoZy5tb2RlKSAmJiBnLnRpbWVzdGFtcC5nZXRUaW1lKCkgPiB3LnRpbWVzdGFtcC5nZXRUaW1lKCkpICYmIChmLnB1c2goeSksIHArKyk7CiAgICAgIH0pLCBmLnNvcnQoKTsKICAgICAgY29uc3QgZCA9IFtdOwogICAgICBpZiAoT2JqZWN0LmtleXMoYy5lbnRyaWVzKS5mb3JFYWNoKGZ1bmN0aW9uKHkpIHsKICAgICAgICBpLmVudHJpZXNbeV0gfHwgKGQucHVzaCh5KSwgcCsrKTsKICAgICAgfSksIGQuc29ydCgpLnJldmVyc2UoKSwgIXApCiAgICAgICAgcmV0dXJuOwogICAgICBjb25zdCBtID0gaS50eXBlID09PSAicmVtb3RlIiA/IGkuaGFuZGxlcyA6IGMuaGFuZGxlczsKICAgICAgZm9yIChjb25zdCB5IG9mIGYpIHsKICAgICAgICBjb25zdCBnID0gbC5ub3JtYWxpemUoeS5yZXBsYWNlKHMubW91bnRwb2ludCwgIi8iKSkuc3Vic3RyaW5nKDEpOwogICAgICAgIGlmIChjLnR5cGUgPT09ICJsb2NhbCIpIHsKICAgICAgICAgIGNvbnN0IHcgPSBtLmdldChnKSwgRiA9IGF3YWl0IHUubG9hZFJlbW90ZUVudHJ5KHcpOwogICAgICAgICAgdS5zdG9yZUxvY2FsRW50cnkoeSwgRik7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGNvbnN0IHcgPSB1LmxvYWRMb2NhbEVudHJ5KHkpOwogICAgICAgICAgYXdhaXQgdS5zdG9yZVJlbW90ZUVudHJ5KG0sIGcsIHcpOwogICAgICAgIH0KICAgICAgfQogICAgICBmb3IgKGNvbnN0IHkgb2YgZCkKICAgICAgICBpZiAoYy50eXBlID09PSAibG9jYWwiKQogICAgICAgICAgdS5yZW1vdmVMb2NhbEVudHJ5KHkpOwogICAgICAgIGVsc2UgewogICAgICAgICAgY29uc3QgZ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YgZ2V0X2F1dG9jb21wbGV0aW9uKGNvZGUsIGxpbmUsIGNvbHVtbik6CiAgICByZXN1bHQgPSBqZWRpLkludGVycHJldGVyKGNvZGUsIFtnbG9iYWxzKCksIGxvY2FscygpXSkKCiAgICBjb21wbGV0aW9ucyA9IHJlc3VsdC5jb21wbGV0ZShsaW5lLCBjb2x1bW4pCgogICAgbWF0Y2hlcyA9IFtdCiAgICBmb3IgY29tcCBpbiBjb21wbGV0aW9uczoKICAgICAgICBtYXRjaGVzLmFwcGVuZChkaWN0KAogICAgICAgICAgICBuYW1lPWNvbXAubmFtZSwKICAgICAgICAgICAgdHlwZT1jb21wLnR5cGUsCiAgICAgICAgICAgIGRlc2NyaXB0aW9uPWNvbXAuZGVzY3JpcHRpb24sCiAgICAgICAgICAgIGZ1bGxfbmFtZT1jb21wLmZ1bGxfbmFtZQogICAgICAgICkpCgogICAgcmV0dXJuIHsKICAgICAgICAibWF0Y2hlcyI6IG1hdGNoZXMKICAgIH0KCgphc3luYyBkZWYgaW5zdGFsbF9wYWNha2dlKHBhY2thZ2UpOgogICAgdHJ5OgogICAgICAgIGF3YWl0IG1pY3JvcGlwLmluc3RhbGwocGFja2FnZSwga2VlcF9nb2luZz1UcnVlKQogICAgICAgIHJldHVybiB7CiAgICAgICAgICAgICJzdWNjZXNzIjogVHJ1ZQogICAgICAgIH0KICAgIGV4Y2VwdCBFeGNlcHRpb24gYXMgZToKICAgICAgICByZXR1cm4gewogICAgICAgICAgICAic3VjY2VzcyI6IEZhbHNlLAogICAgICAgICAgICAiZXJyb3IiOiBzdHIoZSkKICAgICAgICB9CgoKZGVmIGZvcm1hdF9jb2RlKGNvZGUsIG9wdGlvbnMpOgogICAgaWYgb3B0aW9uczoKICAgICAgICBtb2RlID0gRmlsZU1vZGUoKipvcHRpb25zKQogICAgICAgIHJldHVybiBmb3JtYXRfc3RyKGNvZGUsIG1vZGU9bW9kZSkKICAgIHJldHVybiBmb3JtYXRfc3RyKGNvZGUsIG1vZGU9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gICAgIG4ocywgdSkKICAgICAgICApIDogZS5nbG9iYWxzLnNldChzLCBlLnRvUHkoaSkpOwogICAgICB9KTsKICAgICAgdHJ5IHsKICAgICAgICBhd2FpdCBlLmxvYWRQYWNrYWdlc0Zyb21JbXBvcnRzKGEpLCBlLnJ1blB5dGhvbigiaW1wb3J0IHN5cywgaW87IHN5cy5zdGRvdXQgPSBpby5TdHJpbmdJTygpOyBzeXMuc3RkZXJyID0gaW8uU3RyaW5nSU8oKSIpOwogICAgICAgIGNvbnN0IHMgPSBhd2FpdCBlLnJ1blB5dGhvbkFzeW5jKGEpLCBpID0gZS5ydW5QeXRob24oImltcG9ydCBzeXM7IHN5cy5zdGRvdXQuZ2V0dmFsdWUoKSIpLnRyaW0oKSwgYyA9IGUucnVuUHl0aG9uKCJpbXBvcnQgc3lzOyBzeXMuc3RkZXJyLmdldHZhbHVlKCkiKS50cmltKCk7CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIHJlc3VsdDogdihzLCBlKSwKICAgICAgICAgIHN0ZG91dDogdihpLCBlKSwKICAgICAgICAgIHN0ZGVycjogYywKICAgICAgICAgIGVycm9yOiBudWxsCiAgICAgICAgfTsKICAgICAgfSBjYXRjaCAocykgewogICAgICAgIHJldHVybiB7CiAgICAgICAgICByZXN1bHQ6IG51bGwsCiAgICAgICAgICBzdGRvdXQ6IG51bGwsCiAgICAgICAgICBzdGRlcnI6IG51bGwsCiAgICAgICAgICBlcnJvcjogRmUocy5tZXNzYWdlKQogICAgICAgIH07CiAgICAgIH0gZmluYWxseSB7CiAgICAgICAgY29uc3QgeyBjYWxsYmFja3M6IHMgfSA9IEQoKTsKICAgICAgICBPYmplY3QuZW50cmllcyhsKS5mb3JFYWNoKChbaV0pID0+IHsKICAgICAgICAgIHZhciBjOwogICAgICAgICAgZS5nbG9iYWxzLnNldChpLCAoYyA9IGUudG9QeShudWxsKSkgPT0gbnVsbCA/IHZvaWQgMCA6IGMudG9TdHJpbmcoKSk7CiAgICAgICAgfSksIHUuZm9yRWFjaCgoaSkgPT4gewogICAgICAgICAgZGVsZXRlIHNbaV07CiAgICAgICAgfSk7CiAgICAgIH0KICAgIH0sCiAgICBbaC5DT01QTEVURV06IGFzeW5jICh7CiAgICAgIGNvZGU6IGEsCiAgICAgIGxpbmU6IGwsCiAgICAgIGNvbHVtbjogdQogICAgfSkgPT4gewogICAgICBhd2FpdCBlLmxvYWRQYWNrYWdlc0Zyb21JbXBvcnRzKGEpOwogICAgICBjb25zdCBzID0gZS5nbG9iYWxzLmdldCgiZ2V0X2F1dG9jb21wbGV0aW9uIikoYSwgbCwgdSk7CiAgICAgIHJldHVybiB7IHJlc3VsdDogdihzLCBlKSwgZXJyb3I6IG51bGwgfTsKICAgIH0sCiAgICBbaC5JTlNUQUxMXTogYXN5bmMgKHsgcGFja2FnZXM6IGEgfSkgPT4gewogICAgICBjb25zdCBsID0gYXdhaXQgZS5nbG9iYWxzLmdldCgiaW5zdGFsbF9wYWNha2dlIikoYVswXSk7CiAgICAgIHJldHVybiB2KGwsIGUpOwogICAgfSwKICAgIFtoLkZPUk1BVF06IGFzeW5jICh7CiAgICAgIGNvZGU6IGEsCiAgICAgIG9wdGlvbnM6IGwgPSB7fQogICAgfSkgPT4gewogICAgICBjb25zdCB1ID0gZS5nbG9iYWxzLmdldCgiZm9ybWF0X2NvZGUiKShhLCBlLnRvUHkobCkpOwogICAgICByZXR1cm4geyByZXN1bHQ6IHYodSwgZSksIGVycm9yOiBudWxsIH07CiAgICB9CiAgfTsKICBvbm1lc3NhZ2UgPSBhc3luYyBmdW5jdGlvbihsKSB7CiAgICBjb25zdCB7IGlkOiB1LCBhY3Rpb246IHMgPSBoLkVYRUMsIGRhdGE6IGkgfSA9IGwuZGF0YTsKICAgIGlmIChzID09PSBoLkpTX0ZOX0NBTEwpCiAgICAgIHIoaSwgdSk7CiAgICBlbHNlIHsKICAgICAgbGV0IGM7CiAgICAgIHN3aXRjaCAocykgewogICAgICAgIGNhc2UgaC5FWEVDOgogICAgICAgICAgYyA9IGF3YWl0IG9baC5FWEVDXShpKTsKICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgaC5DT01QTEVURToKICAgICAgICAgIGMgPSBhd2FpdCBvW2guQ09NUExFVEVdKGkpOwogICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBoLklOU1RBTEw6CiAgICAgICAgICBjID0gYXdhaXQgb1toLklOU1RBTExdKGkpOwogICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBoLkZPUk1BVDoKICAgICAgICAgIGMgPSBhd2FpdCBvW2guRk9STUFUXShpKTsKICAgICAgICAgIGJyZWFrOwogICAgICB9CiAgICAgIHBvc3RNZXNzYWdlKHsKICAgICAgICBkYXRhOiBjLAogICAgICAgIGlkOiB1LAogICAgICAgIGFjdGlvbjogcwogICAgICB9KTsKICAgIH0KICB9OwogIGZ1bmN0aW9uIHIoYSwgbCkgewogICAgY29uc3QgeyByZXN1bHQ6IHUsIGVycm9yOiBzIH0gPSBhLCB7IGNhbGxiYWNrczogaSB9ID0gRCgpOwogICAgcyAmJiBpW2xdLnJlamVjdChzKSwgaVtsXS5yZXNvbHZlKHUpOwogIH0KICBmdW5jdGlvbiBuKGEsIGwpIHsKICAgIHJldHVybiBhc3luYyAoLi4udSkgPT4gbmV3IFByb21pc2UoKHMsIGkpID0+IHsKICAgICAgY29uc3QgeyBjYWxsYmFja3M6IGMsIGNvbW1hbmRVbmlxdWVJZDogcCB9ID0gRCgpOwogICAgICBwb3N0TWVzc2FnZSh7CiAgICAgICAgYWN0aW9uOiBoLkpTX0ZOX0NBTEwsCiAgICAgICAgZGF0YTogewogICAgICAgICAgYXJnczogdSwKICAgICAgICAgIG5hbWU6IGEKICAgICAgICB9LAogICAgICAgIGlkOiBwCiAgICAgIH0pLCBsLnB1c2gocCksIE5lKHsKICAgICAgICBjYWxsYmFja3M6IExlKGMsIHAsIHsKICAgICAgICAgIHJlc29sdmU6IHMsCiAgICAgICAgICByZWplY3Q6IGkKICAgICAgICB9KSwKICAgICAgICBjb21tYW5kVW5pcXVlSWQ6IHAgKyAxCiAgICAgIH0pOwogICAgfSk7CiAgfQp9CnhlKCk7Cg==",h=typeof window<"u"&&window.Blob&&new Blob([atob(w)],{type:"text/javascript;charset=utf-8"});function E(){const I=h&&(window.URL||window.webkitURL).createObjectURL(h);try{return I?new Worker(I):new Worker("data:application/javascript;base64,"+w,{type:"module"})}finally{I&&(window.URL||window.webkitURL).revokeObjectURL(I)}}const q=Boolean(globalThis.Worker),[c,K]=f.create({config:O,pyodideWorker:null,callbacks:{},commandUniqueId:0,jsFunctions:{},interruptBuffer:null}),n={async ensureWorkerIsSetup(){const{pyodideWorker:I}=c();I||await e()},async command(I,g,C){await n.ensureWorkerIsSetup();const{commandUniqueId:A,pyodideWorker:i,interruptBuffer:l}=c();l&&(l[0]=0),C||K({commandUniqueId:A+1}),i==null||i.postMessage({data:I,id:C??A,action:g})}},e=P(function(){return new Promise((g,C)=>{q||C(new Error(`your browser does | ||
t support web workers!`));const A=new E;A.onmessage=function(l){var G;((G=l.data)==null?void 0:G.status)===a.READY?(K({pyodideWorker:A,interruptBuffer:l.data.interruptBuffer}),A.onmessage=function(Z){const{action:B,id:X,data:k}=Z.data;switch(B){case m.JS_FN_CALL:iI(X,k);break;default:AI(X,k);break}},g(A)):C(new Error("unexpected error in setup process"))},A.onerror=function(l){C(l.message)}})});async function _(I){return new Promise((g,C)=>{const{callbacks:A,commandUniqueId:i}=c();n.command(bI(I),m.EXEC),K({callbacks:p(A,i,{resolve:g,reject:C})})})}const $={async repl(I){return new Promise((g,C)=>{const{commandUniqueId:A,callbacks:i}=c(),{code:l,line:G,column:d}=I;let Z=G,B=d;G||(Z=l.split(` | ||
`).length),B||(B=l.split(` | ||
`)[Z-1].length),n.command({code:l,line:Z,column:B},m.COMPLETE),K({callbacks:p(i,A,{resolve:g,reject:C})})})}};async function II(I){return new Promise((g,C)=>{const{callbacks:A,commandUniqueId:i}=c();n.command({packages:I},m.INSTALL),K({callbacks:p(A,i,{resolve:g,reject:C})})})}async function gI(I){return new Promise((g,C)=>{const{callbacks:A,commandUniqueId:i}=c();n.command(I,m.FORMAT),K({callbacks:p(A,i,{resolve:g,reject:C})})})}function CI(){const{interruptBuffer:I}=c();if(!globalThis.SharedArrayBuffer)throw new Error(` | ||
\`.interrupt\` method uses SharedArrayBuffer which requires "cross-origin-isolation" to be enabled. | ||
To enable "cross-origin-isolation" check this article - https://web.dev/cross-origin-isolation-guide/#enable-cross-origin-isolation | ||
`);I&&(I[0]=2)}function AI(I,g){const{callbacks:C}=B();P(I,Boolean(C[I]));const{resolve:A,reject:i}=C[I];if(K({callbacks:x(C,I)}),g.error){i==null||i(g.error);return}A(g)}async function iI(I,{args:g,name:C}){var Z;const{jsFunctions:A}=B();let i,l;try{i=await((Z=A[C])==null?void 0:Z.call(A,...g))}catch(d){l=d}n.command({result:i,error:l},m.JS_FN_CALL,I)}function lI(I){const{jsFunctions:g}=B();return Object.entries(I).reduce((C,[A,i])=>(typeof i=="function"?(C[A]={type:Y.FN,name:i.name},K({jsFunctions:D(g,i.name,i)})):C[A]=i,C),{})}function bI(I){return I.context?{...I,context:lI(I.context)}:I}b.ActionType=m,b.ChannelSetupStatus=V,b.PayloadType=Y,b.complete=$,b.exec=_,b.format=gI,b.init=e,b.install=II,b.interrupt=CI,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}); | ||
`);I&&(I[0]=2)}function AI(I,g){const{callbacks:C}=c();D(I,Boolean(C[I]));const{resolve:A,reject:i}=C[I];if(K({callbacks:M(C,I)}),g.error){i==null||i(g.error);return}A(g)}async function iI(I,{args:g,name:C}){var G;const{jsFunctions:A}=c();let i,l;try{i=await((G=A[C])==null?void 0:G.call(A,...g))}catch(d){l=d}n.command({result:i,error:l},m.JS_FN_CALL,I)}function lI(I){const{jsFunctions:g}=c();return Object.entries(I).reduce((C,[A,i])=>(typeof i=="function"?(C[A]={type:Y.FN,name:i.name},K({jsFunctions:x(g,i.name,i)})):C[A]=i,C),{})}function bI(I){return I.context?{...I,context:lI(I.context)}:I}b.ActionType=m,b.ChannelSetupStatus=a,b.PayloadType=Y,b.complete=$,b.exec=_,b.format=gI,b.init=e,b.install=II,b.interrupt=CI,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}); |
{ | ||
"name": "@x-python/core", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"type": "module", | ||
@@ -54,3 +54,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"pyodide": "^0.23.0", | ||
"pyodide": "^0.23.2", | ||
"state-local": "^1.0.7" | ||
@@ -57,0 +57,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
109914
757
Updatedpyodide@^0.23.2