-
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) · 4.95 KB
/
node.js
File metadata and controls
3 lines (3 loc) · 4.95 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,b=/[\x01\x02]/g;let v;const $=(e,n,r)=>{r=r.slice(1),v||(v=new WeakMap);const l=v.get(e)||s(v,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},N=(e,t,n)=>e[n]=t,C=(e,t,n)=>N(e,t,n.slice(1)),y=(e,t)=>("function"==typeof t?t(e):t.current=e,t),w=(e,t,n)=>(null==t?e.removeAttribute(n):e.setAttribute(n,t),t),A=(e,t,n)=>(e.toggleAttribute(n.slice(1),t),t),W=(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),k=new Map([["aria",(e,t)=>{for(const n in t){const r=t[n],s="role"===n?n:`aria-${n}`;null==r?e.removeAttribute(s):e.setAttribute(s,r)}return t}],["class",(e,t)=>N(e,t,"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",y],["style",(e,t)=>N(e.style,t,"cssText")]]),E=(e,t,n)=>{switch(t[0]){case".":return C;case"?":return A;case"@":return $;default:return n||"ownerSVGElement"in e?"ref"===t?y:w:k.get(t)||(t in e?N:w)}},S=(e,t)=>(e.textContent=null==t?"":t,t);function O(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}let T,B,M=document.createElement("template");var j=(e,t)=>{if(t)return T||(T=document.createElementNS("http://www.w3.org/2000/svg","svg"),B=r(),B.selectNodeContents(T)),B.createContextualFragment(e);M.innerHTML=e;const{content:n}=M;return M=M.cloneNode(!1),n};const L=e=>{const t=[];let n;for(;n=e.parentNode;)t.push(t.indexOf.call(n.childNodes,e)),e=n;return t},z=()=>O.bind({n:null}),F=()=>W,R=(e,r,l)=>{const o=j(((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(b,(e=>""===e?`\x3c!--${t+r++}--\x3e`:t+r++))})(e,D,l),l),{length:i}=e;let c=!1,a=n;if(i>1){const e=document.createTreeWalker(o,129),n=[];let s=0,u=`${D}${s++}`;for(a=[];s<i;){const o=e.nextNode();if(8===o.nodeType){if(o.data===u){let e=t(r[s-1])?F:z;e===z?n.push(o):c=!0,a.push(h(8,L(o),e)),u=`${D}${s++}`}}else{let e;for(;o.hasAttribute(u);){e||(e=L(o));const t=o.getAttribute(u);a.push(h(2,e,E(o,t,l),t)),o.removeAttribute(u),u=`${D}${s++}`}p.test(o.localName)&&o.textContent.trim()===`\x3c!--${u}--\x3e`&&(a.push(h(3,e||L(o),S)),u=`${D}${s++}`)}}for(s=0;s<n.length;s++)n[s].replaceWith(document.createTextNode(""))}const u=o.childNodes.length;return s(Z,e,((e,t,n)=>({c:e,e:t,l:n}))(o,a,1===u&&c?0:u))},Z=new WeakMap,D="isµ";var G=(e,t)=>(e.replaceChildren("function"==typeof t?t():t),e);
/*! (c) Andrea Giammarchi - MIT */
const H=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)=>Z.get(e)||R(e,t,r)));var r;return(e,...n)=>t(e,n).n},P=H(!1),V=H(!0);export{k as attr,P as html,G as render,V as svg};