code-playpad 0.10.1 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +222 -17
  2. package/dist/THIRD-PARTY-NOTICES.txt +223 -0
  3. package/dist/cdn.js +2 -2
  4. package/dist/compiler-B408qd3N.js +151 -0
  5. package/dist/{config-CT3H6Oum.js → config-DB58UVsk.js} +1 -1
  6. package/dist/{cpp-Cs32J8JC.js → cpp-Bhr_Zgfk.js} +1 -1
  7. package/dist/{cpp-CO2abWii.js → cpp-xLJOrOXX.js} +1 -1
  8. package/dist/dist-3xj9-ylK.js +6 -0
  9. package/dist/{dist-BIgiGgKu.js → dist-7CHy0evE.js} +1 -1
  10. package/dist/dist-BDifu2bQ.js +6 -0
  11. package/dist/dist-BwlTZqCY.js +28 -0
  12. package/dist/dist-C41hAfPr.js +6 -0
  13. package/dist/dist-CRXZcpYD.js +14 -0
  14. package/dist/dist-CTLX4tws.js +8 -0
  15. package/dist/dist-CjnVq6q1.js +10 -0
  16. package/dist/{dist-Vr-fb58P.js → dist-D4P7t1AU.js} +4 -4
  17. package/dist/dist-DHeVjdBc.js +6 -0
  18. package/dist/dist-IFh_mUXG.js +7 -0
  19. package/dist/dist-UbI3_a5S.js +6 -0
  20. package/dist/dist-_fde-E8H.js +6 -0
  21. package/dist/dist-g8djAEMH.js +6 -0
  22. package/dist/dist-ixcYRC9x.js +6 -0
  23. package/dist/editor.d.ts +3 -1
  24. package/dist/element-Dzhksh6_.js +596 -0
  25. package/dist/element.d.ts +26 -0
  26. package/dist/element.js +1 -1
  27. package/dist/hints-DpBIeoeG.js +6 -0
  28. package/dist/index.d.ts +5 -3
  29. package/dist/index.js +1 -1
  30. package/dist/{java-8qjVCjsN.js → java-DFiOVxDN.js} +1 -1
  31. package/dist/{java-DeBiVPXO.js → java-DjuG1fCk.js} +1 -1
  32. package/dist/{javascript-DLPaJJzf.js → javascript-BBiCDtZ3.js} +2 -2
  33. package/dist/{javascript-B1tVx7AD.js → javascript-CLaHCZ8o.js} +1 -1
  34. package/dist/languages.d.ts +1 -1
  35. package/dist/{pyodide-C8ImkXdD.js → pyodide-Cs-Kwccb.js} +1 -1
  36. package/dist/{pyodide-BOoYEfX1.js → pyodide-QurAOd7j.js} +2 -2
  37. package/dist/react-ALhWeEZ5.js +9 -0
  38. package/dist/react-DmuIc3qw.js +4 -0
  39. package/dist/react-runtime-19.2.8.js +240 -0
  40. package/dist/react-vendor.generated-DMxIoCMn.js +6 -0
  41. package/dist/react-version.generated-BNNJmf7J.js +6 -0
  42. package/dist/react.d.ts +9 -1
  43. package/dist/react.js +1 -1
  44. package/dist/rolldown-runtime-DK3Fl9T5.js +6 -0
  45. package/dist/runtime/config.d.ts +15 -1
  46. package/dist/runtime/react/boot.d.ts +9 -0
  47. package/dist/runtime/react/compiler.d.ts +30 -0
  48. package/dist/runtime/react-vendor.generated.d.ts +5 -0
  49. package/dist/runtime/react-version.generated.d.ts +3 -0
  50. package/dist/runtime/react.d.ts +2 -0
  51. package/dist/standalone.js +289 -17
  52. package/dist/styles.d.ts +0 -2
  53. package/dist/theme.d.ts +48 -0
  54. package/dist/{hints-CCMgezw9.js → types-CfcYqU2K.js} +1 -1
  55. package/dist/types.d.ts +23 -0
  56. package/dist/worker-runtime-DvpugeXD.js +9 -0
  57. package/dist/{worker-runtime-sUPz1J56.js → worker-runtime-tSXm-pPB.js} +1 -1
  58. package/package.json +23 -6
  59. package/dist/dist--J_vhCIU.js +0 -14
  60. package/dist/dist-BNvM_BAY.js +0 -6
  61. package/dist/dist-BkpKCrXQ.js +0 -6
  62. package/dist/dist-CJxiVI4a.js +0 -6
  63. package/dist/dist-CNOK8CHE.js +0 -6
  64. package/dist/dist-D25hs99E.js +0 -10
  65. package/dist/dist-D2igTc4m.js +0 -6
  66. package/dist/dist-D7jBL3Ib.js +0 -28
  67. package/dist/dist-DXjodKfp.js +0 -6
  68. package/dist/dist-DfFrsBkU.js +0 -8
  69. package/dist/element-CQGYVEF7.js +0 -324
  70. package/dist/worker-runtime-DfYet3xy.js +0 -9
