@soomo/text-annotator 3.1.0-staging.20 → 3.1.0-staging.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/TextAnnotator.d.ts +1 -1
- package/dist/src/highlight/HighlightStyle.d.ts +1 -1
- package/dist/src/model/w3c/W3CTextFormatAdapter.d.ts +3 -3
- package/dist/text-annotator.es.js +189 -189
- package/dist/text-annotator.es.js.map +1 -1
- package/dist/text-annotator.umd.js +2 -2
- package/dist/text-annotator.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -118,9 +118,9 @@ const de = "not-annotatable", et = `.${de}`, st = (t) => {
|
|
|
118
118
|
const a = document.createRange();
|
|
119
119
|
let l = s.nextNode();
|
|
120
120
|
l === null && console.error("Could not revive annotation target. Content missing.");
|
|
121
|
-
let
|
|
121
|
+
let u = !i;
|
|
122
122
|
for (; l !== null; ) {
|
|
123
|
-
if (
|
|
123
|
+
if (u || (u = i == null ? void 0 : i.contains(l)), u) {
|
|
124
124
|
const h = ((p = l.textContent) == null ? void 0 : p.length) || 0;
|
|
125
125
|
if (r + h > n) {
|
|
126
126
|
a.setStart(l, n - r);
|
|
@@ -213,7 +213,7 @@ const de = "not-annotatable", et = `.${de}`, st = (t) => {
|
|
|
213
213
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : he(t.parentElement);
|
|
214
214
|
}, ze = (t, e) => (n) => {
|
|
215
215
|
const o = typeof n == "string" ? n : n.id, i = (r) => {
|
|
216
|
-
const a = s.getBoundingClientRect(), l = s.clientHeight,
|
|
216
|
+
const a = s.getBoundingClientRect(), l = s.clientHeight, u = s.clientWidth, p = r.selector[0].range.getBoundingClientRect(), { width: d, height: h } = e.getAnnotationBounds(o), g = p.top - a.top, b = p.left - a.left, A = s.parentElement ? s.scrollTop : 0, C = s.parentElement ? s.scrollLeft : 0, m = g + A - (l - h) / 2, c = b + C - (u - d) / 2;
|
|
217
217
|
s.scroll({ top: m, left: c, behavior: "smooth" });
|
|
218
218
|
}, s = he(t);
|
|
219
219
|
if (s) {
|
|
@@ -221,8 +221,8 @@ const de = "not-annotatable", et = `.${de}`, st = (t) => {
|
|
|
221
221
|
if (a && !a.collapsed)
|
|
222
222
|
return i(r.target), !0;
|
|
223
223
|
{
|
|
224
|
-
const l = At(r.target, t), { range:
|
|
225
|
-
if (
|
|
224
|
+
const l = At(r.target, t), { range: u } = l.selector[0];
|
|
225
|
+
if (u && !u.collapsed)
|
|
226
226
|
return i(l), !0;
|
|
227
227
|
}
|
|
228
228
|
}
|
|
@@ -249,27 +249,27 @@ function pe(t, e = 100, n = {}) {
|
|
|
249
249
|
throw new RangeError("`wait` must not be negative.");
|
|
250
250
|
const { immediate: o } = typeof n == "boolean" ? { immediate: n } : n;
|
|
251
251
|
let i, s, r, a, l;
|
|
252
|
-
function
|
|
252
|
+
function u() {
|
|
253
253
|
const h = i, g = s;
|
|
254
254
|
return i = void 0, s = void 0, l = t.apply(h, g), l;
|
|
255
255
|
}
|
|
256
256
|
function p() {
|
|
257
257
|
const h = Date.now() - a;
|
|
258
|
-
h < e && h >= 0 ? r = setTimeout(p, e - h) : (r = void 0, o || (l =
|
|
258
|
+
h < e && h >= 0 ? r = setTimeout(p, e - h) : (r = void 0, o || (l = u()));
|
|
259
259
|
}
|
|
260
260
|
const d = function(...h) {
|
|
261
261
|
if (i && this !== i && Object.getPrototypeOf(this) === Object.getPrototypeOf(i))
|
|
262
262
|
throw new Error("Debounced method called with different contexts of the same prototype.");
|
|
263
263
|
i = this, s = h, a = Date.now();
|
|
264
264
|
const g = o && !r;
|
|
265
|
-
return r || (r = setTimeout(p, e)), g && (l =
|
|
265
|
+
return r || (r = setTimeout(p, e)), g && (l = u()), l;
|
|
266
266
|
};
|
|
267
267
|
return d.clear = () => {
|
|
268
268
|
r && (clearTimeout(r), r = void 0);
|
|
269
269
|
}, d.flush = () => {
|
|
270
270
|
r && d.trigger();
|
|
271
271
|
}, d.trigger = () => {
|
|
272
|
-
l =
|
|
272
|
+
l = u(), d.clear();
|
|
273
273
|
}, d;
|
|
274
274
|
}
|
|
275
275
|
Xt.exports.debounce = pe;
|
|
@@ -286,21 +286,21 @@ const Pt = /* @__PURE__ */ We(qe), Ge = (t) => {
|
|
|
286
286
|
};
|
|
287
287
|
}, $t = (t, e, n, o) => {
|
|
288
288
|
const { store: i, selection: s, hover: r } = e;
|
|
289
|
-
let a, l,
|
|
289
|
+
let a, l, u;
|
|
290
290
|
const p = Qe(n), d = (T) => {
|
|
291
291
|
const { x: M, y: w } = t.getBoundingClientRect(), v = i.getAt(T.clientX - M, T.clientY - w, !1, l);
|
|
292
292
|
v ? r.current !== v.id && (t.classList.add("hovered"), r.set(v.id)) : r.current && (t.classList.remove("hovered"), r.set(null));
|
|
293
293
|
};
|
|
294
294
|
t.addEventListener("pointermove", d);
|
|
295
295
|
const h = (T = !1) => {
|
|
296
|
-
|
|
297
|
-
const M = Ge(t), { minX: w, minY: v, maxX:
|
|
296
|
+
u && u.clear();
|
|
297
|
+
const M = Ge(t), { minX: w, minY: v, maxX: f, maxY: E } = M, B = l ? i.getIntersecting(w, v, f, E).filter(({ annotation: _ }) => l(_)) : i.getIntersecting(w, v, f, E), R = s.selected.map(({ id: _ }) => _), U = B.map(({ annotation: _, rects: ht }) => {
|
|
298
298
|
const W = R.includes(_.id), G = _.id === r.current;
|
|
299
299
|
return { annotation: _, rects: ht, state: { selected: W, hover: G } };
|
|
300
300
|
});
|
|
301
|
-
o.redraw(U, M, a,
|
|
301
|
+
o.redraw(U, M, a, u, T), setTimeout(() => p(B.map(({ annotation: _ }) => _)), 1);
|
|
302
302
|
}, g = (T) => {
|
|
303
|
-
|
|
303
|
+
u = T, h();
|
|
304
304
|
}, b = (T) => {
|
|
305
305
|
a = T, h();
|
|
306
306
|
}, A = (T) => {
|
|
@@ -310,7 +310,7 @@ const Pt = /* @__PURE__ */ We(qe), Ge = (t) => {
|
|
|
310
310
|
const m = s.subscribe(() => h()), c = () => h(!0);
|
|
311
311
|
document.addEventListener("scroll", c, { capture: !0, passive: !0 });
|
|
312
312
|
const y = Pt(() => {
|
|
313
|
-
i.recalculatePositions(),
|
|
313
|
+
i.recalculatePositions(), u == null || u.reset(), h();
|
|
314
314
|
}, 10);
|
|
315
315
|
window.addEventListener("resize", y);
|
|
316
316
|
const S = new ResizeObserver(y);
|
|
@@ -337,7 +337,7 @@ const Pt = /* @__PURE__ */ We(qe), Ge = (t) => {
|
|
|
337
337
|
t.classList.add("r6o-annotatable");
|
|
338
338
|
const e = Je(), n = e.getContext("2d");
|
|
339
339
|
document.body.appendChild(e);
|
|
340
|
-
const o = (a, l,
|
|
340
|
+
const o = (a, l, u, p) => requestAnimationFrame(() => {
|
|
341
341
|
const { width: d, height: h } = e;
|
|
342
342
|
n.clearRect(-0.5, -0.5, d + 1, h + 1), p && p.clear();
|
|
343
343
|
const { top: g, left: b } = l;
|
|
@@ -346,7 +346,7 @@ const Pt = /* @__PURE__ */ We(qe), Ge = (t) => {
|
|
|
346
346
|
return c.getTime() - y.getTime();
|
|
347
347
|
}).forEach((C) => {
|
|
348
348
|
var S;
|
|
349
|
-
const m =
|
|
349
|
+
const m = u ? typeof u == "function" ? u(C.annotation, C.state) : u : (S = C.state) != null && S.selected ? xt : q, c = p && p.paint(C, l) || m, y = C.rects.map(({ x, y: L, width: O, height: T }) => ({
|
|
350
350
|
x: x + b,
|
|
351
351
|
y: L + g,
|
|
352
352
|
width: O,
|
|
@@ -394,8 +394,8 @@ var nn = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, H = function(t) {
|
|
|
394
394
|
}, ye = function(t) {
|
|
395
395
|
var e = t.h, n = t.s, o = t.v, i = t.a;
|
|
396
396
|
e = e / 360 * 6, n /= 100, o /= 100;
|
|
397
|
-
var s = Math.floor(e), r = o * (1 - n), a = o * (1 - (e - s) * n), l = o * (1 - (1 - e + s) * n),
|
|
398
|
-
return { r: 255 * [o, a, r, r, l, o][
|
|
397
|
+
var s = Math.floor(e), r = o * (1 - n), a = o * (1 - (e - s) * n), l = o * (1 - (1 - e + s) * n), u = s % 6;
|
|
398
|
+
return { r: 255 * [o, a, r, r, l, o][u], g: 255 * [l, o, o, a, r, r][u], b: 255 * [r, r, l, o, o, a][u], a: i };
|
|
399
399
|
}, Ft = function(t) {
|
|
400
400
|
return { h: ge(t.h), s: X(t.s, 0, 100), l: X(t.l, 0, 100), a: X(t.a) };
|
|
401
401
|
}, Wt = function(t) {
|
|
@@ -522,8 +522,8 @@ const dn = (t) => [
|
|
|
522
522
|
},
|
|
523
523
|
redraw: (s, r, a, l) => {
|
|
524
524
|
l && l.clear();
|
|
525
|
-
const
|
|
526
|
-
Array.from(e).filter((d) => !
|
|
525
|
+
const u = new Set(s.map((d) => d.annotation.id));
|
|
526
|
+
Array.from(e).filter((d) => !u.has(d));
|
|
527
527
|
const p = s.map((d) => {
|
|
528
528
|
var b;
|
|
529
529
|
const h = a ? typeof a == "function" ? a(d.annotation, d.state) : a : (b = d.state) != null && b.selected ? xt : q, g = l && l.paint(d, r) || h;
|
|
@@ -533,7 +533,7 @@ const dn = (t) => [
|
|
|
533
533
|
`), CSS.highlights.clear(), s.forEach(({ annotation: d }) => {
|
|
534
534
|
const h = d.target.selector.map((b) => b.range), g = new Highlight(...h);
|
|
535
535
|
CSS.highlights.set(`_${d.id}`, g);
|
|
536
|
-
}), e =
|
|
536
|
+
}), e = u;
|
|
537
537
|
}
|
|
538
538
|
};
|
|
539
539
|
}, fn = (t, e, n) => $t(t, e, n, un());
|
|
@@ -570,15 +570,15 @@ const hn = (t, e) => {
|
|
|
570
570
|
destroy: () => {
|
|
571
571
|
e.remove();
|
|
572
572
|
},
|
|
573
|
-
redraw: (r, a, l,
|
|
573
|
+
redraw: (r, a, l, u, p) => {
|
|
574
574
|
const h = !(Yt(n, r) && p);
|
|
575
|
-
if (!
|
|
575
|
+
if (!u && !h) return;
|
|
576
576
|
h && (e.innerHTML = ""), [...r].sort((b, A) => {
|
|
577
577
|
const { annotation: { target: { created: C } } } = b, { annotation: { target: { created: m } } } = A;
|
|
578
578
|
return C && m ? C.getTime() - m.getTime() : 0;
|
|
579
579
|
}).forEach((b) => {
|
|
580
580
|
b.rects.map((A) => {
|
|
581
|
-
const C = hn(A, r), m = Fe(b, a, l,
|
|
581
|
+
const C = hn(A, r), m = Fe(b, a, l, u, C);
|
|
582
582
|
if (h) {
|
|
583
583
|
const c = document.createElement("span");
|
|
584
584
|
c.className = "r6o-annotation", c.dataset.annotation = b.annotation.id, c.style.left = `${A.x}px`, c.style.top = `${A.y}px`, c.style.width = `${A.width}px`, c.style.height = `${A.height}px`, c.style.backgroundColor = $((m == null ? void 0 : m.fill) || q.fill).alpha((m == null ? void 0 : m.fillOpacity) === void 0 ? q.fillOpacity : m.fillOpacity).toHex(), m.underlineStyle && (c.style.borderStyle = m.underlineStyle), m.underlineColor && (c.style.borderColor = m.underlineColor), m.underlineThickness && (c.style.borderBottomWidth = `${m.underlineThickness}px`), m.underlineOffset && (c.style.paddingBottom = `${m.underlineOffset}px`), e.appendChild(c);
|
|
@@ -647,11 +647,11 @@ function jt(t, e = Rt) {
|
|
|
647
647
|
function i(a) {
|
|
648
648
|
if (An(t, a) && (t = a, n)) {
|
|
649
649
|
const l = !J.length;
|
|
650
|
-
for (const
|
|
651
|
-
|
|
650
|
+
for (const u of o)
|
|
651
|
+
u[1](), J.push(u, t);
|
|
652
652
|
if (l) {
|
|
653
|
-
for (let
|
|
654
|
-
J[
|
|
653
|
+
for (let u = 0; u < J.length; u += 2)
|
|
654
|
+
J[u][0](J[u + 1]);
|
|
655
655
|
J.length = 0;
|
|
656
656
|
}
|
|
657
657
|
}
|
|
@@ -660,9 +660,9 @@ function jt(t, e = Rt) {
|
|
|
660
660
|
i(a(t));
|
|
661
661
|
}
|
|
662
662
|
function r(a, l = Rt) {
|
|
663
|
-
const
|
|
664
|
-
return o.add(
|
|
665
|
-
o.delete(
|
|
663
|
+
const u = [a, l];
|
|
664
|
+
return o.add(u), o.size === 1 && (n = e(i, s) || Rt), a(t), () => {
|
|
665
|
+
o.delete(u), o.size === 0 && n && (n(), n = null);
|
|
666
666
|
};
|
|
667
667
|
}
|
|
668
668
|
return { set: i, update: s, subscribe: r };
|
|
@@ -694,7 +694,7 @@ const mt = { selected: [] }, En = (t, e, n) => {
|
|
|
694
694
|
}, l = () => {
|
|
695
695
|
var b;
|
|
696
696
|
return ((b = r.selected) == null ? void 0 : b.length) === 0;
|
|
697
|
-
},
|
|
697
|
+
}, u = (b) => {
|
|
698
698
|
if (l())
|
|
699
699
|
return !1;
|
|
700
700
|
const A = typeof b == "string" ? b : b.id;
|
|
@@ -747,7 +747,7 @@ const mt = { selected: [] }, En = (t, e, n) => {
|
|
|
747
747
|
},
|
|
748
748
|
clear: a,
|
|
749
749
|
isEmpty: l,
|
|
750
|
-
isSelected:
|
|
750
|
+
isSelected: u,
|
|
751
751
|
setSelected: d,
|
|
752
752
|
setUserSelectAction: g,
|
|
753
753
|
subscribe: o,
|
|
@@ -822,8 +822,8 @@ const kn = (t, e) => {
|
|
|
822
822
|
if (t.options.ignore) {
|
|
823
823
|
const { ignore: r } = t.options, a = (l) => l && l.length > 0;
|
|
824
824
|
if (!(a(i.created) || a(i.deleted))) {
|
|
825
|
-
const l = (n = i.updated) == null ? void 0 : n.some((p) => a(p.bodiesCreated) || a(p.bodiesDeleted) || a(p.bodiesUpdated)),
|
|
826
|
-
if (r === "BODY_ONLY" && l && !
|
|
825
|
+
const l = (n = i.updated) == null ? void 0 : n.some((p) => a(p.bodiesCreated) || a(p.bodiesDeleted) || a(p.bodiesUpdated)), u = (o = i.updated) == null ? void 0 : o.some((p) => p.targetUpdated);
|
|
826
|
+
if (r === "BODY_ONLY" && l && !u || r === "TARGET_ONLY" && u && !l)
|
|
827
827
|
return !1;
|
|
828
828
|
}
|
|
829
829
|
}
|
|
@@ -840,7 +840,7 @@ const kn = (t, e) => {
|
|
|
840
840
|
const n = new Set((t.created || []).map((d) => d.id)), o = new Set((t.updated || []).map(({ newValue: d }) => d.id)), i = new Set((e.created || []).map((d) => d.id)), s = new Set((e.deleted || []).map((d) => d.id)), r = new Set((e.updated || []).map(({ oldValue: d }) => d.id)), a = new Set((e.updated || []).filter(({ oldValue: d }) => n.has(d.id) || o.has(d.id)).map(({ oldValue: d }) => d.id)), l = [
|
|
841
841
|
...(t.created || []).filter((d) => !s.has(d.id)).map((d) => r.has(d.id) ? e.updated.find(({ oldValue: h }) => h.id === d.id).newValue : d),
|
|
842
842
|
...e.created || []
|
|
843
|
-
],
|
|
843
|
+
], u = [
|
|
844
844
|
...(t.deleted || []).filter((d) => !i.has(d.id)),
|
|
845
845
|
...(e.deleted || []).filter((d) => !n.has(d.id))
|
|
846
846
|
], p = [
|
|
@@ -854,7 +854,7 @@ const kn = (t, e) => {
|
|
|
854
854
|
}),
|
|
855
855
|
...(e.updated || []).filter(({ oldValue: d }) => !a.has(d.id))
|
|
856
856
|
];
|
|
857
|
-
return { created: l, deleted:
|
|
857
|
+
return { created: l, deleted: u, updated: p };
|
|
858
858
|
}, kt = (t) => {
|
|
859
859
|
const e = t.id === void 0 ? we() : t.id;
|
|
860
860
|
return {
|
|
@@ -873,10 +873,10 @@ const kn = (t, e) => {
|
|
|
873
873
|
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (w, v = {}) => {
|
|
874
874
|
n.push({ onChange: w, options: v });
|
|
875
875
|
}, i = (w) => {
|
|
876
|
-
const v = n.findIndex((
|
|
876
|
+
const v = n.findIndex((f) => f.onChange == w);
|
|
877
877
|
v > -1 && n.splice(v, 1);
|
|
878
878
|
}, s = (w, v) => {
|
|
879
|
-
const
|
|
879
|
+
const f = {
|
|
880
880
|
origin: w,
|
|
881
881
|
changes: {
|
|
882
882
|
created: v.created || [],
|
|
@@ -886,40 +886,40 @@ const kn = (t, e) => {
|
|
|
886
886
|
state: [...t.values()]
|
|
887
887
|
};
|
|
888
888
|
n.forEach((E) => {
|
|
889
|
-
kn(E,
|
|
889
|
+
kn(E, f) && E.onChange(f);
|
|
890
890
|
});
|
|
891
891
|
}, r = (w, v = k.LOCAL) => {
|
|
892
892
|
if (w.id && t.get(w.id))
|
|
893
893
|
throw Error(`Cannot add annotation ${w.id} - exists already`);
|
|
894
894
|
{
|
|
895
|
-
const
|
|
896
|
-
t.set(
|
|
895
|
+
const f = kt(w);
|
|
896
|
+
t.set(f.id, f), f.bodies.forEach((E) => e.set(E.id, f.id)), s(v, { created: [f] });
|
|
897
897
|
}
|
|
898
898
|
}, a = (w, v) => {
|
|
899
|
-
const
|
|
899
|
+
const f = kt(typeof w == "string" ? v : w), E = typeof w == "string" ? w : w.id, B = E && t.get(E);
|
|
900
900
|
if (B) {
|
|
901
|
-
const R = Ae(B,
|
|
902
|
-
return E ===
|
|
901
|
+
const R = Ae(B, f);
|
|
902
|
+
return E === f.id ? t.set(E, f) : (t.delete(E), t.set(f.id, f)), B.bodies.forEach((U) => e.delete(U.id)), f.bodies.forEach((U) => e.set(U.id, f.id)), R;
|
|
903
903
|
} else
|
|
904
904
|
console.warn(`Cannot update annotation ${E} - does not exist`);
|
|
905
|
-
}, l = (w, v = k.LOCAL,
|
|
906
|
-
const E = Nn(v) ?
|
|
905
|
+
}, l = (w, v = k.LOCAL, f = k.LOCAL) => {
|
|
906
|
+
const E = Nn(v) ? f : v, B = a(w, v);
|
|
907
907
|
B && s(E, { updated: [B] });
|
|
908
|
-
},
|
|
909
|
-
const
|
|
908
|
+
}, u = (w, v = k.LOCAL) => {
|
|
909
|
+
const f = w.reduce((E, B) => {
|
|
910
910
|
const R = a(B);
|
|
911
911
|
return R ? [...E, R] : E;
|
|
912
912
|
}, []);
|
|
913
|
-
|
|
913
|
+
f.length > 0 && s(v, { updated: f });
|
|
914
914
|
}, p = (w, v = k.LOCAL) => {
|
|
915
|
-
const
|
|
916
|
-
if (
|
|
915
|
+
const f = t.get(w.annotation);
|
|
916
|
+
if (f) {
|
|
917
917
|
const E = {
|
|
918
|
-
...
|
|
919
|
-
bodies: [...
|
|
918
|
+
...f,
|
|
919
|
+
bodies: [...f.bodies, w]
|
|
920
920
|
};
|
|
921
|
-
t.set(
|
|
922
|
-
oldValue:
|
|
921
|
+
t.set(f.id, E), e.set(w.id, E.id), s(v, { updated: [{
|
|
922
|
+
oldValue: f,
|
|
923
923
|
newValue: E,
|
|
924
924
|
bodiesCreated: [w]
|
|
925
925
|
}] });
|
|
@@ -928,13 +928,13 @@ const kn = (t, e) => {
|
|
|
928
928
|
}, d = () => [...t.values()], h = (w = k.LOCAL) => {
|
|
929
929
|
const v = [...t.values()];
|
|
930
930
|
t.clear(), e.clear(), s(w, { deleted: v });
|
|
931
|
-
}, g = (w, v = !0,
|
|
931
|
+
}, g = (w, v = !0, f = k.LOCAL) => {
|
|
932
932
|
const E = w.map(kt);
|
|
933
933
|
if (v) {
|
|
934
934
|
const B = [...t.values()];
|
|
935
935
|
t.clear(), e.clear(), E.forEach((R) => {
|
|
936
936
|
t.set(R.id, R), R.bodies.forEach((U) => e.set(U.id, R.id));
|
|
937
|
-
}), s(
|
|
937
|
+
}), s(f, { created: E, deleted: B });
|
|
938
938
|
} else {
|
|
939
939
|
const B = w.reduce((R, U) => {
|
|
940
940
|
const _ = U.id && t.get(U.id);
|
|
@@ -944,28 +944,28 @@ const kn = (t, e) => {
|
|
|
944
944
|
throw Error(`Bulk insert would overwrite the following annotations: ${B.map((R) => R.id).join(", ")}`);
|
|
945
945
|
E.forEach((R) => {
|
|
946
946
|
t.set(R.id, R), R.bodies.forEach((U) => e.set(U.id, R.id));
|
|
947
|
-
}), s(
|
|
947
|
+
}), s(f, { created: E });
|
|
948
948
|
}
|
|
949
949
|
}, b = (w) => {
|
|
950
|
-
const v = typeof w == "string" ? w : w.id,
|
|
951
|
-
if (
|
|
952
|
-
return t.delete(v),
|
|
950
|
+
const v = typeof w == "string" ? w : w.id, f = t.get(v);
|
|
951
|
+
if (f)
|
|
952
|
+
return t.delete(v), f.bodies.forEach((E) => e.delete(E.id)), f;
|
|
953
953
|
console.warn(`Attempt to delete missing annotation: ${v}`);
|
|
954
954
|
}, A = (w, v = k.LOCAL) => {
|
|
955
|
-
const
|
|
956
|
-
|
|
955
|
+
const f = b(w);
|
|
956
|
+
f && s(v, { deleted: [f] });
|
|
957
957
|
}, C = (w, v = k.LOCAL) => {
|
|
958
|
-
const
|
|
958
|
+
const f = w.reduce((E, B) => {
|
|
959
959
|
const R = b(B);
|
|
960
960
|
return R ? [...E, R] : E;
|
|
961
961
|
}, []);
|
|
962
|
-
|
|
962
|
+
f.length > 0 && s(v, { deleted: f });
|
|
963
963
|
}, m = (w) => {
|
|
964
964
|
const v = t.get(w.annotation);
|
|
965
965
|
if (v) {
|
|
966
|
-
const
|
|
967
|
-
if (
|
|
968
|
-
e.delete(
|
|
966
|
+
const f = v.bodies.find((E) => E.id === w.id);
|
|
967
|
+
if (f) {
|
|
968
|
+
e.delete(f.id);
|
|
969
969
|
const E = {
|
|
970
970
|
...v,
|
|
971
971
|
bodies: v.bodies.filter((B) => B.id !== w.id)
|
|
@@ -973,65 +973,65 @@ const kn = (t, e) => {
|
|
|
973
973
|
return t.set(v.id, E), {
|
|
974
974
|
oldValue: v,
|
|
975
975
|
newValue: E,
|
|
976
|
-
bodiesDeleted: [
|
|
976
|
+
bodiesDeleted: [f]
|
|
977
977
|
};
|
|
978
978
|
} else
|
|
979
979
|
console.warn(`Attempt to delete missing body ${w.id} from annotation ${w.annotation}`);
|
|
980
980
|
} else
|
|
981
981
|
console.warn(`Attempt to delete body from missing annotation ${w.annotation}`);
|
|
982
982
|
}, c = (w, v = k.LOCAL) => {
|
|
983
|
-
const
|
|
984
|
-
|
|
983
|
+
const f = m(w);
|
|
984
|
+
f && s(v, { updated: [f] });
|
|
985
985
|
}, y = (w, v = k.LOCAL) => {
|
|
986
|
-
const
|
|
987
|
-
|
|
986
|
+
const f = w.map((E) => m(E)).filter(Boolean);
|
|
987
|
+
f.length > 0 && s(v, { updated: f });
|
|
988
988
|
}, S = (w) => {
|
|
989
989
|
const v = t.get(w);
|
|
990
990
|
return v ? { ...v } : void 0;
|
|
991
991
|
}, x = (w) => {
|
|
992
992
|
const v = e.get(w);
|
|
993
993
|
if (v) {
|
|
994
|
-
const
|
|
995
|
-
if (
|
|
996
|
-
return
|
|
994
|
+
const f = S(v).bodies.find((E) => E.id === w);
|
|
995
|
+
if (f)
|
|
996
|
+
return f;
|
|
997
997
|
console.error(`Store integrity error: body ${w} in index, but not in annotation`);
|
|
998
998
|
} else
|
|
999
999
|
console.warn(`Attempt to retrieve missing body: ${w}`);
|
|
1000
1000
|
}, L = (w, v) => {
|
|
1001
1001
|
if (w.annotation !== v.annotation)
|
|
1002
1002
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
1003
|
-
const
|
|
1004
|
-
if (
|
|
1005
|
-
const E =
|
|
1006
|
-
...
|
|
1007
|
-
bodies:
|
|
1003
|
+
const f = t.get(w.annotation);
|
|
1004
|
+
if (f) {
|
|
1005
|
+
const E = f.bodies.find((R) => R.id === w.id), B = {
|
|
1006
|
+
...f,
|
|
1007
|
+
bodies: f.bodies.map((R) => R.id === E.id ? v : R)
|
|
1008
1008
|
};
|
|
1009
|
-
return t.set(
|
|
1010
|
-
oldValue:
|
|
1009
|
+
return t.set(f.id, B), E.id !== v.id && (e.delete(E.id), e.set(v.id, B.id)), {
|
|
1010
|
+
oldValue: f,
|
|
1011
1011
|
newValue: B,
|
|
1012
1012
|
bodiesUpdated: [{ oldBody: E, newBody: v }]
|
|
1013
1013
|
};
|
|
1014
1014
|
} else
|
|
1015
1015
|
console.warn(`Attempt to add body to missing annotation ${w.annotation}`);
|
|
1016
|
-
}, O = (w, v,
|
|
1016
|
+
}, O = (w, v, f = k.LOCAL) => {
|
|
1017
1017
|
const E = L(w, v);
|
|
1018
|
-
E && s(
|
|
1018
|
+
E && s(f, { updated: [E] });
|
|
1019
1019
|
}, T = (w, v = k.LOCAL) => {
|
|
1020
|
-
const
|
|
1021
|
-
s(v, { updated:
|
|
1020
|
+
const f = w.map((E) => L({ id: E.id, annotation: E.annotation }, E)).filter(Boolean);
|
|
1021
|
+
s(v, { updated: f });
|
|
1022
1022
|
}, M = (w) => {
|
|
1023
1023
|
const v = t.get(w.annotation);
|
|
1024
1024
|
if (v) {
|
|
1025
|
-
const
|
|
1025
|
+
const f = {
|
|
1026
1026
|
...v,
|
|
1027
1027
|
target: {
|
|
1028
1028
|
...v.target,
|
|
1029
1029
|
...w
|
|
1030
1030
|
}
|
|
1031
1031
|
};
|
|
1032
|
-
return t.set(v.id,
|
|
1032
|
+
return t.set(v.id, f), {
|
|
1033
1033
|
oldValue: v,
|
|
1034
|
-
newValue:
|
|
1034
|
+
newValue: f,
|
|
1035
1035
|
targetUpdated: {
|
|
1036
1036
|
oldTarget: v.target,
|
|
1037
1037
|
newTarget: w
|
|
@@ -1047,11 +1047,11 @@ const kn = (t, e) => {
|
|
|
1047
1047
|
bulkAddAnnotation: g,
|
|
1048
1048
|
bulkDeleteAnnotation: C,
|
|
1049
1049
|
bulkDeleteBodies: y,
|
|
1050
|
-
bulkUpdateAnnotation:
|
|
1050
|
+
bulkUpdateAnnotation: u,
|
|
1051
1051
|
bulkUpdateBodies: T,
|
|
1052
1052
|
bulkUpdateTargets: (w, v = k.LOCAL) => {
|
|
1053
|
-
const
|
|
1054
|
-
|
|
1053
|
+
const f = w.map((E) => M(E)).filter(Boolean);
|
|
1054
|
+
f.length > 0 && s(v, { updated: f });
|
|
1055
1055
|
},
|
|
1056
1056
|
clear: h,
|
|
1057
1057
|
deleteAnnotation: A,
|
|
@@ -1063,8 +1063,8 @@ const kn = (t, e) => {
|
|
|
1063
1063
|
updateAnnotation: l,
|
|
1064
1064
|
updateBody: O,
|
|
1065
1065
|
updateTarget: (w, v = k.LOCAL) => {
|
|
1066
|
-
const
|
|
1067
|
-
|
|
1066
|
+
const f = M(w);
|
|
1067
|
+
f && s(v, { updated: [f] });
|
|
1068
1068
|
}
|
|
1069
1069
|
};
|
|
1070
1070
|
};
|
|
@@ -1099,7 +1099,7 @@ const Dn = 250, Vn = (t) => {
|
|
|
1099
1099
|
i = !1;
|
|
1100
1100
|
};
|
|
1101
1101
|
t.observe(r, { origin: k.LOCAL });
|
|
1102
|
-
const a = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g), l = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1),
|
|
1102
|
+
const a = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g), l = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), u = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ oldValue: b }) => b)), p = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ newValue: b }) => b)), d = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), h = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g);
|
|
1103
1103
|
return {
|
|
1104
1104
|
canRedo: () => n.length - 1 > o,
|
|
1105
1105
|
canUndo: () => o > -1,
|
|
@@ -1116,7 +1116,7 @@ const Dn = 250, Vn = (t) => {
|
|
|
1116
1116
|
if (o > -1) {
|
|
1117
1117
|
i = !0;
|
|
1118
1118
|
const { created: g, updated: b, deleted: A } = n[o];
|
|
1119
|
-
a(g),
|
|
1119
|
+
a(g), u(b), d(A), e.emit("undo", n[o]), o -= 1;
|
|
1120
1120
|
}
|
|
1121
1121
|
}
|
|
1122
1122
|
};
|
|
@@ -1128,7 +1128,7 @@ const Dn = 250, Vn = (t) => {
|
|
|
1128
1128
|
};
|
|
1129
1129
|
}, Kn = (t, e, n, o) => {
|
|
1130
1130
|
const { hover: i, selection: s, store: r, viewport: a } = t, l = /* @__PURE__ */ new Map();
|
|
1131
|
-
let
|
|
1131
|
+
let u = [], p;
|
|
1132
1132
|
const d = (A, C) => {
|
|
1133
1133
|
l.has(A) ? l.get(A).push(C) : l.set(A, [C]);
|
|
1134
1134
|
}, h = (A, C) => {
|
|
@@ -1149,27 +1149,27 @@ const Dn = 250, Vn = (t) => {
|
|
|
1149
1149
|
}, 1);
|
|
1150
1150
|
};
|
|
1151
1151
|
s.subscribe(({ selected: A }) => {
|
|
1152
|
-
if (!(
|
|
1153
|
-
if (
|
|
1154
|
-
|
|
1155
|
-
else if (
|
|
1156
|
-
|
|
1152
|
+
if (!(u.length === 0 && A.length === 0)) {
|
|
1153
|
+
if (u.length === 0 && A.length > 0)
|
|
1154
|
+
u = A.map(({ id: C }) => r.getAnnotation(C));
|
|
1155
|
+
else if (u.length > 0 && A.length === 0)
|
|
1156
|
+
u.forEach((C) => {
|
|
1157
1157
|
const m = r.getAnnotation(C.id);
|
|
1158
1158
|
m && !Q(m, C) && g("updateAnnotation", m, C);
|
|
1159
|
-
}),
|
|
1159
|
+
}), u = [];
|
|
1160
1160
|
else {
|
|
1161
|
-
const C = new Set(
|
|
1162
|
-
|
|
1161
|
+
const C = new Set(u.map((c) => c.id)), m = new Set(A.map(({ id: c }) => c));
|
|
1162
|
+
u.filter((c) => !m.has(c.id)).forEach((c) => {
|
|
1163
1163
|
const y = r.getAnnotation(c.id);
|
|
1164
1164
|
y && !Q(y, c) && g("updateAnnotation", y, c);
|
|
1165
|
-
}),
|
|
1165
|
+
}), u = [
|
|
1166
1166
|
// Remove annotations that were deselected
|
|
1167
|
-
...
|
|
1167
|
+
...u.filter((c) => m.has(c.id)),
|
|
1168
1168
|
// Add editable annotations that were selected
|
|
1169
1169
|
...A.filter(({ id: c }) => !C.has(c)).map(({ id: c }) => r.getAnnotation(c))
|
|
1170
1170
|
];
|
|
1171
1171
|
}
|
|
1172
|
-
g("selectionChanged",
|
|
1172
|
+
g("selectionChanged", u);
|
|
1173
1173
|
}
|
|
1174
1174
|
}), i.subscribe((A) => {
|
|
1175
1175
|
!p && A ? g("mouseEnterAnnotation", r.getAnnotation(A)) : p && !A ? g("mouseLeaveAnnotation", r.getAnnotation(p)) : p && A && (g("mouseLeaveAnnotation", r.getAnnotation(p)), g("mouseEnterAnnotation", r.getAnnotation(A))), p = A;
|
|
@@ -1180,13 +1180,13 @@ const Dn = 250, Vn = (t) => {
|
|
|
1180
1180
|
...c.bodiesDeleted || [],
|
|
1181
1181
|
...c.bodiesUpdated || []
|
|
1182
1182
|
].length > 0).forEach(({ oldValue: c, newValue: y }) => {
|
|
1183
|
-
const S =
|
|
1184
|
-
|
|
1183
|
+
const S = u.find((x) => x.id === c.id) || c;
|
|
1184
|
+
u = u.map((x) => x.id === c.id ? y : x), g("updateAnnotation", y, S);
|
|
1185
1185
|
});
|
|
1186
1186
|
}, { origin: k.LOCAL }), r.observe((A) => {
|
|
1187
|
-
if (
|
|
1188
|
-
const C = new Set(
|
|
1189
|
-
m.length > 0 && (
|
|
1187
|
+
if (u) {
|
|
1188
|
+
const C = new Set(u.map((c) => c.id)), m = (A.changes.updated || []).filter(({ newValue: c }) => C.has(c.id)).map(({ newValue: c }) => c);
|
|
1189
|
+
m.length > 0 && (u = u.map((c) => m.find((S) => S.id === c.id) || c));
|
|
1190
1190
|
}
|
|
1191
1191
|
}, { origin: k.REMOTE });
|
|
1192
1192
|
const b = (A) => (C) => {
|
|
@@ -1215,7 +1215,7 @@ const Dn = 250, Vn = (t) => {
|
|
|
1215
1215
|
}, r = () => i.clear(), a = () => o.clear(), l = (m) => {
|
|
1216
1216
|
const c = o.getAnnotation(m);
|
|
1217
1217
|
return n && c ? n.serialize(c) : c;
|
|
1218
|
-
},
|
|
1218
|
+
}, u = () => n ? o.all().map(n.serialize) : o.all(), p = () => {
|
|
1219
1219
|
var m;
|
|
1220
1220
|
const c = (((m = i.selected) == null ? void 0 : m.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
|
|
1221
1221
|
return n ? c.map(n.serialize) : c;
|
|
@@ -1255,7 +1255,7 @@ const Dn = 250, Vn = (t) => {
|
|
|
1255
1255
|
canUndo: e.canUndo,
|
|
1256
1256
|
clearAnnotations: a,
|
|
1257
1257
|
getAnnotationById: l,
|
|
1258
|
-
getAnnotations:
|
|
1258
|
+
getAnnotations: u,
|
|
1259
1259
|
getSelected: p,
|
|
1260
1260
|
loadAnnotations: d,
|
|
1261
1261
|
redo: e.redo,
|
|
@@ -1292,14 +1292,14 @@ const Wn = () => ({ isGuest: !0, id: zn("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
1292
1292
|
}
|
|
1293
1293
|
return `${n}`;
|
|
1294
1294
|
}, xe = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Gn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
|
|
1295
|
-
const { id: o, type: i, purpose: s, value: r, created: a, modified: l, creator:
|
|
1295
|
+
const { id: o, type: i, purpose: s, value: r, created: a, modified: l, creator: u, ...p } = n;
|
|
1296
1296
|
return {
|
|
1297
1297
|
id: o || `temp-${qn(n)}`,
|
|
1298
1298
|
annotation: e,
|
|
1299
1299
|
type: i,
|
|
1300
1300
|
purpose: s,
|
|
1301
1301
|
value: r,
|
|
1302
|
-
creator: xe(
|
|
1302
|
+
creator: xe(u),
|
|
1303
1303
|
created: a ? new Date(a) : void 0,
|
|
1304
1304
|
updated: l ? new Date(l) : void 0,
|
|
1305
1305
|
...p
|
|
@@ -1387,7 +1387,7 @@ const Io = (t, e) => ({
|
|
|
1387
1387
|
selector: r,
|
|
1388
1388
|
creator: a,
|
|
1389
1389
|
created: l,
|
|
1390
|
-
updated:
|
|
1390
|
+
updated: u,
|
|
1391
1391
|
...p
|
|
1392
1392
|
} = i, d = r.map((h) => {
|
|
1393
1393
|
const { id: g, quote: b, start: A, end: C, range: m } = h, { prefix: c, suffix: y } = Ue(m, n), S = [{
|
|
@@ -1417,14 +1417,14 @@ const Io = (t, e) => ({
|
|
|
1417
1417
|
body: Qn(t.bodies),
|
|
1418
1418
|
creator: a,
|
|
1419
1419
|
created: l == null ? void 0 : l.toISOString(),
|
|
1420
|
-
modified:
|
|
1420
|
+
modified: u == null ? void 0 : u.toISOString(),
|
|
1421
1421
|
target: d
|
|
1422
1422
|
};
|
|
1423
1423
|
};
|
|
1424
1424
|
function ve(t, e, n = 0, o = t.length - 1, i = no) {
|
|
1425
1425
|
for (; o > n; ) {
|
|
1426
1426
|
if (o - n > 600) {
|
|
1427
|
-
const l = o - n + 1,
|
|
1427
|
+
const l = o - n + 1, u = e - n + 1, p = Math.log(l), d = 0.5 * Math.exp(2 * p / 3), h = 0.5 * Math.sqrt(p * d * (l - d) / l) * (u - l / 2 < 0 ? -1 : 1), g = Math.max(n, Math.floor(e - u * d / l + h)), b = Math.min(o, Math.floor(e + (l - u) * d / l + h));
|
|
1428
1428
|
ve(t, e, g, b, i);
|
|
1429
1429
|
}
|
|
1430
1430
|
const s = t[e];
|
|
@@ -1511,14 +1511,14 @@ class oo {
|
|
|
1511
1511
|
if (!e) return this;
|
|
1512
1512
|
let o = this.data;
|
|
1513
1513
|
const i = this.toBBox(e), s = [], r = [];
|
|
1514
|
-
let a, l,
|
|
1514
|
+
let a, l, u;
|
|
1515
1515
|
for (; o || s.length; ) {
|
|
1516
|
-
if (o || (o = s.pop(), l = s[s.length - 1], a = r.pop(),
|
|
1516
|
+
if (o || (o = s.pop(), l = s[s.length - 1], a = r.pop(), u = !0), o.leaf) {
|
|
1517
1517
|
const p = io(e, o.children, n);
|
|
1518
1518
|
if (p !== -1)
|
|
1519
1519
|
return o.children.splice(p, 1), s.push(o), this._condense(s), this;
|
|
1520
1520
|
}
|
|
1521
|
-
!
|
|
1521
|
+
!u && !o.leaf && Nt(o, i) ? (s.push(o), r.push(a), a = 0, l = o, o = o.children[0]) : l ? (a++, o = l.children[a], u = !1) : o = null;
|
|
1522
1522
|
}
|
|
1523
1523
|
return this;
|
|
1524
1524
|
}
|
|
@@ -1549,10 +1549,10 @@ class oo {
|
|
|
1549
1549
|
if (s <= r)
|
|
1550
1550
|
return a = tt(e.slice(n, o + 1)), Z(a, this.toBBox), a;
|
|
1551
1551
|
i || (i = Math.ceil(Math.log(s) / Math.log(r)), r = Math.ceil(s / Math.pow(r, i - 1))), a = tt([]), a.leaf = !1, a.height = i;
|
|
1552
|
-
const l = Math.ceil(s / r),
|
|
1553
|
-
se(e, n, o,
|
|
1554
|
-
for (let p = n; p <= o; p +=
|
|
1555
|
-
const d = Math.min(p +
|
|
1552
|
+
const l = Math.ceil(s / r), u = l * Math.ceil(Math.sqrt(r));
|
|
1553
|
+
se(e, n, o, u, this.compareMinX);
|
|
1554
|
+
for (let p = n; p <= o; p += u) {
|
|
1555
|
+
const d = Math.min(p + u - 1, o);
|
|
1556
1556
|
se(e, p, d, l, this.compareMinY);
|
|
1557
1557
|
for (let h = p; h <= d; h += l) {
|
|
1558
1558
|
const g = Math.min(h + l - 1, d);
|
|
@@ -1565,8 +1565,8 @@ class oo {
|
|
|
1565
1565
|
for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
|
|
1566
1566
|
let s = 1 / 0, r = 1 / 0, a;
|
|
1567
1567
|
for (let l = 0; l < n.children.length; l++) {
|
|
1568
|
-
const
|
|
1569
|
-
d < r ? (r = d, s = p < s ? p : s, a =
|
|
1568
|
+
const u = n.children[l], p = It(u), d = ao(e, u) - p;
|
|
1569
|
+
d < r ? (r = d, s = p < s ? p : s, a = u) : d === r && p < s && (s = p, a = u);
|
|
1570
1570
|
}
|
|
1571
1571
|
n = a || n.children[0];
|
|
1572
1572
|
}
|
|
@@ -1591,7 +1591,7 @@ class oo {
|
|
|
1591
1591
|
_chooseSplitIndex(e, n, o) {
|
|
1592
1592
|
let i, s = 1 / 0, r = 1 / 0;
|
|
1593
1593
|
for (let a = n; a <= o - n; a++) {
|
|
1594
|
-
const l = rt(e, 0, a, this.toBBox),
|
|
1594
|
+
const l = rt(e, 0, a, this.toBBox), u = rt(e, a, o, this.toBBox), p = co(l, u), d = It(l) + It(u);
|
|
1595
1595
|
p < s ? (s = p, i = a, r = d < r ? d : r) : p === s && d < r && (r = d, i = a);
|
|
1596
1596
|
}
|
|
1597
1597
|
return i || o - n;
|
|
@@ -1606,12 +1606,12 @@ class oo {
|
|
|
1606
1606
|
e.children.sort(i);
|
|
1607
1607
|
const s = this.toBBox, r = rt(e, 0, n, s), a = rt(e, o - n, o, s);
|
|
1608
1608
|
let l = yt(r) + yt(a);
|
|
1609
|
-
for (let
|
|
1610
|
-
const p = e.children[
|
|
1609
|
+
for (let u = n; u < o - n; u++) {
|
|
1610
|
+
const p = e.children[u];
|
|
1611
1611
|
at(r, e.leaf ? s(p) : p), l += yt(r);
|
|
1612
1612
|
}
|
|
1613
|
-
for (let
|
|
1614
|
-
const p = e.children[
|
|
1613
|
+
for (let u = o - n - 1; u >= n; u--) {
|
|
1614
|
+
const p = e.children[u];
|
|
1615
1615
|
at(a, e.leaf ? s(p) : p), l += yt(a);
|
|
1616
1616
|
}
|
|
1617
1617
|
return l;
|
|
@@ -1727,11 +1727,11 @@ const uo = (t, e) => {
|
|
|
1727
1727
|
}, l = (y) => {
|
|
1728
1728
|
const S = s(y, e.getBoundingClientRect());
|
|
1729
1729
|
S.forEach((x) => n.insert(x)), o.set(y.annotation, S);
|
|
1730
|
-
},
|
|
1730
|
+
}, u = (y) => {
|
|
1731
1731
|
const S = o.get(y.annotation);
|
|
1732
1732
|
S && (S.forEach((x) => n.remove(x)), o.delete(y.annotation));
|
|
1733
1733
|
}, p = (y) => {
|
|
1734
|
-
|
|
1734
|
+
u(y), l(y);
|
|
1735
1735
|
}, d = (y, S = !0) => {
|
|
1736
1736
|
S && a();
|
|
1737
1737
|
const x = e.getBoundingClientRect(), L = y.map((T) => ({ target: T, rects: s(T, x) }));
|
|
@@ -1777,7 +1777,7 @@ const uo = (t, e) => {
|
|
|
1777
1777
|
recalculate: () => {
|
|
1778
1778
|
d(t.all().map((y) => y.target), !0), i.emit("recalculate");
|
|
1779
1779
|
},
|
|
1780
|
-
remove:
|
|
1780
|
+
remove: u,
|
|
1781
1781
|
set: d,
|
|
1782
1782
|
size: () => n.all().length,
|
|
1783
1783
|
update: p,
|
|
@@ -1792,7 +1792,7 @@ const uo = (t, e) => {
|
|
|
1792
1792
|
}, l = (c, y = !0, S = k.LOCAL) => {
|
|
1793
1793
|
const x = c.map((O) => Et(O, t)), L = x.filter((O) => !F(O.target.selector));
|
|
1794
1794
|
return n.bulkAddAnnotation(x, y, S), L;
|
|
1795
|
-
},
|
|
1795
|
+
}, u = (c, y = k.LOCAL) => {
|
|
1796
1796
|
const S = c.map((L) => Et(L, t)), x = S.filter((L) => !F(L.target.selector));
|
|
1797
1797
|
return S.forEach((L) => {
|
|
1798
1798
|
n.getAnnotation(L.id) ? n.updateAnnotation(L, y) : n.addAnnotation(L, y);
|
|
@@ -1828,7 +1828,7 @@ const uo = (t, e) => {
|
|
|
1828
1828
|
addAnnotation: a,
|
|
1829
1829
|
bulkAddAnnotation: l,
|
|
1830
1830
|
bulkUpdateTargets: d,
|
|
1831
|
-
bulkUpsertAnnotations:
|
|
1831
|
+
bulkUpsertAnnotations: u,
|
|
1832
1832
|
getAnnotationBounds: g,
|
|
1833
1833
|
getAnnotationRects: A,
|
|
1834
1834
|
getIntersecting: b,
|
|
@@ -2088,7 +2088,7 @@ const wt = (t) => {
|
|
|
2088
2088
|
splitKey: i = "+"
|
|
2089
2089
|
} = t;
|
|
2090
2090
|
Se(e).forEach((r) => {
|
|
2091
|
-
const a = r.split(i), l = a.length,
|
|
2091
|
+
const a = r.split(i), l = a.length, u = a[l - 1], p = u === "*" ? "*" : ft(u);
|
|
2092
2092
|
if (!N[p]) return;
|
|
2093
2093
|
n || (n = ut());
|
|
2094
2094
|
const d = l > 1 ? Ee(j, a) : [], h = [];
|
|
@@ -2134,8 +2134,8 @@ function ae(t, e) {
|
|
|
2134
2134
|
for (let a = 0; a < r; a++)
|
|
2135
2135
|
if ((t.type === "keydown" && s[a].keydown || t.type === "keyup" && s[a].keyup) && s[a].key) {
|
|
2136
2136
|
const l = s[a], {
|
|
2137
|
-
splitKey:
|
|
2138
|
-
} = l, p = l.key.split(
|
|
2137
|
+
splitKey: u
|
|
2138
|
+
} = l, p = l.key.split(u), d = [];
|
|
2139
2139
|
for (let h = 0; h < p.length; h++)
|
|
2140
2140
|
d.push(ft(p[h]));
|
|
2141
2141
|
d.sort().join("") === I.sort().join("") && re(t, l, i, e);
|
|
@@ -2144,11 +2144,11 @@ function ae(t, e) {
|
|
|
2144
2144
|
function P(t, e, n) {
|
|
2145
2145
|
I = [];
|
|
2146
2146
|
const o = Se(t);
|
|
2147
|
-
let i = [], s = "all", r = document, a = 0, l = !1,
|
|
2148
|
-
for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (r = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (
|
|
2147
|
+
let i = [], s = "all", r = document, a = 0, l = !1, u = !0, p = "+", d = !1, h = !1;
|
|
2148
|
+
for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (r = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (u = e.keydown), e.capture !== void 0 && (d = e.capture), typeof e.splitKey == "string" && (p = e.splitKey), e.single === !0 && (h = !0)), typeof e == "string" && (s = e), h && Te(t, s); a < o.length; a++)
|
|
2149
2149
|
t = o[a].split(p), i = [], t.length > 1 && (i = Ee(j, t)), t = t[t.length - 1], t = t === "*" ? "*" : ft(t), t in N || (N[t] = []), N[t].push({
|
|
2150
2150
|
keyup: l,
|
|
2151
|
-
keydown:
|
|
2151
|
+
keydown: u,
|
|
2152
2152
|
scope: s,
|
|
2153
2153
|
mods: i,
|
|
2154
2154
|
shortcut: o[a],
|
|
@@ -2255,20 +2255,20 @@ const ce = 300, Oe = ["up", "down", "left", "right"], Re = ke ? "⌘+a" : "ctrl+
|
|
|
2255
2255
|
], Oo = (t, e, n) => {
|
|
2256
2256
|
const { store: o, selection: i } = e;
|
|
2257
2257
|
let s;
|
|
2258
|
-
const { annotatingEnabled: r, offsetReferenceSelector: a, selectionMode: l } = n,
|
|
2258
|
+
const { annotatingEnabled: r, offsetReferenceSelector: a, selectionMode: l } = n, u = (f) => s = f;
|
|
2259
2259
|
let p;
|
|
2260
|
-
const d = (
|
|
2260
|
+
const d = (f) => p = f;
|
|
2261
2261
|
let h, g, b, A = r;
|
|
2262
|
-
const C = (
|
|
2263
|
-
A =
|
|
2264
|
-
}, m = (
|
|
2265
|
-
A && g !== !1 && (h = st(
|
|
2262
|
+
const C = (f) => {
|
|
2263
|
+
A = f, c.clear(), f || (h = void 0, g = void 0, b = void 0);
|
|
2264
|
+
}, m = (f) => {
|
|
2265
|
+
A && g !== !1 && (h = st(f.target) ? void 0 : {
|
|
2266
2266
|
annotation: be(),
|
|
2267
2267
|
selector: [],
|
|
2268
2268
|
creator: s,
|
|
2269
2269
|
created: /* @__PURE__ */ new Date()
|
|
2270
2270
|
});
|
|
2271
|
-
}, c = Pt((
|
|
2271
|
+
}, c = Pt((f) => {
|
|
2272
2272
|
if (!A) return;
|
|
2273
2273
|
const E = document.getSelection();
|
|
2274
2274
|
if (!(E != null && E.anchorNode))
|
|
@@ -2277,8 +2277,8 @@ const ce = 300, Oe = ["up", "down", "left", "right"], Re = ke ? "⌘+a" : "ctrl+
|
|
|
2277
2277
|
h = void 0;
|
|
2278
2278
|
return;
|
|
2279
2279
|
}
|
|
2280
|
-
const B =
|
|
2281
|
-
if ((b == null ? void 0 : b.type) === "pointerdown" && (B < 1e3 && !h || E.isCollapsed && B < ce) && m(b ||
|
|
2280
|
+
const B = f.timeStamp - ((b == null ? void 0 : b.timeStamp) || f.timeStamp);
|
|
2281
|
+
if ((b == null ? void 0 : b.type) === "pointerdown" && (B < 1e3 && !h || E.isCollapsed && B < ce) && m(b || f), !h) return;
|
|
2282
2282
|
if (E.isCollapsed) {
|
|
2283
2283
|
o.getAnnotation(h.annotation) && (i.clear(), o.deleteAnnotation(h.annotation));
|
|
2284
2284
|
return;
|
|
@@ -2294,19 +2294,19 @@ const ce = 300, Oe = ["up", "down", "left", "right"], Re = ke ? "⌘+a" : "ctrl+
|
|
|
2294
2294
|
selector: _.map((W) => Pe(W, t, a)),
|
|
2295
2295
|
updated: /* @__PURE__ */ new Date()
|
|
2296
2296
|
}, o.getAnnotation(h.annotation) ? o.updateTarget(h, k.LOCAL) : i.clear());
|
|
2297
|
-
}, 10), y = (
|
|
2298
|
-
st(
|
|
2299
|
-
}, S = async (
|
|
2300
|
-
if (st(
|
|
2297
|
+
}, 10), y = (f) => {
|
|
2298
|
+
st(f.target) || (b = St(f), g = b.button === 0);
|
|
2299
|
+
}, S = async (f) => {
|
|
2300
|
+
if (st(f.target) || !g) return;
|
|
2301
2301
|
const E = () => {
|
|
2302
|
-
const { x: R, y: U } = t.getBoundingClientRect(), _ =
|
|
2302
|
+
const { x: R, y: U } = t.getBoundingClientRect(), _ = f.target instanceof Node && t.contains(f.target) && o.getAt(f.clientX - R, f.clientY - U, l === "all", p);
|
|
2303
2303
|
if (_) {
|
|
2304
2304
|
const { selected: ht } = i, W = new Set(ht.map((nt) => nt.id)), G = Array.isArray(_) ? _.map((nt) => nt.id) : [_.id];
|
|
2305
|
-
(W.size !== G.length || !G.every((nt) => W.has(nt))) && i.userSelect(G,
|
|
2305
|
+
(W.size !== G.length || !G.every((nt) => W.has(nt))) && i.userSelect(G, f);
|
|
2306
2306
|
} else
|
|
2307
2307
|
i.clear();
|
|
2308
2308
|
};
|
|
2309
|
-
if (
|
|
2309
|
+
if (f.timeStamp - b.timeStamp < ce) {
|
|
2310
2310
|
await x();
|
|
2311
2311
|
const R = document.getSelection();
|
|
2312
2312
|
if (R != null && R.isCollapsed) {
|
|
@@ -2314,39 +2314,39 @@ const ce = 300, Oe = ["up", "down", "left", "right"], Re = ke ? "⌘+a" : "ctrl+
|
|
|
2314
2314
|
return;
|
|
2315
2315
|
}
|
|
2316
2316
|
}
|
|
2317
|
-
h && h.selector.length > 0 && (w(), i.userSelect(h.annotation, St(
|
|
2317
|
+
h && h.selector.length > 0 && (w(), i.userSelect(h.annotation, St(f)));
|
|
2318
2318
|
}, x = async () => {
|
|
2319
|
-
const
|
|
2320
|
-
let E = !1, B =
|
|
2319
|
+
const f = document.getSelection();
|
|
2320
|
+
let E = !1, B = f == null ? void 0 : f.isCollapsed;
|
|
2321
2321
|
const R = () => B || E, U = 1;
|
|
2322
|
-
return setTimeout(() => E = !0, 50), Lo(() => B =
|
|
2323
|
-
}, L = (
|
|
2322
|
+
return setTimeout(() => E = !0, 50), Lo(() => B = f == null ? void 0 : f.isCollapsed, U, R);
|
|
2323
|
+
}, L = (f) => {
|
|
2324
2324
|
const E = document.getSelection();
|
|
2325
|
-
E != null && E.isCollapsed || ((!h || h.selector.length === 0) && c(
|
|
2326
|
-
}, O = (
|
|
2327
|
-
A &&
|
|
2328
|
-
}, T = (
|
|
2325
|
+
E != null && E.isCollapsed || ((!h || h.selector.length === 0) && c(f), w(), i.userSelect(h.annotation, St(f)));
|
|
2326
|
+
}, O = (f) => {
|
|
2327
|
+
A && f.key === "Shift" && h && (document.getSelection().isCollapsed || (w(), i.userSelect(h.annotation, pt(f))));
|
|
2328
|
+
}, T = (f) => {
|
|
2329
2329
|
const E = () => setTimeout(() => {
|
|
2330
2330
|
(h == null ? void 0 : h.selector.length) > 0 && (i.clear(), o.addAnnotation({
|
|
2331
2331
|
id: h.annotation,
|
|
2332
2332
|
bodies: [],
|
|
2333
2333
|
target: h
|
|
2334
|
-
}), i.userSelect(h.annotation, pt(
|
|
2334
|
+
}), i.userSelect(h.annotation, pt(f))), document.removeEventListener("selectionchange", E);
|
|
2335
2335
|
}, 100);
|
|
2336
|
-
document.addEventListener("selectionchange", E), m(
|
|
2336
|
+
document.addEventListener("selectionchange", E), m(f);
|
|
2337
2337
|
};
|
|
2338
|
-
P(To.join(","), { element: t, keydown: !0, keyup: !1 }, (
|
|
2339
|
-
|
|
2340
|
-
}), P(Re, { keydown: !0, keyup: !1 }, (
|
|
2341
|
-
b = pt(
|
|
2338
|
+
P(To.join(","), { element: t, keydown: !0, keyup: !1 }, (f) => {
|
|
2339
|
+
f.repeat || (b = pt(f));
|
|
2340
|
+
}), P(Re, { keydown: !0, keyup: !1 }, (f) => {
|
|
2341
|
+
b = pt(f), T(f);
|
|
2342
2342
|
});
|
|
2343
|
-
const M = (
|
|
2344
|
-
|
|
2343
|
+
const M = (f) => {
|
|
2344
|
+
f.repeat || f.target !== t && f.target !== document.body || (h = void 0, i.clear());
|
|
2345
2345
|
};
|
|
2346
2346
|
P(Oe.join(","), { keydown: !0, keyup: !1 }, M);
|
|
2347
2347
|
const w = () => {
|
|
2348
|
-
const
|
|
2349
|
-
if (!
|
|
2348
|
+
const f = o.getAnnotation(h.annotation);
|
|
2349
|
+
if (!f) {
|
|
2350
2350
|
o.addAnnotation({
|
|
2351
2351
|
id: h.annotation,
|
|
2352
2352
|
bodies: [],
|
|
@@ -2354,7 +2354,7 @@ const ce = 300, Oe = ["up", "down", "left", "right"], Re = ke ? "⌘+a" : "ctrl+
|
|
|
2354
2354
|
});
|
|
2355
2355
|
return;
|
|
2356
2356
|
}
|
|
2357
|
-
const { target: { updated: E } } =
|
|
2357
|
+
const { target: { updated: E } } = f, { updated: B } = h;
|
|
2358
2358
|
(!E || !B || E < B) && o.updateTarget(h);
|
|
2359
2359
|
};
|
|
2360
2360
|
return document.addEventListener("pointerdown", y), document.addEventListener("pointerup", S), document.addEventListener("contextmenu", L), t.addEventListener("keyup", O), t.addEventListener("selectstart", m), document.addEventListener("selectionchange", c), {
|
|
@@ -2362,7 +2362,7 @@ const ce = 300, Oe = ["up", "down", "left", "right"], Re = ke ? "⌘+a" : "ctrl+
|
|
|
2362
2362
|
h = void 0, g = void 0, b = void 0, c.clear(), document.removeEventListener("pointerdown", y), document.removeEventListener("pointerup", S), document.removeEventListener("contextmenu", L), t.removeEventListener("keyup", O), t.removeEventListener("selectstart", m), document.removeEventListener("selectionchange", c), P.unbind();
|
|
2363
2363
|
},
|
|
2364
2364
|
setFilter: d,
|
|
2365
|
-
setUser:
|
|
2365
|
+
setUser: u,
|
|
2366
2366
|
setAnnotatingEnabled: C
|
|
2367
2367
|
};
|
|
2368
2368
|
}, Ro = (t, e) => ({
|
|
@@ -2375,21 +2375,21 @@ const ce = 300, Oe = ["up", "down", "left", "right"], Re = ke ? "⌘+a" : "ctrl+
|
|
|
2375
2375
|
annotatingEnabled: !0,
|
|
2376
2376
|
user: Wn()
|
|
2377
2377
|
}), o = fo(t, n.userSelectAction), { selection: i, viewport: s } = o, r = o.store, a = Vn(r), l = Kn(o, a, n.adapter);
|
|
2378
|
-
let
|
|
2378
|
+
let u = n.user;
|
|
2379
2379
|
const p = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : le : n.renderer || le, d = p === "SPANS" ? gn(t, o, s) : p === "CSS_HIGHLIGHTS" ? fn(t, o, s) : p === "CANVAS" ? en(t, o, s) : void 0;
|
|
2380
2380
|
if (!d)
|
|
2381
2381
|
throw `Unknown renderer implementation: ${p}`;
|
|
2382
2382
|
console.debug(`Using ${p} renderer`), n.style && d.setStyle(n.style);
|
|
2383
2383
|
const h = Oo(t, o, n);
|
|
2384
|
-
h.setUser(
|
|
2385
|
-
const g = Pn(o, a, n.adapter), b = () =>
|
|
2384
|
+
h.setUser(u), h.setAnnotatingEnabled(n.annotatingEnabled);
|
|
2385
|
+
const g = Pn(o, a, n.adapter), b = () => u, A = (x) => {
|
|
2386
2386
|
h.setAnnotatingEnabled(
|
|
2387
2387
|
x === void 0 ? !0 : x
|
|
2388
2388
|
);
|
|
2389
2389
|
}, C = (x) => {
|
|
2390
2390
|
d.setFilter(x), h.setFilter(x);
|
|
2391
2391
|
}, m = (x) => {
|
|
2392
|
-
|
|
2392
|
+
u = x, h.setUser(x);
|
|
2393
2393
|
}, c = (x) => {
|
|
2394
2394
|
x && (d.setPainter(po(x, n.presence)), x.on("selectionChange", () => d.redraw()));
|
|
2395
2395
|
}, y = (x) => {
|