code-playpad 0.15.0 → 0.17.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.
@@ -1,4 +1,4 @@
1
- import{l as e}from"./config-3Z6xX6Jr.js";import{t}from"./worker-runtime-5Ujf07eB.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{l as e}from"./config-3Z6xX6Jr.js";import{t}from"./worker-runtime-BptYo0uF.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(\`
@@ -1 +1 @@
1
- import{t as e}from"./react-version.generated-BNNJmf7J.js";import{u as t}from"./config-3Z6xX6Jr.js";import{n,t as r}from"./boot-BVedZD8N.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};
1
+ import{t as e}from"./react-version.generated-BNNJmf7J.js";import{u as t}from"./config-3Z6xX6Jr.js";import{n,t as r}from"./boot-DcnEI4qy.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};
package/dist/react.js CHANGED
@@ -1 +1 @@
1
- import{n as e}from"./element-UgFuSGoC.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};
1
+ import{n as e}from"./element-BpSZy4LD.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};
@@ -1,10 +1,10 @@
1
1
  export declare const NEXT_SERVER_STAMP: {
2
2
  readonly react: "19.2.8";
3
- readonly sha256: "edf0a1c7f0b89207cedfcc97d70ce7690dd7b74b2759fe40d09962aa1217d306";
3
+ readonly sha256: "98f768e8931a395e50d957b48a7e339d85ba732d8a80d4b475854a32bdf513b5";
4
4
  };
5
5
  export declare const NEXT_CLIENT_STAMP: {
6
6
  readonly react: "19.2.8";
7
- readonly sha256: "9fa987a50b2071a7767c37ae9d15f0e621a5d115de640ba782e7a7f77095aa3d";
7
+ readonly sha256: "59bf0c9600b43e79adb18b99cb2022dc8a28523e8008d16961d82477ca6d5fbf";
8
8
  };
9
9
  export declare const NEXT_SERVER_SOURCE: string;
10
10
  export declare const NEXT_CLIENT_SOURCE: string;
@@ -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 S(e){try{return await D(e)}catch(t){return console.warn(`[code-playpad] CodeMirror unavailable, using plain textarea:`,t),O(e)}}var C=/* @__PURE__ */ new Map,w=/* @__PURE__ */ new Set,T=!1;function E(){T||(T=!0,queueMicrotask(()=>{T=!1;for(let e of w){let t=[...e.adoptedStyleSheets];e.adoptedStyleSheets=[],e.adoptedStyleSheets=t}}))}async function D(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:u,highlightActiveLine:f,highlightActiveLineGutter:p,highlightSpecialChars:m,drawSelection:h,rectangularSelection:g,crosshairCursor:_}=t,{EditorState:v,Compartment:y}=n,{defaultKeymap:b,history:x,historyKeymap:S,indentWithTab:T}=r,{syntaxHighlighting:D,defaultHighlightStyle:O,HighlightStyle:k,indentOnInput:A,bracketMatching:j,foldGutter:M,foldKeymap:N}=i,{autocompletion:P,closeBrackets:F,closeBracketsKeymap:I,completionKeymap:ee}=a,L=new y,R=new y,z=new y,B=C.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})];C.set(`default-light`,B);let{tags:V}=s,H=(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:[V.comment,V.meta],color:e.comment,fontStyle:`italic`},{tag:[V.keyword,V.operatorKeyword,V.modifier],color:e.keyword},{tag:[V.string,V.special(V.string),V.regexp],color:e.string},{tag:[V.number,V.bool,V.null,V.atom],color:e.number},{tag:[V.function(V.variableName),V.function(V.propertyName),V.definition(V.function(V.variableName))],color:e.fn},{tag:[V.typeName,V.className,V.namespace,V.tagName],color:e.type},{tag:[V.variableName,V.propertyName,V.attributeName],color:e.variable},{tag:V.invalid,color:e.keyword,textDecoration:`underline`}]))],U=(e,t)=>{let n=d.find(e=>e.id===t);if(!n?.colors)return e?o.oneDark:B;let r=C.get(n.id);return r||(r=H(n.colors,n.mode===`dark`),C.set(n.id,r)),r},W=l.of([{key:`Mod-Enter`,preventDefault:!0,run:()=>(e.onRun?.(),!0)},{key:`Shift-Enter`,preventDefault:!0,run:()=>(e.onRun?.(),!0)}]),G=e.dark,K=e.themeId,q=e.readOnly,J=e.language??[],Y=t=>v.create({doc:t,extensions:[u(),p(),m(),x(),M(),h(),v.allowMultipleSelections.of(!0),A(),j(),F(),P(),g(),_(),f(),W,l.of([...I,...b,...S,...N,...ee,T]),c.lineWrapping,z.of(J),L.of(U(G,K)),R.of(v.readOnly.of(q)),c.updateListener.of(t=>{t.startState.facet(c.styleModule)!==t.state.facet(c.styleModule)&&E(),t.docChanged&&e.onChange?.(t.state.doc.toString())})]}),X=new c({parent:e.parent,state:Y(e.doc)});w.add(X.root),E();let Z=/* @__PURE__ */ new Map,Q=e.name??``;return{fallback:!1,getCode:()=>X.state.doc.toString(),setCode(e){X.dispatch({changes:{from:0,to:X.state.doc.length,insert:e}})},openFile(e,t){if(e===Q)return;Z.set(Q,X.state);let n=Z.get(e);X.setState(n??Y(t)),Q=e,n&&X.dispatch({effects:[L.reconfigure(U(G,K)),R.reconfigure(v.readOnly.of(q)),z.reconfigure(J)]}),E()},fileCode(e,t){if(e===Q)return X.state.doc.toString();let n=Z.get(e);return n?n.doc.toString():t},forgetFiles(e){for(let t of[...Z.keys()])e.includes(t)||Z.delete(t)},setTheme(e,t){G=e,K=t,X.dispatch({effects:L.reconfigure(U(G,K))})},setReadOnly(e){q=e,X.dispatch({effects:R.reconfigure(v.readOnly.of(q))})},setLanguage(e){J=e,X.dispatch({effects:z.reconfigure(J)})},focus:()=>X.focus(),destroy(){w.delete(X.root),X.destroy()}}}function O(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 k=/* @__PURE__ */ new Map,A=/* @__PURE__ */ new Map;function j(e,t){k.set(e,t)}function M(){return[...k.keys()]}function N(e){let t=A.get(e);if(t)return t;let n=k.get(e);if(!n)return Promise.reject(/* @__PURE__ */ Error(`Unknown runtime "${e}". Registered: ${M().join(`, `)||`none`}`));let r=n().catch(t=>{throw A.delete(e),t});return A.set(e,r),r}j(`python`,()=>import(`./pyodide-C5KhmXre.js`).then(e=>e.pythonRuntime)),j(`javascript`,()=>import(`./javascript-kqyWH6DS.js`).then(e=>e.javascriptRuntime)),j(`typescript`,()=>import(`./javascript-kqyWH6DS.js`).then(e=>e.typescriptRuntime)),j(`java`,()=>import(`./java-2z8CcJaR.js`).then(e=>e.javaRuntime)),j(`c`,()=>import(`./cpp-BxFy0NSM.js`).then(e=>e.cRuntime)),j(`cpp`,()=>import(`./cpp-BxFy0NSM.js`).then(e=>e.cppRuntime)),j(`csharp`,()=>import(`./csharp-ByGGaB0V.js`).then(e=>e.csharpRuntime)),j(`cs`,()=>import(`./csharp-ByGGaB0V.js`).then(e=>e.csharpRuntime)),j(`react`,()=>import(`./react-BKPRfjtf.js`).then(e=>e.reactRuntime)),j(`next`,()=>import(`./next-xTgh8PXL.js`).then(e=>e.nextRuntime));var P=String.raw`
18
+ `)}async function S(e){try{return await D(e)}catch(t){return console.warn(`[code-playpad] CodeMirror unavailable, using plain textarea:`,t),O(e)}}var C=/* @__PURE__ */ new Map,w=/* @__PURE__ */ new Set,T=!1;function E(){T||(T=!0,queueMicrotask(()=>{T=!1;for(let e of w){let t=[...e.adoptedStyleSheets];e.adoptedStyleSheets=[],e.adoptedStyleSheets=t}}))}async function D(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:u,highlightActiveLine:f,highlightActiveLineGutter:p,highlightSpecialChars:m,drawSelection:h,rectangularSelection:g,crosshairCursor:_}=t,{EditorState:v,Compartment:y}=n,{defaultKeymap:b,history:x,historyKeymap:S,indentWithTab:T}=r,{syntaxHighlighting:D,defaultHighlightStyle:O,HighlightStyle:k,indentOnInput:A,bracketMatching:j,foldGutter:M,foldKeymap:N}=i,{autocompletion:P,closeBrackets:F,closeBracketsKeymap:I,completionKeymap:ee}=a,L=new y,R=new y,z=new y,B=C.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})];C.set(`default-light`,B);let{tags:V}=s,H=(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:[V.comment,V.meta],color:e.comment,fontStyle:`italic`},{tag:[V.keyword,V.operatorKeyword,V.modifier],color:e.keyword},{tag:[V.string,V.special(V.string),V.regexp],color:e.string},{tag:[V.number,V.bool,V.null,V.atom],color:e.number},{tag:[V.function(V.variableName),V.function(V.propertyName),V.definition(V.function(V.variableName))],color:e.fn},{tag:[V.typeName,V.className,V.namespace,V.tagName],color:e.type},{tag:[V.variableName,V.propertyName,V.attributeName],color:e.variable},{tag:V.invalid,color:e.keyword,textDecoration:`underline`}]))],U=(e,t)=>{let n=d.find(e=>e.id===t);if(!n?.colors)return e?o.oneDark:B;let r=C.get(n.id);return r||(r=H(n.colors,n.mode===`dark`),C.set(n.id,r)),r},W=l.of([{key:`Mod-Enter`,preventDefault:!0,run:()=>(e.onRun?.(),!0)},{key:`Shift-Enter`,preventDefault:!0,run:()=>(e.onRun?.(),!0)}]),G=e.dark,K=e.themeId,q=e.readOnly,J=e.language??[],Y=t=>v.create({doc:t,extensions:[u(),p(),m(),x(),M(),h(),v.allowMultipleSelections.of(!0),A(),j(),F(),P(),g(),_(),f(),W,l.of([...I,...b,...S,...N,...ee,T]),c.lineWrapping,z.of(J),L.of(U(G,K)),R.of(v.readOnly.of(q)),c.updateListener.of(t=>{t.startState.facet(c.styleModule)!==t.state.facet(c.styleModule)&&E(),t.docChanged&&e.onChange?.(t.state.doc.toString())})]}),X=new c({parent:e.parent,state:Y(e.doc)});w.add(X.root),E();let Z=/* @__PURE__ */ new Map,Q=e.name??``;return{fallback:!1,getCode:()=>X.state.doc.toString(),setCode(e){X.dispatch({changes:{from:0,to:X.state.doc.length,insert:e}})},openFile(e,t){if(e===Q)return;Z.set(Q,X.state);let n=Z.get(e);X.setState(n??Y(t)),Q=e,n&&X.dispatch({effects:[L.reconfigure(U(G,K)),R.reconfigure(v.readOnly.of(q)),z.reconfigure(J)]}),E()},fileCode(e,t){if(e===Q)return X.state.doc.toString();let n=Z.get(e);return n?n.doc.toString():t},forgetFiles(e){for(let t of[...Z.keys()])e.includes(t)||Z.delete(t)},setTheme(e,t){G=e,K=t,X.dispatch({effects:L.reconfigure(U(G,K))})},setReadOnly(e){q=e,X.dispatch({effects:R.reconfigure(v.readOnly.of(q))})},setLanguage(e){J=e,X.dispatch({effects:z.reconfigure(J)})},focus:()=>X.focus(),destroy(){w.delete(X.root),X.destroy()}}}function O(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 k=/* @__PURE__ */ new Map,A=/* @__PURE__ */ new Map;function j(e,t){k.set(e,t)}function M(){return[...k.keys()]}function N(e){let t=A.get(e);if(t)return t;let n=k.get(e);if(!n)return Promise.reject(/* @__PURE__ */ Error(`Unknown runtime "${e}". Registered: ${M().join(`, `)||`none`}`));let r=n().catch(t=>{throw A.delete(e),t});return A.set(e,r),r}j(`python`,()=>import(`./pyodide-C5KhmXre.js`).then(e=>e.pythonRuntime)),j(`javascript`,()=>import(`./javascript-kqyWH6DS.js`).then(e=>e.javascriptRuntime)),j(`typescript`,()=>import(`./javascript-kqyWH6DS.js`).then(e=>e.typescriptRuntime)),j(`java`,()=>import(`./java-2z8CcJaR.js`).then(e=>e.javaRuntime)),j(`c`,()=>import(`./cpp-BxFy0NSM.js`).then(e=>e.cRuntime)),j(`cpp`,()=>import(`./cpp-BxFy0NSM.js`).then(e=>e.cppRuntime)),j(`csharp`,()=>import(`./csharp-ByGGaB0V.js`).then(e=>e.csharpRuntime)),j(`cs`,()=>import(`./csharp-ByGGaB0V.js`).then(e=>e.csharpRuntime)),j(`react`,()=>import(`./react-BKPRfjtf.js`).then(e=>e.reactRuntime)),j(`next`,()=>import(`./next-BIUzwrH6.js`).then(e=>e.nextRuntime));var P=String.raw`
19
19
  :host {
20
20
  --cp-bg: #ffffff;
21
21
  --cp-fg: #1f2328;
@@ -617,7 +617,7 @@ table.cp-table th { background: var(--cp-bg); }
617
617
  <pre class="cp-output" part="output" hidden></pre>
618
618
  </div>
619
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`,()=>{y({mode:this.#ue()?`light`:`dark`})}),t.querySelector(`.cp-theme-picker select`).addEventListener(`change`,e=>{let t=e.target.value,n=d.find(e=>e.id===t)?.mode;n&&y({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 N(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 ee(e,this.language);if(t){this.#g===e&&this.#u?.setLanguage(t);return}let n=e.includes(`.`)?null:await(this.#f??await N(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`)||ne(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`:ne(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=v().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 v()[this.#ue()?`dark`:`light`]}#fe(){this.#D??=b(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(`
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 ee(e,this.language);if(t){this.#g===e&&this.#u?.setLanguage(t);return}let n=e.includes(`.`)?null:await(this.#f??await N(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`)||ne(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`:ne(this.language);if(e.includes(n))return n;if(this.language===`next`){let t=e.filter(e=>/^(src\/)?app\/(\([^/]+\)\/)*page\.(jsx?|tsx?)$/.test(e)).sort((e,t)=>e.split(`/`).length-t.split(`/`).length)[0];if(t)return t}return 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=v().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 v()[this.#ue()?`dark`:`light`]}#fe(){this.#D??=b(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(`
621
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)+`
622
622
  … output truncated for display — the full text is in the playpad-output event
623
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-UgFuSGoC.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;get recycleAfterRun(){return!1}get startTimeoutMs(){}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;let i=this.startTimeoutMs,a=i===void 0?void 0:setTimeout(()=>{this.#e!==r||this.#a||(this.#m(),n(/* @__PURE__ */ Error(`The ${this.label} worker did not start within ${i} ms.`)))},i);r.onmessage=e=>{if(this.#e!==r)return;let i=e.data;i.type===`ready`?(this.#s=i.version,this.#o=i.interactiveStdin===!0,this.#a=!0,this.#i=null,clearTimeout(a),this.#h({phase:`ready`,message:`${this.label} ready`}),t()):i.type===`fatal`&&!this.#a?(clearTimeout(a),this.#p(i.message,t,n)):this.#g(i)},r.onerror=e=>{if(this.#e!==r)return;let i=e.message||`Worker failed to start`;clearTimeout(a),this.#a?this.#u&&this.#y(this.#u,Error(i)):this.#p(i,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),this.recycleAfterRun&&this.#f();return}}this.#f()}#f(){let e=this.#e!==null,t=this.#i;if(this.#m(),this.#u&&this.#y(this.#u,new n),e&&(t||!this.recycleAfterRun)){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-BpSZy4LD.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;get recycleAfterRun(){return!1}get startTimeoutMs(){}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;let i=this.startTimeoutMs,a=i===void 0?void 0:setTimeout(()=>{this.#e!==r||this.#a||(this.#m(),n(/* @__PURE__ */ Error(`The ${this.label} worker did not start within ${i} ms.`)))},i);r.onmessage=e=>{if(this.#e!==r)return;let i=e.data;i.type===`ready`?(this.#s=i.version,this.#o=i.interactiveStdin===!0,this.#a=!0,this.#i=null,clearTimeout(a),this.#h({phase:`ready`,message:`${this.label} ready`}),t()):i.type===`fatal`&&!this.#a?(clearTimeout(a),this.#p(i.message,t,n)):this.#g(i)},r.onerror=e=>{if(this.#e!==r)return;let i=e.message||`Worker failed to start`;clearTimeout(a),this.#a?this.#u&&this.#y(this.#u,Error(i)):this.#p(i,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),this.recycleAfterRun&&this.#f();return}}this.#f()}#f(){let e=this.#e!==null,t=this.#i;if(this.#m(),this.#u&&this.#y(this.#u,new n),e&&(t||!this.recycleAfterRun)){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;let t=null;try{if(this.recycleAfterRun?await Promise.race([this.load(),e.done]):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)),t=this.#e,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,this.recycleAfterRun&&t&&this.#e===t&&this.#m()}}}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.15.0",
3
+ "version": "0.17.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",
@@ -1,13 +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{CompileError as e,applyInserts as t,loopGuardInserts as n,parseModule as r,sucraseError as i,t as a,walk as o}from"./compiler-A2mqXrqO.js";var s=[`react`,`react-dom`,`react/jsx-runtime`,`react/jsx-dev-runtime`,`next/navigation`,`next/link`,`next/image`,`next/script`,`next/dynamic`,`next/font/google`,`next/font/local`],c=[...s,`next/headers`,`next/cache`,`next/server`,`server-only`],l=[...s,`client-only`],u=[`next/headers`,`server-only`],d=[`useState`,`useEffect`,`useLayoutEffect`,`useReducer`,`useRef`,`useContext`,`useTransition`,`useDeferredValue`,`useOptimistic`,`useActionState`,`useImperativeHandle`,`useInsertionEffect`,`useSyncExternalStore`],f=/^(src\/)?app\/(.*\/)?(page|layout|loading|error|not-found|template|route)\.(jsx?|tsx?)$/,p=/^(src\/)?app\/layout\.(jsx?|tsx?)$/,m=/\.(jsx?|mjs|tsx?)$/,h=`export default function RootLayout({ children }) {
7
- return (
8
- <html lang="en">
9
- <body>{children}</body>
10
- </html>
11
- );
12
- }
13
- `;function g(e,t){try{return e.endsWith(`.tsx`)?a(t,{transforms:[`typescript`,`jsx`],jsxRuntime:`preserve`,disableESTransforms:!0,filePath:e}).code:e.endsWith(`.ts`)?a(t,{transforms:[`typescript`],disableESTransforms:!0,filePath:e}).code:t}catch(n){throw i(e,t,n)}}function _(e,t,n){let r=n.startsWith(`@/`),i=r?n.slice(2):n,a=t=>{let n=[...t];for(let e of i.split(`/`))if(e!==``&&e!==`.`){if(e===`..`){if(!n.length)return;n.pop()}else n.push(e)}let r=n.join(`/`),a=[`.tsx`,`.ts`,`.jsx`,`.js`,`.mjs`];return[r,...a.map(e=>r+e),...a.map(e=>`${r}/index${e}`)].find(t=>Object.hasOwn(e,t))};return r?a([])??a([`src`]):a(n.startsWith(`/`)?[]:t.split(`/`).slice(0,-1))}function v(s,c){let l=g(c,s[c]),u=r(c,l),d=null;for(let e of u.body){if(e.type!==`ExpressionStatement`||typeof e.directive!=`string`)break;e.directive===`use client`&&(d=`client`),e.directive===`use server`&&(d=`server`)}let f=[],p=[],m=n(u),h=0;o(u,t=>{let n=t.source;if(/^(ImportDeclaration|ExportNamedDeclaration|ExportAllDeclaration|ImportExpression)$/.test(t.type)&&n&&typeof n.value==`string`){if(t.type===`ExportAllDeclaration`&&d===`server`)throw new e(c,`Only async functions are allowed to be exported in a "use server" file.`,t.loc.start.line,t.loc.start.column+1);f.push({spec:n.value,node:t})}if(t.type===`ExportDefaultDeclaration`&&p.push(`default`),t.type===`ExportNamedDeclaration`){for(let e of t.specifiers??[])p.push(e.exported.name);let e=t.declaration,n=e?.id;n&&p.push(n.name);for(let t of e?.declarations??[]){let e=t.id;e.type===`Identifier`&&p.push(e.name)}}let r=t.body;if(d!==`server`&&/^(FunctionDeclaration|FunctionExpression|ArrowFunctionExpression)$/.test(t.type)&&r?.type===`BlockStatement`&&r.body[0]?.directive===`use server`){let e=JSON.stringify(`${c}#inline${h++}`);t.type===`FunctionDeclaration`?m.push({at:t.end,text:`;__playpadAction(${t.id.name},${e});`}):m.push({at:t.start,text:`__playpadAction(`},{at:t.end,text:`,${e})`})}});try{let{code:e}=a(t(l,m),{transforms:[`jsx`,`imports`],jsxRuntime:`automatic`,production:!1,filePath:c});return{path:c,text:e,imports:f,directive:d,exportNames:p}}catch(e){throw i(c,l,e)}}function y(e,t){let n={},r=e.replace(/\W/g,`_`);return{css:t.replace(/"[^"]*"|'[^']*'|url\([^)]*\)|\.(-?[_a-zA-Z][\w-]*)/g,(e,t)=>t?(n[t]=`${r}__${t}`,`.${n[t]}`):e),names:n}}function b(t){let n=Object.keys(t).some(e=>/^(src\/)?app\//.test(e));if(!n&&Object.keys(t).some(e=>/^(src\/)?pages\//.test(e)))throw new e(`pages`,`The pages/ router is not available in this preview. Use the app/ directory.`);if(!n)throw new e(`app/page.jsx`,"Couldn't find any `pages` or `app` directory. Please create one under the project root");let r=Object.keys(t).some(e=>e.startsWith(`src/app/`)),i=Object.keys(t).some(e=>p.test(e))?t:{...t,[`${r?`src/`:``}app/layout.jsx`]:h},a=[];Object.keys(i).some(e=>/^(src\/)?(proxy|middleware)\.(js|ts)$/.test(e))&&a.push(`proxy (middleware) does not run in this preview.`),Object.keys(i).some(e=>/\/(@[^/]+|\(\.+\)[^/]*)\//.test(e))&&a.push(`Parallel and intercepting routes do not work in this preview.`);let o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map,g=/* @__PURE__ */ new Map,b=[],x=e=>(o.has(e)||o.set(e,v(i,e)),o.get(e));function S(e,t){let n=i[e],r=`{}`;if(e.endsWith(`.module.css`)){let t=y(e,n);n=t.css,r=JSON.stringify({__esModule:!0,default:t.names,...t.names})}b.some(t=>t.path===e)||b.push({path:e,text:n}),t.set(e,{path:e,kind:`json`,text:r,links:{}})}function C(t,n){try{JSON.parse(i[t])}catch(n){throw new e(t,`This file is not valid JSON: ${n.message}`)}n.set(t,{path:t,kind:`json`,text:i[t],links:{}})}function w(t,n){let r={},a=n===`server`?s:g;for(let{spec:o,node:s}of t.imports){let{line:f,column:p}=s.loc.start;if(/^(\.|\/|@\/)/.test(o)){let s=_(i,t.path,o);if(!s)throw new e(t.path,`Module not found: Can't resolve '${o}'`,f,p+1);if(r[o]=s,s.endsWith(`.css`))S(s,a);else if(s.endsWith(`.json`))C(s,a);else if(m.test(s))n===`server`?T(s):E(s);else throw new e(t.path,`"${o}" cannot be imported here. A project can import .js, .jsx, .ts, .tsx, .css and .json files.`,f,p+1)}else{if(n===`client`&&u.includes(o))throw new e(t.path,`You're importing a module that depends on "${o}" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use client", so this module is also a Client Component.`,f,p+1);if(!(n===`server`?c:l).includes(o))throw new e(t.path,`Module not found: Can't resolve '${o}'. Only react, react-dom and next/* can be imported here.`,f,p+1);if(n===`server`&&o===`react`)for(let n of s.specifiers??[]){let r=n.imported?.name;if(r&&d.includes(r))throw new e(t.path,`You're importing a module that depends on \`${r}\` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the \`"use client"\` directive.`,n.loc.start.line,n.loc.start.column+1)}}}return r}function T(e){if(s.has(e))return;let t=x(e);if(t.directive===`client`){s.set(e,{path:e,kind:`client-ref`,links:{}}),E(e);return}let n={path:e,kind:`js`,text:t.text,links:{},directive:t.directive===`server`?`server`:null};s.set(e,n),n.links=w(t,`server`)}function E(e){if(g.has(e))return;let t=x(e);if(t.directive===`server`){g.set(e,{path:e,kind:`server-ref`,exportNames:t.exportNames,links:{}}),T(e);return}let n={path:e,kind:`js`,text:t.text,links:{}};g.set(e,n),n.links=w(t,`client`)}let D=Object.keys(i).filter(e=>f.test(e));for(let e of D)T(e);return{server:[...s.values()],client:[...g.values()],css:b,routeFiles:D,notices:a}}function x(e){let t=/^(?:src\/)?app\/(?:(.*)\/)?page\.(?:jsx?|tsx?)$/.exec(e);if(!t)return`/`;let n=(t[1]??``).split(`/`).filter(e=>e&&!/^\(.*\)$/.test(e));return n.some(e=>e.startsWith(`[`)||e.startsWith(`@`))?`/`:`/${n.join(`/`)}`}export{e as CompileError,b as compileProject,x as startPath};