code-playpad 0.13.0 → 0.14.1

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 (33) hide show
  1. package/README.md +97 -4
  2. package/dist/THIRD-PARTY-NOTICES.txt +50 -0
  3. package/dist/boot-DW1YzgCY.js +6 -0
  4. package/dist/boot-nmFndPHW.js +11 -0
  5. package/dist/cdn.js +2 -2
  6. package/dist/{compiler-B408qd3N.js → compiler-A2mqXrqO.js} +1 -1
  7. package/dist/compiler-D7kIFltD.js +13 -0
  8. package/dist/compiler-license-manifest.json +12 -0
  9. package/dist/{cpp-BVqJclgd.js → cpp-C8YnpTSR.js} +1 -1
  10. package/dist/{element-BGm-1VOq.js → element-BuS9dUwa.js} +22 -4
  11. package/dist/element.js +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/{java-BEvn335o.js → java-DkfYRvpA.js} +1 -1
  14. package/dist/{javascript-j4E_GxwK.js → javascript-BSjoEAXh.js} +1 -1
  15. package/dist/next-9Fyfv6iD.js +1 -0
  16. package/dist/next-CO6N0Gb9.js +6 -0
  17. package/dist/next-tailwind.generated-BWL5i33i.js +6 -0
  18. package/dist/next-vendor.generated-DcyCefTD.js +6 -0
  19. package/dist/{pyodide-BRw8SuuC.js → pyodide-ZBchw4qA.js} +1 -1
  20. package/dist/react-DI6SODv8.js +1 -0
  21. package/dist/react-DgCTfCMl.js +6 -0
  22. package/dist/react.js +1 -1
  23. package/dist/runtime/next/compiler.d.ts +29 -0
  24. package/dist/runtime/next-tailwind.generated.d.ts +1 -0
  25. package/dist/runtime/next-vendor.generated.d.ts +10 -0
  26. package/dist/runtime/next.d.ts +2 -0
  27. package/dist/runtime/preview-session.d.ts +34 -0
  28. package/dist/runtime/react/compiler.d.ts +26 -0
  29. package/dist/standalone.js +22 -4
  30. package/dist/{worker-runtime-Bk9bsGrP.js → worker-runtime-Dd2eBtq3.js} +1 -1
  31. package/package.json +8 -4
  32. package/dist/react-ALhWeEZ5.js +0 -9
  33. package/dist/react-uV_SMJrS.js +0 -4
package/README.md CHANGED
@@ -4,19 +4,19 @@
4
4
 
5
5
  Runnable code in any web page. A CodeMirror editor that **executes what it
6
6
  shows** — Python, JavaScript, TypeScript, a documented subset of Java,
7
- experimental C and C++, and multi-file React — entirely in the reader's browser. No backend, no sign-up.
7
+ experimental C and C++, multi-file React, and Next.js App Router projects — entirely in the reader's browser. No backend, no sign-up.
8
8
 
