@vanillawc/wc-include
Version:
A vanilla web component for including external media
2 lines (1 loc) • 714 B
JavaScript
var i=class extends HTMLElement{static get observedAttributes(){return["src"]}attributeChangedCallback(t,e,s){!this.__initialized||e!==s&&(this[t]=s)}get src(){return this.getAttribute("src")}set src(t){this.setAttribute("src",t),this.setSrc()}constructor(){super();this.__initialized=!1,this.__element=null;let t=this.hasAttribute("shadow");t&&this.attachShadow({mode:"open"}),this.__element=t?this.shadowRoot:this}async connectedCallback(){this.hasAttribute("src")&&this.setSrc(),this.__initialized=!0}async setSrc(){let t=this.getAttribute("src"),e=await this.fetchSrc(t);this.__element.innerHTML=e}async fetchSrc(t){return(await fetch(t)).text()}};customElements.define("wc-include",i);export{i as WCInclude};