diff2html/dist/diff2html.min.js

4 lines
70 KiB
JavaScript
Raw Normal View History

2016-04-25 12:52:23 +00:00
!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(){},{}],2:[function(require,module,exports){"use strict";function convertChangesToDMP(changes){for(var ret=[],change=void 0,operation=void 0,i=0;i<changes.length;i++)change=changes[i],operation=change.added?1:change.removed?-1:0,ret.push([operation,change.value]);return ret}exports.__esModule=!0,exports.convertChangesToDMP=convertChangesToDMP},{}],3:[function(require,module,exports){"use strict";function convertChangesToXML(changes){for(var ret=[],i=0;i<changes.length;i++){var change=changes[i];change.added?ret.push("<ins>"):change.removed&&ret.push("<del>"),ret.push(escapeHTML(change.value)),change.added?ret.push("</ins>"):change.removed&&ret.push("</del>")}return ret.join("")}function escapeHTML(s){var n=s;return n=n.replace(/&/g,"&amp;"),n=n.replace(/</g,"&lt;"),n=n.replace(/>/g,"&gt;"),n=n.replace(/"/g,"&quot;")}exports.__esModule=!0,exports.convertChangesToXML=convertChangesToXML},{}],4:[function(require,module,exports){"use strict";function Diff(){}function buildValues(diff,components,newString,oldString,useLongestToken){for(var componentPos=0,componentLen=components.length,newPos=0,oldPos=0;componentLen>componentPos;componentPos++){var component=components[componentPos];if(component.removed){if(component.value=oldString.slice(oldPos,oldPos+component.count).join(""),oldPos+=component.count,componentPos&&components[componentPos-1].added){var tmp=components[componentPos-1];components[componentPos-1]=components[componentPos],components[componentPos]=tmp}}else{if(!component.added&&useLongestToken){var value=newString.slice(newPos,newPos+component.count);value=value.map(function(value,i){var oldValue=oldString[oldPos+i];return oldValue.length>value.length?oldValue:value}),component.value=value.join("")}else component.value=newString.slice(newPos,newPos+component.count).join("");newPos+=component.count,component.added||(oldPos+=component.count)}}var lastComponent=components[componentLen-1];return componentLen>1&&(lastComponent.added||lastComponent.removed)&&diff.equals("",lastComponent.value)&&(components[componentLen-2].value+=lastComponent.value,components.pop()),components}function clonePath(path){return{newPos:path.newPos,components:path.components.slice(0)}}exports.__esModule=!0,exports["default"]=Diff,Diff.prototype={diff:function(oldString,newString){function done(value){return callback?(setTimeout(function(){callback(void 0,value)},0),!0):value}function execEditLength(){for(var diagonalPath=-1*editLength;editLength>=diagonalPath;diagonalPath+=2){var basePath=void 0,addPath=bestPath[diagonalPath-1],removePath=bestPath[diagonalPath+1],_oldPos=(removePath?removePath.newPos:0)-diagonalPath;addPath&&(bestPath[diagonalPath-1]=void 0);var canAdd=addPath&&addPath.newPos+1<newLen,canRemove=removePath&&_oldPos>=0&&oldLen>_oldPos;if(canAdd||canRemove){if(!canAdd||canRemove&&addPath.newPos<removePath.newPos?(basePath=clonePath(removePath),self.pushComponent(basePath.components,void 0,!0)):(basePath=addPath,basePath.newPos++,self.pushComponent(basePath.components,!0,void 0)),_oldPos=self.extractCommon(basePath,newString,oldString,diagonalPath),basePath.newPos+1>=newLen&&_oldPos+1>=oldLen)return done(buildValues(self,basePath.components,newString,oldString,self.useLongestToken));bestPath[diagonalPath]=basePath}else bestPath[diagonalPath]=void 0}editLength++}var options=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],callback=options.callback;"function"==typeof options&&(callback=options,options={}),this.options=options;var self=this;oldString=this.castInput(oldString),newString=this.castInput(newString),oldString=this.removeEmpty(this.tokenize(oldString)),newString=this.re
2016-04-25 18:24:35 +00:00
if("string"==typeof template){if(!this.c)throw new Error("No compiler available.");template=this.c.compile(template,this.options)}if(!template)return null;if(this.partials[symbol].base=template,partial.subs){partials.stackText||(partials.stackText={});for(key in partial.subs)partials.stackText[key]||(partials.stackText[key]=void 0!==this.activeSub&&partials.stackText[this.activeSub]?partials.stackText[this.activeSub]:this.text);template=createSpecializedPartial(template,partial.subs,partial.partials,this.stackSubs,this.stackPartials,partials.stackText)}return this.partials[symbol].instance=template,template},rp:function(symbol,context,partials,indent){var partial=this.ep(symbol,partials);return partial?partial.ri(context,partials,indent):""},rs:function(context,partials,section){var tail=context[context.length-1];if(!isArray(tail))return void section(context,partials,this);for(var i=0;i<tail.length;i++)context.push(tail[i]),section(context,partials,this),context.pop()},s:function(val,ctx,partials,inverted,start,end,tags){var pass;return isArray(val)&&0===val.length?!1:("function"==typeof val&&(val=this.ms(val,ctx,partials,inverted,start,end,tags)),pass=!!val,!inverted&&pass&&ctx&&ctx.push("object"==typeof val?val:ctx[ctx.length-1]),pass)},d:function(key,ctx,partials,returnFound){var found,names=key.split("."),val=this.f(names[0],ctx,partials,returnFound),doModelGet=this.options.modelGet,cx=null;if("."===key&&isArray(ctx[ctx.length-2]))val=ctx[ctx.length-1];else for(var i=1;i<names.length;i++)found=findInScope(names[i],val,doModelGet),void 0!==found?(cx=val,val=found):val="";return returnFound&&!val?!1:(returnFound||"function"!=typeof val||(ctx.push(cx),val=this.mv(val,ctx,partials),ctx.pop()),val)},f:function(key,ctx,partials,returnFound){for(var val=!1,v=null,found=!1,doModelGet=this.options.modelGet,i=ctx.length-1;i>=0;i--)if(v=ctx[i],val=findInScope(key,v,doModelGet),void 0!==val){found=!0;break}return found?(returnFound||"function"!=typeof val||(val=this.mv(val,ctx,partials)),val):returnFound?!1:""},ls:function(func,cx,partials,text,tags){var oldTags=this.options.delimiters;return this.options.delimiters=tags,this.b(this.ct(coerceToString(func.call(cx,text)),cx,partials)),this.options.delimiters=oldTags,!1},ct:function(text,cx,partials){if(this.options.disableLambda)throw new Error("Lambda features disabled.");return this.c.compile(text,this.options).render(cx,partials)},b:function(s){this.buf+=s},fl:function(){var r=this.buf;return this.buf="",r},ms:function(func,ctx,partials,inverted,start,end,tags){var textSource,cx=ctx[ctx.length-1],result=func.call(cx);return"function"==typeof result?inverted?!0:(textSource=this.activeSub&&this.subsText&&this.subsText[this.activeSub]?this.subsText[this.activeSub]:this.text,this.ls(result,cx,partials,textSource.substring(start,end),tags)):result},mv:function(func,ctx,partials){var cx=ctx[ctx.length-1],result=func.call(cx);return"function"==typeof result?this.ct(coerceToString(result.call(cx)),cx,partials):result},sub:function(name,context,partials,indent){var f=this.subs[name];f&&(this.activeSub=name,f(context,partials,this,indent),this.activeSub=!1)}};var rAmp=/&/g,rLt=/</g,rGt=/>/g,rApos=/\'/g,rQuot=/\"/g,hChars=/[&<>\"\']/,isArray=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)}}("undefined"!=typeof exports?exports:Hogan)},{}],20:[function(require,module,exports){(function(process){function normalizeArray(parts,allowAboveRoot){for(var up=0,i=parts.length-1;i>=0;i--){var last=parts[i];"."===last?parts.splice(i,1):".."===last?(parts.splice(i,1),up++):up&&(parts.splice(i,1),up--)}if(allowAboveRoot)for(;up--;up)parts.unshift("..");return parts}function filter(xs,f){if(xs.filter)return xs.filter(f);for(var res=[],i=0;i<xs.length;i++)f(xs[i],i,xs)&&res.push(xs[i]);return res}var splitPathRe=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,splitPath=function(filename){return splitPathRe.exec(filename).slice(1)};exports.resolve=function(){for(var resolvedPath="",resolvedAbsolute=!1,i=arguments.length-1;i>=-1&&!resolvedAbsolute;i--)
var line=block.lines[i],prefix=line.content[0],escapedLine=utils.escape(line.content.substr(1));line.type!==diffParser.LINE_TYPE.INSERTS&&(newLines.length>0||line.type!==diffParser.LINE_TYPE.DELETES&&oldLines.length>0)&&processChangeBlock(),line.type===diffParser.LINE_TYPE.CONTEXT?(fileHtml.left+=that.generateSingleLineHtml(line.type,line.oldNumber,escapedLine,prefix),fileHtml.right+=that.generateSingleLineHtml(line.type,line.newNumber,escapedLine,prefix)):line.type!==diffParser.LINE_TYPE.INSERTS||oldLines.length?line.type===diffParser.LINE_TYPE.DELETES?oldLines.push(line):line.type===diffParser.LINE_TYPE.INSERTS&&Boolean(oldLines.length)?newLines.push(line):(console.error("unknown state in html side-by-side generator"),processChangeBlock()):(fileHtml.left+=that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT,"","",""),fileHtml.right+=that.generateSingleLineHtml(line.type,line.newNumber,escapedLine,prefix))}processChangeBlock()}),fileHtml},SideBySidePrinter.prototype.processLines=function(oldLines,newLines){var that=this,fileHtml={};fileHtml.left="",fileHtml.right="";for(var maxLinesNumber=Math.max(oldLines.length,newLines.length),i=0;maxLinesNumber>i;i++){var oldContent,newContent,oldPrefix,newPrefix,oldLine=oldLines[i],newLine=newLines[i];oldLine&&(oldContent=utils.escape(oldLine.content.substr(1)),oldPrefix=oldLine.content[0]),newLine&&(newContent=utils.escape(newLine.content.substr(1)),newPrefix=newLine.content[0]),oldLine&&newLine?(fileHtml.left+=that.generateSingleLineHtml(oldLine.type,oldLine.oldNumber,oldContent,oldPrefix),fileHtml.right+=that.generateSingleLineHtml(newLine.type,newLine.newNumber,newContent,newPrefix)):oldLine?(fileHtml.left+=that.generateSingleLineHtml(oldLine.type,oldLine.oldNumber,oldContent,oldPrefix),fileHtml.right+=that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT,"","","")):newLine?(fileHtml.left+=that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT,"","",""),fileHtml.right+=that.generateSingleLineHtml(newLine.type,newLine.newNumber,newContent,newPrefix)):console.error("How did it get here?")}return fileHtml},SideBySidePrinter.prototype.makeSingleLineHtml=function(type,number,htmlContent,htmlPrefix){return'<tr>\n <td class="d2h-code-side-linenumber '+type+'">'+number+'</td>\n <td class="'+type+'"> <div class="d2h-code-side-line '+type+'">'+htmlPrefix+htmlContent+"</div> </td>\n </tr>\n"},SideBySidePrinter.prototype.generateSingleLineHtml=function(type,number,content,prefix){var htmlPrefix="";prefix&&(htmlPrefix='<span class="d2h-code-line-prefix">'+prefix+"</span>");var htmlContent="";return content&&(htmlContent='<span class="d2h-code-line-ctn">'+content+"</span>"),this.makeSingleLineHtml(type,number,htmlContent,htmlPrefix)},SideBySidePrinter.prototype.generateEmptyDiff=function(){var fileHtml={};return fileHtml.right="",fileHtml.left='<tr>\n <td class="'+diffParser.LINE_TYPE.INFO+'"> <div class="d2h-code-side-line '+diffParser.LINE_TYPE.INFO+'">File without changes </div> </td>\n</tr>\n',fileHtml},module.exports.SideBySidePrinter=SideBySidePrinter}()},{"./diff-parser.js":22,"./printer-utils.js":28,"./rematch.js":29,"./utils.js":32}],31:[function(require,module){(function(global){!function(){global.browserTemplates||(global.browserTemplates={});var Hogan=require("hogan.js");global.browserTemplates["line-by-line-column-line-number"]=new Hogan.Template({code:function(c,p,i){var t=this;return t.b(i=i||""),t.b("<tr>"),t.b("\n"+i),t.b(' <td class="d2h-code-linenumber '),t.b(t.v(t.d("diffParser.LINE_TYPE.INFO",c,p,0))),t.b('"></td>'),t.b("\n"+i),t.b(' <td class="'),t.b(t.v(t.d("diffParser.LINE_TYPE.INFO",c,p,0))),t.b('">'),t.b("\n"+i),t.b(' <div class="d2h-code-line '),t.b(t.v(t.d("diffParser.LINE_TYPE.INFO",c,p,0))),t.b('">'),t.b(t.t(t.f("blockHeader",c,p,0))),t.b("</div>"),t.b("\n"+i),t.b(" </td>"),t.b("\n"+i),t.b("</tr>"),t.fl()},partials:{},subs:{}}),global.browserTemplates["line-by-line-empty-diff"]=new Hogan.Template({code:function(c,p,i){var t=this;return t.b(i=i||""),t.b("<tr>"),t.b("\n"+i),t.b(' <td class="'),t.b(t.v(t.d("diffPa