@@ -386,22 +386,34 @@ export const fnTypeArr = [
386386 } ,
387387] as const satisfies FnType [ ] ;
388388
389-
390389// Datum define
391390import { defineStore } from "pinia" ;
392391import { computed , ref } from "vue" ;
393392export const useProfile = defineStore ( "profile" , ( ) => {
394393 const data = ref < InternalDatum [ ] > ( [
395394 { fnType : "linear" , graphType : "polyline" , fn : "x^2" , key : 1 } ,
396395 ] ) ;
397- const getOriginalCopy = ( forExport ?: boolean ) => toOriginalDatum ( data . value , forExport ) ;
396+ const getOriginalCopy = ( forExport ?: boolean ) =>
397+ toOriginalDatum ( data . value , forExport ) ;
398398 return { data, getOriginalCopy } ;
399399} ) ;
400+
400401// Theme define
401402export const useTheme = defineStore ( "theme" , ( ) => {
402403 const themeValues = [ "auto" , "dark" , "light" ] as const ;
403- const index = ref ( 0 ) ;
404+ const initialIndex = ( ( ) => {
405+ if ( typeof localStorage !== "undefined" ) {
406+ const savedTheme = Number ( localStorage . getItem ( "theme" ) ) ;
407+ if ( [ 0 , 1 , 2 ] . includes ( savedTheme ) ) return savedTheme as 0 | 1 | 2 ;
408+ }
409+ return 0 ;
410+ } ) ( ) ;
411+ const index = ref ( initialIndex ) ;
412+ const initialValue = themeValues [ initialIndex ] ;
404413 const value = computed ( ( ) => themeValues [ index . value ] ) ;
405- const toogle = ( ) => index . value = ( index . value + 1 ) % themeValues . length
406- return { index, value, toogle }
407- } )
414+ const toogle = ( ) => {
415+ index . value = ( ( index . value + 1 ) % themeValues . length ) as 0 | 1 | 2 ;
416+ localStorage . setItem ( "theme" , index . value . toString ( ) ) ;
417+ } ;
418+ return { initialIndex, initialValue, index, value, toogle } ;
419+ } ) ;
0 commit comments