9
9
  **[Live demo →](https://code-playpad.swengr.com)**
10
10
 
11
11
  ```html
12
- <script type="module" src="https://cdn.jsdelivr.net/npm/code-playpad@0.13.0/dist/standalone.js"></script>
12
+ <script type="module" src="https://cdn.jsdelivr.net/npm/code-playpad@0.14.1/dist/standalone.js"></script>
13
13
 
14
14
  <code-playpad height="auto">
15
15
  print("hello from a static page")
16
16
  </code-playpad>
17
17
  ```
18
18
 
19
- **Contents** — [Languages](#languages) · [Experimental C/C++](#experimental-cc) · [React](#react)
19
+ **Contents** — [Languages](#languages) · [Experimental C/C++](#experimental-cc) · [React](#react) · [Next.js](#nextjs)
20
20
  · [Install](#install) · [Attributes](#attributes) · [Sizing](#sizing) · [Several files](#several-files) · [Input](#input)
21
21
  · [Controlling it from JavaScript](#controlling-it-from-javascript)
22
22
  · [Events and grading](#events-and-grading) · [Saving work](#saving-work)
@@ -33,6 +33,7 @@ experimental C and C++, and multi-file React — entirely in the reader's browse
33
33
  | `java` | A documented subset of Java 25, compiled and interpreted in a Worker by an engine built for this package — see [Java](#java) | nothing: the engine is a ~105 KB (gzipped) chunk of this package, loaded with the first Java widget, and its library a ~75 KB chunk loaded the first time a program uses it |
34
34
  | `c`, `cpp` | Experimental: C17 and C++20, compiled by a real Clang compiler in a Worker — see [Experimental C/C++](#experimental-cc) | ~30 MB on the first C/C++ Run, then cached |
35
35
  | `react` | A multi-file React project, rendered in a sandboxed preview with a console — see [React](#react) | nothing from another service: ~208 KB (gzipped) of this package's chunks, loaded with the first React widget |
36
+ | `next` | A Next.js App Router project, with server components and server actions running in a Worker in the sandboxed preview — see [Next.js](#nextjs) | nothing from another service: part of this package, loaded the first time a widget runs; Tailwind only for projects that use it |
36
37
 
37
38
  ```html
38
39
  <code-playpad height="auto">print("python is the default")</code-playpad>
@@ -321,6 +322,76 @@ import { configureReact } from 'code-playpad';
321
322
  configureReact({ runtimeURL: 'https://your-site.example/react-runtime-19.2.8.js' }); // before any widget runs
322
323
  ```
323
324
 
325
+ ## Next.js
326
+
327
+ `language="next"` runs a Next.js App Router project in the browser, with no server
328
+ and no build. A worker inside the widget's sandboxed frame plays the server, using
329
+ React's real server components packages, and the frame renders what it streams.
330
+
331
+ ```html
332
+ <code-playpad language="next" height="auto" preview-height="360" autorun>
333
+ <playpad-file name="app/page.tsx">
334
+ import { Counter } from './Counter';
335
+
336
+ export default async function Page() {
337
+ const start: number = await Promise.resolve(41);
338
+ return &lt;Counter start={start} />;
339
+ }
340
+ </playpad-file>
341
+ <playpad-file name="app/Counter.jsx">
342
+ 'use client';
343
+ import { useState } from 'react';
344
+
345
+ export function Counter({ start }) {
346
+ const [n, setN] = useState(start);
347
+ return &lt;button onClick={() => setN(n + 1)}>Count: {n}&lt;/button>;
348
+ }
349
+ </playpad-file>
350
+ </code-playpad>
351
+ ```
352
+
353
+ **This is not Next.js.** No code from the `next` package runs. The router and `next/*`
354
+ are this project's own, checked against recordings of real `next dev` 16.4.3 (run
355
+ `scripts/record-next.mjs` to record again). `entry` picks the page it opens at, and
356
+ the preview has an address bar, because a sandboxed frame has no URL to show.
357
+
358
+ | Works | |
359
+ |---|---|
360
+ | Files | `page`, `layout`, `template`, `loading`, `error`, `not-found`, `route` (`.js`, `.jsx`, `.ts`, `.tsx`), under `app/` or `src/app/`. A missing root layout is created, as `next dev` does |
361
+ | Routes | nested layouts, `[slug]`, `[...all]`, `[[...all]]`, `(groups)`, `@/` imports |
362
+ | Server | async server components, streaming with `loading`, `"use server"` files and inline actions, `cookies()`, `headers()`, `revalidatePath()`, `redirect()`, `notFound()`, route handlers (`fetch('/api/x')`), `metadata` and `generateMetadata` |
363
+ | Client | `"use client"`, `next/link`, `next/navigation` hooks, `next/image`, `next/dynamic` |
364
+ | Styles | global CSS, CSS Modules, Tailwind 4 (`@import "tailwindcss"`; its 75 KB gzipped only downloads for projects that use it) |
365
+
366
+ **What differs from real Next:**
367
+
368
+ - **There is no server rendering of client components.** A client component that reads
369
+ `window` while rendering works here but throws `window is not defined` in real Next,
370
+ and hydration errors never happen. Every page behaves as under `next dev`: nothing is
371
+ static or cached.
372
+ - **The sandbox stays.** `location.pathname` is `srcdoc`; `history.pushState` and
373
+ `localStorage` throw; `fetch` to other sites and remote images are blocked; only
374
+ `public/*.svg` is available to `next/image`, and only through `next/image`.
375
+ - **Only `react`, `react-dom` and `next/*` can be imported.** `next/font` keeps the
376
+ browser's default font.
377
+ - **Not available:** the `pages/` router (an error), `proxy`/middleware and parallel and
378
+ intercepting routes (a console warning), `use cache`, `unstable_cache`,
379
+ `generateStaticParams`, `useSelectedLayoutSegment`, `forbidden()`, `unauthorized()`,
380
+ `global-error`.
381
+ - **A plain `<a href="/x">` keeps client state.** Real Next does a full page load, which
382
+ loses it. `next/link` behaves the same in both.
383
+ - **Each Run is a server restart:** module state and cookies start over.
384
+ - **Not yet measured on a phone.** Desktop Chrome, Chromium, Firefox and WebKit pass the
385
+ browser suite.
386
+ - **Inline server actions keep their closures in memory.** Each declaration keeps its
387
+ newest 4,096; a form still holding an older one gets `Failed to find Server Action`.
388
+ - **Loops:** a loop running over 1 second without yielding throws, on either side.
389
+
390
+ A host page's CSP must allow everything [React previews need](#host-pages-with-a-csp),
391
+ plus `worker-src blob:` and `script-src blob:`. `configureReact({ nonce })` applies;
392
+ `runtimeURL` does not. The runtime is about 180 KB gzipped, on demand. A page with no
393
+ `language="next"` widget downloads none of it.
394
+
324
395
  ## Download size
325
396
 
326
397
  What a page downloads once a reader presses Run, with the CDN build, as
@@ -392,7 +463,7 @@ actually sent.
392
463
  ### From a CDN — nothing to install
393
464
 
394
465
  ```html
395
- <script type="module" src="https://cdn.jsdelivr.net/npm/code-playpad@0.13.0/dist/standalone.js"></script>
466
+ <script type="module" src="https://cdn.jsdelivr.net/npm/code-playpad@0.14.1/dist/standalone.js"></script>
396
467
  ```
397
468
 
398
469
  This is the `standalone` build: CodeMirror is bundled in, so a static blog post
@@ -1085,6 +1156,28 @@ checked by SHA-256, so another version fails. A different origin must allow CORS
1085
1156
 
1086
1157
  ## Version history
1087
1158
 
1159
+ ### 0.14.1
1160
+
1161
+ - **No changes to the widget or its runtimes.** This release moves the version in the
1162
+ CDN URLs alongside five new examples on the demo site's Next.js Labs page: streaming,
1163
+ search in the URL, cookies and redirects, optimistic updates, and active links with
1164
+ catch-all routes. There's no need to upgrade from 0.14.0.
1165
+
1166
+ ### 0.14.0
1167
+
1168
+ - **New `language="next"`:** run a Next.js App Router project in the browser, with no
1169
+ server. Server components, server actions, route handlers, layouts, `loading` and
1170
+ `error` files, `next/link` and `next/navigation` work, and a small address bar drives
1171
+ the app. No code from the `next` package runs: the router and `next/*` are this
1172
+ package's own, checked against recorded `next dev` 16.4.3. See [Next.js](#nextjs) for
1173
+ what differs. It has not been measured on a phone yet.
1174
+ - **`run()` resolves slightly later on preview languages,** React as well as Next.js:
1175
+ once the preview can take clicks, usually tens of milliseconds and at most about 250 ms.
1176
+ Chrome could send a click made right after a run to the host page instead of the
1177
+ preview. The reported duration and the run's outcome don't change.
1178
+ - **Fixed:** the widget's content moved up 2 pixels when a run finished, in every
1179
+ language. The progress bar now sits over the content.
1180
+
1088
1181
  ### 0.13.0
1089
1182
 
1090
1183
  - **React projects with a file tree now use two rows:** the tree and the code on top,
@@ -722,6 +722,31 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
722
722
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
723
723
  THE SOFTWARE.
724
724
 
725
+ ==============================================================================
726
+ @tailwindcss/browser 4.3.3 — MIT
727
+
728
+ MIT License
729
+
730
+ Copyright (c) Tailwind Labs, Inc.
731
+
732
+ Permission is hereby granted, free of charge, to any person obtaining a copy
733
+ of this software and associated documentation files (the "Software"), to deal
734
+ in the Software without restriction, including without limitation the rights
735
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
736
+ copies of the Software, and to permit persons to whom the Software is
737
+ furnished to do so, subject to the following conditions:
738
+
739
+ The above copyright notice and this permission notice shall be included in all
740
+ copies or substantial portions of the Software.
741
+
742
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
743
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
744
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
745
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
746
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
747
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
748
+ SOFTWARE.
749
+
725
750
  ==============================================================================
726
751
  acorn 8.15.0 — MIT
727
752
 
@@ -868,6 +893,31 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
868
893
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
869
894
  SOFTWARE.
870
895
 
896
+ ==============================================================================
897
+ react-server-dom-webpack 19.2.8 — MIT
898
+
899
+ MIT License
900
+
901
+ Copyright (c) Meta Platforms, Inc. and affiliates.
902
+
903
+ Permission is hereby granted, free of charge, to any person obtaining a copy
904
+ of this software and associated documentation files (the "Software"), to deal
905
+ in the Software without restriction, including without limitation the rights
906
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
907
+ copies of the Software, and to permit persons to whom the Software is
908
+ furnished to do so, subject to the following conditions:
909
+
910
+ The above copyright notice and this permission notice shall be included in all
911
+ copies or substantial portions of the Software.
912
+
913
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
914
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
915
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
916
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
917
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
918
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
919
+ SOFTWARE.
920
+
871
921
  ==============================================================================
872
922
  scheduler 0.27.0 — MIT
873
923
 
@@ -0,0 +1,6 @@
1
+ import{u as e}from"./element-BuS9dUwa.js";var t=5e3,n=4e3,r=65536,i=class{preview;payload;onRoute;#e=null;#t=null;#n=null;#r=null;#i=null;#a=!1;#o=null;#s=null;#c=``;#l=``;#u;#d=performance.now();#f=!1;#p=null;#m=null;constructor(e,t,n,r,i){this.preview=e,this.payload=t,this.onRoute=i,this.#i=n,this.#s=r}get live(){return this.#e!==null}send(e){this.#e?.contentWindow?.postMessage(e,`*`)}open(e,n=[]){let r=document.createElement(`iframe`);r.setAttribute(`sandbox`,`allow-scripts allow-forms`),r.setAttribute(`allow`,``),r.setAttribute(`referrerpolicy`,`no-referrer`),r.title=`Preview`,r.className=`cp-preview-frame`,r.srcdoc=e,this.#e=r,this.#t=this.preview.host.ownerDocument.defaultView??window,this.#t.addEventListener(`message`,this.#x),this.preview.host.replaceChildren(...n,r),this.#n=setTimeout(()=>{this.fail(`The preview did not start. A Content-Security-Policy on this page probably blocks it: see "Host pages with a CSP" in the README.`)},t)}fail(e,t={},n){this.#n&&clearTimeout(this.#n),this.#n=null,this.#v(e,t),this.#h(!0,n)}#h(e,t,n=e=>e()){let r=this.#i;this.#i=null,this.#s=null;let i={stdout:this.#c,...this.#l?{stderr:this.#l}:{},...t?{hint:t}:{},...e&&this.#u?{problem:this.#u}:{},durationMs:Math.round(performance.now()-this.#d),failed:e};n(()=>r?.(i))}#g=e=>{setTimeout(e,250),this.#o=()=>requestAnimationFrame(()=>requestAnimationFrame(e)),this.#a&&this.#o()};#_(e,t){this.#i&&(e===`warn`||e===`error`?this.#l+=`${t}\n`:this.#c+=`${t}\n`),this.preview.onConsole(e,t)}#v(e,t){let n=(t.file?`${t.file}${t.line?`:${t.line}`:``}${t.column?`:${t.column}`:``}: `:``)+e;this.#_(`error`,n),this.#y(n);let r={message:n,...t};this.#i?this.#u??=r:this.preview.onError(r)}#y(e){this.#p||(this.#p=document.createElement(`pre`),this.#p.className=`cp-preview-banner`,this.#p.setAttribute(`role`,`alert`),this.preview.host.append(this.#p)),this.#p.textContent=e}#b(e){this.#m||(this.#m=document.createElement(`div`),this.#m.className=`cp-preview-notice`,this.#m.setAttribute(`role`,`status`),this.preview.host.append(this.#m)),this.#m.textContent=e,this.#m.hidden=!1,this.#r&&clearTimeout(this.#r),this.#r=setTimeout(()=>{this.#m&&(this.#m.hidden=!0)},n)}showCompileBanner(e){e&&this.#p&&(this.#p.textContent+=`\n${e}`)}#x=e=>{if(!this.#e||e.source!==this.#e.contentWindow)return;let t=e.data;if(typeof t!=`object`||!t||t.__playpad!==1)return;let n=e=>String(e??``).slice(0,r);switch(t.type){case`booted`:if(this.#f)return;this.#f=!0,this.#n&&clearTimeout(this.#n),this.#n=null,this.preview.onStart?.(),e.ports[0]?.postMessage(this.payload);break;case`console`:{let e=t.level===`info`||t.level===`warn`||t.level===`error`?t.level:`log`;this.#_(e,n(t.text));break}case`error`:this.#v(n(t.message),{...typeof t.file==`string`?{file:t.file.slice(0,512)}:{},...typeof t.line==`number`?{line:t.line}:{}});break;case`fatal`:this.fail(n(t.message));break;case`entry-done`:this.#i&&this.#h(t.failed===!0,void 0,this.#g);break;case`drawn`:this.#a=!0,this.#o?.();break;case`render`:this.preview.onRender(n(t.rootText));break;case`route`:this.onRoute?.({url:n(t.url),canBack:t.canBack===!0,canForward:t.canForward===!0});break;case`alert`:this.#_(`info`,`alert: ${n(t.text)}`),this.#b(n(t.text))}};dispose(t){this.#n&&clearTimeout(this.#n),this.#r&&clearTimeout(this.#r),this.#t?.removeEventListener(`message`,this.#x),this.#e=null,this.preview.host.replaceChildren(),this.#s&&t&&this.#s(new e),this.#i=null,this.#s=null}},a=`(function(){var a=function(n,e){n.__playpad=1,parent.postMessage(n,"*",e||[])};function l(n,e){if(typeof n=="string")return n;if(typeof n=="function")return"[Function "+(n.name||"anonymous")+"]";if(typeof n!="object"||n===null)return String(n);if(n instanceof Error)return n.name+": "+n.message;if(n instanceof Node)return"<"+n.nodeName.toLowerCase()+">";try{return JSON.stringify(n)}catch{return String(n)}}function L(n){if(typeof n[0]!="string")return n.map(function(r){return l(r)}).join(" ");var e=1,i=n[0].replace(/%([sdifoOc%])/g,function(r,u){if(u==="%")return"%";if(e>=n.length)return r;var c=n[e++];return u==="c"?"":u==="d"||u==="i"?String(parseInt(c,10)):u==="f"?String(parseFloat(c)):l(c)});return[i].concat(n.slice(e).map(function(r){return l(r)})).join(" ")}["log","info","warn","error","debug"].forEach(function(n){var e=console[n];console[n]=function(){var i=Array.prototype.slice.call(arguments);a({type:"console",level:n==="debug"?"log":n,text:L(i)}),e.apply(console,i)}});function k(n){var e=/playpad-project\\/([^\\s:)]+):(\\d+)/.exec(n&&n.stack||"");return e?{file:e[1],line:Number(e[2])}:{}}function f(n,e){var i=n&&typeof n=="object"&&"message"in n,r=i&&n.name?n.name+": ":"",u=k(n);a({type:"error",message:e+r+(i?n.message:l(n)),file:u.file,line:u.line})}addEventListener("error",function(n){n.error?f(n.error,"Uncaught "):n.message==="Script error."?a({type:"error",message:"An error happened in the preview, but this browser hides its details. Open the browser's developer console to see it."}):f(n.message,"Uncaught ")}),window.reportError=function(n){f(n,"Uncaught ")};function M(n){return function(){try{return n.apply(this,arguments)}catch(e){f(e,"Uncaught ")}}}["setTimeout","setInterval","requestAnimationFrame","queueMicrotask"].forEach(function(n){var e=window[n];window[n]=function(i){var r=Array.prototype.slice.call(arguments);return typeof i=="function"&&(r[0]=M(i)),e.apply(window,r)}}),addEventListener("unhandledrejection",function(n){f(n.reason,"Unhandled promise rejection: ")}),window.alert=function(n){a({type:"alert",text:n===void 0?"":String(n)})},window.confirm=function(){return console.warn("confirm() cannot wait for an answer in this preview, so it returned true."),!0},window.prompt=function(){return console.warn("prompt() cannot wait for an answer in this preview, so it returned null."),null};var N=1e3,y=!1,_=0,v=0,b=new MessageChannel;b.port1.onmessage=function(){y=!1},window.__playpadLoopGuard=function(){if(!y){y=!0,_=performance.now(),v=0,b.port2.postMessage(0);return}if((++v&63)===0&&performance.now()-_>N)throw new Error("This loop ran for more than 1 second. Is it infinite?")};function O(n){var e=n.nonce;function i(o){e&&(o.nonce=e),document.head.appendChild(o)}function r(o){var d=document.createElement("script");d.textContent=o,i(d)}if(n.nextClient){if(window.__webpack_require__=function(o){return window.__playpadLoad(o)},window.__webpack_require__.u=function(){return""},window.__webpack_chunk_load__=function(){return Promise.resolve()},n.tailwind&&r(n.tailwind),r(n.nextClient),!window.__playpadNext){a({type:"fatal",message:"The preview could not run the Next.js runtime. A Content-Security-Policy on this page probably blocks it."});return}n.modules.forEach(function(o){o.kind==="js"&&r("__playpadDefine("+JSON.stringify(o.path)+",function(require,module,exports){"+o.text+\`
2
+ });
3
+ //# sourceURL=playpad-project/\`+o.path)}),window.__playpadNext.start(n,e);return}function u(){if(!window.__vendor){a({type:"fatal",message:"The preview could not run the React runtime. A Content-Security-Policy on this page probably blocks it."});return}var o={};window.__playpadDefine=function(t,s){o[t]=s};var d={};n.modules.forEach(function(t){d[t.path]=t,t.kind==="js"&&r("__playpadDefine("+JSON.stringify(t.path)+",function(require,module,exports){"+t.text+\`
4
+ });
5
+ //# sourceURL=playpad-project/\`+t.path)});var h={};function E(t){if(h[t])return h[t].exports;var s=d[t],w=h[t]={exports:{}};if(s.kind==="json")w.exports=JSON.parse(s.text);else if(s.kind==="css"){var m=document.createElement("style");e&&(m.nonce=e),m.dataset.file=t,m.textContent=s.text,document.head.appendChild(m)}else{if(!o[t])throw new Error("The file "+t+" could not be loaded.");o[t](function(p){if(window.__vendor[p])return window.__vendor[p];if(s.links[p])return E(s.links[p]);throw new Error('Cannot find "'+p+'" from '+t+".")},w,w.exports)}return w.exports}var g=document.getElementById("root");if(g){var S;new MutationObserver(function(){clearTimeout(S),S=setTimeout(function(){a({type:"render",rootText:g.textContent})},100)}).observe(g,{childList:!0,subtree:!0,characterData:!0})}var C=!1;try{n.entries.forEach(E)}catch(t){C=!0,f(t,"Uncaught ")}a({type:"entry-done",failed:C}),requestAnimationFrame(function(){requestAnimationFrame(function(){a({type:"drawn"})})})}if(n.vendor)r(n.vendor),u();else{var c=document.createElement("script");c.src=n.runtimeURL,c.onload=u,c.onerror=function(){a({type:"fatal",message:"The React runtime could not be loaded from "+n.runtimeURL+"."})},i(c)}}function x(){var n=new MessageChannel;n.port1.onmessage=function(e){n.port1.close(),O(e.data)},a({type:"booted"},[n.port2])}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",x):x()})();
6
+ `;export{i as n,a as t};
@@ -0,0 +1,11 @@
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{t as e}from"./types-CfcYqU2K.js";var t=5e3,n=4e3,r=65536,i=class{preview;payload;onRoute;#e=null;#t=null;#n=null;#r=null;#i=null;#a=!1;#o=null;#s=null;#c=``;#l=``;#u;#d=performance.now();#f=!1;#p=null;#m=null;constructor(e,t,n,r,i){this.preview=e,this.payload=t,this.onRoute=i,this.#i=n,this.#s=r}get live(){return this.#e!==null}send(e){this.#e?.contentWindow?.postMessage(e,`*`)}open(e,n=[]){let r=document.createElement(`iframe`);r.setAttribute(`sandbox`,`allow-scripts allow-forms`),r.setAttribute(`allow`,``),r.setAttribute(`referrerpolicy`,`no-referrer`),r.title=`Preview`,r.className=`cp-preview-frame`,r.srcdoc=e,this.#e=r,this.#t=this.preview.host.ownerDocument.defaultView??window,this.#t.addEventListener(`message`,this.#x),this.preview.host.replaceChildren(...n,r),this.#n=setTimeout(()=>{this.fail(`The preview did not start. A Content-Security-Policy on this page probably blocks it: see "Host pages with a CSP" in the README.`)},t)}fail(e,t={},n){this.#n&&clearTimeout(this.#n),this.#n=null,this.#v(e,t),this.#h(!0,n)}#h(e,t,n=e=>e()){let r=this.#i;this.#i=null,this.#s=null;let i={stdout:this.#c,...this.#l?{stderr:this.#l}:{},...t?{hint:t}:{},...e&&this.#u?{problem:this.#u}:{},durationMs:Math.round(performance.now()-this.#d),failed:e};n(()=>r?.(i))}#g=e=>{setTimeout(e,250),this.#o=()=>requestAnimationFrame(()=>requestAnimationFrame(e)),this.#a&&this.#o()};#_(e,t){this.#i&&(e===`warn`||e===`error`?this.#l+=`${t}\n`:this.#c+=`${t}\n`),this.preview.onConsole(e,t)}#v(e,t){let n=(t.file?`${t.file}${t.line?`:${t.line}`:``}${t.column?`:${t.column}`:``}: `:``)+e;this.#_(`error`,n),this.#y(n);let r={message:n,...t};this.#i?this.#u??=r:this.preview.onError(r)}#y(e){this.#p||(this.#p=document.createElement(`pre`),this.#p.className=`cp-preview-banner`,this.#p.setAttribute(`role`,`alert`),this.preview.host.append(this.#p)),this.#p.textContent=e}#b(e){this.#m||(this.#m=document.createElement(`div`),this.#m.className=`cp-preview-notice`,this.#m.setAttribute(`role`,`status`),this.preview.host.append(this.#m)),this.#m.textContent=e,this.#m.hidden=!1,this.#r&&clearTimeout(this.#r),this.#r=setTimeout(()=>{this.#m&&(this.#m.hidden=!0)},n)}showCompileBanner(e){e&&this.#p&&(this.#p.textContent+=`\n${e}`)}#x=e=>{if(!this.#e||e.source!==this.#e.contentWindow)return;let t=e.data;if(typeof t!=`object`||!t||t.__playpad!==1)return;let n=e=>String(e??``).slice(0,r);switch(t.type){case`booted`:if(this.#f)return;this.#f=!0,this.#n&&clearTimeout(this.#n),this.#n=null,this.preview.onStart?.(),e.ports[0]?.postMessage(this.payload);break;case`console`:{let e=t.level===`info`||t.level===`warn`||t.level===`error`?t.level:`log`;this.#_(e,n(t.text));break}case`error`:this.#v(n(t.message),{...typeof t.file==`string`?{file:t.file.slice(0,512)}:{},...typeof t.line==`number`?{line:t.line}:{}});break;case`fatal`:this.fail(n(t.message));break;case`entry-done`:this.#i&&this.#h(t.failed===!0,void 0,this.#g);break;case`drawn`:this.#a=!0,this.#o?.();break;case`render`:this.preview.onRender(n(t.rootText));break;case`route`:this.onRoute?.({url:n(t.url),canBack:t.canBack===!0,canForward:t.canForward===!0});break;case`alert`:this.#_(`info`,`alert: ${n(t.text)}`),this.#b(n(t.text))}};dispose(t){this.#n&&clearTimeout(this.#n),this.#r&&clearTimeout(this.#r),this.#t?.removeEventListener(`message`,this.#x),this.#e=null,this.preview.host.replaceChildren(),this.#s&&t&&this.#s(new e),this.#i=null,this.#s=null}},a=`(function(){var a=function(n,e){n.__playpad=1,parent.postMessage(n,"*",e||[])};function l(n,e){if(typeof n=="string")return n;if(typeof n=="function")return"[Function "+(n.name||"anonymous")+"]";if(typeof n!="object"||n===null)return String(n);if(n instanceof Error)return n.name+": "+n.message;if(n instanceof Node)return"<"+n.nodeName.toLowerCase()+">";try{return JSON.stringify(n)}catch{return String(n)}}function L(n){if(typeof n[0]!="string")return n.map(function(r){return l(r)}).join(" ");var e=1,i=n[0].replace(/%([sdifoOc%])/g,function(r,u){if(u==="%")return"%";if(e>=n.length)return r;var c=n[e++];return u==="c"?"":u==="d"||u==="i"?String(parseInt(c,10)):u==="f"?String(parseFloat(c)):l(c)});return[i].concat(n.slice(e).map(function(r){return l(r)})).join(" ")}["log","info","warn","error","debug"].forEach(function(n){var e=console[n];console[n]=function(){var i=Array.prototype.slice.call(arguments);a({type:"console",level:n==="debug"?"log":n,text:L(i)}),e.apply(console,i)}});function k(n){var e=/playpad-project\\/([^\\s:)]+):(\\d+)/.exec(n&&n.stack||"");return e?{file:e[1],line:Number(e[2])}:{}}function f(n,e){var i=n&&typeof n=="object"&&"message"in n,r=i&&n.name?n.name+": ":"",u=k(n);a({type:"error",message:e+r+(i?n.message:l(n)),file:u.file,line:u.line})}addEventListener("error",function(n){n.error?f(n.error,"Uncaught "):n.message==="Script error."?a({type:"error",message:"An error happened in the preview, but this browser hides its details. Open the browser's developer console to see it."}):f(n.message,"Uncaught ")}),window.reportError=function(n){f(n,"Uncaught ")};function M(n){return function(){try{return n.apply(this,arguments)}catch(e){f(e,"Uncaught ")}}}["setTimeout","setInterval","requestAnimationFrame","queueMicrotask"].forEach(function(n){var e=window[n];window[n]=function(i){var r=Array.prototype.slice.call(arguments);return typeof i=="function"&&(r[0]=M(i)),e.apply(window,r)}}),addEventListener("unhandledrejection",function(n){f(n.reason,"Unhandled promise rejection: ")}),window.alert=function(n){a({type:"alert",text:n===void 0?"":String(n)})},window.confirm=function(){return console.warn("confirm() cannot wait for an answer in this preview, so it returned true."),!0},window.prompt=function(){return console.warn("prompt() cannot wait for an answer in this preview, so it returned null."),null};var N=1e3,y=!1,_=0,v=0,b=new MessageChannel;b.port1.onmessage=function(){y=!1},window.__playpadLoopGuard=function(){if(!y){y=!0,_=performance.now(),v=0,b.port2.postMessage(0);return}if((++v&63)===0&&performance.now()-_>N)throw new Error("This loop ran for more than 1 second. Is it infinite?")};function O(n){var e=n.nonce;function i(o){e&&(o.nonce=e),document.head.appendChild(o)}function r(o){var d=document.createElement("script");d.textContent=o,i(d)}if(n.nextClient){if(window.__webpack_require__=function(o){return window.__playpadLoad(o)},window.__webpack_require__.u=function(){return""},window.__webpack_chunk_load__=function(){return Promise.resolve()},n.tailwind&&r(n.tailwind),r(n.nextClient),!window.__playpadNext){a({type:"fatal",message:"The preview could not run the Next.js runtime. A Content-Security-Policy on this page probably blocks it."});return}n.modules.forEach(function(o){o.kind==="js"&&r("__playpadDefine("+JSON.stringify(o.path)+",function(require,module,exports){"+o.text+\`
7
+ });
8
+ //# sourceURL=playpad-project/\`+o.path)}),window.__playpadNext.start(n,e);return}function u(){if(!window.__vendor){a({type:"fatal",message:"The preview could not run the React runtime. A Content-Security-Policy on this page probably blocks it."});return}var o={};window.__playpadDefine=function(t,s){o[t]=s};var d={};n.modules.forEach(function(t){d[t.path]=t,t.kind==="js"&&r("__playpadDefine("+JSON.stringify(t.path)+",function(require,module,exports){"+t.text+\`
9
+ });
10
+ //# sourceURL=playpad-project/\`+t.path)});var h={};function E(t){if(h[t])return h[t].exports;var s=d[t],w=h[t]={exports:{}};if(s.kind==="json")w.exports=JSON.parse(s.text);else if(s.kind==="css"){var m=document.createElement("style");e&&(m.nonce=e),m.dataset.file=t,m.textContent=s.text,document.head.appendChild(m)}else{if(!o[t])throw new Error("The file "+t+" could not be loaded.");o[t](function(p){if(window.__vendor[p])return window.__vendor[p];if(s.links[p])return E(s.links[p]);throw new Error('Cannot find "'+p+'" from '+t+".")},w,w.exports)}return w.exports}var g=document.getElementById("root");if(g){var S;new MutationObserver(function(){clearTimeout(S),S=setTimeout(function(){a({type:"render",rootText:g.textContent})},100)}).observe(g,{childList:!0,subtree:!0,characterData:!0})}var C=!1;try{n.entries.forEach(E)}catch(t){C=!0,f(t,"Uncaught ")}a({type:"entry-done",failed:C}),requestAnimationFrame(function(){requestAnimationFrame(function(){a({type:"drawn"})})})}if(n.vendor)r(n.vendor),u();else{var c=document.createElement("script");c.src=n.runtimeURL,c.onload=u,c.onerror=function(){a({type:"fatal",message:"The React runtime could not be loaded from "+n.runtimeURL+"."})},i(c)}}function x(){var n=new MessageChannel;n.port1.onmessage=function(e){n.port1.close(),O(e.data)},a({type:"booted"},[n.port2])}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",x):x()})();
11
+ `;export{i as n,a as t};
package/dist/cdn.js CHANGED
@@ -1,2 +1,2 @@
1
- /*! code-playpad 0.13.0: CDN entry, loads dist/standalone.js of this exact version */
2
- export * from "https://cdn.jsdelivr.net/npm/code-playpad@0.13.0/dist/standalone.js";
1
+ /*! code-playpad 0.14.1: CDN entry, loads dist/standalone.js of this exact version */
2
+ export * from "https://cdn.jsdelivr.net/npm/code-playpad@0.14.1/dist/standalone.js";
@@ -148,4 +148,4 @@ ${t.map(({variableName:e,uniqueLocalName:t})=>` reactHotLoader.register(${e}, "
148
148
  })();`}process(){return!1}},ud=/* @__PURE__ */ new Set(/* @__PURE__ */ `break.case.catch.class.const.continue.debugger.default.delete.do.else.export.extends.finally.for.function.if.import.in.instanceof.new.return.super.switch.this.throw.try.typeof.var.void.while.with.yield.enum.implements.interface.let.package.private.protected.public.static.await.false.null.true`.split(`.`));function dd(e){if(e.length===0||!Qn[e.charCodeAt(0)])return!1;for(let t=1;t<e.length;t++)if(!Zn[e.charCodeAt(t)])return!1;return!ud.has(e)}var fd=class extends Kr{constructor(e,t,n){super(),this.rootTransformer=e,this.tokens=t,this.isImportsTransformEnabled=n}process(){return this.rootTransformer.processPossibleArrowParamEnd()||this.rootTransformer.processPossibleAsyncArrowWithTypeParams()||this.rootTransformer.processPossibleTypeRange()?!0:this.tokens.matches1(O._public)||this.tokens.matches1(O._protected)||this.tokens.matches1(O._private)||this.tokens.matches1(O._abstract)||this.tokens.matches1(O._readonly)||this.tokens.matches1(O._override)||this.tokens.matches1(O.nonNullAssertion)?(this.tokens.removeInitialToken(),!0):this.tokens.matches1(O._enum)||this.tokens.matches2(O._const,O._enum)?(this.processEnum(),!0):this.tokens.matches2(O._export,O._enum)||this.tokens.matches3(O._export,O._const,O._enum)?(this.processEnum(!0),!0):!1}processEnum(e=!1){for(this.tokens.removeInitialToken();this.tokens.matches1(O._const)||this.tokens.matches1(O._enum);)this.tokens.removeToken();let t=this.tokens.identifierName();this.tokens.removeToken(),e&&!this.isImportsTransformEnabled&&this.tokens.appendCode(`export `),this.tokens.appendCode(`var ${t}; (function (${t})`),this.tokens.copyExpectedToken(O.braceL),this.processEnumBody(t),this.tokens.copyExpectedToken(O.braceR),e&&this.isImportsTransformEnabled?this.tokens.appendCode(`)(${t} || (exports.${t} = ${t} = {}));`):this.tokens.appendCode(`)(${t} || (${t} = {}));`)}processEnumBody(e){let t=null;for(;!this.tokens.matches1(O.braceR);){let{nameStringCode:n,variableName:r}=this.extractEnumKeyInfo(this.tokens.currentToken());this.tokens.removeInitialToken(),this.tokens.matches3(O.eq,O.string,O.comma)||this.tokens.matches3(O.eq,O.string,O.braceR)?this.processStringLiteralEnumMember(e,n,r):this.tokens.matches1(O.eq)?this.processExplicitValueEnumMember(e,n,r):this.processImplicitValueEnumMember(e,n,r,t),this.tokens.matches1(O.comma)&&this.tokens.removeToken(),t=r??`${e}[${n}]`}}extractEnumKeyInfo(e){if(e.type===O.name){let t=this.tokens.identifierNameForToken(e);return{nameStringCode:`"${t}"`,variableName:dd(t)?t:null}}if(e.type===O.string){let t=this.tokens.stringValueForToken(e);return{nameStringCode:this.tokens.code.slice(e.start,e.end),variableName:dd(t)?t:null}}throw Error(`Expected name or string at beginning of enum element.`)}processStringLiteralEnumMember(e,t,n){n==null?(this.tokens.appendCode(`${e}[${t}]`),this.tokens.copyToken(),this.tokens.copyToken(),this.tokens.appendCode(`;`)):(this.tokens.appendCode(`const ${n}`),this.tokens.copyToken(),this.tokens.copyToken(),this.tokens.appendCode(`; ${e}[${t}] = ${n};`))}processExplicitValueEnumMember(e,t,n){let r=this.tokens.currentToken().rhsEndIndex;if(r==null)throw Error(`Expected rhsEndIndex on enum assign.`);if(n!=null){for(this.tokens.appendCode(`const ${n}`),this.tokens.copyToken();this.tokens.currentIndex()<r;)this.rootTransformer.processToken();this.tokens.appendCode(`; ${e}[${e}[${t}] = ${n}] = ${t};`)}else{for(this.tokens.appendCode(`${e}[${e}[${t}]`),this.tokens.copyToken();this.tokens.currentIndex()<r;)this.rootTransformer.processToken();this.tokens.appendCode(`] = ${t};`)}}processImplicitValueEnumMember(e,t,n,r){let i=r==null?`0`:`${r} + 1`;n!=null&&(this.tokens.appendCode(`const ${n} = ${i}; `),i=n),this.tokens.appendCode(`${e}[${e}[${t}] = ${i}] = ${t};`)}},pd=class e{__init(){this.transformers=[]}__init2(){this.generatedVariables=[]}constructor(t,n,r,i){e.prototype.__init.call(this),e.prototype.__init2.call(this),this.nameManager=t.nameManager,this.helperManager=t.helperManager;let{tokenProcessor:a,importProcessor:o}=t;this.tokens=a,this.isImportsTransformEnabled=n.includes(`imports`),this.isReactHotLoaderTransformEnabled=n.includes(`react-hot-loader`),this.disableESTransforms=!!i.disableESTransforms,i.disableESTransforms||(this.transformers.push(new sd(a,this.nameManager)),this.transformers.push(new ad(a)),this.transformers.push(new od(a,this.nameManager))),n.includes(`jsx`)&&(i.jsxRuntime!==`preserve`&&this.transformers.push(new qr(this,a,o,this.nameManager,i)),this.transformers.push(new cd(this,a,o,i)));let s=null;if(n.includes(`react-hot-loader`)){if(!i.filePath)throw Error(`filePath is required when using the react-hot-loader transform.`);s=new ld(a,i.filePath),this.transformers.push(s)}if(n.includes(`imports`)){if(o===null)throw Error(`Expected non-null importProcessor with imports transform enabled.`);this.transformers.push(new Qu(this,a,o,this.nameManager,this.helperManager,s,r,!!i.enableLegacyTypeScriptModuleInterop,n.includes(`typescript`),n.includes(`flow`),!!i.preserveDynamicImport,!!i.keepUnusedImports))}else this.transformers.push(new $u(a,this.nameManager,this.helperManager,s,n.includes(`typescript`),n.includes(`flow`),!!i.keepUnusedImports,i));n.includes(`flow`)&&this.transformers.push(new ed(this,a,n.includes(`imports`))),n.includes(`typescript`)&&this.transformers.push(new fd(this,a,n.includes(`imports`))),n.includes(`jest`)&&this.transformers.push(new id(this,a,this.nameManager,o))}transform(){this.tokens.reset(),this.processBalancedCode();let e=this.isImportsTransformEnabled?`"use strict";`:``;for(let t of this.transformers)e+=t.getPrefixCode();e+=this.helperManager.emitHelpers(),e+=this.generatedVariables.map(e=>` var ${e};`).join(``);for(let t of this.transformers)e+=t.getHoistedCode();let t=``;for(let e of this.transformers)t+=e.getSuffixCode();let n=this.tokens.finish(),{code:r}=n;if(r.startsWith(`#!`)){let i=r.indexOf(`
149
149
  `);return i===-1&&(i=r.length,r+=`
150
150
  `),{code:r.slice(0,i+1)+e+r.slice(i+1)+t,mappings:this.shiftMappings(n.mappings,e.length)}}return{code:e+r+t,mappings:this.shiftMappings(n.mappings,e.length)}}processBalancedCode(){let e=0,t=0;for(;!this.tokens.isAtEnd();){if(this.tokens.matches1(O.braceL)||this.tokens.matches1(O.dollarBraceL))e++;else if(this.tokens.matches1(O.braceR)){if(e===0)return;e--}if(this.tokens.matches1(O.parenL))t++;else if(this.tokens.matches1(O.parenR)){if(t===0)return;t--}this.processToken()}}processToken(){if(this.tokens.matches1(O._class))this.processClass();else{for(let e of this.transformers)if(e.process())return;this.tokens.copyToken()}}processNamedClass(){if(!this.tokens.matches2(O._class,O.name))throw Error(`Expected identifier for exported class name.`);let e=this.tokens.identifierNameAtIndex(this.tokens.currentIndex()+1);return this.processClass(),e}processClass(){let e=Bu(this,this.tokens,this.nameManager,this.disableESTransforms),t=(e.headerInfo.isExpression||!e.headerInfo.className)&&e.staticInitializerNames.length+e.instanceInitializerNames.length>0,n=e.headerInfo.className;t&&(n=this.nameManager.claimFreeName(`_class`),this.generatedVariables.push(n),this.tokens.appendCode(` (${n} =`));let r=this.tokens.currentToken().contextId;if(r==null)throw Error(`Expected class to have a context ID.`);for(this.tokens.copyExpectedToken(O._class);!this.tokens.matchesContextIdAndLabel(O.braceL,r);)this.processToken();this.processClassBody(e,n);let i=e.staticInitializerNames.map(e=>`${n}.${e}()`);t?this.tokens.appendCode(`, ${i.map(e=>`${e}, `).join(``)}${n})`):e.staticInitializerNames.length>0&&this.tokens.appendCode(` ${i.map(e=>`${e};`).join(` `)}`)}processClassBody(e,t){let{headerInfo:n,constructorInsertPos:r,constructorInitializerStatements:i,fields:a,instanceInitializerNames:o,rangesToRemove:s}=e,c=0,l=0,u=this.tokens.currentToken().contextId;if(u==null)throw Error(`Expected non-null context ID on class.`);this.tokens.copyExpectedToken(O.braceL),this.isReactHotLoaderTransformEnabled&&this.tokens.appendCode(`__reactstandin__regenerateByEval(key, code) {this[key] = eval(code);}`);let d=i.length+o.length>0;if(r===null&&d){let e=this.makeConstructorInitCode(i,o,t);if(n.hasSuperclass){let t=this.nameManager.claimFreeName(`args`);this.tokens.appendCode(`constructor(...${t}) { super(...${t}); ${e}; }`)}else this.tokens.appendCode(`constructor() { ${e}; }`)}for(;!this.tokens.matchesContextIdAndLabel(O.braceR,u);)if(c<a.length&&this.tokens.currentIndex()===a[c].start){let e=!1;for(this.tokens.matches1(O.bracketL)?this.tokens.copyTokenWithPrefix(`${a[c].initializerName}() {this`):this.tokens.matches1(O.string)||this.tokens.matches1(O.num)?(this.tokens.copyTokenWithPrefix(`${a[c].initializerName}() {this[`),e=!0):this.tokens.copyTokenWithPrefix(`${a[c].initializerName}() {this.`);this.tokens.currentIndex()<a[c].end;)e&&this.tokens.currentIndex()===a[c].equalsIndex&&this.tokens.appendCode(`]`),this.processToken();this.tokens.appendCode(`}`),c++}else if(l<s.length&&this.tokens.currentIndex()>=s[l].start){for(this.tokens.currentIndex()<s[l].end&&this.tokens.removeInitialToken();this.tokens.currentIndex()<s[l].end;)this.tokens.removeToken();l++}else this.tokens.currentIndex()===r&&(this.tokens.copyToken(),d&&this.tokens.appendCode(`;${this.makeConstructorInitCode(i,o,t)};`)),this.processToken();this.tokens.copyExpectedToken(O.braceR)}makeConstructorInitCode(e,t,n){return[...e,...t.map(e=>`${n}.prototype.${e}.call(this)`)].join(`;`)}processPossibleArrowParamEnd(){if(this.tokens.matches2(O.parenR,O.colon)&&this.tokens.tokenAtRelativeIndex(1).isType){let e=this.tokens.currentIndex()+1;for(;this.tokens.tokens[e].isType;)e++;if(this.tokens.matches1AtIndex(e,O.arrow)){for(this.tokens.removeInitialToken();this.tokens.currentIndex()<e;)this.tokens.removeToken();return this.tokens.replaceTokenTrimmingLeftWhitespace(`) =>`),!0}}return!1}processPossibleAsyncArrowWithTypeParams(){if(!this.tokens.matchesContextual(D._async)&&!this.tokens.matches1(O._async))return!1;let e=this.tokens.tokenAtRelativeIndex(1);if(e.type!==O.lessThan||!e.isType)return!1;let t=this.tokens.currentIndex()+1;for(;this.tokens.tokens[t].isType;)t++;if(this.tokens.matches1AtIndex(t,O.parenL)){for(this.tokens.replaceToken(`async (`),this.tokens.removeInitialToken();this.tokens.currentIndex()<t;)this.tokens.removeToken();return this.tokens.removeToken(),this.processBalancedCode(),this.processToken(),!0}return!1}processPossibleTypeRange(){if(this.tokens.currentToken().isType){for(this.tokens.removeInitialToken();this.tokens.currentToken().isType;)this.tokens.removeToken();return!0}return!1}shiftMappings(e,t){for(let n=0;n<e.length;n++){let r=e[n];r!==void 0&&(e[n]=r+t)}return e}};u(kn());function md(e){let t=/* @__PURE__ */ new Set;for(let n=0;n<e.tokens.length;n++)e.matches1AtIndex(n,O._import)&&!e.matches3AtIndex(n,O._import,O.name,O.eq)&&hd(e,n,t);return t}function hd(e,t,n){t++,!e.matches1AtIndex(t,O.parenL)&&(e.matches1AtIndex(t,O.name)&&(n.add(e.identifierNameAtIndex(t)),t++,e.matches1AtIndex(t,O.comma)&&t++),e.matches1AtIndex(t,O.star)&&(t+=2,n.add(e.identifierNameAtIndex(t)),t++),e.matches1AtIndex(t,O.braceL)&&(t++,gd(e,t,n)))}function gd(e,t,n){for(;;){if(e.matches1AtIndex(t,O.braceR))return;let r=Vr(e,t);if(t=r.endIndex,r.isType||n.add(r.rightName),e.matches2AtIndex(t,O.comma,O.braceR)||e.matches1AtIndex(t,O.braceR))return;if(e.matches1AtIndex(t,O.comma))t++;else throw Error(`Unexpected token: ${JSON.stringify(e.tokens[t])}`)}}function _d(e,t){qi(t);try{let n=vd(e,t),r=new pd(n,t.transforms,!!t.enableLegacyBabel5ModuleInterop,t).transform(),i={code:r.code};if(t.sourceMapOptions){if(!t.filePath)throw Error(`filePath must be specified when generating a source map.`);i={...i,sourceMap:Pi(r,t.filePath,t.sourceMapOptions,e,n.tokenProcessor.tokens)}}return i}catch(e){throw t.filePath&&(e.message=`Error transforming ${t.filePath}: ${e.message}`),e}}function vd(e,t){let n=t.transforms.includes(`jsx`),r=t.transforms.includes(`typescript`),i=t.transforms.includes(`flow`),a=t.disableESTransforms===!0,o=Lu(e,n,r,i),s=o.tokens,c=o.scopes,l=new Ui(e,s),u=new Li(l),d=new zu(e,s,i,a,u),f=!!t.enableLegacyTypeScriptModuleInterop,p=null;return t.transforms.includes(`imports`)?(p=new ni(l,d,f,t,t.transforms.includes(`typescript`),!!t.keepUnusedImports,u),p.preprocessTokens(),Ri(d,c,p.getGlobalNames()),t.transforms.includes(`typescript`)&&!t.keepUnusedImports&&p.pruneTypeOnlyImports()):t.transforms.includes(`typescript`)&&!t.keepUnusedImports&&Ri(d,c,md(d)),{tokenProcessor:d,scopes:c,nameManager:l,importProcessor:p,helperManager:u}}var yd=x.extend((0,An.default)()),bd=[`react`,`react-dom/client`,`react/jsx-runtime`,`react/jsx-dev-runtime`],xd=`__playpadLoopGuard`,Sd=class extends Error{file;reason;line;column;hint;constructor(e,t,n,r,i){super(`${e}${n?`:${n}${r?`:${r}`:``}`:``}: ${t}`),this.file=e,this.reason=t,this.line=n,this.column=r,this.hint=i,this.name=`CompileError`}},Cd=e=>typeof e==`object`&&!!e&&typeof e.type==`string`;function wd(e,t){t(e);for(let n of Object.keys(e)){let r=e[n];if(Array.isArray(r))for(let e of r)Cd(e)&&wd(e,t);else Cd(r)&&wd(r,t)}}var Td=`Two JSX elements side by side need a parent. Wrap them in one element or in <>...</>.`,Ed=`A tag isn't closed. Tags with no children close themselves: <img />, <br />, <input />.`,Dd=`An opening tag and its closing tag don't match. Check the spelling and the nesting order.`,Od=`JSX comments are written {/* like this */}, not <!-- like this -->.`;function kd(e,t,n){if(n&&t.split(`
151
- `)[n-1]?.includes(`<!--`))return Od;if(/Adjacent JSX elements|Unterminated regular expression/.test(e))return Td;if(/Unterminated JSX contents/.test(e))return Ed;if(/Expected corresponding JSX closing tag/.test(e))return Dd}var Ad=e=>({transforms:[`jsx`,`imports`],jsxRuntime:`automatic`,production:!1,filePath:e});function jd(e,t,n,r,i){return new Sd(e,n,r,i,kd(n,t,r))}function Md(e,t,n){let r=String(n.message??n).replace(/^Error transforming [^:]+: /,``),i=/\s*\((\d+):(\d+)\)\s*$/.exec(r);return jd(e,t,i?r.slice(0,i.index):r,i?Number(i[1]):void 0,i?Number(i[2]):void 0)}function Nd(e,t){try{return yd.parse(t,{ecmaVersion:`latest`,sourceType:`module`,locations:!0,allowHashBang:!0})}catch(n){try{_d(t,Ad(e))}catch(n){if(/Unterminated JSX contents/.test(String(n.message)))throw Md(e,t,n)}let r=n;throw jd(e,t,r.message.replace(/\s*\(\d+:\d+\)\s*$/,``),r.loc?.line,r.loc?r.loc.column+1:void 0)}}function Pd(e,t){let n=[],r=`${xd}();`;wd(t,e=>{if(!/^(While|DoWhile|For|ForIn|ForOf)Statement$/.test(e.type))return;let t=e.body;t.type===`BlockStatement`?n.push({at:t.start+1,text:r}):n.push({at:t.start,text:`{${r}`},{at:t.end,text:`}`})});let i=e;for(let{at:e,text:t}of n.sort((e,t)=>t.at-e.at))i=i.slice(0,e)+t+i.slice(e);return i}function Fd(e){let t=[],n=e=>{Cd(e)&&e.type===`Literal`&&typeof e.value==`string`&&t.push({spec:e.value,node:e})};return wd(e,e=>{switch(e.type){case`ImportDeclaration`:case`ExportNamedDeclaration`:case`ExportAllDeclaration`:case`ImportExpression`:n(e.source);break;case`CallExpression`:e.callee.type===`Identifier`&&e.callee.name===`require`&&n(e.arguments[0])}}),t}function Id(e,t,n){let r=n.startsWith(`/`)?[]:t.split(`/`).slice(0,-1);for(let e of n.split(`/`))if(e!==``&&e!==`.`){if(e===`..`){if(!r.length)return;r.pop()}else r.push(e)}let i=r.join(`/`);return[i,`${i}.jsx`,`${i}.js`,`${i}/index.jsx`,`${i}/index.js`].find(t=>Object.hasOwn(e,t))}function Ld(e,t,n,r){let i=Nd(e,t);wd(i,t=>{if(t.type===`MetaProperty`&&t.meta.name===`import`)throw new Sd(e,`import.meta is not available here.`,t.loc.start.line,t.loc.start.column+1)});let a={};for(let{spec:t,node:o}of Fd(i)){let{line:i,column:s}=o.loc.start;if(t.startsWith(`.`)||t.startsWith(`/`)){let o=Id(n,e,t);if(!o)throw new Sd(e,`Cannot find the file "${t}". Check the spelling and the folder.`,i,s+1);a[t]=o,r.push(o)}else if(!bd.includes(t))throw new Sd(e,`The package "${t}" is not available here. Only react and react-dom/client can be imported.`,i,s+1)}try{return{path:e,kind:`js`,text:_d(Pd(t,i),Ad(e)).code,links:a}}catch(n){throw Md(e,t,n)}}function Rd(e,t){let n=/* @__PURE__ */ new Map,r=[...t];for(;r.length;){let t=r.shift();if(n.has(t))continue;let i=e[t]??``;if(/\.(jsx?|mjs)$/.test(t))n.set(t,Ld(t,i,e,r));else if(t.endsWith(`.css`))n.set(t,{path:t,kind:`css`,text:i,links:{}});else if(t.endsWith(`.json`)){try{JSON.parse(i)}catch(e){throw new Sd(t,`This file is not valid JSON: ${e.message}`)}n.set(t,{path:t,kind:`json`,text:i,links:{}})}else throw new Sd(t,`This kind of file cannot be imported here. A project can import .js, .jsx, .css and .json files.`)}return[...n.values()]}export{Sd as CompileError,xd as LOOP_GUARD,bd as REACT_PACKAGES,Rd as compileProject,Id as resolveImport};
151
+ `)[n-1]?.includes(`<!--`))return Od;if(/Adjacent JSX elements|Unterminated regular expression/.test(e))return Td;if(/Unterminated JSX contents/.test(e))return Ed;if(/Expected corresponding JSX closing tag/.test(e))return Dd}var Ad=e=>({transforms:[`jsx`,`imports`],jsxRuntime:`automatic`,production:!1,filePath:e});function jd(e,t,n,r,i){return new Sd(e,n,r,i,kd(n,t,r))}function Md(e,t,n){let r=String(n.message??n).replace(/^Error transforming [^:]+: /,``),i=/\s*\((\d+):(\d+)\)\s*$/.exec(r);return jd(e,t,i?r.slice(0,i.index):r,i?Number(i[1]):void 0,i?Number(i[2]):void 0)}function Nd(e,t){try{return yd.parse(t,{ecmaVersion:`latest`,sourceType:`module`,locations:!0,allowHashBang:!0})}catch(n){try{_d(t,Ad(e))}catch(n){if(/Unterminated JSX contents/.test(String(n.message)))throw Md(e,t,n)}let r=n;throw jd(e,t,r.message.replace(/\s*\(\d+:\d+\)\s*$/,``),r.loc?.line,r.loc?r.loc.column+1:void 0)}}function Pd(e){let t=[],n=`${xd}();`;return wd(e,e=>{if(!/^(While|DoWhile|For|ForIn|ForOf)Statement$/.test(e.type))return;let r=e.body;r.type===`BlockStatement`?t.push({at:r.start+1,text:n}):t.push({at:r.start,text:`{${n}`},{at:r.end,text:`}`})}),t}function Fd(e,t){let n=e;for(let{at:e,text:r}of[...t].sort((e,t)=>t.at-e.at))n=n.slice(0,e)+r+n.slice(e);return n}function Id(e,t){return Fd(e,Pd(t))}function Ld(e){let t=[],n=e=>{Cd(e)&&e.type===`Literal`&&typeof e.value==`string`&&t.push({spec:e.value,node:e})};return wd(e,e=>{switch(e.type){case`ImportDeclaration`:case`ExportNamedDeclaration`:case`ExportAllDeclaration`:case`ImportExpression`:n(e.source);break;case`CallExpression`:e.callee.type===`Identifier`&&e.callee.name===`require`&&n(e.arguments[0])}}),t}function Rd(e,t,n){let r=n.startsWith(`/`)?[]:t.split(`/`).slice(0,-1);for(let e of n.split(`/`))if(e!==``&&e!==`.`){if(e===`..`){if(!r.length)return;r.pop()}else r.push(e)}let i=r.join(`/`);return[i,`${i}.jsx`,`${i}.js`,`${i}/index.jsx`,`${i}/index.js`].find(t=>Object.hasOwn(e,t))}function zd(e,t,n,r){let i=Nd(e,t);wd(i,t=>{if(t.type===`MetaProperty`&&t.meta.name===`import`)throw new Sd(e,`import.meta is not available here.`,t.loc.start.line,t.loc.start.column+1)});let a={};for(let{spec:t,node:o}of Ld(i)){let{line:i,column:s}=o.loc.start;if(t.startsWith(`.`)||t.startsWith(`/`)){let o=Rd(n,e,t);if(!o)throw new Sd(e,`Cannot find the file "${t}". Check the spelling and the folder.`,i,s+1);a[t]=o,r.push(o)}else if(!bd.includes(t))throw new Sd(e,`The package "${t}" is not available here. Only react and react-dom/client can be imported.`,i,s+1)}try{return{path:e,kind:`js`,text:_d(Id(t,i),Ad(e)).code,links:a}}catch(n){throw Md(e,t,n)}}function Bd(e,t){let n=/* @__PURE__ */ new Map,r=[...t];for(;r.length;){let t=r.shift();if(n.has(t))continue;let i=e[t]??``;if(/\.(jsx?|mjs)$/.test(t))n.set(t,zd(t,i,e,r));else if(t.endsWith(`.css`))n.set(t,{path:t,kind:`css`,text:i,links:{}});else if(t.endsWith(`.json`)){try{JSON.parse(i)}catch(e){throw new Sd(t,`This file is not valid JSON: ${e.message}`)}n.set(t,{path:t,kind:`json`,text:i,links:{}})}else throw new Sd(t,`This kind of file cannot be imported here. A project can import .js, .jsx, .css and .json files.`)}return[...n.values()]}export{Sd as CompileError,xd as LOOP_GUARD,bd as REACT_PACKAGES,Fd as applyInserts,Bd as compileProject,Cd as isNode,Pd as loopGuardInserts,Nd as parseModule,Rd as resolveImport,Md as sucraseError,_d as t,wd as walk};
@@ -0,0 +1,13 @@
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{CompileError as e,applyInserts as t,loopGuardInserts as n,parseModule as r,sucraseError as i,t as a,walk as o}from"./compiler-A2mqXrqO.js";var s=[`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`,`next/navigation`,`next/link`,`next/image`,`next/script`,`next/dynamic`,`next/font/google`,`next/font/local`],c=[...s,`next/headers`,`next/cache`,`next/server`,`server-only`],l=[...s,`client-only`],u=[`next/headers`,`server-only`],d=[`useState`,`useEffect`,`useLayoutEffect`,`useReducer`,`useRef`,`useContext`,`useTransition`,`useDeferredValue`,`useOptimistic`,`useActionState`,`useImperativeHandle`,`useInsertionEffect`,`useSyncExternalStore`],f=/^(src\/)?app\/(.*\/)?(page|layout|loading|error|not-found|template|route)\.(jsx?|tsx?)$/,p=/^(src\/)?app\/layout\.(jsx?|tsx?)$/,m=/\.(jsx?|mjs|tsx?)$/,h=`export default function RootLayout({ children }) {
7
+ return (
8
+ <html lang="en">
9
+ <body>{children}</body>
10
+ </html>
11
+ );
12
+ }
13
+ `;function g(e,t){try{return e.endsWith(`.tsx`)?a(t,{transforms:[`typescript`,`jsx`],jsxRuntime:`preserve`,disableESTransforms:!0,filePath:e}).code:e.endsWith(`.ts`)?a(t,{transforms:[`typescript`],disableESTransforms:!0,filePath:e}).code:t}catch(n){throw i(e,t,n)}}function _(e,t,n){let r=n.startsWith(`@/`),i=r?n.slice(2):n,a=t=>{let n=[...t];for(let e of i.split(`/`))if(e!==``&&e!==`.`){if(e===`..`){if(!n.length)return;n.pop()}else n.push(e)}let r=n.join(`/`),a=[`.tsx`,`.ts`,`.jsx`,`.js`,`.mjs`];return[r,...a.map(e=>r+e),...a.map(e=>`${r}/index${e}`)].find(t=>Object.hasOwn(e,t))};return r?a([])??a([`src`]):a(n.startsWith(`/`)?[]:t.split(`/`).slice(0,-1))}function v(s,c){let l=g(c,s[c]),u=r(c,l),d=null;for(let e of u.body){if(e.type!==`ExpressionStatement`||typeof e.directive!=`string`)break;e.directive===`use client`&&(d=`client`),e.directive===`use server`&&(d=`server`)}let f=[],p=[],m=n(u),h=0;o(u,t=>{let n=t.source;if(/^(ImportDeclaration|ExportNamedDeclaration|ExportAllDeclaration|ImportExpression)$/.test(t.type)&&n&&typeof n.value==`string`){if(t.type===`ExportAllDeclaration`&&d===`server`)throw new e(c,`Only async functions are allowed to be exported in a "use server" file.`,t.loc.start.line,t.loc.start.column+1);f.push({spec:n.value,node:t})}if(t.type===`ExportDefaultDeclaration`&&p.push(`default`),t.type===`ExportNamedDeclaration`){for(let e of t.specifiers??[])p.push(e.exported.name);let e=t.declaration,n=e?.id;n&&p.push(n.name);for(let t of e?.declarations??[]){let e=t.id;e.type===`Identifier`&&p.push(e.name)}}let r=t.body;if(d!==`server`&&/^(FunctionDeclaration|FunctionExpression|ArrowFunctionExpression)$/.test(t.type)&&r?.type===`BlockStatement`&&r.body[0]?.directive===`use server`){let e=JSON.stringify(`${c}#inline${h++}`);t.type===`FunctionDeclaration`?m.push({at:t.end,text:`;__playpadAction(${t.id.name},${e});`}):m.push({at:t.start,text:`__playpadAction(`},{at:t.end,text:`,${e})`})}});try{let{code:e}=a(t(l,m),{transforms:[`jsx`,`imports`],jsxRuntime:`automatic`,production:!1,filePath:c});return{path:c,text:e,imports:f,directive:d,exportNames:p}}catch(e){throw i(c,l,e)}}function y(e,t){let n={},r=e.replace(/\W/g,`_`);return{css:t.replace(/"[^"]*"|'[^']*'|url\([^)]*\)|\.(-?[_a-zA-Z][\w-]*)/g,(e,t)=>t?(n[t]=`${r}__${t}`,`.${n[t]}`):e),names:n}}function b(t){let n=Object.keys(t).some(e=>/^(src\/)?app\//.test(e));if(!n&&Object.keys(t).some(e=>/^(src\/)?pages\//.test(e)))throw new e(`pages`,`The pages/ router is not available in this preview. Use the app/ directory.`);if(!n)throw new e(`app/page.jsx`,"Couldn't find any `pages` or `app` directory. Please create one under the project root");let r=Object.keys(t).some(e=>e.startsWith(`src/app/`)),i=Object.keys(t).some(e=>p.test(e))?t:{...t,[`${r?`src/`:``}app/layout.jsx`]:h},a=[];Object.keys(i).some(e=>/^(src\/)?(proxy|middleware)\.(js|ts)$/.test(e))&&a.push(`proxy (middleware) does not run in this preview.`),Object.keys(i).some(e=>/\/(@[^/]+|\(\.+\)[^/]*)\//.test(e))&&a.push(`Parallel and intercepting routes do not work in this preview.`);let o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map,g=/* @__PURE__ */ new Map,b=[],x=e=>(o.has(e)||o.set(e,v(i,e)),o.get(e));function S(e,t){let n=i[e],r=`{}`;if(e.endsWith(`.module.css`)){let t=y(e,n);n=t.css,r=JSON.stringify({__esModule:!0,default:t.names,...t.names})}b.some(t=>t.path===e)||b.push({path:e,text:n}),t.set(e,{path:e,kind:`json`,text:r,links:{}})}function C(t,n){try{JSON.parse(i[t])}catch(n){throw new e(t,`This file is not valid JSON: ${n.message}`)}n.set(t,{path:t,kind:`json`,text:i[t],links:{}})}function w(t,n){let r={},a=n===`server`?s:g;for(let{spec:o,node:s}of t.imports){let{line:f,column:p}=s.loc.start;if(/^(\.|\/|@\/)/.test(o)){let s=_(i,t.path,o);if(!s)throw new e(t.path,`Module not found: Can't resolve '${o}'`,f,p+1);if(r[o]=s,s.endsWith(`.css`))S(s,a);else if(s.endsWith(`.json`))C(s,a);else if(m.test(s))n===`server`?T(s):E(s);else throw new e(t.path,`"${o}" cannot be imported here. A project can import .js, .jsx, .ts, .tsx, .css and .json files.`,f,p+1)}else{if(n===`client`&&u.includes(o))throw new e(t.path,`You're importing a module that depends on "${o}" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use client", so this module is also a Client Component.`,f,p+1);if(!(n===`server`?c:l).includes(o))throw new e(t.path,`Module not found: Can't resolve '${o}'. Only react, react-dom and next/* can be imported here.`,f,p+1);if(n===`server`&&o===`react`)for(let n of s.specifiers??[]){let r=n.imported?.name;if(r&&d.includes(r))throw new e(t.path,`You're importing a module that depends on \`${r}\` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the \`"use client"\` directive.`,n.loc.start.line,n.loc.start.column+1)}}}return r}function T(e){if(s.has(e))return;let t=x(e);if(t.directive===`client`){s.set(e,{path:e,kind:`client-ref`,links:{}}),E(e);return}let n={path:e,kind:`js`,text:t.text,links:{},directive:t.directive===`server`?`server`:null};s.set(e,n),n.links=w(t,`server`)}function E(e){if(g.has(e))return;let t=x(e);if(t.directive===`server`){g.set(e,{path:e,kind:`server-ref`,exportNames:t.exportNames,links:{}}),T(e);return}let n={path:e,kind:`js`,text:t.text,links:{}};g.set(e,n),n.links=w(t,`client`)}let D=Object.keys(i).filter(e=>f.test(e));for(let e of D)T(e);return{server:[...s.values()],client:[...g.values()],css:b,routeFiles:D,notices:a}}function x(e){let t=/^(?:src\/)?app\/(?:(.*)\/)?page\.(?:jsx?|tsx?)$/.exec(e);if(!t)return`/`;let n=(t[1]??``).split(`/`).filter(e=>e&&!/^\(.*\)$/.test(e));return n.some(e=>e.startsWith(`[`)||e.startsWith(`@`))?`/`:`/${n.join(`/`)}`}export{e as CompileError,b as compileProject,x as startPath};
@@ -166,6 +166,18 @@
166
166
  "blockers": [],
167
167
  "scope": "Only the rebuilt hashes in toolchains/cpp/assets.lock.json, distributed with their notice/provenance companions. Hosting and physical-device gates are separate.",
168
168
  "provenance": "third-party/compiler/cpp-rebuild/provenance.json"
169
+ },
170
+ "csharp": {
171
+ "id": "code-playpad-csharp-roslyn-5.0.0-dotnet-10.0.14-r1",
172
+ "licenseReviewComplete": false,
173
+ "blockers": [
174
+ "Codex has not reviewed the notice mapping in third-party/csharp/manifest.json.",
175
+ "The owner has not approved this release.",
176
+ "The package name has not been settled against Microsoft trademark terms.",
177
+ "The runtime is not wired in (step 4), and the phone check and real CDN delivery are untested."
178
+ ],
179
+ "scope": "Only the hashes in toolchains/csharp/assets.lock.json, distributed with third-party/csharp notices.",
180
+ "notices": "third-party/csharp/manifest.json"
169
181
  }
170
182
  },
171
183
  "supersededArtifacts": [
@@ -1 +1 @@
1
- import{o as e}from"./config-DB58UVsk.js";import{t}from"./worker-runtime-Bk9bsGrP.js";var n=`code-playpad-cpp-20.1.2-emscripten-4.0.6-r1`,r=/* @__PURE__ */ new Map;async function i(e){r.has(e)||r.set(e,(async()=>{try{return await caches.open(e)}catch{return}})()),await r.get(e)}var a='"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',o=new class extends t{id=`cpp`;get label(){return`C/C++ (Clang 20, experimental)`}get source(){return a}async load(e){return await i(n),super.load(e)}initPayload(){return{toolchainURL:e().indexURL}}};function s(t){return{id:t,label:t===`c`?`C17 (experimental)`:`C++20 (experimental)`,statusDecidesFailure:!0,get ready(){return o.ready},interactiveStdin:!1,async editorLanguage(){return(await import(`@codemirror/lang-cpp`)).cpp()},load:e=>o.load(e),run:(n,r={})=>o.run(n,{...r,compilerLanguage:t,timeoutMs:r.timeoutMs??e().timeoutMs}),stop:e=>o.stop(e)}}var c=s(`c`),l=s(`cpp`);export{c as cRuntime,l as cppRuntime};
1
+ import{o as e}from"./config-DB58UVsk.js";import{t}from"./worker-runtime-Dd2eBtq3.js";var n=`code-playpad-cpp-20.1.2-emscripten-4.0.6-r1`,r=/* @__PURE__ */ new Map;async function i(e){r.has(e)||r.set(e,(async()=>{try{return await caches.open(e)}catch{return}})()),await r.get(e)}var a='"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',o=new class extends t{id=`cpp`;get label(){return`C/C++ (Clang 20, experimental)`}get source(){return a}async load(e){return await i(n),super.load(e)}initPayload(){return{toolchainURL:e().indexURL}}};function s(t){return{id:t,label:t===`c`?`C17 (experimental)`:`C++20 (experimental)`,statusDecidesFailure:!0,get ready(){return o.ready},interactiveStdin:!1,async editorLanguage(){return(await import(`@codemirror/lang-cpp`)).cpp()},load:e=>o.load(e),run:(n,r={})=>o.run(n,{...r,compilerLanguage:t,timeoutMs:r.timeoutMs??e().timeoutMs}),stop:e=>o.stop(e)}}var c=s(`c`),l=s(`cpp`);export{c as cRuntime,l as cppRuntime};