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.01 kB
/*! * NENT 2022 */ import{r as t,d as s,a as i}from"./index-916ca544.js";import{w as e}from"./logging-5a93c8af.js";import{h as n,m as o,R as r}from"./references-808b36f2.js";import"./mutex-e5645c85.js";import"./index-4bfabbbd.js";const a=class{constructor(i){t(this,i),this.reference=s(this,"referenced",6),this.module=!1,this.noModule=!1,this.inline=!1,this.deferLoad=!1,this.timeout=1e3}async forceLoad(){var t,s;null===(t=this.scriptElement)||void 0===t||t.dispatchEvent(new CustomEvent("load")),null===(s=this.linkElement)||void 0===s||s.dispatchEvent(new CustomEvent("load"))}registered(t,s){this.reference.emit({type:t,loaded:s})}async getStylePromise(t){const s=this.styleSrc;return new Promise((async i=>{if(null==s)return i(!1);if(await n(s))return i(!0);this.linkElement=this.el.ownerDocument.createElement("link"),this.linkElement.href=s,this.linkElement.rel="stylesheet";let r=!1;this.linkElement.addEventListener("load",(async()=>(r=!0,i(r)))),t.append(this.linkElement),await o(s),setTimeout((()=>{r||(e(`Stylesheet '${s}' did not load before the ${this.timeout} timeout.`),i(!1))}),this.timeout)}))}getScriptPromise(t){const s=this.scriptSrc;return new Promise((async i=>{if(null==s)return i(!1);if(await n(s))return i(!0);this.scriptElement=this.el.ownerDocument.createElement("script"),this.scriptElement.src=s;let r=!1;this.module?this.scriptElement.type="module":this.noModule&&this.scriptElement.setAttribute("nomodule",""),this.scriptElement.addEventListener("load",(async()=>(r=!0,await o(s),i(r)))),t.append(this.scriptElement),await o(s),setTimeout((()=>{r||(e(`Script '${s}' did not load before the ${this.timeout} timeout.`),i(!1))}),this.timeout)}))}async componentWillRender(){if(this.deferLoad)return;const t=this.inline?this.el:this.el.ownerDocument.head;await this.getStylePromise(t).then((t=>this.registered(r.styles,t))),await this.getScriptPromise(t).then((t=>this.registered(r.script,t)))}disconnectedCallback(){}get el(){return i(this)}};export{a as n_content_reference}