@innovatorved/code-lab 0.4.0 → 0.5.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 (64) hide show
  1. package/ARCHITECTURE.md +2 -2
  2. package/CHANGELOG.md +21 -0
  3. package/README.md +4 -28
  4. package/dist/code-lab-sql.esm.js +1 -1
  5. package/dist/code-lab-sql.umd.js +2 -2
  6. package/dist/code-lab.css +1553 -98
  7. package/dist/code-lab.d.ts +1 -1
  8. package/dist/code-lab.esm.js +11883 -1619
  9. package/dist/code-lab.js +11882 -1618
  10. package/dist/code-lab.umd.js +11882 -1618
  11. package/dist/diagnostics.d.ts +3 -0
  12. package/dist/extensions/cpp.esm.js +27 -29
  13. package/dist/extensions/cpp.js +27 -29
  14. package/dist/extensions/python.esm.js +27 -28
  15. package/dist/extensions/python.js +27 -28
  16. package/dist/index.d.ts +1 -1
  17. package/dist/packages/settings/src/configuration-service.d.ts +7 -0
  18. package/dist/packages/settings/src/index.d.ts +1 -1
  19. package/dist/packages/ui/src/index.d.ts +2 -2
  20. package/dist/packages/ui/src/plugin-registry.d.ts +1 -0
  21. package/dist/packages/ui/src/settings-dialog.d.ts +31 -3
  22. package/dist/packages/ui/src/themes.d.ts +5 -0
  23. package/dist/preview-sw.js +1 -1
  24. package/dist/runtime.esm.js +1 -1
  25. package/dist/runtime.js +1 -1
  26. package/dist/schemas.d.ts +1 -1
  27. package/dist/scm.d.ts +92 -11
  28. package/dist/shell.esm.js +937 -113
  29. package/dist/shell.js +937 -113
  30. package/dist/storage.d.ts +47 -0
  31. package/dist/terminal.esm.js +1 -1
  32. package/dist/terminal.js +1 -1
  33. package/dist/workbench/index.d.ts +1 -1
  34. package/dist/workbench/styles.d.ts +1 -1
  35. package/package.json +2 -2
  36. package/packages/commands/package.json +1 -1
  37. package/packages/core/package.json +1 -1
  38. package/packages/editor/package.json +1 -1
  39. package/packages/fs/package.json +1 -1
  40. package/packages/preview/package.json +1 -1
  41. package/packages/runtime/package.json +1 -1
  42. package/packages/settings/package.json +1 -1
  43. package/packages/settings/src/builtin-schemas.ts +17 -6
  44. package/packages/settings/src/configuration-service.ts +72 -6
  45. package/packages/settings/src/index.ts +1 -0
  46. package/packages/sql/package.json +1 -1
  47. package/packages/terminal/package.json +1 -1
  48. package/packages/ui/package.json +1 -1
  49. package/packages/ui/src/index.ts +4 -0
  50. package/packages/ui/src/plugin-registry.ts +17 -2
  51. package/packages/ui/src/settings-dialog.ts +374 -92
  52. package/packages/ui/src/themes.ts +105 -12
  53. package/src/code-lab.css +1553 -98
  54. package/src/diagnostics.ts +139 -7
  55. package/src/extensions/cpp.ts +33 -33
  56. package/src/extensions/python.ts +33 -32
  57. package/src/index.ts +1 -1
  58. package/src/schemas.ts +1 -1
  59. package/src/scm.ts +781 -58
  60. package/src/shell.ts +936 -112
  61. package/src/storage.ts +336 -3
  62. package/src/workbench/icons.ts +8 -1
  63. package/src/workbench/styles.ts +25 -19
  64. package/src/workbench.ts +12010 -3814
@@ -28,8 +28,10 @@ export const DARK_THEME: ThemeDefinition = {
28
28
  '--cl-surface': '#0a0a0a',
29
29
  '--cl-fg': '#f5f5f5',
30
30
  '--cl-muted': '#8e8e93',
31
+ '--cl-fg-muted': '#8e8e93',
31
32
  '--cl-border': '#262626',
32
- '--cl-accent': '#0284c7'
33
+ '--cl-accent': '#0ea5e9',
34
+ '--cl-accent-fg': '#000000'
33
35
  }
34
36
  };
35
37
 
