whisper.cat/weboasis/text/js/lib/diffview.js
2023-10-05 23:28:32 +11:00

1 line
2.5 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

diffview={buildView:function(e){var t=e.baseTextLines,n=e.newTextLines,d=e.opcodes,a=e.baseTextName?e.baseTextName:"Column A",i=e.newTextName?e.newTextName:"Column B",l=e.contextSize,p=0==e.viewType||1==e.viewType?e.viewType:0;if(null==t)throw"Cannot build diff view; baseTextLines is not defined.";if(null==n)throw"Cannot build diff view; newTextLines is not defined.";if(!d)throw"Canno build diff view; opcodes is not defined.";function h(e,t){var n=document.createElement(e);return n.className=t,n}function c(e,t){var n=document.createElement(e);return n.appendChild(document.createTextNode(t)),n}function r(e,t,n){var d=document.createElement(e);return d.className=t,d.appendChild(document.createTextNode(n)),d}var o=document.createElement("thead"),u=document.createElement("tr");o.appendChild(u),p?(u.appendChild(document.createElement("th")),u.appendChild(document.createElement("th")),u.appendChild(r("th","texttitle",a+" vs. "+i))):(u.appendChild(document.createElement("th")),u.appendChild(r("th","texttitle",a)),u.appendChild(document.createElement("th")),u.appendChild(r("th","texttitle",i))),o=[o];var m,f=[];function s(e,t,n,d,a){return t<n?(e.appendChild(c("th",(t+1).toString())),e.appendChild(r("td",a,d[t].replace(/\t/g,"    "))),t+1):(e.appendChild(document.createElement("th")),e.appendChild(h("td","empty")),t)}function C(e,t,n,d,a){e.appendChild(c("th",null==t?"":(t+1).toString())),e.appendChild(c("th",null==n?"":(n+1).toString())),e.appendChild(r("td",a,d[null!=t?t:n].replace(/\t/g,"    ")))}for(var g=0;g<d.length;g++){code=d[g],change=code[0];for(var v=code[1],w=code[2],x=code[3],E=code[4],T=Math.max(w-v,E-x),b=[],N=[],y=0;y<T;y++){if(l&&d.length>1&&(g>0&&y==l||0==g&&0==y)&&"equal"==change){var L=T-(0==g?1:2)*l;if(L>1){if(b.push(u=document.createElement("tr")),v+=L,x+=L,y+=L-1,u.appendChild(c("th","...")),p||u.appendChild(r("td","skip","")),u.appendChild(c("th","...")),u.appendChild(r("td","skip","")),g+1==d.length)break;continue}}b.push(u=document.createElement("tr")),p?"insert"==change?C(u,null,x++,n,change):"replace"==change?(N.push(m=document.createElement("tr")),v<w&&C(u,v++,null,t,"delete"),x<E&&C(m,null,x++,n,"insert")):"delete"==change?C(u,v++,null,t,change):C(u,v++,x++,t,change):(v=s(u,v,w,t,change),x=s(u,x,E,n,change))}for(y=0;y<b.length;y++)f.push(b[y]);for(y=0;y<N.length;y++)f.push(N[y])}for(var g in o.push(u=document.createElement("tbody")),f)f.hasOwnProperty(g)&&u.appendChild(f[g]);for(var g in u=h("table","diff"+(p?" inlinediff":"")),o)o.hasOwnProperty(g)&&u.appendChild(o[g]);return u}};