@innovatorved/code-lab 0.1.13 → 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.
Files changed (80) hide show
  1. package/ARCHITECTURE.md +12 -7
  2. package/CHANGELOG.md +134 -0
  3. package/README.md +59 -9
  4. package/dist/code-lab.css +198 -0
  5. package/dist/code-lab.d.ts +37 -7
  6. package/dist/code-lab.esm.js +20444 -1278
  7. package/dist/code-lab.js +20439 -1276
  8. package/dist/extensions/cpp.d.ts +145 -0
  9. package/dist/extensions/cpp.esm.js +5932 -0
  10. package/dist/extensions/cpp.js +5951 -0
  11. package/dist/extensions/guided-lab.esm.js +86 -6
  12. package/dist/extensions/guided-lab.js +87 -6
  13. package/dist/extensions/javascript.d.ts +24 -0
  14. package/dist/extensions/javascript.esm.js +36 -0
  15. package/dist/extensions/javascript.js +59 -0
  16. package/dist/extensions/python.d.ts +92 -0
  17. package/dist/extensions/python.esm.js +5476 -0
  18. package/dist/extensions/python.js +5495 -0
  19. package/dist/extensions/typescript.d.ts +36 -0
  20. package/dist/extensions/typescript.esm.js +55 -0
  21. package/dist/extensions/typescript.js +78 -0
  22. package/dist/index.d.ts +9 -3
  23. package/dist/preview-sw.js +1 -1
  24. package/dist/runtime/index.d.ts +4 -0
  25. package/dist/runtime/module-loader.d.ts +11 -0
  26. package/dist/runtime/test-harness.d.ts +24 -0
  27. package/dist/runtime/vfs.d.ts +31 -0
  28. package/dist/runtime/wasi-host.d.ts +33 -0
  29. package/dist/runtime.d.ts +6 -0
  30. package/dist/runtime.esm.js +920 -15
  31. package/dist/runtime.js +914 -15
  32. package/dist/schemas.d.ts +237 -25
  33. package/dist/schemas.esm.js +85 -6
  34. package/dist/schemas.js +85 -6
  35. package/dist/shell/coreutils/compilers-cli.d.ts +24 -0
  36. package/dist/shell/index.d.ts +4 -0
  37. package/dist/shell/lexer-parser.d.ts +26 -0
  38. package/dist/shell.esm.js +289 -4
  39. package/dist/shell.js +289 -4
  40. package/dist/terminal.esm.js +1 -1
  41. package/dist/terminal.js +1 -1
  42. package/dist/workbench/command-palette.d.ts +10 -0
  43. package/dist/workbench/diff-editor.d.ts +26 -0
  44. package/dist/workbench/drawer.d.ts +18 -0
  45. package/dist/workbench/editor.d.ts +11 -0
  46. package/dist/workbench/file-tree.d.ts +11 -0
  47. package/dist/workbench/guided-pane.d.ts +11 -0
  48. package/dist/workbench/icons.d.ts +5 -0
  49. package/dist/workbench/index.d.ts +39 -0
  50. package/dist/workbench/share.d.ts +21 -0
  51. package/dist/workbench/styles.d.ts +4 -0
  52. package/dist/workbench/toolbar.d.ts +17 -0
  53. package/dist/workbench.d.ts +6 -1
  54. package/package.json +33 -3
  55. package/src/code-lab.css +198 -0
  56. package/src/extensions/cpp.ts +1786 -0
  57. package/src/extensions/guided-lab.ts +10 -0
  58. package/src/extensions/javascript.ts +54 -0
  59. package/src/extensions/python.ts +1293 -0
  60. package/src/extensions/typescript.ts +85 -0
  61. package/src/index.ts +66 -3
  62. package/src/runtime/index.ts +5 -0
  63. package/src/runtime/test-harness.ts +57 -0
  64. package/src/runtime.ts +915 -14
  65. package/src/schemas.ts +94 -7
  66. package/src/shell/coreutils/compilers-cli.ts +103 -0
  67. package/src/shell/index.ts +5 -0
  68. package/src/shell.ts +288 -3
  69. package/src/workbench/command-palette.ts +140 -0
  70. package/src/workbench/diff-editor.ts +216 -0
  71. package/src/workbench/drawer.ts +148 -0
  72. package/src/workbench/editor.ts +49 -0
  73. package/src/workbench/file-tree.ts +51 -0
  74. package/src/workbench/guided-pane.ts +33 -0
  75. package/src/workbench/icons.ts +48 -0
  76. package/src/workbench/index.ts +38 -0
  77. package/src/workbench/share.ts +99 -0
  78. package/src/workbench/styles.ts +200 -0
  79. package/src/workbench/toolbar.ts +171 -0
  80. package/src/workbench.ts +1016 -78
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @innovatorved/code-lab — Workbench SVG Icon Registry
3
+ * Complete set of lightweight, crisp SVG icons for toolbar, file tree, drawer, and modals.
4
+ */
5
+
6
+ export const CL_ICONS: Record<string, string> = {
7
+ arrowLeft: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>',
8
+ arrowRight: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg>',
9
+ target: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="6"/><circle cx="12" cy="12" r="2"/></svg>',
10
+ code: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>',
11
+ play: '<svg width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><polygon points="6 4 20 12 6 20 6 4"/></svg>',
12
+ stop: '<svg width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><rect x="5" y="5" width="14" height="14" rx="2"/></svg>',
13
+ check: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>',
14
+ lightbulb: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5"/><path d="M9 18h6"/><path d="M10 22h4"/></svg>',
15
+ list: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><line x1="3" y1="6" x2="3.01" y2="6"/><line x1="3" y1="12" x2="3.01" y2="12"/><line x1="3" y1="18" x2="3.01" y2="18"/></svg>',
16
+ book: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/></svg>',
17
+ file: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>',
18
+ terminal: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>',
19
+ database: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/></svg>',
20
+ globe: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>',
21
+ package: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m16.5 9.4-9-5.19"/><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><polyline points="3.29 7 12 12 20.71 7"/><line x1="12" y1="22" x2="12" y2="12"/></svg>',
22
+ chevronsUpDown: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/></svg>',
23
+ chevronDown: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>',
24
+ chevronRight: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>',
25
+ folder: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/></svg>',
26
+ plus: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>',
27
+ edit: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>',
28
+ trash: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>',
29
+ box: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><polyline points="3.29 7 12 12 20.71 7"/><line x1="12" y1="22" x2="12" y2="12"/></svg>',
30
+ search: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>',
31
+ diff: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="3" x2="12" y2="21"/><path d="M8 8H4v8h4"/><path d="M16 8h4v8h-4"/></svg>',
32
+ command: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 3a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3 3 3 0 0 0 3-3 3 3 0 0 0-3-3H6a3 3 0 0 0-3 3 3 3 0 0 0 3 3 3 3 0 0 0 3-3V6a3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3h12a3 3 0 0 0 3-3 3 3 0 0 0-3-3z"/></svg>',
33
+ download: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>',
34
+ refresh: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M23 4v6h-6"/><path d="M1 20v-6h6"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/></svg>',
35
+ send: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>',
36
+ activity: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg>',
37
+ radio: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="2"/><path d="M16.24 7.76a6 6 0 0 1 0 8.49m-8.48-.01a6 6 0 0 1 0-8.49m11.31-2.82a10 10 0 0 1 0 14.14m-14.14 0a10 10 0 0 1 0-14.14"/></svg>',
38
+ monitor: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>',
39
+ tablet: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="2" width="16" height="20" rx="2"/><line x1="12" y1="18" x2="12.01" y2="18"/></svg>',
40
+ smartphone: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="7" y="2" width="10" height="20" rx="2"/><line x1="12" y1="18" x2="12.01" y2="18"/></svg>',
41
+ externalLink: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>',
42
+ x: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',
43
+ warning: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>',
44
+ clock: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>',
45
+ memory: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 19v2"/><path d="M10 19v2"/><path d="M14 19v2"/><path d="M18 19v2"/><path d="M6 3v2"/><path d="M10 3v2"/><path d="M14 3v2"/><path d="M18 3v2"/><rect x="2" y="5" width="20" height="14" rx="2"/></svg>',
46
+ keyboard: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="M6 8h.01"/><path d="M10 8h.01"/><path d="M14 8h.01"/><path d="M18 8h.01"/><path d="M6 12h.01"/><path d="M10 12h.01"/><path d="M14 12h.01"/><path d="M18 12h.01"/><path d="M7 16h10"/></svg>',
47
+ share: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><line x1="8.59" y1="13.51" x2="15.42" y2="17.49"/><line x1="15.41" y1="6.51" x2="8.59" y2="10.49"/></svg>'
48
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @innovatorved/code-lab — Workbench Subsystem Entrypoint
3
+ */
4
+
5
+ export * from './icons';
6
+ export * from './styles';
7
+ export * from './toolbar';
8
+ export * from './drawer';
9
+ export * from './diff-editor';
10
+ export * from './command-palette';
11
+ export * from './share';
12
+ export * from './file-tree';
13
+ export * from './editor';
14
+ export * from './guided-pane';
15
+
16
+ import * as icons from './icons';
17
+ import * as styles from './styles';
18
+ import * as toolbar from './toolbar';
19
+ import * as drawer from './drawer';
20
+ import * as diffEditor from './diff-editor';
21
+ import * as commandPalette from './command-palette';
22
+ import * as share from './share';
23
+ import * as fileTree from './file-tree';
24
+ import * as editor from './editor';
25
+ import * as guidedPane from './guided-pane';
26
+
27
+ export const CodeLabWorkbenchComponents = {
28
+ ...icons,
29
+ ...styles,
30
+ ...toolbar,
31
+ ...drawer,
32
+ ...diffEditor,
33
+ ...commandPalette,
34
+ ...share,
35
+ ...fileTree,
36
+ ...editor,
37
+ ...guidedPane
38
+ };
@@ -0,0 +1,99 @@
1
+ /**
2
+ * @innovatorved/code-lab — Zero-Backend URL Snapshot Compressor & Decompressor
3
+ *
4
+ * Serializes workspace state { lang, activeFile, files, stdin }, compresses it
5
+ * with browser-native `CompressionStream('deflate-raw')`, and encodes as Base64url
6
+ * in the URL hash `#codelab=<base64url>`.
7
+ */
8
+
9
+ export interface WorkspaceSharePayload {
10
+ lang?: string;
11
+ activeFile?: string | null;
12
+ files: Record<string, string>;
13
+ stdin?: string;
14
+ }
15
+
16
+ function bufferToBase64Url(uint8: Uint8Array): string {
17
+ let binary = '';
18
+ for (let i = 0; i < uint8.length; i++) {
19
+ binary += String.fromCharCode(uint8[i]);
20
+ }
21
+ const base64 = typeof btoa !== 'undefined' ? btoa(binary) : Buffer.from(uint8).toString('base64');
22
+ return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
23
+ }
24
+
25
+ function base64UrlToBuffer(base64url: string): Uint8Array {
26
+ let base64 = base64url.replace(/-/g, '+').replace(/_/g, '/');
27
+ while (base64.length % 4) {
28
+ base64 += '=';
29
+ }
30
+ if (typeof atob !== 'undefined') {
31
+ const binary = atob(base64);
32
+ const bytes = new Uint8Array(binary.length);
33
+ for (let i = 0; i < binary.length; i++) {
34
+ bytes[i] = binary.charCodeAt(i);
35
+ }
36
+ return bytes;
37
+ }
38
+ return new Uint8Array(Buffer.from(base64, 'base64'));
39
+ }
40
+
41
+ /**
42
+ * Compresses workspace payload into a compact Base64url string.
43
+ */
44
+ export async function compressWorkspaceSnapshot(payload: WorkspaceSharePayload): Promise<string> {
45
+ const jsonStr = JSON.stringify(payload);
46
+ const encoder = new TextEncoder();
47
+ const rawBytes = encoder.encode(jsonStr);
48
+
49
+ if (typeof CompressionStream !== 'undefined') {
50
+ const cs = new CompressionStream('deflate-raw');
51
+ const writer = cs.writable.getWriter();
52
+ writer.write(rawBytes);
53
+ writer.close();
54
+
55
+ const response = new Response(cs.readable);
56
+ const compressedBuffer = await response.arrayBuffer();
57
+ return bufferToBase64Url(new Uint8Array(compressedBuffer));
58
+ }
59
+
60
+ // Fallback: uncompressed Base64url if CompressionStream unsupported
61
+ return bufferToBase64Url(rawBytes);
62
+ }
63
+
64
+ /**
65
+ * Decompresses a Base64url string into workspace snapshot payload.
66
+ */
67
+ export async function decompressWorkspaceSnapshot(encoded: string): Promise<WorkspaceSharePayload | null> {
68
+ if (!encoded || typeof encoded !== 'string') return null;
69
+ try {
70
+ const bytes = base64UrlToBuffer(encoded);
71
+
72
+ if (typeof DecompressionStream !== 'undefined') {
73
+ try {
74
+ const ds = new DecompressionStream('deflate-raw');
75
+ const writer = ds.writable.getWriter();
76
+ writer.write(bytes as any);
77
+ writer.close();
78
+
79
+ const response = new Response(ds.readable);
80
+ const decompressed = await response.arrayBuffer();
81
+ const text = new TextDecoder().decode(decompressed);
82
+ return JSON.parse(text);
83
+ } catch (err) {
84
+ // Fallback for uncompressed raw JSON payload
85
+ void err;
86
+ const rawText = new TextDecoder().decode(bytes);
87
+ return JSON.parse(rawText);
88
+ }
89
+ }
90
+
91
+ const rawText = new TextDecoder().decode(bytes);
92
+ return JSON.parse(rawText);
93
+ } catch (err) {
94
+ if (typeof console !== 'undefined' && console.warn) {
95
+ console.warn('[CodeLab Share Snapshot Restore Error]:', err);
96
+ }
97
+ return null;
98
+ }
99
+ }
@@ -0,0 +1,200 @@
1
+ /**
2
+ * @innovatorved/code-lab — Workbench CSS Tokens, Themes & Styles
3
+ */
4
+
5
+ export const WORKBENCH_STYLES = `
6
+ /* ── Split Run Button ── */
7
+ .codelab-btn-split {
8
+ display: inline-flex;
9
+ align-items: stretch;
10
+ border-radius: var(--cl-radius, 6px);
11
+ overflow: visible;
12
+ position: relative;
13
+ }
14
+ .codelab-btn-split .codelab-btn-split__main {
15
+ border-top-right-radius: 0;
16
+ border-bottom-right-radius: 0;
17
+ border-right: 1px solid rgba(255, 255, 255, 0.2);
18
+ }
19
+ .codelab-btn-split .codelab-btn-split__trigger {
20
+ border-top-left-radius: 0;
21
+ border-bottom-left-radius: 0;
22
+ padding: 0 6px;
23
+ min-width: 24px;
24
+ }
25
+ .codelab-split-menu {
26
+ position: absolute;
27
+ top: calc(100% + 4px);
28
+ right: 0;
29
+ background: var(--cl-bg-elevated, #252526);
30
+ border: 1px solid var(--cl-border, #3c3c3c);
31
+ border-radius: var(--cl-radius, 6px);
32
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
33
+ z-index: 1000;
34
+ min-width: 220px;
35
+ padding: 4px 0;
36
+ display: none;
37
+ }
38
+ .codelab-split-menu.open {
39
+ display: block;
40
+ }
41
+ .codelab-split-menu__item {
42
+ display: flex;
43
+ align-items: center;
44
+ justify-content: space-between;
45
+ width: 100%;
46
+ padding: 6px 12px;
47
+ background: none;
48
+ border: none;
49
+ color: var(--cl-fg, #cccccc);
50
+ font-size: 12px;
51
+ cursor: pointer;
52
+ text-align: left;
53
+ }
54
+ .codelab-split-menu__item:hover {
55
+ background: var(--cl-accent, #007acc);
56
+ color: #ffffff;
57
+ }
58
+
59
+ /* ── Command Palette Trigger Pill ── */
60
+ .codelab-cmd-trigger {
61
+ display: inline-flex;
62
+ align-items: center;
63
+ gap: 6px;
64
+ padding: 3px 10px;
65
+ border-radius: var(--cl-radius, 6px);
66
+ background: var(--cl-input-bg, rgba(255, 255, 255, 0.06));
67
+ border: 1px solid var(--cl-border, #3c3c3c);
68
+ color: var(--cl-fg-muted, #858585);
69
+ font-size: 11px;
70
+ cursor: pointer;
71
+ transition: all 0.15s ease;
72
+ }
73
+ .codelab-cmd-trigger:hover {
74
+ background: var(--cl-input-bg-focus, rgba(255, 255, 255, 0.12));
75
+ color: var(--cl-fg, #cccccc);
76
+ border-color: var(--cl-accent, #007acc);
77
+ }
78
+
79
+ /* ── HUD Telemetry Pill ── */
80
+ .codelab-hud-pill {
81
+ display: inline-flex;
82
+ align-items: center;
83
+ gap: 8px;
84
+ padding: 2px 10px;
85
+ border-radius: 12px;
86
+ background: var(--cl-hud-bg, rgba(0, 122, 204, 0.15));
87
+ border: 1px solid var(--cl-hud-border, rgba(0, 122, 204, 0.35));
88
+ color: var(--cl-hud-fg, #4fc1ff);
89
+ font-family: var(--cl-font-mono, monospace);
90
+ font-size: 11px;
91
+ font-weight: 500;
92
+ letter-spacing: 0.3px;
93
+ margin-left: auto;
94
+ user-select: none;
95
+ }
96
+ .codelab-hud-pill__metric {
97
+ display: inline-flex;
98
+ align-items: center;
99
+ gap: 4px;
100
+ }
101
+
102
+ /* ── Stdin / Custom Input Panel ── */
103
+ .codelab-stdin-panel {
104
+ display: flex;
105
+ flex-direction: column;
106
+ height: 100%;
107
+ padding: 8px 12px;
108
+ background: var(--cl-bg-editor, #1e1e1e);
109
+ box-sizing: border-box;
110
+ }
111
+ .codelab-stdin-panel__header {
112
+ display: flex;
113
+ align-items: center;
114
+ justify-content: space-between;
115
+ margin-bottom: 6px;
116
+ font-size: 11px;
117
+ color: var(--cl-fg-muted, #858585);
118
+ font-weight: 600;
119
+ text-transform: uppercase;
120
+ letter-spacing: 0.5px;
121
+ }
122
+ .codelab-stdin-panel__textarea {
123
+ flex: 1;
124
+ width: 100%;
125
+ background: var(--cl-input-bg, #252526);
126
+ border: 1px solid var(--cl-border, #3c3c3c);
127
+ border-radius: var(--cl-radius, 4px);
128
+ color: var(--cl-fg, #cccccc);
129
+ font-family: var(--cl-font-mono, monospace);
130
+ font-size: 12px;
131
+ line-height: 1.5;
132
+ padding: 8px;
133
+ resize: none;
134
+ outline: none;
135
+ box-sizing: border-box;
136
+ }
137
+ .codelab-stdin-panel__textarea:focus {
138
+ border-color: var(--cl-accent, #007acc);
139
+ }
140
+
141
+ /* ── Problems Drawer Tab ── */
142
+ .codelab-problems-list {
143
+ display: flex;
144
+ flex-direction: column;
145
+ overflow-y: auto;
146
+ height: 100%;
147
+ padding: 4px 0;
148
+ }
149
+ .codelab-problem-item {
150
+ display: flex;
151
+ align-items: center;
152
+ gap: 8px;
153
+ padding: 5px 12px;
154
+ font-size: 12px;
155
+ font-family: var(--cl-font-mono, monospace);
156
+ cursor: pointer;
157
+ border-bottom: 1px solid rgba(255, 255, 255, 0.04);
158
+ }
159
+ .codelab-problem-item:hover {
160
+ background: var(--cl-tree-hover, rgba(255, 255, 255, 0.06));
161
+ }
162
+ .codelab-problem-item--error {
163
+ color: #f14c4c;
164
+ }
165
+ .codelab-problem-item--warning {
166
+ color: #cca700;
167
+ }
168
+ .codelab-problem-item--info {
169
+ color: #3794ff;
170
+ }
171
+ .codelab-problem-item__location {
172
+ color: var(--cl-fg-muted, #858585);
173
+ font-size: 11px;
174
+ margin-left: auto;
175
+ }
176
+
177
+ /* ── Monaco Side-by-Side Diff Editor ── */
178
+ .codelab-diff-container {
179
+ display: flex;
180
+ flex-direction: column;
181
+ width: 100%;
182
+ height: 100%;
183
+ background: var(--cl-bg-editor, #1e1e1e);
184
+ }
185
+ .codelab-diff-toolbar {
186
+ display: flex;
187
+ align-items: center;
188
+ gap: 8px;
189
+ padding: 6px 12px;
190
+ background: var(--cl-bg-panel, #252526);
191
+ border-bottom: 1px solid var(--cl-border, #3c3c3c);
192
+ font-size: 12px;
193
+ }
194
+ .codelab-diff-host {
195
+ flex: 1;
196
+ width: 100%;
197
+ height: calc(100% - 36px);
198
+ position: relative;
199
+ }
200
+ `;
@@ -0,0 +1,171 @@
1
+ /**
2
+ * @innovatorved/code-lab — Topbar Navigation & Contextual Execution Controls
3
+ */
4
+
5
+ import { CL_ICONS } from './icons';
6
+
7
+ export interface ToolbarRenderOptions {
8
+ workbench: any;
9
+ title: string;
10
+ backLabel: string;
11
+ hasGuidedLab: boolean;
12
+ mode: string;
13
+ activeFile: string | null;
14
+ enabledLanguages: Set<string>;
15
+ currentLang: string;
16
+ hasWebContent: boolean;
17
+ activeServerCount: number;
18
+ }
19
+
20
+ export function renderLanguageSwitcherHtml(workbench: any): string {
21
+ const enabled = workbench.enabledLanguages || new Set(['js']);
22
+ const showTs = enabled.has('ts');
23
+ const showCpp = enabled.has('cpp');
24
+ const showPy = enabled.has('py');
25
+
26
+ const count = (enabled.has('js') ? 1 : 0) + (showTs ? 1 : 0) + (showCpp ? 1 : 0) + (showPy ? 1 : 0);
27
+ if (count <= 1) return '';
28
+
29
+ const activeLang = workbench.lang || 'js';
30
+
31
+ return `
32
+ <span class="codelab-toolbar__sep" aria-hidden="true"></span>
33
+ <div class="codelab-lang-switch codelab-segmented" role="tablist" aria-label="Language">
34
+ <button type="button" role="tab" aria-selected="${activeLang === 'js'}" class="codelab-segmented__btn ${activeLang === 'js' ? 'active' : ''}" data-cl-lang="js" title="JavaScript (Node.js &amp; Bun runtime)">JS</button>
35
+ ${showTs ? `<button type="button" role="tab" aria-selected="${activeLang === 'ts'}" class="codelab-segmented__btn ${activeLang === 'ts' ? 'active' : ''}" data-cl-lang="ts" title="TypeScript (Instant in-browser transpile)">TS</button>` : ''}
36
+ ${showCpp ? `<button type="button" role="tab" aria-selected="${activeLang === 'cpp'}" class="codelab-segmented__btn ${activeLang === 'cpp' ? 'active' : ''}" data-cl-lang="cpp" title="C++20 (WASI Clang/LLVM WebAssembly compiler)">C++</button>` : ''}
37
+ ${showPy ? `<button type="button" role="tab" aria-selected="${activeLang === 'py'}" class="codelab-segmented__btn ${activeLang === 'py' ? 'active' : ''}" data-cl-lang="py" title="Python 3.12 (CPython WebAssembly via Pyodide)">PY</button>` : ''}
38
+ </div>
39
+ `;
40
+ }
41
+
42
+ export function renderToolbarHtml(opts: ToolbarRenderOptions): string {
43
+ const { workbench, title, backLabel, hasGuidedLab, mode, activeFile, hasWebContent, activeServerCount } = opts;
44
+ const isGuided = Boolean(hasGuidedLab && mode === 'guided');
45
+ const brandLabel = title || 'code-lab';
46
+
47
+ const testFileExists = Boolean(
48
+ workbench._findEntryFile && workbench._findEntryFile('test') !== null
49
+ );
50
+
51
+ return `
52
+ <div class="codelab-topbar codelab-toolbar">
53
+ <div class="codelab-topbar__left">
54
+ ${workbench.onClose ? `
55
+ <button type="button" class="codelab-btn codelab-btn--back" data-cl-action="close-lab" title="${backLabel}">
56
+ ${CL_ICONS.arrowLeft}
57
+ <span>${backLabel}</span>
58
+ </button>
59
+ ` : ''}
60
+ <span class="codelab-brand ${workbench.onClose ? 'codelab-brand--with-back' : ''}" title="${brandLabel}">
61
+ <span class="codelab-brand__dot"></span>
62
+ <span>${brandLabel}</span>
63
+ </span>
64
+
65
+ ${hasGuidedLab ? `
66
+ <span class="codelab-toolbar__sep" aria-hidden="true"></span>
67
+ <div class="codelab-mode-switch" role="tablist" aria-label="Lab Mode">
68
+ <button type="button" role="tab" aria-selected="${mode === 'guided'}" class="codelab-mode-btn ${mode === 'guided' ? 'active' : ''}" data-cl-mode="guided">
69
+ ${CL_ICONS.target}
70
+ <span>Guided Challenge</span>
71
+ </button>
72
+ <button type="button" role="tab" aria-selected="${mode === 'sandbox'}" class="codelab-mode-btn ${mode === 'sandbox' ? 'active' : ''}" data-cl-mode="sandbox">
73
+ ${CL_ICONS.code}
74
+ <span>Reference Sandbox</span>
75
+ </button>
76
+ </div>
77
+ ` : ''}
78
+
79
+ ${renderLanguageSwitcherHtml(workbench)}
80
+
81
+ <span class="codelab-toolbar__sep" aria-hidden="true"></span>
82
+ <button type="button" class="codelab-cmd-trigger" data-cl-action="command-palette" title="Open Command Palette (⌘K / ⇧⌘P)">
83
+ ${CL_ICONS.search}
84
+ <span>Command Palette</span>
85
+ <kbd style="opacity:0.7">⇧⌘P</kbd>
86
+ </button>
87
+ </div>
88
+
89
+ <div class="codelab-topbar__right">
90
+ <button type="button" class="codelab-btn codelab-btn--stop" id="cl-stop-btn" data-cl-action="stop-run" title="Stop Running Execution" style="display:none">
91
+ ${CL_ICONS.stop}
92
+ <span>Stop</span>
93
+ </button>
94
+
95
+ ${isGuided ? `
96
+ <button type="button" class="codelab-btn codelab-btn--run" data-cl-action="run-demo" title="Run Demo Script (⇧⌘↵)">
97
+ ${CL_ICONS.play}
98
+ <span>Run Demo</span>
99
+ <span class="codelab-btn__kbd">⇧⌘↵</span>
100
+ </button>
101
+ <button type="button" class="codelab-btn codelab-btn--test" id="cl-primary-exec-btn" data-cl-action="verify-step" title="Verify Current Step (⌘↵)">
102
+ ${CL_ICONS.check}
103
+ <span>Verify Step</span>
104
+ <span class="codelab-btn__kbd">⌘↵</span>
105
+ </button>
106
+ ` : `
107
+ <div class="codelab-btn-split">
108
+ <button type="button" class="codelab-btn codelab-btn--run codelab-btn-split__main" data-cl-action="run-code" title="Run Code (⌘↵)">
109
+ ${CL_ICONS.play}
110
+ <span>Run Code</span>
111
+ <span class="codelab-btn__kbd">⌘↵</span>
112
+ </button>
113
+ <button type="button" class="codelab-btn codelab-btn--run codelab-btn-split__trigger" id="cl-split-run-trigger" title="More Execution Options" aria-haspopup="true">
114
+ ${CL_ICONS.chevronDown}
115
+ </button>
116
+ <div class="codelab-split-menu" id="cl-split-run-menu">
117
+ <button type="button" class="codelab-split-menu__item" data-cl-action="run-entry">
118
+ <span>▶ Run Entry / Demo</span> <kbd style="opacity:0.6">⌘↵</kbd>
119
+ </button>
120
+ <button type="button" class="codelab-split-menu__item" data-cl-action="run-active-file">
121
+ <span>▶ Run Active File (${activeFile || 'active'})</span> <kbd style="opacity:0.6">⇧⌘↵</kbd>
122
+ </button>
123
+ ${testFileExists ? `
124
+ <button type="button" class="codelab-split-menu__item" data-cl-action="run-tests">
125
+ <span>✓ Run Test Suite</span>
126
+ </button>
127
+ ` : ''}
128
+ <button type="button" class="codelab-split-menu__item" data-cl-action="open-stdin">
129
+ <span>⌨ Configure Stdin / Input...</span>
130
+ </button>
131
+ </div>
132
+ </div>
133
+ `}
134
+
135
+ ${hasWebContent ? `
136
+ <button type="button" class="codelab-btn codelab-btn--icon" id="cl-preview-app-btn" data-cl-action="preview-app" title="Run &amp; Preview in Browser" aria-label="Run and Preview in Browser">
137
+ ${CL_ICONS.globe}
138
+ ${activeServerCount > 0 ? `<span class="codelab-port-badge" style="position:absolute;top:2px;right:2px;font-size:9px;background:#007acc;color:#fff;border-radius:6px;padding:0 3px;">${activeServerCount}</span>` : ''}
139
+ </button>
140
+ ` : ''}
141
+
142
+ <button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="share-snapshot" title="Share Snapshot Link (#codelab=...)" aria-label="Share Snapshot Link">
143
+ ${CL_ICONS.share}
144
+ </button>
145
+
146
+ <span class="codelab-toolbar__sep" aria-hidden="true"></span>
147
+
148
+ ${hasGuidedLab ? `
149
+ <button type="button" class="codelab-btn codelab-btn--icon" id="cl-toggle-guide-btn" data-cl-action="toggle-guide" title="Toggle Guide Panel" aria-label="Toggle Guide Panel">
150
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M9 3v18"/></svg>
151
+ </button>
152
+ ` : ''}
153
+
154
+ <button type="button" class="codelab-btn codelab-btn--icon" id="cl-toggle-drawer-btn" data-cl-action="toggle-drawer" title="Toggle Bottom Drawer" aria-label="Toggle Bottom Drawer">
155
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 15h18"/></svg>
156
+ </button>
157
+
158
+ <button type="button" class="codelab-btn codelab-btn--icon" id="cl-fullscreen-btn" data-cl-action="toggle-fullscreen" title="Toggle Fullscreen IDE (Esc to exit)" aria-label="Toggle Fullscreen IDE">
159
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/></svg>
160
+ </button>
161
+
162
+ ${workbench.onClose ? `
163
+ <button type="button" class="codelab-btn codelab-btn--exit-lab codelab-btn--close-ide" id="cl-close-ide-btn" data-cl-action="close-lab" title="Exit Lab" aria-label="Exit Lab">
164
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>
165
+ <span class="codelab-btn__label">Exit</span>
166
+ </button>
167
+ ` : ''}
168
+ </div>
169
+ </div>
170
+ `;
171
+ }