import{hU as p,gX as x,hq as N}from"./useAppFontEffects-B53Rb6m7.js";import{p as $}from"./VirtualizedFileDiff-lESMT-2b.js";function F(t,e=10){const i=[];let n;for(const s of t.split(`
`)){const l=s.match(p);if(l!=null){n!=null&&(n.hunkLines.length>0&&(h(n,e,"trailing"),L(n,i)),n=void 0);const r=parseInt(l[3]),u=parseInt(l[1]),a=parseInt(l[4]??"1"),o=parseInt(l[2]??"1");isNaN(r)||isNaN(u)||isNaN(a)||isNaN(o)?i.push(s):n={additionStart:r,deletionStart:u,additionCount:0,deletionCount:0,hunkLines:[],contextLines:[]};continue}if(n==null){i.push(s);continue}if(s.startsWith(" "))n.contextLines.push(s);else if(s!==""){if(n.hunkLines.length>0&&n.contextLines.length>e*2){const r=n.contextLines.length-e*2,u=n.contextLines.slice(-e);h(n,e,"trailing");const{additionCount:a,deletionCount:o}=n;L(n,i),n={additionStart:n.additionStart+a+r,deletionStart:n.deletionStart+o+r,deletionCount:0,additionCount:0,contextLines:u,hunkLines:[]}}h(n,e,n.hunkLines.length===0?"leading":"before-change"),n.hunkLines.push(s),s.startsWith("+")?n.additionCount+=1:s.startsWith("-")&&(n.deletionCount+=1)}}n!=null&&n.hunkLines.length>0&&(h(n,e,"trailing"),L(n,i));const c=i.join(`
`);return t.endsWith(`
`)?`${c}
`:c}function h(t,e,i){if(i==="leading"&&t.contextLines.length>e){const n=t.contextLines.length-e;t.contextLines.splice(0,n),t.additionStart+=n,t.deletionStart+=n}return i==="trailing"&&t.contextLines.length>e&&(t.contextLines.length=e),t.contextLines.length>0&&(t.hunkLines.push(...t.contextLines),t.additionCount+=t.contextLines.length,t.deletionCount+=t.contextLines.length,t.contextLines.length=0),t}function L(t,e){e.push(`@@ -${g(t.deletionStart,t.deletionCount)} +${g(t.additionStart,t.additionCount)} @@`),e.push(...t.hunkLines)}function g(t,e){return e===1?`${t}`:`${t},${e}`}const w=64,W=3,d=new Map,D=(t,e,i=W)=>{const n=`${t}\0${i}\0${e}`,c=d.get(n);if(c)return d.delete(n),d.set(n,c),c;const s=H(e),l=s?x(F(e,i),{oldFile:{name:t,contents:s.before},newFile:{name:t,contents:s.after}})??m(t):N(b(t,e))[0]?.files[0]??m(t);for(d.set(n,l);d.size>w;){const r=d.keys().next().value;if(!r)break;d.delete(r)}return l},b=(t,e)=>!e.trim()||e.startsWith("diff --git ")||/^--- [^\n]*\r?\n\+\+\+ /m.test(e)?e:`Index: ${t}
===================================================================
--- ${t}	
+++ ${t}	
${e}`,H=t=>{if(!t.startsWith("diff --git ")&&!/^--- [^\n]*\t?\r?\n\+\+\+ [^\n]*\t?(?:\r?\n|$)/m.test(t))return;const e=[...t.matchAll(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@[^\n]*(?:\r?\n|$)/gm)];if(e.length!==1)return;const i=e[0],n=Number.parseInt(i[1]??"",10),c=Number.parseInt(i[2]??"",10);if(n>1||c>1||!Number.isFinite(n)||!Number.isFinite(c))return;const s=(i.index??0)+i[0].length,l=t.slice(s),r=[],u=[];let a;for(const o of l.split(/\r?\n/)){if(o.startsWith("diff --git ")||o.startsWith("@@ "))break;if(o.startsWith("\\")){if(a==="-"||a===" "){const f=r.at(-1);f&&(f.newline=!1)}if(a==="+"||a===" "){const f=u.at(-1);f&&(f.newline=!1)}continue}if(o.startsWith("-")){r.push({text:o.slice(1),newline:!0}),a="-";continue}if(o.startsWith("+")){u.push({text:o.slice(1),newline:!0}),a="+";continue}o.startsWith(" ")&&(r.push({text:o.slice(1),newline:!0}),u.push({text:o.slice(1),newline:!0}),a=" ")}return{before:C(r),after:C(u)}},C=t=>t.map(e=>e.text+(e.newline?`
`:"")).join(""),m=t=>$({name:t,contents:""},{name:t,contents:""});export{D as f};
