@@ -83,18 +83,7 @@ function resolveStringIndices(node) {
8383// ============================================================================
8484
8585function toggleTheme ( ) {
86- const html = document . documentElement ;
87- const current = html . getAttribute ( 'data-theme' ) || 'light' ;
88- const next = current === 'light' ? 'dark' : 'light' ;
89- html . setAttribute ( 'data-theme' , next ) ;
90- localStorage . setItem ( 'flamegraph-theme' , next ) ;
91-
92- // Update theme button icon
93- const btn = document . getElementById ( 'theme-btn' ) ;
94- if ( btn ) {
95- btn . querySelector ( '.icon-moon' ) . style . display = next === 'dark' ? 'none' : '' ;
96- btn . querySelector ( '.icon-sun' ) . style . display = next === 'dark' ? '' : 'none' ;
97- }
86+ toggleAndSaveTheme ( ) ;
9887
9988 // Re-render flamegraph with new theme colors
10089 if ( window . flamegraphData && normalData ) {
@@ -154,17 +143,9 @@ function toggleSection(sectionId) {
154143 }
155144}
156145
146+ // Restore theme from localStorage, or use browser preference
157147function restoreUIState ( ) {
158- // Restore theme
159- const savedTheme = localStorage . getItem ( 'flamegraph-theme' ) ;
160- if ( savedTheme ) {
161- document . documentElement . setAttribute ( 'data-theme' , savedTheme ) ;
162- const btn = document . getElementById ( 'theme-btn' ) ;
163- if ( btn ) {
164- btn . querySelector ( '.icon-moon' ) . style . display = savedTheme === 'dark' ? 'none' : '' ;
165- btn . querySelector ( '.icon-sun' ) . style . display = savedTheme === 'dark' ? '' : 'none' ;
166- }
167- }
148+ applyTheme ( getPreferredTheme ( ) ) ;
168149
169150 // Restore sidebar state
170151 const savedSidebar = localStorage . getItem ( 'flamegraph-sidebar' ) ;
0 commit comments