on-codemerge
Version:
A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product
34 lines (33 loc) • 1.25 kB
JavaScript
/*! on-codemerge v1.3.1 @author Pavel Kuzmin @license MIT @homepage https://s00d.github.io/on-codemerge/ @repository git+https://github.com/s00d/on-codemerge.git Copyright (c) 2026 Pavel Kuzmin - Built on 2026-07-02T13:39:17.947Z */
function i(a, n) {
const o = [], l = a.split(/(\s+|<[^>]+>)/), u = n.split(/(\s+|<[^>]+>)/);
let e = 0, t = 0;
for (; e < l.length || t < u.length; )
if (e >= l.length)
o.push({ type: "add", value: u[t] }), t++;
else if (t >= u.length)
o.push({ type: "remove", value: l[e] }), e++;
else if (l[e] === u[t])
o.push({ type: "equal", value: l[e] }), e++, t++;
else {
let p = !1, s = 1;
const f = 3;
for (; s <= f && !p; ) {
if (e + s < l.length && l[e + s] === u[t]) {
for (let h = 0; h < s; h++)
o.push({ type: "remove", value: l[e + h] });
e += s, p = !0;
} else if (t + s < u.length && l[e] === u[t + s]) {
for (let h = 0; h < s; h++)
o.push({ type: "add", value: u[t + h] });
t += s, p = !0;
}
s++;
}
p || (o.push({ type: "remove", value: l[e] }), o.push({ type: "add", value: u[t] }), e++, t++);
}
return o;
}
export {
i as computeDiff
};