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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1 line
22 KiB
JavaScript
Raw Normal View History

!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("coll