code-playpad 0.7.0 → 0.9.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.
Files changed (72) hide show
  1. package/JAVA-COMPATIBILITY.md +12 -12
  2. package/README.md +104 -14
  3. package/dist/COMPILER-LICENSE-AUDIT.md +104 -0
  4. package/dist/COMPILER-NOTICES.txt +16973 -0
  5. package/dist/THIRD-PARTY-NOTICES.txt +102 -0
  6. package/dist/cdn.js +2 -2
  7. package/dist/compiler-license-manifest.json +198 -0
  8. package/dist/{config-D9w0xYhX.js → config-cwuPIQ48.js} +1 -1
  9. package/dist/cpp-D2TrExLz.js +1 -0
  10. package/dist/cpp-DakNa4ys.js +6 -0
  11. package/dist/dist--J_vhCIU.js +14 -0
  12. package/dist/{dist-B5vq9x6M.js → dist-BIgiGgKu.js} +1 -1
  13. package/dist/dist-BNvM_BAY.js +6 -0
  14. package/dist/{dist-XlpaG2JF.js → dist-BkpKCrXQ.js} +1 -1
  15. package/dist/{dist-BKRQwpg6.js → dist-CJxiVI4a.js} +1 -1
  16. package/dist/dist-CNOK8CHE.js +6 -0
  17. package/dist/dist-D25hs99E.js +10 -0
  18. package/dist/dist-D2igTc4m.js +6 -0
  19. package/dist/{dist-CqpVTRAq.js → dist-D7jBL3Ib.js} +9 -9
  20. package/dist/dist-DXjodKfp.js +6 -0
  21. package/dist/dist-DfFrsBkU.js +8 -0
  22. package/dist/dist-Vr-fb58P.js +12 -0
  23. package/dist/{element-DaStU7U7.js → element-BQWrbSEp.js} +7 -7
  24. package/dist/element.js +1 -1
  25. package/dist/{hints-v5iHTd1l.js → hints-CCMgezw9.js} +1 -1
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +1 -1
  28. package/dist/java-DeBiVPXO.js +6 -0
  29. package/dist/java-Xf1xYcVv.js +1 -0
  30. package/dist/{java-library-bitset.generated-Duwl7F-b.js → java-library-bitset.generated-C3m-nf8F.js} +1 -1
  31. package/dist/{java-library-math.generated-DmUvund7.js → java-library-math.generated-BQwpn8sQ.js} +1 -1
  32. package/dist/{java-library-regex.generated-a8crcad3.js → java-library-regex.generated-ItYSF2aV.js} +1 -1
  33. package/dist/java-library-time.generated-Dl0XA7nZ.js +6 -0
  34. package/dist/java-library.generated-B7ib0gOX.js +6 -0
  35. package/dist/{javascript-CSfl5gbA.js → javascript-CTY3U1Mc.js} +4 -2
  36. package/dist/{javascript-CX-lsX2u.js → javascript-DkarEcEB.js} +4 -2
  37. package/dist/{pyodide-Crdd9em4.js → pyodide-B1U3JD9Z.js} +2 -2
  38. package/dist/{pyodide-CdDlM0du.js → pyodide-BGBI232i.js} +1 -1
  39. package/dist/react.js +1 -1
  40. package/dist/runtime/compiler-assets.d.ts +5 -0
  41. package/dist/runtime/compiler-cache.d.ts +9 -0
  42. package/dist/runtime/config.d.ts +11 -0
  43. package/dist/runtime/cpp/assets.d.ts +6 -0
  44. package/dist/runtime/cpp/project.d.ts +9 -0
  45. package/dist/runtime/cpp/worker.d.ts +1 -0
  46. package/dist/runtime/cpp-worker.generated.d.ts +1 -0
  47. package/dist/runtime/cpp.d.ts +3 -0
  48. package/dist/runtime/java-library-bitset.generated.d.ts +2 -2
  49. package/dist/runtime/java-library-math.generated.d.ts +2 -2
  50. package/dist/runtime/java-library-regex.generated.d.ts +2 -2
  51. package/dist/runtime/java-library-time.generated.d.ts +3 -3
  52. package/dist/runtime/java-library.generated.d.ts +3 -3
  53. package/dist/runtime/java-worker.generated.d.ts +3 -3
  54. package/dist/runtime/worker-runtime.d.ts +1 -0
  55. package/dist/standalone.js +9 -9
  56. package/dist/types.d.ts +13 -1
  57. package/dist/worker-runtime-DfYet3xy.js +9 -0
  58. package/dist/worker-runtime-Dq71SbjR.js +4 -0
  59. package/package.json +18 -6
  60. package/dist/dist-BThnYaQ5.js +0 -12
  61. package/dist/dist-CnC1nMtN.js +0 -6
  62. package/dist/dist-D0FPZcUi.js +0 -8
  63. package/dist/dist-DOsLUKSb.js +0 -10
  64. package/dist/dist-D_qJovVA.js +0 -14
  65. package/dist/dist-DlIO0dzi.js +0 -6
  66. package/dist/dist-DmrP6yta.js +0 -6
  67. package/dist/java-DIL6bxPF.js +0 -1
  68. package/dist/java-DxQWnfHu.js +0 -6
  69. package/dist/java-library-time.generated-mFyqZ0pg.js +0 -6
  70. package/dist/java-library.generated-1yFV284B.js +0 -6
  71. package/dist/worker-runtime-C8pmmgW9.js +0 -4
  72. package/dist/worker-runtime-CNPpMRo1.js +0 -9
