@pyscript/core 0.3.19 → 0.3.20

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.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-6S0jIzXN.js";
1
+ export{b as PyWorker,T as TYPES,c as config,e as hooks,f as whenDefined}from"./core-_MDTi7dy.js";
2
2
  //# sourceMappingURL=core.js.map
@@ -1,2 +1,2 @@
1
- import{e}from"./core-6S0jIzXN.js";import{notify as o}from"./error-x3a_NRy9.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-QZp4vVh_.js.map
1
+ import{e}from"./core-_MDTi7dy.js";import{notify as o}from"./error-yavCjy9g.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-xSJEJMfx.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"deprecations-manager-QZp4vVh_.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
+ {"version":3,"file":"deprecations-manager-xSJEJMfx.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-6S0jIzXN.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-x3a_NRy9.js.map
1
+ import{e}from"./core-_MDTi7dy.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-yavCjy9g.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-x3a_NRy9.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
+ {"version":3,"file":"error-yavCjy9g.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-6S0jIzXN.js";let o=0;const i=e=>`${e}-editor-${o++}`,s=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:i}=this;if(e.disabled=!0,i.innerHTML="",!s.has(t)){const e=URL.createObjectURL(new Blob([""])),o=r.call(new n(null,a),e,{type:this.interpreter}),{sync:i}=o,{promise:c,resolve:l}=Promise.withResolvers();s.set(t,c),i.revoke=()=>{URL.revokeObjectURL(e),l(o)}}s.get(t).then((t=>{t.onerror=({error:e})=>{i.innerHTML+=`<span style='color:red'>${e.message||e}</span>\n`,console.error(e)};const r=()=>{e.disabled=!1},{sync:n}=t;n.write=e=>{i.innerText+=`${e}\n`},n.writeErr=e=>{i.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=`${i(e)}-output`,t})(t);return r.append(n,o),[r,o]},u=async(e,r,n)=>{const[{basicSetup:o,EditorView:s},{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=i(r)),v.hasAttribute("exec-id")||v.setAttribute("exec-id",0),v.hasAttribute("root")||v.setAttribute("root",v.id);const f=`${n}-${e.getAttribute("env")||i(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 s({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;const p=()=>{m=0,y()},y=async()=>{if(!m){m=setTimeout(p,250);for(const[t,r]of e){const e=`script[type="${t}-editor"]`;for(const n of document.querySelectorAll(e))n.type+="-active",await u(n,t,r)}}};new MutationObserver(y).observe(document,{childList:!0,subtree:!0});var v=y();export{v as default};
2
- //# sourceMappingURL=py-editor-FrqrJEvY.js.map
1
+ import{T as e,d as t,X as r,H as n}from"./core-_MDTi7dy.js";let o=0;const i=e=>`${e}-editor-${o++}`,s=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:i}=this;if(e.disabled=!0,i.innerHTML="",!s.has(t)){const e=URL.createObjectURL(new Blob([""])),o=r.call(new n(null,a),e,{type:this.interpreter}),{sync:i}=o,{promise:c,resolve:l}=Promise.withResolvers();s.set(t,c),i.revoke=()=>{URL.revokeObjectURL(e),l(o)}}s.get(t).then((t=>{t.onerror=({error:e})=>{i.innerHTML+=`<span style='color:red'>${e.message||e}</span>\n`,console.error(e)};const r=()=>{e.disabled=!1},{sync:n}=t;n.write=e=>{i.innerText+=`${e}\n`},n.writeErr=e=>{i.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=`${i(e)}-output`,t})(t);return r.append(n,o),[r,o]},u=async(e,r,n)=>{const[{basicSetup:o,EditorView:s},{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=i(r)),v.hasAttribute("exec-id")||v.setAttribute("exec-id",0),v.hasAttribute("root")||v.setAttribute("root",v.id);const f=`${n}-${e.getAttribute("env")||i(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 s({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;const p=()=>{m=0,y()},y=async()=>{if(!m){m=setTimeout(p,250);for(const[t,r]of e){const e=`script[type="${t}-editor"]`;for(const n of document.querySelectorAll(e))n.type+="-active",await u(n,t,r)}}};new MutationObserver(y).observe(document,{childList:!0,subtree:!0});var v=y();export{v as default};
2
+ //# sourceMappingURL=py-editor-9M31cFPh.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"py-editor-FrqrJEvY.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// 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\n script.type += \"-active\";\n await init(script, type, interpreter);\n }\n }\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","resetTimeout","pyEditor","setTimeout","TYPES","querySelectorAll","MutationObserver","observe","childList","subtree","pyEditor$1"],"mappings":"4DAMA,IAAIA,EAAK,EACT,MAAMC,EAASC,GAAS,GAAGA,YAAeF,MAEpCG,EAAO,IAAIC,IAEXC,EAAQ,CACVC,OAAQ,CAEJC,QAAS,EAAGC,WAAUC,OAAQC,WAC1BD,EAAGE,OAAUC,GAASF,EAAKG,MAAMD,GACjCH,EAAGK,OAAUF,GAASF,EAAKK,SAASH,GACpCF,EAAKM,SACLN,EAAKF,SAAWA,CAAQ,IAKpCS,eAAeC,GAAQC,cAAEA,IACrB,MAAMC,IAAEA,EAAGC,MAAEA,EAAKC,OAAEA,GAAWC,KAK/B,GAHAJ,EAAcK,UAAW,EACzBF,EAAOG,UAAY,IAEdtB,EAAKuB,IAAIN,GAAM,CAChB,MAAMO,EAAUC,IAAIC,gBAAgB,IAAIC,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,EAAWlC,EAAQ+E,KAAKL,IACvB1B,EAAQ5C,GAAU2C,EAAWb,EAAUlD,GAC9CgE,EAAOgC,QAAQ9E,IAAMiD,EAAOsB,aAAa,OAASvE,EAAMe,EAExD,MACMgE,EADajC,EAAOoB,cAAc,IAAIpF,wBAClBkG,aAAa,CAAEC,KAAM,SAE/CF,EAAO1E,UAAY,0CAEnB2D,EAAOkB,YAAYpC,GAEnB,MAAM6B,EAAMQ,EAAOlC,EAAOmC,aAAaC,OAGjCC,EAAc,UAAUC,KAAKZ,GAAOa,OAAOC,GAAK,OAEhDhB,EAAS,IAAItB,EAAW,CAC1BuC,WAAY,CACRpC,EAAWqC,GAAGL,IACd,IAAIlC,GAAcuC,GAAGtC,KACrBE,EAAOoC,GAAG,IACHnC,EACH,CAAEoC,IAAK,aAAcC,IAAK7D,EAAU8D,gBAAgB,GACpD,CAAEF,IAAK,YAAaC,IAAK7D,EAAU8D,gBAAgB,GACnD,CAAEF,IAAK,cAAeC,IAAK7D,EAAU8D,gBAAgB,KAEzD5C,GAEJ6B,SACAJ,QAGJF,EAAOsB,OAAO,EAIlB,IAAIC,EAAU,EAGd,MAAMC,EAAe,KACjBD,EAAU,EACVE,GAAU,EAIRA,EAAWrG,UACb,IAAImG,EAAJ,CACAA,EAAUG,WAAWF,EAAc,KACnC,IAAK,MAAOnH,EAAMiC,KAAgBqF,EAAO,CACrC,MAAMtC,EAAW,gBAAgBhF,aACjC,IAAK,MAAMmE,KAAUf,SAASmE,iBAAiBvC,GAE3Cb,EAAOnE,MAAQ,gBACTkE,EAAKC,EAAQnE,EAAMiC,EAEhC,CATmB,CASnB,EAGL,IAAIuF,iBAAiBJ,GAAUK,QAAQrE,SAAU,CAC7CsE,WAAW,EACXC,SAAS,IAIb,IAAAC,EAAeR"}
1
+ {"version":3,"file":"py-editor-9M31cFPh.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// 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\n script.type += \"-active\";\n await init(script, type, interpreter);\n }\n }\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","resetTimeout","pyEditor","setTimeout","TYPES","querySelectorAll","MutationObserver","observe","childList","subtree","pyEditor$1"],"mappings":"4DAMA,IAAIA,EAAK,EACT,MAAMC,EAASC,GAAS,GAAGA,YAAeF,MAEpCG,EAAO,IAAIC,IAEXC,EAAQ,CACVC,OAAQ,CAEJC,QAAS,EAAGC,WAAUC,OAAQC,WAC1BD,EAAGE,OAAUC,GAASF,EAAKG,MAAMD,GACjCH,EAAGK,OAAUF,GAASF,EAAKK,SAASH,GACpCF,EAAKM,SACLN,EAAKF,SAAWA,CAAQ,IAKpCS,eAAeC,GAAQC,cAAEA,IACrB,MAAMC,IAAEA,EAAGC,MAAEA,EAAKC,OAAEA,GAA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@@ -0,0 +1,2 @@
1
+ import{T as e,e as t,a as r}from"./core-_MDTi7dy.js";import{notify as n}from"./error-yavCjy9g.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-oMtvSdlI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"py-terminal-oMtvSdlI.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":"kGAKA,MAAMA,EAAW,IAAIC,EAAMC,QACtBC,KAAKC,GAAS,gBAAgBA,iBAAoBA,uBAClDC,KAAK,KAIJC,EAAkBC,IAEpB,MADAC,EAAOD,GACD,IAAIE,MAAMF,EAAQ,EAGtBG,EAAgBC,IAAYC,EAAaC,IAAIF,GAE7CG,EAAa,EAAGC,YAAcC,cAAgBA,EAE9CJ,EAAe,IAAIK,QAEzB,IAAIC,GAAW,EAKf,MAAMC,EAAc,EAAGC,cAAaC,KAAIC,QAASC,WAC7C,IAAKA,EAAKC,gBAAiB,OAG3BF,EAAI,iEAKJ,MAAMG,EAAU,IAAIC,YACpB,IAAIC,EAAO,GACX,MAAMC,EAAU,CACZC,QAAQ,EACRC,MAAMC,IACFJ,EAAOF,EAAQO,OAAOD,GACtBR,EAAKU,iBAAiBN,GACfI,EAAOG,SAGtBd,EAAYe,UAAUP,GACtBR,EAAYgB,UAAUR,GACtBR,EAAYiB,SAAS,CACjBR,QAAQ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.3.20",
4
4
  "type": "module",
5
5
  "description": "PyScript",
6
6
  "module": "./index.js",
@@ -14,31 +14,73 @@ const notifyAndThrow = (message) => {
14
14
  throw new Error(message);
15
15
  };
16
16
 
17
+ const notParsedYet = (script) => !bootstrapped.has(script);
18
+
19
+ const onceOnMain = ({ attributes: { worker } }) => !worker;
20
+
21
+ const bootstrapped = new WeakSet();
22
+
23
+ let addStyle = true;
24
+
25
+ // this callback will be serialized as string and it never needs
26
+ // to be invoked multiple times. Each xworker here is bootstrapped
27
+ // only once thanks to the `sync.is_pyterminal()` check.
28
+ const workerReady = ({ interpreter, io, run }, { sync }) => {
29
+ if (!sync.is_pyterminal()) return;
30
+
31
+ // in workers it's always safe to grab the polyscript currentScript
32
+ run("from polyscript.currentScript import terminal as __terminal__");
33
+
34
+ // This part is inevitably duplicated as external scope
35
+ // can't be reached by workers out of the box.
36
+ // The detail is that here we use sync though, not readline.
37
+ const decoder = new TextDecoder();
38
+ let data = "";
39
+ const generic = {
40
+ isatty: true,
41
+ write(buffer) {
42
+ data = decoder.decode(buffer);
43
+ sync.pyterminal_write(data);
44
+ return buffer.length;
45
+ },
46
+ };
47
+ interpreter.setStdout(generic);
48
+ interpreter.setStderr(generic);
49
+ interpreter.setStdin({
50
+ isatty: true,
51
+ stdin: () => sync.pyterminal_read(data),
52
+ });
53
+
54
+ io.stderr = (error) => {
55
+ sync.pyterminal_write(`${error.message || error}\n`);
56
+ };
57
+ };
58
+
17
59
  const pyTerminal = async () => {
18
60
  const terminals = document.querySelectorAll(SELECTOR);
19
61
 
20
- // no results will look further for runtime nodes
21
- if (!terminals.length) return;
62
+ const unknown = [].filter.call(terminals, notParsedYet);
22
63
 
23
- // if we arrived this far, let's drop the MutationObserver
24
- // as we only support one terminal per page (right now).
25
- mo.disconnect();
64
+ // no results will look further for runtime nodes
65
+ if (!unknown.length) return;
66
+ // early flag elements as known to avoid concurrent
67
+ // MutationObserver invokes of this async handler
68
+ else unknown.forEach(bootstrapped.add, bootstrapped);
26
69
 
27
70
  // we currently support only one terminal as in "classic"
28
- if (terminals.length > 1) notifyAndThrow("You can use at most 1 terminal.");
29
-
30
- const [element] = terminals;
31
- // hopefully to be removed in the near future!
32
- if (element.matches('script[type="mpy"],mpy-script'))
33
- notifyAndThrow("Unsupported terminal.");
71
+ if ([].filter.call(terminals, onceOnMain).length > 1)
72
+ notifyAndThrow("You can use at most 1 main terminal");
34
73
 
35
74
  // import styles lazily
36
- document.head.append(
37
- Object.assign(document.createElement("link"), {
38
- rel: "stylesheet",
39
- href: new URL("./xterm.css", import.meta.url),
40
- }),
41
- );
75
+ if (addStyle) {
76
+ addStyle = false;
77
+ document.head.append(
78
+ Object.assign(document.createElement("link"), {
79
+ rel: "stylesheet",
80
+ href: new URL("./xterm.css", import.meta.url),
81
+ }),
82
+ );
83
+ }
42
84
 
43
85
  // lazy load these only when a valid terminal is found
44
86
  const [{ Terminal }, { Readline }, { FitAddon }] = await Promise.all([
@@ -47,136 +89,113 @@ const pyTerminal = async () => {
47
89
  import(/* webpackIgnore: true */ "../3rd-party/xterm_addon-fit.js"),
48
90
  ]);
49
91
 
50
- const readline = new Readline();
51
-
52
- // common main thread initialization for both worker
53
- // or main case, bootstrapping the terminal on its target
54
- const init = (options) => {
55
- let target = element;
56
- const selector = element.getAttribute("target");
57
- if (selector) {
58
- target =
59
- document.getElementById(selector) ||
60
- document.querySelector(selector);
61
- if (!target) throw new Error(`Unknown target ${selector}`);
62
- } else {
63
- target = document.createElement("py-terminal");
64
- target.style.display = "block";
65
- element.after(target);
66
- }
67
- const terminal = new Terminal({
68
- theme: {
69
- background: "#191A19",
70
- foreground: "#F5F2E7",
71
- },
72
- ...options,
73
- });
74
- const fitAddon = new FitAddon();
75
- terminal.loadAddon(fitAddon);
76
- terminal.loadAddon(readline);
77
- terminal.open(target);
78
- fitAddon.fit();
79
- terminal.focus();
80
- defineProperty(element, "terminal", { value: terminal });
81
- return terminal;
82
- };
83
-
84
- // branch logic for the worker
85
- if (element.hasAttribute("worker")) {
86
- // when the remote thread onReady triggers:
87
- // setup the interpreter stdout and stderr
88
- const workerReady = ({ interpreter, io, run }, { sync }) => {
89
- // in workers it's always safe to grab the polyscript currentScript
90
- run(
91
- "from polyscript.currentScript import terminal as __terminal__",
92
- );
93
- sync.pyterminal_drop_hooks();
94
-
95
- // This part is inevitably duplicated as external scope
96
- // can't be reached by workers out of the box.
97
- // The detail is that here we use sync though, not readline.
98
- const decoder = new TextDecoder();
99
- let data = "";
100
- const generic = {
101
- isatty: true,
102
- write(buffer) {
103
- data = decoder.decode(buffer);
104
- sync.pyterminal_write(data);
105
- return buffer.length;
92
+ for (const element of unknown) {
93
+ // hopefully to be removed in the near future!
94
+ if (element.matches('script[type="mpy"],mpy-script'))
95
+ notifyAndThrow("Unsupported terminal.");
96
+
97
+ const readline = new Readline();
98
+
99
+ // common main thread initialization for both worker
100
+ // or main case, bootstrapping the terminal on its target
101
+ const init = (options) => {
102
+ let target = element;
103
+ const selector = element.getAttribute("target");
104
+ if (selector) {
105
+ target =
106
+ document.getElementById(selector) ||
107
+ document.querySelector(selector);
108
+ if (!target) throw new Error(`Unknown target ${selector}`);
109
+ } else {
110
+ target = document.createElement("py-terminal");
111
+ target.style.display = "block";
112
+ element.after(target);
113
+ }
114
+ const terminal = new Terminal({
115
+ theme: {
116
+ background: "#191A19",
117
+ foreground: "#F5F2E7",
106
118
  },
107
- };
108
- interpreter.setStdout(generic);
109
- interpreter.setStderr(generic);
110
- interpreter.setStdin({
111
- isatty: true,
112
- stdin: () => sync.pyterminal_read(data),
119
+ ...options,
113
120
  });
114
-
115
- io.stderr = (error) => {
116
- sync.pyterminal_write(`${error.message || error}\n`);
117
- };
121
+ const fitAddon = new FitAddon();
122
+ terminal.loadAddon(fitAddon);
123
+ terminal.loadAddon(readline);
124
+ terminal.open(target);
125
+ fitAddon.fit();
126
+ terminal.focus();
127
+ defineProperty(element, "terminal", { value: terminal });
128
+ return terminal;
118
129
  };
119
130
 
120
- // add a hook on the main thread to setup all sync helpers
121
- // also bootstrapping the XTerm target on main
122
- hooks.main.onWorker.add(function worker(_, xworker) {
123
- hooks.main.onWorker.delete(worker);
124
- init({
125
- disableStdin: false,
126
- cursorBlink: true,
127
- cursorStyle: "block",
128
- });
129
- xworker.sync.pyterminal_read = readline.read.bind(readline);
130
- xworker.sync.pyterminal_write = readline.write.bind(readline);
131
- // allow a worker to drop main thread hooks ASAP
132
- xworker.sync.pyterminal_drop_hooks = () => {
133
- hooks.worker.onReady.delete(workerReady);
134
- };
135
- });
136
-
137
- // setup remote thread JS/Python code for whenever the
138
- // worker is ready to become a terminal
139
- hooks.worker.onReady.add(workerReady);
140
- } else {
141
- // in the main case, just bootstrap XTerm without
142
- // allowing any input as that's not possible / awkward
143
- hooks.main.onReady.add(function main({ interpreter, io, run }) {
144
- console.warn("py-terminal is read only on main thread");
145
- hooks.main.onReady.delete(main);
146
-
147
- // on main, it's easy to trash and clean the current terminal
148
- globalThis.__py_terminal__ = init({
149
- disableStdin: true,
150
- cursorBlink: false,
151
- cursorStyle: "underline",
152
- });
153
- run("from js import __py_terminal__ as __terminal__");
154
- delete globalThis.__py_terminal__;
155
-
156
- // This part is inevitably duplicated as external scope
157
- // can't be reached by workers out of the box.
158
- // The detail is that here we use readline here, not sync.
159
- const decoder = new TextDecoder();
160
- let data = "";
161
- const generic = {
162
- isatty: true,
163
- write(buffer) {
164
- data = decoder.decode(buffer);
165
- readline.write(data);
166
- return buffer.length;
167
- },
168
- };
169
- interpreter.setStdout(generic);
170
- interpreter.setStderr(generic);
171
- interpreter.setStdin({
172
- isatty: true,
173
- stdin: () => readline.read(data),
131
+ // branch logic for the worker
132
+ if (element.hasAttribute("worker")) {
133
+ // add a hook on the main thread to setup all sync helpers
134
+ // also bootstrapping the XTerm target on main *BUT* ...
135
+ hooks.main.onWorker.add(function worker(_, xworker) {
136
+ // ... as multiple workers will add multiple callbacks
137
+ // be sure no xworker is ever initialized twice!
138
+ if (bootstrapped.has(xworker)) return;
139
+ bootstrapped.add(xworker);
140
+
141
+ // still cleanup this callback for future scripts/workers
142
+ hooks.main.onWorker.delete(worker);
143
+
144
+ init({
145
+ disableStdin: false,
146
+ cursorBlink: true,
147
+ cursorStyle: "block",
148
+ });
149
+
150
+ xworker.sync.is_pyterminal = () => true;
151
+ xworker.sync.pyterminal_read = readline.read.bind(readline);
152
+ xworker.sync.pyterminal_write = readline.write.bind(readline);
174
153
  });
175
154
 
176
- io.stderr = (error) => {
177
- readline.write(`${error.message || error}\n`);
178
- };
179
- });
155
+ // setup remote thread JS/Python code for whenever the
156
+ // worker is ready to become a terminal
157
+ hooks.worker.onReady.add(workerReady);
158
+ } else {
159
+ // in the main case, just bootstrap XTerm without
160
+ // allowing any input as that's not possible / awkward
161
+ hooks.main.onReady.add(function main({ interpreter, io, run }) {
162
+ console.warn("py-terminal is read only on main thread");
163
+ hooks.main.onReady.delete(main);
164
+
165
+ // on main, it's easy to trash and clean the current terminal
166
+ globalThis.__py_terminal__ = init({
167
+ disableStdin: true,
168
+ cursorBlink: false,
169
+ cursorStyle: "underline",
170
+ });
171
+ run("from js import __py_terminal__ as __terminal__");
172
+ delete globalThis.__py_terminal__;
173
+
174
+ // This part is inevitably duplicated as external scope
175
+ // can't be reached by workers out of the box.
176
+ // The detail is that here we use readline here, not sync.
177
+ const decoder = new TextDecoder();
178
+ let data = "";
179
+ const generic = {
180
+ isatty: true,
181
+ write(buffer) {
182
+ data = decoder.decode(buffer);
183
+ readline.write(data);
184
+ return buffer.length;
185
+ },
186
+ };
187
+ interpreter.setStdout(generic);
188
+ interpreter.setStderr(generic);
189
+ interpreter.setStdin({
190
+ isatty: true,
191
+ stdin: () => readline.read(data),
192
+ });
193
+
194
+ io.stderr = (error) => {
195
+ readline.write(`${error.message || error}\n`);
196
+ };
197
+ });
198
+ }
180
199
  }
181
200
  };
182
201
 
package/src/sync.js CHANGED
@@ -1,4 +1,7 @@
1
1
  export default {
2
+ // allow pyterminal checks to bootstrap
3
+ is_pyterminal: () => false,
4
+
2
5
  /**
3
6
  * 'Sleep' for the given number of seconds. Used to implement Python's time.sleep in Worker threads.
4
7
  * @param {number} seconds The number of seconds to sleep.
package/types/sync.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  declare namespace _default {
2
+ function is_pyterminal(): boolean;
2
3
  /**
3
4
  * 'Sleep' for the given number of seconds. Used to implement Python's time.sleep in Worker threads.
4
5
  * @param {number} seconds The number of seconds to sleep.
@@ -1,2 +0,0 @@
1
- import{T as e,e as t,a as r}from"./core-6S0jIzXN.js";import{notify as n}from"./error-x3a_NRy9.js";const o=[...e.keys()].map((e=>`script[type="${e}"][terminal],${e}-script[terminal]`)).join(","),i=e=>{throw n(e),new Error(e)},a=async()=>{const e=document.querySelectorAll(o);if(!e.length)return;s.disconnect(),e.length>1&&i("You can use at most 1 terminal.");const[n]=e;n.matches('script[type="mpy"],mpy-script')&&i("Unsupported terminal."),document.head.append(Object.assign(document.createElement("link"),{rel:"stylesheet",href:new URL("./xterm.css",import.meta.url)}));const[{Terminal:a},{Readline:d},{FitAddon:l}]=await Promise.all([import("./xterm-f2QfYNGL.js"),import("./xterm-readline-ONk85xtH.js"),import("./xterm_addon-fit-E4yMPZTX.js")]),m=new d,c=e=>{let t=n;const o=n.getAttribute("target");if(o){if(t=document.getElementById(o)||document.querySelector(o),!t)throw new Error(`Unknown target ${o}`)}else t=document.createElement("py-terminal"),t.style.display="block",n.after(t);const i=new a({theme:{background:"#191A19",foreground:"#F5F2E7"},...e}),s=new l;return i.loadAddon(s),i.loadAddon(m),i.open(t),s.fit(),i.focus(),r(n,"terminal",{value:i}),i};if(n.hasAttribute("worker")){const e=({interpreter:e,io:t,run:r},{sync:n})=>{r("from polyscript.currentScript import terminal as __terminal__"),n.pyterminal_drop_hooks();const o=new TextDecoder;let i="";const a={isatty:!0,write:e=>(i=o.decode(e),n.pyterminal_write(i),e.length)};e.setStdout(a),e.setStderr(a),e.setStdin({isatty:!0,stdin:()=>n.pyterminal_read(i)}),t.stderr=e=>{n.pyterminal_write(`${e.message||e}\n`)}};t.main.onWorker.add((function r(n,o){t.main.onWorker.delete(r),c({disableStdin:!1,cursorBlink:!0,cursorStyle:"block"}),o.sync.pyterminal_read=m.read.bind(m),o.sync.pyterminal_write=m.write.bind(m),o.sync.pyterminal_drop_hooks=()=>{t.worker.onReady.delete(e)}})),t.worker.onReady.add(e)}else t.main.onReady.add((function e({interpreter:r,io:n,run:o}){console.warn("py-terminal is read only on main thread"),t.main.onReady.delete(e),globalThis.__py_terminal__=c({disableStdin:!0,cursorBlink:!1,cursorStyle:"underline"}),o("from js import __py_terminal__ as __terminal__"),delete globalThis.__py_terminal__;const i=new TextDecoder;let a="";const s={isatty:!0,write:e=>(a=i.decode(e),m.write(a),e.length)};r.setStdout(s),r.setStderr(s),r.setStdin({isatty:!0,stdin:()=>m.read(a)}),n.stderr=e=>{m.write(`${e.message||e}\n`)}}))},s=new MutationObserver(a);s.observe(document,{childList:!0,subtree:!0});var d=a();export{d as default};
2
- //# sourceMappingURL=py-terminal-241Fp4HZ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"py-terminal-241Fp4HZ.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 pyTerminal = async () => {\n const terminals = document.querySelectorAll(SELECTOR);\n\n // no results will look further for runtime nodes\n if (!terminals.length) return;\n\n // if we arrived this far, let's drop the MutationObserver\n // as we only support one terminal per page (right now).\n mo.disconnect();\n\n // we currently support only one terminal as in \"classic\"\n if (terminals.length > 1) notifyAndThrow(\"You can use at most 1 terminal.\");\n\n const [element] = terminals;\n // hopefully to be removed in the near future!\n if (element.matches('script[type=\"mpy\"],mpy-script'))\n notifyAndThrow(\"Unsupported terminal.\");\n\n // import styles lazily\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 // 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 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 // when the remote thread onReady triggers:\n // setup the interpreter stdout and stderr\n const workerReady = ({ interpreter, io, run }, { sync }) => {\n // in workers it's always safe to grab the polyscript currentScript\n run(\n \"from polyscript.currentScript import terminal as __terminal__\",\n );\n sync.pyterminal_drop_hooks();\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\n // add a hook on the main thread to setup all sync helpers\n // also bootstrapping the XTerm target on main\n hooks.main.onWorker.add(function worker(_, xworker) {\n hooks.main.onWorker.delete(worker);\n init({\n disableStdin: false,\n cursorBlink: true,\n cursorStyle: \"block\",\n });\n xworker.sync.pyterminal_read = readline.read.bind(readline);\n xworker.sync.pyterminal_write = readline.write.bind(readline);\n // allow a worker to drop main thread hooks ASAP\n xworker.sync.pyterminal_drop_hooks = () => {\n hooks.worker.onReady.delete(workerReady);\n };\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\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","pyTerminal","async","terminals","document","querySelectorAll","length","mo","disconnect","element","matches","head","append","Object","assign","createElement","rel","href","URL","url","Terminal","Readline","FitAddon","Promise","all","import","readline","init","options","target","selector","getAttribute","getElementById","querySelector","style","display","after","terminal","theme","background","foreground","fitAddon","loadAddon","open","fit","focus","defineProperty","value","hasAttribute","workerReady","interpreter","io","run","sync","pyterminal_drop_hooks","decoder","TextDecoder","data","generic","isatty","write","buffer","decode","pyterminal_write","setStdout","setStderr","setStdin","stdin","pyterminal_read","stderr","error","hooks","main","onWorker","add","worker","_","xworker","delete","disableStdin","cursorBlink","cursorStyle","read","bind","onReady","console","warn","globalThis","__py_terminal__","MutationObserver","observe","childList","subtree","pyTerminal$1"],"mappings":"kGAKA,MAAMA,EAAW,IAAIC,EAAMC,QACtBC,KAAKC,GAAS,gBAAgBA,iBAAoBA,uBAClDC,KAAK,KAIJC,EAAkBC,IAEpB,MADAC,EAAOD,GACD,IAAIE,MAAMF,EAAQ,EAGtBG,EAAaC,UACf,MAAMC,EAAYC,SAASC,iBAAiBd,GAG5C,IAAKY,EAAUG,OAAQ,OAIvBC,EAAGC,aAGCL,EAAUG,OAAS,GAAGT,EAAe,mCAEzC,MAAOY,GAAWN,EAEdM,EAAQC,QAAQ,kCAChBb,EAAe,yBAGnBO,SAASO,KAAKC,OACVC,OAAOC,OAAOV,SAASW,cAAc,QAAS,CAC1CC,IAAK,aACLC,KAAM,IAAIC,IAAI,0BAA2BC,QAKjD,OAAOC,SAAEA,IAAYC,SAAEA,IAAYC,SAAEA,UAAoBC,QAAQC,IAAI,CACjEC,OAAiC,uBACjCA,OAAiC,gCACjCA,OAAiC,mCAG/BC,EAAW,IAAIL,EAIfM,EAAQC,IACV,IAAIC,EAASpB,EACb,MAAMqB,EAAWrB,EAAQsB,aAAa,UACtC,GAAID,GAIA,GAHAD,EACIzB,SAAS4B,eAAeF,IACxB1B,SAAS6B,cAAcH,IACtBD,EAAQ,MAAM,IAAI7B,MAAM,kBAAkB8B,UAE/CD,EAASz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