You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
25 KiB

4 years ago
  1. var diffDOM=function(e){"use strict";function t(e,o,n){var s;return"#text"===e.nodeName?s=n.document.createTextNode(e.data):"#comment"===e.nodeName?s=n.document.createComment(e.data):("svg"===e.nodeName||o?(s=n.document.createElementNS("http://www.w3.org/2000/svg",e.nodeName),o=!0):s=n.document.createElement(e.nodeName),e.attributes&&Object.entries(e.attributes).forEach(function(e){var t=e[0],o=e[1];return s.setAttribute(t,o)}),e.childNodes&&e.childNodes.forEach(function(e){return s.appendChild(t(e,o,n))}),n.valueDiffing&&(e.value&&(s.value=e.value),e.checked&&(s.checked=e.checked),e.selected&&(s.selected=e.selected))),s}function o(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 n(e,n,s){var i,a,l,c,r=o(e,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(t(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=o(e,l)).insertBefore(t(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=o(e,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 s(e,t,o){var n=e[t];e[t]=e[o],e[o]=n}function i(e,t,o){t.length||(t=[t]),(t=t.slice()).reverse(),t.forEach(function(t){!function(e,t,o){switch(t[o._const.action]){case o._const.addAttribute:t[o._const.action]=o._const.removeAttribute,n(e,t,o);break;case o._const.modifyAttribute:s(t,o._const.oldValue,o._const.newValue),n(e,t,o);break;case o._const.removeAttribute:t[o._const.action]=o._const.addAttribute,n(e,t,o);break;case o._const.modifyTextElement:case o._const.modifyValue:case o._const.modifyComment:case o._const.modifyChecked:case o._const.modifySelected:case o._const.replaceElement:s(t,o._const.oldValue,o._const.newValue),n(e,t,o);break;case o._const.relocateGroup:s(t,o._const.from,o._const.to),n(e,t,o);break;case o._const.removeElement:t[o._const.action]=o._const.addElement,n(e,t,o);break;case o._const.addElement:t[o._const.action]=o._const.removeElement,n(e,t,o);break;case o._const.removeTextElement:t[o._const.action]=o._const.addTextElement,n(e,t,o);break;case o._const.addTextElement:t[o._const.action]=o._const.removeTextElement,n(e,t,o);break;default:console.log("unknown action")}}(e,t,o)})}var a=function(e){var t=this;void 0===e&&(e={}),Object.entries(e).forEa
  2. //# sourceMappingURL=diffDOM.js.map