Comparing version 4.2.5 to 4.2.6
@@ -1,2 +0,2 @@ | ||
"use strict";function e(t,o,n){var s;return"#text"===t.nodeName?s=n.document.createTextNode(t.data):"#comment"===t.nodeName?s=n.document.createComment(t.data):(o?s=n.document.createElementNS("http://www.w3.org/2000/svg",t.nodeName):"svg"===t.nodeName.toLowerCase()?(s=n.document.createElementNS("http://www.w3.org/2000/svg","svg"),o=!0):s=n.document.createElement(t.nodeName),t.attributes&&Object.entries(t.attributes).forEach((function(e){var t=e[0],o=e[1];return s.setAttribute(t,o)})),t.childNodes&&t.childNodes.forEach((function(t){return s.appendChild(e(t,o,n))})),n.valueDiffing&&(t.value&&(s.value=t.value),t.checked&&(s.checked=t.checked),t.selected&&(s.selected=t.selected))),s}function t(e,t){for(t=t.slice();t.length>0;){if(!e.childNodes)return!1;var o=t.splice(0,1)[0];e=e.childNodes[o]}return e}function o(o,n,s){var i,a,l,c,r=t(o,n[s._const.route]),u={diff:n,node:r};if(s.preDiffApply(u))return!0;switch(n[s._const.action]){case s._const.addAttribute:if(!r||!r.setAttribute)return!1;r.setAttribute(n[s._const.name],n[s._const.value]);break;case s._const.modifyAttribute:if(!r||!r.setAttribute)return!1;r.setAttribute(n[s._const.name],n[s._const.newValue]),"INPUT"===r.nodeName&&"value"===n[s._const.name]&&(r.value=n[s._const.newValue]);break;case s._const.removeAttribute:if(!r||!r.removeAttribute)return!1;r.removeAttribute(n[s._const.name]);break;case s._const.modifyTextElement:if(!r||3!==r.nodeType)return!1;s.textDiff(r,r.data,n[s._const.oldValue],n[s._const.newValue]);break;case s._const.modifyValue:if(!r||void 0===r.value)return!1;r.value=n[s._const.newValue];break;case s._const.modifyComment:if(!r||void 0===r.data)return!1;s.textDiff(r,r.data,n[s._const.oldValue],n[s._const.newValue]);break;case s._const.modifyChecked:if(!r||void 0===r.checked)return!1;r.checked=n[s._const.newValue];break;case s._const.modifySelected:if(!r||void 0===r.selected)return!1;r.selected=n[s._const.newValue];break;case s._const.replaceElement:r.parentNode.replaceChild(e(n[s._const.newValue],"http://www.w3.org/2000/svg"===r.namespaceURI,s),r);break;case s._const.relocateGroup:Array.apply(void 0,new Array(n.groupLength)).map((function(){return r.removeChild(r.childNodes[n[s._const.from]])})).forEach((function(e,t){0===t&&(a=r.childNodes[n[s._const.to]]),r.insertBefore(e,a||null)}));break;case s._const.removeElement:r.parentNode.removeChild(r);break;case s._const.addElement:c=(l=n[s._const.route].slice()).splice(l.length-1,1)[0],(r=t(o,l)).insertBefore(e(n[s._const.element],"http://www.w3.org/2000/svg"===r.namespaceURI,s),r.childNodes[c]||null);break;case s._const.removeTextElement:if(!r||3!==r.nodeType)return!1;r.parentNode.removeChild(r);break;case s._const.addTextElement:if(c=(l=n[s._const.route].slice()).splice(l.length-1,1)[0],i=s.document.createTextNode(n[s._const.value]),!(r=t(o,l))||!r.childNodes)return!1;r.insertBefore(i,r.childNodes[c]||null);break;default:console.log("unknown action")}return u.newNode=i,s.postDiffApply(u),!0}function n(e,t,o){var n=e[t];e[t]=e[o],e[o]=n}function s(e,t,s){t.length||(t=[t]),(t=t.slice()).reverse(),t.forEach((function(t){!function(e,t,s){switch(t[s._const.action]){case s._const.addAttribute:t[s._const.action]=s._const.removeAttribute,o(e,t,s);break;case s._const.modifyAttribute:n(t,s._const.oldValue,s._const.newValue),o(e,t,s);break;case s._const.removeAttribute:t[s._const.action]=s._const.addAttribute,o(e,t,s);break;case s._const.modifyTextElement:case s._const.modifyValue:case s._const.modifyComment:case s._const.modifyChecked:case s._const.modifySelected:case s._const.replaceElement:n(t,s._const.oldValue,s._const.newValue),o(e,t,s);break;case s._const.relocateGroup:n(t,s._const.from,s._const.to),o(e,t,s);break;case s._const.removeElement:t[s._const.action]=s._const.addElement,o(e,t,s);break;case s._const.addElement:t[s._const.action]=s._const.removeElement,o(e,t,s);break;case s._const.removeTextElement:t[s._const.action]=s._const.addTextElement,o(e,t,s);break;case s._const.addTextElement:t[s._const.action]=s._const.removeTextElement,o(e,t,s);break;default:console.log("unknown action")}}(e,t,s)}))}Object.defineProperty(exports,"__esModule",{value:!0});var i=function(e){var t=this;void 0===e&&(e={}),Object.entries(e).forEach((function(e){var o=e[0],n=e[1];return t[o]=n}))};function a(e){var t=[];return t.push(e.nodeName),"#text"!==e.nodeName&&"#comment"!==e.nodeName&&e.attributes&&(e.attributes.class&&t.push(e.nodeName+"."+e.attributes.class.replace(/ /g,".")),e.attributes.id&&t.push(e.nodeName+"#"+e.attributes.id)),t}function l(e){var t={},o={};return e.forEach((function(e){a(e).forEach((function(e){var n=e in t;n||e in o?n&&(delete t[e],o[e]=!0):t[e]=!0}))})),t}function c(e,t){var o=l(e),n=l(t),s={};return Object.keys(o).forEach((function(e){n[e]&&(s[e]=!0)})),s}function r(e){return delete e.outerDone,delete e.innerDone,delete e.valueDone,!e.childNodes||e.childNodes.every(r)}function u(e,t){if(!["nodeName","value","checked","selected","data"].every((function(o){return e[o]===t[o]})))return!1;if(Boolean(e.attributes)!==Boolean(t.attributes))return!1;if(Boolean(e.childNodes)!==Boolean(t.childNodes))return!1;if(e.attributes){var o=Object.keys(e.attributes),n=Object.keys(t.attributes);if(o.length!==n.length)return!1;if(!o.every((function(o){return e.attributes[o]===t.attributes[o]})))return!1}if(e.childNodes){if(e.childNodes.length!==t.childNodes.length)return!1;if(!e.childNodes.every((function(e,o){return u(e,t.childNodes[o])})))return!1}return!0}function d(e,t,o,n,s){if(!e||!t)return!1;if(e.nodeName!==t.nodeName)return!1;if("#text"===e.nodeName)return!!s||e.data===t.data;if(e.nodeName in o)return!0;if(e.attributes&&t.attributes){if(e.attributes.id){if(e.attributes.id!==t.attributes.id)return!1;if(e.nodeName+"#"+e.attributes.id in o)return!0}if(e.attributes.class&&e.attributes.class===t.attributes.class)if(e.nodeName+"."+e.attributes.class.replace(/ /g,".")in o)return!0}if(n)return!0;var i=e.childNodes?e.childNodes.slice().reverse():[],a=t.childNodes?t.childNodes.slice().reverse():[];if(i.length!==a.length)return!1;if(s)return i.every((function(e,t){return e.nodeName===a[t].nodeName}));var l=c(i,a);return i.every((function(e,t){return d(e,a[t],l,!0,!0)}))}function h(e){return JSON.parse(JSON.stringify(e))}function f(e,t,o,n){var s=0,i=[],l=e.length,r=t.length,u=Array.apply(void 0,new Array(l+1)).map((function(){return[]})),h=c(e,t),f=l===r;f&&e.some((function(e,o){var n=a(e),s=a(t[o]);return n.length!==s.length?(f=!1,!0):(n.some((function(e,t){if(e!==s[t])return f=!1,!0})),!f||void 0)}));for(var p=0;p<l;p++)for(var m=e[p],_=0;_<r;_++){var V=t[_];o[p]||n[_]||!d(m,V,h,f)?u[p+1][_+1]=0:(u[p+1][_+1]=u[p][_]?u[p][_]+1:1,u[p+1][_+1]>=s&&(s=u[p+1][_+1],i=[p+1,_+1]))}return 0!==s&&{oldValue:i[0]-s,newValue:i[1]-s,length:s}}function p(e,t){return Array.apply(void 0,new Array(e)).map((function(){return t}))}i.prototype.toString=function(){return JSON.stringify(this)},i.prototype.setValue=function(e,t){return this[e]=t,this};var m=function(){this.list=[]};function _(e,t){var o,n,s=e;for(t=t.slice();t.length>0;){if(!s.childNodes)return!1;n=t.splice(0,1)[0],o=s,s=s.childNodes[n]}return{node:s,parentNode:o,nodeIndex:n}}function V(e,t,o){return t.forEach((function(t){!function(e,t,o){var n,s,i,a=_(e,t[o._const.route]),l=a.node,c=a.parentNode,r=a.nodeIndex,u=[],d={diff:t,node:l};if(o.preVirtualDiffApply(d))return!0;switch(t[o._const.action]){case o._const.addAttribute:l.attributes||(l.attributes={}),l.attributes[t[o._const.name]]=t[o._const.value],"checked"===t[o._const.name]?l.checked=!0:"selected"===t[o._const.name]?l.selected=!0:"INPUT"===l.nodeName&&"value"===t[o._const.name]&&(l.value=t[o._const.value]);break;case o._const.modifyAttribute:l.attributes[t[o._const.name]]=t[o._const.newValue];break;case o._const.removeAttribute:delete l.attributes[t[o._const.name]],0===Object.keys(l.attributes).length&&delete l.attributes,"checked"===t[o._const.name]?l.checked=!1:"selected"===t[o._const.name]?delete l.selected:"INPUT"===l.nodeName&&"value"===t[o._const.name]&&delete l.value;break;case o._const.modifyTextElement:l.data=t[o._const.newValue];break;case o._const.modifyValue:l.value=t[o._const.newValue];break;case o._const.modifyComment:l.data=t[o._const.newValue];break;case o._const.modifyChecked:l.checked=t[o._const.newValue];break;case o._const.modifySelected:l.selected=t[o._const.newValue];break;case o._const.replaceElement:(n=h(t[o._const.newValue])).outerDone=!0,n.innerDone=!0,n.valueDone=!0,c.childNodes[r]=n;break;case o._const.relocateGroup:l.childNodes.splice(t[o._const.from],t.groupLength).reverse().forEach((function(e){return l.childNodes.splice(t[o._const.to],0,e)})),l.subsets&&l.subsets.forEach((function(e){if(t[o._const.from]<t[o._const.to]&&e.oldValue<=t[o._const.to]&&e.oldValue>t[o._const.from]){e.oldValue-=t.groupLength;var n=e.oldValue+e.length-t[o._const.to];n>0&&(u.push({oldValue:t[o._const.to]+t.groupLength,newValue:e.newValue+e.length-n,length:n}),e.length-=n)}else if(t[o._const.from]>t[o._const.to]&&e.oldValue>t[o._const.to]&&e.oldValue<t[o._const.from]){e.oldValue+=t.groupLength;var s=e.oldValue+e.length-t[o._const.to];s>0&&(u.push({oldValue:t[o._const.to]+t.groupLength,newValue:e.newValue+e.length-s,length:s}),e.length-=s)}else e.oldValue===t[o._const.from]&&(e.oldValue=t[o._const.to])}));break;case o._const.removeElement:c.childNodes.splice(r,1),c.subsets&&c.subsets.forEach((function(e){e.oldValue>r?e.oldValue-=1:e.oldValue===r?e.delete=!0:e.oldValue<r&&e.oldValue+e.length>r&&(e.oldValue+e.length-1===r?e.length--:(u.push({newValue:e.newValue+r-e.oldValue,oldValue:r,length:e.length-r+e.oldValue-1}),e.length=r-e.oldValue))})),l=c;break;case o._const.addElement:s=t[o._const.route].slice(),i=s.splice(s.length-1,1)[0],l=_(e,s).node,(n=h(t[o._const.element])).outerDone=!0,n.innerDone=!0,n.valueDone=!0,l.childNodes||(l.childNodes=[]),i>=l.childNodes.length?l.childNodes.push(n):l.childNodes.splice(i,0,n),l.subsets&&l.subsets.forEach((function(e){if(e.oldValue>=i)e.oldValue+=1;else if(e.oldValue<i&&e.oldValue+e.length>i){var t=e.oldValue+e.length-i;u.push({newValue:e.newValue+e.length-t,oldValue:i+1,length:t}),e.length-=t}}));break;case o._const.removeTextElement:c.childNodes.splice(r,1),"TEXTAREA"===c.nodeName&&delete c.value,c.subsets&&c.subsets.forEach((function(e){e.oldValue>r?e.oldValue-=1:e.oldValue===r?e.delete=!0:e.oldValue<r&&e.oldValue+e.length>r&&(e.oldValue+e.length-1===r?e.length--:(u.push({newValue:e.newValue+r-e.oldValue,oldValue:r,length:e.length-r+e.oldValue-1}),e.length=r-e.oldValue))})),l=c;break;case o._const.addTextElement:s=t[o._const.route].slice(),i=s.splice(s.length-1,1)[0],(n={}).nodeName="#text",n.data=t[o._const.value],(l=_(e,s).node).childNodes||(l.childNodes=[]),i>=l.childNodes.length?l.childNodes.push(n):l.childNodes.splice(i,0,n),"TEXTAREA"===l.nodeName&&(l.value=t[o._const.newValue]),l.subsets&&l.subsets.forEach((function(e){if(e.oldValue>=i&&(e.oldValue+=1),e.oldValue<i&&e.oldValue+e.length>i){var t=e.oldValue+e.length-i;u.push({newValue:e.newValue+e.length-t,oldValue:i+1,length:t}),e.length-=t}}));break;default:console.log("unknown action")}l.subsets&&(l.subsets=l.subsets.filter((function(e){return!e.delete&&e.oldValue!==e.newValue})),u.length&&(l.subsets=l.subsets.concat(u))),d.newNode=n,o.postVirtualDiffApply(d)}(e,t,o)})),!0}function g(e,t){void 0===t&&(t={});var o={};if(o.nodeName=e.nodeName,"#text"===o.nodeName||"#comment"===o.nodeName)o.data=e.data;else{if(e.attributes&&e.attributes.length>0)o.attributes={},Array.prototype.slice.call(e.attributes).forEach((function(e){return o.attributes[e.name]=e.value}));if("TEXTAREA"===o.nodeName)o.value=e.value;else if(e.childNodes&&e.childNodes.length>0){o.childNodes=[],Array.prototype.slice.call(e.childNodes).forEach((function(e){return o.childNodes.push(g(e,t))}))}t.valueDiffing&&(void 0!==e.checked&&e.type&&["radio","checkbox"].includes(e.type.toLowerCase())?o.checked=e.checked:void 0!==e.value&&(o.value=e.value),void 0!==e.selected&&(o.selected=e.selected))}return o}m.prototype.add=function(e){var t;(t=this.list).push.apply(t,e)},m.prototype.forEach=function(e){this.list.forEach((function(t){return e(t)}))};var v=/<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>/g,N=Object.create?Object.create(null):{},b=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function y(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&")}var w={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuItem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0};function E(e){var t={nodeName:"",attributes:{}},o=e.match(/<\/?([^\s]+?)[/\s>]/);if(o&&(t.nodeName=o[1].toUpperCase(),(w[o[1]]||"/"===e.charAt(e.length-2))&&(t.voidElement=!0),t.nodeName.startsWith("!--"))){var n=e.indexOf("--\x3e");return{type:"comment",data:-1!==n?e.slice(4,n):""}}for(var s=new RegExp(b),i=null,a=!1;!a;)if(null===(i=s.exec(e)))a=!0;else if(i[0].trim())if(i[1]){var l=i[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),t.attributes[c[0]]=c[1],s.lastIndex--}else i[2]&&(t.attributes[i[2]]=i[3].trim().substring(1,i[3].length-1));return t}function k(e){return function e(t){return delete t.voidElement,t.childNodes&&t.childNodes.forEach((function(t){return e(t)})),t}(function(e,t){void 0===t&&(t={components:N});var o,n=[],s=-1,i=[],a=!1;if(0!==e.indexOf("<")){var l=e.indexOf("<");n.push({nodeName:"#text",data:-1===l?e:e.substring(0,l)})}return e.replace(v,(function(l,c){if(a){if(l!=="</"+o.nodeName+">")return;a=!1}var r,u="/"!==l.charAt(1),d=l.startsWith("\x3c!--"),h=c+l.length,f=e.charAt(h);if(d){var p=E(l);return s<0?(n.push(p),n):((r=i[s])&&(r.childNodes||(r.childNodes=[]),r.childNodes.push(p)),n)}if(u&&(o=E(l),s++,"tag"===o.type&&t.components[o.nodeName]&&(o.type="component",a=!0),o.voidElement||a||!f||"<"===f||(o.childNodes||(o.childNodes=[]),o.childNodes.push({nodeName:"#text",data:y(e.slice(h,e.indexOf("<",h)))})),0===s&&n.push(o),(r=i[s-1])&&(r.childNodes||(r.childNodes=[]),r.childNodes.push(o)),i[s]=o),(!u||o.voidElement)&&(s>-1&&(o.voidElement||o.nodeName===l.slice(2,-1).toUpperCase())&&(s--,o=-1===s?n:i[s]),!a&&"<"!==f&&f)){r=-1===s?n:i[s].childNodes||[];var m=e.indexOf("<",h),_=y(e.slice(h,-1===m?void 0:m));r.push({nodeName:"#text",data:_})}})),n[0]}(e))}var x=function(e,t,o){this.options=o,this.t1=e instanceof HTMLElement?g(e,this.options):"string"==typeof e?k(e,this.options):JSON.parse(JSON.stringify(e)),this.t2=t instanceof HTMLElement?g(t,this.options):"string"==typeof t?k(t,this.options):JSON.parse(JSON.stringify(t)),this.diffcount=0,this.foundAll=!1,this.debug&&(this.t1Orig=g(e,this.options),this.t2Orig=g(t,this.options)),this.tracker=new m};x.prototype.init=function(){return this.findDiffs(this.t1,this.t2)},x.prototype.findDiffs=function(e,t){var o;do{if(this.options.debug&&(this.diffcount+=1,this.diffcount>this.options.diffcap))throw new Error("surpassed diffcap:"+JSON.stringify(this.t1Orig)+" -> "+JSON.stringify(this.t2Orig));0===(o=this.findNextDiff(e,t,[])).length&&(u(e,t)||(this.foundAll?console.error("Could not find remaining diffs!"):(this.foundAll=!0,r(e),o=this.findNextDiff(e,t,[])))),o.length>0&&(this.foundAll=!1,this.tracker.add(o),V(e,o,this.options))}while(o.length>0);return this.tracker.list},x.prototype.findNextDiff=function(e,t,o){var n,s;if(this.options.maxDepth&&o.length>this.options.maxDepth)return[];if(!e.outerDone){if(n=this.findOuterDiff(e,t,o),this.options.filterOuterDiff&&(s=this.options.filterOuterDiff(e,t,n))&&(n=s),n.length>0)return e.outerDone=!0,n;e.outerDone=!0}if(!e.innerDone){if((n=this.findInnerDiff(e,t,o)).length>0)return n;e.innerDone=!0}if(this.options.valueDiffing&&!e.valueDone){if((n=this.findValueDiff(e,t,o)).length>0)return e.valueDone=!0,n;e.valueDone=!0}return[]},x.prototype.findOuterDiff=function(e,t,o){var n,s,a,l,c,r,u=[];if(e.nodeName!==t.nodeName){if(!o.length)throw new Error("Top level nodes have to be of the same kind.");return[(new i).setValue(this.options._const.action,this.options._const.replaceElement).setValue(this.options._const.oldValue,h(e)).setValue(this.options._const.newValue,h(t)).setValue(this.options._const.route,o)]}if(o.length&&this.options.maxNodeDiffCount<Math.abs((e.childNodes||[]).length-(t.childNodes||[]).length))return[(new i).setValue(this.options._const.action,this.options._const.replaceElement).setValue(this.options._const.oldValue,h(e)).setValue(this.options._const.newValue,h(t)).setValue(this.options._const.route,o)];if(e.data!==t.data)return"#text"===e.nodeName?[(new i).setValue(this.options._const.action,this.options._const.modifyTextElement).setValue(this.options._const.route,o).setValue(this.options._const.oldValue,e.data).setValue(this.options._const.newValue,t.data)]:[(new i).setValue(this.options._const.action,this.options._const.modifyComment).setValue(this.options._const.route,o).setValue(this.options._const.oldValue,e.data).setValue(this.options._const.newValue,t.data)];for(s=e.attributes?Object.keys(e.attributes).sort():[],a=t.attributes?Object.keys(t.attributes).sort():[],l=s.length,r=0;r<l;r++)n=s[r],-1===(c=a.indexOf(n))?u.push((new i).setValue(this.options._const.action,this.options._const.removeAttribute).setValue(this.options._const.route,o).setValue(this.options._const.name,n).setValue(this.options._const.value,e.attributes[n])):(a.splice(c,1),e.attributes[n]!==t.attributes[n]&&u.push((new i).setValue(this.options._const.action,this.options._const.modifyAttribute).setValue(this.options._const.route,o).setValue(this.options._const.name,n).setValue(this.options._const.oldValue,e.attributes[n]).setValue(this.options._const.newValue,t.attributes[n])));for(l=a.length,r=0;r<l;r++)n=a[r],u.push((new i).setValue(this.options._const.action,this.options._const.addAttribute).setValue(this.options._const.route,o).setValue(this.options._const.name,n).setValue(this.options._const.value,t.attributes[n]));return u},x.prototype.findInnerDiff=function(e,t,o){var n=e.childNodes?e.childNodes.slice():[],s=t.childNodes?t.childNodes.slice():[],a=Math.max(n.length,s.length),l=Math.abs(n.length-s.length),c=[],r=0;if(!this.options.maxChildCount||a<this.options.maxChildCount){var d=e.subsets&&e.subsetsAge--,m=d?e.subsets:e.childNodes&&t.childNodes?function(e,t){for(var o=e.childNodes?e.childNodes:[],n=t.childNodes?t.childNodes:[],s=p(o.length,!1),i=p(n.length,!1),a=[],l=!0,c=function(){return arguments[1]};l;){if(l=f(o,n,s,i))a.push(l),Array.apply(void 0,new Array(l.length)).map(c).forEach((function(e){return t=e,s[l.oldValue+t]=!0,void(i[l.newValue+t]=!0);var t}))}return e.subsets=a,e.subsetsAge=100,a}(e,t):[];if(m.length>0&&(c=this.attemptGroupRelocation(e,t,m,o,d)).length>0)return c}for(var _=0;_<a;_+=1){var V=n[_],g=s[_];l&&(V&&!g?"#text"===V.nodeName?(c.push((new i).setValue(this.options._const.action,this.options._const.removeTextElement).setValue(this.options._const.route,o.concat(r)).setValue(this.options._const.value,V.data)),r-=1):(c.push((new i).setValue(this.options._const.action,this.options._const.removeElement).setValue(this.options._const.route,o.concat(r)).setValue(this.options._const.element,h(V))),r-=1):g&&!V&&("#text"===g.nodeName?c.push((new i).setValue(this.options._const.action,this.options._const.addTextElement).setValue(this.options._const.route,o.concat(r)).setValue(this.options._const.value,g.data)):c.push((new i).setValue(this.options._const.action,this.options._const.addElement).setValue(this.options._const.route,o.concat(r)).setValue(this.options._const.element,h(g))))),V&&g&&(!this.options.maxChildCount||a<this.options.maxChildCount?c=c.concat(this.findNextDiff(V,g,o.concat(r))):u(V,g)||(n.length>s.length?("#text"===V.nodeName?c.push((new i).setValue(this.options._const.action,this.options._const.removeTextElement).setValue(this.options._const.route,o.concat(r)).setValue(this.options._const.value,V.data)):c.push((new i).setValue(this.options._const.action,this.options._const.removeElement).setValue(this.options._const.element,h(V)).setValue(this.options._const.route,o.concat(r))),n.splice(_,1),_-=1,r-=1,l-=1):n.length<s.length?(c=c.concat([(new i).setValue(this.options._const.action,this.options._const.addElement).setValue(this.options._const.element,h(g)).setValue(this.options._const.route,o.concat(r))]),n.splice(_,0,{}),l-=1):c=c.concat([(new i).setValue(this.options._const.action,this.options._const.replaceElement).setValue(this.options._const.oldValue,h(V)).setValue(this.options._const.newValue,h(g)).setValue(this.options._const.route,o.concat(r))]))),r+=1}return e.innerDone=!0,c},x.prototype.attemptGroupRelocation=function(e,t,o,n,s){for(var a,l,c,r,u,f,m=function(e,t,o){var n=e.childNodes?p(e.childNodes.length,!0):[],s=t.childNodes?p(t.childNodes.length,!0):[],i=0;return o.forEach((function(e){for(var t=e.oldValue+e.length,o=e.newValue+e.length,a=e.oldValue;a<t;a+=1)n[a]=i;for(var l=e.newValue;l<o;l+=1)s[l]=i;i+=1})),{gaps1:n,gaps2:s}}(e,t,o),_=m.gaps1,V=m.gaps2,g=Math.min(_.length,V.length),v=[],N=0,b=0;N<g;b+=1,N+=1)if(!s||!0!==_[N]&&!0!==V[N]){if(!0===_[N])if("#text"===(r=e.childNodes[b]).nodeName)if("#text"===t.childNodes[N].nodeName){if(r.data!==t.childNodes[N].data){for(f=b;e.childNodes.length>f+1&&"#text"===e.childNodes[f+1].nodeName;)if(f+=1,t.childNodes[N].data===e.childNodes[f].data){u=!0;break}if(!u)return v.push((new i).setValue(this.options._const.action,this.options._const.modifyTextElement).setValue(this.options._const.route,n.concat(N)).setValue(this.options._const.oldValue,r.data).setValue(this.options._const.newValue,t.childNodes[N].data)),v}}else v.push((new i).setValue(this.options._const.action,this.options._const.removeTextElement).setValue(this.options._const.route,n.concat(N)).setValue(this.options._const.value,r.data)),_.splice(N,1),g=Math.min(_.length,V.length),N-=1;else v.push((new i).setValue(this.options._const.action,this.options._const.removeElement).setValue(this.options._const.route,n.concat(N)).setValue(this.options._const.element,h(r))),_.splice(N,1),g=Math.min(_.length,V.length),N-=1;else if(!0===V[N])"#text"===(r=t.childNodes[N]).nodeName?(v.push((new i).setValue(this.options._const.action,this.options._const.addTextElement).setValue(this.options._const.route,n.concat(N)).setValue(this.options._const.value,r.data)),_.splice(N,0,!0),g=Math.min(_.length,V.length),b-=1):(v.push((new i).setValue(this.options._const.action,this.options._const.addElement).setValue(this.options._const.route,n.concat(N)).setValue(this.options._const.element,h(r))),_.splice(N,0,!0),g=Math.min(_.length,V.length),b-=1);else if(_[N]!==V[N]){if(v.length>0)return v;if(c=o[_[N]],(l=Math.min(c.newValue,e.childNodes.length-c.length))!==c.oldValue){a=!1;for(var y=0;y<c.length;y+=1)d(e.childNodes[l+y],e.childNodes[c.oldValue+y],[],!1,!0)||(a=!0);if(a)return[(new i).setValue(this.options._const.action,this.options._const.relocateGroup).setValue("groupLength",c.length).setValue(this.options._const.from,c.oldValue).setValue(this.options._const.to,l).setValue(this.options._const.route,n)]}}}else;return v},x.prototype.findValueDiff=function(e,t,o){var n=[];return e.selected!==t.selected&&n.push((new i).setValue(this.options._const.action,this.options._const.modifySelected).setValue(this.options._const.oldValue,e.selected).setValue(this.options._const.newValue,t.selected).setValue(this.options._const.route,o)),(e.value||t.value)&&e.value!==t.value&&"OPTION"!==e.nodeName&&n.push((new i).setValue(this.options._const.action,this.options._const.modifyValue).setValue(this.options._const.oldValue,e.value||"").setValue(this.options._const.newValue,t.value||"").setValue(this.options._const.route,o)),e.checked!==t.checked&&n.push((new i).setValue(this.options._const.action,this.options._const.modifyChecked).setValue(this.options._const.oldValue,e.checked).setValue(this.options._const.newValue,t.checked).setValue(this.options._const.route,o)),n};var A={debug:!1,diffcap:10,maxDepth:!1,maxChildCount:50,valueDiffing:!0,textDiff:function(e,t,o,n){e.data=n},preVirtualDiffApply:function(){},postVirtualDiffApply:function(){},preDiffApply:function(){},postDiffApply:function(){},filterOuterDiff:null,compress:!1,_const:!1,document:!("undefined"==typeof window||!window.document)&&window.document},D=function(e){var t=this;if(void 0===e&&(e={}),this.options=e,Object.entries(A).forEach((function(e){var o=e[0],n=e[1];Object.prototype.hasOwnProperty.call(t.options,o)||(t.options[o]=n)})),!this.options._const){var o=["addAttribute","modifyAttribute","removeAttribute","modifyTextElement","relocateGroup","removeElement","addElement","removeTextElement","addTextElement","replaceElement","modifyValue","modifyChecked","modifySelected","modifyComment","action","route","oldValue","newValue","element","group","from","to","name","value","data","attributes","nodeName","childNodes","checked","selected"];this.options._const={},this.options.compress?o.forEach((function(e,o){return t.options._const[e]=o})):o.forEach((function(e){return t.options._const[e]=e}))}this.DiffFinder=x};D.prototype.apply=function(e,t){return function(e,t,n){return t.every((function(t){return o(e,t,n)}))}(e,t,this.options)},D.prototype.undo=function(e,t){return s(e,t,this.options)},D.prototype.diff=function(e,t){return new this.DiffFinder(e,t,this.options).init()};var O=function(e){var t=this;void 0===e&&(e={}),this.pad="│ ",this.padding="",this.tick=1,this.messages=[];var o=function(e,o){var n=e[o];e[o]=function(){for(var s=[],i=arguments.length;i--;)s[i]=arguments[i];t.fin(o,Array.prototype.slice.call(s));var a=n.apply(e,s);return t.fout(o,a),a}};for(var n in e)"function"==typeof e[n]&&o(e,n);this.log("┌ TRACELOG START")};O.prototype.fin=function(e,t){this.padding+=this.pad,this.log("├─> entering "+e,t)},O.prototype.fout=function(e,t){this.log("│<──┘ generated return value",t),this.padding=this.padding.substring(0,this.padding.length-this.pad.length)},O.prototype.format=function(e,t){return function(e){for(e=""+e;e.length<4;)e="0"+e;return e}(t)+"> "+this.padding+e},O.prototype.log=function(){var e=Array.prototype.slice.call(arguments),t=function(e){return e?"string"==typeof e?e:e instanceof HTMLElement?e.outerHTML||"<empty>":e instanceof Array?"["+e.map(t).join(",")+"]":e.toString()||e.valueOf()||"<unknown>":"<falsey>"};e=e.map(t).join(", "),this.messages.push(this.format(e,this.tick++))},O.prototype.toString=function(){for(var e="└───";e.length<=this.padding.length+this.pad.length;)e+="× ";var t=this.padding;return this.padding="",e=this.format(e,this.tick),this.padding=t,this.messages.join("\n")+"\n"+e},exports.DiffDOM=D,exports.TraceLogger=O,exports.nodeToObj=g,exports.stringToObj=k; | ||
"use strict";function e(t,o,n){var s;return"#text"===t.nodeName?s=n.document.createTextNode(t.data):"#comment"===t.nodeName?s=n.document.createComment(t.data):(o?s=n.document.createElementNS("http://www.w3.org/2000/svg",t.nodeName):"svg"===t.nodeName.toLowerCase()?(s=n.document.createElementNS("http://www.w3.org/2000/svg","svg"),o=!0):s=n.document.createElement(t.nodeName),t.attributes&&Object.entries(t.attributes).forEach((function(e){var t=e[0],o=e[1];return s.setAttribute(t,o)})),t.childNodes&&t.childNodes.forEach((function(t){return s.appendChild(e(t,o,n))})),n.valueDiffing&&(t.value&&(s.value=t.value),t.checked&&(s.checked=t.checked),t.selected&&(s.selected=t.selected))),s}function t(e,t){for(t=t.slice();t.length>0;){if(!e.childNodes)return!1;var o=t.splice(0,1)[0];e=e.childNodes[o]}return e}function o(o,n,s){var i,a,l,c,r=t(o,n[s._const.route]),u={diff:n,node:r};if(s.preDiffApply(u))return!0;switch(n[s._const.action]){case s._const.addAttribute:if(!r||!r.setAttribute)return!1;r.setAttribute(n[s._const.name],n[s._const.value]);break;case s._const.modifyAttribute:if(!r||!r.setAttribute)return!1;r.setAttribute(n[s._const.name],n[s._const.newValue]),"INPUT"===r.nodeName&&"value"===n[s._const.name]&&(r.value=n[s._const.newValue]);break;case s._const.removeAttribute:if(!r||!r.removeAttribute)return!1;r.removeAttribute(n[s._const.name]);break;case s._const.modifyTextElement:if(!r||3!==r.nodeType)return!1;s.textDiff(r,r.data,n[s._const.oldValue],n[s._const.newValue]);break;case s._const.modifyValue:if(!r||void 0===r.value)return!1;r.value=n[s._const.newValue];break;case s._const.modifyComment:if(!r||void 0===r.data)return!1;s.textDiff(r,r.data,n[s._const.oldValue],n[s._const.newValue]);break;case s._const.modifyChecked:if(!r||void 0===r.checked)return!1;r.checked=n[s._const.newValue];break;case s._const.modifySelected:if(!r||void 0===r.selected)return!1;r.selected=n[s._const.newValue];break;case s._const.replaceElement:r.parentNode.replaceChild(e(n[s._const.newValue],"http://www.w3.org/2000/svg"===r.namespaceURI,s),r);break;case s._const.relocateGroup:Array.apply(void 0,new Array(n.groupLength)).map((function(){return r.removeChild(r.childNodes[n[s._const.from]])})).forEach((function(e,t){0===t&&(a=r.childNodes[n[s._const.to]]),r.insertBefore(e,a||null)}));break;case s._const.removeElement:r.parentNode.removeChild(r);break;case s._const.addElement:c=(l=n[s._const.route].slice()).splice(l.length-1,1)[0],(r=t(o,l)).insertBefore(e(n[s._const.element],"http://www.w3.org/2000/svg"===r.namespaceURI,s),r.childNodes[c]||null);break;case s._const.removeTextElement:if(!r||3!==r.nodeType)return!1;r.parentNode.removeChild(r);break;case s._const.addTextElement:if(c=(l=n[s._const.route].slice()).splice(l.length-1,1)[0],i=s.document.createTextNode(n[s._const.value]),!(r=t(o,l))||!r.childNodes)return!1;r.insertBefore(i,r.childNodes[c]||null);break;default:console.log("unknown action")}return u.newNode=i,s.postDiffApply(u),!0}function n(e,t,o){var n=e[t];e[t]=e[o],e[o]=n}function s(e,t,s){t.length||(t=[t]),(t=t.slice()).reverse(),t.forEach((function(t){!function(e,t,s){switch(t[s._const.action]){case s._const.addAttribute:t[s._const.action]=s._const.removeAttribute,o(e,t,s);break;case s._const.modifyAttribute:n(t,s._const.oldValue,s._const.newValue),o(e,t,s);break;case s._const.removeAttribute:t[s._const.action]=s._const.addAttribute,o(e,t,s);break;case s._const.modifyTextElement:case s._const.modifyValue:case s._const.modifyComment:case s._const.modifyChecked:case s._const.modifySelected:case s._const.replaceElement:n(t,s._const.oldValue,s._const.newValue),o(e,t,s);break;case s._const.relocateGroup:n(t,s._const.from,s._const.to),o(e,t,s);break;case s._const.removeElement:t[s._const.action]=s._const.addElement,o(e,t,s);break;case s._const.addElement:t[s._const.action]=s._const.removeElement,o(e,t,s);break;case s._const.removeTextElement:t[s._const.action]=s._const.addTextElement,o(e,t,s);break;case s._const.addTextElement:t[s._const.action]=s._const.removeTextElement,o(e,t,s);break;default:console.log("unknown action")}}(e,t,s)}))}Object.defineProperty(exports,"__esModule",{value:!0});var i=function(e){var t=this;void 0===e&&(e={}),Object.entries(e).forEach((function(e){var o=e[0],n=e[1];return t[o]=n}))};function a(e){var t=[];return t.push(e.nodeName),"#text"!==e.nodeName&&"#comment"!==e.nodeName&&e.attributes&&(e.attributes.class&&t.push(e.nodeName+"."+e.attributes.class.replace(/ /g,".")),e.attributes.id&&t.push(e.nodeName+"#"+e.attributes.id)),t}function l(e){var t={},o={};return e.forEach((function(e){a(e).forEach((function(e){var n=e in t;n||e in o?n&&(delete t[e],o[e]=!0):t[e]=!0}))})),t}function c(e,t){var o=l(e),n=l(t),s={};return Object.keys(o).forEach((function(e){n[e]&&(s[e]=!0)})),s}function r(e){return delete e.outerDone,delete e.innerDone,delete e.valueDone,!e.childNodes||e.childNodes.every(r)}function u(e,t){if(!["nodeName","value","checked","selected","data"].every((function(o){return e[o]===t[o]})))return!1;if(Boolean(e.attributes)!==Boolean(t.attributes))return!1;if(Boolean(e.childNodes)!==Boolean(t.childNodes))return!1;if(e.attributes){var o=Object.keys(e.attributes),n=Object.keys(t.attributes);if(o.length!==n.length)return!1;if(!o.every((function(o){return e.attributes[o]===t.attributes[o]})))return!1}if(e.childNodes){if(e.childNodes.length!==t.childNodes.length)return!1;if(!e.childNodes.every((function(e,o){return u(e,t.childNodes[o])})))return!1}return!0}function d(e,t,o,n,s){if(!e||!t)return!1;if(e.nodeName!==t.nodeName)return!1;if("#text"===e.nodeName)return!!s||e.data===t.data;if(e.nodeName in o)return!0;if(e.attributes&&t.attributes){if(e.attributes.id){if(e.attributes.id!==t.attributes.id)return!1;if(e.nodeName+"#"+e.attributes.id in o)return!0}if(e.attributes.class&&e.attributes.class===t.attributes.class)if(e.nodeName+"."+e.attributes.class.replace(/ /g,".")in o)return!0}if(n)return!0;var i=e.childNodes?e.childNodes.slice().reverse():[],a=t.childNodes?t.childNodes.slice().reverse():[];if(i.length!==a.length)return!1;if(s)return i.every((function(e,t){return e.nodeName===a[t].nodeName}));var l=c(i,a);return i.every((function(e,t){return d(e,a[t],l,!0,!0)}))}function h(e){return JSON.parse(JSON.stringify(e))}function f(e,t,o,n){var s=0,i=[],l=e.length,r=t.length,u=Array.apply(void 0,new Array(l+1)).map((function(){return[]})),h=c(e,t),f=l===r;f&&e.some((function(e,o){var n=a(e),s=a(t[o]);return n.length!==s.length?(f=!1,!0):(n.some((function(e,t){if(e!==s[t])return f=!1,!0})),!f||void 0)}));for(var p=0;p<l;p++)for(var m=e[p],_=0;_<r;_++){var V=t[_];o[p]||n[_]||!d(m,V,h,f)?u[p+1][_+1]=0:(u[p+1][_+1]=u[p][_]?u[p][_]+1:1,u[p+1][_+1]>=s&&(s=u[p+1][_+1],i=[p+1,_+1]))}return 0!==s&&{oldValue:i[0]-s,newValue:i[1]-s,length:s}}function p(e,t){return Array.apply(void 0,new Array(e)).map((function(){return t}))}i.prototype.toString=function(){return JSON.stringify(this)},i.prototype.setValue=function(e,t){return this[e]=t,this};var m=function(){this.list=[]};function _(e,t){var o,n,s=e;for(t=t.slice();t.length>0;){if(!s.childNodes)return!1;n=t.splice(0,1)[0],o=s,s=s.childNodes[n]}return{node:s,parentNode:o,nodeIndex:n}}function V(e,t,o){return t.forEach((function(t){!function(e,t,o){var n,s,i,a=_(e,t[o._const.route]),l=a.node,c=a.parentNode,r=a.nodeIndex,u=[],d={diff:t,node:l};if(o.preVirtualDiffApply(d))return!0;switch(t[o._const.action]){case o._const.addAttribute:l.attributes||(l.attributes={}),l.attributes[t[o._const.name]]=t[o._const.value],"checked"===t[o._const.name]?l.checked=!0:"selected"===t[o._const.name]?l.selected=!0:"INPUT"===l.nodeName&&"value"===t[o._const.name]&&(l.value=t[o._const.value]);break;case o._const.modifyAttribute:l.attributes[t[o._const.name]]=t[o._const.newValue];break;case o._const.removeAttribute:delete l.attributes[t[o._const.name]],0===Object.keys(l.attributes).length&&delete l.attributes,"checked"===t[o._const.name]?l.checked=!1:"selected"===t[o._const.name]?delete l.selected:"INPUT"===l.nodeName&&"value"===t[o._const.name]&&delete l.value;break;case o._const.modifyTextElement:l.data=t[o._const.newValue];break;case o._const.modifyValue:l.value=t[o._const.newValue];break;case o._const.modifyComment:l.data=t[o._const.newValue];break;case o._const.modifyChecked:l.checked=t[o._const.newValue];break;case o._const.modifySelected:l.selected=t[o._const.newValue];break;case o._const.replaceElement:(n=h(t[o._const.newValue])).outerDone=!0,n.innerDone=!0,n.valueDone=!0,c.childNodes[r]=n;break;case o._const.relocateGroup:l.childNodes.splice(t[o._const.from],t.groupLength).reverse().forEach((function(e){return l.childNodes.splice(t[o._const.to],0,e)})),l.subsets&&l.subsets.forEach((function(e){if(t[o._const.from]<t[o._const.to]&&e.oldValue<=t[o._const.to]&&e.oldValue>t[o._const.from]){e.oldValue-=t.groupLength;var n=e.oldValue+e.length-t[o._const.to];n>0&&(u.push({oldValue:t[o._const.to]+t.groupLength,newValue:e.newValue+e.length-n,length:n}),e.length-=n)}else if(t[o._const.from]>t[o._const.to]&&e.oldValue>t[o._const.to]&&e.oldValue<t[o._const.from]){e.oldValue+=t.groupLength;var s=e.oldValue+e.length-t[o._const.to];s>0&&(u.push({oldValue:t[o._const.to]+t.groupLength,newValue:e.newValue+e.length-s,length:s}),e.length-=s)}else e.oldValue===t[o._const.from]&&(e.oldValue=t[o._const.to])}));break;case o._const.removeElement:c.childNodes.splice(r,1),c.subsets&&c.subsets.forEach((function(e){e.oldValue>r?e.oldValue-=1:e.oldValue===r?e.delete=!0:e.oldValue<r&&e.oldValue+e.length>r&&(e.oldValue+e.length-1===r?e.length--:(u.push({newValue:e.newValue+r-e.oldValue,oldValue:r,length:e.length-r+e.oldValue-1}),e.length=r-e.oldValue))})),l=c;break;case o._const.addElement:s=t[o._const.route].slice(),i=s.splice(s.length-1,1)[0],l=_(e,s).node,(n=h(t[o._const.element])).outerDone=!0,n.innerDone=!0,n.valueDone=!0,l.childNodes||(l.childNodes=[]),i>=l.childNodes.length?l.childNodes.push(n):l.childNodes.splice(i,0,n),l.subsets&&l.subsets.forEach((function(e){if(e.oldValue>=i)e.oldValue+=1;else if(e.oldValue<i&&e.oldValue+e.length>i){var t=e.oldValue+e.length-i;u.push({newValue:e.newValue+e.length-t,oldValue:i+1,length:t}),e.length-=t}}));break;case o._const.removeTextElement:c.childNodes.splice(r,1),"TEXTAREA"===c.nodeName&&delete c.value,c.subsets&&c.subsets.forEach((function(e){e.oldValue>r?e.oldValue-=1:e.oldValue===r?e.delete=!0:e.oldValue<r&&e.oldValue+e.length>r&&(e.oldValue+e.length-1===r?e.length--:(u.push({newValue:e.newValue+r-e.oldValue,oldValue:r,length:e.length-r+e.oldValue-1}),e.length=r-e.oldValue))})),l=c;break;case o._const.addTextElement:s=t[o._const.route].slice(),i=s.splice(s.length-1,1)[0],(n={}).nodeName="#text",n.data=t[o._const.value],(l=_(e,s).node).childNodes||(l.childNodes=[]),i>=l.childNodes.length?l.childNodes.push(n):l.childNodes.splice(i,0,n),"TEXTAREA"===l.nodeName&&(l.value=t[o._const.newValue]),l.subsets&&l.subsets.forEach((function(e){if(e.oldValue>=i&&(e.oldValue+=1),e.oldValue<i&&e.oldValue+e.length>i){var t=e.oldValue+e.length-i;u.push({newValue:e.newValue+e.length-t,oldValue:i+1,length:t}),e.length-=t}}));break;default:console.log("unknown action")}l.subsets&&(l.subsets=l.subsets.filter((function(e){return!e.delete&&e.oldValue!==e.newValue})),u.length&&(l.subsets=l.subsets.concat(u))),d.newNode=n,o.postVirtualDiffApply(d)}(e,t,o)})),!0}function g(e,t){void 0===t&&(t={});var o={};if(o.nodeName=e.nodeName,"#text"===o.nodeName||"#comment"===o.nodeName)o.data=e.data;else{if(e.attributes&&e.attributes.length>0)o.attributes={},Array.prototype.slice.call(e.attributes).forEach((function(e){return o.attributes[e.name]=e.value}));if("TEXTAREA"===o.nodeName)o.value=e.value;else if(e.childNodes&&e.childNodes.length>0){o.childNodes=[],Array.prototype.slice.call(e.childNodes).forEach((function(e){return o.childNodes.push(g(e,t))}))}t.valueDiffing&&(void 0!==e.checked&&e.type&&["radio","checkbox"].includes(e.type.toLowerCase())?o.checked=e.checked:void 0!==e.value&&(o.value=e.value),void 0!==e.selected&&(o.selected=e.selected))}return o}m.prototype.add=function(e){var t;(t=this.list).push.apply(t,e)},m.prototype.forEach=function(e){this.list.forEach((function(t){return e(t)}))};var v=/<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>/g,N=Object.create?Object.create(null):{},b=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function y(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&")}var w={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuItem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0};function E(e){var t={nodeName:"",attributes:{}},o=e.match(/<\/?([^\s]+?)[/\s>]/);if(o&&(t.nodeName=o[1].toUpperCase(),(w[o[1]]||"/"===e.charAt(e.length-2))&&(t.voidElement=!0),t.nodeName.startsWith("!--"))){var n=e.indexOf("--\x3e");return{type:"comment",data:-1!==n?e.slice(4,n):""}}for(var s=new RegExp(b),i=null,a=!1;!a;)if(null===(i=s.exec(e)))a=!0;else if(i[0].trim())if(i[1]){var l=i[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),t.attributes[c[0]]=c[1],s.lastIndex--}else i[2]&&(t.attributes[i[2]]=i[3].trim().substring(1,i[3].length-1));return t}function k(e){return function e(t){return delete t.voidElement,t.childNodes&&t.childNodes.forEach((function(t){return e(t)})),t}(function(e,t){void 0===t&&(t={components:N});var o,n=[],s=-1,i=[],a=!1;if(0!==e.indexOf("<")){var l=e.indexOf("<");n.push({nodeName:"#text",data:-1===l?e:e.substring(0,l)})}return e.replace(v,(function(l,c){if(a){if(l!=="</"+o.nodeName+">")return;a=!1}var r,u="/"!==l.charAt(1),d=l.startsWith("\x3c!--"),h=c+l.length,f=e.charAt(h);if(d){var p=E(l);return s<0?(n.push(p),n):((r=i[s])&&(r.childNodes||(r.childNodes=[]),r.childNodes.push(p)),n)}if(u&&(o=E(l),s++,"tag"===o.type&&t.components[o.nodeName]&&(o.type="component",a=!0),o.voidElement||a||!f||"<"===f||(o.childNodes||(o.childNodes=[]),o.childNodes.push({nodeName:"#text",data:y(e.slice(h,e.indexOf("<",h)))})),0===s&&n.push(o),(r=i[s-1])&&(r.childNodes||(r.childNodes=[]),r.childNodes.push(o)),i[s]=o),(!u||o.voidElement)&&(s>-1&&(o.voidElement||o.nodeName===l.slice(2,-1).toUpperCase())&&(s--,o=-1===s?n:i[s]),!a&&"<"!==f&&f)){r=-1===s?n:i[s].childNodes||[];var m=e.indexOf("<",h),_=y(e.slice(h,-1===m?void 0:m));r.push({nodeName:"#text",data:_})}})),n[0]}(e))}var x=function(e,t,o){this.options=o,this.t1="undefined"!=typeof HTMLElement&&e instanceof HTMLElement?g(e,this.options):"string"==typeof e?k(e,this.options):JSON.parse(JSON.stringify(e)),this.t2="undefined"!=typeof HTMLElement&&t instanceof HTMLElement?g(t,this.options):"string"==typeof t?k(t,this.options):JSON.parse(JSON.stringify(t)),this.diffcount=0,this.foundAll=!1,this.debug&&(this.t1Orig=g(e,this.options),this.t2Orig=g(t,this.options)),this.tracker=new m};x.prototype.init=function(){return this.findDiffs(this.t1,this.t2)},x.prototype.findDiffs=function(e,t){var o;do{if(this.options.debug&&(this.diffcount+=1,this.diffcount>this.options.diffcap))throw new Error("surpassed diffcap:"+JSON.stringify(this.t1Orig)+" -> "+JSON.stringify(this.t2Orig));0===(o=this.findNextDiff(e,t,[])).length&&(u(e,t)||(this.foundAll?console.error("Could not find remaining diffs!"):(this.foundAll=!0,r(e),o=this.findNextDiff(e,t,[])))),o.length>0&&(this.foundAll=!1,this.tracker.add(o),V(e,o,this.options))}while(o.length>0);return this.tracker.list},x.prototype.findNextDiff=function(e,t,o){var n,s;if(this.options.maxDepth&&o.length>this.options.maxDepth)return[];if(!e.outerDone){if(n=this.findOuterDiff(e,t,o),this.options.filterOuterDiff&&(s=this.options.filterOuterDiff(e,t,n))&&(n=s),n.length>0)return e.outerDone=!0,n;e.outerDone=!0}if(!e.innerDone){if((n=this.findInnerDiff(e,t,o)).length>0)return n;e.innerDone=!0}if(this.options.valueDiffing&&!e.valueDone){if((n=this.findValueDiff(e,t,o)).length>0)return e.valueDone=!0,n;e.valueDone=!0}return[]},x.prototype.findOuterDiff=function(e,t,o){var n,s,a,l,c,r,u=[];if(e.nodeName!==t.nodeName){if(!o.length)throw new Error("Top level nodes have to be of the same kind.");return[(new i).setValue(this.options._const.action,this.options._const.replaceElement).setValue(this.options._const.oldValue,h(e)).setValue(this.options._const.newValue,h(t)).setValue(this.options._const.route,o)]}if(o.length&&this.options.maxNodeDiffCount<Math.abs((e.childNodes||[]).length-(t.childNodes||[]).length))return[(new i).setValue(this.options._const.action,this.options._const.replaceElement).setValue(this.options._const.oldValue,h(e)).setValue(this.options._const.newValue,h(t)).setValue(this.options._const.route,o)];if(e.data!==t.data)return"#text"===e.nodeName?[(new i).setValue(this.options._const.action,this.options._const.modifyTextElement).setValue(this.options._const.route,o).setValue(this.options._const.oldValue,e.data).setValue(this.options._const.newValue,t.data)]:[(new i).setValue(this.options._const.action,this.options._const.modifyComment).setValue(this.options._const.route,o).setValue(this.options._const.oldValue,e.data).setValue(this.options._const.newValue,t.data)];for(s=e.attributes?Object.keys(e.attributes).sort():[],a=t.attributes?Object.keys(t.attributes).sort():[],l=s.length,r=0;r<l;r++)n=s[r],-1===(c=a.indexOf(n))?u.push((new i).setValue(this.options._const.action,this.options._const.removeAttribute).setValue(this.options._const.route,o).setValue(this.options._const.name,n).setValue(this.options._const.value,e.attributes[n])):(a.splice(c,1),e.attributes[n]!==t.attributes[n]&&u.push((new i).setValue(this.options._const.action,this.options._const.modifyAttribute).setValue(this.options._const.route,o).setValue(this.options._const.name,n).setValue(this.options._const.oldValue,e.attributes[n]).setValue(this.options._const.newValue,t.attributes[n])));for(l=a.length,r=0;r<l;r++)n=a[r],u.push((new i).setValue(this.options._const.action,this.options._const.addAttribute).setValue(this.options._const.route,o).setValue(this.options._const.name,n).setValue(this.options._const.value,t.attributes[n]));return u},x.prototype.findInnerDiff=function(e,t,o){var n=e.childNodes?e.childNodes.slice():[],s=t.childNodes?t.childNodes.slice():[],a=Math.max(n.length,s.length),l=Math.abs(n.length-s.length),c=[],r=0;if(!this.options.maxChildCount||a<this.options.maxChildCount){var d=e.subsets&&e.subsetsAge--,m=d?e.subsets:e.childNodes&&t.childNodes?function(e,t){for(var o=e.childNodes?e.childNodes:[],n=t.childNodes?t.childNodes:[],s=p(o.length,!1),i=p(n.length,!1),a=[],l=!0,c=function(){return arguments[1]};l;){if(l=f(o,n,s,i))a.push(l),Array.apply(void 0,new Array(l.length)).map(c).forEach((function(e){return t=e,s[l.oldValue+t]=!0,void(i[l.newValue+t]=!0);var t}))}return e.subsets=a,e.subsetsAge=100,a}(e,t):[];if(m.length>0&&(c=this.attemptGroupRelocation(e,t,m,o,d)).length>0)return c}for(var _=0;_<a;_+=1){var V=n[_],g=s[_];l&&(V&&!g?"#text"===V.nodeName?(c.push((new i).setValue(this.options._const.action,this.options._const.removeTextElement).setValue(this.options._const.route,o.concat(r)).setValue(this.options._const.value,V.data)),r-=1):(c.push((new i).setValue(this.options._const.action,this.options._const.removeElement).setValue(this.options._const.route,o.concat(r)).setValue(this.options._const.element,h(V))),r-=1):g&&!V&&("#text"===g.nodeName?c.push((new i).setValue(this.options._const.action,this.options._const.addTextElement).setValue(this.options._const.route,o.concat(r)).setValue(this.options._const.value,g.data)):c.push((new i).setValue(this.options._const.action,this.options._const.addElement).setValue(this.options._const.route,o.concat(r)).setValue(this.options._const.element,h(g))))),V&&g&&(!this.options.maxChildCount||a<this.options.maxChildCount?c=c.concat(this.findNextDiff(V,g,o.concat(r))):u(V,g)||(n.length>s.length?("#text"===V.nodeName?c.push((new i).setValue(this.options._const.action,this.options._const.removeTextElement).setValue(this.options._const.route,o.concat(r)).setValue(this.options._const.value,V.data)):c.push((new i).setValue(this.options._const.action,this.options._const.removeElement).setValue(this.options._const.element,h(V)).setValue(this.options._const.route,o.concat(r))),n.splice(_,1),_-=1,r-=1,l-=1):n.length<s.length?(c=c.concat([(new i).setValue(this.options._const.action,this.options._const.addElement).setValue(this.options._const.element,h(g)).setValue(this.options._const.route,o.concat(r))]),n.splice(_,0,{}),l-=1):c=c.concat([(new i).setValue(this.options._const.action,this.options._const.replaceElement).setValue(this.options._const.oldValue,h(V)).setValue(this.options._const.newValue,h(g)).setValue(this.options._const.route,o.concat(r))]))),r+=1}return e.innerDone=!0,c},x.prototype.attemptGroupRelocation=function(e,t,o,n,s){for(var a,l,c,r,u,f,m=function(e,t,o){var n=e.childNodes?p(e.childNodes.length,!0):[],s=t.childNodes?p(t.childNodes.length,!0):[],i=0;return o.forEach((function(e){for(var t=e.oldValue+e.length,o=e.newValue+e.length,a=e.oldValue;a<t;a+=1)n[a]=i;for(var l=e.newValue;l<o;l+=1)s[l]=i;i+=1})),{gaps1:n,gaps2:s}}(e,t,o),_=m.gaps1,V=m.gaps2,g=Math.min(_.length,V.length),v=[],N=0,b=0;N<g;b+=1,N+=1)if(!s||!0!==_[N]&&!0!==V[N]){if(!0===_[N])if("#text"===(r=e.childNodes[b]).nodeName)if("#text"===t.childNodes[N].nodeName){if(r.data!==t.childNodes[N].data){for(f=b;e.childNodes.length>f+1&&"#text"===e.childNodes[f+1].nodeName;)if(f+=1,t.childNodes[N].data===e.childNodes[f].data){u=!0;break}if(!u)return v.push((new i).setValue(this.options._const.action,this.options._const.modifyTextElement).setValue(this.options._const.route,n.concat(N)).setValue(this.options._const.oldValue,r.data).setValue(this.options._const.newValue,t.childNodes[N].data)),v}}else v.push((new i).setValue(this.options._const.action,this.options._const.removeTextElement).setValue(this.options._const.route,n.concat(N)).setValue(this.options._const.value,r.data)),_.splice(N,1),g=Math.min(_.length,V.length),N-=1;else v.push((new i).setValue(this.options._const.action,this.options._const.removeElement).setValue(this.options._const.route,n.concat(N)).setValue(this.options._const.element,h(r))),_.splice(N,1),g=Math.min(_.length,V.length),N-=1;else if(!0===V[N])"#text"===(r=t.childNodes[N]).nodeName?(v.push((new i).setValue(this.options._const.action,this.options._const.addTextElement).setValue(this.options._const.route,n.concat(N)).setValue(this.options._const.value,r.data)),_.splice(N,0,!0),g=Math.min(_.length,V.length),b-=1):(v.push((new i).setValue(this.options._const.action,this.options._const.addElement).setValue(this.options._const.route,n.concat(N)).setValue(this.options._const.element,h(r))),_.splice(N,0,!0),g=Math.min(_.length,V.length),b-=1);else if(_[N]!==V[N]){if(v.length>0)return v;if(c=o[_[N]],(l=Math.min(c.newValue,e.childNodes.length-c.length))!==c.oldValue){a=!1;for(var y=0;y<c.length;y+=1)d(e.childNodes[l+y],e.childNodes[c.oldValue+y],[],!1,!0)||(a=!0);if(a)return[(new i).setValue(this.options._const.action,this.options._const.relocateGroup).setValue("groupLength",c.length).setValue(this.options._const.from,c.oldValue).setValue(this.options._const.to,l).setValue(this.options._const.route,n)]}}}else;return v},x.prototype.findValueDiff=function(e,t,o){var n=[];return e.selected!==t.selected&&n.push((new i).setValue(this.options._const.action,this.options._const.modifySelected).setValue(this.options._const.oldValue,e.selected).setValue(this.options._const.newValue,t.selected).setValue(this.options._const.route,o)),(e.value||t.value)&&e.value!==t.value&&"OPTION"!==e.nodeName&&n.push((new i).setValue(this.options._const.action,this.options._const.modifyValue).setValue(this.options._const.oldValue,e.value||"").setValue(this.options._const.newValue,t.value||"").setValue(this.options._const.route,o)),e.checked!==t.checked&&n.push((new i).setValue(this.options._const.action,this.options._const.modifyChecked).setValue(this.options._const.oldValue,e.checked).setValue(this.options._const.newValue,t.checked).setValue(this.options._const.route,o)),n};var A={debug:!1,diffcap:10,maxDepth:!1,maxChildCount:50,valueDiffing:!0,textDiff:function(e,t,o,n){e.data=n},preVirtualDiffApply:function(){},postVirtualDiffApply:function(){},preDiffApply:function(){},postDiffApply:function(){},filterOuterDiff:null,compress:!1,_const:!1,document:!("undefined"==typeof window||!window.document)&&window.document},D=function(e){var t=this;if(void 0===e&&(e={}),this.options=e,Object.entries(A).forEach((function(e){var o=e[0],n=e[1];Object.prototype.hasOwnProperty.call(t.options,o)||(t.options[o]=n)})),!this.options._const){var o=["addAttribute","modifyAttribute","removeAttribute","modifyTextElement","relocateGroup","removeElement","addElement","removeTextElement","addTextElement","replaceElement","modifyValue","modifyChecked","modifySelected","modifyComment","action","route","oldValue","newValue","element","group","from","to","name","value","data","attributes","nodeName","childNodes","checked","selected"];this.options._const={},this.options.compress?o.forEach((function(e,o){return t.options._const[e]=o})):o.forEach((function(e){return t.options._const[e]=e}))}this.DiffFinder=x};D.prototype.apply=function(e,t){return function(e,t,n){return t.every((function(t){return o(e,t,n)}))}(e,t,this.options)},D.prototype.undo=function(e,t){return s(e,t,this.options)},D.prototype.diff=function(e,t){return new this.DiffFinder(e,t,this.options).init()};var T=function(e){var t=this;void 0===e&&(e={}),this.pad="│ ",this.padding="",this.tick=1,this.messages=[];var o=function(e,o){var n=e[o];e[o]=function(){for(var s=[],i=arguments.length;i--;)s[i]=arguments[i];t.fin(o,Array.prototype.slice.call(s));var a=n.apply(e,s);return t.fout(o,a),a}};for(var n in e)"function"==typeof e[n]&&o(e,n);this.log("┌ TRACELOG START")};T.prototype.fin=function(e,t){this.padding+=this.pad,this.log("├─> entering "+e,t)},T.prototype.fout=function(e,t){this.log("│<──┘ generated return value",t),this.padding=this.padding.substring(0,this.padding.length-this.pad.length)},T.prototype.format=function(e,t){return function(e){for(e=""+e;e.length<4;)e="0"+e;return e}(t)+"> "+this.padding+e},T.prototype.log=function(){var e=Array.prototype.slice.call(arguments),t=function(e){return e?"string"==typeof e?e:e instanceof HTMLElement?e.outerHTML||"<empty>":e instanceof Array?"["+e.map(t).join(",")+"]":e.toString()||e.valueOf()||"<unknown>":"<falsey>"};e=e.map(t).join(", "),this.messages.push(this.format(e,this.tick++))},T.prototype.toString=function(){for(var e="└───";e.length<=this.padding.length+this.pad.length;)e+="× ";var t=this.padding;return this.padding="",e=this.format(e,this.tick),this.padding=t,this.messages.join("\n")+"\n"+e},exports.DiffDOM=D,exports.TraceLogger=T,exports.nodeToObj=g,exports.stringToObj=k; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "diff-dom", | ||
"version": "4.2.5", | ||
"version": "4.2.6", | ||
"description": "A diff for DOM elements, as client-side JavaScript code. Gets all modifications, insertions and removals between two DOM fragments.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -11,4 +11,4 @@ import {Diff, DiffTracker, cloneObj, getGapInformation, isEqual, markSubTrees, removeDone, roughlyEqual} from "./helpers" | ||
this.options = options | ||
this.t1 = (t1Node instanceof HTMLElement) ? nodeToObj(t1Node, this.options) : (typeof t1Node === 'string') ? stringToObj(t1Node, this.options) : JSON.parse(JSON.stringify(t1Node)) | ||
this.t2 = (t2Node instanceof HTMLElement) ? nodeToObj(t2Node, this.options) : (typeof t2Node === 'string') ? stringToObj(t2Node, this.options) : JSON.parse(JSON.stringify(t2Node)) | ||
this.t1 = (typeof HTMLElement !== 'undefined' && t1Node instanceof HTMLElement) ? nodeToObj(t1Node, this.options) : (typeof t1Node === 'string') ? stringToObj(t1Node, this.options) : JSON.parse(JSON.stringify(t1Node)) | ||
this.t2 = (typeof HTMLElement !== 'undefined' && t2Node instanceof HTMLElement) ? nodeToObj(t2Node, this.options) : (typeof t2Node === 'string') ? stringToObj(t2Node, this.options) : JSON.parse(JSON.stringify(t2Node)) | ||
this.diffcount = 0 | ||
@@ -15,0 +15,0 @@ this.foundAll = false |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2223
354542
26