-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchunk-XNKMP7HU.js
1 lines (1 loc) · 1.81 KB
/
chunk-XNKMP7HU.js
1
import{a as i}from"./chunk-Z2H34PKS.js";import{A as a,G as l,Sb as S,_ as m,ea as h,j as n}from"./chunk-VICN7ROL.js";var o=function(t){return t.LIGHT="light",t.DARK="dark",t.SYSTEM="system",t}(o||{}),r=function(t){return t.LIGHT="light",t.DARK="dark",t}(r||{});var I=(()=>{class t{document;DEFAULT_SETTINGS={theme:o.SYSTEM,colorScheme:r.DARK};settings$;resize$;settingsSubject$;constructor(e){this.document=e;let s=this.getTheme(),c=this.getColorScheme();this.applyTheme(s),this.settingsSubject$=new n({theme:s,colorScheme:c}),this.settings$=this.settingsSubject$.asObservable(),this.resize$=a(window,"resize").pipe(l(500)),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",({matches:g})=>{this.getTheme()===o.SYSTEM&&(this.applyTheme(g?o.DARK:o.LIGHT),this.settingsSubject$.next({theme:this.getTheme(),colorScheme:this.getColorScheme()}))})}setTheme(e){e&&Object.values(o).includes(e)&&localStorage&&(localStorage.setItem(i.settings.THEME,e),this.applyTheme(e),this.settingsSubject$.next({theme:e,colorScheme:this.getColorScheme()}))}setColorScheme(e){e&&Object.values(r).includes(e)&&localStorage&&localStorage.setItem(i.settings.COLOR_SCHEME,e)}getTheme(){return localStorage&&(localStorage.getItem(i.settings.THEME)||this.DEFAULT_SETTINGS.theme)}getColorScheme(){return localStorage&&(localStorage.getItem(i.settings.COLOR_SCHEME)||this.DEFAULT_SETTINGS.colorScheme)}applyTheme(e){let s=this.document.documentElement.classList,c=!1;(e===o.SYSTEM&&window.matchMedia("(prefers-color-scheme: dark)").matches||e===o.DARK)&&(c=!0),c?(!s.contains("dark")&&s.add("dark"),this.setColorScheme(r.DARK)):(s.contains("dark")&&s.remove("dark"),this.setColorScheme(r.LIGHT))}static \u0275fac=function(s){return new(s||t)(h(S))};static \u0275prov=m({token:t,factory:t.\u0275fac,providedIn:"root"})}return t})();export{o as a,I as b};