UNPKG

@nent/core

Version:

Functional elements to add routing, data-binding, dynamic HTML, declarative actions, audio, video, and so much more. Supercharge static HTML files into web apps without script or builds.

4 lines 1.76 kB
/*! * NENT 2022 */ import{r as s,h as t,H as h,a as i}from"./index-916ca544.js";import{s as e,o}from"./state-6945acbc.js";import"./index-4bfabbbd.js";const l=class{constructor(t){s(this,t),this.targetElement="body",this.darkClass="dark",this.display=!1,this.switch=!1}componentWillLoad(){this.subscribeToSystem()}subscribeToSystem(){const s=window.matchMedia("(prefers-color-scheme: dark)");(null==s?void 0:s.addEventListener)&&null==e.darkMode&&(s.addEventListener("change",(s=>{e.darkMode=s.matches})),e.darkMode=s.matches),this.stateSubscription=o("darkMode",(()=>{this.toggleDarkTheme()}))}componentWillRender(){this.toggleDarkTheme()}toggleDarkTheme(){const s="body"==this.targetElement?this.el.ownerDocument.body:this.el.ownerDocument.querySelector(this.targetElement);e.darkMode?null==s||s.classList.toggle(this.darkClass,!0):null==s||s.classList.remove(this.darkClass)}render(){if(this.display){const s=this.switch?!e.darkMode:e.darkMode;return t(h,null,t("svg",{class:"themeIcon",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24"},t("path",{fill:"none",d:"M0 0h24v24H0z"}),t("path",s?{d:"M11.38 2.019a7.5 7.5 0 1 0 10.6 10.6C21.662 17.854 17.316 22 12.001 22 6.477 22 2 17.523 2 12c0-5.315 4.146-9.661 9.38-9.981z"}:{d:"M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"})))}return null}disconnectedCallback(){var s;null===(s=this.stateSubscription)||void 0===s||s.call(this)}get el(){return i(this)}};export{l as n_app_theme}