@@ -42,9 +44,11 @@ export const LIGHT_THEME: ThemeDefinition = {
42
44
  '--cl-bg': '#ffffff',
43
45
  '--cl-surface': '#f8fafc',
44
46
  '--cl-fg': '#0f172a',
45
- '--cl-muted': '#64748b',
46
- '--cl-border': '#e2e8f0',
47
- '--cl-accent': '#0284c7'
47
+ '--cl-muted': '#475569',
48
+ '--cl-fg-muted': '#475569',
49
+ '--cl-border': '#cbd5e1',
50
+ '--cl-accent': '#0369a1',
51
+ '--cl-accent-fg': '#ffffff'
48
52
  }
49
53
  };
50
54
 
@@ -58,11 +62,64 @@ export const HIGH_CONTRAST_THEME: ThemeDefinition = {
58
62
  '--cl-surface': '#000000',
59
63
  '--cl-fg': '#ffffff',
60
64
  '--cl-muted': '#e5e5e5',
65
+ '--cl-fg-muted': '#e5e5e5',
61
66
  '--cl-border': '#facc15',
62
- '--cl-accent': '#38bdf8'
67
+ '--cl-accent': '#38bdf8',
68
+ '--cl-accent-fg': '#000000'
63
69
  }
64
70
  };
65
71
 
