code-playpad 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -5
- package/dist/{boot-BPyX_lVu.js → boot-ecKcv-zZ.js} +1 -1
- package/dist/cdn.js +2 -2
- package/dist/{cpp-C9kekic8.js → cpp-DBIWUOId.js} +1 -1
- package/dist/{csharp-BoD8d8x4.js → csharp-BH1OwyjY.js} +1 -1
- package/dist/{element-Bzd1Vk4K.js → element-Ce06T38j.js} +54 -15
- package/dist/element.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{java-B2RmbH1B.js → java-BMjF_MwS.js} +1 -1
- package/dist/{javascript-CcekVHtC.js → javascript-DIMC4ddZ.js} +1 -1
- package/dist/{next-CdrJeX7n.js → next-B6FcJNwt.js} +1 -1
- package/dist/{pyodide-BVBDl-OE.js → pyodide-DmqFub0S.js} +1 -1
- package/dist/{react-BPyvHY9v.js → react-BnbPPmhA.js} +1 -1
- package/dist/react.d.ts +3 -1
- package/dist/react.js +1 -1
- package/dist/standalone.js +53 -14
- package/dist/{worker-runtime-VpuXbObm.js → worker-runtime-Ey7jwPA3.js} +1 -1
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ var e=[{id:`default-dark`,label:`One Dark`,mode:`dark`},{id:`monokai`,label:`Mon
|
|
|
10
10
|
--cp-ok: ${n.ok};
|
|
11
11
|
color-scheme: ${t};
|
|
12
12
|
}`]:[]).join(`
|
|
13
|
-
`)}async function d(e){try{return await ee(e)}catch(t){return console.warn(`[code-playpad] CodeMirror unavailable, using plain textarea:`,t),g(e)}}var f=/* @__PURE__ */ new Map,p=/* @__PURE__ */ new Set,m=!1;function h(){m||(m=!0,queueMicrotask(()=>{m=!1;for(let e of p){let t=[...e.adoptedStyleSheets];e.adoptedStyleSheets=[],e.adoptedStyleSheets=t}}))}async function ee(t){let[n,r,i,a,o,s,c]=await Promise.all([import(`@codemirror/view`),import(`@codemirror/state`),import(`@codemirror/commands`),import(`@codemirror/language`),import(`@codemirror/autocomplete`),import(`@codemirror/theme-one-dark`),import(`@lezer/highlight`)]),{EditorView:l,keymap:u,lineNumbers:d,highlightActiveLine:m,highlightActiveLineGutter:ee,highlightSpecialChars:g,drawSelection:_,rectangularSelection:v,crosshairCursor:y}=n,{EditorState:b,Compartment:x}=r,{defaultKeymap:S,history:te,historyKeymap:C,indentWithTab:w}=i,{syntaxHighlighting:T,defaultHighlightStyle:E,HighlightStyle:D,indentOnInput:O,bracketMatching:k,foldGutter:A,foldKeymap:j}=a,{autocompletion:M,closeBrackets:N,closeBracketsKeymap:P,completionKeymap:F}=o,I=new x,L=new x,R=new x,z=f.get(`default-light`)??[l.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`}}),T(E,{fallback:!0})];f.set(`default-light`,z);let{tags:B}=c,V=(e,t)=>[l.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}),T(D.define([{tag:[B.comment,B.meta],color:e.comment,fontStyle:`italic`},{tag:[B.keyword,B.operatorKeyword,B.modifier],color:e.keyword},{tag:[B.string,B.special(B.string),B.regexp],color:e.string},{tag:[B.number,B.bool,B.null,B.atom],color:e.number},{tag:[B.function(B.variableName),B.function(B.propertyName),B.definition(B.function(B.variableName))],color:e.fn},{tag:[B.typeName,B.className,B.namespace,B.tagName],color:e.type},{tag:[B.variableName,B.propertyName,B.attributeName],color:e.variable},{tag:B.invalid,color:e.keyword,textDecoration:`underline`}]))],H=(t,n)=>{let r=e.find(e=>e.id===n);if(!r?.colors)return t?s.oneDark:z;let i=f.get(r.id);return i||(i=V(r.colors,r.mode===`dark`),f.set(r.id,i)),i},U=u.of([{key:`Mod-Enter`,preventDefault:!0,run:()=>(t.onRun?.(),!0)},{key:`Shift-Enter`,preventDefault:!0,run:()=>(t.onRun?.(),!0)}]),W=t.dark,G=t.themeId,K=t.readOnly,q=t.language??[],J=e=>b.create({doc:e,extensions:[d(),ee(),g(),te(),A(),_(),b.allowMultipleSelections.of(!0),O(),k(),N(),M(),v(),y(),m(),U,u.of([...P,...S,...C,...j,...F,w]),l.lineWrapping,R.of(q),I.of(H(W,G)),L.of(b.readOnly.of(K)),l.updateListener.of(e=>{e.startState.facet(l.styleModule)!==e.state.facet(l.styleModule)&&h(),e.docChanged&&t.onChange?.(e.state.doc.toString())})]}),Y=new l({parent:t.parent,state:J(t.doc)});p.add(Y.root),h();let X=/* @__PURE__ */ new Map,Z=t.name??``;return{fallback:!1,getCode:()=>Y.state.doc.toString(),setCode(e){Y.dispatch({changes:{from:0,to:Y.state.doc.length,insert:e}})},openFile(e,t){if(e===Z)return;X.set(Z,Y.state);let n=X.get(e);Y.setState(n??J(t)),Z=e,n&&Y.dispatch({effects:[I.reconfigure(H(W,G)),L.reconfigure(b.readOnly.of(K)),R.reconfigure(q)]}),h()},fileCode(e,t){if(e===Z)return Y.state.doc.toString();let n=X.get(e);return n?n.doc.toString():t},forgetFiles(e){for(let t of[...X.keys()])e.includes(t)||X.delete(t)},renameFile(e,t){Z===e&&(Z=t);let n=X.get(e);n&&(X.delete(e),X.set(t,n))},setTheme(e,t){W=e,G=t,Y.dispatch({effects:I.reconfigure(H(W,G))})},setReadOnly(e){K=e,Y.dispatch({effects:L.reconfigure(b.readOnly.of(K))})},setLanguage(e){q=e,Y.dispatch({effects:R.reconfigure(q)})},focus:()=>Y.focus(),destroy(){p.delete(Y.root),Y.destroy()}}}function g(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)},renameFile(e,t){r===e&&(r=t);let i=n.get(e);i!==void 0&&(n.delete(e),n.set(t,i))},setTheme:()=>{},setReadOnly:e=>{t.readOnly=e},setLanguage:()=>{},focus:()=>t.focus(),destroy:()=>t.remove()}}var _=/* @__PURE__ */ new Map,v=/* @__PURE__ */ new Map;function y(e,t){_.set(e,t)}function b(){return[..._.keys()]}function x(e){let t=v.get(e);if(t)return t;let n=_.get(e);if(!n)return Promise.reject(/* @__PURE__ */ Error(`Unknown runtime "${e}". Registered: ${b().join(`, `)||`none`}`));let r=n().catch(t=>{throw v.delete(e),t});return v.set(e,r),r}y(`python`,()=>import(`./pyodide-
|
|
13
|
+
`)}async function d(e){try{return await ee(e)}catch(t){return console.warn(`[code-playpad] CodeMirror unavailable, using plain textarea:`,t),g(e)}}var f=/* @__PURE__ */ new Map,p=/* @__PURE__ */ new Set,m=!1;function h(){m||(m=!0,queueMicrotask(()=>{m=!1;for(let e of p){let t=[...e.adoptedStyleSheets];e.adoptedStyleSheets=[],e.adoptedStyleSheets=t}}))}async function ee(t){let[n,r,i,a,o,s,c]=await Promise.all([import(`@codemirror/view`),import(`@codemirror/state`),import(`@codemirror/commands`),import(`@codemirror/language`),import(`@codemirror/autocomplete`),import(`@codemirror/theme-one-dark`),import(`@lezer/highlight`)]),{EditorView:l,keymap:u,lineNumbers:d,highlightActiveLine:m,highlightActiveLineGutter:ee,highlightSpecialChars:g,drawSelection:_,rectangularSelection:v,crosshairCursor:y}=n,{EditorState:b,Compartment:x}=r,{defaultKeymap:S,history:te,historyKeymap:C,indentWithTab:w}=i,{syntaxHighlighting:T,defaultHighlightStyle:E,HighlightStyle:D,indentOnInput:O,bracketMatching:k,foldGutter:A,foldKeymap:j}=a,{autocompletion:M,closeBrackets:N,closeBracketsKeymap:P,completionKeymap:F}=o,I=new x,L=new x,R=new x,z=f.get(`default-light`)??[l.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`}}),T(E,{fallback:!0})];f.set(`default-light`,z);let{tags:B}=c,V=(e,t)=>[l.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}),T(D.define([{tag:[B.comment,B.meta],color:e.comment,fontStyle:`italic`},{tag:[B.keyword,B.operatorKeyword,B.modifier],color:e.keyword},{tag:[B.string,B.special(B.string),B.regexp],color:e.string},{tag:[B.number,B.bool,B.null,B.atom],color:e.number},{tag:[B.function(B.variableName),B.function(B.propertyName),B.definition(B.function(B.variableName))],color:e.fn},{tag:[B.typeName,B.className,B.namespace,B.tagName],color:e.type},{tag:[B.variableName,B.propertyName,B.attributeName],color:e.variable},{tag:B.invalid,color:e.keyword,textDecoration:`underline`}]))],H=(t,n)=>{let r=e.find(e=>e.id===n);if(!r?.colors)return t?s.oneDark:z;let i=f.get(r.id);return i||(i=V(r.colors,r.mode===`dark`),f.set(r.id,i)),i},U=u.of([{key:`Mod-Enter`,preventDefault:!0,run:()=>(t.onRun?.(),!0)},{key:`Shift-Enter`,preventDefault:!0,run:()=>(t.onRun?.(),!0)}]),W=t.dark,G=t.themeId,K=t.readOnly,q=t.language??[],J=e=>b.create({doc:e,extensions:[d(),ee(),g(),te(),A(),_(),b.allowMultipleSelections.of(!0),O(),k(),N(),M(),v(),y(),m(),U,u.of([...P,...S,...C,...j,...F,w]),l.lineWrapping,R.of(q),I.of(H(W,G)),L.of(b.readOnly.of(K)),l.updateListener.of(e=>{e.startState.facet(l.styleModule)!==e.state.facet(l.styleModule)&&h(),e.docChanged&&t.onChange?.(e.state.doc.toString())})]}),Y=new l({parent:t.parent,state:J(t.doc)});p.add(Y.root),h();let X=/* @__PURE__ */ new Map,Z=t.name??``;return{fallback:!1,getCode:()=>Y.state.doc.toString(),setCode(e){Y.dispatch({changes:{from:0,to:Y.state.doc.length,insert:e}})},openFile(e,t){if(e===Z)return;X.set(Z,Y.state);let n=X.get(e);Y.setState(n??J(t)),Z=e,n&&Y.dispatch({effects:[I.reconfigure(H(W,G)),L.reconfigure(b.readOnly.of(K)),R.reconfigure(q)]}),h()},fileCode(e,t){if(e===Z)return Y.state.doc.toString();let n=X.get(e);return n?n.doc.toString():t},forgetFiles(e){for(let t of[...X.keys()])e.includes(t)||X.delete(t)},renameFile(e,t){Z===e&&(Z=t);let n=X.get(e);n&&(X.delete(e),X.set(t,n))},setTheme(e,t){W=e,G=t,Y.dispatch({effects:I.reconfigure(H(W,G))})},setReadOnly(e){K=e,Y.dispatch({effects:L.reconfigure(b.readOnly.of(K))})},setLanguage(e){q=e,Y.dispatch({effects:R.reconfigure(q)})},focus:()=>Y.focus(),destroy(){p.delete(Y.root),Y.destroy()}}}function g(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)},renameFile(e,t){r===e&&(r=t);let i=n.get(e);i!==void 0&&(n.delete(e),n.set(t,i))},setTheme:()=>{},setReadOnly:e=>{t.readOnly=e},setLanguage:()=>{},focus:()=>t.focus(),destroy:()=>t.remove()}}var _=/* @__PURE__ */ new Map,v=/* @__PURE__ */ new Map;function y(e,t){_.set(e,t)}function b(){return[..._.keys()]}function x(e){let t=v.get(e);if(t)return t;let n=_.get(e);if(!n)return Promise.reject(/* @__PURE__ */ Error(`Unknown runtime "${e}". Registered: ${b().join(`, `)||`none`}`));let r=n().catch(t=>{throw v.delete(e),t});return v.set(e,r),r}y(`python`,()=>import(`./pyodide-DmqFub0S.js`).then(e=>e.pythonRuntime)),y(`javascript`,()=>import(`./javascript-DIMC4ddZ.js`).then(e=>e.javascriptRuntime)),y(`typescript`,()=>import(`./javascript-DIMC4ddZ.js`).then(e=>e.typescriptRuntime)),y(`java`,()=>import(`./java-BMjF_MwS.js`).then(e=>e.javaRuntime)),y(`c`,()=>import(`./cpp-DBIWUOId.js`).then(e=>e.cRuntime)),y(`cpp`,()=>import(`./cpp-DBIWUOId.js`).then(e=>e.cppRuntime)),y(`csharp`,()=>import(`./csharp-BH1OwyjY.js`).then(e=>e.csharpRuntime)),y(`cs`,()=>import(`./csharp-BH1OwyjY.js`).then(e=>e.csharpRuntime)),y(`react`,()=>import(`./react-BnbPPmhA.js`).then(e=>e.reactRuntime)),y(`next`,()=>import(`./next-B6FcJNwt.js`).then(e=>e.nextRuntime));var S=class extends Error{constructor(e=`Execution stopped`){super(e),this.name=`RunStopped`}},te=class extends Error{constructor(e=`Web Workers are unavailable in this page`){super(e),this.name=`WorkerUnavailable`}},C=/* @__PURE__ */ new WeakSet,w=String.raw`
|
|
14
14
|
:host {
|
|
15
15
|
--cp-bg: #ffffff;
|
|
16
16
|
--cp-fg: #1f2328;
|
|
@@ -422,9 +422,48 @@ table.cp-table th { background: var(--cp-bg); }
|
|
|
422
422
|
.cp-preview-notice[hidden] { display: none; }
|
|
423
423
|
.cp-output .cp-warn { color: #9a6700; }
|
|
424
424
|
:host([data-resolved-theme="dark"]) .cp-output .cp-warn { color: #d29922; }
|
|
425
|
-
.
|
|
426
|
-
.
|
|
427
|
-
|
|
425
|
+
/* What hasn't run yet. A filled mark: changed since the last run. A hollow one:
|
|
426
|
+
differs from what the page shipped, but has run. The text after the slash is
|
|
427
|
+
what a screen reader says; browsers without it keep the first rule. */
|
|
428
|
+
.cp-tabs button.cp-edited::after { content: ' ○'; color: var(--cp-muted); }
|
|
429
|
+
.cp-tabs button.cp-edited::after { content: ' ○' / ', changed'; }
|
|
430
|
+
.cp-tabs button.cp-unrun::after { content: ' ●'; color: var(--cp-accent); }
|
|
431
|
+
.cp-tabs button.cp-unrun::after { content: ' ●' / ', not run yet'; }
|
|
432
|
+
button.cp-primary { position: relative; }
|
|
433
|
+
button.cp-primary.cp-unrun::after {
|
|
434
|
+
content: '';
|
|
435
|
+
position: absolute;
|
|
436
|
+
top: -4px;
|
|
437
|
+
right: -4px;
|
|
438
|
+
width: 8px;
|
|
439
|
+
height: 8px;
|
|
440
|
+
border: 2px solid var(--cp-surface);
|
|
441
|
+
border-radius: 50%;
|
|
442
|
+
background: #bf8700;
|
|
443
|
+
}
|
|
444
|
+
:host([data-resolved-theme="dark"]) button.cp-primary.cp-unrun::after { background: #d29922; }
|
|
445
|
+
/* Over the output, so the widget keeps its size; clicks go through to what's under it. */
|
|
446
|
+
.cp-output-box { position: relative; }
|
|
447
|
+
.cp-has-preview .cp-preview-pane { position: relative; }
|
|
448
|
+
.cp-stale-note {
|
|
449
|
+
position: absolute;
|
|
450
|
+
top: 6px;
|
|
451
|
+
right: 8px;
|
|
452
|
+
z-index: 2;
|
|
453
|
+
max-width: calc(100% - 16px);
|
|
454
|
+
padding: 3px 8px;
|
|
455
|
+
border: 1px solid var(--cp-border);
|
|
456
|
+
border-radius: 999px;
|
|
457
|
+
background: var(--cp-bg);
|
|
458
|
+
color: var(--cp-muted);
|
|
459
|
+
font-size: 12px;
|
|
460
|
+
white-space: nowrap;
|
|
461
|
+
overflow: hidden;
|
|
462
|
+
text-overflow: ellipsis;
|
|
463
|
+
pointer-events: none;
|
|
464
|
+
box-shadow: 0 1px 3px rgb(0 0 0 / 0.12);
|
|
465
|
+
}
|
|
466
|
+
.cp-stale-note[hidden], .cp-output-box:has(> .cp-output[hidden]) .cp-stale-note { display: none; }
|
|
428
467
|
.cp-tab-folder { opacity: 0.65; }
|
|
429
468
|
|
|
430
469
|
@container (max-width: 480px) {
|
|
@@ -667,11 +706,11 @@ table.cp-table th { background: var(--cp-bg); }
|
|
|
667
706
|
}
|
|
668
707
|
`,T=e=>()=>import(`@codemirror/lang-javascript`).then(t=>t.javascript(e)),E={py:()=>import(`@codemirror/lang-python`).then(e=>e.python()),pyi:()=>import(`@codemirror/lang-python`).then(e=>e.python()),js:T({}),mjs:T({}),cjs:T({}),jsx:T({jsx:!0}),ts:T({typescript:!0}),mts:T({typescript:!0}),cts:T({typescript:!0}),tsx:T({typescript:!0,jsx:!0}),json:()=>import(`@codemirror/lang-json`).then(e=>e.json()),css:()=>import(`@codemirror/lang-css`).then(e=>e.css()),html:()=>import(`@codemirror/lang-html`).then(e=>e.html()),c:()=>import(`@codemirror/lang-cpp`).then(e=>e.cpp()),h:()=>import(`@codemirror/lang-cpp`).then(e=>e.cpp()),cpp:()=>import(`@codemirror/lang-cpp`).then(e=>e.cpp()),cc:()=>import(`@codemirror/lang-cpp`).then(e=>e.cpp()),cxx:()=>import(`@codemirror/lang-cpp`).then(e=>e.cpp()),hpp:()=>import(`@codemirror/lang-cpp`).then(e=>e.cpp()),hxx:()=>import(`@codemirror/lang-cpp`).then(e=>e.cpp()),java:()=>import(`@codemirror/lang-java`).then(e=>e.java()),cs:()=>Promise.all([import(`@codemirror/language`),import(`@codemirror/legacy-modes/mode/clike`)]).then(([e,t])=>e.StreamLanguage.define(t.csharp))};async function D(e,t){let n=e.includes(`.`)?e.slice(e.lastIndexOf(`.`)+1).toLowerCase():``,r=(t===`react`||t===`next`)&&n===`js`?E.jsx:E[n];return r?r().catch(()=>null):null}var O=`code-playpad`,k=1,A=`snippets`,j=`progress`,M=null;function N(){return typeof indexedDB>`u`?Promise.reject(/* @__PURE__ */ Error(`IndexedDB unavailable`)):(M||=new Promise((e,t)=>{let n=indexedDB.open(O,k);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(A)||e.createObjectStore(A),e.objectStoreNames.contains(j)||e.createObjectStore(j,{keyPath:`id`})},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}).catch(e=>{throw M=null,e}),M)}function P(e,t,n){return N().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 F(e,t){return P(A,`readwrite`,n=>n.put(t,e)).then(()=>void 0)}function I(e){return P(A,`readonly`,t=>t.get(e)).then(e=>e??null)}function L(e){return P(A,`readwrite`,t=>(t.delete(R(e)),t.delete(e))).then(()=>void 0)}var R=e=>`${e}\nstarters`;function z(e,t){return F(R(e),t)}function B(e){return I(R(e))}function V(e,t={}){let n={completed:!0,...t,id:e,updatedAt:Date.now()};return P(j,`readwrite`,e=>e.put(n)).then(()=>n)}function H(e){return P(j,`readonly`,t=>t.get(e)).then(e=>e??null)}function U(){return P(j,`readonly`,e=>e.getAll())}var W=`code-playpad`,G=`<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 4v14a2 2 0 0 0 2 2h3M5 10h5"/><rect x="11" y="7" width="9" height="5" rx="1"/><rect x="11" y="17" width="9" height="5" rx="1"/><path d="M4 3h3"/></svg>`,K=`<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 20V6a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v3h9a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1zM11 9H3M14 5h6"/></svg>`,q=`<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8zM14 3v5h5M12 11v6M9 14h6"/></svg>`,J=`<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 6a1 1 0 0 1 1-1h5l2 3h9a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1zM12 11v5M9.5 13.5h5"/></svg>`,Y=(e,t)=>e?`${e}/${t}`:t;function X(e){if(typeof e!=`string`||!e.trim())return`A file needs a name.`;if(e.includes(`\\`))return`"${e}" has a backslash. Use / between folders.`;let t=e.split(`/`);return t.some(e=>!e.trim())?`"${e}" has an empty folder name.`:t.some(e=>e===`.`||e===`..`)?`"${e}" can't use . or .. as a folder.`:e===`__proto__`?`"${e}" can't be used as a file name.`:null}function Z(e,t,n){let r={...e};for(let e of Object.keys(n))Object.hasOwn(t,e)?r[e]===t[e]&&(r[e]=n[e]):Object.hasOwn(r,e)||(r[e]=n[e]);for(let e of Object.keys(t))!Object.hasOwn(n,e)&&r[e]===t[e]&&delete r[e];return r}function ne(e){let t=e.replace(/\t/g,` `).split(`
|
|
669
708
|
`);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(`
|
|
670
|
-
`)}var Q=2e5,$=`playpad-file`,re={python:`main.py`,javascript:`main.js`,typescript:`main.ts`,java:`Main.java`,c:`main.c`,cpp:`main.cpp`,csharp:`Program.cs`,cs:`Program.cs`,react:`src/main.jsx`,next:`app/page.jsx`};function ie(e){return re[e]??`main.txt`}var ae=e=>e.tagName===`SCRIPT`&&e.getAttribute(`type`)===`text/plain`;function oe(e){return[...e.children].filter(e=>e.tagName.toLowerCase()===$&&[...e.children].some(e=>!ae(e))).map(e=>e.getAttribute(`name`)??``)}function se(e,t){let n={};for(let t of e.children){if(t.tagName.toLowerCase()!==$)continue;let e=t.getAttribute(`name`),r=[...t.children].find(ae);e&&(n[e]=ne((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=ne(r.filter(e=>!(i&&e.nodeType===Node.TEXT_NODE&&!(e.textContent??``).trim())).map(e=>e.textContent??``).join(``));return{[t]:a}}function ce(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 le=typeof HTMLElement>`u`?class{}:HTMLElement,ue=class extends le{static get observedAttributes(){return[`language`,`height`,`min-height`,`max-height`,`preview-height`,`tree-width`,`file-view`,`file-actions`,`file-view-switch`,`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=!1;#_=`main.py`;#v=null;#y;#b=!1;#x=null;#S=!1;#C=!1;#w=null;#T=null;#E=null;#D=()=>this.#
|
|
671
|
-
`,`cp-err`),this.#
|
|
709
|
+
`)}var Q=2e5,$=`playpad-file`,re={python:`main.py`,javascript:`main.js`,typescript:`main.ts`,java:`Main.java`,c:`main.c`,cpp:`main.cpp`,csharp:`Program.cs`,cs:`Program.cs`,react:`src/main.jsx`,next:`app/page.jsx`};function ie(e){return re[e]??`main.txt`}var ae=e=>e.tagName===`SCRIPT`&&e.getAttribute(`type`)===`text/plain`;function oe(e){return[...e.children].filter(e=>e.tagName.toLowerCase()===$&&[...e.children].some(e=>!ae(e))).map(e=>e.getAttribute(`name`)??``)}function se(e,t){let n={};for(let t of e.children){if(t.tagName.toLowerCase()!==$)continue;let e=t.getAttribute(`name`),r=[...t.children].find(ae);e&&(n[e]=ne((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=ne(r.filter(e=>!(i&&e.nodeType===Node.TEXT_NODE&&!(e.textContent??``).trim())).map(e=>e.textContent??``).join(``));return{[t]:a}}function ce(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 le=typeof HTMLElement>`u`?class{}:HTMLElement,ue=class extends le{static get observedAttributes(){return[`language`,`height`,`min-height`,`max-height`,`preview-height`,`tree-width`,`file-view`,`file-actions`,`file-view-switch`,`change-marks`,`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=!1;#_=`main.py`;#v=null;#y;#b=!1;#x=null;#S=!1;#C=!1;#w=null;#T=null;#E=null;#D=()=>this.#it();#O=null;#k=null;#A=!0;#j=[];#M=null;#N=null;#P=null;#F=0;#I=!1;#L=null;#R;#z;#B=null;#V=``;#H=[];#U=/* @__PURE__ */ new Set;#W=null;#G=null;#K;#q;#J=null;#Y=null;#X=null;#Z=null;#Q=null;constructor(){super(),this.#e=this.attachShadow({mode:`open`})}get code(){return this.#u?this.#u.getCode():this.#m[this.#_]??``}set code(e){this.#m[this.#_]=e,this.#ce(),this.#$e()}get practice(){if(this.#L)return this.#L;let e=this.getAttribute(`practice`);if(!e)return null;try{return JSON.parse(e)}catch{return null}}set practice(e){this.#L=e}get files(){return this.#me()}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.#Y=null,this.#Re(),this.#H=[],t.includes(this.#_)||(this.#_=this.#fe()),this.#oe(),this.#se(),this.#he(),this.#ie()}get entry(){return this.#fe()}set entry(e){this.setAttribute(`entry`,e)}openFile(e){if(e in this.#m){this.#u&&(e!==this.#_&&this.#ae(),this.#m[this.#_]=this.#u.getCode(),this.#u.openFile(e,this.#m[e]??``)),this.#_=e,this.#W=null;for(let t=e.indexOf(`/`);t!==-1;t=e.indexOf(`/`,t+1))this.#U.delete(e.slice(0,t));this.#he(),this.#ie()}}addFile(e,t=``){if(this.#X)return this.#X.widget.addFile(e,t);this.#ye();let n=this.#be(e);if(n)throw Error(n);this.#Ce(()=>{this.#m[e]=t}),this.openFile(e),this.#Ee(`add`,e)}renameFile(e,t){if(this.#X)return this.#X.widget.renameFile(e,t);if(this.#ye(),!Object.hasOwn(this.#m,e))throw Error(`There is no file named "${e}".`);let n=this.#xe(e);if(n)throw Error(`"${e}" can't be renamed: ${n}.`);if(t===e)return;let r=this.#be(t,e);if(r)throw Error(r);let i=this.#me()[e];this.#Ce(()=>{this.#m=Object.fromEntries(Object.entries(this.#m).map(([n,r])=>n===e?[t,i]:[n,r]))}),this.#u?.renameFile(e,t),this.#H=this.#H.filter(t=>t!==e),this.#_===e&&(this.#_=t,this.#we(t)),this.#he(),this.#ie(),this.#Ee(`rename`,t,e)}removeFile(e){if(this.#X)return this.#X.widget.removeFile(e);if(this.#ye(),!Object.hasOwn(this.#m,e))throw Error(`There is no file named "${e}".`);if(Object.keys(this.#m).length===1)throw Error(`"${e}" can't be removed: it's the only file.`);let t=this.#xe(e);if(t)throw Error(`"${e}" can't be removed: ${t}.`);this.#_===e&&this.openFile(this.#Te(e)),delete this.#m[e],this.#u?.forgetFiles(Object.keys(this.#m)),this.#H=this.#H.filter(t=>t!==e),this.#he(),this.#Ee(`remove`,e)}get stdin(){return this.#l?this.#l.value:``}set stdin(e){this.#l&&(this.#l.value=e,this.#c.hidden=!1,this.#$e())}get language(){return this.getAttribute(`language`)||`python`}set language(e){this.setAttribute(`language`,e)}getCode(){return this.code}getFiles(){return this.#me()}reset(){this.#ae(),this.#Re(),this.#Y=null,this.#m={...this.#h},this.#_=this.#fe(),this.#se(),this.#he(),this.#ie(),this.#st(),this.#s.hidden=!0,this.#Qe(),this.#B=null,this.#$e(),this.#ot(this.#f?.ready?`${this.#f.label} ready`:``,`idle`),this.#ve()&&this.#tt(0)}async run(){if(this.#X)return this.#X.widget.run();if(this.#b)return;await this.#d;let e=this.#me(),t=this.getAttribute(`entry`);if(t&&!(t in e))return this.#ue(t,e);this.#le=!1;let n=this.#fe(),r=e[n]??``;this.#b=!0,this.#S=!1,this.#n.disabled=!0,this.#r.hidden=!1,this.#st(),this.#s.hidden=!1;let i=this.practice;this.hasAttribute(`practice`)&&!i&&this.#ct(`The practice attribute is not valid JSON.
|
|
710
|
+
`,`cp-err`),this.#B=e,this.#V=this.#l.value,this.#$e(),this.#Ze()&&this.#H.length&&this.#ct(`${this.#H.join(`, `)}: HTML tags in this file's markup were read as elements, so its code is incomplete. Write < as <, or put the code in <script type="text/plain">. A <script> left unescaped runs on the host page.\n`,`cp-err`),this.#mt(`py-run`,{code:r,entry:n,files:e,language:this.language,...i?{practice:i}:{}});try{let t=await this.#re();if(this.#S)throw new S;if(i&&!t.supportsPractice)throw Error(`Practice mode is not available for ${t.label}.`);this.#ot(`Queued…`,`busy`),this.#o.hidden=!1;let a=t.run(r,{stdin:this.#l.value,files:e,entry:n,onStart:()=>this.#ot(`Running…`,`busy`),onProgress:e=>this.#ot(e.message,`busy`),onStdout:e=>this.#ct(e),onStderr:e=>this.#ct(e,`cp-err`),onEcho:e=>this.#ct(e,`cp-in`),onStdinRequest:()=>this.#ut(),...i?{practice:i}:{},...this.#Ze()?{preview:{host:this.#R,onStart:()=>this.#ot(`Running…`,`busy`),onConsole:(e,t)=>{this.#ct(`${t}\n`,e===`error`?`cp-err`:e===`warn`?`cp-warn`:void 0),this.#ht(`playpad-console`,{level:e,text:t,language:this.language})},onRender:e=>this.#ht(`playpad-render`,{rootText:e,language:this.language}),onError:e=>{this.#ot(`Error`,`error`),this.#mt(`py-error`,{...e,language:this.language})}}}:{}});this.#x={runtime:t,run:a};let o=await a;if(o.table&&this.#pt(o.table),o.value!==void 0&&this.#ct(`${o.value}\n`,`cp-value`),o.hint&&this.#ft(o.hint,C.has(o)),o.failed=t.statusDecidesFailure?o.failed===!0:!!o.stderr,o.failed)this.#ot(`Error · ${o.durationMs} ms`,`error`),this.#mt(`py-error`,{message:o.problem?.message??o.stderr??``,hint:o.hint,language:this.language,...o.problem??{}});else if(o.cases){let e=o.cases.filter(e=>e.expected!==void 0).length,t=o.passed===e;this.#ot(e?`${o.passed} of ${e} passed · ${o.durationMs} ms`:`Done in ${o.durationMs} ms`,t?`ok`:`error`)}else this.#ot(`Done in ${o.durationMs} ms`,`ok`);return this.#mt(`py-output`,{...o,language:this.language}),o}catch(e){if(e instanceof S)this.#ct(`
|
|
672
711
|
[stopped]
|
|
673
|
-
`,`cp-err`),this.#
|
|
674
|
-
`,`cp-err`),this.#
|
|
712
|
+
`,`cp-err`),this.#ot(`Stopped`,`error`);else{let t=e instanceof Error?e.message:String(e);this.#ct(t+`
|
|
713
|
+
`,`cp-err`),this.#ot(`Failed to start`,`error`),this.#mt(`py-error`,{message:t,language:this.language})}return}finally{this.#x=null,this.#dt(null),this.#lt(),this.#b=!1,this.#n.disabled=!1,this.#r.hidden=!(this.#Ze()&&this.#f?.hasLivePreview?.(this.#R)),this.#o.hidden=!0}}stop(){this.#X?this.#X.widget.stop():this.#x?this.#x.runtime.stop?.(this.#x.run):this.#b?this.#S=!0:this.#Ze()&&this.#f?.hasLivePreview?.(this.#R)&&(this.#Qe(),this.#r.hidden=!0,this.#ot(`Stopped`,`idle`))}openWindow(){if(this.#X)return this.#X.window.focus(),!0;if(this.#Z)return!1;let e=window.open(``,`_blank`,`popup,width=1280,height=800`);if(!e)return this.#ot(`The browser blocked the new window`,`error`),!1;let t=this.#me(),n=this.#_,r=document.createElement(this.localName);for(let e of[`language`,`entry`,`file-view`,`file-view-switch`,`file-actions`,`change-marks`,`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.#Z=this,r.#Q={...this.#h},r.#v=t,r.#Y=this.#Y,this.#Qe(),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.#X={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.#X;if(!e)return;this.#X=null,clearInterval(e.timer),window.removeEventListener(`pagehide`,e.onLeave);let{widget:t}=e,n=t.#me(),r=t.#_;t.#Qe(),t.remove(),e.window.closed||e.window.close(),this.#e.querySelector(`.cp-root`)?.classList.remove(`cp-popped`),this.files=n,this.#Y=t.#Y;let i=t.getAttribute(`file-view`);i!==this.getAttribute(`file-view`)&&(i===null?this.removeAttribute(`file-view`):this.setAttribute(`file-view`,i)),this.openFile(r),this.#ot(``,`idle`),this.#ve()&&this.#tt(0)}prewarm(){return this.#re()}connectedCallback(){this.#I?(this.#it(),this.#ne()):!this.textContent?.trim()&&document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>this.isConnected&&this.#$(),{once:!0}):this.#$()}disconnectedCallback(){this.#w?.disconnect(),this.#w=null,this.#T?.removeEventListener(`change`,this.#D),this.#T=null,this.#E?.disconnect(),this.#E=null,this.#O?.(),this.#O=null,this.#k&&clearTimeout(this.#k),this.#dt(null),setTimeout(()=>{this.isConnected||(this.closeWindow(),this.#Qe(),this.#u&&(this.#v=this.#me(),this.#u.destroy(),this.#u=null,this.#d=null,this.#I=!1))},0)}attributeChangedCallback(e,t,n){if(this.#I)switch(e){case`theme`:case`theme-controls`:this.#it();break;case`height`:this.#oe(),this.#at();break;case`min-height`:case`max-height`:case`preview-height`:case`tree-width`:this.#at();break;case`readonly`:this.#u?.setReadOnly(n!==null),this.hasAttribute(`file-actions`)&&(this.#Re(),this.#he());break;case`stdin`:this.#c.hidden=n===null&&!this.#l.value;break;case`file-view`:case`file-actions`:this.#Re(),this.#he();break;case`entry`:case`file-view-switch`:this.#he();break;case`change-marks`:this.#$e();break;case`language`:this.#Qe(),this.#e.querySelector(`.cp-root`)?.classList.toggle(`cp-has-preview`,this.#Ze()),this.#f=null,this.#p=null,this.#C=!1,this.#re().catch(()=>{})}}#$(){this.#I=!0,this.#h=this.#Q??se(this,this.#de()),this.#H=this.#Ze()?oe(this):[],this.#m=this.#v??{...this.#h},this.#_=this.#pe(),this.#ee(),this.#it(),this.#at();let e=this.getAttribute(`persist`);this.#d=(async()=>{if(e&&this.#v==null){let t=await I(e).catch(()=>null),n=t==null?null:ce(t,this.#de()),r=n&&this.#ve()?await this.#De(e):null;if(n&&r){let e=[this.#fe(),...this.#Se()],t=Z(n,r,this.#h);for(let n of e)!Object.hasOwn(t,n)&&Object.hasOwn(this.#h,n)&&(t[n]=this.#h[n]);this.#Ce(()=>{this.#m=t}),this.#_=this.#pe()}else 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.#_=this.#pe()}}this.#he();let t=await x(this.language).catch(()=>null),n=t?await t.editorLanguage().catch(()=>null):null;this.#u=await d({parent:this.#t,doc:this.#m[this.#_]??``,name:this.#_,dark:this.#nt(),themeId:this.#rt(),readOnly:this.hasAttribute(`readonly`),language:n,onRun:()=>void this.run(),onChange:e=>this.#et(e)}),this.#v=null,this.#it(),this.#ie()})(),this.#ne()}#ee(){let t=document.createElement(`style`);t.textContent=w;let n=document.createElement(`div`);if(n.className=this.#Ze()?`cp-root cp-has-preview`:`cp-root`,n.innerHTML=`
|
|
675
714
|
<div class="cp-toolbar">
|
|
676
715
|
<button class="cp-primary" part="run-button" data-action="run">Run</button>
|
|
677
716
|
<button class="cp-danger" part="stop-button" data-action="stop" hidden>Stop</button>
|
|
@@ -691,7 +730,6 @@ table.cp-table th { background: var(--cp-bg); }
|
|
|
691
730
|
<button part="window-button" class="cp-icon-button cp-window-button" data-action="window" aria-label="Open in window" title="Open in a separate window you can resize">
|
|
692
731
|
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>
|
|
693
732
|
</button>
|
|
694
|
-
<span class="cp-edited-note" hidden>Edited since the last run</span>
|
|
695
733
|
<span class="cp-status" data-state="idle"></span>
|
|
696
734
|
</div>
|
|
697
735
|
<div class="cp-progress" hidden></div>
|
|
@@ -717,11 +755,12 @@ table.cp-table th { background: var(--cp-bg); }
|
|
|
717
755
|
<div class="cp-preview" part="preview"></div>
|
|
718
756
|
<div class="cp-split cp-split-console" role="separator" tabindex="0" aria-orientation="horizontal" aria-label="Resize the preview and the console"></div>
|
|
719
757
|
<pre class="cp-output" part="output" hidden></pre>
|
|
758
|
+
<div class="cp-stale-note" part="stale-note" role="status" hidden></div>
|
|
720
759
|
</div>
|
|
721
|
-
</div>`,this.#e.replaceChildren(t,n),this.#n=n.querySelector(`[data-action="run"]`),this.#r=n.querySelector(`[data-action="stop"]`),this.#i=n.querySelector(`[data-action="reset"]`),this.#a=n.querySelector(`.cp-status`),this.#o=n.querySelector(`.cp-progress`),this.#y=n.querySelector(`.cp-tabs`),this.#t=n.querySelector(`.cp-editor`),this.#c=n.querySelector(`.cp-stdin`),this.#l=n.querySelector(`.cp-stdin textarea`),this.#s=n.querySelector(`.cp-output`),this.#R=n.querySelector(`.cp-preview`),this.#z=n.querySelector(`.cp-
|
|
722
|
-
`,`cp-err`),this.#s.hidden=!1,e}finally{this.#o.hidden=!0}return this.#re(),this.#C||(this.#C=!0,this.#ce||this.#at(`${e.label} ready`,`ok`),this.#pt(`py-ready`,{language:e.id,label:e.label})),e})(),this.#p}async#re(){if(!this.#u)return;let e=this.#_,t=await D(e,this.language);if(t){this.#_===e&&this.#u?.setLanguage(t);return}let n=e.includes(`.`)?null:await(this.#f??await x(this.language).catch(()=>null))?.editorLanguage().catch(()=>null);this.#_===e&&this.#u?.setLanguage(n??[])}#ie(){if(this.getAttribute(`height`)!==`auto`||this.#X)return;let e=this.#e.querySelector(`.cp-root`),t=this.#t.getBoundingClientRect().height;e&&t&&!e.classList.contains(`cp-editor-sized`)&&(e.style.setProperty(`--cp-editor-height`,`${t}px`),e.classList.add(`cp-editor-sized`),this.#g=!0)}#ae(){if(!this.#g)return;this.#g=!1;let e=this.#e.querySelector(`.cp-root`);e?.style.removeProperty(`--cp-editor-height`),e?.classList.remove(`cp-editor-sized`)}#oe(){this.#u?.openFile(this.#_,this.#m[this.#_]??``),this.#u?.forgetFiles([]),this.#se()}#se(){this.#u?this.#u.setCode(this.#m[this.#_]??``):this.#d?.then(()=>{this.#u?.setCode(this.#m[this.#_]??``),this.#me()})}#ce=!1;#le(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.#ot(),this.#s.hidden=!1,this.#st(r,`cp-err`),this.#ce=!0,this.#at(`Error · entry not found`,`error`);let i={stdout:``,stderr:r,durationMs:0,failed:!0};return this.#pt(`py-error`,{message:r,language:this.language}),this.#pt(`py-output`,{...i,language:this.language}),i}#ue(){return this.getAttribute(`entry`)||ie(this.language)}#de(){let e=Object.keys(this.#m),t=this.getAttribute(`entry`);if(t&&e.includes(t))return t;if(this.#J&&e.includes(this.#J))return this.#J;let n=this.#Xe()&&e.includes(`index.html`)?`index.html`:ie(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}#fe(){let e=this.getAttribute(`open-file`);return e&&e in this.#m?e:this.#de()}#pe(){if(this.#Y)return this.#Y.widget.#pe();let e={...this.#m};if(this.#u)for(let t of Object.keys(e))e[t]=this.#u.fileCode(t,e[t]);return e}#me(){let e=Object.keys(this.#m),t=this.#_e();this.#y.hidden=e.length<2&&!t,this.#e.querySelector(`.cp-root`)?.classList.toggle(`cp-file-actions`,t),this.#he();let n=t?this.#Ae():null,r=!this.#y.hidden&&this.getAttribute(`file-view`)===`tree`;if(this.#y.classList.toggle(`cp-tree`,r),this.#e.querySelector(`.cp-root`)?.classList.toggle(`cp-has-tree`,r),this.#y.hidden){this.#y.replaceChildren();return}if(r){this.#ge(e),this.#Qe(),t&&this.#je(n);return}let i=this.#de();if(this.#y.replaceChildren(...e.map(e=>{if(this.#W?.from===e)return this.#ke();let n=document.createElement(`button`);n.dataset.file=e;let r=e.lastIndexOf(`/`)+1;if(r){let t=document.createElement(`span`);t.className=`cp-tab-folder`,t.textContent=e.slice(0,r),n.setAttribute(`aria-label`,e),n.append(t)}return n.append(e.slice(r)),n.setAttribute(`aria-pressed`,String(e===this.#_)),e===i&&(n.classList.add(`cp-entry`),n.title=`entry point — this is the file Run executes`),t?this.#Oe(n,e):n})),t){if(this.#W&&this.#W.kind!==`rename`)this.#y.append(this.#ke());else{let e=this.#De(`new-file`,`New file`,`+`);e.classList.add(`cp-file-new`),this.#y.append(e)}}this.#Qe(),t&&this.#je(n)}#he(){let e=this.#e.querySelector(`[data-action="file-view"]`);if(!e)return;e.hidden=!this.hasAttribute(`file-view-switch`)||this.#y.hidden;let t=this.getAttribute(`file-view`)===`tree`,n=t?`Show files as tabs`:`Show files as a tree`;e.setAttribute(`aria-label`,n),e.title=n,e.innerHTML=t?K:G}#ge(e){let t=this.#de(),n=this.#_e(),r=[],i=this.#W,a=i?.folder?[...e,`${i.folder}/`]:e;if(n){let e=document.createElement(`div`);e.className=`cp-tree-head`;let t=document.createElement(`button`);t.type=`button`,t.className=`cp-tree-root`,t.dataset.targetRoot=``,t.textContent=`Files`,t.title=`Add new files and folders at the top level`,this.#U===``&&t.setAttribute(`aria-current`,`true`);let n=this.#Pe(),i=n?`in ${n}`:`at the top level`,a=this.#De(`new-file`,`New file`,q);a.title=`New file ${i}`;let o=this.#De(`new-folder`,`New folder`,J);o.title=`New folder ${i}`,e.append(t,a,o),r.push(e)}let o=(e,s)=>{let c=a.filter(t=>t.startsWith(e)).map(t=>t.slice(e.length));i&&i.kind!==`rename`&&`${i.folder}/`===(e||`/`)&&r.push(this.#ke(s));let l=[...new Set(c.filter(e=>e.includes(`/`)).map(e=>e.slice(0,e.indexOf(`/`))))].sort();for(let t of l){let i=e+t,a=!this.#H.has(i),c=document.createElement(`button`);if(c.className=`cp-tree-folder`,c.dataset.folder=i,c.textContent=t,c.setAttribute(`aria-expanded`,String(a)),n&&this.#U===i&&c.setAttribute(`aria-current`,`true`),c.style.setProperty(`--cp-depth`,String(s)),n){let e=this.#De(`new-file`,`New file in ${i}`,`+`);e.dataset.in=i;let t=document.createElement(`div`);t.className=`cp-file-row`,t.append(c,e),r.push(t)}else r.push(c);a&&o(`${i}/`,s+1)}for(let a of c.filter(e=>e&&!e.includes(`/`)).sort()){let o=e+a;if(i?.from===o){r.push(this.#ke(s));continue}let c=document.createElement(`button`);c.dataset.file=o,c.textContent=a,c.setAttribute(`aria-label`,o),c.setAttribute(`aria-pressed`,String(o===this.#_)),c.style.setProperty(`--cp-depth`,String(s)),o===t&&(c.classList.add(`cp-entry`),c.title=`entry point — this is the file Run executes`),r.push(n?this.#Oe(c,o):c)}};o(``,0),this.#y.replaceChildren(...r)}#_e(){return this.hasAttribute(`file-actions`)&&!this.hasAttribute(`readonly`)}#ve(){if(!this.#I)throw Error(`Add the widget to the page before changing its files.`)}#ye(e,t){let n=X(e);if(n)return n;let r=Object.keys(this.#m).filter(e=>e!==t);if(r.includes(e))return`A file named "${e}" already exists.`;if(r.some(t=>t.startsWith(`${e}/`)))return`"${e}" is a folder.`;let i=r.find(t=>e.startsWith(`${t}/`));return i?`"${i}" is a file, so it can't hold other files.`:null}#be(e){return e===this.#de()?`it's the entry file`:this.#xe().has(e)?`this ${this.language} project needs it`:null}#xe(){let e=/* @__PURE__ */ new Set,t=Object.keys(this.#m);if(this.language===`next`)for(let n of t)/^(src\/)?app\/layout\.(jsx?|tsx?)$/.test(n)&&e.add(n);if(this.language!==`react`)return e;for(let n of[`src/main.jsx`,`src/main.js`])t.includes(n)&&e.add(n);let n=this.#pe()[`index.html`];if(n===void 0)return e;e.add(`index.html`);let r=new DOMParser().parseFromString(n,`text/html`);for(let n of r.querySelectorAll(`script[src], link[rel="stylesheet"][href]`)){let r=(n.getAttribute(`src`)??n.getAttribute(`href`)).replace(/^\.?\//,``);t.includes(r)&&e.add(r)}return e}#Se(e){let t=this.#de();e(),this.#de()!==t&&Object.hasOwn(this.#m,t)&&(this.#J=t)}#Ce(e){for(let t=e.indexOf(`/`);t!==-1;t=e.indexOf(`/`,t+1))this.#H.delete(e.slice(0,t))}#we(e){let t=[...this.#y.querySelectorAll(`button[data-file]`)].map(e=>e.dataset.file),n=t.indexOf(e);return(n===-1?void 0:t[n+1]??t[n-1])??Object.keys(this.#m).find(t=>t!==e)}#Te(e,t,n){this.#et(0),this.#mt(`playpad-files-change`,{action:e,name:t,...n?{previousName:n}:{},files:this.#pe()})}async#Ee(e){let t=await B(e).catch(()=>null);if(!t)return null;try{return JSON.parse(t)}catch{return null}}#De(e,t,n){let r=document.createElement(`button`);return r.type=`button`,r.className=`cp-file-tool`,r.dataset.fileAction=e,r.setAttribute(`aria-label`,t),r.title=t,r.innerHTML=n,r}#Oe(e,t){let n=document.createElement(`div`);if(n.className=`cp-file-row`,n.append(e),this.#be(t))return n;let r=document.createElement(`button`);return r.type=`button`,r.className=`cp-file-tool cp-file-more`,r.dataset.more=t,r.textContent=`⋯`,r.setAttribute(`aria-label`,`Actions for ${t}`),r.setAttribute(`aria-expanded`,`false`),r.title=`Rename or remove`,n.append(r),n}#ke(e=0){let t=this.#W,n=document.createElement(`form`);n.className=`cp-file-field`,n.style.setProperty(`--cp-depth`,String(e));let r=document.createElement(`input`);r.type=`text`,r.value=t.value,r.autocapitalize=`off`,r.autocomplete=`off`,r.spellcheck=!1,r.placeholder=t.kind===`folder`?`components`:`TaskLine.jsx`;let i=t.folder?` in ${t.folder}`:``;r.setAttribute(`aria-label`,t.kind===`rename`?`New name for ${t.from}`:t.kind===`folder`?`Name of the new folder${i}`:`Name of the new file${i}`),r.addEventListener(`input`,()=>{t.value=r.value,this.#Be(``)}),r.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e.preventDefault(),this.#Re())});let a=document.createElement(`button`);return a.type=`button`,a.className=`cp-file-tool`,a.dataset.fileAction=`cancel`,a.textContent=`×`,a.setAttribute(`aria-label`,`Cancel`),n.addEventListener(`submit`,e=>{e.preventDefault(),this.#ze()}),n.append(r,a),n}#Ae(){let e=this.#e.activeElement;if(!e||!this.#y.contains(e))return null;if(e.closest(`.cp-file-field`))return{field:!0};let{file:t,folder:n,more:r}=e.dataset;return{file:t,folder:n,more:r}}#je(e){let t=this.#y.querySelector(`.cp-file-field input`);if(t&&this.#W?.fresh){this.#W.fresh=!1,t.focus();let e=this.#W.kind===`rename`?t.value.lastIndexOf(`.`):-1;e>0?t.setSelectionRange(t.value.lastIndexOf(`/`)+1,e):t.setSelectionRange(t.value.length,t.value.length)}else e?.field?t?.focus():e&&this.#Me(e)?.focus();let n=this.#y.querySelector(`button[aria-pressed="true"]`);if(n&&!t){let e=this.#y.getBoundingClientRect(),t=n.getBoundingClientRect();t.left<e.left?this.#y.scrollLeft-=e.left-t.left:t.right>e.right-32&&(this.#y.scrollLeft+=t.right-e.right+32),t.top<e.top?this.#y.scrollTop-=e.top-t.top:t.bottom>e.bottom&&(this.#y.scrollTop+=t.bottom-e.bottom)}}#Me(e){return[...this.#y.querySelectorAll(`button`)].find(({dataset:t})=>e.file!==void 0&&t.file===e.file||e.folder!==void 0&&t.folder===e.folder||e.more!==void 0&&t.more===e.more)}#Ne(e){let t=e.dataset.fileAction;if(t===`cancel`)return this.#Re();let n=this.getAttribute(`file-view`)===`tree`,r=e.dataset.in??this.#Pe();this.#Ce(`${r}/`),this.#Fe(t===`new-folder`?{kind:`folder`,folder:r,value:``,fresh:!0}:n?{kind:`file`,folder:r,value:``,fresh:!0}:{kind:`file`,folder:``,value:r&&`${r}/`,fresh:!0})}#Pe(){let e=this.#U;return e===``||e&&Object.keys(this.#m).some(t=>t.startsWith(`${e}/`))?e:this.#_.includes(`/`)?this.#_.slice(0,this.#_.lastIndexOf(`/`)):``}#Fe(e){this.#We(!1),this.#Be(``),this.#W=e,this.#me()}#Ie(e){let t=this.getAttribute(`file-view`)===`tree`?e.lastIndexOf(`/`):-1;this.#Fe({kind:`rename`,from:e,folder:t===-1?``:e.slice(0,t),value:e.slice(t+1),fresh:!0})}#Le(){this.#W=null,this.#U=null,this.#G&&(this.#G.hidden=!0,this.#Be(``))}#Re(){let e=this.#W?.from;this.#W=null,this.#Be(``),this.#me(),(e&&this.#Me({more:e})||this.#Me({file:this.#_}))?.focus()}#ze(){let e=this.#W;if(!e)return;let t=e.value.trim(),n=this.getAttribute(`file-view`)===`tree`;if(e.kind===`folder`||e.kind===`file`&&t.endsWith(`/`)){if(!n)return this.#Be(`Add a file name after the folder.`,!0);if(!t)return this.#Be(`A folder needs a name.`,!0);let r=Y(e.folder,t.replace(/\/$/,``)),i=Object.keys(this.#m).some(e=>e.startsWith(`${r}/`))?null:this.#ye(r);return i?this.#Be(i,!0):(this.#Ce(`${r}/`),this.#Fe({kind:`file`,folder:r,value:``,fresh:!0}))}if(!t)return this.#Be(`A file needs a name.`,!0);let r=Y(e.folder,t);if(e.kind===`rename`&&r===e.from)return this.#Re();if(Object.hasOwn(this.#m,r))return this.#W=null,this.openFile(r),this.#u?.focus(),this.#Be(`"${r}" already exists, so it's open now.`,!1,4e3);let i=this.#ye(r,e.from);if(i)return this.#Be(i,!0);if(this.#W=null,this.#Be(``),e.kind===`rename`){let t=this.#_===e.from;this.renameFile(e.from,r),t?this.#u?.focus():this.#Me({file:r})?.focus()}else this.addFile(r),this.#u?.focus()}#Be(e,t=!1,n=0){this.#q&&clearTimeout(this.#q),this.#q=n?setTimeout(()=>this.#Be(``),n):null,this.#K.textContent=e,this.#K.hidden=!e,this.#K.classList.toggle(`cp-file-refused`,t),this.#y.querySelector(`.cp-file-field input`)?.setAttribute(`aria-invalid`,String(!!e&&t)),e&&this.#Ve(this.#K,t&&this.#y.querySelector(`.cp-file-field`)||this.#y)}#Ve(e,t){e.hidden=!1;let n=e.parentElement.getBoundingClientRect(),r=t.getBoundingClientRect();e.style.top=`${Math.max(0,Math.min(r.bottom-n.top+2,n.height-e.offsetHeight))}px`,e.style.left=`${Math.max(0,Math.min(r.left-n.left,n.width-e.offsetWidth))}px`}#He=null;#Ue(e,t){this.#We(!1),this.#He=e,this.#G.replaceChildren(...t),this.#Ve(this.#G,e),this.#G.querySelector(`button`)?.focus()}#We(e){this.#G&&!this.#G.hidden&&(this.#G.hidden=!0,this.#G.replaceChildren(),this.#G.removeAttribute(`role`),this.#G.removeAttribute(`aria-label`),this.#He?.setAttribute(`aria-expanded`,`false`),e&&this.#He?.focus(),this.#He=null)}#Ge(e,t,n=``){let r=document.createElement(`button`);return r.type=`button`,r.textContent=e,r.className=n,r.addEventListener(`click`,t),r}#Ke(e,t){let n=()=>{this.#pe()[t]?.trim()?this.#qe(e,`Remove ${t}? Its code will be lost.`,`Remove`,()=>this.#Je(t)):this.#Je(t)},r=this.#Ge(`Rename`,()=>{this.#We(!1),this.#Ie(t)});this.#Ue(e,[r,this.#Ge(`Remove`,n)]),e.setAttribute(`aria-expanded`,`true`)}#qe(e,t,n,r){let i=document.createElement(`p`);i.textContent=t;let a=document.createElement(`div`);a.className=`cp-file-pop-buttons`,a.append(this.#Ge(`Cancel`,()=>this.#We(!0)),this.#Ge(n,()=>{this.#We(!1),r()},`cp-danger`)),this.#Ue(e,[i,a]),this.#G.setAttribute(`role`,`alertdialog`),this.#G.setAttribute(`aria-label`,t)}#Je(e){this.#We(!1);let t=this.#we(e);this.removeFile(e),this.#Me({file:t})?.focus()}#Ye(){let e=Object.keys(this.#m),t=Object.keys(this.#h),n=e.length===t.length&&e.every(e=>Object.hasOwn(this.#h,e));if(!this.#_e()||n)return this.reset();this.#qe(this.#i,`Reset the project? Files you added go away, and files you removed come back.`,`Reset`,()=>{this.reset(),this.#i.focus()})}#Xe(){return this.language===`react`||this.language===`next`}#Ze(){this.#R&&(this.#f?.dispose?.(this.#R),this.#R.replaceChildren())}#Qe(){if(!this.#Xe())return;let e=this.#pe();for(let t of this.#y.querySelectorAll(`button[data-file]`)){let n=t.dataset.file;t.classList.toggle(`cp-edited`,e[n]!==this.#h[n])}let t=this.#B,n=!this.hasAttribute(`file-actions`)||Object.keys(t??{}).every(t=>Object.hasOwn(e,t));this.#z.hidden=!t||n&&Object.keys(e).every(n=>e[n]===t[n])}#$e(e){this.#m[this.#_]=e,this.#Qe(),this.#et()}#et(e=400){let t=this.getAttribute(`persist`);if(!t)return;this.#k&&clearTimeout(this.#k);let n=JSON.stringify(this.#pe()),r=this.#_e()?JSON.stringify(this.#h):null,i=()=>{r&&z(t,r).catch(()=>{}),F(t,n).catch(()=>{})};e?this.#k=setTimeout(i,e):i()}#tt(){let e=this.getAttribute(`theme`)??`auto`;if(e===`dark`)return!0;if(e===`light`)return!1;let t=s().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.#T?.matches:r}#nt(){return s()[this.#tt()?`dark`:`light`]}#rt(){this.#O??=l(this.#D),!this.#T&&typeof matchMedia==`function`&&(this.#T=matchMedia(`(prefers-color-scheme: dark)`),this.#T.addEventListener(`change`,this.#D)),!this.#E&&typeof MutationObserver==`function`&&typeof document<`u`&&(this.#E=new MutationObserver(this.#D),this.#E.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`,`style`,`data-theme`,`data-color-scheme`,`color-scheme`]}));let e=this.#tt(),t=this.#nt();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}}#it(){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`)}#at(e,t){this.#a.textContent=e,this.#a.dataset.state=t}#ot(){this.#P&&clearTimeout(this.#P),this.#P=null,this.#j=[],this.#F=0,this.#s.replaceChildren(),this.#A=!0}#st(e,t){if(!e)return;let n=t===`cp-err`&&!this.#A?`\n${e}`:e;this.#A=n.endsWith(`
|
|
723
|
-
`),this.#j.push({text:n,className:t}),this.#P??=setTimeout(()=>this.#
|
|
760
|
+
</div>`,this.#e.replaceChildren(t,n),this.#n=n.querySelector(`[data-action="run"]`),this.#r=n.querySelector(`[data-action="stop"]`),this.#i=n.querySelector(`[data-action="reset"]`),this.#a=n.querySelector(`.cp-status`),this.#o=n.querySelector(`.cp-progress`),this.#y=n.querySelector(`.cp-tabs`),this.#t=n.querySelector(`.cp-editor`),this.#c=n.querySelector(`.cp-stdin`),this.#l=n.querySelector(`.cp-stdin textarea`),this.#s=n.querySelector(`.cp-output`),this.#R=n.querySelector(`.cp-preview`),this.#z=n.querySelector(`.cp-stale-note`),this.#K=n.querySelector(`.cp-file-pop`),this.#q=n.querySelector(`.cp-file-message`),!this.#Ze()){let e=document.createElement(`div`);e.className=`cp-output-box`,n.querySelector(`.cp-source`).after(e),e.append(this.#s,this.#z)}this.#c.hidden=!this.hasAttribute(`stdin`),this.#l.addEventListener(`input`,()=>{this.#c.classList.remove(`cp-attention`),this.#$e()}),this.#y.addEventListener(`click`,e=>{let t=e.target,n=t.closest(`[data-file-action]`);if(n){this.#Pe(n);return}let r=t.closest(`[data-more]`);if(r){this.#qe(r,r.dataset.more);return}if(t.closest(`[data-target-root]`)){this.#W=``,this.#he(),this.#y.querySelector(`[data-target-root]`)?.focus();return}let i=t.closest(`button[data-file]`);i&&this.openFile(i.getAttribute(`data-file`));let a=t.closest(`button[data-folder]`)?.dataset.folder;a!==void 0&&(this.#ve()&&(this.#W=a),this.#U.delete(a)||this.#U.add(a),this.#he())}),this.#n.addEventListener(`click`,()=>void this.run()),this.#r.addEventListener(`click`,()=>this.stop()),this.#i.addEventListener(`click`,()=>this.#Xe()),this.#K.addEventListener(`keydown`,e=>{let t={ArrowDown:1,ArrowRight:1,ArrowUp:-1,ArrowLeft:-1}[e.key];if(e.key!==`Escape`&&!t)return;if(e.preventDefault(),!t)return this.#Ge(!0);let n=[...this.#K.querySelectorAll(`button`)];n[(n.indexOf(this.#e.activeElement)+t+n.length)%n.length]?.focus()}),this.#K.addEventListener(`focusout`,e=>{let t=e.relatedTarget;t&&!this.#K.contains(t)&&this.#Ge(!1)}),n.addEventListener(`pointerdown`,e=>{!this.#K.hidden&&!e.composedPath().includes(this.#K)&&this.#Ge(!1)}),n.querySelector(`[data-action="theme"]`).addEventListener(`click`,()=>{c({mode:this.#nt()?`light`:`dark`})}),n.querySelector(`.cp-theme-picker select`).addEventListener(`change`,t=>{let n=t.target.value,r=e.find(e=>e.id===n)?.mode;r&&c({mode:r,[r]:n})}),n.querySelector(`[data-action="file-view"]`).addEventListener(`click`,()=>{this.setAttribute(`file-view`,this.getAttribute(`file-view`)===`tree`?`tabs`:`tree`)}),n.querySelector(`[data-action="window"]`).addEventListener(`click`,()=>this.openWindow()),n.querySelector(`[data-action="show-window"]`).addEventListener(`click`,()=>this.openWindow()),n.querySelector(`[data-action="close-window"]`).addEventListener(`click`,()=>this.closeWindow()),this.#te(n);let r=()=>void this.#re().catch(()=>{});this.#t.addEventListener(`pointerdown`,r,{once:!0}),this.#t.addEventListener(`focusin`,r,{once:!0})}#te(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.#y,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.#Z?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.#Z?i.getBoundingClientRect().height-40:2e3)),()=>e.style.removeProperty(`--cp-preview-height`))}#ne(){this.#Z||this.#w||typeof IntersectionObserver>`u`||(this.#w=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(this.#w?.disconnect(),this.#w=null,this.#re().then(()=>{this.hasAttribute(`autorun`)&&this.run()}).catch(()=>{}))},{rootMargin:`300px`}),this.#w.observe(this))}#re(){return this.#p||=(async()=>{let e=await x(this.language);this.#f=e,!e.ready&&!this.#le&&(this.#o.hidden=!1,this.#ot(`Loading ${e.label}…`,`busy`));try{await e.load(e=>{!this.#b&&!this.#le&&this.#ot(e.message,e.phase===`ready`?`ok`:`busy`)})}catch(e){this.#p=null,this.#ot(`Runtime unavailable`,`error`);let t=e instanceof Error?e.message:String(e);throw this.#ct(t+`
|
|
761
|
+
`,`cp-err`),this.#s.hidden=!1,e}finally{this.#o.hidden=!0}return this.#ie(),this.#C||(this.#C=!0,this.#le||this.#ot(`${e.label} ready`,`ok`),this.#mt(`py-ready`,{language:e.id,label:e.label})),e})(),this.#p}async#ie(){if(!this.#u)return;let e=this.#_,t=await D(e,this.language);if(t){this.#_===e&&this.#u?.setLanguage(t);return}let n=e.includes(`.`)?null:await(this.#f??await x(this.language).catch(()=>null))?.editorLanguage().catch(()=>null);this.#_===e&&this.#u?.setLanguage(n??[])}#ae(){if(this.getAttribute(`height`)!==`auto`||this.#Z)return;let e=this.#e.querySelector(`.cp-root`),t=this.#t.getBoundingClientRect().height;e&&t&&!e.classList.contains(`cp-editor-sized`)&&(e.style.setProperty(`--cp-editor-height`,`${t}px`),e.classList.add(`cp-editor-sized`),this.#g=!0)}#oe(){if(!this.#g)return;this.#g=!1;let e=this.#e.querySelector(`.cp-root`);e?.style.removeProperty(`--cp-editor-height`),e?.classList.remove(`cp-editor-sized`)}#se(){this.#u?.openFile(this.#_,this.#m[this.#_]??``),this.#u?.forgetFiles([]),this.#ce()}#ce(){this.#u?this.#u.setCode(this.#m[this.#_]??``):this.#d?.then(()=>{this.#u?.setCode(this.#m[this.#_]??``),this.#he()})}#le=!1;#ue(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.#st(),this.#s.hidden=!1,this.#ct(r,`cp-err`),this.#le=!0,this.#ot(`Error · entry not found`,`error`);let i={stdout:``,stderr:r,durationMs:0,failed:!0};return this.#mt(`py-error`,{message:r,language:this.language}),this.#mt(`py-output`,{...i,language:this.language}),i}#de(){return this.getAttribute(`entry`)||ie(this.language)}#fe(){let e=Object.keys(this.#m),t=this.getAttribute(`entry`);if(t&&e.includes(t))return t;if(this.#Y&&e.includes(this.#Y))return this.#Y;let n=this.#Ze()&&e.includes(`index.html`)?`index.html`:ie(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}#pe(){let e=this.getAttribute(`open-file`);return e&&e in this.#m?e:this.#fe()}#me(){if(this.#X)return this.#X.widget.#me();let e={...this.#m};if(this.#u)for(let t of Object.keys(e))e[t]=this.#u.fileCode(t,e[t]);return e}#he(){let e=Object.keys(this.#m),t=this.#ve();this.#y.hidden=e.length<2&&!t,this.#e.querySelector(`.cp-root`)?.classList.toggle(`cp-file-actions`,t),this.#ge();let n=t?this.#je():null,r=!this.#y.hidden&&this.getAttribute(`file-view`)===`tree`;if(this.#y.classList.toggle(`cp-tree`,r),this.#e.querySelector(`.cp-root`)?.classList.toggle(`cp-has-tree`,r),this.#y.hidden){this.#y.replaceChildren();return}if(r){this.#_e(e),this.#$e(),t&&this.#Me(n);return}let i=this.#fe();if(this.#y.replaceChildren(...e.map(e=>{if(this.#G?.from===e)return this.#Ae();let n=document.createElement(`button`);n.dataset.file=e;let r=e.lastIndexOf(`/`)+1;if(r){let t=document.createElement(`span`);t.className=`cp-tab-folder`,t.textContent=e.slice(0,r),n.setAttribute(`aria-label`,e),n.append(t)}return n.append(e.slice(r)),n.setAttribute(`aria-pressed`,String(e===this.#_)),e===i&&(n.classList.add(`cp-entry`),n.title=`entry point — this is the file Run executes`),t?this.#ke(n,e):n})),t){if(this.#G&&this.#G.kind!==`rename`)this.#y.append(this.#Ae());else{let e=this.#Oe(`new-file`,`New file`,`+`);e.classList.add(`cp-file-new`),this.#y.append(e)}}this.#$e(),t&&this.#Me(n)}#ge(){let e=this.#e.querySelector(`[data-action="file-view"]`);if(!e)return;e.hidden=!this.hasAttribute(`file-view-switch`)||this.#y.hidden;let t=this.getAttribute(`file-view`)===`tree`,n=t?`Show files as tabs`:`Show files as a tree`;e.setAttribute(`aria-label`,n),e.title=n,e.innerHTML=t?K:G}#_e(e){let t=this.#fe(),n=this.#ve(),r=[],i=this.#G,a=i?.folder?[...e,`${i.folder}/`]:e;if(n){let e=document.createElement(`div`);e.className=`cp-tree-head`;let t=document.createElement(`button`);t.type=`button`,t.className=`cp-tree-root`,t.dataset.targetRoot=``,t.textContent=`Files`,t.title=`Add new files and folders at the top level`,this.#W===``&&t.setAttribute(`aria-current`,`true`);let n=this.#Fe(),i=n?`in ${n}`:`at the top level`,a=this.#Oe(`new-file`,`New file`,q);a.title=`New file ${i}`;let o=this.#Oe(`new-folder`,`New folder`,J);o.title=`New folder ${i}`,e.append(t,a,o),r.push(e)}let o=(e,s)=>{let c=a.filter(t=>t.startsWith(e)).map(t=>t.slice(e.length));i&&i.kind!==`rename`&&`${i.folder}/`===(e||`/`)&&r.push(this.#Ae(s));let l=[...new Set(c.filter(e=>e.includes(`/`)).map(e=>e.slice(0,e.indexOf(`/`))))].sort();for(let t of l){let i=e+t,a=!this.#U.has(i),c=document.createElement(`button`);if(c.className=`cp-tree-folder`,c.dataset.folder=i,c.textContent=t,c.setAttribute(`aria-expanded`,String(a)),n&&this.#W===i&&c.setAttribute(`aria-current`,`true`),c.style.setProperty(`--cp-depth`,String(s)),n){let e=this.#Oe(`new-file`,`New file in ${i}`,`+`);e.dataset.in=i;let t=document.createElement(`div`);t.className=`cp-file-row`,t.append(c,e),r.push(t)}else r.push(c);a&&o(`${i}/`,s+1)}for(let a of c.filter(e=>e&&!e.includes(`/`)).sort()){let o=e+a;if(i?.from===o){r.push(this.#Ae(s));continue}let c=document.createElement(`button`);c.dataset.file=o,c.textContent=a,c.setAttribute(`aria-label`,o),c.setAttribute(`aria-pressed`,String(o===this.#_)),c.style.setProperty(`--cp-depth`,String(s)),o===t&&(c.classList.add(`cp-entry`),c.title=`entry point — this is the file Run executes`),r.push(n?this.#ke(c,o):c)}};o(``,0),this.#y.replaceChildren(...r)}#ve(){return this.hasAttribute(`file-actions`)&&!this.hasAttribute(`readonly`)}#ye(){if(!this.#I)throw Error(`Add the widget to the page before changing its files.`)}#be(e,t){let n=X(e);if(n)return n;let r=Object.keys(this.#m).filter(e=>e!==t);if(r.includes(e))return`A file named "${e}" already exists.`;if(r.some(t=>t.startsWith(`${e}/`)))return`"${e}" is a folder.`;let i=r.find(t=>e.startsWith(`${t}/`));return i?`"${i}" is a file, so it can't hold other files.`:null}#xe(e){return e===this.#fe()?`it's the entry file`:this.#Se().has(e)?`this ${this.language} project needs it`:null}#Se(){let e=/* @__PURE__ */ new Set,t=Object.keys(this.#m);if(this.language===`next`)for(let n of t)/^(src\/)?app\/layout\.(jsx?|tsx?)$/.test(n)&&e.add(n);if(this.language!==`react`)return e;for(let n of[`src/main.jsx`,`src/main.js`])t.includes(n)&&e.add(n);let n=this.#me()[`index.html`];if(n===void 0)return e;e.add(`index.html`);let r=new DOMParser().parseFromString(n,`text/html`);for(let n of r.querySelectorAll(`script[src], link[rel="stylesheet"][href]`)){let r=(n.getAttribute(`src`)??n.getAttribute(`href`)).replace(/^\.?\//,``);t.includes(r)&&e.add(r)}return e}#Ce(e){let t=this.#fe();e(),this.#fe()!==t&&Object.hasOwn(this.#m,t)&&(this.#Y=t)}#we(e){for(let t=e.indexOf(`/`);t!==-1;t=e.indexOf(`/`,t+1))this.#U.delete(e.slice(0,t))}#Te(e){let t=[...this.#y.querySelectorAll(`button[data-file]`)].map(e=>e.dataset.file),n=t.indexOf(e);return(n===-1?void 0:t[n+1]??t[n-1])??Object.keys(this.#m).find(t=>t!==e)}#Ee(e,t,n){this.#tt(0),this.#ht(`playpad-files-change`,{action:e,name:t,...n?{previousName:n}:{},files:this.#me()})}async#De(e){let t=await B(e).catch(()=>null);if(!t)return null;try{return JSON.parse(t)}catch{return null}}#Oe(e,t,n){let r=document.createElement(`button`);return r.type=`button`,r.className=`cp-file-tool`,r.dataset.fileAction=e,r.setAttribute(`aria-label`,t),r.title=t,r.innerHTML=n,r}#ke(e,t){let n=document.createElement(`div`);if(n.className=`cp-file-row`,n.append(e),this.#xe(t))return n;let r=document.createElement(`button`);return r.type=`button`,r.className=`cp-file-tool cp-file-more`,r.dataset.more=t,r.textContent=`⋯`,r.setAttribute(`aria-label`,`Actions for ${t}`),r.setAttribute(`aria-expanded`,`false`),r.title=`Rename or remove`,n.append(r),n}#Ae(e=0){let t=this.#G,n=document.createElement(`form`);n.className=`cp-file-field`,n.style.setProperty(`--cp-depth`,String(e));let r=document.createElement(`input`);r.type=`text`,r.value=t.value,r.autocapitalize=`off`,r.autocomplete=`off`,r.spellcheck=!1,r.placeholder=t.kind===`folder`?`components`:`TaskLine.jsx`;let i=t.folder?` in ${t.folder}`:``;r.setAttribute(`aria-label`,t.kind===`rename`?`New name for ${t.from}`:t.kind===`folder`?`Name of the new folder${i}`:`Name of the new file${i}`),r.addEventListener(`input`,()=>{t.value=r.value,this.#Ve(``)}),r.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e.preventDefault(),this.#ze())});let a=document.createElement(`button`);return a.type=`button`,a.className=`cp-file-tool`,a.dataset.fileAction=`cancel`,a.textContent=`×`,a.setAttribute(`aria-label`,`Cancel`),n.addEventListener(`submit`,e=>{e.preventDefault(),this.#Be()}),n.append(r,a),n}#je(){let e=this.#e.activeElement;if(!e||!this.#y.contains(e))return null;if(e.closest(`.cp-file-field`))return{field:!0};let{file:t,folder:n,more:r}=e.dataset;return{file:t,folder:n,more:r}}#Me(e){let t=this.#y.querySelector(`.cp-file-field input`);if(t&&this.#G?.fresh){this.#G.fresh=!1,t.focus();let e=this.#G.kind===`rename`?t.value.lastIndexOf(`.`):-1;e>0?t.setSelectionRange(t.value.lastIndexOf(`/`)+1,e):t.setSelectionRange(t.value.length,t.value.length)}else e?.field?t?.focus():e&&this.#Ne(e)?.focus();let n=this.#y.querySelector(`button[aria-pressed="true"]`);if(n&&!t){let e=this.#y.getBoundingClientRect(),t=n.getBoundingClientRect();t.left<e.left?this.#y.scrollLeft-=e.left-t.left:t.right>e.right-32&&(this.#y.scrollLeft+=t.right-e.right+32),t.top<e.top?this.#y.scrollTop-=e.top-t.top:t.bottom>e.bottom&&(this.#y.scrollTop+=t.bottom-e.bottom)}}#Ne(e){return[...this.#y.querySelectorAll(`button`)].find(({dataset:t})=>e.file!==void 0&&t.file===e.file||e.folder!==void 0&&t.folder===e.folder||e.more!==void 0&&t.more===e.more)}#Pe(e){let t=e.dataset.fileAction;if(t===`cancel`)return this.#ze();let n=this.getAttribute(`file-view`)===`tree`,r=e.dataset.in??this.#Fe();this.#we(`${r}/`),this.#Ie(t===`new-folder`?{kind:`folder`,folder:r,value:``,fresh:!0}:n?{kind:`file`,folder:r,value:``,fresh:!0}:{kind:`file`,folder:``,value:r&&`${r}/`,fresh:!0})}#Fe(){let e=this.#W;return e===``||e&&Object.keys(this.#m).some(t=>t.startsWith(`${e}/`))?e:this.#_.includes(`/`)?this.#_.slice(0,this.#_.lastIndexOf(`/`)):``}#Ie(e){this.#Ge(!1),this.#Ve(``),this.#G=e,this.#he()}#Le(e){let t=this.getAttribute(`file-view`)===`tree`?e.lastIndexOf(`/`):-1;this.#Ie({kind:`rename`,from:e,folder:t===-1?``:e.slice(0,t),value:e.slice(t+1),fresh:!0})}#Re(){this.#G=null,this.#W=null,this.#K&&(this.#K.hidden=!0,this.#Ve(``))}#ze(){let e=this.#G?.from;this.#G=null,this.#Ve(``),this.#he(),(e&&this.#Ne({more:e})||this.#Ne({file:this.#_}))?.focus()}#Be(){let e=this.#G;if(!e)return;let t=e.value.trim(),n=this.getAttribute(`file-view`)===`tree`;if(e.kind===`folder`||e.kind===`file`&&t.endsWith(`/`)){if(!n)return this.#Ve(`Add a file name after the folder.`,!0);if(!t)return this.#Ve(`A folder needs a name.`,!0);let r=Y(e.folder,t.replace(/\/$/,``)),i=Object.keys(this.#m).some(e=>e.startsWith(`${r}/`))?null:this.#be(r);return i?this.#Ve(i,!0):(this.#we(`${r}/`),this.#Ie({kind:`file`,folder:r,value:``,fresh:!0}))}if(!t)return this.#Ve(`A file needs a name.`,!0);let r=Y(e.folder,t);if(e.kind===`rename`&&r===e.from)return this.#ze();if(Object.hasOwn(this.#m,r))return this.#G=null,this.openFile(r),this.#u?.focus(),this.#Ve(`"${r}" already exists, so it's open now.`,!1,4e3);let i=this.#be(r,e.from);if(i)return this.#Ve(i,!0);if(this.#G=null,this.#Ve(``),e.kind===`rename`){let t=this.#_===e.from;this.renameFile(e.from,r),t?this.#u?.focus():this.#Ne({file:r})?.focus()}else this.addFile(r),this.#u?.focus()}#Ve(e,t=!1,n=0){this.#J&&clearTimeout(this.#J),this.#J=n?setTimeout(()=>this.#Ve(``),n):null,this.#q.textContent=e,this.#q.hidden=!e,this.#q.classList.toggle(`cp-file-refused`,t),this.#y.querySelector(`.cp-file-field input`)?.setAttribute(`aria-invalid`,String(!!e&&t)),e&&this.#He(this.#q,t&&this.#y.querySelector(`.cp-file-field`)||this.#y)}#He(e,t){e.hidden=!1;let n=e.parentElement.getBoundingClientRect(),r=t.getBoundingClientRect();e.style.top=`${Math.max(0,Math.min(r.bottom-n.top+2,n.height-e.offsetHeight))}px`,e.style.left=`${Math.max(0,Math.min(r.left-n.left,n.width-e.offsetWidth))}px`}#Ue=null;#We(e,t){this.#Ge(!1),this.#Ue=e,this.#K.replaceChildren(...t),this.#He(this.#K,e),this.#K.querySelector(`button`)?.focus()}#Ge(e){this.#K&&!this.#K.hidden&&(this.#K.hidden=!0,this.#K.replaceChildren(),this.#K.removeAttribute(`role`),this.#K.removeAttribute(`aria-label`),this.#Ue?.setAttribute(`aria-expanded`,`false`),e&&this.#Ue?.focus(),this.#Ue=null)}#Ke(e,t,n=``){let r=document.createElement(`button`);return r.type=`button`,r.textContent=e,r.className=n,r.addEventListener(`click`,t),r}#qe(e,t){let n=()=>{this.#me()[t]?.trim()?this.#Je(e,`Remove ${t}? Its code will be lost.`,`Remove`,()=>this.#Ye(t)):this.#Ye(t)},r=this.#Ke(`Rename`,()=>{this.#Ge(!1),this.#Le(t)});this.#We(e,[r,this.#Ke(`Remove`,n)]),e.setAttribute(`aria-expanded`,`true`)}#Je(e,t,n,r){let i=document.createElement(`p`);i.textContent=t;let a=document.createElement(`div`);a.className=`cp-file-pop-buttons`,a.append(this.#Ke(`Cancel`,()=>this.#Ge(!0)),this.#Ke(n,()=>{this.#Ge(!1),r()},`cp-danger`)),this.#We(e,[i,a]),this.#K.setAttribute(`role`,`alertdialog`),this.#K.setAttribute(`aria-label`,t)}#Ye(e){this.#Ge(!1);let t=this.#Te(e);this.removeFile(e),this.#Ne({file:t})?.focus()}#Xe(){let e=Object.keys(this.#m),t=Object.keys(this.#h),n=e.length===t.length&&e.every(e=>Object.hasOwn(this.#h,e));if(!this.#ve()||n)return this.reset();this.#Je(this.#i,`Reset the project? Files you added go away, and files you removed come back.`,`Reset`,()=>{this.reset(),this.#i.focus()})}#Ze(){return this.language===`react`||this.language===`next`}#Qe(){this.#R&&(this.#f?.dispose?.(this.#R),this.#R.replaceChildren())}#$e(){if(!this.#z)return;let e=this.getAttribute(`change-marks`)!==`off`,t=this.#me(),n=this.#B,r=n??this.#h;for(let n of this.#y.querySelectorAll(`button[data-file]`)){let i=n.dataset.file;n.classList.toggle(`cp-unrun`,e&&t[i]!==r[i]),n.classList.toggle(`cp-edited`,e&&t[i]!==this.#h[i])}let i=Object.keys(t),a=i.length!==Object.keys(r).length||i.some(e=>t[e]!==r[e])||n!==null&&this.#l.value!==this.#V,o=e&&a;this.#n.classList.toggle(`cp-unrun`,o),o?this.#n.title=`Run to see your changes (${/Mac|iPhone|iPad/.test(navigator.platform)?`⌘`:`Ctrl`}+Enter)`:this.#n.removeAttribute(`title`);let s=o&&n!==null?`Code changed since this run`:``;this.#z.textContent!==s&&(this.#z.hidden=!s,this.#z.textContent=s)}#et(e){this.#m[this.#_]=e,this.#$e(),this.#tt()}#tt(e=400){let t=this.getAttribute(`persist`);if(!t)return;this.#k&&clearTimeout(this.#k);let n=JSON.stringify(this.#me()),r=this.#ve()?JSON.stringify(this.#h):null,i=()=>{r&&z(t,r).catch(()=>{}),F(t,n).catch(()=>{})};e?this.#k=setTimeout(i,e):i()}#nt(){let e=this.getAttribute(`theme`)??`auto`;if(e===`dark`)return!0;if(e===`light`)return!1;let t=s().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.#T?.matches:r}#rt(){return s()[this.#nt()?`dark`:`light`]}#it(){this.#O??=l(this.#D),!this.#T&&typeof matchMedia==`function`&&(this.#T=matchMedia(`(prefers-color-scheme: dark)`),this.#T.addEventListener(`change`,this.#D)),!this.#E&&typeof MutationObserver==`function`&&typeof document<`u`&&(this.#E=new MutationObserver(this.#D),this.#E.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`,`style`,`data-theme`,`data-color-scheme`,`color-scheme`]}));let e=this.#nt(),t=this.#rt();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}}#at(){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`)}#ot(e,t){this.#a.textContent=e,this.#a.dataset.state=t}#st(){this.#P&&clearTimeout(this.#P),this.#P=null,this.#j=[],this.#F=0,this.#s.replaceChildren(),this.#A=!0}#ct(e,t){if(!e)return;let n=t===`cp-err`&&!this.#A?`\n${e}`:e;this.#A=n.endsWith(`
|
|
762
|
+
`),this.#j.push({text:n,className:t}),this.#P??=setTimeout(()=>this.#lt(),16)}#lt(){if(this.#P&&clearTimeout(this.#P),this.#P=null,!this.#j.length)return;let e=this.#j;this.#j=[];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.#F>=Q)break;let e=t.text;this.#F+e.length>Q&&(e=e.slice(0,Q-this.#F)+`
|
|
724
763
|
… output truncated for display — the full text is in the playpad-output event
|
|
725
|
-
`),this.#F+=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}#
|
|
726
|
-
`,`cp-in`):this.#
|
|
727
|
-
`,`cp-in`),this.#
|
|
764
|
+
`),this.#F+=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}#ut(){return this.#lt(),this.#dt(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.#M===e&&(this.#M=null,this.#N=null,t.remove(),n===null?this.#ct(`
|
|
765
|
+
`,`cp-in`):this.#ct(n+`
|
|
766
|
+
`,`cp-in`),this.#lt(),e(n))};t.addEventListener(`submit`,e=>{e.preventDefault(),a(n.value)}),i.addEventListener(`click`,()=>a(null)),n.addEventListener(`keydown`,e=>{(e.key===`Escape`||e.key===`d`&&e.ctrlKey)&&(e.preventDefault(),a(null))}),t.append(n,r,i),this.#s.hidden=!1,this.#s.appendChild(t),this.#s.scrollTop=this.#s.scrollHeight,this.#M=e,this.#N=a,n.focus({preventScroll:!0})})}#dt(e){this.#N?.(e),this.#N=null,this.#M=null}#ft(e,t){this.#lt();let n=document.createElement(`div`);n.className=`cp-hint`,n.textContent=e,this.#s.hidden=!1,this.#s.appendChild(n),this.#s.scrollTop=this.#s.scrollHeight,t&&(this.#c.hidden=!1,this.#c.classList.add(`cp-attention`))}#pt(e){this.#lt();let t=document.createElement(`table`);t.className=`cp-table`;let n=t.createTHead().insertRow();for(let t of e.columns){let e=document.createElement(`th`);e.textContent=t,n.appendChild(e)}let r=t.createTBody();for(let t of e.rows){let e=r.insertRow();for(let n of t)e.insertCell().textContent=n==null?``:String(n)}this.#s.hidden=!1,this.#s.appendChild(t)}#mt(e,t){this.#ht(e,t),this.#ht(`playpad-${e.slice(3)}`,t)}#ht(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0})),this.#Z?.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}};function de(e=W){typeof window<`u`&&typeof customElements<`u`&&(customElements.get(e)||customElements.define(e,ue))}de();export{s as _,H as a,V as c,te as d,x as f,e as g,d as h,L as i,C as l,y as m,de as n,I as o,b as p,U as r,F as s,ue as t,S as u,l as v,c as y};
|
package/dist/element.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{t as CodePlayPadElement,n as defineCodePlayPad}from"./element-
|
|
1
|
+
export{t as CodePlayPadElement,n as defineCodePlayPad}from"./element-Ce06T38j.js";
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,m as c,n as l,o as u,p as d,r as f,s as p,t as m,u as h,v as g,y as _}from"./element-
|
|
1
|
+
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,m as c,n as l,o as u,p as d,r as f,s as p,t as m,u as h,v as g,y as _}from"./element-Ce06T38j.js";import{t as v}from"./react-version.generated-BNNJmf7J.js";import{a as y,f as b,i as x,n as S,o as C,r as w,t as T}from"./config-3Z6xX6Jr.js";export{m as CodePlayPadElement,a as EDITOR_THEMES,T as PYODIDE_VERSION,v as REACT_VERSION,h as RunStopped,r as WorkerUnavailable,f as allProgress,s as clearSnippet,S as configureCSharp,w as configureCpp,x as configurePython,y as configureReact,C as configureTypeScript,o as createEditor,l as defineCodePlayPad,t as getProgress,i as getRuntime,e as getThemePreference,d as listRuntimes,u as loadSnippet,g as onThemePreferenceChange,b as pyodideAssetUrls,c as registerRuntime,p as saveSnippet,n as setProgress,_ as setThemePreference};
|