-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathnode.js
More file actions
3 lines (3 loc) · 5.06 KB
/
node.js
File metadata and controls
3 lines (3 loc) · 5.06 KB
1
2
3
const{setPrototypeOf:e}=Object;const{isArray:t}=Array,n=[],r=()=>document.createRange(),s=(e,t,n)=>(e.set(t,n),n);let l;var o=(e,t,n)=>(l||(l=r()),n?l.setStartAfter(e):l.setStartBefore(e),l.setEndAfter(t),l.deleteContents(),e);const i=({firstChild:e,lastChild:t},n)=>o(e,t,n);let c=!1;const a=(e,t)=>c&&11===e.nodeType?1/t<0?t?i(e,!0):e.lastChild:t?e.valueOf():e.firstChild:e;class u extends((t=>{function n(t){return e(t,new.target.prototype)}return n.prototype=t.prototype,n})(DocumentFragment)){#e;#t;constructor(e){const t=[...e.childNodes];super(e),this.#e=t,this.#t=t.length,c=!0}get firstChild(){return this.#e[0]}get lastChild(){return this.#e.at(-1)}get parentNode(){return this.#e[0].parentNode}remove(){i(this,!1)}replaceWith(e){i(this,!0).replaceWith(e)}valueOf(){return this.childNodes.length!==this.#t&&this.append(...this.#e),this}}const h=(e,t,n,r="")=>({t:e,p:t,u:n,n:r}),d=(e,t)=>t.reduceRight(f,e),f=(e,t)=>e.childNodes[t];const p=/^(?:plaintext|script|style|textarea|title|xmp)$/i,g=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,m=/<([a-zA-Z0-9]+[a-zA-Z0-9:._-]*)([^>]*?)(\/?)>/g,x=/([^\s\\>"'=]+)\s*=\s*(['"]?)\x01/g,$=/[\x01\x02]/g;const b=(e,t,n)=>{e.setAttribute(t,n)},v=(e,t)=>{e.removeAttribute(t)},N=()=>B;let y;const C=(e,n,r)=>{r=r.slice(1),y||(y=new WeakMap);const l=y.get(e)||s(y,e,{});let o=l[r];return o&&o[0]&&e.removeEventListener(r,...o),o=t(n)?n:[n,!1],l[r]=o,o[0]&&e.addEventListener(r,...o),n};function w(e,t){const n=this.n||(this.n=e);switch(typeof t){case"string":case"number":case"boolean":n!==e&&n.replaceWith(this.n=e),this.n.data=t;break;case"object":case"undefined":null==t?(this.n=e).data="":this.n=t.valueOf(),n.replaceWith(this.n)}return t}const A=()=>w.bind({n:null}),W=(e,t,n)=>e[n]=t,k=(e,t,n)=>W(e,t,n.slice(1)),E=(e,t,n)=>null==t?(v(e,n),t):W(e,t,n),S=(e,t)=>("function"==typeof t?t(e):t.current=e,t),O=(e,t,n)=>(null==t?v(e,n):b(e,n,t),t),T=(e,t,n)=>(e.toggleAttribute(n.slice(1),t),t),B=(e,t,r,s)=>t.length?((e,t,n,r,s)=>{const l=n.length;let o=t.length,i=l,c=0,a=0,u=null;for(;c<o||a<i;)if(o===c){const t=i<l?a?r(n[a-1],-0).nextSibling:r(n[i-a],0):s;for(;a<i;)e.insertBefore(r(n[a++],1),t)}else if(i===a)for(;c<o;)u&&u.has(t[c])||e.removeChild(r(t[c],-1)),c++;else if(t[c]===n[a])c++,a++;else if(t[o-1]===n[i-1])o--,i--;else if(t[c]===n[i-1]&&n[a]===t[o-1]){const s=r(t[--o],-1).nextSibling;e.insertBefore(r(n[a++],1),r(t[c++],-1).nextSibling),e.insertBefore(r(n[--i],1),s),t[o]=n[i]}else{if(!u){u=new Map;let e=a;for(;e<i;)u.set(n[e],e++)}if(u.has(t[c])){const s=u.get(t[c]);if(a<s&&s<i){let l=c,h=1;for(;++l<o&&l<i&&u.get(t[l])===s+h;)h++;if(h>s-a){const l=r(t[c],0);for(;a<s;)e.insertBefore(r(n[a++],1),l)}else e.replaceChild(r(n[a++],1),r(t[c++],-1))}else c++}else e.removeChild(r(t[c++],-1))}return n})(e.parentNode,s,t,a,e):(s.length&&o(s[0],s.at(-1),!1),n),M=new Map([["aria",(e,t)=>{for(const n in t){const r=t[n],s="role"===n?n:`aria-${n}`;null==r?v(e,s):b(e,s,r)}return t}],["class",(e,t)=>E(e,t,null==t?"class":"className")],["data",(e,t)=>{const{dataset:n}=e;for(const e in t)null==t[e]?delete n[e]:n[e]=t[e];return t}],["ref",S],["style",(e,t)=>null==t?E(e,t,"style"):W(e.style,t,"cssText")]]),j=(e,t,n)=>{switch(t[0]){case".":return k;case"?":return T;case"@":return C;default:return n||"ownerSVGElement"in e?"ref"===t?S:O:M.get(t)||(t in e?t.startsWith("on")?W:E:O)}},L=(e,t)=>(e.textContent=null==t?"":t,t);let z,F,R=document.createElement("template");var Z=(e,t)=>{if(t)return z||(z=document.createElementNS("http://www.w3.org/2000/svg","svg"),F=r(),F.selectNodeContents(z)),F.createContextualFragment(e);R.innerHTML=e;const{content:n}=R;return R=R.cloneNode(!1),n};const D=e=>{const t=[];let n;for(;n=e.parentNode;)t.push(t.indexOf.call(n.childNodes,e)),e=n;return t},G=(e,r,l)=>{const o=Z(((e,t,n)=>{let r=0;return e.join("").trim().replace(m,((e,t,r,s)=>`<${t}${r.replace(x,"=$2$1").trimEnd()}${s?n||g.test(t)?" /":`></${t}`:""}>`)).replace($,(e=>""===e?`\x3c!--${t+r++}--\x3e`:t+r++))})(e,P,l),l),{length:i}=e;let c=!1,a=n;if(i>1){const e=document.createTreeWalker(o,129),n=[];let s=0,u=`${P}${s++}`;for(a=[];s<i;){const o=e.nextNode();if(8===o.nodeType){if(o.data===u){let e=t(r[s-1])?N:A;e===A?n.push(o):c=!0,a.push(h(8,D(o),e)),u=`${P}${s++}`}}else{let e;for(;o.hasAttribute(u);){e||(e=D(o));const t=o.getAttribute(u);a.push(h(2,e,j(o,t,l),t)),v(o,u),u=`${P}${s++}`}p.test(o.localName)&&o.textContent.trim()===`\x3c!--${u}--\x3e`&&(a.push(h(3,e||D(o),L)),u=`${P}${s++}`)}}for(s=0;s<n.length;s++)n[s].replaceWith(document.createTextNode(""))}const u=o.childNodes.length;return s(H,e,((e,t,n)=>({c:e,e:t,l:n}))(o,a,1===u&&c?0:u))},H=new WeakMap,P="isµ";var V=(e,t)=>(e.replaceChildren("function"==typeof t?t():t),e);
/*! (c) Andrea Giammarchi - MIT */
const _=e=>{const t=(e=>(t,r)=>{const{c:s,e:l,l:o}=e(t,r),i=s.cloneNode(!0);let c,a,h=l.length,f=h?l.slice(0):n;for(;h--;){const{t:e,p:t,u:s,n:o}=l[h],u=t===a?c:c=d(i,a=t),p=8===e?s():s;f[h]={v:p(u,r[h],o,n),u:p,t:u,n:o}}return{n:1===o?i.firstChild:new u(i),d:f}})((r=e,(e,t)=>H.get(e)||G(e,t,r)));var r;return(e,...n)=>t(e,n).n},q=_(!1),I=_(!0);export{M as attr,q as html,V as render,I as svg};