72
+ function parseColorRgb(raw: string): [number, number, number] | null {
73
+ const s = raw.trim();
74
+ if (s.startsWith('#')) {
75
+ const hex = s.slice(1);
76
+ if (hex.length === 3 || hex.length === 4) {
77
+ const r = Number.parseInt(hex[0] + hex[0], 16);
78
+ const g = Number.parseInt(hex[1] + hex[1], 16);
79
+ const b = Number.parseInt(hex[2] + hex[2], 16);
80
+ if (Number.isFinite(r) && Number.isFinite(g) && Number.isFinite(b)) return [r, g, b];
81
+ return null;
82
+ }
83
+ if (hex.length === 6 || hex.length === 8) {
84
+ const r = Number.parseInt(hex.slice(0, 2), 16);
85
+ const g = Number.parseInt(hex.slice(2, 4), 16);
86
+ const b = Number.parseInt(hex.slice(4, 6), 16);
87
+ if (Number.isFinite(r) && Number.isFinite(g) && Number.isFinite(b)) return [r, g, b];
88
+ return null;
89
+ }
90
+ return null;
91
+ }
92
+ const rgbMatch = /^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})/i.exec(s);
93
+ if (rgbMatch) {
94
+ const r = Math.min(255, Number.parseInt(rgbMatch[1], 10));
95
+ const g = Math.min(255, Number.parseInt(rgbMatch[2], 10));
96
+ const b = Math.min(255, Number.parseInt(rgbMatch[3], 10));
97
+ return [r, g, b];
98
+ }
99
+ return null;
100
+ }
101
+
102
+ function toLinearChannel(channel8Bit: number): number {
103
+ const srgb = channel8Bit / 255;
104
+ return srgb <= 0.04045 ? srgb / 12.92 : Math.pow((srgb + 0.055) / 1.055, 2.4);
105
+ }
106
+
107
+ /**
108
+ * Picks `'#ffffff'` or `'#000000'` to maximize WCAG 2.1 contrast (>= 4.58:1)
109
+ * against a solid hex/rgb background color, returning `fallback` for dynamic CSS expressions.
110
+ */
111
+ export function pickContrastingFg(color: string, fallback = '#ffffff'): string {
112
+ const rgb = parseColorRgb(color);
113
+ if (!rgb) return fallback;
114
+ const lum =
115
+ 0.2126 * toLinearChannel(rgb[0]) +
116
+ 0.7152 * toLinearChannel(rgb[1]) +
117
+ 0.0722 * toLinearChannel(rgb[2]);
118
+ const whiteContrast = 1.05 / (lum + 0.05);
119
+ const blackContrast = (lum + 0.05) / 0.05;
120
+ return whiteContrast >= blackContrast ? '#ffffff' : '#000000';
121
+ }
122
+
66
123
  export function parseCustomTheme(rawJsonc: string): ThemeDefinition {
67
124
  const parsed = parseJsonc<Record<string, unknown>>(rawJsonc);
68
125
  if (!parsed.value || typeof parsed.value !== 'object' || Array.isArray(parsed.value)) {
@@ -73,18 +130,36 @@ export function parseCustomTheme(rawJsonc: string): ThemeDefinition {
73
130
  const label = typeof obj.label === 'string' && obj.label.trim() ? obj.label.trim() : id;
74
131
  const kind: ThemeKind =
75
132
  obj.kind === 'light' ? 'light' : obj.kind === 'high-contrast' ? 'high-contrast' : 'dark';
133
+ const rawPaletteCandidate = obj.colors ?? obj.tokens;
76
134
  const rawColors =
77
- typeof obj.colors === 'object' && obj.colors !== null && !Array.isArray(obj.colors)
78
- ? (obj.colors as Record<string, unknown>)
135
+ typeof rawPaletteCandidate === 'object' && rawPaletteCandidate !== null && !Array.isArray(rawPaletteCandidate)
136
+ ? (rawPaletteCandidate as Record<string, unknown>)
79
137
  : {};
80
138
  const base = kind === 'light' ? LIGHT_THEME : kind === 'high-contrast' ? HIGH_CONTRAST_THEME : DARK_THEME;
81
139
  const colors: Record<string, string> = { ...base.colors };
140
+ let explicitAccentFg = false;
141
+ let explicitFgMuted = false;
142
+ let explicitMuted = false;
82
143
  for (const [k, v] of Object.entries(rawColors)) {
83
144
  if (typeof v === 'string') {
84
145
  const cssVar = k.startsWith('--') ? k : `--cl-${k.replace(/\./g, '-')}`;
85
146
  colors[cssVar] = v;
147
+ if (cssVar === '--cl-accent-fg') explicitAccentFg = true;
148
+ if (cssVar === '--cl-fg-muted') explicitFgMuted = true;
149
+ if (cssVar === '--cl-muted') explicitMuted = true;
86
150
  }
87
151
  }
152
+ if (!explicitAccentFg && colors['--cl-accent']) {
153
+ colors['--cl-accent-fg'] = pickContrastingFg(
154
+ colors['--cl-accent'],
155
+ base.colors['--cl-accent-fg'] ?? '#ffffff'
156
+ );
157
+ }
158
+ if (explicitMuted && !explicitFgMuted && colors['--cl-muted']) {
159
+ colors['--cl-fg-muted'] = colors['--cl-muted'];
160
+ } else if (explicitFgMuted && !explicitMuted && colors['--cl-fg-muted']) {
161
+ colors['--cl-muted'] = colors['--cl-fg-muted'];
162
+ }
88
163
  return {
89
164
  id,
90
165
  label,
@@ -158,14 +233,32 @@ export class ThemeService implements IThemeService {
158
233
  target.classList.toggle('cl-theme-dark', t.kind === 'dark');
159
234
  target.classList.toggle('cl-theme-hc', t.kind === 'high-contrast');
160
235
 
236
+ const setCssVar = (prop: string, val: string): void => {
237
+ if (target.style && typeof target.style.setProperty === 'function') {
238
+ target.style.setProperty(prop, val);
239
+ } else if (target.style) {
240
+ (target.style as unknown as Record<string, string>)[prop] = val;
241
+ }
242
+ };
243
+
161
244
  for (const [cssVar, val] of Object.entries(t.colors)) {
162
- target.style.setProperty(cssVar, val);
245
+ setCssVar(cssVar, val);
246
+ }
247
+ const accent = t.colors['--cl-accent'];
248
+ const accentFg = t.colors['--cl-accent-fg'] ?? (accent ? pickContrastingFg(accent) : '#ffffff');
249
+ setCssVar('--cl-accent-fg', accentFg);
250
+ const fgMuted = t.colors['--cl-fg-muted'] ?? t.colors['--cl-muted'];
251
+ if (fgMuted) {
252
+ setCssVar('--cl-fg-muted', fgMuted);
163
253
  }
254
+
164
255
  // Pair color-scheme with explicit background/color/accent-color per Modern Web Guidance
165
- target.style.colorScheme = t.kind === 'light' ? 'light' : 'dark';
166
- if (t.colors['--cl-bg']) target.style.backgroundColor = t.colors['--cl-bg'];
167
- if (t.colors['--cl-fg']) target.style.color = t.colors['--cl-fg'];
168
- if (t.colors['--cl-accent']) target.style.accentColor = t.colors['--cl-accent'];
256
+ if (target.style) {
257
+ target.style.colorScheme = t.kind === 'light' ? 'light' : 'dark';
258
+ if (t.colors['--cl-bg']) target.style.backgroundColor = t.colors['--cl-bg'];
259
+ if (t.colors['--cl-fg']) target.style.color = t.colors['--cl-fg'];
260
+ if (accent) target.style.accentColor = accent;
261
+ }
169
262
  }
170
263
 
171
264
  public dispose(): void {