var z=Object.defineProperty;var I=(s,e)=>{for(var t in e)z(s,t,{get:e[t],enumerable:!0})};var V={};I(V,{DiffView:()=>w,buildDiffRows:()=>O});import*as R from"./../../../core/i18n/i18n.js";import*as c from"./../../../third_party/diff/diff.js";import*as C from"./../../visual_logging/visual_logging.js";import*as H from"./../../lit/lit.js";import*as x from"./../code_highlighter/code_highlighter.js";var N=`.diff-listing{display:grid;grid-template-columns:max-content max-content max-content auto;font-family:var(--source-code-font-family);font-size:var(--source-code-font-size);white-space:pre;line-height:1.2em;user-select:text}.diff-line-number{color:var(--sys-color-token-subtle);padding:0 3px 0 9px;text-align:right;user-select:none}.diff-line-marker{user-select:none;border-right:1px solid var(--sys-color-divider);width:20px;text-align:center}.diff-line-content{padding:0 4px}.diff-line-marker-addition,
.diff-line-addition{background-color:var(--sys-color-surface-green)}.diff-line-marker-deletion,
.diff-line-deletion{background-color:var(--sys-color-surface-error)}.diff-line-addition .inner-diff{background-color:color-mix(in srgb,var(--ref-palette-green70) 40%,transparent)}.diff-line-deletion .inner-diff{background-color:color-mix(in srgb,var(--ref-palette-error60) 40%,transparent)}.diff-hidden-text{display:inline-block;width:0;overflow:hidden}.diff-line-equal{opacity:50%}.diff-line-spacer{text-align:center;background-color:var(--sys-color-surface5)}.diff-listing-no-diff{user-select:auto;font-family:var(--source-code-font-family);font-size:var(--source-code-font-size);margin:0;padding:var(--sys-size-5) 9px}
/*# sourceURL=${import.meta.resolve("./diffView.css")} */`;var{html:g}=H,k={deletions:"Deletion:",additions:"Addition:",changesDiffViewer:"Changes diff viewer",SkippingDMatchingLines:"( \u2026 Skipping {PH1} matching lines \u2026 )",noDiff:"File is identical to its unmodified state"},j=R.i18n.registerUIStrings("ui/components/diff_view/DiffView.ts",k),b=R.i18n.getLocalizedString.bind(void 0,j);function O(s){let e=0,t=0,n=3,a=[],f=[],o=[];for(let i=0;i<s.length;++i){let r=s[i];switch(r[0]){case c.Diff.Operation.Equal:o.push(...p(r[1],i===0,i===s.length-1)),a.push(...r[1]),f.push(...r[1]);break;case c.Diff.Operation.Insert:for(let u of r[1])o.push(l(u,"addition"));f.push(...r[1]);break;case c.Diff.Operation.Delete:if(a.push(...r[1]),s[i+1]&&s[i+1][0]===c.Diff.Operation.Insert)i++,o.push(...$(r[1].join(`
`),s[i][1].join(`
`))),f.push(...s[i][1]);else for(let u of r[1])o.push(l(u,"deletion"));break}}return{originalLines:a,currentLines:f,rows:o};function p(i,r,u){let h=[];if(!r){for(let d=0;d<n&&d<i.length;d++)h.push(l(i[d],"equal"));i.length>n*2+1&&!u&&h.push(l(b(k.SkippingDMatchingLines,{PH1:i.length-n*2}),"spacer"))}if(!u){let d=Math.max(i.length-n-1,r?0:n),m=i.length-n-1;r||(m-=n),m>0&&(t+=m,e+=m);for(let v=d;v<i.length;v++)h.push(l(i[v],"equal"))}return h}function $(i,r){let u=c.Diff.DiffWrapper.charDiff(i,r,!0),h=[l("","deletion")],d=[l("","addition")];for(let m of u){let v=m[1],y=m[0],S=y===c.Diff.Operation.Equal?"":"inner-diff",L=v.split(`
`);for(let D=0;D<L.length;D++)D>0&&y!==c.Diff.Operation.Insert&&h.push(l("","deletion")),D>0&&y!==c.Diff.Operation.Delete&&d.push(l("","addition")),L[D]&&(y!==c.Diff.Operation.Insert&&h[h.length-1].tokens.push({text:L[D],className:S}),y!==c.Diff.Operation.Delete&&d[d.length-1].tokens.push({text:L[D],className:S}))}return h.concat(d)}function l(i,r){return r==="addition"&&e++,r==="deletion"&&t++,r==="equal"&&(t++,e++),{originalLineNumber:t,currentLineNumber:e,tokens:i?[{text:i,className:"inner-diff"}]:[],type:r}}}function q(s){let e=new Map;for(let t=0,n=0;n<s.length;n++)e.set(n+1,t),t+=s[n].length+1;return e}var M=class s{originalHighlighter;originalMap;currentHighlighter;currentMap;constructor(e,t,n,a){this.originalHighlighter=e,this.originalMap=t,this.currentHighlighter=n,this.currentMap=a}#e(e){return g`
      <style>${N}</style>
      <style>${x.codeHighlighterStyles}</style>
      <div class="diff-listing" aria-label=${b(k.changesDiffViewer)}>
        ${e.map(t=>this.#i(t))}
      </div>`}#i(e){let t=e.type==="equal"||e.type==="deletion"?String(e.originalLineNumber):"",n=e.type==="equal"||e.type==="addition"?String(e.currentLineNumber):"",a="",f="diff-line-marker",o=null;return e.type==="addition"?(a="+",f+=" diff-line-addition",o=g`<span class="diff-hidden-text">${b(k.additions)}</span>`):e.type==="deletion"&&(a="-",f+=" diff-line-deletion",o=g`<span class="diff-hidden-text">${b(k.deletions)}</span>`),g`
      <div class="diff-line-number" aria-hidden="true">${t}</div>
      <div class="diff-line-number" aria-hidden="true">${n}</div>
      <div class=${f} aria-hidden="true">${a}</div>
      <div class="diff-line-content diff-line-${e.type}" data-line-number=${n} jslog=${C.link("changes.reveal-source").track({click:!0})}>${o}${this.#t(e)}</div>`}#t(e){if(e.type==="spacer")return e.tokens.map(o=>g`${o.text}`);let[t,n]=e.type==="deletion"?[this.originalHighlighter,this.originalMap.get(e.originalLineNumber)]:[this.currentHighlighter,this.currentMap.get(e.currentLineNumber)],a=[],f=n;for(let o of e.tokens){let p=[];t.highlightRange(f,f+o.text.length,($,l)=>{p.push(l?g`<span class=${l}>${$}</span>`:$)}),a.push(o.className?g`<span class=${o.className}>${p}</span>`:g`${p}`),f+=o.text.length}return a}static async render(e,t,n){let{originalLines:a,currentLines:f,rows:o}=O(e),p=new s(await x.CodeHighlighter.create(a.join(`
`),t),q(a),await x.CodeHighlighter.create(f.join(`
`),t),q(f));H.render(p.#e(o),n,{host:this})}};function E(s){H.render(g`
    <style>${N}</style>
    <p class="diff-listing-no-diff" data-testid="no-diff">${b(k.noDiff)}</p>`,s,{host:s})}var w=class extends HTMLElement{#e=this.attachShadow({mode:"open"});loaded;constructor(e){super(),this.loaded=this.#i(e)}set data(e){this.loaded=this.#i(e)}async#i(e){if(!e||e.diff.length===0){E(this.#e);return}await M.render(e.diff,e.mimeType,this.#e)}};customElements.define("devtools-diff-view",w);export{V as DiffView};
//# sourceMappingURL=diff_view.js.map
