var e=`diffs-container`,t=/(?=^From [a-f0-9]+ .+$)/m,n=/(?=^diff --git)/gm,r=/(?=^---\s+\S)/gm,i=/(?=^@@ )/gm,a=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?: (.*))?/m,o=/(?<=\n)/,s=/^(---|\+\+\+)\s+([^\t\r\n]+)/,c=/^(---|\+\+\+)\s+[ab]\/([^\t\r\n]+)/,l=/^diff --git (?:"a\/(.+?)"|a\/(.+?)) (?:"b\/(.+?)"|b\/(.+?))$/,u=/^index ([0-9a-f]+)\.\.([0-9a-f]+)(?: (\d+))?$/i,d=`header-prefix`,f=`header-metadata`,p=`header-custom`,m={dark:`pierre-dark`,light:`pierre-light`},h=`data-theme-css`,g=`data-unsafe-css`,_={hunkLineCount:50,lineHeight:20,diffHeaderHeight:44,hunkSeparatorHeight:32,fileGap:8},v=Object.freeze({fromStart:0,fromEnd:0}),y={startingLine:0,totalLines:1/0,bufferBefore:0,bufferAfter:0},b={startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:0};function x(e){return e.replace(/\n$|\r\n$/,``)}function S(e){let t=e[0];if(t!==`+`&&t!==`-`&&t!==` `&&t!==`\\`){console.error(`parseLineType: Invalid firstChar: "${t}", full line: "${e}"`);return}let n=e.substring(1);return{line:n===``?`
`:n,type:t===` `?`context`:t===`\\`?`metadata`:t===`+`?`addition`:`deletion`}}function C(e,t,i=!1){let a=n.test(e),o=e.split(a?n:r),s,c=[];for(let e of o){if(a&&!n.test(e)){if(s==null)s=e;else if(i)throw Error(`parsePatchContent: unknown file blob`);else console.error(`parsePatchContent: unknown file blob:`,e);continue}else if(!a&&!r.test(e)){if(s==null)s=e;else if(i)throw Error(`parsePatchContent: unknown file blob`);else console.error(`parsePatchContent: unknown file blob:`,e);continue}let o=w(e,{cacheKey:t==null?void 0:`${t}-${c.length}`,isGitDiff:a,throwOnError:i});o!=null&&c.push(o)}return{patchMetadata:s,files:c}}function w(e,{cacheKey:t,isGitDiff:r=n.test(e),oldFile:d,newFile:f,throwOnError:p=!1}={}){let m=0,h=e.split(i),g,_=d==null||f==null,v=0,y=0;for(let e of h){let n=e.split(o),i=n.shift();if(i==null){if(p)throw Error(`parsePatchContent: invalid hunk`);console.error(`parsePatchContent: invalid hunk`,e);continue}let h=i.match(a),b=0,C=0;if(h==null||g==null){if(g!=null){if(p)throw Error(`parsePatchContent: Invalid hunk`);console.error(`parsePatchContent: Invalid hunk`,e);continue}g={name:``,type:`change`,hunks:[],splitLineCount:0,unifiedLineCount:0,isPartial:_,additionLines:!_&&d!=null&&f!=null?f.contents.split(o):[],deletionLines:!_&&d!=null&&f!=null?d.contents.split(o):[],cacheKey:t},g.additionLines.length===1&&f?.contents===``&&(g.additionLines.length=0),g.deletionLines.length===1&&d?.contents===``&&(g.deletionLines.length=0),n.unshift(i);for(let e of n){let t=e.match(r?c:s);if(e.startsWith(`diff --git`)){let[,,t,,n]=e.trim().match(l)??[];g.name=n.trim(),t!==n&&(g.prevName=t.trim())}else if(t!=null){let[,e,n]=t;e===`---`&&n!==`/dev/null`?(g.prevName=n.trim(),g.name=n.trim()):e===`+++`&&n!==`/dev/null`&&(g.name=n.trim())}else if(r){if(e.startsWith(`new mode `)&&(g.mode=e.replace(`new mode`,``).trim()),e.startsWith(`old mode `)&&(g.prevMode=e.replace(`old mode`,``).trim()),e.startsWith(`new file mode`)&&(g.type=`new`,g.mode=e.replace(`new file mode`,``).trim()),e.startsWith(`deleted file mode`)&&(g.type=`deleted`,g.mode=e.replace(`deleted file mode`,``).trim()),e.startsWith(`similarity index`)&&(e.startsWith(`similarity index 100%`)?g.type=`rename-pure`:g.type=`rename-changed`),e.startsWith(`index `)){let[,t,n,r]=e.trim().match(u)??[];t!=null&&(g.prevObjectId=t),n!=null&&(g.newObjectId=n),r!=null&&(g.mode=r)}e.startsWith(`rename from `)&&(g.prevName=e.replace(`rename from `,``).trim()),e.startsWith(`rename to `)&&(g.name=e.replace(`rename to `,``).trim())}}continue}let w,T;for(;n.length>0&&(n[n.length-1]===`
`||n[n.length-1]===`\r`||n[n.length-1]===`\r
`||n[n.length-1]===``);)n.pop();let D=parseInt(h[3]),O=parseInt(h[1]);v=_?v:O-1,y=_?y:D-1;let k={collapsedBefore:0,splitLineCount:0,splitLineStart:0,unifiedLineCount:0,unifiedLineStart:0,additionCount:parseInt(h[4]??`1`),additionStart:D,additionLines:b,deletionCount:parseInt(h[2]??`1`),deletionStart:O,deletionLines:C,deletionLineIndex:v,additionLineIndex:y,hunkContent:[],hunkContext:h[5],hunkSpecs:i,noEOFCRAdditions:!1,noEOFCRDeletions:!1};if(isNaN(k.additionCount)||isNaN(k.deletionCount)||isNaN(k.additionStart)||isNaN(k.deletionStart)){if(p)throw Error(`parsePatchContent: invalid hunk metadata`);console.error(`parsePatchContent: invalid hunk metadata`,k);continue}for(let e of n){let t=S(e);if(t==null){console.error(`processFile: invalid rawLine:`,e);continue}let{type:n,line:r}=t;if(n===`addition`)(w==null||w.type!==`change`)&&(w=E(`change`,v,y),k.hunkContent.push(w)),y++,_&&g.additionLines.push(r),w.additions++,b++,T=`addition`;else if(n===`deletion`)(w==null||w.type!==`change`)&&(w=E(`change`,v,y),k.hunkContent.push(w)),v++,_&&g.deletionLines.push(r),w.deletions++,C++,T=`deletion`;else if(n===`context`)(w==null||w.type!==`context`)&&(w=E(`context`,v,y),k.hunkContent.push(w)),y++,v++,_&&(g.deletionLines.push(r),g.additionLines.push(r)),w.lines++,T=`context`;else if(n===`metadata`&&w!=null){if(w.type===`context`?(k.noEOFCRAdditions=!0,k.noEOFCRDeletions=!0):T===`deletion`?k.noEOFCRDeletions=!0:T===`addition`&&(k.noEOFCRAdditions=!0),_&&(T===`addition`||T===`context`)){let e=g.additionLines.length-1;e>=0&&(g.additionLines[e]=x(g.additionLines[e]))}if(_&&(T===`deletion`||T===`context`)){let e=g.deletionLines.length-1;e>=0&&(g.deletionLines[e]=x(g.deletionLines[e]))}}}k.additionLines=b,k.deletionLines=C,k.collapsedBefore=Math.max(k.additionStart-1-m,0),g.hunks.push(k),m=k.additionStart+k.additionCount-1;for(let e of k.hunkContent)e.type===`context`?(k.splitLineCount+=e.lines,k.unifiedLineCount+=e.lines):(k.splitLineCount+=Math.max(e.additions,e.deletions),k.unifiedLineCount+=e.deletions+e.additions);k.splitLineStart=g.splitLineCount+k.collapsedBefore,k.unifiedLineStart=g.unifiedLineCount+k.collapsedBefore,g.splitLineCount+=k.collapsedBefore+k.splitLineCount,g.unifiedLineCount+=k.collapsedBefore+k.unifiedLineCount}if(g!=null){if(g.hunks.length>0&&!_&&g.additionLines.length>0&&g.deletionLines.length>0){let e=g.hunks[g.hunks.length-1],t=e.additionStart+e.additionCount-1,n=g.additionLines.length,r=Math.max(n-t,0);g.splitLineCount+=r,g.unifiedLineCount+=r}return r||(g.prevName!=null&&g.name!==g.prevName?g.hunks.length>0?g.type=`rename-changed`:g.type=`rename-pure`:f!=null&&f.contents===``?g.type=`deleted`:d!=null&&d.contents===``&&(g.type=`new`)),g.type!==`rename-pure`&&g.type!==`rename-changed`&&(g.prevName=void 0),g}}function T(e,n,r=!1){let i=[];for(let a of e.split(t))try{i.push(C(a,n==null?void 0:`${n}-${i.length}`,r))}catch(e){if(r)throw e;console.error(e)}return i}function E(e,t,n){return e===`change`?{type:`change`,additions:0,deletions:0,additionLineIndex:n,deletionLineIndex:t}:{type:`context`,lines:0,additionLineIndex:n,deletionLineIndex:t}}export{v as a,_ as c,f as d,d as f,g as h,p as i,e as l,h as m,w as n,y as o,o as p,x as r,m as s,T as t,b as u};
//# sourceMappingURL=parsePatchFiles-Dx-HvB-f.js.map