diff2html/docs/demo.min.js
Rodrigo Fernandes cbfa0aa10d
Release 2.5.0
2018-11-14 23:07:09 +00:00

1 line
No EOL
16 KiB
JavaScript

!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||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(require,module,exports){var global,factory;global=this,factory=function(exports){"use strict";var support_searchParams="URLSearchParams"in self,support_iterable="Symbol"in self&&"iterator"in Symbol,support_blob="FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(e){return!1}}(),support_formData="FormData"in self,support_arrayBuffer="ArrayBuffer"in self;if(support_arrayBuffer)var viewClasses=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],isArrayBufferView=ArrayBuffer.isView||function(obj){return obj&&-1<viewClasses.indexOf(Object.prototype.toString.call(obj))};function normalizeName(name){if("string"!=typeof name&&(name=String(name)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name))throw new TypeError("Invalid character in header field name");return name.toLowerCase()}function normalizeValue(value){return"string"!=typeof value&&(value=String(value)),value}function iteratorFor(items){var iterator={next:function(){var value=items.shift();return{done:void 0===value,value:value}}};return support_iterable&&(iterator[Symbol.iterator]=function(){return iterator}),iterator}function Headers(headers){this.map={},headers instanceof Headers?headers.forEach(function(value,name){this.append(name,value)},this):Array.isArray(headers)?headers.forEach(function(header){this.append(header[0],header[1])},this):headers&&Object.getOwnPropertyNames(headers).forEach(function(name){this.append(name,headers[name])},this)}function consumed(body){if(body.bodyUsed)return Promise.reject(new TypeError("Already read"));body.bodyUsed=!0}function fileReaderReady(reader){return new Promise(function(resolve,reject){reader.onload=function(){resolve(reader.result)},reader.onerror=function(){reject(reader.error)}})}function readBlobAsArrayBuffer(blob){var reader=new FileReader,promise=fileReaderReady(reader);return reader.readAsArrayBuffer(blob),promise}function bufferClone(buf){if(buf.slice)return buf.slice(0);var view=new Uint8Array(buf.byteLength);return view.set(new Uint8Array(buf)),view.buffer}function Body(){return this.bodyUsed=!1,this._initBody=function(body){var obj;(this._bodyInit=body)?"string"==typeof body?this._bodyText=body:support_blob&&Blob.prototype.isPrototypeOf(body)?this._bodyBlob=body:support_formData&&FormData.prototype.isPrototypeOf(body)?this._bodyFormData=body:support_searchParams&&URLSearchParams.prototype.isPrototypeOf(body)?this._bodyText=body.toString():support_arrayBuffer&&support_blob&&((obj=body)&&DataView.prototype.isPrototypeOf(obj))?(this._bodyArrayBuffer=bufferClone(body.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):support_arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(body)||isArrayBufferView(body))?this._bodyArrayBuffer=bufferClone(body):this._bodyText=body=Object.prototype.toString.call(body):this._bodyText="",this.headers.get("content-type")||("string"==typeof body?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):support_searchParams&&URLSearchParams.prototype.isPrototypeOf(body)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},support_blob&&(this.blob=function(){var rejected=consumed(this);if(rejected)return rejected;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?consumed(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(readBlobAsArrayBuffer)}),this.text=function(){var blob,reader,promise,rejected=consumed(this);if(rejected)return rejected;if(this._bodyBlob)return blob=this._bodyBlob,reader=new FileReader,promise=fileReaderReady(reader),reader.readAsText(blob),promise;if(this._bodyArrayBuffer)return Promise.resolve(function(buf){for(var view=new Uint8Array(buf),chars=new Array(view.length),i=0;i<view.length;i++)chars[i]=String.fromCharCode(view[i]);return chars.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},support_formData&&(this.formData=function(){return this.text().then(decode)}),this.json=function(){return this.text().then(JSON.parse)},this}Headers.prototype.append=function(name,value){name=normalizeName(name),value=normalizeValue(value);var oldValue=this.map[name];this.map[name]=oldValue?oldValue+", "+value:value},Headers.prototype.delete=function(name){delete this.map[normalizeName(name)]},Headers.prototype.get=function(name){return name=normalizeName(name),this.has(name)?this.map[name]:null},Headers.prototype.has=function(name){return this.map.hasOwnProperty(normalizeName(name))},Headers.prototype.set=function(name,value){this.map[normalizeName(name)]=normalizeValue(value)},Headers.prototype.forEach=function(callback,thisArg){for(var name in this.map)this.map.hasOwnProperty(name)&&callback.call(thisArg,this.map[name],name,this)},Headers.prototype.keys=function(){var items=[];return this.forEach(function(value,name){items.push(name)}),iteratorFor(items)},Headers.prototype.values=function(){var items=[];return this.forEach(function(value){items.push(value)}),iteratorFor(items)},Headers.prototype.entries=function(){var items=[];return this.forEach(function(value,name){items.push([name,value])}),iteratorFor(items)},support_iterable&&(Headers.prototype[Symbol.iterator]=Headers.prototype.entries);var methods=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function Request(input,options){var method,upcased,body=(options=options||{}).body;if(input instanceof Request){if(input.bodyUsed)throw new TypeError("Already read");this.url=input.url,this.credentials=input.credentials,options.headers||(this.headers=new Headers(input.headers)),this.method=input.method,this.mode=input.mode,this.signal=input.signal,body||null==input._bodyInit||(body=input._bodyInit,input.bodyUsed=!0)}else this.url=String(input);if(this.credentials=options.credentials||this.credentials||"same-origin",!options.headers&&this.headers||(this.headers=new Headers(options.headers)),this.method=(method=options.method||this.method||"GET",upcased=method.toUpperCase(),-1<methods.indexOf(upcased)?upcased:method),this.mode=options.mode||this.mode||null,this.signal=options.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&body)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(body)}function decode(body){var form=new FormData;return body.trim().split("&").forEach(function(bytes){if(bytes){var split=bytes.split("="),name=split.shift().replace(/\+/g," "),value=split.join("=").replace(/\+/g," ");form.append(decodeURIComponent(name),decodeURIComponent(value))}}),form}function Response(bodyInit,options){options||(options={}),this.type="default",this.status=void 0===options.status?200:options.status,this.ok=200<=this.status&&this.status<300,this.statusText="statusText"in options?options.statusText:"OK",this.headers=new Headers(options.headers),this.url=options.url||"",this._initBody(bodyInit)}Request.prototype.clone=function(){return new Request(this,{body:this._bodyInit})},Body.call(Request.prototype),Body.call(Response.prototype),Response.prototype.clone=function(){return new Response(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new Headers(this.headers),url:this.url})},Response.error=function(){var response=new Response(null,{status:0,statusText:""});return response.type="error",response};var redirectStatuses=[301,302,303,307,308];Response.redirect=function(url,status){if(-1===redirectStatuses.indexOf(status))throw new RangeError("Invalid status code");return new Response(null,{status:status,headers:{location:url}})},exports.DOMException=self.DOMException;try{new exports.DOMException}catch(err){exports.DOMException=function(message,name){this.message=message,this.name=name;var error=Error(message);this.stack=error.stack},exports.DOMException.prototype=Object.create(Error.prototype),exports.DOMException.prototype.constructor=exports.DOMException}function fetch(input,init){return new Promise(function(resolve,reject){var request=new Request(input,init);if(request.signal&&request.signal.aborted)return reject(new exports.DOMException("Aborted","AbortError"));var xhr=new XMLHttpRequest;function abortXhr(){xhr.abort()}xhr.onload=function(){var rawHeaders,headers,options={status:xhr.status,statusText:xhr.statusText,headers:(rawHeaders=xhr.getAllResponseHeaders()||"",headers=new Headers,rawHeaders.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(line){var parts=line.split(":"),key=parts.shift().trim();if(key){var value=parts.join(":").trim();headers.append(key,value)}}),headers)};options.url="responseURL"in xhr?xhr.responseURL:options.headers.get("X-Request-URL");var body="response"in xhr?xhr.response:xhr.responseText;resolve(new Response(body,options))},xhr.onerror=function(){reject(new TypeError("Network request failed"))},xhr.ontimeout=function(){reject(new TypeError("Network request failed"))},xhr.onabort=function(){reject(new exports.DOMException("Aborted","AbortError"))},xhr.open(request.method,request.url,!0),"include"===request.credentials?xhr.withCredentials=!0:"omit"===request.credentials&&(xhr.withCredentials=!1),"responseType"in xhr&&support_blob&&(xhr.responseType="blob"),request.headers.forEach(function(value,name){xhr.setRequestHeader(name,value)}),request.signal&&(request.signal.addEventListener("abort",abortXhr),xhr.onreadystatechange=function(){4===xhr.readyState&&request.signal.removeEventListener("abort",abortXhr)}),xhr.send(void 0===request._bodyInit?null:request._bodyInit)})}fetch.polyfill=!0,self.fetch||(self.fetch=fetch,self.Headers=Headers,self.Request=Request,self.Response=Response),exports.Headers=Headers,exports.Request=Request,exports.Response=Response,exports.fetch=fetch,Object.defineProperty(exports,"__esModule",{value:!0})},"object"==typeof exports&&void 0!==module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory(global.WHATWGFetch={})},{}],2:[function(require,module,exports){$(document).ready(function(){require("whatwg-fetch");var searchParam="diff",$container=$(".container"),$url=$("#url"),$outputFormat=$("#diff-url-options-output-format"),$showFiles=$("#diff-url-options-show-files"),$matching=$("#diff-url-options-matching"),$wordsThreshold=$("#diff-url-options-match-words-threshold"),$matchingMaxComparisons=$("#diff-url-options-matching-max-comparisons");if(window.location.search){var url=function(search){try{return search.split("?")[1].split(searchParam+"=")[1].split("&")[0]}catch(_ignore){}return null}(window.location.search);$url.val(url),smartDraw(url)}function getParamsFromSearch(search){var map={};try{search.split("?")[1].split("&").map(function(e){var values=e.split("=");map[values[0]]=values[1]})}catch(_ignore){}return map}function smartDraw(urlOpt,forced){!function(req,forced){if(!validateUrl(req.url))return console.error("Invalid url provided!");validateUrl(req.originalUrl)&&function(url){var params=getParamsFromSearch(window.location.search);if(params[searchParam]===url)return;params[searchParam]=url;var paramString=Object.keys(params).map(function(k){return k+"="+params[k]}).join("&");window.location="demo.html?"+paramString}(req.originalUrl);var outputFormat=$outputFormat.val(),showFiles=$showFiles.is(":checked"),matching=$matching.val(),wordsThreshold=$wordsThreshold.val(),matchingMaxComparisons=$matchingMaxComparisons.val();fetch(req.url,{method:"GET",headers:req.headers,mode:"cors",cache:"default"}).then(function(res){return res.text()}).then(function(data){var container="#url-diff-container",diff2htmlUi=new Diff2HtmlUI({diff:data});"side-by-side"===outputFormat?$container.css({width:"100%"}):$container.css({width:""});var params=getParamsFromSearch(window.location.search);delete params[searchParam],forced?(params.outputFormat=outputFormat,params.showFiles=showFiles,params.matching=matching,params.wordsThreshold=wordsThreshold,params.matchingMaxComparisons=matchingMaxComparisons):(params.outputFormat=params.outputFormat||outputFormat,params.showFiles="false"!==String(params.showFiles)||null===params.showFiles&&showFiles,params.matching=params.matching||matching,params.wordsThreshold=params.wordsThreshold||wordsThreshold,params.matchingMaxComparisons=params.matchingMaxComparisons||matchingMaxComparisons,$outputFormat.val(params.outputFormat),$showFiles.prop("checked",params.showFiles),$matching.val(params.matching),$wordsThreshold.val(params.wordsThreshold),$matchingMaxComparisons.val(params.matchingMaxComparisons)),params.synchronisedScroll=params.synchronisedScroll||!0,diff2htmlUi.draw(container,params),diff2htmlUi.fileListCloseable(container,params.fileListCloseable||!1),(void 0===params.highlight||params.highlight)&&diff2htmlUi.highlightCode(container)})}(function(url){var values,headers=new Headers;function gitLabUrlGen(userName,projectName,type,value){return"https://crossorigin.me/https://gitlab.com/"+userName+"/"+projectName+"/"+type+"/"+value+".diff"}function gitHubUrlGen(userName,projectName,type,value){return headers.append("Accept","application/vnd.github.v3.diff"),"https://api.github.com/repos/"+userName+"/"+projectName+"/"+type+"/"+value}function bitbucketUrlGen(userName,projectName,type,value){var baseUrl="https://bitbucket.org/api/2.0/repositories/";return"pullrequests"===type?baseUrl+userName+"/"+projectName+"/pullrequests/"+value+"/diff":baseUrl+userName+"/"+projectName+"/diff/"+value}return{originalUrl:url,url:(values=/^https?:\/\/(?:www\.)?github\.com\/(.*?)\/(.*?)\/commit\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/.exec(url))?gitHubUrlGen(values[1],values[2],"commits",values[3]):(values=/^https?:\/\/(?:www\.)?github\.com\/(.*?)\/(.*?)\/pull\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/.exec(url))?gitHubUrlGen(values[1],values[2],"pulls",values[3]):(values=/^https?:\/\/(?:www\.)?gitlab\.com\/(.*?)\/(.*?)\/commit\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/.exec(url))?gitLabUrlGen(values[1],values[2],"commit",values[3]):(values=/^https?:\/\/(?:www\.)?gitlab\.com\/(.*?)\/(.*?)\/merge_requests\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/.exec(url))?gitLabUrlGen(values[1],values[2],"merge_requests",values[3]):(values=/^https?:\/\/(?:www\.)?bitbucket\.org\/(.*?)\/(.*?)\/commits\/(.*?)(?:\/raw)?(?:\/.*)?$/.exec(url))?bitbucketUrlGen(values[1],values[2],"commit",values[3]):(values=/^https?:\/\/(?:www\.)?bitbucket\.org\/(.*?)\/(.*?)\/pull-requests\/(.*?)(?:\/.*)?$/.exec(url))?bitbucketUrlGen(values[1],values[2],"pullrequests",values[3]):(console.info("Could not parse url, using the provided url."),"https://crossorigin.me/"+url),headers:headers}}(urlOpt||$url.val()),forced)}function validateUrl(url){return/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(url)}$("#url-btn").click(function(e){e.preventDefault();var url=$url.val();smartDraw(url)}),$url.on("paste",function(e){var url=e.originalEvent.clipboardData.getData("Text");smartDraw(url)}),$outputFormat.add($showFiles).add($matching).add($wordsThreshold).add($matchingMaxComparisons).change(function(e){console.log(""),console.log(e),console.log(""),smartDraw(null,!0)})})},{"whatwg-fetch":1}]},{},[2]);