@pyscript/core 0.4.5 → 0.4.6
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/{codemirror-Bc1Y52-3.js → codemirror-Bt1qaGaC.js} +2 -2
- package/dist/{codemirror-Bc1Y52-3.js.map → codemirror-Bt1qaGaC.js.map} +1 -1
- package/dist/{codemirror_commands-DpfBW1Yg.js → codemirror_commands-CQhRq29F.js} +2 -2
- package/dist/{codemirror_commands-DpfBW1Yg.js.map → codemirror_commands-CQhRq29F.js.map} +1 -1
- package/dist/{codemirror_lang-python-r06KelLU.js → codemirror_lang-python-Be_ZrPIi.js} +2 -2
- package/dist/{codemirror_lang-python-r06KelLU.js.map → codemirror_lang-python-Be_ZrPIi.js.map} +1 -1
- package/dist/{codemirror_language-en2b9geg.js → codemirror_language-15oJ2_xe.js} +2 -2
- package/dist/{codemirror_language-en2b9geg.js.map → codemirror_language-15oJ2_xe.js.map} +1 -1
- package/dist/{codemirror_state-BCMMU3_u.js → codemirror_state-BKbyfKsm.js} +2 -2
- package/dist/{codemirror_state-BCMMU3_u.js.map → codemirror_state-BKbyfKsm.js.map} +1 -1
- package/dist/codemirror_view-ZYshhfdH.js +2 -0
- package/dist/codemirror_view-ZYshhfdH.js.map +1 -0
- package/dist/core-D-4vWlgD.js +3 -0
- package/dist/core-D-4vWlgD.js.map +1 -0
- package/dist/core.js +1 -1
- package/dist/{deprecations-manager-160Yh7XB.js → deprecations-manager-DiDuet8A.js} +2 -2
- package/dist/{deprecations-manager-160Yh7XB.js.map → deprecations-manager-DiDuet8A.js.map} +1 -1
- package/dist/{error-C4n1bJ-b.js → error-BppXsD3P.js} +2 -2
- package/dist/{error-C4n1bJ-b.js.map → error-BppXsD3P.js.map} +1 -1
- package/dist/{index-B1rGWcUY.js → index-DvAsRi-_.js} +2 -2
- package/dist/{index-B1rGWcUY.js.map → index-DvAsRi-_.js.map} +1 -1
- package/dist/py-editor-BAF4-6sB.js +2 -0
- package/dist/py-editor-BAF4-6sB.js.map +1 -0
- package/dist/{py-terminal-CWQX4oMb.js → py-terminal-ZUucIGA-.js} +2 -2
- package/dist/{py-terminal-CWQX4oMb.js.map → py-terminal-ZUucIGA-.js.map} +1 -1
- package/dist/toml-DiUM0_qs.js +3 -0
- package/dist/toml-DiUM0_qs.js.map +1 -0
- package/dist/xterm_addon-fit--gyF3PcZ.js.map +1 -1
- package/package.json +9 -9
- package/src/3rd-party/xterm_addon-fit.js +1 -1
- package/src/plugins/py-editor.js +36 -21
- package/dist/codemirror_view-L6gkqEE1.js +0 -2
- package/dist/codemirror_view-L6gkqEE1.js.map +0 -1
- package/dist/core-CHxEUdn6.js +0 -3
- package/dist/core-CHxEUdn6.js.map +0 -1
- package/dist/py-editor-BhXwimJa.js +0 -2
- package/dist/py-editor-BhXwimJa.js.map +0 -1
@@ -0,0 +1,2 @@
|
|
1
|
+
import{T as e,d as t,X as r,H as n}from"./core-D-4vWlgD.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,c=!!e;if(c&&(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})=>{c&&(s.innerHTML+=`<span style='color:red'>${e.message||e}</span>\n`),console.error(e)};const r=()=>{c&&(e.disabled=!1)},{sync:n}=t;n.write=e=>{c&&(s.innerText+=`${e}\n`)},n.writeErr=e=>{c&&(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},u=(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]},d=async(e,r,n)=>{const[{basicSetup:o,EditorView:i},{Compartment:a},{python:l},{indentUnit:d},{keymap:m},{defaultKeymap:p}]=await Promise.all([import("./codemirror-Bt1qaGaC.js"),import("./codemirror_state-BKbyfKsm.js"),import("./codemirror_lang-python-Be_ZrPIi.js"),import("./codemirror_language-15oJ2_xe.js").then((function(e){return e.x})),import("./codemirror_view-ZYshhfdH.js").then((function(e){return e.q})),import("./codemirror_commands-CQhRq29F.js")]),v=e.hasAttribute("setup"),y=`${n}-${e.getAttribute("env")||s(r)}`,h=e.src?await fetch(e.src).then((e=>e.text())):e.textContent,f={interpreter:n,env:y,get pySrc(){return v?h:C.state.doc.toString()},get outDiv(){return v?null:$}};if(v)return void c.call(f,{currentTarget:null});const g=e.getAttribute("target");let b;if(g){if(b=document.getElementById(g)||document.querySelector(g),!b)throw new Error(`Unknown target ${g}`)}else b=document.createElement(`${r}-editor`),b.style.display="block",e.after(b);b.id||(b.id=s(r)),b.hasAttribute("exec-id")||b.setAttribute("exec-id",0),b.hasAttribute("root")||b.setAttribute("root",b.id);const w=c.bind(f),[E,$]=u(w,r);E.dataset.env=e.hasAttribute("env")?y:n;const x=E.querySelector(`.${r}-editor-input > div`).attachShadow({mode:"open"});x.innerHTML="<style> :host { all: initial; }</style>",b.appendChild(E);const A=t(e.textContent).trim(),L=/^(\s+)/m.test(A)?RegExp.$1:" ",C=new i({extensions:[d.of(L),(new a).of(l()),m.of([...p,{key:"Ctrl-Enter",run:w,preventDefault:!0},{key:"Cmd-Enter",run:w,preventDefault:!0},{key:"Shift-Enter",run:w,preventDefault:!0}]),o],parent:x,doc:A});C.focus()};let m=0,p=Promise.resolve();const v=()=>{m=0,y()},y=async()=>{if(!m){m=setTimeout(v,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((()=>d(n,t,r)))}return p}};new MutationObserver(y).observe(document,{childList:!0,subtree:!0});var h=y();export{h as default};
|
2
|
+
//# sourceMappingURL=py-editor-BAF4-6sB.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"py-editor-BAF4-6sB.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 const hasRunButton = !!currentTarget;\n\n if (hasRunButton) {\n currentTarget.disabled = true;\n outDiv.innerHTML = \"\";\n }\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 if (hasRunButton) {\n outDiv.innerHTML += `<span style='color:red'>${\n error.message || error\n }</span>\\n`;\n }\n console.error(error);\n };\n\n const enable = () => {\n if (hasRunButton) currentTarget.disabled = false;\n };\n const { sync } = xworker;\n sync.write = (str) => {\n if (hasRunButton) outDiv.innerText += `${str}\\n`;\n };\n sync.writeErr = (str) => {\n if (hasRunButton) {\n outDiv.innerHTML += `<span style='color:red'>${str}</span>\\n`;\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 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 isSetup = script.hasAttribute(\"setup\");\n const env = `${interpreter}-${script.getAttribute(\"env\") || getID(type)}`;\n const source = script.src\n ? await fetch(script.src).then((b) => b.text())\n : script.textContent;\n const context = {\n interpreter,\n env,\n get pySrc() {\n return isSetup ? source : editor.state.doc.toString();\n },\n get outDiv() {\n return isSetup ? null : outDiv;\n },\n };\n\n if (isSetup) {\n execute.call(context, { currentTarget: null });\n return;\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 // @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","hasRunButton","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","isSetup","hasAttribute","getAttribute","source","src","fetch","b","text","textContent","context","editor","state","doc","toString","selector","target","getElementById","querySelector","Error","style","display","after","bind","dataset","parent","attachShadow","mode","appendChild","dedent","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":"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,OA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UI,WAAWF,EAAc,KACnC,IAAK,MAAO3H,EAAMkC,KAAgB4F,EAAO,CACrC,MAAM/B,EAAW,gBAAgB/F,aACjC,IAAK,MAAMoE,KAAUf,SAAS0E,iBAAiBhC,GAE3C3B,EAAOpE,MAAQ,UAGf0H,EAAQA,EAAMhF,MAAK,IAAMyB,EAAKC,EAAQpE,EAAMkC,IAEnD,CACD,OAAOwF,CAZa,CAYR,EAGhB,IAAIM,iBAAiBJ,GAAUK,QAAQ5E,SAAU,CAC7C6E,WAAW,EACXC,SAAS,IAIb,IAAAC,EAAeR"}
|
@@ -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-D-4vWlgD.js";import{notify as n}from"./error-BppXsD3P.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-DqawCVsv.js"),import("./xterm-readline-D247p8vq.js"),import("./xterm_addon-fit--gyF3PcZ.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-ZUucIGA-.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"py-terminal-CWQX4oMb.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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QO,OAAOD,GACtBsC,EAASvC,MAAMH,GACRI,EAAOG,SAGtBd,EAAYe,UAAUP,GACtBR,EAAYgB,UAAUR,GACtBR,EAAYiB,SAAS,CACjBR,QAAQ,EACRS,MAAO,IAAM+B,EAASgC,KAAK1E,KAG/BN,EAAGmB,OAAUC,IACT4B,EAASvC,MAAM,GAAGW,EAAMlC,SAAWkC,MAAU,CAEjE,GAEK,GAGM,IAAImE,iBAAiBlE,GAC7BmE,QAAQhE,SAAU,CAAEiE,WAAW,EAAMC,SAAS,IAGjD,IAAAC,EAAetE"}
|
1
|
+
{"version":3,"file":"py-terminal-ZUucIGA-.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,EACRS,MAAO,IAAMf,EAAKgB,gBAAgBZ,KAGtCN,EAAGmB,OAAUC,IACTlB,EAAKU,iBAAiB,GAAGQ,EAAMlC,SAAWkC,MAAU,CACvD,EAG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][r.slice(1)]:r)),p=(r,t,p,l)=>{for(let n=0,{length:a}=r,c=a-1;n<a;n++){const a=s(r[n],t);p=p[a]||(p[a]=l&&n===c?[]:{}),e(p)&&(n!==c&&p.length||p.push({}),p=p.at(-1))}return p},l=e=>{const[r,l]=((e,r,s)=>[e.replace(/(["'])(?:(?=(\\?))\2.)*?\1/g,(e=>`"s${r.push(e.slice(1,-1))-1}"`)).replace(/\d{2,}([:-]\d{2}){2}([ T:-][\dZ:-]+)?/g,(e=>`"d${s.push(new Date(e))-1}"`)).replace(/,\s*[\r\n]+/g,", ").replace(/\[\s*[\r\n]+/g,"[").replace(/[\r\n]+\s*]/g,"]"),{s:r,d:s}])(e,[],[]),n={};let a=n;for(let e of r.split(/[\r\n]+/))if((e=e.trim())&&!e.startsWith("#"))if(/^(\[+)(.*?)\]+/.test(e))a=p(RegExp.$2.trim().split("."),l,n,"["!==RegExp.$1);else if(/^(\S+?)\s*=([^#]+)/.test(e)){const{$1:e,$2:r}=RegExp;a[s(e,l)]=t(r.trim(),l)}return n};export{l as parse};
|
3
|
+
//# sourceMappingURL=toml-DiUM0_qs.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"toml-DiUM0_qs.js","sources":["../node_modules/polyscript/esm/3rd-party/toml.js"],"sourcesContent":["/* c8 ignore start */\n/*! (c) Andrea Giammarchi - ISC */\n\nconst {isArray} = Array;\nconst {parse: jsonParse} = JSON;\n\n/** @typedef {{s: string[], d: Date[]}} Foreign foreign strings and dates */\n\n/**\n * Transform quoted keys into regular keys.\n * @param {string} str the key to eventually normalize\n * @param {Foreign} foreign foreign strings and dates\n * @returns \n */\nconst getKey = (str, {s}) => str.replace(/\"s(\\d+)\"/g, (_, $1) => s[$1]);\n\n/**\n * Given a `'string'` or a `\"string\"` returns a JSON compatible string.\n * @param {string} str a TOML entry to parse\n * @param {Foreign} foreign foreign strings and dates\n * @returns {string}\n */\nconst getValue = (str, foreign) => jsonParse(\n str.replace(/(\\S+?)\\s*=/g, '\"$1\":'),\n (_, value) => typeof value === 'string' ?\n foreign[value[0]][value.slice(1)] :\n value\n);\n\n/**\n * Crawl the `json` object via the given array of keys and handle array entries.\n * @param {string[]} keys a path with all keys to reach the entry\n * @param {Foreign} foreign foreign strings and dates\n * @param {object} entry the root entry of the TOML\n * @param {boolean} asArray handle array entries\n * @returns {object} the current entry to handle\n */\nconst getPath = (keys, foreign, entry, asArray) => {\n for (let i = 0, {length} = keys, last = length - 1; i < length; i++) {\n const key = getKey(keys[i], foreign);\n entry = entry[key] || (entry[key] = (asArray && (i === last) ? [] : {}));\n if (isArray(entry)) {\n if ((i === last) || !entry.length)\n entry.push({});\n entry = entry.at(-1);\n }\n }\n return entry;\n};\n\n/**\n * Given a TOML text, removes stirngs and dates for easier parsing +\n * remove multi-line arrays to not need evaluation.\n * @param {string} toml the TOML text to map\n * @param {string[]} strings mapped strings\n * @param {Date[]} dates mapped Dates\n * @returns {[string, Foreign]}\n */\nconst mapForeign = (toml, strings, dates) => [\n toml\n // map strings in the TOML\n .replace(\n /([\"'])(?:(?=(\\\\?))\\2.)*?\\1/g,\n value => `\"s${strings.push(value.slice(1, -1)) - 1}\"`\n )\n // map dates in the TOML\n .replace(\n /\\d{2,}([:-]\\d{2}){2}([ T:-][\\dZ:-]+)?/g,\n value => `\"d${dates.push(new Date(value)) - 1}\"`\n )\n // avoid multi-line array entries\n .replace(/,\\s*[\\r\\n]+/g, ', ')\n .replace(/\\[\\s*[\\r\\n]+/g, '[')\n .replace(/[\\r\\n]+\\s*]/g, ']'),\n {s: strings, d: dates}\n];\n\n/**\n * Given a simple subset of a TOML file, returns its JS equivalent.\n * @param {string} toml the TOML text to parse\n * @returns {object} the TOML equivalent as JSON serializable\n */\nconst parse = toml => {\n const [text, foreign] = mapForeign(toml, [], []);\n const json = {};\n let entry = json;\n for (let line of text.split(/[\\r\\n]+/)) {\n if ((line = line.trim()) && !line.startsWith('#')) {\n if (/^(\\[+)(.*?)\\]+/.test(line))\n entry = getPath(RegExp.$2.trim().split('.'), foreign, json, RegExp.$1 !== '[');\n else if (/^(\\S+?)\\s*=([^#]+)/.test(line)) {\n const {$1: key, $2: value} = RegExp;\n entry[getKey(key, foreign)] = getValue(value.trim(), foreign);\n }\n }\n }\n return json;\n};\n\nexport { parse };\n\n/* c8 ignore stop */\n"],"names":["isArray","Array","parse","jsonParse","JSON","getKey","str","s","replace","_","$1","getValue","foreign","value","slice","getPath","keys","entry","asArray","i","length","last","key","push","at","toml","text","strings","dates","Date","d","mapForeign","json","line","split","trim","startsWith","test","RegExp","$2"],"mappings":";AAGA,MAAMA,QAACA,GAAWC,OACXC,MAAOC,GAAaC,KAUrBC,EAAS,CAACC,GAAMC,OAAOD,EAAIE,QAAQ,aAAa,CAACC,EAAGC,IAAOH,EAAEG,KAQ7DC,EAAW,CAACL,EAAKM,IAAYT,EACjCG,EAAIE,QAAQ,cAAe,UAC3B,CAACC,EAAGI,IAA2B,iBAAVA,EACnBD,EAAQC,EAAM,IAAIA,EAAMC,MAAM,IAC9BD,IAWEE,EAAU,CAACC,EAAMJ,EAASK,EAAOC,KACrC,IAAK,IAAIC,EAAI,GAAGC,OAACA,GAAUJ,EAAMK,EAAOD,EAAS,EAAGD,EAAIC,EAAQD,IAAK,CACnE,MAAMG,EAAMjB,EAAOW,EAAKG,GAAIP,GAC5BK,EAAQA,EAAMK,KAASL,EAAMK,GAAQJ,GAAYC,IAAME,EAAQ,GAAK,CAAA,GAChErB,EAAQiB,KACLE,IAAME,GAAUJ,EAAMG,QACzBH,EAAMM,KAAK,CAAA,GACbN,EAAQA,EAAMO,IAAI,GAErB,CACD,OAAOP,CAAK,EAmCRf,EAAQuB,IACZ,MAAOC,EAAMd,GAzBI,EAACa,EAAME,EAASC,IAAU,CAC3CH,EAEGjB,QACC,+BACAK,GAAS,KAAKc,EAAQJ,KAAKV,EAAMC,MAAM,GAAI,IAAM,OAGlDN,QACC,0CACAK,GAAS,KAAKe,EAAML,KAAK,IAAIM,KAAKhB,IAAU,OAG7CL,QAAQ,eAAgB,MACxBA,QAAQ,gBAAiB,KACzBA,QAAQ,eAAgB,KAC3B,CAACD,EAAGoB,EAASG,EAAGF,IASQG,CAAWN,EAAM,GAAI,IACvCO,EAAO,CAAA,EACb,IAAIf,EAAQe,EACZ,IAAK,IAAIC,KAAQP,EAAKQ,MAAM,WAC1B,IAAKD,EAAOA,EAAKE,UAAYF,EAAKG,WAAW,KAC3C,GAAI,iBAAiBC,KAAKJ,GACxBhB,EAAQF,EAAQuB,OAAOC,GAAGJ,OAAOD,MAAM,KAAMtB,EAASoB,EAAoB,MAAdM,OAAO5B,SAChE,GAAI,qBAAqB2B,KAAKJ,GAAO,CACxC,MAAOvB,GAAIY,EAAKiB,GAAI1B,GAASyB,OAC7BrB,EAAMZ,EAAOiB,EAAKV,IAAYD,EAASE,EAAMsB,OAAQvB,EACtD,CAGL,OAAOoB,CAAI","x_google_ignoreList":[0]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"xterm_addon-fit--gyF3PcZ.js","sources":["../src/3rd-party/xterm_addon-fit.js"],"sourcesContent":["/**\n * Bundled by jsDelivr using Rollup v2.79.1 and Terser v5.19.2.\n * Original file: /npm/@xterm/addon-fit@0.9.0
|
1
|
+
{"version":3,"file":"xterm_addon-fit--gyF3PcZ.js","sources":["../src/3rd-party/xterm_addon-fit.js"],"sourcesContent":["/**\n * Bundled by jsDelivr using Rollup v2.79.1 and Terser v5.19.2.\n * Original file: /npm/@xterm/addon-fit@0.9.0/lib/addon-fit.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\nvar e,t,r={exports:{}};self;var s=r.exports=(e=t={},Object.defineProperty(e,\"__esModule\",{value:!0}),e.FitAddon=void 0,e.FitAddon=class{activate(e){this._terminal=e}dispose(){}fit(){const e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;const t=this._terminal._core;this._terminal.rows===e.rows&&this._terminal.cols===e.cols||(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal)return;if(!this._terminal.element||!this._terminal.element.parentElement)return;const e=this._terminal._core,t=e._renderService.dimensions;if(0===t.css.cell.width||0===t.css.cell.height)return;const r=0===this._terminal.options.scrollback?0:e.viewport.scrollBarWidth,s=window.getComputedStyle(this._terminal.element.parentElement),i=parseInt(s.getPropertyValue(\"height\")),o=Math.max(0,parseInt(s.getPropertyValue(\"width\"))),n=window.getComputedStyle(this._terminal.element),l=i-(parseInt(n.getPropertyValue(\"padding-top\"))+parseInt(n.getPropertyValue(\"padding-bottom\"))),a=o-(parseInt(n.getPropertyValue(\"padding-right\"))+parseInt(n.getPropertyValue(\"padding-left\")))-r;return{cols:Math.max(2,Math.floor(a/t.css.cell.width)),rows:Math.max(1,Math.floor(l/t.css.cell.height))}}},t),i=r.exports.FitAddon,o=r.exports.__esModule;export{i as FitAddon,o as __esModule,s as default};\n"],"names":["e","t","r","exports","s","Object","defineProperty","value","FitAddon","activate","this","_terminal","dispose","fit","proposeDimensions","isNaN","cols","rows","_core","_renderService","clear","resize","element","parentElement","dimensions","css","cell","width","height","options","scrollback","viewport","scrollBarWidth","window","getComputedStyle","i","parseInt","getPropertyValue","o","Math","max","n","l","a","floor","__esModule"],"mappings":"AAMA,IAAIA,EAAEC,EAAEC,EAAE,CAACC,QAAQ,CAAE,GAAWC,EAAEF,EAAEC,SAASH,EAAEC,EAAE,CAAA,EAAGI,OAAOC,eAAeN,EAAE,aAAa,CAACO,OAAM,IAAKP,EAAEQ,cAAS,EAAOR,EAAEQ,SAAS,MAAM,QAAAC,CAAST,GAAGU,KAAKC,UAAUX,CAAC,CAAC,OAAAY,IAAW,GAAAC,GAAM,MAAMb,EAAEU,KAAKI,oBAAoB,IAAId,IAAIU,KAAKC,WAAWI,MAAMf,EAAEgB,OAAOD,MAAMf,EAAEiB,MAAM,OAAO,MAAMhB,EAAES,KAAKC,UAAUO,MAAMR,KAAKC,UAA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
"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.
|
45
|
+
"polyscript": "^0.11.0",
|
46
46
|
"sticky-module": "^0.1.1",
|
47
47
|
"to-json-callback": "^0.1.1",
|
48
48
|
"type-checked-collections": "^0.1.7"
|
@@ -51,22 +51,22 @@
|
|
51
51
|
"@codemirror/commands": "^6.3.3",
|
52
52
|
"@codemirror/lang-python": "^6.1.4",
|
53
53
|
"@codemirror/language": "^6.10.1",
|
54
|
-
"@codemirror/state": "^6.4.
|
55
|
-
"@codemirror/view": "^6.
|
56
|
-
"@playwright/test": "^1.
|
54
|
+
"@codemirror/state": "^6.4.1",
|
55
|
+
"@codemirror/view": "^6.25.1",
|
56
|
+
"@playwright/test": "^1.42.1",
|
57
57
|
"@rollup/plugin-commonjs": "^25.0.7",
|
58
58
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
59
59
|
"@rollup/plugin-terser": "^0.4.4",
|
60
60
|
"@webreflection/toml-j0.4": "^1.1.3",
|
61
|
-
"@xterm/addon-fit": "^0.9.0
|
61
|
+
"@xterm/addon-fit": "^0.9.0",
|
62
62
|
"chokidar": "^3.6.0",
|
63
63
|
"codemirror": "^6.0.1",
|
64
|
-
"eslint": "^8.
|
65
|
-
"rollup": "^4.
|
64
|
+
"eslint": "^8.57.0",
|
65
|
+
"rollup": "^4.13.0",
|
66
66
|
"rollup-plugin-postcss": "^4.0.2",
|
67
67
|
"rollup-plugin-string": "^3.0.0",
|
68
68
|
"static-handler": "^0.4.3",
|
69
|
-
"typescript": "^5.
|
69
|
+
"typescript": "^5.4.2",
|
70
70
|
"xterm": "^5.3.0",
|
71
71
|
"xterm-readline": "^1.1.1"
|
72
72
|
},
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/**
|
2
2
|
* Bundled by jsDelivr using Rollup v2.79.1 and Terser v5.19.2.
|
3
|
-
* Original file: /npm/@xterm/addon-fit@0.9.0
|
3
|
+
* Original file: /npm/@xterm/addon-fit@0.9.0/lib/addon-fit.js
|
4
4
|
*
|
5
5
|
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
6
6
|
*/
|
package/src/plugins/py-editor.js
CHANGED
@@ -23,9 +23,12 @@ const hooks = {
|
|
23
23
|
|
24
24
|
async function execute({ currentTarget }) {
|
25
25
|
const { env, pySrc, outDiv } = this;
|
26
|
+
const hasRunButton = !!currentTarget;
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
if (hasRunButton) {
|
29
|
+
currentTarget.disabled = true;
|
30
|
+
outDiv.innerHTML = "";
|
31
|
+
}
|
29
32
|
|
30
33
|
if (!envs.has(env)) {
|
31
34
|
const srcLink = URL.createObjectURL(new Blob([""]));
|
@@ -46,21 +49,25 @@ async function execute({ currentTarget }) {
|
|
46
49
|
// before executing the current code
|
47
50
|
envs.get(env).then((xworker) => {
|
48
51
|
xworker.onerror = ({ error }) => {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
+
if (hasRunButton) {
|
53
|
+
outDiv.innerHTML += `<span style='color:red'>${
|
54
|
+
error.message || error
|
55
|
+
}</span>\n`;
|
56
|
+
}
|
52
57
|
console.error(error);
|
53
58
|
};
|
54
59
|
|
55
60
|
const enable = () => {
|
56
|
-
currentTarget.disabled = false;
|
61
|
+
if (hasRunButton) currentTarget.disabled = false;
|
57
62
|
};
|
58
63
|
const { sync } = xworker;
|
59
64
|
sync.write = (str) => {
|
60
|
-
outDiv.innerText += `${str}\n`;
|
65
|
+
if (hasRunButton) outDiv.innerText += `${str}\n`;
|
61
66
|
};
|
62
67
|
sync.writeErr = (str) => {
|
63
|
-
|
68
|
+
if (hasRunButton) {
|
69
|
+
outDiv.innerHTML += `<span style='color:red'>${str}</span>\n`;
|
70
|
+
}
|
64
71
|
};
|
65
72
|
sync.runAsync(pySrc).then(enable, enable);
|
66
73
|
});
|
@@ -120,7 +127,6 @@ const init = async (script, type, interpreter) => {
|
|
120
127
|
{ keymap },
|
121
128
|
{ defaultKeymap },
|
122
129
|
] = await Promise.all([
|
123
|
-
// TODO: find a way to actually produce these bundles locally
|
124
130
|
import(/* webpackIgnore: true */ "../3rd-party/codemirror.js"),
|
125
131
|
import(/* webpackIgnore: true */ "../3rd-party/codemirror_state.js"),
|
126
132
|
import(
|
@@ -131,6 +137,27 @@ const init = async (script, type, interpreter) => {
|
|
131
137
|
import(/* webpackIgnore: true */ "../3rd-party/codemirror_commands.js"),
|
132
138
|
]);
|
133
139
|
|
140
|
+
const isSetup = script.hasAttribute("setup");
|
141
|
+
const env = `${interpreter}-${script.getAttribute("env") || getID(type)}`;
|
142
|
+
const source = script.src
|
143
|
+
? await fetch(script.src).then((b) => b.text())
|
144
|
+
: script.textContent;
|
145
|
+
const context = {
|
146
|
+
interpreter,
|
147
|
+
env,
|
148
|
+
get pySrc() {
|
149
|
+
return isSetup ? source : editor.state.doc.toString();
|
150
|
+
},
|
151
|
+
get outDiv() {
|
152
|
+
return isSetup ? null : outDiv;
|
153
|
+
},
|
154
|
+
};
|
155
|
+
|
156
|
+
if (isSetup) {
|
157
|
+
execute.call(context, { currentTarget: null });
|
158
|
+
return;
|
159
|
+
}
|
160
|
+
|
134
161
|
const selector = script.getAttribute("target");
|
135
162
|
|
136
163
|
let target;
|
@@ -149,18 +176,6 @@ const init = async (script, type, interpreter) => {
|
|
149
176
|
if (!target.hasAttribute("exec-id")) target.setAttribute("exec-id", 0);
|
150
177
|
if (!target.hasAttribute("root")) target.setAttribute("root", target.id);
|
151
178
|
|
152
|
-
const env = `${interpreter}-${script.getAttribute("env") || getID(type)}`;
|
153
|
-
const context = {
|
154
|
-
interpreter,
|
155
|
-
env,
|
156
|
-
get pySrc() {
|
157
|
-
return editor.state.doc.toString();
|
158
|
-
},
|
159
|
-
get outDiv() {
|
160
|
-
return outDiv;
|
161
|
-
},
|
162
|
-
};
|
163
|
-
|
164
179
|
// @see https://github.com/JeffersGlass/mkdocs-pyscript/blob/main/mkdocs_pyscript/js/makeblocks.js
|
165
180
|
const listener = execute.bind(context);
|
166
181
|
const [boxDiv, outDiv] = makeBoxDiv(listener, type);
|