@recogito/text-annotator 3.0.0-rc.6 → 3.0.0-rc.8
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.
|
@@ -9,8 +9,7 @@ const ft = { fill: "rgb(0, 128, 255", fillOpacity: 0.18 }, gt = { fill: "rgb(0,
|
|
|
9
9
|
const i = o.map((s) => s.id);
|
|
10
10
|
(t.size !== i.length || i.some((s) => !t.has(s))) && e.set(i), t = new Set(i);
|
|
11
11
|
};
|
|
12
|
-
}
|
|
13
|
-
const mt = (e, t = 10) => {
|
|
12
|
+
}, mt = (e, t = 10) => {
|
|
14
13
|
let n;
|
|
15
14
|
return (...o) => {
|
|
16
15
|
clearTimeout(n), n = setTimeout(() => e.apply(void 0, o), t);
|
|
@@ -32,41 +31,41 @@ const mt = (e, t = 10) => {
|
|
|
32
31
|
let a, r, d = nt;
|
|
33
32
|
const u = pt(n);
|
|
34
33
|
e.classList.add("r6o-annotatable");
|
|
35
|
-
const b = j("r6o-highlight-layer bg"), h = j("r6o-highlight-layer fg", !0),
|
|
36
|
-
e.insertBefore(b, e.firstChild), e.appendChild(h), e.addEventListener("pointermove", (
|
|
37
|
-
const { x: T, y:
|
|
34
|
+
const b = j("r6o-highlight-layer bg"), h = j("r6o-highlight-layer fg", !0), v = b.getContext("2d"), m = h.getContext("2d");
|
|
35
|
+
e.insertBefore(b, e.firstChild), e.appendChild(h), e.addEventListener("pointermove", (E) => {
|
|
36
|
+
const { x: T, y: L } = e.getBoundingClientRect(), f = o.getAt(E.clientX - T, E.clientY - L);
|
|
38
37
|
f && (!r || r(f)) ? s.current !== f.id && (e.classList.add("hovered"), s.set(f.id)) : s.current && (e.classList.remove("hovered"), s.set(null));
|
|
39
38
|
});
|
|
40
|
-
const
|
|
41
|
-
const { top:
|
|
42
|
-
return { top:
|
|
43
|
-
},
|
|
44
|
-
document.addEventListener("scroll",
|
|
39
|
+
const x = () => {
|
|
40
|
+
const { top: E, left: T } = e.getBoundingClientRect(), { innerWidth: L, innerHeight: f } = window, A = -T, w = -E, B = L - T, S = f - E;
|
|
41
|
+
return { top: E, left: T, minX: A, minY: w, maxX: B, maxY: S };
|
|
42
|
+
}, M = () => c();
|
|
43
|
+
document.addEventListener("scroll", M, { capture: !0, passive: !0 });
|
|
45
44
|
const y = mt(() => {
|
|
46
45
|
Z(b), Z(h, !0), o.recalculatePositions(), c();
|
|
47
46
|
});
|
|
48
47
|
window.addEventListener("resize", y), new ResizeObserver(y).observe(e);
|
|
49
48
|
const c = () => requestAnimationFrame(() => {
|
|
50
|
-
const { top:
|
|
51
|
-
m.clearRect(-0.5, -0.5, S + 1, R + 1),
|
|
49
|
+
const { top: E, left: T, minX: L, minY: f, maxX: A, maxY: w } = x(), B = r ? o.getIntersectingRects(L, f, A, w).filter(({ annotation: Y }) => r(Y)) : o.getIntersectingRects(L, f, A, w), { width: S, height: R } = h, X = new Set(i.selected.map(({ id: Y }) => Y));
|
|
50
|
+
m.clearRect(-0.5, -0.5, S + 1, R + 1), v.clearRect(-0.5, -0.5, S + 1, R + 1), B.forEach(({ annotation: Y, rects: at }) => {
|
|
52
51
|
const rt = at.map(({ x: ct, y: dt, width: ut, height: ht }) => ({
|
|
53
52
|
x: ct + T,
|
|
54
|
-
y: dt +
|
|
53
|
+
y: dt + E,
|
|
55
54
|
width: ut,
|
|
56
55
|
height: ht
|
|
57
|
-
})), lt = X.has(
|
|
58
|
-
d.paint(
|
|
59
|
-
}), setTimeout(() => u(B.map(({ annotation:
|
|
56
|
+
})), lt = X.has(Y.id);
|
|
57
|
+
d.paint(Y, rt, v, m, lt, a);
|
|
58
|
+
}), setTimeout(() => u(B.map(({ annotation: Y }) => Y)), 1);
|
|
60
59
|
});
|
|
61
60
|
return o.observe(() => c()), i.subscribe(() => c()), {
|
|
62
61
|
redraw: c,
|
|
63
|
-
setDrawingStyle: (
|
|
64
|
-
a =
|
|
62
|
+
setDrawingStyle: (E) => {
|
|
63
|
+
a = E, c();
|
|
65
64
|
},
|
|
66
|
-
setFilter: (
|
|
67
|
-
r =
|
|
65
|
+
setFilter: (E) => {
|
|
66
|
+
r = E, c();
|
|
68
67
|
},
|
|
69
|
-
setPainter: (
|
|
68
|
+
setPainter: (E) => d = E
|
|
70
69
|
};
|
|
71
70
|
}, k = (e, t) => {
|
|
72
71
|
const { start: n, end: o } = e.selector, i = e.selector.offsetReference ? e.selector.offsetReference : t;
|
|
@@ -104,7 +103,7 @@ const mt = (e, t = 10) => {
|
|
|
104
103
|
};
|
|
105
104
|
};
|
|
106
105
|
var Q = Object.prototype.hasOwnProperty;
|
|
107
|
-
function
|
|
106
|
+
function U(e, t) {
|
|
108
107
|
var n, o;
|
|
109
108
|
if (e === t)
|
|
110
109
|
return !0;
|
|
@@ -115,14 +114,14 @@ function Y(e, t) {
|
|
|
115
114
|
return e.toString() === t.toString();
|
|
116
115
|
if (n === Array) {
|
|
117
116
|
if ((o = e.length) === t.length)
|
|
118
|
-
for (; o-- &&
|
|
117
|
+
for (; o-- && U(e[o], t[o]); )
|
|
119
118
|
;
|
|
120
119
|
return o === -1;
|
|
121
120
|
}
|
|
122
121
|
if (!n || typeof e == "object") {
|
|
123
122
|
o = 0;
|
|
124
123
|
for (n in e)
|
|
125
|
-
if (Q.call(e, n) && ++o && !Q.call(t, n) || !(n in t) || !
|
|
124
|
+
if (Q.call(e, n) && ++o && !Q.call(t, n) || !(n in t) || !U(e[n], t[n]))
|
|
126
125
|
return !1;
|
|
127
126
|
return Object.keys(t).length === o;
|
|
128
127
|
}
|
|
@@ -131,7 +130,7 @@ function Y(e, t) {
|
|
|
131
130
|
}
|
|
132
131
|
function W() {
|
|
133
132
|
}
|
|
134
|
-
function
|
|
133
|
+
function wt(e, t) {
|
|
135
134
|
return e != e ? t == t : e !== t || e && typeof e == "object" || typeof e == "function";
|
|
136
135
|
}
|
|
137
136
|
const D = [];
|
|
@@ -139,7 +138,7 @@ function J(e, t = W) {
|
|
|
139
138
|
let n;
|
|
140
139
|
const o = /* @__PURE__ */ new Set();
|
|
141
140
|
function i(r) {
|
|
142
|
-
if (
|
|
141
|
+
if (wt(e, r) && (e = r, n)) {
|
|
143
142
|
const d = !D.length;
|
|
144
143
|
for (const u of o)
|
|
145
144
|
u[1](), D.push(u, e);
|
|
@@ -155,19 +154,19 @@ function J(e, t = W) {
|
|
|
155
154
|
}
|
|
156
155
|
function a(r, d = W) {
|
|
157
156
|
const u = [r, d];
|
|
158
|
-
return o.add(u), o.size === 1 && (n = t(i) || W), r(e), () => {
|
|
157
|
+
return o.add(u), o.size === 1 && (n = t(i, s) || W), r(e), () => {
|
|
159
158
|
o.delete(u), o.size === 0 && n && (n(), n = null);
|
|
160
159
|
};
|
|
161
160
|
}
|
|
162
161
|
return { set: i, update: s, subscribe: a };
|
|
163
162
|
}
|
|
164
|
-
const
|
|
165
|
-
const { subscribe: t, set: n } = J(
|
|
166
|
-
let o
|
|
163
|
+
const At = (e) => {
|
|
164
|
+
const { subscribe: t, set: n } = J();
|
|
165
|
+
let o;
|
|
167
166
|
return t((i) => o = i), e.observe(({ changes: i }) => {
|
|
168
167
|
if (o) {
|
|
169
|
-
i.deleted.some((a) => a.id === o) && n(
|
|
170
|
-
const s = i.updated.find(({ oldValue: a }) => a.id === o);
|
|
168
|
+
(i.deleted || []).some((a) => a.id === o) && n(void 0);
|
|
169
|
+
const s = (i.updated || []).find(({ oldValue: a }) => a.id === o);
|
|
171
170
|
s && n(s.newValue.id);
|
|
172
171
|
}
|
|
173
172
|
}), {
|
|
@@ -177,7 +176,7 @@ const xt = (e) => {
|
|
|
177
176
|
subscribe: t,
|
|
178
177
|
set: n
|
|
179
178
|
};
|
|
180
|
-
}, q = { selected: [] },
|
|
179
|
+
}, q = { selected: [] }, xt = (e, t = "EDIT") => {
|
|
181
180
|
const { subscribe: n, set: o } = J(q);
|
|
182
181
|
let i = q;
|
|
183
182
|
n((h) => i = h);
|
|
@@ -187,25 +186,25 @@ const xt = (e) => {
|
|
|
187
186
|
}, r = (h) => {
|
|
188
187
|
if (i.selected.length === 0)
|
|
189
188
|
return !1;
|
|
190
|
-
const
|
|
191
|
-
return i.selected.some((m) => m.id ===
|
|
192
|
-
}, d = (h,
|
|
189
|
+
const v = typeof h == "string" ? h : h.id;
|
|
190
|
+
return i.selected.some((m) => m.id === v);
|
|
191
|
+
}, d = (h, v) => {
|
|
193
192
|
const m = e.getAnnotation(h);
|
|
194
193
|
if (m) {
|
|
195
|
-
const
|
|
196
|
-
o(
|
|
194
|
+
const x = yt(m, t);
|
|
195
|
+
o(x === "EDIT" ? { selected: [{ id: h, editable: !0 }], pointerEvent: v } : x === "SELECT" ? { selected: [{ id: h }], pointerEvent: v } : { selected: [], pointerEvent: v });
|
|
197
196
|
} else
|
|
198
197
|
console.warn("Invalid selection: " + h);
|
|
199
|
-
}, u = (h,
|
|
200
|
-
const m = Array.isArray(h) ? h : [h],
|
|
201
|
-
o({ selected:
|
|
198
|
+
}, u = (h, v = !0) => {
|
|
199
|
+
const m = Array.isArray(h) ? h : [h], x = m.map((M) => e.getAnnotation(M)).filter(Boolean);
|
|
200
|
+
o({ selected: x.map(({ id: M }) => ({ id: M, editable: v })) }), x.length !== m.length && console.warn("Invalid selection", h);
|
|
202
201
|
}, b = (h) => {
|
|
203
202
|
if (i.selected.length === 0)
|
|
204
203
|
return !1;
|
|
205
|
-
const { selected:
|
|
206
|
-
|
|
204
|
+
const { selected: v } = i;
|
|
205
|
+
v.filter(({ id: m }) => h.includes(m)).length > 0 && o({ selected: v.filter(({ id: m }) => !h.includes(m)) });
|
|
207
206
|
};
|
|
208
|
-
return e.observe(({ changes: h }) => b(h.deleted.map((
|
|
207
|
+
return e.observe(({ changes: h }) => b((h.deleted || []).map((v) => v.id))), {
|
|
209
208
|
clear: s,
|
|
210
209
|
clickSelect: d,
|
|
211
210
|
get selected() {
|
|
@@ -219,11 +218,11 @@ const xt = (e) => {
|
|
|
219
218
|
setSelected: u,
|
|
220
219
|
subscribe: n
|
|
221
220
|
};
|
|
222
|
-
}, yt = (e, t) => typeof t == "function" ? t(e) || "EDIT" : t || "EDIT",
|
|
221
|
+
}, yt = (e, t) => typeof t == "function" ? t(e) || "EDIT" : t || "EDIT", Et = [];
|
|
223
222
|
for (let e = 0; e < 256; ++e)
|
|
224
|
-
|
|
223
|
+
Et.push((e + 256).toString(16).slice(1));
|
|
225
224
|
typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
226
|
-
const
|
|
225
|
+
const vt = (e, t) => {
|
|
227
226
|
const n = new Set(e.bodies.map((o) => o.id));
|
|
228
227
|
return t.bodies.filter((o) => !n.has(o.id));
|
|
229
228
|
}, Tt = (e, t) => {
|
|
@@ -231,9 +230,9 @@ const Et = (e, t) => {
|
|
|
231
230
|
return e.bodies.filter((o) => !n.has(o.id));
|
|
232
231
|
}, Bt = (e, t) => t.bodies.map((n) => {
|
|
233
232
|
const o = e.bodies.find((i) => i.id === n.id);
|
|
234
|
-
return { newBody: n, oldBody: o && !
|
|
235
|
-
}).filter(({ oldBody: n }) => n), St = (e, t) => !
|
|
236
|
-
const n =
|
|
233
|
+
return { newBody: n, oldBody: o && !U(o, n) ? o : void 0 };
|
|
234
|
+
}).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), St = (e, t) => !U(e.target, t.target), ot = (e, t) => {
|
|
235
|
+
const n = vt(e, t), o = Tt(e, t), i = Bt(e, t);
|
|
237
236
|
return {
|
|
238
237
|
oldValue: e,
|
|
239
238
|
newValue: t,
|
|
@@ -244,13 +243,13 @@ const Et = (e, t) => {
|
|
|
244
243
|
};
|
|
245
244
|
};
|
|
246
245
|
var C = /* @__PURE__ */ ((e) => (e.LOCAL = "LOCAL", e.REMOTE = "REMOTE", e))(C || {});
|
|
247
|
-
const
|
|
246
|
+
const Mt = (e, t) => {
|
|
248
247
|
var n, o;
|
|
249
248
|
const { changes: i, origin: s } = t;
|
|
250
249
|
if (!(!e.options.origin || e.options.origin === s))
|
|
251
250
|
return !1;
|
|
252
251
|
if (e.options.ignore) {
|
|
253
|
-
const { ignore: a } = e.options, r = (d) =>
|
|
252
|
+
const { ignore: a } = e.options, r = (d) => d && d.length > 0;
|
|
254
253
|
if (!(r(i.created) || r(i.deleted))) {
|
|
255
254
|
const d = (n = i.updated) == null ? void 0 : n.some((b) => r(b.bodiesCreated) || r(b.bodiesDeleted) || r(b.bodiesUpdated)), u = (o = i.updated) == null ? void 0 : o.some((b) => b.targetUpdated);
|
|
256
255
|
if (a === "BODY_ONLY" && d && !u || a === "TARGET_ONLY" && u && !d)
|
|
@@ -259,26 +258,26 @@ const Lt = (e, t) => {
|
|
|
259
258
|
}
|
|
260
259
|
if (e.options.annotations) {
|
|
261
260
|
const a = /* @__PURE__ */ new Set([
|
|
262
|
-
...i.created.map((r) => r.id),
|
|
263
|
-
...i.deleted.map((r) => r.id),
|
|
264
|
-
...i.updated.map(({ oldValue: r }) => r.id)
|
|
261
|
+
...(i.created || []).map((r) => r.id),
|
|
262
|
+
...(i.deleted || []).map((r) => r.id),
|
|
263
|
+
...(i.updated || []).map(({ oldValue: r }) => r.id)
|
|
265
264
|
]);
|
|
266
265
|
return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((r) => a.has(r));
|
|
267
266
|
} else
|
|
268
267
|
return !0;
|
|
269
|
-
},
|
|
268
|
+
}, Lt = (e, t) => {
|
|
270
269
|
const n = new Set((e.created || []).map((h) => h.id)), o = new Set((e.updated || []).map(({ newValue: h }) => h.id)), i = new Set((t.created || []).map((h) => h.id)), s = new Set((t.deleted || []).map((h) => h.id)), a = new Set((t.updated || []).map(({ oldValue: h }) => h.id)), r = new Set((t.updated || []).filter(({ oldValue: h }) => n.has(h.id) || o.has(h.id)).map(({ oldValue: h }) => h.id)), d = [
|
|
271
|
-
...(e.created || []).filter((h) => !s.has(h.id)).map((h) => a.has(h.id) ? t.updated.find(({ oldValue:
|
|
270
|
+
...(e.created || []).filter((h) => !s.has(h.id)).map((h) => a.has(h.id) ? t.updated.find(({ oldValue: v }) => v.id === h.id).newValue : h),
|
|
272
271
|
...t.created || []
|
|
273
272
|
], u = [
|
|
274
273
|
...(e.deleted || []).filter((h) => !i.has(h.id)),
|
|
275
274
|
...(t.deleted || []).filter((h) => !n.has(h.id))
|
|
276
275
|
], b = [
|
|
277
276
|
...(e.updated || []).filter(({ newValue: h }) => !s.has(h.id)).map((h) => {
|
|
278
|
-
const { oldValue:
|
|
277
|
+
const { oldValue: v, newValue: m } = h;
|
|
279
278
|
if (a.has(m.id)) {
|
|
280
|
-
const
|
|
281
|
-
return ot(
|
|
279
|
+
const x = t.updated.find((M) => M.oldValue.id === m.id).newValue;
|
|
280
|
+
return ot(v, x);
|
|
282
281
|
} else
|
|
283
282
|
return h;
|
|
284
283
|
}),
|
|
@@ -286,65 +285,65 @@ const Lt = (e, t) => {
|
|
|
286
285
|
];
|
|
287
286
|
return { created: d, deleted: u, updated: b };
|
|
288
287
|
}, Ct = (e) => e.id !== void 0, Rt = () => {
|
|
289
|
-
const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = [], o = (f,
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
}, s = (f,
|
|
293
|
-
const
|
|
288
|
+
const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = [], o = (f, A = {}) => n.push({ onChange: f, options: A }), i = (f) => {
|
|
289
|
+
const A = n.findIndex((w) => w.onChange == f);
|
|
290
|
+
A > -1 && n.splice(A, 1);
|
|
291
|
+
}, s = (f, A) => {
|
|
292
|
+
const w = {
|
|
294
293
|
origin: f,
|
|
295
294
|
changes: {
|
|
296
|
-
created:
|
|
297
|
-
updated:
|
|
298
|
-
deleted:
|
|
295
|
+
created: A.created || [],
|
|
296
|
+
updated: A.updated || [],
|
|
297
|
+
deleted: A.deleted || []
|
|
299
298
|
},
|
|
300
299
|
state: [...e.values()]
|
|
301
300
|
};
|
|
302
301
|
n.forEach((B) => {
|
|
303
|
-
|
|
302
|
+
Mt(B, w) && B.onChange(w);
|
|
304
303
|
});
|
|
305
|
-
}, a = (f,
|
|
304
|
+
}, a = (f, A = C.LOCAL) => {
|
|
306
305
|
if (e.get(f.id))
|
|
307
306
|
throw Error(`Cannot add annotation ${f.id} - exists already`);
|
|
308
|
-
e.set(f.id, f), f.bodies.forEach((
|
|
309
|
-
}, r = (f,
|
|
310
|
-
const
|
|
307
|
+
e.set(f.id, f), f.bodies.forEach((w) => t.set(w.id, f.id)), s(A, { created: [f] });
|
|
308
|
+
}, r = (f, A) => {
|
|
309
|
+
const w = typeof f == "string" ? A : f, B = typeof f == "string" ? f : f.id, S = e.get(B);
|
|
311
310
|
if (S) {
|
|
312
|
-
const R = ot(S,
|
|
313
|
-
return B ===
|
|
311
|
+
const R = ot(S, w);
|
|
312
|
+
return B === w.id ? e.set(B, w) : (e.delete(B), e.set(w.id, w)), S.bodies.forEach((X) => t.delete(X.id)), w.bodies.forEach((X) => t.set(X.id, w.id)), R;
|
|
314
313
|
} else
|
|
315
314
|
console.warn(`Cannot update annotation ${B} - does not exist`);
|
|
316
|
-
}, d = (f,
|
|
317
|
-
const B = Ct(
|
|
315
|
+
}, d = (f, A = C.LOCAL, w = C.LOCAL) => {
|
|
316
|
+
const B = Ct(A) ? w : A, S = r(f, A);
|
|
318
317
|
S && s(B, { updated: [S] });
|
|
319
|
-
}, u = (f,
|
|
320
|
-
const
|
|
318
|
+
}, u = (f, A = C.LOCAL) => {
|
|
319
|
+
const w = f.reduce((B, S) => {
|
|
321
320
|
const R = r(S);
|
|
322
321
|
return R ? [...B, R] : B;
|
|
323
322
|
}, []);
|
|
324
|
-
|
|
325
|
-
}, b = (f,
|
|
326
|
-
const
|
|
327
|
-
if (
|
|
323
|
+
w.length > 0 && s(A, { updated: w });
|
|
324
|
+
}, b = (f, A = C.LOCAL) => {
|
|
325
|
+
const w = e.get(f.annotation);
|
|
326
|
+
if (w) {
|
|
328
327
|
const B = {
|
|
329
|
-
...
|
|
330
|
-
bodies: [...
|
|
328
|
+
...w,
|
|
329
|
+
bodies: [...w.bodies, f]
|
|
331
330
|
};
|
|
332
|
-
e.set(
|
|
333
|
-
oldValue:
|
|
331
|
+
e.set(w.id, B), t.set(f.id, B.id), s(A, { updated: [{
|
|
332
|
+
oldValue: w,
|
|
334
333
|
newValue: B,
|
|
335
334
|
bodiesCreated: [f]
|
|
336
335
|
}] });
|
|
337
336
|
} else
|
|
338
337
|
console.warn(`Attempt to add body to missing annotation: ${f.annotation}`);
|
|
339
|
-
}, h = () => [...e.values()],
|
|
340
|
-
const
|
|
341
|
-
e.clear(), t.clear(), s(f, { deleted:
|
|
342
|
-
}, m = (f,
|
|
343
|
-
if (
|
|
338
|
+
}, h = () => [...e.values()], v = (f = C.LOCAL) => {
|
|
339
|
+
const A = [...e.values()];
|
|
340
|
+
e.clear(), t.clear(), s(f, { deleted: A });
|
|
341
|
+
}, m = (f, A = !0, w = C.LOCAL) => {
|
|
342
|
+
if (A) {
|
|
344
343
|
const B = [...e.values()];
|
|
345
344
|
e.clear(), t.clear(), f.forEach((S) => {
|
|
346
345
|
e.set(S.id, S), S.bodies.forEach((R) => t.set(R.id, S.id));
|
|
347
|
-
}), s(
|
|
346
|
+
}), s(w, { created: f, deleted: B });
|
|
348
347
|
} else {
|
|
349
348
|
const B = f.reduce((S, R) => {
|
|
350
349
|
const X = e.get(R.id);
|
|
@@ -354,34 +353,34 @@ const Lt = (e, t) => {
|
|
|
354
353
|
throw Error(`Bulk insert would overwrite the following annotations: ${B.map((S) => S.id).join(", ")}`);
|
|
355
354
|
f.forEach((S) => {
|
|
356
355
|
e.set(S.id, S), S.bodies.forEach((R) => t.set(R.id, S.id));
|
|
357
|
-
}), s(
|
|
356
|
+
}), s(w, { created: f });
|
|
358
357
|
}
|
|
359
|
-
},
|
|
360
|
-
const
|
|
361
|
-
if (
|
|
362
|
-
return e.delete(
|
|
363
|
-
console.warn(`Attempt to delete missing annotation: ${
|
|
364
|
-
},
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
}, y = (f,
|
|
368
|
-
const
|
|
369
|
-
const R =
|
|
358
|
+
}, x = (f) => {
|
|
359
|
+
const A = typeof f == "string" ? f : f.id, w = e.get(A);
|
|
360
|
+
if (w)
|
|
361
|
+
return e.delete(A), w.bodies.forEach((B) => t.delete(B.id)), w;
|
|
362
|
+
console.warn(`Attempt to delete missing annotation: ${A}`);
|
|
363
|
+
}, M = (f, A = C.LOCAL) => {
|
|
364
|
+
const w = x(f);
|
|
365
|
+
w && s(A, { deleted: [w] });
|
|
366
|
+
}, y = (f, A = C.LOCAL) => {
|
|
367
|
+
const w = f.reduce((B, S) => {
|
|
368
|
+
const R = x(S);
|
|
370
369
|
return R ? [...B, R] : B;
|
|
371
370
|
}, []);
|
|
372
|
-
|
|
373
|
-
}, l = (f,
|
|
374
|
-
const
|
|
375
|
-
if (
|
|
376
|
-
const B =
|
|
371
|
+
w.length > 0 && s(A, { deleted: w });
|
|
372
|
+
}, l = (f, A = C.LOCAL) => {
|
|
373
|
+
const w = e.get(f.annotation);
|
|
374
|
+
if (w) {
|
|
375
|
+
const B = w.bodies.find((S) => S.id === f.id);
|
|
377
376
|
if (B) {
|
|
378
377
|
t.delete(B.id);
|
|
379
378
|
const S = {
|
|
380
|
-
...
|
|
381
|
-
bodies:
|
|
379
|
+
...w,
|
|
380
|
+
bodies: w.bodies.filter((R) => R.id !== f.id)
|
|
382
381
|
};
|
|
383
|
-
e.set(
|
|
384
|
-
oldValue:
|
|
382
|
+
e.set(w.id, S), s(A, { updated: [{
|
|
383
|
+
oldValue: w,
|
|
385
384
|
newValue: S,
|
|
386
385
|
bodiesDeleted: [B]
|
|
387
386
|
}] });
|
|
@@ -390,54 +389,54 @@ const Lt = (e, t) => {
|
|
|
390
389
|
} else
|
|
391
390
|
console.warn(`Attempt to delete body from missing annotation ${f.annotation}`);
|
|
392
391
|
}, c = (f) => {
|
|
393
|
-
const
|
|
394
|
-
return
|
|
392
|
+
const A = e.get(f);
|
|
393
|
+
return A ? { ...A } : void 0;
|
|
395
394
|
}, g = (f) => {
|
|
396
|
-
const
|
|
397
|
-
if (
|
|
398
|
-
const
|
|
399
|
-
if (
|
|
400
|
-
return
|
|
395
|
+
const A = t.get(f);
|
|
396
|
+
if (A) {
|
|
397
|
+
const w = c(A).bodies.find((B) => B.id === f);
|
|
398
|
+
if (w)
|
|
399
|
+
return w;
|
|
401
400
|
console.error(`Store integrity error: body ${f} in index, but not in annotation`);
|
|
402
401
|
} else
|
|
403
402
|
console.warn(`Attempt to retrieve missing body: ${f}`);
|
|
404
|
-
}, p = (f,
|
|
405
|
-
if (f.annotation !==
|
|
403
|
+
}, p = (f, A) => {
|
|
404
|
+
if (f.annotation !== A.annotation)
|
|
406
405
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
407
|
-
const
|
|
408
|
-
if (
|
|
409
|
-
const B =
|
|
410
|
-
...
|
|
411
|
-
bodies:
|
|
406
|
+
const w = e.get(f.annotation);
|
|
407
|
+
if (w) {
|
|
408
|
+
const B = w.bodies.find((R) => R.id === f.id), S = {
|
|
409
|
+
...w,
|
|
410
|
+
bodies: w.bodies.map((R) => R.id === B.id ? A : R)
|
|
412
411
|
};
|
|
413
|
-
return e.set(
|
|
414
|
-
oldValue:
|
|
412
|
+
return e.set(w.id, S), B.id !== A.id && (t.delete(B.id), t.set(A.id, S.id)), {
|
|
413
|
+
oldValue: w,
|
|
415
414
|
newValue: S,
|
|
416
|
-
bodiesUpdated: [{ oldBody: B, newBody:
|
|
415
|
+
bodiesUpdated: [{ oldBody: B, newBody: A }]
|
|
417
416
|
};
|
|
418
417
|
} else
|
|
419
418
|
console.warn(`Attempt to add body to missing annotation ${f.annotation}`);
|
|
420
|
-
},
|
|
421
|
-
const B = p(f,
|
|
422
|
-
s(
|
|
423
|
-
}, T = (f,
|
|
424
|
-
const
|
|
425
|
-
s(
|
|
426
|
-
},
|
|
427
|
-
const
|
|
428
|
-
if (
|
|
429
|
-
const
|
|
430
|
-
...
|
|
419
|
+
}, E = (f, A, w = C.LOCAL) => {
|
|
420
|
+
const B = p(f, A);
|
|
421
|
+
B && s(w, { updated: [B] });
|
|
422
|
+
}, T = (f, A = C.LOCAL) => {
|
|
423
|
+
const w = f.map((B) => p({ id: B.id, annotation: B.annotation }, B)).filter(Boolean);
|
|
424
|
+
s(A, { updated: w });
|
|
425
|
+
}, L = (f) => {
|
|
426
|
+
const A = e.get(f.annotation);
|
|
427
|
+
if (A) {
|
|
428
|
+
const w = {
|
|
429
|
+
...A,
|
|
431
430
|
target: {
|
|
432
|
-
...
|
|
431
|
+
...A.target,
|
|
433
432
|
...f
|
|
434
433
|
}
|
|
435
434
|
};
|
|
436
|
-
return e.set(
|
|
437
|
-
oldValue:
|
|
438
|
-
newValue:
|
|
435
|
+
return e.set(A.id, w), {
|
|
436
|
+
oldValue: A,
|
|
437
|
+
newValue: w,
|
|
439
438
|
targetUpdated: {
|
|
440
|
-
oldTarget:
|
|
439
|
+
oldTarget: A.target,
|
|
441
440
|
newTarget: f
|
|
442
441
|
}
|
|
443
442
|
};
|
|
@@ -452,79 +451,78 @@ const Lt = (e, t) => {
|
|
|
452
451
|
bulkDeleteAnnotation: y,
|
|
453
452
|
bulkUpdateAnnotation: u,
|
|
454
453
|
bulkUpdateBodies: T,
|
|
455
|
-
bulkUpdateTargets: (f,
|
|
456
|
-
const
|
|
457
|
-
|
|
454
|
+
bulkUpdateTargets: (f, A = C.LOCAL) => {
|
|
455
|
+
const w = f.map((B) => L(B)).filter(Boolean);
|
|
456
|
+
w.length > 0 && s(A, { updated: w });
|
|
458
457
|
},
|
|
459
|
-
clear:
|
|
460
|
-
deleteAnnotation:
|
|
458
|
+
clear: v,
|
|
459
|
+
deleteAnnotation: M,
|
|
461
460
|
deleteBody: l,
|
|
462
461
|
getAnnotation: c,
|
|
463
462
|
getBody: g,
|
|
464
463
|
observe: o,
|
|
465
464
|
unobserve: i,
|
|
466
465
|
updateAnnotation: d,
|
|
467
|
-
updateBody:
|
|
468
|
-
updateTarget: (f,
|
|
469
|
-
const
|
|
470
|
-
|
|
466
|
+
updateBody: E,
|
|
467
|
+
updateTarget: (f, A = C.LOCAL) => {
|
|
468
|
+
const w = L(f);
|
|
469
|
+
w && s(A, { updated: [w] });
|
|
471
470
|
}
|
|
472
471
|
};
|
|
473
472
|
};
|
|
474
473
|
let Ot = () => ({
|
|
475
474
|
emit(e, ...t) {
|
|
476
|
-
let n = this.events[e] || [];
|
|
477
|
-
|
|
478
|
-
n[o](...t);
|
|
475
|
+
for (let n = 0, o = this.events[e] || [], i = o.length; n < i; n++)
|
|
476
|
+
o[n](...t);
|
|
479
477
|
},
|
|
480
478
|
events: {},
|
|
481
479
|
on(e, t) {
|
|
482
480
|
var n;
|
|
483
|
-
return (n = this.events[e]
|
|
481
|
+
return ((n = this.events)[e] || (n[e] = [])).push(t), () => {
|
|
484
482
|
var o;
|
|
485
483
|
this.events[e] = (o = this.events[e]) == null ? void 0 : o.filter((i) => t !== i);
|
|
486
484
|
};
|
|
487
485
|
}
|
|
488
486
|
});
|
|
489
|
-
const Xt = 250,
|
|
487
|
+
const Xt = 250, Yt = (e) => {
|
|
490
488
|
const t = Ot(), n = [];
|
|
491
489
|
let o = -1, i = !1, s = 0;
|
|
492
490
|
const a = (m) => {
|
|
493
491
|
if (!i) {
|
|
494
|
-
const { changes:
|
|
495
|
-
if (
|
|
496
|
-
n.splice(o + 1), n.push(
|
|
492
|
+
const { changes: x } = m, M = performance.now();
|
|
493
|
+
if (M - s > Xt)
|
|
494
|
+
n.splice(o + 1), n.push(x), o = n.length - 1;
|
|
497
495
|
else {
|
|
498
496
|
const y = n.length - 1;
|
|
499
|
-
n[y] =
|
|
497
|
+
n[y] = Lt(n[y], x);
|
|
500
498
|
}
|
|
501
|
-
s =
|
|
499
|
+
s = M;
|
|
502
500
|
}
|
|
503
501
|
i = !1;
|
|
504
502
|
};
|
|
505
503
|
e.observe(a, { origin: C.LOCAL });
|
|
506
|
-
const r = (m) =>
|
|
504
|
+
const r = (m) => m && m.length > 0 && e.bulkDeleteAnnotation(m), d = (m) => m && m.length > 0 && e.bulkAddAnnotation(m, !1), u = (m) => m && m.length > 0 && e.bulkUpdateAnnotation(m.map(({ oldValue: x }) => x)), b = (m) => m && m.length > 0 && e.bulkUpdateAnnotation(m.map(({ newValue: x }) => x)), h = (m) => m && m.length > 0 && e.bulkAddAnnotation(m, !1), v = (m) => m && m.length > 0 && e.bulkDeleteAnnotation(m);
|
|
507
505
|
return {
|
|
508
506
|
canRedo: () => n.length - 1 > o,
|
|
509
507
|
canUndo: () => o > -1,
|
|
510
508
|
destroy: () => e.unobserve(a),
|
|
511
|
-
on: (m,
|
|
509
|
+
on: (m, x) => t.on(m, x),
|
|
512
510
|
redo: () => {
|
|
513
511
|
if (n.length - 1 > o) {
|
|
514
512
|
i = !0;
|
|
515
|
-
const { created: m, updated:
|
|
516
|
-
d(m), b(
|
|
513
|
+
const { created: m, updated: x, deleted: M } = n[o + 1];
|
|
514
|
+
d(m), b(x), v(M), t.emit("redo", n[o + 1]), o += 1;
|
|
517
515
|
}
|
|
518
516
|
},
|
|
519
517
|
undo: () => {
|
|
520
518
|
if (o > -1) {
|
|
521
519
|
i = !0;
|
|
522
|
-
const { created: m, updated:
|
|
523
|
-
r(m), u(
|
|
520
|
+
const { created: m, updated: x, deleted: M } = n[o];
|
|
521
|
+
r(m), u(x), h(M), t.emit("undo", n[o]), o -= 1;
|
|
524
522
|
}
|
|
525
523
|
}
|
|
526
524
|
};
|
|
527
|
-
},
|
|
525
|
+
}, Ut = () => {
|
|
528
526
|
const { subscribe: e, set: t } = J([]);
|
|
529
527
|
return {
|
|
530
528
|
subscribe: e,
|
|
@@ -533,27 +531,27 @@ const Xt = 250, Ut = (e) => {
|
|
|
533
531
|
}, Dt = (e, t, n, o) => {
|
|
534
532
|
const { store: i, selection: s, hover: a, viewport: r } = e, d = /* @__PURE__ */ new Map();
|
|
535
533
|
let u = [], b, h;
|
|
536
|
-
const
|
|
534
|
+
const v = (l, c) => {
|
|
537
535
|
d.has(l) ? d.get(l).push(c) : d.set(l, [c]);
|
|
538
536
|
}, m = (l, c) => {
|
|
539
537
|
const g = d.get(l);
|
|
540
538
|
g && g.indexOf(c) > 0 && g.splice(g.indexOf(c), 1);
|
|
541
|
-
},
|
|
539
|
+
}, x = (l, c, g) => {
|
|
542
540
|
d.has(l) && setTimeout(() => {
|
|
543
541
|
d.get(l).forEach((p) => {
|
|
544
542
|
if (n) {
|
|
545
|
-
const
|
|
546
|
-
p(
|
|
543
|
+
const E = Array.isArray(c) ? c.map((L) => n.serialize(L)) : n.serialize(c), T = g ? g instanceof PointerEvent ? g : n.serialize(g) : void 0;
|
|
544
|
+
p(E, T);
|
|
547
545
|
} else
|
|
548
546
|
p(c, g);
|
|
549
547
|
});
|
|
550
548
|
}, 1);
|
|
551
|
-
},
|
|
552
|
-
const { selected: l } = s, c = l.map(({ id: g }) => i.getAnnotation(g));
|
|
549
|
+
}, M = () => {
|
|
550
|
+
const { selected: l } = s, c = (l || []).map(({ id: g }) => i.getAnnotation(g));
|
|
553
551
|
c.forEach((g) => {
|
|
554
|
-
const p = u.find((
|
|
555
|
-
(!p || !
|
|
556
|
-
}), u = u.map((g) => c.find(({ id:
|
|
552
|
+
const p = u.find((E) => E.id === g.id);
|
|
553
|
+
(!p || !U(p, g)) && x("updateAnnotation", g, p);
|
|
554
|
+
}), u = u.map((g) => c.find(({ id: E }) => E === g.id) || g);
|
|
557
555
|
};
|
|
558
556
|
s.subscribe(({ selected: l }) => {
|
|
559
557
|
if (!(u.length === 0 && l.length === 0)) {
|
|
@@ -562,13 +560,13 @@ const Xt = 250, Ut = (e) => {
|
|
|
562
560
|
else if (u.length > 0 && l.length === 0)
|
|
563
561
|
u.forEach((c) => {
|
|
564
562
|
const g = i.getAnnotation(c.id);
|
|
565
|
-
g && !
|
|
563
|
+
g && !U(g, c) && x("updateAnnotation", g, c);
|
|
566
564
|
}), u = [];
|
|
567
565
|
else {
|
|
568
566
|
const c = new Set(u.map((p) => p.id)), g = new Set(l.map(({ id: p }) => p));
|
|
569
567
|
u.filter((p) => !g.has(p.id)).forEach((p) => {
|
|
570
|
-
const
|
|
571
|
-
|
|
568
|
+
const E = i.getAnnotation(p.id);
|
|
569
|
+
E && !U(E, p) && x("updateAnnotation", E, p);
|
|
572
570
|
}), u = [
|
|
573
571
|
// Remove annotations that were deselected
|
|
574
572
|
...u.filter((p) => g.has(p.id)),
|
|
@@ -576,40 +574,42 @@ const Xt = 250, Ut = (e) => {
|
|
|
576
574
|
...l.filter(({ id: p }) => !c.has(p)).map(({ id: p }) => i.getAnnotation(p))
|
|
577
575
|
];
|
|
578
576
|
}
|
|
579
|
-
|
|
577
|
+
x("selectionChanged", u);
|
|
580
578
|
}
|
|
581
579
|
}), a.subscribe((l) => {
|
|
582
|
-
!b && l ?
|
|
583
|
-
}), r == null || r.subscribe((l) =>
|
|
584
|
-
o && (h && clearTimeout(h), h = setTimeout(
|
|
580
|
+
!b && l ? x("mouseEnterAnnotation", i.getAnnotation(l)) : b && !l ? x("mouseLeaveAnnotation", i.getAnnotation(b)) : b && l && (x("mouseLeaveAnnotation", i.getAnnotation(b)), x("mouseEnterAnnotation", i.getAnnotation(l))), b = l;
|
|
581
|
+
}), r == null || r.subscribe((l) => x("viewportIntersect", l.map((c) => i.getAnnotation(c)))), i.observe((l) => {
|
|
582
|
+
o && (h && clearTimeout(h), h = setTimeout(M, 1e3));
|
|
585
583
|
const { created: c, deleted: g } = l.changes;
|
|
586
|
-
c.forEach((p) =>
|
|
584
|
+
(c || []).forEach((p) => x("createAnnotation", p)), (g || []).forEach((p) => x("deleteAnnotation", p)), (l.changes.updated || []).filter((p) => [
|
|
587
585
|
...p.bodiesCreated || [],
|
|
588
586
|
...p.bodiesDeleted || [],
|
|
589
587
|
...p.bodiesUpdated || []
|
|
590
|
-
].length > 0).forEach(({ oldValue: p, newValue:
|
|
591
|
-
const T = u.find((
|
|
592
|
-
u = u.map((
|
|
588
|
+
].length > 0).forEach(({ oldValue: p, newValue: E }) => {
|
|
589
|
+
const T = u.find((L) => L.id === p.id) || p;
|
|
590
|
+
u = u.map((L) => L.id === p.id ? E : L), x("updateAnnotation", E, T);
|
|
593
591
|
});
|
|
594
592
|
}, { origin: C.LOCAL }), i.observe((l) => {
|
|
595
593
|
if (u) {
|
|
596
|
-
const c = new Set(u.map((p) => p.id)), g = l.changes.updated.filter(({ newValue: p }) => c.has(p.id)).map(({ newValue: p }) => p);
|
|
594
|
+
const c = new Set(u.map((p) => p.id)), g = (l.changes.updated || []).filter(({ newValue: p }) => c.has(p.id)).map(({ newValue: p }) => p);
|
|
597
595
|
g.length > 0 && (u = u.map((p) => g.find((T) => T.id === p.id) || p));
|
|
598
596
|
}
|
|
599
597
|
}, { origin: C.REMOTE });
|
|
600
598
|
const y = (l) => (c) => {
|
|
601
|
-
const { created: g, deleted: p, updated:
|
|
602
|
-
g.forEach((T) =>
|
|
599
|
+
const { created: g, deleted: p, updated: E } = c;
|
|
600
|
+
(g || []).forEach((T) => x("createAnnotation", T)), (p || []).forEach((T) => x("deleteAnnotation", T)), l ? (E || []).forEach((T) => x("updateAnnotation", T.oldValue, T.newValue)) : (E || []).forEach((T) => x("updateAnnotation", T.newValue, T.oldValue));
|
|
603
601
|
};
|
|
604
|
-
return t.on("undo", y(!0)), t.on("redo", y(!1)), { on:
|
|
602
|
+
return t.on("undo", y(!0)), t.on("redo", y(!1)), { on: v, off: m, emit: x };
|
|
605
603
|
}, It = (e) => (t) => t.reduce((n, o) => {
|
|
606
604
|
const { parsed: i, error: s } = e.parse(o);
|
|
607
605
|
return s ? {
|
|
608
606
|
parsed: n.parsed,
|
|
609
607
|
failed: [...n.failed, o]
|
|
610
|
-
} : {
|
|
608
|
+
} : i ? {
|
|
611
609
|
parsed: [...n.parsed, i],
|
|
612
610
|
failed: n.failed
|
|
611
|
+
} : {
|
|
612
|
+
...n
|
|
613
613
|
};
|
|
614
614
|
}, { parsed: [], failed: [] }), Vt = (e, t, n) => {
|
|
615
615
|
const { store: o, selection: i } = e, s = (y) => {
|
|
@@ -623,15 +623,17 @@ const Xt = 250, Ut = (e) => {
|
|
|
623
623
|
return n && l ? n.serialize(l) : l;
|
|
624
624
|
}, u = () => n ? o.all().map(n.serialize) : o.all(), b = () => {
|
|
625
625
|
var y;
|
|
626
|
-
const l = (((y = i.selected) == null ? void 0 : y.map((c) => c.id)) || []).map((c) => o.getAnnotation(c));
|
|
626
|
+
const l = (((y = i.selected) == null ? void 0 : y.map((c) => c.id)) || []).map((c) => o.getAnnotation(c)).filter(Boolean);
|
|
627
627
|
return n ? l.map(n.serialize) : l;
|
|
628
|
-
}, h = (y) => fetch(y).then((l) => l.json()).then((l) => (m(l), l)),
|
|
628
|
+
}, h = (y) => fetch(y).then((l) => l.json()).then((l) => (m(l), l)), v = (y) => {
|
|
629
629
|
if (typeof y == "string") {
|
|
630
630
|
const l = o.getAnnotation(y);
|
|
631
|
-
|
|
631
|
+
if (o.deleteAnnotation(y), l)
|
|
632
|
+
return n ? n.serialize(l) : l;
|
|
632
633
|
} else {
|
|
633
634
|
const l = n ? n.parse(y).parsed : y;
|
|
634
|
-
|
|
635
|
+
if (l)
|
|
636
|
+
return o.deleteAnnotation(l), y;
|
|
635
637
|
}
|
|
636
638
|
}, m = (y) => {
|
|
637
639
|
if (n) {
|
|
@@ -639,9 +641,9 @@ const Xt = 250, Ut = (e) => {
|
|
|
639
641
|
c.length > 0 && console.warn(`Discarded ${c.length} invalid annotations`, c), o.bulkAddAnnotation(l, !0, C.REMOTE);
|
|
640
642
|
} else
|
|
641
643
|
o.bulkAddAnnotation(y, !0, C.REMOTE);
|
|
642
|
-
},
|
|
644
|
+
}, x = (y) => {
|
|
643
645
|
y ? i.setSelected(y) : i.clear();
|
|
644
|
-
},
|
|
646
|
+
}, M = (y) => {
|
|
645
647
|
if (n) {
|
|
646
648
|
const l = n.parse(y).parsed, c = n.serialize(o.getAnnotation(l.id));
|
|
647
649
|
return o.updateAnnotation(l), c;
|
|
@@ -661,11 +663,11 @@ const Xt = 250, Ut = (e) => {
|
|
|
661
663
|
getSelected: b,
|
|
662
664
|
loadAnnotations: h,
|
|
663
665
|
redo: t.redo,
|
|
664
|
-
removeAnnotation:
|
|
666
|
+
removeAnnotation: v,
|
|
665
667
|
setAnnotations: m,
|
|
666
|
-
setSelected:
|
|
668
|
+
setSelected: x,
|
|
667
669
|
undo: t.undo,
|
|
668
|
-
updateAnnotation:
|
|
670
|
+
updateAnnotation: M
|
|
669
671
|
};
|
|
670
672
|
};
|
|
671
673
|
let _t = (e) => crypto.getRandomValues(new Uint8Array(e)), kt = (e, t, n) => {
|
|
@@ -691,14 +693,14 @@ function it(e, t, n, o, i) {
|
|
|
691
693
|
var s = o - n + 1, a = t - n + 1, r = Math.log(s), d = 0.5 * Math.exp(2 * r / 3), u = 0.5 * Math.sqrt(r * d * (s - d) / s) * (a - s / 2 < 0 ? -1 : 1), b = Math.max(n, Math.floor(t - a * d / s + u)), h = Math.min(o, Math.floor(t + (s - a) * d / s + u));
|
|
692
694
|
it(e, t, b, h, i);
|
|
693
695
|
}
|
|
694
|
-
var
|
|
695
|
-
for (_(e, n, t), i(e[o],
|
|
696
|
-
for (_(e, m,
|
|
696
|
+
var v = e[t], m = n, x = o;
|
|
697
|
+
for (_(e, n, t), i(e[o], v) > 0 && _(e, n, o); m < x; ) {
|
|
698
|
+
for (_(e, m, x), m++, x--; i(e[m], v) < 0; )
|
|
697
699
|
m++;
|
|
698
|
-
for (; i(e[
|
|
699
|
-
|
|
700
|
+
for (; i(e[x], v) > 0; )
|
|
701
|
+
x--;
|
|
700
702
|
}
|
|
701
|
-
i(e[n],
|
|
703
|
+
i(e[n], v) === 0 ? _(e, n, x) : (x++, _(e, x, o)), x <= t && (n = x + 1), t <= x && (o = x - 1);
|
|
702
704
|
}
|
|
703
705
|
}
|
|
704
706
|
function _(e, t, n) {
|
|
@@ -824,9 +826,9 @@ class $t {
|
|
|
824
826
|
for (let b = n; b <= o; b += u) {
|
|
825
827
|
const h = Math.min(b + u - 1, o);
|
|
826
828
|
tt(t, b, h, d, this.compareMinY);
|
|
827
|
-
for (let
|
|
828
|
-
const m = Math.min(
|
|
829
|
-
r.children.push(this._build(t,
|
|
829
|
+
for (let v = b; v <= h; v += d) {
|
|
830
|
+
const m = Math.min(v + d - 1, h);
|
|
831
|
+
r.children.push(this._build(t, v, m, i - 1));
|
|
830
832
|
}
|
|
831
833
|
}
|
|
832
834
|
return I(r, this.toBBox), r;
|
|
@@ -1025,14 +1027,14 @@ const jt = (e, t) => {
|
|
|
1025
1027
|
return e;
|
|
1026
1028
|
}, ee = (e, t) => {
|
|
1027
1029
|
const n = new $t(), o = /* @__PURE__ */ new Map(), i = (l) => {
|
|
1028
|
-
const c = t.getBoundingClientRect(), p = l.selector.range instanceof Range && !l.selector.range.collapsed && l.selector.range.startContainer.nodeType === Node.TEXT_NODE && l.selector.range.endContainer.nodeType === Node.TEXT_NODE ? l : k(l, t),
|
|
1029
|
-
return T.map((
|
|
1030
|
-
const { x: f, y:
|
|
1030
|
+
const c = t.getBoundingClientRect(), p = l.selector.range instanceof Range && !l.selector.range.collapsed && l.selector.range.startContainer.nodeType === Node.TEXT_NODE && l.selector.range.endContainer.nodeType === Node.TEXT_NODE ? l : k(l, t), E = Array.from(p.selector.range.getClientRects()), T = Qt(E);
|
|
1031
|
+
return T.map((L) => {
|
|
1032
|
+
const { x: f, y: A, width: w, height: B } = L;
|
|
1031
1033
|
return {
|
|
1032
1034
|
minX: f - c.x,
|
|
1033
|
-
minY:
|
|
1034
|
-
maxX: f - c.x +
|
|
1035
|
-
maxY:
|
|
1035
|
+
minY: A - c.y,
|
|
1036
|
+
maxX: f - c.x + w,
|
|
1037
|
+
maxY: A - c.y + B,
|
|
1036
1038
|
annotation: {
|
|
1037
1039
|
id: l.annotation,
|
|
1038
1040
|
rects: T
|
|
@@ -1050,9 +1052,9 @@ const jt = (e, t) => {
|
|
|
1050
1052
|
d(l), r(l);
|
|
1051
1053
|
}, b = (l, c = !0) => {
|
|
1052
1054
|
c && a();
|
|
1053
|
-
const g = l.map((
|
|
1054
|
-
g.forEach(({ target:
|
|
1055
|
-
const p = g.reduce((
|
|
1055
|
+
const g = l.map((E) => ({ target: E, rects: i(E) }));
|
|
1056
|
+
g.forEach(({ target: E, rects: T }) => o.set(E.annotation, T));
|
|
1057
|
+
const p = g.reduce((E, { rects: T }) => [...E, ...T], []);
|
|
1056
1058
|
n.load(p);
|
|
1057
1059
|
}, h = (l, c) => {
|
|
1058
1060
|
const g = n.search({
|
|
@@ -1060,19 +1062,19 @@ const jt = (e, t) => {
|
|
|
1060
1062
|
minY: c,
|
|
1061
1063
|
maxX: l,
|
|
1062
1064
|
maxY: c
|
|
1063
|
-
}), p = (
|
|
1065
|
+
}), p = (E) => E.annotation.rects.reduce((T, L) => T + L.width * L.height, 0);
|
|
1064
1066
|
if (g.length > 0)
|
|
1065
|
-
return g.sort((
|
|
1066
|
-
},
|
|
1067
|
+
return g.sort((E, T) => p(E) - p(T)), g[0].annotation.id;
|
|
1068
|
+
}, v = (l) => {
|
|
1067
1069
|
const c = m(l);
|
|
1068
1070
|
if (c.length === 0)
|
|
1069
1071
|
return;
|
|
1070
|
-
let g = c[0].left, p = c[0].top,
|
|
1071
|
-
for (let
|
|
1072
|
-
const f = c[
|
|
1073
|
-
g = Math.min(g, f.left), p = Math.min(p, f.top),
|
|
1072
|
+
let g = c[0].left, p = c[0].top, E = c[0].right, T = c[0].bottom;
|
|
1073
|
+
for (let L = 1; L < c.length; L++) {
|
|
1074
|
+
const f = c[L];
|
|
1075
|
+
g = Math.min(g, f.left), p = Math.min(p, f.top), E = Math.max(E, f.right), T = Math.max(T, f.bottom);
|
|
1074
1076
|
}
|
|
1075
|
-
return new DOMRect(g, p,
|
|
1077
|
+
return new DOMRect(g, p, E - g, T - p);
|
|
1076
1078
|
}, m = (l) => {
|
|
1077
1079
|
const c = o.get(l);
|
|
1078
1080
|
return c ? c[0].annotation.rects : [];
|
|
@@ -1081,7 +1083,7 @@ const jt = (e, t) => {
|
|
|
1081
1083
|
all: s,
|
|
1082
1084
|
clear: a,
|
|
1083
1085
|
getAt: h,
|
|
1084
|
-
getBoundsForAnnotation:
|
|
1086
|
+
getBoundsForAnnotation: v,
|
|
1085
1087
|
getDOMRectsForAnnotation: m,
|
|
1086
1088
|
getIntersectingRects: (l, c, g, p) => n.search({ minX: l, minY: c, maxX: g, maxY: p }),
|
|
1087
1089
|
insert: r,
|
|
@@ -1095,14 +1097,14 @@ const jt = (e, t) => {
|
|
|
1095
1097
|
const { range: t } = e.target.selector;
|
|
1096
1098
|
return t instanceof Range && !t.collapsed;
|
|
1097
1099
|
}, ne = (e, t) => {
|
|
1098
|
-
const n = Rt(), o = ee(n, e), i =
|
|
1100
|
+
const n = Rt(), o = ee(n, e), i = xt(n, t), s = At(n), a = Ut(), r = (y, l = C.LOCAL) => {
|
|
1099
1101
|
const c = y.target.selector.range instanceof Range ? y : { ...y, target: k(y.target, e) }, { range: g } = c.target.selector, p = g && !g.collapsed;
|
|
1100
1102
|
return p && n.addAnnotation(c, l), p;
|
|
1101
1103
|
}, d = (y, l = !0, c = C.LOCAL) => {
|
|
1102
|
-
const g = y.map((
|
|
1103
|
-
if (g.some((
|
|
1104
|
-
const
|
|
1105
|
-
return console.warn("Could not revive all targets"), console.warn(
|
|
1104
|
+
const g = y.map((E) => F(E) ? E : { ...E, target: k(E.target, e) });
|
|
1105
|
+
if (g.some((E) => E.target.selector.range.collapsed)) {
|
|
1106
|
+
const E = g.filter((T) => T.target.selector.range.collapsed);
|
|
1107
|
+
return console.warn("Could not revive all targets"), console.warn(E), n.bulkAddAnnotation(g, l, c), E;
|
|
1106
1108
|
} else
|
|
1107
1109
|
return n.bulkAddAnnotation(g, l, c), [];
|
|
1108
1110
|
}, u = (y, l = C.LOCAL) => {
|
|
@@ -1114,26 +1116,26 @@ const jt = (e, t) => {
|
|
|
1114
1116
|
}, h = (y, l) => {
|
|
1115
1117
|
const c = o.getAt(y, l);
|
|
1116
1118
|
return c ? n.getAnnotation(c) : void 0;
|
|
1117
|
-
},
|
|
1119
|
+
}, v = (y, l, c, g) => {
|
|
1118
1120
|
const p = o.getIntersectingRects(y, l, c, g);
|
|
1119
1121
|
return Array.from(new Set(p.map((T) => T.annotation.id))).map((T) => n.getAnnotation(T)).filter((T) => T);
|
|
1120
1122
|
}, m = (y, l, c, g = 5) => {
|
|
1121
1123
|
const p = o.getDOMRectsForAnnotation(y);
|
|
1122
1124
|
if (p.length > 0) {
|
|
1123
1125
|
if (l && c) {
|
|
1124
|
-
const
|
|
1125
|
-
if (
|
|
1126
|
-
return
|
|
1126
|
+
const E = p.find(({ top: T, right: L, bottom: f, left: A }) => l >= A - g && l <= L + g && c >= T - g && c <= f + g);
|
|
1127
|
+
if (E)
|
|
1128
|
+
return E;
|
|
1127
1129
|
}
|
|
1128
1130
|
return o.getBoundsForAnnotation(y);
|
|
1129
1131
|
}
|
|
1130
|
-
},
|
|
1131
|
-
const
|
|
1132
|
-
return Object.entries(
|
|
1132
|
+
}, x = (y, l, c, g) => {
|
|
1133
|
+
const E = o.getIntersectingRects(y, l, c, g).reduce((T, L) => ((T[L.annotation.id] = T[L.annotation.id] || []).push(L), T), {});
|
|
1134
|
+
return Object.entries(E).map(([T, L]) => ({
|
|
1133
1135
|
annotation: n.getAnnotation(T),
|
|
1134
|
-
rects:
|
|
1136
|
+
rects: L.map(({ minX: f, minY: A, maxX: w, maxY: B }) => ({ x: f, y: A, width: w - f, height: B - A }))
|
|
1135
1137
|
}));
|
|
1136
|
-
},
|
|
1138
|
+
}, M = () => o.recalculate();
|
|
1137
1139
|
return n.observe(({ changes: y }) => {
|
|
1138
1140
|
const l = (y.created || []).filter(F), c = (y.deleted || []).filter(F), g = (y.updated || []).filter((p) => F(p.newValue));
|
|
1139
1141
|
l.length > 0 && o.set(l.map((p) => p.target), !1), (c == null ? void 0 : c.length) > 0 && c.forEach((p) => o.remove(p.target)), (g == null ? void 0 : g.length) > 0 && g.forEach(({ newValue: p }) => o.update(p.target));
|
|
@@ -1145,9 +1147,9 @@ const jt = (e, t) => {
|
|
|
1145
1147
|
bulkUpdateTargets: b,
|
|
1146
1148
|
getAnnotationBounds: m,
|
|
1147
1149
|
getAt: h,
|
|
1148
|
-
getIntersecting:
|
|
1149
|
-
getIntersectingRects:
|
|
1150
|
-
recalculatePositions:
|
|
1150
|
+
getIntersecting: v,
|
|
1151
|
+
getIntersectingRects: x,
|
|
1152
|
+
recalculatePositions: M,
|
|
1151
1153
|
updateTarget: u
|
|
1152
1154
|
},
|
|
1153
1155
|
selection: i,
|
|
@@ -1162,20 +1164,25 @@ const jt = (e, t) => {
|
|
|
1162
1164
|
t.font && (d.font = t.font);
|
|
1163
1165
|
const h = n.get(s.id);
|
|
1164
1166
|
if (h) {
|
|
1165
|
-
const { x:
|
|
1166
|
-
d.fillStyle = h.appearance.color, d.fillRect(
|
|
1167
|
-
const
|
|
1168
|
-
d.fillRect(
|
|
1167
|
+
const { x: v, y: m, height: x } = a[0];
|
|
1168
|
+
d.fillStyle = h.appearance.color, d.fillRect(v - 2, m - 2.5, 2, x + 5);
|
|
1169
|
+
const M = d.measureText(h.appearance.label), y = M.width + 6, l = M.actualBoundingBoxAscent + M.actualBoundingBoxDescent + 8, c = M.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1170
|
+
d.fillRect(v - 2, m - 2.5 - l, y, l), d.fillStyle = "#fff", d.fillText(h.appearance.label, v + 1, m - c), r.fillStyle = h.appearance.color, r.globalAlpha = u ? 0.45 : 0.18, a.forEach(({ x: g, y: p, width: E, height: T }) => r.fillRect(g, p - 2.5, E, T + 5));
|
|
1169
1171
|
} else
|
|
1170
1172
|
nt.paint(s, a, r, d, u, b);
|
|
1171
1173
|
} };
|
|
1172
|
-
}, st = (e) =>
|
|
1174
|
+
}, st = (e) => {
|
|
1175
|
+
if (e === null)
|
|
1176
|
+
return document.scrollingElement;
|
|
1177
|
+
const { overflowY: t } = window.getComputedStyle(e);
|
|
1178
|
+
return t !== "visible" && t !== "hidden" && e.scrollHeight > e.clientHeight ? e : st(e.parentElement);
|
|
1179
|
+
}, ie = (e, t) => (n) => {
|
|
1173
1180
|
const o = st(e);
|
|
1174
1181
|
if (o) {
|
|
1175
1182
|
const i = t.getAnnotation(n.id), { range: s } = i.target.selector;
|
|
1176
1183
|
if (!s || s.collapsed)
|
|
1177
1184
|
return !1;
|
|
1178
|
-
const a = o.getBoundingClientRect(), r = o.clientHeight, d = o.clientWidth, u = i.target.selector.range.getBoundingClientRect(), { width: b, height: h } = t.getAnnotationBounds(n.id),
|
|
1185
|
+
const a = o.getBoundingClientRect(), r = o.clientHeight, d = o.clientWidth, u = i.target.selector.range.getBoundingClientRect(), { width: b, height: h } = t.getAnnotationBounds(n.id), v = u.top - a.top, m = u.left - a.left, x = o.parentElement ? o.scrollTop : 0, M = o.parentElement ? o.scrollLeft : 0, y = v + x - (r - h) / 2, l = m + M - (d - b) / 2;
|
|
1179
1186
|
return o.scroll({ top: y, left: l, behavior: "smooth" }), !0;
|
|
1180
1187
|
}
|
|
1181
1188
|
};
|
|
@@ -1216,12 +1223,12 @@ const de = (e, t, n) => {
|
|
|
1216
1223
|
}, ue = (e, t, n) => {
|
|
1217
1224
|
const { store: o, selection: i } = t;
|
|
1218
1225
|
let s, a = null;
|
|
1219
|
-
const r = (
|
|
1226
|
+
const r = (v) => s = v;
|
|
1220
1227
|
let d = !1, u;
|
|
1221
|
-
e.addEventListener("selectstart", (
|
|
1228
|
+
e.addEventListener("selectstart", (v) => {
|
|
1222
1229
|
if (!d)
|
|
1223
1230
|
return;
|
|
1224
|
-
!
|
|
1231
|
+
!v.target.parentElement.closest(".not-annotatable") ? a = {
|
|
1225
1232
|
annotation: ce(),
|
|
1226
1233
|
selector: void 0,
|
|
1227
1234
|
creator: s,
|
|
@@ -1229,17 +1236,17 @@ const de = (e, t, n) => {
|
|
|
1229
1236
|
} : (a = null, u = void 0);
|
|
1230
1237
|
});
|
|
1231
1238
|
let b;
|
|
1232
|
-
document.addEventListener("selectionchange", (
|
|
1239
|
+
document.addEventListener("selectionchange", (v) => {
|
|
1233
1240
|
b && clearTimeout(b), b = setTimeout(() => h(), 50);
|
|
1234
1241
|
});
|
|
1235
1242
|
const h = () => {
|
|
1236
|
-
var m,
|
|
1237
|
-
const
|
|
1238
|
-
if (!
|
|
1239
|
-
const
|
|
1240
|
-
te(
|
|
1243
|
+
var m, x;
|
|
1244
|
+
const v = document.getSelection();
|
|
1245
|
+
if (!v.isCollapsed && d && a) {
|
|
1246
|
+
const M = Array.from(Array(v.rangeCount).keys()).map((c) => v.getRangeAt(c));
|
|
1247
|
+
te(M[0]).toString() !== ((x = (m = a.selector) == null ? void 0 : m.range) == null ? void 0 : x.toString()) && (a = {
|
|
1241
1248
|
...a,
|
|
1242
|
-
selector: de(
|
|
1249
|
+
selector: de(M[0], e, n)
|
|
1243
1250
|
}, o.getAnnotation(a.annotation) ? o.updateTarget(a, C.LOCAL) : (o.addAnnotation({
|
|
1244
1251
|
id: a.annotation,
|
|
1245
1252
|
bodies: [],
|
|
@@ -1247,18 +1254,18 @@ const de = (e, t, n) => {
|
|
|
1247
1254
|
}), i.clickSelect(a.annotation, u)));
|
|
1248
1255
|
}
|
|
1249
1256
|
};
|
|
1250
|
-
return e.addEventListener("pointerdown", (
|
|
1251
|
-
u =
|
|
1252
|
-
}), document.addEventListener("pointerup", (
|
|
1253
|
-
var
|
|
1254
|
-
u =
|
|
1257
|
+
return e.addEventListener("pointerdown", (v) => {
|
|
1258
|
+
u = v, d = v.button === 0;
|
|
1259
|
+
}), document.addEventListener("pointerup", (v) => {
|
|
1260
|
+
var x;
|
|
1261
|
+
u = v, !((x = v.target.parentElement) != null && x.closest(".not-annotatable") || !d) && setTimeout(() => {
|
|
1255
1262
|
if (a != null && a.selector)
|
|
1256
|
-
o.updateTarget(a, C.LOCAL), i.clickSelect(a.annotation,
|
|
1263
|
+
o.updateTarget(a, C.LOCAL), i.clickSelect(a.annotation, v), a = null, u = void 0;
|
|
1257
1264
|
else {
|
|
1258
|
-
const { x:
|
|
1265
|
+
const { x: M, y } = e.getBoundingClientRect(), l = o.getAt(v.clientX - M, v.clientY - y);
|
|
1259
1266
|
if (l) {
|
|
1260
1267
|
const { selected: c } = i;
|
|
1261
|
-
(c.length !== 1 || c[0].id !== l.id) && (i.clickSelect(l.id,
|
|
1268
|
+
(c.length !== 1 || c[0].id !== l.id) && (i.clickSelect(l.id, v), u = void 0);
|
|
1262
1269
|
} else
|
|
1263
1270
|
i.isEmpty() || i.clear();
|
|
1264
1271
|
}
|
|
@@ -1266,9 +1273,8 @@ const de = (e, t, n) => {
|
|
|
1266
1273
|
}), {
|
|
1267
1274
|
setUser: r
|
|
1268
1275
|
};
|
|
1269
|
-
}
|
|
1270
|
-
const
|
|
1271
|
-
const n = ne(e, t.pointerAction), { selection: o, viewport: i } = n, s = n.store, a = Ut(s), r = Dt(
|
|
1276
|
+
}, he = (e, t = {}) => {
|
|
1277
|
+
const n = ne(e, t.pointerAction), { selection: o, viewport: i } = n, s = n.store, a = Yt(s), r = Dt(
|
|
1272
1278
|
n,
|
|
1273
1279
|
a,
|
|
1274
1280
|
t.adapter
|