UNPKG

rvx

Version:

A signal based rendering library

2 lines (1 loc) 949 B
import{ENV as s,$ as t,uncapture as e,watchUpdates as i,capture as o,render as r}from"./rvx.min.js";const n=s.current;class d extends n.HTMLElement{static observedAttributes;#s=new Map;#t;#e;#i;#o;constructor(s){super(),this.#t=s?.start??"on-connect",this.#e=s?.dispose??"on-disconnect";const t=(!0===s?.shadow?void 0:s?.shadow)??{mode:"open"};!1!==t&&(this.#i=this.attachShadow(t))}reflect(s){let o=this.#s.get(s);return void 0===o&&(o=t(this.getAttribute(s)),this.#s.set(s,o),e(()=>{i(o,t=>{null===t?this.removeAttribute(s):this.setAttribute(s,t)})})),o}start(){void 0===this.#o&&(this.#o=o(()=>{s.inject(n,()=>{const s=this.#i??this;s.innerHTML="",r(this.render()).appendTo(s)})}))}dispose(){this.#o?.(),this.#o=void 0}connectedCallback(){"on-connect"===this.#t&&this.start()}disconnectedCallback(){"on-disconnect"===this.#e&&this.dispose()}attributeChangedCallback(s,t,e){const i=this.#s.get(s);void 0!==i&&(i.value=e)}}export{d as RvxElement};