discourse/public/javascripts/diffhtml/1.0.0-beta.30/diffhtml.min.js

1 line
22 KiB
JavaScript

!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<this.size;e++)b.add(w());this.size<b.size&&b.forEach((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<e.length;n++){const o=e[n];o&&o.rawNodeName===k?C(o.childNodes,t):o&&t.push(o)}return t}function V(e,o,s,...i){let d=null;if(M.protected.has(e)||M.allocated.has(e))d=e;else if(!e||x(e)){const t=e?e.length:0;s=[];for(let n=0;n<t;n++){e&&!e[n]||e&&s.push(e[n])}d=V(k,null,s)}if(d)return d;const a="object"==typeof e,l=e;if(e&&a&&"ownerDocument"in l){const{nodeType:i}=l;if(i===t.TEXT){const e=V(v,l.nodeValue);return r.set(e,l),e}o={},s=[];const c=l.attributes;if(l.nodeType===t.ELEMENT&&c&&c.length)for(let t=0;t<c.length;t++){const{name:s,value:r}=c[t];r===n.STR&&s in l?o[s]=e[s]:o[s]=r}if(l.nodeType===t.ELEMENT||l.nodeType===t.FRAGMENT){s=[];for(let e=0;e<l.childNodes.length;e++){const t=l.childNodes[e];s.push(V(t))}}return r.forEach(((t,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<f.length;e++){const n=f[e];if(x(n))d.childNodes.push(...n);else{if(!n)continue;n.nodeType===t.FRAGMENT&&"string"==typeof n.rawNodeName?d.childNodes.push(...n.childNodes):n&&"object"==typeof n?d.childNodes.push(V(n)):d.childNodes.push(V(v,null,n))}}if(o&&"object"==typeof o&&!x(o)&&(d.attributes={...o},o.childNodes)){const e="object"==typeof o.childNodes;d.childNodes.push(e?V(o.childNodes):V(v,o.childNodes))}return"script"===d.nodeName&&d.attributes.src&&(d.key=String(d.attributes.src)),d.attributes&&"key"in d.attributes&&(d.key=String(d.attributes.key)),c.size&&c.forEach(((e,t)=>{(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.childNodes.length;t++)U(e.childNodes[t])}function H(e){if(e.childNodes.length)for(let t=0;t<e.childNodes.length;t++)H(e.childNodes[t]);r.delete(e),B(e)}function $(){D.allocated.forEach((e=>{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<t.childNodes.length;e++)z(t.childNodes[e]);t.shadowRoot&&z(t.shadowRoot),r.forEach(((e,n)=>{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;e<u.childNodes.length;e++){const o=u.childNodes[e];o.nodeType===t.TEXT&&!o.nodeValue.trim()||n.push(o)}1===n.length?e.newTree=n[0]:n.length>1&&(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;e<m.length;e++)N&&l.add(m[e]),K(null,m[e],r,i,c,!0);return r}const T={old:new Map,new:new Map};for(let e=0;e<Y.length;e++){const t=T[Y[e]],n=arguments[e],o=n&&n.childNodes;if(o&&o.length)for(let e=0;e<o.length;e++){const n=o[e];n.key&&t.set(n.key,n)}}const g=e.childNodes||[];let b=q(m.length,g.length);for(let t=0;t<b;t++){const n=g&&g[t],s=m[t];if((N||s&&"svg"===s.nodeName)&&l.add(s),!s){!1===K(n,null,r,i,c,!0)&&m.splice(t,0,n);continue}if(!n){g.push(s),K(null,s,r,i,c,!0),r.push(o.INSERT_BEFORE,e,s,null);continue}const d=s.key,a=n.key,u=T.new.has(a),h=T.old.has(d);if(a||d){if(!u&&!h){K(n,s,r,i,c,!0),r.push(o.REPLACE_CHILD,s,n);continue}if(!u){r.push(o.REMOVE_CHILD,n),g.splice(g.indexOf(n),1),t-=1;continue}if(d!==a){let a=s;d&&h?(a=T.old.get(d),g.splice(g.indexOf(a),1)):a=s,K(null,a,r,i,c,!0),r.push(o.INSERT_BEFORE,e,a,n),g.splice(t,0,a);continue}}const f=n.nodeName===s.nodeName;if(!1!==K(n,s,r,i,c,!f)){if(!f){g[t]=s;const e=g.lastIndexOf(s);e>t&&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<g.length;e++)r.push(o.REMOVE_CHILD,g[e]);g.length=m.length}return r}function Q(e,t=f.document,o){const s=V(e),i=r.get(s);if(i)return i;const{nodeName:c,rawNodeName:a=c,childNodes:l=[]}=s;o=o||"svg"===c;let u=null,h=null;if(d.forEach((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<l.length;e++){const n=Q(l[e],t,o);p&&n&&p.appendChild(n)}return p}function W(e){const{state:r,state:{measure:i},oldTree:c,newTree:d,mount:a}=e;if(i("sync trees"),c&&d&&c.nodeName!==d.nodeName&&d.nodeType!==t.FRAGMENT){e.patches=[o.REPLACE_CHILD,d,c],e.oldTree=r.oldTree=d;const t=Q(d);s.delete(a),s.set(t,r),e.mount=t,"script"===d.nodeName&&r.scriptsToExecute.set(d,d.attributes.type||n.STR)}else e.patches=K(c||null,d||null,[],r,e);i("sync trees")}const ee=f.document?document.createElement("div"):null;function te(e){return ee&&e&&e.indexOf&&e.includes("&")?(ee.innerHTML=e,ee.textContent||n.STR):e}const ne=Symbol.for("diff.after"),oe=Symbol.for("diffHTML"),{keys:se}=Object,re=new Set,ie=new Set,ce=(e,t,o,s)=>{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<e.length;t++)u.style[e[t]]=s[e[t]]}}else{const e=null==s||!0===s;u.setAttribute(a,e?n.STR:s)}},de=(e,t,n)=>{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<t.length;o++){if(e.aborted)return n;if(n=t[o](e),void 0!==n&&n!==e)return n}return n}static assert(e){}static invokeMiddleware(e){const{state:{measure:t},tasks:n}=e;i.forEach((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,we=/-->/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<n.length;e++)t+=Ae(n[e]);else if(n.length||1!==o){if(3===o)t+=r;else if(n.length){const e=n.map((e=>`${Ae(e)}`)).join("");t+=`<${s}${_e(i)}>${e}</${s}>`}}else t+=`<${s}${_e(i)}></${s}>`;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<t.length;e++){n+=e%2!=0?o.attributes[t[e]]:t[e]}e.nodeValue=n}(s=Ue.exec(e.rawNodeName))&&(r=o.tags[s[1]],e=V(r,e.attributes,e.childNodes));for(const t of Be(e.attributes))t.split(" ").forEach((t=>{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<e.length;t++){i+=t%2!=0?o.attributes[e[t]]:e[t]}}if(s=Ue.exec(t)){const e=t.split(Ue);for(let t=0;t<e.length;t++)t%2!=0&&(c=o.attributes[e[t]])}c&&("string"!=typeof c?Array.isArray(c)?delete e.attributes[t]:(delete e.attributes[t],Object.assign(e.attributes,c)):(delete e.attributes[t],"childNodes"===c&&(e.childNodes.length=0,"string"!=typeof i?e.childNodes.push(V(i)):e.childNodes.push(V("#text",i))),e.attributes[c]=void 0===i||i)),e.attributes.key&&(e.key=e.attributes.key),"script"===e.nodeName&&e.attributes.src&&(e.key=e.attributes.src)}));if(s=Ue.exec(e.nodeValue)){const t=e.nodeValue.split(Ue),n=V();for(let e=0;e<t.length;e++)e%2!=0?n.childNodes.push(V(o.children[t[e]])):t[e]&&n.childNodes.push(V("#text",t[e]));return n}for(let t=0;t<e.childNodes.length;t++){const n=He(e.childNodes[t],o);"#document-fragment"===n.nodeName&&n.rawNodeName===n.nodeName?(e.childNodes.splice(t,1,...n.childNodes),t-=1):e.childNodes[t]=n}return e};function $e(e,...o){const s=V("#text",n.STR);if(!e)return s;if("string"==typeof e&&(e=[e]),1===e.length&&!o.length){if(!e[0])return s;let{childNodes:n}=Te.parse(e[0]);const o=n[0],r=n[n.length-1],i=o.nodeType===t.TEXT,c=r.nodeType===t.TEXT;if(i||c){const e=[].concat(...n);for(let n=0;n<e.length;n++){const s=e[n];s!==o&&s!==r||s.nodeType!==t.TEXT||s.nodeValue.trim()||e.splice(n,1)}1===e.length&&(n=e)}return V(1===n.length?n[0]:n)}let r=n.STR;const i={attributes:{},children:{},tags:{}};e.forEach(((e,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(">")<r.lastIndexOf("<"),d=Boolean("<"===n||"</"===s),a="object"==typeof e,l=`${Le}${t}__`;d?(i.tags[t]=e,r+=l):c?(i.attributes[t]=e,r+=l):De(e)||a?(i.children[t]=V(e),r+=l):e&&(r+=e)}}));const{childNodes:c}=Te.parse(r),d=He(V(c),i);return d.nodeType===t.FRAGMENT&&1===d.childNodes.length?d.childNodes[0]:d}function je(e){const t="function"==typeof e,{subscribe:n,unsubscribe:o,createTreeHook:s,createNodeHook:r,syncTreeHook:h,releaseHook:f,parseHook:p}=e;return t&&i.add(e),n&&n(Te),s&&c.add(s),r&&d.add(r),h&&a.add(h),f&&l.add(f),p&&u.add(p),()=>{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<e.length;){ye.lastIndex=d,we.lastIndex=d,Se.lastIndex=d,Oe.lastIndex=d,Re.lastIndex=d,Me.lastIndex=d,xe.lastIndex=0;const t=Boolean(null!==u&&u<=d),{index:o}=t&&ye.exec(e)||n.OBJ;t&&(u=o),-1===o&&(u=null);const f=a!==s,p=a&&r.has(a.nodeName);if(o===d){let{index:t}=we.exec(e)||n.OBJ;-1===t&&(t=e.length);const o=V("#comment");o.nodeValue=e.slice(d+4,t),a.childNodes.push(o),d=t+3;continue}const{0:N,1:m,index:T}=Se.exec(e)||n.OBJ;if(T===d&&m&&!p){if("!"===m[0]){d=e.indexOf(">",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=`</${a.nodeName}>`;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})}));