code-playpad 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,318 +0,0 @@
1
- import{a as e}from"./config-DZqcFPEP.js";import{t}from"./worker-runtime-HpUlPmaH.js";var n=String.raw`
2
- let currentId = null;
3
- let stdinLines = [];
4
- let stdinExhausted = false;
5
- let nextRequest = 1;
6
- let inputWaitMs = 0;
7
- const pendingLines = new Map();
8
-
9
- let sucrasePromise = null;
10
- let sucraseURL = 'https://esm.sh/sucrase@3.35.1?bundle';
11
-
12
- function post(msg) { self.postMessage(msg); }
13
-
14
- // new Function() wraps the body in a header, which shifts every line number in
15
- // a stack trace. Engines differ, so measure the shift instead of assuming it.
16
- let functionLineOffset = 0;
17
- try {
18
- new Function('throw new Error("probe")')();
19
- } catch (probe) {
20
- const match = /<anonymous>:(\d+):/.exec(probe.stack || '');
21
- if (match) functionLineOffset = Number(match[1]) - 1;
22
- }
23
-
24
- let currentFiles = [];
25
-
26
- /* ---------------------------------------------------------------- output */
27
-
28
- const FLUSH_BYTES = 8192;
29
- const FLUSH_MS = 16;
30
- let outputQueue = [];
31
- let queuedChars = 0;
32
- let lastFlush = 0;
33
-
34
- function writeOutput(type, text) {
35
- const last = outputQueue[outputQueue.length - 1];
36
- if (last && last.type === type) last.text += text;
37
- else outputQueue.push({ type: type, text: text });
38
- queuedChars += text.length;
39
- const now = performance.now();
40
- if (queuedChars >= FLUSH_BYTES || now - lastFlush >= FLUSH_MS) flushOutput();
41
- }
42
-
43
- function flushOutput() {
44
- lastFlush = performance.now();
45
- if (!outputQueue.length) return;
46
- const queue = outputQueue;
47
- outputQueue = [];
48
- queuedChars = 0;
49
- for (const chunk of queue) post({ type: chunk.type, id: currentId, text: chunk.text });
50
- }
51
-
52
- /* ------------------------------------------------------- value formatting */
53
-
54
- /** bare=true prints a top-level string without quotes, the way console.log
55
- * does; everywhere else strings are quoted, the way a REPL shows a value. */
56
- function format(value, seen, bare) {
57
- seen = seen || new Set();
58
- if (typeof value === 'string') return bare ? value : JSON.stringify(value);
59
- if (typeof value === 'bigint') return String(value) + 'n';
60
- if (typeof value === 'function') return '[Function' + (value.name ? ': ' + value.name : '') + ']';
61
- if (typeof value === 'symbol') return String(value);
62
- if (value === null || value === undefined || typeof value !== 'object') return String(value);
63
- if (seen.has(value)) return '[Circular]';
64
-
65
- seen.add(value);
66
- try {
67
- if (value instanceof Error) return value.stack || (value.name + ': ' + value.message);
68
- if (Array.isArray(value)) return '[ ' + value.map((v) => format(v, seen)).join(', ') + ' ]';
69
- if (value instanceof Map)
70
- return 'Map(' + value.size + ') { ' +
71
- [...value].map(([k, v]) => format(k, seen) + ' => ' + format(v, seen)).join(', ') + ' }';
72
- if (value instanceof Set)
73
- return 'Set(' + value.size + ') { ' + [...value].map((v) => format(v, seen)).join(', ') + ' }';
74
- if (value instanceof Date) return value.toISOString();
75
- if (value instanceof Promise) return 'Promise { … }';
76
-
77
- const entries = Object.entries(value).map(([k, v]) => k + ': ' + format(v, seen));
78
- const name = value.constructor && value.constructor.name;
79
- const prefix = name && name !== 'Object' ? name + ' ' : '';
80
- return prefix + '{ ' + entries.join(', ') + ' }';
81
- } finally {
82
- seen.delete(value);
83
- }
84
- }
85
-
86
- function formatArgs(args) {
87
- return args.map((a) => format(a, null, true)).join(' ') + '\n';
88
- }
89
-
90
- /* --------------------------------------------------------------- console */
91
-
92
- const nativeConsole = self.console;
93
- self.console = Object.assign(Object.create(nativeConsole), {
94
- log: (...a) => writeOutput('stdout', formatArgs(a)),
95
- info: (...a) => writeOutput('stdout', formatArgs(a)),
96
- debug: (...a) => writeOutput('stdout', formatArgs(a)),
97
- warn: (...a) => writeOutput('stderr', formatArgs(a)),
98
- error: (...a) => writeOutput('stderr', formatArgs(a))
99
- });
100
-
101
- /* ----------------------------------------------------------------- stdin */
102
-
103
- self._ppReadLine = async () => {
104
- if (stdinLines.length) {
105
- const line = stdinLines.shift();
106
- writeOutput('echo', line + '\n');
107
- return line;
108
- }
109
- const request = nextRequest++;
110
- flushOutput();
111
- const started = performance.now();
112
- const line = await new Promise((resolve) => {
113
- pendingLines.set(request, resolve);
114
- post({ type: 'stdin-request', id: currentId, request: request });
115
- });
116
- inputWaitMs += performance.now() - started;
117
- if (typeof line !== 'string') stdinExhausted = true;
118
- return typeof line === 'string' ? line : null;
119
- };
120
-
121
- /** Provided as a global: "const name = await input('name? ')". */
122
- async function input(prompt) {
123
- if (prompt !== undefined) writeOutput('stdout', String(prompt));
124
- const line = await self._ppReadLine();
125
- if (line === null) throw new Error('EOF: no more input');
126
- return line;
127
- }
128
- self.input = input;
129
-
130
- /* ------------------------------------------------- typescript / modules */
131
-
132
- async function loadSucrase() {
133
- if (!sucrasePromise) sucrasePromise = import(sucraseURL);
134
- return sucrasePromise;
135
- }
136
-
137
- /** Several files, or ES module syntax, means it has to run as a module — which
138
- * costs the trailing expression's value, exactly as in Node. A lone script,
139
- * even a TypeScript one, keeps it. */
140
- function isModule(files, entry) {
141
- if (Object.keys(files).length > 1) return true;
142
- return /^\s*(import|export)\s/m.test(files[entry] || '');
143
- }
144
-
145
- function needsTypeScript(name) {
146
- return /\.(ts|tsx|jsx|mts|cts)$/.test(name);
147
- }
148
-
149
- function transformsFor(name) {
150
- const list = ['imports'];
151
- if (/\.tsx?$|\.mts$|\.cts$/.test(name)) list.push('typescript');
152
- if (/\.[jt]sx$/.test(name)) list.push('jsx');
153
- return list;
154
- }
155
-
156
- /** A tiny CommonJS loader over the widget's files, so relative imports,
157
- * re-exports and cycles behave the way they do in a real project. */
158
- async function runAsModules(files, entry) {
159
- const { transform } = await loadSucrase();
160
- const cache = new Map();
161
-
162
- const resolve = (from, request) => {
163
- if (!request.startsWith('.')) return null; // bare specifier: leave to the browser
164
- const base = from.includes('/') ? from.slice(0, from.lastIndexOf('/') + 1) : '';
165
- const parts = (base + request).split('/');
166
- const out = [];
167
- for (const part of parts) {
168
- if (part === '.' || part === '') continue;
169
- if (part === '..') out.pop();
170
- else out.push(part);
171
- }
172
- const path = out.join('/');
173
- const candidates = [path, path + '.js', path + '.ts', path + '.tsx', path + '.jsx',
174
- path + '.json', path + '/index.js', path + '/index.ts'];
175
- return candidates.find((c) => c in files) || null;
176
- };
177
-
178
- function load(name) {
179
- if (cache.has(name)) return cache.get(name).exports;
180
- const module = { exports: {} };
181
- cache.set(name, module);
182
-
183
- // A .json import is data, not code — same as Node and every bundler.
184
- if (name.endsWith('.json')) {
185
- try {
186
- module.exports = JSON.parse(files[name]);
187
- } catch (err) {
188
- throw new SyntaxError('Invalid JSON in ' + name + ': ' + err.message);
189
- }
190
- return module.exports;
191
- }
192
-
193
- const { code } = transform(files[name], {
194
- transforms: transformsFor(name),
195
- filePath: name,
196
- preserveDynamicImport: true
197
- });
198
-
199
- const require = (request) => {
200
- const target = resolve(name, request);
201
- if (!target) throw new Error('Cannot find module "' + request + '" from "' + name + '"');
202
- return load(target);
203
- };
204
-
205
- const fn = new Function('exports', 'require', 'module', '__filename', 'input', 'console',
206
- code + '\n//# sourceURL=' + name);
207
- fn(module.exports, require, module, name, input, self.console);
208
- return module.exports;
209
- }
210
-
211
- load(entry);
212
- return undefined; // a module's completion value is not meaningful
213
- }
214
-
215
- /* ------------------------------------------------------------------- run */
216
-
217
- async function run(msg) {
218
- currentId = msg.id;
219
- stdinLines = msg.stdin ? String(msg.stdin).replace(/\n$/, '').split('\n') : [];
220
- stdinExhausted = false;
221
- inputWaitMs = 0;
222
- for (const resolve of pendingLines.values()) resolve(null);
223
- pendingLines.clear();
224
-
225
- const files = msg.files && Object.keys(msg.files).length ? msg.files : { 'main.js': msg.code };
226
- const entry = msg.entry && files[msg.entry] ? msg.entry : Object.keys(files)[0];
227
- const started = performance.now();
228
- currentFiles = Object.keys(files);
229
- const moduleMode = isModule(files, entry);
230
-
231
- try {
232
- let value;
233
- if (moduleMode) {
234
- value = await runAsModules(files, entry);
235
- } else {
236
- // Single script: strip types if needed, then indirect eval, which keeps
237
- // the completion value — that is what makes a trailing expression print
238
- // like a REPL.
239
- let code = files[entry];
240
- if (needsTypeScript(entry)) {
241
- const { transform } = await loadSucrase();
242
- code = transform(code, { transforms: transformsFor(entry).filter((t) => t !== 'imports'), filePath: entry }).code;
243
- }
244
- const source = code + '\n//# sourceURL=' + entry;
245
- try {
246
- value = (0, eval)(source);
247
- } catch (err) {
248
- if (err instanceof SyntaxError && /await|import/i.test(err.message)) {
249
- const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
250
- value = await new AsyncFunction('input', source)(input);
251
- } else {
252
- throw err;
253
- }
254
- }
255
- if (value && typeof value.then === 'function') value = await value;
256
- }
257
-
258
- flushOutput();
259
- post({
260
- type: 'result',
261
- id: msg.id,
262
- value: value === undefined ? undefined : format(value),
263
- durationMs: performance.now() - started - inputWaitMs
264
- });
265
- } catch (err) {
266
- flushOutput();
267
- post({
268
- type: 'error',
269
- id: msg.id,
270
- message: formatError(err, moduleMode),
271
- hint: stdinExhausted && /EOF/.test(String(err && err.message))
272
- ? 'input() asked for a line that standard input did not have. Add one line per input() call in the box above, then run again.'
273
- : undefined,
274
- durationMs: performance.now() - started - inputWaitMs
275
- });
276
- } finally {
277
- currentId = null;
278
- }
279
- }
280
-
281
- function formatError(err, moduleMode) {
282
- if (!(err instanceof Error)) return 'Uncaught ' + format(err);
283
- const stack = err.stack || (err.name + ': ' + err.message);
284
- const offset = moduleMode ? functionLineOffset : 0;
285
-
286
- const lines = [];
287
- for (const line of stack.split('\n')) {
288
- // Frames in this worker's own plumbing are noise; the user's files are not.
289
- const mine = currentFiles.some((name) => line.includes(name + ':'));
290
- if (!mine && /\bat |blob:/.test(line)) continue;
291
-
292
- lines.push(
293
- offset
294
- ? line.replace(/([\w./-]+):(\d+):(\d+)/g, (whole, file, ln, col) =>
295
- currentFiles.indexOf(file) === -1 ? whole : file + ':' + (Number(ln) - offset) + ':' + col)
296
- : line
297
- );
298
- }
299
- return lines.join('\n').replace(/\s+$/, '');
300
- }
301
-
302
- self.onmessage = async (event) => {
303
- const msg = event.data;
304
- try {
305
- if (msg.type === 'init') {
306
- if (msg.sucraseURL) sucraseURL = msg.sucraseURL;
307
- post({ type: 'ready', version: 'es2022', interactiveStdin: true });
308
- } else if (msg.type === 'run') {
309
- await run(msg);
310
- } else if (msg.type === 'stdin-response') {
311
- const resolve = pendingLines.get(msg.request);
312
- if (resolve) { pendingLines.delete(msg.request); resolve(msg.text); }
313
- }
314
- } catch (err) {
315
- post({ type: 'fatal', id: msg && msg.id, message: formatError(err) });
316
- }
317
- };
318
- `,r=new class extends t{id=`javascript`;get source(){return n}initPayload(){return{sucraseURL:e()}}get label(){return`JavaScript`}};function i(e,t,n){return{id:e,get label(){return t},get ready(){return r.ready},get interactiveStdin(){return r.interactiveStdin},async editorLanguage(){let{javascript:e}=await import(`@codemirror/lang-javascript`);return e({typescript:n})},load:e=>r.load(e),run:(e,t)=>r.run(e,t),stop:()=>r.stop()}}var a=i(`javascript`,`JavaScript`,!1),o=i(`typescript`,`TypeScript`,!0);export{a as javascriptRuntime,o as typescriptRuntime};
@@ -1,323 +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{a as e}from"./config-B2qK2rdk.js";import{t}from"./worker-runtime-8Mnw4vAD.js";var n=String.raw`
7
- let currentId = null;
8
- let stdinLines = [];
9
- let stdinExhausted = false;
10
- let nextRequest = 1;
11
- let inputWaitMs = 0;
12
- const pendingLines = new Map();
13
-
14
- let sucrasePromise = null;
15
- let sucraseURL = 'https://esm.sh/sucrase@3.35.1?bundle';
16
-
17
- function post(msg) { self.postMessage(msg); }
18
-
19
- // new Function() wraps the body in a header, which shifts every line number in
20
- // a stack trace. Engines differ, so measure the shift instead of assuming it.
21
- let functionLineOffset = 0;
22
- try {
23
- new Function('throw new Error("probe")')();
24
- } catch (probe) {
25
- const match = /<anonymous>:(\d+):/.exec(probe.stack || '');
26
- if (match) functionLineOffset = Number(match[1]) - 1;
27
- }
28
-
29
- let currentFiles = [];
30
-
31
- /* ---------------------------------------------------------------- output */
32
-
33
- const FLUSH_BYTES = 8192;
34
- const FLUSH_MS = 16;
35
- let outputQueue = [];
36
- let queuedChars = 0;
37
- let lastFlush = 0;
38
-
39
- function writeOutput(type, text) {
40
- const last = outputQueue[outputQueue.length - 1];
41
- if (last && last.type === type) last.text += text;
42
- else outputQueue.push({ type: type, text: text });
43
- queuedChars += text.length;
44
- const now = performance.now();
45
- if (queuedChars >= FLUSH_BYTES || now - lastFlush >= FLUSH_MS) flushOutput();
46
- }
47
-
48
- function flushOutput() {
49
- lastFlush = performance.now();
50
- if (!outputQueue.length) return;
51
- const queue = outputQueue;
52
- outputQueue = [];
53
- queuedChars = 0;
54
- for (const chunk of queue) post({ type: chunk.type, id: currentId, text: chunk.text });
55
- }
56
-
57
- /* ------------------------------------------------------- value formatting */
58
-
59
- /** bare=true prints a top-level string without quotes, the way console.log
60
- * does; everywhere else strings are quoted, the way a REPL shows a value. */
61
- function format(value, seen, bare) {
62
- seen = seen || new Set();
63
- if (typeof value === 'string') return bare ? value : JSON.stringify(value);
64
- if (typeof value === 'bigint') return String(value) + 'n';
65
- if (typeof value === 'function') return '[Function' + (value.name ? ': ' + value.name : '') + ']';
66
- if (typeof value === 'symbol') return String(value);
67
- if (value === null || value === undefined || typeof value !== 'object') return String(value);
68
- if (seen.has(value)) return '[Circular]';
69
-
70
- seen.add(value);
71
- try {
72
- if (value instanceof Error) return value.stack || (value.name + ': ' + value.message);
73
- if (Array.isArray(value)) return '[ ' + value.map((v) => format(v, seen)).join(', ') + ' ]';
74
- if (value instanceof Map)
75
- return 'Map(' + value.size + ') { ' +
76
- [...value].map(([k, v]) => format(k, seen) + ' => ' + format(v, seen)).join(', ') + ' }';
77
- if (value instanceof Set)
78
- return 'Set(' + value.size + ') { ' + [...value].map((v) => format(v, seen)).join(', ') + ' }';
79
- if (value instanceof Date) return value.toISOString();
80
- if (value instanceof Promise) return 'Promise { … }';
81
-
82
- const entries = Object.entries(value).map(([k, v]) => k + ': ' + format(v, seen));
83
- const name = value.constructor && value.constructor.name;
84
- const prefix = name && name !== 'Object' ? name + ' ' : '';
85
- return prefix + '{ ' + entries.join(', ') + ' }';
86
- } finally {
87
- seen.delete(value);
88
- }
89
- }
90
-
91
- function formatArgs(args) {
92
- return args.map((a) => format(a, null, true)).join(' ') + '\n';
93
- }
94
-
95
- /* --------------------------------------------------------------- console */
96
-
97
- const nativeConsole = self.console;
98
- self.console = Object.assign(Object.create(nativeConsole), {
99
- log: (...a) => writeOutput('stdout', formatArgs(a)),
100
- info: (...a) => writeOutput('stdout', formatArgs(a)),
101
- debug: (...a) => writeOutput('stdout', formatArgs(a)),
102
- warn: (...a) => writeOutput('stderr', formatArgs(a)),
103
- error: (...a) => writeOutput('stderr', formatArgs(a))
104
- });
105
-
106
- /* ----------------------------------------------------------------- stdin */
107
-
108
- self._ppReadLine = async () => {
109
- if (stdinLines.length) {
110
- const line = stdinLines.shift();
111
- writeOutput('echo', line + '\n');
112
- return line;
113
- }
114
- const request = nextRequest++;
115
- flushOutput();
116
- const started = performance.now();
117
- const line = await new Promise((resolve) => {
118
- pendingLines.set(request, resolve);
119
- post({ type: 'stdin-request', id: currentId, request: request });
120
- });
121
- inputWaitMs += performance.now() - started;
122
- if (typeof line !== 'string') stdinExhausted = true;
123
- return typeof line === 'string' ? line : null;
124
- };
125
-
126
- /** Provided as a global: "const name = await input('name? ')". */
127
- async function input(prompt) {
128
- if (prompt !== undefined) writeOutput('stdout', String(prompt));
129
- const line = await self._ppReadLine();
130
- if (line === null) throw new Error('EOF: no more input');
131
- return line;
132
- }
133
- self.input = input;
134
-
135
- /* ------------------------------------------------- typescript / modules */
136
-
137
- async function loadSucrase() {
138
- if (!sucrasePromise) sucrasePromise = import(sucraseURL);
139
- return sucrasePromise;
140
- }
141
-
142
- /** Several files, or ES module syntax, means it has to run as a module — which
143
- * costs the trailing expression's value, exactly as in Node. A lone script,
144
- * even a TypeScript one, keeps it. */
145
- function isModule(files, entry) {
146
- if (Object.keys(files).length > 1) return true;
147
- return /^\s*(import|export)\s/m.test(files[entry] || '');
148
- }
149
-
150
- function needsTypeScript(name) {
151
- return /\.(ts|tsx|jsx|mts|cts)$/.test(name);
152
- }
153
-
154
- function transformsFor(name) {
155
- const list = ['imports'];
156
- if (/\.tsx?$|\.mts$|\.cts$/.test(name)) list.push('typescript');
157
- if (/\.[jt]sx$/.test(name)) list.push('jsx');
158
- return list;
159
- }
160
-
161
- /** A tiny CommonJS loader over the widget's files, so relative imports,
162
- * re-exports and cycles behave the way they do in a real project. */
163
- async function runAsModules(files, entry) {
164
- const { transform } = await loadSucrase();
165
- const cache = new Map();
166
-
167
- const resolve = (from, request) => {
168
- if (!request.startsWith('.')) return null; // bare specifier: leave to the browser
169
- const base = from.includes('/') ? from.slice(0, from.lastIndexOf('/') + 1) : '';
170
- const parts = (base + request).split('/');
171
- const out = [];
172
- for (const part of parts) {
173
- if (part === '.' || part === '') continue;
174
- if (part === '..') out.pop();
175
- else out.push(part);
176
- }
177
- const path = out.join('/');
178
- const candidates = [path, path + '.js', path + '.ts', path + '.tsx', path + '.jsx',
179
- path + '.json', path + '/index.js', path + '/index.ts'];
180
- return candidates.find((c) => c in files) || null;
181
- };
182
-
183
- function load(name) {
184
- if (cache.has(name)) return cache.get(name).exports;
185
- const module = { exports: {} };
186
- cache.set(name, module);
187
-
188
- // A .json import is data, not code — same as Node and every bundler.
189
- if (name.endsWith('.json')) {
190
- try {
191
- module.exports = JSON.parse(files[name]);
192
- } catch (err) {
193
- throw new SyntaxError('Invalid JSON in ' + name + ': ' + err.message);
194
- }
195
- return module.exports;
196
- }
197
-
198
- const { code } = transform(files[name], {
199
- transforms: transformsFor(name),
200
- filePath: name,
201
- preserveDynamicImport: true
202
- });
203
-
204
- const require = (request) => {
205
- const target = resolve(name, request);
206
- if (!target) throw new Error('Cannot find module "' + request + '" from "' + name + '"');
207
- return load(target);
208
- };
209
-
210
- const fn = new Function('exports', 'require', 'module', '__filename', 'input', 'console',
211
- code + '\n//# sourceURL=' + name);
212
- fn(module.exports, require, module, name, input, self.console);
213
- return module.exports;
214
- }
215
-
216
- load(entry);
217
- return undefined; // a module's completion value is not meaningful
218
- }
219
-
220
- /* ------------------------------------------------------------------- run */
221
-
222
- async function run(msg) {
223
- currentId = msg.id;
224
- stdinLines = msg.stdin ? String(msg.stdin).replace(/\n$/, '').split('\n') : [];
225
- stdinExhausted = false;
226
- inputWaitMs = 0;
227
- for (const resolve of pendingLines.values()) resolve(null);
228
- pendingLines.clear();
229
-
230
- const files = msg.files && Object.keys(msg.files).length ? msg.files : { 'main.js': msg.code };
231
- const entry = msg.entry && files[msg.entry] ? msg.entry : Object.keys(files)[0];
232
- const started = performance.now();
233
- currentFiles = Object.keys(files);
234
- const moduleMode = isModule(files, entry);
235
-
236
- try {
237
- let value;
238
- if (moduleMode) {
239
- value = await runAsModules(files, entry);
240
- } else {
241
- // Single script: strip types if needed, then indirect eval, which keeps
242
- // the completion value — that is what makes a trailing expression print
243
- // like a REPL.
244
- let code = files[entry];
245
- if (needsTypeScript(entry)) {
246
- const { transform } = await loadSucrase();
247
- code = transform(code, { transforms: transformsFor(entry).filter((t) => t !== 'imports'), filePath: entry }).code;
248
- }
249
- const source = code + '\n//# sourceURL=' + entry;
250
- try {
251
- value = (0, eval)(source);
252
- } catch (err) {
253
- if (err instanceof SyntaxError && /await|import/i.test(err.message)) {
254
- const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
255
- value = await new AsyncFunction('input', source)(input);
256
- } else {
257
- throw err;
258
- }
259
- }
260
- if (value && typeof value.then === 'function') value = await value;
261
- }
262
-
263
- flushOutput();
264
- post({
265
- type: 'result',
266
- id: msg.id,
267
- value: value === undefined ? undefined : format(value),
268
- durationMs: performance.now() - started - inputWaitMs
269
- });
270
- } catch (err) {
271
- flushOutput();
272
- post({
273
- type: 'error',
274
- id: msg.id,
275
- message: formatError(err, moduleMode),
276
- hint: stdinExhausted && /EOF/.test(String(err && err.message))
277
- ? 'input() asked for a line that standard input did not have. Add one line per input() call in the box above, then run again.'
278
- : undefined,
279
- durationMs: performance.now() - started - inputWaitMs
280
- });
281
- } finally {
282
- currentId = null;
283
- }
284
- }
285
-
286
- function formatError(err, moduleMode) {
287
- if (!(err instanceof Error)) return 'Uncaught ' + format(err);
288
- const stack = err.stack || (err.name + ': ' + err.message);
289
- const offset = moduleMode ? functionLineOffset : 0;
290
-
291
- const lines = [];
292
- for (const line of stack.split('\n')) {
293
- // Frames in this worker's own plumbing are noise; the user's files are not.
294
- const mine = currentFiles.some((name) => line.includes(name + ':'));
295
- if (!mine && /\bat |blob:/.test(line)) continue;
296
-
297
- lines.push(
298
- offset
299
- ? line.replace(/([\w./-]+):(\d+):(\d+)/g, (whole, file, ln, col) =>
300
- currentFiles.indexOf(file) === -1 ? whole : file + ':' + (Number(ln) - offset) + ':' + col)
301
- : line
302
- );
303
- }
304
- return lines.join('\n').replace(/\s+$/, '');
305
- }
306
-
307
- self.onmessage = async (event) => {
308
- const msg = event.data;
309
- try {
310
- if (msg.type === 'init') {
311
- if (msg.sucraseURL) sucraseURL = msg.sucraseURL;
312
- post({ type: 'ready', version: 'es2022', interactiveStdin: true });
313
- } else if (msg.type === 'run') {
314
- await run(msg);
315
- } else if (msg.type === 'stdin-response') {
316
- const resolve = pendingLines.get(msg.request);
317
- if (resolve) { pendingLines.delete(msg.request); resolve(msg.text); }
318
- }
319
- } catch (err) {
320
- post({ type: 'fatal', id: msg && msg.id, message: formatError(err) });
321
- }
322
- };
323
- `,r=new class extends t{id=`javascript`;get source(){return n}initPayload(){return{sucraseURL:e()}}get label(){return`JavaScript`}};function i(e,t,n){return{id:e,get label(){return t},get ready(){return r.ready},get interactiveStdin(){return r.interactiveStdin},async editorLanguage(){let{javascript:e}=await import(`./dist-CqpVTRAq.js`);return e({typescript:n})},load:e=>r.load(e),run:(e,t)=>r.run(e,t),stop:()=>r.stop()}}var a=i(`javascript`,`JavaScript`,!1),o=i(`typescript`,`TypeScript`,!0);export{a as javascriptRuntime,o as typescriptRuntime};
@@ -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{c as e,s as t}from"./config-B2qK2rdk.js";var n=1,r=class{#e=null;#t=null;#n=`module`;#r=null;#i=!1;#a=!1;#o=``;#s=new Set;#c=[];#l=null;#u=!1;initPayload(){return{}}get ready(){return this.#i}get interactiveStdin(){return this.#a}get version(){return this.#o}load(t){t&&this.#s.add(t);let n=()=>{t&&this.#s.delete(t)};if(!this.#r){let t=new Promise((t,n)=>{let r;try{if(typeof Worker>`u`)throw Error(`Worker constructor missing`);let e=new Blob([this.source],{type:`text/javascript`});this.#t=URL.createObjectURL(e),r=new Worker(this.#t,{type:this.#n})}catch(t){n(new e(`Could not start a Web Worker: ${t.message}`));return}this.#e=r,r.onmessage=e=>{let r=e.data;if(r.type===`ready`){this.#o=r.version,this.#a=r.interactiveStdin===!0,this.#i=!0,this.#p({phase:`ready`,message:`${this.label} ready`}),t();return}if(r.type===`fatal`&&!this.#i){this.#d(r.message,t,n);return}this.#m(r)},r.onerror=e=>{let r=e.message||`Worker failed to start`;this.#i?this.#l&&this.#g(this.#l,Error(r)):this.#d(r,t,n)},r.postMessage({type:`init`,...this.initPayload()})});this.#r=t,t.catch(()=>{this.#r===t&&(this.#r=null)})}return this.#r.then(n,e=>{throw n(),e})}run(e,t={}){let r,i=new Promise(e=>{r=e});return new Promise((a,o)=>{this.#c.push({id:n++,code:e,options:t,stdout:``,stderr:``,resolve:a,reject:o,done:i,markDone:r}),this.#_()})}stop(){let e=this.#e!==null;this.#f(),this.#l&&this.#g(this.#l,new t),e&&this.load().catch(()=>{})}#d(e,t,n){if(this.#f(),this.#n===`module`){this.#n=`classic`,this.load().then(t,n);return}n(Error(e))}#f(){this.#e?.terminate(),this.#e=null,this.#t&&=(URL.revokeObjectURL(this.#t),null),this.#r=null,this.#i=!1}#p(e){for(let t of this.#s)t(e)}#m(e){if(e.type===`progress`){this.#p({phase:e.phase,message:e.message});return}let t=this.#l;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.#h(t,e.request);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)}),t.markDone();break;case`error`:case`fatal`:{let n=(t.stderr&&!t.stderr.endsWith(`
7
- `)?`
8
- `:``)+e.message+`
9
- `;t.stderr+=n,t.options.onStderr?.(n),t.resolve({stdout:t.stdout,stderr:t.stderr,hint:`hint`in e?e.hint:void 0,durationMs:Math.round(`durationMs`in e?e.durationMs:0)}),t.markDone();break}}}#h(e,t){let n=this.#e,r=r=>{this.#e===n&&this.#l===e&&n?.postMessage({type:`stdin-response`,request:t,text:r})},i=e.options.onStdinRequest;if(!i){r(null);return}i().then(r,()=>r(null))}#g(e,t){e.reject(t),e.markDone()}async#_(){if(!this.#u){this.#u=!0;try{for(;this.#c.length;){let e=this.#c.shift();this.#l=e;try{await this.load(),e.options.onStart?.(),this.#e.postMessage({type:`run`,id:e.id,code:e.code,stdin:e.options.stdin,files:e.options.files,entry:e.options.entry}),await e.done}catch(t){this.#g(e,t)}finally{this.#l=null}}}finally{this.#u=!1}}}};export{r as t};
@@ -1,4 +0,0 @@
1
- import{l as e,u as t}from"./element-DtCQVStG.js";var n=1,r=class{#e=null;#t=null;#n=`module`;#r=null;#i=!1;#a=!1;#o=``;#s=new Set;#c=[];#l=null;#u=!1;initPayload(){return{}}get ready(){return this.#i}get interactiveStdin(){return this.#a}get version(){return this.#o}load(e){e&&this.#s.add(e);let n=()=>{e&&this.#s.delete(e)};if(!this.#r){let e=new Promise((e,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){n(new t(`Could not start a Web Worker: ${e.message}`));return}this.#e=r,r.onmessage=t=>{let r=t.data;if(r.type===`ready`){this.#o=r.version,this.#a=r.interactiveStdin===!0,this.#i=!0,this.#p({phase:`ready`,message:`${this.label} ready`}),e();return}if(r.type===`fatal`&&!this.#i){this.#d(r.message,e,n);return}this.#m(r)},r.onerror=t=>{let r=t.message||`Worker failed to start`;this.#i?this.#l&&this.#g(this.#l,Error(r)):this.#d(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 r,i=new Promise(e=>{r=e});return new Promise((a,o)=>{this.#c.push({id:n++,code:e,options:t,stdout:``,stderr:``,resolve:a,reject:o,done:i,markDone:r}),this.#_()})}stop(){let t=this.#e!==null;this.#f(),this.#l&&this.#g(this.#l,new e),t&&this.load().catch(()=>{})}#d(e,t,n){if(this.#f(),this.#n===`module`){this.#n=`classic`,this.load().then(t,n);return}n(Error(e))}#f(){this.#e?.terminate(),this.#e=null,this.#t&&=(URL.revokeObjectURL(this.#t),null),this.#r=null,this.#i=!1}#p(e){for(let t of this.#s)t(e)}#m(e){if(e.type===`progress`){this.#p({phase:e.phase,message:e.message});return}let t=this.#l;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.#h(t,e.request);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)}),t.markDone();break;case`error`:case`fatal`:{let n=(t.stderr&&!t.stderr.endsWith(`
2
- `)?`
3
- `:``)+e.message+`
4
- `;t.stderr+=n,t.options.onStderr?.(n),t.resolve({stdout:t.stdout,stderr:t.stderr,hint:`hint`in e?e.hint:void 0,durationMs:Math.round(`durationMs`in e?e.durationMs:0)}),t.markDone();break}}}#h(e,t){let n=this.#e,r=r=>{this.#e===n&&this.#l===e&&n?.postMessage({type:`stdin-response`,request:t,text:r})},i=e.options.onStdinRequest;if(!i){r(null);return}i().then(r,()=>r(null))}#g(e,t){e.reject(t),e.markDone()}async#_(){if(!this.#u){this.#u=!0;try{for(;this.#c.length;){let e=this.#c.shift();this.#l=e;try{await this.load(),e.options.onStart?.(),this.#e.postMessage({type:`run`,id:e.id,code:e.code,stdin:e.options.stdin,files:e.options.files,entry:e.options.entry}),await e.done}catch(t){this.#g(e,t)}finally{this.#l=null}}}finally{this.#u=!1}}}};export{r as t};