UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 1.23 kB
import*as Common from"../../core/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),i=[];for(let t=0;t<a.length;t++){const n=[];for(let r=0;r<a[t][1].length;r++)n.push(e.fromChar(a[t][1][r])||"");i.push({0:a[t][0],1:n})}return i},convertToEditDiff:function(t){const n=[];let e=0,r=0;for(let a=0;a<t.length;++a){const i=t[a];i[0]===Operation.Equal?(o(),n.push([Operation.Equal,i[1].length])):i[0]===Operation.Delete?r+=i[1].length:e+=i[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 t=0;t<r.length;++t)r[t][0]===Operation.Equal&&(e+=r[t][1].length*r[t][1].length);return e}};export var Operation;!function(t){t[t.Equal=0]="Equal",t[t.Insert=1]="Insert",t[t.Delete=-1]="Delete",t[t.Edit=2]="Edit"}(Operation||(Operation={}));