@@ -197,7 +197,9 @@ export class LwcUiPanel {
197197 // Always add colorTheme to initialization data for consistent theme support
198198 const config = vscode . workspace . getConfiguration ( "vsCodeSfdxHardis.theme" ) ;
199199 const colorThemeConfig = config . get ( "colorTheme" , "auto" ) ;
200- data . colorTheme = LwcUiPanel . resolveTheme ( colorThemeConfig ) ;
200+ const { colorTheme, colorContrast } = LwcUiPanel . resolveTheme ( colorThemeConfig ) ;
201+ data . colorTheme = colorTheme ;
202+ data . colorContrast = colorContrast ;
201203
202204 this . panel . webview . postMessage ( {
203205 type : "initialize" ,
@@ -611,8 +613,7 @@ export class LwcUiPanel {
611613 * Refresh the webview HTML (useful when configuration changes, like theme)
612614 */
613615 public refresh ( data : any ) : void {
614-
615- if ( data ?. colorTheme ) { // FIXME
616+ if ( data ?. colorTheme ) {
616617 this . sendMessage ( {
617618 type : "updateTheme" ,
618619 data
@@ -625,24 +626,40 @@ export class LwcUiPanel {
625626
626627 /**
627628 * Resolve the theme to use based on the input and VS Code's active theme
628- * @param theme The input theme, can be "auto", "dark", "light", dark-high-contrast " or "light-high-contrast "
629- * @returns The resolved theme string: everything but "auto"
629+ * @param theme The input theme, can be "auto", "dark", "light", " dark-high" or "light-high"
630+ * @returns An object with colorTheme and colorContrast properties
630631 */
631- public static resolveTheme ( theme : string ) : string {
632- if ( theme === "auto" ) {
632+ public static resolveTheme ( theme : string ) : any {
633+ const resultTheme = {
634+ colorTheme : "light" ,
635+ colorContrast : ""
636+ }
637+ if ( ! theme || theme === "auto" ) {
633638 const vsCodeTheme = vscode . window . activeColorTheme . kind ;
634639 switch ( vsCodeTheme ) {
635640 case vscode . ColorThemeKind . HighContrast :
641+ resultTheme . colorTheme = "dark" ;
642+ resultTheme . colorContrast = "high" ;
643+ break ;
636644 case vscode . ColorThemeKind . Dark :
637- return "dark" ;
645+ resultTheme . colorTheme = "dark" ;
646+ break ;
638647 case vscode . ColorThemeKind . HighContrastLight :
648+ resultTheme . colorTheme = "light" ;
649+ resultTheme . colorContrast = "high" ;
650+ break ;
639651 case vscode . ColorThemeKind . Light :
640652 default :
641- return "light" ;
653+ resultTheme . colorTheme = "light" ;
654+ break ;
642655 }
656+ } else {
657+ const themeParts = theme . split ( "-" , 2 ) ;
658+ resultTheme . colorTheme = themeParts [ 0 ] ;
659+ resultTheme . colorContrast = themeParts . length > 1 ? themeParts [ 1 ] : "" ;
643660 }
644661
645- return theme ;
662+ return resultTheme ;
646663 }
647664
648665 private getHtmlForWebview ( webview : vscode . Webview ) {
@@ -672,28 +689,27 @@ export class LwcUiPanel {
672689 vscode . Uri . joinPath ( this . extensionUri , "out" , "assets" , "styles" , "global-theme.css" ) ,
673690 ) ;
674691
675- // Safely serialize initialization data
676- const initDataJson = this . initializationData
677- ? JSON . stringify ( this . initializationData )
678- . replace ( / ' / g, "'" )
679- . replace ( / " / g, """ )
680- : "{}" ;
681-
682692 // Determine theme based on configuration
683693 const config = vscode . workspace . getConfiguration ( "vsCodeSfdxHardis.theme" ) ;
684694 const colorThemeConfig = config . get ( "colorTheme" , "auto" ) ;
685- const colorTheme = LwcUiPanel . resolveTheme ( colorThemeConfig ) ;
695+ const { colorTheme, colorContrast } = LwcUiPanel . resolveTheme ( colorThemeConfig ) ;
696+ const initData = this . initializationData || { } ;
697+ initData . colorTheme = colorTheme ;
698+ initData . colorContrast = colorContrast ;
699+
700+ // Safely serialize initialization data
701+ const initDataJson = JSON . stringify ( initData )
702+ . replace ( / ' / g, "'" )
703+ . replace ( / " / g, """ ) ;
686704
687705 const mermaidTheme = {
688706 clusterBkg : "#EAF5FC" ,
689707 edgeLabelBackground : "rgba(232,232,232, 0.8)"
690708 }
691- if ( colorTheme . indexOf ( "dark" ) >= 0 ) {
709+ if ( colorTheme == "dark" ) {
692710 mermaidTheme . clusterBkg = "#333" ;
693711 mermaidTheme . edgeLabelBackground = "rgba(77, 77, 77, 0.5)" ;
694712 }
695- const colorThemeInfo = colorTheme . split ( '-' )
696- const colorContrast = colorThemeInfo . length > 1 ? colorThemeInfo [ 1 ] : "" ;
697713
698714 return `<!DOCTYPE html>
699715 <html lang="en">
@@ -713,7 +729,7 @@ export class LwcUiPanel {
713729 <!-- Global theme stylesheet: always included, handles both light and dark themes. -->
714730 <link rel="stylesheet" href="${ globalThemeCssUri } ">
715731 </head>
716- <body class="slds-scope blue-back" data-theme="${ colorThemeInfo [ 0 ] } " data-contrast="${ colorContrast } ">
732+ <body class="slds-scope blue-back" data-theme="${ colorTheme } " data-contrast="${ colorContrast } ">
717733 <div id="app" data-lwc-id="${ this . lwcId } " data-init-data="${ initDataJson } "></div>
718734
719735 <script>
0 commit comments