@openclaw/diffs 2026.7.2-beta.7 → 2026.8.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -222,7 +222,7 @@ diff --git a/src/example.ts b/src/example.ts
222
222
  - The viewer is hosted locally through the gateway under `/plugins/diffs/...`.
223
223
  - Viewer HTML and metadata are ephemeral SQLite plugin blobs. The URL token is returned to the caller while SQLite stores only its SHA-256 hash.
224
224
  - Rendered PNG/PDF files remain temporary materializations in `$TMPDIR/openclaw-diffs` because delivery APIs require a file path. No JSON metadata sidecars are written or imported.
225
- - Default viewer URLs use loopback (`127.0.0.1`) unless you set plugin `viewerBaseUrl`, pass `baseUrl`, or use `gateway.bind=custom` + `gateway.customBindHost`.
225
+ - Default viewer URLs use `gateway.publicOrigin` when configured, then the existing bind-aware Gateway fallback. Plugin `viewerBaseUrl` and per-call `baseUrl` take precedence.
226
226
  - If `gateway.trustedProxies` includes loopback for a same-host proxy (for example Tailscale Serve), raw `127.0.0.1` viewer requests without forwarded client-IP headers fail closed by design.
227
227
  - In that topology, prefer `mode=file` / `mode=both` for attachments, or intentionally enable remote viewers and set plugin `viewerBaseUrl` (or pass a proxy/public `baseUrl`) when you need a shareable viewer URL.
228
228
  - Remote viewer misses are throttled to reduce token-guess abuse.
