@innovatorved/code-lab 0.1.7 → 0.1.8

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,6 +1,6 @@
1
1
  /**
2
2
  * ============================================================
3
- * @innovatorved/code-lab v0.1.7 — Standalone Browser Code IDE & Virtual Runtime
3
+ * @innovatorved/code-lab v0.1.8 — Standalone Browser Code IDE & Virtual Runtime
4
4
  * ============================================================
5
5
  * Features:
6
6
  * - Sandboxed Web Worker Execution Engine with Multi-Instance Isolation & Watchdog Timer
@@ -15,6 +15,107 @@
15
15
  * ============================================================
16
16
  */
17
17
  const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : {};
18
+ var CodeLabLogger = (() => {
19
+ var __defProp = Object.defineProperty;
20
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
21
+ var __getOwnPropNames = Object.getOwnPropertyNames;
22
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
23
+ var __export = (target, all) => {
24
+ for (var name in all)
25
+ __defProp(target, name, { get: all[name], enumerable: true });
26
+ };
27
+ var __copyProps = (to, from, except, desc) => {
28
+ if (from && typeof from === "object" || typeof from === "function") {
29
+ for (let key of __getOwnPropNames(from))
30
+ if (!__hasOwnProp.call(to, key) && key !== except)
31
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
+ }
33
+ return to;
34
+ };
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+
37
+ // src/logger.ts
38
+ var logger_exports = {};
39
+ __export(logger_exports, {
40
+ CodeLabError: () => CodeLabError,
41
+ DEFAULT_LOGGER: () => DEFAULT_LOGGER,
42
+ LOG_PREFIX: () => LOG_PREFIX,
43
+ createLogger: () => createLogger,
44
+ default: () => logger_default,
45
+ isCodeLabError: () => isCodeLabError
46
+ });
47
+ var LOG_PREFIX = "[code-lab]";
48
+ var CodeLabError = class extends Error {
49
+ code;
50
+ options;
51
+ cause;
52
+ recoverable;
53
+ details;
54
+ context;
55
+ constructor(code, message, options = {}) {
56
+ super(message);
57
+ this.name = "CodeLabError";
58
+ this.code = code;
59
+ this.options = options;
60
+ this.cause = options.cause;
61
+ this.recoverable = options.recoverable !== false;
62
+ const meta = options.details ?? options.context;
63
+ if (meta !== void 0) {
64
+ this.details = meta;
65
+ this.context = meta;
66
+ }
67
+ Object.setPrototypeOf(this, new.target.prototype);
68
+ }
69
+ };
70
+ function isCodeLabError(value) {
71
+ return Boolean(
72
+ value && typeof value === "object" && (value instanceof CodeLabError || value.name === "CodeLabError" && typeof value.code === "string")
73
+ );
74
+ }
75
+ function createLogger(options = {}) {
76
+ const sink = options.logger ?? null;
77
+ const debugEnabled = options.debug === true;
78
+ const prefix = options.prefix || LOG_PREFIX;
79
+ const write = (level, args) => {
80
+ if (level === "debug" && !debugEnabled) return;
81
+ if (sink && typeof sink[level] === "function") {
82
+ let sinkError = null;
83
+ try {
84
+ sink[level](...args);
85
+ return;
86
+ } catch (err) {
87
+ sinkError = err;
88
+ }
89
+ }
90
+ const consoleObj = typeof console !== "undefined" ? console : null;
91
+ const fn = consoleObj ? consoleObj[level] : null;
92
+ if (typeof fn === "function") {
93
+ fn.call(consoleObj, prefix, ...args);
94
+ }
95
+ };
96
+ return {
97
+ debug: (...args) => write("debug", args),
98
+ info: (...args) => write("info", args),
99
+ warn: (...args) => write("warn", args),
100
+ error: (...args) => write("error", args)
101
+ };
102
+ }
103
+ var DEFAULT_LOGGER = createLogger();
104
+ var _loggerNamespace = {
105
+ LOG_PREFIX,
106
+ CodeLabError,
107
+ isCodeLabError,
108
+ createLogger,
109
+ DEFAULT_LOGGER
110
+ };
111
+ var _globalRoot = typeof globalThis !== "undefined" ? globalThis : null;
112
+ if (_globalRoot && !_globalRoot.CodeLabLogger) {
113
+ _globalRoot.CodeLabLogger = _loggerNamespace;
114
+ }
115
+ var logger_default = _loggerNamespace;
116
+ return __toCommonJS(logger_exports);
117
+ })();
118
+
18
119
  (function () {
19
120
  // @ts-nocheck
20
121
  /**
@@ -51,6 +152,16 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
51
152
  })(typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : this), function () {
52
153
  'use strict';
53
154
 
155
+ const _termRoot = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : {});
156
+ const _terminalLogger = (_termRoot && _termRoot.CodeLabLogger && typeof _termRoot.CodeLabLogger.createLogger === 'function')
157
+ ? _termRoot.CodeLabLogger.createLogger()
158
+ : {
159
+ debug() {},
160
+ info(...args) { if (typeof console !== 'undefined' && console.info) console.info('[code-lab]', ...args); },
161
+ warn(...args) { if (typeof console !== 'undefined' && console.warn) console.warn('[code-lab]', ...args); },
162
+ error(...args) { if (typeof console !== 'undefined' && console.error) console.error('[code-lab]', ...args); }
163
+ };
164
+
54
165
  const ANSI_CODE_MAP = {
55
166
  1: 'cl-ansi-bold',
56
167
  2: 'cl-ansi-dim',
@@ -591,7 +702,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
591
702
  if (!this.container || typeof this.container.querySelector !== 'function') return;
592
703
  const input = this.container.querySelector('#cl-repl-input');
593
704
  if (input && typeof input.focus === 'function') {
594
- try { input.focus(); } catch (_) {}
705
+ try { input.focus(); } catch (err) { _terminalLogger.debug('Terminal input focus skipped.', err); }
595
706
  }
596
707
  }
597
708
 
@@ -615,9 +726,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
615
726
  }
616
727
  for (const entry of this._listeners) {
617
728
  if (typeof entry === 'function') {
618
- try { entry(); } catch (_) {}
729
+ try { entry(); } catch (err) { _terminalLogger.debug('Terminal listener cleanup callback failed.', err); }
619
730
  } else if (entry && entry.target && typeof entry.target.removeEventListener === 'function') {
620
- try { entry.target.removeEventListener(entry.type, entry.handler); } catch (_) {}
731
+ try { entry.target.removeEventListener(entry.type, entry.handler); } catch (err) { _terminalLogger.debug('Terminal removeEventListener failed.', err); }
621
732
  }
622
733
  }
623
734
  this._listeners = [];
@@ -686,7 +797,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
686
797
  try {
687
798
  const res = this.onKey(e);
688
799
  if (res === false) return;
689
- } catch (_) {}
800
+ } catch (err) {
801
+ _terminalLogger.warn('Terminal onKey callback threw.', err);
802
+ }
690
803
  }
691
804
 
692
805
  const key = e.key;
@@ -839,7 +952,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
839
952
  this.replMode = false;
840
953
  }
841
954
  if (this.onInterrupt) {
842
- try { this.onInterrupt(); } catch (_) {}
955
+ try { this.onInterrupt(); } catch (err) { _terminalLogger.warn('Terminal onInterrupt callback threw.', err); }
843
956
  }
844
957
  this.render();
845
958
  return;
@@ -1040,7 +1153,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
1040
1153
  if (typeof nextInput.setSelectionRange === 'function') {
1041
1154
  nextInput.setSelectionRange(this.cursor, this.cursor);
1042
1155
  }
1043
- } catch (_) {}
1156
+ } catch (err) {
1157
+ _terminalLogger.debug('Terminal focus/selection restore skipped.', err);
1158
+ }
1044
1159
  }
1045
1160
  }
1046
1161
  }
package/dist/terminal.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * ============================================================
3
- * @innovatorved/code-lab v0.1.7 — Standalone Browser Code IDE & Virtual Runtime
3
+ * @innovatorved/code-lab v0.1.8 — 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,107 @@
16
16
  */
17
17
  (function (root) {
18
18
  'use strict';
19
+ var CodeLabLogger = (() => {
20
+ var __defProp = Object.defineProperty;
21
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
22
+ var __getOwnPropNames = Object.getOwnPropertyNames;
23
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+
38
+ // src/logger.ts
39
+ var logger_exports = {};
40
+ __export(logger_exports, {
41
+ CodeLabError: () => CodeLabError,
42
+ DEFAULT_LOGGER: () => DEFAULT_LOGGER,
43
+ LOG_PREFIX: () => LOG_PREFIX,
44
+ createLogger: () => createLogger,
45
+ default: () => logger_default,
46
+ isCodeLabError: () => isCodeLabError
47
+ });
48
+ var LOG_PREFIX = "[code-lab]";
49
+ var CodeLabError = class extends Error {
50
+ code;
51
+ options;
52
+ cause;
53
+ recoverable;
54
+ details;
55
+ context;
56
+ constructor(code, message, options = {}) {
57
+ super(message);
58
+ this.name = "CodeLabError";
59
+ this.code = code;
60
+ this.options = options;
61
+ this.cause = options.cause;
62
+ this.recoverable = options.recoverable !== false;
63
+ const meta = options.details ?? options.context;
64
+ if (meta !== void 0) {
65
+ this.details = meta;
66
+ this.context = meta;
67
+ }
68
+ Object.setPrototypeOf(this, new.target.prototype);
69
+ }
70
+ };
71
+ function isCodeLabError(value) {
72
+ return Boolean(
73
+ value && typeof value === "object" && (value instanceof CodeLabError || value.name === "CodeLabError" && typeof value.code === "string")
74
+ );
75
+ }
76
+ function createLogger(options = {}) {
77
+ const sink = options.logger ?? null;
78
+ const debugEnabled = options.debug === true;
79
+ const prefix = options.prefix || LOG_PREFIX;
80
+ const write = (level, args) => {
81
+ if (level === "debug" && !debugEnabled) return;
82
+ if (sink && typeof sink[level] === "function") {
83
+ let sinkError = null;
84
+ try {
85
+ sink[level](...args);
86
+ return;
87
+ } catch (err) {
88
+ sinkError = err;
89
+ }
90
+ }
91
+ const consoleObj = typeof console !== "undefined" ? console : null;
92
+ const fn = consoleObj ? consoleObj[level] : null;
93
+ if (typeof fn === "function") {
94
+ fn.call(consoleObj, prefix, ...args);
95
+ }
96
+ };
97
+ return {
98
+ debug: (...args) => write("debug", args),
99
+ info: (...args) => write("info", args),
100
+ warn: (...args) => write("warn", args),
101
+ error: (...args) => write("error", args)
102
+ };
103
+ }
104
+ var DEFAULT_LOGGER = createLogger();
105
+ var _loggerNamespace = {
106
+ LOG_PREFIX,
107
+ CodeLabError,
108
+ isCodeLabError,
109
+ createLogger,
110
+ DEFAULT_LOGGER
111
+ };
112
+ var _globalRoot = typeof globalThis !== "undefined" ? globalThis : null;
113
+ if (_globalRoot && !_globalRoot.CodeLabLogger) {
114
+ _globalRoot.CodeLabLogger = _loggerNamespace;
115
+ }
116
+ var logger_default = _loggerNamespace;
117
+ return __toCommonJS(logger_exports);
118
+ })();
119
+
19
120
  (function () {
20
121
  // @ts-nocheck
21
122
  /**
@@ -52,6 +153,16 @@
52
153
  })(typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : this), function () {
53
154
  'use strict';
54
155
 
156
+ const _termRoot = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : {});
157
+ const _terminalLogger = (_termRoot && _termRoot.CodeLabLogger && typeof _termRoot.CodeLabLogger.createLogger === 'function')
158
+ ? _termRoot.CodeLabLogger.createLogger()
159
+ : {
160
+ debug() {},
161
+ info(...args) { if (typeof console !== 'undefined' && console.info) console.info('[code-lab]', ...args); },
162
+ warn(...args) { if (typeof console !== 'undefined' && console.warn) console.warn('[code-lab]', ...args); },
163
+ error(...args) { if (typeof console !== 'undefined' && console.error) console.error('[code-lab]', ...args); }
164
+ };
165
+
55
166
  const ANSI_CODE_MAP = {
56
167
  1: 'cl-ansi-bold',
57
168
  2: 'cl-ansi-dim',
@@ -592,7 +703,7 @@
592
703
  if (!this.container || typeof this.container.querySelector !== 'function') return;
593
704
  const input = this.container.querySelector('#cl-repl-input');
594
705
  if (input && typeof input.focus === 'function') {
595
- try { input.focus(); } catch (_) {}
706
+ try { input.focus(); } catch (err) { _terminalLogger.debug('Terminal input focus skipped.', err); }
596
707
  }
597
708
  }
598
709
 
@@ -616,9 +727,9 @@
616
727
  }
617
728
  for (const entry of this._listeners) {
618
729
  if (typeof entry === 'function') {
619
- try { entry(); } catch (_) {}
730
+ try { entry(); } catch (err) { _terminalLogger.debug('Terminal listener cleanup callback failed.', err); }
620
731
  } else if (entry && entry.target && typeof entry.target.removeEventListener === 'function') {
621
- try { entry.target.removeEventListener(entry.type, entry.handler); } catch (_) {}
732
+ try { entry.target.removeEventListener(entry.type, entry.handler); } catch (err) { _terminalLogger.debug('Terminal removeEventListener failed.', err); }
622
733
  }
623
734
  }
624
735
  this._listeners = [];
@@ -687,7 +798,9 @@
687
798
  try {
688
799
  const res = this.onKey(e);
689
800
  if (res === false) return;
690
- } catch (_) {}
801
+ } catch (err) {
802
+ _terminalLogger.warn('Terminal onKey callback threw.', err);
803
+ }
691
804
  }
692
805
 
693
806
  const key = e.key;
@@ -840,7 +953,7 @@
840
953
  this.replMode = false;
841
954
  }
842
955
  if (this.onInterrupt) {
843
- try { this.onInterrupt(); } catch (_) {}
956
+ try { this.onInterrupt(); } catch (err) { _terminalLogger.warn('Terminal onInterrupt callback threw.', err); }
844
957
  }
845
958
  this.render();
846
959
  return;
@@ -1041,7 +1154,9 @@
1041
1154
  if (typeof nextInput.setSelectionRange === 'function') {
1042
1155
  nextInput.setSelectionRange(this.cursor, this.cursor);
1043
1156
  }
1044
- } catch (_) {}
1157
+ } catch (err) {
1158
+ _terminalLogger.debug('Terminal focus/selection restore skipped.', err);
1159
+ }
1045
1160
  }
1046
1161
  }
1047
1162
  }
package/dist/zip.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @innovatorved/code-lab — Zero-Dependency PKZip v2.0 Archive Engine
3
+ * ============================================================================
4
+ * Pure TypeScript implementation of PKZip 2.0 (Store method 0 + UTF-8 flag
5
+ * bit 11 + IEEE 802.3 CRC32) for browser and Node/Bun project export & import.
6
+ *
7
+ * Includes built-in Zip-Slip path traversal sanitization and header integrity
8
+ * verification.
9
+ *
10
+ * Strict leaf module: fully typed, zero explicit any, zero empty catches.
11
+ */
12
+ /**
13
+ * Converts a string or byte buffer into a `Uint8Array`.
14
+ */
15
+ export declare function toUint8Array(input: string | Uint8Array | ArrayBuffer): Uint8Array;
16
+ /**
17
+ * Computes the standard IEEE 802.3 CRC32 checksum of a string or byte array.
18
+ */
19
+ export declare function computeCrc32(data: string | Uint8Array | ArrayBuffer): number;
20
+ /**
21
+ * Sanitizes an archive entry path to prevent Zip-Slip directory traversal attacks.
22
+ * Normalizes backslashes, strips drive prefixes and leading slashes, and collapses
23
+ * or removes `..` and `.` segments so the resulting path is strictly relative.
24
+ */
25
+ export declare function sanitizeZipPath(rawPath: string): string;
26
+ /**
27
+ * Creates a standard PKZip v2.0 archive from a map of file paths to contents.
28
+ */
29
+ export declare function createZip(files: Record<string, string | Uint8Array>): Promise<Uint8Array>;
30
+ /**
31
+ * Extracts a PKZip v2.0 archive into a UTF-8 file dictionary (`Record<string, string>`).
32
+ * Validates magic headers, checks boundaries, and sanitizes paths against Zip-Slip.
33
+ */
34
+ export declare function extractZip(data: Uint8Array | ArrayBuffer): Promise<Record<string, string>>;
35
+ declare const _default: {
36
+ createZip: typeof createZip;
37
+ extractZip: typeof extractZip;
38
+ computeCrc32: typeof computeCrc32;
39
+ sanitizeZipPath: typeof sanitizeZipPath;
40
+ toUint8Array: typeof toUint8Array;
41
+ };
42
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innovatorved/code-lab",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
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",
@@ -71,7 +71,9 @@
71
71
  "packageManager": "bun@1.4.3",
72
72
  "scripts": {
73
73
  "build": "bun run tools/bundle.js",
74
+ "lint": "node tools/lint.js",
74
75
  "typecheck": "bun x tsc --noEmit",
76
+ "typecheck:strict": "bun x tsc -p tsconfig.strict.json",
75
77
  "test": "bun run tools/bundle.js && bun run tests/run-all.js",
76
78
  "test:all": "bun run test",
77
79
  "test:unit": "bun run tests/run-all.js --filter=test-",
package/src/code-lab.css CHANGED
@@ -2300,6 +2300,11 @@ code-lab,
2300
2300
  background: var(--cl-red);
2301
2301
  }
2302
2302
 
2303
+ .codelab-statusbar__save.is-failed {
2304
+ color: var(--cl-amber);
2305
+ font-weight: 500;
2306
+ }
2307
+
2303
2308
  @keyframes clStatusPulse {
2304
2309
  0%, 100% { opacity: 1; transform: scale(1); }
2305
2310
  50% { opacity: 0.45; transform: scale(0.85); }
@@ -4317,6 +4322,27 @@ code-lab,
4317
4322
 
4318
4323
  .codelab-preview-modes { display: flex; gap: 2px; flex: 0 0 auto; }
4319
4324
 
4325
+ /* CSP badge: which remote hosts the current preview may reach. */
4326
+ .codelab-preview-csp {
4327
+ flex: 0 0 auto;
4328
+ max-width: 220px;
4329
+ overflow: hidden;
4330
+ text-overflow: ellipsis;
4331
+ white-space: nowrap;
4332
+ font-size: 11px;
4333
+ line-height: 18px;
4334
+ padding: 0 8px;
4335
+ border-radius: 999px;
4336
+ border: 1px solid var(--cl-border);
4337
+ color: var(--cl-fg-muted);
4338
+ background: var(--cl-bg-elevated);
4339
+ }
4340
+
4341
+ .codelab-preview-csp--blocked {
4342
+ color: var(--cl-red);
4343
+ border-color: var(--cl-red);
4344
+ }
4345
+
4320
4346
  .codelab-preview-viewport {
4321
4347
  flex: 1 1 auto;
4322
4348
  min-height: 180px;