!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).diff={})}(this,(function(e){"use strict";const t={ELEMENT:1,ATTR:2,TEXT:3,COMMENT:8,FRAGMENT:11},n={STR:"",NUM:1,OBJ:{},ARR:[],MAP:new Map,SET:new Set,DOM:{},FUN:()=>{}},o={SET_ATTRIBUTE:0,REMOVE_ATTRIBUTE:1,NODE_VALUE:2,INSERT_BEFORE:3,REPLACE_CHILD:4,REMOVE_CHILD:5},s=new Map,r=new Map,i=new Set,c=new Set,d=new Set,a=new Set,l=new Set,u=new Set;var h="undefined"!=typeof process?process:{env:{NODE_ENV:"development"},argv:[]},f="object"==typeof global?global:("object"==typeof window?window:self)||{};const{parseInt:p}=Number,{parse:N}=JSON;function m(e,t){const n=String(e);switch(t){case"boolean":return"false"!==n;case"string":return n;case"number":return p(n,10);case"object":return N(n)}}function T(e,t,n=typeof t,o){const{location:s,URLSearchParams:r}=f,i=void 0!==r&&void 0!==s,c=h.env;if(o&&e in o)return o[e];const d=`DIFF_${e.replace(/[^a-zA-Z0-9]/,"")}`;if(i){const e=new r(s.search),t=d.toLowerCase();if(e.has(t))return m(decodeURIComponent(String(e.get(t))),n)}const a=d.toUpperCase();return c&&a in h.env?m(h.env[a.toUpperCase()],n):t}const g=T("initialPoolSize",5e3),b=new Set,E=new Set,y=new Set,w=()=>({rawNodeName:n.STR,nodeName:n.STR,nodeValue:n.STR,nodeType:t.ELEMENT,key:n.STR,childNodes:[],attributes:{}}),S={free:b,allocated:E,protected:y};let O=b.values();const R={size:g,memory:S,fill(){for(let e=b.size;e{b.size!==this.size&&b.delete(e)}))},get(){const{value:e=w(),done:t}=O.next();return t&&(O=b.values()),b.delete(e),E.add(e),e},protect(e){E.delete(e),y.add(e)},unprotect(e){(y.has(e)||E.has(e))&&(y.delete(e),E.add(e))}};R.fill();const{isArray:x}=Array,{memory:M}=R,k="#document-fragment",v="#text";function C(e,t=[]){for(let n=0;n{t===e&&(d=n)})),d=d||V(l.nodeName,o,s),d.attributes={...d.attributes,...o},d.childNodes=s,r.set(d,l),d}if(a&&!o){const{rawNodeName:t,nodeName:n,nodeValue:o,attributes:s,childNodes:r,children:i}=e,c=V(t||n,s||null,i||r);return o&&(c.nodeValue=o),c}i.length&&(s=[s,...i]),d=R.get();const u=e===v;"string"==typeof e?(d.rawNodeName=e,d.nodeName=d.rawNodeName.toLowerCase()):(d.rawNodeName=e,d.nodeName=k),d.nodeValue=n.STR,d.key=n.STR,d.childNodes.length=0,d.attributes={};const h=x(o)||"object"!=typeof o?o:s,f=C(x(h)?h:[h]);if(u){const e=f.join(n.STR);return d.nodeType=t.TEXT,d.nodeValue=String(e),d}if(d.nodeName===k?d.nodeType=t.FRAGMENT:d.nodeType="#comment"===e?t.COMMENT:t.ELEMENT,h&&f.length&&(!o||!o.childNodes))for(let e=0;e{(t=e(d))&&(d=V(t))})),d}const I=new Map;let _=0;function A(e){const{mount:t,input:o}=e,s=o,r=_++;return T("collectMetrics",!1)?e=>{e=`[${r}] ${e}`;const{host:n}=t;t&&n?e=`${n.constructor.name} ${e}`:s&&"function"==typeof s.rawNodeName&&(e=`${s.rawNodeName.name} ${e}`);const o=`${e}-end`;if(I.has(e)){const t=I.get(e)||0,n=(performance.now()-t).toFixed(3);I.delete(e),performance.mark(o),performance.measure(`diffHTML ${e} (${n}ms)`,e,o)}else I.set(e,performance.now()),performance.mark(e)}:n.FUN}const{protect:L,unprotect:B,memory:D}=R;function U(e){if(L(e),e.childNodes.length)for(let t=0;t{e.attributes={},e.childNodes.length=0,e.key=n.STR,D.free.add(e),D.allocated.delete(e),r.delete(e)}))}var j=Object.freeze({__proto__:null,protectVTree:U,unprotectVTree:H,gc:$});function F(e){const{mount:t,input:n,state:{measure:o},config:s}=e,r=s.inner?"innerHTML":"outerHTML";o("should update");if("string"==typeof n&&t[r]===n)return e.abort(!0);o("should update")}const J="undefined"!=typeof requestIdleCallback;let P=-1;function z(e){if(s.has(e)){const{mutationObserver:t,oldTree:n}=s.get(e);t&&t.disconnect(),n&&!r.has(n)&&(l.forEach((e=>e(n))),H(n)),s.delete(e)}if(!e)return;const t=e;if(t.childNodes&&t.childNodes.length)for(let e=0;e{e===t&&(l.forEach((e=>e(n))),H(n))})),(J?cancelIdleCallback:clearTimeout)(P),P=(J?requestIdleCallback:setTimeout)($)}function G(e){const{state:n,mount:o,input:r,config:i}=e,{inner:c}=i,d=o;n.mutationObserver&&!n.isDirty?n.isDirty=Boolean(n.mutationObserver.takeRecords().length):n.mutationObserver||(n.isDirty=!1),!n.isDirty&&n.oldTree||(z(d),d.ownerDocument&&n.mutationObserver&&n.mutationObserver.observe(d,{subtree:!0,childList:!0,attributes:!0,characterData:!0}),n.oldTree=V(d),U(n.oldTree),s.set(o,n));const{nodeName:a,attributes:l}=n.oldTree;e.newTree||(e.newTree=V(r));const u=e.newTree;if(!c&&u.nodeType===t.FRAGMENT&&n.oldTree.nodeType!==t.FRAGMENT){let n=[];for(let e=0;e1&&(e.newTree=V(u.childNodes))}e.oldTree=n.oldTree;const{oldTree:h,newTree:f}=e;if(c&&h&&f){const n="string"!=typeof f.rawNodeName,o=f.nodeType===t.FRAGMENT&&!n?f.childNodes:f;e.newTree=V(a,l,o)}}const{assign:X}=Object,{max:q}=Math,Y=["old","new"],Z="#text";function K(e,s,r=[],i={},c=n.OBJ,d){e||(e=n.OBJ),s||(s=n.OBJ);const{svgElements:l=new Set}=i,u=e===n.OBJ||d;let h=null;if(a.size&&a.forEach((t=>{const n=t(e,s,c);n&&n===e?h=r:!1===n?h=!1:n&&X(s,n)})),null!==h||!s)return h;const f=e.nodeName,p=s.nodeName,N="svg"===p||l.has(s);if(p===Z){if(f===Z&&e.nodeValue!==s.nodeValue)return r.push(o.NODE_VALUE,e,s.nodeValue,e.nodeValue),e.nodeValue=s.nodeValue,r;if(u)return r.push(o.NODE_VALUE,s,s.nodeValue,null),r}const m=s.childNodes||[];if(s.nodeType===t.ELEMENT){const t=u?n.OBJ:e.attributes,i=s.attributes||n.OBJ;for(let n in i){const c=i[n];n in t&&t[n]===i[n]||(u||(t[n]=c),(e&&"script"===e.nodeName||"script"!==s.nodeName||"type"!==n)&&r.push(o.SET_ATTRIBUTE,u?s:e,n,c))}if(!u)for(let n in t)n in i||(r.push(o.REMOVE_ATTRIBUTE,e,n),delete t[n])}if(d){for(let e=0;et&&g.splice(e,1),r.push(o.REPLACE_CHILD,s,n)}}else m.splice(t,0,n),b+=1}if(g.length!==m.length){for(let e=m.length;e{(h=e(s))&&(u=h)})),!t)return u;let p=u;p||(p="#comment"===c?t.createComment(s.nodeValue||n.STR):"#text"===c?t.createTextNode(s.nodeValue||n.STR):"#document-fragment"===c?t.createDocumentFragment():o?t.createElementNS("http://www.w3.org/2000/svg",a):t.createElement(a),"script"===c&&(p.type="no-execute")),r.set(s,p);for(let e=0;e{const r="object"==typeof s&&s,i="function"==typeof s,c="symbol"==typeof s,d=t,a=0===o.indexOf("on")?o.toLowerCase():o,l="s-"+e.nodeName+"-"+a,u=t;if(ie.has(l))d[a]=s;else if(!re.has(l))try{d[a]=s,ie.add(l)}catch{re.add(l)}if(r||i||c){if(r&&"style"===a){const e=se(s);for(let t=0;t{const o="r-"+e.nodeName+"-"+n,s=t;if(ie.has(o))s[n]=void 0,delete s[n];else if(!re.has(o))try{s[n]=void 0,delete s[n],ie.add(o)}catch{re.add(o)}t.removeAttribute(n)};function ae(e){const{mount:t,state:s,patches:i}=e,{measure:c,scriptsToExecute:a}=s;c("patch node");const{ownerDocument:l}=t;s.ownerDocument=l||f.document;const u=e=>{"script"===e.nodeName&&a.set(e,e.attributes.type)};d.add(u),s.ownerDocument&&function(e,t=n.OBJ){const{ownerDocument:s,svgElements:i=new Set}=t,{length:c}=e;let d=0;for(;;){const t=e[d];if(d===c)break;switch(t){case o.REMOVE_ATTRIBUTE:case o.SET_ATTRIBUTE:{const n=t===o.SET_ATTRIBUTE,r=e[d+1],c=e[d+2],a=n?te(e[d+3]):null;d+=n?4:3;const l=Q(r,s,i.has(r));U(r),(n?ce:de)(r,l,c,a);break}case o.NODE_VALUE:{const t=e[d+1],n=e[d+2];d+=4;const o=Q(t,s,i.has(t));U(t),n.includes("&")?o.nodeValue=te(n):o.nodeValue=n;break}case o.INSERT_BEFORE:{const t=e[d+1],n=e[d+2];let o=e[d+3];if(d+=4,!r.has(t)&&t!==ne)continue;let c=r.get(t);if(t===ne){const e=r.get(o);e&&(c=e.parentNode,o=e.nextSibling?e.nextSibling:null)}const a=i.has(n);U(n);const l=o&&Q(o,s,a),u=Q(n,s,a);c.insertBefore(u,l||null);break}case o.REPLACE_CHILD:{const t=e[d+1],n=e[d+2];d+=3;const o=i.has(t),c=r.get(n),a=Q(t,s,o);if(!c||!c.parentNode)break;U(t),c.parentNode.insertBefore(a,c),c.parentNode.removeChild(c),H(n);break}case o.REMOVE_CHILD:{const t=e[d+1];d+=2;const n=r.get(t);if(!n||!n.parentNode)break;n.parentNode.removeChild(n),H(t);break}}}}(i,s),d.delete(u),c("patch node")}function le(e){return e.end()}const ue=f.document?document.createElement("script"):null;const{assign:he}=Object,fe=[F,G,W,ae,le],pe={shouldUpdate:F,reconcileTrees:G,syncTrees:W,patchNode:ae,endAsTransaction:le};class Ne{static create(e,t,n){return new Ne(e,t,n)}static flow(e,t){let n=e;for(let o=0;o{const s=`invoke ${o.name||"anon"}`;t(s);const r=o(e);r&&n.push(r),t(s)}))}constructor(e,t,o){this.mount=e,this.input=t,this.config=o;const r=!o.disableMutationObserver&&"MutationObserver"in(f.window||n.OBJ);this.state=s.get(e)||{measure:A(this),svgElements:new Set,scriptsToExecute:new Map,mutationObserver:r&&new f.window.MutationObserver((()=>{this.state.isDirty=!0}))},this.tasks=T("tasks",fe,void 0,o).slice(),this.endedCallbacks=new Set,s.set(e,this.state)}start(){const{state:{measure:e},tasks:t}=this,n=t.pop();return e("render"),this.aborted=!1,Ne.invokeMiddleware(this),n&&t.push(n),Ne.flow(this,t)}abort(e){if(this.aborted=!0,e)return this.tasks[this.tasks.length-1](this)}end(){const{state:e,config:t,mount:n}=this,{mutationObserver:o,measure:i,svgElements:c,scriptsToExecute:d}=e,a=n;return i("finalize"),this.completed=!0,c.clear(),e.isRendering=!1,e.isDirty=!1,s.forEach((e=>{e.mutationObserver&&e.mutationObserver.takeRecords()})),a.ownerDocument&&o?o.observe(a,{subtree:!0,childList:!0,attributes:!0,characterData:!0}):e.isDirty=!0,d.forEach(((n,o)=>{const i=r.get(o);if(i.type=n,!t.executeScripts||Boolean(ue&&"noModule"in ue)&&"nomodule"===n)return;const c=he(i.ownerDocument.createElement("script"),i);for(let e in o.attributes){const t=o.attributes[e];c.setAttribute(e,t)}c.textContent=i.textContent,s.has(i)&&(z(i),s.set(c,e)),r.set(o,c),i.parentNode&&i.parentNode.replaceChild(c,i)})),d.clear(),this.endedCallbacks.forEach((e=>e(this))),this.endedCallbacks.clear(),i("finalize"),i("render"),e.oldTree&&U(e.oldTree),this}onceEnded(e){this.endedCallbacks.add(e)}state=n.OBJ;mount=n.OBJ;input=n.OBJ;oldTree=void 0;newTree=void 0;tasks=[];patches=[]}function me(e){return e.replace(/[&<>]/g,(e=>`&#${e.charCodeAt(0)};`))}var Te={decodeEntities:te,escape:me,makeMeasure:A,memory:j,Pool:R,process:h,globalConfig:{collectMetrics:!0,executeScripts:!0},parse:n.FUN,PATCH_TYPE:o,NODE_TYPE:t,createNode:Q,syncTree:K,Transaction:Ne,defaultTasks:fe,tasks:pe,...{StateCache:s,NodeCache:r,MiddlewareCache:i,CreateTreeHookCache:c,CreateNodeHookCache:d,SyncTreeHookCache:a,ReleaseHookCache:l,ParseHookCache:u}};const ge=["script","noscript","style","template"],be=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Ee={li:{li:n.NUM},dt:{dt:n.NUM,dd:n.NUM},dd:{dt:n.NUM,dd:n.NUM},td:{td:n.NUM,th:n.NUM},th:{td:n.NUM,th:n.NUM},tbody:{tbody:n.NUM,tfoot:n.NUM},tfoot:{tbody:n.NUM,tfoot:n.NUM}},ye=//g,Se=/<([^\s\\/>]*)\s?/g,Oe=/\s?(\/>)|(<\/(.*?)>)/g,Re=/([^>\/\n ])*?(["'])(?:(?=(\\?))\3.)*?\2|.*?(?=\/>|>|\n| )/gms,xe=/([^=]*)=(.*)|([^>])/gms,Me=/([^<]*)/g;function ke(e){if("string"!=typeof e)return e;const t=['"',"'"],n=t.indexOf(e[0]),o=-1!==n&&t.indexOf(e[e.length-1]);return-1!==n&&o===n?e.slice(1,e.length-1):e}function ve(e,t=n.STR,o={}){return o.inner=!0,o.executeScripts=!("executeScripts"in o)||o.executeScripts,o.tasks=o.tasks||fe,Ne.create(e,t,o).start()}function Ce(e,t=n.STR,o={}){return o.inner=!1,o.executeScripts=!("executeScripts"in o)||o.executeScripts,o.tasks=o.tasks||fe,Ne.create(e,t,o).start()}const{keys:Ve}=Object;function Ie(e,t={}){const n=V(),o=new Set(t.tasks||fe);o.delete(pe.patchNode),o.delete(pe.endAsTransaction),o.add((function(e){return Ae(e.oldTree)})),t.tasks=[...o],t.inner=!0;let s="";try{s=Ne.create(n,e,t).start()}catch(e){throw z(n),e}return z(n),s}function _e(e){const t=Ve(e);return t.length?" "+t.map((t=>{const n=e[t];return!0===n?t:`${t}${!n||("object"==typeof n||"function"==typeof n)?"":`="${String(n)}"`}`})).join(" "):""}function Ae(e){let t="";if(!e)return t;const{childNodes:n,nodeType:o,nodeName:s,nodeValue:r,attributes:i}=e;if(11===o)for(let e=0;e`${Ae(e)}`)).join("");t+=`<${s}${_e(i)}>${e}`}}else t+=`<${s}${_e(i)}>`;return t}const Le="__DIFFHTML__",{getOwnPropertyNames:Be}=Object,{isArray:De}=Array,Ue=new RegExp(`${Le}([^_]*)__`),He=(e,o)=>{let s=null,r=e.rawNodeName;if(e.nodeType===t.COMMENT){const t=e.nodeValue.split(Ue);let n="";for(let e=0;e{const r=e.attributes[t];let i=r,c=t;if(s=Ue.exec(r)){const e=r.split(Ue);if(i="",3===e.length&&e[0]===n.STR&&e[2]===n.STR)i=o.attributes[e[1]];else for(let t=0;t{if(r+=e,o.length){const e=(e=>{const t=e.shift();return"string"==typeof t?me(te(t)):t})(o),n=r.trim().slice(-1),s=r.trim().slice(-2),c=r.lastIndexOf(">"){t&&i.delete(e),o&&o(Te),s&&c.delete(s),r&&d.delete(r),h&&a.delete(h),f&&l.delete(f),p&&u.delete(p)}}const Fe="1.0.0-beta.30";fe.splice(fe.indexOf(G),0,(function(e){const{state:t,input:n,config:o}=e,{measure:s}=t;if("string"==typeof n){s("parsing input for new tree");const{childNodes:t}=Te.parse(n,o),r=V(t);r&&(e.newTree=r),s("parsing input for new tree")}})),Te.VERSION=Fe,Te.parse=function(e,o={}){const s=V("#document-fragment",null,[]);if(!e)return s.childNodes.push(V("#text",n.STR)),s;o.parser||(o.parser=n.OBJ);const r=new Set(T("rawElements",ge,"array",o.parser)),i=new Set(T("voidElements",be,"array",o.parser));if(!e.includes("<")&&!e.includes(">")){const t=V("#text",e);return s.childNodes.push(t),s}const c=[s];let d=0,a=s,l=!1,u=e.indexOf("\x3c!--");const h=()=>{const e=V(c.pop());a=c[c.length-1],a.childNodes.push(e)};for(;d",T)+1;continue}const t={rawNodeName:m,nodeName:m,childNodes:[],attributes:{},nodeType:n.NUM,nodeValue:n.STR,key:n.STR},o=Ee[m];o&&o[a.nodeName]&&h(),a=t,c.push(a),l=!0,d=T+N.length;continue}const{0:g,index:b}=Re.exec(e)||n.OBJ,E=b===d&&g.trim();if(l&&b===d){if(!E){if(d=d+g.length+1,">"===e[d-1]){const t=d===e.length;("/"===e[d-2]||i.has(a.nodeName)||t)&&h(),l=!1}continue}const{1:t=g,2:o=g}=xe.exec(E)||n.OBJ,s=t===o||void 0===o,r=t.trim();a.attributes[r]=s?Boolean(o):ke(o),d=b+g.length;continue}if(p){const t=``;let n=e.indexOf(t,d);-1===n&&(n=e.length);const o=e.slice(d,n);o&&a.childNodes.push(V("#text",o)),d=n+t.length,l=!1,h();continue}if(">"===e[d]){l=!1,d+=1,i.has(a.nodeName)&&h();continue}const{0:y,3:w,index:S}=Oe.exec(e)||n.OBJ;if(S===d&&y){const e=i.has(w);"/"===y[1]&&f&&!e&&h(),l=!1,d=S+y.length;continue}const{0:O,index:R}=Me.exec(e)||n.OBJ;if(l||R!==d||!O.length)a.childNodes.push(V("#text",e.slice(d,e.length))),d=e.length;else{const t=V("#text",O);a.childNodes.push(t),d=R+O.length,d===e.length&&f&&h()}}if(s.childNodes.length&&"html"===s.childNodes[0].nodeName){const e={before:[],after:[]},n={after:[]},o=s.childNodes[0];let r=!0,i=!0;if(o.childNodes=o.childNodes.filter((o=>{if("body"===o.nodeName||"head"===o.nodeName)return"head"===o.nodeName&&(r=!1),"body"===o.nodeName&&(i=!1),!0;o.nodeType===t.ELEMENT&&(r&&i?e.before.push(o):!r&&i?e.after.push(o):i||n.after.push(o))})),o.childNodes[0]&&"head"===o.childNodes[0].nodeName){const t=o.childNodes[0].childNodes;t.unshift.apply(t,e.before),t.push.apply(t,e.after)}else{const t=V("head",null,[]);if(t){const n=t.childNodes;n.unshift.apply(n,e.before),n.push.apply(n,e.after),o.childNodes.unshift(t)}}if(o.childNodes[1]&&"body"===o.childNodes[1].nodeName){const e=o.childNodes[1].childNodes;e.push.apply(e,n.after)}else{const e=V("body",null,[]);if(e){const t=e.childNodes;t.push.apply(t,n.after),o.childNodes.push(e)}}}return s};const Je={};if(Je.VERSION=Fe,Je.release=z,Je.createTree=V,Je.use=je,Je.outerHTML=Ce,Je.innerHTML=ve,Je.toString=Ie,Je.html=$e,Je.Internals=Te,oe in f){const e=f[oe];Fe!==e.VERSION&&console.log(`Loaded 1.0.0-beta.30 after ${e.VERSION}`)}f[oe]=Je,f.devTools&&(f.unsubscribeDevTools=je(f.devTools(Te))),e.Internals=Te,e.VERSION=Fe,e.createTree=V,e.default=Je,e.html=$e,e.innerHTML=ve,e.outerHTML=Ce,e.release=z,e.toString=Ie,e.use=je,Object.defineProperty(e,"__esModule",{value:!0})}));