UNPKG

soo.js

Version:

custom-elements with renderer

2 lines (1 loc) 909 B
var soo=function(){"use strict";return class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}async connectedCallback(){this.install.apply(this),this.beforeRender();const t=await this.render();this.css&&this.shadowRoot.appendChild(function(t){const e=document.createElement("style");return e.textContent=t,e}(this.css())),this.shadowRoot.appendChild(t),this.installed()}disconnectedCallback(){this.uninstall()}fire(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))}fireGlobal(t,e){document.dispatchEvent(new CustomEvent(t,{detail:e}))}async update(){this.beforeUpdate();const t=await this.render();11===t.nodeType?(this.shadowRoot.childNodes.forEach(t=>{"STYLE"!==t.tagName&&3!==t.nodeType&&t.remove()}),this.shadowRoot.appendChild(t)):this.shadowRoot.lastChild.replaceWith(t),this.updated()}install(){}installed(){}uninstall(){}beforeUpdate(){}updated(){}beforeRender(){}}}();