Skip to content

Commit d913e5a

Browse files
theme
1 parent 12adf24 commit d913e5a

File tree

8 files changed

+827
-302
lines changed

8 files changed

+827
-302
lines changed

apps/explorer/src/components/atoms/code-static.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import {
44
type Highlighter,
55
type BundledLanguage,
66
} from 'shiki';
7+
import { palenightTheme } from '../../themes/palenight';
8+
import { lighthouseTheme } from '../../themes/lighthouse';
9+
import { monacoThemeToShiki } from '../../themes/shiki-adapter';
10+
import { ELB_THEME_DARK, ELB_THEME_LIGHT } from '../../themes/names';
711

812
export interface CodeStaticProps {
913
code: string;
@@ -26,12 +30,29 @@ const LANGS: readonly BundledLanguage[] = [
2630
'markdown',
2731
];
2832

33+
// Derive Shiki themes from the same Monaco theme objects CodeBox uses,
34+
// so CodeView (Shiki) and CodeBox (Monaco) render identical colors.
35+
// Names match Monaco's `monaco.editor.setTheme(...)` keys.
36+
const ELB_SHIKI_LIGHT = monacoThemeToShiki(lighthouseTheme, {
37+
name: ELB_THEME_LIGHT,
38+
type: 'light',
39+
defaultBackground: '#ffffff',
40+
defaultForeground: '#24292E',
41+
});
42+
43+
const ELB_SHIKI_DARK = monacoThemeToShiki(palenightTheme, {
44+
name: ELB_THEME_DARK,
45+
type: 'dark',
46+
defaultBackground: '#292d3e',
47+
defaultForeground: '#bfc7d5',
48+
});
49+
2950
let highlighterPromise: Promise<Highlighter> | null = null;
3051

3152
function getHighlighter(): Promise<Highlighter> {
3253
if (!highlighterPromise) {
3354
highlighterPromise = createHighlighter({
34-
themes: ['dark-plus', 'light-plus'],
55+
themes: [ELB_SHIKI_LIGHT, ELB_SHIKI_DARK],
3556
langs: [...LANGS],
3657
});
3758
}
@@ -85,7 +106,7 @@ export function CodeStatic({
85106
if (cancelled) return;
86107
const rendered = highlighter.codeToHtml(code, {
87108
lang: resolveLang(language),
88-
theme: activeTheme === 'dark' ? 'dark-plus' : 'light-plus',
109+
theme: activeTheme === 'dark' ? ELB_THEME_DARK : ELB_THEME_LIGHT,
89110
});
90111
setHtml(rendered);
91112
});
@@ -94,7 +115,9 @@ export function CodeStatic({
94115
};
95116
}, [code, language, activeTheme]);
96117

118+
const wrapperClass = `elb-code-static${className ? ` ${className}` : ''}`;
119+
97120
return (
98-
<div className={className} dangerouslySetInnerHTML={{ __html: html }} />
121+
<div className={wrapperClass} dangerouslySetInnerHTML={{ __html: html }} />
99122
);
100123
}

apps/explorer/src/components/atoms/code.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import React, {
77
} from 'react';
88
import { Editor, loader } from '@monaco-editor/react';
99
import type { editor } from 'monaco-editor';
10-
import { registerAllThemes } from '../../themes';
10+
import {
11+
registerAllThemes,
12+
ELB_THEME_DARK,
13+
ELB_THEME_LIGHT,
14+
} from '../../themes';
1115
import {
1216
configureMonacoTypeScript,
1317
registerWalkerOSAmbients,
@@ -261,7 +265,7 @@ export function Code({
261265
dataTheme === 'dark' ||
262266
(dataTheme === null &&
263267
window.matchMedia('(prefers-color-scheme: dark)').matches);
264-
const newTheme = isDark ? 'elbTheme-dark' : 'elbTheme-light';
268+
const newTheme = isDark ? ELB_THEME_DARK : ELB_THEME_LIGHT;
265269

266270
setMonacoTheme(newTheme);
267271
};
@@ -389,7 +393,7 @@ export function Code({
389393
dataTheme === 'dark' ||
390394
(dataTheme === null &&
391395
window.matchMedia('(prefers-color-scheme: dark)').matches);
392-
const themeName = isDark ? 'elbTheme-dark' : 'elbTheme-light';
396+
const themeName = isDark ? ELB_THEME_DARK : ELB_THEME_LIGHT;
393397
monaco.editor.setTheme(themeName);
394398

395399
// Register walkerOS IntelliSense providers for JSON

apps/explorer/src/styles/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@use './components/atoms/button';
2323
@use './components/atoms/button-link';
2424
@use './components/atoms/code';
25+
@use './components/atoms/code-static';
2526
@use './components/atoms/mdx-code';
2627
@use './components/atoms/toggle';
2728
@use './components/atoms/spinner';

apps/explorer/src/themes/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import { registerLighthouseTheme } from './lighthouse';
1313
export { palenightTheme, registerPalenightTheme } from './palenight';
1414
export { lighthouseTheme, registerLighthouseTheme } from './lighthouse';
1515

16+
// Theme name constants — use these instead of hard-coded string literals
17+
export { ELB_THEME_DARK, ELB_THEME_LIGHT } from './names';
18+
export type { ElbThemeName } from './names';
19+
20+
// Unified scope → color grouping (drives Monaco + Shiki from one source)
21+
export type { TokenGroup } from './token-groups';
22+
1623
// Theme types (for documentation and TypeScript support)
1724
export type { ExplorerTheme } from './types';
1825

0 commit comments

Comments
 (0)