!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,c=new Set,a=new Set,i=new Set,l=new Set,d=new Set,u=new Set;var h={env:{NODE_ENV:"production"}},f="object"==typeof global?global:("object"==typeof window?window:self)||{};const{parseInt:p}=Number,{parse:T}=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 T(n)}}function N(e,t,n=typeof t,o){const{location:s,URLSearchParams:r}=f,c=void 0!==r&&void 0!==s,a=h.env;if(o&&e in o)return o[e];const i=`DIFF_${e.replace(/[^a-zA-Z0-9]/,"")}`;if(c){const e=new r(s.search),t=i.toLowerCase();if(e.has(t))return m(decodeURIComponent(String(e.get(t))),n)}const l=i.toUpperCase();return a&&l in h.env?m(h.env[l.toUpperCase()],n):t}const E=N("initialPoolSize",5e3),b=new Set,g=new Set,w=new Set,y=()=>({rawNodeName:n.STR,nodeName:n.STR,nodeValue:n.STR,nodeType:t.ELEMENT,key:n.STR,childNodes:[],attributes:{}}),S={free:b,allocated:g,protected:w};let R=b.values();const O={size:E,memory:S,fill(){for(let e=b.size;e{b.size!==this.size&&b.delete(e)}))},get(){const{value:e=y(),done:t}=R.next();return t&&(R=b.values()),b.delete(e),g.add(e),e},protect(e){g.delete(e),w.add(e)},unprotect(e){(w.has(e)||g.has(e))&&(w.delete(e),g.add(e))}};O.fill();const{isArray:k}=Array,{memory:M}=O,v="#document-fragment",C="#text";function L(e,t=[]){for(let n=0;n{t===e&&(i=n)})),i=i||V(d.nodeName,o,s),i.attributes={...i.attributes,...o},i.childNodes=s,r.set(i,d),i}if(l&&!o){const{rawNodeName:t,nodeName:n,nodeValue:o,attributes:s,childNodes:r,children:c}=e,a=V(t||n,s||null,c||r);return o&&(a.nodeValue=o),a}c.length&&(s=[s,...c]),i=O.get();const u=e===C;"string"==typeof e?(i.rawNodeName=e,i.nodeName=i.rawNodeName.toLowerCase()):(i.rawNodeName=e,i.nodeName=v),i.nodeValue=n.STR,i.key=n.STR,i.childNodes.length=0,i.attributes={};const h=k(o)||"object"!=typeof o?o:s,f=L(k(h)?h:[h]);if(u){const e=f.join(n.STR);return i.nodeType=t.TEXT,i.nodeValue=String(e),i}if(i.nodeName===v?i.nodeType=t.FRAGMENT:i.nodeType="#comment"===e?t.COMMENT:t.ELEMENT,h&&f.length&&(!o||!o.childNodes))for(let e=0;e{(t=e(i))&&(i=V(t))})),i}const A=new Map;let D=0;function I(e){const{mount:t,input:o}=e,s=o,r=D++;return N("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(A.has(e)){const t=A.get(e)||0,n=(performance.now()-t).toFixed(3);A.delete(e),performance.mark(o),performance.measure(`diffHTML ${e} (${n}ms)`,e,o)}else A.set(e,performance.now()),performance.mark(e)}:n.FUN}const{protect:_,unprotect:x,memory:H}=O;function B(e){if(_(e),e.childNodes.length)for(let t=0;t{e.attributes={},e.childNodes.length=0,e.key=n.STR,H.free.add(e),H.allocated.delete(e),r.delete(e)}))}var j=Object.freeze({__proto__:null,protectVTree:B,unprotectVTree:U,gc:F});function z(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 P="undefined"!=typeof requestIdleCallback;let $=-1;function J(e){if(s.has(e)){const{mutationObserver:t,oldTree:n}=s.get(e);t&&t.disconnect(),n&&!r.has(n)&&(d.forEach((e=>e(n))),U(n)),s.delete(e)}if(!e)return;const t=e;if(t.childNodes&&t.childNodes.length)for(let e=0;e{e===t&&(d.forEach((e=>e(n))),U(n))})),(P?cancelIdleCallback:clearTimeout)($),$=(P?requestIdleCallback:setTimeout)(F)}function G(e){const{state:n,mount:o,input:r,config:c}=e,{inner:a}=c,i=o;n.mutationObserver&&!n.isDirty?n.isDirty=Boolean(n.mutationObserver.takeRecords().length):n.mutationObserver||(n.isDirty=!1),!n.isDirty&&n.oldTree||(J(i),i.ownerDocument&&n.mutationObserver&&n.mutationObserver.observe(i,{subtree:!0,childList:!0,attributes:!0,characterData:!0}),n.oldTree=V(i),B(n.oldTree),s.set(o,n));const{nodeName:l,attributes:d}=n.oldTree;e.newTree||(e.newTree=V(r));const u=e.newTree;if(!a&&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(a&&h&&f){const n="string"!=typeof f.rawNodeName,o=f.nodeType===t.FRAGMENT&&!n?f.childNodes:f;e.newTree=V(l,d,o)}}const{assign:X}=Object,{max:q}=Math,Y=["old","new"],Z="#text";function K(e,s,r=[],c={},a=n.OBJ,i){e||(e=n.OBJ),s||(s=n.OBJ);const{svgElements:d=new Set}=c,u=e===n.OBJ||i;let h=null;if(l.size&&l.forEach((t=>{const n=t(e,s,a);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,T="svg"===p||d.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,c=s.attributes||n.OBJ;for(let n in c){const a=c[n];n in t&&t[n]===c[n]||(u||(t[n]=a),(e&&"script"===e.nodeName||"script"!==s.nodeName||"type"!==n)&&r.push(o.SET_ATTRIBUTE,u?s:e,n,a))}if(!u)for(let n in t)n in c||(r.push(o.REMOVE_ATTRIBUTE,e,n),delete t[n])}if(i){for(let e=0;et&&E.splice(e,1),r.push(o.REPLACE_CHILD,s,n)}}else m.splice(t,0,n),b+=1}if(E.length!==m.length){for(let e=m.length;e{(h=e(s))&&(u=h)})),!t)return u;let p=u;p||(p="#comment"===a?t.createComment(s.nodeValue||n.STR):"#text"===a?t.createTextNode(s.nodeValue||n.STR):"#document-fragment"===a?t.createDocumentFragment():o?t.createElementNS("http://www.w3.org/2000/svg",l):t.createElement(l),"script"===a&&(p.type="no-execute")),r.set(s,p);for(let e=0;e{const r="object"==typeof s&&s,c="function"==typeof s,a="symbol"==typeof s,i=t,l=0===o.indexOf("on")?o.toLowerCase():o,d="s-"+e.nodeName+"-"+l,u=t;if(ce.has(d))i[l]=s;else if(!re.has(d))try{i[l]=s,ce.add(d)}catch{re.add(d)}if(r||c||a){if(r&&"style"===l){const e=se(s);for(let t=0;t{const o="r-"+e.nodeName+"-"+n,s=t;if(ce.has(o))s[n]=void 0,delete s[n];else if(!re.has(o))try{s[n]=void 0,delete s[n],ce.add(o)}catch{re.add(o)}t.removeAttribute(n)};function le(e){const{mount:t,state:s,patches:c}=e,{measure:a,scriptsToExecute:l}=s;a("patch node");const{ownerDocument:d}=t;s.ownerDocument=d||f.document;const u=e=>{"script"===e.nodeName&&l.set(e,e.attributes.type)};i.add(u),s.ownerDocument&&function(e,t=n.OBJ){const{ownerDocument:s,svgElements:c=new Set}=t,{length:a}=e;let i=0;for(;;){const t=e[i];if(i===a)break;switch(t){case o.REMOVE_ATTRIBUTE:case o.SET_ATTRIBUTE:{const n=t===o.SET_ATTRIBUTE,r=e[i+1],a=e[i+2],l=n?te(e[i+3]):null;i+=n?4:3;const d=Q(r,s,c.has(r));B(r),(n?ae:ie)(r,d,a,l);break}case o.NODE_VALUE:{const t=e[i+1],n=e[i+2];i+=4;const o=Q(t,s,c.has(t));B(t),n.includes("&")?o.nodeValue=te(n):o.nodeValue=n;break}case o.INSERT_BEFORE:{const t=e[i+1],n=e[i+2];let o=e[i+3];if(i+=4,!r.has(t)&&t!==ne)continue;let a=r.get(t);if(t===ne){const e=r.get(o);e&&(a=e.parentNode,o=e.nextSibling?e.nextSibling:null)}const l=c.has(n);B(n);const d=o&&Q(o,s,l),u=Q(n,s,l);a.insertBefore(u,d||null);break}case o.REPLACE_CHILD:{const t=e[i+1],n=e[i+2];i+=3;const o=c.has(t),a=r.get(n),l=Q(t,s,o);if(!a||!a.parentNode)break;B(t),a.parentNode.insertBefore(l,a),a.parentNode.removeChild(a),U(n);break}case o.REMOVE_CHILD:{const t=e[i+1];i+=2;const n=r.get(t);if(!n||!n.parentNode)break;n.parentNode.removeChild(n),U(t);break}}}}(c,s),i.delete(u),a("patch node")}function de(e){return e.end()}const ue=f.document?document.createElement("script"):null;const{assign:he}=Object,fe=[z,G,W,le,de],pe={shouldUpdate:z,reconcileTrees:G,syncTrees:W,patchNode:le,endAsTransaction:de};class Te{static create(e,t,n){return new Te(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:I(this),svgElements:new Set,scriptsToExecute:new Map,mutationObserver:r&&new f.window.MutationObserver((()=>{this.state.isDirty=!0}))},this.tasks=N("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,Te.invokeMiddleware(this),n&&t.push(n),Te.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:c,svgElements:a,scriptsToExecute:i}=e,l=n;return c("finalize"),this.completed=!0,a.clear(),e.isRendering=!1,e.isDirty=!1,s.forEach((e=>{e.mutationObserver&&e.mutationObserver.takeRecords()})),l.ownerDocument&&o?o.observe(l,{subtree:!0,childList:!0,attributes:!0,characterData:!0}):e.isDirty=!0,i.forEach(((n,o)=>{const c=r.get(o);if(c.type=n,!t.executeScripts||Boolean(ue&&"noModule"in ue)&&"nomodule"===n)return;const a=he(c.ownerDocument.createElement("script"),c);for(let e in o.attributes){const t=o.attributes[e];a.setAttribute(e,t)}a.textContent=c.textContent,s.has(c)&&(J(c),s.set(a,e)),r.set(o,a),c.parentNode&&c.parentNode.replaceChild(a,c)})),i.clear(),this.endedCallbacks.forEach((e=>e(this))),this.endedCallbacks.clear(),c("finalize"),c("render"),e.oldTree&&B(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=[]}var me={decodeEntities:te,escape:function(e){return e.replace(/[&<>]/g,(e=>`&#${e.charCodeAt(0)};`))},makeMeasure:I,memory:j,Pool:O,process:h,globalConfig:{collectMetrics:!0,executeScripts:!0},parse:n.FUN,PATCH_TYPE:o,NODE_TYPE:t,createNode:Q,syncTree:K,Transaction:Te,defaultTasks:fe,tasks:pe,...{StateCache:s,NodeCache:r,MiddlewareCache:c,CreateTreeHookCache:a,CreateNodeHookCache:i,SyncTreeHookCache:l,ReleaseHookCache:d,ParseHookCache:u}};function Ne(e,t=n.STR,o={}){return o.inner=!0,o.executeScripts=!("executeScripts"in o)||o.executeScripts,o.tasks=o.tasks||fe,Te.create(e,t,o).start()}function Ee(e,t=n.STR,o={}){return o.inner=!1,o.executeScripts=!("executeScripts"in o)||o.executeScripts,o.tasks=o.tasks||fe,Te.create(e,t,o).start()}function be(e){const t="function"==typeof e,{subscribe:n,unsubscribe:o,createTreeHook:s,createNodeHook:r,syncTreeHook:h,releaseHook:f,parseHook:p}=e;return t&&c.add(e),n&&n(me),s&&a.add(s),r&&i.add(r),h&&l.add(h),f&&d.add(f),p&&u.add(p),()=>{t&&c.delete(e),o&&o(me),s&&a.delete(s),r&&i.delete(r),h&&l.delete(h),f&&d.delete(f),p&&u.delete(p)}}const{assign:ge}=Object,we="1.0.0-beta.30-lite";ge(me,{VERSION:we});const ye={};if(ye.VERSION=we,ye.release=J,ye.createTree=V,ye.use=be,ye.outerHTML=Ee,ye.innerHTML=Ne,ye.html=V,ye.Internals=me,oe in f){const e=f[oe];we!==e.VERSION&&console.log(`Loaded ${we} after ${e.VERSION}`)}f[oe]=ye,f.devTools&&(f.unsubscribeDevTools=be(f.devTools(me))),e.Internals=me,e.VERSION=we,e.createTree=V,e.default=ye,e.html=V,e.innerHTML=Ne,e.outerHTML=Ee,e.release=J,e.use=be,Object.defineProperty(e,"__esModule",{value:!0})}));