UNPKG

@tntsuperman/rjs

Version:

simple, react, fast JavaScript framework

3 lines (2 loc) 1.85 kB
define(["exports"],(function(e){"use strict";const t=[],o=(e,o,n)=>{t.push([e,o,n]),o(),t.pop(),n()},n=(e,t=()=>0)=>{const n=Symbol();return o(n,e,t),n};class r{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 s=[],c=e=>{let n=[],r=[];const i=e=>n=n.filter((t=>t[1]!=e)),{proxy:d,revoke:f}=Proxy.revocable(e,{get(e,o,s){let i=Reflect.get(e,o,s);if("object"==typeof i){const e=r.find((e=>e[0]==o));if(e)i=e[1];else{const e=c(i);r.push([o,...e]),i=e[0]}}const d=t.at(-1);return d&&n.push([o,...d]),i},set(e,t,r,c){const i=Reflect.set(e,t,r,c);return n.filter((e=>e[0]==t)).forEach((e=>{s.forEach((t=>t(e[1]))),o(e[1],e[2],e[3])})),i}});return s.push(i),[d,()=>(s.splice(s.findIndex((e=>e==i)),1),r.forEach((e=>e[2]?e[2]():0)),f())]},i=(e,t)=>new Proxy((function(...o){if("function"==typeof o[0]){const n=t.pop();return n&&e.addEventListener(n,o[0]),i(e,t)}return e.append(...o.map((e=>"string"==typeof e?e:e instanceof r?e.node:""))),new r(e)}),{get(o,n){if("string"==typeof n)return t.push(n),2==t.length&&e.setAttribute(t.shift()??"",t.pop()??""),i(e,t)}}),d=new Proxy({},{get:(e,t)=>"string"==typeof t?i(window.document.createElement(t),[]):void 0});e.VNode=r,e.createProxy=c,e.createVElement=(e,t,o=()=>({}),s={})=>{const c=window.document.createElement(e);return n((()=>Object.entries(o()).forEach((e=>c.setAttribute(...e))))),n((()=>{for(;c.childNodes.length;)c.childNodes[0].remove();t().forEach((e=>c.appendChild(e.node)))})),Object.entries(s).forEach((e=>c.addEventListener(...e))),new r(c)},e.createVText=e=>{const t=new window.Text("");return n((()=>t.nodeValue=e())),new r(t)},e.hook=n,e.seg=d})); //# sourceMappingURL=R.amd.min.js.map