-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvan-0.10.0.min.js
1 lines (1 loc) · 1.26 KB
/
van-0.10.0.min.js
1
let t,e=document,n=Object,r=null,l={};export let empty=l;class o{constructor(t){this.t=t,this.l=[],this.o=[]}get val(){return this.t}set val(e){let n=this;e!==n.t&&(n.i?e===n.i&&(n.i=r,t.delete(n)):((e=>{t=(t??(setTimeout(s),new Set)).add(e)})(n),n.i=n.t),n.t=e,n.o.forEach((t=>t())))}}export let state=t=>new o(t);export let add=(t,...n)=>n.flat(1/0).forEach((n=>{return t.appendChild((r=n)instanceof Node?r:r instanceof o?bind(r,(t=>e.createTextNode(t))):e.createTextNode(r));var r}));export let tags=new Proxy(((t,...r)=>{let[l,...s]=r[0]?.constructor===n?r:[{},...r],i=e.createElement(t);return n.entries(l).forEach((([t,e])=>{t.startsWith("on")?i[t]=e:e instanceof o?bind(e,(e=>(i[t]=e,i))):i.setAttribute(t,e)})),add(i,...s),i}),{get:(t,e)=>t.bind(r,e)});let s=()=>{let e=[...t];t=r,new Set(e.flatMap((t=>t.l=t.l.filter((t=>t.u.isConnected))))).forEach((t=>{let{u:e,p:n,h:r}=t,o=r(...n.map((t=>t.t)),e,...n.map((t=>t.i)));o!==e&&(o!==l?e.replaceWith(o):e.remove(),t.u=o)})),e.forEach((t=>t.i=r))};export let bind=(...t)=>{let e=t.slice(0,-1),n=t[t.length-1],r=n(...e.map((t=>t.t)));if(r===l)return[];if(r instanceof Node){let t={p:e,u:r,h:n};return e.forEach((e=>e.l.push(t))),r}let o=state(r),s=()=>o.val=n(...e.map((t=>t.t)),o.t,...e.map((t=>t.i)));return e.forEach((t=>t.o.push(s))),o};