0)break;d=!1===l?this.newText.tokens[d].next:this.newText.tokens[d].prev}for(var u=o;null!==u;){if(null===this.oldText.tokens[u].link){k=this.oldText.tokens[u].token;if(!1===Object.prototype.hasOwnProperty.call(r.hashTable,k))r.hashTable[k]=r.token.length,r.token.push({newCount:0,oldCount:1,newToken:null,oldToken:u});else{g=r.hashTable[k];r.token[g].oldCount++,r.token[g].oldToken=u}}else if(s>0)break;u=!1===l?this.oldText.tokens[u].next:this.oldText.tokens[u].prev}var p=r.token.length;for(d=0;d=this.config.blockMinLength)b=!0;else for(d=0;d0&&this.maxWords>=this.config.blockMinLength){!0===this.config.timer&&this.time("total unlinking");for(var i=!0;!0===i&&ts?s=t[h].oldNumber:t[h].oldNumbero){for(var f=o;f<=l;f++)t[f].section=i.length;i.push({blockStart:o,blockEnd:l}),n=l}}!0===this.config.timer&&this.timeEnd("getSections")},this.getGroups=function(){!0===this.config.timer&&this.time("getGroups");var t=this.blocks,i=this.groups;i.splice(0);for(var e=t.length,n=0;nh&&(h=t[a].words),!0===t[a].unique&&(f=!0),r+=t[a].words,c+=t[a].chars,l=a;if(l>=o){var d=!1;null===t[o].section&&(d=!0);for(a=o;a<=l;a++)t[a].group=i.length,t[a].fixed=d;i.push({oldNumber:t[o].oldNumber,blockStart:o,blockEnd:l,unique:f,maxWords:h,words:r,chars:c,fixed:d,movedFrom:null,color:null}),n=l,h>this.maxWords&&(this.maxWords=h)}}!0===this.config.timer&&this.timeEnd("getGroups")},this.setFixed=function(){!0===this.config.timer&&this.time("setFixed");for(var t=this.blocks,i=this.groups,e=this.sections,n=e.length,o=0;oc&&(a=k.path,c=k.chars)}var g=a.length;for(d=0;do&&(o=h.chars,s=h)}return s.path.unshift(t),s.chars+=n[t].chars,void 0===e[t]&&(e[t]={path:s.path.slice(),chars:s.chars}),s},this.unlinkBlocks=function(){for(var t=this.blocks,i=this.groups,e=!1,n=i.length,o=0;o1||!0===t[r].unique)break;this.unlinkSingleBlock(t[r]),e=!0,l=r}for(r=s;r>l;r--)if("="===t[r].type){if(t[r].words>1||1===t[r].words&&!0===t[r].unique)break;this.unlinkSingleBlock(t[r]),e=!0}}}return e},this.unlinkSingleBlock=function(t){for(var i=t.oldStart,e=0;e0&&(r=t[s=e[o-1].newBlock]);var h=null,f=null;o=0;a--)if("="===e[a].type&&!0===e[a].fixed){c=e[a];break}null===c?l.newNumber=-1:(l.newNumber=c.newNumber,l.section=c.section,l.group=c.group,l.fixed=c.fixed)}}this.sortBlocks(),!0===this.config.timer&&this.timeEnd("positionDelBlocks")},this.getInsBlocks=function(){!0===this.config.timer&&this.time("getInsBlocks");for(var t=this.blocks,i=this.newText.first;null!==i;){for(;null!==i&&null!==this.newText.tokens[i].link;)i=this.newText.tokens[i].next;if(null!==i){for(var e=i,n=0,o="";null!==i&&null===this.newText.tokens[i].link;)n++,o+=this.newText.tokens[i].token,i=this.newText.tokens[i].next;t.push({oldBlock:null,newBlock:null,oldNumber:null,newNumber:this.newText.tokens[e].number,oldStart:null,count:n,unique:!1,words:null,chars:o.length,type:"+",section:null,group:null,fixed:null,moved:null,text:o})}}this.sortBlocks(),!0===this.config.timer&&this.timeEnd("getInsBlocks")},this.sortBlocks=function(){var t=this.blocks,i=this.groups;t.sort((function(t,i){var e=t.newNumber-i.newNumber;return 0===e&&(e=t.oldNumber-i.oldNumber),e}));for(var e=null,n=t.length,o=0;o0&&(a=o[d-1]);var d,k=null;(d=r[f.blockEnd])=0;m--)if("="===o[m].type&&!0===o[m].fixed){p=o[m];break}null===p?(g=-1,u=i.length,i.push({oldNumber:0,blockStart:t.length,blockEnd:t.length,unique:!1,maxWords:null,words:null,chars:0,fixed:null,movedFrom:null,color:null})):(g=p.newNumber,u=p.group),t.push({oldBlock:null,newBlock:null,oldNumber:c,newNumber:g,oldStart:null,count:null,unique:null,words:null,chars:0,type:"|",section:null,group:u,fixed:!0,moved:e,text:""}),f.color=n,f.movedFrom=u,n++}}this.sortBlocks(),!0===this.config.timer&&this.timeEnd("insertMarks")},this.getDiffFragments=function(){var t=this.blocks,i=this.groups,e=this.fragments,n=i.slice();n.sort((function(t,i){return t.blockStart-i.blockStart}));for(var o=n.length,l=0;l",e.push({text:"",type:c,color:h});for(var f=s;f<=r;f++){var c;if("="===(c=t[f].type)||"-"===c||"+"===c)e.push({text:t[f].text,type:c,color:h});else if("|"===c){for(var a,d=i[t[f].moved],k="",g=d.blockStart;g<=d.blockEnd;g++)"="!==t[g].type&&"-"!==t[g].type||(k+=t[g].text);a=d.blockStart",e.push({text:k,type:a,color:d.color})}}null!==h&&e.push({text:"",type:" )",color:h})}for(var u=e.length,p=1;pthis.config.clipHeadingLeft||k[b]>w);b++){p=k[b],x="heading";break}if(null===p){var D=g.length;for(b=0;bthis.config.clipParagraphLeftMax||g[b]>w);b++)if(g[b]>this.config.clipParagraphLeftMin){p=g[b],x="paragraph";break}}if(null===p){var B=c.length;for(b=0;bthis.config.clipLineLeftMax||c[b]>w);b++)if(c[b]>this.config.clipLineLeftMin){p=c[b],x="line";break}}null===p&&(this.config.regExp.clipBlank.lastIndex=this.config.clipBlankLeftMin,null!==(f=this.config.regExp.clipBlank.exec(r))&&f.index=this.config.clipLinesRightMax&&(A=c[c.length-this.config.clipLinesRightMax]),null===u)for(b=d.length-1;b>=0&&!(d[b]=0&&!(g[b]=0&&!(c[b]h-this.config.clipBlankRightMin){null!==v&&(u=v,m="blank");break}v=f.index}}null===u&&h-this.config.clipCharsRight>A&&(u=h-this.config.clipCharsRight,m="chars"),null===u&&(u=A,m="fixed")}if(null!==p&&null!==u){if(p>u)continue;if(u-pu||T>this.config.clipSkipLines);b++)c[b]>p&&T++;if(T"===s){var c;if("old"!==t)c=!0===this.config.noUnicodeSymbols?this.config.msg["wiked-diff-block-right-nounicode"]:this.config.msg["wiked-diff-block-right"],h=!0===this.config.coloredBlocks?this.config.htmlCode.blockColoredStart:this.config.htmlCode.blockStart,h=this.htmlCustomize(h,r,c)}else" )"===s&&"old"!==t&&(h=this.config.htmlCode.blockEnd);"="===s?(l=this.htmlEscape(l),null!==r?"old"!==t&&(h=this.markupBlanks(l,!0)):h=this.markupBlanks(l)):"-"===s?"new"!==t&&("old"===t&&null!==r||(l=this.htmlEscape(l),l=this.markupBlanks(l,!0),h=!0===f?this.config.htmlCode.deleteStartBlank:this.config.htmlCode.deleteStart,h+=l+this.config.htmlCode.deleteEnd)):"+"===s?"old"!==t&&(l=this.htmlEscape(l),l=this.markupBlanks(l,!0),h=!0===f?this.config.htmlCode.insertStartBlank:this.config.htmlCode.insertStart,h+=l+this.config.htmlCode.insertEnd):"<"!==s&&">"!==s||"new"!==t&&(!1===this.config.showBlockMoves||"old"===t?(l=this.htmlEscape(l),l=this.markupBlanks(l,!0),h="old"===t?!0===this.config.coloredBlocks?this.htmlCustomize(this.config.htmlCode.blockColoredStart,r)+l+this.config.htmlCode.blockEnd:this.htmlCustomize(this.config.htmlCode.blockStart,r)+l+this.config.htmlCode.blockEnd:!0===f?this.config.htmlCode.deleteStartBlank+l+this.config.htmlCode.deleteEnd:this.config.htmlCode.deleteStart+l+this.config.htmlCode.deleteEnd):h="<"===s?!0===this.config.coloredBlocks?this.htmlCustomize(this.config.htmlCode.markLeftColored,r,l):this.htmlCustomize(this.config.htmlCode.markLeft,r,l):!0===this.config.coloredBlocks?this.htmlCustomize(this.config.htmlCode.markRightColored,r,l):this.htmlCustomize(this.config.htmlCode.markRight,r,l)),e.push(h)}this.html=e.join("")}else this.html=""},this.htmlCustomize=function(t,i,e){if(t=t.replace(/\{number\}/g,i),t=!0===this.config.noUnicodeSymbols?t.replace(/\{nounicode\}/g," wikEdDiffNoUnicode"):t.replace(/\{nounicode\}/g,""),void 0!==e){var n=" [...] ";e.length>512&&(e=e.substr(0,377)+n+e.substr(e.length-128)),e=(e=(e=this.htmlEscape(e)).replace(/\t/g," ")).replace(/ /g," "),t=t.replace(/\{title\}/,e)}return t},this.htmlEscape=function(t){return t=(t=(t=(t=t.replace(/&/g,"&")).replace(//g,">")).replace(/"/g,""")},this.markupBlanks=function(t,i){return!0===i&&(t=(t=t.replace(/ /g,this.config.htmlCode.space)).replace(/\n/g,this.config.htmlCode.newline)),t=t.replace(/\t/g,this.config.htmlCode.tab)},this.wordCount=function(t){return(t.match(this.config.regExp.countWords)||[]).length},this.unitTests=function(){var t,i;this.getDiffHtml("new"),(t=this.html.replace(/<[^>]*>/g,""))!==(i=this.htmlEscape(this.newText.text))?(console.log("Error: wikEdDiff unit test failure: diff not consistent with new text version!"),this.error=!0,console.log("new text:\n",i),console.log("new diff:\n",t)):console.log("OK: wikEdDiff unit test passed: diff consistent with new text."),this.getDiffHtml("old"),(t=this.html.replace(/<[^>]*>/g,""))!==(i=this.htmlEscape(this.oldText.text))?(console.log("Error: wikEdDiff unit test failure: diff not consistent with old text version!"),this.error=!0,console.log("old text:\n",i),console.log("old diff:\n",t)):console.log("OK: wikEdDiff unit test passed: diff consistent with old text.")},this.debugBlocks=function(t,i){void 0===i&&(i=this.blocks);for(var e="\ni \toldBl \tnewBl \toldNm \tnewNm \toldSt \tcount \tuniq\twords \tchars \ttype \tsect \tgroup \tfixed \tmoved \ttext\n",n=i.length,o=0;oi&&(t=t.substr(0,i-1-e)+"…"+t.substr(t.length-e)),'"'+t+'"'},this.time=function(t){this.timer[t]=(new Date).getTime()},this.timeEnd=function(t,i){var e=0;if(void 0!==this.timer[t]){var n=this.timer[t];e=(new Date).getTime()-n,this.timer[t]=void 0,!0!==i&&console.log(t+": "+e.toFixed(2)+" ms")}return e},this.timeRecursionEnd=function(t){if(this.recursionTimer.length>1){for(var i=this.recursionTimer.length-1,e=0;ec&&f.push(s.substring(c,r.index)),f.push(r[0]),c=a.lastIndex;c0&&void 0!==i&&(null!==e&&(this.tokens[e].next=n),null!==n&&(this.tokens[n].prev=e)),h>0&&(void 0===i?(this.first=0,this.last=e):(i===this.first&&(this.first=l),i===this.last&&(this.last=e)))},this.splitRefine=function(t){for(var i=this.first;null!==i;)null===this.tokens[i].link&&this.splitText(t,i),i=this.tokens[i].next},this.enumerateTokens=function(){for(var t=0,i=this.first;null!==i;)this.tokens[i].number=t,t++,i=this.tokens[i].next},this.debugText=function(t){var e=this.tokens,n="first: "+this.first+"\tlast: "+this.last+"\n";n+='\ni \tlink \t(prev \tnext) \tuniq \t#num \t"token"\n';for(var o=this.first;null!==o;)n+=o+" \t"+e[o].link+" \t("+e[o].prev+" \t"+e[o].next+") \t"+e[o].unique+" \t#"+e[o].number+" \t"+i.debugShortenText(e[o].token)+"\n",o=e[o].next;console.log(t+":\n"+n)},this.init()};
\ No newline at end of file