Skip to content

Commit b7b3c66

Browse files
committed
fix
1 parent 2f8fbac commit b7b3c66

File tree

3 files changed

+134
-4
lines changed

3 files changed

+134
-4
lines changed

scripts/generate-github-themes.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* Script to generate GitHub Light/Dark Default Monaco theme JSON files locally.
2+
* It uses the generator from github-vscode-theme (CJS) and writes to src/lib/themes.
3+
*/
4+
5+
import { mkdir, writeFile } from 'node:fs/promises';
6+
import { dirname, resolve } from 'node:path';
7+
import { fileURLToPath } from 'node:url';
8+
9+
// Use CJS module via dynamic import; this path is resolvable in Node (not via Vite bundler)
10+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
11+
// @ts-ignore
12+
const getThemeModule = await import('github-vscode-theme/src/theme.js');
13+
14+
// Interop for CJS default export
15+
const getTheme: (args: { theme: 'light' | 'dark' | string; name: string }) => any =
16+
// @ts-expect-error - cjs interop
17+
getThemeModule.default || getThemeModule;
18+
19+
const __filename = fileURLToPath(import.meta.url);
20+
const __dirname = dirname(__filename);
21+
22+
async function main() {
23+
const outDir = resolve(__dirname, '../src/lib/themes');
24+
await mkdir(outDir, { recursive: true });
25+
26+
const light = getTheme({ theme: 'light', name: 'GitHub Light Default' });
27+
const dark = getTheme({ theme: 'dark', name: 'GitHub Dark Default' });
28+
29+
await writeFile(resolve(outDir, 'github-light-default.json'), JSON.stringify(light, null, 2), 'utf-8');
30+
await writeFile(resolve(outDir, 'github-dark-default.json'), JSON.stringify(dark, null, 2), 'utf-8');
31+
32+
// eslint-disable-next-line no-console
33+
console.log('Generated themes at', outDir);
34+
}
35+
36+
main().catch((err) => {
37+
// eslint-disable-next-line no-console
38+
console.error('Failed to generate themes:', err);
39+
process.exitCode = 1;
40+
});

