@tntsuperman/rjs
Version:
simple, react, fast JavaScript framework
3 lines (2 loc) • 1.83 kB
JavaScript
const e=[],t=(t,o,n)=>{e.push([t,o,n]),o(),e.pop(),n()},o=(e,o=()=>0)=>{const n=Symbol();return t(n,e,o),n};class n{node;#e;constructor(e){e.dispatchEvent(new window.CustomEvent("create")),this.node=e,this.#e=[e.remove.bind(e)],e.remove=()=>{for(this.#e.forEach((e=>e()));this.node.childNodes.length;)this.node.childNodes[0].remove()}}ondestroy(e){this.#e.push(e)}}const r=(e,t,r=()=>({}),s={})=>{const c=window.document.createElement(e);return o((()=>Object.entries(r()).forEach((e=>c.setAttribute(...e))))),o((()=>{for(;c.childNodes.length;)c.childNodes[0].remove();t().forEach((e=>c.appendChild(e.node)))})),Object.entries(s).forEach((e=>c.addEventListener(...e))),new n(c)},s=e=>{const t=new window.Text("");return o((()=>t.nodeValue=e())),new n(t)},c=[],i=o=>{let n=[],r=[];const s=e=>n=n.filter((t=>t[1]!=e)),{proxy:d,revoke:h}=Proxy.revocable(o,{get(t,o,s){let c=Reflect.get(t,o,s);if("object"==typeof c){const e=r.find((e=>e[0]==o));if(e)c=e[1];else{const e=i(c);r.push([o,...e]),c=e[0]}}const d=e.at(-1);return d&&n.push([o,...d]),c},set(e,o,r,s){const i=Reflect.set(e,o,r,s);return n.filter((e=>e[0]==o)).forEach((e=>{c.forEach((t=>t(e[1]))),t(e[1],e[2],e[3])})),i}});return c.push(s),[d,()=>(c.splice(c.findIndex((e=>e==s)),1),r.forEach((e=>e[2]?e[2]():0)),h())]},d=(e,t)=>new Proxy((function(...o){if("function"==typeof o[0]){const n=t.pop();return n&&e.addEventListener(n,o[0]),d(e,t)}return e.append(...o.map((e=>"string"==typeof e?e:e instanceof n?e.node:""))),new n(e)}),{get(o,n){if("string"==typeof n)return t.push(n),2==t.length&&e.setAttribute(t.shift()??"",t.pop()??""),d(e,t)}}),h=new Proxy({},{get:(e,t)=>"string"==typeof t?d(window.document.createElement(t),[]):void 0});export{n as VNode,i as createProxy,r as createVElement,s as createVText,o as hook,h as seg};
//# sourceMappingURL=R.esm.min.js.map