TP_JO2024/home/dist/scheme/scheme.module.min.js

4 lines
3.2 KiB
JavaScript
Raw Permalink Normal View History

2024-03-27 17:19:37 +01:00
/*! DSFR v1.11.2 | SPDX-License-Identifier: MIT | License-Filename: LICENSE.md | restricted use (see terms and conditions) */
const e=window.dsfr,t={SYSTEM:"system",LIGHT:"light",DARK:"dark"},s={THEME:e.internals.ns.attr("theme"),SCHEME:e.internals.ns.attr("scheme"),TRANSITION:e.internals.ns.attr("transition")},i={LIGHT:"light",DARK:"dark"},h={SCHEME:e.internals.ns.emission("scheme","scheme"),THEME:e.internals.ns.emission("scheme","theme"),ASK:e.internals.ns.emission("scheme","ask")},n={SCHEME:e.internals.ns.event("scheme"),THEME:e.internals.ns.event("theme")};class r extends e.core.Instance{constructor(){super(!1)}static get instanceClassName(){return"Scheme"}init(){this.changing=this.change.bind(this),this.hasAttribute(s.TRANSITION)&&(this.removeAttribute(s.TRANSITION),this.request(this.restoreTransition.bind(this)));const i=e.internals.support.supportLocalStorage()?localStorage.getItem("scheme"):"",n=this.getAttribute(s.SCHEME);switch(i){case t.DARK:case t.LIGHT:case t.SYSTEM:this.scheme=i;break;default:switch(n){case t.DARK:this.scheme=t.DARK;break;case t.LIGHT:this.scheme=t.LIGHT;break;default:this.scheme=t.SYSTEM}}this.addAscent(h.ASK,this.ask.bind(this)),this.addAscent(h.SCHEME,this.apply.bind(this))}get proxy(){const t=this,s={get scheme(){return t.scheme},set scheme(e){t.scheme=e}};return e.internals.property.completeAssign(super.proxy,s)}restoreTransition(){this.setAttribute(s.TRANSITION,"")}ask(){this.descend(h.SCHEME,this.scheme)}apply(e){this.scheme=e}get scheme(){return this._scheme}set scheme(r){if(this._scheme!==r){switch(this._scheme=r,r){case t.SYSTEM:this.listenPreferences();break;case t.DARK:this.unlistenPreferences(),this.theme=i.DARK;break;case t.LIGHT:this.unlistenPreferences(),this.theme=i.LIGHT;break;default:return void(this.scheme=t.SYSTEM)}this.descend(h.SCHEME,r),e.internals.support.supportLocalStorage()&&localStorage.setItem("scheme",r),this.setAttribute(s.SCHEME,r),this.dispatch(n.SCHEME,{scheme:this._scheme})}}get theme(){return this._theme}set theme(e){if(this._theme!==e)switch(e){case i.LIGHT:case i.DARK:this._theme=e,this.setAttribute(s.THEME,e),this.descend(h.THEME,e),this.dispatch(n.THEME,{theme:this._theme}),document.documentElement.style.colorScheme=e===i.DARK?"dark":""}}listenPreferences(){this.isListening||(this.isListening=!0,this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),this.mediaQuery.addEventListener&&this.mediaQuery.addEventListener("change",this.changing),this.change())}unlistenPreferences(){this.isListening&&(this.isListening=!1,this.mediaQuery.removeEventListener("change",this.changing),this.mediaQuery=null)}change(){this.isListening&&(this.theme=this.mediaQuery.matches?i.DARK:i.LIGHT)}mutate(e){e.indexOf(s.SCHEME)>-1&&(this.scheme=this.getAttribute(s.SCHEME)),e.indexOf(s.THEME)>-1&&(this.theme=this.getAttribute(s.THEME))}dispose(){this.unlistenPreferences()}}const c={SCHEME:`:root${e.internals.ns.attr.selector("theme")}, :root${e.internals.ns.attr.selector("scheme")}`,SWITCH_THEME:e.internals.ns.selector("switch-theme"),RADIO_BUTTONS:`input[name="${e.internals.ns("radios-theme")}"]`};e.scheme={Scheme:r,SchemeValue:t,SchemeSelector:c,SchemeEmission:h,SchemeTheme:i,SchemeEvent:n},e.internals.register(e.scheme.SchemeSelector.SCHEME,e.scheme.Scheme);
//# sourceMappingURL=scheme.module.min.js.map