(function(v,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(v=v||self,x(v.Diff={}))})(this,function(v){"use strict";function x(){}x.prototype={diff:function(n,r){var t,l=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i=l.callback;typeof l=="function"&&(i=l,l={}),this.options=l;var f=this;function o(p){return i?(setTimeout(function(){i(void 0,p)},0),!0):p}n=this.castInput(n),r=this.castInput(r),n=this.removeEmpty(this.tokenize(n)),r=this.removeEmpty(this.tokenize(r));var s=r.length,a=n.length,c=1,u=s+a;l.maxEditLength&&(u=Math.min(u,l.maxEditLength));var d=(t=l.timeout)!==null&&t!==void 0?t:1/0,g=Date.now()+d,h=[{oldPos:-1,lastComponent:void 0}],w=this.extractCommon(h[0],r,n,0);if(h[0].oldPos+1>=a&&w+1>=s)return o([{value:this.join(r),count:r.length}]);var b=-1/0,y=1/0;function O(){for(var p=Math.max(b,-c);p<=Math.min(y,c);p+=2){var F=void 0,m=h[p-1],L=h[p+1];m&&(h[p-1]=void 0);var N=!1;if(L){var S=L.oldPos-p;N=L&&0<=S&&S=a&&w+1>=s)return o(Le(f,F.lastComponent,r,n,f.useLongestToken));h[p]=F,F.oldPos+1>=a&&(y=Math.min(y,p-1)),w+1>=s&&(b=Math.max(b,p+1))}c++}if(i)(function p(){setTimeout(function(){if(c>u||Date.now()>g)return i();O()||p()},0)})();else for(;c<=u&&Date.now()<=g;){var H=O();if(H)return H}},addToPath:function(n,r,t,l){var i=n.lastComponent;return i&&i.added===r&&i.removed===t?{oldPos:n.oldPos+l,lastComponent:{count:i.count+1,added:r,removed:t,previousComponent:i.previousComponent}}:{oldPos:n.oldPos+l,lastComponent:{count:1,added:r,removed:t,previousComponent:i}}},extractCommon:function(n,r,t,l){for(var i=r.length,f=t.length,o=n.oldPos,s=o-l,a=0;s+1w.length?y:w}),u.value=e.join(d)}else u.value=e.join(r.slice(a,a+u.count));a+=u.count,u.added||(c+=u.count)}}var h=i[s-1];return s>1&&typeof h.value=="string"&&(h.added||h.removed)&&e.equals("",h.value)&&(i[s-2].value+=h.value,i.pop()),i}var xe=new x;function Fe(e,n,r){return xe.diff(e,n,r)}function ee(e,n){if(typeof e=="function")n.callback=e;else if(e)for(var r in e)e.hasOwnProperty(r)&&(n[r]=e[r]);return n}var ne=/^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/,re=/\S/,P=new x;P.equals=function(e,n){return this.options.ignoreCase&&(e=e.toLowerCase(),n=n.toLowerCase()),e===n||this.options.ignoreWhitespace&&!re.test(e)&&!re.test(n)},P.tokenize=function(e){for(var n=e.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/),r=0;re.length)&&(n=e.length);for(var r=0,t=new Array(n);r"u"?r:f}:t;return typeof e=="string"?e:JSON.stringify($(e,null,null,l),l," ")},C.equals=function(e,n){return x.prototype.equals.call(C,e.replace(/,([\r\n])/g,"$1"),n.replace(/,([\r\n])/g,"$1"))};function Me(e,n,r){return C.diff(e,n,r)}function $(e,n,r,t,l){n=n||[],r=r||[],t&&(e=t(l,e));var i;for(i=0;i1&&arguments[1]!==void 0?arguments[1]:{},r=e.split(/\r\n|[\n\v\f\r\x85]/),t=e.match(/\r\n|[\n\v\f\r\x85]/g)||[],l=[],i=0;function f(){var a={};for(l.push(a);i"u"?1:+u[2],newStart:+u[3],newLines:typeof u[4]>"u"?1:+u[4],lines:[],linedelimiters:[]};d.oldLines===0&&(d.oldStart+=1),d.newLines===0&&(d.newStart+=1);for(var g=0,h=0;i2&&arguments[2]!==void 0?arguments[2]:{};if(typeof n=="string"&&(n=R(n)),Array.isArray(n)){if(n.length>1)throw new Error("applyPatch only works with a single input.");n=n[0]}var t=e.split(/\r\n|[\n\v\f\r\x85]/),l=e.match(/\r\n|[\n\v\f\r\x85]/g)||[],i=n.hunks,f=r.compareLine||function(_,W,V,z){return W===z},o=0,s=r.fuzzFactor||0,a=0,c=0,u,d;function g(_,W){for(var V=0;V<_.lines.length;V++){var z=_.lines[V],k=z.length>0?z[0]:" ",Ge=z.length>0?z.substr(1):z;if(k===" "||k==="-"){if(!f(W+1,t[W],k,Ge)&&(o++,o>s))return!1;W++}}return!0}for(var h=0;h0?S[0]:" ",U=S.length>0?S.substr(1):S,K=m.linedelimiters&&m.linedelimiters[N]||` `;if(T===" ")L++;else if(T==="-")t.splice(L,1),l.splice(L,1);else if(T==="+")t.splice(L,0,U),l.splice(L,0,K),L++;else if(T==="\\"){var M=m.lines[N-1]?m.lines[N-1][0]:null;M==="+"?u=!0:M==="-"&&(d=!0)}}}if(u)for(;!t[t.length-1];)t.pop(),l.pop();else d&&(t.push(""),l.push(` `));for(var A=0;A"u"&&(f.context=4);var o=te(r,t,f);if(!o)return;o.push({value:"",lines:[]});function s(y){return y.map(function(O){return" "+O})}for(var a=[],c=0,u=0,d=[],g=1,h=1,w=function(O){var H=o[O],p=H.lines||H.value.replace(/\n$/,"").split(` `);if(H.lines=p,H.added||H.removed){var F;if(!c){var m=o[O-1];c=g,u=h,m&&(d=f.context>0?s(m.lines.slice(-f.context)):[],c-=d.length,u-=d.length)}(F=d).push.apply(F,I(p.map(function(A){return(H.added?"+":"-")+A}))),H.added?h+=p.length:g+=p.length}else{if(c)if(p.length<=f.context*2&&O=o.length-2&&p.length<=f.context){var U=/\n$/.test(r),K=/\n$/.test(t),M=p.length==0&&d.length>T.oldLines;!U&&M&&r.length>0&&d.splice(T.oldLines,0,"\\ No newline at end of file"),(!U&&!M||!K)&&d.push("\\ No newline at end of file")}a.push(T),c=0,u=0,d=[]}g+=p.length,h+=p.length}},b=0;b"u"?"":" "+e.oldHeader)),n.push("+++ "+e.newFileName+(typeof e.newHeader>"u"?"":" "+e.newHeader));for(var r=0;re.length)return!1;for(var r=0;r"):t.removed&&n.push(""),n.push(Be(t.value)),t.added?n.push(""):t.removed&&n.push("")}return n.join("")}function Be(e){var n=e;return n=n.replace(/&/g,"&"),n=n.replace(//g,">"),n=n.replace(/"/g,"""),n}v.Diff=x,v.applyPatch=se,v.applyPatches=De,v.canonicalize=$,v.convertChangesToDMP=Xe,v.convertChangesToXML=Ze,v.createPatch=qe,v.createTwoFilesPatch=ae,v.diffArrays=We,v.diffChars=Fe,v.diffCss=be,v.diffJson=Me,v.diffLines=te,v.diffSentences=Se,v.diffTrimmedLines=He,v.diffWords=Ne,v.diffWordsWithSpace=Oe,v.formatPatch=B,v.merge=Re,v.parsePatch=R,v.reversePatch=ye,v.structuredPatch=Z,Object.defineProperty(v,"__esModule",{value:!0})});