src/components/YamlEditor/YamlEditor.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ export type YamlEditorProps = Omit<ComponentProps<typeof Editor>, 'language'>;
99
// Simple wrapper that forwards all props to Monaco Editor
1010
export const YamlEditor = (props: YamlEditorProps) => {
1111
const { isDarkTheme } = useTheme();
12-
const { theme, ...rest } = props;
12+
const { theme, options, ...rest } = props;
1313
const computedTheme = theme ?? (isDarkTheme ? GITHUB_DARK_DEFAULT : GITHUB_LIGHT_DEFAULT);
1414

15+
const enforcedOptions = {
16+
...options,
17+
minimap: { enabled: false },
18+
};
19+
1520
return (
1621
<Editor
1722
{...rest}
1823
theme={computedTheme}
24+
options={enforcedOptions}
1925
// Force YAML language for this editor wrapper
2026
language="yaml"
2127
/>

src/lib/monaco.ts

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,94 @@ loader.config({ monaco });
1212

1313
export const GITHUB_LIGHT_DEFAULT = 'github-light-default';
1414
export const GITHUB_DARK_DEFAULT = 'github-dark-default';
15+
16+
// Lightweight RGBA helper
17+
function rgba(hex: string, alpha: number) {
18+
const h = hex.replace('#', '');
19+
const v =
20+
h.length === 3
21+
? h
22+
.split('')
23+
.map((c) => c + c)
24+
.join('')
25+
: h;
26+
const n = parseInt(v, 16);
27+
// If parse fails, fallback to transparent
28+
if (Number.isNaN(n)) return `rgba(0,0,0,${alpha})`;
29+
const r = (n >> 16) & 255;
30+
const g = (n >> 8) & 255;
31+
const b = n & 255;
32+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
33+
}
34+
35+
// Inlined GitHub Light Default editor colors (subset focused on Monaco editor UI)
36+
const GITHUB_LIGHT_EDITOR_COLORS: monaco.editor.IColors = {
37+
'editor.foreground': '#1f2328',
38+
'editor.background': '#ffffff',
39+
'editorWidget.background': '#f6f8fa',
40+
'editor.lineHighlightBackground': '#eaeef2',
41+
'editorCursor.foreground': '#0969da',
42+
'editor.selectionBackground': rgba('#0969da', 0.2),
43+
'editor.inactiveSelectionBackground': rgba('#0969da', 0.07),
44+
'editor.selectionHighlightBackground': rgba('#1a7f37', 0.25),
45+
'editorLineNumber.foreground': '#8c959f',
46+
'editorLineNumber.activeForeground': '#1f2328',
47+
'editorIndentGuide.background': rgba('#1f2328', 0.12),
48+
'editorIndentGuide.activeBackground': rgba('#1f2328', 0.24),
49+
'editorGutter.background': '#ffffff',
50+
'editorHoverWidget.background': '#f6f8fa',
51+
'editorHoverWidget.border': '#d0d7de',
52+
'editorSuggestWidget.background': '#f6f8fa',
53+
'editorSuggestWidget.border': '#d0d7de',
54+
'editorWidget.border': '#d0d7de',
55+
'editorWhitespace.foreground': '#d0d7de',
56+
'editor.wordHighlightBackground': rgba('#afb8c1', 0.5),
57+
'editor.wordHighlightStrongBackground': rgba('#afb8c1', 0.3),
58+
};
59+
60+
// Inlined GitHub Dark Default editor colors (subset focused on Monaco editor UI)
61+
const GITHUB_DARK_EDITOR_COLORS: monaco.editor.IColors = {
62+
'editor.foreground': '#e6edf3',
63+
'editor.background': '#0d1117',
64+
'editorWidget.background': '#161b22',
65+
'editor.lineHighlightBackground': '#161b22',
66+
'editorCursor.foreground': '#2f81f7',
67+
'editor.selectionBackground': rgba('#2f81f7', 0.2),
68+
'editor.inactiveSelectionBackground': rgba('#2f81f7', 0.07),
69+
'editor.selectionHighlightBackground': rgba('#2ea043', 0.25),
70+
'editorLineNumber.foreground': '#6e7681',
71+
'editorLineNumber.activeForeground': '#e6edf3',
72+
'editorIndentGuide.background': rgba('#e6edf3', 0.12),
73+
'editorIndentGuide.activeBackground': rgba('#e6edf3', 0.24),
74+
'editorGutter.background': '#0d1117',
75+
'editorHoverWidget.background': '#161b22',
76+
'editorHoverWidget.border': '#30363d',
77+
'editorSuggestWidget.background': '#161b22',
78+
'editorSuggestWidget.border': '#30363d',
79+
'editorWidget.border': '#30363d',
80+
'editorWhitespace.foreground': '#484f58',
81+
'editor.wordHighlightBackground': rgba('#6e7681', 0.5),
82+
'editor.wordHighlightStrongBackground': rgba('#6e7681', 0.3),
83+
};
84+
1585
export const configureMonaco = () => {
1686
self.MonacoEnvironment = {
17-
getWorker: (_: string) => {
18-
return new EditorWorker();
19-
},
87+
getWorker: (_: string) => new EditorWorker(),
2088
};
89+
90+
// Register GitHub Light Default
91+
monaco.editor.defineTheme(GITHUB_LIGHT_DEFAULT, {
92+
base: 'vs',
93+
inherit: true,
94+
rules: [],
95+
colors: GITHUB_LIGHT_EDITOR_COLORS,
96+
});
97+
98+
// Register GitHub Dark Default
99+
monaco.editor.defineTheme(GITHUB_DARK_DEFAULT, {
100+
base: 'vs-dark',
101+
inherit: true,
102+
rules: [],
103+
colors: GITHUB_DARK_EDITOR_COLORS,
104+
});
21105
};

0 commit comments

Comments
 (0)