@@ -1551,7 +1551,7 @@ ${t}`,A=e.startsWith(t)?0:zp(e,n,0);if(A===-1)return[e];let o=[];A>0&&o.push(e.s
1551
1551
  `}function Ls(e,t,n,A,o,r,a){if(typeof a=="function"&&(a={callback:a}),a?.callback){let{callback:s}=a;Ss(e,t,n,A,o,r,Object.assign(Object.assign({},a),{callback:i=>{s(i?OA(i,a.headerOptions):void 0)}}))}else{let s=Ss(e,t,n,A,o,r,a);return s?OA(s,a?.headerOptions):void 0}}function qE(e){let t=e.endsWith(`
1552
1552
  `),n=e.split(`
1553
1553
  `).map(A=>A+`
1554
- `);return t?n.pop():n.push(n.pop().slice(0,-1)),n}function Rs(e,t,n,A=!1){let o=Vp(Ls(e.name,t.name,e.contents,t.contents,e.header,t.header,n),{cacheKey:(()=>{if(e.cacheKey!=null&&t.cacheKey!=null)return`${e.cacheKey}:${t.cacheKey}`})(),oldFile:e,newFile:t,throwOnError:A});if(o==null)throw new Error("parseDiffFrom: FileInvalid diff -- probably need to fix something -- if the files are the same maybe?");return t.lang!=null&&(o.lang=t.lang),o}var Al=class{constructor(){f(this,"isDeletionsScrolling",!1);f(this,"isAdditionsScrolling",!1);f(this,"timeoutId",-1);f(this,"codeDeletions");f(this,"codeAdditions");f(this,"enabled",!1);f(this,"handleDeletionsScroll",()=>{this.isAdditionsScrolling||(this.isDeletionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isDeletionsScrolling=!1},300),this.codeAdditions?.scrollTo({left:this.codeDeletions?.scrollLeft}))});f(this,"handleAdditionsScroll",()=>{this.isDeletionsScrolling||(this.isAdditionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isAdditionsScrolling=!1},300),this.codeDeletions?.scrollTo({left:this.codeAdditions?.scrollLeft}))})}cleanUp(){this.enabled&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),clearTimeout(this.timeoutId),this.codeDeletions=void 0,this.codeAdditions=void 0,this.enabled=!1)}setup(e,t,n){if(t==null||n==null)for(let A of e.children??[])A instanceof HTMLElement&&("deletions"in A.dataset?t=A:"additions"in A.dataset&&(n=A));if(n==null||t==null){this.cleanUp();return}this.codeDeletions!==t&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeDeletions=t,t.addEventListener("scroll",this.handleDeletionsScroll,{passive:!0})),this.codeAdditions!==n&&(this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),this.codeAdditions=n,n.addEventListener("scroll",this.handleAdditionsScroll,{passive:!0})),this.enabled=!0}};function Ht(e,t){return Sn(e.theme,t.theme)&&e.useTokenTransformer===t.useTokenTransformer&&e.tokenizeMaxLineLength===t.tokenizeMaxLineLength&&e.lineDiffType===t.lineDiffType&&e.maxLineDiffLength===t.maxLineDiffLength}function kn(e){return M({tagName:"div",properties:{"data-content-buffer":"","data-buffer-size":e,style:`grid-row: span ${e};min-height:calc(${e} * 1lh)`}})}function In(e){return M({tagName:"div",children:[M({tagName:"span",children:[ae("No newline at end of file")]})],properties:{"data-no-newline":"","data-line-type":e,"data-column-content":""}})}function Ns(e){return M({tagName:"div",children:[at({name:e==="both"?"diffs-icon-expand-all":"diffs-icon-expand",properties:{"data-icon":""}})],properties:{role:"button","data-expand-button":"","data-expand-both":e==="both"?"":void 0,"data-expand-up":e==="up"?"":void 0,"data-expand-down":e==="down"?"":void 0}})}function wt({type:e,content:t,expandIndex:n,chunked:A=!1,slotName:o,isFirstHunk:r,isLastHunk:a}){let s=0,i=[];if(e==="metadata"&&t!=null&&i.push(M({tagName:"div",children:[ae(t)],properties:{"data-separator-wrapper":""}})),(e==="line-info"||e==="line-info-basic")&&t!=null){let c=[];n!=null&&(A?(r||(c.push(Ns("up")),s++),a||(c.push(Ns("down")),s++)):(c.push(Ns(!r&&!a?"both":r?"down":"up")),s++)),c.push(M({tagName:"div",children:[M({tagName:"span",children:[ae(t)],properties:{"data-unmodified-lines":""}})],properties:{"data-separator-content":""}})),A&&n!=null&&c.push(M({tagName:"div",children:[ae("Expand all")],properties:{role:"button","data-expand-button":"","data-expand-all-button":""}})),i.push(M({tagName:"div",children:c,properties:{"data-separator-wrapper":"","data-separator-multi-button":s>1?"":void 0}}))}return e==="custom"&&o!=null&&i.push(M({tagName:"slot",properties:{name:o}})),M({tagName:"div",children:i,properties:{"data-separator":i.length===0?"simple":e,"data-expand-index":n,"data-separator-first":r?"":void 0,"data-separator-last":a?"":void 0}})}function ol(e,t){return`hunk-separator-${e}-${t}`}function rl(e){let t=e.at(-1);return t==null?0:Math.max(t.additionStart+t.additionCount,t.deletionStart+t.deletionCount)}function al(e){return e.startingLine===0&&e.totalLines===1/0&&e.bufferBefore===0&&e.bufferAfter===0}function Gs({line:e,spanStart:t,spanLength:n}){return{start:{line:e,character:t},end:{line:e,character:t+n},properties:{"data-diff-span":""},alwaysWrap:!0}}function _n({item:e,arr:t,enableJoin:n,isNeutral:A=!1,isLastItem:o=!1}){let r=t[t.length-1];if(r==null||o||!n){t.push([A?0:1,e.value]);return}let a=r[0]===0;if(A===a||A&&e.value.length===1&&!a){r[1]+=e.value;return}t.push([A?0:1,e.value])}function Hs({isPartial:e,rangeSize:t,expandedHunks:n,hunkIndex:A,collapsedContextThreshold:o}){let r=Math.max(t,0);if(r===0||e)return{fromStart:0,fromEnd:0,rangeSize:r,collapsedLines:r,renderAll:!1};if(n===!0||r<=o)return{fromStart:r,fromEnd:0,rangeSize:r,collapsedLines:0,renderAll:!0};let a=n?.get(A),s=Math.min(Math.max(a?.fromStart??0,0),r),i=Math.min(Math.max(a?.fromEnd??0,0),r),c=s+i,d=c>=r;return{fromStart:d?r:s,fromEnd:d?0:i,rangeSize:r,collapsedLines:Math.max(r-c,0),renderAll:d}}function js({fileDiff:e,errorPrefix:t}){let n=e.hunks[e.hunks.length-1];if(n==null||e.isPartial||e.additionLines.length===0||e.deletionLines.length===0)return 0;let A=e.additionLines.length-(n.additionLineIndex+n.additionCount),o=e.deletionLines.length-(n.deletionLineIndex+n.deletionCount);if(A<=0&&o<=0)return 0;if(A!==o)throw new Error(`${t}: trailing context mismatch (additions=${A}, deletions=${o}) for ${e.name}`);return Math.min(A,o)}function Us({fileDiff:e,hunkIndex:t,expandedHunks:n,collapsedContextThreshold:A,errorPrefix:o}){if(t!==e.hunks.length-1)return;let r=js({fileDiff:e,errorPrefix:o});if(r<=0)return;if(n===!0||r<=A)return{fromStart:r,fromEnd:0,rangeSize:r,collapsedLines:0,renderAll:!0};let a=n?.get(e.hunks.length),s=Math.min(Math.max(a?.fromStart??0,0),r);return{fromStart:s,fromEnd:0,rangeSize:r,collapsedLines:r-s,renderAll:s>=r}}function WA({diff:e,diffStyle:t,startingLine:n=0,totalLines:A=1/0,expandedHunks:o,collapsedContextThreshold:r=1,callback:a}){let s=YE({diff:e,diffStyle:t,startingLine:n,expandedHunks:o,collapsedContextThreshold:r}),i={viewportStart:n,viewportEnd:n+A,isWindowedHighlight:n>0||A<1/0,splitCount:s.splitCount,unifiedCount:s.unifiedCount,finalHunkIndex:e.hunks.length-1,shouldBreak(){if(!i.isWindowedHighlight)return!1;let c=i.unifiedCount>=n+A,d=i.splitCount>=n+A;return t==="unified"?c:(t==="split"||c)&&d},shouldSkip(c,d){if(!i.isWindowedHighlight)return!1;let u=i.unifiedCount+c<n,g=i.splitCount+d<n;return t==="unified"?u:(t==="split"||u)&&g},incrementCounts(c,d){(t==="unified"||t==="both")&&(i.unifiedCount+=c),(t==="split"||t==="both")&&(i.splitCount+=d)},isInWindow(c,d){if(!i.isWindowedHighlight)return!0;let u=i.isInUnifiedWindow(c),g=i.isInSplitWindow(d);return t==="unified"?u:t==="split"?g:u||g},isInUnifiedWindow(c){return!i.isWindowedHighlight||i.unifiedCount>=n-c&&i.unifiedCount<n+A},isInSplitWindow(c){return!i.isWindowedHighlight||i.splitCount>=n-c&&i.splitCount<n+A},emit(c,d=!1){return d||(t==="unified"?i.incrementCounts(1,0):t==="split"?i.incrementCounts(0,1):i.incrementCounts(1,1)),a(c)??!1}};e:for(let c=s.hunkIndex;c<e.hunks.length;c++){let l=function(_,D){return g==null||g.collapsedLines<=0||g.fromStart+g.fromEnd>0?0:t==="unified"?_===d.unifiedLineStart+d.unifiedLineCount-1?g.collapsedLines:0:D===d.splitLineStart+d.splitLineCount-1?g.collapsedLines:0},C=function(){return h?0:(h=!0,u.collapsedLines)},d=e.hunks[c];if(d==null)throw new Error("iterateOverDiff: invalid hunk index");if(i.shouldBreak())break;let u=Hs({isPartial:e.isPartial,rangeSize:d.collapsedBefore,expandedHunks:o,hunkIndex:c,collapsedContextThreshold:r}),g=c===i.finalHunkIndex?Us({fileDiff:e,hunkIndex:c,expandedHunks:o,collapsedContextThreshold:r,errorPrefix:"iterateOverDiff"}):void 0,p=u.fromStart+u.fromEnd,h=u.collapsedLines===0;if(i.shouldSkip(p,p))i.incrementCounts(p,p),C();else{let _=d.unifiedLineStart-u.rangeSize,D=d.splitLineStart-u.rangeSize,L=d.deletionLineIndex-u.rangeSize,R=d.additionLineIndex-u.rangeSize,x=d.deletionStart-u.rangeSize,v=d.additionStart-u.rangeSize;if(JA(i,u.fromStart,t,G=>i.emit({hunkIndex:c,hunk:d,collapsedBefore:0,collapsedAfter:0,type:"context-expanded",deletionLine:{lineNumber:x+G,lineIndex:L+G,noEOFCR:!1,unifiedLineIndex:_+G,splitLineIndex:D+G},additionLine:{unifiedLineIndex:_+G,splitLineIndex:D+G,lineIndex:R+G,lineNumber:v+G,noEOFCR:!1}}))||(_=d.unifiedLineStart-u.fromEnd,D=d.splitLineStart-u.fromEnd,L=d.deletionLineIndex-u.fromEnd,R=d.additionLineIndex-u.fromEnd,x=d.deletionStart-u.fromEnd,v=d.additionStart-u.fromEnd,JA(i,u.fromEnd,t,G=>i.emit({hunkIndex:c,hunk:d,collapsedBefore:C(),collapsedAfter:0,type:"context-expanded",deletionLine:{lineNumber:x+G,lineIndex:L+G,noEOFCR:!1,unifiedLineIndex:_+G,splitLineIndex:D+G},additionLine:{unifiedLineIndex:_+G,splitLineIndex:D+G,lineIndex:R+G,lineNumber:v+G,noEOFCR:!1}}),()=>{C()})))break e}let b=d.unifiedLineStart,m=d.splitLineStart,B=d.deletionLineIndex,E=d.additionLineIndex,Q=d.deletionStart,k=d.additionStart,F=d.hunkContent.at(-1);for(let _ of d.hunkContent){if(i.shouldBreak())break e;let D=_===F;if(_.type==="context"){if(i.shouldSkip(_.lines,_.lines))i.incrementCounts(_.lines,_.lines),C();else if(JA(i,_.lines,t,L=>{let R=D&&L===_.lines-1,x=b+L,v=m+L;return i.emit({hunkIndex:c,hunk:d,collapsedBefore:C(),collapsedAfter:l(x,v),type:"context",deletionLine:{lineNumber:Q+L,lineIndex:B+L,noEOFCR:R&&d.noEOFCRDeletions,unifiedLineIndex:x,splitLineIndex:v},additionLine:{unifiedLineIndex:x,splitLineIndex:v,lineIndex:E+L,lineNumber:k+L,noEOFCR:R&&d.noEOFCRAdditions}})},()=>{C()}))break e;b+=_.lines,m+=_.lines,B+=_.lines,E+=_.lines,Q+=_.lines,k+=_.lines}else{let L=Math.max(_.deletions,_.additions),R=_.deletions+_.additions;if(!i.shouldSkip(R,L)){let x=OE(i,_,t);(x[0]?.[0]??0)>0&&C();for(let[v,G]of x)for(let $=v;$<G;$++){let ce=l(b+$,t==="unified"?m+($<_.deletions?$:$-_.deletions):m+$);if(i.emit(JE({hunkIndex:c,hunk:d,collapsedBefore:C(),collapsedAfter:ce,diffStyle:t,index:$,unifiedLineIndex:b,splitLineIndex:m,additionLineIndex:E,deletionLineIndex:B,additionLineNumber:k,deletionLineNumber:Q,content:_,isLastContent:D,unifiedCount:R,splitCount:L}),!0))break e}}C(),i.incrementCounts(R,L),b+=R,m+=L,B+=_.deletions,E+=_.additions,Q+=_.deletions,k+=_.additions}}if(g!=null){let{collapsedLines:_,fromStart:D,fromEnd:L}=g,R=D+L;if(JA(i,R,t,x=>{let v=x===R-1;return i.emit({hunkIndex:e.hunks.length,hunk:void 0,collapsedBefore:0,collapsedAfter:v?_:0,type:"context-expanded",deletionLine:{lineNumber:Q+x,lineIndex:B+x,noEOFCR:!1,unifiedLineIndex:b+x,splitLineIndex:m+x},additionLine:{unifiedLineIndex:b+x,splitLineIndex:m+x,lineIndex:E+x,lineNumber:k+x,noEOFCR:!1}})},void 0,()=>i.shouldBreak()))break e}}}function YE({diff:e,diffStyle:t,startingLine:n,expandedHunks:A,collapsedContextThreshold:o}){if(n<=0||t==="both")return{hunkIndex:0,splitCount:0,unifiedCount:0};let r=TE({diff:e,expandedHunks:A,collapsedContextThreshold:o}),a=0,s=e.hunks.length-1,i=e.hunks.length;for(;a<=s;){let d=a+s>>1,u=r[d+1];if(u==null)throw new Error("iterateOverDiff: invalid hunk prefix index");(t==="unified"?u.unifiedCount:u.splitCount)>n?(i=d,s=d-1):a=d+1}if(i>=e.hunks.length){let d=r[e.hunks.length];if(d==null)throw new Error("iterateOverDiff: invalid terminal hunk prefix index");return{hunkIndex:e.hunks.length,splitCount:d.splitCount,unifiedCount:d.unifiedCount}}let c=r[i];if(c==null)throw new Error("iterateOverDiff: invalid selected hunk prefix index");return{hunkIndex:i,splitCount:c.splitCount,unifiedCount:c.unifiedCount}}function TE({diff:e,expandedHunks:t,collapsedContextThreshold:n}){let A=0,o=0,r=e.hunks.length-1,a=[{splitCount:0,unifiedCount:0}];for(let s=0;s<e.hunks.length;s++){let i=e.hunks[s];if(i==null)throw new Error("iterateOverDiff: invalid hunk summary index");let c=Hs({isPartial:e.isPartial,rangeSize:i.collapsedBefore,expandedHunks:t,hunkIndex:s,collapsedContextThreshold:n}),d=c.fromStart+c.fromEnd;A+=d+i.splitLineCount,o+=d+i.unifiedLineCount;let u=s===r?Us({fileDiff:e,hunkIndex:s,expandedHunks:t,collapsedContextThreshold:n,errorPrefix:"iterateOverDiff"}):void 0;if(u!=null){let g=u.fromStart+u.fromEnd;A+=g,o+=g}a.push({splitCount:A,unifiedCount:o})}return a}function KE(e,t,n){if(!e.isWindowedHighlight||t<=0)return[0,t];let A=[];function o(s){let i=Math.max(0,e.viewportStart-s),c=Math.min(t,e.viewportEnd-s);c>i&&A.push([i,c])}if(n!=="split"&&o(e.unifiedCount),n!=="unified"&&o(e.splitCount),A.length===0)return[0,0];let r=A[0][0],a=A[0][1];for(let s=1;s<A.length;s++){let i=A[s];r=Math.min(r,i[0]),a=Math.max(a,i[1])}return[r,a]}function JA(e,t,n,A,o,r){let[a,s]=KE(e,t,n);a>0&&(e.incrementCounts(a,a),o?.());let i=a;for(;i<t;){if(r?.()===!0)return!0;if(i>=s){e.incrementCounts(t-i,t-i);break}if(e.isInWindow(0,0)){if(A(i)===!0)return!0}else e.incrementCounts(1,1);i++}return!1}function OE(e,t,n){if(!e.isWindowedHighlight)return[[0,n==="unified"?t.deletions+t.additions:Math.max(t.deletions,t.additions)]];let A=n!=="split",o=n!=="unified",r=n==="unified"?"unified":"split",a=[];function s(u,g){if(u+g<=e.viewportStart||u>=e.viewportEnd)return;let p=Math.max(0,e.viewportStart-u),l=Math.min(g,e.viewportEnd-u);return l>p?[p,l]:void 0}function i(u,g){return r==="split"?u:g==="additions"?[u[0]+t.deletions,u[1]+t.deletions]:u}function c(u,g){if(u==null)return;let[p,l]=i(u,g);l>p&&a.push([p,l])}if(A&&(c(s(e.unifiedCount,t.deletions),"deletions"),c(s(e.unifiedCount+t.deletions,t.additions),"additions")),o&&(c(s(e.splitCount,t.deletions),"deletions"),c(s(e.splitCount,t.additions),"additions")),a.length===0)return a;a.sort((u,g)=>u[0]-g[0]);let d=[a[0]];for(let[u,g]of a.slice(1)){let p=d[d.length-1];u<=p[1]?p[1]=Math.max(p[1],g):d.push([u,g])}return d}function JE({hunkIndex:e,hunk:t,collapsedAfter:n,collapsedBefore:A,diffStyle:o,index:r,unifiedLineIndex:a,splitLineIndex:s,additionLineIndex:i,deletionLineIndex:c,additionLineNumber:d,deletionLineNumber:u,content:g,isLastContent:p,unifiedCount:l,splitCount:h}){let C=r<g.deletions?a+r:void 0,b=o==="unified"?r>=g.deletions?a+r:void 0:r<g.additions?a+g.deletions+r:void 0,m=o==="unified"?s+(r<g.deletions?r:r-g.deletions):s+r,B=r<g.deletions?c+r:void 0,E=r<g.deletions?u+r:void 0,Q=o==="unified"?r>=g.deletions?i+(r-g.deletions):void 0:r<g.additions?i+r:void 0,k=o==="unified"?r>=g.deletions?d+(r-g.deletions):void 0:r<g.additions?d+r:void 0,F=o==="unified"?p&&r===g.deletions-1&&t.noEOFCRDeletions:p&&r===h-1&&t.noEOFCRDeletions,_=o==="unified"?p&&r===l-1&&t.noEOFCRAdditions:p&&r===h-1&&t.noEOFCRAdditions,D=B!=null&&E!=null&&C!=null?{lineNumber:E,lineIndex:B,noEOFCR:F,unifiedLineIndex:C,splitLineIndex:m}:void 0,L=Q!=null&&k!=null&&b!=null?{unifiedLineIndex:b,splitLineIndex:m,lineIndex:Q,lineNumber:k,noEOFCR:_}:void 0;if(D==null&&L!=null)return{type:"change",hunkIndex:e,hunk:t,collapsedAfter:n,collapsedBefore:A,deletionLine:void 0,additionLine:L};if(D!=null&&L==null)return{type:"change",hunkIndex:e,hunk:t,collapsedAfter:n,collapsedBefore:A,deletionLine:D,additionLine:void 0};if(D==null||L==null)throw new Error("iterateOverDiff: missing change line data");return{type:"change",hunkIndex:e,hunk:t,collapsedAfter:n,collapsedBefore:A,deletionLine:D,additionLine:L}}var WE={forcePlainText:!1};function il(e,t,n,{forcePlainText:A,startingLine:o,totalLines:r,expandedHunks:a,collapsedContextThreshold:s=1}=WE){A?(o??(o=0),r??(r=1/0)):(o=0,r=1/0);let i=o>0||r<1/0,c=typeof n.theme=="string"?t.getTheme(n.theme).type:void 0,d=vp({theme:n.theme,highlighter:t}),u=A&&!i&&(e.unifiedLineCount>1e3||e.splitLineCount>1e3)?"none":n.lineDiffType,g={deletionLines:[],additionLines:[]},{maxLineDiffLength:p}=n,l=!A&&!e.isPartial,h=A?a:void 0,C=new Map;function b(B){let E=l?0:B,Q=C.get(E)??ZE();return C.set(E,Q),Q}function m(B,E,Q,k){if(i){let F=Q.at(-1);(F==null||F.targetIndex+F.count!==E)&&(F={targetIndex:E,originalOffset:k.length,count:0},Q.push(F)),F.count++}k.push(B)}WA({diff:e,diffStyle:"both",startingLine:o,totalLines:r,expandedHunks:i?h:!0,collapsedContextThreshold:s,callback:({hunkIndex:B,additionLine:E,deletionLine:Q,type:k})=>{let F=b(B),_=E!=null?E.splitLineIndex:Q.splitLineIndex;k==="change"&&E!=null&&Q!=null&&zE({additionLine:e.additionLines[E.lineIndex],deletionLine:e.deletionLines[Q.lineIndex],deletionLineIndex:F.deletionContent.length,additionLineIndex:F.additionContent.length,deletionDecorations:F.deletionDecorations,additionDecorations:F.additionDecorations,lineDiffType:u,maxLineDiffLength:p}),Q!=null&&(m(e.deletionLines[Q.lineIndex],Q.lineIndex,F.deletionSegments,F.deletionContent),F.deletionInfo.push({type:k==="change"?"change-deletion":k,lineNumber:Q.lineNumber,altLineNumber:k==="change"?void 0:E.lineNumber??void 0,lineIndex:`${Q.unifiedLineIndex},${_}`})),E!=null&&(m(e.additionLines[E.lineIndex],E.lineIndex,F.additionSegments,F.additionContent),F.additionInfo.push({type:k==="change"?"change-addition":k,lineNumber:E.lineNumber,altLineNumber:k==="change"?void 0:Q.lineNumber??void 0,lineIndex:`${E.unifiedLineIndex},${_}`}))}});for(let B of C.values()){if(B.deletionContent.length===0&&B.additionContent.length===0)continue;let E={name:e.prevName??e.name,contents:B.deletionContent.value},Q={name:e.name,contents:B.additionContent.value},{deletionLines:k,additionLines:F}=VE({deletionFile:E,deletionInfo:B.deletionInfo,deletionDecorations:B.deletionDecorations,additionFile:Q,additionInfo:B.additionInfo,additionDecorations:B.additionDecorations,highlighter:t,options:n,languageOverride:A?"text":e.lang});if(l){g.deletionLines=k,g.additionLines=F;continue}if(B.deletionSegments.length>0)for(let _ of B.deletionSegments)for(let D=0;D<_.count;D++)g.deletionLines[_.targetIndex+D]=k[_.originalOffset+D];else g.deletionLines.push(...k);if(B.additionSegments.length>0)for(let _ of B.additionSegments)for(let D=0;D<_.count;D++)g.additionLines[_.targetIndex+D]=F[_.originalOffset+D];else g.additionLines.push(...F)}return{code:g,themeStyles:d,baseThemeType:c}}function zE({deletionLine:e,additionLine:t,deletionLineIndex:n,additionLineIndex:A,deletionDecorations:o,additionDecorations:r,lineDiffType:a,maxLineDiffLength:s}){if(e==null||t==null||a==="none"||(e=At(e),t=At(t),e.length>s||t.length>s))return;let i=a==="char"?ys(e,t):Fs(e,t),c=[],d=[],u=a==="word-alt",g=i.at(-1);for(let l of i){let h=l===g;!l.added&&!l.removed?(_n({item:l,arr:c,enableJoin:u,isNeutral:!0,isLastItem:h}),_n({item:l,arr:d,enableJoin:u,isNeutral:!0,isLastItem:h})):l.removed?_n({item:l,arr:c,enableJoin:u,isLastItem:h}):_n({item:l,arr:d,enableJoin:u,isLastItem:h})}let p=0;for(let l of c)l[0]===1&&o.push(Gs({line:n,spanStart:p,spanLength:l[1].length})),p+=l[1].length;p=0;for(let l of d)l[0]===1&&r.push(Gs({line:A,spanStart:p,spanLength:l[1].length})),p+=l[1].length}function ZE(){return{deletionContent:{push(e){this.value+=e,this.length++},value:"",length:0},additionContent:{push(e){this.value+=e,this.length++},value:"",length:0},deletionInfo:[],additionInfo:[],deletionDecorations:[],additionDecorations:[],deletionSegments:[],additionSegments:[]}}function VE({deletionFile:e,additionFile:t,deletionInfo:n,additionInfo:A,highlighter:o,deletionDecorations:r,additionDecorations:a,languageOverride:s,options:{theme:i=oe,...c}}){let d=s??De(e.name),u=s??De(t.name),{state:g,transformers:p}=_p(c.useTokenTransformer),l=typeof i=="string"?{...c,lang:"text",theme:i,transformers:p,decorations:void 0,defaultColor:!1,cssVariablePrefix:ge("token"),tokenizeTimeLimit:0}:{...c,lang:"text",themes:i,transformers:p,decorations:void 0,defaultColor:!1,cssVariablePrefix:ge("token"),tokenizeTimeLimit:0};return{deletionLines:e.contents===""?[]:(l.lang=d,g.lineInfo=n,l.decorations=r,ls(o.codeToHast(At(e.contents),l))),additionLines:t.contents===""?[]:(l.lang=u,l.decorations=a,g.lineInfo=A,ls(o.codeToHast(At(t.contents),l)))}}function Dn(e){let t=e.lang??De(e.name),n=e.lang??(e.prevName!=null?De(e.prevName):"text");return t==="text"&&n==="text"}var XE=-1,gl=class{constructor(e={theme:oe},t,n){f(this,"options");f(this,"onRenderUpdate");f(this,"workerManager");f(this,"__id",`diff-hunks-renderer:${++XE}`);f(this,"highlighter");f(this,"diff");f(this,"expandedHunks",new Map);f(this,"deletionAnnotations",{});f(this,"additionAnnotations",{});f(this,"computedLang","text");f(this,"renderCache");f(this,"createAnnotationElement",e=>hp(e));this.options=e,this.onRenderUpdate=t,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=NA(e.theme??oe)?rs():void 0)}cleanUp(){this.recycle(),this.expandedHunks.clear(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.highlighter=void 0,this.diff=void 0,this.clearRenderCache(),this.additionAnnotations={},this.deletionAnnotations={},this.workerManager?.cleanUpTasks(this)}clearRenderCache(){this.renderCache=void 0}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}expandHunk(e,t,n=this.getOptionsWithDefaults().expansionLineCount){let A={...this.expandedHunks.get(e)??{fromStart:0,fromEnd:0}};(t==="up"||t==="both")&&(A.fromStart+=n),(t==="down"||t==="both")&&(A.fromEnd+=n),this.renderCache?.highlighted!==!0&&this.clearRenderCache(),this.expandedHunks.set(e,A)}getExpandedHunk(e){return this.expandedHunks.get(e)??cc}getExpandedHunksMap(){return this.expandedHunks}setLineAnnotations(e){this.additionAnnotations={},this.deletionAnnotations={};for(let t of e){let n=(()=>{switch(t.side){case"deletions":return this.deletionAnnotations;case"additions":return this.additionAnnotations}})(),A=n[t.lineNumber]??[];n[t.lineNumber]=A,A.push(t)}}getUnifiedLineDecoration({lineType:e}){return{gutterLineType:e}}getSplitLineDecoration({side:e,type:t}){return t!=="change"?{gutterLineType:t}:{gutterLineType:e==="deletions"?"change-deletion":"change-addition"}}getOptionsWithDefaults(){let{diffIndicators:e="bars",diffStyle:t="split",disableBackground:n=!1,disableFileHeader:A=!1,disableLineNumbers:o=!1,disableVirtualizationBuffers:r=!1,collapsed:a=!1,expandUnchanged:s=!1,collapsedContextThreshold:i=1,expansionLineCount:c=100,hunkSeparators:d="line-info",lineDiffType:u="word-alt",maxLineDiffLength:g=1e3,overflow:p="scroll",stickyHeader:l=!1,theme:h=oe,headerRenderMode:C="default",tokenizeMaxLineLength:b=1e3,tokenizeMaxLength:m=sc,useTokenTransformer:B=!1,useCSSClasses:E=!1}=this.options;return{diffIndicators:e,diffStyle:t,disableBackground:n,disableFileHeader:A,disableLineNumbers:o,disableVirtualizationBuffers:r,collapsed:a,expandUnchanged:s,collapsedContextThreshold:i,expansionLineCount:c,hunkSeparators:d,lineDiffType:u,maxLineDiffLength:g,overflow:p,stickyHeader:l,theme:this.workerManager?.getDiffRenderOptions().theme??h,headerRenderMode:C,tokenizeMaxLineLength:b,tokenizeMaxLength:m,useTokenTransformer:B,useCSSClasses:E}}async initializeHighlighter(){return this.highlighter=await LA(wp(this.computedLang,this.options)),this.highlighter}hydrate(e){if(e==null)return;this.diff=e;let{options:t}=this.getRenderOptions(e),n=$s(e,this.getTokenizeMaxLength()),A=this.workerManager?.getDiffResultCache(e);A!=null&&!Ht(t,A.options)&&(A=void 0),this.renderCache??(this.renderCache={diff:e,highlighted:!n&&!Dn(e),options:t,result:n?void 0:A?.result,renderRange:void 0}),this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!n&&this.workerManager.highlightDiffAST(this,this.diff):this.highlighter==null&&(this.computedLang=e.lang??De(e.name),this.initializeHighlighter())}getRenderOptions(e){let t=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getDiffRenderOptions();let{theme:A,tokenizeMaxLineLength:o,lineDiffType:r,maxLineDiffLength:a}=this.getOptionsWithDefaults();return{theme:A,useTokenTransformer:Sp(this.options),tokenizeMaxLineLength:o,lineDiffType:r,maxLineDiffLength:a}})();this.getOptionsWithDefaults();let{renderCache:n}=this;return n?.result==null?{options:t,forceHighlight:!0}:!wn(e,n.diff)||!Ht(t,n.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}renderDiff(e=this.renderCache?.diff,t=io){if(e==null)return;let{expandUnchanged:n=!1,collapsedContextThreshold:A}=this.getOptionsWithDefaults(),{options:o,forceHighlight:r}=this.getRenderOptions(e),a=this.getMatchingWorkerResultCache(e,o);a!=null&&!this.hasHighlightedRenderCache(e,o)&&(this.renderCache={diff:e,highlighted:!0,renderRange:void 0,...a},r=!1),this.renderCache??(this.renderCache={diff:e,highlighted:!1,options:o,result:void 0,renderRange:void 0});let s=e.additionLines.length>0||e.deletionLines.length>0,i=!s||Dn(e)||$s(e,this.getTokenizeMaxLength()),c=!wn(e,this.renderCache.diff),d=!GA(this.renderCache.renderRange,t);if(this.workerManager?.isWorkingPool()===!0)(i||this.renderCache.result==null||!this.renderCache.highlighted&&(c||d))&&(this.renderCache.diff=e,this.renderCache.options=o,this.renderCache.highlighted=!1,(this.renderCache.result==null||c||d||r)&&(this.renderCache.result=this.workerManager.getPlainDiffAST(e,t.startingLine,t.totalLines,al(t)||n?!0:this.expandedHunks,A)),this.renderCache.renderRange=t),!i&&s&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightDiffAST(this,e);else{this.computedLang=e.lang??De(e.name);let u=this.highlighter!=null&&NA(o.theme),g=this.highlighter!=null&&wo(this.computedLang),p=!i&&g;if(this.highlighter!=null&&u&&(r||i||!this.renderCache.highlighted&&p||this.renderCache.result==null)){let{result:l,options:h}=this.renderDiffWithHighlighter(e,this.highlighter,i||!g);this.renderCache={diff:e,options:h,highlighted:p,result:l,renderRange:void 0}}(!u||!i&&!g)&&this.asyncHighlight(e).then(({result:l,options:h})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.onHighlightSuccess(e,l,h,!i)})}return this.renderCache.result!=null?this.processDiffResult(this.renderCache.diff,t,this.renderCache.result):void 0}async asyncRender(e,t=io){let{result:n}=await this.asyncHighlight(e);return this.processDiffResult(e,t,n)}createPreElement(e,t,n){let{diffIndicators:A,disableBackground:o,disableLineNumbers:r,overflow:a}=this.getOptionsWithDefaults();return yp({type:"diff",diffIndicators:A,disableBackground:o,disableLineNumbers:r,overflow:a,split:e,totalLines:t,customProperties:n})}async asyncHighlight(e){let t=$s(e,this.getTokenizeMaxLength());this.computedLang=t?"text":e.lang??De(e.name);let n=this.highlighter!=null&&NA(this.options.theme??oe),A=t||this.highlighter!=null&&wo(this.computedLang);return(this.highlighter==null||!n||!A)&&(this.highlighter=await this.initializeHighlighter()),this.renderDiffWithHighlighter(e,this.highlighter,t)}renderDiffWithHighlighter(e,t,n=!1){let{options:A}=this.getRenderOptions(e),{collapsedContextThreshold:o}=this.getOptionsWithDefaults();return{result:il(e,t,A,{forcePlainText:n,expandedHunks:n?!0:void 0,collapsedContextThreshold:o}),options:A}}onHighlightSuccess(e,t,n,A=!0){if(this.renderCache==null)return;let o=!this.renderCache.highlighted||!Ht(this.renderCache.options,n)||!wn(this.renderCache.diff,e);this.renderCache={diff:e,options:n,highlighted:A,result:t,renderRange:void 0},o&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){let n=this.workerManager?.getDiffResultCache(e);if(!(n==null||!Ht(t,n.options)))return n}hasHighlightedRenderCache(e,t){let{renderCache:n}=this;return n?.result!=null&&n.highlighted&&wn(e,n.diff)&&Ht(t,n.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}processDiffResult(e,t,{code:n,themeStyles:A,baseThemeType:o}){let{diffStyle:r,disableFileHeader:a,expandUnchanged:s,expansionLineCount:i,collapsedContextThreshold:c,hunkSeparators:d}=this.getOptionsWithDefaults();this.diff=e;let u=r==="unified",g=[],p=[],l=[],h=[],{additionLines:C,deletionLines:b}=n,m={rowCount:0,hunkSeparators:d,additionsContentAST:g,deletionsContentAST:p,unifiedContentAST:l,unifiedGutterAST:Pt(),deletionsGutterAST:Pt(),additionsGutterAST:Pt(),expansionLineCount:i,hunkData:h,incrementRowCount(v=1){m.rowCount+=v},pushToGutter(v,G){switch(v){case"unified":m.unifiedGutterAST.children.push(G);break;case"deletions":m.deletionsGutterAST.children.push(G);break;case"additions":m.additionsGutterAST.children.push(G);break}}},B=js({fileDiff:e,errorPrefix:"DiffHunksRenderer.processDiffResult"}),E={size:0,side:void 0,increment(){this.size+=1},flush(){if(r!=="unified"){if(this.size<=0||this.side==null){this.side=void 0,this.size=0;return}this.side==="additions"?(m.pushToGutter("additions",pe(void 0,"buffer",this.size)),g?.push(kn(this.size))):(m.pushToGutter("deletions",pe(void 0,"buffer",this.size)),p?.push(kn(this.size))),this.size=0,this.side=void 0}}},Q=(v,G,$,ce,P)=>{m.pushToGutter(v,gc(G,$,ce,P))};function k(v){E.flush(),r==="unified"?Ps("unified",v,m):(Ps("deletions",v,m),Ps("additions",v,m))}this.pushFileLevelAnnotations(e,r,t,m),WA({diff:e,diffStyle:r,startingLine:t.startingLine,totalLines:t.totalLines,expandedHunks:s?!0:this.expandedHunks,collapsedContextThreshold:c,callback:({hunkIndex:v,hunk:G,collapsedBefore:$,collapsedAfter:ce,additionLine:P,deletionLine:X,type:ee})=>{let Qt=X!=null?X.splitLineIndex:P.splitLineIndex,to=P!=null?P.unifiedLineIndex:X.unifiedLineIndex;r==="split"&&ee!=="change"&&E.flush(),$>0&&k({hunkIndex:v,collapsedLines:$,rangeSize:Math.max(G?.collapsedBefore??0,0),hunkSpecs:G?.hunkSpecs,isFirstHunk:v===0,isLastHunk:!1,isExpandable:!e.isPartial});let no=r==="unified"?to:Qt,Os={type:ee,hunkIndex:v,lineIndex:no,unifiedLineIndex:to,splitLineIndex:Qt,deletionLine:X,additionLine:P};if(r==="unified"){let O=this.getUnifiedInjectedRowsForLine?.(Os);O?.before!=null&&dl(O.before,m);let Be=X!=null?b[X.lineIndex]:void 0,he=P!=null?C[P.lineIndex]:void 0;if(Be==null&&he==null){let Ke="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(Ke,{file:e.name}),new Error(Ke)}let Ut=ee==="change"?P!=null?"change-addition":"change-deletion":ee,Te=this.getUnifiedLineDecoration({type:ee,lineType:Ut,additionLineIndex:P?.lineIndex,deletionLineIndex:X?.lineIndex});Q("unified",Te.gutterLineType,P!=null?P.lineNumber:X.lineNumber,`${to},${Qt}`,Te.gutterProperties),he!=null?he=ZA(he,Te.contentProperties):Be!=null&&(Be=ZA(Be,Te.contentProperties)),zA({diffStyle:"unified",type:ee,deletionLine:Be,additionLine:he,unifiedSpan:this.getAnnotations("unified",X?.lineNumber,P?.lineNumber,v,no),createAnnotationElement:Ke=>this.createAnnotationElement(Ke),context:m}),O?.after!=null&&dl(O.after,m)}else{let O=this.getSplitInjectedRowsForLine?.(Os);O?.before!=null&&ul(O.before,m,E);let Be=X!=null?b[X.lineIndex]:void 0,he=P!=null?C[P.lineIndex]:void 0,Ut=this.getSplitLineDecoration({side:"deletions",type:ee,lineIndex:X?.lineIndex}),Te=this.getSplitLineDecoration({side:"additions",type:ee,lineIndex:P?.lineIndex});if(Be==null&&he==null){let Qe="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(Qe,{file:e.name}),new Error(Qe)}let Ke=(()=>{if(ee==="change"){if(he==null)return"additions";if(Be==null)return"deletions"}})();if(Ke!=null){if(E.side!=null&&E.side!==Ke)throw new Error("DiffHunksRenderer.processDiffResult: iterateOverDiff, invalid pending splits");E.side=Ke,E.increment()}let Ws=this.getAnnotations("split",X?.lineNumber,P?.lineNumber,v,no);if(Ws!=null&&E.size>0&&E.flush(),X!=null){let Qe=ZA(Be,Ut.contentProperties);Q("deletions",Ut.gutterLineType,X.lineNumber,`${X.unifiedLineIndex},${Qt}`,Ut.gutterProperties),Qe!=null&&(Be=Qe)}if(P!=null){let Qe=ZA(he,Te.contentProperties);Q("additions",Te.gutterLineType,P.lineNumber,`${P.unifiedLineIndex},${Qt}`,Te.gutterProperties),Qe!=null&&(he=Qe)}zA({diffStyle:"split",type:ee,additionLine:he,deletionLine:Be,...Ws,createAnnotationElement:Qe=>this.createAnnotationElement(Qe),context:m}),O?.after!=null&&ul(O.after,m,E)}let Js=r==="split"&&G!=null&&Qt===G.splitLineStart+G.splitLineCount-1,_l=Js?G.noEOFCRDeletions:!1,Dl=Js?G.noEOFCRAdditions:!1,Ao=(X?.noEOFCR??!1)||_l,oo=(P?.noEOFCR??!1)||Dl;if(oo||Ao){if(r==="split"&&E.flush(),Ao){let O=ee==="context"||ee==="context-expanded"?ee:"change-deletion";r==="unified"?(m.unifiedContentAST.push(In(O)),m.pushToGutter("unified",pe(O,"metadata",1))):(m.deletionsContentAST.push(In(O)),m.pushToGutter("deletions",pe(O,"metadata",1)),oo||(m.pushToGutter("additions",pe(void 0,"buffer",1)),m.additionsContentAST.push(kn(1))))}if(oo){let O=ee==="context"||ee==="context-expanded"?ee:"change-addition";r==="unified"?(m.unifiedContentAST.push(In(O)),m.pushToGutter("unified",pe(O,"metadata",1))):(m.additionsContentAST.push(In(O)),m.pushToGutter("additions",pe(O,"metadata",1)),Ao||(m.pushToGutter("deletions",pe(void 0,"buffer",1)),m.deletionsContentAST.push(kn(1))))}m.incrementRowCount(1)}ce>0&&d!=="simple"&&k({hunkIndex:ee==="context-expanded"?v:v+1,collapsedLines:ce,rangeSize:B,hunkSpecs:void 0,isFirstHunk:!1,isLastHunk:!0,isExpandable:!e.isPartial}),m.incrementRowCount(1)}}),r==="split"&&E.flush();let F=Math.max(rl(e.hunks),e.additionLines.length??0,e.deletionLines.length??0),_=t.bufferBefore>0||t.bufferAfter>0,D=!u&&e.type!=="deleted",L=!u&&e.type!=="new",R=m.rowCount>0||_;g=D&&R?g:void 0,p=L&&R?p:void 0,l=u&&R?l:void 0;let x=this.createPreElement(p!=null&&g!=null,F);return{unifiedGutterAST:u&&R?m.unifiedGutterAST.children:void 0,unifiedContentAST:l,deletionsGutterAST:L&&R?m.deletionsGutterAST.children:void 0,deletionsContentAST:p,additionsGutterAST:D&&R?m.additionsGutterAST.children:void 0,additionsContentAST:g,hunkData:h,preNode:x,themeStyles:A,baseThemeType:o,headerElement:a?void 0:this.renderHeader(this.diff),totalLines:F,rowCount:m.rowCount,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:""}}renderCodeAST(e,t){let n=e==="unified"?t.unifiedGutterAST:e==="deletions"?t.deletionsGutterAST:t.additionsGutterAST,A=e==="unified"?t.unifiedContentAST:e==="deletions"?t.deletionsContentAST:t.additionsContentAST;if(n==null||A==null)return;let o=Pt(n);return o.properties.style=`grid-row: span ${t.rowCount}`,[o,Mp(A,t.rowCount)]}renderFullAST(e,t=[]){let n=this.getOptionsWithDefaults().hunkSeparators==="line-info",A=this.renderCodeAST("unified",e);if(A!=null)return t.push(M({tagName:"code",children:A,properties:{"data-code":"","data-container-size":n?"":void 0,"data-unified":""}})),{...e.preNode,children:t};let o=this.renderCodeAST("deletions",e);o!=null&&t.push(M({tagName:"code",children:o,properties:{"data-code":"","data-container-size":n?"":void 0,"data-deletions":""}}));let r=this.renderCodeAST("additions",e);return r!=null&&t.push(M({tagName:"code",children:r,properties:{"data-code":"","data-container-size":n?"":void 0,"data-additions":""}})),{...e.preNode,children:t}}renderFullHTML(e,t=[]){return Ee(this.renderFullAST(e,t))}renderPartialHTML(e,t){return t==null?Ee(e):Ee(M({tagName:"code",children:e,properties:{"data-code":"","data-container-size":this.getOptionsWithDefaults().hunkSeparators==="line-info"?"":void 0,[`data-${t}`]:""}}))}pushFileLevelAnnotations(e,t,n,A){if(!xp(n))return;let o=e.type!=="new"?sl(ms(this.deletionAnnotations)):[],r=e.type!=="deleted"?sl(ms(this.additionAnnotations)):[];if(o.length===0&&r.length===0)return;let a=-1,s=-1,{createAnnotationElement:i}=this;if(t==="unified"){zA({diffStyle:t,type:"context",unifiedSpan:{type:"annotation",hunkIndex:a,lineIndex:s,annotations:o.concat(r)},createAnnotationElement:i,context:A});return}zA({diffStyle:t,type:"context",deletionSpan:{type:"annotation",hunkIndex:a,lineIndex:s,annotations:o},additionSpan:{type:"annotation",hunkIndex:a,lineIndex:s,annotations:r},createAnnotationElement:i,context:A})}getAnnotations(e,t,n,A,o){let r={type:"annotation",hunkIndex:A,lineIndex:o,annotations:[]};if(t!=null)for(let s of this.deletionAnnotations[t]??[])r.annotations.push(Et(s));let a={type:"annotation",hunkIndex:A,lineIndex:o,annotations:[]};if(n!=null)for(let s of this.additionAnnotations[n]??[])(e==="unified"?r:a).annotations.push(Et(s));if(e==="unified")return r.annotations.length>0?r:void 0;if(!(a.annotations.length===0&&r.annotations.length===0))return{deletionSpan:r,additionSpan:a}}renderHeader(e){let{headerRenderMode:t,stickyHeader:n}=this.getOptionsWithDefaults();return Ep({fileOrDiff:e,mode:t,stickyHeader:n})}};function sl(e){return e?.map(t=>Et(t))??[]}var ey=new Intl.PluralRules("en-US");function cl(e){return`${e} unmodified line${ey.select(e)==="one"?"":"s"}`}function dl(e,t){for(let n of e)t.unifiedContentAST.push(n.content),t.pushToGutter("unified",n.gutter),t.incrementRowCount(1)}function ul(e,t,n){for(let{deletion:A,addition:o}of e){if(A==null&&o==null)continue;let r=A!=null&&o!=null?void 0:A==null?"deletions":"additions";(r==null||n.side!==r)&&n.flush(),A!=null&&(t.deletionsContentAST.push(A.content),t.pushToGutter("deletions",A.gutter)),o!=null&&(t.additionsContentAST.push(o.content),t.pushToGutter("additions",o.gutter)),r!=null&&(n.side=r,n.increment()),t.incrementRowCount(1)}}function zA({diffStyle:e,type:t,deletionLine:n,additionLine:A,unifiedSpan:o,deletionSpan:r,additionSpan:a,createAnnotationElement:s,context:i}){let c=!1;if(e==="unified"){if(A!=null?i.unifiedContentAST.push(A):n!=null&&i.unifiedContentAST.push(n),o!=null){let d=t==="change"?n!=null?"change-deletion":"change-addition":t;i.unifiedContentAST.push(s(o)),i.pushToGutter("unified",pe(d,"annotation",1)),c=!0}}else if(e==="split"){if(n!=null&&i.deletionsContentAST.push(n),A!=null&&i.additionsContentAST.push(A),r!=null){let d=t==="change"?n!=null?"change-deletion":"context":t;i.deletionsContentAST.push(s(r)),i.pushToGutter("deletions",pe(d,"annotation",1)),c=!0}if(a!=null){let d=t==="change"?A!=null?"change-addition":"context":t;i.additionsContentAST.push(s(a)),i.pushToGutter("additions",pe(d,"annotation",1)),c=!0}}c&&i.incrementRowCount(1)}function Ps(e,{hunkIndex:t,collapsedLines:n,rangeSize:A,hunkSpecs:o,isFirstHunk:r,isLastHunk:a,isExpandable:s},i){if(n<=0)return;let c=e==="unified"?i.unifiedContentAST:e==="deletions"?i.deletionsContentAST:i.additionsContentAST;if(i.hunkSeparators==="metadata"){o!=null&&(i.pushToGutter(e,wt({type:"metadata",content:o,isFirstHunk:r,isLastHunk:a})),c.push(wt({type:"metadata",content:o,isFirstHunk:r,isLastHunk:a})),e!=="additions"&&i.incrementRowCount(1));return}if(i.hunkSeparators==="simple"){t>0&&(i.pushToGutter(e,wt({type:"simple",isFirstHunk:r,isLastHunk:!1})),c.push(wt({type:"simple",isFirstHunk:r,isLastHunk:!1})),e!=="additions"&&i.incrementRowCount(1));return}let d=ol(e,t),u=A>i.expansionLineCount,g=s?t:void 0;i.pushToGutter(e,wt({type:i.hunkSeparators,content:cl(n),expandIndex:g,chunked:u,slotName:d,isFirstHunk:r,isLastHunk:a})),c.push(wt({type:i.hunkSeparators,content:cl(n),expandIndex:g,chunked:u,slotName:d,isFirstHunk:r,isLastHunk:a})),e!=="additions"&&i.incrementRowCount(1),i.hunkData.push({slotName:d,hunkIndex:t,lines:n,type:e,expandable:s?{up:!r,down:!a,chunked:u}:void 0})}function ZA(e,t){return e==null||e.type!=="element"||t==null?e:{...e,properties:{...e.properties,...t}}}function $s(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function pl(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function ll(e,t){return e.slotName===t.slotName&&e.hunkIndex===t.hunkIndex&&e.lines===t.lines&&e.type===t.type&&e.expandable?.chunked===t.expandable?.chunked&&e.expandable?.up===t.expandable?.up&&e.expandable?.down===t.expandable?.down}function ml(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:e?.useTokenTransformer,tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,diffStyle:e?.diffStyle,diffIndicators:e?.diffIndicators,disableBackground:e?.disableBackground,hunkSeparators:typeof e?.hunkSeparators=="function"?"custom":e?.hunkSeparators,expandUnchanged:e?.expandUnchanged,collapsedContextThreshold:e?.collapsedContextThreshold,lineDiffType:e?.lineDiffType,maxLineDiffLength:e?.maxLineDiffLength,expansionLineCount:e?.expansionLineCount,headerRenderMode:e?.renderCustomHeader!=null?"custom":"default"}}var ty=-1,qs,Ys=(qs=class{constructor(e={theme:oe},t,n=!1){f(this,"options");f(this,"workerManager");f(this,"isContainerManaged");f(this,"__id",`file-diff:${++ty}`);f(this,"type","file-diff");f(this,"fileContainer");f(this,"spriteSVG");f(this,"pre");f(this,"codeUnified");f(this,"codeDeletions");f(this,"codeAdditions");f(this,"bufferBefore");f(this,"bufferAfter");f(this,"themeCSSStyle");f(this,"appliedThemeCSS");f(this,"hasAdoptedThemeCSS",!1);f(this,"unsafeCSSStyle");f(this,"appliedUnsafeCSS");f(this,"gutterUtilityContent");f(this,"headerElement");f(this,"headerPrefix");f(this,"headerMetadata");f(this,"headerCustom");f(this,"separatorCache",new Map);f(this,"errorWrapper");f(this,"placeHolder");f(this,"hunksRenderer");f(this,"resizeManager");f(this,"scrollSyncManager");f(this,"interactionManager");f(this,"annotationCache",new Map);f(this,"lineAnnotations",[]);f(this,"managersDirty",!1);f(this,"deletionFile");f(this,"additionFile");f(this,"fileDiff");f(this,"renderRange");f(this,"appliedPreAttributes");f(this,"lastRenderedHeaderHTML");f(this,"cachedHeaderHTML");f(this,"lastRowCount");f(this,"mounted",!1);f(this,"enabled",!0);f(this,"handleHighlightRender",()=>{this.rerender()});f(this,"getLineIndex",(e,t="additions")=>{if(this.fileDiff==null)return;let n=this.fileDiff.hunks.at(-1),A,o;e:for(let r of this.fileDiff.hunks){let a=t==="deletions"?r.deletionStart:r.additionStart,s=t==="deletions"?r.deletionCount:r.additionCount,i=r.splitLineStart,c=r.unifiedLineStart;if(e<a){let d=a-e;A=Math.max(c-d,0),o=Math.max(i-d,0);break e}if(e>=a+s){if(r===n){let d=e-(a+s);A=c+r.unifiedLineCount+d,o=i+r.splitLineCount+d;break e}continue}for(let d of r.hunkContent)if(d.type==="context")if(e<a+d.lines){let u=e-a;o=i+u,A=c+u;break e}else a+=d.lines,i+=d.lines,c+=d.lines;else{let u=t==="deletions"?d.deletions:d.additions;if(e<a+u){let g=e-a;A=c+(t==="additions"?d.deletions:0)+g,o=i+g;break e}else a+=u,i+=Math.max(d.deletions,d.additions),c+=d.deletions+d.additions}break e}if(!(A==null||o==null))return[A,o]});f(this,"getHoveredLine",()=>this.interactionManager.getHoveredLine());f(this,"handleExpandHunk",(e,t,n)=>{this.expandHunk(e,t,n)});f(this,"expandHunk",(e,t,n)=>{this.hunksRenderer.expandHunk(e,t,n),this.rerender()});this.options=e,this.workerManager=t,this.isContainerManaged=n,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new zc,this.scrollSyncManager=new Al,this.interactionManager=new Wc("diff",yo(e,typeof e.hunkSeparators=="function"||(e.hunkSeparators??"line-info")==="line-info"||e.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex)),this.workerManager?.subscribeToThemeChanges(this),this.enabled=!0}getHunksRendererOptions(e){return ml(e)}createHunksRenderer(e){return new gl(this.getHunksRendererOptions(e),this.handleHighlightRender,this.workerManager)}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.hunksRenderer.setOptions(this.getHunksRendererOptions(e)),this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(yo(this.options,typeof this.options.hunkSeparators=="function"||(this.options.hunkSeparators??"line-info")==="line-info"||this.options.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;let t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType===t?!1:(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!Sn(this.appliedThemeCSS.theme,this.options.theme??oe)}setLineAnnotations(e){this.lineAnnotations=e}canPartiallyRender(e,t,n){return!(e||t||n||typeof this.options.hunkSeparators=="function")}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}let{diffStyle:e="split",overflow:t="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,t==="wrap"),t==="scroll"&&e==="split"?this.scrollSyncManager.setup(this.pre,this.codeDeletions,this.codeAdditions):this.scrollSyncManager.cleanUp(),this.managersDirty=!1}cleanUp(e=!1){this.emitPostRender(!0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.annotationCache.clear(),this.pre=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,this.bufferBefore=void 0,this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.placeHolder=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper=void 0,this.spriteSVG=void 0,this.lastRowCount=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,e?this.hunksRenderer.recycle():(this.hunksRenderer.cleanUp(),this.workerManager=void 0,this.fileDiff=void 0,this.deletionFile=void 0,this.additionFile=void 0),this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){let{fileContainer:t,prerenderedHTML:n,preventEmit:A=!1,lineAnnotations:o,oldFile:r,newFile:a,fileDiff:s}=e;this.hydrateElements(t,n),oy(this.pre,ny({fileDiff:s,oldFile:r,newFile:a}),this.options.collapsed)||ry(this.headerElement,Ay({fileDiff:s,oldFile:r,newFile:a}),this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({fileDiff:s,oldFile:r,newFile:a,lineAnnotations:o}),A||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),Tp(e,t);for(let n of e.shadowRoot?.children??[]){if(n instanceof SVGElement){this.spriteSVG=n;continue}if(n instanceof HTMLElement){if(n instanceof HTMLPreElement){this.pre=n;for(let A of n.children)!(A instanceof HTMLElement)||A.tagName.toLowerCase()!=="code"||("deletions"in A.dataset&&(this.codeDeletions=A),"additions"in A.dataset&&(this.codeAdditions=A),"unified"in A.dataset&&(this.codeUnified=A));continue}if("diffsHeader"in n.dataset){this.headerElement=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-theme-css")){this.themeCSSStyle=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=n,this.appliedUnsafeCSS=n.textContent;continue}}}this.pre!=null&&(this.syncCodeNodesFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({fileDiff:e,oldFile:t,newFile:n,lineAnnotations:A}){this.lineAnnotations=A??this.lineAnnotations,this.additionFile=n,this.deletionFile=t,this.fileDiff=e??(t!=null&&n!=null?Rs(t,n,this.options.parseDiffOptions):void 0),this.pre!=null&&(this.syncInteractionOptions(),this.hunksRenderer.hydrate(this.fileDiff),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||this.render({forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.hunksRenderer.clearRenderCache(),this.rerender()}render({oldFile:e,newFile:t,fileDiff:n,deferManagers:A=!1,forceRender:o=!1,preventEmit:r=!1,lineAnnotations:a,fileContainer:s,containerWrapper:i,renderRange:c}){if(!this.enabled)throw new Error("FileDiff.render: attempting to call render after cleaned up");let{collapsed:d=!1,themeType:u="system"}=this.options,g=d?void 0:c,p=this.hasThemeChanged(),l=e!=null&&t!=null&&(!is(e,this.deletionFile)||!is(t,this.additionFile)),h=n!=null&&n!==this.fileDiff,C=a!=null&&(a.length>0||this.lineAnnotations.length>0)?a!==this.lineAnnotations:!1;if(!d&&GA(g,this.renderRange)&&!o&&!C&&!p&&(n!=null&&n===this.fileDiff||n==null&&!l))return this.applyCachedThemeState(u);let{renderRange:b}=this;if(this.renderRange=g,this.deletionFile=e,this.additionFile=t,n!=null?this.fileDiff=n:e!=null&&t!=null&&l&&(h=!0,this.fileDiff=Rs(e,t,this.options.parseDiffOptions)),h&&(this.cachedHeaderHTML=void 0),a!=null&&this.setLineAnnotations(a),this.fileDiff==null)return!1;this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options)),this.syncInteractionOptions(),this.hunksRenderer.setLineAnnotations(this.lineAnnotations);let{disableErrorHandling:m=!1,disableFileHeader:B=!1}=this.options;if(B&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),s=this.getOrCreateFileContainer(s,i),this.applyCachedThemeState(u),d){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{let E=this.hunksRenderer.renderDiff(this.fileDiff,dc);E!=null&&this.applyThemeState(s,E.themeStyles,u,E.baseThemeType),E?.headerElement!=null&&this.applyHeaderToDOM(E.headerElement,s),this.renderSeparators([]),this.injectUnsafeCSS()}catch(E){if(m)throw E;console.error(E),E instanceof Error&&this.applyErrorToDOM(E,s)}return r||this.emitPostRender(),!0}try{let E=this.getOrCreatePreNode(s);if(!(this.canPartiallyRender(o,C,l||h||p)&&this.applyPartialRender({previousRenderRange:b,renderRange:g}))){let Q=this.hunksRenderer.renderDiff(this.fileDiff,g);if(Q==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(s,Q.themeStyles,u,Q.baseThemeType),Q.headerElement!=null&&this.applyHeaderToDOM(Q.headerElement,s),Q.additionsContentAST!=null||Q.deletionsContentAST!=null||Q.unifiedContentAST!=null?this.applyHunksToDOM(E,Q):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(Q.hunkData)}this.applyBuffers(E,g),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,A||this.flushManagers()}catch(E){if(m)throw E;console.error(E),E instanceof Error&&this.applyErrorToDOM(E,s)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){let{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;this.options.onPostRender?.(t,this,"unmount");return}if(t==null)return;let A=this.mounted?"update":"mount";this.mounted=!0,n?.(t,this,A)}removeRenderedCode(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(let{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();for(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){let t=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:"open"});this.placeHolder=document.createElement("div"),this.placeHolder.dataset.placeholder="",t.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty("height",`${e}px`),!0}primeHighlightCache(){let{fileDiff:e,workerManager:t}=this;if(e==null||t==null||Dn(e))return;let n=this.options.tokenizeMaxLength??1e5;Math.max(e.additionLines.length,e.deletionLines.length)>n||t.primeDiffHighlightCache(e)}cleanChildNodes(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.codeAdditions?.remove(),this.codeDeletions?.remove(),this.codeUnified?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.headerPrefix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.codeAdditions=void 0,this.codeDeletions=void 0,this.codeUnified=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderSeparators(e){let{hunkSeparators:t}=this.options;if(this.isContainerManaged||this.fileContainer==null||typeof t!="function"){for(let{element:A}of this.separatorCache.values())A.remove();this.separatorCache.clear();return}let n=new Map(this.separatorCache);for(let A of e){let o=A.slotName,r=this.separatorCache.get(o);if(r==null||!ll(A,r.hunkData)){r?.element.remove();let a=document.createElement("div");a.style.display="contents",a.slot=A.slotName;let s=t(A,this);s!=null&&a.appendChild(s),this.fileContainer.appendChild(a),r={element:a,hunkData:A},this.separatorCache.set(o,r)}n.delete(o)}for(let[A,{element:o}]of n.entries())this.separatorCache.delete(A),o.remove()}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(let{element:n}of this.annotationCache.values())n.remove();this.annotationCache.clear();return}let e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(let[n,A]of this.lineAnnotations.entries()){let o=`${n}-${Et(A)}`,r=this.annotationCache.get(o);if(r==null||!pl(A,r.annotation)){r?.element.remove();let a=t(A);if(a==null)continue;r={element:Gp(Et(A)),annotation:A},r.element.appendChild(a),this.fileContainer.appendChild(r.element),this.annotationCache.set(o,r)}e.delete(o)}for(let[n,{element:A}]of e.entries())this.annotationCache.delete(n),A.remove()}renderGutterUtility(){let{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let n=Hp();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}getOrCreateFileContainer(e,t){let{fileContainer:n}=this,A=e??n??document.createElement("diffs-container"),o=n!==A;return o&&this.emitPostRender(!0),this.fileContainer=A,n!=null&&o&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),o&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){let{shadowRoot:t}=e;if(t!=null)for(let n of t.children)n instanceof SVGElement?this.spriteSVG??(this.spriteSVG=n):bs(n)&&n.hasAttribute("data-theme-css")?(this.themeCSSStyle??(this.themeCSSStyle=n),this.hasAdoptedThemeCSS=!0):bs(n)&&n.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??(this.unsafeCSSStyle=n),this.appliedUnsafeCSS??(this.appliedUnsafeCSS=this.options.unsafeCSS??void 0))}ensureSpriteSVG(e){let t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){let n=document.createElement("div");n.innerHTML=Lp;let A=n.firstChild;A instanceof SVGElement&&(this.spriteSVG=A)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){let t=e.shadowRoot??e.attachShadow({mode:"open"});return this.pre==null?(this.pre=document.createElement("pre"),this.appliedPreAttributes=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(t.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodesFromPre(e){this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0;for(let t of Array.from(e.children))t instanceof HTMLElement&&(t.hasAttribute("data-unified")?this.codeUnified=t:t.hasAttribute("data-deletions")?this.codeDeletions=t:t.hasAttribute("data-additions")&&(this.codeAdditions=t))}applyHeaderToDOM(e,t){this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;let{fileDiff:n}=this,A=this.cachedHeaderHTML??Ee(e);if(this.cachedHeaderHTML=A,A!==this.lastRenderedHeaderHTML){let c=document.createElement("div");c.innerHTML=A;let d=c.firstElementChild;if(!(d instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(d,this.headerElement):t.shadowRoot?.prepend(d),this.headerElement=d,this.lastRenderedHeaderHTML=A}if(this.isContainerManaged||n==null)return;let{renderCustomHeader:o,renderHeaderPrefix:r,renderHeaderMetadata:a}=this.options;if(o!=null){let c=o(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,xn,c),this.headerPrefix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerMetadata=void 0;return}let s=r?.(n)??void 0,i=a?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Fn,s),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,vn,i),this.headerCustom?.remove(),this.headerCustom=void 0}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,n,A){if(A==null){t?.remove();return}let o=t??this.createHeaderSlotElement(n);return t==null&&e.appendChild(o),this.replaceHeaderSlotContent(o,A),o}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){let t=document.createElement("div");return t.slot=e,t}injectUnsafeCSS(){let{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===""){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}this.unsafeCSSStyle?.parentNode===t&&this.appliedUnsafeCSS===e||(this.unsafeCSSStyle??(this.unsafeCSSStyle=jp()),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=$p(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,A){let o=e.shadowRoot??e.attachShadow({mode:"open"}),r=A??n,a=this.options.theme??oe,s=typeof a=="string"?a:{...a},i=yn(o);if(this.themeCSSStyle?.parentNode===o&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===r&&this.appliedThemeCSS.scrollbarGutter===i){this.appliedThemeCSS.theme=s;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===o){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:s,themeStyles:t,themeType:r,baseThemeType:A,scrollbarGutter:i};return}this.themeCSSStyle=Op({shadowRoot:o,currentNode:this.themeCSSStyle,themeCSS:qp(t,r,i)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:s,themeStyles:t,themeType:r,baseThemeType:A,scrollbarGutter:i}:void 0}hydrateMeasuredScrollbar(){let e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=Yp(this.themeCSSStyle.textContent??"",yn(e)))}applyHunksToDOM(e,t){let{overflow:n="scroll"}=this.options,A=(this.options.hunkSeparators??"line-info")==="line-info",o=n==="wrap"?t.rowCount:void 0;this.cleanupErrorWrapper(),this.applyPreNodeAttributes(e,t);let r=!1,a=[],s=this.hunksRenderer.renderCodeAST("unified",t),i=this.hunksRenderer.renderCodeAST("deletions",t),c=this.hunksRenderer.renderCodeAST("additions",t);s!=null?(r=this.codeUnified==null||this.codeAdditions!=null||this.codeDeletions!=null,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.codeUnified=PA({code:this.codeUnified,columnType:"unified",rowSpan:o,containerSize:A}),this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(s),a.push(this.codeUnified)):i!=null||c!=null?(i!=null?(r=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=PA({code:this.codeDeletions,columnType:"deletions",rowSpan:o,containerSize:A}),this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(i),a.push(this.codeDeletions)):(this.codeDeletions?.remove(),this.codeDeletions=void 0),c!=null?(r=r||this.codeAdditions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeAdditions=PA({code:this.codeAdditions,columnType:"additions",rowSpan:o,containerSize:A}),this.codeAdditions.innerHTML=this.hunksRenderer.renderPartialHTML(c),a.push(this.codeAdditions)):(this.codeAdditions?.remove(),this.codeAdditions=void 0)):(this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0),a.length===0?e.textContent="":r&&e.replaceChildren(...a),this.lastRowCount=t.rowCount}applyPartialRender({previousRenderRange:e,renderRange:t}){let{pre:n,codeUnified:A,codeAdditions:o,codeDeletions:r,options:{diffStyle:a="split"}}=this;if(n==null||e==null||t==null||!Number.isFinite(e.totalLines)||!Number.isFinite(t.totalLines)||this.lastRowCount==null)return!1;let s=this.getCodeColumns(a,A,r,o);if(s==null)return!1;let i=e.startingLine,c=t.startingLine,d=i+e.totalLines,u=c+t.totalLines,g=Math.max(i,c),p=Math.min(d,u);if(p<=g)return!1;let l=Math.max(0,g-i),h=Math.max(0,d-p),C=this.trimColumns({columns:s,trimStart:l,trimEnd:h,previousStart:i,overlapStart:g,overlapEnd:p,diffStyle:a});if(C<0)throw new Error("applyPartialRender: failed to trim to overlap");if(this.lastRowCount<C)throw new Error("applyPartialRender: trimmed beyond DOM row count");let b=this.lastRowCount-C,m=(k,F)=>{if(!(F<=0||this.fileDiff==null))return this.hunksRenderer.renderDiff(this.fileDiff,{startingLine:k,totalLines:F,bufferBefore:0,bufferAfter:0})},B=m(c,Math.max(g-c,0));if(B==null&&c<g)return!1;let E=m(p,Math.max(u-p,0));if(E==null&&u>p)return!1;let Q=(k,F)=>{if(k!=null){if(a==="unified"&&!Array.isArray(s))this.insertPartialHTML(a,s,k,F);else if(a==="split"&&Array.isArray(s))this.insertPartialHTML(a,s,k,F);else throw new Error("FileDiff.applyPartialRender.applyChunk: invalid chunk application");b+=k.rowCount}};return this.cleanupErrorWrapper(),Q(B,"afterbegin"),Q(E,"beforeend"),this.lastRowCount!==b&&(this.applyRowSpan(a,s,b),this.lastRowCount=b),!0}insertPartialHTML(e,t,n,A){if(e==="unified"&&!Array.isArray(t)){let o=this.hunksRenderer.renderCodeAST("unified",n);this.renderPartialColumn(t,o,A)}else if(e==="split"&&Array.isArray(t)){let o=this.hunksRenderer.renderCodeAST("deletions",n),r=this.hunksRenderer.renderCodeAST("additions",n);this.renderPartialColumn(t[0],o,A),this.renderPartialColumn(t[1],r,A)}else throw new Error("FileDiff.insertPartialHTML: Invalid argument composition")}renderPartialColumn(e,t,n){if(e==null||t==null)return;let A=fl(t[0]),o=fl(t[1]);if(A==null||o==null)throw new Error("FileDiff.insertPartialHTML: Unexpected AST structure");let r=o.at(0);n==="beforeend"&&r?.type==="element"&&typeof r.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(r.properties["data-buffer-size"],e.content.children[e.content.children.length-1],e.gutter.children[e.gutter.children.length-1],A,o,!0);let a=o.at(-1);n==="afterbegin"&&a?.type==="element"&&typeof a.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(a.properties["data-buffer-size"],e.content.children[0],e.gutter.children[0],A,o,!1),e.gutter.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(A)),e.content.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(o))}mergeBuffersIfNecessary(e,t,n,A,o,r){if(!(t instanceof HTMLElement)||!(n instanceof HTMLElement))return;let a=this.getBufferSize(t.dataset);a!=null&&(r?(A.shift(),o.shift()):(A.pop(),o.pop()),this.updateBufferSize(t,a+e),this.updateBufferSize(n,a+e))}applyRowSpan(e,t,n){let A=o=>{o!=null&&(o.gutter.style.setProperty("grid-row",`span ${n}`),o.content.style.setProperty("grid-row",`span ${n}`))};if(e==="unified"&&!Array.isArray(t))A(t);else if(e==="split"&&Array.isArray(t))A(t[0]),A(t[1]);else throw new Error("dun fuuuuked up")}trimColumnRows(e,t,n){let A=0,o=0,r=0,a=!1,s=n>=0;if(e==null)return 0;let i=Array.from(e.content.children),c=Array.from(e.gutter.children);if(i.length!==c.length)throw new Error("FileDiff.trimColumnRows: columns do not match");for(;r<i.length&&!(t<=0&&!s&&!a);){let d=c[r],u=i[r];if(r++,!(d instanceof HTMLElement)||!(u instanceof HTMLElement))throw console.error({gutterElement:d,contentElement:u}),new Error("FileDiff.trimColumnRows: invalid row elements");if(a&&(a=!1,d.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in u.dataset||d.dataset.gutterBuffer==="metadata"&&"noNewline"in u.dataset)){d.remove(),u.remove(),o++;continue}if("lineIndex"in d.dataset&&"lineIndex"in u.dataset){(t>0||s&&A>=n)&&(d.remove(),u.remove(),t>0&&(t--,t===0&&(a=!0)),o++),A++;continue}if("separator"in d.dataset&&"separator"in u.dataset){(t>0||s&&A>=n)&&(d.remove(),u.remove(),o++);continue}if(d.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in u.dataset){(t>0||s&&A>=n)&&(d.remove(),u.remove(),o++);continue}if(d.dataset.gutterBuffer==="metadata"&&"noNewline"in u.dataset){(t>0||s&&A>=n)&&(d.remove(),u.remove(),o++);continue}if(d.dataset.gutterBuffer==="buffer"&&"contentBuffer"in u.dataset){let g=this.getBufferSize(u.dataset);if(g==null)throw new Error("FileDiff.trimColumnRows: invalid element");if(t>0){let p=Math.min(t,g),l=g-p;l>0?(this.updateBufferSize(d,l),this.updateBufferSize(u,l),o+=p):(d.remove(),u.remove(),o+=g),t-=p,t===0&&l===0&&(a=!0)}else if(s){let p=A,l=A+g-1;if(n<=p)d.remove(),u.remove(),o+=g;else if(n<=l){let h=l-n+1,C=g-h;this.updateBufferSize(d,C),this.updateBufferSize(u,C),o+=h}}A+=g;continue}throw console.error({gutterElement:d,contentElement:u}),new Error("FileDiff.trimColumnRows: unknown row elements")}return o}trimColumns({columns:e,diffStyle:t,overlapEnd:n,overlapStart:A,previousStart:o,trimEnd:r,trimStart:a}){let s=Math.max(0,A-o),i=n-o;if(i<0)throw new Error("FileDiff.trimColumns: overlap ends before previous");let c=a>0,d=r>0;if(!c&&!d)return 0;let u=c?s:0,g=d?i:-1;if(t==="unified"&&!Array.isArray(e))return this.trimColumnRows(e,u,g);if(t==="split"&&Array.isArray(e)){let p=this.trimColumnRows(e[0],u,g),l=this.trimColumnRows(e[1],u,g);if(e[0]!=null&&e[1]!=null&&p!==l)throw new Error("FileDiff.trimColumns: split columns out of sync");return e[0]!=null?p:l}else throw console.error({diffStyle:t,columns:e}),new Error("FileDiff.trimColumns: Invalid columns for diffType")}getBufferSize(e){let t=Number.parseInt(e?.bufferSize??"",10);return Number.isNaN(t)?void 0:t}updateBufferSize(e,t){e.dataset.bufferSize=`${t}`,e.style.setProperty("grid-row",`span ${t}`),e.style.setProperty("min-height",`calc(${t} * 1lh)`)}getCodeColumns(e,t,n,A){function o(r){if(r==null)return;let a=r.children[0],s=r.children[1];if(!(!(a instanceof HTMLElement)||!(s instanceof HTMLElement)||a.dataset.gutter==null||s.dataset.content==null))return{gutter:a,content:s}}if(e==="unified")return o(t);{let r=o(n),a=o(A);return r!=null||a!=null?[r,a]:void 0}}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==null&&(this.bufferBefore=document.createElement("div"),this.bufferBefore.dataset.virtualizerBuffer="before",e.before(this.bufferBefore)),this.bufferBefore.style.setProperty("height",`${t.bufferBefore}px`),this.bufferBefore.style.setProperty("contain","strict")):this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),t.bufferAfter>0?(this.bufferAfter==null&&(this.bufferAfter=document.createElement("div"),this.bufferAfter.dataset.virtualizerBuffer="after",e.after(this.bufferAfter)),this.bufferAfter.style.setProperty("height",`${t.bufferAfter}px`),this.bufferAfter.style.setProperty("contain","strict")):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyPreNodeAttributes(e,{additionsContentAST:t,deletionsContentAST:n,totalLines:A},o){let{diffIndicators:r="bars",disableBackground:a=!1,disableLineNumbers:s=!1,overflow:i="scroll",diffStyle:c="split"}=this.options,d={type:"diff",diffIndicators:r,disableBackground:a,disableLineNumbers:s,overflow:i,split:c==="unified"?!1:t!=null&&n!=null,totalLines:A,customProperties:o};Np(d,this.appliedPreAttributes)||(Kp(e,d),this.appliedPreAttributes=d)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;let n=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??(this.errorWrapper=document.createElement("div")),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",n.appendChild(this.errorWrapper);let A=document.createElement("div");A.dataset.errorMessage="",A.innerText=e.message,this.errorWrapper.appendChild(A);let o=document.createElement("pre");o.dataset.errorStack="",o.innerText=e.stack??"No Error Stack",this.errorWrapper.appendChild(o)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}},f(qs,"LoadedCustomComponent",!0),qs);function ny({fileDiff:e,oldFile:t,newFile:n}){return e!=null&&e.hunks.length>0||t!=null||n!=null}function Ay({fileDiff:e,oldFile:t,newFile:n}){return e!=null||t!=null||n!=null}function oy(e,t,n=!1){return!n&&e==null&&t}function ry(e,t,n=!1){return e==null&&t&&!n}function fl(e){if(!(e==null||e.type!=="element"))return e.children??[]}var ay=[...Object.keys(DA),"text","ansi"],iy=new Set(ay),sy=new Map(bn.flatMap(e=>Ng(e).map(t=>[t,e.id])));function cy(e){if(typeof e!="string")return;let t=e.trim().toLowerCase();return t||void 0}async function bl(e,t={}){let n=cy(e);if(!n)return;let A=sy.get(n);if(A)return A;if(iy.has(n))return n;if(t.languagePackAvailable)try{return await Bn(n),n}catch{return}}async function dy(e,t){let n=new Set;for(let A of e){let o=await bl(A,t);o&&n.add(o)}return t.fallbackToText&&n.size===0&&n.add("text"),[...n]}function uy(e){let t=new Set;return e.fileDiff?.lang&&t.add(e.fileDiff.lang),e.oldFile?.lang&&t.add(e.oldFile.lang),e.newFile?.lang&&t.add(e.newFile.lang),[...t]}async function Ts(e,t){if(!e)return;if(typeof e.lang!="string")return e;let n=await bl(e.lang,t);return e.lang===n?e:n?{...e,lang:n}:{...e,lang:"text"}}async function Bl(e,t={}){let[n,A,o,r]=await Promise.all([Ts(e.fileDiff,t),Ts(e.oldFile,t),Ts(e.newFile,t),dy(e.langs,{fallbackToText:!1,...t})]),a=new Set(r);for(let s of uy({fileDiff:n,oldFile:A,newFile:o}))a.add(s);return a.size===0&&a.add("text"),{...e,fileDiff:n,oldFile:A,newFile:o,langs:[...a]}}var hl=["unified","split"];var Cl=["light","dark"],El=["bars","classic","none"];var gy=["scroll","wrap"];function jt(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function yl(e){let t;try{t=JSON.parse(e)}catch{throw new Error("Diff payload is not valid JSON.")}if(!py(t))throw new Error("Diff payload has invalid shape.");return t}function py(e){if(!jt(e)||typeof e.prerenderedHTML!="string"||!Array.isArray(e.langs)||!e.langs.every(A=>typeof A=="string")||!ly(e.options))return!1;let t=jt(e.fileDiff),n=jt(e.oldFile)&&jt(e.newFile);return!(!t&&!n)}function ly(e){return!(!jt(e)||!jt(e.theme)||e.theme.light!=="pierre-light"||e.theme.dark!=="pierre-dark"||!VA(hl,e.diffStyle)||!VA(El,e.diffIndicators)||!VA(Cl,e.themeType)||!VA(gy,e.overflow)||typeof e.disableLineNumbers!="boolean"||typeof e.expandUnchanged!="boolean"||typeof e.backgroundEnabled!="boolean"||typeof e.unsafeCSS!="string")}function VA(e,t){return typeof t=="string"&&e.includes(t)}function my(){return!1}function fy(e=my()){return e===!0}var Ks=[],j={theme:"dark",layout:"unified",backgroundEnabled:!0,wrapEnabled:!0};function by(e){let t=e.textContent?.trim();if(!t)throw new Error("Diff payload was empty.");return yl(t)}function By(){let e=[];for(let t of document.querySelectorAll(".oc-diff-card")){let n=t.querySelector("[data-openclaw-diff-host]"),A=t.querySelector("[data-openclaw-diff-payload]");if(!(!n||!A))try{e.push({host:n,payload:by(A)})}catch(o){console.warn("Skipping invalid diff payload",o)}}return e}var hy={split:`<svg viewBox="0 0 16 16" aria-hidden="true">
1554
+ `);return t?n.pop():n.push(n.pop().slice(0,-1)),n}function Rs(e,t,n,A=!1){let o=Vp(Ls(e.name,t.name,e.contents,t.contents,e.header,t.header,n),{cacheKey:(()=>{if(e.cacheKey!=null&&t.cacheKey!=null)return`${e.cacheKey}:${t.cacheKey}`})(),oldFile:e,newFile:t,throwOnError:A});if(o==null)throw new Error("parseDiffFrom: FileInvalid diff -- probably need to fix something -- if the files are the same maybe?");return t.lang!=null&&(o.lang=t.lang),o}var Al=class{constructor(){f(this,"isDeletionsScrolling",!1);f(this,"isAdditionsScrolling",!1);f(this,"timeoutId",-1);f(this,"codeDeletions");f(this,"codeAdditions");f(this,"enabled",!1);f(this,"handleDeletionsScroll",()=>{this.isAdditionsScrolling||(this.isDeletionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isDeletionsScrolling=!1},300),this.codeAdditions?.scrollTo({left:this.codeDeletions?.scrollLeft}))});f(this,"handleAdditionsScroll",()=>{this.isDeletionsScrolling||(this.isAdditionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isAdditionsScrolling=!1},300),this.codeDeletions?.scrollTo({left:this.codeAdditions?.scrollLeft}))})}cleanUp(){this.enabled&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),clearTimeout(this.timeoutId),this.codeDeletions=void 0,this.codeAdditions=void 0,this.enabled=!1)}setup(e,t,n){if(t==null||n==null)for(let A of e.children??[])A instanceof HTMLElement&&("deletions"in A.dataset?t=A:"additions"in A.dataset&&(n=A));if(n==null||t==null){this.cleanUp();return}this.codeDeletions!==t&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeDeletions=t,t.addEventListener("scroll",this.handleDeletionsScroll,{passive:!0})),this.codeAdditions!==n&&(this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),this.codeAdditions=n,n.addEventListener("scroll",this.handleAdditionsScroll,{passive:!0})),this.enabled=!0}};function Ht(e,t){return Sn(e.theme,t.theme)&&e.useTokenTransformer===t.useTokenTransformer&&e.tokenizeMaxLineLength===t.tokenizeMaxLineLength&&e.lineDiffType===t.lineDiffType&&e.maxLineDiffLength===t.maxLineDiffLength}function kn(e){return M({tagName:"div",properties:{"data-content-buffer":"","data-buffer-size":e,style:`grid-row: span ${e};min-height:calc(${e} * 1lh)`}})}function In(e){return M({tagName:"div",children:[M({tagName:"span",children:[ae("No newline at end of file")]})],properties:{"data-no-newline":"","data-line-type":e,"data-column-content":""}})}function Ns(e){return M({tagName:"div",children:[at({name:e==="both"?"diffs-icon-expand-all":"diffs-icon-expand",properties:{"data-icon":""}})],properties:{role:"button","data-expand-button":"","data-expand-both":e==="both"?"":void 0,"data-expand-up":e==="up"?"":void 0,"data-expand-down":e==="down"?"":void 0}})}function wt({type:e,content:t,expandIndex:n,chunked:A=!1,slotName:o,isFirstHunk:r,isLastHunk:a}){let s=0,i=[];if(e==="metadata"&&t!=null&&i.push(M({tagName:"div",children:[ae(t)],properties:{"data-separator-wrapper":""}})),(e==="line-info"||e==="line-info-basic")&&t!=null){let c=[];n!=null&&(A?(r||(c.push(Ns("up")),s++),a||(c.push(Ns("down")),s++)):(c.push(Ns(!r&&!a?"both":r?"down":"up")),s++)),c.push(M({tagName:"div",children:[M({tagName:"span",children:[ae(t)],properties:{"data-unmodified-lines":""}})],properties:{"data-separator-content":""}})),A&&n!=null&&c.push(M({tagName:"div",children:[ae("Expand all")],properties:{role:"button","data-expand-button":"","data-expand-all-button":""}})),i.push(M({tagName:"div",children:c,properties:{"data-separator-wrapper":"","data-separator-multi-button":s>1?"":void 0}}))}return e==="custom"&&o!=null&&i.push(M({tagName:"slot",properties:{name:o}})),M({tagName:"div",children:i,properties:{"data-separator":i.length===0?"simple":e,"data-expand-index":n,"data-separator-first":r?"":void 0,"data-separator-last":a?"":void 0}})}function ol(e,t){return`hunk-separator-${e}-${t}`}function rl(e){let t=e.at(-1);return t==null?0:Math.max(t.additionStart+t.additionCount,t.deletionStart+t.deletionCount)}function al(e){return e.startingLine===0&&e.totalLines===1/0&&e.bufferBefore===0&&e.bufferAfter===0}function Gs({line:e,spanStart:t,spanLength:n}){return{start:{line:e,character:t},end:{line:e,character:t+n},properties:{"data-diff-span":""},alwaysWrap:!0}}function _n({item:e,arr:t,enableJoin:n,isNeutral:A=!1,isLastItem:o=!1}){let r=t[t.length-1];if(r==null||o||!n){t.push([A?0:1,e.value]);return}let a=r[0]===0;if(A===a||A&&e.value.length===1&&!a){r[1]+=e.value;return}t.push([A?0:1,e.value])}function Hs({isPartial:e,rangeSize:t,expandedHunks:n,hunkIndex:A,collapsedContextThreshold:o}){let r=Math.max(t,0);if(r===0||e)return{fromStart:0,fromEnd:0,rangeSize:r,collapsedLines:r,renderAll:!1};if(n===!0||r<=o)return{fromStart:r,fromEnd:0,rangeSize:r,collapsedLines:0,renderAll:!0};let a=n?.get(A),s=Math.min(Math.max(a?.fromStart??0,0),r),i=Math.min(Math.max(a?.fromEnd??0,0),r),c=s+i,d=c>=r;return{fromStart:d?r:s,fromEnd:d?0:i,rangeSize:r,collapsedLines:Math.max(r-c,0),renderAll:d}}function js({fileDiff:e,errorPrefix:t}){let n=e.hunks[e.hunks.length-1];if(n==null||e.isPartial||e.additionLines.length===0||e.deletionLines.length===0)return 0;let A=e.additionLines.length-(n.additionLineIndex+n.additionCount),o=e.deletionLines.length-(n.deletionLineIndex+n.deletionCount);if(A<=0&&o<=0)return 0;if(A!==o)throw new Error(`${t}: trailing context mismatch (additions=${A}, deletions=${o}) for ${e.name}`);return Math.min(A,o)}function Us({fileDiff:e,hunkIndex:t,expandedHunks:n,collapsedContextThreshold:A,errorPrefix:o}){if(t!==e.hunks.length-1)return;let r=js({fileDiff:e,errorPrefix:o});if(r<=0)return;if(n===!0||r<=A)return{fromStart:r,fromEnd:0,rangeSize:r,collapsedLines:0,renderAll:!0};let a=n?.get(e.hunks.length),s=Math.min(Math.max(a?.fromStart??0,0),r);return{fromStart:s,fromEnd:0,rangeSize:r,collapsedLines:r-s,renderAll:s>=r}}function WA({diff:e,diffStyle:t,startingLine:n=0,totalLines:A=1/0,expandedHunks:o,collapsedContextThreshold:r=1,callback:a}){let s=YE({diff:e,diffStyle:t,startingLine:n,expandedHunks:o,collapsedContextThreshold:r}),i={viewportStart:n,viewportEnd:n+A,isWindowedHighlight:n>0||A<1/0,splitCount:s.splitCount,unifiedCount:s.unifiedCount,finalHunkIndex:e.hunks.length-1,shouldBreak(){if(!i.isWindowedHighlight)return!1;let c=i.unifiedCount>=n+A,d=i.splitCount>=n+A;return t==="unified"?c:(t==="split"||c)&&d},shouldSkip(c,d){if(!i.isWindowedHighlight)return!1;let u=i.unifiedCount+c<n,g=i.splitCount+d<n;return t==="unified"?u:(t==="split"||u)&&g},incrementCounts(c,d){(t==="unified"||t==="both")&&(i.unifiedCount+=c),(t==="split"||t==="both")&&(i.splitCount+=d)},isInWindow(c,d){if(!i.isWindowedHighlight)return!0;let u=i.isInUnifiedWindow(c),g=i.isInSplitWindow(d);return t==="unified"?u:t==="split"?g:u||g},isInUnifiedWindow(c){return!i.isWindowedHighlight||i.unifiedCount>=n-c&&i.unifiedCount<n+A},isInSplitWindow(c){return!i.isWindowedHighlight||i.splitCount>=n-c&&i.splitCount<n+A},emit(c,d=!1){return d||(t==="unified"?i.incrementCounts(1,0):t==="split"?i.incrementCounts(0,1):i.incrementCounts(1,1)),a(c)??!1}};e:for(let c=s.hunkIndex;c<e.hunks.length;c++){let l=function(_,D){return g==null||g.collapsedLines<=0||g.fromStart+g.fromEnd>0?0:t==="unified"?_===d.unifiedLineStart+d.unifiedLineCount-1?g.collapsedLines:0:D===d.splitLineStart+d.splitLineCount-1?g.collapsedLines:0},C=function(){return h?0:(h=!0,u.collapsedLines)},d=e.hunks[c];if(d==null)throw new Error("iterateOverDiff: invalid hunk index");if(i.shouldBreak())break;let u=Hs({isPartial:e.isPartial,rangeSize:d.collapsedBefore,expandedHunks:o,hunkIndex:c,collapsedContextThreshold:r}),g=c===i.finalHunkIndex?Us({fileDiff:e,hunkIndex:c,expandedHunks:o,collapsedContextThreshold:r,errorPrefix:"iterateOverDiff"}):void 0,p=u.fromStart+u.fromEnd,h=u.collapsedLines===0;if(i.shouldSkip(p,p))i.incrementCounts(p,p),C();else{let _=d.unifiedLineStart-u.rangeSize,D=d.splitLineStart-u.rangeSize,L=d.deletionLineIndex-u.rangeSize,R=d.additionLineIndex-u.rangeSize,x=d.deletionStart-u.rangeSize,v=d.additionStart-u.rangeSize;if(JA(i,u.fromStart,t,G=>i.emit({hunkIndex:c,hunk:d,collapsedBefore:0,collapsedAfter:0,type:"context-expanded",deletionLine:{lineNumber:x+G,lineIndex:L+G,noEOFCR:!1,unifiedLineIndex:_+G,splitLineIndex:D+G},additionLine:{unifiedLineIndex:_+G,splitLineIndex:D+G,lineIndex:R+G,lineNumber:v+G,noEOFCR:!1}}))||(_=d.unifiedLineStart-u.fromEnd,D=d.splitLineStart-u.fromEnd,L=d.deletionLineIndex-u.fromEnd,R=d.additionLineIndex-u.fromEnd,x=d.deletionStart-u.fromEnd,v=d.additionStart-u.fromEnd,JA(i,u.fromEnd,t,G=>i.emit({hunkIndex:c,hunk:d,collapsedBefore:C(),collapsedAfter:0,type:"context-expanded",deletionLine:{lineNumber:x+G,lineIndex:L+G,noEOFCR:!1,unifiedLineIndex:_+G,splitLineIndex:D+G},additionLine:{unifiedLineIndex:_+G,splitLineIndex:D+G,lineIndex:R+G,lineNumber:v+G,noEOFCR:!1}}),()=>{C()})))break e}let b=d.unifiedLineStart,m=d.splitLineStart,B=d.deletionLineIndex,E=d.additionLineIndex,Q=d.deletionStart,k=d.additionStart,F=d.hunkContent.at(-1);for(let _ of d.hunkContent){if(i.shouldBreak())break e;let D=_===F;if(_.type==="context"){if(i.shouldSkip(_.lines,_.lines))i.incrementCounts(_.lines,_.lines),C();else if(JA(i,_.lines,t,L=>{let R=D&&L===_.lines-1,x=b+L,v=m+L;return i.emit({hunkIndex:c,hunk:d,collapsedBefore:C(),collapsedAfter:l(x,v),type:"context",deletionLine:{lineNumber:Q+L,lineIndex:B+L,noEOFCR:R&&d.noEOFCRDeletions,unifiedLineIndex:x,splitLineIndex:v},additionLine:{unifiedLineIndex:x,splitLineIndex:v,lineIndex:E+L,lineNumber:k+L,noEOFCR:R&&d.noEOFCRAdditions}})},()=>{C()}))break e;b+=_.lines,m+=_.lines,B+=_.lines,E+=_.lines,Q+=_.lines,k+=_.lines}else{let L=Math.max(_.deletions,_.additions),R=_.deletions+_.additions;if(!i.shouldSkip(R,L)){let x=OE(i,_,t);(x[0]?.[0]??0)>0&&C();for(let[v,G]of x)for(let $=v;$<G;$++){let ce=l(b+$,t==="unified"?m+($<_.deletions?$:$-_.deletions):m+$);if(i.emit(JE({hunkIndex:c,hunk:d,collapsedBefore:C(),collapsedAfter:ce,diffStyle:t,index:$,unifiedLineIndex:b,splitLineIndex:m,additionLineIndex:E,deletionLineIndex:B,additionLineNumber:k,deletionLineNumber:Q,content:_,isLastContent:D,unifiedCount:R,splitCount:L}),!0))break e}}C(),i.incrementCounts(R,L),b+=R,m+=L,B+=_.deletions,E+=_.additions,Q+=_.deletions,k+=_.additions}}if(g!=null){let{collapsedLines:_,fromStart:D,fromEnd:L}=g,R=D+L;if(JA(i,R,t,x=>{let v=x===R-1;return i.emit({hunkIndex:e.hunks.length,hunk:void 0,collapsedBefore:0,collapsedAfter:v?_:0,type:"context-expanded",deletionLine:{lineNumber:Q+x,lineIndex:B+x,noEOFCR:!1,unifiedLineIndex:b+x,splitLineIndex:m+x},additionLine:{unifiedLineIndex:b+x,splitLineIndex:m+x,lineIndex:E+x,lineNumber:k+x,noEOFCR:!1}})},void 0,()=>i.shouldBreak()))break e}}}function YE({diff:e,diffStyle:t,startingLine:n,expandedHunks:A,collapsedContextThreshold:o}){if(n<=0||t==="both")return{hunkIndex:0,splitCount:0,unifiedCount:0};let r=TE({diff:e,expandedHunks:A,collapsedContextThreshold:o}),a=0,s=e.hunks.length-1,i=e.hunks.length;for(;a<=s;){let d=a+s>>1,u=r[d+1];if(u==null)throw new Error("iterateOverDiff: invalid hunk prefix index");(t==="unified"?u.unifiedCount:u.splitCount)>n?(i=d,s=d-1):a=d+1}if(i>=e.hunks.length){let d=r[e.hunks.length];if(d==null)throw new Error("iterateOverDiff: invalid terminal hunk prefix index");return{hunkIndex:e.hunks.length,splitCount:d.splitCount,unifiedCount:d.unifiedCount}}let c=r[i];if(c==null)throw new Error("iterateOverDiff: invalid selected hunk prefix index");return{hunkIndex:i,splitCount:c.splitCount,unifiedCount:c.unifiedCount}}function TE({diff:e,expandedHunks:t,collapsedContextThreshold:n}){let A=0,o=0,r=e.hunks.length-1,a=[{splitCount:0,unifiedCount:0}];for(let s=0;s<e.hunks.length;s++){let i=e.hunks[s];if(i==null)throw new Error("iterateOverDiff: invalid hunk summary index");let c=Hs({isPartial:e.isPartial,rangeSize:i.collapsedBefore,expandedHunks:t,hunkIndex:s,collapsedContextThreshold:n}),d=c.fromStart+c.fromEnd;A+=d+i.splitLineCount,o+=d+i.unifiedLineCount;let u=s===r?Us({fileDiff:e,hunkIndex:s,expandedHunks:t,collapsedContextThreshold:n,errorPrefix:"iterateOverDiff"}):void 0;if(u!=null){let g=u.fromStart+u.fromEnd;A+=g,o+=g}a.push({splitCount:A,unifiedCount:o})}return a}function KE(e,t,n){if(!e.isWindowedHighlight||t<=0)return[0,t];let A=[];function o(s){let i=Math.max(0,e.viewportStart-s),c=Math.min(t,e.viewportEnd-s);c>i&&A.push([i,c])}if(n!=="split"&&o(e.unifiedCount),n!=="unified"&&o(e.splitCount),A.length===0)return[0,0];let r=A[0][0],a=A[0][1];for(let s=1;s<A.length;s++){let i=A[s];r=Math.min(r,i[0]),a=Math.max(a,i[1])}return[r,a]}function JA(e,t,n,A,o,r){let[a,s]=KE(e,t,n);a>0&&(e.incrementCounts(a,a),o?.());let i=a;for(;i<t;){if(r?.()===!0)return!0;if(i>=s){e.incrementCounts(t-i,t-i);break}if(e.isInWindow(0,0)){if(A(i)===!0)return!0}else e.incrementCounts(1,1);i++}return!1}function OE(e,t,n){if(!e.isWindowedHighlight)return[[0,n==="unified"?t.deletions+t.additions:Math.max(t.deletions,t.additions)]];let A=n!=="split",o=n!=="unified",r=n==="unified"?"unified":"split",a=[];function s(u,g){if(u+g<=e.viewportStart||u>=e.viewportEnd)return;let p=Math.max(0,e.viewportStart-u),l=Math.min(g,e.viewportEnd-u);return l>p?[p,l]:void 0}function i(u,g){return r==="split"?u:g==="additions"?[u[0]+t.deletions,u[1]+t.deletions]:u}function c(u,g){if(u==null)return;let[p,l]=i(u,g);l>p&&a.push([p,l])}if(A&&(c(s(e.unifiedCount,t.deletions),"deletions"),c(s(e.unifiedCount+t.deletions,t.additions),"additions")),o&&(c(s(e.splitCount,t.deletions),"deletions"),c(s(e.splitCount,t.additions),"additions")),a.length===0)return a;a.sort((u,g)=>u[0]-g[0]);let d=[a[0]];for(let[u,g]of a.slice(1)){let p=d[d.length-1];u<=p[1]?p[1]=Math.max(p[1],g):d.push([u,g])}return d}function JE({hunkIndex:e,hunk:t,collapsedAfter:n,collapsedBefore:A,diffStyle:o,index:r,unifiedLineIndex:a,splitLineIndex:s,additionLineIndex:i,deletionLineIndex:c,additionLineNumber:d,deletionLineNumber:u,content:g,isLastContent:p,unifiedCount:l,splitCount:h}){let C=r<g.deletions?a+r:void 0,b=o==="unified"?r>=g.deletions?a+r:void 0:r<g.additions?a+g.deletions+r:void 0,m=o==="unified"?s+(r<g.deletions?r:r-g.deletions):s+r,B=r<g.deletions?c+r:void 0,E=r<g.deletions?u+r:void 0,Q=o==="unified"?r>=g.deletions?i+(r-g.deletions):void 0:r<g.additions?i+r:void 0,k=o==="unified"?r>=g.deletions?d+(r-g.deletions):void 0:r<g.additions?d+r:void 0,F=o==="unified"?p&&r===g.deletions-1&&t.noEOFCRDeletions:p&&r===h-1&&t.noEOFCRDeletions,_=o==="unified"?p&&r===l-1&&t.noEOFCRAdditions:p&&r===h-1&&t.noEOFCRAdditions,D=B!=null&&E!=null&&C!=null?{lineNumber:E,lineIndex:B,noEOFCR:F,unifiedLineIndex:C,splitLineIndex:m}:void 0,L=Q!=null&&k!=null&&b!=null?{unifiedLineIndex:b,splitLineIndex:m,lineIndex:Q,lineNumber:k,noEOFCR:_}:void 0;if(D==null&&L!=null)return{type:"change",hunkIndex:e,hunk:t,collapsedAfter:n,collapsedBefore:A,deletionLine:void 0,additionLine:L};if(D!=null&&L==null)return{type:"change",hunkIndex:e,hunk:t,collapsedAfter:n,collapsedBefore:A,deletionLine:D,additionLine:void 0};if(D==null||L==null)throw new Error("iterateOverDiff: missing change line data");return{type:"change",hunkIndex:e,hunk:t,collapsedAfter:n,collapsedBefore:A,deletionLine:D,additionLine:L}}var WE={forcePlainText:!1};function il(e,t,n,{forcePlainText:A,startingLine:o,totalLines:r,expandedHunks:a,collapsedContextThreshold:s=1}=WE){A?(o??(o=0),r??(r=1/0)):(o=0,r=1/0);let i=o>0||r<1/0,c=typeof n.theme=="string"?t.getTheme(n.theme).type:void 0,d=vp({theme:n.theme,highlighter:t}),u=A&&!i&&(e.unifiedLineCount>1e3||e.splitLineCount>1e3)?"none":n.lineDiffType,g={deletionLines:[],additionLines:[]},{maxLineDiffLength:p}=n,l=!A&&!e.isPartial,h=A?a:void 0,C=new Map;function b(B){let E=l?0:B,Q=C.get(E)??ZE();return C.set(E,Q),Q}function m(B,E,Q,k){if(i){let F=Q.at(-1);(F==null||F.targetIndex+F.count!==E)&&(F={targetIndex:E,originalOffset:k.length,count:0},Q.push(F)),F.count++}k.push(B)}WA({diff:e,diffStyle:"both",startingLine:o,totalLines:r,expandedHunks:i?h:!0,collapsedContextThreshold:s,callback:({hunkIndex:B,additionLine:E,deletionLine:Q,type:k})=>{let F=b(B),_=E!=null?E.splitLineIndex:Q.splitLineIndex;k==="change"&&E!=null&&Q!=null&&zE({additionLine:e.additionLines[E.lineIndex],deletionLine:e.deletionLines[Q.lineIndex],deletionLineIndex:F.deletionContent.length,additionLineIndex:F.additionContent.length,deletionDecorations:F.deletionDecorations,additionDecorations:F.additionDecorations,lineDiffType:u,maxLineDiffLength:p}),Q!=null&&(m(e.deletionLines[Q.lineIndex],Q.lineIndex,F.deletionSegments,F.deletionContent),F.deletionInfo.push({type:k==="change"?"change-deletion":k,lineNumber:Q.lineNumber,altLineNumber:k==="change"?void 0:E.lineNumber??void 0,lineIndex:`${Q.unifiedLineIndex},${_}`})),E!=null&&(m(e.additionLines[E.lineIndex],E.lineIndex,F.additionSegments,F.additionContent),F.additionInfo.push({type:k==="change"?"change-addition":k,lineNumber:E.lineNumber,altLineNumber:k==="change"?void 0:Q.lineNumber??void 0,lineIndex:`${E.unifiedLineIndex},${_}`}))}});for(let B of C.values()){if(B.deletionContent.length===0&&B.additionContent.length===0)continue;let E={name:e.prevName??e.name,contents:B.deletionContent.value},Q={name:e.name,contents:B.additionContent.value},{deletionLines:k,additionLines:F}=VE({deletionFile:E,deletionInfo:B.deletionInfo,deletionDecorations:B.deletionDecorations,additionFile:Q,additionInfo:B.additionInfo,additionDecorations:B.additionDecorations,highlighter:t,options:n,languageOverride:A?"text":e.lang});if(l){g.deletionLines=k,g.additionLines=F;continue}if(B.deletionSegments.length>0)for(let _ of B.deletionSegments)for(let D=0;D<_.count;D++)g.deletionLines[_.targetIndex+D]=k[_.originalOffset+D];else g.deletionLines.push(...k);if(B.additionSegments.length>0)for(let _ of B.additionSegments)for(let D=0;D<_.count;D++)g.additionLines[_.targetIndex+D]=F[_.originalOffset+D];else g.additionLines.push(...F)}return{code:g,themeStyles:d,baseThemeType:c}}function zE({deletionLine:e,additionLine:t,deletionLineIndex:n,additionLineIndex:A,deletionDecorations:o,additionDecorations:r,lineDiffType:a,maxLineDiffLength:s}){if(e==null||t==null||a==="none"||(e=At(e),t=At(t),e.length>s||t.length>s))return;let i=a==="char"?ys(e,t):Fs(e,t),c=[],d=[],u=a==="word-alt",g=i.at(-1);for(let l of i){let h=l===g;!l.added&&!l.removed?(_n({item:l,arr:c,enableJoin:u,isNeutral:!0,isLastItem:h}),_n({item:l,arr:d,enableJoin:u,isNeutral:!0,isLastItem:h})):l.removed?_n({item:l,arr:c,enableJoin:u,isLastItem:h}):_n({item:l,arr:d,enableJoin:u,isLastItem:h})}let p=0;for(let l of c)l[0]===1&&o.push(Gs({line:n,spanStart:p,spanLength:l[1].length})),p+=l[1].length;p=0;for(let l of d)l[0]===1&&r.push(Gs({line:A,spanStart:p,spanLength:l[1].length})),p+=l[1].length}function ZE(){return{deletionContent:{push(e){this.value+=e,this.length++},value:"",length:0},additionContent:{push(e){this.value+=e,this.length++},value:"",length:0},deletionInfo:[],additionInfo:[],deletionDecorations:[],additionDecorations:[],deletionSegments:[],additionSegments:[]}}function VE({deletionFile:e,additionFile:t,deletionInfo:n,additionInfo:A,highlighter:o,deletionDecorations:r,additionDecorations:a,languageOverride:s,options:{theme:i=oe,...c}}){let d=s??De(e.name),u=s??De(t.name),{state:g,transformers:p}=_p(c.useTokenTransformer),l=typeof i=="string"?{...c,lang:"text",theme:i,transformers:p,decorations:void 0,defaultColor:!1,cssVariablePrefix:ge("token"),tokenizeTimeLimit:0}:{...c,lang:"text",themes:i,transformers:p,decorations:void 0,defaultColor:!1,cssVariablePrefix:ge("token"),tokenizeTimeLimit:0};return{deletionLines:e.contents===""?[]:(l.lang=d,g.lineInfo=n,l.decorations=r,ls(o.codeToHast(At(e.contents),l))),additionLines:t.contents===""?[]:(l.lang=u,l.decorations=a,g.lineInfo=A,ls(o.codeToHast(At(t.contents),l)))}}function Dn(e){let t=e.lang??De(e.name),n=e.lang??(e.prevName!=null?De(e.prevName):"text");return t==="text"&&n==="text"}var XE=-1,gl=class{constructor(e={theme:oe},t,n){f(this,"options");f(this,"onRenderUpdate");f(this,"workerManager");f(this,"__id",`diff-hunks-renderer:${++XE}`);f(this,"highlighter");f(this,"diff");f(this,"expandedHunks",new Map);f(this,"deletionAnnotations",{});f(this,"additionAnnotations",{});f(this,"computedLang","text");f(this,"renderCache");f(this,"createAnnotationElement",e=>hp(e));this.options=e,this.onRenderUpdate=t,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=NA(e.theme??oe)?rs():void 0)}cleanUp(){this.recycle(),this.expandedHunks.clear(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.highlighter=void 0,this.diff=void 0,this.clearRenderCache(),this.additionAnnotations={},this.deletionAnnotations={},this.workerManager?.cleanUpTasks(this)}clearRenderCache(){this.renderCache=void 0}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}expandHunk(e,t,n=this.getOptionsWithDefaults().expansionLineCount){let A={...this.expandedHunks.get(e)??{fromStart:0,fromEnd:0}};(t==="up"||t==="both")&&(A.fromStart+=n),(t==="down"||t==="both")&&(A.fromEnd+=n),this.renderCache?.highlighted!==!0&&this.clearRenderCache(),this.expandedHunks.set(e,A)}getExpandedHunk(e){return this.expandedHunks.get(e)??cc}getExpandedHunksMap(){return this.expandedHunks}setLineAnnotations(e){this.additionAnnotations={},this.deletionAnnotations={};for(let t of e){let n=(()=>{switch(t.side){case"deletions":return this.deletionAnnotations;case"additions":return this.additionAnnotations}})(),A=n[t.lineNumber]??[];n[t.lineNumber]=A,A.push(t)}}getUnifiedLineDecoration({lineType:e}){return{gutterLineType:e}}getSplitLineDecoration({side:e,type:t}){return t!=="change"?{gutterLineType:t}:{gutterLineType:e==="deletions"?"change-deletion":"change-addition"}}getOptionsWithDefaults(){let{diffIndicators:e="bars",diffStyle:t="split",disableBackground:n=!1,disableFileHeader:A=!1,disableLineNumbers:o=!1,disableVirtualizationBuffers:r=!1,collapsed:a=!1,expandUnchanged:s=!1,collapsedContextThreshold:i=1,expansionLineCount:c=100,hunkSeparators:d="line-info",lineDiffType:u="word-alt",maxLineDiffLength:g=1e3,overflow:p="scroll",stickyHeader:l=!1,theme:h=oe,headerRenderMode:C="default",tokenizeMaxLineLength:b=1e3,tokenizeMaxLength:m=sc,useTokenTransformer:B=!1,useCSSClasses:E=!1}=this.options;return{diffIndicators:e,diffStyle:t,disableBackground:n,disableFileHeader:A,disableLineNumbers:o,disableVirtualizationBuffers:r,collapsed:a,expandUnchanged:s,collapsedContextThreshold:i,expansionLineCount:c,hunkSeparators:d,lineDiffType:u,maxLineDiffLength:g,overflow:p,stickyHeader:l,theme:this.workerManager?.getDiffRenderOptions().theme??h,headerRenderMode:C,tokenizeMaxLineLength:b,tokenizeMaxLength:m,useTokenTransformer:B,useCSSClasses:E}}async initializeHighlighter(){return this.highlighter=await LA(wp(this.computedLang,this.options)),this.highlighter}hydrate(e){if(e==null)return;this.diff=e;let{options:t}=this.getRenderOptions(e),n=$s(e,this.getTokenizeMaxLength()),A=this.workerManager?.getDiffResultCache(e);A!=null&&!Ht(t,A.options)&&(A=void 0),this.renderCache??(this.renderCache={diff:e,highlighted:!n&&!Dn(e),options:t,result:n?void 0:A?.result,renderRange:void 0}),this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!n&&this.workerManager.highlightDiffAST(this,this.diff):this.highlighter==null&&(this.computedLang=e.lang??De(e.name),this.initializeHighlighter())}getRenderOptions(e){let t=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getDiffRenderOptions();let{theme:A,tokenizeMaxLineLength:o,lineDiffType:r,maxLineDiffLength:a}=this.getOptionsWithDefaults();return{theme:A,useTokenTransformer:Sp(this.options),tokenizeMaxLineLength:o,lineDiffType:r,maxLineDiffLength:a}})();this.getOptionsWithDefaults();let{renderCache:n}=this;return n?.result==null?{options:t,forceHighlight:!0}:!wn(e,n.diff)||!Ht(t,n.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}renderDiff(e=this.renderCache?.diff,t=io){if(e==null)return;let{expandUnchanged:n=!1,collapsedContextThreshold:A}=this.getOptionsWithDefaults(),{options:o,forceHighlight:r}=this.getRenderOptions(e),a=this.getMatchingWorkerResultCache(e,o);a!=null&&!this.hasHighlightedRenderCache(e,o)&&(this.renderCache={diff:e,highlighted:!0,renderRange:void 0,...a},r=!1),this.renderCache??(this.renderCache={diff:e,highlighted:!1,options:o,result:void 0,renderRange:void 0});let s=e.additionLines.length>0||e.deletionLines.length>0,i=!s||Dn(e)||$s(e,this.getTokenizeMaxLength()),c=!wn(e,this.renderCache.diff),d=!GA(this.renderCache.renderRange,t);if(this.workerManager?.isWorkingPool()===!0)(i||this.renderCache.result==null||!this.renderCache.highlighted&&(c||d))&&(this.renderCache.diff=e,this.renderCache.options=o,this.renderCache.highlighted=!1,(this.renderCache.result==null||c||d||r)&&(this.renderCache.result=this.workerManager.getPlainDiffAST(e,t.startingLine,t.totalLines,al(t)||n?!0:this.expandedHunks,A)),this.renderCache.renderRange=t),!i&&s&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightDiffAST(this,e);else{this.computedLang=e.lang??De(e.name);let u=this.highlighter!=null&&NA(o.theme),g=this.highlighter!=null&&wo(this.computedLang),p=!i&&g;if(this.highlighter!=null&&u&&(r||i||!this.renderCache.highlighted&&p||this.renderCache.result==null)){let{result:l,options:h}=this.renderDiffWithHighlighter(e,this.highlighter,i||!g);this.renderCache={diff:e,options:h,highlighted:p,result:l,renderRange:void 0}}(!u||!i&&!g)&&this.asyncHighlight(e).then(({result:l,options:h})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.onHighlightSuccess(e,l,h,!i)})}return this.renderCache.result!=null?this.processDiffResult(this.renderCache.diff,t,this.renderCache.result):void 0}async asyncRender(e,t=io){let{result:n}=await this.asyncHighlight(e);return this.processDiffResult(e,t,n)}createPreElement(e,t,n){let{diffIndicators:A,disableBackground:o,disableLineNumbers:r,overflow:a}=this.getOptionsWithDefaults();return yp({type:"diff",diffIndicators:A,disableBackground:o,disableLineNumbers:r,overflow:a,split:e,totalLines:t,customProperties:n})}async asyncHighlight(e){let t=$s(e,this.getTokenizeMaxLength());this.computedLang=t?"text":e.lang??De(e.name);let n=this.highlighter!=null&&NA(this.options.theme??oe),A=t||this.highlighter!=null&&wo(this.computedLang);return(this.highlighter==null||!n||!A)&&(this.highlighter=await this.initializeHighlighter()),this.renderDiffWithHighlighter(e,this.highlighter,t)}renderDiffWithHighlighter(e,t,n=!1){let{options:A}=this.getRenderOptions(e),{collapsedContextThreshold:o}=this.getOptionsWithDefaults();return{result:il(e,t,A,{forcePlainText:n,expandedHunks:n?!0:void 0,collapsedContextThreshold:o}),options:A}}onHighlightSuccess(e,t,n,A=!0){if(this.renderCache==null)return;let o=!this.renderCache.highlighted||!Ht(this.renderCache.options,n)||!wn(this.renderCache.diff,e);this.renderCache={diff:e,options:n,highlighted:A,result:t,renderRange:void 0},o&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){let n=this.workerManager?.getDiffResultCache(e);if(!(n==null||!Ht(t,n.options)))return n}hasHighlightedRenderCache(e,t){let{renderCache:n}=this;return n?.result!=null&&n.highlighted&&wn(e,n.diff)&&Ht(t,n.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}processDiffResult(e,t,{code:n,themeStyles:A,baseThemeType:o}){let{diffStyle:r,disableFileHeader:a,expandUnchanged:s,expansionLineCount:i,collapsedContextThreshold:c,hunkSeparators:d}=this.getOptionsWithDefaults();this.diff=e;let u=r==="unified",g=[],p=[],l=[],h=[],{additionLines:C,deletionLines:b}=n,m={rowCount:0,hunkSeparators:d,additionsContentAST:g,deletionsContentAST:p,unifiedContentAST:l,unifiedGutterAST:Pt(),deletionsGutterAST:Pt(),additionsGutterAST:Pt(),expansionLineCount:i,hunkData:h,incrementRowCount(v=1){m.rowCount+=v},pushToGutter(v,G){switch(v){case"unified":m.unifiedGutterAST.children.push(G);break;case"deletions":m.deletionsGutterAST.children.push(G);break;case"additions":m.additionsGutterAST.children.push(G);break}}},B=js({fileDiff:e,errorPrefix:"DiffHunksRenderer.processDiffResult"}),E={size:0,side:void 0,increment(){this.size+=1},flush(){if(r!=="unified"){if(this.size<=0||this.side==null){this.side=void 0,this.size=0;return}this.side==="additions"?(m.pushToGutter("additions",pe(void 0,"buffer",this.size)),g?.push(kn(this.size))):(m.pushToGutter("deletions",pe(void 0,"buffer",this.size)),p?.push(kn(this.size))),this.size=0,this.side=void 0}}},Q=(v,G,$,ce,P)=>{m.pushToGutter(v,gc(G,$,ce,P))};function k(v){E.flush(),r==="unified"?Ps("unified",v,m):(Ps("deletions",v,m),Ps("additions",v,m))}this.pushFileLevelAnnotations(e,r,t,m),WA({diff:e,diffStyle:r,startingLine:t.startingLine,totalLines:t.totalLines,expandedHunks:s?!0:this.expandedHunks,collapsedContextThreshold:c,callback:({hunkIndex:v,hunk:G,collapsedBefore:$,collapsedAfter:ce,additionLine:P,deletionLine:X,type:ee})=>{let Qt=X!=null?X.splitLineIndex:P.splitLineIndex,to=P!=null?P.unifiedLineIndex:X.unifiedLineIndex;r==="split"&&ee!=="change"&&E.flush(),$>0&&k({hunkIndex:v,collapsedLines:$,rangeSize:Math.max(G?.collapsedBefore??0,0),hunkSpecs:G?.hunkSpecs,isFirstHunk:v===0,isLastHunk:!1,isExpandable:!e.isPartial});let no=r==="unified"?to:Qt,Os={type:ee,hunkIndex:v,lineIndex:no,unifiedLineIndex:to,splitLineIndex:Qt,deletionLine:X,additionLine:P};if(r==="unified"){let O=this.getUnifiedInjectedRowsForLine?.(Os);O?.before!=null&&dl(O.before,m);let Be=X!=null?b[X.lineIndex]:void 0,he=P!=null?C[P.lineIndex]:void 0;if(Be==null&&he==null){let Ke="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(Ke,{file:e.name}),new Error(Ke)}let Ut=ee==="change"?P!=null?"change-addition":"change-deletion":ee,Te=this.getUnifiedLineDecoration({type:ee,lineType:Ut,additionLineIndex:P?.lineIndex,deletionLineIndex:X?.lineIndex});Q("unified",Te.gutterLineType,P!=null?P.lineNumber:X.lineNumber,`${to},${Qt}`,Te.gutterProperties),he!=null?he=ZA(he,Te.contentProperties):Be!=null&&(Be=ZA(Be,Te.contentProperties)),zA({diffStyle:"unified",type:ee,deletionLine:Be,additionLine:he,unifiedSpan:this.getAnnotations("unified",X?.lineNumber,P?.lineNumber,v,no),createAnnotationElement:Ke=>this.createAnnotationElement(Ke),context:m}),O?.after!=null&&dl(O.after,m)}else{let O=this.getSplitInjectedRowsForLine?.(Os);O?.before!=null&&ul(O.before,m,E);let Be=X!=null?b[X.lineIndex]:void 0,he=P!=null?C[P.lineIndex]:void 0,Ut=this.getSplitLineDecoration({side:"deletions",type:ee,lineIndex:X?.lineIndex}),Te=this.getSplitLineDecoration({side:"additions",type:ee,lineIndex:P?.lineIndex});if(Be==null&&he==null){let Qe="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(Qe,{file:e.name}),new Error(Qe)}let Ke=(()=>{if(ee==="change"){if(he==null)return"additions";if(Be==null)return"deletions"}})();if(Ke!=null){if(E.side!=null&&E.side!==Ke)throw new Error("DiffHunksRenderer.processDiffResult: iterateOverDiff, invalid pending splits");E.side=Ke,E.increment()}let Ws=this.getAnnotations("split",X?.lineNumber,P?.lineNumber,v,no);if(Ws!=null&&E.size>0&&E.flush(),X!=null){let Qe=ZA(Be,Ut.contentProperties);Q("deletions",Ut.gutterLineType,X.lineNumber,`${X.unifiedLineIndex},${Qt}`,Ut.gutterProperties),Qe!=null&&(Be=Qe)}if(P!=null){let Qe=ZA(he,Te.contentProperties);Q("additions",Te.gutterLineType,P.lineNumber,`${P.unifiedLineIndex},${Qt}`,Te.gutterProperties),Qe!=null&&(he=Qe)}zA({diffStyle:"split",type:ee,additionLine:he,deletionLine:Be,...Ws,createAnnotationElement:Qe=>this.createAnnotationElement(Qe),context:m}),O?.after!=null&&ul(O.after,m,E)}let Js=r==="split"&&G!=null&&Qt===G.splitLineStart+G.splitLineCount-1,_l=Js?G.noEOFCRDeletions:!1,Dl=Js?G.noEOFCRAdditions:!1,Ao=(X?.noEOFCR??!1)||_l,oo=(P?.noEOFCR??!1)||Dl;if(oo||Ao){if(r==="split"&&E.flush(),Ao){let O=ee==="context"||ee==="context-expanded"?ee:"change-deletion";r==="unified"?(m.unifiedContentAST.push(In(O)),m.pushToGutter("unified",pe(O,"metadata",1))):(m.deletionsContentAST.push(In(O)),m.pushToGutter("deletions",pe(O,"metadata",1)),oo||(m.pushToGutter("additions",pe(void 0,"buffer",1)),m.additionsContentAST.push(kn(1))))}if(oo){let O=ee==="context"||ee==="context-expanded"?ee:"change-addition";r==="unified"?(m.unifiedContentAST.push(In(O)),m.pushToGutter("unified",pe(O,"metadata",1))):(m.additionsContentAST.push(In(O)),m.pushToGutter("additions",pe(O,"metadata",1)),Ao||(m.pushToGutter("deletions",pe(void 0,"buffer",1)),m.deletionsContentAST.push(kn(1))))}m.incrementRowCount(1)}ce>0&&d!=="simple"&&k({hunkIndex:ee==="context-expanded"?v:v+1,collapsedLines:ce,rangeSize:B,hunkSpecs:void 0,isFirstHunk:!1,isLastHunk:!0,isExpandable:!e.isPartial}),m.incrementRowCount(1)}}),r==="split"&&E.flush();let F=Math.max(rl(e.hunks),e.additionLines.length??0,e.deletionLines.length??0),_=t.bufferBefore>0||t.bufferAfter>0,D=!u&&e.type!=="deleted",L=!u&&e.type!=="new",R=m.rowCount>0||_;g=D&&R?g:void 0,p=L&&R?p:void 0,l=u&&R?l:void 0;let x=this.createPreElement(p!=null&&g!=null,F);return{unifiedGutterAST:u&&R?m.unifiedGutterAST.children:void 0,unifiedContentAST:l,deletionsGutterAST:L&&R?m.deletionsGutterAST.children:void 0,deletionsContentAST:p,additionsGutterAST:D&&R?m.additionsGutterAST.children:void 0,additionsContentAST:g,hunkData:h,preNode:x,themeStyles:A,baseThemeType:o,headerElement:a?void 0:this.renderHeader(this.diff),totalLines:F,rowCount:m.rowCount,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:""}}renderCodeAST(e,t){let n=e==="unified"?t.unifiedGutterAST:e==="deletions"?t.deletionsGutterAST:t.additionsGutterAST,A=e==="unified"?t.unifiedContentAST:e==="deletions"?t.deletionsContentAST:t.additionsContentAST;if(n==null||A==null)return;let o=Pt(n);return o.properties.style=`grid-row: span ${t.rowCount}`,[o,Mp(A,t.rowCount)]}renderFullAST(e,t=[]){let n=this.getOptionsWithDefaults().hunkSeparators==="line-info",A=this.renderCodeAST("unified",e);if(A!=null)return t.push(M({tagName:"code",children:A,properties:{"data-code":"","data-container-size":n?"":void 0,"data-unified":""}})),{...e.preNode,children:t};let o=this.renderCodeAST("deletions",e);o!=null&&t.push(M({tagName:"code",children:o,properties:{"data-code":"","data-container-size":n?"":void 0,"data-deletions":""}}));let r=this.renderCodeAST("additions",e);return r!=null&&t.push(M({tagName:"code",children:r,properties:{"data-code":"","data-container-size":n?"":void 0,"data-additions":""}})),{...e.preNode,children:t}}renderFullHTML(e,t=[]){return Ee(this.renderFullAST(e,t))}renderPartialHTML(e,t){return t==null?Ee(e):Ee(M({tagName:"code",children:e,properties:{"data-code":"","data-container-size":this.getOptionsWithDefaults().hunkSeparators==="line-info"?"":void 0,[`data-${t}`]:""}}))}pushFileLevelAnnotations(e,t,n,A){if(!xp(n))return;let o=e.type!=="new"?sl(ms(this.deletionAnnotations)):[],r=e.type!=="deleted"?sl(ms(this.additionAnnotations)):[];if(o.length===0&&r.length===0)return;let a=-1,s=-1,{createAnnotationElement:i}=this;if(t==="unified"){zA({diffStyle:t,type:"context",unifiedSpan:{type:"annotation",hunkIndex:a,lineIndex:s,annotations:o.concat(r)},createAnnotationElement:i,context:A});return}zA({diffStyle:t,type:"context",deletionSpan:{type:"annotation",hunkIndex:a,lineIndex:s,annotations:o},additionSpan:{type:"annotation",hunkIndex:a,lineIndex:s,annotations:r},createAnnotationElement:i,context:A})}getAnnotations(e,t,n,A,o){let r={type:"annotation",hunkIndex:A,lineIndex:o,annotations:[]};if(t!=null)for(let s of this.deletionAnnotations[t]??[])r.annotations.push(Et(s));let a={type:"annotation",hunkIndex:A,lineIndex:o,annotations:[]};if(n!=null)for(let s of this.additionAnnotations[n]??[])(e==="unified"?r:a).annotations.push(Et(s));if(e==="unified")return r.annotations.length>0?r:void 0;if(!(a.annotations.length===0&&r.annotations.length===0))return{deletionSpan:r,additionSpan:a}}renderHeader(e){let{headerRenderMode:t,stickyHeader:n}=this.getOptionsWithDefaults();return Ep({fileOrDiff:e,mode:t,stickyHeader:n})}};function sl(e){return e?.map(t=>Et(t))??[]}var ey=new Intl.PluralRules("en-US");function cl(e){return`${e} unmodified line${ey.select(e)==="one"?"":"s"}`}function dl(e,t){for(let n of e)t.unifiedContentAST.push(n.content),t.pushToGutter("unified",n.gutter),t.incrementRowCount(1)}function ul(e,t,n){for(let{deletion:A,addition:o}of e){if(A==null&&o==null)continue;let r=A!=null&&o!=null?void 0:A==null?"deletions":"additions";(r==null||n.side!==r)&&n.flush(),A!=null&&(t.deletionsContentAST.push(A.content),t.pushToGutter("deletions",A.gutter)),o!=null&&(t.additionsContentAST.push(o.content),t.pushToGutter("additions",o.gutter)),r!=null&&(n.side=r,n.increment()),t.incrementRowCount(1)}}function zA({diffStyle:e,type:t,deletionLine:n,additionLine:A,unifiedSpan:o,deletionSpan:r,additionSpan:a,createAnnotationElement:s,context:i}){let c=!1;if(e==="unified"){if(A!=null?i.unifiedContentAST.push(A):n!=null&&i.unifiedContentAST.push(n),o!=null){let d=t==="change"?n!=null?"change-deletion":"change-addition":t;i.unifiedContentAST.push(s(o)),i.pushToGutter("unified",pe(d,"annotation",1)),c=!0}}else if(e==="split"){if(n!=null&&i.deletionsContentAST.push(n),A!=null&&i.additionsContentAST.push(A),r!=null){let d=t==="change"?n!=null?"change-deletion":"context":t;i.deletionsContentAST.push(s(r)),i.pushToGutter("deletions",pe(d,"annotation",1)),c=!0}if(a!=null){let d=t==="change"?A!=null?"change-addition":"context":t;i.additionsContentAST.push(s(a)),i.pushToGutter("additions",pe(d,"annotation",1)),c=!0}}c&&i.incrementRowCount(1)}function Ps(e,{hunkIndex:t,collapsedLines:n,rangeSize:A,hunkSpecs:o,isFirstHunk:r,isLastHunk:a,isExpandable:s},i){if(n<=0)return;let c=e==="unified"?i.unifiedContentAST:e==="deletions"?i.deletionsContentAST:i.additionsContentAST;if(i.hunkSeparators==="metadata"){o!=null&&(i.pushToGutter(e,wt({type:"metadata",content:o,isFirstHunk:r,isLastHunk:a})),c.push(wt({type:"metadata",content:o,isFirstHunk:r,isLastHunk:a})),e!=="additions"&&i.incrementRowCount(1));return}if(i.hunkSeparators==="simple"){t>0&&(i.pushToGutter(e,wt({type:"simple",isFirstHunk:r,isLastHunk:!1})),c.push(wt({type:"simple",isFirstHunk:r,isLastHunk:!1})),e!=="additions"&&i.incrementRowCount(1));return}let d=ol(e,t),u=A>i.expansionLineCount,g=s?t:void 0;i.pushToGutter(e,wt({type:i.hunkSeparators,content:cl(n),expandIndex:g,chunked:u,slotName:d,isFirstHunk:r,isLastHunk:a})),c.push(wt({type:i.hunkSeparators,content:cl(n),expandIndex:g,chunked:u,slotName:d,isFirstHunk:r,isLastHunk:a})),e!=="additions"&&i.incrementRowCount(1),i.hunkData.push({slotName:d,hunkIndex:t,lines:n,type:e,expandable:s?{up:!r,down:!a,chunked:u}:void 0})}function ZA(e,t){return e==null||e.type!=="element"||t==null?e:{...e,properties:{...e.properties,...t}}}function $s(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function pl(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function ll(e,t){return e.slotName===t.slotName&&e.hunkIndex===t.hunkIndex&&e.lines===t.lines&&e.type===t.type&&e.expandable?.chunked===t.expandable?.chunked&&e.expandable?.up===t.expandable?.up&&e.expandable?.down===t.expandable?.down}function ml(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:e?.useTokenTransformer,tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,diffStyle:e?.diffStyle,diffIndicators:e?.diffIndicators,disableBackground:e?.disableBackground,hunkSeparators:typeof e?.hunkSeparators=="function"?"custom":e?.hunkSeparators,expandUnchanged:e?.expandUnchanged,collapsedContextThreshold:e?.collapsedContextThreshold,lineDiffType:e?.lineDiffType,maxLineDiffLength:e?.maxLineDiffLength,expansionLineCount:e?.expansionLineCount,headerRenderMode:e?.renderCustomHeader!=null?"custom":"default"}}var ty=-1,qs,Ys=(qs=class{constructor(e={theme:oe},t,n=!1){f(this,"options");f(this,"workerManager");f(this,"isContainerManaged");f(this,"__id",`file-diff:${++ty}`);f(this,"type","file-diff");f(this,"fileContainer");f(this,"spriteSVG");f(this,"pre");f(this,"codeUnified");f(this,"codeDeletions");f(this,"codeAdditions");f(this,"bufferBefore");f(this,"bufferAfter");f(this,"themeCSSStyle");f(this,"appliedThemeCSS");f(this,"hasAdoptedThemeCSS",!1);f(this,"unsafeCSSStyle");f(this,"appliedUnsafeCSS");f(this,"gutterUtilityContent");f(this,"headerElement");f(this,"headerPrefix");f(this,"headerMetadata");f(this,"headerCustom");f(this,"separatorCache",new Map);f(this,"errorWrapper");f(this,"placeHolder");f(this,"hunksRenderer");f(this,"resizeManager");f(this,"scrollSyncManager");f(this,"interactionManager");f(this,"annotationCache",new Map);f(this,"lineAnnotations",[]);f(this,"managersDirty",!1);f(this,"deletionFile");f(this,"additionFile");f(this,"fileDiff");f(this,"renderRange");f(this,"appliedPreAttributes");f(this,"lastRenderedHeaderHTML");f(this,"cachedHeaderHTML");f(this,"lastRowCount");f(this,"mounted",!1);f(this,"enabled",!0);f(this,"handleHighlightRender",()=>{this.rerender()});f(this,"getLineIndex",(e,t="additions")=>{if(this.fileDiff==null)return;let n=this.fileDiff.hunks.at(-1),A,o;e:for(let r of this.fileDiff.hunks){let a=t==="deletions"?r.deletionStart:r.additionStart,s=t==="deletions"?r.deletionCount:r.additionCount,i=r.splitLineStart,c=r.unifiedLineStart;if(e<a){let d=a-e;A=Math.max(c-d,0),o=Math.max(i-d,0);break e}if(e>=a+s){if(r===n){let d=e-(a+s);A=c+r.unifiedLineCount+d,o=i+r.splitLineCount+d;break e}continue}for(let d of r.hunkContent)if(d.type==="context")if(e<a+d.lines){let u=e-a;o=i+u,A=c+u;break e}else a+=d.lines,i+=d.lines,c+=d.lines;else{let u=t==="deletions"?d.deletions:d.additions;if(e<a+u){let g=e-a;A=c+(t==="additions"?d.deletions:0)+g,o=i+g;break e}else a+=u,i+=Math.max(d.deletions,d.additions),c+=d.deletions+d.additions}break e}if(!(A==null||o==null))return[A,o]});f(this,"getHoveredLine",()=>this.interactionManager.getHoveredLine());f(this,"handleExpandHunk",(e,t,n)=>{this.expandHunk(e,t,n)});f(this,"expandHunk",(e,t,n)=>{this.hunksRenderer.expandHunk(e,t,n),this.rerender()});this.options=e,this.workerManager=t,this.isContainerManaged=n,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new zc,this.scrollSyncManager=new Al,this.interactionManager=new Wc("diff",yo(e,typeof e.hunkSeparators=="function"||(e.hunkSeparators??"line-info")==="line-info"||e.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex)),this.workerManager?.subscribeToThemeChanges(this),this.enabled=!0}getHunksRendererOptions(e){return ml(e)}createHunksRenderer(e){return new gl(this.getHunksRendererOptions(e),this.handleHighlightRender,this.workerManager)}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.hunksRenderer.setOptions(this.getHunksRendererOptions(e)),this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(yo(this.options,typeof this.options.hunkSeparators=="function"||(this.options.hunkSeparators??"line-info")==="line-info"||this.options.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;let t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType===t?!1:(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!Sn(this.appliedThemeCSS.theme,this.options.theme??oe)}setLineAnnotations(e){this.lineAnnotations=e}canPartiallyRender(e,t,n){return!(e||t||n||typeof this.options.hunkSeparators=="function")}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}let{diffStyle:e="split",overflow:t="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,t==="wrap"),t==="scroll"&&e==="split"?this.scrollSyncManager.setup(this.pre,this.codeDeletions,this.codeAdditions):this.scrollSyncManager.cleanUp(),this.managersDirty=!1}cleanUp(e=!1){this.emitPostRender(!0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.annotationCache.clear(),this.pre=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,this.bufferBefore=void 0,this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.placeHolder=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper=void 0,this.spriteSVG=void 0,this.lastRowCount=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,e?this.hunksRenderer.recycle():(this.hunksRenderer.cleanUp(),this.workerManager=void 0,this.fileDiff=void 0,this.deletionFile=void 0,this.additionFile=void 0),this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){let{fileContainer:t,prerenderedHTML:n,preventEmit:A=!1,lineAnnotations:o,oldFile:r,newFile:a,fileDiff:s}=e;this.hydrateElements(t,n),oy(this.pre,ny({fileDiff:s,oldFile:r,newFile:a}),this.options.collapsed)||ry(this.headerElement,Ay({fileDiff:s,oldFile:r,newFile:a}),this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({fileDiff:s,oldFile:r,newFile:a,lineAnnotations:o}),A||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),Tp(e,t);for(let n of e.shadowRoot?.children??[]){if(n instanceof SVGElement){this.spriteSVG=n;continue}if(n instanceof HTMLElement){if(n instanceof HTMLPreElement){this.pre=n;for(let A of n.children)!(A instanceof HTMLElement)||A.tagName.toLowerCase()!=="code"||("deletions"in A.dataset&&(this.codeDeletions=A),"additions"in A.dataset&&(this.codeAdditions=A),"unified"in A.dataset&&(this.codeUnified=A));continue}if("diffsHeader"in n.dataset){this.headerElement=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-theme-css")){this.themeCSSStyle=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=n,this.appliedUnsafeCSS=n.textContent;continue}}}this.pre!=null&&(this.syncCodeNodesFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({fileDiff:e,oldFile:t,newFile:n,lineAnnotations:A}){this.lineAnnotations=A??this.lineAnnotations,this.additionFile=n,this.deletionFile=t,this.fileDiff=e??(t!=null&&n!=null?Rs(t,n,this.options.parseDiffOptions):void 0),this.pre!=null&&(this.syncInteractionOptions(),this.hunksRenderer.hydrate(this.fileDiff),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||this.render({forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.hunksRenderer.clearRenderCache(),this.rerender()}render({oldFile:e,newFile:t,fileDiff:n,deferManagers:A=!1,forceRender:o=!1,preventEmit:r=!1,lineAnnotations:a,fileContainer:s,containerWrapper:i,renderRange:c}){if(!this.enabled)throw new Error("FileDiff.render: attempting to call render after cleaned up");let{collapsed:d=!1,themeType:u="system"}=this.options,g=d?void 0:c,p=this.hasThemeChanged(),l=e!=null&&t!=null&&(!is(e,this.deletionFile)||!is(t,this.additionFile)),h=n!=null&&n!==this.fileDiff,C=a!=null&&(a.length>0||this.lineAnnotations.length>0)?a!==this.lineAnnotations:!1;if(!d&&GA(g,this.renderRange)&&!o&&!C&&!p&&(n!=null&&n===this.fileDiff||n==null&&!l))return this.applyCachedThemeState(u);let{renderRange:b}=this;if(this.renderRange=g,this.deletionFile=e,this.additionFile=t,n!=null?this.fileDiff=n:e!=null&&t!=null&&l&&(h=!0,this.fileDiff=Rs(e,t,this.options.parseDiffOptions)),h&&(this.cachedHeaderHTML=void 0),a!=null&&this.setLineAnnotations(a),this.fileDiff==null)return!1;this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options)),this.syncInteractionOptions(),this.hunksRenderer.setLineAnnotations(this.lineAnnotations);let{disableErrorHandling:m=!1,disableFileHeader:B=!1}=this.options;if(B&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),s=this.getOrCreateFileContainer(s,i),this.applyCachedThemeState(u),d){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{let E=this.hunksRenderer.renderDiff(this.fileDiff,dc);E!=null&&this.applyThemeState(s,E.themeStyles,u,E.baseThemeType),E?.headerElement!=null&&this.applyHeaderToDOM(E.headerElement,s),this.renderSeparators([]),this.injectUnsafeCSS()}catch(E){if(m)throw E;console.error(E),E instanceof Error&&this.applyErrorToDOM(E,s)}return r||this.emitPostRender(),!0}try{let E=this.getOrCreatePreNode(s);if(!(this.canPartiallyRender(o,C,l||h||p)&&this.applyPartialRender({previousRenderRange:b,renderRange:g}))){let Q=this.hunksRenderer.renderDiff(this.fileDiff,g);if(Q==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(s,Q.themeStyles,u,Q.baseThemeType),Q.headerElement!=null&&this.applyHeaderToDOM(Q.headerElement,s),Q.additionsContentAST!=null||Q.deletionsContentAST!=null||Q.unifiedContentAST!=null?this.applyHunksToDOM(E,Q):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(Q.hunkData)}this.applyBuffers(E,g),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,A||this.flushManagers()}catch(E){if(m)throw E;console.error(E),E instanceof Error&&this.applyErrorToDOM(E,s)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){let{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;this.options.onPostRender?.(t,this,"unmount");return}if(t==null)return;let A=this.mounted?"update":"mount";this.mounted=!0,n?.(t,this,A)}removeRenderedCode(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(let{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();for(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){let t=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:"open"});this.placeHolder=document.createElement("div"),this.placeHolder.dataset.placeholder="",t.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty("height",`${e}px`),!0}primeHighlightCache(){let{fileDiff:e,workerManager:t}=this;if(e==null||t==null||Dn(e))return;let n=this.options.tokenizeMaxLength??1e5;Math.max(e.additionLines.length,e.deletionLines.length)>n||t.primeDiffHighlightCache(e)}cleanChildNodes(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.codeAdditions?.remove(),this.codeDeletions?.remove(),this.codeUnified?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.headerPrefix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.codeAdditions=void 0,this.codeDeletions=void 0,this.codeUnified=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderSeparators(e){let{hunkSeparators:t}=this.options;if(this.isContainerManaged||this.fileContainer==null||typeof t!="function"){for(let{element:A}of this.separatorCache.values())A.remove();this.separatorCache.clear();return}let n=new Map(this.separatorCache);for(let A of e){let o=A.slotName,r=this.separatorCache.get(o);if(r==null||!ll(A,r.hunkData)){r?.element.remove();let a=document.createElement("div");a.style.display="contents",a.slot=A.slotName;let s=t(A,this);s!=null&&a.appendChild(s),this.fileContainer.appendChild(a),r={element:a,hunkData:A},this.separatorCache.set(o,r)}n.delete(o)}for(let[A,{element:o}]of n.entries())this.separatorCache.delete(A),o.remove()}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(let{element:n}of this.annotationCache.values())n.remove();this.annotationCache.clear();return}let e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(let[n,A]of this.lineAnnotations.entries()){let o=`${n}-${Et(A)}`,r=this.annotationCache.get(o);if(r==null||!pl(A,r.annotation)){r?.element.remove();let a=t(A);if(a==null)continue;r={element:Gp(Et(A)),annotation:A},r.element.appendChild(a),this.fileContainer.appendChild(r.element),this.annotationCache.set(o,r)}e.delete(o)}for(let[n,{element:A}]of e.entries())this.annotationCache.delete(n),A.remove()}renderGutterUtility(){let{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let n=Hp();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}getOrCreateFileContainer(e,t){let{fileContainer:n}=this,A=e??n??document.createElement("diffs-container"),o=n!==A;return o&&this.emitPostRender(!0),this.fileContainer=A,n!=null&&o&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),o&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){let{shadowRoot:t}=e;if(t!=null)for(let n of t.children)n instanceof SVGElement?this.spriteSVG??(this.spriteSVG=n):bs(n)&&n.hasAttribute("data-theme-css")?(this.themeCSSStyle??(this.themeCSSStyle=n),this.hasAdoptedThemeCSS=!0):bs(n)&&n.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??(this.unsafeCSSStyle=n),this.appliedUnsafeCSS??(this.appliedUnsafeCSS=this.options.unsafeCSS??void 0))}ensureSpriteSVG(e){let t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){let n=document.createElement("div");n.innerHTML=Lp;let A=n.firstChild;A instanceof SVGElement&&(this.spriteSVG=A)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){let t=e.shadowRoot??e.attachShadow({mode:"open"});return this.pre==null?(this.pre=document.createElement("pre"),this.appliedPreAttributes=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(t.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodesFromPre(e){this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0;for(let t of Array.from(e.children))t instanceof HTMLElement&&(t.hasAttribute("data-unified")?this.codeUnified=t:t.hasAttribute("data-deletions")?this.codeDeletions=t:t.hasAttribute("data-additions")&&(this.codeAdditions=t))}applyHeaderToDOM(e,t){this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;let{fileDiff:n}=this,A=this.cachedHeaderHTML??Ee(e);if(this.cachedHeaderHTML=A,A!==this.lastRenderedHeaderHTML){let c=document.createElement("div");c.innerHTML=A;let d=c.firstElementChild;if(!(d instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(d,this.headerElement):t.shadowRoot?.prepend(d),this.headerElement=d,this.lastRenderedHeaderHTML=A}if(this.isContainerManaged||n==null)return;let{renderCustomHeader:o,renderHeaderPrefix:r,renderHeaderMetadata:a}=this.options;if(o!=null){let c=o(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,xn,c),this.headerPrefix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerMetadata=void 0;return}let s=r?.(n)??void 0,i=a?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Fn,s),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,vn,i),this.headerCustom?.remove(),this.headerCustom=void 0}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,n,A){if(A==null){t?.remove();return}let o=t??this.createHeaderSlotElement(n);return t==null&&e.appendChild(o),this.replaceHeaderSlotContent(o,A),o}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){let t=document.createElement("div");return t.slot=e,t}injectUnsafeCSS(){let{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===""){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}this.unsafeCSSStyle?.parentNode===t&&this.appliedUnsafeCSS===e||(this.unsafeCSSStyle??(this.unsafeCSSStyle=jp()),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=$p(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,A){let o=e.shadowRoot??e.attachShadow({mode:"open"}),r=A??n,a=this.options.theme??oe,s=typeof a=="string"?a:{...a},i=yn(o);if(this.themeCSSStyle?.parentNode===o&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===r&&this.appliedThemeCSS.scrollbarGutter===i){this.appliedThemeCSS.theme=s;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===o){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:s,themeStyles:t,themeType:r,baseThemeType:A,scrollbarGutter:i};return}this.themeCSSStyle=Op({shadowRoot:o,currentNode:this.themeCSSStyle,themeCSS:qp(t,r,i)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:s,themeStyles:t,themeType:r,baseThemeType:A,scrollbarGutter:i}:void 0}hydrateMeasuredScrollbar(){let e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=Yp(this.themeCSSStyle.textContent??"",yn(e)))}applyHunksToDOM(e,t){let{overflow:n="scroll"}=this.options,A=(this.options.hunkSeparators??"line-info")==="line-info",o=n==="wrap"?t.rowCount:void 0;this.cleanupErrorWrapper(),this.applyPreNodeAttributes(e,t);let r=!1,a=[],s=this.hunksRenderer.renderCodeAST("unified",t),i=this.hunksRenderer.renderCodeAST("deletions",t),c=this.hunksRenderer.renderCodeAST("additions",t);s!=null?(r=this.codeUnified==null||this.codeAdditions!=null||this.codeDeletions!=null,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.codeUnified=PA({code:this.codeUnified,columnType:"unified",rowSpan:o,containerSize:A}),this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(s),a.push(this.codeUnified)):i!=null||c!=null?(i!=null?(r=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=PA({code:this.codeDeletions,columnType:"deletions",rowSpan:o,containerSize:A}),this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(i),a.push(this.codeDeletions)):(this.codeDeletions?.remove(),this.codeDeletions=void 0),c!=null?(r=r||this.codeAdditions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeAdditions=PA({code:this.codeAdditions,columnType:"additions",rowSpan:o,containerSize:A}),this.codeAdditions.innerHTML=this.hunksRenderer.renderPartialHTML(c),a.push(this.codeAdditions)):(this.codeAdditions?.remove(),this.codeAdditions=void 0)):(this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0),a.length===0?e.textContent="":r&&e.replaceChildren(...a),this.lastRowCount=t.rowCount}applyPartialRender({previousRenderRange:e,renderRange:t}){let{pre:n,codeUnified:A,codeAdditions:o,codeDeletions:r,options:{diffStyle:a="split"}}=this;if(n==null||e==null||t==null||!Number.isFinite(e.totalLines)||!Number.isFinite(t.totalLines)||this.lastRowCount==null)return!1;let s=this.getCodeColumns(a,A,r,o);if(s==null)return!1;let i=e.startingLine,c=t.startingLine,d=i+e.totalLines,u=c+t.totalLines,g=Math.max(i,c),p=Math.min(d,u);if(p<=g)return!1;let l=Math.max(0,g-i),h=Math.max(0,d-p),C=this.trimColumns({columns:s,trimStart:l,trimEnd:h,previousStart:i,overlapStart:g,overlapEnd:p,diffStyle:a});if(C<0)throw new Error("applyPartialRender: failed to trim to overlap");if(this.lastRowCount<C)throw new Error("applyPartialRender: trimmed beyond DOM row count");let b=this.lastRowCount-C,m=(k,F)=>{if(!(F<=0||this.fileDiff==null))return this.hunksRenderer.renderDiff(this.fileDiff,{startingLine:k,totalLines:F,bufferBefore:0,bufferAfter:0})},B=m(c,Math.max(g-c,0));if(B==null&&c<g)return!1;let E=m(p,Math.max(u-p,0));if(E==null&&u>p)return!1;let Q=(k,F)=>{if(k!=null){if(a==="unified"&&!Array.isArray(s))this.insertPartialHTML(a,s,k,F);else if(a==="split"&&Array.isArray(s))this.insertPartialHTML(a,s,k,F);else throw new Error("FileDiff.applyPartialRender.applyChunk: invalid chunk application");b+=k.rowCount}};return this.cleanupErrorWrapper(),Q(B,"afterbegin"),Q(E,"beforeend"),this.lastRowCount!==b&&(this.applyRowSpan(a,s,b),this.lastRowCount=b),!0}insertPartialHTML(e,t,n,A){if(e==="unified"&&!Array.isArray(t)){let o=this.hunksRenderer.renderCodeAST("unified",n);this.renderPartialColumn(t,o,A)}else if(e==="split"&&Array.isArray(t)){let o=this.hunksRenderer.renderCodeAST("deletions",n),r=this.hunksRenderer.renderCodeAST("additions",n);this.renderPartialColumn(t[0],o,A),this.renderPartialColumn(t[1],r,A)}else throw new Error("FileDiff.insertPartialHTML: Invalid argument composition")}renderPartialColumn(e,t,n){if(e==null||t==null)return;let A=fl(t[0]),o=fl(t[1]);if(A==null||o==null)throw new Error("FileDiff.insertPartialHTML: Unexpected AST structure");let r=o.at(0);n==="beforeend"&&r?.type==="element"&&typeof r.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(r.properties["data-buffer-size"],e.content.children[e.content.children.length-1],e.gutter.children[e.gutter.children.length-1],A,o,!0);let a=o.at(-1);n==="afterbegin"&&a?.type==="element"&&typeof a.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(a.properties["data-buffer-size"],e.content.children[0],e.gutter.children[0],A,o,!1),e.gutter.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(A)),e.content.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(o))}mergeBuffersIfNecessary(e,t,n,A,o,r){if(!(t instanceof HTMLElement)||!(n instanceof HTMLElement))return;let a=this.getBufferSize(t.dataset);a!=null&&(r?(A.shift(),o.shift()):(A.pop(),o.pop()),this.updateBufferSize(t,a+e),this.updateBufferSize(n,a+e))}applyRowSpan(e,t,n){let A=o=>{o!=null&&(o.gutter.style.setProperty("grid-row",`span ${n}`),o.content.style.setProperty("grid-row",`span ${n}`))};if(e==="unified"&&!Array.isArray(t))A(t);else if(e==="split"&&Array.isArray(t))A(t[0]),A(t[1]);else throw new Error("dun fuuuuked up")}trimColumnRows(e,t,n){let A=0,o=0,r=0,a=!1,s=n>=0;if(e==null)return 0;let i=Array.from(e.content.children),c=Array.from(e.gutter.children);if(i.length!==c.length)throw new Error("FileDiff.trimColumnRows: columns do not match");for(;r<i.length&&!(t<=0&&!s&&!a);){let d=c[r],u=i[r];if(r++,!(d instanceof HTMLElement)||!(u instanceof HTMLElement))throw console.error({gutterElement:d,contentElement:u}),new Error("FileDiff.trimColumnRows: invalid row elements");if(a&&(a=!1,d.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in u.dataset||d.dataset.gutterBuffer==="metadata"&&"noNewline"in u.dataset)){d.remove(),u.remove(),o++;continue}if("lineIndex"in d.dataset&&"lineIndex"in u.dataset){(t>0||s&&A>=n)&&(d.remove(),u.remove(),t>0&&(t--,t===0&&(a=!0)),o++),A++;continue}if("separator"in d.dataset&&"separator"in u.dataset){(t>0||s&&A>=n)&&(d.remove(),u.remove(),o++);continue}if(d.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in u.dataset){(t>0||s&&A>=n)&&(d.remove(),u.remove(),o++);continue}if(d.dataset.gutterBuffer==="metadata"&&"noNewline"in u.dataset){(t>0||s&&A>=n)&&(d.remove(),u.remove(),o++);continue}if(d.dataset.gutterBuffer==="buffer"&&"contentBuffer"in u.dataset){let g=this.getBufferSize(u.dataset);if(g==null)throw new Error("FileDiff.trimColumnRows: invalid element");if(t>0){let p=Math.min(t,g),l=g-p;l>0?(this.updateBufferSize(d,l),this.updateBufferSize(u,l),o+=p):(d.remove(),u.remove(),o+=g),t-=p,t===0&&l===0&&(a=!0)}else if(s){let p=A,l=A+g-1;if(n<=p)d.remove(),u.remove(),o+=g;else if(n<=l){let h=l-n+1,C=g-h;this.updateBufferSize(d,C),this.updateBufferSize(u,C),o+=h}}A+=g;continue}throw console.error({gutterElement:d,contentElement:u}),new Error("FileDiff.trimColumnRows: unknown row elements")}return o}trimColumns({columns:e,diffStyle:t,overlapEnd:n,overlapStart:A,previousStart:o,trimEnd:r,trimStart:a}){let s=Math.max(0,A-o),i=n-o;if(i<0)throw new Error("FileDiff.trimColumns: overlap ends before previous");let c=a>0,d=r>0;if(!c&&!d)return 0;let u=c?s:0,g=d?i:-1;if(t==="unified"&&!Array.isArray(e))return this.trimColumnRows(e,u,g);if(t==="split"&&Array.isArray(e)){let p=this.trimColumnRows(e[0],u,g),l=this.trimColumnRows(e[1],u,g);if(e[0]!=null&&e[1]!=null&&p!==l)throw new Error("FileDiff.trimColumns: split columns out of sync");return e[0]!=null?p:l}else throw console.error({diffStyle:t,columns:e}),new Error("FileDiff.trimColumns: Invalid columns for diffType")}getBufferSize(e){let t=Number.parseInt(e?.bufferSize??"",10);return Number.isNaN(t)?void 0:t}updateBufferSize(e,t){e.dataset.bufferSize=`${t}`,e.style.setProperty("grid-row",`span ${t}`),e.style.setProperty("min-height",`calc(${t} * 1lh)`)}getCodeColumns(e,t,n,A){function o(r){if(r==null)return;let a=r.children[0],s=r.children[1];if(!(!(a instanceof HTMLElement)||!(s instanceof HTMLElement)||a.dataset.gutter==null||s.dataset.content==null))return{gutter:a,content:s}}if(e==="unified")return o(t);{let r=o(n),a=o(A);return r!=null||a!=null?[r,a]:void 0}}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==null&&(this.bufferBefore=document.createElement("div"),this.bufferBefore.dataset.virtualizerBuffer="before",e.before(this.bufferBefore)),this.bufferBefore.style.setProperty("height",`${t.bufferBefore}px`),this.bufferBefore.style.setProperty("contain","strict")):this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),t.bufferAfter>0?(this.bufferAfter==null&&(this.bufferAfter=document.createElement("div"),this.bufferAfter.dataset.virtualizerBuffer="after",e.after(this.bufferAfter)),this.bufferAfter.style.setProperty("height",`${t.bufferAfter}px`),this.bufferAfter.style.setProperty("contain","strict")):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyPreNodeAttributes(e,{additionsContentAST:t,deletionsContentAST:n,totalLines:A},o){let{diffIndicators:r="bars",disableBackground:a=!1,disableLineNumbers:s=!1,overflow:i="scroll",diffStyle:c="split"}=this.options,d={type:"diff",diffIndicators:r,disableBackground:a,disableLineNumbers:s,overflow:i,split:c==="unified"?!1:t!=null&&n!=null,totalLines:A,customProperties:o};Np(d,this.appliedPreAttributes)||(Kp(e,d),this.appliedPreAttributes=d)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;let n=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??(this.errorWrapper=document.createElement("div")),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",n.appendChild(this.errorWrapper);let A=document.createElement("div");A.dataset.errorMessage="",A.innerText=e.message,this.errorWrapper.appendChild(A);let o=document.createElement("pre");o.dataset.errorStack="",o.innerText=e.stack??"No Error Stack",this.errorWrapper.appendChild(o)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}},f(qs,"LoadedCustomComponent",!0),qs);function ny({fileDiff:e,oldFile:t,newFile:n}){return e!=null&&e.hunks.length>0||t!=null||n!=null}function Ay({fileDiff:e,oldFile:t,newFile:n}){return e!=null||t!=null||n!=null}function oy(e,t,n=!1){return!n&&e==null&&t}function ry(e,t,n=!1){return e==null&&t&&!n}function fl(e){if(!(e==null||e.type!=="element"))return e.children??[]}var ay=[...Object.keys(DA),"text","ansi"],iy=new Set(ay),sy=new Map(bn.flatMap(e=>Ng(e).map(t=>[t,e.id])));function cy(e){return typeof e!="string"?void 0:e.trim().toLowerCase()||void 0}async function bl(e,t={}){let n=cy(e);if(!n)return;let A=sy.get(n);if(A)return A;if(iy.has(n))return n;if(t.languagePackAvailable)try{return await Bn(n),n}catch{return}}async function dy(e,t){let n=new Set;for(let A of e){let o=await bl(A,t);o&&n.add(o)}return t.fallbackToText&&n.size===0&&n.add("text"),[...n]}function uy(e){let t=new Set;return e.fileDiff?.lang&&t.add(e.fileDiff.lang),e.oldFile?.lang&&t.add(e.oldFile.lang),e.newFile?.lang&&t.add(e.newFile.lang),[...t]}async function Ts(e,t){if(!e)return;if(typeof e.lang!="string")return e;let n=await bl(e.lang,t);return e.lang===n?e:n?{...e,lang:n}:{...e,lang:"text"}}async function Bl(e,t={}){let[n,A,o,r]=await Promise.all([Ts(e.fileDiff,t),Ts(e.oldFile,t),Ts(e.newFile,t),dy(e.langs,{fallbackToText:!1,...t})]),a=new Set(r);for(let s of uy({fileDiff:n,oldFile:A,newFile:o}))a.add(s);return a.size===0&&a.add("text"),{...e,fileDiff:n,oldFile:A,newFile:o,langs:[...a]}}var hl=["unified","split"];var Cl=["light","dark"],El=["bars","classic","none"];var gy=["scroll","wrap"];function jt(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function yl(e){let t;try{t=JSON.parse(e)}catch{throw new Error("Diff payload is not valid JSON.")}if(!py(t))throw new Error("Diff payload has invalid shape.");return t}function py(e){if(!jt(e)||typeof e.prerenderedHTML!="string"||!Array.isArray(e.langs)||!e.langs.every(A=>typeof A=="string")||!ly(e.options))return!1;let t=jt(e.fileDiff),n=jt(e.oldFile)&&jt(e.newFile);return!(!t&&!n)}function ly(e){return!(!jt(e)||!jt(e.theme)||e.theme.light!=="pierre-light"||e.theme.dark!=="pierre-dark"||!VA(hl,e.diffStyle)||!VA(El,e.diffIndicators)||!VA(Cl,e.themeType)||!VA(gy,e.overflow)||typeof e.disableLineNumbers!="boolean"||typeof e.expandUnchanged!="boolean"||typeof e.backgroundEnabled!="boolean"||typeof e.unsafeCSS!="string")}function VA(e,t){return typeof t=="string"&&e.includes(t)}function my(){return!1}function fy(e=my()){return e===!0}var Ks=[],j={theme:"dark",layout:"unified",backgroundEnabled:!0,wrapEnabled:!0};function by(e){let t=e.textContent?.trim();if(!t)throw new Error("Diff payload was empty.");return yl(t)}function By(){let e=[];for(let t of document.querySelectorAll(".oc-diff-card")){let n=t.querySelector("[data-openclaw-diff-host]"),A=t.querySelector("[data-openclaw-diff-payload]");if(!(!n||!A))try{e.push({host:n,payload:by(A)})}catch(o){console.warn("Skipping invalid diff payload",o)}}return e}var hy={split:`<svg viewBox="0 0 16 16" aria-hidden="true">
1555
1555
  <path fill="currentColor" d="M14 0H8.5v16H14a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2m-1.5 6.5v1h1a.5.5 0 0 1 0 1h-1v1a.5.5 0 0 1-1 0v-1h-1a.5.5 0 0 1 0-1h1v-1a.5.5 0 0 1 1 0"></path>
1556
1556
  <path fill="currentColor" opacity="0.5" d="M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h5.5V0zm.5 7.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1 0-1"></path>
1557
1557
  </svg>`,unified:`<svg viewBox="0 0 16 16" aria-hidden="true">
package/dist/index.js CHANGED
@@ -3,6 +3,8 @@ import { resolveRequestClientIp } from "./runtime-api.js";
3
3
  import { buildPluginConfigSchema } from "openclaw/plugin-sdk/plugin-entry";
4
4
  import { mapPluginConfigIssues } from "openclaw/plugin-sdk/extension-shared";
5
5
  import { z } from "zod";
6
+ import { resolveGatewayPublicOrigin } from "openclaw/plugin-sdk/config-contracts";
7
+ import { resolveGatewayPort } from "openclaw/plugin-sdk/core";
6
8
  import fs, { constants } from "node:fs";
7
9
  import path from "node:path";
8
10
  import { resolveLivePluginConfigObject } from "openclaw/plugin-sdk/plugin-config-runtime";
@@ -18,6 +20,7 @@ import { optionalFiniteNumberSchema, stringEnum } from "openclaw/plugin-sdk/chan
18
20
  import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
19
21
  import { readFiniteNumberParam } from "openclaw/plugin-sdk/param-readers";
20
22
  import { Type } from "typebox";
23
+ import os from "node:os";
21
24
  import { chromium } from "playwright-core";
22
25
  import { parsePatchFiles, resolveLanguage } from "@pierre/diffs";
23
26
  import { preloadDiffHTML } from "@pierre/diffs/ssr";
@@ -46,9 +49,8 @@ const DIFF_ARTIFACT_ID_PATTERN = /^[0-9a-f]{20}$/;
46
49
  const DIFF_ARTIFACT_TOKEN_PATTERN = /^[0-9a-f]{48}$/;
47
50
  //#endregion
48
51
  //#region extensions/diffs/src/url.ts
49
- const DEFAULT_GATEWAY_PORT = 18789;
50
52
  function buildViewerUrl(params) {
51
- const normalizedBase = normalizeViewerBaseUrl(params.baseUrl?.trim() || resolveGatewayBaseUrl(params.config));
53
+ const normalizedBase = normalizeViewerBaseUrl(params.baseUrl?.trim() || params.viewerBaseUrl?.trim() || resolveGatewayPublicOrigin(params.config) || resolveGatewayBaseUrl(params.config));
52
54
  const viewerPath = params.viewerPath.startsWith("/") ? params.viewerPath : `/${params.viewerPath}`;
53
55
  const parsedBase = new URL(normalizedBase);
54
56
  parsedBase.pathname = `${parsedBase.pathname === "/" ? "" : parsedBase.pathname.replace(/\/+$/, "")}${viewerPath}`;
@@ -72,7 +74,7 @@ function normalizeViewerBaseUrl(raw, fieldName = "baseUrl") {
72
74
  }
73
75
  function resolveGatewayBaseUrl(config) {
74
76
  const scheme = config.gateway?.tls?.enabled ? "https" : "http";
75
- const port = typeof config.gateway?.port === "number" ? config.gateway.port : DEFAULT_GATEWAY_PORT;
77
+ const port = resolveGatewayPort(config);
76
78
  const customHost = config.gateway?.customBindHost?.trim();
77
79
  if (config.gateway?.bind === "custom" && customHost) return `${scheme}://${customHost}:${port}`;
78
80
  return `${scheme}://127.0.0.1:${port}`;
@@ -1244,17 +1246,18 @@ function commonExecutablePathsForPlatform() {
1244
1246
  "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
1245
1247
  ];
1246
1248
  if (process.platform === "win32") {
1247
- const localAppData = process.env.LOCALAPPDATA ?? "";
1248
- const programFiles = process.env.ProgramFiles ?? "C:\\Program Files";
1249
- const programFilesX86 = process.env["ProgramFiles(x86)"] ?? "C:\\Program Files (x86)";
1249
+ const joinWindowsPath = path.win32.join;
1250
+ const localAppData = normalizeOptionalString(process.env.LOCALAPPDATA) ?? joinWindowsPath(os.homedir(), "AppData", "Local");
1251
+ const programFiles = normalizeOptionalString(process.env.ProgramFiles) ?? "C:\\Program Files";
1252
+ const programFilesX86 = normalizeOptionalString(process.env["ProgramFiles(x86)"]) ?? "C:\\Program Files (x86)";
1250
1253
  return [
1251
- path.join(localAppData, "Google", "Chrome", "Application", "chrome.exe"),
1252
- path.join(programFiles, "Google", "Chrome", "Application", "chrome.exe"),
1253
- path.join(programFilesX86, "Google", "Chrome", "Application", "chrome.exe"),
1254
- path.join(programFiles, "Microsoft", "Edge", "Application", "msedge.exe"),
1255
- path.join(programFilesX86, "Microsoft", "Edge", "Application", "msedge.exe"),
1256
- path.join(programFiles, "BraveSoftware", "Brave-Browser", "Application", "brave.exe"),
1257
- path.join(programFilesX86, "BraveSoftware", "Brave-Browser", "Application", "brave.exe")
1254
+ joinWindowsPath(localAppData, "Google", "Chrome", "Application", "chrome.exe"),
1255
+ joinWindowsPath(programFiles, "Google", "Chrome", "Application", "chrome.exe"),
1256
+ joinWindowsPath(programFilesX86, "Google", "Chrome", "Application", "chrome.exe"),
1257
+ joinWindowsPath(programFiles, "Microsoft", "Edge", "Application", "msedge.exe"),
1258
+ joinWindowsPath(programFilesX86, "Microsoft", "Edge", "Application", "msedge.exe"),
1259
+ joinWindowsPath(programFiles, "BraveSoftware", "Brave-Browser", "Application", "brave.exe"),
1260
+ joinWindowsPath(programFilesX86, "BraveSoftware", "Brave-Browser", "Application", "brave.exe")
1258
1261
  ];
1259
1262
  }
1260
1263
  return [
@@ -1509,13 +1512,12 @@ const BASE_DIFF_VIEWER_LANGUAGE_HINTS = [
1509
1512
  ];
1510
1513
  const BASE_LANGUAGE_HINTS = new Set(BASE_DIFF_VIEWER_LANGUAGE_HINTS);
1511
1514
  const BASE_LANGUAGE_ALIASES = new Map(bundledLanguagesInfo.flatMap((language) => getBundledLanguageAliases(language).map((alias) => [alias, language.id])));
1512
- function normalizeOptionalString$1(value) {
1515
+ function normalizeLanguageHint(value) {
1513
1516
  if (typeof value !== "string") return;
1514
- const normalized = value.trim().toLowerCase();
1515
- return normalized ? normalized : void 0;
1517
+ return value.trim().toLowerCase() || void 0;
1516
1518
  }
1517
1519
  async function normalizeSupportedLanguageHint(value, options = {}) {
1518
- const normalized = normalizeOptionalString$1(value);
1520
+ const normalized = normalizeLanguageHint(value);
1519
1521
  if (!normalized) return;
1520
1522
  const baseAlias = BASE_LANGUAGE_ALIASES.get(normalized);
1521
1523
  if (baseAlias) return baseAlias;
@@ -2296,7 +2298,8 @@ function createDiffsTool(params) {
2296
2298
  const viewerUrl = buildViewerUrl({
2297
2299
  config: params.api.config,
2298
2300
  viewerPath: artifact.viewerPath,
2299
- baseUrl: normalizeBaseUrl(toolParams.baseUrl) ?? params.viewerBaseUrl
2301
+ baseUrl: normalizeBaseUrl(toolParams.baseUrl),
2302
+ viewerBaseUrl: params.viewerBaseUrl
2300
2303
  });
2301
2304
  const baseDetails = {
2302
2305
  changed: true,