code-playpad 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +110 -7
  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-xLJOrOXX.js → cpp-C8YnpTSR.js} +1 -1
  10. package/dist/{element-Dzhksh6_.js → element-BuS9dUwa.js} +41 -17
  11. package/dist/element.js +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/{java-DFiOVxDN.js → java-DkfYRvpA.js} +1 -1
  14. package/dist/{javascript-CLaHCZ8o.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-Cs-Kwccb.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.d.ts +3 -1
  23. package/dist/react.js +1 -1
  24. package/dist/runtime/next/compiler.d.ts +29 -0
  25. package/dist/runtime/next-tailwind.generated.d.ts +1 -0
  26. package/dist/runtime/next-vendor.generated.d.ts +10 -0
  27. package/dist/runtime/next.d.ts +2 -0
  28. package/dist/runtime/preview-session.d.ts +34 -0
  29. package/dist/runtime/react/compiler.d.ts +26 -0
  30. package/dist/standalone.js +41 -17
  31. package/dist/{worker-runtime-tSXm-pPB.js → worker-runtime-Dd2eBtq3.js} +1 -1
  32. package/package.json +8 -4
  33. package/dist/react-ALhWeEZ5.js +0 -9
  34. package/dist/react-DmuIc3qw.js +0 -4
@@ -1,4 +1,4 @@
1
- import{s as e}from"./config-DB58UVsk.js";import{t}from"./worker-runtime-tSXm-pPB.js";var n=`let pyodide=null,stdinLines=[],stdinExhausted=!1,currentId=null,interactive=!1,inputWaitMs=0,nextRequest=1;const pendingLines=new Map,MOUNT="/home/pyodide/playground";let written=new Set,internals=null;const REFRESH=["import importlib, os, sys","MOUNT = "+JSON.stringify(MOUNT),"os.makedirs(MOUNT, exist_ok=True)","sys.path.insert(0, MOUNT) if MOUNT not in sys.path else None","os.chdir(MOUNT)","for _name, _mod in list(sys.modules.items()):",' _file = getattr(_mod, "__file__", None) or ""',' _paths = list(getattr(_mod, "__path__", None) or [])'," if _file.startswith(MOUNT) or any(str(p).startswith(MOUNT) for p in _paths):"," del sys.modules[_name]","importlib.invalidate_caches()"].join(\`
1
+ import{s as e}from"./config-DB58UVsk.js";import{t}from"./worker-runtime-Dd2eBtq3.js";var n=`let pyodide=null,stdinLines=[],stdinExhausted=!1,currentId=null,interactive=!1,inputWaitMs=0,nextRequest=1;const pendingLines=new Map,MOUNT="/home/pyodide/playground";let written=new Set,internals=null;const REFRESH=["import importlib, os, sys","MOUNT = "+JSON.stringify(MOUNT),"os.makedirs(MOUNT, exist_ok=True)","sys.path.insert(0, MOUNT) if MOUNT not in sys.path else None","os.chdir(MOUNT)","for _name, _mod in list(sys.modules.items()):",' _file = getattr(_mod, "__file__", None) or ""',' _paths = list(getattr(_mod, "__path__", None) or [])'," if _file.startswith(MOUNT) or any(str(p).startswith(MOUNT) for p in _paths):"," del sys.modules[_name]","importlib.invalidate_caches()"].join(\`
2
2
  \`);function flushStreams(){try{pyodide.runPython(\`import sys
3
3
  sys.stdout.flush()
4
4
  sys.stderr.flush()\`,{globals:internals})}catch{}flushOutput()}const INPUT_OVERRIDE=["import builtins, sys, js","from pyodide.ffi import run_sync","",'def _pg_input(prompt=""):',' if prompt != "":'," sys.stdout.write(str(prompt))"," sys.stdout.flush()"," line = run_sync(js._pgReadLine())"," # Pyodide maps JS null to its own JsNull singleton, not None, so test"," # for what we want rather than for the several ways EOF can arrive."," if not isinstance(line, str):",' raise EOFError("EOF when reading a line")'," return line","",'_pg_input.__name__ = "input"','_pg_input.__qualname__ = "input"',"_pg_input.__doc__ = builtins.input.__doc__","builtins.input = _pg_input"].join(\`
@@ -0,0 +1 @@
1
+ import{t as e}from"./react-version.generated-BNNJmf7J.js";import{c as t}from"./config-DB58UVsk.js";import{n,t as r}from"./boot-DW1YzgCY.js";var i=[`src/main.jsx`,`src/main.js`],a=`<!doctype html><html lang="en"><head><meta charset="utf-8"></head><body><div id="root"></div></body></html>`;function o(e){return/^([a-z][a-z0-9+.-]*:|\/\/)/i.test(e)}function s(e,n,s){let{CompileError:c,compileProject:l,resolveImport:u}=s,d=n.endsWith(`.html`)?n:`index.html`,f=Object.hasOwn(e,d),p=new DOMParser().parseFromString(f?e[d]:a,`text/html`),m=[];if(f){let t=[...p.querySelectorAll(`script[src], link[rel="stylesheet"][href]`)],n=[];for(let r of t){let t=r.tagName===`SCRIPT`,i=r.getAttribute(t?`src`:`href`);if(o(i))throw new c(d,`This project can't load "${i}". The preview can only use the project's own files.`);let a=u(e,d,i);if(!a)throw new c(d,`The file "${i}" does not exist.`);(t?n:m).push(a),r.remove()}if(!n.length)throw new c(d,`Add <script type="module" src="/src/main.jsx"><\/script> so the app has an entry file.`);m.push(...n)}else{let t=n.endsWith(`.html`)?void 0:Object.hasOwn(e,n)?n:i.find(t=>Object.hasOwn(e,t));if(!t)throw new c(`index.html`,`This project has no entry file. Add src/main.jsx.`);m.push(t)}let h=l(e,m),{nonce:g,runtimeURL:_}=t(),v=p.createElement(`meta`);v.httpEquiv=`Content-Security-Policy`,v.content=`default-src 'none'; script-src 'unsafe-inline'${_?` ${_}`:``}; style-src 'unsafe-inline'; img-src data:; font-src data:; form-action 'none'; base-uri 'none'`;let y=p.createElement(`script`);return g&&y.setAttribute(`nonce`,g),y.textContent=r,p.head.prepend(v,y),{html:`<!doctype html>${p.documentElement.outerHTML}`,modules:h,entries:m}}var c=new class{id=`react`;label=`React ${e}`;interactiveStdin=!1;statusDecidesFailure=!0;#e=null;#t=null;#n=null;#r=/* @__PURE__ */ new WeakMap;#i=/* @__PURE__ */ new WeakMap;get ready(){return this.#e!==null}async editorLanguage(){let{javascript:e}=await import(`@codemirror/lang-javascript`);return e({jsx:!0})}load(){return this.#n??=(async()=>{try{let e=import(`./compiler-A2mqXrqO.js`),n=t().runtimeURL?null:import(`./react-vendor.generated-DMxIoCMn.js`);this.#t=(await n)?.REACT_VENDOR_SOURCE??null,this.#e=await e}catch(e){throw this.#n=null,Error(`The React runtime could not be loaded. Check your connection and reload the page. (${e.message})`)}})(),this.#n}run(e,r={}){let i=r.preview;if(!i)return Promise.reject(/* @__PURE__ */ Error(`React needs a <code-playpad> widget to render in.`));this.dispose(i.host);let a,o=r.files??{},s=new Promise((e,r)=>{let o=t().runtimeURL;a=new n(i,{...o?{runtimeURL:o}:{vendor:this.#t},nonce:t().nonce},e,r)});return this.#r.set(i.host,a),this.#i.set(s,a),this.#a(a,o,r.entry??`index.html`),s}async#a(e,t,n){try{await this.load();let r=this.#e,i;try{i=s(t,n,r)}catch(t){if(t instanceof r.CompileError){e.fail(t.reason,{file:t.file,...t.line?{line:t.line}:{},...t.column?{column:t.column}:{}},t.hint),e.showCompileBanner(t.hint);return}throw t}e.payload.modules=i.modules,e.payload.entries=i.entries,e.open(i.html)}catch(t){e.fail(t.message)}}stop(e){e&&this.#i.get(e)?.dispose(!0)}hasLivePreview(e){return this.#r.get(e)?.live??!1}dispose(e){this.#r.get(e)?.dispose(!0),this.#r.delete(e)}};export{c as reactRuntime};
@@ -0,0 +1,6 @@
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"./react-version.generated-BNNJmf7J.js";import{c as t}from"./config-DB58UVsk.js";import{n,t as r}from"./boot-nmFndPHW.js";var i=[`src/main.jsx`,`src/main.js`],a=`<!doctype html><html lang="en"><head><meta charset="utf-8"></head><body><div id="root"></div></body></html>`;function o(e){return/^([a-z][a-z0-9+.-]*:|\/\/)/i.test(e)}function s(e,n,s){let{CompileError:c,compileProject:l,resolveImport:u}=s,d=n.endsWith(`.html`)?n:`index.html`,f=Object.hasOwn(e,d),p=new DOMParser().parseFromString(f?e[d]:a,`text/html`),m=[];if(f){let t=[...p.querySelectorAll(`script[src], link[rel="stylesheet"][href]`)],n=[];for(let r of t){let t=r.tagName===`SCRIPT`,i=r.getAttribute(t?`src`:`href`);if(o(i))throw new c(d,`This project can't load "${i}". The preview can only use the project's own files.`);let a=u(e,d,i);if(!a)throw new c(d,`The file "${i}" does not exist.`);(t?n:m).push(a),r.remove()}if(!n.length)throw new c(d,`Add <script type="module" src="/src/main.jsx"><\/script> so the app has an entry file.`);m.push(...n)}else{let t=n.endsWith(`.html`)?void 0:Object.hasOwn(e,n)?n:i.find(t=>Object.hasOwn(e,t));if(!t)throw new c(`index.html`,`This project has no entry file. Add src/main.jsx.`);m.push(t)}let h=l(e,m),{nonce:g,runtimeURL:_}=t(),v=p.createElement(`meta`);v.httpEquiv=`Content-Security-Policy`,v.content=`default-src 'none'; script-src 'unsafe-inline'${_?` ${_}`:``}; style-src 'unsafe-inline'; img-src data:; font-src data:; form-action 'none'; base-uri 'none'`;let y=p.createElement(`script`);return g&&y.setAttribute(`nonce`,g),y.textContent=r,p.head.prepend(v,y),{html:`<!doctype html>${p.documentElement.outerHTML}`,modules:h,entries:m}}var c=new class{id=`react`;label=`React ${e}`;interactiveStdin=!1;statusDecidesFailure=!0;#e=null;#t=null;#n=null;#r=/* @__PURE__ */ new WeakMap;#i=/* @__PURE__ */ new WeakMap;get ready(){return this.#e!==null}async editorLanguage(){let{javascript:e}=await import(`./dist-BwlTZqCY.js`);return e({jsx:!0})}load(){return this.#n??=(async()=>{try{let e=import(`./compiler-A2mqXrqO.js`),n=t().runtimeURL?null:import(`./react-vendor.generated-DMxIoCMn.js`);this.#t=(await n)?.REACT_VENDOR_SOURCE??null,this.#e=await e}catch(e){throw this.#n=null,Error(`The React runtime could not be loaded. Check your connection and reload the page. (${e.message})`)}})(),this.#n}run(e,r={}){let i=r.preview;if(!i)return Promise.reject(/* @__PURE__ */ Error(`React needs a <code-playpad> widget to render in.`));this.dispose(i.host);let a,o=r.files??{},s=new Promise((e,r)=>{let o=t().runtimeURL;a=new n(i,{...o?{runtimeURL:o}:{vendor:this.#t},nonce:t().nonce},e,r)});return this.#r.set(i.host,a),this.#i.set(s,a),this.#a(a,o,r.entry??`index.html`),s}async#a(e,t,n){try{await this.load();let r=this.#e,i;try{i=s(t,n,r)}catch(t){if(t instanceof r.CompileError){e.fail(t.reason,{file:t.file,...t.line?{line:t.line}:{},...t.column?{column:t.column}:{}},t.hint),e.showCompileBanner(t.hint);return}throw t}e.payload.modules=i.modules,e.payload.entries=i.entries,e.open(i.html)}catch(t){e.fail(t.message)}}stop(e){e&&this.#i.get(e)?.dispose(!0)}hasLivePreview(e){return this.#r.get(e)?.live??!1}dispose(e){this.#r.get(e)?.dispose(!0),this.#r.delete(e)}};export{c as reactRuntime};
package/dist/react.d.ts CHANGED
@@ -18,6 +18,8 @@ export interface CodePlayPadProps {
18
18
  maxHeight?: number | string;
19
19
  /** language="react": the preview's height. A number means pixels. */
20
20
  previewHeight?: number | string;
21
+ /** The file tree's width: a percentage such as "20%", or a number of pixels. */
22
+ treeWidth?: number | string;
21
23
  /** How to list several files: "tabs" (default) or "tree". */
22
24
  fileView?: 'tabs' | 'tree';
23
25
  /** Which file is on screen to begin with, if not the entry. */
@@ -46,7 +48,7 @@ export interface CodePlayPadProps {
46
48
  * which keeps React 18 (no non-string prop support on custom elements) working
47
49
  * the same as React 19.
48
50
  */
49
- export declare function CodePlayPad({ code, files, entry, stdin, language, height, minHeight, maxHeight, previewHeight, fileView, openFile, theme, themeControls, readOnly, autoRun, persist, practice, className, style, onReady, onRun, onOutput, onError }: CodePlayPadProps): import("react").JSX.Element;
51
+ export declare function CodePlayPad({ code, files, entry, stdin, language, height, minHeight, maxHeight, previewHeight, treeWidth, fileView, openFile, theme, themeControls, readOnly, autoRun, persist, practice, className, style, onReady, onRun, onOutput, onError }: CodePlayPadProps): import("react").JSX.Element;
50
52
  declare module 'react' {
51
53
  namespace JSX {
52
54
  interface IntrinsicElements {
package/dist/react.js CHANGED
@@ -1 +1 @@
1
- import{n as e}from"./element-Dzhksh6_.js";import{useEffect as t,useRef as n}from"react";import{jsx as r}from"react/jsx-runtime";e();function i({code:e=``,files:i,entry:a,stdin:o,language:s=`python`,height:c,minHeight:l,maxHeight:u,previewHeight:d,fileView:f,openFile:p,theme:m=`auto`,themeControls:h=!0,readOnly:g,autoRun:_,persist:v,practice:y,className:b,style:x,onReady:S,onRun:C,onOutput:w,onError:T}){let E=n(null),D=n({onReady:S,onRun:C,onOutput:w,onError:T});D.current={onReady:S,onRun:C,onOutput:w,onError:T},t(()=>{let e=E.current;if(!e)return;let t=(t,n)=>{let r=e=>n(D.current)?.(e.detail);return e.addEventListener(t,r),()=>e.removeEventListener(t,r)},n=[t(`py-ready`,e=>e.onReady),t(`py-run`,e=>e.onRun),t(`py-output`,e=>e.onOutput),t(`py-error`,e=>e.onError)];return()=>n.forEach(e=>e())},[]);let O=i?JSON.stringify(i):null;t(()=>{let t=E.current;t&&(O?t.files=JSON.parse(O):e!==t.code&&(t.code=e))},[e,O]),t(()=>{E.current&&o!==void 0&&(E.current.stdin=o)},[o]);let k=y?JSON.stringify(y):null;return t(()=>{E.current&&(E.current.practice=k?JSON.parse(k):null)},[k]),/* @__PURE__ */ r(`code-playpad`,{ref:E,language:s,theme:m,"theme-controls":h?void 0:`off`,class:b,style:x,...c===void 0?{}:{height:String(c)},...l===void 0?{}:{"min-height":String(l)},...u===void 0?{}:{"max-height":String(u)},...d===void 0?{}:{"preview-height":String(d)},...f?{"file-view":f}:{},...p?{"open-file":p}:{},...g?{readonly:``}:{},..._?{autorun:``}:{},...v?{persist:v}:{},...a?{entry:a}:{},children:i?null:e})}export{i as CodePlayPad,i as default};
1
+ import{n as e}from"./element-BuS9dUwa.js";import{useEffect as t,useRef as n}from"react";import{jsx as r}from"react/jsx-runtime";e();function i({code:e=``,files:i,entry:a,stdin:o,language:s=`python`,height:c,minHeight:l,maxHeight:u,previewHeight:d,treeWidth:f,fileView:p,openFile:m,theme:h=`auto`,themeControls:g=!0,readOnly:_,autoRun:v,persist:y,practice:b,className:x,style:S,onReady:C,onRun:w,onOutput:T,onError:E}){let D=n(null),O=n({onReady:C,onRun:w,onOutput:T,onError:E});O.current={onReady:C,onRun:w,onOutput:T,onError:E},t(()=>{let e=D.current;if(!e)return;let t=(t,n)=>{let r=e=>n(O.current)?.(e.detail);return e.addEventListener(t,r),()=>e.removeEventListener(t,r)},n=[t(`py-ready`,e=>e.onReady),t(`py-run`,e=>e.onRun),t(`py-output`,e=>e.onOutput),t(`py-error`,e=>e.onError)];return()=>n.forEach(e=>e())},[]);let k=i?JSON.stringify(i):null;t(()=>{let t=D.current;t&&(k?t.files=JSON.parse(k):e!==t.code&&(t.code=e))},[e,k]),t(()=>{D.current&&o!==void 0&&(D.current.stdin=o)},[o]);let A=b?JSON.stringify(b):null;return t(()=>{D.current&&(D.current.practice=A?JSON.parse(A):null)},[A]),/* @__PURE__ */ r(`code-playpad`,{ref:D,language:s,theme:h,"theme-controls":g?void 0:`off`,class:x,style:S,...c===void 0?{}:{height:String(c)},...l===void 0?{}:{"min-height":String(l)},...u===void 0?{}:{"max-height":String(u)},...d===void 0?{}:{"preview-height":String(d)},...f===void 0?{}:{"tree-width":String(f)},...p?{"file-view":p}:{},...m?{"open-file":m}:{},..._?{readonly:``}:{},...v?{autorun:``}:{},...y?{persist:y}:{},...a?{entry:a}:{},children:i?null:e})}export{i as CodePlayPad,i as default};
@@ -0,0 +1,29 @@
1
+ import { CompileError } from '../react/compiler.js';
2
+ export { CompileError };
3
+ export interface ServerModule {
4
+ path: string;
5
+ kind: 'js' | 'json' | 'client-ref';
6
+ text?: string;
7
+ links: Record<string, string>;
8
+ directive?: 'server' | null;
9
+ }
10
+ export interface ClientModule {
11
+ path: string;
12
+ kind: 'js' | 'json' | 'server-ref';
13
+ text?: string;
14
+ links: Record<string, string>;
15
+ exportNames?: string[];
16
+ }
17
+ export interface NextProject {
18
+ server: ServerModule[];
19
+ client: ClientModule[];
20
+ css: {
21
+ path: string;
22
+ text: string;
23
+ }[];
24
+ routeFiles: string[];
25
+ notices: string[];
26
+ }
27
+ export declare function compileProject(input: Record<string, string>): NextProject;
28
+ /** The URL a project opens at: the page the entry names, when that page has one fixed URL. */
29
+ export declare function startPath(entry: string): string;
@@ -0,0 +1 @@
1
+ export declare const NEXT_TAILWIND_SOURCE: string;
@@ -0,0 +1,10 @@
1
+ export declare const NEXT_SERVER_STAMP: {
2
+ readonly react: "19.2.8";
3
+ readonly sha256: "edf0a1c7f0b89207cedfcc97d70ce7690dd7b74b2759fe40d09962aa1217d306";
4
+ };
5
+ export declare const NEXT_CLIENT_STAMP: {
6
+ readonly react: "19.2.8";
7
+ readonly sha256: "9fa987a50b2071a7767c37ae9d15f0e621a5d115de640ba782e7a7f77095aa3d";
8
+ };
9
+ export declare const NEXT_SERVER_SOURCE: string;
10
+ export declare const NEXT_CLIENT_SOURCE: string;
@@ -0,0 +1,2 @@
1
+ import type { Runtime } from '../types.js';
2
+ export declare const nextRuntime: Runtime;
@@ -0,0 +1,34 @@
1
+ import type { PreviewBinding, Result } from '../types.js';
2
+ /** One run's frame, from creation until it is replaced. */
3
+ export declare class PreviewSession {
4
+ #private;
5
+ readonly preview: PreviewBinding;
6
+ readonly payload: Record<string, unknown>;
7
+ /** Next.js: the app moved to another URL. */
8
+ readonly onRoute?: ((route: {
9
+ url: string;
10
+ canBack: boolean;
11
+ canForward: boolean;
12
+ }) => void) | undefined;
13
+ constructor(preview: PreviewBinding, payload: Record<string, unknown>, resolve: (result: Result) => void, reject: (err: Error) => void,
14
+ /** Next.js: the app moved to another URL. */
15
+ onRoute?: ((route: {
16
+ url: string;
17
+ canBack: boolean;
18
+ canForward: boolean;
19
+ }) => void) | undefined);
20
+ get live(): boolean;
21
+ /** Tell the app in the frame something. It treats this as untrusted, like anything else it reads. */
22
+ send(message: Record<string, unknown>): void;
23
+ open(html: string, before?: HTMLElement[]): void;
24
+ /** A failure with no frame to speak for it. */
25
+ fail(message: string, location?: {
26
+ file?: string;
27
+ line?: number;
28
+ column?: number;
29
+ }, hint?: string): void;
30
+ showCompileBanner(hint: string | undefined): void;
31
+ /** Removes the frame. Replacing the element, not resetting srcdoc, is what
32
+ * recovers from a stuck frame: a new document would wait on the stuck process. */
33
+ dispose(stopped: boolean): void;
34
+ }
@@ -24,6 +24,32 @@ export declare class CompileError extends Error {
24
24
  readonly hint?: string | undefined;
25
25
  constructor(file: string, reason: string, line?: number | undefined, column?: number | undefined, hint?: string | undefined);
26
26
  }
27
+ export interface AstNode {
28
+ type: string;
29
+ start: number;
30
+ end: number;
31
+ loc: {
32
+ start: {
33
+ line: number;
34
+ column: number;
35
+ };
36
+ };
37
+ [key: string]: unknown;
38
+ }
39
+ export declare const isNode: (value: unknown) => value is AstNode;
40
+ export declare function walk(node: AstNode, visit: (node: AstNode) => void): void;
41
+ export declare function sucraseError(path: string, source: string, err: unknown): CompileError;
42
+ /** acorn reports columns from 0; editors and Sucrase count them from 1. */
43
+ export declare function parseModule(path: string, source: string): AstNode;
44
+ /** A time check at the top of every loop body. Inserted on the same line, so line numbers stay true. */
45
+ export declare function loopGuardInserts(ast: AstNode): {
46
+ at: number;
47
+ text: string;
48
+ }[];
49
+ export declare function applyInserts(source: string, inserts: {
50
+ at: number;
51
+ text: string;
52
+ }[]): string;
27
53
  /** Resolve an import as Vite does: against the importing file, trying the extensions a learner may leave off. */
28
54
  export declare function resolveImport(files: Record<string, string>, from: string, spec: string): string | undefined;
29
55
  /** Compile the entry files and everything they import. A file nothing imports is not compiled, as in Vite. */
@@ -15,7 +15,7 @@ import{n as e,t}from"./types-CfcYqU2K.js";import{t as n}from"./hints-DpBIeoeG.js
15
15
  --cp-ok: ${n.ok};
16
16
  color-scheme: ${t};
17
17
  }`]:[]).join(`
18
- `)}async function x(e){try{return await E(e)}catch(t){return console.warn(`[code-playpad] CodeMirror unavailable, using plain textarea:`,t),D(e)}}var S=/* @__PURE__ */ new Map,C=/* @__PURE__ */ new Set,w=!1;function T(){w||(w=!0,queueMicrotask(()=>{w=!1;for(let e of C){let t=[...e.adoptedStyleSheets];e.adoptedStyleSheets=[],e.adoptedStyleSheets=t}}))}async function E(e){let[t,n,r,i,a,o,s]=await Promise.all([import(`./dist-D4P7t1AU.js`).then(e=>e.s),import(`./dist-CjnVq6q1.js`).then(e=>e.x),import(`./dist-g8djAEMH.js`),import(`./dist-CTLX4tws.js`),import(`./dist-_fde-E8H.js`).then(e=>e.n),import(`./dist-DHeVjdBc.js`),import(`./dist-IFh_mUXG.js`).then(e=>e.t)]),{EditorView:c,keymap:l,lineNumbers:d,highlightActiveLine:f,highlightActiveLineGutter:p,highlightSpecialChars:m,drawSelection:h,rectangularSelection:g,crosshairCursor:_}=t,{EditorState:v,Compartment:y}=n,{defaultKeymap:b,history:x,historyKeymap:w,indentWithTab:E}=r,{syntaxHighlighting:D,defaultHighlightStyle:O,HighlightStyle:k,indentOnInput:A,bracketMatching:j,foldGutter:M,foldKeymap:N}=i,{autocompletion:P,closeBrackets:F,closeBracketsKeymap:I,completionKeymap:L}=a,R=new y,z=new y,B=new y,V=S.get(`default-light`)??[c.theme({"&":{color:`#1f2328`,backgroundColor:`#ffffff`},".cm-gutters":{backgroundColor:`#f6f8fa`,color:`#8b949e`,border:`none`},".cm-activeLine":{backgroundColor:`#f6f8fa88`},".cm-activeLineGutter":{backgroundColor:`#eaeef2`},".cm-cursor":{borderLeftColor:`#1f2328`},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:`#cfe3ff`}}),D(O,{fallback:!0})];S.set(`default-light`,V);let{tags:H}=s,U=(e,t)=>[c.theme({"&":{color:e.fg,backgroundColor:e.bg},".cm-content":{caretColor:e.fg},".cm-gutters":{backgroundColor:e.surface,color:e.muted,border:`none`},".cm-activeLine":{backgroundColor:e.activeLine},".cm-activeLineGutter":{backgroundColor:e.selection},".cm-cursor, .cm-dropCursor":{borderLeftColor:e.fg},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:e.selection},".cm-tooltip":{backgroundColor:e.surface,color:e.fg,border:`1px solid ${e.border}`},".cm-tooltip-autocomplete > ul > li[aria-selected]":{backgroundColor:e.selection,color:e.fg}},{dark:t}),D(k.define([{tag:[H.comment,H.meta],color:e.comment,fontStyle:`italic`},{tag:[H.keyword,H.operatorKeyword,H.modifier],color:e.keyword},{tag:[H.string,H.special(H.string),H.regexp],color:e.string},{tag:[H.number,H.bool,H.null,H.atom],color:e.number},{tag:[H.function(H.variableName),H.function(H.propertyName),H.definition(H.function(H.variableName))],color:e.fn},{tag:[H.typeName,H.className,H.namespace,H.tagName],color:e.type},{tag:[H.variableName,H.propertyName,H.attributeName],color:e.variable},{tag:H.invalid,color:e.keyword,textDecoration:`underline`}]))],W=(e,t)=>{let n=u.find(e=>e.id===t);if(!n?.colors)return e?o.oneDark:V;let r=S.get(n.id);return r||(r=U(n.colors,n.mode===`dark`),S.set(n.id,r)),r},G=l.of([{key:`Mod-Enter`,preventDefault:!0,run:()=>(e.onRun?.(),!0)},{key:`Shift-Enter`,preventDefault:!0,run:()=>(e.onRun?.(),!0)}]),K=e.dark,q=e.themeId,J=e.readOnly,Y=e.language??[],X=t=>v.create({doc:t,extensions:[d(),p(),m(),x(),M(),h(),v.allowMultipleSelections.of(!0),A(),j(),F(),P(),g(),_(),f(),G,l.of([...I,...b,...w,...N,...L,E]),c.lineWrapping,B.of(Y),R.of(W(K,q)),z.of(v.readOnly.of(J)),c.updateListener.of(t=>{t.startState.facet(c.styleModule)!==t.state.facet(c.styleModule)&&T(),t.docChanged&&e.onChange?.(t.state.doc.toString())})]}),Z=new c({parent:e.parent,state:X(e.doc)});C.add(Z.root),T();let Q=/* @__PURE__ */ new Map,$=e.name??``;return{fallback:!1,getCode:()=>Z.state.doc.toString(),setCode(e){Z.dispatch({changes:{from:0,to:Z.state.doc.length,insert:e}})},openFile(e,t){if(e===$)return;Q.set($,Z.state);let n=Q.get(e);Z.setState(n??X(t)),$=e,n&&Z.dispatch({effects:[R.reconfigure(W(K,q)),z.reconfigure(v.readOnly.of(J)),B.reconfigure(Y)]}),T()},fileCode(e,t){if(e===$)return Z.state.doc.toString();let n=Q.get(e);return n?n.doc.toString():t},forgetFiles(e){for(let t of[...Q.keys()])e.includes(t)||Q.delete(t)},setTheme(e,t){K=e,q=t,Z.dispatch({effects:R.reconfigure(W(K,q))})},setReadOnly(e){J=e,Z.dispatch({effects:z.reconfigure(v.readOnly.of(J))})},setLanguage(e){Y=e,Z.dispatch({effects:B.reconfigure(Y)})},focus:()=>Z.focus(),destroy(){C.delete(Z.root),Z.destroy()}}}function D(e){let t=document.createElement(`textarea`);t.className=`cp-fallback-editor`,t.spellcheck=!1,t.value=e.doc,t.readOnly=e.readOnly,t.addEventListener(`input`,()=>e.onChange?.(t.value)),t.addEventListener(`keydown`,t=>{(t.metaKey||t.ctrlKey)&&t.key===`Enter`&&(t.preventDefault(),e.onRun?.())}),e.parent.appendChild(t);let n=/* @__PURE__ */ new Map,r=e.name??``;return{fallback:!0,getCode:()=>t.value,setCode:e=>{t.value=e},openFile(e,i){e!==r&&(n.set(r,t.value),t.value=n.get(e)??i,r=e)},fileCode(e,i){return e===r?t.value:n.get(e)??i},forgetFiles(e){for(let t of[...n.keys()])e.includes(t)||n.delete(t)},setTheme:()=>{},setReadOnly:e=>{t.readOnly=e},setLanguage:()=>{},focus:()=>t.focus(),destroy:()=>t.remove()}}var O=/* @__PURE__ */ new Map,k=/* @__PURE__ */ new Map;function A(e,t){O.set(e,t)}function j(){return[...O.keys()]}function M(e){let t=k.get(e);if(t)return t;let n=O.get(e);if(!n)return Promise.reject(/* @__PURE__ */ Error(`Unknown runtime "${e}". Registered: ${j().join(`, `)||`none`}`));let r=n().catch(t=>{throw k.delete(e),t});return k.set(e,r),r}A(`python`,()=>import(`./pyodide-QurAOd7j.js`).then(e=>e.pythonRuntime)),A(`javascript`,()=>import(`./javascript-BBiCDtZ3.js`).then(e=>e.javascriptRuntime)),A(`typescript`,()=>import(`./javascript-BBiCDtZ3.js`).then(e=>e.typescriptRuntime)),A(`java`,()=>import(`./java-DjuG1fCk.js`).then(e=>e.javaRuntime)),A(`c`,()=>import(`./cpp-Bhr_Zgfk.js`).then(e=>e.cRuntime)),A(`cpp`,()=>import(`./cpp-Bhr_Zgfk.js`).then(e=>e.cppRuntime)),A(`react`,()=>import(`./react-ALhWeEZ5.js`).then(e=>e.reactRuntime));var N=String.raw`
18
+ `)}async function x(e){try{return await E(e)}catch(t){return console.warn(`[code-playpad] CodeMirror unavailable, using plain textarea:`,t),D(e)}}var S=/* @__PURE__ */ new Map,C=/* @__PURE__ */ new Set,w=!1;function T(){w||(w=!0,queueMicrotask(()=>{w=!1;for(let e of C){let t=[...e.adoptedStyleSheets];e.adoptedStyleSheets=[],e.adoptedStyleSheets=t}}))}async function E(e){let[t,n,r,i,a,o,s]=await Promise.all([import(`./dist-D4P7t1AU.js`).then(e=>e.s),import(`./dist-CjnVq6q1.js`).then(e=>e.x),import(`./dist-g8djAEMH.js`),import(`./dist-CTLX4tws.js`),import(`./dist-_fde-E8H.js`).then(e=>e.n),import(`./dist-DHeVjdBc.js`),import(`./dist-IFh_mUXG.js`).then(e=>e.t)]),{EditorView:c,keymap:l,lineNumbers:d,highlightActiveLine:f,highlightActiveLineGutter:p,highlightSpecialChars:m,drawSelection:h,rectangularSelection:g,crosshairCursor:_}=t,{EditorState:v,Compartment:y}=n,{defaultKeymap:b,history:x,historyKeymap:w,indentWithTab:E}=r,{syntaxHighlighting:D,defaultHighlightStyle:O,HighlightStyle:k,indentOnInput:A,bracketMatching:j,foldGutter:M,foldKeymap:N}=i,{autocompletion:P,closeBrackets:F,closeBracketsKeymap:I,completionKeymap:L}=a,R=new y,z=new y,B=new y,V=S.get(`default-light`)??[c.theme({"&":{color:`#1f2328`,backgroundColor:`#ffffff`},".cm-gutters":{backgroundColor:`#f6f8fa`,color:`#8b949e`,border:`none`},".cm-activeLine":{backgroundColor:`#f6f8fa88`},".cm-activeLineGutter":{backgroundColor:`#eaeef2`},".cm-cursor":{borderLeftColor:`#1f2328`},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:`#cfe3ff`}}),D(O,{fallback:!0})];S.set(`default-light`,V);let{tags:H}=s,U=(e,t)=>[c.theme({"&":{color:e.fg,backgroundColor:e.bg},".cm-content":{caretColor:e.fg},".cm-gutters":{backgroundColor:e.surface,color:e.muted,border:`none`},".cm-activeLine":{backgroundColor:e.activeLine},".cm-activeLineGutter":{backgroundColor:e.selection},".cm-cursor, .cm-dropCursor":{borderLeftColor:e.fg},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:e.selection},".cm-tooltip":{backgroundColor:e.surface,color:e.fg,border:`1px solid ${e.border}`},".cm-tooltip-autocomplete > ul > li[aria-selected]":{backgroundColor:e.selection,color:e.fg}},{dark:t}),D(k.define([{tag:[H.comment,H.meta],color:e.comment,fontStyle:`italic`},{tag:[H.keyword,H.operatorKeyword,H.modifier],color:e.keyword},{tag:[H.string,H.special(H.string),H.regexp],color:e.string},{tag:[H.number,H.bool,H.null,H.atom],color:e.number},{tag:[H.function(H.variableName),H.function(H.propertyName),H.definition(H.function(H.variableName))],color:e.fn},{tag:[H.typeName,H.className,H.namespace,H.tagName],color:e.type},{tag:[H.variableName,H.propertyName,H.attributeName],color:e.variable},{tag:H.invalid,color:e.keyword,textDecoration:`underline`}]))],W=(e,t)=>{let n=u.find(e=>e.id===t);if(!n?.colors)return e?o.oneDark:V;let r=S.get(n.id);return r||(r=U(n.colors,n.mode===`dark`),S.set(n.id,r)),r},G=l.of([{key:`Mod-Enter`,preventDefault:!0,run:()=>(e.onRun?.(),!0)},{key:`Shift-Enter`,preventDefault:!0,run:()=>(e.onRun?.(),!0)}]),K=e.dark,q=e.themeId,J=e.readOnly,Y=e.language??[],X=t=>v.create({doc:t,extensions:[d(),p(),m(),x(),M(),h(),v.allowMultipleSelections.of(!0),A(),j(),F(),P(),g(),_(),f(),G,l.of([...I,...b,...w,...N,...L,E]),c.lineWrapping,B.of(Y),R.of(W(K,q)),z.of(v.readOnly.of(J)),c.updateListener.of(t=>{t.startState.facet(c.styleModule)!==t.state.facet(c.styleModule)&&T(),t.docChanged&&e.onChange?.(t.state.doc.toString())})]}),Z=new c({parent:e.parent,state:X(e.doc)});C.add(Z.root),T();let Q=/* @__PURE__ */ new Map,$=e.name??``;return{fallback:!1,getCode:()=>Z.state.doc.toString(),setCode(e){Z.dispatch({changes:{from:0,to:Z.state.doc.length,insert:e}})},openFile(e,t){if(e===$)return;Q.set($,Z.state);let n=Q.get(e);Z.setState(n??X(t)),$=e,n&&Z.dispatch({effects:[R.reconfigure(W(K,q)),z.reconfigure(v.readOnly.of(J)),B.reconfigure(Y)]}),T()},fileCode(e,t){if(e===$)return Z.state.doc.toString();let n=Q.get(e);return n?n.doc.toString():t},forgetFiles(e){for(let t of[...Q.keys()])e.includes(t)||Q.delete(t)},setTheme(e,t){K=e,q=t,Z.dispatch({effects:R.reconfigure(W(K,q))})},setReadOnly(e){J=e,Z.dispatch({effects:z.reconfigure(v.readOnly.of(J))})},setLanguage(e){Y=e,Z.dispatch({effects:B.reconfigure(Y)})},focus:()=>Z.focus(),destroy(){C.delete(Z.root),Z.destroy()}}}function D(e){let t=document.createElement(`textarea`);t.className=`cp-fallback-editor`,t.spellcheck=!1,t.value=e.doc,t.readOnly=e.readOnly,t.addEventListener(`input`,()=>e.onChange?.(t.value)),t.addEventListener(`keydown`,t=>{(t.metaKey||t.ctrlKey)&&t.key===`Enter`&&(t.preventDefault(),e.onRun?.())}),e.parent.appendChild(t);let n=/* @__PURE__ */ new Map,r=e.name??``;return{fallback:!0,getCode:()=>t.value,setCode:e=>{t.value=e},openFile(e,i){e!==r&&(n.set(r,t.value),t.value=n.get(e)??i,r=e)},fileCode(e,i){return e===r?t.value:n.get(e)??i},forgetFiles(e){for(let t of[...n.keys()])e.includes(t)||n.delete(t)},setTheme:()=>{},setReadOnly:e=>{t.readOnly=e},setLanguage:()=>{},focus:()=>t.focus(),destroy:()=>t.remove()}}var O=/* @__PURE__ */ new Map,k=/* @__PURE__ */ new Map;function A(e,t){O.set(e,t)}function j(){return[...O.keys()]}function M(e){let t=k.get(e);if(t)return t;let n=O.get(e);if(!n)return Promise.reject(/* @__PURE__ */ Error(`Unknown runtime "${e}". Registered: ${j().join(`, `)||`none`}`));let r=n().catch(t=>{throw k.delete(e),t});return k.set(e,r),r}A(`python`,()=>import(`./pyodide-QurAOd7j.js`).then(e=>e.pythonRuntime)),A(`javascript`,()=>import(`./javascript-BBiCDtZ3.js`).then(e=>e.javascriptRuntime)),A(`typescript`,()=>import(`./javascript-BBiCDtZ3.js`).then(e=>e.typescriptRuntime)),A(`java`,()=>import(`./java-DjuG1fCk.js`).then(e=>e.javaRuntime)),A(`c`,()=>import(`./cpp-Bhr_Zgfk.js`).then(e=>e.cRuntime)),A(`cpp`,()=>import(`./cpp-Bhr_Zgfk.js`).then(e=>e.cppRuntime)),A(`react`,()=>import(`./react-DgCTfCMl.js`).then(e=>e.reactRuntime)),A(`next`,()=>import(`./next-CO6N0Gb9.js`).then(e=>e.nextRuntime));var N=String.raw`
19
19
  :host {
20
20
  --cp-bg: #ffffff;
21
21
  --cp-fg: #1f2328;
@@ -345,6 +345,11 @@ table.cp-table th, table.cp-table td {
345
345
  table.cp-table th { background: var(--cp-bg); }
346
346
 
347
347
  .cp-progress {
348
+ /* Over the content, not above it: a bar that took space would move the preview when it
349
+ goes, and a moved frame misses clicks for a moment in Chrome. */
350
+ position: relative;
351
+ z-index: 1;
352
+ margin-bottom: -2px;
348
353
  height: 2px;
349
354
  background: linear-gradient(90deg, transparent, var(--cp-accent), transparent);
350
355
  background-size: 40% 100%;
@@ -374,6 +379,19 @@ table.cp-table th { background: var(--cp-bg); }
374
379
  border: 0;
375
380
  background: #ffffff;
376
381
  }
382
+ .cp-next-bar {
383
+ display: flex;
384
+ gap: 4px;
385
+ align-items: center;
386
+ height: 32px;
387
+ box-sizing: border-box;
388
+ padding: 3px 6px;
389
+ background: var(--cp-surface);
390
+ border-bottom: 1px solid var(--cp-border);
391
+ }
392
+ .cp-next-bar button { flex: none; width: 24px; height: 24px; padding: 0; cursor: pointer; }
393
+ .cp-next-bar input { flex: 1 1 auto; min-width: 0; height: 24px; box-sizing: border-box; padding: 0 8px; font: 12px ui-monospace, monospace; }
394
+ .cp-next-bar + .cp-preview-frame { height: calc(100% - 32px); }
377
395
  .cp-preview-banner {
378
396
  position: absolute;
379
397
  left: 0;
@@ -468,14 +486,19 @@ table.cp-table th { background: var(--cp-bg); }
468
486
  :host([data-window]) .cp-source { flex: 1 1 0; display: flex; flex-direction: column; }
469
487
  :host([data-window]) .cp-has-tree .cp-source { display: grid; }
470
488
  :host([data-window]) .cp-preview-pane { flex: 1 1 0; }
489
+ :host([data-window]) .cp-editor-sized .cp-source { flex: none; }
471
490
 
472
491
  /* file-view="tree": the files in a column beside the editor. */
473
492
  .cp-root.cp-has-tree { container-type: inline-size; }
474
493
  .cp-has-tree .cp-source {
475
494
  display: grid;
476
- grid-template-columns: var(--cp-tree-width, 200px) 7px minmax(0, 1fr);
495
+ grid-template-columns: min(var(--cp-tree-width, 200px), calc(100% - 167px)) 7px minmax(0, 1fr);
477
496
  grid-template-rows: 1fr auto;
478
497
  }
498
+ /* With a preview, the code gets its own row, so the tree shares only that. */
499
+ .cp-has-tree.cp-has-preview .cp-source { grid-template-columns: min(var(--cp-tree-width, 20%), calc(100% - 167px)) 7px minmax(0, 1fr); }
500
+ /* A sized row follows the divider, so a long tree scrolls instead of holding it open. */
501
+ .cp-editor-sized.cp-has-tree .cp-tabs.cp-tree { height: 0; min-height: 100%; }
479
502
  .cp-has-tree .cp-source > :not(.cp-tabs, .cp-split-tree) { grid-column: 3; }
480
503
  .cp-has-tree .cp-split-tree { display: block; grid-column: 2; grid-row: 1 / span 2; }
481
504
  .cp-tabs.cp-tree {
@@ -519,19 +542,20 @@ table.cp-table th { background: var(--cp-bg); }
519
542
  .cp-has-tree .cp-source { display: block; }
520
543
  .cp-has-tree .cp-split-tree { display: none; }
521
544
  .cp-tabs.cp-tree { max-height: 150px; border-bottom: 1px solid var(--cp-border); }
545
+ .cp-editor-sized.cp-has-tree .cp-tabs.cp-tree { height: auto; min-height: 0; }
522
546
  }
523
547
 
524
- /* Only a preview sits beside the code: a tree makes any widget a container. */
548
+ /* Only a preview sits beside the code, and only with no tree: three columns leave
549
+ the preview too little room. A tree makes any widget a container. */
525
550
  @container (min-width: 760px) {
526
- .cp-has-preview .cp-body { display: flex; align-items: stretch; }
527
- .cp-has-preview .cp-source { flex: 0 0 var(--cp-source-width, calc(50% - 4px)); min-width: 0; }
528
- .cp-has-preview .cp-preview-pane { flex: 1 1 0; min-width: 0; }
529
- .cp-has-preview .cp-preview { border-top: 0; }
530
- .cp-has-preview .cp-source:not(:has(.cp-tree)) { display: flex; flex-direction: column; }
531
- .cp-has-preview .cp-source:not(:has(.cp-tree)) .cp-editor { flex: 1 1 auto; }
532
- .cp-split.cp-split-main { width: 7px; height: auto; cursor: col-resize; border-width: 0 1px; }
533
- :host([data-window]) .cp-body { flex-direction: row; }
534
- :host([data-window]) .cp-source { flex: 0 0 var(--cp-source-width, calc(50% - 4px)); }
551
+ .cp-has-preview:not(.cp-has-tree) .cp-body { display: flex; align-items: stretch; }
552
+ .cp-has-preview:not(.cp-has-tree) .cp-source { display: flex; flex-direction: column; flex: 0 0 var(--cp-source-width, calc(50% - 4px)); min-width: 0; }
553
+ .cp-has-preview:not(.cp-has-tree) .cp-source .cp-editor { flex: 1 1 auto; }
554
+ .cp-has-preview:not(.cp-has-tree) .cp-preview-pane { flex: 1 1 0; min-width: 0; }
555
+ .cp-has-preview:not(.cp-has-tree) .cp-preview { border-top: 0; }
556
+ .cp-has-preview:not(.cp-has-tree) .cp-split.cp-split-main { width: 7px; height: auto; cursor: col-resize; border-width: 0 1px; }
557
+ :host([data-window]) .cp-root:not(.cp-has-tree) .cp-body { flex-direction: row; }
558
+ :host([data-window]) .cp-root:not(.cp-has-tree) .cp-source { flex: 0 0 var(--cp-source-width, calc(50% - 4px)); }
535
559
  }
536
560
 
537
561
  @keyframes cp-slide {
@@ -542,13 +566,13 @@ table.cp-table th { background: var(--cp-bg); }
542
566
  @media (prefers-reduced-motion: reduce) {
543
567
  .cp-progress { animation: none; background-position: 0 0; background-size: 100% 100%; opacity: 0.4; }
544
568
  }
545
- `,P=e=>()=>import(`./dist-BwlTZqCY.js`).then(t=>t.javascript(e)),F={py:()=>import(`./dist-CRXZcpYD.js`).then(e=>e.python()),pyi:()=>import(`./dist-CRXZcpYD.js`).then(e=>e.python()),js:P({}),mjs:P({}),cjs:P({}),jsx:P({jsx:!0}),ts:P({typescript:!0}),mts:P({typescript:!0}),cts:P({typescript:!0}),tsx:P({typescript:!0,jsx:!0}),json:()=>import(`./dist-BDifu2bQ.js`).then(e=>e.json()),css:()=>import(`./dist-UbI3_a5S.js`).then(e=>e.css()),html:()=>import(`./dist-C41hAfPr.js`).then(e=>e.html()),c:()=>import(`./dist-3xj9-ylK.js`).then(e=>e.cpp()),h:()=>import(`./dist-3xj9-ylK.js`).then(e=>e.cpp()),cpp:()=>import(`./dist-3xj9-ylK.js`).then(e=>e.cpp()),cc:()=>import(`./dist-3xj9-ylK.js`).then(e=>e.cpp()),cxx:()=>import(`./dist-3xj9-ylK.js`).then(e=>e.cpp()),hpp:()=>import(`./dist-3xj9-ylK.js`).then(e=>e.cpp()),hxx:()=>import(`./dist-3xj9-ylK.js`).then(e=>e.cpp()),java:()=>import(`./dist-ixcYRC9x.js`).then(e=>e.java())};async function I(e,t){let n=e.includes(`.`)?e.slice(e.lastIndexOf(`.`)+1).toLowerCase():``,r=t===`react`&&n===`js`?F.jsx:F[n];return r?r().catch(()=>null):null}var L=`code-playpad`,R=1,z=`snippets`,B=`progress`,V=null;function H(){return typeof indexedDB>`u`?Promise.reject(/* @__PURE__ */ Error(`IndexedDB unavailable`)):(V||=new Promise((e,t)=>{let n=indexedDB.open(L,R);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(z)||e.createObjectStore(z),e.objectStoreNames.contains(B)||e.createObjectStore(B,{keyPath:`id`})},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}).catch(e=>{throw V=null,e}),V)}function U(e,t,n){return H().then(r=>new Promise((i,a)=>{let o=n(r.transaction(e,t).objectStore(e));o.onsuccess=()=>i(o.result),o.onerror=()=>a(o.error)}))}function W(e,t){return U(z,`readwrite`,n=>n.put(t,e)).then(()=>void 0)}function G(e){return U(z,`readonly`,t=>t.get(e)).then(e=>e??null)}function K(e){return U(z,`readwrite`,t=>t.delete(e)).then(()=>void 0)}function q(e,t={}){let n={completed:!0,...t,id:e,updatedAt:Date.now()};return U(B,`readwrite`,e=>e.put(n)).then(()=>n)}function J(e){return U(B,`readonly`,t=>t.get(e)).then(e=>e??null)}function Y(){return U(B,`readonly`,e=>e.getAll())}var X=`code-playpad`;function Z(e){let t=e.replace(/\t/g,` `).split(`
569
+ `,P=e=>()=>import(`./dist-BwlTZqCY.js`).then(t=>t.javascript(e)),F={py:()=>import(`./dist-CRXZcpYD.js`).then(e=>e.python()),pyi:()=>import(`./dist-CRXZcpYD.js`).then(e=>e.python()),js:P({}),mjs:P({}),cjs:P({}),jsx:P({jsx:!0}),ts:P({typescript:!0}),mts:P({typescript:!0}),cts:P({typescript:!0}),tsx:P({typescript:!0,jsx:!0}),json:()=>import(`./dist-BDifu2bQ.js`).then(e=>e.json()),css:()=>import(`./dist-UbI3_a5S.js`).then(e=>e.css()),html:()=>import(`./dist-C41hAfPr.js`).then(e=>e.html()),c:()=>import(`./dist-3xj9-ylK.js`).then(e=>e.cpp()),h:()=>import(`./dist-3xj9-ylK.js`).then(e=>e.cpp()),cpp:()=>import(`./dist-3xj9-ylK.js`).then(e=>e.cpp()),cc:()=>import(`./dist-3xj9-ylK.js`).then(e=>e.cpp()),cxx:()=>import(`./dist-3xj9-ylK.js`).then(e=>e.cpp()),hpp:()=>import(`./dist-3xj9-ylK.js`).then(e=>e.cpp()),hxx:()=>import(`./dist-3xj9-ylK.js`).then(e=>e.cpp()),java:()=>import(`./dist-ixcYRC9x.js`).then(e=>e.java())};async function I(e,t){let n=e.includes(`.`)?e.slice(e.lastIndexOf(`.`)+1).toLowerCase():``,r=(t===`react`||t===`next`)&&n===`js`?F.jsx:F[n];return r?r().catch(()=>null):null}var L=`code-playpad`,R=1,z=`snippets`,B=`progress`,V=null;function H(){return typeof indexedDB>`u`?Promise.reject(/* @__PURE__ */ Error(`IndexedDB unavailable`)):(V||=new Promise((e,t)=>{let n=indexedDB.open(L,R);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(z)||e.createObjectStore(z),e.objectStoreNames.contains(B)||e.createObjectStore(B,{keyPath:`id`})},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}).catch(e=>{throw V=null,e}),V)}function U(e,t,n){return H().then(r=>new Promise((i,a)=>{let o=n(r.transaction(e,t).objectStore(e));o.onsuccess=()=>i(o.result),o.onerror=()=>a(o.error)}))}function W(e,t){return U(z,`readwrite`,n=>n.put(t,e)).then(()=>void 0)}function G(e){return U(z,`readonly`,t=>t.get(e)).then(e=>e??null)}function K(e){return U(z,`readwrite`,t=>t.delete(e)).then(()=>void 0)}function q(e,t={}){let n={completed:!0,...t,id:e,updatedAt:Date.now()};return U(B,`readwrite`,e=>e.put(n)).then(()=>n)}function J(e){return U(B,`readonly`,t=>t.get(e)).then(e=>e??null)}function Y(){return U(B,`readonly`,e=>e.getAll())}var X=`code-playpad`;function Z(e){let t=e.replace(/\t/g,` `).split(`
546
570
  `);for(;t.length&&t[0].trim()===``;)t.shift();for(;t.length&&t[t.length-1].trim()===``;)t.pop();let n=t.filter(e=>e.trim()!==``).reduce((e,t)=>Math.min(e,t.match(/^ */)[0].length),1/0);return(n===1/0?t:t.map(e=>e.slice(n))).join(`
547
- `)}var Q=2e5,$=`playpad-file`,ee={python:`main.py`,javascript:`main.js`,typescript:`main.ts`,java:`Main.java`,c:`main.c`,cpp:`main.cpp`,react:`src/main.jsx`};function te(e){return ee[e]??`main.txt`}var ne=e=>e.tagName===`SCRIPT`&&e.getAttribute(`type`)===`text/plain`;function re(e){return[...e.children].filter(e=>e.tagName.toLowerCase()===$&&[...e.children].some(e=>!ne(e))).map(e=>e.getAttribute(`name`)??``)}function ie(e,t){let n={};for(let t of e.children){if(t.tagName.toLowerCase()!==$)continue;let e=t.getAttribute(`name`),r=[...t.children].find(ne);e&&(n[e]=Z((r??t).textContent??``))}if(Object.keys(n).length)return n;let r=[...e.childNodes].filter(e=>e.nodeType!==Node.ELEMENT_NODE||e.tagName.toLowerCase()!==$),i=r.some(e=>e.nodeType===Node.ELEMENT_NODE),a=Z(r.filter(e=>!(i&&e.nodeType===Node.TEXT_NODE&&!(e.textContent??``).trim())).map(e=>e.textContent??``).join(``));return{[t]:a}}function ae(e,t){try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t)){let e=t;return Object.keys(e).length?e:null}}catch{}return e?{[t]:e}:null}var oe=typeof HTMLElement>`u`?class{}:HTMLElement,se=class extends oe{static get observedAttributes(){return[`language`,`height`,`min-height`,`max-height`,`preview-height`,`file-view`,`open-file`,`theme`,`theme-controls`,`readonly`,`autorun`,`stdin`,`persist`,`entry`,`practice`]}#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u=null;#d=null;#f=null;#p=null;#m={};#h={};#g=`main.py`;#_=null;#v;#y=!1;#b=null;#x=!1;#S=!1;#C=null;#w=null;#T=null;#E=()=>this.#fe();#D=null;#O=null;#k=!0;#A=[];#j=null;#M=null;#N=null;#P=0;#F=!1;#I=null;#L;#R;#z=null;#B=[];#V=/* @__PURE__ */ new Set;#H=null;#U=null;#W=null;constructor(){super(),this.#e=this.attachShadow({mode:`open`})}get code(){return this.#u?this.#u.getCode():this.#m[this.#g]??``}set code(e){this.#m[this.#g]=e,this.#Z()}get practice(){if(this.#I)return this.#I;let e=this.getAttribute(`practice`);if(!e)return null;try{return JSON.parse(e)}catch{return null}}set practice(e){this.#I=e}get files(){return this.#re()}set files(e){let t=Object.keys(e);if(!t.length)return;let n=Object.keys(this.#h);n.length===1&&!this.#h[n[0]]&&(this.#h={...e}),this.#m={...e},this.#B=[],t.includes(this.#g)||(this.#g=this.#te()),this.#u?.forgetFiles([]),this.#Z(),this.#ie(),this.#X()}get entry(){return this.#te()}set entry(e){this.setAttribute(`entry`,e)}openFile(e){if(e in this.#m){this.#u&&(this.#m[this.#g]=this.#u.getCode(),this.#u.openFile(e,this.#m[e]??``)),this.#g=e;for(let t=e.indexOf(`/`);t!==-1;t=e.indexOf(`/`,t+1))this.#V.delete(e.slice(0,t));this.#ie(),this.#X()}}get stdin(){return this.#l?this.#l.value:``}set stdin(e){this.#l&&(this.#l.value=e,this.#c.hidden=!1)}get language(){return this.getAttribute(`language`)||`python`}set language(e){this.setAttribute(`language`,e)}getCode(){return this.code}getFiles(){return this.#re()}reset(){this.#m={...this.#h},this.#g=this.#te(),this.#u?.forgetFiles([]),this.#Z(),this.#ie(),this.#he(),this.#s.hidden=!0,this.#se(),this.#z=null,this.#ce(),this.#me(this.#f?.ready?`${this.#f.label} ready`:``,`idle`)}async run(){if(this.#H)return this.#H.widget.run();if(this.#y)return;await this.#d;let e=this.#re(),r=this.getAttribute(`entry`);if(r&&!(r in e))return this.#$(r,e);this.#Q=!1;let i=this.#te(),a=e[i]??``;this.#y=!0,this.#x=!1,this.#n.disabled=!0,this.#r.hidden=!1,this.#he(),this.#s.hidden=!1;let o=this.practice;this.hasAttribute(`practice`)&&!o&&this.#ge(`The practice attribute is not valid JSON.
571
+ `)}var Q=2e5,$=`playpad-file`,ee={python:`main.py`,javascript:`main.js`,typescript:`main.ts`,java:`Main.java`,c:`main.c`,cpp:`main.cpp`,react:`src/main.jsx`,next:`app/page.jsx`};function te(e){return ee[e]??`main.txt`}var ne=e=>e.tagName===`SCRIPT`&&e.getAttribute(`type`)===`text/plain`;function re(e){return[...e.children].filter(e=>e.tagName.toLowerCase()===$&&[...e.children].some(e=>!ne(e))).map(e=>e.getAttribute(`name`)??``)}function ie(e,t){let n={};for(let t of e.children){if(t.tagName.toLowerCase()!==$)continue;let e=t.getAttribute(`name`),r=[...t.children].find(ne);e&&(n[e]=Z((r??t).textContent??``))}if(Object.keys(n).length)return n;let r=[...e.childNodes].filter(e=>e.nodeType!==Node.ELEMENT_NODE||e.tagName.toLowerCase()!==$),i=r.some(e=>e.nodeType===Node.ELEMENT_NODE),a=Z(r.filter(e=>!(i&&e.nodeType===Node.TEXT_NODE&&!(e.textContent??``).trim())).map(e=>e.textContent??``).join(``));return{[t]:a}}function ae(e,t){try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t)){let e=t;return Object.keys(e).length?e:null}}catch{}return e?{[t]:e}:null}var oe=typeof HTMLElement>`u`?class{}:HTMLElement,se=class extends oe{static get observedAttributes(){return[`language`,`height`,`min-height`,`max-height`,`preview-height`,`tree-width`,`file-view`,`open-file`,`theme`,`theme-controls`,`readonly`,`autorun`,`stdin`,`persist`,`entry`,`practice`]}#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u=null;#d=null;#f=null;#p=null;#m={};#h={};#g=`main.py`;#_=null;#v;#y=!1;#b=null;#x=!1;#S=!1;#C=null;#w=null;#T=null;#E=()=>this.#fe();#D=null;#O=null;#k=!0;#A=[];#j=null;#M=null;#N=null;#P=0;#F=!1;#I=null;#L;#R;#z=null;#B=[];#V=/* @__PURE__ */ new Set;#H=null;#U=null;#W=null;constructor(){super(),this.#e=this.attachShadow({mode:`open`})}get code(){return this.#u?this.#u.getCode():this.#m[this.#g]??``}set code(e){this.#m[this.#g]=e,this.#Z()}get practice(){if(this.#I)return this.#I;let e=this.getAttribute(`practice`);if(!e)return null;try{return JSON.parse(e)}catch{return null}}set practice(e){this.#I=e}get files(){return this.#re()}set files(e){let t=Object.keys(e);if(!t.length)return;let n=Object.keys(this.#h);n.length===1&&!this.#h[n[0]]&&(this.#h={...e}),this.#m={...e},this.#B=[],t.includes(this.#g)||(this.#g=this.#te()),this.#u?.forgetFiles([]),this.#Z(),this.#ie(),this.#X()}get entry(){return this.#te()}set entry(e){this.setAttribute(`entry`,e)}openFile(e){if(e in this.#m){this.#u&&(this.#m[this.#g]=this.#u.getCode(),this.#u.openFile(e,this.#m[e]??``)),this.#g=e;for(let t=e.indexOf(`/`);t!==-1;t=e.indexOf(`/`,t+1))this.#V.delete(e.slice(0,t));this.#ie(),this.#X()}}get stdin(){return this.#l?this.#l.value:``}set stdin(e){this.#l&&(this.#l.value=e,this.#c.hidden=!1)}get language(){return this.getAttribute(`language`)||`python`}set language(e){this.setAttribute(`language`,e)}getCode(){return this.code}getFiles(){return this.#re()}reset(){this.#m={...this.#h},this.#g=this.#te(),this.#u?.forgetFiles([]),this.#Z(),this.#ie(),this.#he(),this.#s.hidden=!0,this.#se(),this.#z=null,this.#ce(),this.#me(this.#f?.ready?`${this.#f.label} ready`:``,`idle`)}async run(){if(this.#H)return this.#H.widget.run();if(this.#y)return;await this.#d;let e=this.#re(),r=this.getAttribute(`entry`);if(r&&!(r in e))return this.#$(r,e);this.#Q=!1;let i=this.#te(),a=e[i]??``;this.#y=!0,this.#x=!1,this.#n.disabled=!0,this.#r.hidden=!1,this.#he(),this.#s.hidden=!1;let o=this.practice;this.hasAttribute(`practice`)&&!o&&this.#ge(`The practice attribute is not valid JSON.
548
572
  `,`cp-err`),this.#oe()&&(this.#z=e,this.#ce(),this.#B.length&&this.#ge(`${this.#B.join(`, `)}: HTML tags in this file's markup were read as elements, so its code is incomplete. Write < as &lt;, or put the code in <script type="text/plain">. A <script> left unescaped runs on the host page.\n`,`cp-err`)),this.#Se(`py-run`,{code:a,entry:i,files:e,language:this.language,...o?{practice:o}:{}});try{let r=await this.#Y();if(this.#x)throw new t;if(o&&!r.supportsPractice)throw Error(`Practice mode is not available for ${r.label}.`);this.#me(`Queued…`,`busy`),this.#o.hidden=!1;let s=r.run(a,{stdin:this.#l.value,files:e,entry:i,onStart:()=>this.#me(`Running…`,`busy`),onProgress:e=>this.#me(e.message,`busy`),onStdout:e=>this.#ge(e),onStderr:e=>this.#ge(e,`cp-err`),onEcho:e=>this.#ge(e,`cp-in`),onStdinRequest:()=>this.#ve(),...o?{practice:o}:{},...this.#oe()?{preview:{host:this.#L,onStart:()=>this.#me(`Running…`,`busy`),onConsole:(e,t)=>{this.#ge(`${t}\n`,e===`error`?`cp-err`:e===`warn`?`cp-warn`:void 0),this.#Ce(`playpad-console`,{level:e,text:t,language:this.language})},onRender:e=>this.#Ce(`playpad-render`,{rootText:e,language:this.language}),onError:e=>{this.#me(`Error`,`error`),this.#Se(`py-error`,{...e,language:this.language})}}}:{}});this.#b={runtime:r,run:s};let c=await s;if(c.table&&this.#xe(c.table),c.value!==void 0&&this.#ge(`${c.value}\n`,`cp-value`),c.hint&&this.#be(c.hint,n.has(c)),c.failed=r.statusDecidesFailure?c.failed===!0:!!c.stderr,c.failed)this.#me(`Error · ${c.durationMs} ms`,`error`),this.#Se(`py-error`,{message:c.problem?.message??c.stderr??``,hint:c.hint,language:this.language,...c.problem??{}});else if(c.cases){let e=c.cases.filter(e=>e.expected!==void 0).length,t=c.passed===e;this.#me(e?`${c.passed} of ${e} passed · ${c.durationMs} ms`:`Done in ${c.durationMs} ms`,t?`ok`:`error`)}else this.#me(`Done in ${c.durationMs} ms`,`ok`);return this.#Se(`py-output`,{...c,language:this.language}),c}catch(e){if(e instanceof t)this.#ge(`
549
573
  [stopped]
550
574
  `,`cp-err`),this.#me(`Stopped`,`error`);else{let t=e instanceof Error?e.message:String(e);this.#ge(t+`
551
- `,`cp-err`),this.#me(`Failed to start`,`error`),this.#Se(`py-error`,{message:t,language:this.language})}return}finally{this.#b=null,this.#ye(null),this.#_e(),this.#y=!1,this.#n.disabled=!1,this.#r.hidden=!(this.#oe()&&this.#f?.hasLivePreview?.(this.#L)),this.#o.hidden=!0}}stop(){this.#H?this.#H.widget.stop():this.#b?this.#b.runtime.stop?.(this.#b.run):this.#y?this.#x=!0:this.#oe()&&this.#f?.hasLivePreview?.(this.#L)&&(this.#se(),this.#r.hidden=!0,this.#me(`Stopped`,`idle`))}openWindow(){if(this.#H)return this.#H.window.focus(),!0;if(this.#U)return!1;let e=window.open(``,`_blank`,`popup,width=1280,height=800`);if(!e)return this.#me(`The browser blocked the new window`,`error`),!1;let t=this.#re(),n=this.#g,r=document.createElement(this.localName);for(let e of[`language`,`entry`,`file-view`,`preview-height`,`theme`,`theme-controls`,`readonly`,`stdin`]){let t=this.getAttribute(e);t!==null&&r.setAttribute(e,t)}r.setAttribute(`data-window`,``),r.#U=this,r.#W={...this.#h},r.#_=t,this.#se(),this.#r.hidden=!0,e.document.title=`Code playground`,e.document.documentElement.style.height=`100%`,e.document.body.style.cssText=`margin:0;height:100%`,e.document.body.append(r);let i=()=>this.closeWindow();return window.addEventListener(`pagehide`,i),this.#H={window:e,widget:r,onLeave:i,timer:setInterval(()=>{e.closed&&this.closeWindow()},300)},this.#e.querySelector(`.cp-root`)?.classList.add(`cp-popped`),r.#d?.then(()=>(r.openFile(n),r.run())),!0}closeWindow(){let e=this.#H;if(!e)return;this.#H=null,clearInterval(e.timer),window.removeEventListener(`pagehide`,e.onLeave);let{widget:t}=e,n=t.#re(),r=t.#g;t.#se(),t.remove(),e.window.closed||e.window.close(),this.#e.querySelector(`.cp-root`)?.classList.remove(`cp-popped`),this.files=n,this.openFile(r),this.#me(``,`idle`)}prewarm(){return this.#Y()}connectedCallback(){this.#F?(this.#fe(),this.#J()):!this.textContent?.trim()&&document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>this.isConnected&&this.#G(),{once:!0}):this.#G()}disconnectedCallback(){this.#C?.disconnect(),this.#C=null,this.#w?.removeEventListener(`change`,this.#E),this.#w=null,this.#T?.disconnect(),this.#T=null,this.#D?.(),this.#D=null,this.#O&&clearTimeout(this.#O),this.#ye(null),setTimeout(()=>{this.isConnected||(this.closeWindow(),this.#se(),this.#u&&(this.#_=this.#re(),this.#u.destroy(),this.#u=null,this.#d=null,this.#F=!1))},0)}attributeChangedCallback(e,t,n){if(this.#F)switch(e){case`theme`:case`theme-controls`:this.#fe();break;case`height`:case`min-height`:case`max-height`:case`preview-height`:this.#pe();break;case`readonly`:this.#u?.setReadOnly(n!==null);break;case`stdin`:this.#c.hidden=n===null&&!this.#l.value;break;case`entry`:case`file-view`:this.#ie();break;case`language`:this.#se(),this.#e.querySelector(`.cp-root`)?.classList.toggle(`cp-has-preview`,this.#oe()),this.#f=null,this.#p=null,this.#S=!1,this.#Y().catch(()=>{})}}#G(){this.#F=!0,this.#h=this.#W??ie(this,this.#ee()),this.#B=this.#oe()?re(this):[],this.#m=this.#_??{...this.#h},this.#g=this.#ne(),this.#K(),this.#fe(),this.#pe();let e=this.getAttribute(`persist`);this.#d=(async()=>{if(e&&this.#_==null){let t=await G(e).catch(()=>null),n=t==null?null:ae(t,this.#ee());if(n){let e={},t=Object.keys(this.#h),r=Object.keys(n);for(let r of t)e[r]=n[r]??this.#h[r];t.length===1&&r.length===1&&!(t[0]in n)&&(e[t[0]]=n[r[0]]),this.#m=e,this.#g=this.#ne()}}this.#ie();let t=await M(this.language).catch(()=>null),n=t?await t.editorLanguage().catch(()=>null):null;this.#u=await x({parent:this.#t,doc:this.#m[this.#g]??``,name:this.#g,dark:this.#ue(),themeId:this.#de(),readOnly:this.hasAttribute(`readonly`),language:n,onRun:()=>void this.run(),onChange:e=>this.#le(e)}),this.#_=null,this.#fe(),this.#X()})(),this.#J()}#K(){let e=document.createElement(`style`);e.textContent=N;let t=document.createElement(`div`);t.className=this.#oe()?`cp-root cp-has-preview`:`cp-root`,t.innerHTML=`
575
+ `,`cp-err`),this.#me(`Failed to start`,`error`),this.#Se(`py-error`,{message:t,language:this.language})}return}finally{this.#b=null,this.#ye(null),this.#_e(),this.#y=!1,this.#n.disabled=!1,this.#r.hidden=!(this.#oe()&&this.#f?.hasLivePreview?.(this.#L)),this.#o.hidden=!0}}stop(){this.#H?this.#H.widget.stop():this.#b?this.#b.runtime.stop?.(this.#b.run):this.#y?this.#x=!0:this.#oe()&&this.#f?.hasLivePreview?.(this.#L)&&(this.#se(),this.#r.hidden=!0,this.#me(`Stopped`,`idle`))}openWindow(){if(this.#H)return this.#H.window.focus(),!0;if(this.#U)return!1;let e=window.open(``,`_blank`,`popup,width=1280,height=800`);if(!e)return this.#me(`The browser blocked the new window`,`error`),!1;let t=this.#re(),n=this.#g,r=document.createElement(this.localName);for(let e of[`language`,`entry`,`file-view`,`preview-height`,`tree-width`,`theme`,`theme-controls`,`readonly`,`stdin`]){let t=this.getAttribute(e);t!==null&&r.setAttribute(e,t)}r.setAttribute(`data-window`,``),r.#U=this,r.#W={...this.#h},r.#_=t,this.#se(),this.#r.hidden=!0,e.document.title=`Code playground`,e.document.documentElement.style.height=`100%`,e.document.body.style.cssText=`margin:0;height:100%`,e.document.body.append(r);let i=()=>this.closeWindow();return window.addEventListener(`pagehide`,i),this.#H={window:e,widget:r,onLeave:i,timer:setInterval(()=>{e.closed&&this.closeWindow()},300)},this.#e.querySelector(`.cp-root`)?.classList.add(`cp-popped`),r.#d?.then(()=>(r.openFile(n),r.run())),!0}closeWindow(){let e=this.#H;if(!e)return;this.#H=null,clearInterval(e.timer),window.removeEventListener(`pagehide`,e.onLeave);let{widget:t}=e,n=t.#re(),r=t.#g;t.#se(),t.remove(),e.window.closed||e.window.close(),this.#e.querySelector(`.cp-root`)?.classList.remove(`cp-popped`),this.files=n,this.openFile(r),this.#me(``,`idle`)}prewarm(){return this.#Y()}connectedCallback(){this.#F?(this.#fe(),this.#J()):!this.textContent?.trim()&&document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>this.isConnected&&this.#G(),{once:!0}):this.#G()}disconnectedCallback(){this.#C?.disconnect(),this.#C=null,this.#w?.removeEventListener(`change`,this.#E),this.#w=null,this.#T?.disconnect(),this.#T=null,this.#D?.(),this.#D=null,this.#O&&clearTimeout(this.#O),this.#ye(null),setTimeout(()=>{this.isConnected||(this.closeWindow(),this.#se(),this.#u&&(this.#_=this.#re(),this.#u.destroy(),this.#u=null,this.#d=null,this.#F=!1))},0)}attributeChangedCallback(e,t,n){if(this.#F)switch(e){case`theme`:case`theme-controls`:this.#fe();break;case`height`:case`min-height`:case`max-height`:case`preview-height`:case`tree-width`:this.#pe();break;case`readonly`:this.#u?.setReadOnly(n!==null);break;case`stdin`:this.#c.hidden=n===null&&!this.#l.value;break;case`entry`:case`file-view`:this.#ie();break;case`language`:this.#se(),this.#e.querySelector(`.cp-root`)?.classList.toggle(`cp-has-preview`,this.#oe()),this.#f=null,this.#p=null,this.#S=!1,this.#Y().catch(()=>{})}}#G(){this.#F=!0,this.#h=this.#W??ie(this,this.#ee()),this.#B=this.#oe()?re(this):[],this.#m=this.#_??{...this.#h},this.#g=this.#ne(),this.#K(),this.#fe(),this.#pe();let e=this.getAttribute(`persist`);this.#d=(async()=>{if(e&&this.#_==null){let t=await G(e).catch(()=>null),n=t==null?null:ae(t,this.#ee());if(n){let e={},t=Object.keys(this.#h),r=Object.keys(n);for(let r of t)e[r]=n[r]??this.#h[r];t.length===1&&r.length===1&&!(t[0]in n)&&(e[t[0]]=n[r[0]]),this.#m=e,this.#g=this.#ne()}}this.#ie();let t=await M(this.language).catch(()=>null),n=t?await t.editorLanguage().catch(()=>null):null;this.#u=await x({parent:this.#t,doc:this.#m[this.#g]??``,name:this.#g,dark:this.#ue(),themeId:this.#de(),readOnly:this.hasAttribute(`readonly`),language:n,onRun:()=>void this.run(),onChange:e=>this.#le(e)}),this.#_=null,this.#fe(),this.#X()})(),this.#J()}#K(){let e=document.createElement(`style`);e.textContent=N;let t=document.createElement(`div`);t.className=this.#oe()?`cp-root cp-has-preview`:`cp-root`,t.innerHTML=`
552
576
  <div class="cp-toolbar">
553
577
  <button class="cp-primary" part="run-button" data-action="run">Run</button>
554
578
  <button class="cp-danger" part="stop-button" data-action="stop" hidden>Stop</button>
@@ -592,8 +616,8 @@ table.cp-table th { background: var(--cp-bg); }
592
616
  <div class="cp-split cp-split-console" role="separator" tabindex="0" aria-orientation="horizontal" aria-label="Resize the preview and the console"></div>
593
617
  <pre class="cp-output" part="output" hidden></pre>
594
618
  </div>
595
- </div>`,this.#e.replaceChildren(e,t),this.#n=t.querySelector(`[data-action="run"]`),this.#r=t.querySelector(`[data-action="stop"]`),this.#i=t.querySelector(`[data-action="reset"]`),this.#a=t.querySelector(`.cp-status`),this.#o=t.querySelector(`.cp-progress`),this.#v=t.querySelector(`.cp-tabs`),this.#t=t.querySelector(`.cp-editor`),this.#c=t.querySelector(`.cp-stdin`),this.#l=t.querySelector(`.cp-stdin textarea`),this.#s=t.querySelector(`.cp-output`),this.#L=t.querySelector(`.cp-preview`),this.#R=t.querySelector(`.cp-edited-note`),this.#oe()||t.querySelector(`.cp-source`).after(this.#s),this.#c.hidden=!this.hasAttribute(`stdin`),this.#l.addEventListener(`input`,()=>this.#c.classList.remove(`cp-attention`)),this.#v.addEventListener(`click`,e=>{let t=e.target,n=t.closest(`button[data-file]`);n&&this.openFile(n.getAttribute(`data-file`));let r=t.closest(`button[data-folder]`)?.dataset.folder;r!==void 0&&(this.#V.delete(r)||this.#V.add(r),this.#ie())}),this.#n.addEventListener(`click`,()=>void this.run()),this.#r.addEventListener(`click`,()=>this.stop()),this.#i.addEventListener(`click`,()=>this.reset()),t.querySelector(`[data-action="theme"]`).addEventListener(`click`,()=>{v({mode:this.#ue()?`light`:`dark`})}),t.querySelector(`.cp-theme-picker select`).addEventListener(`change`,e=>{let t=e.target.value,n=u.find(e=>e.id===t)?.mode;n&&v({mode:n,[n]:t})}),t.querySelector(`[data-action="window"]`).addEventListener(`click`,()=>this.openWindow()),t.querySelector(`[data-action="show-window"]`).addEventListener(`click`,()=>this.openWindow()),t.querySelector(`[data-action="close-window"]`).addEventListener(`click`,()=>this.closeWindow()),this.#q(t);let n=()=>void this.#Y().catch(()=>{});this.#t.addEventListener(`pointerdown`,n,{once:!0}),this.#t.addEventListener(`focusin`,n,{once:!0})}#q(e){let t=e.querySelector(`.cp-body`),n=e.querySelector(`.cp-source`),r=e.querySelector(`.cp-preview`),i=e.querySelector(`.cp-preview-pane`),a=this.#v,o=(e,t,n)=>Math.round(Math.max(t,Math.min(e,Math.max(t,n)))),s=(t,n)=>e.style.setProperty(t,`${n}px`),c=(t,n,r,i,a)=>{let o=()=>t.setAttribute(`aria-orientation`,n()===`x`?`vertical`:`horizontal`);t.addEventListener(`pointerdown`,a=>{a.preventDefault();let o=n()===`x`,s=o?a.clientX:a.clientY,c=r();t.setPointerCapture(a.pointerId),e.classList.add(`cp-dragging`,o?`cp-dragging-x`:`cp-dragging-y`);let l=e=>i(c+(o?e.clientX:e.clientY)-s),u=()=>{e.classList.remove(`cp-dragging`,`cp-dragging-x`,`cp-dragging-y`),t.removeEventListener(`pointermove`,l),t.removeEventListener(`pointerup`,u),t.removeEventListener(`pointercancel`,u)};t.addEventListener(`pointermove`,l),t.addEventListener(`pointerup`,u),t.addEventListener(`pointercancel`,u)}),t.addEventListener(`keydown`,e=>{let t={ArrowLeft:-24,ArrowUp:-24,ArrowRight:24,ArrowDown:24}[e.key];t&&(e.preventDefault(),i(r()+t))}),t.addEventListener(`dblclick`,a),t.addEventListener(`focus`,o),t.addEventListener(`pointerenter`,o)},l=()=>getComputedStyle(t).flexDirection===`row`&&getComputedStyle(t).display===`flex`;c(e.querySelector(`.cp-split-tree`),()=>`x`,()=>a.getBoundingClientRect().width,e=>s(`--cp-tree-width`,o(e,90,n.getBoundingClientRect().width-160)),()=>e.style.removeProperty(`--cp-tree-width`)),c(e.querySelector(`.cp-split-main`),()=>l()?`x`:`y`,()=>l()?n.getBoundingClientRect().width:this.#t.getBoundingClientRect().height,n=>{l()?s(`--cp-source-width`,o(n,200,t.getBoundingClientRect().width-200)):(s(`--cp-editor-height`,o(n,80,2e3)),e.classList.add(`cp-editor-sized`))},()=>{e.style.removeProperty(`--cp-source-width`),e.style.removeProperty(`--cp-editor-height`),e.classList.remove(`cp-editor-sized`)}),c(e.querySelector(`.cp-split-console`),()=>`y`,()=>r.getBoundingClientRect().height,e=>s(`--cp-preview-height`,o(e,60,l()||this.#U?i.getBoundingClientRect().height-40:2e3)),()=>e.style.removeProperty(`--cp-preview-height`))}#J(){this.#U||this.#C||typeof IntersectionObserver>`u`||(this.#C=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(this.#C?.disconnect(),this.#C=null,this.#Y().then(()=>{this.hasAttribute(`autorun`)&&this.run()}).catch(()=>{}))},{rootMargin:`300px`}),this.#C.observe(this))}#Y(){return this.#p||=(async()=>{let e=await M(this.language);this.#f=e,!e.ready&&!this.#Q&&(this.#o.hidden=!1,this.#me(`Loading ${e.label}…`,`busy`));try{await e.load(e=>{!this.#y&&!this.#Q&&this.#me(e.message,e.phase===`ready`?`ok`:`busy`)})}catch(e){this.#p=null,this.#me(`Runtime unavailable`,`error`);let t=e instanceof Error?e.message:String(e);throw this.#ge(t+`
596
- `,`cp-err`),this.#s.hidden=!1,e}finally{this.#o.hidden=!0}return this.#X(),this.#S||(this.#S=!0,this.#Q||this.#me(`${e.label} ready`,`ok`),this.#Se(`py-ready`,{language:e.id,label:e.label})),e})(),this.#p}async#X(){if(!this.#u)return;let e=this.#g,t=await I(e,this.language);if(t){this.#g===e&&this.#u?.setLanguage(t);return}let n=e.includes(`.`)?null:await(this.#f??await M(this.language).catch(()=>null))?.editorLanguage().catch(()=>null);this.#g===e&&this.#u?.setLanguage(n??[])}#Z(){this.#u?this.#u.setCode(this.#m[this.#g]??``):this.#d?.then(()=>{this.#u?.setCode(this.#m[this.#g]??``),this.#ie()})}#Q=!1;#$(e,t){let n=Object.keys(t),r=`This widget's entry is "${e}", but it has no file of that name${n.length?` (its files: ${n.join(`, `)})`:``}. Set entry to one of its files.\n`;this.#he(),this.#s.hidden=!1,this.#ge(r,`cp-err`),this.#Q=!0,this.#me(`Error · entry not found`,`error`);let i={stdout:``,stderr:r,durationMs:0,failed:!0};return this.#Se(`py-error`,{message:r,language:this.language}),this.#Se(`py-output`,{...i,language:this.language}),i}#ee(){return this.getAttribute(`entry`)||te(this.language)}#te(){let e=Object.keys(this.#m),t=this.getAttribute(`entry`);if(t&&e.includes(t))return t;let n=this.#oe()&&e.includes(`index.html`)?`index.html`:te(this.language);return e.includes(n)?n:e[0]??n}#ne(){let e=this.getAttribute(`open-file`);return e&&e in this.#m?e:this.#te()}#re(){if(this.#H)return this.#H.widget.#re();let e={...this.#m};if(this.#u)for(let t of Object.keys(e))e[t]=this.#u.fileCode(t,e[t]);return e}#ie(){let e=Object.keys(this.#m);this.#v.hidden=e.length<2;let t=!this.#v.hidden&&this.getAttribute(`file-view`)===`tree`;if(this.#v.classList.toggle(`cp-tree`,t),this.#e.querySelector(`.cp-root`)?.classList.toggle(`cp-has-tree`,t),this.#v.hidden){this.#v.replaceChildren();return}if(t){this.#ae(e),this.#ce();return}let n=this.#te();this.#v.replaceChildren(...e.map(e=>{let t=document.createElement(`button`);t.dataset.file=e;let r=e.lastIndexOf(`/`)+1;if(r){let n=document.createElement(`span`);n.className=`cp-tab-folder`,n.textContent=e.slice(0,r),t.setAttribute(`aria-label`,e),t.append(n)}return t.append(e.slice(r)),t.setAttribute(`aria-pressed`,String(e===this.#g)),e===n&&(t.classList.add(`cp-entry`),t.title=`entry point — this is the file Run executes`),t})),this.#ce()}#ae(e){let t=this.#te(),n=[],r=(i,a)=>{let o=e.filter(e=>e.startsWith(i)).map(e=>e.slice(i.length)),s=[...new Set(o.filter(e=>e.includes(`/`)).map(e=>e.slice(0,e.indexOf(`/`))))].sort();for(let e of s){let t=i+e,o=!this.#V.has(t),s=document.createElement(`button`);s.className=`cp-tree-folder`,s.dataset.folder=t,s.textContent=e,s.setAttribute(`aria-expanded`,String(o)),s.style.setProperty(`--cp-depth`,String(a)),n.push(s),o&&r(`${t}/`,a+1)}for(let e of o.filter(e=>!e.includes(`/`)).sort()){let r=i+e,o=document.createElement(`button`);o.dataset.file=r,o.textContent=e,o.setAttribute(`aria-label`,r),o.setAttribute(`aria-pressed`,String(r===this.#g)),o.style.setProperty(`--cp-depth`,String(a)),r===t&&(o.classList.add(`cp-entry`),o.title=`entry point — this is the file Run executes`),n.push(o)}};r(``,0),this.#v.replaceChildren(...n)}#oe(){return this.language===`react`}#se(){this.#L&&(this.#f?.dispose?.(this.#L),this.#L.replaceChildren())}#ce(){if(!this.#oe())return;let e=this.#re();for(let t of this.#v.querySelectorAll(`button[data-file]`)){let n=t.dataset.file;t.classList.toggle(`cp-edited`,e[n]!==this.#h[n])}let t=this.#z;this.#R.hidden=!t||Object.keys(e).every(n=>e[n]===t[n])}#le(e){this.#m[this.#g]=e,this.#ce();let t=this.getAttribute(`persist`);if(!t)return;this.#O&&clearTimeout(this.#O);let n=JSON.stringify(this.#re());this.#O=setTimeout(()=>void W(t,n).catch(()=>{}),400)}#ue(){let e=this.getAttribute(`theme`)??`auto`;if(e===`dark`)return!0;if(e===`light`)return!1;let t=_().mode;if(t)return t===`dark`;let n=typeof document>`u`?``:getComputedStyle(document.documentElement).colorScheme,r=n.includes(`dark`);return r===n.includes(`light`)?!!this.#w?.matches:r}#de(){return _()[this.#ue()?`dark`:`light`]}#fe(){this.#D??=y(this.#E),!this.#w&&typeof matchMedia==`function`&&(this.#w=matchMedia(`(prefers-color-scheme: dark)`),this.#w.addEventListener(`change`,this.#E)),!this.#T&&typeof MutationObserver==`function`&&typeof document<`u`&&(this.#T=new MutationObserver(this.#E),this.#T.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`,`style`,`data-theme`,`data-color-scheme`,`color-scheme`]}));let e=this.#ue(),t=this.#de();this.setAttribute(`data-resolved-theme`,e?`dark`:`light`),this.setAttribute(`data-editor-theme`,t),this.#u?.setTheme(e,t);let n=this.getAttribute(`theme`),r=n===`light`||n===`dark`||this.getAttribute(`theme-controls`)===`off`,i=this.#e.querySelector(`[data-action="theme"]`),a=this.#e.querySelector(`.cp-theme-picker`);if(i&&a){let n=e?`Switch to the light theme`:`Switch to the dark theme`;i.hidden=a.hidden=r,i.title=n,i.setAttribute(`aria-label`,n),a.querySelector(`select`).value=t}}#pe(){for(let[e,t]of[[`height`,`--cp-height`],[`min-height`,`--cp-min-height`],[`max-height`,`--cp-max-height`],[`preview-height`,`--cp-preview-height`]]){let n=this.getAttribute(e);n===null||n===``?this.style.removeProperty(t):this.style.setProperty(t,/^\d+$/.test(n)?`${n}px`:n)}}#me(e,t){this.#a.textContent=e,this.#a.dataset.state=t}#he(){this.#N&&clearTimeout(this.#N),this.#N=null,this.#A=[],this.#P=0,this.#s.replaceChildren(),this.#k=!0}#ge(e,t){if(!e)return;let n=t===`cp-err`&&!this.#k?`\n${e}`:e;this.#k=n.endsWith(`
619
+ </div>`,this.#e.replaceChildren(e,t),this.#n=t.querySelector(`[data-action="run"]`),this.#r=t.querySelector(`[data-action="stop"]`),this.#i=t.querySelector(`[data-action="reset"]`),this.#a=t.querySelector(`.cp-status`),this.#o=t.querySelector(`.cp-progress`),this.#v=t.querySelector(`.cp-tabs`),this.#t=t.querySelector(`.cp-editor`),this.#c=t.querySelector(`.cp-stdin`),this.#l=t.querySelector(`.cp-stdin textarea`),this.#s=t.querySelector(`.cp-output`),this.#L=t.querySelector(`.cp-preview`),this.#R=t.querySelector(`.cp-edited-note`),this.#oe()||t.querySelector(`.cp-source`).after(this.#s),this.#c.hidden=!this.hasAttribute(`stdin`),this.#l.addEventListener(`input`,()=>this.#c.classList.remove(`cp-attention`)),this.#v.addEventListener(`click`,e=>{let t=e.target,n=t.closest(`button[data-file]`);n&&this.openFile(n.getAttribute(`data-file`));let r=t.closest(`button[data-folder]`)?.dataset.folder;r!==void 0&&(this.#V.delete(r)||this.#V.add(r),this.#ie())}),this.#n.addEventListener(`click`,()=>void this.run()),this.#r.addEventListener(`click`,()=>this.stop()),this.#i.addEventListener(`click`,()=>this.reset()),t.querySelector(`[data-action="theme"]`).addEventListener(`click`,()=>{v({mode:this.#ue()?`light`:`dark`})}),t.querySelector(`.cp-theme-picker select`).addEventListener(`change`,e=>{let t=e.target.value,n=u.find(e=>e.id===t)?.mode;n&&v({mode:n,[n]:t})}),t.querySelector(`[data-action="window"]`).addEventListener(`click`,()=>this.openWindow()),t.querySelector(`[data-action="show-window"]`).addEventListener(`click`,()=>this.openWindow()),t.querySelector(`[data-action="close-window"]`).addEventListener(`click`,()=>this.closeWindow()),this.#q(t);let n=()=>void this.#Y().catch(()=>{});this.#t.addEventListener(`pointerdown`,n,{once:!0}),this.#t.addEventListener(`focusin`,n,{once:!0})}#q(e){let t=e.querySelector(`.cp-body`),n=e.querySelector(`.cp-source`),r=e.querySelector(`.cp-preview`),i=e.querySelector(`.cp-preview-pane`),a=this.#v,o=(e,t,n)=>Math.round(Math.max(t,Math.min(e,Math.max(t,n)))),s=(t,n)=>e.style.setProperty(t,`${n}px`),c=(t,n,r,i,a)=>{let o=()=>t.setAttribute(`aria-orientation`,n()===`x`?`vertical`:`horizontal`);t.addEventListener(`pointerdown`,a=>{a.preventDefault();let o=n()===`x`,s=o?a.clientX:a.clientY,c=r();t.setPointerCapture(a.pointerId),e.classList.add(`cp-dragging`,o?`cp-dragging-x`:`cp-dragging-y`);let l=e=>i(c+(o?e.clientX:e.clientY)-s),u=()=>{e.classList.remove(`cp-dragging`,`cp-dragging-x`,`cp-dragging-y`),t.removeEventListener(`pointermove`,l),t.removeEventListener(`pointerup`,u),t.removeEventListener(`pointercancel`,u)};t.addEventListener(`pointermove`,l),t.addEventListener(`pointerup`,u),t.addEventListener(`pointercancel`,u)}),t.addEventListener(`keydown`,e=>{let t={ArrowLeft:-24,ArrowUp:-24,ArrowRight:24,ArrowDown:24}[e.key];t&&(e.preventDefault(),i(r()+t))}),t.addEventListener(`dblclick`,a),t.addEventListener(`focus`,o),t.addEventListener(`pointerenter`,o)},l=()=>getComputedStyle(t).flexDirection===`row`&&getComputedStyle(t).display===`flex`;c(e.querySelector(`.cp-split-tree`),()=>`x`,()=>a.getBoundingClientRect().width,e=>s(`--cp-tree-width`,o(e,90,n.getBoundingClientRect().width-160)),()=>e.style.removeProperty(`--cp-tree-width`)),c(e.querySelector(`.cp-split-main`),()=>l()?`x`:`y`,()=>l()?n.getBoundingClientRect().width:this.#t.getBoundingClientRect().height,n=>{l()?s(`--cp-source-width`,o(n,200,t.getBoundingClientRect().width-200)):(s(`--cp-editor-height`,o(n,80,this.#U?t.getBoundingClientRect().height-100:2e3)),e.classList.add(`cp-editor-sized`))},()=>{e.style.removeProperty(`--cp-source-width`),e.style.removeProperty(`--cp-editor-height`),e.classList.remove(`cp-editor-sized`)}),c(e.querySelector(`.cp-split-console`),()=>`y`,()=>r.getBoundingClientRect().height,e=>s(`--cp-preview-height`,o(e,60,l()||this.#U?i.getBoundingClientRect().height-40:2e3)),()=>e.style.removeProperty(`--cp-preview-height`))}#J(){this.#U||this.#C||typeof IntersectionObserver>`u`||(this.#C=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(this.#C?.disconnect(),this.#C=null,this.#Y().then(()=>{this.hasAttribute(`autorun`)&&this.run()}).catch(()=>{}))},{rootMargin:`300px`}),this.#C.observe(this))}#Y(){return this.#p||=(async()=>{let e=await M(this.language);this.#f=e,!e.ready&&!this.#Q&&(this.#o.hidden=!1,this.#me(`Loading ${e.label}…`,`busy`));try{await e.load(e=>{!this.#y&&!this.#Q&&this.#me(e.message,e.phase===`ready`?`ok`:`busy`)})}catch(e){this.#p=null,this.#me(`Runtime unavailable`,`error`);let t=e instanceof Error?e.message:String(e);throw this.#ge(t+`
620
+ `,`cp-err`),this.#s.hidden=!1,e}finally{this.#o.hidden=!0}return this.#X(),this.#S||(this.#S=!0,this.#Q||this.#me(`${e.label} ready`,`ok`),this.#Se(`py-ready`,{language:e.id,label:e.label})),e})(),this.#p}async#X(){if(!this.#u)return;let e=this.#g,t=await I(e,this.language);if(t){this.#g===e&&this.#u?.setLanguage(t);return}let n=e.includes(`.`)?null:await(this.#f??await M(this.language).catch(()=>null))?.editorLanguage().catch(()=>null);this.#g===e&&this.#u?.setLanguage(n??[])}#Z(){this.#u?this.#u.setCode(this.#m[this.#g]??``):this.#d?.then(()=>{this.#u?.setCode(this.#m[this.#g]??``),this.#ie()})}#Q=!1;#$(e,t){let n=Object.keys(t),r=`This widget's entry is "${e}", but it has no file of that name${n.length?` (its files: ${n.join(`, `)})`:``}. Set entry to one of its files.\n`;this.#he(),this.#s.hidden=!1,this.#ge(r,`cp-err`),this.#Q=!0,this.#me(`Error · entry not found`,`error`);let i={stdout:``,stderr:r,durationMs:0,failed:!0};return this.#Se(`py-error`,{message:r,language:this.language}),this.#Se(`py-output`,{...i,language:this.language}),i}#ee(){return this.getAttribute(`entry`)||te(this.language)}#te(){let e=Object.keys(this.#m),t=this.getAttribute(`entry`);if(t&&e.includes(t))return t;let n=this.#oe()&&e.includes(`index.html`)?`index.html`:te(this.language);return e.includes(n)?n:e[0]??n}#ne(){let e=this.getAttribute(`open-file`);return e&&e in this.#m?e:this.#te()}#re(){if(this.#H)return this.#H.widget.#re();let e={...this.#m};if(this.#u)for(let t of Object.keys(e))e[t]=this.#u.fileCode(t,e[t]);return e}#ie(){let e=Object.keys(this.#m);this.#v.hidden=e.length<2;let t=!this.#v.hidden&&this.getAttribute(`file-view`)===`tree`;if(this.#v.classList.toggle(`cp-tree`,t),this.#e.querySelector(`.cp-root`)?.classList.toggle(`cp-has-tree`,t),this.#v.hidden){this.#v.replaceChildren();return}if(t){this.#ae(e),this.#ce();return}let n=this.#te();this.#v.replaceChildren(...e.map(e=>{let t=document.createElement(`button`);t.dataset.file=e;let r=e.lastIndexOf(`/`)+1;if(r){let n=document.createElement(`span`);n.className=`cp-tab-folder`,n.textContent=e.slice(0,r),t.setAttribute(`aria-label`,e),t.append(n)}return t.append(e.slice(r)),t.setAttribute(`aria-pressed`,String(e===this.#g)),e===n&&(t.classList.add(`cp-entry`),t.title=`entry point — this is the file Run executes`),t})),this.#ce()}#ae(e){let t=this.#te(),n=[],r=(i,a)=>{let o=e.filter(e=>e.startsWith(i)).map(e=>e.slice(i.length)),s=[...new Set(o.filter(e=>e.includes(`/`)).map(e=>e.slice(0,e.indexOf(`/`))))].sort();for(let e of s){let t=i+e,o=!this.#V.has(t),s=document.createElement(`button`);s.className=`cp-tree-folder`,s.dataset.folder=t,s.textContent=e,s.setAttribute(`aria-expanded`,String(o)),s.style.setProperty(`--cp-depth`,String(a)),n.push(s),o&&r(`${t}/`,a+1)}for(let e of o.filter(e=>!e.includes(`/`)).sort()){let r=i+e,o=document.createElement(`button`);o.dataset.file=r,o.textContent=e,o.setAttribute(`aria-label`,r),o.setAttribute(`aria-pressed`,String(r===this.#g)),o.style.setProperty(`--cp-depth`,String(a)),r===t&&(o.classList.add(`cp-entry`),o.title=`entry point — this is the file Run executes`),n.push(o)}};r(``,0),this.#v.replaceChildren(...n)}#oe(){return this.language===`react`||this.language===`next`}#se(){this.#L&&(this.#f?.dispose?.(this.#L),this.#L.replaceChildren())}#ce(){if(!this.#oe())return;let e=this.#re();for(let t of this.#v.querySelectorAll(`button[data-file]`)){let n=t.dataset.file;t.classList.toggle(`cp-edited`,e[n]!==this.#h[n])}let t=this.#z;this.#R.hidden=!t||Object.keys(e).every(n=>e[n]===t[n])}#le(e){this.#m[this.#g]=e,this.#ce();let t=this.getAttribute(`persist`);if(!t)return;this.#O&&clearTimeout(this.#O);let n=JSON.stringify(this.#re());this.#O=setTimeout(()=>void W(t,n).catch(()=>{}),400)}#ue(){let e=this.getAttribute(`theme`)??`auto`;if(e===`dark`)return!0;if(e===`light`)return!1;let t=_().mode;if(t)return t===`dark`;let n=typeof document>`u`?``:getComputedStyle(document.documentElement).colorScheme,r=n.includes(`dark`);return r===n.includes(`light`)?!!this.#w?.matches:r}#de(){return _()[this.#ue()?`dark`:`light`]}#fe(){this.#D??=y(this.#E),!this.#w&&typeof matchMedia==`function`&&(this.#w=matchMedia(`(prefers-color-scheme: dark)`),this.#w.addEventListener(`change`,this.#E)),!this.#T&&typeof MutationObserver==`function`&&typeof document<`u`&&(this.#T=new MutationObserver(this.#E),this.#T.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`,`style`,`data-theme`,`data-color-scheme`,`color-scheme`]}));let e=this.#ue(),t=this.#de();this.setAttribute(`data-resolved-theme`,e?`dark`:`light`),this.setAttribute(`data-editor-theme`,t),this.#u?.setTheme(e,t);let n=this.getAttribute(`theme`),r=n===`light`||n===`dark`||this.getAttribute(`theme-controls`)===`off`,i=this.#e.querySelector(`[data-action="theme"]`),a=this.#e.querySelector(`.cp-theme-picker`);if(i&&a){let n=e?`Switch to the light theme`:`Switch to the dark theme`;i.hidden=a.hidden=r,i.title=n,i.setAttribute(`aria-label`,n),a.querySelector(`select`).value=t}}#pe(){for(let[e,t]of[[`height`,`--cp-height`],[`min-height`,`--cp-min-height`],[`max-height`,`--cp-max-height`],[`preview-height`,`--cp-preview-height`]]){let n=this.getAttribute(e);n===null||n===``?this.style.removeProperty(t):this.style.setProperty(t,/^\d+$/.test(n)?`${n}px`:n)}let e=this.getAttribute(`tree-width`)?.trim();e?/^(\d+(px)?|\d+(\.\d+)?%)$/.test(e)?this.style.setProperty(`--cp-tree-width`,/\d$/.test(e)?`${e}px`:e):(this.style.removeProperty(`--cp-tree-width`),console.warn(`code-playpad: tree-width="${e}" is not a size. Use a percentage like "20%" or pixels like "240".`)):this.style.removeProperty(`--cp-tree-width`)}#me(e,t){this.#a.textContent=e,this.#a.dataset.state=t}#he(){this.#N&&clearTimeout(this.#N),this.#N=null,this.#A=[],this.#P=0,this.#s.replaceChildren(),this.#k=!0}#ge(e,t){if(!e)return;let n=t===`cp-err`&&!this.#k?`\n${e}`:e;this.#k=n.endsWith(`
597
621
  `),this.#A.push({text:n,className:t}),this.#N??=setTimeout(()=>this.#_e(),16)}#_e(){if(this.#N&&clearTimeout(this.#N),this.#N=null,!this.#A.length)return;let e=this.#A;this.#A=[];let t=document.createDocumentFragment(),n=``,r,i=()=>{if(!n)return;let e=document.createElement(`span`);r&&(e.className=r),e.textContent=n,t.appendChild(e),n=``};for(let t of e){if(this.#P>=Q)break;let e=t.text;this.#P+e.length>Q&&(e=e.slice(0,Q-this.#P)+`
598
622
  … output truncated for display — the full text is in the playpad-output event
599
623
  `),this.#P+=t.text.length,r!==t.className&&(i(),r=t.className),n+=e}i(),this.#s.hidden=!1;let a=this.#s.querySelector(`.cp-prompt`);a?this.#s.insertBefore(t,a):this.#s.appendChild(t),this.#s.scrollTop=this.#s.scrollHeight}#ve(){return this.#_e(),this.#ye(null),new Promise(e=>{let t=document.createElement(`form`);t.className=`cp-prompt`;let n=document.createElement(`input`);n.type=`text`,n.setAttribute(`aria-label`,`Program input — press Enter to send`),n.autocapitalize=`off`,n.autocomplete=`off`,n.spellcheck=!1;let r=document.createElement(`button`);r.type=`submit`,r.className=`cp-send`,r.textContent=`⏎`,r.title=`Send this line (Enter)`;let i=document.createElement(`button`);i.type=`button`,i.className=`cp-eof`,i.textContent=`EOF`,i.title=`End of input (Ctrl-D) — makes input() raise EOFError`;let a=n=>{this.#j===e&&(this.#j=null,this.#M=null,t.remove(),n===null?this.#ge(`
@@ -1,4 +1,4 @@
1
- import{d as e,l as t,u as n}from"./element-Dzhksh6_.js";var r=1,i=class{#e=null;#t=null;#n=`module`;#r=null;#i=null;#a=!1;#o=!1;#s=``;#c=/* @__PURE__ */ new Set;#l=[];#u=null;#d=!1;initPayload(){return{}}loadModule(e){return Promise.reject(/* @__PURE__ */ Error(`no module named ${e}`))}get ready(){return this.#a}get interactiveStdin(){return this.#o}get version(){return this.#s}load(t){t&&this.#c.add(t);let n=()=>{t&&this.#c.delete(t)};if(!this.#r){let t=new Promise((t,n)=>{this.#i={resolve:t,reject:n};let r;try{if(typeof Worker>`u`)throw Error(`Worker constructor missing`);let e=new Blob([this.source],{type:`text/javascript`});this.#t=URL.createObjectURL(e),r=new Worker(this.#t,{type:this.#n})}catch(t){this.#i=null,n(new e(`Could not start a Web Worker: ${t.message}`));return}this.#e=r,r.onmessage=e=>{let r=e.data;r.type===`ready`?(this.#s=r.version,this.#o=r.interactiveStdin===!0,this.#a=!0,this.#i=null,this.#h({phase:`ready`,message:`${this.label} ready`}),t()):r.type===`fatal`&&!this.#a?this.#p(r.message,t,n):this.#g(r)},r.onerror=e=>{let r=e.message||`Worker failed to start`;this.#a?this.#u&&this.#y(this.#u,Error(r)):this.#p(r,t,n)},r.postMessage({type:`init`,...this.initPayload()})});this.#r=t,t.catch(()=>{this.#r===t&&(this.#r=null)})}return this.#r.then(n,e=>{throw n(),e})}run(e,t={}){let n,i,a=new Promise((e,t)=>{n=e,i=t}),o,s=new Promise(e=>{o=e}),c={id:r++,code:e,options:t,stdout:``,stderr:``,resolve:n,reject:i,promise:a,started:!1,settled:!1,done:s,markDone:()=>{clearTimeout(c.timer),c.settled=!0,o()}};return this.#l.push(c),this.#b(),a}stop(e){if(e){let t=this.#l.findIndex(t=>t.promise===e);if(t!==-1){this.#y(this.#l.splice(t,1)[0],new n);return}let r=this.#u;if(!r||r.promise!==e||r.settled)return;if(!r.started){this.#y(r,new n);return}}this.#f()}#f(){let e=this.#e!==null,t=this.#i;if(this.#m(),this.#u&&this.#y(this.#u,new n),e){let e=this.load();t&&e.then(t.resolve,t.reject),e.catch(()=>{})}}#p(e,t,n){this.#m(),this.#n===`module`?(this.#n=`classic`,this.load().then(t,n)):n(Error(e))}#m(){this.#e?.terminate(),this.#e=null,this.#t&&=(URL.revokeObjectURL(this.#t),null),this.#r=null,this.#i=null,this.#a=!1}#h(e){for(let t of this.#c)t(e)}#g(e){if(e.type===`progress`){this.#h({phase:e.phase,message:e.message}),this.#u&&e.id===this.#u.id&&!this.#u.settled&&this.#u.options.onProgress?.({phase:e.phase,message:e.message});return}let n=this.#u;if(n&&`id`in e&&e.id===n.id)switch(e.type){case`stdout`:n.stdout+=e.text,n.options.onStdout?.(e.text);break;case`echo`:n.options.onEcho?.(e.text);break;case`stdin-request`:this.#v(n,e.request);break;case`module-request`:this.#_(n,e.name);break;case`stderr`:n.stderr+=e.text,n.options.onStderr?.(e.text);break;case`result`:n.resolve({stdout:n.stdout,stderr:n.stderr||void 0,value:e.value,durationMs:Math.round(e.durationMs),failed:!1,...e.memory?{memory:e.memory}:{},...e.cases?{cases:e.cases,passed:e.passed,total:e.total}:{}}),n.markDone();break;case`error`:case`fatal`:{let r=(n.stderr&&!n.stderr.endsWith(`
1
+ import{d as e,l as t,u as n}from"./element-BuS9dUwa.js";var r=1,i=class{#e=null;#t=null;#n=`module`;#r=null;#i=null;#a=!1;#o=!1;#s=``;#c=/* @__PURE__ */ new Set;#l=[];#u=null;#d=!1;initPayload(){return{}}loadModule(e){return Promise.reject(/* @__PURE__ */ Error(`no module named ${e}`))}get ready(){return this.#a}get interactiveStdin(){return this.#o}get version(){return this.#s}load(t){t&&this.#c.add(t);let n=()=>{t&&this.#c.delete(t)};if(!this.#r){let t=new Promise((t,n)=>{this.#i={resolve:t,reject:n};let r;try{if(typeof Worker>`u`)throw Error(`Worker constructor missing`);let e=new Blob([this.source],{type:`text/javascript`});this.#t=URL.createObjectURL(e),r=new Worker(this.#t,{type:this.#n})}catch(t){this.#i=null,n(new e(`Could not start a Web Worker: ${t.message}`));return}this.#e=r,r.onmessage=e=>{let r=e.data;r.type===`ready`?(this.#s=r.version,this.#o=r.interactiveStdin===!0,this.#a=!0,this.#i=null,this.#h({phase:`ready`,message:`${this.label} ready`}),t()):r.type===`fatal`&&!this.#a?this.#p(r.message,t,n):this.#g(r)},r.onerror=e=>{let r=e.message||`Worker failed to start`;this.#a?this.#u&&this.#y(this.#u,Error(r)):this.#p(r,t,n)},r.postMessage({type:`init`,...this.initPayload()})});this.#r=t,t.catch(()=>{this.#r===t&&(this.#r=null)})}return this.#r.then(n,e=>{throw n(),e})}run(e,t={}){let n,i,a=new Promise((e,t)=>{n=e,i=t}),o,s=new Promise(e=>{o=e}),c={id:r++,code:e,options:t,stdout:``,stderr:``,resolve:n,reject:i,promise:a,started:!1,settled:!1,done:s,markDone:()=>{clearTimeout(c.timer),c.settled=!0,o()}};return this.#l.push(c),this.#b(),a}stop(e){if(e){let t=this.#l.findIndex(t=>t.promise===e);if(t!==-1){this.#y(this.#l.splice(t,1)[0],new n);return}let r=this.#u;if(!r||r.promise!==e||r.settled)return;if(!r.started){this.#y(r,new n);return}}this.#f()}#f(){let e=this.#e!==null,t=this.#i;if(this.#m(),this.#u&&this.#y(this.#u,new n),e){let e=this.load();t&&e.then(t.resolve,t.reject),e.catch(()=>{})}}#p(e,t,n){this.#m(),this.#n===`module`?(this.#n=`classic`,this.load().then(t,n)):n(Error(e))}#m(){this.#e?.terminate(),this.#e=null,this.#t&&=(URL.revokeObjectURL(this.#t),null),this.#r=null,this.#i=null,this.#a=!1}#h(e){for(let t of this.#c)t(e)}#g(e){if(e.type===`progress`){this.#h({phase:e.phase,message:e.message}),this.#u&&e.id===this.#u.id&&!this.#u.settled&&this.#u.options.onProgress?.({phase:e.phase,message:e.message});return}let n=this.#u;if(n&&`id`in e&&e.id===n.id)switch(e.type){case`stdout`:n.stdout+=e.text,n.options.onStdout?.(e.text);break;case`echo`:n.options.onEcho?.(e.text);break;case`stdin-request`:this.#v(n,e.request);break;case`module-request`:this.#_(n,e.name);break;case`stderr`:n.stderr+=e.text,n.options.onStderr?.(e.text);break;case`result`:n.resolve({stdout:n.stdout,stderr:n.stderr||void 0,value:e.value,durationMs:Math.round(e.durationMs),failed:!1,...e.memory?{memory:e.memory}:{},...e.cases?{cases:e.cases,passed:e.passed,total:e.total}:{}}),n.markDone();break;case`error`:case`fatal`:{let r=(n.stderr&&!n.stderr.endsWith(`
2
2
  `)?`
3
3
  `:``)+e.message+`
4
4
  `;n.stderr+=r,n.options.onStderr?.(r);let i={stdout:n.stdout,stderr:n.stderr,hint:`hint`in e?e.hint:void 0,durationMs:Math.round(`durationMs`in e?e.durationMs:0),failed:!0,...`cases`in e&&e.cases?{cases:e.cases,passed:0,total:e.cases.length}:{}};`hintAbout`in e&&e.hintAbout===`stdin`&&t.add(i),n.resolve(i),n.markDone();break}}}#_(e,t){let n=this.#e,r=r=>{this.#e===n&&this.#u===e&&n?.postMessage({type:`module`,name:t,...r})};this.loadModule(t).then(e=>r({code:e}),e=>r({error:e instanceof Error?e.message:String(e)}))}#v(e,t){let n=this.#e,r=r=>{this.#e===n&&this.#u===e&&n?.postMessage({type:`stdin-response`,request:t,text:r})},i=e.options.onStdinRequest;i?i().then(r,()=>r(null)):r(null)}#y(e,t){e.reject(t),e.markDone()}async#b(){if(!this.#d){this.#d=!0;try{for(;this.#l.length;){let e=this.#l.shift();this.#u=e;try{if(await this.load(),e.settled)continue;e.started=!0,e.options.onStart?.(),e.options.timeoutMs&&Number.isFinite(e.options.timeoutMs)&&e.options.timeoutMs>0&&(e.timer=setTimeout(()=>{this.#u!==e||e.settled||(this.#g({type:`error`,id:e.id,message:`Run exceeded its wall-clock time limit.`,durationMs:e.options.timeoutMs}),this.#m())},e.options.timeoutMs)),this.#e.postMessage({type:`run`,id:e.id,code:e.code,stdin:e.options.stdin,files:e.options.files,entry:e.options.entry,...e.options.compilerLanguage?{compilerLanguage:e.options.compilerLanguage}:{},...e.options.practice?{practice:e.options.practice}:{}}),await e.done}catch(t){this.#y(e,t)}finally{this.#u=null}}}finally{this.#d=!1}}}};export{i as t};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-playpad",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "Embeddable browser code playground: a CodeMirror editor that runs Python, JavaScript, TypeScript, a subset of Java, experimental C/C++ and multi-file React in the browser. No backend. One shared worker per page, blocking input(), multi-file projects, lazy per-language loading.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -45,12 +45,16 @@
45
45
  "sync:cpp": "node scripts/sync-cpp.mjs",
46
46
  "check:compiler-licenses": "node scripts/check-compiler-licenses.mjs",
47
47
  "sync:react": "node scripts/sync-react.mjs",
48
+ "sync:next": "node scripts/sync-next.mjs",
49
+ "test:next": "node scripts/test-next-browser.mjs",
48
50
  "test:react": "node scripts/test-react-browser.mjs"
49
51
  },
50
52
  "peerDependencies": {
51
53
  "@codemirror/autocomplete": "^6",
52
54
  "@codemirror/commands": "^6",
53
55
  "@codemirror/lang-cpp": "^6",
56
+ "@codemirror/lang-css": "^6",
57
+ "@codemirror/lang-html": "^6",
54
58
  "@codemirror/lang-java": "^6",
55
59
  "@codemirror/lang-javascript": "^6",
56
60
  "@codemirror/lang-json": "^6",
@@ -60,9 +64,7 @@
60
64
  "@codemirror/theme-one-dark": "^6",
61
65
  "@codemirror/view": "^6",
62
66
  "@lezer/highlight": "^1",
63
- "react": ">=18",
64
- "@codemirror/lang-css": "^6",
65
- "@codemirror/lang-html": "^6"
67
+ "react": ">=18"
66
68
  },
67
69
  "peerDependenciesMeta": {
68
70
  "react": {
@@ -106,6 +108,7 @@
106
108
  "@codemirror/theme-one-dark": "^6.1.3",
107
109
  "@codemirror/view": "^6.43.9",
108
110
  "@lezer/highlight": "^1.2.3",
111
+ "@tailwindcss/browser": "4.3.3",
109
112
  "@types/react": "^19.2.18",
110
113
  "@types/react-dom": "^19.2.4",
111
114
  "@vercel/analytics": "^2.0.1",
@@ -114,6 +117,7 @@
114
117
  "esbuild": "^0.28.2",
115
118
  "react": "19.2.8",
116
119
  "react-dom": "19.2.8",
120
+ "react-server-dom-webpack": "19.2.8",
117
121
  "sucrase": "3.35.1",
118
122
  "typescript": "^5.9.3",
119
123
  "vite": "^8.3.5"
@@ -1,9 +0,0 @@
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";import{t}from"./react-version.generated-BNNJmf7J.js";import{c as n}from"./config-DB58UVsk.js";var r=`(function(){var a=function(e,n){e.__playpad=1,parent.postMessage(e,"*",n||[])};function l(e,n){if(typeof e=="string")return e;if(typeof e=="function")return"[Function "+(e.name||"anonymous")+"]";if(typeof e!="object"||e===null)return String(e);if(e instanceof Error)return e.name+": "+e.message;if(e instanceof Node)return"<"+e.nodeName.toLowerCase()+">";try{return JSON.stringify(e)}catch{return String(e)}}function C(e){if(typeof e[0]!="string")return e.map(function(o){return l(o)}).join(" ");var n=1,r=e[0].replace(/%([sdifoOc%])/g,function(o,i){if(i==="%")return"%";if(n>=e.length)return o;var c=e[n++];return i==="c"?"":i==="d"||i==="i"?String(parseInt(c,10)):i==="f"?String(parseFloat(c)):l(c)});return[r].concat(e.slice(n).map(function(o){return l(o)})).join(" ")}["log","info","warn","error","debug"].forEach(function(e){var n=console[e];console[e]=function(){var r=Array.prototype.slice.call(arguments);a({type:"console",level:e==="debug"?"log":e,text:C(r)}),n.apply(console,r)}});function M(e){var n=/playpad-project\\/([^\\s:)]+):(\\d+)/.exec(e&&e.stack||"");return n?{file:n[1],line:Number(n[2])}:{}}function u(e,n){var r=e&&typeof e=="object"&&"message"in e,o=r&&e.name?e.name+": ":"",i=M(e);a({type:"error",message:n+o+(r?e.message:l(e)),file:i.file,line:i.line})}addEventListener("error",function(e){e.error?u(e.error,"Uncaught "):e.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."}):u(e.message,"Uncaught ")}),window.reportError=function(e){u(e,"Uncaught ")};function O(e){return function(){try{return e.apply(this,arguments)}catch(n){u(n,"Uncaught ")}}}["setTimeout","setInterval","requestAnimationFrame","queueMicrotask"].forEach(function(e){var n=window[e];window[e]=function(r){var o=Array.prototype.slice.call(arguments);return typeof r=="function"&&(o[0]=O(r)),n.apply(window,o)}}),addEventListener("unhandledrejection",function(e){u(e.reason,"Unhandled promise rejection: ")}),window.alert=function(e){a({type:"alert",text:e===void 0?"":String(e)})},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 T=1e3,h=!1,v=0,b=0,x=new MessageChannel;x.port1.onmessage=function(){h=!1},window.__playpadLoopGuard=function(){if(!h){h=!0,v=performance.now(),b=0,x.port2.postMessage(0);return}if((++b&63)===0&&performance.now()-v>T)throw new Error("This loop ran for more than 1 second. Is it infinite?")};function U(e){var n=e.nonce;function r(s){n&&(s.nonce=n),document.head.appendChild(s)}function o(s){var d=document.createElement("script");d.textContent=s,r(d)}function i(){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 s={};window.__playpadDefine=function(t,f){s[t]=f};var d={};e.modules.forEach(function(t){d[t.path]=t,t.kind==="js"&&o("__playpadDefine("+JSON.stringify(t.path)+",function(require,module,exports){"+t.text+\`
7
- });
8
- //# sourceURL=playpad-project/\`+t.path)});var y={};function _(t){if(y[t])return y[t].exports;var f=d[t],m=y[t]={exports:{}};if(f.kind==="json")m.exports=JSON.parse(f.text);else if(f.kind==="css"){var w=document.createElement("style");n&&(w.nonce=n),w.dataset.file=t,w.textContent=f.text,document.head.appendChild(w)}else{if(!s[t])throw new Error("The file "+t+" could not be loaded.");s[t](function(p){if(window.__vendor[p])return window.__vendor[p];if(f.links[p])return _(f.links[p]);throw new Error('Cannot find "'+p+'" from '+t+".")},m,m.exports)}return m.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 L=!1;try{e.entries.forEach(_)}catch(t){L=!0,u(t,"Uncaught ")}a({type:"entry-done",failed:L})}if(e.vendor)o(e.vendor),i();else{var c=document.createElement("script");c.src=e.runtimeURL,c.onload=i,c.onerror=function(){a({type:"fatal",message:"The React runtime could not be loaded from "+e.runtimeURL+"."})},r(c)}}function E(){var e=new MessageChannel;e.port1.onmessage=function(n){e.port1.close(),U(n.data)},a({type:"booted"},[e.port2])}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",E):E()})();
9
- `,i=5e3,a=4e3,o=65536,s=[`src/main.jsx`,`src/main.js`],c=`<!doctype html><html lang="en"><head><meta charset="utf-8"></head><body><div id="root"></div></body></html>`;function l(e){return/^([a-z][a-z0-9+.-]*:|\/\/)/i.test(e)}function u(e,t,i){let{CompileError:a,compileProject:o,resolveImport:u}=i,d=t.endsWith(`.html`)?t:`index.html`,f=Object.hasOwn(e,d),p=new DOMParser().parseFromString(f?e[d]:c,`text/html`),m=[];if(f){let t=[...p.querySelectorAll(`script[src], link[rel="stylesheet"][href]`)],n=[];for(let r of t){let t=r.tagName===`SCRIPT`,i=r.getAttribute(t?`src`:`href`);if(l(i))throw new a(d,`This project can't load "${i}". The preview can only use the project's own files.`);let o=u(e,d,i);if(!o)throw new a(d,`The file "${i}" does not exist.`);(t?n:m).push(o),r.remove()}if(!n.length)throw new a(d,`Add <script type="module" src="/src/main.jsx"><\/script> so the app has an entry file.`);m.push(...n)}else{let n=t.endsWith(`.html`)?void 0:Object.hasOwn(e,t)?t:s.find(t=>Object.hasOwn(e,t));if(!n)throw new a(`index.html`,`This project has no entry file. Add src/main.jsx.`);m.push(n)}let h=o(e,m),{nonce:g,runtimeURL:_}=n(),v=p.createElement(`meta`);v.httpEquiv=`Content-Security-Policy`,v.content=`default-src 'none'; script-src 'unsafe-inline'${_?` ${_}`:``}; style-src 'unsafe-inline'; img-src data:; font-src data:; form-action 'none'; base-uri 'none'`;let y=p.createElement(`script`);return g&&y.setAttribute(`nonce`,g),y.textContent=r,p.head.prepend(v,y),{html:`<!doctype html>${p.documentElement.outerHTML}`,modules:h,entries:m}}var d=class{preview;payload;#e=null;#t=null;#n=null;#r=null;#i=null;#a=null;#o=``;#s=``;#c;#l=performance.now();#u=!1;#d=null;#f=null;constructor(e,t,n,r){this.preview=e,this.payload=t,this.#i=n,this.#a=r}get live(){return this.#e!==null}open(e){let t=document.createElement(`iframe`);t.setAttribute(`sandbox`,`allow-scripts allow-forms`),t.setAttribute(`allow`,``),t.setAttribute(`referrerpolicy`,`no-referrer`),t.title=`Preview`,t.className=`cp-preview-frame`,t.srcdoc=e,this.#e=t,this.#t=this.preview.host.ownerDocument.defaultView??window,this.#t.addEventListener(`message`,this.#v),this.preview.host.replaceChildren(t),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.`)},i)}fail(e,t={},n){this.#n&&clearTimeout(this.#n),this.#n=null,this.#h(e,t),this.#p(!0,n)}#p(e,t){let n=this.#i;this.#i=null,this.#a=null,n?.({stdout:this.#o,...this.#s?{stderr:this.#s}:{},...t?{hint:t}:{},...e&&this.#c?{problem:this.#c}:{},durationMs:Math.round(performance.now()-this.#l),failed:e})}#m(e,t){this.#i&&(e===`warn`||e===`error`?this.#s+=`${t}\n`:this.#o+=`${t}\n`),this.preview.onConsole(e,t)}#h(e,t){let n=(t.file?`${t.file}${t.line?`:${t.line}`:``}${t.column?`:${t.column}`:``}: `:``)+e;this.#m(`error`,n),this.#g(n);let r={message:n,...t};this.#i?this.#c??=r:this.preview.onError(r)}#g(e){this.#d||(this.#d=document.createElement(`pre`),this.#d.className=`cp-preview-banner`,this.#d.setAttribute(`role`,`alert`),this.preview.host.append(this.#d)),this.#d.textContent=e}#_(e){this.#f||(this.#f=document.createElement(`div`),this.#f.className=`cp-preview-notice`,this.#f.setAttribute(`role`,`status`),this.preview.host.append(this.#f)),this.#f.textContent=e,this.#f.hidden=!1,this.#r&&clearTimeout(this.#r),this.#r=setTimeout(()=>{this.#f&&(this.#f.hidden=!0)},a)}showCompileBanner(e){e&&this.#d&&(this.#d.textContent+=`\n${e}`)}#v=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,o);switch(t.type){case`booted`:if(this.#u)return;this.#u=!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.#m(e,n(t.text));break}case`error`:this.#h(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.#p(t.failed===!0);break;case`render`:this.preview.onRender(n(t.rootText));break;case`alert`:this.#m(`info`,`alert: ${n(t.text)}`),this.#_(n(t.text))}};dispose(t){this.#n&&clearTimeout(this.#n),this.#r&&clearTimeout(this.#r),this.#t?.removeEventListener(`message`,this.#v),this.#e=null,this.preview.host.replaceChildren(),this.#a&&t&&this.#a(new e),this.#i=null,this.#a=null}},f=new class{id=`react`;label=`React ${t}`;interactiveStdin=!1;statusDecidesFailure=!0;#e=null;#t=null;#n=null;#r=/* @__PURE__ */ new WeakMap;#i=/* @__PURE__ */ new WeakMap;get ready(){return this.#e!==null}async editorLanguage(){let{javascript:e}=await import(`./dist-BwlTZqCY.js`);return e({jsx:!0})}load(){return this.#n??=(async()=>{try{let e=import(`./compiler-B408qd3N.js`),t=n().runtimeURL?null:import(`./react-vendor.generated-DMxIoCMn.js`);this.#t=(await t)?.REACT_VENDOR_SOURCE??null,this.#e=await e}catch(e){throw this.#n=null,Error(`The React runtime could not be loaded. Check your connection and reload the page. (${e.message})`)}})(),this.#n}run(e,t={}){let r=t.preview;if(!r)return Promise.reject(/* @__PURE__ */ Error(`React needs a <code-playpad> widget to render in.`));this.dispose(r.host);let i,a=t.files??{},o=new Promise((e,t)=>{let a=n().runtimeURL;i=new d(r,{...a?{runtimeURL:a}:{vendor:this.#t},nonce:n().nonce},e,t)});return this.#r.set(r.host,i),this.#i.set(o,i),this.#a(i,a,t.entry??`index.html`),o}async#a(e,t,n){try{await this.load();let r=this.#e,i;try{i=u(t,n,r)}catch(t){if(t instanceof r.CompileError){e.fail(t.reason,{file:t.file,...t.line?{line:t.line}:{},...t.column?{column:t.column}:{}},t.hint),e.showCompileBanner(t.hint);return}throw t}e.payload.modules=i.modules,e.payload.entries=i.entries,e.open(i.html)}catch(t){e.fail(t.message)}}stop(e){e&&this.#i.get(e)?.dispose(!0)}hasLivePreview(e){return this.#r.get(e)?.live??!1}dispose(e){this.#r.get(e)?.dispose(!0),this.#r.delete(e)}};export{f as reactRuntime};
@@ -1,4 +0,0 @@
1
- import{u as e}from"./element-Dzhksh6_.js";import{t}from"./react-version.generated-BNNJmf7J.js";import{c as n}from"./config-DB58UVsk.js";var r=`(function(){var a=function(e,n){e.__playpad=1,parent.postMessage(e,"*",n||[])};function l(e,n){if(typeof e=="string")return e;if(typeof e=="function")return"[Function "+(e.name||"anonymous")+"]";if(typeof e!="object"||e===null)return String(e);if(e instanceof Error)return e.name+": "+e.message;if(e instanceof Node)return"<"+e.nodeName.toLowerCase()+">";try{return JSON.stringify(e)}catch{return String(e)}}function C(e){if(typeof e[0]!="string")return e.map(function(o){return l(o)}).join(" ");var n=1,r=e[0].replace(/%([sdifoOc%])/g,function(o,i){if(i==="%")return"%";if(n>=e.length)return o;var c=e[n++];return i==="c"?"":i==="d"||i==="i"?String(parseInt(c,10)):i==="f"?String(parseFloat(c)):l(c)});return[r].concat(e.slice(n).map(function(o){return l(o)})).join(" ")}["log","info","warn","error","debug"].forEach(function(e){var n=console[e];console[e]=function(){var r=Array.prototype.slice.call(arguments);a({type:"console",level:e==="debug"?"log":e,text:C(r)}),n.apply(console,r)}});function M(e){var n=/playpad-project\\/([^\\s:)]+):(\\d+)/.exec(e&&e.stack||"");return n?{file:n[1],line:Number(n[2])}:{}}function u(e,n){var r=e&&typeof e=="object"&&"message"in e,o=r&&e.name?e.name+": ":"",i=M(e);a({type:"error",message:n+o+(r?e.message:l(e)),file:i.file,line:i.line})}addEventListener("error",function(e){e.error?u(e.error,"Uncaught "):e.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."}):u(e.message,"Uncaught ")}),window.reportError=function(e){u(e,"Uncaught ")};function O(e){return function(){try{return e.apply(this,arguments)}catch(n){u(n,"Uncaught ")}}}["setTimeout","setInterval","requestAnimationFrame","queueMicrotask"].forEach(function(e){var n=window[e];window[e]=function(r){var o=Array.prototype.slice.call(arguments);return typeof r=="function"&&(o[0]=O(r)),n.apply(window,o)}}),addEventListener("unhandledrejection",function(e){u(e.reason,"Unhandled promise rejection: ")}),window.alert=function(e){a({type:"alert",text:e===void 0?"":String(e)})},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 T=1e3,h=!1,v=0,b=0,x=new MessageChannel;x.port1.onmessage=function(){h=!1},window.__playpadLoopGuard=function(){if(!h){h=!0,v=performance.now(),b=0,x.port2.postMessage(0);return}if((++b&63)===0&&performance.now()-v>T)throw new Error("This loop ran for more than 1 second. Is it infinite?")};function U(e){var n=e.nonce;function r(s){n&&(s.nonce=n),document.head.appendChild(s)}function o(s){var d=document.createElement("script");d.textContent=s,r(d)}function i(){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 s={};window.__playpadDefine=function(t,f){s[t]=f};var d={};e.modules.forEach(function(t){d[t.path]=t,t.kind==="js"&&o("__playpadDefine("+JSON.stringify(t.path)+",function(require,module,exports){"+t.text+\`
2
- });
3
- //# sourceURL=playpad-project/\`+t.path)});var y={};function _(t){if(y[t])return y[t].exports;var f=d[t],m=y[t]={exports:{}};if(f.kind==="json")m.exports=JSON.parse(f.text);else if(f.kind==="css"){var w=document.createElement("style");n&&(w.nonce=n),w.dataset.file=t,w.textContent=f.text,document.head.appendChild(w)}else{if(!s[t])throw new Error("The file "+t+" could not be loaded.");s[t](function(p){if(window.__vendor[p])return window.__vendor[p];if(f.links[p])return _(f.links[p]);throw new Error('Cannot find "'+p+'" from '+t+".")},m,m.exports)}return m.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 L=!1;try{e.entries.forEach(_)}catch(t){L=!0,u(t,"Uncaught ")}a({type:"entry-done",failed:L})}if(e.vendor)o(e.vendor),i();else{var c=document.createElement("script");c.src=e.runtimeURL,c.onload=i,c.onerror=function(){a({type:"fatal",message:"The React runtime could not be loaded from "+e.runtimeURL+"."})},r(c)}}function E(){var e=new MessageChannel;e.port1.onmessage=function(n){e.port1.close(),U(n.data)},a({type:"booted"},[e.port2])}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",E):E()})();
4
- `,i=5e3,a=4e3,o=65536,s=[`src/main.jsx`,`src/main.js`],c=`<!doctype html><html lang="en"><head><meta charset="utf-8"></head><body><div id="root"></div></body></html>`;function l(e){return/^([a-z][a-z0-9+.-]*:|\/\/)/i.test(e)}function u(e,t,i){let{CompileError:a,compileProject:o,resolveImport:u}=i,d=t.endsWith(`.html`)?t:`index.html`,f=Object.hasOwn(e,d),p=new DOMParser().parseFromString(f?e[d]:c,`text/html`),m=[];if(f){let t=[...p.querySelectorAll(`script[src], link[rel="stylesheet"][href]`)],n=[];for(let r of t){let t=r.tagName===`SCRIPT`,i=r.getAttribute(t?`src`:`href`);if(l(i))throw new a(d,`This project can't load "${i}". The preview can only use the project's own files.`);let o=u(e,d,i);if(!o)throw new a(d,`The file "${i}" does not exist.`);(t?n:m).push(o),r.remove()}if(!n.length)throw new a(d,`Add <script type="module" src="/src/main.jsx"><\/script> so the app has an entry file.`);m.push(...n)}else{let n=t.endsWith(`.html`)?void 0:Object.hasOwn(e,t)?t:s.find(t=>Object.hasOwn(e,t));if(!n)throw new a(`index.html`,`This project has no entry file. Add src/main.jsx.`);m.push(n)}let h=o(e,m),{nonce:g,runtimeURL:_}=n(),v=p.createElement(`meta`);v.httpEquiv=`Content-Security-Policy`,v.content=`default-src 'none'; script-src 'unsafe-inline'${_?` ${_}`:``}; style-src 'unsafe-inline'; img-src data:; font-src data:; form-action 'none'; base-uri 'none'`;let y=p.createElement(`script`);return g&&y.setAttribute(`nonce`,g),y.textContent=r,p.head.prepend(v,y),{html:`<!doctype html>${p.documentElement.outerHTML}`,modules:h,entries:m}}var d=class{preview;payload;#e=null;#t=null;#n=null;#r=null;#i=null;#a=null;#o=``;#s=``;#c;#l=performance.now();#u=!1;#d=null;#f=null;constructor(e,t,n,r){this.preview=e,this.payload=t,this.#i=n,this.#a=r}get live(){return this.#e!==null}open(e){let t=document.createElement(`iframe`);t.setAttribute(`sandbox`,`allow-scripts allow-forms`),t.setAttribute(`allow`,``),t.setAttribute(`referrerpolicy`,`no-referrer`),t.title=`Preview`,t.className=`cp-preview-frame`,t.srcdoc=e,this.#e=t,this.#t=this.preview.host.ownerDocument.defaultView??window,this.#t.addEventListener(`message`,this.#v),this.preview.host.replaceChildren(t),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.`)},i)}fail(e,t={},n){this.#n&&clearTimeout(this.#n),this.#n=null,this.#h(e,t),this.#p(!0,n)}#p(e,t){let n=this.#i;this.#i=null,this.#a=null,n?.({stdout:this.#o,...this.#s?{stderr:this.#s}:{},...t?{hint:t}:{},...e&&this.#c?{problem:this.#c}:{},durationMs:Math.round(performance.now()-this.#l),failed:e})}#m(e,t){this.#i&&(e===`warn`||e===`error`?this.#s+=`${t}\n`:this.#o+=`${t}\n`),this.preview.onConsole(e,t)}#h(e,t){let n=(t.file?`${t.file}${t.line?`:${t.line}`:``}${t.column?`:${t.column}`:``}: `:``)+e;this.#m(`error`,n),this.#g(n);let r={message:n,...t};this.#i?this.#c??=r:this.preview.onError(r)}#g(e){this.#d||(this.#d=document.createElement(`pre`),this.#d.className=`cp-preview-banner`,this.#d.setAttribute(`role`,`alert`),this.preview.host.append(this.#d)),this.#d.textContent=e}#_(e){this.#f||(this.#f=document.createElement(`div`),this.#f.className=`cp-preview-notice`,this.#f.setAttribute(`role`,`status`),this.preview.host.append(this.#f)),this.#f.textContent=e,this.#f.hidden=!1,this.#r&&clearTimeout(this.#r),this.#r=setTimeout(()=>{this.#f&&(this.#f.hidden=!0)},a)}showCompileBanner(e){e&&this.#d&&(this.#d.textContent+=`\n${e}`)}#v=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,o);switch(t.type){case`booted`:if(this.#u)return;this.#u=!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.#m(e,n(t.text));break}case`error`:this.#h(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.#p(t.failed===!0);break;case`render`:this.preview.onRender(n(t.rootText));break;case`alert`:this.#m(`info`,`alert: ${n(t.text)}`),this.#_(n(t.text))}};dispose(t){this.#n&&clearTimeout(this.#n),this.#r&&clearTimeout(this.#r),this.#t?.removeEventListener(`message`,this.#v),this.#e=null,this.preview.host.replaceChildren(),this.#a&&t&&this.#a(new e),this.#i=null,this.#a=null}},f=new class{id=`react`;label=`React ${t}`;interactiveStdin=!1;statusDecidesFailure=!0;#e=null;#t=null;#n=null;#r=/* @__PURE__ */ new WeakMap;#i=/* @__PURE__ */ new WeakMap;get ready(){return this.#e!==null}async editorLanguage(){let{javascript:e}=await import(`@codemirror/lang-javascript`);return e({jsx:!0})}load(){return this.#n??=(async()=>{try{let e=import(`./compiler-B408qd3N.js`),t=n().runtimeURL?null:import(`./react-vendor.generated-DMxIoCMn.js`);this.#t=(await t)?.REACT_VENDOR_SOURCE??null,this.#e=await e}catch(e){throw this.#n=null,Error(`The React runtime could not be loaded. Check your connection and reload the page. (${e.message})`)}})(),this.#n}run(e,t={}){let r=t.preview;if(!r)return Promise.reject(/* @__PURE__ */ Error(`React needs a <code-playpad> widget to render in.`));this.dispose(r.host);let i,a=t.files??{},o=new Promise((e,t)=>{let a=n().runtimeURL;i=new d(r,{...a?{runtimeURL:a}:{vendor:this.#t},nonce:n().nonce},e,t)});return this.#r.set(r.host,i),this.#i.set(o,i),this.#a(i,a,t.entry??`index.html`),o}async#a(e,t,n){try{await this.load();let r=this.#e,i;try{i=u(t,n,r)}catch(t){if(t instanceof r.CompileError){e.fail(t.reason,{file:t.file,...t.line?{line:t.line}:{},...t.column?{column:t.column}:{}},t.hint),e.showCompileBanner(t.hint);return}throw t}e.payload.modules=i.modules,e.payload.entries=i.entries,e.open(i.html)}catch(t){e.fail(t.message)}}stop(e){e&&this.#i.get(e)?.dispose(!0)}hasLivePreview(e){return this.#r.get(e)?.live??!1}dispose(e){this.#r.get(e)?.dispose(!0),this.#r.delete(e)}};export{f as reactRuntime};