code-playpad 0.7.0 → 0.8.0
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/JAVA-COMPATIBILITY.md +12 -12
- package/README.md +49 -14
- package/dist/cdn.js +2 -2
- package/dist/dist--J_vhCIU.js +14 -0
- package/dist/{dist-B5vq9x6M.js → dist-BIgiGgKu.js} +1 -1
- package/dist/dist-BNvM_BAY.js +6 -0
- package/dist/{dist-XlpaG2JF.js → dist-BkpKCrXQ.js} +1 -1
- package/dist/{dist-BKRQwpg6.js → dist-CJxiVI4a.js} +1 -1
- package/dist/dist-D25hs99E.js +10 -0
- package/dist/dist-D2igTc4m.js +6 -0
- package/dist/{dist-CqpVTRAq.js → dist-D7jBL3Ib.js} +9 -9
- package/dist/dist-DXjodKfp.js +6 -0
- package/dist/dist-DfFrsBkU.js +8 -0
- package/dist/dist-Vr-fb58P.js +12 -0
- package/dist/{element-DaStU7U7.js → element-BTbopmDc.js} +5 -5
- package/dist/element.js +1 -1
- package/dist/{hints-v5iHTd1l.js → hints-CCMgezw9.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/java-CAuQOfuB.js +1 -0
- package/dist/{java-library-bitset.generated-Duwl7F-b.js → java-library-bitset.generated-C3m-nf8F.js} +1 -1
- package/dist/{java-library-math.generated-DmUvund7.js → java-library-math.generated-BQwpn8sQ.js} +1 -1
- package/dist/{java-library-regex.generated-a8crcad3.js → java-library-regex.generated-ItYSF2aV.js} +1 -1
- package/dist/java-library-time.generated-Dl0XA7nZ.js +6 -0
- package/dist/java-library.generated-B7ib0gOX.js +6 -0
- package/dist/java-p3d2UdsW.js +6 -0
- package/dist/{javascript-CX-lsX2u.js → javascript-BUUMtBcS.js} +4 -2
- package/dist/{javascript-CSfl5gbA.js → javascript-BgIyjzbD.js} +4 -2
- package/dist/{pyodide-Crdd9em4.js → pyodide-BCtQRDyT.js} +2 -2
- package/dist/{pyodide-CdDlM0du.js → pyodide-DKoE92s5.js} +1 -1
- package/dist/react.js +1 -1
- package/dist/runtime/java-library-bitset.generated.d.ts +2 -2
- package/dist/runtime/java-library-math.generated.d.ts +2 -2
- package/dist/runtime/java-library-regex.generated.d.ts +2 -2
- package/dist/runtime/java-library-time.generated.d.ts +3 -3
- package/dist/runtime/java-library.generated.d.ts +3 -3
- package/dist/runtime/java-worker.generated.d.ts +3 -3
- package/dist/standalone.js +5 -5
- package/dist/worker-runtime-C2AhIV7u.js +9 -0
- package/dist/worker-runtime-DJs9O_oY.js +4 -0
- package/package.json +2 -2
- package/dist/dist-BThnYaQ5.js +0 -12
- package/dist/dist-CnC1nMtN.js +0 -6
- package/dist/dist-D0FPZcUi.js +0 -8
- package/dist/dist-DOsLUKSb.js +0 -10
- package/dist/dist-D_qJovVA.js +0 -14
- package/dist/dist-DlIO0dzi.js +0 -6
- package/dist/dist-DmrP6yta.js +0 -6
- package/dist/java-DIL6bxPF.js +0 -1
- package/dist/java-DxQWnfHu.js +0 -6
- package/dist/java-library-time.generated-mFyqZ0pg.js +0 -6
- package/dist/java-library.generated-1yFV284B.js +0 -6
- package/dist/worker-runtime-C8pmmgW9.js +0 -4
- package/dist/worker-runtime-CNPpMRo1.js +0 -9
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Bundles CodeMirror 6 and Lezer (MIT) © Marijn Haverbeke and others.
|
|
4
4
|
* Full third-party licences: THIRD-PARTY-NOTICES.txt in this package.
|
|
5
5
|
*/
|
|
6
|
-
import{a as e}from"./config-D9w0xYhX.js";import{t}from"./worker-runtime-
|
|
6
|
+
import{a as e}from"./config-D9w0xYhX.js";import{t}from"./worker-runtime-C2AhIV7u.js";var n=`let currentId=null,stdinLines=[],stdinExhausted=!1,nextRequest=1,inputWaitMs=0;const pendingLines=new Map;let sucrasePromise=null,sucraseURL=null;const pendingModules=new Map;class TransformLoadError extends Error{}function requestModule(t){return new Promise((e,r)=>{pendingModules.set(t,{resolve:e,reject:r}),post({type:"module-request",id:currentId,name:t})})}function post(t){self.postMessage(t)}let functionLineOffset=0;try{new Function('throw new Error("probe")')()}catch(t){const e=/<anonymous>:(\\d+):/.exec(t.stack||"");e&&(functionLineOffset=Number(e[1])-1)}let currentFiles=[];const FLUSH_BYTES=8192,FLUSH_MS=16,EAGER_POSTS=32;let outputQueue=[],queuedChars=0,windowStart=-1/0,windowPosts=0;function writeOutput(t,e){const r=outputQueue[outputQueue.length-1];r&&r.type===t?r.text+=e:outputQueue.push({type:t,text:e}),queuedChars+=e.length;const i=performance.now();i-windowStart>=FLUSH_MS&&(windowStart=i,windowPosts=0),(windowPosts<EAGER_POSTS||queuedChars>=FLUSH_BYTES)&&flushOutput()}function flushOutput(){if(!outputQueue.length)return;windowPosts++;const t=outputQueue;outputQueue=[],queuedChars=0;for(const e of t)post({type:e.type,id:currentId,text:e.text})}function format(t,e,r){if(e=e||new Set,typeof t=="string")return r?t:JSON.stringify(t);if(typeof t=="bigint")return String(t)+"n";if(typeof t=="function")return"[Function"+(t.name?": "+t.name:"")+"]";if(typeof t=="symbol"||t==null||typeof t!="object")return String(t);if(e.has(t))return"[Circular]";e.add(t);try{if(t instanceof Error)return t.stack||t.name+": "+t.message;if(Array.isArray(t))return"[ "+t.map(n=>format(n,e)).join(", ")+" ]";if(t instanceof Map)return"Map("+t.size+") { "+[...t].map(([n,o])=>format(n,e)+" => "+format(o,e)).join(", ")+" }";if(t instanceof Set)return"Set("+t.size+") { "+[...t].map(n=>format(n,e)).join(", ")+" }";if(t instanceof Date)return t.toISOString();if(t instanceof Promise)return"Promise { \\u2026 }";const i=Object.entries(t).map(([n,o])=>n+": "+format(o,e)),a=t.constructor&&t.constructor.name;return(a&&a!=="Object"?a+" ":"")+"{ "+i.join(", ")+" }"}finally{e.delete(t)}}function formatArgs(t){return t.map(e=>format(e,null,!0)).join(" ")+\`
|
|
7
7
|
\`}const nativeConsole=self.console;self.console=Object.assign(Object.create(nativeConsole),{log:(...t)=>writeOutput("stdout",formatArgs(t)),info:(...t)=>writeOutput("stdout",formatArgs(t)),debug:(...t)=>writeOutput("stdout",formatArgs(t)),warn:(...t)=>writeOutput("stderr",formatArgs(t)),error:(...t)=>writeOutput("stderr",formatArgs(t))}),self._ppReadLine=async()=>{if(stdinLines.length){const i=stdinLines.shift();return writeOutput("echo",i+\`
|
|
8
8
|
\`),i}const t=nextRequest++;flushOutput();const e=performance.now(),r=await new Promise(i=>{pendingLines.set(t,i),post({type:"stdin-request",id:currentId,request:t})});return inputWaitMs+=performance.now()-e,typeof r!="string"&&(stdinExhausted=!0),typeof r=="string"?r:null};async function input(t){t!==void 0&&writeOutput("stdout",String(t));const e=await self._ppReadLine();if(e===null)throw new Error("EOF: no more input");return e}self.input=input;async function loadSucrase(){return sucrasePromise||(sucrasePromise=(async()=>{try{if(sucraseURL)return await import(sucraseURL);const t=await requestModule("sucrase"),e=URL.createObjectURL(new Blob([t],{type:"text/javascript"}));try{return await import(e)}finally{URL.revokeObjectURL(e)}}catch(t){const e=sucraseURL?" from "+sucraseURL:"";throw new TransformLoadError("Could not load the TypeScript transform (Sucrase)"+e+": "+(t&&t.message?t.message:String(t)))}})(),sucrasePromise.catch(()=>{sucrasePromise=null})),sucrasePromise}function isModule(t,e){return Object.keys(t).length>1?!0:/^\\s*(import|export)\\s/m.test(t[e]||"")}function needsTypeScript(t){return/\\.(ts|tsx|jsx|mts|cts)$/.test(t)}function transformsFor(t){const e=["imports"];return/\\.tsx?$|\\.mts$|\\.cts$/.test(t)&&e.push("typescript"),/\\.[jt]sx$/.test(t)&&e.push("jsx"),e}async function runAsModules(t,e){const{transform:r}=await loadSucrase(),i=new Map,a=(n,o)=>{if(!o.startsWith("."))return null;const u=((n.includes("/")?n.slice(0,n.lastIndexOf("/")+1):"")+o).split("/"),d=[];for(const p of u)p==="."||p===""||(p===".."?d.pop():d.push(p));const c=d.join("/");return[c,c+".js",c+".ts",c+".tsx",c+".jsx",c+".json",c+"/index.js",c+"/index.ts"].find(p=>p in t)||null};function s(n){if(i.has(n))return i.get(n).exports;const o={exports:{}};if(i.set(n,o),n.endsWith(".json")){try{o.exports=JSON.parse(t[n])}catch(c){throw new SyntaxError("Invalid JSON in "+n+": "+c.message)}return o.exports}const{code:f}=r(t[n],{transforms:transformsFor(n),filePath:n,preserveDynamicImport:!0}),u=c=>{const l=a(n,c);if(!l)throw new Error('Cannot find module "'+c+'" from "'+n+'"');return s(l)};return new Function("exports","require","module","__filename","input","console",f+\`
|
|
9
9
|
//# sourceURL=\`+n)(o.exports,u,o,n,input,self.console),o.exports}s(e)}async function run(t){currentId=t.id,stdinLines=t.stdin?String(t.stdin).replace(/\\n$/,"").split(\`
|
|
@@ -11,4 +11,6 @@ import{a as e}from"./config-D9w0xYhX.js";import{t}from"./worker-runtime-CNPpMRo1
|
|
|
11
11
|
//# sourceURL=\`+r;try{s=(0,eval)(o)}catch(f){if(f instanceof SyntaxError&&(/await|import/i.test(f.message)||/\\bawait\\b/.test(n))){const u=Object.getPrototypeOf(async function(){}).constructor;s=await new u("input",o)(input)}else throw f}s&&typeof s.then=="function"&&(s=await s)}flushOutput(),post({type:"result",id:t.id,value:s===void 0?void 0:format(s),durationMs:performance.now()-i-inputWaitMs})}catch(s){flushOutput();const n=s instanceof TransformLoadError;post({type:"error",id:t.id,message:n?s.message:formatError(s,a),hint:n?"This is not an error in your code: the TypeScript transform did not load. Check the connection (or anything that blocks scripts on this page), then press Run again, or reload the page if it keeps failing.":stdinExhausted&&/EOF/.test(String(s&&s.message))?"input() asked for a line that standard input did not have. Add one line per input() call in the box above, then run again.":void 0,hintAbout:stdinExhausted&&/EOF/.test(String(s&&s.message))?"stdin":void 0,durationMs:performance.now()-i-inputWaitMs})}finally{currentId=null}}function formatError(t,e){if(!(t instanceof Error))return"Uncaught "+format(t);const r=t.stack||t.name+": "+t.message,i=e?functionLineOffset:0,a=[];for(const s of r.split(\`
|
|
12
12
|
\`))!currentFiles.some(o=>s.includes(o+":"))&&/\\bat |blob:/.test(s)||a.push(i?s.replace(/([\\w./-]+):(\\d+):(\\d+)/g,(o,f,u,d)=>currentFiles.indexOf(f)===-1?o:f+":"+(Number(u)-i)+":"+d):s);return a.join(\`
|
|
13
13
|
\`).replace(/\\s+$/,"")}self.onmessage=async t=>{const e=t.data;try{if(e.type==="init")e.sucraseURL&&(sucraseURL=e.sucraseURL),post({type:"ready",version:"es2022",interactiveStdin:!0});else if(e.type==="run")await run(e);else if(e.type==="stdin-response"){const r=pendingLines.get(e.request);r&&(pendingLines.delete(e.request),r(e.text))}else if(e.type==="module"){const r=pendingModules.get(e.name);r&&(pendingModules.delete(e.name),typeof e.code=="string"?r.resolve(e.code):r.reject(new Error(e.error||"the page did not provide "+e.name)))}}catch(r){post({type:"fatal",id:e&&e.id,message:formatError(r)})}};
|
|
14
|
-
`,r=`sucrase-3.35.1.js`,i=new class extends t{id=`javascript`;get source(){return n}initPayload(){return{sucraseURL:e()}}async loadModule(e){if(e!==`sucrase`)throw Error(`no module named ${e}`);try{let{SUCRASE_SOURCE:e}=this.#e===0?await import(`./sucrase-3.35.1.js`):await import(
|
|
14
|
+
`,r=`sucrase-3.35.1.js`,i=new class extends t{id=`javascript`;get source(){return n}initPayload(){return{sucraseURL:e()}}async loadModule(e){if(e!==`sucrase`)throw Error(`no module named ${e}`);try{let{SUCRASE_SOURCE:e}=this.#e===0?await import(`./sucrase-3.35.1.js`):await import(
|
|
15
|
+
/* @vite-ignore */
|
|
16
|
+
this.#t());return e}catch(e){throw this.#e++,e}}#e=0;#t(){let e=import.meta.url;return new URL(`./`+r+`?retry=`+this.#e,e).href}get label(){return`JavaScript`}};function a(e,t,n){return{id:e,get label(){return t},get ready(){return i.ready},get interactiveStdin(){return i.interactiveStdin},async editorLanguage(){let{javascript:e}=await import(`./dist-D7jBL3Ib.js`);return e({typescript:n})},load:e=>i.load(e),run:(e,t)=>i.run(e,t),stop:e=>i.stop(e)}}var o=a(`javascript`,`JavaScript`,!1),s=a(`typescript`,`TypeScript`,!0);export{o as javascriptRuntime,s as typescriptRuntime};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as e}from"./config-D9w0xYhX.js";import{t}from"./worker-runtime-
|
|
1
|
+
import{a as e}from"./config-D9w0xYhX.js";import{t}from"./worker-runtime-DJs9O_oY.js";var n=`let currentId=null,stdinLines=[],stdinExhausted=!1,nextRequest=1,inputWaitMs=0;const pendingLines=new Map;let sucrasePromise=null,sucraseURL=null;const pendingModules=new Map;class TransformLoadError extends Error{}function requestModule(t){return new Promise((e,r)=>{pendingModules.set(t,{resolve:e,reject:r}),post({type:"module-request",id:currentId,name:t})})}function post(t){self.postMessage(t)}let functionLineOffset=0;try{new Function('throw new Error("probe")')()}catch(t){const e=/<anonymous>:(\\d+):/.exec(t.stack||"");e&&(functionLineOffset=Number(e[1])-1)}let currentFiles=[];const FLUSH_BYTES=8192,FLUSH_MS=16,EAGER_POSTS=32;let outputQueue=[],queuedChars=0,windowStart=-1/0,windowPosts=0;function writeOutput(t,e){const r=outputQueue[outputQueue.length-1];r&&r.type===t?r.text+=e:outputQueue.push({type:t,text:e}),queuedChars+=e.length;const i=performance.now();i-windowStart>=FLUSH_MS&&(windowStart=i,windowPosts=0),(windowPosts<EAGER_POSTS||queuedChars>=FLUSH_BYTES)&&flushOutput()}function flushOutput(){if(!outputQueue.length)return;windowPosts++;const t=outputQueue;outputQueue=[],queuedChars=0;for(const e of t)post({type:e.type,id:currentId,text:e.text})}function format(t,e,r){if(e=e||new Set,typeof t=="string")return r?t:JSON.stringify(t);if(typeof t=="bigint")return String(t)+"n";if(typeof t=="function")return"[Function"+(t.name?": "+t.name:"")+"]";if(typeof t=="symbol"||t==null||typeof t!="object")return String(t);if(e.has(t))return"[Circular]";e.add(t);try{if(t instanceof Error)return t.stack||t.name+": "+t.message;if(Array.isArray(t))return"[ "+t.map(n=>format(n,e)).join(", ")+" ]";if(t instanceof Map)return"Map("+t.size+") { "+[...t].map(([n,o])=>format(n,e)+" => "+format(o,e)).join(", ")+" }";if(t instanceof Set)return"Set("+t.size+") { "+[...t].map(n=>format(n,e)).join(", ")+" }";if(t instanceof Date)return t.toISOString();if(t instanceof Promise)return"Promise { \\u2026 }";const i=Object.entries(t).map(([n,o])=>n+": "+format(o,e)),a=t.constructor&&t.constructor.name;return(a&&a!=="Object"?a+" ":"")+"{ "+i.join(", ")+" }"}finally{e.delete(t)}}function formatArgs(t){return t.map(e=>format(e,null,!0)).join(" ")+\`
|
|
2
2
|
\`}const nativeConsole=self.console;self.console=Object.assign(Object.create(nativeConsole),{log:(...t)=>writeOutput("stdout",formatArgs(t)),info:(...t)=>writeOutput("stdout",formatArgs(t)),debug:(...t)=>writeOutput("stdout",formatArgs(t)),warn:(...t)=>writeOutput("stderr",formatArgs(t)),error:(...t)=>writeOutput("stderr",formatArgs(t))}),self._ppReadLine=async()=>{if(stdinLines.length){const i=stdinLines.shift();return writeOutput("echo",i+\`
|
|
3
3
|
\`),i}const t=nextRequest++;flushOutput();const e=performance.now(),r=await new Promise(i=>{pendingLines.set(t,i),post({type:"stdin-request",id:currentId,request:t})});return inputWaitMs+=performance.now()-e,typeof r!="string"&&(stdinExhausted=!0),typeof r=="string"?r:null};async function input(t){t!==void 0&&writeOutput("stdout",String(t));const e=await self._ppReadLine();if(e===null)throw new Error("EOF: no more input");return e}self.input=input;async function loadSucrase(){return sucrasePromise||(sucrasePromise=(async()=>{try{if(sucraseURL)return await import(sucraseURL);const t=await requestModule("sucrase"),e=URL.createObjectURL(new Blob([t],{type:"text/javascript"}));try{return await import(e)}finally{URL.revokeObjectURL(e)}}catch(t){const e=sucraseURL?" from "+sucraseURL:"";throw new TransformLoadError("Could not load the TypeScript transform (Sucrase)"+e+": "+(t&&t.message?t.message:String(t)))}})(),sucrasePromise.catch(()=>{sucrasePromise=null})),sucrasePromise}function isModule(t,e){return Object.keys(t).length>1?!0:/^\\s*(import|export)\\s/m.test(t[e]||"")}function needsTypeScript(t){return/\\.(ts|tsx|jsx|mts|cts)$/.test(t)}function transformsFor(t){const e=["imports"];return/\\.tsx?$|\\.mts$|\\.cts$/.test(t)&&e.push("typescript"),/\\.[jt]sx$/.test(t)&&e.push("jsx"),e}async function runAsModules(t,e){const{transform:r}=await loadSucrase(),i=new Map,a=(n,o)=>{if(!o.startsWith("."))return null;const u=((n.includes("/")?n.slice(0,n.lastIndexOf("/")+1):"")+o).split("/"),d=[];for(const p of u)p==="."||p===""||(p===".."?d.pop():d.push(p));const c=d.join("/");return[c,c+".js",c+".ts",c+".tsx",c+".jsx",c+".json",c+"/index.js",c+"/index.ts"].find(p=>p in t)||null};function s(n){if(i.has(n))return i.get(n).exports;const o={exports:{}};if(i.set(n,o),n.endsWith(".json")){try{o.exports=JSON.parse(t[n])}catch(c){throw new SyntaxError("Invalid JSON in "+n+": "+c.message)}return o.exports}const{code:f}=r(t[n],{transforms:transformsFor(n),filePath:n,preserveDynamicImport:!0}),u=c=>{const l=a(n,c);if(!l)throw new Error('Cannot find module "'+c+'" from "'+n+'"');return s(l)};return new Function("exports","require","module","__filename","input","console",f+\`
|
|
4
4
|
//# sourceURL=\`+n)(o.exports,u,o,n,input,self.console),o.exports}s(e)}async function run(t){currentId=t.id,stdinLines=t.stdin?String(t.stdin).replace(/\\n$/,"").split(\`
|
|
@@ -6,4 +6,6 @@ import{a as e}from"./config-D9w0xYhX.js";import{t}from"./worker-runtime-C8pmmgW9
|
|
|
6
6
|
//# sourceURL=\`+r;try{s=(0,eval)(o)}catch(f){if(f instanceof SyntaxError&&(/await|import/i.test(f.message)||/\\bawait\\b/.test(n))){const u=Object.getPrototypeOf(async function(){}).constructor;s=await new u("input",o)(input)}else throw f}s&&typeof s.then=="function"&&(s=await s)}flushOutput(),post({type:"result",id:t.id,value:s===void 0?void 0:format(s),durationMs:performance.now()-i-inputWaitMs})}catch(s){flushOutput();const n=s instanceof TransformLoadError;post({type:"error",id:t.id,message:n?s.message:formatError(s,a),hint:n?"This is not an error in your code: the TypeScript transform did not load. Check the connection (or anything that blocks scripts on this page), then press Run again, or reload the page if it keeps failing.":stdinExhausted&&/EOF/.test(String(s&&s.message))?"input() asked for a line that standard input did not have. Add one line per input() call in the box above, then run again.":void 0,hintAbout:stdinExhausted&&/EOF/.test(String(s&&s.message))?"stdin":void 0,durationMs:performance.now()-i-inputWaitMs})}finally{currentId=null}}function formatError(t,e){if(!(t instanceof Error))return"Uncaught "+format(t);const r=t.stack||t.name+": "+t.message,i=e?functionLineOffset:0,a=[];for(const s of r.split(\`
|
|
7
7
|
\`))!currentFiles.some(o=>s.includes(o+":"))&&/\\bat |blob:/.test(s)||a.push(i?s.replace(/([\\w./-]+):(\\d+):(\\d+)/g,(o,f,u,d)=>currentFiles.indexOf(f)===-1?o:f+":"+(Number(u)-i)+":"+d):s);return a.join(\`
|
|
8
8
|
\`).replace(/\\s+$/,"")}self.onmessage=async t=>{const e=t.data;try{if(e.type==="init")e.sucraseURL&&(sucraseURL=e.sucraseURL),post({type:"ready",version:"es2022",interactiveStdin:!0});else if(e.type==="run")await run(e);else if(e.type==="stdin-response"){const r=pendingLines.get(e.request);r&&(pendingLines.delete(e.request),r(e.text))}else if(e.type==="module"){const r=pendingModules.get(e.name);r&&(pendingModules.delete(e.name),typeof e.code=="string"?r.resolve(e.code):r.reject(new Error(e.error||"the page did not provide "+e.name)))}}catch(r){post({type:"fatal",id:e&&e.id,message:formatError(r)})}};
|
|
9
|
-
`,r=`sucrase-3.35.1.js`,i=new class extends t{id=`javascript`;get source(){return n}initPayload(){return{sucraseURL:e()}}async loadModule(e){if(e!==`sucrase`)throw Error(`no module named ${e}`);try{let{SUCRASE_SOURCE:e}=this.#e===0?await import(`./sucrase-3.35.1.js`):await import(
|
|
9
|
+
`,r=`sucrase-3.35.1.js`,i=new class extends t{id=`javascript`;get source(){return n}initPayload(){return{sucraseURL:e()}}async loadModule(e){if(e!==`sucrase`)throw Error(`no module named ${e}`);try{let{SUCRASE_SOURCE:e}=this.#e===0?await import(`./sucrase-3.35.1.js`):await import(
|
|
10
|
+
/* @vite-ignore */
|
|
11
|
+
this.#t());return e}catch(e){throw this.#e++,e}}#e=0;#t(){let e=import.meta.url;return new URL(`./`+r+`?retry=`+this.#e,e).href}get label(){return`JavaScript`}};function a(e,t,n){return{id:e,get label(){return t},get ready(){return i.ready},get interactiveStdin(){return i.interactiveStdin},async editorLanguage(){let{javascript:e}=await import(`@codemirror/lang-javascript`);return e({typescript:n})},load:e=>i.load(e),run:(e,t)=>i.run(e,t),stop:e=>i.stop(e)}}var o=a(`javascript`,`JavaScript`,!1),s=a(`typescript`,`TypeScript`,!0);export{o as javascriptRuntime,s as typescriptRuntime};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Bundles CodeMirror 6 and Lezer (MIT) © Marijn Haverbeke and others.
|
|
4
4
|
* Full third-party licences: THIRD-PARTY-NOTICES.txt in this package.
|
|
5
5
|
*/
|
|
6
|
-
import{i as e}from"./config-D9w0xYhX.js";import{t}from"./worker-runtime-
|
|
6
|
+
import{i as e}from"./config-D9w0xYhX.js";import{t}from"./worker-runtime-C2AhIV7u.js";var n=`let pyodide=null,stdinLines=[],stdinExhausted=!1,currentId=null,interactive=!1,inputWaitMs=0,nextRequest=1;const pendingLines=new Map,MOUNT="/home/pyodide/playground";let written=new Set,internals=null;const REFRESH=["import importlib, os, sys","MOUNT = "+JSON.stringify(MOUNT),"os.makedirs(MOUNT, exist_ok=True)","sys.path.insert(0, MOUNT) if MOUNT not in sys.path else None","os.chdir(MOUNT)","for _name, _mod in list(sys.modules.items()):",' _file = getattr(_mod, "__file__", None) or ""',' _paths = list(getattr(_mod, "__path__", None) or [])'," if _file.startswith(MOUNT) or any(str(p).startswith(MOUNT) for p in _paths):"," del sys.modules[_name]","importlib.invalidate_caches()"].join(\`
|
|
7
7
|
\`);function flushStreams(){try{pyodide.runPython(\`import sys
|
|
8
8
|
sys.stdout.flush()
|
|
9
9
|
sys.stderr.flush()\`,{globals:internals})}catch{}flushOutput()}const INPUT_OVERRIDE=["import builtins, sys, js","from pyodide.ffi import run_sync","",'def _pg_input(prompt=""):',' if prompt != "":'," sys.stdout.write(str(prompt))"," sys.stdout.flush()"," line = run_sync(js._pgReadLine())"," # Pyodide maps JS null to its own JsNull singleton, not None, so test"," # for what we want rather than for the several ways EOF can arrive."," if not isinstance(line, str):",' raise EOFError("EOF when reading a line")'," return line","",'_pg_input.__name__ = "input"','_pg_input.__qualname__ = "input"',"_pg_input.__doc__ = builtins.input.__doc__","builtins.input = _pg_input"].join(\`
|
|
@@ -15,4 +15,4 @@ sys.stderr.flush()\`,{globals:internals})}catch{}flushOutput()}const INPUT_OVERR
|
|
|
15
15
|
\`}return stdinExhausted=!0,null},autoEOF:!1});let s=pyodide.version;try{s=pyodide.runPython("import sys; '.'.join(str(p) for p in sys.version_info[:3])")}catch{}if(internals=pyodide.runPython("dict()"),typeof WebAssembly.Suspending=="function")try{pyodide.runPython(INPUT_OVERRIDE,{globals:internals}),interactive=!0}catch{interactive=!1}post({type:"ready",version:s,interactiveStdin:interactive})}async function run(e){let t=null;currentId=e.id,stdinLines=e.stdin?String(e.stdin).replace(/\\n$/,"").split(\`
|
|
16
16
|
\`):[],stdinExhausted=!1,inputWaitMs=0,windowStart=-1/0;for(const i of pendingLines.values())i(null);pendingLines.clear();const n=performance.now();try{e.files&&syncFiles(e.files);try{await pyodide.loadPackagesFromImports(e.code,{messageCallback:r=>post({type:"progress",id:e.id,phase:"packages",message:r}),errorCallback:()=>{}})}catch(r){post({type:"stderr",id:e.id,text:"Could not auto-install packages: "+formatError(r)+\`
|
|
17
17
|
\`})}t=pyodide.runPython('dict(__name__="__main__")'),e.entry&&t.set("__file__",e.entry);const i={globals:t};e.entry&&(i.filename=MOUNT+"/"+e.entry);const s=await pyodide.runPythonAsync(e.code,i);flushStreams();let o;if(s!=null)try{t.set("_pg_last",s),o=pyodide.runPython("repr(_pg_last)",{globals:t})}catch{o=String(s)}s&&typeof s.destroy=="function"&&s.destroy(),post({type:"result",id:e.id,value:o,durationMs:performance.now()-n-inputWaitMs})}catch(i){flushStreams();const s=formatError(i);post({type:"error",id:e.id,message:s,hint:stdinExhausted&&s.indexOf("EOFError")!==-1?"input() asked for a line that standard input did not have. Add one line per input() call in the box above, then run again.":void 0,hintAbout:stdinExhausted&&s.indexOf("EOFError")!==-1?"stdin":void 0,durationMs:performance.now()-n-inputWaitMs})}finally{if(currentId=null,t){try{t.destroy()}catch{}t=null}}}self.onmessage=async e=>{const t=e.data;try{if(t.type==="init")await boot(t.indexURL);else if(t.type==="run")await run(t);else if(t.type==="stdin-response"){const n=pendingLines.get(t.request);n&&(pendingLines.delete(t.request),n(t.text===void 0?null:t.text))}}catch(n){post({type:"fatal",id:t&&t.id,message:formatError(n)})}};
|
|
18
|
-
`,r=new class extends t{id=`python`;get source(){return n}initPayload(){return{indexURL:e()}}get label(){return this.version?`Python ${this.version.split(`.`).slice(0,2).join(`.`)}`:`Python`}async editorLanguage(){let{python:e}=await import(`./dist
|
|
18
|
+
`,r=new class extends t{id=`python`;get source(){return n}initPayload(){return{indexURL:e()}}get label(){return this.version?`Python ${this.version.split(`.`).slice(0,2).join(`.`)}`:`Python`}async editorLanguage(){let{python:e}=await import(`./dist--J_vhCIU.js`);return e()}};export{r as pythonRuntime};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{i as e}from"./config-D9w0xYhX.js";import{t}from"./worker-runtime-
|
|
1
|
+
import{i as e}from"./config-D9w0xYhX.js";import{t}from"./worker-runtime-DJs9O_oY.js";var n=`let pyodide=null,stdinLines=[],stdinExhausted=!1,currentId=null,interactive=!1,inputWaitMs=0,nextRequest=1;const pendingLines=new Map,MOUNT="/home/pyodide/playground";let written=new Set,internals=null;const REFRESH=["import importlib, os, sys","MOUNT = "+JSON.stringify(MOUNT),"os.makedirs(MOUNT, exist_ok=True)","sys.path.insert(0, MOUNT) if MOUNT not in sys.path else None","os.chdir(MOUNT)","for _name, _mod in list(sys.modules.items()):",' _file = getattr(_mod, "__file__", None) or ""',' _paths = list(getattr(_mod, "__path__", None) or [])'," if _file.startswith(MOUNT) or any(str(p).startswith(MOUNT) for p in _paths):"," del sys.modules[_name]","importlib.invalidate_caches()"].join(\`
|
|
2
2
|
\`);function flushStreams(){try{pyodide.runPython(\`import sys
|
|
3
3
|
sys.stdout.flush()
|
|
4
4
|
sys.stderr.flush()\`,{globals:internals})}catch{}flushOutput()}const INPUT_OVERRIDE=["import builtins, sys, js","from pyodide.ffi import run_sync","",'def _pg_input(prompt=""):',' if prompt != "":'," sys.stdout.write(str(prompt))"," sys.stdout.flush()"," line = run_sync(js._pgReadLine())"," # Pyodide maps JS null to its own JsNull singleton, not None, so test"," # for what we want rather than for the several ways EOF can arrive."," if not isinstance(line, str):",' raise EOFError("EOF when reading a line")'," return line","",'_pg_input.__name__ = "input"','_pg_input.__qualname__ = "input"',"_pg_input.__doc__ = builtins.input.__doc__","builtins.input = _pg_input"].join(\`
|
package/dist/react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./element-
|
|
1
|
+
import{n as e}from"./element-BTbopmDc.js";import{useEffect as t,useRef as n}from"react";import{jsx as r}from"react/jsx-runtime";e();function i({code:e=``,files:i,entry:a,stdin:o,language:s=`python`,height:c,minHeight:l,maxHeight:u,theme:d=`auto`,readOnly:f,autoRun:p,persist:m,practice:h,className:g,style:_,onReady:v,onRun:y,onOutput:b,onError:x}){let S=n(null),C=n({onReady:v,onRun:y,onOutput:b,onError:x});C.current={onReady:v,onRun:y,onOutput:b,onError:x},t(()=>{let e=S.current;if(!e)return;let t=(t,n)=>{let r=e=>n(C.current)?.(e.detail);return e.addEventListener(t,r),()=>e.removeEventListener(t,r)},n=[t(`py-ready`,e=>e.onReady),t(`py-run`,e=>e.onRun),t(`py-output`,e=>e.onOutput),t(`py-error`,e=>e.onError)];return()=>n.forEach(e=>e())},[]);let w=i?JSON.stringify(i):null;t(()=>{let t=S.current;t&&(w?t.files=JSON.parse(w):e!==t.code&&(t.code=e))},[e,w]),t(()=>{S.current&&o!==void 0&&(S.current.stdin=o)},[o]);let T=h?JSON.stringify(h):null;return t(()=>{S.current&&(S.current.practice=T?JSON.parse(T):null)},[T]),/* @__PURE__ */ r(`code-playpad`,{ref:S,language:s,theme:d,class:g,style:_,...c===void 0?{}:{height:String(c)},...l===void 0?{}:{"min-height":String(l)},...u===void 0?{}:{"max-height":String(u)},...f?{readonly:``}:{},...p?{autorun:``}:{},...m?{persist:m}:{},...a?{entry:a}:{},children:i?null:e})}export{i as CodePlayPad,i as default};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const JAVA_LIBRARY: {
|
|
2
2
|
readonly name: "java-online-compiler";
|
|
3
|
-
readonly version: "0.
|
|
4
|
-
readonly commit: "
|
|
3
|
+
readonly version: "0.39.0";
|
|
4
|
+
readonly commit: "b00eddf254edc4545e4856c2bf729adfc6d7265c";
|
|
5
5
|
readonly dirty: false;
|
|
6
6
|
readonly sha256: "059abe477f6a313ca43107e462a96571ac981a21285a2b5554dfb68af49ba82f";
|
|
7
7
|
readonly module: "java-library-bitset";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const JAVA_LIBRARY: {
|
|
2
2
|
readonly name: "java-online-compiler";
|
|
3
|
-
readonly version: "0.
|
|
4
|
-
readonly commit: "
|
|
3
|
+
readonly version: "0.39.0";
|
|
4
|
+
readonly commit: "b00eddf254edc4545e4856c2bf729adfc6d7265c";
|
|
5
5
|
readonly dirty: false;
|
|
6
6
|
readonly sha256: "de645a0e067cb410e3bc4ffbeb940bb6c0f6df45495d499c7eb5c272726daf5a";
|
|
7
7
|
readonly module: "java-library-math";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const JAVA_LIBRARY: {
|
|
2
2
|
readonly name: "java-online-compiler";
|
|
3
|
-
readonly version: "0.
|
|
4
|
-
readonly commit: "
|
|
3
|
+
readonly version: "0.39.0";
|
|
4
|
+
readonly commit: "b00eddf254edc4545e4856c2bf729adfc6d7265c";
|
|
5
5
|
readonly dirty: false;
|
|
6
6
|
readonly sha256: "0ee5814d5c14fa664c3d5e684054e83de5a6fd14824e04b3bd0f147fe0cf8223";
|
|
7
7
|
readonly module: "java-library-regex";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export declare const JAVA_LIBRARY: {
|
|
2
2
|
readonly name: "java-online-compiler";
|
|
3
|
-
readonly version: "0.
|
|
4
|
-
readonly commit: "
|
|
3
|
+
readonly version: "0.39.0";
|
|
4
|
+
readonly commit: "b00eddf254edc4545e4856c2bf729adfc6d7265c";
|
|
5
5
|
readonly dirty: false;
|
|
6
|
-
readonly sha256: "
|
|
6
|
+
readonly sha256: "db81378da281b92ac2c229427d4ab04f398a10901c00ada8812c843be6dd6928";
|
|
7
7
|
readonly module: "java-library-time";
|
|
8
8
|
};
|
|
9
9
|
export declare const JAVA_LIBRARY_SOURCE: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const JAVA_LIBRARY: {
|
|
2
2
|
readonly name: "java-online-compiler";
|
|
3
|
-
readonly version: "0.
|
|
4
|
-
readonly commit: "
|
|
3
|
+
readonly version: "0.39.0";
|
|
4
|
+
readonly commit: "b00eddf254edc4545e4856c2bf729adfc6d7265c";
|
|
5
5
|
readonly dirty: false;
|
|
6
|
-
readonly sha256: "
|
|
6
|
+
readonly sha256: "85e97402b0e1d4c48bee7150a38fd6b01113608c7f501eaff130b34a0373582a";
|
|
7
7
|
};
|
|
8
8
|
export declare const JAVA_LIBRARY_SOURCE: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const JAVA_ENGINE: {
|
|
2
2
|
readonly name: "java-online-compiler";
|
|
3
|
-
readonly version: "0.
|
|
4
|
-
readonly commit: "
|
|
3
|
+
readonly version: "0.39.0";
|
|
4
|
+
readonly commit: "b00eddf254edc4545e4856c2bf729adfc6d7265c";
|
|
5
5
|
readonly dirty: false;
|
|
6
|
-
readonly sha256: "
|
|
6
|
+
readonly sha256: "252c770562fbca0245aa38b8006e82ae61c5f0df0bd2b56506e859675788ac79";
|
|
7
7
|
};
|
|
8
8
|
export declare const JAVA_WORKER_SOURCE: string;
|
package/dist/standalone.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Bundles CodeMirror 6 and Lezer (MIT) © Marijn Haverbeke and others.
|
|
4
4
|
* Full third-party licences: THIRD-PARTY-NOTICES.txt in this package.
|
|
5
5
|
*/
|
|
6
|
-
import{n as e,r as t,t as n}from"./hints-
|
|
6
|
+
import{n as e,r as t,t as n}from"./hints-CCMgezw9.js";import{n as r,o as i,r as a,t as o}from"./config-D9w0xYhX.js";async function s(e){try{return await c(e)}catch(t){return console.warn(`[code-playpad] CodeMirror unavailable, using plain textarea:`,t),l(e)}}async function c(e){let[t,n,r,i,a,o]=await Promise.all([import(`./dist-Vr-fb58P.js`).then(e=>e.s),import(`./dist-D25hs99E.js`).then(e=>e.x),import(`./dist-D2igTc4m.js`),import(`./dist-DfFrsBkU.js`),import(`./dist-BNvM_BAY.js`),import(`./dist-DXjodKfp.js`)]),{EditorView:s,keymap:c,lineNumbers:l,highlightActiveLine:u,highlightActiveLineGutter:d,highlightSpecialChars:f,drawSelection:p,rectangularSelection:m,crosshairCursor:h}=t,{EditorState:g,Compartment:_}=n,{defaultKeymap:v,history:y,historyKeymap:b,indentWithTab:x}=r,{syntaxHighlighting:S,defaultHighlightStyle:C,indentOnInput:w,bracketMatching:T,foldGutter:E,foldKeymap:D}=i,{autocompletion:O,closeBrackets:k,closeBracketsKeymap:A,completionKeymap:j}=a,M=new _,N=new _,P=new _,F=[s.theme({"&":{color:`#1f2328`,backgroundColor:`#ffffff`},".cm-gutters":{backgroundColor:`#f6f8fa`,color:`#8b949e`,border:`none`},".cm-activeLine":{backgroundColor:`#f6f8fa88`},".cm-activeLineGutter":{backgroundColor:`#eaeef2`},".cm-cursor":{borderLeftColor:`#1f2328`},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:`#cfe3ff`}}),S(C,{fallback:!0})],I=e=>e?o.oneDark:F,L=c.of([{key:`Mod-Enter`,preventDefault:!0,run:()=>(e.onRun?.(),!0)},{key:`Shift-Enter`,preventDefault:!0,run:()=>(e.onRun?.(),!0)}]),R=e.dark,z=e.readOnly,B=e.language??[],V=t=>g.create({doc:t,extensions:[l(),d(),f(),y(),E(),p(),g.allowMultipleSelections.of(!0),w(),T(),k(),O(),m(),h(),u(),L,c.of([...A,...v,...b,...D,...j,x]),s.lineWrapping,P.of(B),M.of(I(R)),N.of(g.readOnly.of(z)),s.updateListener.of(t=>{t.docChanged&&e.onChange?.(t.state.doc.toString())})]}),H=new s({parent:e.parent,state:V(e.doc)}),U=/* @__PURE__ */ new Map,W=e.name??``;return{fallback:!1,getCode:()=>H.state.doc.toString(),setCode(e){H.dispatch({changes:{from:0,to:H.state.doc.length,insert:e}})},openFile(e,t){if(e===W)return;U.set(W,H.state);let n=U.get(e);H.setState(n??V(t)),W=e,n&&H.dispatch({effects:[M.reconfigure(I(R)),N.reconfigure(g.readOnly.of(z)),P.reconfigure(B)]})},fileCode(e,t){if(e===W)return H.state.doc.toString();let n=U.get(e);return n?n.doc.toString():t},forgetFiles(e){for(let t of[...U.keys()])e.includes(t)||U.delete(t)},setTheme(e){R=e,H.dispatch({effects:M.reconfigure(I(R))})},setReadOnly(e){z=e,H.dispatch({effects:N.reconfigure(g.readOnly.of(z))})},setLanguage(e){B=e,H.dispatch({effects:P.reconfigure(B)})},focus:()=>H.focus(),destroy:()=>H.destroy()}}function l(e){let t=document.createElement(`textarea`);t.className=`cp-fallback-editor`,t.spellcheck=!1,t.value=e.doc,t.readOnly=e.readOnly,t.addEventListener(`input`,()=>e.onChange?.(t.value)),t.addEventListener(`keydown`,t=>{(t.metaKey||t.ctrlKey)&&t.key===`Enter`&&(t.preventDefault(),e.onRun?.())}),e.parent.appendChild(t);let n=/* @__PURE__ */ new Map,r=e.name??``;return{fallback:!0,getCode:()=>t.value,setCode:e=>{t.value=e},openFile(e,i){e!==r&&(n.set(r,t.value),t.value=n.get(e)??i,r=e)},fileCode(e,i){return e===r?t.value:n.get(e)??i},forgetFiles(e){for(let t of[...n.keys()])e.includes(t)||n.delete(t)},setTheme:()=>{},setReadOnly:e=>{t.readOnly=e},setLanguage:()=>{},focus:()=>t.focus(),destroy:()=>t.remove()}}var u=/* @__PURE__ */ new Map,d=/* @__PURE__ */ new Map;function f(e,t){u.set(e,t)}function p(){return[...u.keys()]}function m(e){let t=d.get(e);if(t)return t;let n=u.get(e);if(!n)return Promise.reject(/* @__PURE__ */ Error(`Unknown runtime "${e}". Registered: ${p().join(`, `)||`none`}`));let r=n().catch(t=>{throw d.delete(e),t});return d.set(e,r),r}f(`python`,()=>import(`./pyodide-BCtQRDyT.js`).then(e=>e.pythonRuntime)),f(`javascript`,()=>import(`./javascript-BUUMtBcS.js`).then(e=>e.javascriptRuntime)),f(`typescript`,()=>import(`./javascript-BUUMtBcS.js`).then(e=>e.typescriptRuntime)),f(`java`,()=>import(`./java-p3d2UdsW.js`).then(e=>e.javaRuntime));var h=String.raw`
|
|
7
7
|
:host {
|
|
8
8
|
--cp-bg: #ffffff;
|
|
9
9
|
--cp-fg: #1f2328;
|
|
@@ -299,13 +299,13 @@ table.cp-table th { background: var(--cp-bg); }
|
|
|
299
299
|
@media (prefers-reduced-motion: reduce) {
|
|
300
300
|
.cp-progress { animation: none; background-position: 0 0; background-size: 100% 100%; opacity: 0.4; }
|
|
301
301
|
}
|
|
302
|
-
`,g=e=>()=>import(`./dist-
|
|
302
|
+
`,g=e=>()=>import(`./dist-D7jBL3Ib.js`).then(t=>t.javascript(e)),_={py:()=>import(`./dist--J_vhCIU.js`).then(e=>e.python()),pyi:()=>import(`./dist--J_vhCIU.js`).then(e=>e.python()),js:g({}),mjs:g({}),cjs:g({}),jsx:g({jsx:!0}),ts:g({typescript:!0}),mts:g({typescript:!0}),cts:g({typescript:!0}),tsx:g({typescript:!0,jsx:!0}),json:()=>import(`./dist-BkpKCrXQ.js`).then(e=>e.json()),java:()=>import(`./dist-CJxiVI4a.js`).then(e=>e.java())};async function v(e){let t=_[e.includes(`.`)?e.slice(e.lastIndexOf(`.`)+1).toLowerCase():``];return t?t().catch(()=>null):null}var y=`code-playpad`,b=1,x=`snippets`,S=`progress`,C=null;function w(){return typeof indexedDB>`u`?Promise.reject(/* @__PURE__ */ Error(`IndexedDB unavailable`)):(C||=new Promise((e,t)=>{let n=indexedDB.open(y,b);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(x)||e.createObjectStore(x),e.objectStoreNames.contains(S)||e.createObjectStore(S,{keyPath:`id`})},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}).catch(e=>{throw C=null,e}),C)}function T(e,t,n){return w().then(r=>new Promise((i,a)=>{let o=n(r.transaction(e,t).objectStore(e));o.onsuccess=()=>i(o.result),o.onerror=()=>a(o.error)}))}function E(e,t){return T(x,`readwrite`,n=>n.put(t,e)).then(()=>void 0)}function D(e){return T(x,`readonly`,t=>t.get(e)).then(e=>e??null)}function O(e){return T(x,`readwrite`,t=>t.delete(e)).then(()=>void 0)}function k(e,t={}){let n={completed:!0,...t,id:e,updatedAt:Date.now()};return T(S,`readwrite`,e=>e.put(n)).then(()=>n)}function A(e){return T(S,`readonly`,t=>t.get(e)).then(e=>e??null)}function j(){return T(S,`readonly`,e=>e.getAll())}var M=`code-playpad`;function N(e){let t=e.replace(/\t/g,` `).split(`
|
|
303
303
|
`);for(;t.length&&t[0].trim()===``;)t.shift();for(;t.length&&t[t.length-1].trim()===``;)t.pop();let n=t.filter(e=>e.trim()!==``).reduce((e,t)=>Math.min(e,t.match(/^ */)[0].length),1/0);return(n===1/0?t:t.map(e=>e.slice(n))).join(`
|
|
304
304
|
`)}var P=2e5,F=`playpad-file`,I={python:`main.py`,javascript:`main.js`,typescript:`main.ts`,java:`Main.java`};function L(e){return I[e]??`main.txt`}function R(e,t){let n={};for(let t of e.children){if(t.tagName.toLowerCase()!==F)continue;let e=t.getAttribute(`name`);e&&(n[e]=N(t.textContent??``))}if(Object.keys(n).length)return n;let r=[...e.childNodes].filter(e=>e.nodeType!==Node.ELEMENT_NODE||e.tagName.toLowerCase()!==F),i=r.some(e=>e.nodeType===Node.ELEMENT_NODE),a=N(r.filter(e=>!(i&&e.nodeType===Node.TEXT_NODE&&!(e.textContent??``).trim())).map(e=>e.textContent??``).join(``));return{[t]:a}}function z(e,t){try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t)){let e=t;return Object.keys(e).length?e:null}}catch{}return e?{[t]:e}:null}var B=typeof HTMLElement>`u`?class{}:HTMLElement,V=class extends B{static get observedAttributes(){return[`language`,`height`,`min-height`,`max-height`,`theme`,`readonly`,`autorun`,`stdin`,`persist`,`entry`,`practice`]}#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u=null;#d=null;#f=null;#p=null;#m={};#h={};#g=`main.py`;#_=null;#v;#y=!1;#b=null;#x=!1;#S=!1;#C=null;#w=null;#T=null;#E=()=>this.#X();#D=null;#O=!0;#k=[];#A=null;#j=null;#M=null;#N=0;#P=!1;#F=null;constructor(){super(),this.#e=this.attachShadow({mode:`open`})}get code(){return this.#u?this.#u.getCode():this.#m[this.#g]??``}set code(e){this.#m[this.#g]=e,this.#V()}get practice(){if(this.#F)return this.#F;let e=this.getAttribute(`practice`);if(!e)return null;try{return JSON.parse(e)}catch{return null}}set practice(e){this.#F=e}get files(){return this.#K()}set files(e){let t=Object.keys(e);if(!t.length)return;let n=Object.keys(this.#h);n.length===1&&!this.#h[n[0]]&&(this.#h={...e}),this.#m={...e},t.includes(this.#g)||(this.#g=this.#G()),this.#u?.forgetFiles([]),this.#V(),this.#q(),this.#B()}get entry(){return this.#G()}set entry(e){this.setAttribute(`entry`,e)}openFile(e){e in this.#m&&(this.#u&&(this.#m[this.#g]=this.#u.getCode(),this.#u.openFile(e,this.#m[e]??``)),this.#g=e,this.#q(),this.#B())}get stdin(){return this.#l?this.#l.value:``}set stdin(e){this.#l&&(this.#l.value=e,this.#c.hidden=!1)}get language(){return this.getAttribute(`language`)||`python`}set language(e){this.setAttribute(`language`,e)}getCode(){return this.code}getFiles(){return this.#K()}reset(){this.#m={...this.#h},this.#g=this.#G(),this.#u?.forgetFiles([]),this.#V(),this.#q(),this.#$(),this.#s.hidden=!0,this.#Q(this.#f?.ready?`${this.#f.label} ready`:``,`idle`)}async run(){if(this.#y)return;await this.#d;let t=this.#K(),r=this.getAttribute(`entry`);if(r&&!(r in t))return this.#U(r,t);this.#H=!1;let i=this.#G(),a=t[i]??``;this.#y=!0,this.#x=!1,this.#n.disabled=!0,this.#r.hidden=!1,this.#$(),this.#s.hidden=!1;let o=this.practice;this.hasAttribute(`practice`)&&!o&&this.#ee(`The practice attribute is not valid JSON.
|
|
305
305
|
`,`cp-err`),this.#oe(`py-run`,{code:a,entry:i,files:t,language:this.language,...o?{practice:o}:{}});try{let r=await this.#z();if(this.#x)throw new e;if(o&&!r.supportsPractice)throw Error(`Practice mode is not available for ${r.label}.`);this.#Q(`Queued…`,`busy`),this.#o.hidden=!1;let s=r.run(a,{stdin:this.#l.value,files:t,entry:i,onStart:()=>this.#Q(`Running…`,`busy`),onStdout:e=>this.#ee(e),onStderr:e=>this.#ee(e,`cp-err`),onEcho:e=>this.#ee(e,`cp-in`),onStdinRequest:()=>this.#ne(),...o?{practice:o}:{}});this.#b={runtime:r,run:s};let c=await s;if(c.table&&this.#ae(c.table),c.value!==void 0&&this.#ee(`${c.value}\n`,`cp-value`),c.hint&&this.#ie(c.hint,n.has(c)),c.failed=r.statusDecidesFailure?c.failed===!0:!!c.stderr,c.failed)this.#Q(`Error · ${c.durationMs} ms`,`error`),this.#oe(`py-error`,{message:c.stderr??``,hint:c.hint,language:this.language});else if(c.cases){let e=c.cases.filter(e=>e.expected!==void 0).length,t=c.passed===e;this.#Q(e?`${c.passed} of ${e} passed · ${c.durationMs} ms`:`Done in ${c.durationMs} ms`,t?`ok`:`error`)}else this.#Q(`Done in ${c.durationMs} ms`,`ok`);return this.#oe(`py-output`,{...c,language:this.language}),c}catch(t){if(t instanceof e)this.#ee(`
|
|
306
306
|
[stopped]
|
|
307
307
|
`,`cp-err`),this.#Q(`Stopped`,`error`);else{let e=t instanceof Error?t.message:String(t);this.#ee(e+`
|
|
308
|
-
`,`cp-err`),this.#Q(`Failed to start`,`error`),this.#oe(`py-error`,{message:e,language:this.language})}return}finally{this.#b=null,this.#re(null),this.#te(),this.#y=!1,this.#n.disabled=!1,this.#r.hidden=!0,this.#o.hidden=!0}}stop(){this.#b?this.#b.runtime.stop?.(this.#b.run):this.#y&&(this.#x=!0)}prewarm(){return this.#z()}connectedCallback(){
|
|
308
|
+
`,`cp-err`),this.#Q(`Failed to start`,`error`),this.#oe(`py-error`,{message:e,language:this.language})}return}finally{this.#b=null,this.#re(null),this.#te(),this.#y=!1,this.#n.disabled=!1,this.#r.hidden=!0,this.#o.hidden=!0}}stop(){this.#b?this.#b.runtime.stop?.(this.#b.run):this.#y&&(this.#x=!0)}prewarm(){return this.#z()}connectedCallback(){this.#P?this.#R():!this.textContent?.trim()&&document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>this.isConnected&&this.#I(),{once:!0}):this.#I()}disconnectedCallback(){this.#C?.disconnect(),this.#C=null,this.#w?.removeEventListener(`change`,this.#E),this.#w=null,this.#T?.disconnect(),this.#T=null,this.#D&&clearTimeout(this.#D),this.#re(null),setTimeout(()=>{!this.isConnected&&this.#u&&(this.#_=this.#K(),this.#u.destroy(),this.#u=null,this.#d=null,this.#P=!1)},0)}attributeChangedCallback(e,t,n){if(this.#P)switch(e){case`theme`:this.#X();break;case`height`:case`min-height`:case`max-height`:this.#Z();break;case`readonly`:this.#u?.setReadOnly(n!==null);break;case`stdin`:this.#c.hidden=n===null&&!this.#l.value;break;case`entry`:this.#q();break;case`language`:this.#f=null,this.#p=null,this.#S=!1,this.#z().catch(()=>{})}}#I(){this.#P=!0,this.#h=R(this,this.#W()),this.#m=this.#_??{...this.#h},this.#g=this.#G(),this.#L(),this.#X(),this.#Z();let e=this.getAttribute(`persist`);this.#d=(async()=>{if(e&&this.#_==null){let t=await D(e).catch(()=>null),n=t==null?null:z(t,this.#W());if(n){let e={},t=Object.keys(this.#h),r=Object.keys(n);for(let r of t)e[r]=n[r]??this.#h[r];t.length===1&&r.length===1&&!(t[0]in n)&&(e[t[0]]=n[r[0]]),this.#m=e,this.#g=this.#G()}}this.#q();let t=await m(this.language).catch(()=>null),n=t?await t.editorLanguage().catch(()=>null):null;this.#u=await s({parent:this.#t,doc:this.#m[this.#g]??``,name:this.#g,dark:this.#Y(),readOnly:this.hasAttribute(`readonly`),language:n,onRun:()=>void this.run(),onChange:e=>this.#J(e)}),this.#_=null,this.#B()})(),this.#R()}#L(){let e=document.createElement(`style`);e.textContent=h;let t=document.createElement(`div`);t.className=`cp-root`,t.innerHTML=`
|
|
309
309
|
<div class="cp-toolbar">
|
|
310
310
|
<button class="cp-primary" part="run-button" data-action="run">Run</button>
|
|
311
311
|
<button class="cp-danger" part="stop-button" data-action="stop" hidden>Stop</button>
|
|
@@ -321,9 +321,9 @@ table.cp-table th { background: var(--cp-bg); }
|
|
|
321
321
|
<textarea rows="2" spellcheck="false"></textarea>
|
|
322
322
|
</div>
|
|
323
323
|
<pre class="cp-output" part="output" hidden></pre>`,this.#e.replaceChildren(e,t),this.#n=t.querySelector(`[data-action="run"]`),this.#r=t.querySelector(`[data-action="stop"]`),this.#i=t.querySelector(`[data-action="reset"]`),this.#a=t.querySelector(`.cp-status`),this.#o=t.querySelector(`.cp-progress`),this.#v=t.querySelector(`.cp-tabs`),this.#t=t.querySelector(`.cp-editor`),this.#c=t.querySelector(`.cp-stdin`),this.#l=t.querySelector(`.cp-stdin textarea`),this.#s=t.querySelector(`.cp-output`),this.#c.hidden=!this.hasAttribute(`stdin`),this.#l.addEventListener(`input`,()=>this.#c.classList.remove(`cp-attention`)),this.#v.addEventListener(`click`,e=>{let t=e.target.closest(`button[data-file]`);t&&this.openFile(t.getAttribute(`data-file`))}),this.#n.addEventListener(`click`,()=>void this.run()),this.#r.addEventListener(`click`,()=>this.stop()),this.#i.addEventListener(`click`,()=>this.reset());let n=()=>void this.#z().catch(()=>{});this.#t.addEventListener(`pointerdown`,n,{once:!0}),this.#t.addEventListener(`focusin`,n,{once:!0})}#R(){this.#C||typeof IntersectionObserver>`u`||(this.#C=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(this.#C?.disconnect(),this.#C=null,this.#z().then(()=>{this.hasAttribute(`autorun`)&&this.run()}).catch(()=>{}))},{rootMargin:`300px`}),this.#C.observe(this))}#z(){return this.#p||=(async()=>{let e=await m(this.language);this.#f=e,!e.ready&&!this.#H&&(this.#o.hidden=!1,this.#Q(`Loading ${e.label}…`,`busy`));try{await e.load(e=>{!this.#y&&!this.#H&&this.#Q(e.message,e.phase===`ready`?`ok`:`busy`)})}catch(e){this.#p=null,this.#Q(`Runtime unavailable`,`error`);let t=e instanceof Error?e.message:String(e);throw this.#ee(t+`
|
|
324
|
-
`,`cp-err`),this.#s.hidden=!1,e}finally{this.#o.hidden=!0}return this.#B(),this.#S||(this.#S=!0,this.#H||this.#Q(`${e.label} ready`,`ok`),this.#oe(`py-ready`,{language:e.id,label:e.label})),e})(),this.#p}async#B(){if(!this.#u)return;let e=this.#g,t=await v(e);if(t){this.#g===e&&this.#u?.setLanguage(t);return}let n=e.includes(`.`)?null:await(this.#f??await m(this.language).catch(()=>null))?.editorLanguage().catch(()=>null);this.#g===e&&this.#u?.setLanguage(n??[])}#V(){
|
|
324
|
+
`,`cp-err`),this.#s.hidden=!1,e}finally{this.#o.hidden=!0}return this.#B(),this.#S||(this.#S=!0,this.#H||this.#Q(`${e.label} ready`,`ok`),this.#oe(`py-ready`,{language:e.id,label:e.label})),e})(),this.#p}async#B(){if(!this.#u)return;let e=this.#g,t=await v(e);if(t){this.#g===e&&this.#u?.setLanguage(t);return}let n=e.includes(`.`)?null:await(this.#f??await m(this.language).catch(()=>null))?.editorLanguage().catch(()=>null);this.#g===e&&this.#u?.setLanguage(n??[])}#V(){this.#u?this.#u.setCode(this.#m[this.#g]??``):this.#d?.then(()=>{this.#u?.setCode(this.#m[this.#g]??``),this.#q()})}#H=!1;#U(e,t){let n=Object.keys(t),r=`This widget's entry is "${e}", but it has no file of that name${n.length?` (its files: ${n.join(`, `)})`:``}. Set entry to one of its files.\n`;this.#$(),this.#s.hidden=!1,this.#ee(r,`cp-err`),this.#H=!0,this.#Q(`Error · entry not found`,`error`);let i={stdout:``,stderr:r,durationMs:0,failed:!0};return this.#oe(`py-error`,{message:r,language:this.language}),this.#oe(`py-output`,{...i,language:this.language}),i}#W(){return this.getAttribute(`entry`)||L(this.language)}#G(){let e=Object.keys(this.#m),t=this.getAttribute(`entry`);if(t&&e.includes(t))return t;let n=L(this.language);return e.includes(n)?n:e[0]??n}#K(){let e={...this.#m};if(this.#u)for(let t of Object.keys(e))e[t]=this.#u.fileCode(t,e[t]);return e}#q(){let e=Object.keys(this.#m);if(this.#v.hidden=e.length<2,this.#v.hidden){this.#v.replaceChildren();return}let t=this.#G();this.#v.replaceChildren(...e.map(e=>{let n=document.createElement(`button`);return n.dataset.file=e,n.textContent=e,n.setAttribute(`aria-pressed`,String(e===this.#g)),e===t&&(n.classList.add(`cp-entry`),n.title=`entry point — this is the file Run executes`),n}))}#J(e){this.#m[this.#g]=e;let t=this.getAttribute(`persist`);if(!t)return;this.#D&&clearTimeout(this.#D);let n=JSON.stringify(this.#K());this.#D=setTimeout(()=>void E(t,n).catch(()=>{}),400)}#Y(){let e=this.getAttribute(`theme`)??`auto`;if(e===`dark`)return!0;if(e===`light`)return!1;let t=typeof document>`u`?``:getComputedStyle(document.documentElement).colorScheme,n=t.includes(`dark`);return n===t.includes(`light`)?!!this.#w?.matches:n}#X(){!this.#w&&typeof matchMedia==`function`&&(this.#w=matchMedia(`(prefers-color-scheme: dark)`),this.#w.addEventListener(`change`,this.#E)),!this.#T&&typeof MutationObserver==`function`&&typeof document<`u`&&(this.#T=new MutationObserver(this.#E),this.#T.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`,`style`,`data-theme`,`data-color-scheme`,`color-scheme`]}));let e=this.#Y();this.setAttribute(`data-resolved-theme`,e?`dark`:`light`),this.#u?.setTheme(e)}#Z(){for(let[e,t]of[[`height`,`--cp-height`],[`min-height`,`--cp-min-height`],[`max-height`,`--cp-max-height`]]){let n=this.getAttribute(e);n===null||n===``?this.style.removeProperty(t):this.style.setProperty(t,/^\d+$/.test(n)?`${n}px`:n)}}#Q(e,t){this.#a.textContent=e,this.#a.dataset.state=t}#$(){this.#M&&clearTimeout(this.#M),this.#M=null,this.#k=[],this.#N=0,this.#s.replaceChildren(),this.#O=!0}#ee(e,t){if(!e)return;let n=t===`cp-err`&&!this.#O?`\n${e}`:e;this.#O=n.endsWith(`
|
|
325
325
|
`),this.#k.push({text:n,className:t}),this.#M??=setTimeout(()=>this.#te(),16)}#te(){if(this.#M&&clearTimeout(this.#M),this.#M=null,!this.#k.length)return;let e=this.#k;this.#k=[];let t=document.createDocumentFragment(),n=``,r,i=()=>{if(!n)return;let e=document.createElement(`span`);r&&(e.className=r),e.textContent=n,t.appendChild(e),n=``};for(let t of e){if(this.#N>=P)break;let e=t.text;this.#N+e.length>P&&(e=e.slice(0,P-this.#N)+`
|
|
326
326
|
… output truncated for display — the full text is in the playpad-output event
|
|
327
327
|
`),this.#N+=t.text.length,r!==t.className&&(i(),r=t.className),n+=e}i(),this.#s.hidden=!1;let a=this.#s.querySelector(`.cp-prompt`);a?this.#s.insertBefore(t,a):this.#s.appendChild(t),this.#s.scrollTop=this.#s.scrollHeight}#ne(){return this.#te(),this.#re(null),new Promise(e=>{let t=document.createElement(`form`);t.className=`cp-prompt`;let n=document.createElement(`input`);n.type=`text`,n.setAttribute(`aria-label`,`Program input — press Enter to send`),n.autocapitalize=`off`,n.autocomplete=`off`,n.spellcheck=!1;let r=document.createElement(`button`);r.type=`submit`,r.className=`cp-send`,r.textContent=`⏎`,r.title=`Send this line (Enter)`;let i=document.createElement(`button`);i.type=`button`,i.className=`cp-eof`,i.textContent=`EOF`,i.title=`End of input (Ctrl-D) — makes input() raise EOFError`;let a=n=>{this.#A===e&&(this.#A=null,this.#j=null,t.remove(),n===null?this.#ee(`
|
|
328
328
|
`,`cp-in`):this.#ee(n+`
|
|
329
|
-
`,`cp-in`),this.#te(),e(n))};t.addEventListener(`submit`,e=>{e.preventDefault(),a(n.value)}),i.addEventListener(`click`,()=>a(null)),n.addEventListener(`keydown`,e=>{(e.key===`Escape`||e.key===`d`&&e.ctrlKey)&&(e.preventDefault(),a(null))}),t.append(n,r,i),this.#s.hidden=!1,this.#s.appendChild(t),this.#s.scrollTop=this.#s.scrollHeight,this.#A=e,this.#j=a,n.focus({preventScroll:!0})})}#re(e){this.#j?.(e),this.#j=null,this.#A=null}#ie(e,t){this.#te();let n=document.createElement(`div`);n.className=`cp-hint`,n.textContent=e,this.#s.hidden=!1,this.#s.appendChild(n),this.#s.scrollTop=this.#s.scrollHeight,t&&(this.#c.hidden=!1,this.#c.classList.add(`cp-attention`))}#ae(e){this.#te();let t=document.createElement(`table`);t.className=`cp-table`;let n=t.createTHead().insertRow();for(let t of e.columns){let e=document.createElement(`th`);e.textContent=t,n.appendChild(e)}let r=t.createTBody();for(let t of e.rows){let e=r.insertRow();for(let n of t)e.insertCell().textContent=n==null?``:String(n)}this.#s.hidden=!1,this.#s.appendChild(t)}#oe(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`playpad-${e.slice(3)}`,{detail:t,bubbles:!0,composed:!0}))}};function H(e=M){typeof window
|
|
329
|
+
`,`cp-in`),this.#te(),e(n))};t.addEventListener(`submit`,e=>{e.preventDefault(),a(n.value)}),i.addEventListener(`click`,()=>a(null)),n.addEventListener(`keydown`,e=>{(e.key===`Escape`||e.key===`d`&&e.ctrlKey)&&(e.preventDefault(),a(null))}),t.append(n,r,i),this.#s.hidden=!1,this.#s.appendChild(t),this.#s.scrollTop=this.#s.scrollHeight,this.#A=e,this.#j=a,n.focus({preventScroll:!0})})}#re(e){this.#j?.(e),this.#j=null,this.#A=null}#ie(e,t){this.#te();let n=document.createElement(`div`);n.className=`cp-hint`,n.textContent=e,this.#s.hidden=!1,this.#s.appendChild(n),this.#s.scrollTop=this.#s.scrollHeight,t&&(this.#c.hidden=!1,this.#c.classList.add(`cp-attention`))}#ae(e){this.#te();let t=document.createElement(`table`);t.className=`cp-table`;let n=t.createTHead().insertRow();for(let t of e.columns){let e=document.createElement(`th`);e.textContent=t,n.appendChild(e)}let r=t.createTBody();for(let t of e.rows){let e=r.insertRow();for(let n of t)e.insertCell().textContent=n==null?``:String(n)}this.#s.hidden=!1,this.#s.appendChild(t)}#oe(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`playpad-${e.slice(3)}`,{detail:t,bubbles:!0,composed:!0}))}};function H(e=M){typeof window<`u`&&typeof customElements<`u`&&(customElements.get(e)||customElements.define(e,V))}H();export{V as CodePlayPadElement,o as PYODIDE_VERSION,e as RunStopped,t as WorkerUnavailable,j as allProgress,O as clearSnippet,r as configurePython,a as configureTypeScript,s as createEditor,H as defineCodePlayPad,A as getProgress,m as getRuntime,p as listRuntimes,D as loadSnippet,i as pyodideAssetUrls,f as registerRuntime,E as saveSnippet,k as setProgress};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* code-playpad — MIT © 2026 Seung Hun Lee
|
|
3
|
+
* Bundles CodeMirror 6 and Lezer (MIT) © Marijn Haverbeke and others.
|
|
4
|
+
* Full third-party licences: THIRD-PARTY-NOTICES.txt in this package.
|
|
5
|
+
*/
|
|
6
|
+
import{n as e,r as t,t as n}from"./hints-CCMgezw9.js";var r=1,i=class{#e=null;#t=null;#n=`module`;#r=null;#i=null;#a=!1;#o=!1;#s=``;#c=/* @__PURE__ */ new Set;#l=[];#u=null;#d=!1;initPayload(){return{}}loadModule(e){return Promise.reject(/* @__PURE__ */ Error(`no module named ${e}`))}get ready(){return this.#a}get interactiveStdin(){return this.#o}get version(){return this.#s}load(e){e&&this.#c.add(e);let n=()=>{e&&this.#c.delete(e)};if(!this.#r){let e=new Promise((e,n)=>{this.#i={resolve:e,reject:n};let r;try{if(typeof Worker>`u`)throw Error(`Worker constructor missing`);let e=new Blob([this.source],{type:`text/javascript`});this.#t=URL.createObjectURL(e),r=new Worker(this.#t,{type:this.#n})}catch(e){this.#i=null,n(new t(`Could not start a Web Worker: ${e.message}`));return}this.#e=r,r.onmessage=t=>{let r=t.data;r.type===`ready`?(this.#s=r.version,this.#o=r.interactiveStdin===!0,this.#a=!0,this.#i=null,this.#h({phase:`ready`,message:`${this.label} ready`}),e()):r.type===`fatal`&&!this.#a?this.#p(r.message,e,n):this.#g(r)},r.onerror=t=>{let r=t.message||`Worker failed to start`;this.#a?this.#u&&this.#y(this.#u,Error(r)):this.#p(r,e,n)},r.postMessage({type:`init`,...this.initPayload()})});this.#r=e,e.catch(()=>{this.#r===e&&(this.#r=null)})}return this.#r.then(n,e=>{throw n(),e})}run(e,t={}){let n,i,a=new Promise((e,t)=>{n=e,i=t}),o,s=new Promise(e=>{o=e}),c={id:r++,code:e,options:t,stdout:``,stderr:``,resolve:n,reject:i,promise:a,started:!1,settled:!1,done:s,markDone:()=>{c.settled=!0,o()}};return this.#l.push(c),this.#b(),a}stop(t){if(t){let n=this.#l.findIndex(e=>e.promise===t);if(n!==-1){this.#y(this.#l.splice(n,1)[0],new e);return}let r=this.#u;if(!r||r.promise!==t||r.settled)return;if(!r.started){this.#y(r,new e);return}}this.#f()}#f(){let t=this.#e!==null,n=this.#i;if(this.#m(),this.#u&&this.#y(this.#u,new e),t){let e=this.load();n&&e.then(n.resolve,n.reject),e.catch(()=>{})}}#p(e,t,n){this.#m(),this.#n===`module`?(this.#n=`classic`,this.load().then(t,n)):n(Error(e))}#m(){this.#e?.terminate(),this.#e=null,this.#t&&=(URL.revokeObjectURL(this.#t),null),this.#r=null,this.#i=null,this.#a=!1}#h(e){for(let t of this.#c)t(e)}#g(e){if(e.type===`progress`){this.#h({phase:e.phase,message:e.message});return}let t=this.#u;if(t&&`id`in e&&e.id===t.id)switch(e.type){case`stdout`:t.stdout+=e.text,t.options.onStdout?.(e.text);break;case`echo`:t.options.onEcho?.(e.text);break;case`stdin-request`:this.#v(t,e.request);break;case`module-request`:this.#_(t,e.name);break;case`stderr`:t.stderr+=e.text,t.options.onStderr?.(e.text);break;case`result`:t.resolve({stdout:t.stdout,stderr:t.stderr||void 0,value:e.value,durationMs:Math.round(e.durationMs),failed:!1,...e.cases?{cases:e.cases,passed:e.passed,total:e.total}:{}}),t.markDone();break;case`error`:case`fatal`:{let r=(t.stderr&&!t.stderr.endsWith(`
|
|
7
|
+
`)?`
|
|
8
|
+
`:``)+e.message+`
|
|
9
|
+
`;t.stderr+=r,t.options.onStderr?.(r);let i={stdout:t.stdout,stderr:t.stderr,hint:`hint`in e?e.hint:void 0,durationMs:Math.round(`durationMs`in e?e.durationMs:0),failed:!0,...`cases`in e&&e.cases?{cases:e.cases,passed:0,total:e.cases.length}:{}};`hintAbout`in e&&e.hintAbout===`stdin`&&n.add(i),t.resolve(i),t.markDone();break}}}#_(e,t){let n=this.#e,r=r=>{this.#e===n&&this.#u===e&&n?.postMessage({type:`module`,name:t,...r})};this.loadModule(t).then(e=>r({code:e}),e=>r({error:e instanceof Error?e.message:String(e)}))}#v(e,t){let n=this.#e,r=r=>{this.#e===n&&this.#u===e&&n?.postMessage({type:`stdin-response`,request:t,text:r})},i=e.options.onStdinRequest;i?i().then(r,()=>r(null)):r(null)}#y(e,t){e.reject(t),e.markDone()}async#b(){if(!this.#d){this.#d=!0;try{for(;this.#l.length;){let e=this.#l.shift();this.#u=e;try{if(await this.load(),e.settled)continue;e.started=!0,e.options.onStart?.(),this.#e.postMessage({type:`run`,id:e.id,code:e.code,stdin:e.options.stdin,files:e.options.files,entry:e.options.entry,...e.options.practice?{practice:e.options.practice}:{}}),await e.done}catch(t){this.#y(e,t)}finally{this.#u=null}}}finally{this.#d=!1}}}};export{i as t};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{d as e,l as t,u as n}from"./element-BTbopmDc.js";var r=1,i=class{#e=null;#t=null;#n=`module`;#r=null;#i=null;#a=!1;#o=!1;#s=``;#c=/* @__PURE__ */ new Set;#l=[];#u=null;#d=!1;initPayload(){return{}}loadModule(e){return Promise.reject(/* @__PURE__ */ Error(`no module named ${e}`))}get ready(){return this.#a}get interactiveStdin(){return this.#o}get version(){return this.#s}load(t){t&&this.#c.add(t);let n=()=>{t&&this.#c.delete(t)};if(!this.#r){let t=new Promise((t,n)=>{this.#i={resolve:t,reject:n};let r;try{if(typeof Worker>`u`)throw Error(`Worker constructor missing`);let e=new Blob([this.source],{type:`text/javascript`});this.#t=URL.createObjectURL(e),r=new Worker(this.#t,{type:this.#n})}catch(t){this.#i=null,n(new e(`Could not start a Web Worker: ${t.message}`));return}this.#e=r,r.onmessage=e=>{let r=e.data;r.type===`ready`?(this.#s=r.version,this.#o=r.interactiveStdin===!0,this.#a=!0,this.#i=null,this.#h({phase:`ready`,message:`${this.label} ready`}),t()):r.type===`fatal`&&!this.#a?this.#p(r.message,t,n):this.#g(r)},r.onerror=e=>{let r=e.message||`Worker failed to start`;this.#a?this.#u&&this.#y(this.#u,Error(r)):this.#p(r,t,n)},r.postMessage({type:`init`,...this.initPayload()})});this.#r=t,t.catch(()=>{this.#r===t&&(this.#r=null)})}return this.#r.then(n,e=>{throw n(),e})}run(e,t={}){let n,i,a=new Promise((e,t)=>{n=e,i=t}),o,s=new Promise(e=>{o=e}),c={id:r++,code:e,options:t,stdout:``,stderr:``,resolve:n,reject:i,promise:a,started:!1,settled:!1,done:s,markDone:()=>{c.settled=!0,o()}};return this.#l.push(c),this.#b(),a}stop(e){if(e){let t=this.#l.findIndex(t=>t.promise===e);if(t!==-1){this.#y(this.#l.splice(t,1)[0],new n);return}let r=this.#u;if(!r||r.promise!==e||r.settled)return;if(!r.started){this.#y(r,new n);return}}this.#f()}#f(){let e=this.#e!==null,t=this.#i;if(this.#m(),this.#u&&this.#y(this.#u,new n),e){let e=this.load();t&&e.then(t.resolve,t.reject),e.catch(()=>{})}}#p(e,t,n){this.#m(),this.#n===`module`?(this.#n=`classic`,this.load().then(t,n)):n(Error(e))}#m(){this.#e?.terminate(),this.#e=null,this.#t&&=(URL.revokeObjectURL(this.#t),null),this.#r=null,this.#i=null,this.#a=!1}#h(e){for(let t of this.#c)t(e)}#g(e){if(e.type===`progress`){this.#h({phase:e.phase,message:e.message});return}let n=this.#u;if(n&&`id`in e&&e.id===n.id)switch(e.type){case`stdout`:n.stdout+=e.text,n.options.onStdout?.(e.text);break;case`echo`:n.options.onEcho?.(e.text);break;case`stdin-request`:this.#v(n,e.request);break;case`module-request`:this.#_(n,e.name);break;case`stderr`:n.stderr+=e.text,n.options.onStderr?.(e.text);break;case`result`:n.resolve({stdout:n.stdout,stderr:n.stderr||void 0,value:e.value,durationMs:Math.round(e.durationMs),failed:!1,...e.cases?{cases:e.cases,passed:e.passed,total:e.total}:{}}),n.markDone();break;case`error`:case`fatal`:{let r=(n.stderr&&!n.stderr.endsWith(`
|
|
2
|
+
`)?`
|
|
3
|
+
`:``)+e.message+`
|
|
4
|
+
`;n.stderr+=r,n.options.onStderr?.(r);let i={stdout:n.stdout,stderr:n.stderr,hint:`hint`in e?e.hint:void 0,durationMs:Math.round(`durationMs`in e?e.durationMs:0),failed:!0,...`cases`in e&&e.cases?{cases:e.cases,passed:0,total:e.cases.length}:{}};`hintAbout`in e&&e.hintAbout===`stdin`&&t.add(i),n.resolve(i),n.markDone();break}}}#_(e,t){let n=this.#e,r=r=>{this.#e===n&&this.#u===e&&n?.postMessage({type:`module`,name:t,...r})};this.loadModule(t).then(e=>r({code:e}),e=>r({error:e instanceof Error?e.message:String(e)}))}#v(e,t){let n=this.#e,r=r=>{this.#e===n&&this.#u===e&&n?.postMessage({type:`stdin-response`,request:t,text:r})},i=e.options.onStdinRequest;i?i().then(r,()=>r(null)):r(null)}#y(e,t){e.reject(t),e.markDone()}async#b(){if(!this.#d){this.#d=!0;try{for(;this.#l.length;){let e=this.#l.shift();this.#u=e;try{if(await this.load(),e.settled)continue;e.started=!0,e.options.onStart?.(),this.#e.postMessage({type:`run`,id:e.id,code:e.code,stdin:e.options.stdin,files:e.options.files,entry:e.options.entry,...e.options.practice?{practice:e.options.practice}:{}}),await e.done}catch(t){this.#y(e,t)}finally{this.#u=null}}}finally{this.#d=!1}}}};export{i as t};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "code-playpad",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Embeddable browser code playground: a CodeMirror editor that runs Python, JavaScript, TypeScript and a subset of Java in the browser. No backend. One shared worker per page, blocking input(), multi-file projects, lazy per-language loading.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"react-dom": "^19.2.8",
|
|
92
92
|
"sucrase": "3.35.1",
|
|
93
93
|
"typescript": "^5.9.3",
|
|
94
|
-
"vite": "^8.
|
|
94
|
+
"vite": "^8.3.5"
|
|
95
95
|
},
|
|
96
96
|
"keywords": [
|
|
97
97
|
"playground",
|