import*as Common from"../common/common.js";export const DiffWrapper={charDiff:function(t,n,e){const r=new diff_match_patch,o=r.diff_main(t,n);return e&&r.diff_cleanupSemantic(o),o},lineDiff:function(t,n){const e=new Common.CharacterIdMap.CharacterIdMap,r=t.map((t=>e.toChar(t))).join(""),o=n.map((t=>e.toChar(t))).join(""),a=DiffWrapper.charDiff(r,o),f=[];for(let i=0;i<a.length;i++){const t=[];for(let n=0;n<a[i][1].length;n++)t.push(e.fromChar(a[i][1][n])||"");f.push({0:a[i][0],1:t})}return f},convertToEditDiff:function(t){const n=[];let e=0,r=0;for(let a=0;a<t.length;++a){const f=t[a];f[0]===Operation.Equal?(o(),n.push([Operation.Equal,f[1].length])):f[0]===Operation.Delete?r+=f[1].length:e+=f[1].length}return o(),n;function o(){if(e&&r){const t=Math.min(e,r);n.push([Operation.Edit,t]),e-=t,r-=t}if(e||r){const t=e-r,o=t<0?Operation.Delete:Operation.Insert;n.push([o,Math.abs(t)]),e=0,r=0}}},characterScore:function(t,n){let e=0;const r=DiffWrapper.charDiff(t,n);for(let o=0;o<r.length;++o)r[o][0]===Operation.Equal&&(e+=r[o][1].length*r[o][1].length);return e}};export const Operation={Equal:0,Insert:1,Delete:-1,Edit:2};export let DiffArray;