#!/usr/bin/env node
var E=class{diff(e,t,n={}){let i;typeof n=="function"?(i=n,n={}):"callback"in n&&(i=n.callback);let u=this.castInput(e,n),r=this.castInput(t,n),s=this.removeEmpty(this.tokenize(u,n)),c=this.removeEmpty(this.tokenize(r,n));return this.diffWithOptionsObj(s,c,n,i)}diffWithOptionsObj(e,t,n,i){var u;let r=o=>{if(o=this.postProcess(o,n),i){setTimeout(function(){i(o)},0);return}else return o},s=t.length,c=e.length,d=1,f=s+c;n.maxEditLength!=null&&(f=Math.min(f,n.maxEditLength));let P=(u=n.timeout)!==null&&u!==void 0?u:1/0,x=Date.now()+P,m=[{oldPos:-1,lastComponent:void 0}],g=this.extractCommon(m[0],t,e,0,n);if(m[0].oldPos+1>=c&&g+1>=s)return r(this.buildValues(m[0].lastComponent,t,e));let w=-1/0,L=1/0,C=()=>{for(let o=Math.max(w,-d);o<=Math.min(L,d);o+=2){let a,h=m[o-1],p=m[o+1];h&&(m[o-1]=void 0);let v=!1;if(p){let b=p.oldPos-o;v=p&&0<=b&&b<s}let D=h&&h.oldPos+1<c;if(!v&&!D){m[o]=void 0;continue}if(!D||v&&h.oldPos<p.oldPos?a=this.addToPath(p,!0,!1,0,n):a=this.addToPath(h,!1,!0,1,n),g=this.extractCommon(a,t,e,o,n),a.oldPos+1>=c&&g+1>=s)return r(this.buildValues(a.lastComponent,t,e))||!0;m[o]=a,a.oldPos+1>=c&&(L=Math.min(L,o-1)),g+1>=s&&(w=Math.max(w,o+1))}d++};if(i)(function o(){setTimeout(function(){if(d>f||Date.now()>x)return i(void 0);C()||o()},0)})();else for(;d<=f&&Date.now()<=x;){let o=C();if(o)return o}}addToPath(e,t,n,i,u){let r=e.lastComponent;return r&&!u.oneChangePerToken&&r.added===t&&r.removed===n?{oldPos:e.oldPos+i,lastComponent:{count:r.count+1,added:t,removed:n,previousComponent:r.previousComponent}}:{oldPos:e.oldPos+i,lastComponent:{count:1,added:t,removed:n,previousComponent:r}}}extractCommon(e,t,n,i,u){let r=t.length,s=n.length,c=e.oldPos,d=c-i,f=0;for(;d+1<r&&c+1<s&&this.equals(n[c+1],t[d+1],u);)d++,c++,f++,u.oneChangePerToken&&(e.lastComponent={count:1,previousComponent:e.lastComponent,added:!1,removed:!1});return f&&!u.oneChangePerToken&&(e.lastComponent={count:f,previousComponent:e.lastComponent,added:!1,removed:!1}),e.oldPos=c,d}equals(e,t,n){return n.comparator?n.comparator(e,t):e===t||!!n.ignoreCase&&e.toLowerCase()===t.toLowerCase()}removeEmpty(e){let t=[];for(let n=0;n<e.length;n++)e[n]&&t.push(e[n]);return t}castInput(e,t){return e}tokenize(e,t){return Array.from(e)}join(e){return e.join("")}postProcess(e,t){return e}get useLongestToken(){return!1}buildValues(e,t,n){let i=[],u;for(;e;)i.push(e),u=e.previousComponent,delete e.previousComponent,e=u;i.reverse();let r=i.length,s=0,c=0,d=0;for(;s<r;s++){let f=i[s];if(f.removed)f.value=this.join(n.slice(d,d+f.count)),d+=f.count;else{if(!f.added&&this.useLongestToken){let P=t.slice(c,c+f.count);P=P.map(function(x,m){let g=n[d+m];return g.length>x.length?g:x}),f.value=this.join(P)}else f.value=this.join(t.slice(c,c+f.count));c+=f.count,f.added||(d+=f.count)}}return i}};var I=class extends E{constructor(){super(...arguments),this.tokenize=H}equals(e,t,n){return n.ignoreWhitespace?((!n.newlineIsToken||!e.includes(`
`))&&(e=e.trim()),(!n.newlineIsToken||!t.includes(`
`))&&(t=t.trim())):n.ignoreNewlineAtEof&&!n.newlineIsToken&&(e.endsWith(`
`)&&(e=e.slice(0,-1)),t.endsWith(`
`)&&(t=t.slice(0,-1))),super.equals(e,t,n)}},j=new I;function T(l,e,t){return j.diff(l,e,t)}function H(l,e){e.stripTrailingCr&&(l=l.replace(/\r\n/g,`
`));let t=[],n=l.split(/(\n|\r\n)/);n[n.length-1]||n.pop();for(let i=0;i<n.length;i++){let u=n[i];i%2&&!e.newlineIsToken?t[t.length-1]+=u:t.push(u)}return t}var S={includeIndex:!0,includeUnderline:!0,includeFileHeaders:!0};function y(l,e,t,n,i,u,r){let s;r?typeof r=="function"?s={callback:r}:s=r:s={},typeof s.context>"u"&&(s.context=4);let c=s.context;if(s.newlineIsToken)throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");if(s.callback){let{callback:f}=s;T(t,n,Object.assign(Object.assign({},s),{callback:P=>{let x=d(P);f(x)}}))}else return d(T(t,n,s));function d(f){if(!f)return;f.push({value:"",lines:[]});function P(o){return o.map(function(a){return" "+a})}let x=[],m=0,g=0,w=[],L=1,C=1;for(let o=0;o<f.length;o++){let a=f[o],h=a.lines||F(a.value);if(a.lines=h,a.added||a.removed){if(!m){let p=f[o-1];m=L,g=C,p&&(w=c>0?P(p.lines.slice(-c)):[],m-=w.length,g-=w.length)}for(let p of h)w.push((a.added?"+":"-")+p);a.added?C+=h.length:L+=h.length}else{if(m)if(h.length<=c*2&&o<f.length-2)for(let p of P(h))w.push(p);else{let p=Math.min(h.length,c);for(let D of P(h.slice(0,p)))w.push(D);let v={oldStart:m,oldLines:L-m+p,newStart:g,newLines:C-g+p,lines:w};x.push(v),m=0,g=0,w=[]}L+=h.length,C+=h.length}}for(let o of x)for(let a=0;a<o.lines.length;a++)o.lines[a].endsWith(`
`)?o.lines[a]=o.lines[a].slice(0,-1):(o.lines.splice(a+1,0,"\\ No newline at end of file"),a++);return{oldFileName:l,newFileName:e,oldHeader:i,newHeader:u,hunks:x}}}function k(l,e){if(e||(e=S),Array.isArray(l)){if(l.length>1&&!e.includeFileHeaders)throw new Error("Cannot omit file headers on a multi-file patch. (The result would be unparseable; how would a tool trying to apply the patch know which changes are to which file?)");return l.map(n=>k(n,e)).join(`
`)}let t=[];e.includeIndex&&l.oldFileName==l.newFileName&&t.push("Index: "+l.oldFileName),e.includeUnderline&&t.push("==================================================================="),e.includeFileHeaders&&(t.push("--- "+l.oldFileName+(typeof l.oldHeader>"u"?"":"	"+l.oldHeader)),t.push("+++ "+l.newFileName+(typeof l.newHeader>"u"?"":"	"+l.newHeader)));for(let n=0;n<l.hunks.length;n++){let i=l.hunks[n];i.oldLines===0&&(i.oldStart-=1),i.newLines===0&&(i.newStart-=1),t.push("@@ -"+i.oldStart+","+i.oldLines+" +"+i.newStart+","+i.newLines+" @@");for(let u of i.lines)t.push(u)}return t.join(`
`)+`
`}function A(l,e,t,n,i,u,r){if(typeof r=="function"&&(r={callback:r}),r?.callback){let{callback:s}=r;y(l,e,t,n,i,u,Object.assign(Object.assign({},r),{callback:c=>{s(c?k(c,r.headerOptions):void 0)}}))}else{let s=y(l,e,t,n,i,u,r);return s?k(s,r?.headerOptions):void 0}}function F(l){let e=l.endsWith(`
`),t=l.split(`
`).map(n=>n+`
`);return e?t.pop():t.push(t.pop().slice(0,-1)),t}export{y as a,A as b};
