class k{diff(e,i,t={}){let l;typeof t=="function"?(l=t,t={}):"callback"in t&&(l=t.callback);const f=this.castInput(e,t),r=this.castInput(i,t),u=this.removeEmpty(this.tokenize(f,t)),o=this.removeEmpty(this.tokenize(r,t));return this.diffWithOptionsObj(u,o,t,l)}diffWithOptionsObj(e,i,t,l){var f;const r=d=>{if(d=this.postProcess(d,t),l){setTimeout(function(){l(d)},0);return}else return d},u=i.length,o=e.length;let m=1,s=u+o;t.maxEditLength!=null&&(s=Math.min(s,t.maxEditLength));const a=(f=t.timeout)!==null&&f!==void 0?f:1/0,C=Date.now()+a,h=[{oldPos:-1,lastComponent:void 0}];let x=this.extractCommon(h[0],i,e,0,t);if(h[0].oldPos+1>=o&&x+1>=u)return r(this.buildValues(h[0].lastComponent,i,e));let v=-1/0,P=1/0;const F=()=>{for(let d=Math.max(v,-m);d<=Math.min(P,m);d+=2){let c;const w=h[d-1],g=h[d+1];w&&(h[d-1]=void 0);let L=!1;if(g){const D=g.oldPos-d;L=g&&0<=D&&D<u}const N=w&&w.oldPos+1<o;if(!L&&!N){h[d]=void 0;continue}if(!N||L&&w.oldPos<g.oldPos?c=this.addToPath(g,!0,!1,0,t):c=this.addToPath(w,!1,!0,1,t),x=this.extractCommon(c,i,e,d,t),c.oldPos+1>=o&&x+1>=u)return r(this.buildValues(c.lastComponent,i,e))||!0;h[d]=c,c.oldPos+1>=o&&(P=Math.min(P,d-1)),x+1>=u&&(v=Math.max(v,d+1))}m++};if(l)(function d(){setTimeout(function(){if(m>s||Date.now()>C)return l(void 0);F()||d()},0)})();else for(;m<=s&&Date.now()<=C;){const d=F();if(d)return d}}addToPath(e,i,t,l,f){const r=e.lastComponent;return r&&!f.oneChangePerToken&&r.added===i&&r.removed===t?{oldPos:e.oldPos+l,lastComponent:{count:r.count+1,added:i,removed:t,previousComponent:r.previousComponent}}:{oldPos:e.oldPos+l,lastComponent:{count:1,added:i,removed:t,previousComponent:r}}}extractCommon(e,i,t,l,f){const r=i.length,u=t.length;let o=e.oldPos,m=o-l,s=0;for(;m+1<r&&o+1<u&&this.equals(t[o+1],i[m+1],f);)m++,o++,s++,f.oneChangePerToken&&(e.lastComponent={count:1,previousComponent:e.lastComponent,added:!1,removed:!1});return s&&!f.oneChangePerToken&&(e.lastComponent={count:s,previousComponent:e.lastComponent,added:!1,removed:!1}),e.oldPos=o,m}equals(e,i,t){return t.comparator?t.comparator(e,i):e===i||!!t.ignoreCase&&e.toLowerCase()===i.toLowerCase()}removeEmpty(e){const i=[];for(let t=0;t<e.length;t++)e[t]&&i.push(e[t]);return i}castInput(e,i){return e}tokenize(e,i){return Array.from(e)}join(e){return e.join("")}postProcess(e,i){return e}get useLongestToken(){return!1}buildValues(e,i,t){const l=[];let f;for(;e;)l.push(e),f=e.previousComponent,delete e.previousComponent,e=f;l.reverse();const r=l.length;let u=0,o=0,m=0;for(;u<r;u++){const s=l[u];if(s.removed)s.value=this.join(t.slice(m,m+s.count)),m+=s.count;else{if(!s.added&&this.useLongestToken){let a=i.slice(o,o+s.count);a=a.map(function(C,h){const x=t[m+h];return x.length>C.length?x:C}),s.value=this.join(a)}else s.value=this.join(i.slice(o,o+s.count));o+=s.count,s.added||(m+=s.count)}}return l}}class T extends k{}const j=new T;function q(n,e,i){return j.diff(n,e,i)}const E="a-zA-Z0-9_\\u{AD}\\u{C0}-\\u{D6}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}";class W extends k{tokenize(e){const i=new RegExp(`(\\r?\\n)|[${E}]+|[^\\S\\n\\r]+|[^${E}]`,"ug");return e.match(i)||[]}}const M=new W;function G(n,e,i){return M.diff(n,e,i)}class A extends k{constructor(){super(...arguments),this.tokenize=_}equals(e,i,t){return t.ignoreWhitespace?((!t.newlineIsToken||!e.includes(`
`))&&(e=e.trim()),(!t.newlineIsToken||!i.includes(`
`))&&(i=i.trim())):t.ignoreNewlineAtEof&&!t.newlineIsToken&&(e.endsWith(`
`)&&(e=e.slice(0,-1)),i.endsWith(`
`)&&(i=i.slice(0,-1))),super.equals(e,i,t)}}const H=new A;function y(n,e,i){return H.diff(n,e,i)}function _(n,e){e.stripTrailingCr&&(n=n.replace(/\r\n/g,`
`));const i=[],t=n.split(/(\n|\r\n)/);t[t.length-1]||t.pop();for(let l=0;l<t.length;l++){const f=t[l];l%2&&!e.newlineIsToken?i[i.length-1]+=f:i.push(f)}return i}function z(n){for(let e=0;e<n.length;e++)if(n[e]<" "||n[e]>"~"||n[e]==='"'||n[e]==="\\")return!0;return!1}function b(n){if(!z(n))return n;let e='"';const i=new TextEncoder().encode(n);let t=0;for(;t<i.length;){const l=i[t];l===7?e+="\\a":l===8?e+="\\b":l===9?e+="\\t":l===10?e+="\\n":l===11?e+="\\v":l===12?e+="\\f":l===13?e+="\\r":l===34?e+='\\"':l===92?e+="\\\\":l>=32&&l<=126?e+=String.fromCharCode(l):e+="\\"+l.toString(8).padStart(3,"0"),t++}return e+='"',e}const S={includeIndex:!0,includeUnderline:!0,includeFileHeaders:!0};function I(n,e,i,t,l,f,r){let u;r?typeof r=="function"?u={callback:r}:u=r:u={},typeof u.context>"u"&&(u.context=4);const o=u.context;if(u.newlineIsToken)throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");if(u.callback){const{callback:s}=u;y(i,t,Object.assign(Object.assign({},u),{callback:a=>{const C=m(a);s(C)}}))}else return m(y(i,t,u));function m(s){if(!s)return;s.push({value:"",lines:[]});function a(d){return d.map(function(c){return" "+c})}const C=[];let h=0,x=0,v=[],P=1,F=1;for(let d=0;d<s.length;d++){const c=s[d],w=c.lines||R(c.value);if(c.lines=w,c.added||c.removed){if(!h){const g=s[d-1];h=P,x=F,g&&(v=o>0?a(g.lines.slice(-o)):[],h-=v.length,x-=v.length)}for(const g of w)v.push((c.added?"+":"-")+g);c.added?F+=w.length:P+=w.length}else{if(h)if(w.length<=o*2&&d<s.length-2)for(const g of a(w))v.push(g);else{const g=Math.min(w.length,o);for(const N of a(w.slice(0,g)))v.push(N);const L={oldStart:h,oldLines:P-h+g,newStart:x,newLines:F-x+g,lines:v};C.push(L),h=0,x=0,v=[]}P+=w.length,F+=w.length}}for(const d of C)for(let c=0;c<d.lines.length;c++)d.lines[c].endsWith(`
`)?d.lines[c]=d.lines[c].slice(0,-1):(d.lines.splice(c+1,0,"\\ No newline at end of file"),c++);return{oldFileName:n,newFileName:e,oldHeader:l,newHeader:f,hunks:C}}}function p(n,e){var i,t,l,f,r,u;if(e||(e=S),Array.isArray(n)){if(n.length>1&&!e.includeFileHeaders&&!n.every(s=>s.isGit))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 n.map(s=>p(s,e)).join(`
`)}const o=[];if(n.isGit){if(e=S,!n.oldFileName)throw new Error("oldFileName must be specified for Git patches");if(!n.newFileName)throw new Error("newFileName must be specified for Git patches");let s=n.oldFileName,a=n.newFileName;n.isCreate&&s==="/dev/null"?s=a.replace(/^b\//,"a/"):n.isDelete&&a==="/dev/null"&&(a=s.replace(/^a\//,"b/")),o.push("diff --git "+b(s)+" "+b(a)),n.isDelete&&o.push("deleted file mode "+((i=n.oldMode)!==null&&i!==void 0?i:"100644")),n.isCreate&&o.push("new file mode "+((t=n.newMode)!==null&&t!==void 0?t:"100644")),n.oldMode&&n.newMode&&!n.isDelete&&!n.isCreate&&(o.push("old mode "+n.oldMode),o.push("new mode "+n.newMode)),n.isRename&&(o.push("rename from "+b(((l=n.oldFileName)!==null&&l!==void 0?l:"").replace(/^a\//,""))),o.push("rename to "+b(((f=n.newFileName)!==null&&f!==void 0?f:"").replace(/^b\//,"")))),n.isCopy&&(o.push("copy from "+b(((r=n.oldFileName)!==null&&r!==void 0?r:"").replace(/^a\//,""))),o.push("copy to "+b(((u=n.newFileName)!==null&&u!==void 0?u:"").replace(/^b\//,""))))}else e.includeIndex&&n.oldFileName==n.newFileName&&n.oldFileName!==void 0&&o.push("Index: "+n.oldFileName),e.includeUnderline&&o.push("===================================================================");const m=n.hunks.length>0;e.includeFileHeaders&&n.oldFileName!==void 0&&n.newFileName!==void 0&&(!n.isGit||m)&&(o.push("--- "+b(n.oldFileName)+(n.oldHeader?"	"+n.oldHeader:"")),o.push("+++ "+b(n.newFileName)+(n.newHeader?"	"+n.newHeader:"")));for(let s=0;s<n.hunks.length;s++){const a=n.hunks[s],C=a.oldLines===0?a.oldStart-1:a.oldStart,h=a.newLines===0?a.newStart-1:a.newStart;o.push("@@ -"+C+","+a.oldLines+" +"+h+","+a.newLines+" @@");for(const x of a.lines)o.push(x)}return o.join(`
`)+`
`}function O(n,e,i,t,l,f,r){if(typeof r=="function"&&(r={callback:r}),r?.callback){const{callback:u}=r;I(n,e,i,t,l,f,Object.assign(Object.assign({},r),{callback:o=>{u(o?p(o,r.headerOptions):void 0)}}))}else{const u=I(n,e,i,t,l,f,r);return u?p(u,r?.headerOptions):void 0}}function R(n){const e=n.endsWith(`
`),i=n.split(`
`).map(t=>t+`
`);return e?i.pop():i.push(i.pop().slice(0,-1)),i}export{G as a,O as c,q as d};
