@@ -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' ) ;
@@ -1242,23 +1223,6 @@ function generateInvertedFlamegraph(data) {
12421223 return invertedRoot ;
12431224}
12441225
1245- function updateToggleUI ( toggleId , isOn ) {
1246- const toggle = document . getElementById ( toggleId ) ;
1247- if ( toggle ) {
1248- const track = toggle . querySelector ( '.toggle-track' ) ;
1249- const labels = toggle . querySelectorAll ( '.toggle-label' ) ;
1250- if ( isOn ) {
1251- track . classList . add ( 'on' ) ;
1252- labels [ 0 ] . classList . remove ( 'active' ) ;
1253- labels [ 1 ] . classList . add ( 'active' ) ;
1254- } else {
1255- track . classList . remove ( 'on' ) ;
1256- labels [ 0 ] . classList . add ( 'active' ) ;
1257- labels [ 1 ] . classList . remove ( 'active' ) ;
1258- }
1259- }
1260- }
1261-
12621226function toggleInvert ( ) {
12631227 isInverted = ! isInverted ;
12641228 updateToggleUI ( 'toggle-invert' , isInverted ) ;
0 commit comments