@pyscript/core 0.3.22 → 0.3.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core-78rkmWeI.js +3 -0
- package/dist/core-78rkmWeI.js.map +1 -0
- package/dist/core.js +1 -1
- package/dist/{deprecations-manager-DiLupR6w.js → deprecations-manager-2rEkYgsn.js} +2 -2
- package/dist/{deprecations-manager-DiLupR6w.js.map → deprecations-manager-2rEkYgsn.js.map} +1 -1
- package/dist/{error-tt9AxwDf.js → error-sz_Yjd9A.js} +2 -2
- package/dist/{error-tt9AxwDf.js.map → error-sz_Yjd9A.js.map} +1 -1
- package/dist/{py-editor-d8hnd4Gu.js → py-editor-1Il3Lcfv.js} +2 -2
- package/dist/{py-editor-d8hnd4Gu.js.map → py-editor-1Il3Lcfv.js.map} +1 -1
- package/dist/{py-terminal-HcALwKhy.js → py-terminal-E5d6qafs.js} +2 -2
- package/dist/{py-terminal-HcALwKhy.js.map → py-terminal-E5d6qafs.js.map} +1 -1
- package/package.json +2 -2
- package/dist/core-14p8E60X.js +0 -3
- package/dist/core-14p8E60X.js.map +0 -1
package/dist/core.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export{b as PyWorker,T as TYPES,c as config,e as hooks,f as whenDefined}from"./core-
|
1
|
+
export{b as PyWorker,T as TYPES,c as config,e as hooks,f as whenDefined}from"./core-78rkmWeI.js";
|
2
2
|
//# sourceMappingURL=core.js.map
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{e}from"./core-
|
2
|
-
//# sourceMappingURL=deprecations-manager-
|
1
|
+
import{e}from"./core-78rkmWeI.js";import{notify as o}from"./error-sz_Yjd9A.js";function r(){const e=document.querySelectorAll("script");for(const o of e)s(o.src)}function s(e){/\/pyscript\.net\/latest/.test(e)&&o("Loading scripts from latest is deprecated and will be removed soon. Please use a specific version instead.")}e.main.onReady.add(r),e.main.onWorker.add(r);
|
2
|
+
//# sourceMappingURL=deprecations-manager-2rEkYgsn.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"deprecations-manager-
|
1
|
+
{"version":3,"file":"deprecations-manager-2rEkYgsn.js","sources":["../src/plugins/deprecations-manager.js"],"sourcesContent":["// PyScript Derepcations Plugin\nimport { hooks } from \"../core.js\";\nimport { notify } from \"./error.js\";\n\n// react lazily on PyScript bootstrap\nhooks.main.onReady.add(checkDeprecations);\nhooks.main.onWorker.add(checkDeprecations);\n\n/**\n * Check that there are no scripts loading from pyscript.net/latest\n */\nfunction checkDeprecations() {\n const scripts = document.querySelectorAll(\"script\");\n for (const script of scripts) checkLoadingScriptsFromLatest(script.src);\n}\n\n/**\n * Check if src being loaded from pyscript.net/latest and display a notification if true\n * * @param {string} src\n */\nfunction checkLoadingScriptsFromLatest(src) {\n if (/\\/pyscript\\.net\\/latest/.test(src)) {\n notify(\n \"Loading scripts from latest is deprecated and will be removed soon. Please use a specific version instead.\",\n );\n }\n}\n"],"names":["checkDeprecations","scripts","document","querySelectorAll","script","checkLoadingScriptsFromLatest","src","test","notify","hooks","main","onReady","add","onWorker"],"mappings":"+EAWA,SAASA,IACL,MAAMC,EAAUC,SAASC,iBAAiB,UAC1C,IAAK,MAAMC,KAAUH,EAASI,EAA8BD,EAAOE,IACvE,CAMA,SAASD,EAA8BC,GAC/B,0BAA0BC,KAAKD,IAC/BE,EACI,6GAGZ,CArBAC,EAAMC,KAAKC,QAAQC,IAAIZ,GACvBS,EAAMC,KAAKG,SAASD,IAAIZ"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{e}from"./core-
|
2
|
-
//# sourceMappingURL=error-
|
1
|
+
import{e}from"./core-78rkmWeI.js";function n(e){const n=document.createElement("div");n.className="py-error",n.textContent=e,n.style.cssText="\n border: 1px solid red;\n background: #ffdddd;\n color: black;\n font-family: courier, monospace;\n white-space: pre;\n overflow-x: auto;\n padding: 8px;\n margin-top: 8px;\n ",document.body.append(n)}e.main.onReady.add((function o(r){e.main.onReady.delete(o);const{stderr:t}=r.io;r.io.stderr=(e,...o)=>(n(e.message||e),t(e,...o)),addEventListener("error",(({message:e})=>{e.startsWith("Uncaught PythonError")&&n(e)}))}));export{n as notify};
|
2
|
+
//# sourceMappingURL=error-sz_Yjd9A.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"error-
|
1
|
+
{"version":3,"file":"error-sz_Yjd9A.js","sources":["../src/plugins/error.js"],"sourcesContent":["// PyScript Error Plugin\nimport { hooks } from \"../core.js\";\n\nhooks.main.onReady.add(function override(pyScript) {\n // be sure this override happens only once\n hooks.main.onReady.delete(override);\n\n // trap generic `stderr` to propagate to it regardless\n const { stderr } = pyScript.io;\n\n // override it with our own logic\n pyScript.io.stderr = (error, ...rest) => {\n notify(error.message || error);\n // let other plugins or stderr hook, if any, do the rest\n return stderr(error, ...rest);\n };\n\n // be sure uncaught Python errors are also visible\n addEventListener(\"error\", ({ message }) => {\n if (message.startsWith(\"Uncaught PythonError\")) notify(message);\n });\n});\n\n// Error hook utilities\n\n// Custom function to show notifications\n\n/**\n * Add a banner to the top of the page, notifying the user of an error\n * @param {string} message\n */\nexport function notify(message) {\n const div = document.createElement(\"div\");\n div.className = \"py-error\";\n div.textContent = message;\n div.style.cssText = `\n border: 1px solid red;\n background: #ffdddd;\n color: black;\n font-family: courier, monospace;\n white-space: pre;\n overflow-x: auto;\n padding: 8px;\n margin-top: 8px;\n `;\n document.body.append(div);\n}\n"],"names":["notify","message","div","document","createElement","className","textContent","style","cssText","body","append","hooks","main","onReady","add","override","pyScript","delete","stderr","io","error","rest","addEventListener","startsWith"],"mappings":"kCA+BO,SAASA,EAAOC,GACnB,MAAMC,EAAMC,SAASC,cAAc,OACnCF,EAAIG,UAAY,WAChBH,EAAII,YAAcL,EAClBC,EAAIK,MAAMC,QAAU,6MAUpBL,SAASM,KAAKC,OAAOR,EACzB,CA3CAS,EAAMC,KAAKC,QAAQC,KAAI,SAASC,EAASC,GAErCL,EAAMC,KAAKC,QAAQI,OAAOF,GAG1B,MAAMG,OAAEA,GAAWF,EAASG,GAG5BH,EAASG,GAAGD,OAAS,CAACE,KAAUC,KAC5BrB,EAAOoB,EAAMnB,SAAWmB,GAEjBF,EAAOE,KAAUC,IAI5BC,iBAAiB,SAAS,EAAGrB,cACrBA,EAAQsB,WAAW,yBAAyBvB,EAAOC,EAAQ,GAEvE"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{T as e,d as t,X as r,H as n}from"./core-
|
2
|
-
//# sourceMappingURL=py-editor-
|
1
|
+
import{T as e,d as t,X as r,H as n}from"./core-78rkmWeI.js";let o=0;const s=e=>`${e}-editor-${o++}`,i=new Map,a={worker:{onReady:({runAsync:e,io:t},{sync:r})=>{t.stdout=e=>r.write(e),t.stderr=e=>r.writeErr(e),r.revoke(),r.runAsync=e}}};async function c({currentTarget:e}){const{env:t,pySrc:o,outDiv:s}=this;if(e.disabled=!0,s.innerHTML="",!i.has(t)){const e=URL.createObjectURL(new Blob([""])),o=r.call(new n(null,a),e,{type:this.interpreter}),{sync:s}=o,{promise:c,resolve:l}=Promise.withResolvers();i.set(t,c),s.revoke=()=>{URL.revokeObjectURL(e),l(o)}}i.get(t).then((t=>{t.onerror=({error:e})=>{s.innerHTML+=`<span style='color:red'>${e.message||e}</span>\n`,console.error(e)};const r=()=>{e.disabled=!1},{sync:n}=t;n.write=e=>{s.innerText+=`${e}\n`},n.writeErr=e=>{s.innerHTML+=`<span style='color:red'>${e}</span>\n`},n.runAsync(o).then(r,r)}))}const l=(e,t)=>{const r=document.createElement("div");r.className=`${t}-editor-input`,r.setAttribute("aria-label","Python Script Area");const n=((e,t)=>{const r=document.createElement("button");return r.className=`absolute ${t}-editor-run-button`,r.innerHTML='<svg style="height:20px;width:20px;vertical-align:-.125em;transform-origin:center;overflow:visible;color:green" viewBox="0 0 384 512" aria-hidden="true" role="img" xmlns="http://www.w3.org/2000/svg"><g transform="translate(192 256)" transform-origin="96 0"><g transform="translate(0,0) scale(1,1)"><path d="M361 215C375.3 223.8 384 239.3 384 256C384 272.7 375.3 288.2 361 296.1L73.03 472.1C58.21 482 39.66 482.4 24.52 473.9C9.377 465.4 0 449.4 0 432V80C0 62.64 9.377 46.63 24.52 38.13C39.66 29.64 58.21 29.99 73.03 39.04L361 215z" fill="currentColor" transform="translate(-192 -256)"></path></g></g></svg>',r.setAttribute("aria-label","Python Script Run Button"),r.addEventListener("click",e),r})(e,t),o=document.createElement("div");return o.addEventListener("keydown",(e=>{e.stopPropagation()})),r.append(n,o),r},d=(e,t)=>{const r=document.createElement("div");r.className=`${t}-editor-box`;const n=l(e,t),o=(e=>{const t=document.createElement("div");return t.className=`${e}-editor-output`,t.id=`${s(e)}-output`,t})(t);return r.append(n,o),[r,o]},u=async(e,r,n)=>{const[{basicSetup:o,EditorView:i},{Compartment:a},{python:l},{indentUnit:u},{keymap:m},{defaultKeymap:p}]=await Promise.all([import("./codemirror-Maf5R0Dz.js"),import("./codemirror_state-W084kUeH.js"),import("./codemirror_lang-python-FADyYnPB.js"),import("./codemirror_language-xy4t5bF6.js").then((function(e){return e.x})),import("./codemirror_view-8wK3J563.js").then((function(e){return e.q})),import("./codemirror_commands-bA0DvCyD.js")]),y=e.getAttribute("target");let v;if(y){if(v=document.getElementById(y)||document.querySelector(y),!v)throw new Error(`Unknown target ${y}`)}else v=document.createElement(`${r}-editor`),v.style.display="block",e.after(v);v.id||(v.id=s(r)),v.hasAttribute("exec-id")||v.setAttribute("exec-id",0),v.hasAttribute("root")||v.setAttribute("root",v.id);const f=`${n}-${e.getAttribute("env")||s(r)}`,g={interpreter:n,env:f,get pySrc(){return L.state.doc.toString()},get outDiv(){return w}},h=c.bind(g),[b,w]=d(h,r);b.dataset.env=e.hasAttribute("env")?f:n;const E=b.querySelector(`.${r}-editor-input > div`).attachShadow({mode:"open"});E.innerHTML="<style> :host { all: initial; }</style>",v.appendChild(b);const $=t(e.textContent).trim(),A=/^(\s+)/m.test($)?RegExp.$1:" ",L=new i({extensions:[u.of(A),(new a).of(l()),m.of([...p,{key:"Ctrl-Enter",run:h,preventDefault:!0},{key:"Cmd-Enter",run:h,preventDefault:!0},{key:"Shift-Enter",run:h,preventDefault:!0}]),o],parent:E,doc:$});L.focus()};let m=0,p=Promise.resolve();const y=()=>{m=0,v()},v=async()=>{if(!m){m=setTimeout(y,250);for(const[t,r]of e){const e=`script[type="${t}-editor"]`;for(const n of document.querySelectorAll(e))n.type+="-active",p=p.then((()=>u(n,t,r)))}return p}};new MutationObserver(v).observe(document,{childList:!0,subtree:!0});var f=v();export{f as default};
|
2
|
+
//# sourceMappingURL=py-editor-1Il3Lcfv.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"py-editor-d8hnd4Gu.js","sources":["../src/plugins/py-editor.js"],"sourcesContent":["// PyScript py-editor plugin\nimport { Hook, XWorker, dedent } from \"polyscript/exports\";\nimport { TYPES } from \"../core.js\";\n\nconst RUN_BUTTON = `<svg style=\"height:20px;width:20px;vertical-align:-.125em;transform-origin:center;overflow:visible;color:green\" viewBox=\"0 0 384 512\" aria-hidden=\"true\" role=\"img\" xmlns=\"http://www.w3.org/2000/svg\"><g transform=\"translate(192 256)\" transform-origin=\"96 0\"><g transform=\"translate(0,0) scale(1,1)\"><path d=\"M361 215C375.3 223.8 384 239.3 384 256C384 272.7 375.3 288.2 361 296.1L73.03 472.1C58.21 482 39.66 482.4 24.52 473.9C9.377 465.4 0 449.4 0 432V80C0 62.64 9.377 46.63 24.52 38.13C39.66 29.64 58.21 29.99 73.03 39.04L361 215z\" fill=\"currentColor\" transform=\"translate(-192 -256)\"></path></g></g></svg>`;\n\nlet id = 0;\nconst getID = (type) => `${type}-editor-${id++}`;\n\nconst envs = new Map();\n\nconst hooks = {\n worker: {\n // works on both Pyodide and MicroPython\n onReady: ({ runAsync, io }, { sync }) => {\n io.stdout = (line) => sync.write(line);\n io.stderr = (line) => sync.writeErr(line);\n sync.revoke();\n sync.runAsync = runAsync;\n },\n },\n};\n\nasync function execute({ currentTarget }) {\n const { env, pySrc, outDiv } = this;\n\n currentTarget.disabled = true;\n outDiv.innerHTML = \"\";\n\n if (!envs.has(env)) {\n const srcLink = URL.createObjectURL(new Blob([\"\"]));\n const xworker = XWorker.call(new Hook(null, hooks), srcLink, {\n type: this.interpreter,\n });\n\n const { sync } = xworker;\n const { promise, resolve } = Promise.withResolvers();\n envs.set(env, promise);\n sync.revoke = () => {\n URL.revokeObjectURL(srcLink);\n resolve(xworker);\n };\n }\n\n // wait for the env then set the target div\n // before executing the current code\n envs.get(env).then((xworker) => {\n xworker.onerror = ({ error }) => {\n outDiv.innerHTML += `<span style='color:red'>${\n error.message || error\n }</span>\\n`;\n console.error(error);\n };\n\n const enable = () => {\n currentTarget.disabled = false;\n };\n const { sync } = xworker;\n sync.write = (str) => {\n outDiv.innerText += `${str}\\n`;\n };\n sync.writeErr = (str) => {\n outDiv.innerHTML += `<span style='color:red'>${str}</span>\\n`;\n };\n sync.runAsync(pySrc).then(enable, enable);\n });\n}\n\nconst makeRunButton = (listener, type) => {\n const runButton = document.createElement(\"button\");\n runButton.className = `absolute ${type}-editor-run-button`;\n runButton.innerHTML = RUN_BUTTON;\n runButton.setAttribute(\"aria-label\", \"Python Script Run Button\");\n runButton.addEventListener(\"click\", listener);\n return runButton;\n};\n\nconst makeEditorDiv = (listener, type) => {\n const editorDiv = document.createElement(\"div\");\n editorDiv.className = `${type}-editor-input`;\n editorDiv.setAttribute(\"aria-label\", \"Python Script Area\");\n\n const runButton = makeRunButton(listener, type);\n const editorShadowContainer = document.createElement(\"div\");\n\n // avoid outer elements intercepting key events (reveal as example)\n editorShadowContainer.addEventListener(\"keydown\", (event) => {\n event.stopPropagation();\n });\n\n editorDiv.append(runButton, editorShadowContainer);\n\n return editorDiv;\n};\n\nconst makeOutDiv = (type) => {\n const outDiv = document.createElement(\"div\");\n outDiv.className = `${type}-editor-output`;\n outDiv.id = `${getID(type)}-output`;\n return outDiv;\n};\n\nconst makeBoxDiv = (listener, type) => {\n const boxDiv = document.createElement(\"div\");\n boxDiv.className = `${type}-editor-box`;\n\n const editorDiv = makeEditorDiv(listener, type);\n const outDiv = makeOutDiv(type);\n boxDiv.append(editorDiv, outDiv);\n\n return [boxDiv, outDiv];\n};\n\nconst init = async (script, type, interpreter) => {\n const [\n { basicSetup, EditorView },\n { Compartment },\n { python },\n { indentUnit },\n { keymap },\n { defaultKeymap },\n ] = await Promise.all([\n // TODO: find a way to actually produce these bundles locally\n import(/* webpackIgnore: true */ \"../3rd-party/codemirror.js\"),\n import(/* webpackIgnore: true */ \"../3rd-party/codemirror_state.js\"),\n import(\n /* webpackIgnore: true */ \"../3rd-party/codemirror_lang-python.js\"\n ),\n import(/* webpackIgnore: true */ \"../3rd-party/codemirror_language.js\"),\n import(/* webpackIgnore: true */ \"../3rd-party/codemirror_view.js\"),\n import(/* webpackIgnore: true */ \"../3rd-party/codemirror_commands.js\"),\n ]);\n\n const selector = script.getAttribute(\"target\");\n\n let target;\n if (selector) {\n target =\n document.getElementById(selector) ||\n document.querySelector(selector);\n if (!target) throw new Error(`Unknown target ${selector}`);\n } else {\n target = document.createElement(`${type}-editor`);\n target.style.display = \"block\";\n script.after(target);\n }\n\n if (!target.id) target.id = getID(type);\n if (!target.hasAttribute(\"exec-id\")) target.setAttribute(\"exec-id\", 0);\n if (!target.hasAttribute(\"root\")) target.setAttribute(\"root\", target.id);\n\n const env = `${interpreter}-${script.getAttribute(\"env\") || getID(type)}`;\n const context = {\n interpreter,\n env,\n get pySrc() {\n return editor.state.doc.toString();\n },\n get outDiv() {\n return outDiv;\n },\n };\n\n // @see https://github.com/JeffersGlass/mkdocs-pyscript/blob/main/mkdocs_pyscript/js/makeblocks.js\n const listener = execute.bind(context);\n const [boxDiv, outDiv] = makeBoxDiv(listener, type);\n boxDiv.dataset.env = script.hasAttribute(\"env\") ? env : interpreter;\n\n const inputChild = boxDiv.querySelector(`.${type}-editor-input > div`);\n const parent = inputChild.attachShadow({ mode: \"open\" });\n // avoid inheriting styles from the outer component\n parent.innerHTML = `<style> :host { all: initial; }</style>`;\n\n target.appendChild(boxDiv);\n\n const doc = dedent(script.textContent).trim();\n\n // preserve user indentation, if any\n const indentation = /^(\\s+)/m.test(doc) ? RegExp.$1 : \" \";\n\n const editor = new EditorView({\n extensions: [\n indentUnit.of(indentation),\n new Compartment().of(python()),\n keymap.of([\n ...defaultKeymap,\n { key: \"Ctrl-Enter\", run: listener, preventDefault: true },\n { key: \"Cmd-Enter\", run: listener, preventDefault: true },\n { key: \"Shift-Enter\", run: listener, preventDefault: true },\n ]),\n basicSetup,\n ],\n parent,\n doc,\n });\n\n editor.focus();\n};\n\n// avoid too greedy MutationObserver operations at distance\nlet timeout = 0;\n\n// avoid delayed initialization\nlet queue = Promise.resolve();\n\n// reset interval value then check for new scripts\nconst resetTimeout = () => {\n timeout = 0;\n pyEditor();\n};\n\n// triggered both ASAP on the living DOM and via MutationObserver later\nconst pyEditor = async () => {\n if (timeout) return;\n timeout = setTimeout(resetTimeout, 250);\n for (const [type, interpreter] of TYPES) {\n const selector = `script[type=\"${type}-editor\"]`;\n for (const script of document.querySelectorAll(selector)) {\n // avoid any further bootstrap by changing the type as active\n script.type += \"-active\";\n // don't await in here or multiple calls might happen\n // while the first script is being initialized\n queue = queue.then(() => init(script, type, interpreter));\n }\n }\n return queue;\n};\n\nnew MutationObserver(pyEditor).observe(document, {\n childList: true,\n subtree: true,\n});\n\n// try to check the current document ASAP\nexport default pyEditor();\n"],"names":["id","getID","type","envs","Map","hooks","worker","onReady","runAsync","io","sync","stdout","line","write","stderr","writeErr","revoke","async","execute","currentTarget","env","pySrc","outDiv","this","disabled","innerHTML","has","srcLink","URL","createObjectURL","Blob","xworker","XWorker","call","Hook","interpreter","promise","resolve","Promise","withResolvers","set","revokeObjectURL","get","then","onerror","error","message","console","enable","str","innerText","makeEditorDiv","listener","editorDiv","document","createElement","className","setAttribute","runButton","addEventListener","makeRunButton","editorShadowContainer","event","stopPropagation","append","makeBoxDiv","boxDiv","makeOutDiv","init","script","basicSetup","EditorView","Compartment","python","indentUnit","keymap","defaultKeymap","all","import","n","x","q","selector","getAttribute","target","getElementById","querySelector","Error","style","display","after","hasAttribute","context","editor","state","doc","toString","bind","dataset","parent","attachShadow","mode","appendChild","dedent","textContent","trim","indentation","test","RegExp","$1","extensions","of","key","run","preventDefault","focus","timeout","queue","resetTimeout","pyEditor","setTimeout","TYPES","querySelectorAll","MutationObserver","observe","childList","subtree","pyEditor$1"],"mappings":"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"}
|
1
|
+
{"version":3,"file":"py-editor-1Il3Lcfv.js","sources":["../src/plugins/py-editor.js"],"sourcesContent":["// PyScript py-editor plugin\nimport { Hook, XWorker, dedent } from \"polyscript/exports\";\nimport { TYPES } from \"../core.js\";\n\nconst RUN_BUTTON = `<svg style=\"height:20px;width:20px;vertical-align:-.125em;transform-origin:center;overflow:visible;color:green\" viewBox=\"0 0 384 512\" aria-hidden=\"true\" role=\"img\" xmlns=\"http://www.w3.org/2000/svg\"><g transform=\"translate(192 256)\" transform-origin=\"96 0\"><g transform=\"translate(0,0) scale(1,1)\"><path d=\"M361 215C375.3 223.8 384 239.3 384 256C384 272.7 375.3 288.2 361 296.1L73.03 472.1C58.21 482 39.66 482.4 24.52 473.9C9.377 465.4 0 449.4 0 432V80C0 62.64 9.377 46.63 24.52 38.13C39.66 29.64 58.21 29.99 73.03 39.04L361 215z\" fill=\"currentColor\" transform=\"translate(-192 -256)\"></path></g></g></svg>`;\n\nlet id = 0;\nconst getID = (type) => `${type}-editor-${id++}`;\n\nconst envs = new Map();\n\nconst hooks = {\n worker: {\n // works on both Pyodide and MicroPython\n onReady: ({ runAsync, io }, { sync }) => {\n io.stdout = (line) => sync.write(line);\n io.stderr = (line) => sync.writeErr(line);\n sync.revoke();\n sync.runAsync = runAsync;\n },\n },\n};\n\nasync function execute({ currentTarget }) {\n const { env, pySrc, outDiv } = this;\n\n currentTarget.disabled = true;\n outDiv.innerHTML = \"\";\n\n if (!envs.has(env)) {\n const srcLink = URL.createObjectURL(new Blob([\"\"]));\n const xworker = XWorker.call(new Hook(null, hooks), srcLink, {\n type: this.interpreter,\n });\n\n const { sync } = xworker;\n const { promise, resolve } = Promise.withResolvers();\n envs.set(env, promise);\n sync.revoke = () => {\n URL.revokeObjectURL(srcLink);\n resolve(xworker);\n };\n }\n\n // wait for the env then set the target div\n // before executing the current code\n envs.get(env).then((xworker) => {\n xworker.onerror = ({ error }) => {\n outDiv.innerHTML += `<span style='color:red'>${\n error.message || error\n }</span>\\n`;\n console.error(error);\n };\n\n const enable = () => {\n currentTarget.disabled = false;\n };\n const { sync } = xworker;\n sync.write = (str) => {\n outDiv.innerText += `${str}\\n`;\n };\n sync.writeErr = (str) => {\n outDiv.innerHTML += `<span style='color:red'>${str}</span>\\n`;\n };\n sync.runAsync(pySrc).then(enable, enable);\n });\n}\n\nconst makeRunButton = (listener, type) => {\n const runButton = document.createElement(\"button\");\n runButton.className = `absolute ${type}-editor-run-button`;\n runButton.innerHTML = RUN_BUTTON;\n runButton.setAttribute(\"aria-label\", \"Python Script Run Button\");\n runButton.addEventListener(\"click\", listener);\n return runButton;\n};\n\nconst makeEditorDiv = (listener, type) => {\n const editorDiv = document.createElement(\"div\");\n editorDiv.className = `${type}-editor-input`;\n editorDiv.setAttribute(\"aria-label\", \"Python Script Area\");\n\n const runButton = makeRunButton(listener, type);\n const editorShadowContainer = document.createElement(\"div\");\n\n // avoid outer elements intercepting key events (reveal as example)\n editorShadowContainer.addEventListener(\"keydown\", (event) => {\n event.stopPropagation();\n });\n\n editorDiv.append(runButton, editorShadowContainer);\n\n return editorDiv;\n};\n\nconst makeOutDiv = (type) => {\n const outDiv = document.createElement(\"div\");\n outDiv.className = `${type}-editor-output`;\n outDiv.id = `${getID(type)}-output`;\n return outDiv;\n};\n\nconst makeBoxDiv = (listener, type) => {\n const boxDiv = document.createElement(\"div\");\n boxDiv.className = `${type}-editor-box`;\n\n const editorDiv = makeEditorDiv(listener, type);\n const outDiv = makeOutDiv(type);\n boxDiv.append(editorDiv, outDiv);\n\n return [boxDiv, outDiv];\n};\n\nconst init = async (script, type, interpreter) => {\n const [\n { basicSetup, EditorView },\n { Compartment },\n { python },\n { indentUnit },\n { keymap },\n { defaultKeymap },\n ] = await Promise.all([\n // TODO: find a way to actually produce these bundles locally\n import(/* webpackIgnore: true */ \"../3rd-party/codemirror.js\"),\n import(/* webpackIgnore: true */ \"../3rd-party/codemirror_state.js\"),\n import(\n /* webpackIgnore: true */ \"../3rd-party/codemirror_lang-python.js\"\n ),\n import(/* webpackIgnore: true */ \"../3rd-party/codemirror_language.js\"),\n import(/* webpackIgnore: true */ \"../3rd-party/codemirror_view.js\"),\n import(/* webpackIgnore: true */ \"../3rd-party/codemirror_commands.js\"),\n ]);\n\n const selector = script.getAttribute(\"target\");\n\n let target;\n if (selector) {\n target =\n document.getElementById(selector) ||\n document.querySelector(selector);\n if (!target) throw new Error(`Unknown target ${selector}`);\n } else {\n target = document.createElement(`${type}-editor`);\n target.style.display = \"block\";\n script.after(target);\n }\n\n if (!target.id) target.id = getID(type);\n if (!target.hasAttribute(\"exec-id\")) target.setAttribute(\"exec-id\", 0);\n if (!target.hasAttribute(\"root\")) target.setAttribute(\"root\", target.id);\n\n const env = `${interpreter}-${script.getAttribute(\"env\") || getID(type)}`;\n const context = {\n interpreter,\n env,\n get pySrc() {\n return editor.state.doc.toString();\n },\n get outDiv() {\n return outDiv;\n },\n };\n\n // @see https://github.com/JeffersGlass/mkdocs-pyscript/blob/main/mkdocs_pyscript/js/makeblocks.js\n const listener = execute.bind(context);\n const [boxDiv, outDiv] = makeBoxDiv(listener, type);\n boxDiv.dataset.env = script.hasAttribute(\"env\") ? env : interpreter;\n\n const inputChild = boxDiv.querySelector(`.${type}-editor-input > div`);\n const parent = inputChild.attachShadow({ mode: \"open\" });\n // avoid inheriting styles from the outer component\n parent.innerHTML = `<style> :host { all: initial; }</style>`;\n\n target.appendChild(boxDiv);\n\n const doc = dedent(script.textContent).trim();\n\n // preserve user indentation, if any\n const indentation = /^(\\s+)/m.test(doc) ? RegExp.$1 : \" \";\n\n const editor = new EditorView({\n extensions: [\n indentUnit.of(indentation),\n new Compartment().of(python()),\n keymap.of([\n ...defaultKeymap,\n { key: \"Ctrl-Enter\", run: listener, preventDefault: true },\n { key: \"Cmd-Enter\", run: listener, preventDefault: true },\n { key: \"Shift-Enter\", run: listener, preventDefault: true },\n ]),\n basicSetup,\n ],\n parent,\n doc,\n });\n\n editor.focus();\n};\n\n// avoid too greedy MutationObserver operations at distance\nlet timeout = 0;\n\n// avoid delayed initialization\nlet queue = Promise.resolve();\n\n// reset interval value then check for new scripts\nconst resetTimeout = () => {\n timeout = 0;\n pyEditor();\n};\n\n// triggered both ASAP on the living DOM and via MutationObserver later\nconst pyEditor = async () => {\n if (timeout) return;\n timeout = setTimeout(resetTimeout, 250);\n for (const [type, interpreter] of TYPES) {\n const selector = `script[type=\"${type}-editor\"]`;\n for (const script of document.querySelectorAll(selector)) {\n // avoid any further bootstrap by changing the type as active\n script.type += \"-active\";\n // don't await in here or multiple calls might happen\n // while the first script is being initialized\n queue = queue.then(() => init(script, type, interpreter));\n }\n }\n return queue;\n};\n\nnew MutationObserver(pyEditor).observe(document, {\n childList: true,\n subtree: true,\n});\n\n// try to check the current document ASAP\nexport default pyEditor();\n"],"names":["id","getID","type","envs","Map","hooks","worker","onReady","runAsync","io","sync","stdout","line","write","stderr","writeErr","revoke","async","execute","currentTarget","env","pySrc","outDiv","this","disabled","innerHTML","has","srcLink","URL","createObjectURL","Blob","xworker","XWorker","call","Hook","interpreter","promise","resolve","Promise","withResolvers","set","revokeObjectURL","get","then","onerror","error","message","console","enable","str","innerText","makeEditorDiv","listener","editorDiv","document","createElement","className","setAttribute","runButton","addEventListener","makeRunButton","editorShadowContainer","event","stopPropagation","append","makeBoxDiv","boxDiv","makeOutDiv","init","script","basicSetup","EditorView","Compartment","python","indentUnit","keymap","defaultKeymap","all","import","n","x","q","selector","getAttribute","target","getElementById","querySelector","Error","style","display","after","hasAttribute","context","editor","state","doc","toString","bind","dataset","parent","attachShadow","mode","appendChild","dedent","textContent","trim","indentation","test","RegExp","$1","extensions","of","key","run","preventDefault","focus","timeout","queue","resetTimeout","pyEditor","setTimeout","TYPES","querySelectorAll","MutationObserver","observe","childList","subtree","pyEditor$1"],"mappings":"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"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{T as e,e as t,a as r}from"./core-
|
2
|
-
//# sourceMappingURL=py-terminal-
|
1
|
+
import{T as e,e as t,a as r}from"./core-78rkmWeI.js";import{notify as n}from"./error-sz_Yjd9A.js";const i=[...e.keys()].map((e=>`script[type="${e}"][terminal],${e}-script[terminal]`)).join(","),a=e=>{throw n(e),new Error(e)},o=e=>!l.has(e),s=({attributes:{worker:e}})=>!e,l=new WeakSet;let d=!0;const m=({interpreter:e,io:t,run:r},{sync:n})=>{if(!n.is_pyterminal())return;r("from polyscript.currentScript import terminal as __terminal__");const i=new TextDecoder;let a="";const o={isatty:!0,write:e=>(a=i.decode(e),n.pyterminal_write(a),e.length)};e.setStdout(o),e.setStderr(o),e.setStdin({isatty:!0,stdin:()=>n.pyterminal_read(a)}),t.stderr=e=>{n.pyterminal_write(`${e.message||e}\n`)}},c=async()=>{const e=document.querySelectorAll(i),n=[].filter.call(e,o);if(!n.length)return;n.forEach(l.add,l),[].filter.call(e,s).length>1&&a("You can use at most 1 main terminal"),d&&(d=!1,document.head.append(Object.assign(document.createElement("link"),{rel:"stylesheet",href:new URL("./xterm.css",import.meta.url)})));const[{Terminal:c},{Readline:p},{FitAddon:y}]=await Promise.all([import("./xterm-f2QfYNGL.js"),import("./xterm-readline-ONk85xtH.js"),import("./xterm_addon-fit-E4yMPZTX.js")]);for(const e of n){e.matches('script[type="mpy"],mpy-script')&&a("Unsupported terminal.");const n=new p,i=t=>{let i=e;const a=e.getAttribute("target");if(a){if(i=document.getElementById(a)||document.querySelector(a),!i)throw new Error(`Unknown target ${a}`)}else i=document.createElement("py-terminal"),i.style.display="block",e.after(i);const o=new c({theme:{background:"#191A19",foreground:"#F5F2E7"},...t}),s=new y;return o.loadAddon(s),o.loadAddon(n),o.open(i),s.fit(),o.focus(),r(e,"terminal",{value:o}),o};e.hasAttribute("worker")?(t.main.onWorker.add((function e(r,a){l.has(a)||(l.add(a),t.main.onWorker.delete(e),i({disableStdin:!1,cursorBlink:!0,cursorStyle:"block"}),a.sync.is_pyterminal=()=>!0,a.sync.pyterminal_read=n.read.bind(n),a.sync.pyterminal_write=n.write.bind(n))})),t.worker.onReady.add(m)):t.main.onReady.add((function e({interpreter:r,io:a,run:o}){console.warn("py-terminal is read only on main thread"),t.main.onReady.delete(e),globalThis.__py_terminal__=i({disableStdin:!0,cursorBlink:!1,cursorStyle:"underline"}),o("from js import __py_terminal__ as __terminal__"),delete globalThis.__py_terminal__;const s=new TextDecoder;let l="";const d={isatty:!0,write:e=>(l=s.decode(e),n.write(l),e.length)};r.setStdout(d),r.setStderr(d),r.setStdin({isatty:!0,stdin:()=>n.read(l)}),a.stderr=e=>{n.write(`${e.message||e}\n`)}}))}};new MutationObserver(c).observe(document,{childList:!0,subtree:!0});var p=c();export{p as default};
|
2
|
+
//# sourceMappingURL=py-terminal-E5d6qafs.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"py-terminal-HcALwKhy.js","sources":["../src/plugins/py-terminal.js"],"sourcesContent":["// PyScript py-terminal plugin\nimport { TYPES, hooks } from \"../core.js\";\nimport { notify } from \"./error.js\";\nimport { defineProperty } from \"polyscript/exports\";\n\nconst SELECTOR = [...TYPES.keys()]\n .map((type) => `script[type=\"${type}\"][terminal],${type}-script[terminal]`)\n .join(\",\");\n\n// show the error on main and\n// stops the module from keep executing\nconst notifyAndThrow = (message) => {\n notify(message);\n throw new Error(message);\n};\n\nconst notParsedYet = (script) => !bootstrapped.has(script);\n\nconst onceOnMain = ({ attributes: { worker } }) => !worker;\n\nconst bootstrapped = new WeakSet();\n\nlet addStyle = true;\n\n// this callback will be serialized as string and it never needs\n// to be invoked multiple times. Each xworker here is bootstrapped\n// only once thanks to the `sync.is_pyterminal()` check.\nconst workerReady = ({ interpreter, io, run }, { sync }) => {\n if (!sync.is_pyterminal()) return;\n\n // in workers it's always safe to grab the polyscript currentScript\n run(\"from polyscript.currentScript import terminal as __terminal__\");\n\n // This part is inevitably duplicated as external scope\n // can't be reached by workers out of the box.\n // The detail is that here we use sync though, not readline.\n const decoder = new TextDecoder();\n let data = \"\";\n const generic = {\n isatty: true,\n write(buffer) {\n data = decoder.decode(buffer);\n sync.pyterminal_write(data);\n return buffer.length;\n },\n };\n interpreter.setStdout(generic);\n interpreter.setStderr(generic);\n interpreter.setStdin({\n isatty: true,\n stdin: () => sync.pyterminal_read(data),\n });\n\n io.stderr = (error) => {\n sync.pyterminal_write(`${error.message || error}\\n`);\n };\n};\n\nconst pyTerminal = async () => {\n const terminals = document.querySelectorAll(SELECTOR);\n\n const unknown = [].filter.call(terminals, notParsedYet);\n\n // no results will look further for runtime nodes\n if (!unknown.length) return;\n // early flag elements as known to avoid concurrent\n // MutationObserver invokes of this async handler\n else unknown.forEach(bootstrapped.add, bootstrapped);\n\n // we currently support only one terminal as in \"classic\"\n if ([].filter.call(terminals, onceOnMain).length > 1)\n notifyAndThrow(\"You can use at most 1 main terminal\");\n\n // import styles lazily\n if (addStyle) {\n addStyle = false;\n document.head.append(\n Object.assign(document.createElement(\"link\"), {\n rel: \"stylesheet\",\n href: new URL(\"./xterm.css\", import.meta.url),\n }),\n );\n }\n\n // lazy load these only when a valid terminal is found\n const [{ Terminal }, { Readline }, { FitAddon }] = await Promise.all([\n import(/* webpackIgnore: true */ \"../3rd-party/xterm.js\"),\n import(/* webpackIgnore: true */ \"../3rd-party/xterm-readline.js\"),\n import(/* webpackIgnore: true */ \"../3rd-party/xterm_addon-fit.js\"),\n ]);\n\n for (const element of unknown) {\n // hopefully to be removed in the near future!\n if (element.matches('script[type=\"mpy\"],mpy-script'))\n notifyAndThrow(\"Unsupported terminal.\");\n\n const readline = new Readline();\n\n // common main thread initialization for both worker\n // or main case, bootstrapping the terminal on its target\n const init = (options) => {\n let target = element;\n const selector = element.getAttribute(\"target\");\n if (selector) {\n target =\n document.getElementById(selector) ||\n document.querySelector(selector);\n if (!target) throw new Error(`Unknown target ${selector}`);\n } else {\n target = document.createElement(\"py-terminal\");\n target.style.display = \"block\";\n element.after(target);\n }\n const terminal = new Terminal({\n theme: {\n background: \"#191A19\",\n foreground: \"#F5F2E7\",\n },\n ...options,\n });\n const fitAddon = new FitAddon();\n terminal.loadAddon(fitAddon);\n terminal.loadAddon(readline);\n terminal.open(target);\n fitAddon.fit();\n terminal.focus();\n defineProperty(element, \"terminal\", { value: terminal });\n return terminal;\n };\n\n // branch logic for the worker\n if (element.hasAttribute(\"worker\")) {\n // add a hook on the main thread to setup all sync helpers\n // also bootstrapping the XTerm target on main *BUT* ...\n hooks.main.onWorker.add(function worker(_, xworker) {\n // ... as multiple workers will add multiple callbacks\n // be sure no xworker is ever initialized twice!\n if (bootstrapped.has(xworker)) return;\n bootstrapped.add(xworker);\n\n // still cleanup this callback for future scripts/workers\n hooks.main.onWorker.delete(worker);\n\n init({\n disableStdin: false,\n cursorBlink: true,\n cursorStyle: \"block\",\n });\n\n xworker.sync.is_pyterminal = () => true;\n xworker.sync.pyterminal_read = readline.read.bind(readline);\n xworker.sync.pyterminal_write = readline.write.bind(readline);\n });\n\n // setup remote thread JS/Python code for whenever the\n // worker is ready to become a terminal\n hooks.worker.onReady.add(workerReady);\n } else {\n // in the main case, just bootstrap XTerm without\n // allowing any input as that's not possible / awkward\n hooks.main.onReady.add(function main({ interpreter, io, run }) {\n console.warn(\"py-terminal is read only on main thread\");\n hooks.main.onReady.delete(main);\n\n // on main, it's easy to trash and clean the current terminal\n globalThis.__py_terminal__ = init({\n disableStdin: true,\n cursorBlink: false,\n cursorStyle: \"underline\",\n });\n run(\"from js import __py_terminal__ as __terminal__\");\n delete globalThis.__py_terminal__;\n\n // This part is inevitably duplicated as external scope\n // can't be reached by workers out of the box.\n // The detail is that here we use readline here, not sync.\n const decoder = new TextDecoder();\n let data = \"\";\n const generic = {\n isatty: true,\n write(buffer) {\n data = decoder.decode(buffer);\n readline.write(data);\n return buffer.length;\n },\n };\n interpreter.setStdout(generic);\n interpreter.setStderr(generic);\n interpreter.setStdin({\n isatty: true,\n stdin: () => readline.read(data),\n });\n\n io.stderr = (error) => {\n readline.write(`${error.message || error}\\n`);\n };\n });\n }\n }\n};\n\nconst mo = new MutationObserver(pyTerminal);\nmo.observe(document, { childList: true, subtree: true });\n\n// try to check the current document ASAP\nexport default pyTerminal();\n"],"names":["SELECTOR","TYPES","keys","map","type","join","notifyAndThrow","message","notify","Error","notParsedYet","script","bootstrapped","has","onceOnMain","attributes","worker","WeakSet","addStyle","workerReady","interpreter","io","run","sync","is_pyterminal","decoder","TextDecoder","data","generic","isatty","write","buffer","decode","pyterminal_write","length","setStdout","setStderr","setStdin","stdin","pyterminal_read","stderr","error","pyTerminal","async","terminals","document","querySelectorAll","unknown","filter","call","forEach","add","head","append","Object","assign","createElement","rel","href","URL","url","Terminal","Readline","FitAddon","Promise","all","import","element","matches","readline","init","options","target","selector","getAttribute","getElementById","querySelector","style","display","after","terminal","theme","background","foreground","fitAddon","loadAddon","open","fit","focus","defineProperty","value","hasAttribute","hooks","main","onWorker","_","xworker","delete","disableStdin","cursorBlink","cursorStyle","read","bind","onReady","console","warn","globalThis","__py_terminal__","MutationObserver","observe","childList","subtree","pyTerminal$1"],"mappings":"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"}
|
1
|
+
{"version":3,"file":"py-terminal-E5d6qafs.js","sources":["../src/plugins/py-terminal.js"],"sourcesContent":["// PyScript py-terminal plugin\nimport { TYPES, hooks } from \"../core.js\";\nimport { notify } from \"./error.js\";\nimport { defineProperty } from \"polyscript/exports\";\n\nconst SELECTOR = [...TYPES.keys()]\n .map((type) => `script[type=\"${type}\"][terminal],${type}-script[terminal]`)\n .join(\",\");\n\n// show the error on main and\n// stops the module from keep executing\nconst notifyAndThrow = (message) => {\n notify(message);\n throw new Error(message);\n};\n\nconst notParsedYet = (script) => !bootstrapped.has(script);\n\nconst onceOnMain = ({ attributes: { worker } }) => !worker;\n\nconst bootstrapped = new WeakSet();\n\nlet addStyle = true;\n\n// this callback will be serialized as string and it never needs\n// to be invoked multiple times. Each xworker here is bootstrapped\n// only once thanks to the `sync.is_pyterminal()` check.\nconst workerReady = ({ interpreter, io, run }, { sync }) => {\n if (!sync.is_pyterminal()) return;\n\n // in workers it's always safe to grab the polyscript currentScript\n run(\"from polyscript.currentScript import terminal as __terminal__\");\n\n // This part is inevitably duplicated as external scope\n // can't be reached by workers out of the box.\n // The detail is that here we use sync though, not readline.\n const decoder = new TextDecoder();\n let data = \"\";\n const generic = {\n isatty: true,\n write(buffer) {\n data = decoder.decode(buffer);\n sync.pyterminal_write(data);\n return buffer.length;\n },\n };\n interpreter.setStdout(generic);\n interpreter.setStderr(generic);\n interpreter.setStdin({\n isatty: true,\n stdin: () => sync.pyterminal_read(data),\n });\n\n io.stderr = (error) => {\n sync.pyterminal_write(`${error.message || error}\\n`);\n };\n};\n\nconst pyTerminal = async () => {\n const terminals = document.querySelectorAll(SELECTOR);\n\n const unknown = [].filter.call(terminals, notParsedYet);\n\n // no results will look further for runtime nodes\n if (!unknown.length) return;\n // early flag elements as known to avoid concurrent\n // MutationObserver invokes of this async handler\n else unknown.forEach(bootstrapped.add, bootstrapped);\n\n // we currently support only one terminal as in \"classic\"\n if ([].filter.call(terminals, onceOnMain).length > 1)\n notifyAndThrow(\"You can use at most 1 main terminal\");\n\n // import styles lazily\n if (addStyle) {\n addStyle = false;\n document.head.append(\n Object.assign(document.createElement(\"link\"), {\n rel: \"stylesheet\",\n href: new URL(\"./xterm.css\", import.meta.url),\n }),\n );\n }\n\n // lazy load these only when a valid terminal is found\n const [{ Terminal }, { Readline }, { FitAddon }] = await Promise.all([\n import(/* webpackIgnore: true */ \"../3rd-party/xterm.js\"),\n import(/* webpackIgnore: true */ \"../3rd-party/xterm-readline.js\"),\n import(/* webpackIgnore: true */ \"../3rd-party/xterm_addon-fit.js\"),\n ]);\n\n for (const element of unknown) {\n // hopefully to be removed in the near future!\n if (element.matches('script[type=\"mpy\"],mpy-script'))\n notifyAndThrow(\"Unsupported terminal.\");\n\n const readline = new Readline();\n\n // common main thread initialization for both worker\n // or main case, bootstrapping the terminal on its target\n const init = (options) => {\n let target = element;\n const selector = element.getAttribute(\"target\");\n if (selector) {\n target =\n document.getElementById(selector) ||\n document.querySelector(selector);\n if (!target) throw new Error(`Unknown target ${selector}`);\n } else {\n target = document.createElement(\"py-terminal\");\n target.style.display = \"block\";\n element.after(target);\n }\n const terminal = new Terminal({\n theme: {\n background: \"#191A19\",\n foreground: \"#F5F2E7\",\n },\n ...options,\n });\n const fitAddon = new FitAddon();\n terminal.loadAddon(fitAddon);\n terminal.loadAddon(readline);\n terminal.open(target);\n fitAddon.fit();\n terminal.focus();\n defineProperty(element, \"terminal\", { value: terminal });\n return terminal;\n };\n\n // branch logic for the worker\n if (element.hasAttribute(\"worker\")) {\n // add a hook on the main thread to setup all sync helpers\n // also bootstrapping the XTerm target on main *BUT* ...\n hooks.main.onWorker.add(function worker(_, xworker) {\n // ... as multiple workers will add multiple callbacks\n // be sure no xworker is ever initialized twice!\n if (bootstrapped.has(xworker)) return;\n bootstrapped.add(xworker);\n\n // still cleanup this callback for future scripts/workers\n hooks.main.onWorker.delete(worker);\n\n init({\n disableStdin: false,\n cursorBlink: true,\n cursorStyle: \"block\",\n });\n\n xworker.sync.is_pyterminal = () => true;\n xworker.sync.pyterminal_read = readline.read.bind(readline);\n xworker.sync.pyterminal_write = readline.write.bind(readline);\n });\n\n // setup remote thread JS/Python code for whenever the\n // worker is ready to become a terminal\n hooks.worker.onReady.add(workerReady);\n } else {\n // in the main case, just bootstrap XTerm without\n // allowing any input as that's not possible / awkward\n hooks.main.onReady.add(function main({ interpreter, io, run }) {\n console.warn(\"py-terminal is read only on main thread\");\n hooks.main.onReady.delete(main);\n\n // on main, it's easy to trash and clean the current terminal\n globalThis.__py_terminal__ = init({\n disableStdin: true,\n cursorBlink: false,\n cursorStyle: \"underline\",\n });\n run(\"from js import __py_terminal__ as __terminal__\");\n delete globalThis.__py_terminal__;\n\n // This part is inevitably duplicated as external scope\n // can't be reached by workers out of the box.\n // The detail is that here we use readline here, not sync.\n const decoder = new TextDecoder();\n let data = \"\";\n const generic = {\n isatty: true,\n write(buffer) {\n data = decoder.decode(buffer);\n readline.write(data);\n return buffer.length;\n },\n };\n interpreter.setStdout(generic);\n interpreter.setStderr(generic);\n interpreter.setStdin({\n isatty: true,\n stdin: () => readline.read(data),\n });\n\n io.stderr = (error) => {\n readline.write(`${error.message || error}\\n`);\n };\n });\n }\n }\n};\n\nconst mo = new MutationObserver(pyTerminal);\nmo.observe(document, { childList: true, subtree: true });\n\n// try to check the current document ASAP\nexport default pyTerminal();\n"],"names":["SELECTOR","TYPES","keys","map","type","join","notifyAndThrow","message","notify","Error","notParsedYet","script","bootstrapped","has","onceOnMain","attributes","worker","WeakSet","addStyle","workerReady","interpreter","io","run","sync","is_pyterminal","decoder","TextDecoder","data","generic","isatty","write","buffer","decode","pyterminal_write","length","setStdout","setStderr","setStdin","stdin","pyterminal_read","stderr","error","pyTerminal","async","terminals","document","querySelectorAll","unknown","filter","call","forEach","add","head","append","Object","assign","createElement","rel","href","URL","url","Terminal","Readline","FitAddon","Promise","all","import","element","matches","readline","init","options","target","selector","getAttribute","getElementById","querySelector","style","display","after","terminal","theme","background","foreground","fitAddon","loadAddon","open","fit","focus","defineProperty","value","hasAttribute","hooks","main","onWorker","_","xworker","delete","disableStdin","cursorBlink","cursorStyle","read","bind","onReady","console","warn","globalThis","__py_terminal__","MutationObserver","observe","childList","subtree","pyTerminal$1"],"mappings":"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"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pyscript/core",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.23",
|
4
4
|
"type": "module",
|
5
5
|
"description": "PyScript",
|
6
6
|
"module": "./index.js",
|
@@ -42,7 +42,7 @@
|
|
42
42
|
"dependencies": {
|
43
43
|
"@ungap/with-resolvers": "^0.1.0",
|
44
44
|
"basic-devtools": "^0.1.6",
|
45
|
-
"polyscript": "^0.6.
|
45
|
+
"polyscript": "^0.6.18",
|
46
46
|
"sticky-module": "^0.1.1",
|
47
47
|
"to-json-callback": "^0.1.1",
|
48
48
|
"type-checked-collections": "^0.1.7"
|
package/dist/core-14p8E60X.js
DELETED
@@ -1,3 +0,0 @@
|
|
1
|
-
const e=(e,t,n=globalThis)=>{const r=Symbol.for(e),s=r in n;return[s?n[r]:Object.defineProperty(n,r,{value:t})[r],s]};Promise.withResolvers||(Promise.withResolvers=function(){var e,t,n=new this((function(n,r){e=n,t=r}));return{resolve:e,reject:t,promise:n}});const t=e=>e.arrayBuffer(),n=e=>e.json(),r=e=>e.text(),s=(e,t=document)=>[...t.querySelectorAll(e)],o=(e,t=document)=>{const n=(new XPathEvaluator).createExpression(e).evaluate(t,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE),r=[];for(let e=0,{snapshotLength:t}=n;e<t;e++)r.push(n.snapshotItem(e));return r},a="object"==typeof self?self:globalThis,i=e=>((e,t)=>{const n=(t,n)=>(e.set(n,t),t),r=s=>{if(e.has(s))return e.get(s);const[o,i]=t[s];switch(o){case 0:case-1:return n(i,s);case 1:{const e=n([],s);for(const t of i)e.push(r(t));return e}case 2:{const e=n({},s);for(const[t,n]of i)e[r(t)]=r(n);return e}case 3:return n(new Date(i),s);case 4:{const{source:e,flags:t}=i;return n(new RegExp(e,t),s)}case 5:{const e=n(new Map,s);for(const[t,n]of i)e.set(r(t),r(n));return e}case 6:{const e=n(new Set,s);for(const t of i)e.add(r(t));return e}case 7:{const{name:e,message:t}=i;return n(new a[e](t),s)}case 8:return n(BigInt(i),s);case"BigInt":return n(Object(BigInt(i)),s)}return n(new a[o](i),s)};return r})(new Map,e)(0),l="",{toString:c}={},{keys:p}=Object,f=e=>{const t=typeof e;if("object"!==t||!e)return[0,t];const n=c.call(e).slice(8,-1);switch(n){case"Array":return[1,l];case"Object":return[2,l];case"Date":return[3,l];case"RegExp":return[4,l];case"Map":return[5,l];case"Set":return[6,l]}return n.includes("Array")?[1,n]:n.includes("Error")?[7,n]:[2,n]},u=([e,t])=>0===e&&("function"===t||"symbol"===t),d=(e,{json:t,lossy:n}={})=>{const r=[];return((e,t,n,r)=>{const s=(e,t)=>{const s=r.push(e)-1;return n.set(t,s),s},o=r=>{if(n.has(r))return n.get(r);let[a,i]=f(r);switch(a){case 0:{let t=r;switch(i){case"bigint":a=8,t=r.toString();break;case"function":case"symbol":if(e)throw new TypeError("unable to serialize "+i);t=null;break;case"undefined":return s([-1],r)}return s([a,t],r)}case 1:{if(i)return s([i,[...r]],r);const e=[],t=s([a,e],r);for(const t of r)e.push(o(t));return t}case 2:{if(i)switch(i){case"BigInt":return s([i,r.toString()],r);case"Boolean":case"Number":case"String":return s([i,r.valueOf()],r)}if(t&&"toJSON"in r)return o(r.toJSON());const n=[],l=s([a,n],r);for(const t of p(r))!e&&u(f(r[t]))||n.push([o(t),o(r[t])]);return l}case 3:return s([a,r.toISOString()],r);case 4:{const{source:e,flags:t}=r;return s([a,{source:e,flags:t}],r)}case 5:{const t=[],n=s([a,t],r);for(const[n,s]of r)(e||!u(f(n))&&!u(f(s)))&&t.push([o(n),o(s)]);return n}case 6:{const t=[],n=s([a,t],r);for(const n of r)!e&&u(f(n))||t.push(o(n));return n}}const{message:l}=r;return s([a,{name:i,message:l}],r)};return o})(!(t||n),!!t,new Map,r)(e),r},{parse:h,stringify:m}=JSON,y={json:!0,lossy:!0};var g=Object.freeze({__proto__:null,parse:e=>i(h(e)),stringify:e=>m(d(e,y))});const _="ac6c1995-0675-46af-a99f-7fa298fa4e6d",w="M"+_,b="T"+_,v="array",E="function",k="null",j="number",R="object",A="string",T="symbol",x="undefined",S="apply",N="construct",O="defineProperty",I="deleteProperty",P="get",$="getOwnPropertyDescriptor",M="getPrototypeOf",F="has",C="isExtensible",H="ownKeys",L="preventExtensions",W="set",D="setPrototypeOf",B="delete";var U=e=>({value:new Promise((t=>{let n=new Worker("data:application/javascript,onmessage%3D(%7Bdata%3Ab%7D)%3D%3E(Atomics.wait(b%2C0)%2CpostMessage(0))");n.onmessage=t,n.postMessage(e)}))})
|
2
|
-
/*! (c) Andrea Giammarchi - ISC */;const{Int32Array:J,Map:q,SharedArrayBuffer:G,Uint16Array:Y}=globalThis,{BYTES_PER_ELEMENT:V}=J,{BYTES_PER_ELEMENT:K}=Y,{isArray:X}=Array,{notify:z,wait:Z,waitAsync:Q}=Atomics,ee=new WeakSet,te=new WeakMap,ne={value:{then:e=>e()}};let re=0;const se=(e,{parse:t=JSON.parse,stringify:n=JSON.stringify,transform:r,interrupt:s}=JSON)=>{if(!te.has(e)){const o=(t,...n)=>e.postMessage({[_]:n},{transfer:t}),a=typeof s===E?s:s?.handler,i=s?.delay||42,l=new TextDecoder("utf-16"),c=(e,t)=>e?(Q||U)(t,0):(a?((e,t,n)=>{for(;"timed-out"===Z(e,0,0,t);)n()})(t,i,a):Z(t,0),ne);let p=!1;te.set(e,new Proxy(new q,{[F]:(e,t)=>"string"==typeof t&&!t.startsWith("_"),[P]:(n,s)=>"then"===s?null:(...n)=>{const a=re++;let i=new J(new G(2*V)),f=[];ee.has(n.at(-1)||f)&&ee.delete(f=n.pop()),o(f,a,i,s,r?n.map(r):n);const u=e!==globalThis;let d=0;return p&&u&&(d=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${s}(...args) is awaited`)),c(u,i).value.then((()=>{clearTimeout(d);const e=i[1];if(!e)return;const n=K*e;return i=new J(new G(n+n%V)),o([],a,i),c(u,i).value.then((()=>t(l.decode(new Y(i.buffer).slice(0,e)))))}))},[W](t,s,o){const a=typeof o;if(a!==E)throw new Error(`Unable to assign ${s} as ${a}`);if(!t.size){const s=new q;e.addEventListener("message",(async e=>{const o=e.data?.[_];if(X(o)){e.stopImmediatePropagation();const[a,i,...l]=o;let c;if(l.length){const[e,o]=l;if(t.has(e)){p=!0;try{const l=await t.get(e)(...o);if(void 0!==l){const e=n(r?r(l):l);s.set(a,e),i[1]=e.length}}catch(e){c=e}finally{p=!1}}else c=new Error(`Unsupported action: ${e}`);i[0]=1}else{const e=s.get(a);s.delete(a);for(let t=new Y(i.buffer),n=0;n<e.length;n++)t[n]=e.charCodeAt(n)}if(z(i,0),c)throw c}}))}return!!t.set(s,o)}}))}return te.get(e)};se.transfer=(...e)=>(ee.add(e),e);const{isArray:oe}=Array,ae=(e,t)=>t,ie=e=>typeof e===E?(e=>e())(e):e;function le(){return this}const ce=(e,t)=>e===v?[t]:{t:e,v:t},pe=(e,t=ae)=>{let n=typeof e,r=e;return n===R&&(oe(e)?(n=v,r=e.at(0)):({t:n,v:r}=e)),t(n,r)},fe=(e,t)=>e===E?t:ce(e,t),ue=(e,t=fe)=>{const n=null===e?k:typeof e;return t(n===R&&oe(e)?v:n,e)},de=new FinalizationRegistry((([e,t,n])=>{n&&console.debug(`Held value ${String(t)} not relevant anymore`),e(t)})),he=Object.create(null),me=(e,t,{debug:n,return:r,token:s=e}=he)=>{const o=r||new Proxy(e,he),a=[o,[t,e,!!n]];return!1!==s&&a.push(s),de.register(...a),o},{defineProperty:ye,deleteProperty:ge,getOwnPropertyDescriptor:_e,getPrototypeOf:we,isExtensible:be,ownKeys:ve,preventExtensions:Ee,set:ke,setPrototypeOf:je}=Reflect,{assign:Re,create:Ae}=Object,Te=we(Int8Array),xe=(e,t)=>{const{get:n,set:r,value:s}=e;return n&&(e.get=t(n)),r&&(e.set=t(r)),s&&(e.value=t(s)),e},Se=e=>t=>ue(t,((t,n)=>{switch(t){case k:return ce(k,n);case R:if(n===globalThis)return ce(t,null);case v:case E:return e(t,n);case"boolean":case j:case A:case x:case"bigint":return ce(t,n);case T:{if(Ne.has(n))return ce(t,Ne.get(n));let e=Symbol.keyFor(n);if(e)return ce(t,`.${e}`)}}throw new TypeError(`Unable to handle this ${t}: ${String(n)}`)})),Ne=new Map(ve(Symbol).filter((e=>typeof Symbol[e]===T)).map((e=>[Symbol[e],e]))),Oe=e=>{if(e.startsWith("."))return Symbol.for(e.slice(1));for(const[t,n]of Ne)if(n===e)return t},Ie=e=>e;var Pe=((e,t)=>{const n=t&&new WeakMap;if(t){const{addEventListener:e}=EventTarget.prototype;ye(EventTarget.prototype,"addEventListener",{value(t,r,...s){return s.at(0)?.invoke&&(n.has(this)||n.set(this,new Map),n.get(this).set(t,[].concat(s[0].invoke)),delete s[0].invoke),e.call(this,t,r,...s)}})}const r=t&&(e=>{const{currentTarget:t,target:r,type:s}=e;for(const o of n.get(t||r)?.get(s)||[])e[o]()});return function(n,s,o,...a){let i=0,l=this?.transform||Ie;const c=new Map,p=new Map,{[o]:f}=n,u=a.length?Re(Ae(globalThis),...a):globalThis,d=Se(((e,t)=>{if(!c.has(t)){let n;for(;p.has(n=i++););c.set(t,n),p.set(n,e===E?t:l(t))}return ce(e,c.get(t))})),h=e=>{f(B,ce(A,e))},m=(e,n)=>{switch(e){case R:if(null==n)return u;case v:if(typeof n===j)return p.get(n);if(!(n instanceof Te))for(const e in n)n[e]=y(n[e]);return n;case E:if(typeof n===A){if(!p.has(n)){const e=function(...e){return t&&e.at(0)instanceof Event&&r(...e),f(S,ce(E,n),d(this),e.map(d))};return p.set(n,new WeakRef(e)),me(n,h,{return:e,token:!1})}return p.get(n).deref()}return p.get(n);case T:return Oe(n)}return n},y=e=>pe(e,m),g={[S]:(e,t,n)=>d(e.apply(t,n)),[N]:(e,t)=>d(new e(...t)),[O]:(e,t,n)=>d(ye(e,t,n)),[I]:(e,t)=>d(ge(e,t)),[M]:e=>d(we(e)),[P]:(e,t)=>d(e[t]),[$]:(e,t)=>{const n=_e(e,t);return n?ce(R,xe(n,d)):ce(x,n)},[F]:(e,t)=>d(t in e),[C]:e=>d(be(e)),[H]:e=>ce(v,ve(e).map(d)),[L]:e=>d(Ee(e)),[W]:(e,t,n)=>d(ke(e,t,n)),[D]:(e,t)=>d(je(e,t)),[B](e){c.delete(p.get(e)),p.delete(e)}};return n[s]=(e,t,...n)=>{switch(e){case S:n[0]=y(n[0]),n[1]=n[1].map(y);break;case N:n[0]=n[0].map(y);break;case O:{const[e,t]=n;n[0]=y(e);const{get:r,set:s,value:o}=t;r&&(t.get=y(r)),s&&(t.set=y(s)),o&&(t.value=y(o));break}default:n=n.map(y)}return g[e](y(t),...n)},{proxy:n,[e.toLowerCase()]:u,[`is${e}Proxy`]:()=>!1}}})("Window",!0),$e=(e=>{let t=0;const n=new Map,r=new Map,s=Symbol();return function(o,a,i){const l=this?.transform||Ie,{[a]:c}=o,p=new Map,f=e=>{p.delete(e),c(B,u(e))},u=Se(((e,o)=>{if(s in o)return ie(o[s]);if(e===E){if(o=l(o),!r.has(o)){let e;for(;r.has(e=String(t++)););n.set(o,e),r.set(e,o)}return ce(e,n.get(o))}if(!(o instanceof Te)){o=l(o);for(const e in o)o[e]=u(o[e])}return ce(e,o)})),d=(e,t,n)=>{if(!p.has(n)){const r=t===E?(e=>le.bind(e))(e):e,s=new Proxy(r,y);return p.set(n,new WeakRef(s)),me(n,f,{return:s,token:!1})}return p.get(n).deref()},h=e=>pe(e,((t,n)=>{switch(t){case R:if(null===n)return globalThis;case v:return typeof n===j?d(e,t,n):n;case E:return typeof n===A?r.get(n):d(e,t,n);case T:return Oe(n)}return n})),m=(e,t,...n)=>h(c(e,ie(t),...n)),y={[S]:(e,t,n)=>m(S,e,u(t),n.map(u)),[N]:(e,t)=>m(N,e,t.map(u)),[O]:(e,t,n)=>{const{get:r,set:s,value:o}=n;return typeof r===E&&(n.get=u(r)),typeof s===E&&(n.set=u(s)),typeof o===E&&(n.value=u(o)),m(O,e,u(t),n)},[I]:(e,t)=>m(I,e,u(t)),[M]:e=>m(M,e),[P]:(e,t)=>t===s?e:m(P,e,u(t)),[$]:(e,t)=>{const n=m($,e,u(t));return n&&xe(n,h)},[F]:(e,t)=>t===s||m(F,e,u(t)),[C]:e=>m(C,e),[H]:e=>m(H,e).map(h),[L]:e=>m(L,e),[W]:(e,t,n)=>m(W,e,u(t),u(n)),[D]:(e,t)=>m(D,e,u(t))};o[i]=(e,t,s,o)=>{switch(e){case S:return h(t).apply(h(s),o.map(h));case B:{const e=h(t);n.delete(r.get(e)),r.delete(e)}}};const g=new Proxy(ce(R,null),y);return{[e.toLowerCase()]:g,[`is${e}Proxy`]:e=>typeof e===R&&!!e&&s in e,proxy:o}}})("Window"),Me=typeof Worker===E?Worker:class{};const Fe=new WeakMap,Ce=(e,...t)=>{const n=se(e,...t);if(!Fe.has(n)){const r=e instanceof Me?Pe:$e;Fe.set(n,r.call(t.at(0),n,w,b))}return Fe.get(n)};Ce.transfer=se.transfer;const He={object(...e){return this.string(function(e){for(var t=e[0],n=1,r=arguments.length;n<r;n++)t+=arguments[n]+e[n];return t}(...e))},string(e){for(const t of e.split(/[\r\n]+/))if(t.trim().length){/^(\s+)/.test(t)&&(e=e.replace(new RegExp("^"+RegExp.$1,"gm"),""));break}return e}},{replace:Le}="",We=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g,De={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'},Be=e=>De[e],Ue=new WeakMap,Je=e=>{const t=e||console,n={stderr:(t.stderr||console.error).bind(t),stdout:(t.stdout||console.log).bind(t)};return{stderr:(...e)=>n.stderr(...e),stdout:(...e)=>n.stdout(...e),async get(e){const t=await e;return Ue.set(t,n),t}}},qe=(e,...t)=>He[typeof e](e,...t),Ge=e=>Le.call(e,We,Be),{isArray:Ye}=Array,{assign:Ve,create:Ke,defineProperties:Xe,defineProperty:ze,entries:Ze}=Object,{all:Qe,resolve:et}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),tt=(e,t=location.href)=>new URL(e,t.replace(/^blob:/,"")).href;let nt=0;const rt=(e,t)=>({id:e.id||(e.id=`${t}-w${nt++}`),tag:e.tagName}),st=(e,t,n,r=!1,s=CustomEvent)=>{e.dispatchEvent(new s(`${t}:${n}`,{bubbles:!0,detail:{worker:r}}))},ot=(e,t,n,r)=>({type:t,config:n,interpreter:r,io:Ue.get(r),run:(t,...n)=>e.run(r,t,...n),runAsync:(t,...n)=>e.runAsync(r,t,...n),runEvent:(...t)=>e.runEvent(r,...t)}),at=(e,t)=>(n,r)=>{const s=e[t].bind(e);e[t]=(e,t,...o)=>s(e,`${r?n:t}\n${r?t:n}`,...o)},it=Symbol.for("polyscript.js_modules"),lt=new Map;ze(globalThis,it,{value:lt});const ct=new Proxy(lt,{get:(e,t)=>e.get(t),has:(e,t)=>e.has(t),ownKeys:e=>[...e.keys()]}),pt=(e,t)=>!t.startsWith("_"),ft=(e,t)=>new Proxy(e,{has:pt,get:(e,n)=>e[t][n]}),ut=(e,t,n,r)=>{if("pyodide"===e)return;const s="polyscript.js_modules";for(const e of Reflect.ownKeys(r))t.registerJSModule(n,`${s}.${e}`,ft(r,e));t.registerJSModule(n,s,r)},dt=(e,t)=>import(e).then((e=>{lt.set(t,{...e})})),ht=e=>new Promise(((t,n)=>{document.querySelector(`link[href="${e}"]`)&&t(),document.head.append(Ve(document.createElement("link"),{rel:"stylesheet",href:e,onload:t,onerror:n}))})),mt=e=>/\.css/i.test(new URL(e).pathname),yt=({FS:e,PATH:t,PATH_FS:n},r,s)=>{const o=n.resolve(r);return e.mkdirTree(t.dirname(o)),e.writeFile(o,new Uint8Array(s),{canOwn:!0})},gt=e=>{const t=e.split("/");return t.pop(),t.join("/")},_t=(e,t)=>{const n=[];for(const r of t.split("/"))"."!==r&&(n.push(r),r&&e.mkdir(n.join("/")))},wt=(e,t)=>{const n=[];for(const e of t.split("/"))switch(e){case"":case".":break;case"..":n.pop();break;default:n.push(e)}return[e.cwd()].concat(n).join("/").replace(/^\/+/,"/")},bt=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((e=>""!==e&&"."!==e)).join("/");return e[0].startsWith("/")?`/${t}`:t},vt=(e,t)=>fetch(tt(t,Et.get(e))),Et=new WeakMap,kt=(e,n,r)=>Qe((e=>{for(const{files:t,to_file:n,from:r=""}of e){if(void 0!==t&&void 0!==n)throw new Error("Cannot use 'to_file' and 'files' parameters together!");if(void 0===t&&void 0===n&&r.endsWith("/"))throw new Error(`Couldn't determine the filename from the path ${r}, please supply 'to_file' parameter.`)}return e.flatMap((({from:e="",to_folder:t=".",to_file:n,files:r})=>{if(Ye(r))return r.map((n=>({url:bt([e,n]),path:bt([t,n])})));const s=n||e.slice(1+e.lastIndexOf("/"));return[{url:e,path:bt([t,s])}]}))})(r).map((({url:s,path:o})=>vt(r,s).then(t).then((t=>e.writeFile(n,o,t)))))),jt=(e,t)=>t.endsWith("/")?`${t}${e.split("/").pop()}`:t,Rt=(e,t)=>e.replace(/\{.+?\}/g,(e=>{if(!t.has(e))throw new SyntaxError(`Invalid template: ${e}`);return t.get(e)})),At=(e,n,r)=>Qe((e=>{const t=new Map,n=new Set,r=[];for(const[s,o]of Ze(e))if(/^\{.+\}$/.test(s)){if(t.has(s))throw new SyntaxError(`Duplicated template: ${s}`);t.set(s,Rt(o,t))}else{const e=Rt(s,t),a=jt(e,Rt(o||"./",t));if(n.has(a))throw new SyntaxError(`Duplicated destination: ${a}`);n.add(a),r.push({url:e,path:a})}return r})(r).map((({url:s,path:o})=>vt(r,s).then(t).then((t=>e.writeFile(n,o,t)))))),Tt=typeof document===x,xt=({main:e,worker:t})=>{const n=[];if(t&&Tt)for(let[e,r]of Ze(t))e=tt(e,Et.get(t)),n.push(dt(e,r));if(e&&!Tt)for(let[t,r]of Ze(e))t=tt(t,Et.get(e)),mt(t)?ht(t):n.push(dt(t,r));return Qe(n)},St=(e,t,n)=>{e.registerJsModule(t,n)},Nt=(e,t,...n)=>{try{return e.runPython(qe(t),...n)}catch(t){Ue.get(e).stderr(t)}},Ot=async(e,t,...n)=>{try{return await e.runPythonAsync(qe(t),...n)}catch(t){Ue.get(e).stderr(t)}},It=async(e,t,n)=>{const[r,...s]=t.split(".");let o,a=e.globals.get(r);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,n)}catch(t){Ue.get(e).stderr(t)}};var Pt=(new TextEncoder).encode('from uio import StringIO\nimport sys\n\nclass Response:\n def __init__(self, f):\n self.raw = f\n self.encoding = "utf-8"\n self._cached = None\n\n def close(self):\n if self.raw:\n self.raw.close()\n self.raw = None\n self._cached = None\n\n @property\n def content(self):\n if self._cached is None:\n try:\n self._cached = self.raw.read()\n finally:\n self.raw.close()\n self.raw = None\n return self._cached\n\n @property\n def text(self):\n return str(self.content, self.encoding)\n\n def json(self):\n import ujson\n\n return ujson.loads(self.content)\n\n\n# TODO try to support streaming xhr requests, a-la pyodide-http\nHEADERS_TO_IGNORE = ("user-agent",)\n\n\ntry:\n import js\nexcept Exception as err:\n raise OSError("This version of urequests can only be used in the browser")\n\n# TODO try to support streaming xhr requests, a-la pyodide-http\n\nHEADERS_TO_IGNORE = ("user-agent",)\n\n\ndef request(\n method,\n url,\n data=None,\n json=None,\n headers={},\n stream=None,\n auth=None,\n timeout=None,\n parse_headers=True,\n):\n from js import XMLHttpRequest\n\n xhr = XMLHttpRequest.new()\n xhr.withCredentials = False\n\n if auth is not None:\n import ubinascii\n\n username, password = auth\n xhr.open(method, url, False, username, password)\n else:\n xhr.open(method, url, False)\n\n for name, value in headers.items():\n if name.lower() not in HEADERS_TO_IGNORE:\n xhr.setRequestHeader(name, value)\n\n if timeout:\n xhr.timeout = int(timeout * 1000)\n\n if json is not None:\n assert data is None\n import ujson\n\n data = ujson.dumps(json)\n # s.write(b"Content-Type: application/json\\r\\n")\n xhr.setRequestHeader("Content-Type", "application/json")\n\n xhr.send(data)\n\n # Emulates the construction process in the original urequests\n resp = Response(StringIO(xhr.responseText))\n resp.status_code = xhr.status\n resp.reason = xhr.statusText\n resp.headers = xhr.getAllResponseHeaders()\n\n return resp\n\n\n# Other methods - head, post, put, patch, delete - are not used by\n# mip and therefore not included\n\n\ndef get(url, **kw):\n return request("GET", url, **kw)\n\n\n# Content below this line is from the Micropython MIP package and is covered\n# by the applicable MIT license:\n# \n# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, \n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER \n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING \n# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \n# DEALINGS IN THE SOFTWARE.\n\n# MicroPython package installer\n# MIT license; Copyright (c) 2022 Jim Mussared\n\n\n_PACKAGE_INDEX = const("https://micropython.org/pi/v2")\n_CHUNK_SIZE = 128\n\n\n# This implements os.makedirs(os.dirname(path))\ndef _ensure_path_exists(path):\n import os\n\n split = path.split("/")\n\n # Handle paths starting with "/".\n if not split[0]:\n split.pop(0)\n split[0] = "/" + split[0]\n\n prefix = ""\n for i in range(len(split) - 1):\n prefix += split[i]\n try:\n os.stat(prefix)\n except:\n os.mkdir(prefix)\n prefix += "/"\n\n\n# Copy from src (stream) to dest (function-taking-bytes)\ndef _chunk(src, dest):\n buf = memoryview(bytearray(_CHUNK_SIZE))\n while True:\n n = src.readinto(buf)\n if n == 0:\n break\n dest(buf if n == _CHUNK_SIZE else buf[:n])\n\n\n# Check if the specified path exists and matches the hash.\ndef _check_exists(path, short_hash):\n import os\n\n try:\n import binascii\n import hashlib\n\n with open(path, "rb") as f:\n hs256 = hashlib.sha256()\n _chunk(f, hs256.update)\n existing_hash = str(binascii.hexlify(hs256.digest())[: len(short_hash)], "utf-8")\n return existing_hash == short_hash\n except:\n return False\n\n\ndef _rewrite_url(url, branch=None):\n if not branch:\n branch = "HEAD"\n if url.startswith("github:"):\n url = url[7:].split("/")\n url = (\n "https://raw.githubusercontent.com/"\n + url[0]\n + "/"\n + url[1]\n + "/"\n + branch\n + "/"\n + "/".join(url[2:])\n )\n return url\n\n\ndef _download_file(url, dest):\n response = get(url)\n try:\n if response.status_code != 200:\n print("Error", response.status_code, "requesting", url)\n return False\n\n print("Copying:", dest)\n _ensure_path_exists(dest)\n with open(dest, "wb") as f:\n _chunk(response.raw, f.write)\n\n return True\n finally:\n response.close()\n\n\ndef _install_json(package_json_url, index, target, version, mpy):\n response = get(_rewrite_url(package_json_url, version))\n try:\n if response.status_code != 200:\n print("Package not found:", package_json_url)\n return False\n\n package_json = response.json()\n finally:\n response.close()\n for target_path, short_hash in package_json.get("hashes", ()):\n fs_target_path = target + "/" + target_path\n if _check_exists(fs_target_path, short_hash):\n print("Exists:", fs_target_path)\n else:\n file_url = "{}/file/{}/{}".format(index, short_hash[:2], short_hash)\n if not _download_file(file_url, fs_target_path):\n print("File not found: {} {}".format(target_path, short_hash))\n return False\n for target_path, url in package_json.get("urls", ()):\n fs_target_path = target + "/" + target_path\n if not _download_file(_rewrite_url(url, version), fs_target_path):\n print("File not found: {} {}".format(target_path, url))\n return False\n for dep, dep_version in package_json.get("deps", ()):\n if not _install_package(dep, index, target, dep_version, mpy):\n return False\n return True\n\n\ndef _install_package(package, index, target, version, mpy):\n if (\n package.startswith("http://")\n or package.startswith("https://")\n or package.startswith("github:")\n ):\n if package.endswith(".py") or package.endswith(".mpy"):\n print("Downloading {} to {}".format(package, target))\n return _download_file(\n _rewrite_url(package, version), target + "/" + package.rsplit("/")[-1]\n )\n else:\n if not package.endswith(".json"):\n if not package.endswith("/"):\n package += "/"\n package += "package.json"\n print("Installing {} to {}".format(package, target))\n else:\n if not version:\n version = "latest"\n print("Installing {} ({}) from {} to {}".format(package, version, index, target))\n\n mpy_version = (\n sys.implementation._mpy & 0xFF if mpy and hasattr(sys.implementation, "_mpy") else "py"\n )\n\n package = "{}/package/{}/{}/{}.json".format(index, mpy_version, package, version)\n\n return _install_json(package, index, target, version, mpy)\n\n\ndef install(package, index=None, target=None, version=None, mpy=True):\n if not target:\n for p in sys.path:\n if p.endswith("/lib"):\n target = p\n break\n else:\n print("Unable to find lib dir in sys.path")\n return\n\n if not index:\n index = _PACKAGE_INDEX\n\n if _install_package(package, index.rstrip("/"), target, version, mpy):\n print("Done")\n else:\n print("Package may be partially installed")\n');var $t={type:"micropython",module:(e="1.21.0-279")=>`https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@${e}/micropython.mjs`,async engine({loadMicroPython:e},t,n){const{stderr:r,stdout:s,get:o}=Je();n=n.replace(/\.m?js$/,".wasm");const a=await o(e({stderr:r,stdout:s,url:n}));if(t.files&&await At(this,a,t.files),t.fetch&&await kt(this,a,t.fetch),t.js_modules&&await xt(t.js_modules),this.writeFile(a,"./mip.py",Pt),t.packages){const e=a.pyimport("mip");for(const n of t.packages)e.install(n)}return a},registerJSModule:St,run:Nt,runAsync:Ot,runEvent:It,transform:(e,t)=>t instanceof e.PyProxy?e.PyProxy.toJs(t):t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:n}},r,s)=>yt({FS:e,PATH:t,PATH_FS:n},r,s)};const Mt=new FinalizationRegistry((([e,t,n])=>{n&&console.debug(`Held value ${String(t)} not relevant anymore`),e(t)})),Ft=Object.create(null),Ct=(e,t,{debug:n,return:r,token:s=e}=Ft)=>{const o=r||new Proxy(e,Ft),a=[o,[t,e,!!n]];return!1!==s&&a.push(s),Mt.register(...a),o},Ht=!!globalThis.window,Lt={dict_converter:Object.fromEntries};let Wt=!1;const Dt=e=>(...t)=>{try{return Wt=!0,e(...t)}finally{Wt=!1}};let Bt=!1;const Ut=()=>{if(Bt)return;Bt=!0;const e=new WeakMap,t=e=>e.destroy(),n=n=>{for(let r=0;r<n.length;r++){const s=n[r];if("function"==typeof s&&"copy"in s){Wt=!1;let o=e.get(s)?.deref();if(!o)try{o=Ct(s.copy(),t),e.set(s,new WeakRef(o))}catch(e){console.error(e)}o&&(n[r]=o),Wt=!0}}},{call:r}=Function,s=r.bind(r,r.apply);Object.defineProperties(Function.prototype,{apply:{value(e,t){return Wt&&n(t),s(this,e,t)}},call:{value(e,...t){return Wt&&n(t),s(this,e,t)}}})};var Jt={type:"pyodide",module:(e="0.25.0")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,n){Ht&&"auto"===t.experimental_create_proxy&&Ut();const{stderr:r,stdout:s,get:o}=Je(),a=n.slice(0,n.lastIndexOf("/")),i=await o(e({stderr:r,stdout:s,indexURL:a}));if(t.files&&await At(this,i,t.files),t.fetch&&await kt(this,i,t.fetch),t.js_modules&&await xt(t.js_modules),t.packages){await i.loadPackage("micropip");const e=await i.pyimport("micropip");await e.install(t.packages,{keep_going:!0}),e.destroy()}return i},registerJSModule:St,run:Dt(Nt),runAsync:Dt(Ot),runEvent:Dt(It),transform:({ffi:{PyProxy:e}},t)=>t instanceof e?t.toJs(Lt):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:n}},r,s)=>yt({FS:e,PATH:t,PATH_FS:n},r,s)};const qt="ruby-wasm-wasi",Gt=qt.replace(/\W+/g,"_");var Yt={type:qt,experimental:!0,module:(e="2.2.0")=>`https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@${e}/dist/browser.esm.js`,async engine({DefaultRubyVM:e},t,n){const r=await fetch(`${n.slice(0,n.lastIndexOf("/"))}/ruby.wasm`),s=await WebAssembly.compile(await r.arrayBuffer()),{vm:o}=await e(s);return t.files&&await At(this,o,t.files),t.fetch&&await kt(this,o,t.fetch),t.js_modules&&await xt(t.js_modules),o},registerJSModule(e,t,n){t=t.replace(/\W+/g,"__");const r=`__module_${Gt}_${t}`;globalThis[r]=n,this.run(e,`require "js";$${t}=JS.global[:${r}]`),delete globalThis[r]},run:(e,t,...n)=>e.eval(qe(t),...n),runAsync:(e,t,...n)=>e.evalAsync(qe(t),...n),async runEvent(e,t,n){if(/^xworker\.(on\w+)$/.test(t)){const{$1:t}=RegExp,r=`__module_${Gt}_event`;globalThis[r]=n,this.run(e,`require "js";$xworker.call("${t}",JS.global[:${r}])`),delete globalThis[r]}else{const r=this.run(e,`method(:${t})`);await r.call(t,e.wrap(n))}},transform:(e,t)=>t,writeFile:()=>{throw new Error(`writeFile is not supported in ${qt}`)}};var Vt={type:"wasmoon",module:(e="1.16.0")=>`https://cdn.jsdelivr.net/npm/wasmoon@${e}/+esm`,async engine({LuaFactory:e,LuaLibraries:t},n){const{stderr:r,stdout:s,get:o}=Je(),a=await o((new e).createEngine());return a.global.getTable(t.Base,(e=>{a.global.setField(e,"print",s),a.global.setField(e,"printErr",r)})),n.files&&await At(this,a,n.files),n.fetch&&await kt(this,a,n.fetch),n.js_modules&&await xt(n.js_modules),a},registerJSModule:(e,t,n)=>{e.global.set(t,n)},run:(e,t,...n)=>{try{return e.doStringSync(qe(t),...n)}catch(t){Ue.get(e).stderr(t)}},runAsync:async(e,t,...n)=>{try{return await e.doString(qe(t),...n)}catch(t){Ue.get(e).stderr(t)}},runEvent:async(e,t,n)=>{const[r,...s]=t.split(".");let o,a=e.global.get(r);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,n)}catch(t){Ue.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,n)=>((e,t,n)=>(_t(e,gt(t)),t=wt(e,t),e.writeFile(t,new Uint8Array(n),{canOwn:!0})))(e,t,n)};const Kt=new Map,Xt=new Map,zt=[],Zt=[],Qt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[n,...r]=t.split("@"),s=Kt.get(n),o=/^(?:\.?\.?\/|https?:\/\/)/i.test(r)?r.join("@"):s.module(...r);e.set(t,{url:o,module:import(o),engine:s.engine.bind(s)})}const{url:n,module:r,engine:s}=e.get(t);return(e,o)=>r.then((r=>{Xt.set(t,e);for(const t of["files","fetch"]){const n=e?.[t];n&&Et.set(n,o)}for(const t of["main","worker"]){const n=e?.js_modules?.[t];n&&Et.set(n,o)}return s(r,e,n)}))}}),en=e=>{for(const t of[].concat(e.type))Kt.set(t,e),zt.push(`script[type="${t}"]`),Zt.push(`${t}-`)};for(const e of[$t,Jt,Yt,Vt])en(e);const tn=async e=>(await import("https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js")).parse(e),nn=(e,t="./config.txt")=>{let n=typeof e;return"string"===n&&/\.(json|toml|txt)$/.test(e)?n=RegExp.$1:e=t,[tt(e),n]},rn=e=>{try{return JSON.parse(e)}catch(t){return tn(e)}},sn=(e,t,s,o={})=>{if(t){const[e,a]=nn(t,s);"json"===a?o=fetch(e).then(n):"toml"===a?o=fetch(e).then(r).then(tn):"string"===a?o=rn(t):"object"===a&&t?o=t:"txt"===a&&"string"==typeof o&&(o=rn(o)),t=e}return et(o).then((n=>Qt[e](n,t)))},on=(e,t="")=>`${e}@${t}`.replace(/@$/,"");function an(e=this){return String(e).replace(/^(async\s*)?(\bfunction\b)?(.*?)\(/,((e,t,n,r)=>r&&!n?`${t||""}function ${r}(`:e))}const ln="BeforeRun",cn="AfterRun",pn=[`code${ln}`,`code${ln}Async`,`code${cn}`,`code${cn}Async`],fn=["onWorker","onReady",`on${ln}`,`on${ln}Async`,`on${cn}`,`on${cn}Async`];function un(e,t){const{run:n,runAsync:r}=Kt.get(this.type);return{...e,run:n.bind(this,t),runAsync:r.bind(this,t)}}const dn=(e,t,n,r,s,o)=>{if(s||o){const a=un.bind(e,t),i=r?"runAsync":"run",l=e[i];e[i]=r?async function(e,t,...r){s&&await s.call(this,a(e),n);const i=await l.call(this,e,t,...r);return o&&await o.call(this,a(e),n),i}:function(e,t,...r){s&&s.call(this,a(e),n);const i=l.call(this,e,t,...r);return o&&o.call(this,a(e),n),i}}};let hn=class{constructor(e,t={}){const{main:n,worker:r}=t;this.interpreter=e,this.onWorker=n?.onWorker;for(const e of fn.slice(1))this[e]=r?.[e];for(const e of pn)this[e]=r?.[e]}toJSON(){const e={};for(const t of fn.slice(1))this[t]&&(e[t]=an(this[t]));for(const t of pn)this[t]&&(e[t]=qe(this[t]()));return e}};var mn=(...e)=>function(t,n){const s=new Worker(URL.createObjectURL(new Blob(['const e="object"==typeof self?self:globalThis,t=t=>((t,n)=>{const r=(e,n)=>(t.set(n,e),e),s=o=>{if(t.has(o))return t.get(o);const[a,i]=n[o];switch(a){case 0:case-1:return r(i,o);case 1:{const e=r([],o);for(const t of i)e.push(s(t));return e}case 2:{const e=r({},o);for(const[t,n]of i)e[s(t)]=s(n);return e}case 3:return r(new Date(i),o);case 4:{const{source:e,flags:t}=i;return r(new RegExp(e,t),o)}case 5:{const e=r(new Map,o);for(const[t,n]of i)e.set(s(t),s(n));return e}case 6:{const e=r(new Set,o);for(const t of i)e.add(s(t));return e}case 7:{const{name:t,message:n}=i;return r(new e[t](n),o)}case 8:return r(BigInt(i),o);case"BigInt":return r(Object(BigInt(i)),o)}return r(new e[a](i),o)};return s})(new Map,t)(0),n="",{toString:r}={},{keys:s}=Object,o=e=>{const t=typeof e;if("object"!==t||!e)return[0,t];const s=r.call(e).slice(8,-1);switch(s){case"Array":return[1,n];case"Object":return[2,n];case"Date":return[3,n];case"RegExp":return[4,n];case"Map":return[5,n];case"Set":return[6,n]}return s.includes("Array")?[1,s]:s.includes("Error")?[7,s]:[2,s]},a=([e,t])=>0===e&&("function"===t||"symbol"===t),i=(e,{json:t,lossy:n}={})=>{const r=[];return((e,t,n,r)=>{const i=(e,t)=>{const s=r.push(e)-1;return n.set(t,s),s},c=r=>{if(n.has(r))return n.get(r);let[l,u]=o(r);switch(l){case 0:{let t=r;switch(u){case"bigint":l=8,t=r.toString();break;case"function":case"symbol":if(e)throw new TypeError("unable to serialize "+u);t=null;break;case"undefined":return i([-1],r)}return i([l,t],r)}case 1:{if(u)return i([u,[...r]],r);const e=[],t=i([l,e],r);for(const t of r)e.push(c(t));return t}case 2:{if(u)switch(u){case"BigInt":return i([u,r.toString()],r);case"Boolean":case"Number":case"String":return i([u,r.valueOf()],r)}if(t&&"toJSON"in r)return c(r.toJSON());const n=[],p=i([l,n],r);for(const t of s(r))!e&&a(o(r[t]))||n.push([c(t),c(r[t])]);return p}case 3:return i([l,r.toISOString()],r);case 4:{const{source:e,flags:t}=r;return i([l,{source:e,flags:t}],r)}case 5:{const t=[],n=i([l,t],r);for(const[n,s]of r)(e||!a(o(n))&&!a(o(s)))&&t.push([c(n),c(s)]);return n}case 6:{const t=[],n=i([l,t],r);for(const n of r)!e&&a(o(n))||t.push(c(n));return n}}const{message:p}=r;return i([l,{name:u,message:p}],r)};return c})(!(t||n),!!t,new Map,r)(e),r},{parse:c,stringify:l}=JSON,u={json:!0,lossy:!0};var p=Object.freeze({__proto__:null,parse:e=>t(c(e)),stringify:e=>l(i(e,u))});const f="ac6c1995-0675-46af-a99f-7fa298fa4e6d",h="M"+f,d="T"+f,g="array",y="function",m="null",w="number",_="object",b="string",E="symbol",k="undefined",v="apply",T="construct",x="defineProperty",S="deleteProperty",A="get",O="getOwnPropertyDescriptor",j="getPrototypeOf",R="has",P="isExtensible",N="ownKeys",I="preventExtensions",$="set",M="setPrototypeOf",F="delete";var H=e=>({value:new Promise((t=>{let n=new Worker("data:application/javascript,onmessage%3D(%7Bdata%3Ab%7D)%3D%3E(Atomics.wait(b%2C0)%2CpostMessage(0))");n.onmessage=t,n.postMessage(e)}))})\n/*! (c) Andrea Giammarchi - ISC */;const{Int32Array:W,Map:C,SharedArrayBuffer:D,Uint16Array:L}=globalThis,{BYTES_PER_ELEMENT:B}=W,{BYTES_PER_ELEMENT:U}=L,{isArray:J}=Array,{notify:q,wait:G,waitAsync:K}=Atomics,Y=new WeakSet,z=new WeakMap,X={value:{then:e=>e()}};let V=0;const Z=(e,{parse:t=JSON.parse,stringify:n=JSON.stringify,transform:r,interrupt:s}=JSON)=>{if(!z.has(e)){const o=(t,...n)=>e.postMessage({[f]:n},{transfer:t}),a=typeof s===y?s:s?.handler,i=s?.delay||42,c=new TextDecoder("utf-16"),l=(e,t)=>e?(K||H)(t,0):(a?((e,t,n)=>{for(;"timed-out"===G(e,0,0,t);)n()})(t,i,a):G(t,0),X);let u=!1;z.set(e,new Proxy(new C,{[R]:(e,t)=>"string"==typeof t&&!t.startsWith("_"),[A]:(n,s)=>"then"===s?null:(...n)=>{const a=V++;let i=new W(new D(2*B)),p=[];Y.has(n.at(-1)||p)&&Y.delete(p=n.pop()),o(p,a,i,s,r?n.map(r):n);const f=e!==globalThis;let h=0;return u&&f&&(h=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${s}(...args) is awaited`)),l(f,i).value.then((()=>{clearTimeout(h);const e=i[1];if(!e)return;const n=U*e;return i=new W(new D(n+n%B)),o([],a,i),l(f,i).value.then((()=>t(c.decode(new L(i.buffer).slice(0,e)))))}))},[$](t,s,o){const a=typeof o;if(a!==y)throw new Error(`Unable to assign ${s} as ${a}`);if(!t.size){const s=new C;e.addEventListener("message",(async e=>{const o=e.data?.[f];if(J(o)){e.stopImmediatePropagation();const[a,i,...c]=o;let l;if(c.length){const[e,o]=c;if(t.has(e)){u=!0;try{const c=await t.get(e)(...o);if(void 0!==c){const e=n(r?r(c):c);s.set(a,e),i[1]=e.length}}catch(e){l=e}finally{u=!1}}else l=new Error(`Unsupported action: ${e}`);i[0]=1}else{const e=s.get(a);s.delete(a);for(let t=new L(i.buffer),n=0;n<e.length;n++)t[n]=e.charCodeAt(n)}if(q(i,0),l)throw l}}))}return!!t.set(s,o)}}))}return z.get(e)};Z.transfer=(...e)=>(Y.add(e),e);const{isArray:Q}=Array,ee=(e,t)=>t,te=e=>typeof e===y?(e=>e())(e):e;function ne(){return this}const re=(e,t)=>e===g?[t]:{t:e,v:t},se=(e,t=ee)=>{let n=typeof e,r=e;return n===_&&(Q(e)?(n=g,r=e.at(0)):({t:n,v:r}=e)),t(n,r)},oe=(e,t)=>e===y?t:re(e,t),ae=(e,t=oe)=>{const n=null===e?m:typeof e;return t(n===_&&Q(e)?g:n,e)},ie=new FinalizationRegistry((([e,t,n])=>{n&&console.debug(`Held value ${String(t)} not relevant anymore`),e(t)})),ce=Object.create(null),le=(e,t,{debug:n,return:r,token:s=e}=ce)=>{const o=r||new Proxy(e,ce),a=[o,[t,e,!!n]];return!1!==s&&a.push(s),ie.register(...a),o},{defineProperty:ue,deleteProperty:pe,getOwnPropertyDescriptor:fe,getPrototypeOf:he,isExtensible:de,ownKeys:ge,preventExtensions:ye,set:me,setPrototypeOf:we}=Reflect,{assign:_e,create:be}=Object,Ee=he(Int8Array),ke=(e,t)=>{const{get:n,set:r,value:s}=e;return n&&(e.get=t(n)),r&&(e.set=t(r)),s&&(e.value=t(s)),e},ve=e=>t=>ae(t,((t,n)=>{switch(t){case m:return re(m,n);case _:if(n===globalThis)return re(t,null);case g:case y:return e(t,n);case"boolean":case w:case b:case k:case"bigint":return re(t,n);case E:{if(Te.has(n))return re(t,Te.get(n));let e=Symbol.keyFor(n);if(e)return re(t,`.${e}`)}}throw new TypeError(`Unable to handle this ${t}: ${String(n)}`)})),Te=new Map(ge(Symbol).filter((e=>typeof Symbol[e]===E)).map((e=>[Symbol[e],e]))),xe=e=>{if(e.startsWith("."))return Symbol.for(e.slice(1));for(const[t,n]of Te)if(n===e)return t},Se=e=>e;var Ae=((e,t)=>{const n=t&&new WeakMap;if(t){const{addEventListener:e}=EventTarget.prototype;ue(EventTarget.prototype,"addEventListener",{value(t,r,...s){return s.at(0)?.invoke&&(n.has(this)||n.set(this,new Map),n.get(this).set(t,[].concat(s[0].invoke)),delete s[0].invoke),e.call(this,t,r,...s)}})}const r=t&&(e=>{const{currentTarget:t,target:r,type:s}=e;for(const o of n.get(t||r)?.get(s)||[])e[o]()});return function(n,s,o,...a){let i=0,c=this?.transform||Se;const l=new Map,u=new Map,{[o]:p}=n,f=a.length?_e(be(globalThis),...a):globalThis,h=ve(((e,t)=>{if(!l.has(t)){let n;for(;u.has(n=i++););l.set(t,n),u.set(n,e===y?t:c(t))}return re(e,l.get(t))})),d=e=>{p(F,re(b,e))},m=(e,n)=>{switch(e){case _:if(null==n)return f;case g:if(typeof n===w)return u.get(n);if(!(n instanceof Ee))for(const e in n)n[e]=H(n[e]);return n;case y:if(typeof n===b){if(!u.has(n)){const e=function(...e){return t&&e.at(0)instanceof Event&&r(...e),p(v,re(y,n),h(this),e.map(h))};return u.set(n,new WeakRef(e)),le(n,d,{return:e,token:!1})}return u.get(n).deref()}return u.get(n);case E:return xe(n)}return n},H=e=>se(e,m),W={[v]:(e,t,n)=>h(e.apply(t,n)),[T]:(e,t)=>h(new e(...t)),[x]:(e,t,n)=>h(ue(e,t,n)),[S]:(e,t)=>h(pe(e,t)),[j]:e=>h(he(e)),[A]:(e,t)=>h(e[t]),[O]:(e,t)=>{const n=fe(e,t);return n?re(_,ke(n,h)):re(k,n)},[R]:(e,t)=>h(t in e),[P]:e=>h(de(e)),[N]:e=>re(g,ge(e).map(h)),[I]:e=>h(ye(e)),[$]:(e,t,n)=>h(me(e,t,n)),[M]:(e,t)=>h(we(e,t)),[F](e){l.delete(u.get(e)),u.delete(e)}};return n[s]=(e,t,...n)=>{switch(e){case v:n[0]=H(n[0]),n[1]=n[1].map(H);break;case T:n[0]=n[0].map(H);break;case x:{const[e,t]=n;n[0]=H(e);const{get:r,set:s,value:o}=t;r&&(t.get=H(r)),s&&(t.set=H(s)),o&&(t.value=H(o));break}default:n=n.map(H)}return W[e](H(t),...n)},{proxy:n,[e.toLowerCase()]:f,[`is${e}Proxy`]:()=>!1}}})("Window",!0),Oe=(e=>{let t=0;const n=new Map,r=new Map,s=Symbol();return function(o,a,i){const c=this?.transform||Se,{[a]:l}=o,u=new Map,p=e=>{u.delete(e),l(F,f(e))},f=ve(((e,o)=>{if(s in o)return te(o[s]);if(e===y){if(o=c(o),!r.has(o)){let e;for(;r.has(e=String(t++)););n.set(o,e),r.set(e,o)}return re(e,n.get(o))}if(!(o instanceof Ee)){o=c(o);for(const e in o)o[e]=f(o[e])}return re(e,o)})),h=(e,t,n)=>{if(!u.has(n)){const r=t===y?(e=>ne.bind(e))(e):e,s=new Proxy(r,k);return u.set(n,new WeakRef(s)),le(n,p,{return:s,token:!1})}return u.get(n).deref()},d=e=>se(e,((t,n)=>{switch(t){case _:if(null===n)return globalThis;case g:return typeof n===w?h(e,t,n):n;case y:return typeof n===b?r.get(n):h(e,t,n);case E:return xe(n)}return n})),m=(e,t,...n)=>d(l(e,te(t),...n)),k={[v]:(e,t,n)=>m(v,e,f(t),n.map(f)),[T]:(e,t)=>m(T,e,t.map(f)),[x]:(e,t,n)=>{const{get:r,set:s,value:o}=n;return typeof r===y&&(n.get=f(r)),typeof s===y&&(n.set=f(s)),typeof o===y&&(n.value=f(o)),m(x,e,f(t),n)},[S]:(e,t)=>m(S,e,f(t)),[j]:e=>m(j,e),[A]:(e,t)=>t===s?e:m(A,e,f(t)),[O]:(e,t)=>{const n=m(O,e,f(t));return n&&ke(n,d)},[R]:(e,t)=>t===s||m(R,e,f(t)),[P]:e=>m(P,e),[N]:e=>m(N,e).map(d),[I]:e=>m(I,e),[$]:(e,t,n)=>m($,e,f(t),f(n)),[M]:(e,t)=>m(M,e,f(t))};o[i]=(e,t,s,o)=>{switch(e){case v:return d(t).apply(d(s),o.map(d));case F:{const e=d(t);n.delete(r.get(e)),r.delete(e)}}};const H=new Proxy(re(_,null),k);return{[e.toLowerCase()]:H,[`is${e}Proxy`]:e=>typeof e===_&&!!e&&s in e,proxy:o}}})("Window"),je=typeof Worker===y?Worker:class{};const Re=new WeakMap,Pe=(e,...t)=>{const n=Z(e,...t);if(!Re.has(n)){const r=e instanceof je?Ae:Oe;Re.set(n,r.call(t.at(0),n,h,d))}return Re.get(n)};Pe.transfer=Z.transfer;const Ne={object(...e){return this.string(function(e){for(var t=e[0],n=1,r=arguments.length;n<r;n++)t+=arguments[n]+e[n];return t}(...e))},string(e){for(const t of e.split(/[\\r\\n]+/))if(t.trim().length){/^(\\s+)/.test(t)&&(e=e.replace(new RegExp("^"+RegExp.$1,"gm"),""));break}return e}},Ie=new WeakMap,$e=e=>{const t=e||console,n={stderr:(t.stderr||console.error).bind(t),stdout:(t.stdout||console.log).bind(t)};return{stderr:(...e)=>n.stderr(...e),stdout:(...e)=>n.stdout(...e),async get(e){const t=await e;return Ie.set(t,n),t}}},Me=(e,...t)=>Ne[typeof e](e,...t),{isArray:Fe}=Array,{assign:He,create:We,defineProperties:Ce,defineProperty:De,entries:Le}=Object,{all:Be,resolve:Ue}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),Je=(e,t=location.href)=>new URL(e,t.replace(/^blob:/,"")).href,qe=(e,t,n,r=!1,s=CustomEvent)=>{e.dispatchEvent(new s(`${t}:${n}`,{bubbles:!0,detail:{worker:r}}))},Ge=e=>Function(`\'use strict\';return (${e})`)(),Ke=Symbol.for("polyscript.js_modules"),Ye=new Map;De(globalThis,Ke,{value:Ye}),new Proxy(Ye,{get:(e,t)=>e.get(t),has:(e,t)=>e.has(t),ownKeys:e=>[...e.keys()]});const ze=(e,t)=>!t.startsWith("_"),Xe=(e,t)=>new Proxy(e,{has:ze,get:(e,n)=>e[t][n]}),Ve=(e,t)=>import(e).then((e=>{Ye.set(t,{...e})})),Ze=e=>new Promise(((t,n)=>{document.querySelector(`link[href="${e}"]`)&&t(),document.head.append(He(document.createElement("link"),{rel:"stylesheet",href:e,onload:t,onerror:n}))})),Qe=e=>/\\.css/i.test(new URL(e).pathname);Promise.withResolvers||(Promise.withResolvers=function(){var e,t,n=new this((function(n,r){e=n,t=r}));return{resolve:e,reject:t,promise:n}});const et=e=>e.arrayBuffer(),tt=e=>e.json(),nt=e=>e.text(),rt=({FS:e,PATH:t,PATH_FS:n},r,s)=>{const o=n.resolve(r);return e.mkdirTree(t.dirname(o)),e.writeFile(o,new Uint8Array(s),{canOwn:!0})},st=e=>{const t=e.split("/");return t.pop(),t.join("/")},ot=(e,t)=>{const n=[];for(const r of t.split("/"))"."!==r&&(n.push(r),r&&e.mkdir(n.join("/")))},at=(e,t)=>{const n=[];for(const e of t.split("/"))switch(e){case"":case".":break;case"..":n.pop();break;default:n.push(e)}return[e.cwd()].concat(n).join("/").replace(/^\\/+/,"/")},it=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((e=>""!==e&&"."!==e)).join("/");return e[0].startsWith("/")?`/${t}`:t},ct=(e,t)=>fetch(Je(t,lt.get(e))),lt=new WeakMap,ut=(e,t,n)=>Be((e=>{for(const{files:t,to_file:n,from:r=""}of e){if(void 0!==t&&void 0!==n)throw new Error("Cannot use \'to_file\' and \'files\' parameters together!");if(void 0===t&&void 0===n&&r.endsWith("/"))throw new Error(`Couldn\'t determine the filename from the path ${r}, please supply \'to_file\' parameter.`)}return e.flatMap((({from:e="",to_folder:t=".",to_file:n,files:r})=>{if(Fe(r))return r.map((n=>({url:it([e,n]),path:it([t,n])})));const s=n||e.slice(1+e.lastIndexOf("/"));return[{url:e,path:it([t,s])}]}))})(n).map((({url:r,path:s})=>ct(n,r).then(et).then((n=>e.writeFile(t,s,n)))))),pt=(e,t)=>t.endsWith("/")?`${t}${e.split("/").pop()}`:t,ft=(e,t)=>e.replace(/\\{.+?\\}/g,(e=>{if(!t.has(e))throw new SyntaxError(`Invalid template: ${e}`);return t.get(e)})),ht=(e,t,n)=>Be((e=>{const t=new Map,n=new Set,r=[];for(const[s,o]of Le(e))if(/^\\{.+\\}$/.test(s)){if(t.has(s))throw new SyntaxError(`Duplicated template: ${s}`);t.set(s,ft(o,t))}else{const e=ft(s,t),a=pt(e,ft(o||"./",t));if(n.has(a))throw new SyntaxError(`Duplicated destination: ${a}`);n.add(a),r.push({url:e,path:a})}return r})(n).map((({url:r,path:s})=>ct(n,r).then(et).then((n=>e.writeFile(t,s,n)))))),dt=typeof document===k,gt=({main:e,worker:t})=>{const n=[];if(t&&dt)for(let[e,r]of Le(t))e=Je(e,lt.get(t)),n.push(Ve(e,r));if(e&&!dt)for(let[t,r]of Le(e))t=Je(t,lt.get(e)),Qe(t)?Ze(t):n.push(Ve(t,r));return Be(n)},yt=(e,t)=>e.has(t),mt=e=>[...e.keys()];var wt=(e,t,n)=>{let r=globalThis[Ke],s="";if(n){s=lt.get(n);for(let[e,t]of Le(n)){let n=r.get(t);n&&!Fe(n)||(r.set(t,n||(n=[])),n.push(e))}}return((e,t,n,r)=>new Proxy(e,{has:yt,ownKeys:mt,get:(e,s)=>{let o=e.get(s);if(Fe(o)){let a=o;o=null;for(let e of a)e=Je(e,r),Qe(e)?n.importCSS(e):(n.importJS(e,s),o=t[Ke].get(s));e.set(s,o)}return o}}))(r,e,t,s)};const _t=(e,t,n)=>{e.registerJsModule(t,n)},bt=(e,t,...n)=>{try{return e.runPython(Me(t),...n)}catch(t){Ie.get(e).stderr(t)}},Et=async(e,t,...n)=>{try{return await e.runPythonAsync(Me(t),...n)}catch(t){Ie.get(e).stderr(t)}},kt=async(e,t,n)=>{const[r,...s]=t.split(".");let o,a=e.globals.get(r);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,n)}catch(t){Ie.get(e).stderr(t)}};var vt=(new TextEncoder).encode(\'from uio import StringIO\\nimport sys\\n\\nclass Response:\\n def __init__(self, f):\\n self.raw = f\\n self.encoding = "utf-8"\\n self._cached = None\\n\\n def close(self):\\n if self.raw:\\n self.raw.close()\\n self.raw = None\\n self._cached = None\\n\\n @property\\n def content(self):\\n if self._cached is None:\\n try:\\n self._cached = self.raw.read()\\n finally:\\n self.raw.close()\\n self.raw = None\\n return self._cached\\n\\n @property\\n def text(self):\\n return str(self.content, self.encoding)\\n\\n def json(self):\\n import ujson\\n\\n return ujson.loads(self.content)\\n\\n\\n# TODO try to support streaming xhr requests, a-la pyodide-http\\nHEADERS_TO_IGNORE = ("user-agent",)\\n\\n\\ntry:\\n import js\\nexcept Exception as err:\\n raise OSError("This version of urequests can only be used in the browser")\\n\\n# TODO try to support streaming xhr requests, a-la pyodide-http\\n\\nHEADERS_TO_IGNORE = ("user-agent",)\\n\\n\\ndef request(\\n method,\\n url,\\n data=None,\\n json=None,\\n headers={},\\n stream=None,\\n auth=None,\\n timeout=None,\\n parse_headers=True,\\n):\\n from js import XMLHttpRequest\\n\\n xhr = XMLHttpRequest.new()\\n xhr.withCredentials = False\\n\\n if auth is not None:\\n import ubinascii\\n\\n username, password = auth\\n xhr.open(method, url, False, username, password)\\n else:\\n xhr.open(method, url, False)\\n\\n for name, value in headers.items():\\n if name.lower() not in HEADERS_TO_IGNORE:\\n xhr.setRequestHeader(name, value)\\n\\n if timeout:\\n xhr.timeout = int(timeout * 1000)\\n\\n if json is not None:\\n assert data is None\\n import ujson\\n\\n data = ujson.dumps(json)\\n # s.write(b"Content-Type: application/json\\\\r\\\\n")\\n xhr.setRequestHeader("Content-Type", "application/json")\\n\\n xhr.send(data)\\n\\n # Emulates the construction process in the original urequests\\n resp = Response(StringIO(xhr.responseText))\\n resp.status_code = xhr.status\\n resp.reason = xhr.statusText\\n resp.headers = xhr.getAllResponseHeaders()\\n\\n return resp\\n\\n\\n# Other methods - head, post, put, patch, delete - are not used by\\n# mip and therefore not included\\n\\n\\ndef get(url, **kw):\\n return request("GET", url, **kw)\\n\\n\\n# Content below this line is from the Micropython MIP package and is covered\\n# by the applicable MIT license:\\n# \\n# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, \\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER \\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING \\n# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \\n# DEALINGS IN THE SOFTWARE.\\n\\n# MicroPython package installer\\n# MIT license; Copyright (c) 2022 Jim Mussared\\n\\n\\n_PACKAGE_INDEX = const("https://micropython.org/pi/v2")\\n_CHUNK_SIZE = 128\\n\\n\\n# This implements os.makedirs(os.dirname(path))\\ndef _ensure_path_exists(path):\\n import os\\n\\n split = path.split("/")\\n\\n # Handle paths starting with "/".\\n if not split[0]:\\n split.pop(0)\\n split[0] = "/" + split[0]\\n\\n prefix = ""\\n for i in range(len(split) - 1):\\n prefix += split[i]\\n try:\\n os.stat(prefix)\\n except:\\n os.mkdir(prefix)\\n prefix += "/"\\n\\n\\n# Copy from src (stream) to dest (function-taking-bytes)\\ndef _chunk(src, dest):\\n buf = memoryview(bytearray(_CHUNK_SIZE))\\n while True:\\n n = src.readinto(buf)\\n if n == 0:\\n break\\n dest(buf if n == _CHUNK_SIZE else buf[:n])\\n\\n\\n# Check if the specified path exists and matches the hash.\\ndef _check_exists(path, short_hash):\\n import os\\n\\n try:\\n import binascii\\n import hashlib\\n\\n with open(path, "rb") as f:\\n hs256 = hashlib.sha256()\\n _chunk(f, hs256.update)\\n existing_hash = str(binascii.hexlify(hs256.digest())[: len(short_hash)], "utf-8")\\n return existing_hash == short_hash\\n except:\\n return False\\n\\n\\ndef _rewrite_url(url, branch=None):\\n if not branch:\\n branch = "HEAD"\\n if url.startswith("github:"):\\n url = url[7:].split("/")\\n url = (\\n "https://raw.githubusercontent.com/"\\n + url[0]\\n + "/"\\n + url[1]\\n + "/"\\n + branch\\n + "/"\\n + "/".join(url[2:])\\n )\\n return url\\n\\n\\ndef _download_file(url, dest):\\n response = get(url)\\n try:\\n if response.status_code != 200:\\n print("Error", response.status_code, "requesting", url)\\n return False\\n\\n print("Copying:", dest)\\n _ensure_path_exists(dest)\\n with open(dest, "wb") as f:\\n _chunk(response.raw, f.write)\\n\\n return True\\n finally:\\n response.close()\\n\\n\\ndef _install_json(package_json_url, index, target, version, mpy):\\n response = get(_rewrite_url(package_json_url, version))\\n try:\\n if response.status_code != 200:\\n print("Package not found:", package_json_url)\\n return False\\n\\n package_json = response.json()\\n finally:\\n response.close()\\n for target_path, short_hash in package_json.get("hashes", ()):\\n fs_target_path = target + "/" + target_path\\n if _check_exists(fs_target_path, short_hash):\\n print("Exists:", fs_target_path)\\n else:\\n file_url = "{}/file/{}/{}".format(index, short_hash[:2], short_hash)\\n if not _download_file(file_url, fs_target_path):\\n print("File not found: {} {}".format(target_path, short_hash))\\n return False\\n for target_path, url in package_json.get("urls", ()):\\n fs_target_path = target + "/" + target_path\\n if not _download_file(_rewrite_url(url, version), fs_target_path):\\n print("File not found: {} {}".format(target_path, url))\\n return False\\n for dep, dep_version in package_json.get("deps", ()):\\n if not _install_package(dep, index, target, dep_version, mpy):\\n return False\\n return True\\n\\n\\ndef _install_package(package, index, target, version, mpy):\\n if (\\n package.startswith("http://")\\n or package.startswith("https://")\\n or package.startswith("github:")\\n ):\\n if package.endswith(".py") or package.endswith(".mpy"):\\n print("Downloading {} to {}".format(package, target))\\n return _download_file(\\n _rewrite_url(package, version), target + "/" + package.rsplit("/")[-1]\\n )\\n else:\\n if not package.endswith(".json"):\\n if not package.endswith("/"):\\n package += "/"\\n package += "package.json"\\n print("Installing {} to {}".format(package, target))\\n else:\\n if not version:\\n version = "latest"\\n print("Installing {} ({}) from {} to {}".format(package, version, index, target))\\n\\n mpy_version = (\\n sys.implementation._mpy & 0xFF if mpy and hasattr(sys.implementation, "_mpy") else "py"\\n )\\n\\n package = "{}/package/{}/{}/{}.json".format(index, mpy_version, package, version)\\n\\n return _install_json(package, index, target, version, mpy)\\n\\n\\ndef install(package, index=None, target=None, version=None, mpy=True):\\n if not target:\\n for p in sys.path:\\n if p.endswith("/lib"):\\n target = p\\n break\\n else:\\n print("Unable to find lib dir in sys.path")\\n return\\n\\n if not index:\\n index = _PACKAGE_INDEX\\n\\n if _install_package(package, index.rstrip("/"), target, version, mpy):\\n print("Done")\\n else:\\n print("Package may be partially installed")\\n\');var Tt={type:"micropython",module:(e="1.21.0-279")=>`https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@${e}/micropython.mjs`,async engine({loadMicroPython:e},t,n){const{stderr:r,stdout:s,get:o}=$e();n=n.replace(/\\.m?js$/,".wasm");const a=await o(e({stderr:r,stdout:s,url:n}));if(t.files&&await ht(this,a,t.files),t.fetch&&await ut(this,a,t.fetch),t.js_modules&&await gt(t.js_modules),this.writeFile(a,"./mip.py",vt),t.packages){const e=a.pyimport("mip");for(const n of t.packages)e.install(n)}return a},registerJSModule:_t,run:bt,runAsync:Et,runEvent:kt,transform:(e,t)=>t instanceof e.PyProxy?e.PyProxy.toJs(t):t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:n}},r,s)=>rt({FS:e,PATH:t,PATH_FS:n},r,s)};const xt=!!globalThis.window,St={dict_converter:Object.fromEntries};let At=!1;const Ot=e=>(...t)=>{try{return At=!0,e(...t)}finally{At=!1}};let jt=!1;const Rt=()=>{if(jt)return;jt=!0;const e=new WeakMap,t=e=>e.destroy(),n=n=>{for(let r=0;r<n.length;r++){const s=n[r];if("function"==typeof s&&"copy"in s){At=!1;let o=e.get(s)?.deref();if(!o)try{o=le(s.copy(),t),e.set(s,new WeakRef(o))}catch(e){console.error(e)}o&&(n[r]=o),At=!0}}},{call:r}=Function,s=r.bind(r,r.apply);Object.defineProperties(Function.prototype,{apply:{value(e,t){return At&&n(t),s(this,e,t)}},call:{value(e,...t){return At&&n(t),s(this,e,t)}}})};var Pt={type:"pyodide",module:(e="0.25.0")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,n){xt&&"auto"===t.experimental_create_proxy&&Rt();const{stderr:r,stdout:s,get:o}=$e(),a=n.slice(0,n.lastIndexOf("/")),i=await o(e({stderr:r,stdout:s,indexURL:a}));if(t.files&&await ht(this,i,t.files),t.fetch&&await ut(this,i,t.fetch),t.js_modules&&await gt(t.js_modules),t.packages){await i.loadPackage("micropip");const e=await i.pyimport("micropip");await e.install(t.packages,{keep_going:!0}),e.destroy()}return i},registerJSModule:_t,run:Ot(bt),runAsync:Ot(Et),runEvent:Ot(kt),transform:({ffi:{PyProxy:e}},t)=>t instanceof e?t.toJs(St):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:n}},r,s)=>rt({FS:e,PATH:t,PATH_FS:n},r,s)};const Nt="ruby-wasm-wasi",It=Nt.replace(/\\W+/g,"_");var $t={type:Nt,experimental:!0,module:(e="2.2.0")=>`https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@${e}/dist/browser.esm.js`,async engine({DefaultRubyVM:e},t,n){const r=await fetch(`${n.slice(0,n.lastIndexOf("/"))}/ruby.wasm`),s=await WebAssembly.compile(await r.arrayBuffer()),{vm:o}=await e(s);return t.files&&await ht(this,o,t.files),t.fetch&&await ut(this,o,t.fetch),t.js_modules&&await gt(t.js_modules),o},registerJSModule(e,t,n){t=t.replace(/\\W+/g,"__");const r=`__module_${It}_${t}`;globalThis[r]=n,this.run(e,`require "js";$${t}=JS.global[:${r}]`),delete globalThis[r]},run:(e,t,...n)=>e.eval(Me(t),...n),runAsync:(e,t,...n)=>e.evalAsync(Me(t),...n),async runEvent(e,t,n){if(/^xworker\\.(on\\w+)$/.test(t)){const{$1:t}=RegExp,r=`__module_${It}_event`;globalThis[r]=n,this.run(e,`require "js";$xworker.call("${t}",JS.global[:${r}])`),delete globalThis[r]}else{const r=this.run(e,`method(:${t})`);await r.call(t,e.wrap(n))}},transform:(e,t)=>t,writeFile:()=>{throw new Error(`writeFile is not supported in ${Nt}`)}};var Mt={type:"wasmoon",module:(e="1.16.0")=>`https://cdn.jsdelivr.net/npm/wasmoon@${e}/+esm`,async engine({LuaFactory:e,LuaLibraries:t},n){const{stderr:r,stdout:s,get:o}=$e(),a=await o((new e).createEngine());return a.global.getTable(t.Base,(e=>{a.global.setField(e,"print",s),a.global.setField(e,"printErr",r)})),n.files&&await ht(this,a,n.files),n.fetch&&await ut(this,a,n.fetch),n.js_modules&&await gt(n.js_modules),a},registerJSModule:(e,t,n)=>{e.global.set(t,n)},run:(e,t,...n)=>{try{return e.doStringSync(Me(t),...n)}catch(t){Ie.get(e).stderr(t)}},runAsync:async(e,t,...n)=>{try{return await e.doString(Me(t),...n)}catch(t){Ie.get(e).stderr(t)}},runEvent:async(e,t,n)=>{const[r,...s]=t.split(".");let o,a=e.global.get(r);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,n)}catch(t){Ie.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,n)=>((e,t,n)=>(ot(e,st(t)),t=at(e,t),e.writeFile(t,new Uint8Array(n),{canOwn:!0})))(e,t,n)};const Ft=new Map,Ht=new Map,Wt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[n,...r]=t.split("@"),s=Ft.get(n),o=/^(?:\\.?\\.?\\/|https?:\\/\\/)/i.test(r)?r.join("@"):s.module(...r);e.set(t,{url:o,module:import(o),engine:s.engine.bind(s)})}const{url:n,module:r,engine:s}=e.get(t);return(e,o)=>r.then((r=>{Ht.set(t,e);for(const t of["files","fetch"]){const n=e?.[t];n&<.set(n,o)}for(const t of["main","worker"]){const n=e?.js_modules?.[t];n&<.set(n,o)}return s(r,e,n)}))}}),Ct=e=>{for(const t of[].concat(e.type))Ft.set(t,e)};for(const e of[Tt,Pt,$t,Mt])Ct(e);const Dt=async e=>(await import("https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js")).parse(e),Lt=e=>{try{return JSON.parse(e)}catch(t){return Dt(e)}},Bt=(e,t,n,r={})=>{if(t){const[e,s]=((e,t="./config.txt")=>{let n=typeof e;return"string"===n&&/\\.(json|toml|txt)$/.test(e)?n=RegExp.$1:e=t,[Je(e),n]})(t,n);"json"===s?r=fetch(e).then(tt):"toml"===s?r=fetch(e).then(nt).then(Dt):"string"===s?r=Lt(t):"object"===s&&t?r=t:"txt"===s&&"string"==typeof r&&(r=Lt(r)),t=e}return Ue(r).then((n=>Wt[e](n,t)))},Ut="BeforeRun",Jt="AfterRun",qt=[`code${Ut}`,`code${Ut}Async`,`code${Jt}`,`code${Jt}Async`],Gt=["onWorker","onReady",`on${Ut}`,`on${Ut}Async`,`on${Jt}`,`on${Jt}Async`];function Kt(e,t){const{run:n,runAsync:r}=Ft.get(this.type);return{...e,run:n.bind(this,t),runAsync:r.bind(this,t)}}const Yt=(e,t,n,r,s,o)=>{if(s||o){const a=Kt.bind(e,t),i=r?"runAsync":"run",c=e[i];e[i]=r?async function(e,t,...r){s&&await s.call(this,a(e),n);const i=await c.call(this,e,t,...r);return o&&await o.call(this,a(e),n),i}:function(e,t,...r){s&&s.call(this,a(e),n);const i=c.call(this,e,t,...r);return o&&o.call(this,a(e),n),i}}};try{new SharedArrayBuffer(4)}catch(e){throw new Error(["Unable to use SharedArrayBuffer due insecure environment.","Please read requirements in MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements"].join("\\n"))}let zt,Xt,Vt;const Zt=(e,t)=>{addEventListener(e,t||(async t=>{try{await zt,Xt(`xworker.on${e}`,t)}catch(e){postMessage(e)}}),!!t&&{once:!0})},{parse:Qt,stringify:en}=p,{proxy:tn,window:nn,isWindowProxy:rn}=Pe(self,{parse:Qt,stringify:en,transform:e=>Vt?Vt(e):e}),sn={sync:tn,window:nn,isWindowProxy:rn,onmessage:console.info,onerror:console.error,onmessageerror:console.warn,postMessage:postMessage.bind(self)};Zt("message",(({data:{options:e,config:t,configURL:n,code:r,hooks:s}})=>{zt=(async()=>{try{const{id:o,tag:a,type:i,custom:c,version:l,config:u,async:p}=e,f=((e,t="")=>`${e}@${t}`.replace(/@$/,""))(i,l),h=await Bt(f,t,n,u),d=Ht.get(f).js_modules?.main,g=We(Ft.get(i)),y=((e,t,n,r)=>({type:t,config:n,interpreter:r,io:Ie.get(r),run:(t,...n)=>e.run(r,t,...n),runAsync:(t,...n)=>e.runAsync(r,t,...n),runEvent:(...t)=>e.runEvent(r,...t)}))(g,c||i,u,h);let m="run";if(p&&(m+="Async"),s){const e=((e,t)=>(n,r)=>{const s=e[t].bind(e);e[t]=(e,t,...o)=>s(e,`${r?n:t}\\n${r?t:n}`,...o)})(g,m);let t,n,r="",o="";for(const e of qt){const t=s[e];if(t){const n=e.endsWith("Async");(n&&p||!n&&!p)&&(e.startsWith("codeBefore")?r=t:o=t)}}o&&e(o,!1),r&&e(r,!0);for(const e of Gt.slice(2)){const r=s[e];if(r){const s=e.endsWith("Async");if(s&&p||!s&&!p){const s=Ge(r);e.startsWith("onBefore")?t=s:n=s}}}Yt(g,y,sn,p,t,n)}const{CustomEvent:w,document:_}=nn,b=o&&_.getElementById(o)||null,E=e=>qe(b,c||i,e,!0,w),k=wt(nn,tn,d);let v="";return((e,t,n,r)=>{if("pyodide"===e)return;const s="polyscript.js_modules";for(const e of Reflect.ownKeys(r))t.registerJSModule(n,`${s}.${e}`,Xe(r,e));t.registerJSModule(n,s,r)})(i,g,h,k),g.registerJSModule(h,"polyscript",{xworker:sn,currentScript:b,js_modules:k,get target(){return!v&&b&&("SCRIPT"===a?b.after(He(_.createElement(`script-${c||i}`),{id:v=`${o}-target`})):(v=o,b.replaceChildren(),b.style.display="block")),v}}),Xt=g.runEvent.bind(g,h),Vt=g.transform.bind(g,h),b&&E("ready"),s?.onReady&&Ge(s?.onReady).call(g,Kt.call(g,y,h),sn),await g[m](h,r),b&&E("done"),h}catch(e){postMessage(e)}})(),Zt("error"),Zt("message"),Zt("messageerror")}));\n'],{type:"application/javascript"})),{type:"module"}),{postMessage:o}=s,a=this instanceof hn;if(e.length){const[t,r]=e;(n=Ve({},n||{type:t,version:r})).type||(n.type=t)}const[i]=nn(n.config,n.configURL),l=fetch(t).then(r).then((e=>{const t=a?this.toJSON():void 0;o.call(s,{options:n,config:i,code:e,hooks:t})})),c=Ve(Ce(s,g).proxy,{importJS:dt,importCSS:ht});return Xe(s,{sync:{value:c},postMessage:{value:(e,...t)=>l.then((()=>o.call(s,e,...t)))},onerror:{writable:!0,configurable:!0,value:console.error}}),s.addEventListener("message",(e=>{const{data:t}=e;t instanceof Error&&(e.stopImmediatePropagation(),s.onerror(Ke(e,{type:{value:"error"},error:{value:t}})))})),a&&this.onWorker?.(this.interpreter,s),s};const yn="Invalid content";var gn=e=>{const{src:t,worker:n}=e.attributes;if(n){let{value:r}=n;if(r)throw new SyntaxError("Invalid worker attribute");if(r=t?.value,!r){if(t)throw new SyntaxError("Invalid worker attribute");if(e.childElementCount){const{innerHTML:t,localName:n,type:s}=e,o=s||n.replace(/-script$/,"");r=Ge(t),console.warn(`Deprecated: use <script type="${o}"> for an always safe content parsing:\n`,r)}else r=e.textContent;return URL.createObjectURL(new Blob([qe(r)],{type:"text/plain"}))}return r}if(t&&e.textContent.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*(?:\/\/|#).*/gm,"").trim())throw new SyntaxError(yn)};const _n=(e,t)=>{const n=(e=>{let t=e;for(;t.parentNode;)t=t.parentNode;return t})(e);return n.getElementById(t)||((e,t=document)=>t.querySelector(e))(t,n)},wn=new WeakMap,bn={get(){let e=wn.get(this);return e||(e=document.createElement(`${this.type}-script`),wn.set(this,e),Rn(this)),e},set(e){"string"==typeof e?wn.set(this,_n(this,e)):(wn.set(this,e),Rn(this))}},vn=new WeakMap,En=new Map,kn=(e,t)=>{const n=e?.value;return n?t+n:""},jn=(e,t,n,r,s,o,a=e)=>{if(!En.has(t)){const i={interpreter:sn(n,s,o),queue:et(),XWorker:mn(e,r)};En.set(t,i),En.has(e)||En.set(e,i),En.has(a)||En.set(a,i)}return En.get(t)},Rn=async e=>{if(vn.has(e)){const{target:t}=e;t&&(e.closest("head")?document.body.append(t):e.after(t))}else{const{attributes:{async:t,config:n,env:s,target:o,version:a},src:i,type:l}=e,c=a?.value,p=on(l,c);let f=kn(n,"|");const u=kn(s,"")||`${p}${f}`;f=f.slice(1);const d=gn(e);if(d){const n=new(mn(l,c))(d,{...rt(e,l),async:!!t,config:f});return void vn.set(ze(e,"xworker",{value:n}),{xworker:n})}const h=kn(o,""),m=jn(l,u,p,c,f);vn.set(ze(e,"target",bn),m),h&&wn.set(e,_n(e,h));const y=i?fetch(i).then(r):e.textContent;m.queue=m.queue.then((()=>(async(e,t,n,r)=>{const{type:s}=e,o=Kt.get(s);o.experimental&&console.warn(`The ${s} interpreter is experimental`);const[a,i]=await Qe([vn.get(e).interpreter,t]);try{ze(document,"currentScript",{configurable:!0,get:()=>e}),ut(s,o,a,ct),o.registerJSModule(a,"polyscript",{XWorker:n,currentScript:e,js_modules:ct}),st(e,s,"ready");const t=o[r?"runAsync":"run"](a,i),l=st.bind(null,e,s,"done");return r?t.then(l):l(),t}finally{delete document.currentScript}})(e,y,m.XWorker,!!t)))}},An=new Proxy(Ke(null),{get:(e,t)=>new Promise(queueMicrotask).then((()=>Tn(t)))}),Tn=async e=>{if(En.has(e)){const{interpreter:t,queue:n}=En.get(e);return(await Qe([t,n]))[0]}const t=En.size?`Available interpreters are: ${[...En.keys()].map((e=>`"${e}"`)).join(", ")}.`:"There are no interpreters in this page.";throw new Error(`The interpreter "${e}" was not found. ${t}`)},xn=async e=>{const{type:t,currentTarget:n}=e;if(Zt.length)for(let{name:r,value:s,ownerElement:a}of o(`./@*[${Zt.map((e=>`name()="${e}${t}"`)).join(" or ")}]`,n)){r=r.slice(0,-(t.length+1));const n=await Tn(a.getAttribute(`${r}-env`)||r);Kt.get(r).runEvent(n,s,e)}},Sn=e=>{if(Zt.length)for(let{name:t,ownerElement:n}of o(`.//@*[${Zt.map((e=>`starts-with(name(),"${e}")`)).join(" or ")}]`,e)){const e=t.lastIndexOf("-"),r=t.slice(e+1);"env"!==r&&(n.addEventListener(r,xn),"disabled"in n&&!n.disabled&&(n.disabled=!0,An[t.slice(0,e)].then((()=>{n.disabled=!1}))))}},Nn=mn(),On=[],In=new Map,Pn=new Map,$n=e=>{for(const t of On)if(e.matches(t)){const n=In.get(t),r=Mn.get(n),{resolve:s}=Pn.get(n),{options:o,known:a}=r;if(!a.has(e)){a.add(e);const{interpreter:t,configURL:i,config:l,version:c,env:p,onerror:f,hooks:u}=o;let d;try{const r=gn(e);if(r){const o=Nn.call(new hn(null,u),r,{...rt(e,n),version:c,configURL:i,type:t,custom:n,config:e.getAttribute("config")||l||{},async:e.hasAttribute("async")});return ze(e,"xworker",{value:o}),void s({type:n,xworker:o})}}catch(e){d=e}const h=on(t,c),m=p||`${h}${l?`|${l}`:""}`,{interpreter:y,XWorker:g}=jn(n,m,h,c,l,i,t);y.then((o=>{const a=Ke(Kt.get(t)),i=new hn(o,u),l=function(...e){return g.apply(i,e)},c={...ot(a,n,structuredClone(Xt.get(h)),o),XWorker:l};ut(t,a,o,ct),a.registerJSModule(o,"polyscript",{XWorker:l,currentScript:n.startsWith("_")?null:e,js_modules:ct});for(const t of["Run","RunAsync"]){const n=at(a,`r${t.slice(1)}`);let r,s,o="",i="";for(const e of pn){const n=u?.main?.[e];n&&e.endsWith(t)&&(e.startsWith("codeBefore")?o=qe(n()):i=qe(n()))}i&&n(i,!1),o&&n(o,!0);for(let e=2;e<fn.length;e++){const n=fn[e],o=u?.main?.[n];o&&n.endsWith(t)&&(n.startsWith("onBefore")?r=o:s=o)}dn(a,c,e,t.endsWith("Async"),r,s)}r.queue=r.queue.then((()=>(s(c),d&&f?.(d,e),u?.main?.onReady?.(c,e))))}))}}},Mn=new Map;let Fn=0;const Cn=e=>(Pn.has(e)||Pn.set(e,Promise.withResolvers()),Pn.get(e).promise),[{define:Hn,whenDefined:Ln,env:Wn,Hook:Dn,XWorker:Bn},Un]=e("polyscript",{define:(e,t)=>{let n=null==e;if(n)e="_ps"+Fn++;else if(Kt.has(e)||Mn.has(e))throw new Error(`<script type="${e}"> already registered`);if(!Kt.has(t?.interpreter))throw new Error("Unspecified interpreter");Kt.set(e,Kt.get(t.interpreter));const r=[`script[type="${e}"]`];if(Cn(e),n){const{hooks:n}=t,r=n?.main?.onReady;t={...t,hooks:{...n,main:{...n?.main,onReady(t,n){On.splice(On.indexOf(e),1),Kt.delete(e),Mn.delete(e),Pn.delete(e),n.remove(),r?.(t)}}}},document.head.append(Ve(document.createElement("script"),{type:e}))}else r.push(`${e}-script`),Zt.push(`${e}-`);for(const t of r)In.set(t,e);On.push(...r),Mn.set(e,{options:Ve({env:e},t),known:new WeakSet,queue:Promise.resolve()}),n||Sn(document),s(r.join(",")).forEach($n)},whenDefined:Cn,env:An,Hook:hn,XWorker:Nn});if(!Un){const e=new MutationObserver((e=>{const n=zt.join(",");for(const{type:r,target:s,attributeName:o,addedNodes:a}of e)if("attributes"!==r)for(const e of a)1===e.nodeType&&(Sn(e),n&&e.matches(n)?Rn(e):t(n,e,!0));else{const e=o.lastIndexOf("-")+1;if(e){const t=o.slice(0,e);for(const n of Zt)if(t===n){const t=o.slice(e);if("env"!==t){const e=s.hasAttribute(o)?"add":"remove";s[`${e}EventListener`](t,xn)}break}}}})),t=(e,t,n)=>{e&&s(e,t).forEach(Rn),(e=On.join(","))&&(n&&$n(t),s(e,t).forEach($n))},n=t=>(e.observe(t,{childList:!0,subtree:!0,attributes:!0}),t),{attachShadow:r}=Element.prototype;Ve(Element.prototype,{attachShadow(e){return n(r.call(this,e))}}),queueMicrotask((()=>{Sn(n(document)),t(zt.join(","),document,!1)}))}var Jn=new Map([["py","pyodide"],["mpy","micropython"]]);const qn=[];for(const[e]of Jn){const t=[`script[type="${e}"]`,`${e}-script`];for(const n of document.querySelectorAll(t.join(","))){const{promise:t,resolve:r}=Promise.withResolvers();qn.push(t),n.addEventListener(`${e}:done`,r,{once:!0})}}Promise.all(qn).then((()=>{dispatchEvent(new Event("py:all-done"))}));var Gn={"deprecations-manager":()=>import("./deprecations-manager-DiLupR6w.js"),error:()=>import("./error-tt9AxwDf.js"),"py-editor":()=>import("./py-editor-d8hnd4Gu.js"),"py-terminal":()=>import("./py-terminal-HcALwKhy.js")};const Yn={GENERIC:"PY0000",CONFLICTING_CODE:"PY0409",BAD_CONFIG:"PY1000",MICROPIP_INSTALL_ERROR:"PY1001",BAD_PLUGIN_FILE_EXTENSION:"PY2000",NO_DEFAULT_EXPORT:"PY2001",TOP_LEVEL_AWAIT:"PY9000",FETCH_ERROR:"PY0001",FETCH_NAME_ERROR:"PY0002",FETCH_UNAUTHORIZED_ERROR:"PY0401",FETCH_FORBIDDEN_ERROR:"PY0403",FETCH_NOT_FOUND_ERROR:"PY0404",FETCH_SERVER_ERROR:"PY0500",FETCH_UNAVAILABLE_ERROR:"PY0503"};class Vn extends Error{constructor(e,t="",n="text"){super(`(${e}): ${t}`),this.errorCode=e,this.messageType=n,this.name="UserError"}}class Kn extends Vn{constructor(e,t){super(e,t),this.name="FetchError"}}async function Xn(e,t){let n;try{n=await fetch(e,t)}catch(t){const n=t;let r;throw r=e.startsWith("http")?`Fetching from URL ${e} failed with error '${n.message}'. Are your filename and path correct?`:'Polyscript: Access to local files\n (using [[fetch]] configurations in <py-config>)\n is not available when directly opening a HTML file;\n you must use a webserver to serve the additional files.\n See <a style="text-decoration: underline;" href="https://github.com/pyscript/pyscript/issues/257#issuecomment-1119595062">this reference</a>\n on starting a simple webserver with Python.\n ',new Kn(Yn.FETCH_ERROR,r)}if(!n.ok){const t=`Fetching from URL ${e} failed with error ${n.status} (${n.statusText}). Are your filename and path correct?`;switch(n.status){case 404:throw new Kn(Yn.FETCH_NOT_FOUND_ERROR,t);case 401:throw new Kn(Yn.FETCH_UNAUTHORIZED_ERROR,t);case 403:throw new Kn(Yn.FETCH_FORBIDDEN_ERROR,t);case 500:throw new Kn(Yn.FETCH_SERVER_ERROR,t);case 503:throw new Kn(Yn.FETCH_UNAVAILABLE_ERROR,t);default:throw new Kn(Yn.FETCH_ERROR,t)}}return n}const{BAD_CONFIG:zn,CONFLICTING_CODE:Zn}=Yn,Qn=async(e,t)=>{let n=e?.trim(),s="",o=!1,a=/^{/.test(n)&&/}$/.test(n);if(!a&&/\.(\w+)(?:\?\S*)?$/.test(n)){const e=RegExp.$1;"json"===e&&"toml"!==t?a=!0:"toml"===e&&"json"!==t?o=!0:((e,t="")=>{let n=`(${zn}): Invalid URL: ${e}`;throw t&&(n+=`\nexpected ${t} content`),new Error(n)})(n,t),s=n,n=(await Xn(s).then(r)).trim()}return{json:a,toml:o||!a&&!!n,text:n,url:s}},er=e=>new Error(`(${Zn}): ${e}`),tr=(e,t,{message:n})=>{let r=`(${zn}): Invalid ${e}`;return t&&(r+=` @ ${t}`),new SyntaxError(`${r}\n${n}`)},nr=new Map;for(const[e]of Jn){let t,n,r,o,a,i,l,c=s(`${e}-config`),p=s([`script[type="${e}"][config]:not([worker])`,`${e}-script[config]:not([worker])`].join(","));if(c.length>1?r=er(`Too many ${e}-config`):c.length&&p.length?r=er(`Ambiguous ${e}-config VS config attribute`):c.length?([l]=c,a=l.getAttribute("src")||l.textContent,i=l.getAttribute("type")):p.length&&([l,...p]=p,a=l.getAttribute("config"),p.some((e=>e.getAttribute("config")!==a))&&(r=er("Unable to use different configs on main"))),!r&&a)try{const{json:e,toml:t,text:s,url:l}=await Qn(a,i);if(l&&(o=new URL(l,location.href).href),a=s,e||"json"===i)try{n=JSON.parse(s)}catch(e){r=tr("JSON",l,e)}else if(t||"toml"===i)try{const{parse:e}=await import("./toml--Dzglv4T.js");n=e(s)}catch(e){r=tr("TOML",l,e)}}catch(e){r=e}const f=[];for(const[e,t]of Object.entries(Gn))r?"error"===e&&t().then((({notify:e})=>e(r.message))):n?.plugins?.includes(`!${e}`)||f.push(t().then((({default:e})=>e)));t=Promise.all(f),nr.set(e,{config:n,configURL:o,plugins:t,error:r})}var rr={is_pyterminal:()=>!1,sleep:e=>new Promise((t=>setTimeout(t,1e3*e)))};const sr=e=>{ze(document,"currentScript",{configurable:!0,get:()=>e})},or=()=>{delete document.currentScript};var ar=async(e,t,n,r)=>{const s=r.endsWith("Async");(r.startsWith("onBefore")?sr:or)(n);for(const o of e(r))s?await o(t,n):o(t,n)};const ir=()=>!0,lr=e=>{throw new TypeError(e)},cr=(e,t)=>{const n=[];if(e)for(const t of e.split(/\s*\|\s*/))"object"===t?n.push((e=>null!==e&&typeof e===t)):"null"===t?n.push((e=>null===e)):n.push((e=>typeof e===t));if(t)for(const e of[].concat(t))n.push((t=>t instanceof e));switch(n.length){case 0:return ir;case 1:return n[0];default:return e=>n.some((t=>t(e)))}},pr=(e,t,n,r=lr)=>s=>{const o=[`Invalid ${typeof s} ${n}: expected `];e&&(o.push(e),t&&o.push(" or ")),t&&(o.push("an instanceof "),o.push([].concat(t).map((({name:e})=>e)).join(" | "))),r(o.join(""),s)},fr=(e=>t=>{const[n,r]=((e,t="value")=>{const n=e?.typeof,r=e?.instanceof;return[cr(n,r),pr(n,r,t,e?.onerror)]})(t);return class extends e{add(e){return n(e)?super.add(e):r(e)}}})(Set);const{entries:ur}=Object,dr=["import os as _os","from pathlib import Path as _Path","_path = None"],hr=(e,t)=>{for(const[n,r]of ur(t))if(dr.push(`_path = _Path("${e}/${n}")`),"string"==typeof r){const e=JSON.stringify(r);dr.push(`_path.write_text(${e})`)}else dr.push(`if not _os.path.exists("${e}/${n}"):`),dr.push(" _path.mkdir(parents=True, exist_ok=True)"),hr(`${e}/${n}`,r)};hr(".",{pyscript:{"__init__.py":'# Some notes about the naming conventions and the relationship between various\n# similar-but-different names.\n#\n# import pyscript\n# this package contains the main user-facing API offered by pyscript. All\n# the names which are supposed be used by end users should be made\n# available in pyscript/__init__.py (i.e., this file)\n#\n# import _pyscript\n# this is an internal module implemented in JS. It is used internally by\n# the pyscript package, end users should not use it directly. For its\n# implementation, grep for `interpreter.registerJsModule("_pyscript",\n# ...)` in core.js\n#\n# import js\n# this is the JS globalThis, as exported by pyodide and/or micropython\'s\n# FFIs. As such, it contains different things in the main thread or in a\n# worker.\n#\n# import pyscript.magic_js\n# this submodule abstracts away some of the differences between the main\n# thread and the worker. In particular, it defines `window` and `document`\n# in such a way that these names work in both cases: in the main thread,\n# they are the "real" objects, in the worker they are proxies which work\n# thanks to coincident.\n#\n# from pyscript import window, document\n# these are just the window and document objects as defined by\n# pyscript.magic_js. This is the blessed way to access them from pyscript,\n# as it works transparently in both the main thread and worker cases.\n\nfrom pyscript.display import HTML, display\nfrom pyscript.magic_js import (\n RUNNING_IN_WORKER,\n PyWorker,\n current_target,\n document,\n js_modules,\n sync,\n window,\n)\n\ntry:\n from pyscript.event_handling import when\nexcept:\n from pyscript.util import NotSupported\n\n when = NotSupported(\n "pyscript.when", "pyscript.when currently not available with this interpreter"\n )\n',"display.py":'import base64\nimport html\nimport io\nimport re\n\nfrom pyscript.magic_js import current_target, document, window\n\n_MIME_METHODS = {\n "__repr__": "text/plain",\n "_repr_html_": "text/html",\n "_repr_markdown_": "text/markdown",\n "_repr_svg_": "image/svg+xml",\n "_repr_pdf_": "application/pdf",\n "_repr_jpeg_": "image/jpeg",\n "_repr_png_": "image/png",\n "_repr_latex": "text/latex",\n "_repr_json_": "application/json",\n "_repr_javascript_": "application/javascript",\n "savefig": "image/png",\n}\n\n\ndef _render_image(mime, value, meta):\n # If the image value is using bytes we should convert it to base64\n # otherwise it will return raw bytes and the browser will not be able to\n # render it.\n if isinstance(value, bytes):\n value = base64.b64encode(value).decode("utf-8")\n\n # This is the pattern of base64 strings\n base64_pattern = re.compile(\n r"^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$"\n )\n # If value doesn\'t match the base64 pattern we should encode it to base64\n if len(value) > 0 and not base64_pattern.match(value):\n value = base64.b64encode(value.encode("utf-8")).decode("utf-8")\n\n data = f"data:{mime};charset=utf-8;base64,{value}"\n attrs = " ".join([\'{k}="{v}"\' for k, v in meta.items()])\n return f\'<img src="{data}" {attrs}></img>\'\n\n\ndef _identity(value, meta):\n return value\n\n\n_MIME_RENDERERS = {\n "text/plain": html.escape,\n "text/html": _identity,\n "image/png": lambda value, meta: _render_image("image/png", value, meta),\n "image/jpeg": lambda value, meta: _render_image("image/jpeg", value, meta),\n "image/svg+xml": _identity,\n "application/json": _identity,\n "application/javascript": lambda value, meta: f"<script>{value}<\\\\/script>",\n}\n\n\nclass HTML:\n """\n Wrap a string so that display() can render it as plain HTML\n """\n\n def __init__(self, html):\n self._html = html\n\n def _repr_html_(self):\n return self._html\n\n\ndef _eval_formatter(obj, print_method):\n """\n Evaluates a formatter method.\n """\n if print_method == "__repr__":\n return repr(obj)\n elif hasattr(obj, print_method):\n if print_method == "savefig":\n buf = io.BytesIO()\n obj.savefig(buf, format="png")\n buf.seek(0)\n return base64.b64encode(buf.read()).decode("utf-8")\n return getattr(obj, print_method)()\n elif print_method == "_repr_mimebundle_":\n return {}, {}\n return None\n\n\ndef _format_mime(obj):\n """\n Formats object using _repr_x_ methods.\n """\n if isinstance(obj, str):\n return html.escape(obj), "text/plain"\n\n mimebundle = _eval_formatter(obj, "_repr_mimebundle_")\n if isinstance(mimebundle, tuple):\n format_dict, _ = mimebundle\n else:\n format_dict = mimebundle\n\n output, not_available = None, []\n for method, mime_type in reversed(_MIME_METHODS.items()):\n if mime_type in format_dict:\n output = format_dict[mime_type]\n else:\n output = _eval_formatter(obj, method)\n\n if output is None:\n continue\n elif mime_type not in _MIME_RENDERERS:\n not_available.append(mime_type)\n continue\n break\n if output is None:\n if not_available:\n window.console.warn(\n f"Rendered object requested unavailable MIME renderers: {not_available}"\n )\n output = repr(output)\n mime_type = "text/plain"\n elif isinstance(output, tuple):\n output, meta = output\n else:\n meta = {}\n return _MIME_RENDERERS[mime_type](output, meta), mime_type\n\n\ndef _write(element, value, append=False):\n html, mime_type = _format_mime(value)\n if html == "\\\\n":\n return\n\n if append:\n out_element = document.createElement("div")\n element.append(out_element)\n else:\n out_element = element.lastElementChild\n if out_element is None:\n out_element = element\n\n if mime_type in ("application/javascript", "text/html"):\n script_element = document.createRange().createContextualFragment(html)\n out_element.append(script_element)\n else:\n out_element.innerHTML = html\n\n\ndef display(*values, target=None, append=True):\n if target is None:\n target = current_target()\n elif not isinstance(target, str):\n raise TypeError(f"target must be str or None, not {target.__class__.__name__}")\n elif target == "":\n raise ValueError("Cannot have an empty target")\n elif target.startswith("#"):\n # note: here target is str and not None!\n # align with @when behavior\n target = target[1:]\n\n element = document.getElementById(target)\n\n # If target cannot be found on the page, a ValueError is raised\n if element is None:\n raise ValueError(\n f"Invalid selector with id={target}. Cannot be found in the page."\n )\n\n # if element is a <script type="py">, it has a \'target\' attribute which\n # points to the visual element holding the displayed values. In that case,\n # use that.\n if element.tagName == "SCRIPT" and hasattr(element, "target"):\n element = element.target\n\n for v in values:\n if not append:\n element.replaceChildren()\n _write(element, v, append=append)\n',"event_handling.py":'import inspect\n\nfrom pyodide.ffi.wrappers import add_event_listener\nfrom pyscript.magic_js import document\n\n\ndef when(event_type=None, selector=None):\n """\n Decorates a function and passes py-* events to the decorated function\n The events might or not be an argument of the decorated function\n """\n\n def decorator(func):\n if isinstance(selector, str):\n elements = document.querySelectorAll(selector)\n else:\n # TODO: This is a hack that will be removed when pyscript becomes a package\n # and we can better manage the imports without circular dependencies\n from pyweb import pydom\n\n if isinstance(selector, pydom.Element):\n elements = [selector._js]\n elif isinstance(selector, pydom.ElementCollection):\n elements = [el._js for el in selector]\n else:\n raise ValueError(\n f"Invalid selector: {selector}. Selector must"\n " be a string, a pydom.Element or a pydom.ElementCollection."\n )\n\n sig = inspect.signature(func)\n # Function doesn\'t receive events\n if not sig.parameters:\n\n def wrapper(*args, **kwargs):\n func()\n\n for el in elements:\n add_event_listener(el, event_type, wrapper)\n else:\n for el in elements:\n add_event_listener(el, event_type, func)\n return func\n\n return decorator\n',"magic_js.py":'import sys\n\nimport js as globalThis\nfrom polyscript import js_modules\nfrom pyscript.util import NotSupported\n\nRUNNING_IN_WORKER = not hasattr(globalThis, "document")\n\n\n# allow `from pyscript.js_modules.xxx import yyy`\nclass JSModule:\n def __init__(self, name):\n self.name = name\n\n def __getattr__(self, field):\n # avoid pyodide looking for non existent fields\n if not field.startswith("_"):\n return getattr(getattr(js_modules, self.name), field)\n\n\n# generate N modules in the system that will proxy the real value\nfor name in globalThis.Reflect.ownKeys(js_modules):\n sys.modules[f"pyscript.js_modules.{name}"] = JSModule(name)\nsys.modules["pyscript.js_modules"] = js_modules\n\nif RUNNING_IN_WORKER:\n import js\n import polyscript\n\n PyWorker = NotSupported(\n "pyscript.PyWorker",\n "pyscript.PyWorker works only when running in the main thread",\n )\n window = polyscript.xworker.window\n document = window.document\n js.document = document\n sync = polyscript.xworker.sync\n\n # in workers the display does not have a default ID\n # but there is a sync utility from xworker\n def current_target():\n return polyscript.target\n\nelse:\n import _pyscript\n from _pyscript import PyWorker\n\n window = globalThis\n document = globalThis.document\n sync = NotSupported(\n "pyscript.sync", "pyscript.sync works only when running in a worker"\n )\n\n # in MAIN the current element target exist, just use it\n def current_target():\n return _pyscript.target\n',"util.py":'class NotSupported:\n """\n Small helper that raises exceptions if you try to get/set any attribute on\n it.\n """\n\n def __init__(self, name, error):\n object.__setattr__(self, "name", name)\n object.__setattr__(self, "error", error)\n\n def __repr__(self):\n return f"<NotSupported {self.name} [{self.error}]>"\n\n def __getattr__(self, attr):\n raise AttributeError(self.error)\n\n def __setattr__(self, attr, value):\n raise AttributeError(self.error)\n\n def __call__(self, *args):\n raise TypeError(self.error)\n'},pyweb:{"media.py":'from pyodide.ffi import to_js\nfrom pyscript import window\n\n\nclass Device:\n """Device represents a media input or output device, such as a microphone,\n camera, or headset.\n """\n\n def __init__(self, device):\n self._js = device\n\n @property\n def id(self):\n return self._js.deviceId\n\n @property\n def group(self):\n return self._js.groupId\n\n @property\n def kind(self):\n return self._js.kind\n\n @property\n def label(self):\n return self._js.label\n\n def __getitem__(self, key):\n return getattr(self, key)\n\n @classmethod\n async def load(cls, audio=False, video=True):\n """Load the device stream."""\n options = window.Object.new()\n options.audio = audio\n if isinstance(video, bool):\n options.video = video\n else:\n # TODO: Think this can be simplified but need to check it on the pyodide side\n\n # TODO: this is pyodide specific. shouldn\'t be!\n options.video = window.Object.new()\n for k in video:\n setattr(\n options.video,\n k,\n to_js(video[k], dict_converter=window.Object.fromEntries),\n )\n\n stream = await window.navigator.mediaDevices.getUserMedia(options)\n return stream\n\n async def get_stream(self):\n key = self.kind.replace("input", "").replace("output", "")\n options = {key: {"deviceId": {"exact": self.id}}}\n\n return await self.load(**options)\n\n\nasync def list_devices() -> list[dict]:\n """\n Return the list of the currently available media input and output devices,\n such as microphones, cameras, headsets, and so forth.\n\n Output:\n\n list(dict) - list of dictionaries representing the available media devices.\n Each dictionary has the following keys:\n * deviceId: a string that is an identifier for the represented device\n that is persisted across sessions. It is un-guessable by other\n applications and unique to the origin of the calling application.\n It is reset when the user clears cookies (for Private Browsing, a\n different identifier is used that is not persisted across sessions).\n\n * groupId: a string that is a group identifier. Two devices have the same\n group identifier if they belong to the same physical device — for\n example a monitor with both a built-in camera and a microphone.\n\n * kind: an enumerated value that is either "videoinput", "audioinput"\n or "audiooutput".\n\n * label: a string describing this device (for example "External USB\n Webcam").\n\n Note: the returned list will omit any devices that are blocked by the document\n Permission Policy: microphone, camera, speaker-selection (for output devices),\n and so on. Access to particular non-default devices is also gated by the\n Permissions API, and the list will omit devices for which the user has not\n granted explicit permission.\n """\n # https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices\n return [\n Device(obj) for obj in await window.navigator.mediaDevices.enumerateDevices()\n ]\n',"pydom.py":'import sys\nimport warnings\nfrom functools import cached_property\nfrom typing import Any\n\nfrom pyodide.ffi import JsProxy\nfrom pyscript import display, document, window\n\nalert = window.alert\n\n\nclass BaseElement:\n def __init__(self, js_element):\n self._js = js_element\n self._parent = None\n self.style = StyleProxy(self)\n self._proxies = {}\n\n def __eq__(self, obj):\n """Check if the element is the same as the other element by comparing\n the underlying JS element"""\n return isinstance(obj, BaseElement) and obj._js == self._js\n\n @property\n def parent(self):\n if self._parent:\n return self._parent\n\n if self._js.parentElement:\n self._parent = self.__class__(self._js.parentElement)\n\n return self._parent\n\n @property\n def __class(self):\n return self.__class__ if self.__class__ != PyDom else Element\n\n def create(self, type_, is_child=True, classes=None, html=None, label=None):\n js_el = document.createElement(type_)\n element = self.__class(js_el)\n\n if classes:\n for class_ in classes:\n element.add_class(class_)\n\n if html is not None:\n element.html = html\n\n if label is not None:\n element.label = label\n\n if is_child:\n self.append(element)\n\n return element\n\n def find(self, selector):\n """Return an ElementCollection representing all the child elements that\n match the specified selector.\n\n Args:\n selector (str): A string containing a selector expression\n\n Returns:\n ElementCollection: A collection of elements matching the selector\n """\n elements = self._js.querySelectorAll(selector)\n if not elements:\n return None\n return ElementCollection([Element(el) for el in elements])\n\n\nclass Element(BaseElement):\n @property\n def children(self):\n return [self.__class__(el) for el in self._js.children]\n\n def append(self, child):\n # TODO: this is Pyodide specific for now!!!!!!\n # if we get passed a JSProxy Element directly we just map it to the\n # higher level Python element\n if isinstance(child, JsProxy):\n return self.append(Element(child))\n\n elif isinstance(child, Element):\n self._js.appendChild(child._js)\n\n return child\n\n elif isinstance(child, ElementCollection):\n for el in child:\n self.append(el)\n\n # -------- Pythonic Interface to Element -------- #\n @property\n def html(self):\n return self._js.innerHTML\n\n @html.setter\n def html(self, value):\n self._js.innerHTML = value\n\n @property\n def content(self):\n # TODO: This breaks with with standard template elements. Define how to best\n # handle this specifica use case. Just not support for now?\n if self._js.tagName == "TEMPLATE":\n warnings.warn(\n "Content attribute not supported for template elements.", stacklevel=2\n )\n return None\n return self._js.innerHTML\n\n @content.setter\n def content(self, value):\n # TODO: (same comment as above)\n if self._js.tagName == "TEMPLATE":\n warnings.warn(\n "Content attribute not supported for template elements.", stacklevel=2\n )\n return\n\n display(value, target=self.id)\n\n @property\n def id(self):\n return self._js.id\n\n @id.setter\n def id(self, value):\n self._js.id = value\n\n @property\n def options(self):\n if "options" in self._proxies:\n return self._proxies["options"]\n\n if not self._js.tagName.lower() in {"select", "datalist", "optgroup"}:\n raise AttributeError(\n f"Element {self._js.tagName} has no options attribute."\n )\n self._proxies["options"] = OptionsProxy(self)\n return self._proxies["options"]\n\n @property\n def value(self):\n return self._js.value\n\n @value.setter\n def value(self, value):\n # in order to avoid confusion to the user, we don\'t allow setting the\n # value of elements that don\'t have a value attribute\n if not hasattr(self._js, "value"):\n raise AttributeError(\n f"Element {self._js.tagName} has no value attribute. If you want to "\n "force a value attribute, set it directly using the `_js.value = <value>` "\n "javascript API attribute instead."\n )\n self._js.value = value\n\n @property\n def selected(self):\n return self._js.selected\n\n @selected.setter\n def selected(self, value):\n # in order to avoid confusion to the user, we don\'t allow setting the\n # value of elements that don\'t have a value attribute\n if not hasattr(self._js, "selected"):\n raise AttributeError(\n f"Element {self._js.tagName} has no value attribute. If you want to "\n "force a value attribute, set it directly using the `_js.value = <value>` "\n "javascript API attribute instead."\n )\n self._js.selected = value\n\n def clone(self, new_id=None):\n clone = Element(self._js.cloneNode(True))\n clone.id = new_id\n\n return clone\n\n def remove_class(self, classname):\n classList = self._js.classList\n if isinstance(classname, list):\n classList.remove(*classname)\n else:\n classList.remove(classname)\n return self\n\n def add_class(self, classname):\n classList = self._js.classList\n if isinstance(classname, list):\n classList.add(*classname)\n else:\n self._js.classList.add(classname)\n return self\n\n @property\n def classes(self):\n classes = self._js.classList.values()\n return [x for x in classes]\n\n def show_me(self):\n self._js.scrollIntoView()\n\n def snap(\n self,\n to: BaseElement | str = None,\n width: int | None = None,\n height: int | None = None,\n ):\n """\n Captures a snapshot of a video element. (Only available for video elements)\n\n Inputs:\n\n * to: element where to save the snapshot of the video frame to\n * width: width of the image\n * height: height of the image\n\n Output:\n (Element) canvas element where the video frame snapshot was drawn into\n """\n if self._js.tagName != "VIDEO":\n raise AttributeError("Snap method is only available for video Elements")\n\n if to is None:\n canvas = self.create("canvas")\n if width is None:\n width = self._js.width\n if height is None:\n height = self._js.height\n canvas._js.width = width\n canvas._js.height = height\n\n elif isistance(to, Element):\n if to._js.tagName != "CANVAS":\n raise TypeError("Element to snap to must a canvas.")\n canvas = to\n elif getattr(to, "tagName", "") == "CANVAS":\n canvas = Element(to)\n elif isinstance(to, str):\n canvas = pydom[to][0]\n if canvas._js.tagName != "CANVAS":\n raise TypeError("Element to snap to must a be canvas.")\n\n canvas.draw(self, width, height)\n\n return canvas\n\n def download(self, filename: str = "snapped.png") -> None:\n """Download the current element (only available for canvas elements) with the filename\n provided in input.\n\n Inputs:\n * filename (str): name of the file being downloaded\n\n Output:\n None\n """\n if self._js.tagName != "CANVAS":\n raise AttributeError(\n "The download method is only available for canvas Elements"\n )\n\n link = self.create("a")\n link._js.download = filename\n link._js.href = self._js.toDataURL()\n link._js.click()\n\n def draw(self, what, width, height):\n """Draw `what` on the current element (only available for canvas elements).\n\n Inputs:\n\n * what (canvas image source): An element to draw into the context. The specification permits any canvas\n image source, specifically, an HTMLImageElement, an SVGImageElement, an HTMLVideoElement,\n an HTMLCanvasElement, an ImageBitmap, an OffscreenCanvas, or a VideoFrame.\n """\n if self._js.tagName != "CANVAS":\n raise AttributeError(\n "The draw method is only available for canvas Elements"\n )\n\n if isinstance(what, Element):\n what = what._js\n\n # https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage\n self._js.getContext("2d").drawImage(what, 0, 0, width, height)\n\n\nclass OptionsProxy:\n """This class represents the options of a select element. It\n allows to access to add and remove options by using the `add` and `remove` methods.\n """\n\n def __init__(self, element: Element) -> None:\n self._element = element\n if self._element._js.tagName.lower() != "select":\n raise AttributeError(\n f"Element {self._element._js.tagName} has no options attribute."\n )\n\n def add(\n self,\n value: Any = None,\n html: str = None,\n text: str = None,\n before: Element | int = None,\n **kws,\n ) -> None:\n """Add a new option to the select element"""\n # create the option element and set the attributes\n option = document.createElement("option")\n if value is not None:\n kws["value"] = value\n if html is not None:\n option.innerHTML = html\n if text is not None:\n kws["text"] = text\n\n for key, value in kws.items():\n option.setAttribute(key, value)\n\n if before:\n if isinstance(before, Element):\n before = before._js\n\n self._element._js.add(option, before)\n\n def remove(self, item: int) -> None:\n """Remove the option at the specified index"""\n self._element._js.remove(item)\n\n def clear(self) -> None:\n """Remove all the options"""\n for i in range(len(self)):\n self.remove(0)\n\n @property\n def options(self):\n """Return the list of options"""\n return [Element(opt) for opt in self._element._js.options]\n\n @property\n def selected(self):\n """Return the selected option"""\n return self.options[self._element._js.selectedIndex]\n\n def __iter__(self):\n yield from self.options\n\n def __len__(self):\n return len(self.options)\n\n def __repr__(self):\n return f"{self.__class__.__name__} (length: {len(self)}) {self.options}"\n\n def __getitem__(self, key):\n return self.options[key]\n\n\nclass StyleProxy(dict):\n def __init__(self, element: Element) -> None:\n self._element = element\n\n @cached_property\n def _style(self):\n return self._element._js.style\n\n def __getitem__(self, key):\n return self._style.getPropertyValue(key)\n\n def __setitem__(self, key, value):\n self._style.setProperty(key, value)\n\n def remove(self, key):\n self._style.removeProperty(key)\n\n def set(self, **kws):\n for k, v in kws.items():\n self._element._js.style.setProperty(k, v)\n\n # CSS Properties\n # Reference: https://github.com/microsoft/TypeScript/blob/main/src/lib/dom.generated.d.ts#L3799C1-L5005C2\n # Following prperties automatically generated from the above reference using\n # tools/codegen_css_proxy.py\n @property\n def visible(self):\n return self._element._js.style.visibility\n\n @visible.setter\n def visible(self, value):\n self._element._js.style.visibility = value\n\n\nclass StyleCollection:\n def __init__(self, collection: "ElementCollection") -> None:\n self._collection = collection\n\n def __get__(self, obj, objtype=None):\n return obj._get_attribute("style")\n\n def __getitem__(self, key):\n return self._collection._get_attribute("style")[key]\n\n def __setitem__(self, key, value):\n for element in self._collection._elements:\n element.style[key] = value\n\n def remove(self, key):\n for element in self._collection._elements:\n element.style.remove(key)\n\n\nclass ElementCollection:\n def __init__(self, elements: [Element]) -> None:\n self._elements = elements\n self.style = StyleCollection(self)\n\n def __getitem__(self, key):\n # If it\'s an integer we use it to access the elements in the collection\n if isinstance(key, int):\n return self._elements[key]\n # If it\'s a slice we use it to support slice operations over the elements\n # in the collection\n elif isinstance(key, slice):\n return ElementCollection(self._elements[key])\n\n # If it\'s anything else (basically a string) we use it as a selector\n # TODO: Write tests!\n elements = self._element.querySelectorAll(key)\n return ElementCollection([Element(el) for el in elements])\n\n def __len__(self):\n return len(self._elements)\n\n def __eq__(self, obj):\n """Check if the element is the same as the other element by comparing\n the underlying JS element"""\n return isinstance(obj, ElementCollection) and obj._elements == self._elements\n\n def _get_attribute(self, attr, index=None):\n if index is None:\n return [getattr(el, attr) for el in self._elements]\n\n # As JQuery, when getting an attr, only return it for the first element\n return getattr(self._elements[index], attr)\n\n def _set_attribute(self, attr, value):\n for el in self._elements:\n setattr(el, attr, value)\n\n @property\n def html(self):\n return self._get_attribute("html")\n\n @html.setter\n def html(self, value):\n self._set_attribute("html", value)\n\n @property\n def value(self):\n return self._get_attribute("value")\n\n @value.setter\n def value(self, value):\n self._set_attribute("value", value)\n\n @property\n def children(self):\n return self._elements\n\n def __iter__(self):\n yield from self._elements\n\n def __repr__(self):\n return f"{self.__class__.__name__} (length: {len(self._elements)}) {self._elements}"\n\n\nclass DomScope:\n def __getattr__(self, __name: str) -> Any:\n element = document[f"#{__name}"]\n if element:\n return element[0]\n\n\nclass PyDom(BaseElement):\n # Add objects we want to expose to the DOM namespace since this class instance is being\n # remapped as "the module" itself\n BaseElement = BaseElement\n Element = Element\n ElementCollection = ElementCollection\n\n def __init__(self):\n super().__init__(document)\n self.ids = DomScope()\n self.body = Element(document.body)\n self.head = Element(document.head)\n\n def create(self, type_, classes=None, html=None):\n return super().create(type_, is_child=False, classes=classes, html=html)\n\n def __getitem__(self, key):\n if isinstance(key, int):\n indices = range(*key.indices(len(self.list)))\n return [self.list[i] for i in indices]\n\n elements = self._js.querySelectorAll(key)\n if not elements:\n return None\n return ElementCollection([Element(el) for el in elements])\n\n\ndom = PyDom()\n\nsys.modules[__name__] = dom\n'}}),dr.push("import pyscript as _pyscript"),dr.push(...["_Path","_path","_os","_pyscript"].map((e=>`del ${e}`))),dr.push("\n");var mr=dr.join("\n");const yr=e=>kr.main[e],gr=e=>kr.worker[e],_r=(e,t,n,r)=>{e[n]=()=>{const e=r?[r]:[];return e.push(...t(n)),e.map(qe).join("\n")}},wr=e=>{const t={};return _r(t,e,"codeBeforeRun",mr),_r(t,e,"codeBeforeRunAsync",mr),_r(t,e,"codeAfterRun"),_r(t,e,"codeAfterRunAsync"),t},br=(e,t)=>{const n=[...gr(t)];if(n.length){const r=an(e[`_${t}`]||(t.endsWith("Async")?async(e,t,...n)=>{for(const r of n)await r(e,t)}:(e,t,...n)=>{for(const r of n)r(e,t)})),s=n.map(an).join(", ");return Function(`return(w,x)=>(${r})(w,x,...[${s}])`)()}},vr=fr({typeof:"function"}),Er=fr({typeof:"string"}),kr={main:{onWorker:new vr,onReady:new vr,onBeforeRun:new vr,onBeforeRunAsync:new vr,onAfterRun:new vr,onAfterRunAsync:new vr,codeBeforeRun:new Er(['\n import builtins\n def input(prompt=""):\n raise Exception("\\n ".join([\n "input() doesn\'t work when PyScript runs in the main thread.",\n "Consider using the worker attribute: https://pyscript.github.io/docs/2023.11.2/user-guide/workers/"\n ]))\n\n builtins.input = input\n del builtins\n del input\n']),codeBeforeRunAsync:new Er,codeAfterRun:new Er,codeAfterRunAsync:new Er},worker:{onReady:new vr,onBeforeRun:new vr,onBeforeRunAsync:new vr,onAfterRun:new vr,onAfterRunAsync:new vr,codeBeforeRun:new Er,codeBeforeRunAsync:new Er,codeAfterRun:new Er,codeAfterRunAsync:new Er}},jr=({tagName:e})=>"SCRIPT"===e,[{PyWorker:Rr,hooks:Ar,config:Tr,whenDefined:xr},Sr]=e("@pyscript/core",{PyWorker:function(e,t){const n=Nr.get("py"),r=Bn.call(new Dn(null,n),e,{type:"pyodide",...t});return Ve(r.sync,rr),r},hooks:kr,config:{},whenDefined:Ln}),Nr=new Map;for(const[e,t]of Jn){if(Sr)break;const n=(t,n,r)=>{n?r.then((()=>st(t,e,"done"))):st(t,e,"done")},{config:s,configURL:o,plugins:a,error:i}=nr.get(e);let l=0;const c=(t=e)=>`${t}-${l++}`,p=async(t,n,s)=>{if(t.hasAttribute("src"))try{return await Xn(t.getAttribute("src")).then(r)}catch(e){n.stderr(e)}if(s)return qe(t.textContent);const o=qe(Ge(t.innerHTML));return console.warn(`Deprecated: use <script type="${e}"> for an always safe content parsing:\n`,o),o};let f,u=!1;const d=({XWorker:e,interpreter:t,io:n})=>{u||(u=!0,t.registerJsModule("_pyscript",{PyWorker:function(...t){const r=e(...t);return r.onerror=({error:e})=>n.stderr(e),r},get target(){return jr(f)?f.target.id:f.id}}))};i||a.then((()=>{const r=new Map,a={main:{...wr(yr),async onReady(t,s){d(t);for(const e of yr("onReady"))await e(t,s);if(r.has(s)){let{message:e}=r.get(s);r.delete(s);const n=e===yn;return e=`(${Yn.CONFLICTING_CODE}) ${e} for `,e+=s.cloneNode(n).outerHTML,void t.io.stderr(e)}if(jr(s)){const{attributes:{async:r,target:o}}=s,a=!!o?.value,i=a?_n(s,o.value):document.createElement("script-py");if(!a){const{head:e,body:t}=document;e.contains(s)?t.append(i):s.after(i)}i.id||(i.id=c()),ze(s,"target",{value:i}),st(s,e,"ready"),n(s,r,t["run"+(r?"Async":"")](await p(s,t.io,!0)))}else s._wrap.resolve(t);console.debug("[pyscript/main] PyScript Ready")},onWorker(e,t){Ve(t.sync,rr);for(const n of yr("onWorker"))n(e,t)},onBeforeRun(e,t){f=t,ar(yr,e,t,"onBeforeRun")},onBeforeRunAsync:(e,t)=>(f=t,ar(yr,e,t,"onBeforeRunAsync")),onAfterRun(e,t){ar(yr,e,t,"onAfterRun")},onAfterRunAsync:(e,t)=>ar(yr,e,t,"onAfterRunAsync")},worker:{...wr(gr),get onReady(){return br(this,"onReady")},get onBeforeRun(){return br(this,"onBeforeRun")},get onBeforeRunAsync(){return br(this,"onBeforeRunAsync")},get onAfterRun(){return br(this,"onAfterRun")},get onAfterRunAsync(){return br(this,"onAfterRunAsync")}}};Nr.set(e,a),Hn(e,{config:s,configURL:o,interpreter:t,hooks:a,env:`${e}-script`,version:s?.interpreter,onerror(e,t){r.set(t,e)}}),customElements.define(`${e}-script`,class extends HTMLElement{constructor(){Ve(super(),{_wrap:Promise.withResolvers(),srcCode:"",executed:!1})}get id(){return super.id||(super.id=c())}set id(e){super.id=e}async connectedCallback(){if(!this.executed){this.executed=!0;const t=this.hasAttribute("async"),{io:r,run:s,runAsync:o}=await this._wrap.promise;this.srcCode=await p(this,r,!this.childElementCount),this.replaceChildren(),this.style.display="block",st(this,e,"ready"),n(this,t,(t?o:s)(this.srcCode))}}})})),Tr[e]=structuredClone(s)}export{Dn as H,Jn as T,Bn as X,ze as a,Rr as b,Tr as c,qe as d,Ar as e,xr as f};
|
3
|
-
//# sourceMappingURL=core-14p8E60X.js.map
|