var T=e=>(t,r)=>t[`node${e}`]===r[`node${e}`],b=T("Name"),C=T("Type"),g=T("Value");function M(e,t){if(e.attributes.length===0&&t.attributes.length===0)return[];let r=[],n=new Map,o=new Map;for(let s of e.attributes)n.set(s.name,s.value);for(let s of t.attributes){let a=n.get(s.name);s.value===a?n.delete(s.name):(typeof a<"u"&&n.delete(s.name),o.set(s.name,s.value))}for(let s of n.keys())r.push({type:5,name:s});for(let[s,a]of o.entries())r.push({type:4,name:s,value:a});return r}function N(e,t=!0){let r=`${e.localName}`;for(let{name:n,value:o}of e.attributes)t&&n.startsWith("data-")||(r+=`[${n}=${o}]`);return r+=e.innerHTML,r}function h(e){switch(e.tagName){case"BASE":case"TITLE":return e.localName;case"META":{if(e.hasAttribute("name"))return`meta[name="${e.getAttribute("name")}"]`;if(e.hasAttribute("property"))return`meta[name="${e.getAttribute("property")}"]`;break}case"LINK":{if(e.hasAttribute("rel")&&e.hasAttribute("href"))return`link[rel="${e.getAttribute("rel")}"][href="${e.getAttribute("href")}"]`;if(e.hasAttribute("href"))return`link[href="${e.getAttribute("href")}"]`;break}}return N(e)}function x(e){let[t,r=""]=e.split("?");return`${t}?t=${Date.now()}&${r.replace(/t=\d+/g,"")}`}function c(e){if(e.nodeType===1&&e.hasAttribute("data-persist"))return e;if(e.nodeType===1&&e.localName==="script"){let t=document.createElement("script");for(let{name:r,value:n}of e.attributes)r==="src"&&(n=x(n)),t.setAttribute(r,n);return t.innerHTML=e.innerHTML,t}return e.cloneNode(!0)}function R(e,t){if(e.children.length===0&&t.children.length===0)return[];let r=[],n=new Map,o=new Map,s=new Map;for(let a of e.children)n.set(h(a),a);for(let a of t.children){let i=h(a),u=n.get(i);u?N(a,!1)!==N(u,!1)&&o.set(i,c(a)):s.set(i,c(a)),n.delete(i)}for(let a of e.childNodes){if(a.nodeType===1){let i=h(a);if(n.has(i)){r.push({type:1});continue}else if(o.has(i)){let u=o.get(i);r.push({type:3,attributes:M(a,u),children:I(a,u)});continue}}r.push(void 0)}for(let a of s.values())r.push({type:0,node:c(a)});return r}function I(e,t){let r=[],n=Math.max(e.childNodes.length,t.childNodes.length);for(let o=0;oO(n,i,a[u])));return}}}function P(e,t){let r=p(e,t);return O(e,r)}export{P as default,p as diff,O as patch};