p3x-redis-ui-material
Version:
💿 P3X Redis UI triple frontend — Angular + React/MUI + Vue/Vuetify with 54 languages, 7 themes, Socket.IO, desktop notifications, and full feature parity
1 lines • 3.36 kB
JavaScript
import{Ni as xe,Vn as cr,ct as N,ot as Mf,vt as P}from"./chunk-CHqDEyfr.js";import{t as Q}from"./chunk-CyniViPG.js";var T=class t{state;static STORAGE_KEY=`p3xr-theme`;static AUTO_THEME=`auto`;static DARK_THEMES=[`p3xrThemeDarkNeu`,`p3xrThemeDark`,`p3xrThemeDarkoBluo`,`p3xrThemeMatrix`];static LIGHT_THEMES=[`p3xrThemeLight`,`p3xrThemeEnterprise`,`p3xrThemeRedis`];static ALL_THEMES=[...t.DARK_THEMES,...t.LIGHT_THEMES];static THEME_CSS_CLASS_MAP={p3xrThemeDark:`p3xr-mat-theme-dark`,p3xrThemeDarkNeu:`p3xr-mat-theme-dark-neu`,p3xrThemeDarkoBluo:`p3xr-mat-theme-darko-bluo`,p3xrThemeMatrix:`p3xr-mat-theme-matrix`,p3xrThemeLight:`p3xr-mat-theme-light`,p3xrThemeEnterprise:`p3xr-mat-theme-enterprise`,p3xrThemeRedis:`p3xr-mat-theme-redis`};static DEFAULT_THEME=typeof window<`u`&&window.matchMedia?.(`(prefers-color-scheme: dark)`).matches?`p3xrThemeDark`:`p3xrThemeEnterprise`;currentTheme;isDark=Mf(()=>t.DARK_THEMES.includes(this.currentTheme()));themeLayout=Mf(()=>this.currentTheme()+`Layout`);themeCommon=Mf(()=>this.currentTheme()+`Common`);isAuto;constructor(e){this.state=e;let r=this.getInitialTheme(),s=r===t.AUTO_THEME;this.isAuto=xe(s);let i=s?t.getSystemTheme():r;this.currentTheme=xe(i),cr(()=>{let o=this.currentTheme();this.applyTheme(o)}),typeof window<`u`&&window.matchMedia&&window.matchMedia(`(prefers-color-scheme: dark)`).addEventListener(`change`,o=>{this.isAuto()&&this.currentTheme.set(o.matches?`p3xrThemeDark`:`p3xrThemeEnterprise`)})}static getSystemTheme(){return typeof window<`u`&&window.matchMedia?.(`(prefers-color-scheme: dark)`).matches?`p3xrThemeDark`:`p3xrThemeEnterprise`}setTheme(e){if(e===t.AUTO_THEME){this.isAuto.set(!0);let r=t.getSystemTheme();this.currentTheme.set(r);return}if(!t.ALL_THEMES.includes(e)){console.warn(`[ThemeService] Unknown theme: ${e}`);return}this.isAuto.set(!1),this.currentTheme.set(e)}getDisplayName(e){return e.replace(`p3xrTheme`,``)}generateThemeName(e){return`p3xrTheme`+e[0].toUpperCase()+e.substring(1)}fromShortKey(e){if(e.startsWith(`p3xrTheme`))return e;let r=`p3xrTheme`+e.charAt(0).toUpperCase()+e.slice(1);return t.ALL_THEMES.includes(r)?r:e}toShortKey(e){if(!e.startsWith(`p3xrTheme`))return e;let r=e.replace(`p3xrTheme`,``);return r.charAt(0).toLowerCase()+r.slice(1)}getInitialTheme(){let e=this.readStorageItem(t.STORAGE_KEY);return e?e===t.AUTO_THEME?e:this.fromShortKey(e):t.AUTO_THEME}applyTheme(e){let r=t.DARK_THEMES.includes(e);if(this.setStorageItem(t.STORAGE_KEY,this.isAuto()?t.AUTO_THEME:this.toShortKey(e)),typeof document<`u`){document.body.classList.remove(`p3xr-theme-light`,`p3xr-theme-dark`),document.body.classList.add(r?`p3xr-theme-dark`:`p3xr-theme-light`);let s=Object.values(t.THEME_CSS_CLASS_MAP);document.body.classList.remove(...s);let i=t.THEME_CSS_CLASS_MAP[e];i&&document.body.classList.add(i),document.documentElement.style.display=`none`,document.documentElement.setAttribute(`data-color-scheme`,r?`dark`:`light`),document.body.clientWidth,document.documentElement.style.display=``;try{window.parent?.postMessage({type:`p3x-theme-change`,dark:r},`*`)}catch(o){}}this.state.theme.set(e)}readStorageItem(e){try{return localStorage.getItem(e)}catch(r){return null}}setStorageItem(e,r){try{localStorage.setItem(e,r)}catch(s){}}static ɵfac=function(r){return new(r||t)(N(Q))};static ɵprov=P({token:t,factory:t.ɵfac,providedIn:`root`})};export{T as t};