-
Notifications
You must be signed in to change notification settings - Fork 1
/
skruv.min.js
2 lines (2 loc) · 2.74 KB
/
skruv.min.js
1
2
var p="http://www.w3.org/1999/xhtml",m=new WeakMap,C=new WeakMap,b=new WeakMap,x={},w=(t,i=globalThis.document.documentElement,h=i.parentNode,a=p,K=!1)=>{if(!h)throw new Error("No parent to render to");if(typeof t=="boolean"||!t){i&&h.removeChild(i);return}if(!globalThis?.isSkruvSSR&&t?.t?.toLowerCase()==="skruvtext"&&t?.c?.[0]){t.r=()=>!i||!h.contains(i)?!1:(w(t,i,h,a),!0),w(t?.c?.[0],i);return}let k=typeof t=="string"||typeof t=="number";if(K||!i||k&&i.nodeName!=="#text"||!k&&i.nodeName.toLowerCase()!==t.t.toLowerCase()){let s=i;if(k?i=document.createTextNode(""+t):(t.t==="svg"&&(a="http://www.w3.org/2000/svg"),t.t==="math"&&(a="http://www.w3.org/1998/Math/MathML"),t.t==="feed"&&(a="http://www.w3.org/2005/Atom"),(t.t==="urlset"||t.t==="sitemapindex")&&(a="https://www.sitemaps.org/schemas/sitemap/0.9"),i=(x[t.t]||(x[t.t]=document.createElementNS(a,t.t))).cloneNode(!1)),s?h.replaceChild(i,s):h.appendChild(i),k)return}if(k){i.textContent!=t&&(i.textContent=""+t);return}t.r&&(t.r=()=>!i||!h.contains(i)?!1:(w(t,i,h,a),!0)),t.t==="foreignObject"&&(a=p);let f=t.c.flat(1/0);globalThis?.isSkruvSSR||(f=f.filter(s=>!s?.t?.startsWith("skruv")));let o={};if(f[0]?.constructor===Object&&!f[0]?.isSkruvDom){o=f[0],f=f.slice(1);let s=b.get(i);s||(s={},b.set(i,s));for(let[e,l]of Object.entries(o))if(""+s[e]!=""+l){if(e==="skruvAfterCreate"){setTimeout(()=>l(i),0),s[e]=l;continue}if(!e.startsWith("skruv")){if(e[0]==="o"&&e[1]==="n"){let v=e.slice(2);s[e]?l||i.removeEventListener(v,l):(s[e]&&i.removeEventListener(v,l),i.addEventListener(v,l)),s[e]=l;continue}(e==="checked"||e==="selected"||e==="value"||i.nodeName.includes("-"))&&(i[e]=l),l!==void 0?i.setAttribute(e,""+l):i.removeAttribute(e),s[e]=l}}}for(let s of i.getAttributeNames().filter(e=>!Object.keys(o).includes(e)))i.removeAttribute(s);if(!f.length&&i.childNodes.length){if(o.skruvWaitForNotEmpty)return;i.replaceChildren();return}if(i.childNodes.length>f.length)for(let s=i.childNodes.length-1;s>=f.length;s--)i.removeChild(i.childNodes[s]);for(let s=0;s<f.length;s++){let e=!1,l;if(f[s]?.c)if(l=m.get(f[s].c[0]?.skruvKey),l){if(l!==i.childNodes[s]&&(l===i.childNodes[s+1]?i.removeChild(i.childNodes[s]):i.childNodes[s]&&m.get(f[s+1]?.c?.[0]?.skruvKey)===i.childNodes[s]?i.insertBefore(l,i.childNodes[s]):i.childNodes[s]?i.replaceChild(l,i.childNodes[s]):i.appendChild(l)),e=f[s].c[0].skruvKey!==C.get(i.childNodes[s]),!e){let v=m.get(i.childNodes[s]);if(v){let g=!0;for(let y in f[s].c[0].skruvKey)f[s].c[0].skruvKey[y]!==v[y]&&(g=!1);if(g)continue}}}else e=m.has(i.childNodes[s]);w(f[s],i.childNodes[s]||!1,i,a,e)}o.skruvKey&&(m.set(o.skruvKey,i),C.set(i,o.skruvKey),m.set(i,{...o.skruvKey}))},S=new Proxy({},{get:(t,i)=>(...h)=>({isSkruvDom:!0,t:i,c:h})});export{S as elementFactory,w as render};
//# sourceMappingURL=skruv.min.js.map