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.
- package/README.md +222 -17
- package/dist/THIRD-PARTY-NOTICES.txt +223 -0
- package/dist/cdn.js +2 -2
- package/dist/compiler-B408qd3N.js +151 -0
- package/dist/{config-CT3H6Oum.js → config-DB58UVsk.js} +1 -1
- package/dist/{cpp-Cs32J8JC.js → cpp-Bhr_Zgfk.js} +1 -1
- package/dist/{cpp-CO2abWii.js → cpp-xLJOrOXX.js} +1 -1
- package/dist/dist-3xj9-ylK.js +6 -0
- package/dist/{dist-BIgiGgKu.js → dist-7CHy0evE.js} +1 -1
- package/dist/dist-BDifu2bQ.js +6 -0
- package/dist/dist-BwlTZqCY.js +28 -0
- package/dist/dist-C41hAfPr.js +6 -0
- package/dist/dist-CRXZcpYD.js +14 -0
- package/dist/dist-CTLX4tws.js +8 -0
- package/dist/dist-CjnVq6q1.js +10 -0
- package/dist/{dist-Vr-fb58P.js → dist-D4P7t1AU.js} +4 -4
- package/dist/dist-DHeVjdBc.js +6 -0
- package/dist/dist-IFh_mUXG.js +7 -0
- package/dist/dist-UbI3_a5S.js +6 -0
- package/dist/dist-_fde-E8H.js +6 -0
- package/dist/dist-g8djAEMH.js +6 -0
- package/dist/dist-ixcYRC9x.js +6 -0
- package/dist/editor.d.ts +3 -1
- package/dist/element-Dzhksh6_.js +596 -0
- package/dist/element.d.ts +26 -0
- package/dist/element.js +1 -1
- package/dist/hints-DpBIeoeG.js +6 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +1 -1
- package/dist/{java-8qjVCjsN.js → java-DFiOVxDN.js} +1 -1
- package/dist/{java-DeBiVPXO.js → java-DjuG1fCk.js} +1 -1
- package/dist/{javascript-DLPaJJzf.js → javascript-BBiCDtZ3.js} +2 -2
- package/dist/{javascript-B1tVx7AD.js → javascript-CLaHCZ8o.js} +1 -1
- package/dist/languages.d.ts +1 -1
- package/dist/{pyodide-C8ImkXdD.js → pyodide-Cs-Kwccb.js} +1 -1
- package/dist/{pyodide-BOoYEfX1.js → pyodide-QurAOd7j.js} +2 -2
- package/dist/react-ALhWeEZ5.js +9 -0
- package/dist/react-DmuIc3qw.js +4 -0
- package/dist/react-runtime-19.2.8.js +240 -0
- package/dist/react-vendor.generated-DMxIoCMn.js +6 -0
- package/dist/react-version.generated-BNNJmf7J.js +6 -0
- package/dist/react.d.ts +9 -1
- package/dist/react.js +1 -1
- package/dist/rolldown-runtime-DK3Fl9T5.js +6 -0
- package/dist/runtime/config.d.ts +15 -1
- package/dist/runtime/react/boot.d.ts +9 -0
- package/dist/runtime/react/compiler.d.ts +30 -0
- package/dist/runtime/react-vendor.generated.d.ts +5 -0
- package/dist/runtime/react-version.generated.d.ts +3 -0
- package/dist/runtime/react.d.ts +2 -0
- package/dist/standalone.js +289 -17
- package/dist/styles.d.ts +0 -2
- package/dist/theme.d.ts +48 -0
- package/dist/{hints-CCMgezw9.js → types-CfcYqU2K.js} +1 -1
- package/dist/types.d.ts +23 -0
- package/dist/worker-runtime-DvpugeXD.js +9 -0
- package/dist/{worker-runtime-sUPz1J56.js → worker-runtime-tSXm-pPB.js} +1 -1
- package/package.json +23 -6
- package/dist/dist--J_vhCIU.js +0 -14
- package/dist/dist-BNvM_BAY.js +0 -6
- package/dist/dist-BkpKCrXQ.js +0 -6
- package/dist/dist-CJxiVI4a.js +0 -6
- package/dist/dist-CNOK8CHE.js +0 -6
- package/dist/dist-D25hs99E.js +0 -10
- package/dist/dist-D2igTc4m.js +0 -6
- package/dist/dist-D7jBL3Ib.js +0 -28
- package/dist/dist-DXjodKfp.js +0 -6
- package/dist/dist-DfFrsBkU.js +0 -8
- package/dist/element-CQGYVEF7.js +0 -324
- package/dist/worker-runtime-DfYet3xy.js +0 -9
package/dist/element-CQGYVEF7.js
DELETED
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
async function e(e){try{return await t(e)}catch(t){return console.warn(`[code-playpad] CodeMirror unavailable, using plain textarea:`,t),n(e)}}async function t(e){let[t,n,r,i,a,o]=await Promise.all([import(`@codemirror/view`),import(`@codemirror/state`),import(`@codemirror/commands`),import(`@codemirror/language`),import(`@codemirror/autocomplete`),import(`@codemirror/theme-one-dark`)]),{EditorView:s,keymap:c,lineNumbers:l,highlightActiveLine:u,highlightActiveLineGutter:d,highlightSpecialChars:f,drawSelection:p,rectangularSelection:m,crosshairCursor:h}=t,{EditorState:g,Compartment:_}=n,{defaultKeymap:v,history:y,historyKeymap:b,indentWithTab:x}=r,{syntaxHighlighting:S,defaultHighlightStyle:C,indentOnInput:w,bracketMatching:T,foldGutter:E,foldKeymap:D}=i,{autocompletion:O,closeBrackets:k,closeBracketsKeymap:A,completionKeymap:j}=a,M=new _,N=new _,P=new _,F=[s.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`}}),S(C,{fallback:!0})],I=e=>e?o.oneDark:F,L=c.of([{key:`Mod-Enter`,preventDefault:!0,run:()=>(e.onRun?.(),!0)},{key:`Shift-Enter`,preventDefault:!0,run:()=>(e.onRun?.(),!0)}]),R=e.dark,z=e.readOnly,B=e.language??[],V=t=>g.create({doc:t,extensions:[l(),d(),f(),y(),E(),p(),g.allowMultipleSelections.of(!0),w(),T(),k(),O(),m(),h(),u(),L,c.of([...A,...v,...b,...D,...j,x]),s.lineWrapping,P.of(B),M.of(I(R)),N.of(g.readOnly.of(z)),s.updateListener.of(t=>{t.docChanged&&e.onChange?.(t.state.doc.toString())})]}),H=new s({parent:e.parent,state:V(e.doc)}),U=/* @__PURE__ */ new Map,W=e.name??``;return{fallback:!1,getCode:()=>H.state.doc.toString(),setCode(e){H.dispatch({changes:{from:0,to:H.state.doc.length,insert:e}})},openFile(e,t){if(e===W)return;U.set(W,H.state);let n=U.get(e);H.setState(n??V(t)),W=e,n&&H.dispatch({effects:[M.reconfigure(I(R)),N.reconfigure(g.readOnly.of(z)),P.reconfigure(B)]})},fileCode(e,t){if(e===W)return H.state.doc.toString();let n=U.get(e);return n?n.doc.toString():t},forgetFiles(e){for(let t of[...U.keys()])e.includes(t)||U.delete(t)},setTheme(e){R=e,H.dispatch({effects:M.reconfigure(I(R))})},setReadOnly(e){z=e,H.dispatch({effects:N.reconfigure(g.readOnly.of(z))})},setLanguage(e){B=e,H.dispatch({effects:P.reconfigure(B)})},focus:()=>H.focus(),destroy:()=>H.destroy()}}function n(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 r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map;function a(e,t){r.set(e,t)}function o(){return[...r.keys()]}function s(e){let t=i.get(e);if(t)return t;let n=r.get(e);if(!n)return Promise.reject(/* @__PURE__ */ Error(`Unknown runtime "${e}". Registered: ${o().join(`, `)||`none`}`));let a=n().catch(t=>{throw i.delete(e),t});return i.set(e,a),a}a(`python`,()=>import(`./pyodide-C8ImkXdD.js`).then(e=>e.pythonRuntime)),a(`javascript`,()=>import(`./javascript-B1tVx7AD.js`).then(e=>e.javascriptRuntime)),a(`typescript`,()=>import(`./javascript-B1tVx7AD.js`).then(e=>e.typescriptRuntime)),a(`java`,()=>import(`./java-8qjVCjsN.js`).then(e=>e.javaRuntime)),a(`c`,()=>import(`./cpp-CO2abWii.js`).then(e=>e.cRuntime)),a(`cpp`,()=>import(`./cpp-CO2abWii.js`).then(e=>e.cppRuntime));var c=class extends Error{constructor(e=`Execution stopped`){super(e),this.name=`RunStopped`}},l=class extends Error{constructor(e=`Web Workers are unavailable in this page`){super(e),this.name=`WorkerUnavailable`}},u=/* @__PURE__ */ new WeakSet,d=String.raw`
|
|
2
|
-
:host {
|
|
3
|
-
--cp-bg: #ffffff;
|
|
4
|
-
--cp-fg: #1f2328;
|
|
5
|
-
--cp-muted: #656d76;
|
|
6
|
-
--cp-border: #d0d7de;
|
|
7
|
-
--cp-surface: #f6f8fa;
|
|
8
|
-
--cp-accent: #1f6feb;
|
|
9
|
-
--cp-accent-fg: #ffffff;
|
|
10
|
-
--cp-danger: #cf222e;
|
|
11
|
-
--cp-ok: #1a7f37;
|
|
12
|
-
--cp-radius: 8px;
|
|
13
|
-
--cp-font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
|
|
14
|
-
--cp-font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
15
|
-
|
|
16
|
-
display: block;
|
|
17
|
-
margin: 1rem 0;
|
|
18
|
-
color-scheme: light;
|
|
19
|
-
contain: content;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
:host([hidden]) { display: none; }
|
|
23
|
-
|
|
24
|
-
:host([data-resolved-theme="dark"]) {
|
|
25
|
-
--cp-bg: #0d1117;
|
|
26
|
-
--cp-fg: #e6edf3;
|
|
27
|
-
--cp-muted: #8b949e;
|
|
28
|
-
--cp-border: #30363d;
|
|
29
|
-
--cp-surface: #161b22;
|
|
30
|
-
--cp-accent: #388bfd;
|
|
31
|
-
--cp-danger: #ff7b72;
|
|
32
|
-
--cp-ok: #3fb950;
|
|
33
|
-
color-scheme: dark;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
* { box-sizing: border-box; }
|
|
37
|
-
|
|
38
|
-
.cp-root {
|
|
39
|
-
border: 1px solid var(--cp-border);
|
|
40
|
-
border-radius: var(--cp-radius);
|
|
41
|
-
background: var(--cp-bg);
|
|
42
|
-
color: var(--cp-fg);
|
|
43
|
-
font-family: var(--cp-font-ui);
|
|
44
|
-
font-size: 14px;
|
|
45
|
-
overflow: hidden;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
.cp-toolbar {
|
|
49
|
-
display: flex;
|
|
50
|
-
align-items: center;
|
|
51
|
-
gap: 8px;
|
|
52
|
-
padding: 6px 8px;
|
|
53
|
-
background: var(--cp-surface);
|
|
54
|
-
border-bottom: 1px solid var(--cp-border);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.cp-spacer { flex: 1 1 auto; }
|
|
58
|
-
|
|
59
|
-
.cp-status {
|
|
60
|
-
font-size: 12px;
|
|
61
|
-
color: var(--cp-muted);
|
|
62
|
-
white-space: nowrap;
|
|
63
|
-
overflow: hidden;
|
|
64
|
-
text-overflow: ellipsis;
|
|
65
|
-
max-width: 55%;
|
|
66
|
-
}
|
|
67
|
-
.cp-status[data-state="error"] { color: var(--cp-danger); }
|
|
68
|
-
.cp-status[data-state="ok"] { color: var(--cp-ok); }
|
|
69
|
-
|
|
70
|
-
button {
|
|
71
|
-
font: inherit;
|
|
72
|
-
font-size: 13px;
|
|
73
|
-
line-height: 1;
|
|
74
|
-
padding: 6px 12px;
|
|
75
|
-
border-radius: 6px;
|
|
76
|
-
border: 1px solid var(--cp-border);
|
|
77
|
-
background: var(--cp-bg);
|
|
78
|
-
color: var(--cp-fg);
|
|
79
|
-
cursor: pointer;
|
|
80
|
-
}
|
|
81
|
-
button:hover:not(:disabled) { border-color: var(--cp-accent); }
|
|
82
|
-
button:disabled { opacity: 0.5; cursor: default; }
|
|
83
|
-
button:focus-visible { outline: 2px solid var(--cp-accent); outline-offset: 1px; }
|
|
84
|
-
|
|
85
|
-
button.cp-primary {
|
|
86
|
-
background: var(--cp-accent);
|
|
87
|
-
border-color: var(--cp-accent);
|
|
88
|
-
color: var(--cp-accent-fg);
|
|
89
|
-
font-weight: 600;
|
|
90
|
-
}
|
|
91
|
-
button.cp-danger { color: var(--cp-danger); border-color: var(--cp-danger); }
|
|
92
|
-
|
|
93
|
-
.cp-tabs {
|
|
94
|
-
display: flex;
|
|
95
|
-
gap: 2px;
|
|
96
|
-
overflow-x: auto;
|
|
97
|
-
padding: 0 6px;
|
|
98
|
-
background: var(--cp-surface);
|
|
99
|
-
border-bottom: 1px solid var(--cp-border);
|
|
100
|
-
scrollbar-width: thin;
|
|
101
|
-
}
|
|
102
|
-
.cp-tabs[hidden] { display: none; }
|
|
103
|
-
.cp-tabs button {
|
|
104
|
-
border: 0;
|
|
105
|
-
border-bottom: 2px solid transparent;
|
|
106
|
-
border-radius: 0;
|
|
107
|
-
background: transparent;
|
|
108
|
-
color: var(--cp-muted);
|
|
109
|
-
font-family: var(--cp-font-mono);
|
|
110
|
-
font-size: 12px;
|
|
111
|
-
padding: 7px 10px;
|
|
112
|
-
white-space: nowrap;
|
|
113
|
-
}
|
|
114
|
-
.cp-tabs button:hover:not(:disabled) { color: var(--cp-fg); }
|
|
115
|
-
.cp-tabs button[aria-pressed='true'] {
|
|
116
|
-
color: var(--cp-fg);
|
|
117
|
-
border-bottom-color: var(--cp-accent);
|
|
118
|
-
background: var(--cp-bg);
|
|
119
|
-
}
|
|
120
|
-
.cp-tabs button.cp-entry::before {
|
|
121
|
-
content: '▸';
|
|
122
|
-
margin-right: 4px;
|
|
123
|
-
color: var(--cp-accent);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
.cp-editor {
|
|
127
|
-
height: var(--cp-height, 220px);
|
|
128
|
-
overflow: hidden;
|
|
129
|
-
}
|
|
130
|
-
.cp-editor .cm-editor { height: 100%; }
|
|
131
|
-
|
|
132
|
-
/* Content-fitting mode. Until 0.2.0 height="auto" happened to work, because a
|
|
133
|
-
percentage height against an indefinite parent computes to auto — true, but
|
|
134
|
-
accidental, and one future rule away from silently reverting to 220px. These
|
|
135
|
-
rules make it a supported mode instead. */
|
|
136
|
-
:host([height='auto']) .cp-editor,
|
|
137
|
-
:host([height='auto']) .cp-editor .cm-editor,
|
|
138
|
-
:host([height='auto']) .cp-fallback-editor {
|
|
139
|
-
height: auto;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/* Bounds for that mode, following CodeMirror's own recipes.
|
|
143
|
-
|
|
144
|
-
max-height goes on .cm-editor: its theme already gives .cm-scroller
|
|
145
|
-
overflow-y: auto, so a capped editor scrolls rather than clips. Putting the
|
|
146
|
-
cap on .cp-editor instead would clip, since the scroller has already sized
|
|
147
|
-
itself to the content.
|
|
148
|
-
|
|
149
|
-
min-height goes on .cm-content and .cm-gutter, not on .cm-editor. Both give
|
|
150
|
-
the right outer height, but on .cm-editor the scroller stays at content
|
|
151
|
-
height — so the empty space below a one-line snippet is not part of the
|
|
152
|
-
editor and clicking it does nothing. That empty space is exactly what a
|
|
153
|
-
"write your answer here" box is for. */
|
|
154
|
-
.cp-editor .cm-editor { max-height: var(--cp-max-height, none); }
|
|
155
|
-
|
|
156
|
-
/* Three classes deep on purpose: CodeMirror's base theme sets
|
|
157
|
-
.cm-content { min-height: 100% } through a generated wrapper class, which
|
|
158
|
-
ties on specificity with a two-class selector and wins on order, since its
|
|
159
|
-
stylesheet is injected into the shadow root after this one. */
|
|
160
|
-
.cp-editor .cm-editor .cm-content,
|
|
161
|
-
.cp-editor .cm-editor .cm-gutter { min-height: var(--cp-min-height, 0); }
|
|
162
|
-
.cp-editor .cp-fallback-editor {
|
|
163
|
-
min-height: var(--cp-min-height, 0);
|
|
164
|
-
max-height: var(--cp-max-height, none);
|
|
165
|
-
}
|
|
166
|
-
.cp-editor .cm-scroller {
|
|
167
|
-
font-family: var(--cp-font-mono);
|
|
168
|
-
font-size: 13px;
|
|
169
|
-
line-height: 1.5;
|
|
170
|
-
}
|
|
171
|
-
.cp-editor .cm-editor.cm-focused { outline: none; }
|
|
172
|
-
|
|
173
|
-
.cp-fallback-editor {
|
|
174
|
-
width: 100%;
|
|
175
|
-
height: 100%;
|
|
176
|
-
border: 0;
|
|
177
|
-
padding: 8px;
|
|
178
|
-
resize: none;
|
|
179
|
-
background: var(--cp-bg);
|
|
180
|
-
color: var(--cp-fg);
|
|
181
|
-
font-family: var(--cp-font-mono);
|
|
182
|
-
font-size: 13px;
|
|
183
|
-
line-height: 1.5;
|
|
184
|
-
}
|
|
185
|
-
.cp-fallback-editor:focus { outline: none; }
|
|
186
|
-
|
|
187
|
-
.cp-stdin { border-top: 1px solid var(--cp-border); background: var(--cp-surface); }
|
|
188
|
-
.cp-stdin[hidden] { display: none; }
|
|
189
|
-
.cp-stdin.cp-attention {
|
|
190
|
-
box-shadow: inset 0 0 0 2px var(--cp-accent);
|
|
191
|
-
}
|
|
192
|
-
.cp-stdin label {
|
|
193
|
-
display: block;
|
|
194
|
-
padding: 6px 8px 0;
|
|
195
|
-
font-size: 11px;
|
|
196
|
-
text-transform: uppercase;
|
|
197
|
-
letter-spacing: 0.04em;
|
|
198
|
-
color: var(--cp-muted);
|
|
199
|
-
}
|
|
200
|
-
.cp-stdin textarea {
|
|
201
|
-
display: block;
|
|
202
|
-
width: 100%;
|
|
203
|
-
min-height: 52px;
|
|
204
|
-
border: 0;
|
|
205
|
-
padding: 4px 8px 8px;
|
|
206
|
-
background: transparent;
|
|
207
|
-
color: var(--cp-fg);
|
|
208
|
-
font-family: var(--cp-font-mono);
|
|
209
|
-
font-size: 13px;
|
|
210
|
-
resize: vertical;
|
|
211
|
-
}
|
|
212
|
-
.cp-stdin textarea:focus { outline: none; }
|
|
213
|
-
|
|
214
|
-
.cp-output {
|
|
215
|
-
border-top: 1px solid var(--cp-border);
|
|
216
|
-
padding: 8px 10px;
|
|
217
|
-
margin: 0;
|
|
218
|
-
max-height: 260px;
|
|
219
|
-
overflow: auto;
|
|
220
|
-
background: var(--cp-surface);
|
|
221
|
-
font-family: var(--cp-font-mono);
|
|
222
|
-
font-size: 13px;
|
|
223
|
-
line-height: 1.5;
|
|
224
|
-
white-space: pre-wrap;
|
|
225
|
-
word-break: break-word;
|
|
226
|
-
}
|
|
227
|
-
.cp-output[hidden] { display: none; }
|
|
228
|
-
.cp-output .cp-err { color: var(--cp-danger); }
|
|
229
|
-
.cp-output .cp-hint {
|
|
230
|
-
margin-top: 6px;
|
|
231
|
-
padding: 6px 8px;
|
|
232
|
-
border-left: 3px solid var(--cp-accent);
|
|
233
|
-
background: var(--cp-bg);
|
|
234
|
-
color: var(--cp-fg);
|
|
235
|
-
font-family: var(--cp-font-ui);
|
|
236
|
-
font-size: 12.5px;
|
|
237
|
-
white-space: normal;
|
|
238
|
-
}
|
|
239
|
-
.cp-output .cp-value { color: var(--cp-muted); }
|
|
240
|
-
.cp-output .cp-in { color: var(--cp-accent); }
|
|
241
|
-
|
|
242
|
-
.cp-prompt {
|
|
243
|
-
display: inline-flex;
|
|
244
|
-
align-items: center;
|
|
245
|
-
gap: 4px;
|
|
246
|
-
}
|
|
247
|
-
.cp-prompt input {
|
|
248
|
-
font: inherit;
|
|
249
|
-
color: var(--cp-accent);
|
|
250
|
-
background: transparent;
|
|
251
|
-
border: 0;
|
|
252
|
-
border-bottom: 1px solid var(--cp-accent);
|
|
253
|
-
padding: 0 2px;
|
|
254
|
-
min-width: 12ch;
|
|
255
|
-
caret-color: var(--cp-accent);
|
|
256
|
-
}
|
|
257
|
-
.cp-prompt input:focus { outline: none; }
|
|
258
|
-
.cp-prompt button {
|
|
259
|
-
padding: 1px 6px;
|
|
260
|
-
font-size: 11px;
|
|
261
|
-
line-height: 1.4;
|
|
262
|
-
border-radius: 4px;
|
|
263
|
-
color: var(--cp-muted);
|
|
264
|
-
font-family: var(--cp-font-mono);
|
|
265
|
-
}
|
|
266
|
-
.cp-prompt button.cp-send { color: var(--cp-accent); border-color: var(--cp-accent); }
|
|
267
|
-
|
|
268
|
-
table.cp-table {
|
|
269
|
-
border-collapse: collapse;
|
|
270
|
-
margin: 6px 0;
|
|
271
|
-
font-size: 12px;
|
|
272
|
-
}
|
|
273
|
-
table.cp-table th, table.cp-table td {
|
|
274
|
-
border: 1px solid var(--cp-border);
|
|
275
|
-
padding: 3px 8px;
|
|
276
|
-
text-align: left;
|
|
277
|
-
}
|
|
278
|
-
table.cp-table th { background: var(--cp-bg); }
|
|
279
|
-
|
|
280
|
-
.cp-progress {
|
|
281
|
-
height: 2px;
|
|
282
|
-
background: linear-gradient(90deg, transparent, var(--cp-accent), transparent);
|
|
283
|
-
background-size: 40% 100%;
|
|
284
|
-
background-repeat: no-repeat;
|
|
285
|
-
animation: cp-slide 1.1s ease-in-out infinite;
|
|
286
|
-
}
|
|
287
|
-
.cp-progress[hidden] { display: none; }
|
|
288
|
-
|
|
289
|
-
@keyframes cp-slide {
|
|
290
|
-
0% { background-position: -40% 0; }
|
|
291
|
-
100% { background-position: 140% 0; }
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
@media (prefers-reduced-motion: reduce) {
|
|
295
|
-
.cp-progress { animation: none; background-position: 0 0; background-size: 100% 100%; opacity: 0.4; }
|
|
296
|
-
}
|
|
297
|
-
`,f=e=>()=>import(`@codemirror/lang-javascript`).then(t=>t.javascript(e)),p={py:()=>import(`@codemirror/lang-python`).then(e=>e.python()),pyi:()=>import(`@codemirror/lang-python`).then(e=>e.python()),js:f({}),mjs:f({}),cjs:f({}),jsx:f({jsx:!0}),ts:f({typescript:!0}),mts:f({typescript:!0}),cts:f({typescript:!0}),tsx:f({typescript:!0,jsx:!0}),json:()=>import(`@codemirror/lang-json`).then(e=>e.json()),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 m(e){let t=p[e.includes(`.`)?e.slice(e.lastIndexOf(`.`)+1).toLowerCase():``];return t?t().catch(()=>null):null}var h=`code-playpad`,g=1,_=`snippets`,v=`progress`,y=null;function b(){return typeof indexedDB>`u`?Promise.reject(/* @__PURE__ */ Error(`IndexedDB unavailable`)):(y||=new Promise((e,t)=>{let n=indexedDB.open(h,g);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(_)||e.createObjectStore(_),e.objectStoreNames.contains(v)||e.createObjectStore(v,{keyPath:`id`})},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}).catch(e=>{throw y=null,e}),y)}function x(e,t,n){return b().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 S(e,t){return x(_,`readwrite`,n=>n.put(t,e)).then(()=>void 0)}function C(e){return x(_,`readonly`,t=>t.get(e)).then(e=>e??null)}function w(e){return x(_,`readwrite`,t=>t.delete(e)).then(()=>void 0)}function T(e,t={}){let n={completed:!0,...t,id:e,updatedAt:Date.now()};return x(v,`readwrite`,e=>e.put(n)).then(()=>n)}function E(e){return x(v,`readonly`,t=>t.get(e)).then(e=>e??null)}function D(){return x(v,`readonly`,e=>e.getAll())}var O=`code-playpad`;function k(e){let t=e.replace(/\t/g,` `).split(`
|
|
298
|
-
`);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(`
|
|
299
|
-
`)}var A=2e5,j=`playpad-file`,M={python:`main.py`,javascript:`main.js`,typescript:`main.ts`,java:`Main.java`,c:`main.c`,cpp:`main.cpp`};function N(e){return M[e]??`main.txt`}function P(e,t){let n={};for(let t of e.children){if(t.tagName.toLowerCase()!==j)continue;let e=t.getAttribute(`name`);e&&(n[e]=k(t.textContent??``))}if(Object.keys(n).length)return n;let r=[...e.childNodes].filter(e=>e.nodeType!==Node.ELEMENT_NODE||e.tagName.toLowerCase()!==j),i=r.some(e=>e.nodeType===Node.ELEMENT_NODE),a=k(r.filter(e=>!(i&&e.nodeType===Node.TEXT_NODE&&!(e.textContent??``).trim())).map(e=>e.textContent??``).join(``));return{[t]:a}}function F(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 I=typeof HTMLElement>`u`?class{}:HTMLElement,L=class extends I{static get observedAttributes(){return[`language`,`height`,`min-height`,`max-height`,`theme`,`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.#X();#D=null;#O=!0;#k=[];#A=null;#j=null;#M=null;#N=0;#P=!1;#F=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.#V()}get practice(){if(this.#F)return this.#F;let e=this.getAttribute(`practice`);if(!e)return null;try{return JSON.parse(e)}catch{return null}}set practice(e){this.#F=e}get files(){return this.#K()}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},t.includes(this.#g)||(this.#g=this.#G()),this.#u?.forgetFiles([]),this.#V(),this.#q(),this.#B()}get entry(){return this.#G()}set entry(e){this.setAttribute(`entry`,e)}openFile(e){e in this.#m&&(this.#u&&(this.#m[this.#g]=this.#u.getCode(),this.#u.openFile(e,this.#m[e]??``)),this.#g=e,this.#q(),this.#B())}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.#K()}reset(){this.#m={...this.#h},this.#g=this.#G(),this.#u?.forgetFiles([]),this.#V(),this.#q(),this.#$(),this.#s.hidden=!0,this.#Q(this.#f?.ready?`${this.#f.label} ready`:``,`idle`)}async run(){if(this.#y)return;await this.#d;let e=this.#K(),t=this.getAttribute(`entry`);if(t&&!(t in e))return this.#U(t,e);this.#H=!1;let n=this.#G(),r=e[n]??``;this.#y=!0,this.#x=!1,this.#n.disabled=!0,this.#r.hidden=!1,this.#$(),this.#s.hidden=!1;let i=this.practice;this.hasAttribute(`practice`)&&!i&&this.#ee(`The practice attribute is not valid JSON.
|
|
300
|
-
`,`cp-err`),this.#oe(`py-run`,{code:r,entry:n,files:e,language:this.language,...i?{practice:i}:{}});try{let t=await this.#z();if(this.#x)throw new c;if(i&&!t.supportsPractice)throw Error(`Practice mode is not available for ${t.label}.`);this.#Q(`Queued…`,`busy`),this.#o.hidden=!1;let a=t.run(r,{stdin:this.#l.value,files:e,entry:n,onStart:()=>this.#Q(`Running…`,`busy`),onProgress:e=>this.#Q(e.message,`busy`),onStdout:e=>this.#ee(e),onStderr:e=>this.#ee(e,`cp-err`),onEcho:e=>this.#ee(e,`cp-in`),onStdinRequest:()=>this.#ne(),...i?{practice:i}:{}});this.#b={runtime:t,run:a};let o=await a;if(o.table&&this.#ae(o.table),o.value!==void 0&&this.#ee(`${o.value}\n`,`cp-value`),o.hint&&this.#ie(o.hint,u.has(o)),o.failed=t.statusDecidesFailure?o.failed===!0:!!o.stderr,o.failed)this.#Q(`Error · ${o.durationMs} ms`,`error`),this.#oe(`py-error`,{message:o.stderr??``,hint:o.hint,language:this.language});else if(o.cases){let e=o.cases.filter(e=>e.expected!==void 0).length,t=o.passed===e;this.#Q(e?`${o.passed} of ${e} passed · ${o.durationMs} ms`:`Done in ${o.durationMs} ms`,t?`ok`:`error`)}else this.#Q(`Done in ${o.durationMs} ms`,`ok`);return this.#oe(`py-output`,{...o,language:this.language}),o}catch(e){if(e instanceof c)this.#ee(`
|
|
301
|
-
[stopped]
|
|
302
|
-
`,`cp-err`),this.#Q(`Stopped`,`error`);else{let t=e instanceof Error?e.message:String(e);this.#ee(t+`
|
|
303
|
-
`,`cp-err`),this.#Q(`Failed to start`,`error`),this.#oe(`py-error`,{message:t,language:this.language})}return}finally{this.#b=null,this.#re(null),this.#te(),this.#y=!1,this.#n.disabled=!1,this.#r.hidden=!0,this.#o.hidden=!0}}stop(){this.#b?this.#b.runtime.stop?.(this.#b.run):this.#y&&(this.#x=!0)}prewarm(){return this.#z()}connectedCallback(){this.#P?this.#R():!this.textContent?.trim()&&document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>this.isConnected&&this.#I(),{once:!0}):this.#I()}disconnectedCallback(){this.#C?.disconnect(),this.#C=null,this.#w?.removeEventListener(`change`,this.#E),this.#w=null,this.#T?.disconnect(),this.#T=null,this.#D&&clearTimeout(this.#D),this.#re(null),setTimeout(()=>{!this.isConnected&&this.#u&&(this.#_=this.#K(),this.#u.destroy(),this.#u=null,this.#d=null,this.#P=!1)},0)}attributeChangedCallback(e,t,n){if(this.#P)switch(e){case`theme`:this.#X();break;case`height`:case`min-height`:case`max-height`:this.#Z();break;case`readonly`:this.#u?.setReadOnly(n!==null);break;case`stdin`:this.#c.hidden=n===null&&!this.#l.value;break;case`entry`:this.#q();break;case`language`:this.#f=null,this.#p=null,this.#S=!1,this.#z().catch(()=>{})}}#I(){this.#P=!0,this.#h=P(this,this.#W()),this.#m=this.#_??{...this.#h},this.#g=this.#G(),this.#L(),this.#X(),this.#Z();let t=this.getAttribute(`persist`);this.#d=(async()=>{if(t&&this.#_==null){let e=await C(t).catch(()=>null),n=e==null?null:F(e,this.#W());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.#G()}}this.#q();let n=await s(this.language).catch(()=>null),r=n?await n.editorLanguage().catch(()=>null):null;this.#u=await e({parent:this.#t,doc:this.#m[this.#g]??``,name:this.#g,dark:this.#Y(),readOnly:this.hasAttribute(`readonly`),language:r,onRun:()=>void this.run(),onChange:e=>this.#J(e)}),this.#_=null,this.#B()})(),this.#R()}#L(){let e=document.createElement(`style`);e.textContent=d;let t=document.createElement(`div`);t.className=`cp-root`,t.innerHTML=`
|
|
304
|
-
<div class="cp-toolbar">
|
|
305
|
-
<button class="cp-primary" part="run-button" data-action="run">Run</button>
|
|
306
|
-
<button class="cp-danger" part="stop-button" data-action="stop" hidden>Stop</button>
|
|
307
|
-
<button data-action="reset">Reset</button>
|
|
308
|
-
<span class="cp-spacer"></span>
|
|
309
|
-
<span class="cp-status" data-state="idle"></span>
|
|
310
|
-
</div>
|
|
311
|
-
<div class="cp-progress" hidden></div>
|
|
312
|
-
<div class="cp-tabs" part="tabs" hidden></div>
|
|
313
|
-
<div class="cp-editor"></div>
|
|
314
|
-
<div class="cp-stdin" hidden>
|
|
315
|
-
<label>Standard input — one value per line</label>
|
|
316
|
-
<textarea rows="2" spellcheck="false"></textarea>
|
|
317
|
-
</div>
|
|
318
|
-
<pre class="cp-output" part="output" hidden></pre>`,this.#e.replaceChildren(e,t),this.#n=t.querySelector(`[data-action="run"]`),this.#r=t.querySelector(`[data-action="stop"]`),this.#i=t.querySelector(`[data-action="reset"]`),this.#a=t.querySelector(`.cp-status`),this.#o=t.querySelector(`.cp-progress`),this.#v=t.querySelector(`.cp-tabs`),this.#t=t.querySelector(`.cp-editor`),this.#c=t.querySelector(`.cp-stdin`),this.#l=t.querySelector(`.cp-stdin textarea`),this.#s=t.querySelector(`.cp-output`),this.#c.hidden=!this.hasAttribute(`stdin`),this.#l.addEventListener(`input`,()=>this.#c.classList.remove(`cp-attention`)),this.#v.addEventListener(`click`,e=>{let t=e.target.closest(`button[data-file]`);t&&this.openFile(t.getAttribute(`data-file`))}),this.#n.addEventListener(`click`,()=>void this.run()),this.#r.addEventListener(`click`,()=>this.stop()),this.#i.addEventListener(`click`,()=>this.reset());let n=()=>void this.#z().catch(()=>{});this.#t.addEventListener(`pointerdown`,n,{once:!0}),this.#t.addEventListener(`focusin`,n,{once:!0})}#R(){this.#C||typeof IntersectionObserver>`u`||(this.#C=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(this.#C?.disconnect(),this.#C=null,this.#z().then(()=>{this.hasAttribute(`autorun`)&&this.run()}).catch(()=>{}))},{rootMargin:`300px`}),this.#C.observe(this))}#z(){return this.#p||=(async()=>{let e=await s(this.language);this.#f=e,!e.ready&&!this.#H&&(this.#o.hidden=!1,this.#Q(`Loading ${e.label}…`,`busy`));try{await e.load(e=>{!this.#y&&!this.#H&&this.#Q(e.message,e.phase===`ready`?`ok`:`busy`)})}catch(e){this.#p=null,this.#Q(`Runtime unavailable`,`error`);let t=e instanceof Error?e.message:String(e);throw this.#ee(t+`
|
|
319
|
-
`,`cp-err`),this.#s.hidden=!1,e}finally{this.#o.hidden=!0}return this.#B(),this.#S||(this.#S=!0,this.#H||this.#Q(`${e.label} ready`,`ok`),this.#oe(`py-ready`,{language:e.id,label:e.label})),e})(),this.#p}async#B(){if(!this.#u)return;let e=this.#g,t=await m(e);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??[])}#V(){this.#u?this.#u.setCode(this.#m[this.#g]??``):this.#d?.then(()=>{this.#u?.setCode(this.#m[this.#g]??``),this.#q()})}#H=!1;#U(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.#$(),this.#s.hidden=!1,this.#ee(r,`cp-err`),this.#H=!0,this.#Q(`Error · entry not found`,`error`);let i={stdout:``,stderr:r,durationMs:0,failed:!0};return this.#oe(`py-error`,{message:r,language:this.language}),this.#oe(`py-output`,{...i,language:this.language}),i}#W(){return this.getAttribute(`entry`)||N(this.language)}#G(){let e=Object.keys(this.#m),t=this.getAttribute(`entry`);if(t&&e.includes(t))return t;let n=N(this.language);return e.includes(n)?n:e[0]??n}#K(){let e={...this.#m};if(this.#u)for(let t of Object.keys(e))e[t]=this.#u.fileCode(t,e[t]);return e}#q(){let e=Object.keys(this.#m);if(this.#v.hidden=e.length<2,this.#v.hidden){this.#v.replaceChildren();return}let t=this.#G();this.#v.replaceChildren(...e.map(e=>{let n=document.createElement(`button`);return n.dataset.file=e,n.textContent=e,n.setAttribute(`aria-pressed`,String(e===this.#g)),e===t&&(n.classList.add(`cp-entry`),n.title=`entry point — this is the file Run executes`),n}))}#J(e){this.#m[this.#g]=e;let t=this.getAttribute(`persist`);if(!t)return;this.#D&&clearTimeout(this.#D);let n=JSON.stringify(this.#K());this.#D=setTimeout(()=>void S(t,n).catch(()=>{}),400)}#Y(){let e=this.getAttribute(`theme`)??`auto`;if(e===`dark`)return!0;if(e===`light`)return!1;let t=typeof document>`u`?``:getComputedStyle(document.documentElement).colorScheme,n=t.includes(`dark`);return n===t.includes(`light`)?!!this.#w?.matches:n}#X(){!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.#Y();this.setAttribute(`data-resolved-theme`,e?`dark`:`light`),this.#u?.setTheme(e)}#Z(){for(let[e,t]of[[`height`,`--cp-height`],[`min-height`,`--cp-min-height`],[`max-height`,`--cp-max-height`]]){let n=this.getAttribute(e);n===null||n===``?this.style.removeProperty(t):this.style.setProperty(t,/^\d+$/.test(n)?`${n}px`:n)}}#Q(e,t){this.#a.textContent=e,this.#a.dataset.state=t}#$(){this.#M&&clearTimeout(this.#M),this.#M=null,this.#k=[],this.#N=0,this.#s.replaceChildren(),this.#O=!0}#ee(e,t){if(!e)return;let n=t===`cp-err`&&!this.#O?`\n${e}`:e;this.#O=n.endsWith(`
|
|
320
|
-
`),this.#k.push({text:n,className:t}),this.#M??=setTimeout(()=>this.#te(),16)}#te(){if(this.#M&&clearTimeout(this.#M),this.#M=null,!this.#k.length)return;let e=this.#k;this.#k=[];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.#N>=A)break;let e=t.text;this.#N+e.length>A&&(e=e.slice(0,A-this.#N)+`
|
|
321
|
-
… output truncated for display — the full text is in the playpad-output event
|
|
322
|
-
`),this.#N+=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}#ne(){return this.#te(),this.#re(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.#A===e&&(this.#A=null,this.#j=null,t.remove(),n===null?this.#ee(`
|
|
323
|
-
`,`cp-in`):this.#ee(n+`
|
|
324
|
-
`,`cp-in`),this.#te(),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.#A=e,this.#j=a,n.focus({preventScroll:!0})})}#re(e){this.#j?.(e),this.#j=null,this.#A=null}#ie(e,t){this.#te();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`))}#ae(e){this.#te();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)}#oe(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`playpad-${e.slice(3)}`,{detail:t,bubbles:!0,composed:!0}))}};function R(e=O){typeof window<`u`&&typeof customElements<`u`&&(customElements.get(e)||customElements.define(e,L))}R();export{E as a,T as c,l as d,s as f,e as h,w as i,u as l,a as m,R as n,C as o,o as p,D as r,S as s,L as t,c as u};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* code-playpad — MIT © 2026 Seung Hun Lee
|
|
3
|
-
* Bundles CodeMirror 6 and Lezer (MIT) © Marijn Haverbeke and others.
|
|
4
|
-
* Full third-party licences: THIRD-PARTY-NOTICES.txt in this package.
|
|
5
|
-
*/
|
|
6
|
-
import{n as e,r as t,t as n}from"./hints-CCMgezw9.js";var r=1,i=class{#e=null;#t=null;#n=`module`;#r=null;#i=null;#a=!1;#o=!1;#s=``;#c=/* @__PURE__ */ new Set;#l=[];#u=null;#d=!1;initPayload(){return{}}loadModule(e){return Promise.reject(/* @__PURE__ */ Error(`no module named ${e}`))}get ready(){return this.#a}get interactiveStdin(){return this.#o}get version(){return this.#s}load(e){e&&this.#c.add(e);let n=()=>{e&&this.#c.delete(e)};if(!this.#r){let e=new Promise((e,n)=>{this.#i={resolve:e,reject:n};let r;try{if(typeof Worker>`u`)throw Error(`Worker constructor missing`);let e=new Blob([this.source],{type:`text/javascript`});this.#t=URL.createObjectURL(e),r=new Worker(this.#t,{type:this.#n})}catch(e){this.#i=null,n(new t(`Could not start a Web Worker: ${e.message}`));return}this.#e=r,r.onmessage=t=>{let r=t.data;r.type===`ready`?(this.#s=r.version,this.#o=r.interactiveStdin===!0,this.#a=!0,this.#i=null,this.#h({phase:`ready`,message:`${this.label} ready`}),e()):r.type===`fatal`&&!this.#a?this.#p(r.message,e,n):this.#g(r)},r.onerror=t=>{let r=t.message||`Worker failed to start`;this.#a?this.#u&&this.#y(this.#u,Error(r)):this.#p(r,e,n)},r.postMessage({type:`init`,...this.initPayload()})});this.#r=e,e.catch(()=>{this.#r===e&&(this.#r=null)})}return this.#r.then(n,e=>{throw n(),e})}run(e,t={}){let n,i,a=new Promise((e,t)=>{n=e,i=t}),o,s=new Promise(e=>{o=e}),c={id:r++,code:e,options:t,stdout:``,stderr:``,resolve:n,reject:i,promise:a,started:!1,settled:!1,done:s,markDone:()=>{clearTimeout(c.timer),c.settled=!0,o()}};return this.#l.push(c),this.#b(),a}stop(t){if(t){let n=this.#l.findIndex(e=>e.promise===t);if(n!==-1){this.#y(this.#l.splice(n,1)[0],new e);return}let r=this.#u;if(!r||r.promise!==t||r.settled)return;if(!r.started){this.#y(r,new e);return}}this.#f()}#f(){let t=this.#e!==null,n=this.#i;if(this.#m(),this.#u&&this.#y(this.#u,new e),t){let e=this.load();n&&e.then(n.resolve,n.reject),e.catch(()=>{})}}#p(e,t,n){this.#m(),this.#n===`module`?(this.#n=`classic`,this.load().then(t,n)):n(Error(e))}#m(){this.#e?.terminate(),this.#e=null,this.#t&&=(URL.revokeObjectURL(this.#t),null),this.#r=null,this.#i=null,this.#a=!1}#h(e){for(let t of this.#c)t(e)}#g(e){if(e.type===`progress`){this.#h({phase:e.phase,message:e.message}),this.#u&&e.id===this.#u.id&&!this.#u.settled&&this.#u.options.onProgress?.({phase:e.phase,message:e.message});return}let t=this.#u;if(t&&`id`in e&&e.id===t.id)switch(e.type){case`stdout`:t.stdout+=e.text,t.options.onStdout?.(e.text);break;case`echo`:t.options.onEcho?.(e.text);break;case`stdin-request`:this.#v(t,e.request);break;case`module-request`:this.#_(t,e.name);break;case`stderr`:t.stderr+=e.text,t.options.onStderr?.(e.text);break;case`result`:t.resolve({stdout:t.stdout,stderr:t.stderr||void 0,value:e.value,durationMs:Math.round(e.durationMs),failed:!1,...e.memory?{memory:e.memory}:{},...e.cases?{cases:e.cases,passed:e.passed,total:e.total}:{}}),t.markDone();break;case`error`:case`fatal`:{let r=(t.stderr&&!t.stderr.endsWith(`
|
|
7
|
-
`)?`
|
|
8
|
-
`:``)+e.message+`
|
|
9
|
-
`;t.stderr+=r,t.options.onStderr?.(r);let i={stdout:t.stdout,stderr:t.stderr,hint:`hint`in e?e.hint:void 0,durationMs:Math.round(`durationMs`in e?e.durationMs:0),failed:!0,...`cases`in e&&e.cases?{cases:e.cases,passed:0,total:e.cases.length}:{}};`hintAbout`in e&&e.hintAbout===`stdin`&&n.add(i),t.resolve(i),t.markDone();break}}}#_(e,t){let n=this.#e,r=r=>{this.#e===n&&this.#u===e&&n?.postMessage({type:`module`,name:t,...r})};this.loadModule(t).then(e=>r({code:e}),e=>r({error:e instanceof Error?e.message:String(e)}))}#v(e,t){let n=this.#e,r=r=>{this.#e===n&&this.#u===e&&n?.postMessage({type:`stdin-response`,request:t,text:r})},i=e.options.onStdinRequest;i?i().then(r,()=>r(null)):r(null)}#y(e,t){e.reject(t),e.markDone()}async#b(){if(!this.#d){this.#d=!0;try{for(;this.#l.length;){let e=this.#l.shift();this.#u=e;try{if(await this.load(),e.settled)continue;e.started=!0,e.options.onStart?.(),e.options.timeoutMs&&Number.isFinite(e.options.timeoutMs)&&e.options.timeoutMs>0&&(e.timer=setTimeout(()=>{this.#u!==e||e.settled||(this.#g({type:`error`,id:e.id,message:`Run exceeded its wall-clock time limit.`,durationMs:e.options.timeoutMs}),this.#m())},e.options.timeoutMs)),this.#e.postMessage({type:`run`,id:e.id,code:e.code,stdin:e.options.stdin,files:e.options.files,entry:e.options.entry,...e.options.compilerLanguage?{compilerLanguage:e.options.compilerLanguage}:{},...e.options.practice?{practice:e.options.practice}:{}}),await e.done}catch(t){this.#y(e,t)}finally{this.#u=null}}}finally{this.#d=!1}}}};export{i as t};
|