@@ -0,0 +1,596 @@
1
+ var e=[{id:`default-dark`,label:`One Dark`,mode:`dark`},{id:`monokai`,label:`Monokai`,mode:`dark`,colors:{bg:`#272822`,fg:`#f8f8f2`,muted:`#b4b19c`,surface:`#1e1f1a`,border:`#49483e`,accent:`#a6e22e`,accentFg:`#1e1f1a`,danger:`#ff6188`,ok:`#a6e22e`,selection:`#49483e`,activeLine:`#3e3d3266`,comment:`#a09b80`,keyword:`#ff5c94`,string:`#e6db74`,number:`#ae81ff`,fn:`#a6e22e`,type:`#66d9ef`,variable:`#f8f8f2`}},{id:`dracula`,label:`Dracula`,mode:`dark`,colors:{bg:`#282a36`,fg:`#f8f8f2`,muted:`#b6bcd6`,surface:`#21222c`,border:`#44475a`,accent:`#bd93f9`,accentFg:`#21222c`,danger:`#ff5555`,ok:`#50fa7b`,selection:`#44475a`,activeLine:`#44475a55`,comment:`#9aa5ce`,keyword:`#ff79c6`,string:`#f1fa8c`,number:`#bd93f9`,fn:`#50fa7b`,type:`#8be9fd`,variable:`#f8f8f2`}},{id:`nord`,label:`Nord`,mode:`dark`,colors:{bg:`#2e3440`,fg:`#d8dee9`,muted:`#b0b9c9`,surface:`#272c36`,border:`#434c5e`,accent:`#88c0d0`,accentFg:`#272c36`,danger:`#e08a91`,ok:`#a3be8c`,selection:`#434c5e`,activeLine:`#3b425266`,comment:`#a0abbf`,keyword:`#81a1c1`,string:`#a3be8c`,number:`#bd98b6`,fn:`#88c0d0`,type:`#8fbcbb`,variable:`#d8dee9`}},{id:`solarized-dark`,label:`Solarized Dark`,mode:`dark`,colors:{bg:`#002b36`,fg:`#c5d3d3`,muted:`#9fb0b0`,surface:`#00222b`,border:`#17505e`,accent:`#2aa198`,accentFg:`#00222b`,danger:`#f0746f`,ok:`#a3b300`,selection:`#17505e`,activeLine:`#073642aa`,comment:`#8fa3a8`,keyword:`#a3b300`,string:`#2aa198`,number:`#e87f7c`,fn:`#4ba3e3`,type:`#d6a100`,variable:`#c5d3d3`}},{id:`default-light`,label:`Default Light`,mode:`light`},{id:`github-light`,label:`GitHub Light`,mode:`light`,colors:{bg:`#ffffff`,fg:`#24292f`,muted:`#59636e`,surface:`#f6f8fa`,border:`#d1d9e0`,accent:`#0969da`,accentFg:`#ffffff`,danger:`#cf222e`,ok:`#1a7f37`,selection:`#b6d7ff`,activeLine:`#eaeef266`,comment:`#59636e`,keyword:`#cf222e`,string:`#0a3069`,number:`#0550ae`,fn:`#8250df`,type:`#953800`,variable:`#24292f`}},{id:`solarized-light`,label:`Solarized Light`,mode:`light`,colors:{bg:`#fdf6e3`,fg:`#47565c`,muted:`#566569`,surface:`#eee8d5`,border:`#d6cfb8`,accent:`#1f6fa8`,accentFg:`#ffffff`,danger:`#c0302c`,ok:`#5f6f00`,selection:`#e3dcc4`,activeLine:`#eee8d588`,comment:`#5c6c70`,keyword:`#5f6f00`,string:`#1a7a73`,number:`#c0302c`,fn:`#1f6fa8`,type:`#8f6a00`,variable:`#47565c`}}],t=`code-playpad:theme`,n=`playpad-theme-change`,r={mode:null,light:`default-light`,dark:`default-dark`},i=null,a=!1;function o(t,n){return e.some(e=>e.id===t&&e.mode===n)?t:r[n]}function s(){let e=i;if(!e)try{e=JSON.parse(localStorage.getItem(t)??`null`)}catch{}return{mode:e?.mode===`light`||e?.mode===`dark`?e.mode:null,light:o(e?.light,`light`),dark:o(e?.dark,`dark`)}}function c(e){let r={...s(),...e};r.light=o(r.light,`light`),r.dark=o(r.dark,`dark`);try{localStorage.setItem(t,JSON.stringify(r)),i=null}catch{i=r}return window.dispatchEvent(new CustomEvent(n,{detail:r})),r}function l(e){a||(a=!0,window.addEventListener(`storage`,e=>{(e.key===t||e.key===null)&&window.dispatchEvent(new CustomEvent(n,{detail:s()}))}));let r=t=>e(t.detail);return window.addEventListener(n,r),()=>window.removeEventListener(n,r)}function u(){return e.flatMap(({id:e,mode:t,colors:n})=>n?[`:host([data-editor-theme="${e}"]) {
2
+ --cp-bg: ${n.bg};
3
+ --cp-fg: ${n.fg};
4
+ --cp-muted: ${n.muted};
5
+ --cp-border: ${n.border};
6
+ --cp-surface: ${n.surface};
7
+ --cp-accent: ${n.accent};
8
+ --cp-accent-fg: ${n.accentFg};
9
+ --cp-danger: ${n.danger};
10
+ --cp-ok: ${n.ok};
11
+ color-scheme: ${t};
12
+ }`]:[]).join(`
13
+ `)}async function d(e){try{return await g(e)}catch(t){return console.warn(`[code-playpad] CodeMirror unavailable, using plain textarea:`,t),_(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 g(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:g,highlightSpecialChars:_,drawSelection:v,rectangularSelection:y,crosshairCursor:b}=n,{EditorState:x,Compartment:S}=r,{defaultKeymap:C,history:w,historyKeymap:T,indentWithTab:E}=i,{syntaxHighlighting:D,defaultHighlightStyle:O,HighlightStyle:k,indentOnInput:A,bracketMatching:j,foldGutter:M,foldKeymap:N}=a,{autocompletion:P,closeBrackets:F,closeBracketsKeymap:I,completionKeymap:L}=o,R=new S,z=new S,B=new S,V=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`}}),D(O,{fallback:!0})];f.set(`default-light`,V);let{tags:H}=c,U=(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}),D(k.define([{tag:[H.comment,H.meta],color:e.comment,fontStyle:`italic`},{tag:[H.keyword,H.operatorKeyword,H.modifier],color:e.keyword},{tag:[H.string,H.special(H.string),H.regexp],color:e.string},{tag:[H.number,H.bool,H.null,H.atom],color:e.number},{tag:[H.function(H.variableName),H.function(H.propertyName),H.definition(H.function(H.variableName))],color:e.fn},{tag:[H.typeName,H.className,H.namespace,H.tagName],color:e.type},{tag:[H.variableName,H.propertyName,H.attributeName],color:e.variable},{tag:H.invalid,color:e.keyword,textDecoration:`underline`}]))],W=(t,n)=>{let r=e.find(e=>e.id===n);if(!r?.colors)return t?s.oneDark:V;let i=f.get(r.id);return i||(i=U(r.colors,r.mode===`dark`),f.set(r.id,i)),i},G=u.of([{key:`Mod-Enter`,preventDefault:!0,run:()=>(t.onRun?.(),!0)},{key:`Shift-Enter`,preventDefault:!0,run:()=>(t.onRun?.(),!0)}]),K=t.dark,q=t.themeId,J=t.readOnly,Y=t.language??[],X=e=>x.create({doc:e,extensions:[d(),g(),_(),w(),M(),v(),x.allowMultipleSelections.of(!0),A(),j(),F(),P(),y(),b(),m(),G,u.of([...I,...C,...T,...N,...L,E]),l.lineWrapping,B.of(Y),R.of(W(K,q)),z.of(x.readOnly.of(J)),l.updateListener.of(e=>{e.startState.facet(l.styleModule)!==e.state.facet(l.styleModule)&&h(),e.docChanged&&t.onChange?.(e.state.doc.toString())})]}),Z=new l({parent:t.parent,state:X(t.doc)});p.add(Z.root),h();let Q=/* @__PURE__ */ new Map,$=t.name??``;return{fallback:!1,getCode:()=>Z.state.doc.toString(),setCode(e){Z.dispatch({changes:{from:0,to:Z.state.doc.length,insert:e}})},openFile(e,t){if(e===$)return;Q.set($,Z.state);let n=Q.get(e);Z.setState(n??X(t)),$=e,n&&Z.dispatch({effects:[R.reconfigure(W(K,q)),z.reconfigure(x.readOnly.of(J)),B.reconfigure(Y)]}),h()},fileCode(e,t){if(e===$)return Z.state.doc.toString();let n=Q.get(e);return n?n.doc.toString():t},forgetFiles(e){for(let t of[...Q.keys()])e.includes(t)||Q.delete(t)},setTheme(e,t){K=e,q=t,Z.dispatch({effects:R.reconfigure(W(K,q))})},setReadOnly(e){J=e,Z.dispatch({effects:z.reconfigure(x.readOnly.of(J))})},setLanguage(e){Y=e,Z.dispatch({effects:B.reconfigure(Y)})},focus:()=>Z.focus(),destroy(){p.delete(Z.root),Z.destroy()}}}function _(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 v=/* @__PURE__ */ new Map,y=/* @__PURE__ */ new Map;function b(e,t){v.set(e,t)}function x(){return[...v.keys()]}function S(e){let t=y.get(e);if(t)return t;let n=v.get(e);if(!n)return Promise.reject(/* @__PURE__ */ Error(`Unknown runtime "${e}". Registered: ${x().join(`, `)||`none`}`));let r=n().catch(t=>{throw y.delete(e),t});return y.set(e,r),r}b(`python`,()=>import(`./pyodide-Cs-Kwccb.js`).then(e=>e.pythonRuntime)),b(`javascript`,()=>import(`./javascript-CLaHCZ8o.js`).then(e=>e.javascriptRuntime)),b(`typescript`,()=>import(`./javascript-CLaHCZ8o.js`).then(e=>e.typescriptRuntime)),b(`java`,()=>import(`./java-DFiOVxDN.js`).then(e=>e.javaRuntime)),b(`c`,()=>import(`./cpp-xLJOrOXX.js`).then(e=>e.cRuntime)),b(`cpp`,()=>import(`./cpp-xLJOrOXX.js`).then(e=>e.cppRuntime)),b(`react`,()=>import(`./react-DmuIc3qw.js`).then(e=>e.reactRuntime));var C=class extends Error{constructor(e=`Execution stopped`){super(e),this.name=`RunStopped`}},w=class extends Error{constructor(e=`Web Workers are unavailable in this page`){super(e),this.name=`WorkerUnavailable`}},T=/* @__PURE__ */ new WeakSet,E=String.raw`
14
+ :host {
15
+ --cp-bg: #ffffff;
16
+ --cp-fg: #1f2328;
17
+ --cp-muted: #656d76;
18
+ --cp-border: #d0d7de;
19
+ --cp-surface: #f6f8fa;
20
+ --cp-accent: #1f6feb;
21
+ --cp-accent-fg: #ffffff;
22
+ --cp-danger: #cf222e;
23
+ --cp-ok: #1a7f37;
24
+ --cp-radius: 8px;
25
+ --cp-font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
26
+ --cp-font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
27
+
28
+ display: block;
29
+ margin: 1rem 0;
30
+ color-scheme: light;
31
+ contain: content;
32
+ }
33
+
34
+ :host([hidden]) { display: none; }
35
+
36
+ :host([data-resolved-theme="dark"]) {
37
+ --cp-bg: #0d1117;
38
+ --cp-fg: #e6edf3;
39
+ --cp-muted: #8b949e;
40
+ --cp-border: #30363d;
41
+ --cp-surface: #161b22;
42
+ --cp-accent: #388bfd;
43
+ --cp-danger: #ff7b72;
44
+ --cp-ok: #3fb950;
45
+ color-scheme: dark;
46
+ }
47
+
48
+ ${u()}
49
+
50
+ * { box-sizing: border-box; }
51
+
52
+ .cp-root {
53
+ border: 1px solid var(--cp-border);
54
+ border-radius: var(--cp-radius);
55
+ background: var(--cp-bg);
56
+ color: var(--cp-fg);
57
+ font-family: var(--cp-font-ui);
58
+ font-size: 14px;
59
+ overflow: hidden;
60
+ }
61
+
62
+ .cp-toolbar {
63
+ display: flex;
64
+ align-items: center;
65
+ gap: 8px;
66
+ flex-wrap: wrap;
67
+ padding: 6px 8px;
68
+ background: var(--cp-surface);
69
+ border-bottom: 1px solid var(--cp-border);
70
+ }
71
+
72
+ .cp-spacer { flex: 1 1 auto; }
73
+
74
+ .cp-icon-button, .cp-theme-picker {
75
+ position: relative;
76
+ display: inline-flex;
77
+ align-items: center;
78
+ justify-content: center;
79
+ flex: none;
80
+ width: 28px;
81
+ height: 27px;
82
+ padding: 0;
83
+ border: 1px solid var(--cp-border);
84
+ border-radius: 6px;
85
+ background: var(--cp-bg);
86
+ color: var(--cp-fg);
87
+ cursor: pointer;
88
+ }
89
+ .cp-icon-button[hidden], .cp-theme-picker[hidden] { display: none; }
90
+ .cp-icon-button svg, .cp-theme-picker svg {
91
+ width: 15px;
92
+ height: 15px;
93
+ fill: none;
94
+ stroke: currentColor;
95
+ stroke-width: 2;
96
+ stroke-linecap: round;
97
+ stroke-linejoin: round;
98
+ }
99
+ .cp-theme-picker { overflow: hidden; }
100
+ .cp-theme-picker:hover { border-color: var(--cp-accent); }
101
+ .cp-theme-picker:focus-within { outline: 2px solid var(--cp-accent); outline-offset: 1px; }
102
+ /* The native list, laid invisibly over the icon: keyboard and phone pickers come free. */
103
+ .cp-theme-picker select {
104
+ position: absolute;
105
+ inset: 0;
106
+ width: 100%;
107
+ height: 100%;
108
+ opacity: 0;
109
+ min-width: 0;
110
+ margin: 0;
111
+ padding: 0;
112
+ border: 0;
113
+ appearance: none;
114
+ cursor: pointer;
115
+ font-size: 16px;
116
+ }
117
+ .cp-theme-sun { display: none; }
118
+ :host([data-resolved-theme="dark"]) .cp-theme-sun { display: block; }
119
+ :host([data-resolved-theme="dark"]) .cp-theme-moon { display: none; }
120
+
121
+ .cp-status {
122
+ font-size: 12px;
123
+ color: var(--cp-muted);
124
+ white-space: nowrap;
125
+ overflow: hidden;
126
+ text-overflow: ellipsis;
127
+ max-width: 55%;
128
+ }
129
+ .cp-status[data-state="error"] { color: var(--cp-danger); }
130
+ .cp-status[data-state="ok"] { color: var(--cp-ok); }
131
+
132
+ button {
133
+ font: inherit;
134
+ font-size: 13px;
135
+ line-height: 1;
136
+ padding: 6px 12px;
137
+ border-radius: 6px;
138
+ border: 1px solid var(--cp-border);
139
+ background: var(--cp-bg);
140
+ color: var(--cp-fg);
141
+ cursor: pointer;
142
+ }
143
+ button:hover:not(:disabled) { border-color: var(--cp-accent); }
144
+ button:disabled { opacity: 0.5; cursor: default; }
145
+ button:focus-visible { outline: 2px solid var(--cp-accent); outline-offset: 1px; }
146
+
147
+ button.cp-primary {
148
+ background: var(--cp-accent);
149
+ border-color: var(--cp-accent);
150
+ color: var(--cp-accent-fg);
151
+ font-weight: 600;
152
+ }
153
+ button.cp-danger { color: var(--cp-danger); border-color: var(--cp-danger); }
154
+
155
+ .cp-tabs {
156
+ display: flex;
157
+ gap: 2px;
158
+ overflow-x: auto;
159
+ padding: 0 6px;
160
+ background: var(--cp-surface);
161
+ border-bottom: 1px solid var(--cp-border);
162
+ scrollbar-width: thin;
163
+ }
164
+ .cp-tabs[hidden] { display: none; }
165
+ .cp-tabs button {
166
+ border: 0;
167
+ border-bottom: 2px solid transparent;
168
+ border-radius: 0;
169
+ background: transparent;
170
+ color: var(--cp-muted);
171
+ font-family: var(--cp-font-mono);
172
+ font-size: 12px;
173
+ padding: 7px 10px;
174
+ white-space: nowrap;
175
+ }
176
+ .cp-tabs button:hover:not(:disabled) { color: var(--cp-fg); }
177
+ .cp-tabs button[aria-pressed='true'] {
178
+ color: var(--cp-fg);
179
+ border-bottom-color: var(--cp-accent);
180
+ background: var(--cp-bg);
181
+ }
182
+ .cp-tabs button.cp-entry::before {
183
+ content: '▸';
184
+ margin-right: 4px;
185
+ color: var(--cp-accent);
186
+ }
187
+
188
+ .cp-editor {
189
+ height: var(--cp-height, 220px);
190
+ overflow: hidden;
191
+ }
192
+ .cp-editor .cm-editor { height: 100%; }
193
+
194
+ /* Content-fitting mode. Until 0.2.0 height="auto" happened to work, because a
195
+ percentage height against an indefinite parent computes to auto — true, but
196
+ accidental, and one future rule away from silently reverting to 220px. These
197
+ rules make it a supported mode instead. */
198
+ :host([height='auto']) .cp-editor,
199
+ :host([height='auto']) .cp-editor .cm-editor,
200
+ :host([height='auto']) .cp-fallback-editor {
201
+ height: auto;
202
+ }
203
+
204
+ /* Bounds for that mode, following CodeMirror's own recipes.
205
+
206
+ max-height goes on .cm-editor: its theme already gives .cm-scroller
207
+ overflow-y: auto, so a capped editor scrolls rather than clips. Putting the
208
+ cap on .cp-editor instead would clip, since the scroller has already sized
209
+ itself to the content.
210
+
211
+ min-height goes on .cm-content and .cm-gutter, not on .cm-editor. Both give
212
+ the right outer height, but on .cm-editor the scroller stays at content
213
+ height — so the empty space below a one-line snippet is not part of the
214
+ editor and clicking it does nothing. That empty space is exactly what a
215
+ "write your answer here" box is for. */
216
+ .cp-editor .cm-editor { max-height: var(--cp-max-height, none); }
217
+
218
+ /* Three classes deep on purpose: CodeMirror's base theme sets
219
+ .cm-content { min-height: 100% } through a generated wrapper class, which
220
+ ties on specificity with a two-class selector and wins on order, since its
221
+ stylesheet is injected into the shadow root after this one. */
222
+ .cp-editor .cm-editor .cm-content,
223
+ .cp-editor .cm-editor .cm-gutter { min-height: var(--cp-min-height, 0); }
224
+ .cp-editor .cp-fallback-editor {
225
+ min-height: var(--cp-min-height, 0);
226
+ max-height: var(--cp-max-height, none);
227
+ }
228
+ .cp-editor .cm-scroller {
229
+ font-family: var(--cp-font-mono);
230
+ font-size: 13px;
231
+ line-height: 1.5;
232
+ }
233
+ .cp-editor .cm-editor.cm-focused { outline: none; }
234
+
235
+ .cp-fallback-editor {
236
+ width: 100%;
237
+ height: 100%;
238
+ border: 0;
239
+ padding: 8px;
240
+ resize: none;
241
+ background: var(--cp-bg);
242
+ color: var(--cp-fg);
243
+ font-family: var(--cp-font-mono);
244
+ font-size: 13px;
245
+ line-height: 1.5;
246
+ }
247
+ .cp-fallback-editor:focus { outline: none; }
248
+
249
+ .cp-stdin { border-top: 1px solid var(--cp-border); background: var(--cp-surface); }
250
+ .cp-stdin[hidden] { display: none; }
251
+ .cp-stdin.cp-attention {
252
+ box-shadow: inset 0 0 0 2px var(--cp-accent);
253
+ }
254
+ .cp-stdin label {
255
+ display: block;
256
+ padding: 6px 8px 0;
257
+ font-size: 11px;
258
+ text-transform: uppercase;
259
+ letter-spacing: 0.04em;
260
+ color: var(--cp-muted);
261
+ }
262
+ .cp-stdin textarea {
263
+ display: block;
264
+ width: 100%;
265
+ min-height: 52px;
266
+ border: 0;
267
+ padding: 4px 8px 8px;
268
+ background: transparent;
269
+ color: var(--cp-fg);
270
+ font-family: var(--cp-font-mono);
271
+ font-size: 13px;
272
+ resize: vertical;
273
+ }
274
+ .cp-stdin textarea:focus { outline: none; }
275
+
276
+ .cp-output {
277
+ border-top: 1px solid var(--cp-border);
278
+ padding: 8px 10px;
279
+ margin: 0;
280
+ max-height: 260px;
281
+ overflow: auto;
282
+ background: var(--cp-surface);
283
+ font-family: var(--cp-font-mono);
284
+ font-size: 13px;
285
+ line-height: 1.5;
286
+ white-space: pre-wrap;
287
+ word-break: break-word;
288
+ }
289
+ .cp-output[hidden] { display: none; }
290
+ .cp-output .cp-err { color: var(--cp-danger); }
291
+ .cp-output .cp-hint {
292
+ margin-top: 6px;
293
+ padding: 6px 8px;
294
+ border-left: 3px solid var(--cp-accent);
295
+ background: var(--cp-bg);
296
+ color: var(--cp-fg);
297
+ font-family: var(--cp-font-ui);
298
+ font-size: 12.5px;
299
+ white-space: normal;
300
+ }
301
+ .cp-output .cp-value { color: var(--cp-muted); }
302
+ .cp-output .cp-in { color: var(--cp-accent); }
303
+
304
+ .cp-prompt {
305
+ display: inline-flex;
306
+ align-items: center;
307
+ gap: 4px;
308
+ }
309
+ .cp-prompt input {
310
+ font: inherit;
311
+ color: var(--cp-accent);
312
+ background: transparent;
313
+ border: 0;
314
+ border-bottom: 1px solid var(--cp-accent);
315
+ padding: 0 2px;
316
+ min-width: 12ch;
317
+ caret-color: var(--cp-accent);
318
+ }
319
+ .cp-prompt input:focus { outline: none; }
320
+ .cp-prompt button {
321
+ padding: 1px 6px;
322
+ font-size: 11px;
323
+ line-height: 1.4;
324
+ border-radius: 4px;
325
+ color: var(--cp-muted);
326
+ font-family: var(--cp-font-mono);
327
+ }
328
+ .cp-prompt button.cp-send { color: var(--cp-accent); border-color: var(--cp-accent); }
329
+
330
+ table.cp-table {
331
+ border-collapse: collapse;
332
+ margin: 6px 0;
333
+ font-size: 12px;
334
+ }
335
+ table.cp-table th, table.cp-table td {
336
+ border: 1px solid var(--cp-border);
337
+ padding: 3px 8px;
338
+ text-align: left;
339
+ }
340
+ table.cp-table th { background: var(--cp-bg); }
341
+
342
+ .cp-progress {
343
+ height: 2px;
344
+ background: linear-gradient(90deg, transparent, var(--cp-accent), transparent);
345
+ background-size: 40% 100%;
346
+ background-repeat: no-repeat;
347
+ animation: cp-slide 1.1s ease-in-out infinite;
348
+ }
349
+ .cp-progress[hidden] { display: none; }
350
+
351
+ /* language="react". The widget is the container: lesson columns are narrow even
352
+ on a large screen, so the viewport says nothing about the room there is. */
353
+ .cp-root.cp-has-preview { container-type: inline-size; }
354
+ .cp-preview-pane { display: none; }
355
+ .cp-has-preview .cp-preview-pane { display: flex; flex-direction: column; }
356
+ .cp-has-preview .cp-preview-pane .cp-output { flex: 1 1 auto; border-top: 0; min-height: 40px; }
357
+ .cp-preview {
358
+ position: relative;
359
+ flex: 0 0 var(--cp-preview-height, 320px);
360
+ height: var(--cp-preview-height, 320px);
361
+ border-top: 1px solid var(--cp-border);
362
+ background: var(--cp-surface);
363
+ overflow: hidden;
364
+ }
365
+ .cp-preview-frame {
366
+ display: block;
367
+ width: 100%;
368
+ height: 100%;
369
+ border: 0;
370
+ background: #ffffff;
371
+ }
372
+ .cp-preview-banner {
373
+ position: absolute;
374
+ left: 0;
375
+ right: 0;
376
+ bottom: 0;
377
+ max-height: 60%;
378
+ margin: 0;
379
+ padding: 10px 12px;
380
+ overflow: auto;
381
+ border-top: 3px solid var(--cp-danger);
382
+ background: var(--cp-bg);
383
+ color: var(--cp-danger);
384
+ font-family: var(--cp-font-mono);
385
+ font-size: 12.5px;
386
+ line-height: 1.5;
387
+ white-space: pre-wrap;
388
+ word-break: break-word;
389
+ }
390
+ .cp-preview-notice {
391
+ position: absolute;
392
+ top: 8px;
393
+ left: 8px;
394
+ right: 8px;
395
+ padding: 8px 10px;
396
+ border: 1px solid var(--cp-border);
397
+ border-left: 3px solid var(--cp-accent);
398
+ border-radius: 6px;
399
+ background: var(--cp-bg);
400
+ color: var(--cp-fg);
401
+ font-size: 13px;
402
+ white-space: pre-wrap;
403
+ }
404
+ .cp-preview-notice[hidden] { display: none; }
405
+ .cp-output .cp-warn { color: #9a6700; }
406
+ :host([data-resolved-theme="dark"]) .cp-output .cp-warn { color: #d29922; }
407
+ .cp-edited-note { font-size: 12px; color: var(--cp-muted); white-space: nowrap; }
408
+ .cp-edited-note[hidden] { display: none; }
409
+ .cp-tabs button.cp-edited::after { content: ' ●'; color: var(--cp-accent); }
410
+ .cp-tab-folder { opacity: 0.65; }
411
+
412
+ @container (max-width: 480px) {
413
+ .cp-tab-folder { display: none; }
414
+ }
415
+ /* The dividers between sections. */
416
+ .cp-split {
417
+ display: none;
418
+ flex: none;
419
+ background: var(--cp-surface);
420
+ border: solid var(--cp-border);
421
+ border-width: 0 1px;
422
+ touch-action: none;
423
+ cursor: col-resize;
424
+ }
425
+ .cp-split:hover, .cp-split:focus-visible { background: var(--cp-accent); outline: none; }
426
+ .cp-split-main, .cp-split-console {
427
+ width: auto;
428
+ height: 7px;
429
+ border-width: 1px 0;
430
+ cursor: row-resize;
431
+ }
432
+ .cp-has-preview .cp-split-main { display: block; }
433
+ .cp-has-preview .cp-split-console { display: block; }
434
+ .cp-split-console:has(+ .cp-output[hidden]) { display: none; }
435
+ .cp-dragging .cp-preview-frame { pointer-events: none; }
436
+ .cp-dragging { user-select: none; }
437
+ .cp-dragging-x { cursor: col-resize; }
438
+ .cp-dragging-y { cursor: row-resize; }
439
+ .cp-root.cp-editor-sized .cp-editor { height: var(--cp-editor-height) !important; flex: none !important; }
440
+ .cp-root.cp-editor-sized .cp-editor .cm-editor { height: 100% !important; max-height: none !important; }
441
+
442
+ /* Open in window. */
443
+ .cp-window-button { display: none; }
444
+ .cp-has-preview .cp-window-button { display: inline-flex; }
445
+ :host([data-window]) .cp-window-button { display: none; }
446
+ .cp-window-note { display: none; align-items: center; gap: 8px; padding: 14px 12px; color: var(--cp-muted); }
447
+ .cp-root.cp-popped .cp-window-note { display: flex; }
448
+ .cp-root.cp-popped .cp-toolbar, .cp-root.cp-popped .cp-body { display: none; }
449
+ :host([data-window]) { height: 100%; margin: 0; contain: strict; }
450
+ :host([data-window]) .cp-root {
451
+ display: flex;
452
+ flex-direction: column;
453
+ height: 100%;
454
+ border: 0;
455
+ border-radius: 0;
456
+ }
457
+ :host([data-window]) .cp-body { flex: 1 1 0; min-height: 0; }
458
+ :host([data-window]) .cp-source, :host([data-window]) .cp-preview-pane { min-height: 0; }
459
+ :host([data-window]) .cp-root:not(.cp-editor-sized) .cp-editor { flex: 1 1 0; height: auto; min-height: 0; }
460
+ :host([data-window]) .cp-editor .cm-editor { height: 100%; max-height: none; }
461
+ :host([data-window]) .cp-preview-pane .cp-output { max-height: none; }
462
+ :host([data-window]) .cp-body { display: flex; flex-direction: column; }
463
+ :host([data-window]) .cp-source { flex: 1 1 0; display: flex; flex-direction: column; }
464
+ :host([data-window]) .cp-has-tree .cp-source { display: grid; }
465
+ :host([data-window]) .cp-preview-pane { flex: 1 1 0; }
466
+
467
+ /* file-view="tree": the files in a column beside the editor. */
468
+ .cp-root.cp-has-tree { container-type: inline-size; }
469
+ .cp-has-tree .cp-source {
470
+ display: grid;
471
+ grid-template-columns: var(--cp-tree-width, 200px) 7px minmax(0, 1fr);
472
+ grid-template-rows: 1fr auto;
473
+ }
474
+ .cp-has-tree .cp-source > :not(.cp-tabs, .cp-split-tree) { grid-column: 3; }
475
+ .cp-has-tree .cp-split-tree { display: block; grid-column: 2; grid-row: 1 / span 2; }
476
+ .cp-tabs.cp-tree {
477
+ display: block;
478
+ grid-column: 1;
479
+ grid-row: 1 / span 2;
480
+ padding: 6px 0;
481
+ overflow: auto;
482
+ border-bottom: 0;
483
+ }
484
+ .cp-tabs.cp-tree[hidden] { display: none; }
485
+ .cp-tabs.cp-tree button {
486
+ display: block;
487
+ width: 100%;
488
+ padding: 5px 8px 5px calc(22px + var(--cp-depth, 0) * 12px);
489
+ border-bottom: 0;
490
+ border-left: 2px solid transparent;
491
+ text-align: left;
492
+ overflow: hidden;
493
+ text-overflow: ellipsis;
494
+ }
495
+ .cp-tabs.cp-tree button[aria-pressed='true'] { border-left-color: var(--cp-accent); }
496
+ .cp-tabs.cp-tree button.cp-entry::before {
497
+ content: '▸';
498
+ display: inline-block;
499
+ width: 12px;
500
+ margin: 0 0 0 -12px;
501
+ }
502
+ .cp-tabs.cp-tree .cp-tree-folder {
503
+ padding-left: calc(8px + var(--cp-depth, 0) * 12px);
504
+ color: var(--cp-fg);
505
+ }
506
+ .cp-tabs.cp-tree .cp-tree-folder::before {
507
+ content: '⌄';
508
+ display: inline-block;
509
+ width: 14px;
510
+ color: var(--cp-muted);
511
+ }
512
+ .cp-tabs.cp-tree .cp-tree-folder[aria-expanded='false']::before { content: '›'; }
513
+ @container (max-width: 420px) {
514
+ .cp-has-tree .cp-source { display: block; }
515
+ .cp-has-tree .cp-split-tree { display: none; }
516
+ .cp-tabs.cp-tree { max-height: 150px; border-bottom: 1px solid var(--cp-border); }
517
+ }
518
+
519
+ /* Only a preview sits beside the code: a tree makes any widget a container. */
520
+ @container (min-width: 760px) {
521
+ .cp-has-preview .cp-body { display: flex; align-items: stretch; }
522
+ .cp-has-preview .cp-source { flex: 0 0 var(--cp-source-width, calc(50% - 4px)); min-width: 0; }
523
+ .cp-has-preview .cp-preview-pane { flex: 1 1 0; min-width: 0; }
524
+ .cp-has-preview .cp-preview { border-top: 0; }
525
+ .cp-has-preview .cp-source:not(:has(.cp-tree)) { display: flex; flex-direction: column; }
526
+ .cp-has-preview .cp-source:not(:has(.cp-tree)) .cp-editor { flex: 1 1 auto; }
527
+ .cp-split.cp-split-main { width: 7px; height: auto; cursor: col-resize; border-width: 0 1px; }
528
+ :host([data-window]) .cp-body { flex-direction: row; }
529
+ :host([data-window]) .cp-source { flex: 0 0 var(--cp-source-width, calc(50% - 4px)); }
530
+ }
531
+
532
+ @keyframes cp-slide {
533
+ 0% { background-position: -40% 0; }
534
+ 100% { background-position: 140% 0; }
535
+ }
536
+
537
+ @media (prefers-reduced-motion: reduce) {
538
+ .cp-progress { animation: none; background-position: 0 0; background-size: 100% 100%; opacity: 0.4; }
539
+ }
540
+ `,D=e=>()=>import(`@codemirror/lang-javascript`).then(t=>t.javascript(e)),O={py:()=>import(`@codemirror/lang-python`).then(e=>e.python()),pyi:()=>import(`@codemirror/lang-python`).then(e=>e.python()),js:D({}),mjs:D({}),cjs:D({}),jsx:D({jsx:!0}),ts:D({typescript:!0}),mts:D({typescript:!0}),cts:D({typescript:!0}),tsx:D({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())};async function k(e,t){let n=e.includes(`.`)?e.slice(e.lastIndexOf(`.`)+1).toLowerCase():``,r=t===`react`&&n===`js`?O.jsx:O[n];return r?r().catch(()=>null):null}var A=`code-playpad`,j=1,M=`snippets`,N=`progress`,P=null;function F(){return typeof indexedDB>`u`?Promise.reject(/* @__PURE__ */ Error(`IndexedDB unavailable`)):(P||=new Promise((e,t)=>{let n=indexedDB.open(A,j);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(M)||e.createObjectStore(M),e.objectStoreNames.contains(N)||e.createObjectStore(N,{keyPath:`id`})},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}).catch(e=>{throw P=null,e}),P)}function I(e,t,n){return F().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 L(e,t){return I(M,`readwrite`,n=>n.put(t,e)).then(()=>void 0)}function R(e){return I(M,`readonly`,t=>t.get(e)).then(e=>e??null)}function z(e){return I(M,`readwrite`,t=>t.delete(e)).then(()=>void 0)}function B(e,t={}){let n={completed:!0,...t,id:e,updatedAt:Date.now()};return I(N,`readwrite`,e=>e.put(n)).then(()=>n)}function V(e){return I(N,`readonly`,t=>t.get(e)).then(e=>e??null)}function H(){return I(N,`readonly`,e=>e.getAll())}var U=`code-playpad`;function W(e){let t=e.replace(/\t/g,` `).split(`
541
+ `);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(`
542
+ `)}var G=2e5,K=`playpad-file`,q={python:`main.py`,javascript:`main.js`,typescript:`main.ts`,java:`Main.java`,c:`main.c`,cpp:`main.cpp`,react:`src/main.jsx`};function J(e){return q[e]??`main.txt`}var Y=e=>e.tagName===`SCRIPT`&&e.getAttribute(`type`)===`text/plain`;function X(e){return[...e.children].filter(e=>e.tagName.toLowerCase()===K&&[...e.children].some(e=>!Y(e))).map(e=>e.getAttribute(`name`)??``)}function Z(e,t){let n={};for(let t of e.children){if(t.tagName.toLowerCase()!==K)continue;let e=t.getAttribute(`name`),r=[...t.children].find(Y);e&&(n[e]=W((r??t).textContent??``))}if(Object.keys(n).length)return n;let r=[...e.childNodes].filter(e=>e.nodeType!==Node.ELEMENT_NODE||e.tagName.toLowerCase()!==K),i=r.some(e=>e.nodeType===Node.ELEMENT_NODE),a=W(r.filter(e=>!(i&&e.nodeType===Node.TEXT_NODE&&!(e.textContent??``).trim())).map(e=>e.textContent??``).join(``));return{[t]:a}}function Q(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 $=typeof HTMLElement>`u`?class{}:HTMLElement,ee=class extends ${static get observedAttributes(){return[`language`,`height`,`min-height`,`max-height`,`preview-height`,`file-view`,`open-file`,`theme`,`theme-controls`,`readonly`,`autorun`,`stdin`,`persist`,`entry`,`practice`]}#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u=null;#d=null;#f=null;#p=null;#m={};#h={};#g=`main.py`;#_=null;#v;#y=!1;#b=null;#x=!1;#S=!1;#C=null;#w=null;#T=null;#E=()=>this.#fe();#D=null;#O=null;#k=!0;#A=[];#j=null;#M=null;#N=null;#P=0;#F=!1;#I=null;#L;#R;#z=null;#B=[];#V=/* @__PURE__ */ new Set;#H=null;#U=null;#W=null;constructor(){super(),this.#e=this.attachShadow({mode:`open`})}get code(){return this.#u?this.#u.getCode():this.#m[this.#g]??``}set code(e){this.#m[this.#g]=e,this.#Z()}get practice(){if(this.#I)return this.#I;let e=this.getAttribute(`practice`);if(!e)return null;try{return JSON.parse(e)}catch{return null}}set practice(e){this.#I=e}get files(){return this.#re()}set files(e){let t=Object.keys(e);if(!t.length)return;let n=Object.keys(this.#h);n.length===1&&!this.#h[n[0]]&&(this.#h={...e}),this.#m={...e},this.#B=[],t.includes(this.#g)||(this.#g=this.#te()),this.#u?.forgetFiles([]),this.#Z(),this.#ie(),this.#X()}get entry(){return this.#te()}set entry(e){this.setAttribute(`entry`,e)}openFile(e){if(e in this.#m){this.#u&&(this.#m[this.#g]=this.#u.getCode(),this.#u.openFile(e,this.#m[e]??``)),this.#g=e;for(let t=e.indexOf(`/`);t!==-1;t=e.indexOf(`/`,t+1))this.#V.delete(e.slice(0,t));this.#ie(),this.#X()}}get stdin(){return this.#l?this.#l.value:``}set stdin(e){this.#l&&(this.#l.value=e,this.#c.hidden=!1)}get language(){return this.getAttribute(`language`)||`python`}set language(e){this.setAttribute(`language`,e)}getCode(){return this.code}getFiles(){return this.#re()}reset(){this.#m={...this.#h},this.#g=this.#te(),this.#u?.forgetFiles([]),this.#Z(),this.#ie(),this.#he(),this.#s.hidden=!0,this.#se(),this.#z=null,this.#ce(),this.#me(this.#f?.ready?`${this.#f.label} ready`:``,`idle`)}async run(){if(this.#H)return this.#H.widget.run();if(this.#y)return;await this.#d;let e=this.#re(),t=this.getAttribute(`entry`);if(t&&!(t in e))return this.#$(t,e);this.#Q=!1;let n=this.#te(),r=e[n]??``;this.#y=!0,this.#x=!1,this.#n.disabled=!0,this.#r.hidden=!1,this.#he(),this.#s.hidden=!1;let i=this.practice;this.hasAttribute(`practice`)&&!i&&this.#ge(`The practice attribute is not valid JSON.
543
+ `,`cp-err`),this.#oe()&&(this.#z=e,this.#ce(),this.#B.length&&this.#ge(`${this.#B.join(`, `)}: HTML tags in this file's markup were read as elements, so its code is incomplete. Write < as &lt;, or put the code in <script type="text/plain">. A <script> left unescaped runs on the host page.\n`,`cp-err`)),this.#Se(`py-run`,{code:r,entry:n,files:e,language:this.language,...i?{practice:i}:{}});try{let t=await this.#Y();if(this.#x)throw new C;if(i&&!t.supportsPractice)throw Error(`Practice mode is not available for ${t.label}.`);this.#me(`Queued…`,`busy`),this.#o.hidden=!1;let a=t.run(r,{stdin:this.#l.value,files:e,entry:n,onStart:()=>this.#me(`Running…`,`busy`),onProgress:e=>this.#me(e.message,`busy`),onStdout:e=>this.#ge(e),onStderr:e=>this.#ge(e,`cp-err`),onEcho:e=>this.#ge(e,`cp-in`),onStdinRequest:()=>this.#ve(),...i?{practice:i}:{},...this.#oe()?{preview:{host:this.#L,onStart:()=>this.#me(`Running…`,`busy`),onConsole:(e,t)=>{this.#ge(`${t}\n`,e===`error`?`cp-err`:e===`warn`?`cp-warn`:void 0),this.#Ce(`playpad-console`,{level:e,text:t,language:this.language})},onRender:e=>this.#Ce(`playpad-render`,{rootText:e,language:this.language}),onError:e=>{this.#me(`Error`,`error`),this.#Se(`py-error`,{...e,language:this.language})}}}:{}});this.#b={runtime:t,run:a};let o=await a;if(o.table&&this.#xe(o.table),o.value!==void 0&&this.#ge(`${o.value}\n`,`cp-value`),o.hint&&this.#be(o.hint,T.has(o)),o.failed=t.statusDecidesFailure?o.failed===!0:!!o.stderr,o.failed)this.#me(`Error · ${o.durationMs} ms`,`error`),this.#Se(`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.#me(e?`${o.passed} of ${e} passed · ${o.durationMs} ms`:`Done in ${o.durationMs} ms`,t?`ok`:`error`)}else this.#me(`Done in ${o.durationMs} ms`,`ok`);return this.#Se(`py-output`,{...o,language:this.language}),o}catch(e){if(e instanceof C)this.#ge(`
544
+ [stopped]
545
+ `,`cp-err`),this.#me(`Stopped`,`error`);else{let t=e instanceof Error?e.message:String(e);this.#ge(t+`
546
+ `,`cp-err`),this.#me(`Failed to start`,`error`),this.#Se(`py-error`,{message:t,language:this.language})}return}finally{this.#b=null,this.#ye(null),this.#_e(),this.#y=!1,this.#n.disabled=!1,this.#r.hidden=!(this.#oe()&&this.#f?.hasLivePreview?.(this.#L)),this.#o.hidden=!0}}stop(){this.#H?this.#H.widget.stop():this.#b?this.#b.runtime.stop?.(this.#b.run):this.#y?this.#x=!0:this.#oe()&&this.#f?.hasLivePreview?.(this.#L)&&(this.#se(),this.#r.hidden=!0,this.#me(`Stopped`,`idle`))}openWindow(){if(this.#H)return this.#H.window.focus(),!0;if(this.#U)return!1;let e=window.open(``,`_blank`,`popup,width=1280,height=800`);if(!e)return this.#me(`The browser blocked the new window`,`error`),!1;let t=this.#re(),n=this.#g,r=document.createElement(this.localName);for(let e of[`language`,`entry`,`file-view`,`preview-height`,`theme`,`theme-controls`,`readonly`,`stdin`]){let t=this.getAttribute(e);t!==null&&r.setAttribute(e,t)}r.setAttribute(`data-window`,``),r.#U=this,r.#W={...this.#h},r.#_=t,this.#se(),this.#r.hidden=!0,e.document.title=`Code playground`,e.document.documentElement.style.height=`100%`,e.document.body.style.cssText=`margin:0;height:100%`,e.document.body.append(r);let i=()=>this.closeWindow();return window.addEventListener(`pagehide`,i),this.#H={window:e,widget:r,onLeave:i,timer:setInterval(()=>{e.closed&&this.closeWindow()},300)},this.#e.querySelector(`.cp-root`)?.classList.add(`cp-popped`),r.#d?.then(()=>(r.openFile(n),r.run())),!0}closeWindow(){let e=this.#H;if(!e)return;this.#H=null,clearInterval(e.timer),window.removeEventListener(`pagehide`,e.onLeave);let{widget:t}=e,n=t.#re(),r=t.#g;t.#se(),t.remove(),e.window.closed||e.window.close(),this.#e.querySelector(`.cp-root`)?.classList.remove(`cp-popped`),this.files=n,this.openFile(r),this.#me(``,`idle`)}prewarm(){return this.#Y()}connectedCallback(){this.#F?(this.#fe(),this.#J()):!this.textContent?.trim()&&document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>this.isConnected&&this.#G(),{once:!0}):this.#G()}disconnectedCallback(){this.#C?.disconnect(),this.#C=null,this.#w?.removeEventListener(`change`,this.#E),this.#w=null,this.#T?.disconnect(),this.#T=null,this.#D?.(),this.#D=null,this.#O&&clearTimeout(this.#O),this.#ye(null),setTimeout(()=>{this.isConnected||(this.closeWindow(),this.#se(),this.#u&&(this.#_=this.#re(),this.#u.destroy(),this.#u=null,this.#d=null,this.#F=!1))},0)}attributeChangedCallback(e,t,n){if(this.#F)switch(e){case`theme`:case`theme-controls`:this.#fe();break;case`height`:case`min-height`:case`max-height`:case`preview-height`:this.#pe();break;case`readonly`:this.#u?.setReadOnly(n!==null);break;case`stdin`:this.#c.hidden=n===null&&!this.#l.value;break;case`entry`:case`file-view`:this.#ie();break;case`language`:this.#se(),this.#e.querySelector(`.cp-root`)?.classList.toggle(`cp-has-preview`,this.#oe()),this.#f=null,this.#p=null,this.#S=!1,this.#Y().catch(()=>{})}}#G(){this.#F=!0,this.#h=this.#W??Z(this,this.#ee()),this.#B=this.#oe()?X(this):[],this.#m=this.#_??{...this.#h},this.#g=this.#ne(),this.#K(),this.#fe(),this.#pe();let e=this.getAttribute(`persist`);this.#d=(async()=>{if(e&&this.#_==null){let t=await R(e).catch(()=>null),n=t==null?null:Q(t,this.#ee());if(n){let e={},t=Object.keys(this.#h),r=Object.keys(n);for(let r of t)e[r]=n[r]??this.#h[r];t.length===1&&r.length===1&&!(t[0]in n)&&(e[t[0]]=n[r[0]]),this.#m=e,this.#g=this.#ne()}}this.#ie();let t=await S(this.language).catch(()=>null),n=t?await t.editorLanguage().catch(()=>null):null;this.#u=await d({parent:this.#t,doc:this.#m[this.#g]??``,name:this.#g,dark:this.#ue(),themeId:this.#de(),readOnly:this.hasAttribute(`readonly`),language:n,onRun:()=>void this.run(),onChange:e=>this.#le(e)}),this.#_=null,this.#fe(),this.#X()})(),this.#J()}#K(){let t=document.createElement(`style`);t.textContent=E;let n=document.createElement(`div`);n.className=this.#oe()?`cp-root cp-has-preview`:`cp-root`,n.innerHTML=`
547
+ <div class="cp-toolbar">
548
+ <button class="cp-primary" part="run-button" data-action="run">Run</button>
549
+ <button class="cp-danger" part="stop-button" data-action="stop" hidden>Stop</button>
550
+ <button data-action="reset">Reset</button>
551
+ <span class="cp-spacer"></span>
552
+ <button part="theme-button" class="cp-icon-button" data-action="theme">
553
+ <svg class="cp-theme-moon" viewBox="0 0 24 24" aria-hidden="true"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z"/></svg>
554
+ <svg class="cp-theme-sun" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg>
555
+ </button>
556
+ <label part="editor-theme-picker" class="cp-theme-picker" title="Editor theme">
557
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3a9 9 0 0 0 0 18c1.4 0 2-.9 2-1.8 0-1.2-1-1.7-1-2.7 0-1 .8-1.5 1.8-1.5H17a4 4 0 0 0 4-4c0-4.4-4-8-9-8z"/><circle cx="7.5" cy="11.5" r="1"/><circle cx="10.5" cy="7.5" r="1"/><circle cx="15.5" cy="7.5" r="1"/></svg>
558
+ <select aria-label="Editor theme">
559
+ ${[`dark`,`light`].map(t=>`<optgroup label="${t===`dark`?`Dark`:`Light`}">${e.filter(e=>e.mode===t).map(e=>`<option value="${e.id}">${e.label}</option>`).join(``)}</optgroup>`).join(``)}
560
+ </select>
561
+ </label>
562
+ <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">
563
+ <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>
564
+ </button>
565
+ <span class="cp-edited-note" hidden>Edited since the last run</span>
566
+ <span class="cp-status" data-state="idle"></span>
567
+ </div>
568
+ <div class="cp-progress" hidden></div>
569
+ <div class="cp-window-note">
570
+ <span>Running in a separate window.</span>
571
+ <button data-action="show-window">Show window</button>
572
+ <button data-action="close-window">Bring back here</button>
573
+ </div>
574
+ <div class="cp-body">
575
+ <div class="cp-source">
576
+ <div class="cp-tabs" part="tabs" hidden></div>
577
+ <div class="cp-split cp-split-tree" role="separator" tabindex="0" aria-orientation="vertical" aria-label="Resize the file tree"></div>
578
+ <div class="cp-editor"></div>
579
+ <div class="cp-stdin" hidden>
580
+ <label>Standard input — one value per line</label>
581
+ <textarea rows="2" spellcheck="false"></textarea>
582
+ </div>
583
+ </div>
584
+ <div class="cp-split cp-split-main" role="separator" tabindex="0" aria-label="Resize the code and the preview"></div>
585
+ <div class="cp-preview-pane">
586
+ <div class="cp-preview" part="preview"></div>
587
+ <div class="cp-split cp-split-console" role="separator" tabindex="0" aria-orientation="horizontal" aria-label="Resize the preview and the console"></div>
588
+ <pre class="cp-output" part="output" hidden></pre>
589
+ </div>
590
+ </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.#v=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.#L=n.querySelector(`.cp-preview`),this.#R=n.querySelector(`.cp-edited-note`),this.#oe()||n.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()),n.querySelector(`[data-action="theme"]`).addEventListener(`click`,()=>{c({mode:this.#ue()?`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="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.#q(n);let r=()=>void this.#Y().catch(()=>{});this.#t.addEventListener(`pointerdown`,r,{once:!0}),this.#t.addEventListener(`focusin`,r,{once:!0})}#q(e){let t=e.querySelector(`.cp-body`),n=e.querySelector(`.cp-source`),r=e.querySelector(`.cp-preview`),i=e.querySelector(`.cp-preview-pane`),a=this.#v,o=(e,t,n)=>Math.round(Math.max(t,Math.min(e,Math.max(t,n)))),s=(t,n)=>e.style.setProperty(t,`${n}px`),c=(t,n,r,i,a)=>{let o=()=>t.setAttribute(`aria-orientation`,n()===`x`?`vertical`:`horizontal`);t.addEventListener(`pointerdown`,a=>{a.preventDefault();let o=n()===`x`,s=o?a.clientX:a.clientY,c=r();t.setPointerCapture(a.pointerId),e.classList.add(`cp-dragging`,o?`cp-dragging-x`:`cp-dragging-y`);let l=e=>i(c+(o?e.clientX:e.clientY)-s),u=()=>{e.classList.remove(`cp-dragging`,`cp-dragging-x`,`cp-dragging-y`),t.removeEventListener(`pointermove`,l),t.removeEventListener(`pointerup`,u),t.removeEventListener(`pointercancel`,u)};t.addEventListener(`pointermove`,l),t.addEventListener(`pointerup`,u),t.addEventListener(`pointercancel`,u)}),t.addEventListener(`keydown`,e=>{let t={ArrowLeft:-24,ArrowUp:-24,ArrowRight:24,ArrowDown:24}[e.key];t&&(e.preventDefault(),i(r()+t))}),t.addEventListener(`dblclick`,a),t.addEventListener(`focus`,o),t.addEventListener(`pointerenter`,o)},l=()=>getComputedStyle(t).flexDirection===`row`&&getComputedStyle(t).display===`flex`;c(e.querySelector(`.cp-split-tree`),()=>`x`,()=>a.getBoundingClientRect().width,e=>s(`--cp-tree-width`,o(e,90,n.getBoundingClientRect().width-160)),()=>e.style.removeProperty(`--cp-tree-width`)),c(e.querySelector(`.cp-split-main`),()=>l()?`x`:`y`,()=>l()?n.getBoundingClientRect().width:this.#t.getBoundingClientRect().height,n=>{l()?s(`--cp-source-width`,o(n,200,t.getBoundingClientRect().width-200)):(s(`--cp-editor-height`,o(n,80,2e3)),e.classList.add(`cp-editor-sized`))},()=>{e.style.removeProperty(`--cp-source-width`),e.style.removeProperty(`--cp-editor-height`),e.classList.remove(`cp-editor-sized`)}),c(e.querySelector(`.cp-split-console`),()=>`y`,()=>r.getBoundingClientRect().height,e=>s(`--cp-preview-height`,o(e,60,l()||this.#U?i.getBoundingClientRect().height-40:2e3)),()=>e.style.removeProperty(`--cp-preview-height`))}#J(){this.#U||this.#C||typeof IntersectionObserver>`u`||(this.#C=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(this.#C?.disconnect(),this.#C=null,this.#Y().then(()=>{this.hasAttribute(`autorun`)&&this.run()}).catch(()=>{}))},{rootMargin:`300px`}),this.#C.observe(this))}#Y(){return this.#p||=(async()=>{let e=await S(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+`
591
+ `,`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 k(e,this.language);if(t){this.#g===e&&this.#u?.setLanguage(t);return}let n=e.includes(`.`)?null:await(this.#f??await S(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`)||J(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`:J(this.language);return e.includes(n)?n:e[0]??n}#ne(){let e=this.getAttribute(`open-file`);return e&&e in this.#m?e:this.#te()}#re(){if(this.#H)return this.#H.widget.#re();let e={...this.#m};if(this.#u)for(let t of Object.keys(e))e[t]=this.#u.fileCode(t,e[t]);return e}#ie(){let e=Object.keys(this.#m);this.#v.hidden=e.length<2;let t=!this.#v.hidden&&this.getAttribute(`file-view`)===`tree`;if(this.#v.classList.toggle(`cp-tree`,t),this.#e.querySelector(`.cp-root`)?.classList.toggle(`cp-has-tree`,t),this.#v.hidden){this.#v.replaceChildren();return}if(t){this.#ae(e),this.#ce();return}let n=this.#te();this.#v.replaceChildren(...e.map(e=>{let t=document.createElement(`button`);t.dataset.file=e;let r=e.lastIndexOf(`/`)+1;if(r){let n=document.createElement(`span`);n.className=`cp-tab-folder`,n.textContent=e.slice(0,r),t.setAttribute(`aria-label`,e),t.append(n)}return t.append(e.slice(r)),t.setAttribute(`aria-pressed`,String(e===this.#g)),e===n&&(t.classList.add(`cp-entry`),t.title=`entry point — this is the file Run executes`),t})),this.#ce()}#ae(e){let t=this.#te(),n=[],r=(i,a)=>{let o=e.filter(e=>e.startsWith(i)).map(e=>e.slice(i.length)),s=[...new Set(o.filter(e=>e.includes(`/`)).map(e=>e.slice(0,e.indexOf(`/`))))].sort();for(let e of s){let t=i+e,o=!this.#V.has(t),s=document.createElement(`button`);s.className=`cp-tree-folder`,s.dataset.folder=t,s.textContent=e,s.setAttribute(`aria-expanded`,String(o)),s.style.setProperty(`--cp-depth`,String(a)),n.push(s),o&&r(`${t}/`,a+1)}for(let e of o.filter(e=>!e.includes(`/`)).sort()){let r=i+e,o=document.createElement(`button`);o.dataset.file=r,o.textContent=e,o.setAttribute(`aria-label`,r),o.setAttribute(`aria-pressed`,String(r===this.#g)),o.style.setProperty(`--cp-depth`,String(a)),r===t&&(o.classList.add(`cp-entry`),o.title=`entry point — this is the file Run executes`),n.push(o)}};r(``,0),this.#v.replaceChildren(...n)}#oe(){return this.language===`react`}#se(){this.#L&&(this.#f?.dispose?.(this.#L),this.#L.replaceChildren())}#ce(){if(!this.#oe())return;let e=this.#re();for(let t of this.#v.querySelectorAll(`button[data-file]`)){let n=t.dataset.file;t.classList.toggle(`cp-edited`,e[n]!==this.#h[n])}let t=this.#z;this.#R.hidden=!t||Object.keys(e).every(n=>e[n]===t[n])}#le(e){this.#m[this.#g]=e,this.#ce();let t=this.getAttribute(`persist`);if(!t)return;this.#O&&clearTimeout(this.#O);let n=JSON.stringify(this.#re());this.#O=setTimeout(()=>void L(t,n).catch(()=>{}),400)}#ue(){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.#w?.matches:r}#de(){return s()[this.#ue()?`dark`:`light`]}#fe(){this.#D??=l(this.#E),!this.#w&&typeof matchMedia==`function`&&(this.#w=matchMedia(`(prefers-color-scheme: dark)`),this.#w.addEventListener(`change`,this.#E)),!this.#T&&typeof MutationObserver==`function`&&typeof document<`u`&&(this.#T=new MutationObserver(this.#E),this.#T.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`,`style`,`data-theme`,`data-color-scheme`,`color-scheme`]}));let e=this.#ue(),t=this.#de();this.setAttribute(`data-resolved-theme`,e?`dark`:`light`),this.setAttribute(`data-editor-theme`,t),this.#u?.setTheme(e,t);let n=this.getAttribute(`theme`),r=n===`light`||n===`dark`||this.getAttribute(`theme-controls`)===`off`,i=this.#e.querySelector(`[data-action="theme"]`),a=this.#e.querySelector(`.cp-theme-picker`);if(i&&a){let n=e?`Switch to the light theme`:`Switch to the dark theme`;i.hidden=a.hidden=r,i.title=n,i.setAttribute(`aria-label`,n),a.querySelector(`select`).value=t}}#pe(){for(let[e,t]of[[`height`,`--cp-height`],[`min-height`,`--cp-min-height`],[`max-height`,`--cp-max-height`],[`preview-height`,`--cp-preview-height`]]){let n=this.getAttribute(e);n===null||n===``?this.style.removeProperty(t):this.style.setProperty(t,/^\d+$/.test(n)?`${n}px`:n)}}#me(e,t){this.#a.textContent=e,this.#a.dataset.state=t}#he(){this.#N&&clearTimeout(this.#N),this.#N=null,this.#A=[],this.#P=0,this.#s.replaceChildren(),this.#k=!0}#ge(e,t){if(!e)return;let n=t===`cp-err`&&!this.#k?`\n${e}`:e;this.#k=n.endsWith(`
592
+ `),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>=G)break;let e=t.text;this.#P+e.length>G&&(e=e.slice(0,G-this.#P)+`
593
+ … output truncated for display — the full text is in the playpad-output event
594
+ `),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(`
595
+ `,`cp-in`):this.#ge(n+`
596
+ `,`cp-in`),this.#_e(),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.#j=e,this.#M=a,n.focus({preventScroll:!0})})}#ye(e){this.#M?.(e),this.#M=null,this.#j=null}#be(e,t){this.#_e();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`))}#xe(e){this.#_e();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)}#Se(e,t){this.#Ce(e,t),this.#Ce(`playpad-${e.slice(3)}`,t)}#Ce(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0})),this.#U?.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}};function te(e=U){typeof window<`u`&&typeof customElements<`u`&&(customElements.get(e)||customElements.define(e,ee))}te();export{s as _,V as a,B as c,w as d,S as f,e as g,d as h,z as i,T as l,b as m,te as n,R as o,x as p,H as r,L as s,ee as t,C as u,l as v,c as y};