@innovatorved/code-lab 0.1.5 → 0.1.7
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/ARCHITECTURE.md +1 -1
- package/README.md +1 -1
- package/dist/code-lab.d.ts +3 -1
- package/dist/code-lab.esm.js +811 -74
- package/dist/code-lab.js +801 -73
- package/dist/extensions/guided-lab.esm.js +3 -0
- package/dist/extensions/guided-lab.js +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/preview-sw.js +56 -8
- package/dist/runtime.d.ts +7 -27
- package/dist/runtime.esm.js +458 -16
- package/dist/runtime.js +415 -5
- package/dist/schemas.d.ts +10 -1
- package/dist/schemas.esm.js +4194 -0
- package/dist/schemas.js +4210 -0
- package/dist/shell.d.ts +18 -47
- package/dist/shell.esm.js +139 -29
- package/dist/shell.js +139 -29
- package/dist/terminal.d.ts +11 -87
- package/dist/terminal.esm.js +10 -2
- package/dist/terminal.js +3 -1
- package/package.json +12 -5
- package/src/index.ts +1 -1
- package/src/preview-sw.js +56 -8
- package/src/runtime.ts +478 -79
- package/src/schemas.ts +4 -1
- package/src/shell.ts +412 -359
- package/src/terminal.ts +885 -919
- package/src/workbench.ts +244 -40
- package/src/runtime.js +0 -7821
- package/src/shell.js +0 -7166
- package/src/terminal.js +0 -1046
- package/src/workbench.js +0 -7353
package/dist/terminal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @innovatorved/code-lab - Pure-JS
|
|
2
|
+
* @innovatorved/code-lab - Pure-JS PTY Terminal Emulator Component
|
|
3
3
|
*
|
|
4
4
|
* High-fidelity, self-contained terminal emulator engine providing:
|
|
5
5
|
* - Inline prompt with cwd awareness (codelab:${cwd}$ )
|
|
@@ -13,90 +13,14 @@
|
|
|
13
13
|
*
|
|
14
14
|
* (C) 2026 InnovatorVed / CodeLab. MIT License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
text: string;
|
|
18
|
-
type?: string;
|
|
19
|
-
}
|
|
20
|
-
export interface CompletionResult {
|
|
21
|
-
matches: string[];
|
|
22
|
-
token: string;
|
|
23
|
-
tokenStart: number;
|
|
24
|
-
}
|
|
25
|
-
export interface TerminalOptions {
|
|
26
|
-
container?: any;
|
|
27
|
-
logs?: TerminalLogItem[];
|
|
28
|
-
cwd?: string;
|
|
29
|
-
replMode?: boolean;
|
|
30
|
-
prompt?: string | null;
|
|
31
|
-
history?: string[];
|
|
32
|
-
onCommand?: ((command: string) => void) | null;
|
|
33
|
-
getCompletions?: ((buffer: string, cursor: number) => CompletionResult | null) | null;
|
|
34
|
-
onKey?: ((event: any) => boolean | void) | null;
|
|
35
|
-
onInterrupt?: (() => void) | null;
|
|
36
|
-
}
|
|
16
|
+
declare const _hostTerminal: any;
|
|
37
17
|
export declare const ANSI_CODE_MAP: Record<number, string>;
|
|
38
|
-
export declare const
|
|
39
|
-
export declare
|
|
40
|
-
export declare
|
|
41
|
-
export declare
|
|
42
|
-
export declare
|
|
43
|
-
export declare const
|
|
44
|
-
export declare
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
logs: TerminalLogItem[];
|
|
48
|
-
cwd: string;
|
|
49
|
-
replMode: boolean;
|
|
50
|
-
promptOverride: string | null;
|
|
51
|
-
history: string[];
|
|
52
|
-
historyIdx: number;
|
|
53
|
-
savedBuffer: string;
|
|
54
|
-
buffer: string;
|
|
55
|
-
cursor: number;
|
|
56
|
-
searchMode: boolean;
|
|
57
|
-
searchQuery: string;
|
|
58
|
-
searchMatchIdx: number;
|
|
59
|
-
_readLineQueue: Array<(line: string) => void>;
|
|
60
|
-
onCommand: ((command: string) => void) | null;
|
|
61
|
-
getCompletions: ((buffer: string, cursor: number) => CompletionResult | null) | null;
|
|
62
|
-
onKey: ((event: any) => boolean | void) | null;
|
|
63
|
-
onInterrupt: (() => void) | null;
|
|
64
|
-
_activeLineCommitted: boolean;
|
|
65
|
-
_cursorCol: number;
|
|
66
|
-
_pendingEscape: string;
|
|
67
|
-
_targetLineIdx: number;
|
|
68
|
-
_needsRewrite: boolean;
|
|
69
|
-
_activeLineEl: any;
|
|
70
|
-
_mounted: boolean;
|
|
71
|
-
_listeners: Array<any>;
|
|
72
|
-
constructor(container?: any, options?: TerminalOptions);
|
|
73
|
-
getPrompt(): string;
|
|
74
|
-
setPrompt(p: string | null): void;
|
|
75
|
-
setCwd(cwd: string): void;
|
|
76
|
-
setReplMode(enabled: boolean): void;
|
|
77
|
-
writeStreamChunk(data: any, type?: string): void;
|
|
78
|
-
write(data: any, type?: string): void;
|
|
79
|
-
writeln(data: any, type?: string): void;
|
|
80
|
-
_getActiveLine(type: string): TerminalLogItem;
|
|
81
|
-
_appendDomLine(line: TerminalLogItem): void;
|
|
82
|
-
_updateActiveDomLine(): void;
|
|
83
|
-
_getActiveLineSync(): TerminalLogItem | null;
|
|
84
|
-
_scrollToBottom(): void;
|
|
85
|
-
clear(): void;
|
|
86
|
-
getHistory(): string[];
|
|
87
|
-
readLine(promptText?: string): Promise<string>;
|
|
88
|
-
focus(): void;
|
|
89
|
-
mount(container: any): void;
|
|
90
|
-
_cleanupListeners(): void;
|
|
91
|
-
destroy(): void;
|
|
92
|
-
_addListener(target: any, type: string, handler: any): void;
|
|
93
|
-
_bindEvents(): void;
|
|
94
|
-
_findReverseSearchMatch(query: string, startIdx?: number): number;
|
|
95
|
-
handleKeyDown(e: any): void;
|
|
96
|
-
autoComplete(): void;
|
|
97
|
-
submitLine(): void;
|
|
98
|
-
updateActiveLine(): void;
|
|
99
|
-
render(): void;
|
|
100
|
-
}
|
|
101
|
-
export declare function createTerminal(container?: any, options?: TerminalOptions): PTYTerminalEngine;
|
|
102
|
-
export declare const createPTYTerminalEngine: typeof createTerminal;
|
|
18
|
+
export declare const ansi256ToColor: (n: number | string) => string | null;
|
|
19
|
+
export declare const escapeHtml: (str: any) => string;
|
|
20
|
+
export declare const resolveAnsiControlCodes: (raw: any) => string;
|
|
21
|
+
export declare const ansiToHtml: (str: any) => string;
|
|
22
|
+
export declare const parseAnsiToHtml: (str: any) => string;
|
|
23
|
+
export declare const PTYTerminalEngine: any;
|
|
24
|
+
export declare const createTerminal: (container?: any, options?: any) => any;
|
|
25
|
+
export declare const createPTYTerminalEngine: (container?: any, options?: any) => any;
|
|
26
|
+
export default _hostTerminal;
|
package/dist/terminal.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ============================================================
|
|
3
|
-
* @innovatorved/code-lab
|
|
3
|
+
* @innovatorved/code-lab v0.1.7 — Standalone Browser Code IDE & Virtual Runtime
|
|
4
4
|
* ============================================================
|
|
5
5
|
* Features:
|
|
6
6
|
* - Sandboxed Web Worker Execution Engine with Multi-Instance Isolation & Watchdog Timer
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : {};
|
|
18
18
|
(function () {
|
|
19
|
+
// @ts-nocheck
|
|
19
20
|
/**
|
|
20
21
|
* @innovatorved/code-lab - Pure-JS PTY Terminal Emulator Component
|
|
21
22
|
*
|
|
@@ -1063,6 +1064,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
1063
1064
|
};
|
|
1064
1065
|
});
|
|
1065
1066
|
|
|
1067
|
+
|
|
1066
1068
|
})();
|
|
1067
1069
|
|
|
1068
1070
|
const CodeLabTerminal = _root.CodeLabTerminal;
|
|
@@ -1071,6 +1073,9 @@ const createTerminal = CodeLabTerminal.createTerminal;
|
|
|
1071
1073
|
const createPTYTerminalEngine = CodeLabTerminal.createPTYTerminalEngine;
|
|
1072
1074
|
const ansiToHtml = CodeLabTerminal.ansiToHtml;
|
|
1073
1075
|
const parseAnsiToHtml = CodeLabTerminal.parseAnsiToHtml;
|
|
1076
|
+
const escapeHtml = CodeLabTerminal.escapeHtml;
|
|
1077
|
+
const ANSI_CODE_MAP = CodeLabTerminal.ANSI_CODE_MAP;
|
|
1078
|
+
const resolveAnsiControlCodes = CodeLabTerminal.resolveAnsiControlCodes;
|
|
1074
1079
|
|
|
1075
1080
|
export {
|
|
1076
1081
|
CodeLabTerminal,
|
|
@@ -1078,6 +1083,9 @@ export {
|
|
|
1078
1083
|
createTerminal,
|
|
1079
1084
|
createPTYTerminalEngine,
|
|
1080
1085
|
ansiToHtml,
|
|
1081
|
-
parseAnsiToHtml
|
|
1086
|
+
parseAnsiToHtml,
|
|
1087
|
+
escapeHtml,
|
|
1088
|
+
ANSI_CODE_MAP,
|
|
1089
|
+
resolveAnsiControlCodes
|
|
1082
1090
|
};
|
|
1083
1091
|
export default CodeLabTerminal;
|
package/dist/terminal.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ============================================================
|
|
3
|
-
* @innovatorved/code-lab
|
|
3
|
+
* @innovatorved/code-lab v0.1.7 — Standalone Browser Code IDE & Virtual Runtime
|
|
4
4
|
* ============================================================
|
|
5
5
|
* Features:
|
|
6
6
|
* - Sandboxed Web Worker Execution Engine with Multi-Instance Isolation & Watchdog Timer
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
(function (root) {
|
|
18
18
|
'use strict';
|
|
19
19
|
(function () {
|
|
20
|
+
// @ts-nocheck
|
|
20
21
|
/**
|
|
21
22
|
* @innovatorved/code-lab - Pure-JS PTY Terminal Emulator Component
|
|
22
23
|
*
|
|
@@ -1064,6 +1065,7 @@
|
|
|
1064
1065
|
};
|
|
1065
1066
|
});
|
|
1066
1067
|
|
|
1068
|
+
|
|
1067
1069
|
})();
|
|
1068
1070
|
|
|
1069
1071
|
if (typeof module !== 'undefined' && module.exports) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@innovatorved/code-lab",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Standalone browser-native IDE Workbench, POSIX Shell & Coreutils, PTY Terminal, and Web Worker Node.js/Bun Virtual Runtime.",
|
|
5
5
|
"main": "./dist/code-lab.js",
|
|
6
6
|
"module": "./dist/code-lab.esm.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"./schemas": {
|
|
41
41
|
"types": "./dist/schemas.d.ts",
|
|
42
|
-
"import": "./dist/schemas.js",
|
|
42
|
+
"import": "./dist/schemas.esm.js",
|
|
43
43
|
"require": "./dist/schemas.js",
|
|
44
44
|
"default": "./dist/schemas.js"
|
|
45
45
|
},
|
|
@@ -50,7 +50,8 @@
|
|
|
50
50
|
"./sample": "./dist/sample.html",
|
|
51
51
|
"./preview-sw.js": "./dist/preview-sw.js",
|
|
52
52
|
"./preview-sw": "./dist/preview-sw.js",
|
|
53
|
-
"./sw": "./dist/preview-sw.js"
|
|
53
|
+
"./sw": "./dist/preview-sw.js",
|
|
54
|
+
"./package.json": "./package.json"
|
|
54
55
|
},
|
|
55
56
|
"files": [
|
|
56
57
|
"dist",
|
|
@@ -71,14 +72,20 @@
|
|
|
71
72
|
"scripts": {
|
|
72
73
|
"build": "bun run tools/bundle.js",
|
|
73
74
|
"typecheck": "bun x tsc --noEmit",
|
|
74
|
-
"test": "bun run tests/
|
|
75
|
-
"test:all": "bun run
|
|
75
|
+
"test": "bun run tools/bundle.js && bun run tests/run-all.js",
|
|
76
|
+
"test:all": "bun run test",
|
|
77
|
+
"test:unit": "bun run tests/run-all.js --filter=test-",
|
|
78
|
+
"test:e2e": "bun run tools/bundle.js && bun run tests/e2e/run-all-e2e.js",
|
|
79
|
+
"test:browser": "bunx playwright test --project=chromium",
|
|
80
|
+
"test:browser:all": "bunx playwright test",
|
|
81
|
+
"test:browser:install": "bunx playwright install --with-deps chromium firefox webkit",
|
|
76
82
|
"pack:check": "bun pm pack --dry-run"
|
|
77
83
|
},
|
|
78
84
|
"dependencies": {
|
|
79
85
|
"zod": "^3.23.8"
|
|
80
86
|
},
|
|
81
87
|
"devDependencies": {
|
|
88
|
+
"@playwright/test": "^1.64.1",
|
|
82
89
|
"@types/node": "^22.7.5",
|
|
83
90
|
"esbuild": "^0.24.0",
|
|
84
91
|
"typescript": "^5.6.3"
|
package/src/index.ts
CHANGED
package/src/preview-sw.js
CHANGED
|
@@ -17,6 +17,49 @@
|
|
|
17
17
|
const PREVIEW_PREFIX = '/__preview/';
|
|
18
18
|
const DISPATCH_TIMEOUT_MS = 15000;
|
|
19
19
|
|
|
20
|
+
// Content-Security-Policy applied to every HTML preview response.
|
|
21
|
+
//
|
|
22
|
+
// The preview is untrusted user code. Inline/eval are allowed because previews
|
|
23
|
+
// are built from arbitrary user source, but network access is restricted to
|
|
24
|
+
// the preview origin plus data:/blob: so a preview cannot exfiltrate host data
|
|
25
|
+
// to a third party. Keep this string in sync with PREVIEW_CSP in workbench.js.
|
|
26
|
+
const PREVIEW_CSP = [
|
|
27
|
+
"default-src 'self' data: blob:",
|
|
28
|
+
"base-uri 'self'",
|
|
29
|
+
"object-src 'none'",
|
|
30
|
+
"script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:",
|
|
31
|
+
"style-src 'self' 'unsafe-inline'",
|
|
32
|
+
"img-src 'self' data: blob:",
|
|
33
|
+
"font-src 'self' data:",
|
|
34
|
+
"connect-src 'self' data: blob:",
|
|
35
|
+
"media-src 'self' data: blob:",
|
|
36
|
+
"worker-src 'self' blob:",
|
|
37
|
+
"frame-src 'self' data: blob:",
|
|
38
|
+
"form-action 'self'",
|
|
39
|
+
"frame-ancestors 'self'"
|
|
40
|
+
].join('; ');
|
|
41
|
+
|
|
42
|
+
function injectPreviewHead(html, port) {
|
|
43
|
+
const tags = [];
|
|
44
|
+
if (!/<meta[^>]+http-equiv=["']?content-security-policy/i.test(html)) {
|
|
45
|
+
tags.push(`<meta http-equiv="Content-Security-Policy" content="${PREVIEW_CSP}">`);
|
|
46
|
+
}
|
|
47
|
+
if (!/<base\b/i.test(html)) {
|
|
48
|
+
tags.push(`<base href="${PREVIEW_PREFIX}${port}/">`);
|
|
49
|
+
}
|
|
50
|
+
if (tags.length === 0) return html;
|
|
51
|
+
|
|
52
|
+
const injection = tags.join('');
|
|
53
|
+
if (/<head\b[^>]*>/i.test(html)) {
|
|
54
|
+
return html.replace(/<head\b[^>]*>/i, (match) => match + injection);
|
|
55
|
+
}
|
|
56
|
+
if (/<html\b[^>]*>/i.test(html)) {
|
|
57
|
+
return html.replace(/<html\b[^>]*>/i, (match) => `${match}<head>${injection}</head>`);
|
|
58
|
+
}
|
|
59
|
+
return `<head>${injection}</head>${html}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
20
63
|
self.addEventListener('install', () => {
|
|
21
64
|
self.skipWaiting();
|
|
22
65
|
});
|
|
@@ -32,12 +75,18 @@ function parsePreviewPath(pathname) {
|
|
|
32
75
|
}
|
|
33
76
|
|
|
34
77
|
function previewErrorResponse(status, title, message) {
|
|
35
|
-
const body = `<!doctype html><meta charset="utf-8"
|
|
78
|
+
const body = `<!doctype html><meta charset="utf-8">` +
|
|
79
|
+
`<meta http-equiv="Content-Security-Policy" content="${PREVIEW_CSP}">` +
|
|
80
|
+
`<title>${title}</title>` +
|
|
36
81
|
`<body style="font-family:system-ui,-apple-system,sans-serif;padding:32px;color:#666;background:#0a0a0a">` +
|
|
37
82
|
`<h1 style="color:#e5e5e5;font-size:18px">${title}</h1><p>${message}</p></body>`;
|
|
38
83
|
return new Response(body, {
|
|
39
84
|
status,
|
|
40
|
-
headers: {
|
|
85
|
+
headers: {
|
|
86
|
+
'Content-Type': 'text/html; charset=utf-8',
|
|
87
|
+
'Content-Security-Policy': PREVIEW_CSP,
|
|
88
|
+
'X-Content-Type-Options': 'nosniff'
|
|
89
|
+
}
|
|
41
90
|
});
|
|
42
91
|
}
|
|
43
92
|
|
|
@@ -102,13 +151,12 @@ async function proxyVirtualRequest(event, port, targetPath) {
|
|
|
102
151
|
const responseHeaders = new Headers((response && response.headers) || {});
|
|
103
152
|
const contentType = responseHeaders.get('content-type') || '';
|
|
104
153
|
|
|
105
|
-
// Inject a <base> so relative asset URLs in HTML responses resolve
|
|
106
|
-
// `/__preview/:port/` namespace rather than the host document root.
|
|
154
|
+
// Inject a CSP and a <base> so relative asset URLs in HTML responses resolve
|
|
155
|
+
// under the `/__preview/:port/` namespace rather than the host document root.
|
|
107
156
|
if (/text\/html/i.test(contentType) && typeof responseBody === 'string') {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
157
|
+
responseBody = injectPreviewHead(responseBody, port);
|
|
158
|
+
responseHeaders.set('Content-Security-Policy', PREVIEW_CSP);
|
|
159
|
+
responseHeaders.set('X-Content-Type-Options', 'nosniff');
|
|
112
160
|
}
|
|
113
161
|
|
|
114
162
|
return new Response(responseBody, {
|