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 2.78 kB
/*! * NENT 2022 */ import{r as s,d as t,h as i,a as e,H as n}from"./index-916ca544.js";import{a,e as o}from"./index-f7016b94.js";import{f as r,l,t as d,w as c,a as h}from"./logging-5a93c8af.js";import{a as p}from"./state-27a8a5bc.js";import{o as u,s as m}from"./state-6945acbc.js";import{k as g}from"./strings-47d55561.js";import"./index-4bfabbbd.js";import"./values-ddfac998.js";let v;function f(s,t){r(p.debug,`app-provider: ${s} registered`),v=t}var k,b;!function(s){s.RegisterProvider="register-provider",s.Log="log",s.Warn="warn",s.Dir="dir",s.SetDarkMode="set-dark-mode"}(k||(k={})),function(s){s.ThemeChanged="theme"}(b||(b={}));class w{constructor(s=window,t){this.win=s,this.disposeThemeSubscription=u("darkMode",(i=>{null==i?null==s||s.localStorage.removeItem("darkMode"):null==s||s.localStorage.setItem("darkMode",i.toString()),null==t||t.emit(b.ThemeChanged,i)})),s.addEventListener("storage",(()=>{this.getTheme()})),this.getTheme()}getTheme(){var s;const t=null===(s=this.win)||void 0===s?void 0:s.localStorage.getItem("darkMode");m.darkMode=null!=t?"true"==t:null}setDarkMode(s){const{value:t}=s;m.darkMode=null!=t?Boolean(t):null}log(s){const{message:t}=s;t?l(t):d(s)}warn(s){const{message:t}=s;t?c(t):d(s)}dir(s){h(s)}destroy(){this.disposeThemeSubscription()}}class j{initialize(s,t,i){this.eventBus=i,this.actionsSubscription=t.on("app",(s=>{this.handleAction(s)})),this.defaultProvider=new w(s,i)}handleAction(s){if(r(p.debug,`document-listener: action received ${JSON.stringify(s)}`),s.command===k.RegisterProvider){const{name:t="unknown",provider:i}=s.data;i&&f(t,i)}else{const t=v,i=g(s.command);let e=t?t[i]:null;e||(e=this.defaultProvider[i]),e&&"function"==typeof e&&e.call(this.defaultProvider,s.data)}}destroy(){var s;this.actionsSubscription(),null===(s=this.defaultProvider)||void 0===s||s.destroy()}}const y=class{constructor(i){s(this,i),this.events=t(this,"nent:events",6),this.actions=t(this,"nent:actions",3),this.debug=!1}delegateActionEventFromDOM(s){const t=s.detail;a.emit(t.topic,t)}componentWillLoad(){p.debug=this.debug,l(this.debug?"n-app: initializing <debug>":"n-app: initializing"),this.listener=new j,this.listener.initialize(window,a,o),r(p.debug,"n-app: services and listener registered"),this.actionsSubscription=a.on("*",((...s)=>{this.actions.emit(...s)})),this.eventSubscription=o.on("*",((...s)=>{this.events.emit(...s)}))}render(){return i(n,{style:{display:"block"}})}componentDidLoad(){l("n-app: initialized")}disconnectedCallback(){var s,t;this.listener.destroy(),null===(s=this.actionsSubscription)||void 0===s||s.call(this),null===(t=this.eventSubscription)||void 0===t||t.call(this),o.removeAllListeners(),a.removeAllListeners()}get el(){return e(this)}};y.style="[n-cloak] { display: inherit; }";export{y as n_app}