@@ -1,4 +1,4 @@
1
- import{a as e}from"./config-D9w0xYhX.js";import{t}from"./worker-runtime-C8pmmgW9.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(" ")+\`
1
+ import{s as e}from"./config-cwuPIQ48.js";import{t}from"./worker-runtime-Dq71SbjR.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(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};
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{a as e}from"./config-D9w0xYhX.js";import{t}from"./worker-runtime-CNPpMRo1.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(" ")+\`
6
+ import{s as e}from"./config-cwuPIQ48.js";import{t}from"./worker-runtime-DfYet3xy.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(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-CqpVTRAq.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};
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};
@@ -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-CNPpMRo1.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(\`
6
+ import{o as e}from"./config-cwuPIQ48.js";import{t}from"./worker-runtime-DfYet3xy.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-D_qJovVA.js`);return e()}};export{r as pythonRuntime};
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-C8pmmgW9.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(\`
1
+ import{o as e}from"./config-cwuPIQ48.js";import{t}from"./worker-runtime-Dq71SbjR.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-DaStU7U7.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]),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
+ import{n as e}from"./element-BQWrbSEp.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};
@@ -0,0 +1,5 @@
1
+ /** Verified downloads for the C/C++ compiler worker. */
2
+ export declare function compilerAsset(name: string, spec: {
3
+ bytes: number;
4
+ sha256: string;
5
+ }, baseURL: string, cacheName: string, report: (message: string) => void): Promise<ArrayBuffer>;
@@ -0,0 +1,9 @@
1
+ /** Shared names keep the page and its disposable compiler workers in one cache. */
2
+ export declare const CPP_CACHE = "code-playpad-cpp-20.1.2-emscripten-4.0.6-r1";
3
+ /**
4
+ * Open from the page before a compiler worker uses Cache Storage. In WebKit,
5
+ * worker-only caches can become inaccessible when that worker is terminated.
6
+ * Keep the page's Cache handle alive across Stop/restart; workers still perform
7
+ * all byte reads, integrity checks and writes. This does not download assets.
8
+ */
9
+ export declare function prepareCompilerCache(name: string): Promise<void>;
@@ -30,3 +30,14 @@ export declare function pyodideAssetUrls(): {
30
30
  url: string;
31
31
  as: 'script' | 'fetch';
32
32
  }[];
33
+ /** External immutable compiler assets, loaded on the first C/C++ Run only. */
34
+ declare let cppConfig: {
35
+ indexURL?: string;
36
+ timeoutMs: number;
37
+ };
38
+ export declare function configureCpp(options: {
39
+ indexURL?: string;
40
+ timeoutMs?: number;
41
+ }): void;
42
+ export declare function getCppConfig(): Readonly<typeof cppConfig>;
43
+ export {};
@@ -0,0 +1,6 @@
1
+ /** Audited local rebuild; see toolchains/cpp/inputs.lock.json and assets.lock.json. */
2
+ export declare const CPP_TOOLCHAIN_VERSION = "code-playpad Clang 20.1.2 / Emscripten 4.0.6 r1";
3
+ export declare const CPP_ASSETS: Record<string, {
4
+ bytes: number;
5
+ sha256: string;
6
+ }>;
@@ -0,0 +1,9 @@
1
+ import type { Files } from '../../types.js';
2
+ export declare function projectPath(name: string): string;
3
+ export declare function cppProject(code: string, files: Files | undefined, entry: string | undefined, language: 'c' | 'cpp'): {
4
+ files: {
5
+ [x: string]: string;
6
+ };
7
+ sources: string[];
8
+ entry: string;
9
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const CPP_WORKER_SOURCE = "\"use strict\";(()=>{var it=\"code-playpad-cpp-20.1.2-emscripten-4.0.6-r1\";async function ot(a,e,i,c,E){let t=new URL(a,i).href,r;try{r=await caches.open(c)}catch{}let n;try{n=await r?.match(t)}catch{}let s=async _=>{if(!_.ok)throw new Error(`Toolchain download failed: ${a} (HTTP ${_.status}). Check the asset URL and retry.`);let l=_.body?.getReader();if(!l)return _.arrayBuffer();let u=[],p=0,d=0;for(;;){let S=await l.read();if(S.done)break;if(p+=S.value.length,p>e.bytes)throw await l.cancel(),new Error(`Unexpected toolchain size: ${a}.`);u.push(S.value),performance.now()-d>100&&(E(`${n?\"Reading cached\":\"Downloading\"} ${a}: ${(p/1e6).toFixed(1)} / ${(e.bytes/1e6).toFixed(1)} MB (decoded)`),d=performance.now())}let R=new Uint8Array(p),h=0;for(let S of u)R.set(S,h),h+=S.length;return R.buffer},o=async _=>_.byteLength===e.bytes&&[...new Uint8Array(await crypto.subtle.digest(\"SHA-256\",_))].map(l=>l.toString(16).padStart(2,\"0\")).join(\"\")===e.sha256;if(n){try{let _=await s(n);if(await o(_))return _}catch{}try{await r?.delete(t)}catch{}n=void 0}let f=await s(await fetch(t));if(!await o(f))throw new Error(`Toolchain integrity check failed: ${a}. Use the pinned toolchain assets.`);try{await r?.put(t,new Response(f))}catch{}return f}var C=class a{static read_bytes(e,i){let c=new a;return c.buf=e.getUint32(i,!0),c.buf_len=e.getUint32(i+4,!0),c}static read_bytes_array(e,i,c){let E=[];for(let t=0;t<c;t++)E.push(a.read_bytes(e,i+8*t));return E}},L=class a{static read_bytes(e,i){let c=new a;return c.buf=e.getUint32(i,!0),c.buf_len=e.getUint32(i+4,!0),c}static read_bytes_array(e,i,c){let E=[];for(let t=0;t<c;t++)E.push(a.read_bytes(e,i+8*t));return E}},Q=0,Z=1,V=2;var J=2;var W=4;var q=1;var x=class{write_bytes(e,i){e.setUint8(i,this.fs_filetype),e.setUint16(i+2,this.fs_flags,!0),e.setBigUint64(i+8,this.fs_rights_base,!0),e.setBigUint64(i+16,this.fs_rights_inherited,!0)}constructor(e,i){this.fs_rights_base=0n,this.fs_rights_inherited=0n,this.fs_filetype=e,this.fs_flags=i}};var j=8,A=class{write_bytes(e,i){e.setBigUint64(i,this.dev,!0),e.setBigUint64(i+8,this.ino,!0),e.setUint8(i+16,this.filetype),e.setBigUint64(i+24,this.nlink,!0),e.setBigUint64(i+32,this.size,!0),e.setBigUint64(i+38,this.atim,!0),e.setBigUint64(i+46,this.mtim,!0),e.setBigUint64(i+52,this.ctim,!0)}constructor(e,i,c){this.dev=0n,this.nlink=0n,this.atim=0n,this.mtim=0n,this.ctim=0n,this.ino=e,this.filetype=i,this.size=c}},at=0;var ft=1,k=class a{static read_bytes(e,i){return new a(e.getBigUint64(i,!0),e.getUint8(i+8),e.getUint32(i+16,!0),e.getBigUint64(i+24,!0),e.getUint16(i+36,!0))}constructor(e,i,c,E,t){this.userdata=e,this.eventtype=i,this.clockid=c,this.timeout=E,this.flags=t}},Y=class{write_bytes(e,i){e.setBigUint64(i,this.userdata,!0),e.setUint16(i+8,this.error,!0),e.setUint8(i+10,this.eventtype)}constructor(e,i,c){this.userdata=e,this.error=i,this.eventtype=c}};var wt=class{enable(e){this.log=ht(e===void 0?!0:e,this.prefix)}get enabled(){return this.isEnabled}constructor(e){this.isEnabled=e,this.prefix=\"wasi:\",this.enable(e)}};function ht(a,e){return a?console.log.bind(console,\"%c%s\",\"color: #265BA0\",e):()=>{}}var y=new wt(!1);var U=class extends Error{constructor(e){super(\"exit with exit code \"+e),this.code=e}},rt=class{start(e){this.inst=e;try{return e.exports._start(),0}catch(i){if(i instanceof U)return i.code;throw i}}initialize(e){this.inst=e,e.exports._initialize&&e.exports._initialize()}constructor(e,i,c,E={}){this.args=[],this.env=[],this.fds=[],y.enable(E.debug),this.args=e,this.env=i,this.fds=c;let t=this;this.wasiImport={args_sizes_get(r,n){let s=new DataView(t.inst.exports.memory.buffer);s.setUint32(r,t.args.length,!0);let o=0;for(let f of t.args)o+=f.length+1;return s.setUint32(n,o,!0),y.log(s.getUint32(r,!0),s.getUint32(n,!0)),0},args_get(r,n){let s=new DataView(t.inst.exports.memory.buffer),o=new Uint8Array(t.inst.exports.memory.buffer),f=n;for(let _=0;_<t.args.length;_++){s.setUint32(r,n,!0),r+=4;let l=new TextEncoder().encode(t.args[_]);o.set(l,n),s.setUint8(n+l.length,0),n+=l.length+1}return y.enabled&&y.log(new TextDecoder(\"utf-8\").decode(o.slice(f,n))),0},environ_sizes_get(r,n){let s=new DataView(t.inst.exports.memory.buffer);s.setUint32(r,t.env.length,!0);let o=0;for(let f of t.env)o+=new TextEncoder().encode(f).length+1;return s.setUint32(n,o,!0),y.log(s.getUint32(r,!0),s.getUint32(n,!0)),0},environ_get(r,n){let s=new DataView(t.inst.exports.memory.buffer),o=new Uint8Array(t.inst.exports.memory.buffer),f=n;for(let _=0;_<t.env.length;_++){s.setUint32(r,n,!0),r+=4;let l=new TextEncoder().encode(t.env[_]);o.set(l,n),s.setUint8(n+l.length,0),n+=l.length+1}return y.enabled&&y.log(new TextDecoder(\"utf-8\").decode(o.slice(f,n))),0},clock_res_get(r,n){let s;switch(r){case 1:{s=5000n;break}case 0:{s=1000000n;break}default:return 52}return new DataView(t.inst.exports.memory.buffer).setBigUint64(n,s,!0),0},clock_time_get(r,n,s){let o=new DataView(t.inst.exports.memory.buffer);if(r===0)o.setBigUint64(s,BigInt(new Date().getTime())*1000000n,!0);else if(r==1){let f;try{f=BigInt(Math.round(performance.now()*1e6))}catch{f=0n}o.setBigUint64(s,f,!0)}else o.setBigUint64(s,0n,!0);return 0},fd_advise(r,n,s,o){return t.fds[r]!=null?0:8},fd_allocate(r,n,s){return t.fds[r]!=null?t.fds[r].fd_allocate(n,s):8},fd_close(r){if(t.fds[r]!=null){let n=t.fds[r].fd_close();return t.fds[r]=void 0,n}else return 8},fd_datasync(r){return t.fds[r]!=null?t.fds[r].fd_sync():8},fd_fdstat_get(r,n){if(t.fds[r]!=null){let{ret:s,fdstat:o}=t.fds[r].fd_fdstat_get();return o?.write_bytes(new DataView(t.inst.exports.memory.buffer),n),s}else return 8},fd_fdstat_set_flags(r,n){return t.fds[r]!=null?t.fds[r].fd_fdstat_set_flags(n):8},fd_fdstat_set_rights(r,n,s){return t.fds[r]!=null?t.fds[r].fd_fdstat_set_rights(n,s):8},fd_filestat_get(r,n){if(t.fds[r]!=null){let{ret:s,filestat:o}=t.fds[r].fd_filestat_get();return o?.write_bytes(new DataView(t.inst.exports.memory.buffer),n),s}else return 8},fd_filestat_set_size(r,n){return t.fds[r]!=null?t.fds[r].fd_filestat_set_size(n):8},fd_filestat_set_times(r,n,s,o){return t.fds[r]!=null?t.fds[r].fd_filestat_set_times(n,s,o):8},fd_pread(r,n,s,o,f){let _=new DataView(t.inst.exports.memory.buffer),l=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let u=C.read_bytes_array(_,n,s),p=0;for(let d of u){let{ret:R,data:h}=t.fds[r].fd_pread(d.buf_len,o);if(R!=0)return _.setUint32(f,p,!0),R;if(l.set(h,d.buf),p+=h.length,o+=BigInt(h.length),h.length!=d.buf_len)break}return _.setUint32(f,p,!0),0}else return 8},fd_prestat_get(r,n){let s=new DataView(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let{ret:o,prestat:f}=t.fds[r].fd_prestat_get();return f?.write_bytes(s,n),o}else return 8},fd_prestat_dir_name(r,n,s){if(t.fds[r]!=null){let{ret:o,prestat:f}=t.fds[r].fd_prestat_get();if(f==null)return o;let _=f.inner.pr_name;return new Uint8Array(t.inst.exports.memory.buffer).set(_.slice(0,s),n),_.byteLength>s?37:0}else return 8},fd_pwrite(r,n,s,o,f){let _=new DataView(t.inst.exports.memory.buffer),l=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let u=L.read_bytes_array(_,n,s),p=0;for(let d of u){let R=l.slice(d.buf,d.buf+d.buf_len),{ret:h,nwritten:S}=t.fds[r].fd_pwrite(R,o);if(h!=0)return _.setUint32(f,p,!0),h;if(p+=S,o+=BigInt(S),S!=R.byteLength)break}return _.setUint32(f,p,!0),0}else return 8},fd_read(r,n,s,o){let f=new DataView(t.inst.exports.memory.buffer),_=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let l=C.read_bytes_array(f,n,s),u=0;for(let p of l){let{ret:d,data:R}=t.fds[r].fd_read(p.buf_len);if(d!=0)return f.setUint32(o,u,!0),d;if(_.set(R,p.buf),u+=R.length,R.length!=p.buf_len)break}return f.setUint32(o,u,!0),0}else return 8},fd_readdir(r,n,s,o,f){let _=new DataView(t.inst.exports.memory.buffer),l=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let u=0;for(;;){let{ret:p,dirent:d}=t.fds[r].fd_readdir_single(o);if(p!=0)return _.setUint32(f,u,!0),p;if(d==null)break;if(s-u<d.head_length()){u=s;break}let R=new ArrayBuffer(d.head_length());if(d.write_head_bytes(new DataView(R),0),l.set(new Uint8Array(R).slice(0,Math.min(R.byteLength,s-u)),n),n+=d.head_length(),u+=d.head_length(),s-u<d.name_length()){u=s;break}d.write_name_bytes(l,n,s-u),n+=d.name_length(),u+=d.name_length(),o=d.d_next}return _.setUint32(f,u,!0),0}else return 8},fd_renumber(r,n){if(t.fds[r]!=null&&t.fds[n]!=null){let s=t.fds[n].fd_close();return s!=0?s:(t.fds[n]=t.fds[r],t.fds[r]=void 0,0)}else return 8},fd_seek(r,n,s,o){let f=new DataView(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let{ret:_,offset:l}=t.fds[r].fd_seek(n,s);return f.setBigInt64(o,l,!0),_}else return 8},fd_sync(r){return t.fds[r]!=null?t.fds[r].fd_sync():8},fd_tell(r,n){let s=new DataView(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let{ret:o,offset:f}=t.fds[r].fd_tell();return s.setBigUint64(n,f,!0),o}else return 8},fd_write(r,n,s,o){let f=new DataView(t.inst.exports.memory.buffer),_=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let l=L.read_bytes_array(f,n,s),u=0;for(let p of l){let d=_.slice(p.buf,p.buf+p.buf_len),{ret:R,nwritten:h}=t.fds[r].fd_write(d);if(R!=0)return f.setUint32(o,u,!0),R;if(u+=h,h!=d.byteLength)break}return f.setUint32(o,u,!0),0}else return 8},path_create_directory(r,n,s){let o=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let f=new TextDecoder(\"utf-8\").decode(o.slice(n,n+s));return t.fds[r].path_create_directory(f)}else return 8},path_filestat_get(r,n,s,o,f){let _=new DataView(t.inst.exports.memory.buffer),l=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let u=new TextDecoder(\"utf-8\").decode(l.slice(s,s+o)),{ret:p,filestat:d}=t.fds[r].path_filestat_get(n,u);return d?.write_bytes(_,f),p}else return 8},path_filestat_set_times(r,n,s,o,f,_,l){let u=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let p=new TextDecoder(\"utf-8\").decode(u.slice(s,s+o));return t.fds[r].path_filestat_set_times(n,p,f,_,l)}else return 8},path_link(r,n,s,o,f,_,l){let u=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[r]!=null&&t.fds[f]!=null){let p=new TextDecoder(\"utf-8\").decode(u.slice(s,s+o)),d=new TextDecoder(\"utf-8\").decode(u.slice(_,_+l)),{ret:R,inode_obj:h}=t.fds[r].path_lookup(p,n);return h==null?R:t.fds[f].path_link(d,h,!1)}else return 8},path_open(r,n,s,o,f,_,l,u,p){let d=new DataView(t.inst.exports.memory.buffer),R=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let h=new TextDecoder(\"utf-8\").decode(R.slice(s,s+o));y.log(h);let{ret:S,fd_obj:X}=t.fds[r].path_open(n,h,f,_,l,u);if(S!=0)return S;t.fds.push(X);let H=t.fds.length-1;return d.setUint32(p,H,!0),0}else return 8},path_readlink(r,n,s,o,f,_){let l=new DataView(t.inst.exports.memory.buffer),u=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let p=new TextDecoder(\"utf-8\").decode(u.slice(n,n+s));y.log(p);let{ret:d,data:R}=t.fds[r].path_readlink(p);if(R!=null){let h=new TextEncoder().encode(R);if(h.length>f)return l.setUint32(_,0,!0),8;u.set(h,o),l.setUint32(_,h.length,!0)}return d}else return 8},path_remove_directory(r,n,s){let o=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let f=new TextDecoder(\"utf-8\").decode(o.slice(n,n+s));return t.fds[r].path_remove_directory(f)}else return 8},path_rename(r,n,s,o,f,_){let l=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[r]!=null&&t.fds[o]!=null){let u=new TextDecoder(\"utf-8\").decode(l.slice(n,n+s)),p=new TextDecoder(\"utf-8\").decode(l.slice(f,f+_)),{ret:d,inode_obj:R}=t.fds[r].path_unlink(u);if(R==null)return d;if(d=t.fds[o].path_link(p,R,!0),d!=0&&t.fds[r].path_link(u,R,!0)!=0)throw\"path_link should always return success when relinking an inode back to the original place\";return d}else return 8},path_symlink(r,n,s,o,f){let _=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[s]!=null){let l=new TextDecoder(\"utf-8\").decode(_.slice(r,r+n)),u=new TextDecoder(\"utf-8\").decode(_.slice(o,o+f));return 58}else return 8},path_unlink_file(r,n,s){let o=new Uint8Array(t.inst.exports.memory.buffer);if(t.fds[r]!=null){let f=new TextDecoder(\"utf-8\").decode(o.slice(n,n+s));return t.fds[r].path_unlink_file(f)}else return 8},poll_oneoff(r,n,s){if(s===0)return 28;if(s>1)return y.log(\"poll_oneoff: only a single subscription is supported\"),58;let o=new DataView(t.inst.exports.memory.buffer),f=k.read_bytes(o,r),_=f.eventtype,l=f.clockid,u=f.timeout;if(_!==at)return y.log(\"poll_oneoff: only clock subscriptions are supported\"),58;let p;if(l===1)p=()=>BigInt(Math.round(performance.now()*1e6));else if(l===0)p=()=>BigInt(new Date().getTime())*1000000n;else return 28;let d=(f.flags&ft)!==0?u:p()+u;for(;d>p(););return new Y(f.userdata,0,_).write_bytes(o,n),0},proc_exit(r){throw new U(r)},proc_raise(r){throw\"raised signal \"+r},sched_yield(){},random_get(r,n){let s=new Uint8Array(t.inst.exports.memory.buffer).subarray(r,r+n);if(\"crypto\"in globalThis&&(typeof SharedArrayBuffer>\"u\"||!(t.inst.exports.memory.buffer instanceof SharedArrayBuffer)))for(let o=0;o<n;o+=65536)crypto.getRandomValues(s.subarray(o,o+65536));else for(let o=0;o<n;o++)s[o]=Math.random()*256|0},sock_recv(r,n,s){throw\"sockets not supported\"},sock_send(r,n,s){throw\"sockets not supported\"},sock_shutdown(r,n){throw\"sockets not supported\"},sock_accept(r,n){throw\"sockets not supported\"}}}};var g=class{fd_allocate(e,i){return 58}fd_close(){return 0}fd_fdstat_get(){return{ret:58,fdstat:null}}fd_fdstat_set_flags(e){return 58}fd_fdstat_set_rights(e,i){return 58}fd_filestat_get(){return{ret:58,filestat:null}}fd_filestat_set_size(e){return 58}fd_filestat_set_times(e,i,c){return 58}fd_pread(e,i){return{ret:58,data:new Uint8Array}}fd_prestat_get(){return{ret:58,prestat:null}}fd_pwrite(e,i){return{ret:58,nwritten:0}}fd_read(e){return{ret:58,data:new Uint8Array}}fd_readdir_single(e){return{ret:58,dirent:null}}fd_seek(e,i){return{ret:58,offset:0n}}fd_sync(){return 0}fd_tell(){return{ret:58,offset:0n}}fd_write(e){return{ret:58,nwritten:0}}path_create_directory(e){return 58}path_filestat_get(e,i){return{ret:58,filestat:null}}path_filestat_set_times(e,i,c,E,t){return 58}path_link(e,i,c){return 58}path_unlink(e){return{ret:58,inode_obj:null}}path_lookup(e,i){return{ret:58,inode_obj:null}}path_open(e,i,c,E,t,r){return{ret:54,fd_obj:null}}path_readlink(e){return{ret:58,data:null}}path_remove_directory(e){return 58}path_rename(e,i,c){return 58}path_unlink_file(e){return 58}},m=class a{static issue_ino(){return a.next_ino++}static root_ino(){return 0n}constructor(){this.ino=a.issue_ino()}};m.next_ino=1n;var b=class extends g{fd_allocate(e,i){if(!(this.file.size>e+i)){let c=new Uint8Array(Number(e+i));c.set(this.file.data,0),this.file.data=c}return 0}fd_fdstat_get(){return{ret:0,fdstat:new x(W,0)}}fd_filestat_set_size(e){if(this.file.size>e)this.file.data=new Uint8Array(this.file.data.buffer.slice(0,Number(e)));else{let i=new Uint8Array(Number(e));i.set(this.file.data,0),this.file.data=i}return 0}fd_read(e){let i=this.file.data.slice(Number(this.file_pos),Number(this.file_pos+BigInt(e)));return this.file_pos+=BigInt(i.length),{ret:0,data:i}}fd_pread(e,i){return{ret:0,data:this.file.data.slice(Number(i),Number(i+BigInt(e)))}}fd_seek(e,i){let c;switch(i){case Q:c=e;break;case Z:c=this.file_pos+e;break;case V:c=BigInt(this.file.data.byteLength)+e;break;default:return{ret:28,offset:0n}}return c<0?{ret:28,offset:0n}:(this.file_pos=c,{ret:0,offset:this.file_pos})}fd_tell(){return{ret:0,offset:this.file_pos}}fd_write(e){if(this.file.readonly)return{ret:8,nwritten:0};if(this.file_pos+BigInt(e.byteLength)>this.file.size){let i=this.file.data;this.file.data=new Uint8Array(Number(this.file_pos+BigInt(e.byteLength))),this.file.data.set(i)}return this.file.data.set(e,Number(this.file_pos)),this.file_pos+=BigInt(e.byteLength),{ret:0,nwritten:e.byteLength}}fd_pwrite(e,i){if(this.file.readonly)return{ret:8,nwritten:0};if(i+BigInt(e.byteLength)>this.file.size){let c=this.file.data;this.file.data=new Uint8Array(Number(i+BigInt(e.byteLength))),this.file.data.set(c)}return this.file.data.set(e,Number(i)),{ret:0,nwritten:e.byteLength}}fd_filestat_get(){return{ret:0,filestat:this.file.stat()}}constructor(e){super(),this.file_pos=0n,this.file=e}};var F=class extends m{path_open(e,i,c){if(this.readonly&&(i&BigInt(64))==BigInt(64))return{ret:63,fd_obj:null};if((e&j)==j){if(this.readonly)return{ret:63,fd_obj:null};this.data=new Uint8Array([])}let E=new b(this);return c&q&&E.fd_seek(0n,V),{ret:0,fd_obj:E}}get size(){return BigInt(this.data.byteLength)}stat(){return new A(this.ino,W,this.size)}constructor(e,i){super(),this.data=new Uint8Array(e),this.readonly=!!i?.readonly}};var P=class a extends g{fd_filestat_get(){return{ret:0,filestat:new A(this.ino,J,BigInt(0))}}fd_fdstat_get(){let e=new x(J,0);return e.fs_rights_base=BigInt(64),{ret:0,fdstat:e}}fd_write(e){return this.write(e),{ret:0,nwritten:e.byteLength}}static lineBuffered(e){let i=new TextDecoder(\"utf-8\",{fatal:!1}),c=\"\";return new a(E=>{c+=i.decode(E,{stream:!0});let t=c.split(`\n`);for(let[r,n]of t.entries())r<t.length-1?e(n):c=n})}constructor(e){super(),this.ino=m.issue_ino(),this.write=e}};var ct=\"code-playpad Clang 20.1.2 / Emscripten 4.0.6 r1\",lt={\"clang.js\":{bytes:74300,sha256:\"b437a648812aabd1cc87cba4a7268e2f53ab94a9071a854ba983dd62328dc30c\"},\"clang.wasm\":{bytes:42578038,sha256:\"534571fd4f9136c85d3e25a395cc31983ec3cbd41012e3928b45879a518718fa\"},\"lld.js\":{bytes:71711,sha256:\"2da4b0a04b6953bdc4869137631abd11ea7eb5a667fbd19c4ff6d68d56f302bb\"},\"lld.wasm\":{bytes:23228304,sha256:\"55ffbe1366525c1b55b65140630e0ca00ff47eae7acfdee6a15b46e738800ec7\"},\"sysroot.tar\":{bytes:29009920,sha256:\"a0d92a9fc1dccc2c181ae6812b6c169de3dad851ee4d4e796d15940776648ac5\"}};function K(a){if(!a||a.startsWith(\"/\")||/[\\\\\\x00-\\x1f:]/.test(a)||a.split(\"/\").some(e=>!e||e===\".\"||e===\"..\"))throw new Error(`Invalid project path: ${JSON.stringify(a)}. Use relative paths without . or ...`);return a}function ut(a,e,i,c){let E=K(i??(c===\"c\"?\"main.c\":\"main.cpp\")),t=e?{...e}:{[E]:a};if(!Object.hasOwn(t,E))throw new Error(`Entry file ${E} does not exist.`);let r=Object.keys(t).map(K).sort(),n=f=>/\\.c$/.test(f),s=f=>/\\.(cpp|cc|cxx)$/.test(f);if(r.some(c===\"c\"?s:n))throw new Error(\"Mixed C/C++ source projects are not supported yet.\");let o=r.filter(c===\"c\"?n:s);if(!o.includes(E))throw new Error(`Entry ${E} must have a ${c===\"c\"?\".c\":\".cpp, .cc, or .cxx\"} extension.`);if(o.length>32||r.length>256)throw new Error(\"Project limit: 32 source files and 256 files total.\");if(Object.values(t).reduce((f,_)=>f+new TextEncoder().encode(_).length,0)>2e6)throw new Error(\"Project exceeds the 2 MB source limit.\");return{files:t,sources:o,entry:E}}var st,v,dt=Promise.resolve(),G=a=>globalThis.postMessage(a),M=(a,e,i)=>G({type:\"progress\",id:a,phase:e,message:i}),B=(a,e)=>ot(a,lt[a],st,it,i=>M(e,\"downloading\",i));function St(a){let e=new Uint8Array(a),i=new TextDecoder,c=[],E=(t,r)=>i.decode(e.subarray(t,t+r)).replace(/\\0.*$/,\"\");for(let t=0;t+512<=e.length;){let r=E(t,100);if(!r)break;let n=E(t+345,155);n&&(r=n+\"/\"+r);let s=parseInt(E(t+124,12).trim()||\"0\",8),o=e[t+156];if(!Number.isSafeInteger(s)||s<0||t+512+s>e.length)throw new Error(\"Invalid sysroot archive.\");if(o===48||o===0)c.push({name:\"/\"+K(r),data:e.subarray(t+512,t+512+s)});else if(o!==53)throw new Error(\"Unsupported sysroot archive entry.\");t+=512+Math.ceil(s/512)*512}return c}async function Rt(a){let e=URL.createObjectURL(new Blob([a],{type:\"text/javascript\"}));try{return(await import(e)).default}finally{URL.revokeObjectURL(e)}}function yt(a){return st?(v||(v=(async()=>{let e=await Rt(await B(\"clang.js\",a)),i=await Rt(await B(\"lld.js\",a)),c=await WebAssembly.compile(await B(\"clang.wasm\",a)),E=await WebAssembly.compile(await B(\"lld.wasm\",a));M(a,\"booting\",\"Preparing C/C++ standard libraries\\u2026\");let t=St(await B(\"sysroot.tar\",a));return{clang:e,lld:i,clangModule:c,lldModule:E,sysroot:t}})().catch(e=>{throw v=void 0,e})),v):Promise.reject(new Error(\"Configure the rebuilt C/C++ assets with configureCpp({ indexURL }) before creating widgets. See docs/CPP-REBUILD.md.\"))}async function Et(a,e,i,c){let E,t=await a({thisProgram:i,noInitialRun:!0,print:c,printErr:c,instantiateWasm(r,n){let s=new WebAssembly.Instance(e,r);return E=Object.values(s.exports).find(o=>o instanceof WebAssembly.Memory),n(s,e),s.exports}});return t.memory=E,t}function $(a,e,i){a.mkdirTree(e.slice(0,e.lastIndexOf(\"/\"))||\"/\"),a.writeFile(e,i)}async function mt(a){let e=performance.now(),i=0,c=(E,t)=>{if(i+=t.length,i>1e6)throw new Error(\"Output limit exceeded (1 MB).\");t&&G({type:E,id:a.id,text:t})};try{let E=ut(a.code,a.files,a.entry,a.compilerLanguage),t=await yt(a.id),r=[],n=0;for(let R of E.sources){M(a.id,\"compiling\",`Compiling ${R}\\u2026`);let h=await Et(t.clang,t.clangModule,\"clang\",T=>c(\"stderr\",T+`\n`));for(let T of t.sysroot)$(h.FS,T.name,T.data);for(let[T,pt]of Object.entries(E.files))$(h.FS,\"/project/\"+T,pt);let S=a.compilerLanguage===\"cpp\",X=[\"-cc1\",\"-triple\",\"wasm32-unknown-wasi\",\"-emit-obj\",\"-O0\",\"-std=\"+(S?\"c++20\":\"c17\"),\"-resource-dir\",\"/lib/clang/20\",...S?[\"-internal-isystem\",\"/include/wasm32-wasi/c++/v1\",\"-internal-isystem\",\"/include/c++/v1\"]:[],\"-internal-isystem\",\"/lib/clang/20/include\",\"-internal-isystem\",\"/include/wasm32-wasi\",\"-internal-isystem\",\"/include\",\"-I\",\"/project\",\"-ferror-limit\",\"20\",\"-o\",\"/tmp/output.o\",\"-x\",S?\"c++\":\"c\",\"/project/\"+R],H=h.callMain(X);if(n=Math.max(n,h.memory?.buffer.byteLength??0),H!==0)throw new Error(`Compilation failed (${R}, exit ${H}).`);r.push(h.FS.readFile(\"/tmp/output.o\").slice())}M(a.id,\"linking\",\"Linking\\u2026\");let s=await Et(t.lld,t.lldModule,\"wasm-ld\",R=>c(\"stderr\",R+`\n`));for(let R of t.sysroot)R.name.startsWith(\"/include/\")||$(s.FS,R.name,R.data);r.forEach((R,h)=>$(s.FS,\"/tmp/\"+h+\".o\",R));let o=s.callMain([\"-m\",\"wasm32\",\"-z\",\"stack-size=1048576\",\"--max-memory=268435456\",\"-L/lib/wasm32-wasi\",\"/lib/wasm32-wasi/crt1-command.o\",...r.map((R,h)=>\"/tmp/\"+h+\".o\"),...a.compilerLanguage===\"cpp\"?[\"-lc++\",\"-lc++abi\"]:[],\"-lc\",\"/lib/clang/20/lib/wasm32-unknown-wasi/libclang_rt.builtins.a\",\"-o\",\"/tmp/program.wasm\"]);if(n=Math.max(n,s.memory?.buffer.byteLength??0),o!==0)throw new Error(`Linking failed (exit ${o}).`);let f=await WebAssembly.compile(s.FS.readFile(\"/tmp/program.wasm\").slice().buffer);M(a.id,\"running\",\"Running\\u2026\");let _={stdout:new TextDecoder,stderr:new TextDecoder},l=R=>new P(h=>c(R,_[R].decode(h,{stream:!0}))),u=new rt([E.entry],[],[new b(new F(new TextEncoder().encode(a.stdin??\"\"))),l(\"stdout\"),l(\"stderr\")]),p=await WebAssembly.instantiate(f,{wasi_snapshot_preview1:u.wasiImport}),d=u.start(p);if(c(\"stdout\",_.stdout.decode()),c(\"stderr\",_.stderr.decode()),d!==0)throw new Error(`Program exited with status ${d}.`);G({type:\"result\",id:a.id,durationMs:performance.now()-e,memory:{compilerBytes:n,programBytes:p.exports.memory.buffer.byteLength}})}catch(E){G({type:\"error\",id:a.id,message:E instanceof Error?E.message:String(E),durationMs:performance.now()-e})}}globalThis.onmessage=({data:a})=>{a.type===\"init\"?(st=a.toolchainURL,G({type:\"ready\",version:ct,interactiveStdin:!1})):a.type===\"run\"&&(dt=dt.then(()=>mt(a)))};})();\n";
@@ -0,0 +1,3 @@
1
+ import type { Runtime } from '../types.js';
2
+ export declare const cRuntime: Runtime;
3
+ export declare const cppRuntime: Runtime;
@@ -1,7 +1,7 @@
1
1
  export declare const JAVA_LIBRARY: {
2
2
  readonly name: "java-online-compiler";
3
- readonly version: "0.34.1";
4
- readonly commit: "f3698375f3087bcbeeae3f7736746cd0c807c689";
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.34.1";
4
- readonly commit: "f3698375f3087bcbeeae3f7736746cd0c807c689";
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.34.1";
4
- readonly commit: "f3698375f3087bcbeeae3f7736746cd0c807c689";
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.34.1";
4
- readonly commit: "f3698375f3087bcbeeae3f7736746cd0c807c689";
3
+ readonly version: "0.39.0";
4
+ readonly commit: "b00eddf254edc4545e4856c2bf729adfc6d7265c";
5
5
  readonly dirty: false;
6
- readonly sha256: "f96214f5bd73ef7e78e8b56b304b192b21ccdcea962d6ff8e17ec303c3a4da35";
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.34.1";
4
- readonly commit: "f3698375f3087bcbeeae3f7736746cd0c807c689";
3
+ readonly version: "0.39.0";
4
+ readonly commit: "b00eddf254edc4545e4856c2bf729adfc6d7265c";
5
5
  readonly dirty: false;
6
- readonly sha256: "acd14e1fdf653e291e134ed0f6e8bd4c7b8ec9ecfeaea516fca99131e2046cd3";
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.34.1";
4
- readonly commit: "f3698375f3087bcbeeae3f7736746cd0c807c689";
3
+ readonly version: "0.39.0";
4
+ readonly commit: "b00eddf254edc4545e4856c2bf729adfc6d7265c";
5
5
  readonly dirty: false;
6
- readonly sha256: "dbec4f9435278822722a3407966c7b4779da4e3dc42a47e4a6a2f4985f8601b9";
6
+ readonly sha256: "252c770562fbca0245aa38b8006e82ae61c5f0df0bd2b56506e859675788ac79";
7
7
  };
8
8
  export declare const JAVA_WORKER_SOURCE: string;
@@ -39,6 +39,7 @@ export type WorkerMessage = {
39
39
  id: number;
40
40
  value?: string;
41
41
  durationMs: number;
42
+ memory?: Result['memory'];
42
43
  cases?: CaseResult[];
43
44
  passed?: number;
44
45
  total?: number;
@@ -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-v5iHTd1l.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-BThnYaQ5.js`).then(e=>e.s),import(`./dist-DOsLUKSb.js`).then(e=>e.x),import(`./dist-CnC1nMtN.js`),import(`./dist-D0FPZcUi.js`),import(`./dist-DmrP6yta.js`),import(`./dist-DlIO0dzi.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=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=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=new Map,d=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(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-Crdd9em4.js`).then(e=>e.pythonRuntime)),f(`javascript`,()=>import(`./javascript-CX-lsX2u.js`).then(e=>e.javascriptRuntime)),f(`typescript`,()=>import(`./javascript-CX-lsX2u.js`).then(e=>e.typescriptRuntime)),f(`java`,()=>import(`./java-DxQWnfHu.js`).then(e=>e.javaRuntime));var h=String.raw`
6
+ import{n as e,r as t,t as n}from"./hints-CCMgezw9.js";import{c as r,i,n as a,r as o,t as s}from"./config-cwuPIQ48.js";async function c(e){try{return await l(e)}catch(t){return console.warn(`[code-playpad] CodeMirror unavailable, using plain textarea:`,t),u(e)}}async function l(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 u(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 d=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Map;function p(e,t){d.set(e,t)}function m(){return[...d.keys()]}function h(e){let t=f.get(e);if(t)return t;let n=d.get(e);if(!n)return Promise.reject(/* @__PURE__ */ Error(`Unknown runtime "${e}". Registered: ${m().join(`, `)||`none`}`));let r=n().catch(t=>{throw f.delete(e),t});return f.set(e,r),r}p(`python`,()=>import(`./pyodide-B1U3JD9Z.js`).then(e=>e.pythonRuntime)),p(`javascript`,()=>import(`./javascript-DkarEcEB.js`).then(e=>e.javascriptRuntime)),p(`typescript`,()=>import(`./javascript-DkarEcEB.js`).then(e=>e.typescriptRuntime)),p(`java`,()=>import(`./java-DeBiVPXO.js`).then(e=>e.javaRuntime)),p(`c`,()=>import(`./cpp-DakNa4ys.js`).then(e=>e.cRuntime)),p(`cpp`,()=>import(`./cpp-DakNa4ys.js`).then(e=>e.cppRuntime));var g=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-CqpVTRAq.js`).then(t=>t.javascript(e)),_={py:()=>import(`./dist-D_qJovVA.js`).then(e=>e.python()),pyi:()=>import(`./dist-D_qJovVA.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-XlpaG2JF.js`).then(e=>e.json()),java:()=>import(`./dist-BKRQwpg6.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(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(`
302
+ `,_=e=>()=>import(`./dist-D7jBL3Ib.js`).then(t=>t.javascript(e)),v={py:()=>import(`./dist--J_vhCIU.js`).then(e=>e.python()),pyi:()=>import(`./dist--J_vhCIU.js`).then(e=>e.python()),js:_({}),mjs:_({}),cjs:_({}),jsx:_({jsx:!0}),ts:_({typescript:!0}),mts:_({typescript:!0}),cts:_({typescript:!0}),tsx:_({typescript:!0,jsx:!0}),json:()=>import(`./dist-BkpKCrXQ.js`).then(e=>e.json()),c:()=>import(`./dist-CNOK8CHE.js`).then(e=>e.cpp()),h:()=>import(`./dist-CNOK8CHE.js`).then(e=>e.cpp()),cpp:()=>import(`./dist-CNOK8CHE.js`).then(e=>e.cpp()),cc:()=>import(`./dist-CNOK8CHE.js`).then(e=>e.cpp()),cxx:()=>import(`./dist-CNOK8CHE.js`).then(e=>e.cpp()),hpp:()=>import(`./dist-CNOK8CHE.js`).then(e=>e.cpp()),hxx:()=>import(`./dist-CNOK8CHE.js`).then(e=>e.cpp()),java:()=>import(`./dist-CJxiVI4a.js`).then(e=>e.java())};async function y(e){let t=v[e.includes(`.`)?e.slice(e.lastIndexOf(`.`)+1).toLowerCase():``];return t?t().catch(()=>null):null}var b=`code-playpad`,x=1,S=`snippets`,C=`progress`,w=null;function T(){return typeof indexedDB>`u`?Promise.reject(/* @__PURE__ */ Error(`IndexedDB unavailable`)):(w||=new Promise((e,t)=>{let n=indexedDB.open(b,x);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(S)||e.createObjectStore(S),e.objectStoreNames.contains(C)||e.createObjectStore(C,{keyPath:`id`})},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}).catch(e=>{throw w=null,e}),w)}function E(e,t,n){return T().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 D(e,t){return E(S,`readwrite`,n=>n.put(t,e)).then(()=>void 0)}function O(e){return E(S,`readonly`,t=>t.get(e)).then(e=>e??null)}function k(e){return E(S,`readwrite`,t=>t.delete(e)).then(()=>void 0)}function A(e,t={}){let n={completed:!0,...t,id:e,updatedAt:Date.now()};return E(C,`readwrite`,e=>e.put(n)).then(()=>n)}function j(e){return E(C,`readonly`,t=>t.get(e)).then(e=>e??null)}function M(){return E(C,`readonly`,e=>e.getAll())}var N=`code-playpad`;function P(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
- `)}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
- `,`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(`
304
+ `)}var F=2e5,I=`playpad-file`,L={python:`main.py`,javascript:`main.js`,typescript:`main.ts`,java:`Main.java`,c:`main.c`,cpp:`main.cpp`};function R(e){return L[e]??`main.txt`}function z(e,t){let n={};for(let t of e.children){if(t.tagName.toLowerCase()!==I)continue;let e=t.getAttribute(`name`);e&&(n[e]=P(t.textContent??``))}if(Object.keys(n).length)return n;let r=[...e.childNodes].filter(e=>e.nodeType!==Node.ELEMENT_NODE||e.tagName.toLowerCase()!==I),i=r.some(e=>e.nodeType===Node.ELEMENT_NODE),a=P(r.filter(e=>!(i&&e.nodeType===Node.TEXT_NODE&&!(e.textContent??``).trim())).map(e=>e.textContent??``).join(``));return{[t]:a}}function B(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 V=typeof HTMLElement>`u`?class{}:HTMLElement,H=class extends V{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
+ `,`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`),onProgress:e=>this.#Q(e.message,`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(){if(this.#P){this.#R();return}if(!this.textContent?.trim()&&document.readyState===`loading`){document.addEventListener(`DOMContentLoaded`,()=>this.isConnected&&this.#I(),{once:!0});return}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=`
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=z(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 O(e).catch(()=>null),n=t==null?null:B(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 h(this.language).catch(()=>null),n=t?await t.editorLanguage().catch(()=>null):null;this.#u=await c({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=g;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>
@@ -320,10 +320,10 @@ table.cp-table th { background: var(--cp-bg); }
320
320
  <label>Standard input — one value per line</label>
321
321
  <textarea rows="2" spellcheck="false"></textarea>
322
322
  </div>
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(){if(this.#u){this.#u.setCode(this.#m[this.#g]??``);return}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
- `),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)+`
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 h(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 y(e);if(t){this.#g===e&&this.#u?.setLanguage(t);return}let n=e.includes(`.`)?null:await(this.#f??await h(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`)||R(this.language)}#G(){let e=Object.keys(this.#m),t=this.getAttribute(`entry`);if(t&&e.includes(t))return t;let n=R(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 D(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
+ `),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>=F)break;let e=t.text;this.#N+e.length>F&&(e=e.slice(0,F-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>`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};
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 U(e=N){typeof window<`u`&&typeof customElements<`u`&&(customElements.get(e)||customElements.define(e,H))}U();export{H as CodePlayPadElement,s as PYODIDE_VERSION,e as RunStopped,t as WorkerUnavailable,M as allProgress,k as clearSnippet,a as configureCpp,o as configurePython,i as configureTypeScript,c as createEditor,U as defineCodePlayPad,j as getProgress,h as getRuntime,m as listRuntimes,O as loadSnippet,r as pyodideAssetUrls,p as registerRuntime,D as saveSnippet,A as setProgress};
package/dist/types.d.ts CHANGED
@@ -14,6 +14,12 @@ export interface Result {
14
14
  /** Runtime guidance about a failure, in plain language — not program output. */
15
15
  hint?: string;
16
16
  durationMs: number;
17
+ /** Experimental compilers: sampled Wasm linear memory after each phase.
18
+ * Excludes JS heap, compiled code, caches, and other instances; not process peak. */
19
+ memory?: {
20
+ compilerBytes: number;
21
+ programBytes: number;
22
+ };
17
23
  /** Practice mode: one result per case, in order. */
18
24
  cases?: CaseResult[];
19
25
  /** Practice mode: cases that passed, and cases run. */
@@ -86,13 +92,19 @@ export interface CaseResult {
86
92
  durationMs: number;
87
93
  }
88
94
  export interface LoadProgress {
89
- phase: 'booting' | 'packages' | 'ready';
95
+ phase: 'booting' | 'packages' | 'ready' | 'downloading' | 'compiling' | 'linking' | 'running';
90
96
  message: string;
91
97
  }
92
98
  /** name -> contents. Names are relative paths: "utils.py", "pkg/__init__.py",
93
99
  * "data.csv". Written into the runtime's filesystem before the run. */
94
100
  export type Files = Record<string, string>;
95
101
  export interface RunOptions {
102
+ /** Progress for this run, including compiler downloads and compilation. */
103
+ onProgress?: (progress: LoadProgress) => void;
104
+ /** Optional wall-clock limit after dispatch, including asset loading. */
105
+ timeoutMs?: number;
106
+ /** Used by the C/C++ facades to select a shared compiler's language mode. */
107
+ compilerLanguage?: 'c' | 'cpp';
96
108
  stdin?: string;
97
109
  /** Extra files to place next to the entry point before running. */
98
110
  files?: Files;
@@ -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:()=>{clearTimeout(c.timer),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}),this.#u&&e.id===this.#u.id&&!this.#u.settled&&this.#u.options.onProgress?.({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.memory?{memory:e.memory}:{},...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?.(),e.options.timeoutMs&&Number.isFinite(e.options.timeoutMs)&&e.options.timeoutMs>0&&(e.timer=setTimeout(()=>{this.#u!==e||e.settled||(this.#g({type:`error`,id:e.id,message:`Run exceeded its wall-clock time limit.`,durationMs:e.options.timeoutMs}),this.#m())},e.options.timeoutMs)),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.compilerLanguage?{compilerLanguage:e.options.compilerLanguage}:{},...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-BQWrbSEp.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:()=>{clearTimeout(c.timer),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}),this.#u&&e.id===this.#u.id&&!this.#u.settled&&this.#u.options.onProgress?.({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.memory?{memory:e.memory}:{},...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?.(),e.options.timeoutMs&&Number.isFinite(e.options.timeoutMs)&&e.options.timeoutMs>0&&(e.timer=setTimeout(()=>{this.#u!==e||e.settled||(this.#g({type:`error`,id:e.id,message:`Run exceeded its wall-clock time limit.`,durationMs:e.options.timeoutMs}),this.#m())},e.options.timeoutMs)),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.compilerLanguage?{compilerLanguage:e.options.compilerLanguage}:{},...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};