11/// <reference types="vite/client" />
22
33import codiconCssUrl from "@vscode/codicons/dist/codicon.css?url" ;
4- import { theme as darkTheme } from "@vscode-elements/webview-playground/dist/themes/dark-v2.js" ;
5- import { theme as hcDarkTheme } from "@vscode-elements/webview-playground/dist/themes/hc-dark.js" ;
6- import { theme as hcLightTheme } from "@vscode-elements/webview-playground/dist/themes/hc-light.js" ;
7- import { theme as lightTheme } from "@vscode-elements/webview-playground/dist/themes/light-v2.js" ;
84import { createElement , useEffect } from "react" ;
95
106import "./global.css" ;
7+ import darkTheme from "./themes/generated/dark.json" ;
8+ import "./themes/generated/default-styles.css" ;
9+ import hcLightTheme from "./themes/generated/high-contrast-light.json" ;
10+ import hcDarkTheme from "./themes/generated/high-contrast.json" ;
11+ import lightTheme from "./themes/generated/light.json" ;
1112
1213import type { Preview } from "@storybook/react-vite" ;
1314import type { WebviewApi } from "vscode-webview" ;
4445 document . head . appendChild ( link ) ;
4546}
4647
47- // VS Code injects --vscode-font-family at runtime, but the upstream
48- // vscode-elements theme data omits it. Set a static default so
49- // Storybook (and Chromatic) renders with a predictable sans-serif
50- // stack instead of falling back to the browser default (Times).
51- const VSCODE_FONT_FAMILY =
52- '"Segoe WPC", "Segoe UI", system-ui, "Ubuntu", "Droid Sans", sans-serif' ;
53-
54- const THEMES : Record <
55- string ,
56- { variables : Array < [ string , string ] > ; kind : string }
57- > = {
58- light : { variables : lightTheme , kind : "vscode-light" } ,
59- dark : { variables : darkTheme , kind : "vscode-dark" } ,
60- "high-contrast" : { variables : hcDarkTheme , kind : "vscode-high-contrast" } ,
48+ // Theme variable dumps captured from a real VS Code instance.
49+ // Regenerate with `pnpm sync:vscode-themes`.
50+ const THEMES : Record < string , { variables : string [ ] [ ] ; kind : string } > = {
51+ light : { variables : lightTheme . variables , kind : "vscode-light" } ,
52+ dark : { variables : darkTheme . variables , kind : "vscode-dark" } ,
53+ "high-contrast" : {
54+ variables : hcDarkTheme . variables ,
55+ kind : "vscode-high-contrast" ,
56+ } ,
6157 "high-contrast-light" : {
62- variables : hcLightTheme ,
58+ variables : hcLightTheme . variables ,
6359 kind : "vscode-high-contrast-light" ,
6460 } ,
6561} ;
@@ -100,7 +96,6 @@ const preview: Preview = {
10096
10197 useEffect ( ( ) => {
10298 const root = document . documentElement . style ;
103- root . setProperty ( "--vscode-font-family" , VSCODE_FONT_FAMILY ) ;
10499
105100 // Mirror VS Code's body attribute so theme-aware hooks work in Storybook.
106101 document . body . setAttribute ( "data-vscode-theme-kind" , kind ) ;
@@ -115,7 +110,6 @@ const preview: Preview = {
115110 variables . forEach ( ( [ property ] ) => {
116111 root . removeProperty ( property ) ;
117112 } ) ;
118- root . removeProperty ( "--vscode-font-family" ) ;
119113 document . body . removeAttribute ( "data-vscode-theme-kind" ) ;
120114 } ;
121115 } , [ variables , kind ] ) ;
0 commit comments