@soomo/text-annotator 3.0.0-staging.53 → 3.0.0-staging.54
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.
|
@@ -63,27 +63,27 @@ function re(t, e = 100, n = {}) {
|
|
|
63
63
|
throw new RangeError("`wait` must not be negative.");
|
|
64
64
|
const { immediate: o } = typeof n == "boolean" ? { immediate: n } : n;
|
|
65
65
|
let i, r, a, s, l;
|
|
66
|
-
function
|
|
67
|
-
const
|
|
68
|
-
return i = void 0, r = void 0, l = t.apply(
|
|
66
|
+
function f() {
|
|
67
|
+
const g = i, u = r;
|
|
68
|
+
return i = void 0, r = void 0, l = t.apply(g, u), l;
|
|
69
69
|
}
|
|
70
70
|
function h() {
|
|
71
|
-
const
|
|
72
|
-
|
|
71
|
+
const g = Date.now() - s;
|
|
72
|
+
g < e && g >= 0 ? a = setTimeout(h, e - g) : (a = void 0, o || (l = f()));
|
|
73
73
|
}
|
|
74
|
-
const c = function(...
|
|
74
|
+
const c = function(...g) {
|
|
75
75
|
if (i && this !== i)
|
|
76
76
|
throw new Error("Debounced method called with different contexts.");
|
|
77
|
-
i = this, r =
|
|
78
|
-
const
|
|
79
|
-
return a || (a = setTimeout(h, e)),
|
|
77
|
+
i = this, r = g, s = Date.now();
|
|
78
|
+
const u = o && !a;
|
|
79
|
+
return a || (a = setTimeout(h, e)), u && (l = f()), l;
|
|
80
80
|
};
|
|
81
81
|
return c.clear = () => {
|
|
82
82
|
a && (clearTimeout(a), a = void 0);
|
|
83
83
|
}, c.flush = () => {
|
|
84
84
|
a && c.trigger();
|
|
85
85
|
}, c.trigger = () => {
|
|
86
|
-
l =
|
|
86
|
+
l = f(), c.clear();
|
|
87
87
|
}, c;
|
|
88
88
|
}
|
|
89
89
|
_t.exports.debounce = re;
|
|
@@ -174,34 +174,34 @@ const Ie = /* @__PURE__ */ Be(ke), Ut = (t, e = 10, n) => {
|
|
|
174
174
|
const { start: n, end: o } = t, i = t.offsetReference || e, r = document.createNodeIterator(
|
|
175
175
|
e,
|
|
176
176
|
NodeFilter.SHOW_TEXT,
|
|
177
|
-
(
|
|
178
|
-
var
|
|
179
|
-
return (
|
|
177
|
+
(g) => {
|
|
178
|
+
var u;
|
|
179
|
+
return (u = g.parentElement) != null && u.closest(j) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
|
|
180
180
|
}
|
|
181
181
|
);
|
|
182
182
|
let a = 0;
|
|
183
183
|
const s = document.createRange();
|
|
184
184
|
let l = r.nextNode();
|
|
185
185
|
l === null && console.error("Could not revive annotation target. Content missing.");
|
|
186
|
-
let
|
|
186
|
+
let f = !i;
|
|
187
187
|
for (; l !== null; ) {
|
|
188
|
-
if (
|
|
189
|
-
const
|
|
190
|
-
if (a +
|
|
188
|
+
if (f || (f = i == null ? void 0 : i.contains(l)), f) {
|
|
189
|
+
const g = ((h = l.textContent) == null ? void 0 : h.length) || 0;
|
|
190
|
+
if (a + g > n) {
|
|
191
191
|
s.setStart(l, n - a);
|
|
192
192
|
break;
|
|
193
193
|
}
|
|
194
|
-
a +=
|
|
194
|
+
a += g;
|
|
195
195
|
}
|
|
196
196
|
l = r.nextNode();
|
|
197
197
|
}
|
|
198
198
|
for (; l !== null; ) {
|
|
199
|
-
const
|
|
200
|
-
if (a +
|
|
199
|
+
const g = ((c = l.textContent) == null ? void 0 : c.length) || 0;
|
|
200
|
+
if (a + g >= o) {
|
|
201
201
|
s.setEnd(l, o - a);
|
|
202
202
|
break;
|
|
203
203
|
}
|
|
204
|
-
a +=
|
|
204
|
+
a += g, l = r.nextNode();
|
|
205
205
|
}
|
|
206
206
|
return {
|
|
207
207
|
...t,
|
|
@@ -263,46 +263,46 @@ const Ie = /* @__PURE__ */ Be(ke), Ut = (t, e = 10, n) => {
|
|
|
263
263
|
timeStamp: t.timeStamp
|
|
264
264
|
}), Vt = (t, e, n, o) => {
|
|
265
265
|
const { store: i, selection: r, hover: a } = e;
|
|
266
|
-
let s, l,
|
|
266
|
+
let s, l, f;
|
|
267
267
|
const h = Ce(n), c = (O) => {
|
|
268
|
-
const { x: R, y:
|
|
269
|
-
|
|
268
|
+
const { x: R, y: m } = t.getBoundingClientRect(), v = i.getAt(O.clientX - R, O.clientY - m, l);
|
|
269
|
+
v ? a.current !== v.id && (t.classList.add("hovered"), a.set(v.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
|
|
270
270
|
};
|
|
271
271
|
t.addEventListener("pointermove", c);
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
const R = Se(t), { minX:
|
|
272
|
+
const g = (O = !1) => {
|
|
273
|
+
f && f.clear();
|
|
274
|
+
const R = Se(t), { minX: m, minY: v, maxX: x, maxY: L } = R, B = l ? i.getIntersecting(m, v, x, L).filter(({ annotation: Y }) => l(Y)) : i.getIntersecting(m, v, x, L), M = r.selected.map(({ id: Y }) => Y), K = B.map(({ annotation: Y, rects: lt }) => {
|
|
275
275
|
const Ae = M.includes(Y.id), xe = Y.id === a.current;
|
|
276
276
|
return { annotation: Y, rects: lt, state: { selected: Ae, hover: xe } };
|
|
277
277
|
});
|
|
278
|
-
o.redraw(K, R, s,
|
|
279
|
-
},
|
|
280
|
-
|
|
278
|
+
o.redraw(K, R, s, f, O), setTimeout(() => h(B.map(({ annotation: Y }) => Y)), 1);
|
|
279
|
+
}, u = (O) => {
|
|
280
|
+
f = O, g();
|
|
281
281
|
}, A = (O) => {
|
|
282
|
-
s = O,
|
|
283
|
-
},
|
|
284
|
-
l = O,
|
|
285
|
-
},
|
|
286
|
-
i.observe(
|
|
287
|
-
const
|
|
288
|
-
document.addEventListener("scroll",
|
|
282
|
+
s = O, g();
|
|
283
|
+
}, b = (O) => {
|
|
284
|
+
l = O, g(!1);
|
|
285
|
+
}, C = () => g();
|
|
286
|
+
i.observe(C);
|
|
287
|
+
const p = r.subscribe(() => g()), d = () => g(!0);
|
|
288
|
+
document.addEventListener("scroll", d, { capture: !0, passive: !0 });
|
|
289
289
|
const y = Ut(() => {
|
|
290
|
-
i.recalculatePositions(),
|
|
290
|
+
i.recalculatePositions(), f == null || f.reset(), g();
|
|
291
291
|
});
|
|
292
292
|
window.addEventListener("resize", y);
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
const E = { attributes: !0, childList: !0, subtree: !0 },
|
|
296
|
-
O.every((
|
|
293
|
+
const S = new ResizeObserver(y);
|
|
294
|
+
S.observe(t);
|
|
295
|
+
const E = { attributes: !0, childList: !0, subtree: !0 }, w = new MutationObserver((O) => {
|
|
296
|
+
O.every((m) => m.target === t || t.contains(m.target)) || g(!0);
|
|
297
297
|
});
|
|
298
|
-
return
|
|
298
|
+
return w.observe(document.body, E), {
|
|
299
299
|
destroy: () => {
|
|
300
|
-
t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(
|
|
300
|
+
t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(C), p(), document.removeEventListener("scroll", d), y.clear(), window.removeEventListener("resize", y), S.disconnect(), w.disconnect();
|
|
301
301
|
},
|
|
302
|
-
redraw:
|
|
302
|
+
redraw: g,
|
|
303
303
|
setStyle: A,
|
|
304
|
-
setFilter:
|
|
305
|
-
setPainter:
|
|
304
|
+
setFilter: b,
|
|
305
|
+
setPainter: u,
|
|
306
306
|
setVisible: o.setVisible
|
|
307
307
|
};
|
|
308
308
|
}, He = () => {
|
|
@@ -314,28 +314,28 @@ const Ie = /* @__PURE__ */ Be(ke), Ut = (t, e = 10, n) => {
|
|
|
314
314
|
t.classList.add("r6o-annotatable");
|
|
315
315
|
const e = He(), n = e.getContext("2d");
|
|
316
316
|
document.body.appendChild(e);
|
|
317
|
-
const o = (s, l,
|
|
318
|
-
const { width: c, height:
|
|
319
|
-
n.clearRect(-0.5, -0.5, c + 1,
|
|
320
|
-
const { top:
|
|
321
|
-
[...s].sort((
|
|
322
|
-
const { annotation: { target: { created:
|
|
323
|
-
return
|
|
324
|
-
}).forEach((
|
|
325
|
-
var
|
|
326
|
-
const
|
|
317
|
+
const o = (s, l, f, h) => requestAnimationFrame(() => {
|
|
318
|
+
const { width: c, height: g } = e;
|
|
319
|
+
n.clearRect(-0.5, -0.5, c + 1, g + 1), h && h.clear();
|
|
320
|
+
const { top: u, left: A } = l;
|
|
321
|
+
[...s].sort((C, p) => {
|
|
322
|
+
const { annotation: { target: { created: d } } } = C, { annotation: { target: { created: y } } } = p;
|
|
323
|
+
return d.getTime() - y.getTime();
|
|
324
|
+
}).forEach((C) => {
|
|
325
|
+
var S;
|
|
326
|
+
const p = f ? typeof f == "function" ? f(C.annotation, C.state) : f : (S = C.state) != null && S.selected ? yt : q, d = h && h.paint(C, l) || p, y = C.rects.map(({ x: E, y: w, width: T, height: O }) => ({
|
|
327
327
|
x: E + A,
|
|
328
|
-
y:
|
|
328
|
+
y: w + u,
|
|
329
329
|
width: T,
|
|
330
330
|
height: O
|
|
331
331
|
}));
|
|
332
|
-
if (n.fillStyle =
|
|
333
|
-
({ x: E, y:
|
|
334
|
-
),
|
|
335
|
-
n.globalAlpha = 1, n.strokeStyle =
|
|
336
|
-
const E =
|
|
337
|
-
y.forEach(({ x:
|
|
338
|
-
n.beginPath(), n.moveTo(
|
|
332
|
+
if (n.fillStyle = d.fill, n.globalAlpha = d.fillOpacity || 1, y.forEach(
|
|
333
|
+
({ x: E, y: w, width: T, height: O }) => n.fillRect(E, w, T, O)
|
|
334
|
+
), d.underlineColor) {
|
|
335
|
+
n.globalAlpha = 1, n.strokeStyle = d.underlineColor, n.lineWidth = d.underlineThickness ?? 1;
|
|
336
|
+
const E = d.underlineOffset ?? 0;
|
|
337
|
+
y.forEach(({ x: w, y: T, width: O, height: R }) => {
|
|
338
|
+
n.beginPath(), n.moveTo(w, T + R + E), n.lineTo(w + O, T + R + E), n.stroke();
|
|
339
339
|
});
|
|
340
340
|
}
|
|
341
341
|
});
|
|
@@ -371,8 +371,8 @@ var qe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
|
|
|
371
371
|
}, le = function(t) {
|
|
372
372
|
var e = t.h, n = t.s, o = t.v, i = t.a;
|
|
373
373
|
e = e / 360 * 6, n /= 100, o /= 100;
|
|
374
|
-
var r = Math.floor(e), a = o * (1 - n), s = o * (1 - (e - r) * n), l = o * (1 - (1 - e + r) * n),
|
|
375
|
-
return { r: 255 * [o, s, a, a, l, o][
|
|
374
|
+
var r = Math.floor(e), a = o * (1 - n), s = o * (1 - (e - r) * n), l = o * (1 - (1 - e + r) * n), f = r % 6;
|
|
375
|
+
return { r: 255 * [o, s, a, a, l, o][f], g: 255 * [l, o, o, s, a, a][f], b: 255 * [a, a, l, o, o, s][f], a: i };
|
|
376
376
|
}, Xt = function(t) {
|
|
377
377
|
return { h: ae(t.h), s: X(t.s, 0, 100), l: X(t.l, 0, 100), a: X(t.a) };
|
|
378
378
|
}, Pt = function(t) {
|
|
@@ -499,18 +499,18 @@ const nn = (t) => [
|
|
|
499
499
|
},
|
|
500
500
|
redraw: (r, a, s, l) => {
|
|
501
501
|
l && l.clear();
|
|
502
|
-
const
|
|
503
|
-
Array.from(e).filter((c) => !
|
|
502
|
+
const f = new Set(r.map((c) => c.annotation.id));
|
|
503
|
+
Array.from(e).filter((c) => !f.has(c));
|
|
504
504
|
const h = r.map((c) => {
|
|
505
505
|
var A;
|
|
506
|
-
const
|
|
507
|
-
return `::highlight(_${c.annotation.id}) { ${nn(
|
|
506
|
+
const g = s ? typeof s == "function" ? s(c.annotation, c.state) : s : (A = c.state) != null && A.selected ? yt : q, u = l && l.paint(c, a) || g;
|
|
507
|
+
return `::highlight(_${c.annotation.id}) { ${nn(u)} }`;
|
|
508
508
|
});
|
|
509
509
|
t.innerHTML = h.join(`
|
|
510
510
|
`), CSS.highlights.clear(), r.forEach(({ annotation: c }) => {
|
|
511
|
-
const
|
|
512
|
-
CSS.highlights.set(`_${c.id}`,
|
|
513
|
-
}), e =
|
|
511
|
+
const g = c.target.selector.map((A) => A.range), u = new Highlight(...g);
|
|
512
|
+
CSS.highlights.set(`_${c.id}`, u);
|
|
513
|
+
}), e = f;
|
|
514
514
|
}
|
|
515
515
|
};
|
|
516
516
|
}, rn = (t, e, n) => Vt(t, e, n, on());
|
|
@@ -547,17 +547,21 @@ const sn = (t, e) => {
|
|
|
547
547
|
destroy: () => {
|
|
548
548
|
e.remove();
|
|
549
549
|
},
|
|
550
|
-
redraw: (a, s, l,
|
|
551
|
-
const
|
|
552
|
-
!
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
550
|
+
redraw: (a, s, l, f, h) => {
|
|
551
|
+
const g = !(It(n, a) && h);
|
|
552
|
+
if (!f && !g) return;
|
|
553
|
+
g && (e.innerHTML = ""), [...a].sort((A, b) => {
|
|
554
|
+
const { annotation: { target: { created: C } } } = A, { annotation: { target: { created: p } } } = b;
|
|
555
|
+
return console.log(A.annotation), console.log(b.annotation), C && p ? C.getTime() - p.getTime() : 0;
|
|
556
|
+
}).forEach((A) => {
|
|
557
|
+
A.rects.map((b) => {
|
|
558
|
+
const C = sn(b, a), p = Ee(A, s, l, f, C);
|
|
559
|
+
if (g) {
|
|
560
|
+
const d = document.createElement("span");
|
|
561
|
+
d.className = "r6o-annotation", d.dataset.annotation = A.annotation.id, d.style.left = `${b.x}px`, d.style.top = `${b.y}px`, d.style.width = `${b.width}px`, d.style.height = `${b.height}px`, d.style.backgroundColor = P((p == null ? void 0 : p.fill) || q.fill).alpha((p == null ? void 0 : p.fillOpacity) === void 0 ? q.fillOpacity : p.fillOpacity).toHex(), p.underlineStyle && (d.style.borderStyle = p.underlineStyle), p.underlineColor && (d.style.borderColor = p.underlineColor), p.underlineThickness && (d.style.borderBottomWidth = `${p.underlineThickness}px`), p.underlineOffset && (d.style.paddingBottom = `${p.underlineOffset}px`), e.appendChild(d);
|
|
558
562
|
}
|
|
559
563
|
});
|
|
560
|
-
}), n = a
|
|
564
|
+
}), n = a;
|
|
561
565
|
},
|
|
562
566
|
setVisible: (a) => {
|
|
563
567
|
a ? e.classList.remove("hidden") : e.classList.add("hidden");
|
|
@@ -620,11 +624,11 @@ function Dt(t, e = St) {
|
|
|
620
624
|
function i(s) {
|
|
621
625
|
if (hn(t, s) && (t = s, n)) {
|
|
622
626
|
const l = !Q.length;
|
|
623
|
-
for (const
|
|
624
|
-
|
|
627
|
+
for (const f of o)
|
|
628
|
+
f[1](), Q.push(f, t);
|
|
625
629
|
if (l) {
|
|
626
|
-
for (let
|
|
627
|
-
Q[
|
|
630
|
+
for (let f = 0; f < Q.length; f += 2)
|
|
631
|
+
Q[f][0](Q[f + 1]);
|
|
628
632
|
Q.length = 0;
|
|
629
633
|
}
|
|
630
634
|
}
|
|
@@ -633,14 +637,14 @@ function Dt(t, e = St) {
|
|
|
633
637
|
i(s(t));
|
|
634
638
|
}
|
|
635
639
|
function a(s, l = St) {
|
|
636
|
-
const
|
|
637
|
-
return o.add(
|
|
638
|
-
o.delete(
|
|
640
|
+
const f = [s, l];
|
|
641
|
+
return o.add(f), o.size === 1 && (n = e(i, r) || St), s(t), () => {
|
|
642
|
+
o.delete(f), o.size === 0 && n && (n(), n = null);
|
|
639
643
|
};
|
|
640
644
|
}
|
|
641
645
|
return { set: i, update: r, subscribe: a };
|
|
642
646
|
}
|
|
643
|
-
const
|
|
647
|
+
const gn = (t) => {
|
|
644
648
|
const { subscribe: e, set: n } = Dt();
|
|
645
649
|
let o;
|
|
646
650
|
return e((i) => o = i), t.observe(({ changes: i }) => {
|
|
@@ -657,53 +661,53 @@ const pn = (t) => {
|
|
|
657
661
|
set: n
|
|
658
662
|
};
|
|
659
663
|
};
|
|
660
|
-
var
|
|
664
|
+
var pn = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(pn || {});
|
|
661
665
|
const ft = { selected: [] }, mn = (t, e) => {
|
|
662
666
|
const { subscribe: n, set: o } = Dt(ft);
|
|
663
667
|
let i = e, r = ft;
|
|
664
|
-
n((
|
|
668
|
+
n((u) => r = u);
|
|
665
669
|
const a = () => {
|
|
666
670
|
G(r, ft) || o(ft);
|
|
667
671
|
}, s = () => {
|
|
668
|
-
var
|
|
669
|
-
return ((
|
|
670
|
-
}, l = (
|
|
672
|
+
var u;
|
|
673
|
+
return ((u = r.selected) == null ? void 0 : u.length) === 0;
|
|
674
|
+
}, l = (u) => {
|
|
671
675
|
if (s())
|
|
672
676
|
return !1;
|
|
673
|
-
const A = typeof
|
|
674
|
-
return r.selected.some((
|
|
675
|
-
},
|
|
676
|
-
const
|
|
677
|
-
if (!
|
|
678
|
-
console.warn("Invalid selection: " +
|
|
677
|
+
const A = typeof u == "string" ? u : u.id;
|
|
678
|
+
return r.selected.some((b) => b.id === A);
|
|
679
|
+
}, f = (u, A) => {
|
|
680
|
+
const b = t.getAnnotation(u);
|
|
681
|
+
if (!b) {
|
|
682
|
+
console.warn("Invalid selection: " + u);
|
|
679
683
|
return;
|
|
680
684
|
}
|
|
681
|
-
switch (Qt(
|
|
685
|
+
switch (Qt(b, i)) {
|
|
682
686
|
case "EDIT":
|
|
683
|
-
o({ selected: [{ id:
|
|
687
|
+
o({ selected: [{ id: u, editable: !0 }], event: A });
|
|
684
688
|
break;
|
|
685
689
|
case "SELECT":
|
|
686
|
-
o({ selected: [{ id:
|
|
690
|
+
o({ selected: [{ id: u }], event: A });
|
|
687
691
|
break;
|
|
688
692
|
default:
|
|
689
693
|
o({ selected: [], event: A });
|
|
690
694
|
}
|
|
691
|
-
}, h = (
|
|
692
|
-
const
|
|
695
|
+
}, h = (u, A) => {
|
|
696
|
+
const b = Array.isArray(u) ? u : [u], C = b.map((p) => t.getAnnotation(p)).filter((p) => !!p);
|
|
693
697
|
o({
|
|
694
|
-
selected:
|
|
695
|
-
const
|
|
696
|
-
return { id:
|
|
698
|
+
selected: C.map((p) => {
|
|
699
|
+
const d = A === void 0 ? Qt(p, i) === "EDIT" : A;
|
|
700
|
+
return { id: p.id, editable: d };
|
|
697
701
|
})
|
|
698
|
-
}),
|
|
699
|
-
}, c = (
|
|
702
|
+
}), C.length !== b.length && console.warn("Invalid selection", u);
|
|
703
|
+
}, c = (u) => {
|
|
700
704
|
if (s())
|
|
701
705
|
return !1;
|
|
702
706
|
const { selected: A } = r;
|
|
703
|
-
A.some(({ id:
|
|
704
|
-
},
|
|
707
|
+
A.some(({ id: b }) => u.includes(b)) && o({ selected: A.filter(({ id: b }) => !u.includes(b)) });
|
|
708
|
+
}, g = (u) => i = u;
|
|
705
709
|
return t.observe(
|
|
706
|
-
({ changes:
|
|
710
|
+
({ changes: u }) => c((u.deleted || []).map((A) => A.id))
|
|
707
711
|
), {
|
|
708
712
|
get event() {
|
|
709
713
|
return r ? r.event : null;
|
|
@@ -718,9 +722,9 @@ const ft = { selected: [] }, mn = (t, e) => {
|
|
|
718
722
|
isEmpty: s,
|
|
719
723
|
isSelected: l,
|
|
720
724
|
setSelected: h,
|
|
721
|
-
setUserSelectAction:
|
|
725
|
+
setUserSelectAction: g,
|
|
722
726
|
subscribe: n,
|
|
723
|
-
userSelect:
|
|
727
|
+
userSelect: f
|
|
724
728
|
};
|
|
725
729
|
}, Qt = (t, e) => typeof e == "function" ? e(t) : e || "EDIT";
|
|
726
730
|
var V = [];
|
|
@@ -781,8 +785,8 @@ const Cn = (t, e) => {
|
|
|
781
785
|
if (t.options.ignore) {
|
|
782
786
|
const { ignore: a } = t.options, s = (l) => l && l.length > 0;
|
|
783
787
|
if (!(s(i.created) || s(i.deleted))) {
|
|
784
|
-
const l = (n = i.updated) == null ? void 0 : n.some((h) => s(h.bodiesCreated) || s(h.bodiesDeleted) || s(h.bodiesUpdated)),
|
|
785
|
-
if (a === "BODY_ONLY" && l && !
|
|
788
|
+
const l = (n = i.updated) == null ? void 0 : n.some((h) => s(h.bodiesCreated) || s(h.bodiesDeleted) || s(h.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((h) => h.targetUpdated);
|
|
789
|
+
if (a === "BODY_ONLY" && l && !f || a === "TARGET_ONLY" && f && !l)
|
|
786
790
|
return !1;
|
|
787
791
|
}
|
|
788
792
|
}
|
|
@@ -797,23 +801,23 @@ const Cn = (t, e) => {
|
|
|
797
801
|
return !0;
|
|
798
802
|
}, Ln = (t, e) => {
|
|
799
803
|
const n = new Set((t.created || []).map((c) => c.id)), o = new Set((t.updated || []).map(({ newValue: c }) => c.id)), i = new Set((e.created || []).map((c) => c.id)), r = new Set((e.deleted || []).map((c) => c.id)), a = new Set((e.updated || []).map(({ oldValue: c }) => c.id)), s = new Set((e.updated || []).filter(({ oldValue: c }) => n.has(c.id) || o.has(c.id)).map(({ oldValue: c }) => c.id)), l = [
|
|
800
|
-
...(t.created || []).filter((c) => !r.has(c.id)).map((c) => a.has(c.id) ? e.updated.find(({ oldValue:
|
|
804
|
+
...(t.created || []).filter((c) => !r.has(c.id)).map((c) => a.has(c.id) ? e.updated.find(({ oldValue: g }) => g.id === c.id).newValue : c),
|
|
801
805
|
...e.created || []
|
|
802
|
-
],
|
|
806
|
+
], f = [
|
|
803
807
|
...(t.deleted || []).filter((c) => !i.has(c.id)),
|
|
804
808
|
...(e.deleted || []).filter((c) => !n.has(c.id))
|
|
805
809
|
], h = [
|
|
806
810
|
...(t.updated || []).filter(({ newValue: c }) => !r.has(c.id)).map((c) => {
|
|
807
|
-
const { oldValue:
|
|
808
|
-
if (a.has(
|
|
809
|
-
const A = e.updated.find((
|
|
810
|
-
return fe(
|
|
811
|
+
const { oldValue: g, newValue: u } = c;
|
|
812
|
+
if (a.has(u.id)) {
|
|
813
|
+
const A = e.updated.find((b) => b.oldValue.id === u.id).newValue;
|
|
814
|
+
return fe(g, A);
|
|
811
815
|
} else
|
|
812
816
|
return c;
|
|
813
817
|
}),
|
|
814
818
|
...(e.updated || []).filter(({ oldValue: c }) => !s.has(c.id))
|
|
815
819
|
];
|
|
816
|
-
return { created: l, deleted:
|
|
820
|
+
return { created: l, deleted: f, updated: h };
|
|
817
821
|
}, Lt = (t) => {
|
|
818
822
|
const e = t.id === void 0 ? ue() : t.id;
|
|
819
823
|
return {
|
|
@@ -829,73 +833,73 @@ const Cn = (t, e) => {
|
|
|
829
833
|
}
|
|
830
834
|
};
|
|
831
835
|
}, On = (t) => t.id !== void 0, Tn = () => {
|
|
832
|
-
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (
|
|
833
|
-
n.push({ onChange:
|
|
834
|
-
}, i = (
|
|
835
|
-
const
|
|
836
|
-
|
|
837
|
-
}, r = (
|
|
836
|
+
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (m, v = {}) => {
|
|
837
|
+
n.push({ onChange: m, options: v });
|
|
838
|
+
}, i = (m) => {
|
|
839
|
+
const v = n.findIndex((x) => x.onChange == m);
|
|
840
|
+
v > -1 && n.splice(v, 1);
|
|
841
|
+
}, r = (m, v) => {
|
|
838
842
|
const x = {
|
|
839
|
-
origin:
|
|
843
|
+
origin: m,
|
|
840
844
|
changes: {
|
|
841
|
-
created:
|
|
842
|
-
updated:
|
|
843
|
-
deleted:
|
|
845
|
+
created: v.created || [],
|
|
846
|
+
updated: v.updated || [],
|
|
847
|
+
deleted: v.deleted || []
|
|
844
848
|
},
|
|
845
849
|
state: [...t.values()]
|
|
846
850
|
};
|
|
847
851
|
n.forEach((L) => {
|
|
848
852
|
Cn(L, x) && L.onChange(x);
|
|
849
853
|
});
|
|
850
|
-
}, a = (
|
|
851
|
-
if (
|
|
852
|
-
throw Error(`Cannot add annotation ${
|
|
854
|
+
}, a = (m, v = k.LOCAL) => {
|
|
855
|
+
if (m.id && t.get(m.id))
|
|
856
|
+
throw Error(`Cannot add annotation ${m.id} - exists already`);
|
|
853
857
|
{
|
|
854
|
-
const x = Lt(
|
|
855
|
-
t.set(x.id, x), x.bodies.forEach((L) => e.set(L.id, x.id)), r(
|
|
858
|
+
const x = Lt(m);
|
|
859
|
+
t.set(x.id, x), x.bodies.forEach((L) => e.set(L.id, x.id)), r(v, { created: [x] });
|
|
856
860
|
}
|
|
857
|
-
}, s = (
|
|
858
|
-
const x = Lt(typeof
|
|
861
|
+
}, s = (m, v) => {
|
|
862
|
+
const x = Lt(typeof m == "string" ? v : m), L = typeof m == "string" ? m : m.id, B = L && t.get(L);
|
|
859
863
|
if (B) {
|
|
860
864
|
const M = fe(B, x);
|
|
861
865
|
return L === x.id ? t.set(L, x) : (t.delete(L), t.set(x.id, x)), B.bodies.forEach((K) => e.delete(K.id)), x.bodies.forEach((K) => e.set(K.id, x.id)), M;
|
|
862
866
|
} else
|
|
863
867
|
console.warn(`Cannot update annotation ${L} - does not exist`);
|
|
864
|
-
}, l = (
|
|
865
|
-
const L = On(
|
|
868
|
+
}, l = (m, v = k.LOCAL, x = k.LOCAL) => {
|
|
869
|
+
const L = On(v) ? x : v, B = s(m, v);
|
|
866
870
|
B && r(L, { updated: [B] });
|
|
867
|
-
},
|
|
868
|
-
const x =
|
|
871
|
+
}, f = (m, v = k.LOCAL) => {
|
|
872
|
+
const x = m.reduce((L, B) => {
|
|
869
873
|
const M = s(B);
|
|
870
874
|
return M ? [...L, M] : L;
|
|
871
875
|
}, []);
|
|
872
|
-
x.length > 0 && r(
|
|
873
|
-
}, h = (
|
|
874
|
-
const x = t.get(
|
|
876
|
+
x.length > 0 && r(v, { updated: x });
|
|
877
|
+
}, h = (m, v = k.LOCAL) => {
|
|
878
|
+
const x = t.get(m.annotation);
|
|
875
879
|
if (x) {
|
|
876
880
|
const L = {
|
|
877
881
|
...x,
|
|
878
|
-
bodies: [...x.bodies,
|
|
882
|
+
bodies: [...x.bodies, m]
|
|
879
883
|
};
|
|
880
|
-
t.set(x.id, L), e.set(
|
|
884
|
+
t.set(x.id, L), e.set(m.id, L.id), r(v, { updated: [{
|
|
881
885
|
oldValue: x,
|
|
882
886
|
newValue: L,
|
|
883
|
-
bodiesCreated: [
|
|
887
|
+
bodiesCreated: [m]
|
|
884
888
|
}] });
|
|
885
889
|
} else
|
|
886
|
-
console.warn(`Attempt to add body to missing annotation: ${
|
|
887
|
-
}, c = () => [...t.values()],
|
|
888
|
-
const
|
|
889
|
-
t.clear(), e.clear(), r(
|
|
890
|
-
},
|
|
891
|
-
const L =
|
|
892
|
-
if (
|
|
890
|
+
console.warn(`Attempt to add body to missing annotation: ${m.annotation}`);
|
|
891
|
+
}, c = () => [...t.values()], g = (m = k.LOCAL) => {
|
|
892
|
+
const v = [...t.values()];
|
|
893
|
+
t.clear(), e.clear(), r(m, { deleted: v });
|
|
894
|
+
}, u = (m, v = !0, x = k.LOCAL) => {
|
|
895
|
+
const L = m.map(Lt);
|
|
896
|
+
if (v) {
|
|
893
897
|
const B = [...t.values()];
|
|
894
898
|
t.clear(), e.clear(), L.forEach((M) => {
|
|
895
899
|
t.set(M.id, M), M.bodies.forEach((K) => e.set(K.id, M.id));
|
|
896
900
|
}), r(x, { created: L, deleted: B });
|
|
897
901
|
} else {
|
|
898
|
-
const B =
|
|
902
|
+
const B = m.reduce((M, K) => {
|
|
899
903
|
const Y = K.id && t.get(K.id);
|
|
900
904
|
return Y ? [...M, Y] : M;
|
|
901
905
|
}, []);
|
|
@@ -905,125 +909,125 @@ const Cn = (t, e) => {
|
|
|
905
909
|
t.set(M.id, M), M.bodies.forEach((K) => e.set(K.id, M.id));
|
|
906
910
|
}), r(x, { created: L });
|
|
907
911
|
}
|
|
908
|
-
}, A = (
|
|
909
|
-
const
|
|
912
|
+
}, A = (m) => {
|
|
913
|
+
const v = typeof m == "string" ? m : m.id, x = t.get(v);
|
|
910
914
|
if (x)
|
|
911
|
-
return t.delete(
|
|
912
|
-
console.warn(`Attempt to delete missing annotation: ${
|
|
913
|
-
},
|
|
914
|
-
const x = A(
|
|
915
|
-
x && r(
|
|
916
|
-
},
|
|
917
|
-
const x =
|
|
915
|
+
return t.delete(v), x.bodies.forEach((L) => e.delete(L.id)), x;
|
|
916
|
+
console.warn(`Attempt to delete missing annotation: ${v}`);
|
|
917
|
+
}, b = (m, v = k.LOCAL) => {
|
|
918
|
+
const x = A(m);
|
|
919
|
+
x && r(v, { deleted: [x] });
|
|
920
|
+
}, C = (m, v = k.LOCAL) => {
|
|
921
|
+
const x = m.reduce((L, B) => {
|
|
918
922
|
const M = A(B);
|
|
919
923
|
return M ? [...L, M] : L;
|
|
920
924
|
}, []);
|
|
921
|
-
x.length > 0 && r(
|
|
922
|
-
},
|
|
923
|
-
const
|
|
924
|
-
if (
|
|
925
|
-
const x =
|
|
925
|
+
x.length > 0 && r(v, { deleted: x });
|
|
926
|
+
}, p = (m) => {
|
|
927
|
+
const v = t.get(m.annotation);
|
|
928
|
+
if (v) {
|
|
929
|
+
const x = v.bodies.find((L) => L.id === m.id);
|
|
926
930
|
if (x) {
|
|
927
931
|
e.delete(x.id);
|
|
928
932
|
const L = {
|
|
929
|
-
...
|
|
930
|
-
bodies:
|
|
933
|
+
...v,
|
|
934
|
+
bodies: v.bodies.filter((B) => B.id !== m.id)
|
|
931
935
|
};
|
|
932
|
-
return t.set(
|
|
933
|
-
oldValue:
|
|
936
|
+
return t.set(v.id, L), {
|
|
937
|
+
oldValue: v,
|
|
934
938
|
newValue: L,
|
|
935
939
|
bodiesDeleted: [x]
|
|
936
940
|
};
|
|
937
941
|
} else
|
|
938
|
-
console.warn(`Attempt to delete missing body ${
|
|
942
|
+
console.warn(`Attempt to delete missing body ${m.id} from annotation ${m.annotation}`);
|
|
939
943
|
} else
|
|
940
|
-
console.warn(`Attempt to delete body from missing annotation ${
|
|
941
|
-
},
|
|
942
|
-
const x = m
|
|
943
|
-
x && r(
|
|
944
|
-
}, y = (
|
|
945
|
-
const x =
|
|
946
|
-
x.length > 0 && r(
|
|
947
|
-
},
|
|
948
|
-
const
|
|
949
|
-
return
|
|
950
|
-
}, E = (
|
|
951
|
-
const
|
|
952
|
-
if (
|
|
953
|
-
const x =
|
|
944
|
+
console.warn(`Attempt to delete body from missing annotation ${m.annotation}`);
|
|
945
|
+
}, d = (m, v = k.LOCAL) => {
|
|
946
|
+
const x = p(m);
|
|
947
|
+
x && r(v, { updated: [x] });
|
|
948
|
+
}, y = (m, v = k.LOCAL) => {
|
|
949
|
+
const x = m.map((L) => p(L)).filter(Boolean);
|
|
950
|
+
x.length > 0 && r(v, { updated: x });
|
|
951
|
+
}, S = (m) => {
|
|
952
|
+
const v = t.get(m);
|
|
953
|
+
return v ? { ...v } : void 0;
|
|
954
|
+
}, E = (m) => {
|
|
955
|
+
const v = e.get(m);
|
|
956
|
+
if (v) {
|
|
957
|
+
const x = S(v).bodies.find((L) => L.id === m);
|
|
954
958
|
if (x)
|
|
955
959
|
return x;
|
|
956
|
-
console.error(`Store integrity error: body ${
|
|
960
|
+
console.error(`Store integrity error: body ${m} in index, but not in annotation`);
|
|
957
961
|
} else
|
|
958
|
-
console.warn(`Attempt to retrieve missing body: ${
|
|
959
|
-
},
|
|
960
|
-
if (
|
|
962
|
+
console.warn(`Attempt to retrieve missing body: ${m}`);
|
|
963
|
+
}, w = (m, v) => {
|
|
964
|
+
if (m.annotation !== v.annotation)
|
|
961
965
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
962
|
-
const x = t.get(
|
|
966
|
+
const x = t.get(m.annotation);
|
|
963
967
|
if (x) {
|
|
964
|
-
const L = x.bodies.find((M) => M.id ===
|
|
968
|
+
const L = x.bodies.find((M) => M.id === m.id), B = {
|
|
965
969
|
...x,
|
|
966
|
-
bodies: x.bodies.map((M) => M.id === L.id ?
|
|
970
|
+
bodies: x.bodies.map((M) => M.id === L.id ? v : M)
|
|
967
971
|
};
|
|
968
|
-
return t.set(x.id, B), L.id !==
|
|
972
|
+
return t.set(x.id, B), L.id !== v.id && (e.delete(L.id), e.set(v.id, B.id)), {
|
|
969
973
|
oldValue: x,
|
|
970
974
|
newValue: B,
|
|
971
|
-
bodiesUpdated: [{ oldBody: L, newBody:
|
|
975
|
+
bodiesUpdated: [{ oldBody: L, newBody: v }]
|
|
972
976
|
};
|
|
973
977
|
} else
|
|
974
|
-
console.warn(`Attempt to add body to missing annotation ${
|
|
975
|
-
}, T = (
|
|
976
|
-
const L =
|
|
978
|
+
console.warn(`Attempt to add body to missing annotation ${m.annotation}`);
|
|
979
|
+
}, T = (m, v, x = k.LOCAL) => {
|
|
980
|
+
const L = w(m, v);
|
|
977
981
|
L && r(x, { updated: [L] });
|
|
978
|
-
}, O = (
|
|
979
|
-
const x =
|
|
980
|
-
r(
|
|
981
|
-
}, R = (
|
|
982
|
-
const
|
|
983
|
-
if (
|
|
982
|
+
}, O = (m, v = k.LOCAL) => {
|
|
983
|
+
const x = m.map((L) => w({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
|
|
984
|
+
r(v, { updated: x });
|
|
985
|
+
}, R = (m) => {
|
|
986
|
+
const v = t.get(m.annotation);
|
|
987
|
+
if (v) {
|
|
984
988
|
const x = {
|
|
985
|
-
...
|
|
989
|
+
...v,
|
|
986
990
|
target: {
|
|
987
|
-
...
|
|
988
|
-
...
|
|
991
|
+
...v.target,
|
|
992
|
+
...m
|
|
989
993
|
}
|
|
990
994
|
};
|
|
991
|
-
return t.set(
|
|
992
|
-
oldValue:
|
|
995
|
+
return t.set(v.id, x), {
|
|
996
|
+
oldValue: v,
|
|
993
997
|
newValue: x,
|
|
994
998
|
targetUpdated: {
|
|
995
|
-
oldTarget:
|
|
996
|
-
newTarget:
|
|
999
|
+
oldTarget: v.target,
|
|
1000
|
+
newTarget: m
|
|
997
1001
|
}
|
|
998
1002
|
};
|
|
999
1003
|
} else
|
|
1000
|
-
console.warn(`Attempt to update target on missing annotation: ${
|
|
1004
|
+
console.warn(`Attempt to update target on missing annotation: ${m.annotation}`);
|
|
1001
1005
|
};
|
|
1002
1006
|
return {
|
|
1003
1007
|
addAnnotation: a,
|
|
1004
1008
|
addBody: h,
|
|
1005
1009
|
all: c,
|
|
1006
|
-
bulkAddAnnotation:
|
|
1007
|
-
bulkDeleteAnnotation:
|
|
1010
|
+
bulkAddAnnotation: u,
|
|
1011
|
+
bulkDeleteAnnotation: C,
|
|
1008
1012
|
bulkDeleteBodies: y,
|
|
1009
|
-
bulkUpdateAnnotation:
|
|
1013
|
+
bulkUpdateAnnotation: f,
|
|
1010
1014
|
bulkUpdateBodies: O,
|
|
1011
|
-
bulkUpdateTargets: (
|
|
1012
|
-
const x =
|
|
1013
|
-
x.length > 0 && r(
|
|
1015
|
+
bulkUpdateTargets: (m, v = k.LOCAL) => {
|
|
1016
|
+
const x = m.map((L) => R(L)).filter(Boolean);
|
|
1017
|
+
x.length > 0 && r(v, { updated: x });
|
|
1014
1018
|
},
|
|
1015
|
-
clear:
|
|
1016
|
-
deleteAnnotation:
|
|
1017
|
-
deleteBody:
|
|
1018
|
-
getAnnotation:
|
|
1019
|
+
clear: g,
|
|
1020
|
+
deleteAnnotation: b,
|
|
1021
|
+
deleteBody: d,
|
|
1022
|
+
getAnnotation: S,
|
|
1019
1023
|
getBody: E,
|
|
1020
1024
|
observe: o,
|
|
1021
1025
|
unobserve: i,
|
|
1022
1026
|
updateAnnotation: l,
|
|
1023
1027
|
updateBody: T,
|
|
1024
|
-
updateTarget: (
|
|
1025
|
-
const x = R(
|
|
1026
|
-
x && r(
|
|
1028
|
+
updateTarget: (m, v = k.LOCAL) => {
|
|
1029
|
+
const x = R(m);
|
|
1030
|
+
x && r(v, { updated: [x] });
|
|
1027
1031
|
}
|
|
1028
1032
|
};
|
|
1029
1033
|
};
|
|
@@ -1044,38 +1048,38 @@ let Rn = () => ({
|
|
|
1044
1048
|
const Mn = 250, Bn = (t) => {
|
|
1045
1049
|
const e = Rn(), n = [];
|
|
1046
1050
|
let o = -1, i = !1, r = 0;
|
|
1047
|
-
const a = (
|
|
1051
|
+
const a = (u) => {
|
|
1048
1052
|
if (!i) {
|
|
1049
|
-
const { changes: A } =
|
|
1050
|
-
if (
|
|
1053
|
+
const { changes: A } = u, b = performance.now();
|
|
1054
|
+
if (b - r > Mn)
|
|
1051
1055
|
n.splice(o + 1), n.push(A), o = n.length - 1;
|
|
1052
1056
|
else {
|
|
1053
|
-
const
|
|
1054
|
-
n[
|
|
1057
|
+
const C = n.length - 1;
|
|
1058
|
+
n[C] = Ln(n[C], A);
|
|
1055
1059
|
}
|
|
1056
|
-
r =
|
|
1060
|
+
r = b;
|
|
1057
1061
|
}
|
|
1058
1062
|
i = !1;
|
|
1059
1063
|
};
|
|
1060
1064
|
t.observe(a, { origin: k.LOCAL });
|
|
1061
|
-
const s = (
|
|
1065
|
+
const s = (u) => u && u.length > 0 && t.bulkDeleteAnnotation(u), l = (u) => u && u.length > 0 && t.bulkAddAnnotation(u, !1), f = (u) => u && u.length > 0 && t.bulkUpdateAnnotation(u.map(({ oldValue: A }) => A)), h = (u) => u && u.length > 0 && t.bulkUpdateAnnotation(u.map(({ newValue: A }) => A)), c = (u) => u && u.length > 0 && t.bulkAddAnnotation(u, !1), g = (u) => u && u.length > 0 && t.bulkDeleteAnnotation(u);
|
|
1062
1066
|
return {
|
|
1063
1067
|
canRedo: () => n.length - 1 > o,
|
|
1064
1068
|
canUndo: () => o > -1,
|
|
1065
1069
|
destroy: () => t.unobserve(a),
|
|
1066
|
-
on: (
|
|
1070
|
+
on: (u, A) => e.on(u, A),
|
|
1067
1071
|
redo: () => {
|
|
1068
1072
|
if (n.length - 1 > o) {
|
|
1069
1073
|
i = !0;
|
|
1070
|
-
const { created:
|
|
1071
|
-
l(
|
|
1074
|
+
const { created: u, updated: A, deleted: b } = n[o + 1];
|
|
1075
|
+
l(u), h(A), g(b), e.emit("redo", n[o + 1]), o += 1;
|
|
1072
1076
|
}
|
|
1073
1077
|
},
|
|
1074
1078
|
undo: () => {
|
|
1075
1079
|
if (o > -1) {
|
|
1076
1080
|
i = !0;
|
|
1077
|
-
const { created:
|
|
1078
|
-
s(
|
|
1081
|
+
const { created: u, updated: A, deleted: b } = n[o];
|
|
1082
|
+
s(u), f(A), c(b), e.emit("undo", n[o]), o -= 1;
|
|
1079
1083
|
}
|
|
1080
1084
|
}
|
|
1081
1085
|
};
|
|
@@ -1087,72 +1091,72 @@ const Mn = 250, Bn = (t) => {
|
|
|
1087
1091
|
};
|
|
1088
1092
|
}, In = (t, e, n, o) => {
|
|
1089
1093
|
const { store: i, selection: r, hover: a, viewport: s } = t, l = /* @__PURE__ */ new Map();
|
|
1090
|
-
let
|
|
1091
|
-
const c = (
|
|
1092
|
-
l.has(
|
|
1093
|
-
},
|
|
1094
|
-
const
|
|
1095
|
-
if (
|
|
1096
|
-
const
|
|
1097
|
-
|
|
1094
|
+
let f = [], h;
|
|
1095
|
+
const c = (b, C) => {
|
|
1096
|
+
l.has(b) ? l.get(b).push(C) : l.set(b, [C]);
|
|
1097
|
+
}, g = (b, C) => {
|
|
1098
|
+
const p = l.get(b);
|
|
1099
|
+
if (p) {
|
|
1100
|
+
const d = p.indexOf(C);
|
|
1101
|
+
d !== -1 && p.splice(d, 1);
|
|
1098
1102
|
}
|
|
1099
|
-
},
|
|
1100
|
-
l.has(
|
|
1101
|
-
l.get(
|
|
1103
|
+
}, u = (b, C, p) => {
|
|
1104
|
+
l.has(b) && setTimeout(() => {
|
|
1105
|
+
l.get(b).forEach((d) => {
|
|
1102
1106
|
if (n) {
|
|
1103
|
-
const y = Array.isArray(
|
|
1104
|
-
|
|
1107
|
+
const y = Array.isArray(C) ? C.map((E) => n.serialize(E)) : n.serialize(C), S = p ? p instanceof PointerEvent ? p : n.serialize(p) : void 0;
|
|
1108
|
+
d(y, S);
|
|
1105
1109
|
} else
|
|
1106
|
-
|
|
1110
|
+
d(C, p);
|
|
1107
1111
|
});
|
|
1108
1112
|
}, 1);
|
|
1109
1113
|
};
|
|
1110
|
-
r.subscribe(({ selected:
|
|
1111
|
-
if (!(
|
|
1112
|
-
if (
|
|
1113
|
-
|
|
1114
|
-
else if (
|
|
1115
|
-
|
|
1116
|
-
const
|
|
1117
|
-
|
|
1118
|
-
}),
|
|
1114
|
+
r.subscribe(({ selected: b }) => {
|
|
1115
|
+
if (!(f.length === 0 && b.length === 0)) {
|
|
1116
|
+
if (f.length === 0 && b.length > 0)
|
|
1117
|
+
f = b.map(({ id: C }) => i.getAnnotation(C));
|
|
1118
|
+
else if (f.length > 0 && b.length === 0)
|
|
1119
|
+
f.forEach((C) => {
|
|
1120
|
+
const p = i.getAnnotation(C.id);
|
|
1121
|
+
p && !G(p, C) && u("updateAnnotation", p, C);
|
|
1122
|
+
}), f = [];
|
|
1119
1123
|
else {
|
|
1120
|
-
const
|
|
1121
|
-
|
|
1122
|
-
const y = i.getAnnotation(
|
|
1123
|
-
y && !G(y,
|
|
1124
|
-
}),
|
|
1124
|
+
const C = new Set(f.map((d) => d.id)), p = new Set(b.map(({ id: d }) => d));
|
|
1125
|
+
f.filter((d) => !p.has(d.id)).forEach((d) => {
|
|
1126
|
+
const y = i.getAnnotation(d.id);
|
|
1127
|
+
y && !G(y, d) && u("updateAnnotation", y, d);
|
|
1128
|
+
}), f = [
|
|
1125
1129
|
// Remove annotations that were deselected
|
|
1126
|
-
...
|
|
1130
|
+
...f.filter((d) => p.has(d.id)),
|
|
1127
1131
|
// Add editable annotations that were selected
|
|
1128
|
-
...
|
|
1132
|
+
...b.filter(({ id: d }) => !C.has(d)).map(({ id: d }) => i.getAnnotation(d))
|
|
1129
1133
|
];
|
|
1130
1134
|
}
|
|
1131
|
-
|
|
1135
|
+
u("selectionChanged", f);
|
|
1132
1136
|
}
|
|
1133
|
-
}), a.subscribe((
|
|
1134
|
-
!h &&
|
|
1135
|
-
}), s == null || s.subscribe((
|
|
1136
|
-
const { created:
|
|
1137
|
-
(
|
|
1138
|
-
...
|
|
1139
|
-
...
|
|
1140
|
-
...
|
|
1141
|
-
].length > 0).forEach(({ oldValue:
|
|
1142
|
-
const
|
|
1143
|
-
|
|
1137
|
+
}), a.subscribe((b) => {
|
|
1138
|
+
!h && b ? u("mouseEnterAnnotation", i.getAnnotation(b)) : h && !b ? u("mouseLeaveAnnotation", i.getAnnotation(h)) : h && b && (u("mouseLeaveAnnotation", i.getAnnotation(h)), u("mouseEnterAnnotation", i.getAnnotation(b))), h = b;
|
|
1139
|
+
}), s == null || s.subscribe((b) => u("viewportIntersect", b.map((C) => i.getAnnotation(C)))), i.observe((b) => {
|
|
1140
|
+
const { created: C, deleted: p } = b.changes;
|
|
1141
|
+
(C || []).forEach((d) => u("createAnnotation", d)), (p || []).forEach((d) => u("deleteAnnotation", d)), (b.changes.updated || []).filter((d) => [
|
|
1142
|
+
...d.bodiesCreated || [],
|
|
1143
|
+
...d.bodiesDeleted || [],
|
|
1144
|
+
...d.bodiesUpdated || []
|
|
1145
|
+
].length > 0).forEach(({ oldValue: d, newValue: y }) => {
|
|
1146
|
+
const S = f.find((E) => E.id === d.id) || d;
|
|
1147
|
+
f = f.map((E) => E.id === d.id ? y : E), u("updateAnnotation", y, S);
|
|
1144
1148
|
});
|
|
1145
|
-
}, { origin: k.LOCAL }), i.observe((
|
|
1146
|
-
if (
|
|
1147
|
-
const
|
|
1148
|
-
|
|
1149
|
+
}, { origin: k.LOCAL }), i.observe((b) => {
|
|
1150
|
+
if (f) {
|
|
1151
|
+
const C = new Set(f.map((d) => d.id)), p = (b.changes.updated || []).filter(({ newValue: d }) => C.has(d.id)).map(({ newValue: d }) => d);
|
|
1152
|
+
p.length > 0 && (f = f.map((d) => p.find((S) => S.id === d.id) || d));
|
|
1149
1153
|
}
|
|
1150
1154
|
}, { origin: k.REMOTE });
|
|
1151
|
-
const A = (
|
|
1152
|
-
const { updated:
|
|
1153
|
-
|
|
1155
|
+
const A = (b) => (C) => {
|
|
1156
|
+
const { updated: p } = C;
|
|
1157
|
+
b ? (p || []).forEach((d) => u("updateAnnotation", d.oldValue, d.newValue)) : (p || []).forEach((d) => u("updateAnnotation", d.newValue, d.oldValue));
|
|
1154
1158
|
};
|
|
1155
|
-
return e.on("undo", A(!0)), e.on("redo", A(!1)), { on: c, off:
|
|
1159
|
+
return e.on("undo", A(!0)), e.on("redo", A(!1)), { on: c, off: g, emit: u };
|
|
1156
1160
|
}, Nn = (t) => (e) => e.reduce((n, o) => {
|
|
1157
1161
|
const { parsed: i, error: r } = t.parse(o);
|
|
1158
1162
|
return r ? {
|
|
@@ -1165,46 +1169,46 @@ const Mn = 250, Bn = (t) => {
|
|
|
1165
1169
|
...n
|
|
1166
1170
|
};
|
|
1167
1171
|
}, { parsed: [], failed: [] }), _n = (t, e, n) => {
|
|
1168
|
-
const { store: o, selection: i } = t, r = (
|
|
1172
|
+
const { store: o, selection: i } = t, r = (p) => {
|
|
1169
1173
|
if (n) {
|
|
1170
|
-
const { parsed:
|
|
1171
|
-
|
|
1174
|
+
const { parsed: d, error: y } = n.parse(p);
|
|
1175
|
+
d ? o.addAnnotation(d, k.REMOTE) : console.error(y);
|
|
1172
1176
|
} else
|
|
1173
|
-
o.addAnnotation(
|
|
1174
|
-
}, a = () => i.clear(), s = () => o.clear(), l = (
|
|
1175
|
-
const
|
|
1176
|
-
return n &&
|
|
1177
|
-
},
|
|
1178
|
-
var
|
|
1179
|
-
const
|
|
1180
|
-
return n ?
|
|
1181
|
-
}, c = (
|
|
1182
|
-
if (typeof
|
|
1183
|
-
const
|
|
1184
|
-
if (o.deleteAnnotation(
|
|
1185
|
-
return n ? n.serialize(
|
|
1177
|
+
o.addAnnotation(p, k.REMOTE);
|
|
1178
|
+
}, a = () => i.clear(), s = () => o.clear(), l = (p) => {
|
|
1179
|
+
const d = o.getAnnotation(p);
|
|
1180
|
+
return n && d ? n.serialize(d) : d;
|
|
1181
|
+
}, f = () => n ? o.all().map(n.serialize) : o.all(), h = () => {
|
|
1182
|
+
var p;
|
|
1183
|
+
const d = (((p = i.selected) == null ? void 0 : p.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
|
|
1184
|
+
return n ? d.map(n.serialize) : d;
|
|
1185
|
+
}, c = (p, d = !0) => fetch(p).then((y) => y.json()).then((y) => (u(y, d), y)), g = (p) => {
|
|
1186
|
+
if (typeof p == "string") {
|
|
1187
|
+
const d = o.getAnnotation(p);
|
|
1188
|
+
if (o.deleteAnnotation(p), d)
|
|
1189
|
+
return n ? n.serialize(d) : d;
|
|
1186
1190
|
} else {
|
|
1187
|
-
const
|
|
1188
|
-
if (
|
|
1189
|
-
return o.deleteAnnotation(
|
|
1191
|
+
const d = n ? n.parse(p).parsed : p;
|
|
1192
|
+
if (d)
|
|
1193
|
+
return o.deleteAnnotation(d), p;
|
|
1190
1194
|
}
|
|
1191
|
-
},
|
|
1195
|
+
}, u = (p, d = !0) => {
|
|
1192
1196
|
if (n) {
|
|
1193
|
-
const { parsed: y, failed:
|
|
1194
|
-
|
|
1197
|
+
const { parsed: y, failed: S } = Nn(n)(p);
|
|
1198
|
+
S.length > 0 && console.warn(`Discarded ${S.length} invalid annotations`, S), o.bulkAddAnnotation(y, d, k.REMOTE);
|
|
1195
1199
|
} else
|
|
1196
|
-
o.bulkAddAnnotation(
|
|
1197
|
-
}, A = (
|
|
1198
|
-
|
|
1199
|
-
},
|
|
1200
|
-
i.clear(), i.setUserSelectAction(
|
|
1201
|
-
},
|
|
1200
|
+
o.bulkAddAnnotation(p, d, k.REMOTE);
|
|
1201
|
+
}, A = (p, d) => {
|
|
1202
|
+
p ? i.setSelected(p, d) : i.clear();
|
|
1203
|
+
}, b = (p) => {
|
|
1204
|
+
i.clear(), i.setUserSelectAction(p);
|
|
1205
|
+
}, C = (p) => {
|
|
1202
1206
|
if (n) {
|
|
1203
|
-
const
|
|
1204
|
-
return o.updateAnnotation(
|
|
1207
|
+
const d = n.parse(p).parsed, y = n.serialize(o.getAnnotation(d.id));
|
|
1208
|
+
return o.updateAnnotation(d), y;
|
|
1205
1209
|
} else {
|
|
1206
|
-
const
|
|
1207
|
-
return o.updateAnnotation(
|
|
1210
|
+
const d = o.getAnnotation(p.id);
|
|
1211
|
+
return o.updateAnnotation(p), d;
|
|
1208
1212
|
}
|
|
1209
1213
|
};
|
|
1210
1214
|
return {
|
|
@@ -1214,16 +1218,16 @@ const Mn = 250, Bn = (t) => {
|
|
|
1214
1218
|
canUndo: e.canUndo,
|
|
1215
1219
|
clearAnnotations: s,
|
|
1216
1220
|
getAnnotationById: l,
|
|
1217
|
-
getAnnotations:
|
|
1221
|
+
getAnnotations: f,
|
|
1218
1222
|
getSelected: h,
|
|
1219
1223
|
loadAnnotations: c,
|
|
1220
1224
|
redo: e.redo,
|
|
1221
|
-
removeAnnotation:
|
|
1222
|
-
setAnnotations:
|
|
1225
|
+
removeAnnotation: g,
|
|
1226
|
+
setAnnotations: u,
|
|
1223
1227
|
setSelected: A,
|
|
1224
|
-
setUserSelectAction:
|
|
1228
|
+
setUserSelectAction: b,
|
|
1225
1229
|
undo: e.undo,
|
|
1226
|
-
updateAnnotation:
|
|
1230
|
+
updateAnnotation: C
|
|
1227
1231
|
};
|
|
1228
1232
|
}, Un = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
1229
1233
|
let Vn = (t) => crypto.getRandomValues(new Uint8Array(t)), Dn = (t, e, n) => {
|
|
@@ -1251,14 +1255,14 @@ const Xn = () => ({ isGuest: !0, id: Kn("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
1251
1255
|
}
|
|
1252
1256
|
return `${n}`;
|
|
1253
1257
|
}, he = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, $n = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
|
|
1254
|
-
const { id: o, type: i, purpose: r, value: a, created: s, modified: l, creator:
|
|
1258
|
+
const { id: o, type: i, purpose: r, value: a, created: s, modified: l, creator: f, ...h } = n;
|
|
1255
1259
|
return {
|
|
1256
1260
|
id: o || `temp-${Pn(n)}`,
|
|
1257
1261
|
annotation: e,
|
|
1258
1262
|
type: i,
|
|
1259
1263
|
purpose: r,
|
|
1260
1264
|
value: a,
|
|
1261
|
-
creator: he(
|
|
1265
|
+
creator: he(f),
|
|
1262
1266
|
created: s ? new Date(s) : void 0,
|
|
1263
1267
|
updated: l ? new Date(l) : void 0,
|
|
1264
1268
|
...h
|
|
@@ -1295,13 +1299,13 @@ const Lo = (t, e) => ({
|
|
|
1295
1299
|
styleClass: a[0].styleClass
|
|
1296
1300
|
};
|
|
1297
1301
|
for (const l of a) {
|
|
1298
|
-
const h = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((c,
|
|
1299
|
-
switch (
|
|
1302
|
+
const h = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((c, g) => {
|
|
1303
|
+
switch (g.type) {
|
|
1300
1304
|
case "TextQuoteSelector":
|
|
1301
|
-
c.quote =
|
|
1305
|
+
c.quote = g.exact;
|
|
1302
1306
|
break;
|
|
1303
1307
|
case "TextPositionSelector":
|
|
1304
|
-
c.start =
|
|
1308
|
+
c.start = g.start, c.end = g.end;
|
|
1305
1309
|
break;
|
|
1306
1310
|
}
|
|
1307
1311
|
return c;
|
|
@@ -1338,22 +1342,22 @@ const Lo = (t, e) => ({
|
|
|
1338
1342
|
selector: a,
|
|
1339
1343
|
creator: s,
|
|
1340
1344
|
created: l,
|
|
1341
|
-
updated:
|
|
1345
|
+
updated: f,
|
|
1342
1346
|
...h
|
|
1343
|
-
} = i, c = a.map((
|
|
1344
|
-
const { quote:
|
|
1347
|
+
} = i, c = a.map((g) => {
|
|
1348
|
+
const { quote: u, start: A, end: b, range: C } = g, { prefix: p, suffix: d } = Ne(C, n), y = [{
|
|
1345
1349
|
type: "TextQuoteSelector",
|
|
1346
|
-
exact:
|
|
1347
|
-
prefix:
|
|
1348
|
-
suffix:
|
|
1350
|
+
exact: u,
|
|
1351
|
+
prefix: p,
|
|
1352
|
+
suffix: d
|
|
1349
1353
|
}, {
|
|
1350
1354
|
type: "TextPositionSelector",
|
|
1351
1355
|
start: A,
|
|
1352
|
-
end:
|
|
1356
|
+
end: b
|
|
1353
1357
|
}];
|
|
1354
1358
|
return {
|
|
1355
1359
|
...h,
|
|
1356
|
-
id:
|
|
1360
|
+
id: g.id,
|
|
1357
1361
|
source: e,
|
|
1358
1362
|
selector: y
|
|
1359
1363
|
};
|
|
@@ -1366,15 +1370,15 @@ const Lo = (t, e) => ({
|
|
|
1366
1370
|
body: jn(t.bodies),
|
|
1367
1371
|
creator: s,
|
|
1368
1372
|
created: l == null ? void 0 : l.toISOString(),
|
|
1369
|
-
modified:
|
|
1373
|
+
modified: f == null ? void 0 : f.toISOString(),
|
|
1370
1374
|
target: c
|
|
1371
1375
|
};
|
|
1372
1376
|
};
|
|
1373
|
-
function
|
|
1377
|
+
function ge(t, e, n = 0, o = t.length - 1, i = qn) {
|
|
1374
1378
|
for (; o > n; ) {
|
|
1375
1379
|
if (o - n > 600) {
|
|
1376
|
-
const l = o - n + 1,
|
|
1377
|
-
|
|
1380
|
+
const l = o - n + 1, f = e - n + 1, h = Math.log(l), c = 0.5 * Math.exp(2 * h / 3), g = 0.5 * Math.sqrt(h * c * (l - c) / l) * (f - l / 2 < 0 ? -1 : 1), u = Math.max(n, Math.floor(e - f * c / l + g)), A = Math.min(o, Math.floor(e + (l - f) * c / l + g));
|
|
1381
|
+
ge(t, e, u, A, i);
|
|
1378
1382
|
}
|
|
1379
1383
|
const r = t[e];
|
|
1380
1384
|
let a = n, s = o;
|
|
@@ -1402,12 +1406,12 @@ class Gn {
|
|
|
1402
1406
|
search(e) {
|
|
1403
1407
|
let n = this.data;
|
|
1404
1408
|
const o = [];
|
|
1405
|
-
if (!
|
|
1409
|
+
if (!pt(e, n)) return o;
|
|
1406
1410
|
const i = this.toBBox, r = [];
|
|
1407
1411
|
for (; n; ) {
|
|
1408
1412
|
for (let a = 0; a < n.children.length; a++) {
|
|
1409
1413
|
const s = n.children[a], l = n.leaf ? i(s) : s;
|
|
1410
|
-
|
|
1414
|
+
pt(e, l) && (n.leaf ? o.push(s) : Tt(e, l) ? this._all(s, o) : r.push(s));
|
|
1411
1415
|
}
|
|
1412
1416
|
n = r.pop();
|
|
1413
1417
|
}
|
|
@@ -1415,12 +1419,12 @@ class Gn {
|
|
|
1415
1419
|
}
|
|
1416
1420
|
collides(e) {
|
|
1417
1421
|
let n = this.data;
|
|
1418
|
-
if (!
|
|
1422
|
+
if (!pt(e, n)) return !1;
|
|
1419
1423
|
const o = [];
|
|
1420
1424
|
for (; n; ) {
|
|
1421
1425
|
for (let i = 0; i < n.children.length; i++) {
|
|
1422
1426
|
const r = n.children[i], a = n.leaf ? this.toBBox(r) : r;
|
|
1423
|
-
if (
|
|
1427
|
+
if (pt(e, a)) {
|
|
1424
1428
|
if (n.leaf || Tt(e, a)) return !0;
|
|
1425
1429
|
o.push(r);
|
|
1426
1430
|
}
|
|
@@ -1460,14 +1464,14 @@ class Gn {
|
|
|
1460
1464
|
if (!e) return this;
|
|
1461
1465
|
let o = this.data;
|
|
1462
1466
|
const i = this.toBBox(e), r = [], a = [];
|
|
1463
|
-
let s, l,
|
|
1467
|
+
let s, l, f;
|
|
1464
1468
|
for (; o || r.length; ) {
|
|
1465
|
-
if (o || (o = r.pop(), l = r[r.length - 1], s = a.pop(),
|
|
1469
|
+
if (o || (o = r.pop(), l = r[r.length - 1], s = a.pop(), f = !0), o.leaf) {
|
|
1466
1470
|
const h = Qn(e, o.children, n);
|
|
1467
1471
|
if (h !== -1)
|
|
1468
1472
|
return o.children.splice(h, 1), r.push(o), this._condense(r), this;
|
|
1469
1473
|
}
|
|
1470
|
-
!
|
|
1474
|
+
!f && !o.leaf && Tt(o, i) ? (r.push(o), a.push(s), s = 0, l = o, o = o.children[0]) : l ? (s++, o = l.children[s], f = !1) : o = null;
|
|
1471
1475
|
}
|
|
1472
1476
|
return this;
|
|
1473
1477
|
}
|
|
@@ -1498,14 +1502,14 @@ class Gn {
|
|
|
1498
1502
|
if (r <= a)
|
|
1499
1503
|
return s = Z(e.slice(n, o + 1)), J(s, this.toBBox), s;
|
|
1500
1504
|
i || (i = Math.ceil(Math.log(r) / Math.log(a)), a = Math.ceil(r / Math.pow(a, i - 1))), s = Z([]), s.leaf = !1, s.height = i;
|
|
1501
|
-
const l = Math.ceil(r / a),
|
|
1502
|
-
Zt(e, n, o,
|
|
1503
|
-
for (let h = n; h <= o; h +=
|
|
1504
|
-
const c = Math.min(h +
|
|
1505
|
+
const l = Math.ceil(r / a), f = l * Math.ceil(Math.sqrt(a));
|
|
1506
|
+
Zt(e, n, o, f, this.compareMinX);
|
|
1507
|
+
for (let h = n; h <= o; h += f) {
|
|
1508
|
+
const c = Math.min(h + f - 1, o);
|
|
1505
1509
|
Zt(e, h, c, l, this.compareMinY);
|
|
1506
|
-
for (let
|
|
1507
|
-
const
|
|
1508
|
-
s.children.push(this._build(e,
|
|
1510
|
+
for (let g = h; g <= c; g += l) {
|
|
1511
|
+
const u = Math.min(g + l - 1, c);
|
|
1512
|
+
s.children.push(this._build(e, g, u, i - 1));
|
|
1509
1513
|
}
|
|
1510
1514
|
}
|
|
1511
1515
|
return J(s, this.toBBox), s;
|
|
@@ -1514,8 +1518,8 @@ class Gn {
|
|
|
1514
1518
|
for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
|
|
1515
1519
|
let r = 1 / 0, a = 1 / 0, s;
|
|
1516
1520
|
for (let l = 0; l < n.children.length; l++) {
|
|
1517
|
-
const
|
|
1518
|
-
c < a ? (a = c, r = h < r ? h : r, s =
|
|
1521
|
+
const f = n.children[l], h = Ot(f), c = to(e, f) - h;
|
|
1522
|
+
c < a ? (a = c, r = h < r ? h : r, s = f) : c === a && h < r && (r = h, s = f);
|
|
1519
1523
|
}
|
|
1520
1524
|
n = s || n.children[0];
|
|
1521
1525
|
}
|
|
@@ -1540,7 +1544,7 @@ class Gn {
|
|
|
1540
1544
|
_chooseSplitIndex(e, n, o) {
|
|
1541
1545
|
let i, r = 1 / 0, a = 1 / 0;
|
|
1542
1546
|
for (let s = n; s <= o - n; s++) {
|
|
1543
|
-
const l = nt(e, 0, s, this.toBBox),
|
|
1547
|
+
const l = nt(e, 0, s, this.toBBox), f = nt(e, s, o, this.toBBox), h = eo(l, f), c = Ot(l) + Ot(f);
|
|
1544
1548
|
h < r ? (r = h, i = s, a = c < a ? c : a) : h === r && c < a && (a = c, i = s);
|
|
1545
1549
|
}
|
|
1546
1550
|
return i || o - n;
|
|
@@ -1554,14 +1558,14 @@ class Gn {
|
|
|
1554
1558
|
_allDistMargin(e, n, o, i) {
|
|
1555
1559
|
e.children.sort(i);
|
|
1556
1560
|
const r = this.toBBox, a = nt(e, 0, n, r), s = nt(e, o - n, o, r);
|
|
1557
|
-
let l =
|
|
1558
|
-
for (let
|
|
1559
|
-
const h = e.children[
|
|
1560
|
-
ot(a, e.leaf ? r(h) : h), l +=
|
|
1561
|
+
let l = gt(a) + gt(s);
|
|
1562
|
+
for (let f = n; f < o - n; f++) {
|
|
1563
|
+
const h = e.children[f];
|
|
1564
|
+
ot(a, e.leaf ? r(h) : h), l += gt(a);
|
|
1561
1565
|
}
|
|
1562
|
-
for (let
|
|
1563
|
-
const h = e.children[
|
|
1564
|
-
ot(s, e.leaf ? r(h) : h), l +=
|
|
1566
|
+
for (let f = o - n - 1; f >= n; f--) {
|
|
1567
|
+
const h = e.children[f];
|
|
1568
|
+
ot(s, e.leaf ? r(h) : h), l += gt(s);
|
|
1565
1569
|
}
|
|
1566
1570
|
return l;
|
|
1567
1571
|
}
|
|
@@ -1603,7 +1607,7 @@ function Zn(t, e) {
|
|
|
1603
1607
|
function Ot(t) {
|
|
1604
1608
|
return (t.maxX - t.minX) * (t.maxY - t.minY);
|
|
1605
1609
|
}
|
|
1606
|
-
function
|
|
1610
|
+
function gt(t) {
|
|
1607
1611
|
return t.maxX - t.minX + (t.maxY - t.minY);
|
|
1608
1612
|
}
|
|
1609
1613
|
function to(t, e) {
|
|
@@ -1616,7 +1620,7 @@ function eo(t, e) {
|
|
|
1616
1620
|
function Tt(t, e) {
|
|
1617
1621
|
return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
|
|
1618
1622
|
}
|
|
1619
|
-
function
|
|
1623
|
+
function pt(t, e) {
|
|
1620
1624
|
return e.minX <= t.maxX && e.minY <= t.maxY && e.maxX >= t.minX && e.maxY >= t.minY;
|
|
1621
1625
|
}
|
|
1622
1626
|
function Z(t) {
|
|
@@ -1635,7 +1639,7 @@ function Zt(t, e, n, o, i) {
|
|
|
1635
1639
|
for (; r.length; ) {
|
|
1636
1640
|
if (n = r.pop(), e = r.pop(), n - e <= o) continue;
|
|
1637
1641
|
const a = e + Math.ceil((n - e) / o / 2) * o;
|
|
1638
|
-
|
|
1642
|
+
ge(t, a, e, n, i), r.push(e, a, a, n);
|
|
1639
1643
|
}
|
|
1640
1644
|
}
|
|
1641
1645
|
let no = () => ({
|
|
@@ -1653,70 +1657,70 @@ let no = () => ({
|
|
|
1653
1657
|
}
|
|
1654
1658
|
});
|
|
1655
1659
|
const oo = (t, e) => {
|
|
1656
|
-
const n = new Gn(), o = /* @__PURE__ */ new Map(), i = no(), r = (y,
|
|
1660
|
+
const n = new Gn(), o = /* @__PURE__ */ new Map(), i = no(), r = (y, S) => {
|
|
1657
1661
|
const E = y.selector.flatMap((T) => {
|
|
1658
1662
|
const O = W([T]) ? T.range : se(T, e).range;
|
|
1659
1663
|
return Array.from(O.getClientRects());
|
|
1660
|
-
}),
|
|
1661
|
-
return
|
|
1662
|
-
const { x: O, y: R, width:
|
|
1664
|
+
}), w = Ke(E).map((T) => Pe(T, S));
|
|
1665
|
+
return w.map((T) => {
|
|
1666
|
+
const { x: O, y: R, width: m, height: v } = T;
|
|
1663
1667
|
return {
|
|
1664
1668
|
minX: O,
|
|
1665
1669
|
minY: R,
|
|
1666
|
-
maxX: O +
|
|
1667
|
-
maxY: R +
|
|
1670
|
+
maxX: O + m,
|
|
1671
|
+
maxY: R + v,
|
|
1668
1672
|
annotation: {
|
|
1669
1673
|
id: y.annotation,
|
|
1670
|
-
rects:
|
|
1674
|
+
rects: w
|
|
1671
1675
|
}
|
|
1672
1676
|
};
|
|
1673
1677
|
});
|
|
1674
1678
|
}, a = () => [...o.values()], s = () => {
|
|
1675
1679
|
n.clear(), o.clear();
|
|
1676
1680
|
}, l = (y) => {
|
|
1677
|
-
const
|
|
1678
|
-
|
|
1679
|
-
},
|
|
1680
|
-
const
|
|
1681
|
-
|
|
1681
|
+
const S = r(y, e.getBoundingClientRect());
|
|
1682
|
+
S.forEach((E) => n.insert(E)), o.set(y.annotation, S);
|
|
1683
|
+
}, f = (y) => {
|
|
1684
|
+
const S = o.get(y.annotation);
|
|
1685
|
+
S && (S.forEach((E) => n.remove(E)), o.delete(y.annotation));
|
|
1682
1686
|
}, h = (y) => {
|
|
1683
|
-
|
|
1684
|
-
}, c = (y,
|
|
1685
|
-
|
|
1686
|
-
const E = e.getBoundingClientRect(),
|
|
1687
|
-
|
|
1688
|
-
const T =
|
|
1687
|
+
f(y), l(y);
|
|
1688
|
+
}, c = (y, S = !0) => {
|
|
1689
|
+
S && s();
|
|
1690
|
+
const E = e.getBoundingClientRect(), w = y.map((O) => ({ target: O, rects: r(O, E) }));
|
|
1691
|
+
w.forEach(({ target: O, rects: R }) => o.set(O.annotation, R));
|
|
1692
|
+
const T = w.flatMap(({ rects: O }) => O);
|
|
1689
1693
|
n.load(T);
|
|
1690
|
-
},
|
|
1691
|
-
const
|
|
1694
|
+
}, g = (y, S, E = !1) => {
|
|
1695
|
+
const w = n.search({
|
|
1692
1696
|
minX: y,
|
|
1693
|
-
minY:
|
|
1697
|
+
minY: S,
|
|
1694
1698
|
maxX: y,
|
|
1695
|
-
maxY:
|
|
1696
|
-
}), T = (O) => O.annotation.rects.reduce((R,
|
|
1697
|
-
return
|
|
1698
|
-
},
|
|
1699
|
-
const
|
|
1700
|
-
if (
|
|
1699
|
+
maxY: S
|
|
1700
|
+
}), T = (O) => O.annotation.rects.reduce((R, m) => R + m.width * m.height, 0);
|
|
1701
|
+
return w.length > 0 ? (w.sort((O, R) => T(O) - T(R)), E ? w.map((O) => O.annotation.id) : [w[0].annotation.id]) : [];
|
|
1702
|
+
}, u = (y) => {
|
|
1703
|
+
const S = A(y);
|
|
1704
|
+
if (S.length === 0)
|
|
1701
1705
|
return;
|
|
1702
|
-
let E =
|
|
1703
|
-
for (let R = 1; R <
|
|
1704
|
-
const
|
|
1705
|
-
E = Math.min(E,
|
|
1706
|
+
let E = S[0].left, w = S[0].top, T = S[0].right, O = S[0].bottom;
|
|
1707
|
+
for (let R = 1; R < S.length; R++) {
|
|
1708
|
+
const m = S[R];
|
|
1709
|
+
E = Math.min(E, m.left), w = Math.min(w, m.top), T = Math.max(T, m.right), O = Math.max(O, m.bottom);
|
|
1706
1710
|
}
|
|
1707
|
-
return new DOMRect(E,
|
|
1711
|
+
return new DOMRect(E, w, T - E, O - w);
|
|
1708
1712
|
}, A = (y) => {
|
|
1709
|
-
const
|
|
1710
|
-
return
|
|
1713
|
+
const S = o.get(y);
|
|
1714
|
+
return S ? S[0].annotation.rects : [];
|
|
1711
1715
|
};
|
|
1712
1716
|
return {
|
|
1713
1717
|
all: a,
|
|
1714
1718
|
clear: s,
|
|
1715
|
-
getAt:
|
|
1716
|
-
getAnnotationBounds:
|
|
1719
|
+
getAt: g,
|
|
1720
|
+
getAnnotationBounds: u,
|
|
1717
1721
|
getAnnotationRects: A,
|
|
1718
|
-
getIntersecting: (y,
|
|
1719
|
-
const T = n.search({ minX: y, minY:
|
|
1722
|
+
getIntersecting: (y, S, E, w) => {
|
|
1723
|
+
const T = n.search({ minX: y, minY: S, maxX: E, maxY: w }), O = new Set(T.map((R) => R.annotation.id));
|
|
1720
1724
|
return Array.from(O).map((R) => ({
|
|
1721
1725
|
annotation: t.getAnnotation(R),
|
|
1722
1726
|
rects: A(R)
|
|
@@ -1726,61 +1730,61 @@ const oo = (t, e) => {
|
|
|
1726
1730
|
recalculate: () => {
|
|
1727
1731
|
c(t.all().map((y) => y.target), !0), i.emit("recalculate");
|
|
1728
1732
|
},
|
|
1729
|
-
remove:
|
|
1733
|
+
remove: f,
|
|
1730
1734
|
set: c,
|
|
1731
1735
|
size: () => n.all().length,
|
|
1732
1736
|
update: h,
|
|
1733
|
-
on: (y,
|
|
1737
|
+
on: (y, S) => i.on(y, S)
|
|
1734
1738
|
};
|
|
1735
1739
|
}, io = (t, e) => {
|
|
1736
1740
|
const n = Tn(), o = oo(n, t), i = mn(n);
|
|
1737
1741
|
i.setUserSelectAction(e);
|
|
1738
|
-
const r =
|
|
1739
|
-
const
|
|
1740
|
-
return E && n.addAnnotation(
|
|
1741
|
-
}, l = (
|
|
1742
|
-
const E =
|
|
1743
|
-
return
|
|
1744
|
-
},
|
|
1745
|
-
const
|
|
1746
|
-
return E.length > 0 && console.warn("Could not revive all targets for these annotations:", E),
|
|
1747
|
-
n.getAnnotation(
|
|
1742
|
+
const r = gn(n), a = kn(), s = (d, y = k.LOCAL) => {
|
|
1743
|
+
const S = wt(d, t), E = W(S.target.selector);
|
|
1744
|
+
return E && n.addAnnotation(S, y), E;
|
|
1745
|
+
}, l = (d, y = !0, S = k.LOCAL) => {
|
|
1746
|
+
const E = d.map((T) => wt(T, t)), w = E.filter((T) => !W(T.target.selector));
|
|
1747
|
+
return w.length > 0 ? (console.warn("Could not revive all targets for these annotations:", w), n.bulkAddAnnotation(E, y, S), w) : (n.bulkAddAnnotation(E, y, S), []);
|
|
1748
|
+
}, f = (d, y = k.LOCAL) => {
|
|
1749
|
+
const S = d.map((w) => wt(w, t)), E = S.filter((w) => !W(w.target.selector));
|
|
1750
|
+
return E.length > 0 && console.warn("Could not revive all targets for these annotations:", E), S.forEach((w) => {
|
|
1751
|
+
n.getAnnotation(w.id) ? n.updateAnnotation(w, y) : n.addAnnotation(w, y);
|
|
1748
1752
|
}), E;
|
|
1749
|
-
}, h = (
|
|
1750
|
-
const
|
|
1751
|
-
n.updateTarget(
|
|
1752
|
-
}, c = (
|
|
1753
|
-
const
|
|
1754
|
-
n.bulkUpdateTargets(
|
|
1755
|
-
},
|
|
1756
|
-
const E = o.getAt(
|
|
1757
|
-
return
|
|
1758
|
-
},
|
|
1759
|
-
const
|
|
1760
|
-
if (
|
|
1761
|
-
if (y &&
|
|
1762
|
-
const T =
|
|
1753
|
+
}, h = (d, y = k.LOCAL) => {
|
|
1754
|
+
const S = bt(d, t);
|
|
1755
|
+
n.updateTarget(S, y);
|
|
1756
|
+
}, c = (d, y = k.LOCAL) => {
|
|
1757
|
+
const S = d.map((E) => bt(E, t));
|
|
1758
|
+
n.bulkUpdateTargets(S, y);
|
|
1759
|
+
}, g = (d, y, S) => {
|
|
1760
|
+
const E = o.getAt(d, y, !!S).map((T) => n.getAnnotation(T)), w = S ? E.filter(S) : E;
|
|
1761
|
+
return w.length > 0 ? w[0] : void 0;
|
|
1762
|
+
}, u = (d, y, S, E = 5) => {
|
|
1763
|
+
const w = o.getAnnotationRects(d);
|
|
1764
|
+
if (w.length !== 0) {
|
|
1765
|
+
if (y && S) {
|
|
1766
|
+
const T = w.find(({ top: O, right: R, bottom: m, left: v }) => y >= v - E && y <= R + E && S >= O - E && S <= m + E);
|
|
1763
1767
|
if (T) return T;
|
|
1764
1768
|
}
|
|
1765
|
-
return o.getAnnotationBounds(
|
|
1769
|
+
return o.getAnnotationBounds(d);
|
|
1766
1770
|
}
|
|
1767
|
-
}, A = (
|
|
1768
|
-
return n.observe(({ changes:
|
|
1769
|
-
const y = (
|
|
1770
|
-
(y == null ? void 0 : y.length) > 0 && y.forEach((
|
|
1771
|
+
}, A = (d, y, S, E) => o.getIntersecting(d, y, S, E), b = (d) => o.getAnnotationRects(d), C = () => o.recalculate(), p = (d) => o.on("recalculate", d);
|
|
1772
|
+
return n.observe(({ changes: d }) => {
|
|
1773
|
+
const y = (d.deleted || []).filter((w) => W(w.target.selector)), S = (d.created || []).filter((w) => W(w.target.selector)), E = (d.updated || []).filter((w) => W(w.newValue.target.selector));
|
|
1774
|
+
(y == null ? void 0 : y.length) > 0 && y.forEach((w) => o.remove(w.target)), S.length > 0 && o.set(S.map((w) => w.target), !1), (E == null ? void 0 : E.length) > 0 && E.forEach(({ newValue: w }) => o.update(w.target));
|
|
1771
1775
|
}), {
|
|
1772
1776
|
store: {
|
|
1773
1777
|
...n,
|
|
1774
1778
|
addAnnotation: s,
|
|
1775
1779
|
bulkAddAnnotation: l,
|
|
1776
1780
|
bulkUpdateTargets: c,
|
|
1777
|
-
bulkUpsertAnnotations:
|
|
1778
|
-
getAnnotationBounds:
|
|
1779
|
-
getAnnotationRects:
|
|
1781
|
+
bulkUpsertAnnotations: f,
|
|
1782
|
+
getAnnotationBounds: u,
|
|
1783
|
+
getAnnotationRects: b,
|
|
1780
1784
|
getIntersecting: A,
|
|
1781
|
-
getAt:
|
|
1782
|
-
recalculatePositions:
|
|
1783
|
-
onRecalculatePositions:
|
|
1785
|
+
getAt: g,
|
|
1786
|
+
recalculatePositions: C,
|
|
1787
|
+
onRecalculatePositions: p,
|
|
1784
1788
|
updateTarget: h
|
|
1785
1789
|
},
|
|
1786
1790
|
selection: i,
|
|
@@ -1794,7 +1798,7 @@ function Mt(t, e, n, o) {
|
|
|
1794
1798
|
function et(t, e, n, o) {
|
|
1795
1799
|
t.removeEventListener ? t.removeEventListener(e, n, o) : t.detachEvent && t.detachEvent("on".concat(e), n);
|
|
1796
1800
|
}
|
|
1797
|
-
function
|
|
1801
|
+
function pe(t, e) {
|
|
1798
1802
|
const n = e.slice(0, e.length - 1);
|
|
1799
1803
|
for (let o = 0; o < n.length; o++) n[o] = t[n[o].toLowerCase()];
|
|
1800
1804
|
return n;
|
|
@@ -1943,7 +1947,7 @@ function fo(t) {
|
|
|
1943
1947
|
function ho(t) {
|
|
1944
1948
|
return typeof t == "string" && (t = ct(t)), I.indexOf(t) !== -1;
|
|
1945
1949
|
}
|
|
1946
|
-
function
|
|
1950
|
+
function go(t, e) {
|
|
1947
1951
|
let n, o;
|
|
1948
1952
|
t || (t = at());
|
|
1949
1953
|
for (const i in N)
|
|
@@ -1957,7 +1961,7 @@ function po(t, e) {
|
|
|
1957
1961
|
}) : o++;
|
|
1958
1962
|
at() === t && be(e || "all");
|
|
1959
1963
|
}
|
|
1960
|
-
function
|
|
1964
|
+
function po(t) {
|
|
1961
1965
|
let e = t.keyCode || t.which || t.charCode;
|
|
1962
1966
|
const n = I.indexOf(e);
|
|
1963
1967
|
if (n >= 0 && I.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && I.splice(0, I.length), (e === 93 || e === 224) && (e = 91), e in D) {
|
|
@@ -1996,14 +2000,14 @@ const mt = (t) => {
|
|
|
1996
2000
|
splitKey: i = "+"
|
|
1997
2001
|
} = t;
|
|
1998
2002
|
me(e).forEach((a) => {
|
|
1999
|
-
const s = a.split(i), l = s.length,
|
|
2003
|
+
const s = a.split(i), l = s.length, f = s[l - 1], h = f === "*" ? "*" : ct(f);
|
|
2000
2004
|
if (!N[h]) return;
|
|
2001
2005
|
n || (n = at());
|
|
2002
|
-
const c = l > 1 ?
|
|
2003
|
-
N[h] = N[h].filter((
|
|
2004
|
-
const
|
|
2005
|
-
return
|
|
2006
|
-
}),
|
|
2006
|
+
const c = l > 1 ? pe(H, s) : [], g = [];
|
|
2007
|
+
N[h] = N[h].filter((u) => {
|
|
2008
|
+
const b = (o ? u.method === o : !0) && u.scope === n && ro(u.mods, c);
|
|
2009
|
+
return b && g.push(u.element), !b;
|
|
2010
|
+
}), g.forEach((u) => Kt(u));
|
|
2007
2011
|
});
|
|
2008
2012
|
};
|
|
2009
2013
|
function te(t, e, n, o) {
|
|
@@ -2042,21 +2046,21 @@ function ee(t, e) {
|
|
|
2042
2046
|
for (let s = 0; s < a; s++)
|
|
2043
2047
|
if ((t.type === "keydown" && r[s].keydown || t.type === "keyup" && r[s].keyup) && r[s].key) {
|
|
2044
2048
|
const l = r[s], {
|
|
2045
|
-
splitKey:
|
|
2046
|
-
} = l, h = l.key.split(
|
|
2047
|
-
for (let
|
|
2048
|
-
c.push(ct(h[
|
|
2049
|
+
splitKey: f
|
|
2050
|
+
} = l, h = l.key.split(f), c = [];
|
|
2051
|
+
for (let g = 0; g < h.length; g++)
|
|
2052
|
+
c.push(ct(h[g]));
|
|
2049
2053
|
c.sort().join("") === I.sort().join("") && te(t, l, i, e);
|
|
2050
2054
|
}
|
|
2051
2055
|
}
|
|
2052
2056
|
function $(t, e, n) {
|
|
2053
2057
|
I = [];
|
|
2054
2058
|
const o = me(t);
|
|
2055
|
-
let i = [], r = "all", a = document, s = 0, l = !1,
|
|
2056
|
-
for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (r = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (
|
|
2057
|
-
t = o[s].split(h), i = [], t.length > 1 && (i =
|
|
2059
|
+
let i = [], r = "all", a = document, s = 0, l = !1, f = !0, h = "+", c = !1, g = !1;
|
|
2060
|
+
for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (r = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (f = e.keydown), e.capture !== void 0 && (c = e.capture), typeof e.splitKey == "string" && (h = e.splitKey), e.single === !0 && (g = !0)), typeof e == "string" && (r = e), g && we(t, r); s < o.length; s++)
|
|
2061
|
+
t = o[s].split(h), i = [], t.length > 1 && (i = pe(H, t)), t = t[t.length - 1], t = t === "*" ? "*" : ct(t), t in N || (N[t] = []), N[t].push({
|
|
2058
2062
|
keyup: l,
|
|
2059
|
-
keydown:
|
|
2063
|
+
keydown: f,
|
|
2060
2064
|
scope: r,
|
|
2061
2065
|
mods: i,
|
|
2062
2066
|
shortcut: o[s],
|
|
@@ -2067,27 +2071,27 @@ function $(t, e, n) {
|
|
|
2067
2071
|
});
|
|
2068
2072
|
if (typeof a < "u" && window) {
|
|
2069
2073
|
if (!F.has(a)) {
|
|
2070
|
-
const
|
|
2071
|
-
let
|
|
2072
|
-
return ee(
|
|
2074
|
+
const u = function() {
|
|
2075
|
+
let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
|
|
2076
|
+
return ee(b, a);
|
|
2073
2077
|
}, A = function() {
|
|
2074
|
-
let
|
|
2075
|
-
ee(
|
|
2078
|
+
let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
|
|
2079
|
+
ee(b, a), po(b);
|
|
2076
2080
|
};
|
|
2077
2081
|
F.set(a, {
|
|
2078
|
-
keydownListener:
|
|
2082
|
+
keydownListener: u,
|
|
2079
2083
|
keyupListenr: A,
|
|
2080
2084
|
capture: c
|
|
2081
|
-
}), Mt(a, "keydown",
|
|
2085
|
+
}), Mt(a, "keydown", u, c), Mt(a, "keyup", A, c);
|
|
2082
2086
|
}
|
|
2083
2087
|
if (!rt) {
|
|
2084
|
-
const
|
|
2088
|
+
const u = () => {
|
|
2085
2089
|
I = [];
|
|
2086
2090
|
};
|
|
2087
2091
|
rt = {
|
|
2088
|
-
listener:
|
|
2092
|
+
listener: u,
|
|
2089
2093
|
capture: c
|
|
2090
|
-
}, Mt(window, "focus",
|
|
2094
|
+
}, Mt(window, "focus", u, c);
|
|
2091
2095
|
}
|
|
2092
2096
|
}
|
|
2093
2097
|
}
|
|
@@ -2133,7 +2137,7 @@ const Bt = {
|
|
|
2133
2137
|
getPressedKeyString: lo,
|
|
2134
2138
|
setScope: be,
|
|
2135
2139
|
getScope: at,
|
|
2136
|
-
deleteScope:
|
|
2140
|
+
deleteScope: go,
|
|
2137
2141
|
getPressedKeyCodes: co,
|
|
2138
2142
|
getAllKeyCodes: uo,
|
|
2139
2143
|
isPressed: ho,
|
|
@@ -2152,24 +2156,24 @@ if (typeof window < "u") {
|
|
|
2152
2156
|
}
|
|
2153
2157
|
const ne = 300, yo = (t, e, n) => {
|
|
2154
2158
|
let o;
|
|
2155
|
-
const i = (
|
|
2159
|
+
const i = (w) => o = w;
|
|
2156
2160
|
let r;
|
|
2157
|
-
const a = (
|
|
2161
|
+
const a = (w) => r = w;
|
|
2158
2162
|
let s = !0;
|
|
2159
|
-
const l = (
|
|
2160
|
-
s =
|
|
2161
|
-
}, { store:
|
|
2162
|
-
let c,
|
|
2163
|
-
const A = (
|
|
2163
|
+
const l = (w) => {
|
|
2164
|
+
s = w, b.clear(), w || (c = void 0, g = void 0, u = void 0);
|
|
2165
|
+
}, { store: f, selection: h } = e;
|
|
2166
|
+
let c, g, u;
|
|
2167
|
+
const A = (w) => {
|
|
2164
2168
|
var O;
|
|
2165
|
-
if (!s ||
|
|
2166
|
-
c = !((O =
|
|
2169
|
+
if (!s || g === !1) return;
|
|
2170
|
+
c = !((O = w.target.parentElement) != null && O.closest(j)) ? {
|
|
2167
2171
|
annotation: de(),
|
|
2168
2172
|
selector: [],
|
|
2169
2173
|
creator: o,
|
|
2170
2174
|
created: /* @__PURE__ */ new Date()
|
|
2171
2175
|
} : void 0;
|
|
2172
|
-
},
|
|
2176
|
+
}, b = Ut((w) => {
|
|
2173
2177
|
var B, M;
|
|
2174
2178
|
if (!s) return;
|
|
2175
2179
|
const T = document.getSelection();
|
|
@@ -2177,15 +2181,15 @@ const ne = 300, yo = (t, e, n) => {
|
|
|
2177
2181
|
c = void 0;
|
|
2178
2182
|
return;
|
|
2179
2183
|
}
|
|
2180
|
-
const R =
|
|
2181
|
-
if ((
|
|
2184
|
+
const R = w.timeStamp - ((u == null ? void 0 : u.timeStamp) || w.timeStamp);
|
|
2185
|
+
if ((u == null ? void 0 : u.type) === "pointerdown" && (R < 1e3 && !c || T.isCollapsed && R < ne) && A(u), !c) return;
|
|
2182
2186
|
if (T.isCollapsed) {
|
|
2183
|
-
|
|
2187
|
+
f.getAnnotation(c.annotation) && (h.clear(), f.deleteAnnotation(c.annotation));
|
|
2184
2188
|
return;
|
|
2185
2189
|
}
|
|
2186
|
-
const
|
|
2187
|
-
if (Ue(
|
|
2188
|
-
const x = Te(
|
|
2190
|
+
const m = T.getRangeAt(0), v = Xe(m, t);
|
|
2191
|
+
if (Ue(v)) return;
|
|
2192
|
+
const x = Te(v.cloneRange());
|
|
2189
2193
|
(x.length !== c.selector.length || x.some((K, Y) => {
|
|
2190
2194
|
var lt;
|
|
2191
2195
|
return K.toString() !== ((lt = c.selector[Y]) == null ? void 0 : lt.quote);
|
|
@@ -2193,46 +2197,46 @@ const ne = 300, yo = (t, e, n) => {
|
|
|
2193
2197
|
...c,
|
|
2194
2198
|
selector: x.map((K) => Ye(K, t, n)),
|
|
2195
2199
|
updated: /* @__PURE__ */ new Date()
|
|
2196
|
-
},
|
|
2200
|
+
}, f.getAnnotation(c.annotation) ? f.updateTarget(c, k.LOCAL) : (h.clear(), f.addAnnotation({
|
|
2197
2201
|
id: c.annotation,
|
|
2198
2202
|
bodies: [],
|
|
2199
2203
|
target: c
|
|
2200
|
-
}, k.LOCAL), h.userSelect(c.annotation,
|
|
2201
|
-
}),
|
|
2202
|
-
|
|
2203
|
-
},
|
|
2204
|
-
var
|
|
2205
|
-
if (!!((
|
|
2204
|
+
}, k.LOCAL), h.userSelect(c.annotation, u)));
|
|
2205
|
+
}), C = (w) => {
|
|
2206
|
+
u = $e(w), g = u.button === 0;
|
|
2207
|
+
}, p = (w) => {
|
|
2208
|
+
var m;
|
|
2209
|
+
if (!!((m = w.target.parentElement) != null && m.closest(j)) || !g)
|
|
2206
2210
|
return;
|
|
2207
2211
|
const O = () => {
|
|
2208
|
-
const { x:
|
|
2212
|
+
const { x: v, y: x } = t.getBoundingClientRect(), L = w.target instanceof Node && t.contains(w.target) && f.getAt(w.clientX - v, w.clientY - x, r);
|
|
2209
2213
|
if (L) {
|
|
2210
2214
|
const { selected: B } = h;
|
|
2211
|
-
(B.length !== 1 || B[0].id !== L.id) && h.userSelect(L.id,
|
|
2215
|
+
(B.length !== 1 || B[0].id !== L.id) && h.userSelect(L.id, w);
|
|
2212
2216
|
} else h.isEmpty() || h.clear();
|
|
2213
2217
|
};
|
|
2214
2218
|
document.getSelection();
|
|
2215
|
-
const R =
|
|
2219
|
+
const R = w.timeStamp - u.timeStamp;
|
|
2216
2220
|
setTimeout(() => {
|
|
2217
|
-
const
|
|
2218
|
-
|
|
2221
|
+
const v = document.getSelection();
|
|
2222
|
+
v != null && v.isCollapsed && R < ne ? (c = void 0, O()) : c && f.getAnnotation(c.annotation) && h.userSelect(c.annotation, w);
|
|
2219
2223
|
});
|
|
2220
2224
|
};
|
|
2221
|
-
document.addEventListener("pointerdown",
|
|
2222
|
-
const
|
|
2223
|
-
...
|
|
2225
|
+
document.addEventListener("pointerdown", C), document.addEventListener("pointerup", p), t.addEventListener("selectstart", A), document.addEventListener("selectionchange", b);
|
|
2226
|
+
const d = ["up", "down", "left", "right"], y = [
|
|
2227
|
+
...d.map((w) => `shift+${w}`),
|
|
2224
2228
|
"ctrl+a",
|
|
2225
2229
|
"⌘+a"
|
|
2226
2230
|
];
|
|
2227
|
-
$(y.join(","), { element: t, keydown: !0, keyup: !1 }, (
|
|
2228
|
-
|
|
2231
|
+
$(y.join(","), { element: t, keydown: !0, keyup: !1 }, (w) => {
|
|
2232
|
+
w.repeat || (u = je(w));
|
|
2229
2233
|
});
|
|
2230
|
-
const
|
|
2231
|
-
|
|
2234
|
+
const S = (w) => {
|
|
2235
|
+
w.repeat || w.target !== t && w.target !== document.body || (c = void 0, h.clear());
|
|
2232
2236
|
};
|
|
2233
|
-
return $(
|
|
2237
|
+
return $(d.join(","), { keydown: !0, keyup: !1 }, S), {
|
|
2234
2238
|
destroy: () => {
|
|
2235
|
-
c = void 0,
|
|
2239
|
+
c = void 0, g = void 0, u = void 0, b.clear(), document.removeEventListener("pointerdown", C), document.removeEventListener("pointerup", p), t.removeEventListener("selectstart", A), document.removeEventListener("selectionchange", b), $.unbind();
|
|
2236
2240
|
},
|
|
2237
2241
|
setFilter: a,
|
|
2238
2242
|
setUser: i,
|
|
@@ -2246,27 +2250,27 @@ const ne = 300, yo = (t, e, n) => {
|
|
|
2246
2250
|
}, wo = (t, e, n = {}) => {
|
|
2247
2251
|
const o = bo(), i = o.getContext("2d");
|
|
2248
2252
|
document.body.appendChild(o);
|
|
2249
|
-
const r = /* @__PURE__ */ new Map(), a = (c) => Array.from(r.entries()).filter(([
|
|
2250
|
-
return e.on("selectionChange", (c,
|
|
2251
|
-
a(c).forEach((A) => r.delete(A)),
|
|
2253
|
+
const r = /* @__PURE__ */ new Map(), a = (c) => Array.from(r.entries()).filter(([g, u]) => u.presenceKey === c.presenceKey).map(([g, u]) => g);
|
|
2254
|
+
return e.on("selectionChange", (c, g) => {
|
|
2255
|
+
a(c).forEach((A) => r.delete(A)), g && g.forEach((A) => r.set(A, c));
|
|
2252
2256
|
}), {
|
|
2253
2257
|
clear: () => {
|
|
2254
|
-
const { width: c, height:
|
|
2255
|
-
i.clearRect(-0.5, -0.5, c + 1,
|
|
2258
|
+
const { width: c, height: g } = o;
|
|
2259
|
+
i.clearRect(-0.5, -0.5, c + 1, g + 1);
|
|
2256
2260
|
},
|
|
2257
2261
|
destroy: () => {
|
|
2258
2262
|
o.remove();
|
|
2259
2263
|
},
|
|
2260
|
-
paint: (c,
|
|
2264
|
+
paint: (c, g, u) => {
|
|
2261
2265
|
n.font && (i.font = n.font);
|
|
2262
2266
|
const A = r.get(c.annotation.id);
|
|
2263
2267
|
if (A) {
|
|
2264
|
-
const { height:
|
|
2265
|
-
i.fillStyle = A.appearance.color, i.fillRect(
|
|
2266
|
-
const
|
|
2267
|
-
return i.fillRect(
|
|
2268
|
+
const { height: b } = c.rects[0], C = c.rects[0].x + g.left, p = c.rects[0].y + g.top;
|
|
2269
|
+
i.fillStyle = A.appearance.color, i.fillRect(C - 2, p - 2.5, 2, b + 5);
|
|
2270
|
+
const d = i.measureText(A.appearance.label), y = d.width + 6, S = d.actualBoundingBoxAscent + d.actualBoundingBoxDescent + 8, E = d.fontBoundingBoxAscent ? 8 : 6.5;
|
|
2271
|
+
return i.fillRect(C - 2, p - 2.5 - S, y, S), i.fillStyle = "#fff", i.fillText(A.appearance.label, C + 1, p - E), {
|
|
2268
2272
|
fill: A.appearance.color,
|
|
2269
|
-
fillOpacity:
|
|
2273
|
+
fillOpacity: u ? 0.45 : 0.18
|
|
2270
2274
|
};
|
|
2271
2275
|
}
|
|
2272
2276
|
},
|
|
@@ -2283,16 +2287,16 @@ const ne = 300, yo = (t, e, n) => {
|
|
|
2283
2287
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ve(t.parentElement);
|
|
2284
2288
|
}, vo = (t, e) => (n) => {
|
|
2285
2289
|
const o = typeof n == "string" ? n : n.id, i = (a) => {
|
|
2286
|
-
const s = r.getBoundingClientRect(), l = r.clientHeight,
|
|
2287
|
-
r.scroll({ top:
|
|
2290
|
+
const s = r.getBoundingClientRect(), l = r.clientHeight, f = r.clientWidth, h = a.selector[0].range.getBoundingClientRect(), { width: c, height: g } = e.getAnnotationBounds(o), u = h.top - s.top, A = h.left - s.left, b = r.parentElement ? r.scrollTop : 0, C = r.parentElement ? r.scrollLeft : 0, p = u + b - (l - g) / 2, d = A + C - (f - c) / 2;
|
|
2291
|
+
r.scroll({ top: p, left: d, behavior: "smooth" });
|
|
2288
2292
|
}, r = ve(t);
|
|
2289
2293
|
if (r) {
|
|
2290
2294
|
const a = e.getAnnotation(o), { range: s } = a.target.selector[0];
|
|
2291
2295
|
if (s && !s.collapsed)
|
|
2292
2296
|
return i(a.target), !0;
|
|
2293
2297
|
{
|
|
2294
|
-
const l = bt(a.target, t), { range:
|
|
2295
|
-
if (
|
|
2298
|
+
const l = bt(a.target, t), { range: f } = l.selector[0];
|
|
2299
|
+
if (f && !f.collapsed)
|
|
2296
2300
|
return i(l), !0;
|
|
2297
2301
|
}
|
|
2298
2302
|
}
|
|
@@ -2307,40 +2311,40 @@ const ne = 300, yo = (t, e, n) => {
|
|
|
2307
2311
|
annotatingEnabled: !0,
|
|
2308
2312
|
user: Xn()
|
|
2309
2313
|
}), o = io(t, n.userSelectAction), { selection: i, viewport: r } = o, a = o.store, s = Bn(a), l = In(o, s, n.adapter);
|
|
2310
|
-
let
|
|
2314
|
+
let f = n.user;
|
|
2311
2315
|
const h = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : oe : n.renderer || oe, c = h === "SPANS" ? cn(t, o, r) : h === "CSS_HIGHLIGHTS" ? rn(t, o, r) : h === "CANVAS" ? We(t, o, r) : void 0;
|
|
2312
2316
|
if (!c)
|
|
2313
2317
|
throw `Unknown renderer implementation: ${h}`;
|
|
2314
2318
|
console.debug(`Using ${h} renderer`), n.style && c.setStyle(n.style);
|
|
2315
|
-
const
|
|
2316
|
-
|
|
2317
|
-
const
|
|
2318
|
-
|
|
2319
|
+
const g = yo(t, o, n.offsetReferenceSelector);
|
|
2320
|
+
g.setUser(f), g.setAnnotatingEnabled(n.annotatingEnabled);
|
|
2321
|
+
const u = _n(o, s, n.adapter), A = () => f, b = (E) => {
|
|
2322
|
+
g.setAnnotatingEnabled(
|
|
2319
2323
|
E === void 0 ? !0 : E
|
|
2320
2324
|
);
|
|
2321
|
-
},
|
|
2322
|
-
c.setFilter(E),
|
|
2323
|
-
},
|
|
2324
|
-
|
|
2325
|
-
},
|
|
2325
|
+
}, C = (E) => {
|
|
2326
|
+
c.setFilter(E), g.setFilter(E);
|
|
2327
|
+
}, p = (E) => {
|
|
2328
|
+
f = E, g.setUser(E);
|
|
2329
|
+
}, d = (E) => {
|
|
2326
2330
|
E && (c.setPainter(wo(t, E, n.presence)), E.on("selectionChange", () => c.redraw()));
|
|
2327
2331
|
}, y = (E) => {
|
|
2328
2332
|
E ? i.setSelected(E) : i.clear();
|
|
2329
2333
|
};
|
|
2330
2334
|
return {
|
|
2331
|
-
...
|
|
2335
|
+
...u,
|
|
2332
2336
|
destroy: () => {
|
|
2333
|
-
c.destroy(),
|
|
2337
|
+
c.destroy(), g.destroy(), s.destroy();
|
|
2334
2338
|
},
|
|
2335
2339
|
element: t,
|
|
2336
2340
|
getUser: A,
|
|
2337
|
-
setAnnotatingEnabled:
|
|
2338
|
-
setFilter:
|
|
2341
|
+
setAnnotatingEnabled: b,
|
|
2342
|
+
setFilter: C,
|
|
2339
2343
|
setStyle: c.setStyle.bind(c),
|
|
2340
2344
|
redraw: c.redraw.bind(c),
|
|
2341
|
-
setUser:
|
|
2345
|
+
setUser: p,
|
|
2342
2346
|
setSelected: y,
|
|
2343
|
-
setPresenceProvider:
|
|
2347
|
+
setPresenceProvider: d,
|
|
2344
2348
|
setVisible: c.setVisible.bind(c),
|
|
2345
2349
|
on: l.on,
|
|
2346
2350
|
off: l.off,
|
|
@@ -2354,7 +2358,7 @@ export {
|
|
|
2354
2358
|
ie as NOT_ANNOTATABLE_CLASS,
|
|
2355
2359
|
j as NOT_ANNOTATABLE_SELECTOR,
|
|
2356
2360
|
k as Origin,
|
|
2357
|
-
|
|
2361
|
+
pn as UserSelectAction,
|
|
2358
2362
|
Lo as W3CTextFormat,
|
|
2359
2363
|
Re as cancelSingleClickEvents,
|
|
2360
2364
|
je as cloneKeyboardEvent,
|