@floegence/floe-webapp-core 0.81.6 → 0.82.0
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/dist/assets/diff.worker-D_WqMZMe.js +210 -0
- package/dist/assets/highlight.worker-BasxZ52k.js +6105 -0
- package/dist/assets/markdown.worker-D2sIOyGt.js +1171 -0
- package/dist/code-highlight/highlight.worker.d.ts +1 -0
- package/dist/code-highlight/tokenize.d.ts +3 -0
- package/dist/code-highlight/tokens.d.ts +17 -0
- package/dist/code-highlight/tokens.js +8 -0
- package/dist/code-highlight.d.ts +8 -0
- package/dist/code-highlight.js +96 -0
- package/dist/components/chat/hooks/useCodeDiff.js +7 -7
- package/dist/components/chat/hooks/useMarkdown.js +1 -1
- package/package.json +6 -2
- package/dist/assets/diff.worker-DCUP7uh3.js +0 -7
- package/dist/assets/markdown.worker-DurayC72.js +0 -59
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
class N {
|
|
2
|
+
diff(e, t, n = {}) {
|
|
3
|
+
let o;
|
|
4
|
+
typeof n == "function" ? (o = n, n = {}) : "callback" in n && (o = n.callback);
|
|
5
|
+
const i = this.castInput(e, n), u = this.castInput(t, n), c = this.removeEmpty(this.tokenize(i, n)), s = this.removeEmpty(this.tokenize(u, n));
|
|
6
|
+
return this.diffWithOptionsObj(c, s, n, o);
|
|
7
|
+
}
|
|
8
|
+
diffWithOptionsObj(e, t, n, o) {
|
|
9
|
+
var i;
|
|
10
|
+
const u = (l) => {
|
|
11
|
+
if (l = this.postProcess(l, n), o) {
|
|
12
|
+
setTimeout(function() {
|
|
13
|
+
o(l);
|
|
14
|
+
}, 0);
|
|
15
|
+
return;
|
|
16
|
+
} else
|
|
17
|
+
return l;
|
|
18
|
+
}, c = t.length, s = e.length;
|
|
19
|
+
let d = 1, r = c + s;
|
|
20
|
+
n.maxEditLength != null && (r = Math.min(r, n.maxEditLength));
|
|
21
|
+
const p = (i = n.timeout) !== null && i !== void 0 ? i : 1 / 0, f = Date.now() + p, m = [{ oldPos: -1, lastComponent: void 0 }];
|
|
22
|
+
let h = this.extractCommon(m[0], t, e, 0, n);
|
|
23
|
+
if (m[0].oldPos + 1 >= s && h + 1 >= c)
|
|
24
|
+
return u(this.buildValues(m[0].lastComponent, t, e));
|
|
25
|
+
let v = -1 / 0, L = 1 / 0;
|
|
26
|
+
const w = () => {
|
|
27
|
+
for (let l = Math.max(v, -d); l <= Math.min(L, d); l += 2) {
|
|
28
|
+
let g;
|
|
29
|
+
const C = m[l - 1], P = m[l + 1];
|
|
30
|
+
C && (m[l - 1] = void 0);
|
|
31
|
+
let x = !1;
|
|
32
|
+
if (P) {
|
|
33
|
+
const b = P.oldPos - l;
|
|
34
|
+
x = P && 0 <= b && b < c;
|
|
35
|
+
}
|
|
36
|
+
const y = C && C.oldPos + 1 < s;
|
|
37
|
+
if (!x && !y) {
|
|
38
|
+
m[l] = void 0;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (!y || x && C.oldPos < P.oldPos ? g = this.addToPath(P, !0, !1, 0, n) : g = this.addToPath(C, !1, !0, 1, n), h = this.extractCommon(g, t, e, l, n), g.oldPos + 1 >= s && h + 1 >= c)
|
|
42
|
+
return u(this.buildValues(g.lastComponent, t, e)) || !0;
|
|
43
|
+
m[l] = g, g.oldPos + 1 >= s && (L = Math.min(L, l - 1)), h + 1 >= c && (v = Math.max(v, l + 1));
|
|
44
|
+
}
|
|
45
|
+
d++;
|
|
46
|
+
};
|
|
47
|
+
if (o)
|
|
48
|
+
(function l() {
|
|
49
|
+
setTimeout(function() {
|
|
50
|
+
if (d > r || Date.now() > f)
|
|
51
|
+
return o(void 0);
|
|
52
|
+
w() || l();
|
|
53
|
+
}, 0);
|
|
54
|
+
})();
|
|
55
|
+
else
|
|
56
|
+
for (; d <= r && Date.now() <= f; ) {
|
|
57
|
+
const l = w();
|
|
58
|
+
if (l)
|
|
59
|
+
return l;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
addToPath(e, t, n, o, i) {
|
|
63
|
+
const u = e.lastComponent;
|
|
64
|
+
return u && !i.oneChangePerToken && u.added === t && u.removed === n ? {
|
|
65
|
+
oldPos: e.oldPos + o,
|
|
66
|
+
lastComponent: { count: u.count + 1, added: t, removed: n, previousComponent: u.previousComponent }
|
|
67
|
+
} : {
|
|
68
|
+
oldPos: e.oldPos + o,
|
|
69
|
+
lastComponent: { count: 1, added: t, removed: n, previousComponent: u }
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
extractCommon(e, t, n, o, i) {
|
|
73
|
+
const u = t.length, c = n.length;
|
|
74
|
+
let s = e.oldPos, d = s - o, r = 0;
|
|
75
|
+
for (; d + 1 < u && s + 1 < c && this.equals(n[s + 1], t[d + 1], i); )
|
|
76
|
+
d++, s++, r++, i.oneChangePerToken && (e.lastComponent = { count: 1, previousComponent: e.lastComponent, added: !1, removed: !1 });
|
|
77
|
+
return r && !i.oneChangePerToken && (e.lastComponent = { count: r, previousComponent: e.lastComponent, added: !1, removed: !1 }), e.oldPos = s, d;
|
|
78
|
+
}
|
|
79
|
+
equals(e, t, n) {
|
|
80
|
+
return n.comparator ? n.comparator(e, t) : e === t || !!n.ignoreCase && e.toLowerCase() === t.toLowerCase();
|
|
81
|
+
}
|
|
82
|
+
removeEmpty(e) {
|
|
83
|
+
const t = [];
|
|
84
|
+
for (let n = 0; n < e.length; n++)
|
|
85
|
+
e[n] && t.push(e[n]);
|
|
86
|
+
return t;
|
|
87
|
+
}
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
89
|
+
castInput(e, t) {
|
|
90
|
+
return e;
|
|
91
|
+
}
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
93
|
+
tokenize(e, t) {
|
|
94
|
+
return Array.from(e);
|
|
95
|
+
}
|
|
96
|
+
join(e) {
|
|
97
|
+
return e.join("");
|
|
98
|
+
}
|
|
99
|
+
postProcess(e, t) {
|
|
100
|
+
return e;
|
|
101
|
+
}
|
|
102
|
+
get useLongestToken() {
|
|
103
|
+
return !1;
|
|
104
|
+
}
|
|
105
|
+
buildValues(e, t, n) {
|
|
106
|
+
const o = [];
|
|
107
|
+
let i;
|
|
108
|
+
for (; e; )
|
|
109
|
+
o.push(e), i = e.previousComponent, delete e.previousComponent, e = i;
|
|
110
|
+
o.reverse();
|
|
111
|
+
const u = o.length;
|
|
112
|
+
let c = 0, s = 0, d = 0;
|
|
113
|
+
for (; c < u; c++) {
|
|
114
|
+
const r = o[c];
|
|
115
|
+
if (r.removed)
|
|
116
|
+
r.value = this.join(n.slice(d, d + r.count)), d += r.count;
|
|
117
|
+
else {
|
|
118
|
+
if (!r.added && this.useLongestToken) {
|
|
119
|
+
let p = t.slice(s, s + r.count);
|
|
120
|
+
p = p.map(function(f, m) {
|
|
121
|
+
const h = n[d + m];
|
|
122
|
+
return h.length > f.length ? h : f;
|
|
123
|
+
}), r.value = this.join(p);
|
|
124
|
+
} else
|
|
125
|
+
r.value = this.join(t.slice(s, s + r.count));
|
|
126
|
+
s += r.count, r.added || (d += r.count);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return o;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
class E extends N {
|
|
133
|
+
constructor() {
|
|
134
|
+
super(...arguments), this.tokenize = I;
|
|
135
|
+
}
|
|
136
|
+
equals(e, t, n) {
|
|
137
|
+
return n.ignoreWhitespace ? ((!n.newlineIsToken || !e.includes(`
|
|
138
|
+
`)) && (e = e.trim()), (!n.newlineIsToken || !t.includes(`
|
|
139
|
+
`)) && (t = t.trim())) : n.ignoreNewlineAtEof && !n.newlineIsToken && (e.endsWith(`
|
|
140
|
+
`) && (e = e.slice(0, -1)), t.endsWith(`
|
|
141
|
+
`) && (t = t.slice(0, -1))), super.equals(e, t, n);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const T = new E();
|
|
145
|
+
function D(a, e, t) {
|
|
146
|
+
return T.diff(a, e, t);
|
|
147
|
+
}
|
|
148
|
+
function I(a, e) {
|
|
149
|
+
e.stripTrailingCr && (a = a.replace(/\r\n/g, `
|
|
150
|
+
`));
|
|
151
|
+
const t = [], n = a.split(/(\n|\r\n)/);
|
|
152
|
+
n[n.length - 1] || n.pop();
|
|
153
|
+
for (let o = 0; o < n.length; o++) {
|
|
154
|
+
const i = n[o];
|
|
155
|
+
o % 2 && !e.newlineIsToken ? t[t.length - 1] += i : t.push(i);
|
|
156
|
+
}
|
|
157
|
+
return t;
|
|
158
|
+
}
|
|
159
|
+
function M(a) {
|
|
160
|
+
const e = a.split(`
|
|
161
|
+
`);
|
|
162
|
+
return e.length > 0 && e[e.length - 1] === "" && e.pop(), e;
|
|
163
|
+
}
|
|
164
|
+
function j(a) {
|
|
165
|
+
return a.added ? "added" : a.removed ? "removed" : "context";
|
|
166
|
+
}
|
|
167
|
+
function z(a, e) {
|
|
168
|
+
const t = D(a, e), n = [], o = [], i = [];
|
|
169
|
+
let u = 0, c = 0, s = 0, d = 0, r = 0;
|
|
170
|
+
for (const p of t) {
|
|
171
|
+
const f = j(p), m = M(p.value);
|
|
172
|
+
f === "added" && (d += m.length), f === "removed" && (r += m.length);
|
|
173
|
+
for (const h of m) {
|
|
174
|
+
if (f === "context" && (u += 1), n.push({
|
|
175
|
+
type: f,
|
|
176
|
+
sign: f === "added" ? "+" : f === "removed" ? "-" : " ",
|
|
177
|
+
lineNumber: f === "context" ? u : null,
|
|
178
|
+
content: h || " "
|
|
179
|
+
}), f === "added") {
|
|
180
|
+
s += 1, o.push({ type: "empty", content: "", lineNumber: null }), i.push({ type: "added", content: h || " ", lineNumber: s });
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (f === "removed") {
|
|
184
|
+
c += 1, o.push({ type: "removed", content: h || " ", lineNumber: c }), i.push({ type: "empty", content: "", lineNumber: null });
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
c += 1, s += 1, o.push({ type: "context", content: h || " ", lineNumber: c }), i.push({ type: "context", content: h || " ", lineNumber: s });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
unifiedLines: n,
|
|
192
|
+
split: { left: o, right: i },
|
|
193
|
+
stats: { added: d, removed: r }
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
postMessage({ type: "ready" });
|
|
197
|
+
addEventListener("message", (a) => {
|
|
198
|
+
const { id: e, oldCode: t, newCode: n } = a.data;
|
|
199
|
+
try {
|
|
200
|
+
const o = z(t, n);
|
|
201
|
+
postMessage({ id: e, model: o });
|
|
202
|
+
} catch (o) {
|
|
203
|
+
const i = {
|
|
204
|
+
id: e,
|
|
205
|
+
model: { unifiedLines: [], split: { left: [], right: [] }, stats: { added: 0, removed: 0 } },
|
|
206
|
+
error: o instanceof Error ? o.message : "Failed to compute diff"
|
|
207
|
+
};
|
|
208
|
+
postMessage(i);
|
|
209
|
+
}
|
|
210
|
+
});
|