@soomo/text-annotator 3.1.0-staging.14 → 3.1.0-staging.15
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.
|
@@ -213,7 +213,7 @@ const ae = "not-annotatable", Z = `.${ae}`, nt = (t) => {
|
|
|
213
213
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : de(t.parentElement);
|
|
214
214
|
}, He = (t, e) => (n) => {
|
|
215
215
|
const o = typeof n == "string" ? n : n.id, i = (r) => {
|
|
216
|
-
const a = s.getBoundingClientRect(), l = s.clientHeight, c = s.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: d, height: m } = e.getAnnotationBounds(o), p = f.top - a.top,
|
|
216
|
+
const a = s.getBoundingClientRect(), l = s.clientHeight, c = s.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: d, height: m } = e.getAnnotationBounds(o), p = f.top - a.top, v = f.left - a.left, b = s.parentElement ? s.scrollTop : 0, C = s.parentElement ? s.scrollLeft : 0, g = p + b - (l - m) / 2, u = v + C - (c - d) / 2;
|
|
217
217
|
s.scroll({ top: g, left: u, behavior: "smooth" });
|
|
218
218
|
}, s = de(t);
|
|
219
219
|
if (s) {
|
|
@@ -288,20 +288,20 @@ const Kt = /* @__PURE__ */ Fe(We), qe = (t) => {
|
|
|
288
288
|
const { store: i, selection: s, hover: r } = e;
|
|
289
289
|
let a, l, c;
|
|
290
290
|
const f = Ge(n), d = (T) => {
|
|
291
|
-
const { x, y: h } = t.getBoundingClientRect(),
|
|
292
|
-
|
|
291
|
+
const { x: A, y: h } = t.getBoundingClientRect(), w = i.getAt(T.clientX - A, T.clientY - h, l);
|
|
292
|
+
w ? r.current !== w.id && (t.classList.add("hovered"), r.set(w.id)) : r.current && (t.classList.remove("hovered"), r.set(null));
|
|
293
293
|
};
|
|
294
294
|
t.addEventListener("pointermove", d);
|
|
295
295
|
const m = (T = !1) => {
|
|
296
296
|
c && c.clear();
|
|
297
|
-
const
|
|
297
|
+
const A = qe(t), { minX: h, minY: w, maxX: x, maxY: L } = A, M = l ? i.getIntersecting(h, w, x, L).filter(({ annotation: Y }) => l(Y)) : i.getIntersecting(h, w, x, L), B = s.selected.map(({ id: Y }) => Y), K = M.map(({ annotation: Y, rects: dt }) => {
|
|
298
298
|
const Oe = B.includes(Y.id), Te = Y.id === r.current;
|
|
299
299
|
return { annotation: Y, rects: dt, state: { selected: Oe, hover: Te } };
|
|
300
300
|
});
|
|
301
|
-
o.redraw(K,
|
|
301
|
+
o.redraw(K, A, a, c, T), setTimeout(() => f(M.map(({ annotation: Y }) => Y)), 1);
|
|
302
302
|
}, p = (T) => {
|
|
303
303
|
c = T, m();
|
|
304
|
-
},
|
|
304
|
+
}, v = (T) => {
|
|
305
305
|
a = T, m();
|
|
306
306
|
}, b = (T) => {
|
|
307
307
|
l = T, m(!1);
|
|
@@ -323,7 +323,7 @@ const Kt = /* @__PURE__ */ Fe(We), qe = (t) => {
|
|
|
323
323
|
t.removeEventListener("pointermove", d), o.destroy(), i.unobserve(C), g(), document.removeEventListener("scroll", u), y.clear(), window.removeEventListener("resize", y), S.disconnect(), O.disconnect();
|
|
324
324
|
},
|
|
325
325
|
redraw: m,
|
|
326
|
-
setStyle:
|
|
326
|
+
setStyle: v,
|
|
327
327
|
setFilter: b,
|
|
328
328
|
setPainter: p,
|
|
329
329
|
setVisible: o.setVisible
|
|
@@ -340,14 +340,14 @@ const Kt = /* @__PURE__ */ Fe(We), qe = (t) => {
|
|
|
340
340
|
const o = (a, l, c, f) => requestAnimationFrame(() => {
|
|
341
341
|
const { width: d, height: m } = e;
|
|
342
342
|
n.clearRect(-0.5, -0.5, d + 1, m + 1), f && f.clear();
|
|
343
|
-
const { top: p, left:
|
|
343
|
+
const { top: p, left: v } = l;
|
|
344
344
|
[...a].sort((C, g) => {
|
|
345
345
|
const { annotation: { target: { created: u } } } = C, { annotation: { target: { created: y } } } = g;
|
|
346
346
|
return u.getTime() - y.getTime();
|
|
347
347
|
}).forEach((C) => {
|
|
348
348
|
var S;
|
|
349
349
|
const g = c ? typeof c == "function" ? c(C.annotation, C.state) : c : (S = C.state) != null && S.selected ? wt : W, u = f && f.paint(C, l) || g, y = C.rects.map(({ x: E, y: O, width: R, height: T }) => ({
|
|
350
|
-
x: E +
|
|
350
|
+
x: E + v,
|
|
351
351
|
y: O + p,
|
|
352
352
|
width: R,
|
|
353
353
|
height: T
|
|
@@ -357,8 +357,8 @@ const Kt = /* @__PURE__ */ Fe(We), qe = (t) => {
|
|
|
357
357
|
), u.underlineColor) {
|
|
358
358
|
n.globalAlpha = 1, n.strokeStyle = u.underlineColor, n.lineWidth = u.underlineThickness ?? 1;
|
|
359
359
|
const E = u.underlineOffset ?? 0;
|
|
360
|
-
y.forEach(({ x: O, y: R, width: T, height:
|
|
361
|
-
n.beginPath(), n.moveTo(O, R +
|
|
360
|
+
y.forEach(({ x: O, y: R, width: T, height: A }) => {
|
|
361
|
+
n.beginPath(), n.moveTo(O, R + A + E), n.lineTo(O + T, R + A + E), n.stroke();
|
|
362
362
|
});
|
|
363
363
|
}
|
|
364
364
|
});
|
|
@@ -525,13 +525,13 @@ const ln = (t) => [
|
|
|
525
525
|
const c = new Set(s.map((d) => d.annotation.id));
|
|
526
526
|
Array.from(e).filter((d) => !c.has(d));
|
|
527
527
|
const f = s.map((d) => {
|
|
528
|
-
var
|
|
529
|
-
const m = a ? typeof a == "function" ? a(d.annotation, d.state) : a : (
|
|
528
|
+
var v;
|
|
529
|
+
const m = a ? typeof a == "function" ? a(d.annotation, d.state) : a : (v = d.state) != null && v.selected ? wt : W, p = l && l.paint(d, r) || m;
|
|
530
530
|
return `::highlight(_${d.annotation.id}) { ${ln(p)} }`;
|
|
531
531
|
});
|
|
532
532
|
t.innerHTML = f.join(`
|
|
533
533
|
`), CSS.highlights.clear(), s.forEach(({ annotation: d }) => {
|
|
534
|
-
const m = d.target.selector.map((
|
|
534
|
+
const m = d.target.selector.map((v) => v.range), p = new Highlight(...m);
|
|
535
535
|
CSS.highlights.set(`_${d.id}`, p);
|
|
536
536
|
}), e = c;
|
|
537
537
|
}
|
|
@@ -573,15 +573,15 @@ const fn = (t, e) => {
|
|
|
573
573
|
redraw: (r, a, l, c, f) => {
|
|
574
574
|
const m = !(Ut(n, r) && f);
|
|
575
575
|
if (!c && !m) return;
|
|
576
|
-
m && (e.innerHTML = ""), [...r].sort((
|
|
577
|
-
const { annotation: { target: { created: C } } } =
|
|
576
|
+
m && (e.innerHTML = ""), [...r].sort((v, b) => {
|
|
577
|
+
const { annotation: { target: { created: C } } } = v, { annotation: { target: { created: g } } } = b;
|
|
578
578
|
return C && g ? C.getTime() - g.getTime() : 0;
|
|
579
|
-
}).forEach((
|
|
580
|
-
|
|
581
|
-
const C = fn(b, r), g = ze(
|
|
579
|
+
}).forEach((v) => {
|
|
580
|
+
v.rects.map((b) => {
|
|
581
|
+
const C = fn(b, r), g = ze(v, a, l, c, C);
|
|
582
582
|
if (m) {
|
|
583
583
|
const u = document.createElement("span");
|
|
584
|
-
u.className = "r6o-annotation", u.dataset.annotation =
|
|
584
|
+
u.className = "r6o-annotation", u.dataset.annotation = v.annotation.id, u.style.left = `${b.x}px`, u.style.top = `${b.y}px`, u.style.width = `${b.width}px`, u.style.height = `${b.height}px`, u.style.backgroundColor = $((g == null ? void 0 : g.fill) || W.fill).alpha((g == null ? void 0 : g.fillOpacity) === void 0 ? W.fillOpacity : g.fillOpacity).toHex(), g.underlineStyle && (u.style.borderStyle = g.underlineStyle), g.underlineColor && (u.style.borderColor = g.underlineColor), g.underlineThickness && (u.style.borderBottomWidth = `${g.underlineThickness}px`), g.underlineOffset && (u.style.paddingBottom = `${g.underlineOffset}px`), e.appendChild(u);
|
|
585
585
|
}
|
|
586
586
|
});
|
|
587
587
|
}), n = r;
|
|
@@ -688,49 +688,49 @@ var An = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE =
|
|
|
688
688
|
const ht = { selected: [] }, xn = (t, e, n) => {
|
|
689
689
|
const { subscribe: o, set: i } = Xt(ht);
|
|
690
690
|
let s = e, r = ht;
|
|
691
|
-
o((
|
|
691
|
+
o((v) => r = v);
|
|
692
692
|
const a = () => {
|
|
693
693
|
q(r, ht) || i(ht);
|
|
694
694
|
}, l = () => {
|
|
695
|
-
var
|
|
696
|
-
return ((
|
|
697
|
-
}, c = (
|
|
695
|
+
var v;
|
|
696
|
+
return ((v = r.selected) == null ? void 0 : v.length) === 0;
|
|
697
|
+
}, c = (v) => {
|
|
698
698
|
if (l())
|
|
699
699
|
return !1;
|
|
700
|
-
const b = typeof
|
|
700
|
+
const b = typeof v == "string" ? v : v.id;
|
|
701
701
|
return r.selected.some((C) => C.id === b);
|
|
702
|
-
}, f = (
|
|
703
|
-
const C = t.getAnnotation(
|
|
702
|
+
}, f = (v, b) => {
|
|
703
|
+
const C = t.getAnnotation(v);
|
|
704
704
|
if (!C) {
|
|
705
|
-
console.warn("Invalid selection: " +
|
|
705
|
+
console.warn("Invalid selection: " + v);
|
|
706
706
|
return;
|
|
707
707
|
}
|
|
708
708
|
switch (te(C, s)) {
|
|
709
709
|
case "EDIT":
|
|
710
|
-
i({ selected: [{ id:
|
|
710
|
+
i({ selected: [{ id: v, editable: !0 }], event: b });
|
|
711
711
|
break;
|
|
712
712
|
case "SELECT":
|
|
713
|
-
i({ selected: [{ id:
|
|
713
|
+
i({ selected: [{ id: v }], event: b });
|
|
714
714
|
break;
|
|
715
715
|
default:
|
|
716
716
|
i({ selected: [], event: b });
|
|
717
717
|
}
|
|
718
|
-
}, d = (
|
|
719
|
-
const C = Array.isArray(
|
|
718
|
+
}, d = (v, b) => {
|
|
719
|
+
const C = Array.isArray(v) ? v : [v], g = C.map((u) => t.getAnnotation(u)).filter((u) => !!u);
|
|
720
720
|
i({
|
|
721
721
|
selected: g.map((u) => {
|
|
722
722
|
const y = b === void 0 ? te(u, s) === "EDIT" : b;
|
|
723
723
|
return { id: u.id, editable: y };
|
|
724
724
|
})
|
|
725
|
-
}), g.length !== C.length && console.warn("Invalid selection",
|
|
726
|
-
}, m = (
|
|
725
|
+
}), g.length !== C.length && console.warn("Invalid selection", v);
|
|
726
|
+
}, m = (v) => {
|
|
727
727
|
if (l())
|
|
728
728
|
return !1;
|
|
729
729
|
const { selected: b } = r;
|
|
730
|
-
b.some(({ id: C }) =>
|
|
731
|
-
}, p = (
|
|
730
|
+
b.some(({ id: C }) => v.includes(C)) && i({ selected: b.filter(({ id: C }) => !v.includes(C)) });
|
|
731
|
+
}, p = (v) => s = v;
|
|
732
732
|
return t.observe(
|
|
733
|
-
({ changes:
|
|
733
|
+
({ changes: v }) => m((v.deleted || []).map((b) => b.id))
|
|
734
734
|
), {
|
|
735
735
|
get event() {
|
|
736
736
|
return r ? r.event : null;
|
|
@@ -843,8 +843,8 @@ const Bn = (t, e) => {
|
|
|
843
843
|
...(t.updated || []).filter(({ newValue: d }) => !s.has(d.id)).map((d) => {
|
|
844
844
|
const { oldValue: m, newValue: p } = d;
|
|
845
845
|
if (r.has(p.id)) {
|
|
846
|
-
const
|
|
847
|
-
return ye(m,
|
|
846
|
+
const v = e.updated.find((b) => b.oldValue.id === p.id).newValue;
|
|
847
|
+
return ye(m, v);
|
|
848
848
|
} else
|
|
849
849
|
return d;
|
|
850
850
|
}),
|
|
@@ -866,71 +866,71 @@ const Bn = (t, e) => {
|
|
|
866
866
|
}
|
|
867
867
|
};
|
|
868
868
|
}, In = (t) => t.id !== void 0, Nn = () => {
|
|
869
|
-
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (h,
|
|
870
|
-
n.push({ onChange: h, options:
|
|
869
|
+
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (h, w = {}) => {
|
|
870
|
+
n.push({ onChange: h, options: w });
|
|
871
871
|
}, i = (h) => {
|
|
872
|
-
const
|
|
873
|
-
|
|
874
|
-
}, s = (h,
|
|
875
|
-
const
|
|
872
|
+
const w = n.findIndex((x) => x.onChange == h);
|
|
873
|
+
w > -1 && n.splice(w, 1);
|
|
874
|
+
}, s = (h, w) => {
|
|
875
|
+
const x = {
|
|
876
876
|
origin: h,
|
|
877
877
|
changes: {
|
|
878
|
-
created:
|
|
879
|
-
updated:
|
|
880
|
-
deleted:
|
|
878
|
+
created: w.created || [],
|
|
879
|
+
updated: w.updated || [],
|
|
880
|
+
deleted: w.deleted || []
|
|
881
881
|
},
|
|
882
882
|
state: [...t.values()]
|
|
883
883
|
};
|
|
884
884
|
n.forEach((L) => {
|
|
885
|
-
Bn(L,
|
|
885
|
+
Bn(L, x) && L.onChange(x);
|
|
886
886
|
});
|
|
887
|
-
}, r = (h,
|
|
887
|
+
}, r = (h, w = k.LOCAL) => {
|
|
888
888
|
if (h.id && t.get(h.id))
|
|
889
889
|
throw Error(`Cannot add annotation ${h.id} - exists already`);
|
|
890
890
|
{
|
|
891
|
-
const
|
|
892
|
-
t.set(
|
|
891
|
+
const x = Rt(h);
|
|
892
|
+
t.set(x.id, x), x.bodies.forEach((L) => e.set(L.id, x.id)), s(w, { created: [x] });
|
|
893
893
|
}
|
|
894
|
-
}, a = (h,
|
|
895
|
-
const
|
|
894
|
+
}, a = (h, w) => {
|
|
895
|
+
const x = Rt(typeof h == "string" ? w : h), L = typeof h == "string" ? h : h.id, M = L && t.get(L);
|
|
896
896
|
if (M) {
|
|
897
|
-
const B = ye(M,
|
|
898
|
-
return L ===
|
|
897
|
+
const B = ye(M, x);
|
|
898
|
+
return L === x.id ? t.set(L, x) : (t.delete(L), t.set(x.id, x)), M.bodies.forEach((K) => e.delete(K.id)), x.bodies.forEach((K) => e.set(K.id, x.id)), B;
|
|
899
899
|
} else
|
|
900
900
|
console.warn(`Cannot update annotation ${L} - does not exist`);
|
|
901
|
-
}, l = (h,
|
|
902
|
-
const L = In(
|
|
901
|
+
}, l = (h, w = k.LOCAL, x = k.LOCAL) => {
|
|
902
|
+
const L = In(w) ? x : w, M = a(h, w);
|
|
903
903
|
M && s(L, { updated: [M] });
|
|
904
|
-
}, c = (h,
|
|
905
|
-
const
|
|
904
|
+
}, c = (h, w = k.LOCAL) => {
|
|
905
|
+
const x = h.reduce((L, M) => {
|
|
906
906
|
const B = a(M);
|
|
907
907
|
return B ? [...L, B] : L;
|
|
908
908
|
}, []);
|
|
909
|
-
|
|
910
|
-
}, f = (h,
|
|
911
|
-
const
|
|
912
|
-
if (
|
|
909
|
+
x.length > 0 && s(w, { updated: x });
|
|
910
|
+
}, f = (h, w = k.LOCAL) => {
|
|
911
|
+
const x = t.get(h.annotation);
|
|
912
|
+
if (x) {
|
|
913
913
|
const L = {
|
|
914
|
-
...
|
|
915
|
-
bodies: [...
|
|
914
|
+
...x,
|
|
915
|
+
bodies: [...x.bodies, h]
|
|
916
916
|
};
|
|
917
|
-
t.set(
|
|
918
|
-
oldValue:
|
|
917
|
+
t.set(x.id, L), e.set(h.id, L.id), s(w, { updated: [{
|
|
918
|
+
oldValue: x,
|
|
919
919
|
newValue: L,
|
|
920
920
|
bodiesCreated: [h]
|
|
921
921
|
}] });
|
|
922
922
|
} else
|
|
923
923
|
console.warn(`Attempt to add body to missing annotation: ${h.annotation}`);
|
|
924
924
|
}, d = () => [...t.values()], m = (h = k.LOCAL) => {
|
|
925
|
-
const
|
|
926
|
-
t.clear(), e.clear(), s(h, { deleted:
|
|
927
|
-
}, p = (h,
|
|
925
|
+
const w = [...t.values()];
|
|
926
|
+
t.clear(), e.clear(), s(h, { deleted: w });
|
|
927
|
+
}, p = (h, w = !0, x = k.LOCAL) => {
|
|
928
928
|
const L = h.map(Rt);
|
|
929
|
-
if (
|
|
929
|
+
if (w) {
|
|
930
930
|
const M = [...t.values()];
|
|
931
931
|
t.clear(), e.clear(), L.forEach((B) => {
|
|
932
932
|
t.set(B.id, B), B.bodies.forEach((K) => e.set(K.id, B.id));
|
|
933
|
-
}), s(
|
|
933
|
+
}), s(x, { created: L, deleted: M });
|
|
934
934
|
} else {
|
|
935
935
|
const M = h.reduce((B, K) => {
|
|
936
936
|
const Y = K.id && t.get(K.id);
|
|
@@ -940,96 +940,96 @@ const Bn = (t, e) => {
|
|
|
940
940
|
throw Error(`Bulk insert would overwrite the following annotations: ${M.map((B) => B.id).join(", ")}`);
|
|
941
941
|
L.forEach((B) => {
|
|
942
942
|
t.set(B.id, B), B.bodies.forEach((K) => e.set(K.id, B.id));
|
|
943
|
-
}), s(
|
|
943
|
+
}), s(x, { created: L });
|
|
944
944
|
}
|
|
945
|
-
},
|
|
946
|
-
const
|
|
947
|
-
if (
|
|
948
|
-
return t.delete(
|
|
949
|
-
console.warn(`Attempt to delete missing annotation: ${
|
|
950
|
-
}, b = (h,
|
|
951
|
-
const
|
|
952
|
-
|
|
953
|
-
}, C = (h,
|
|
954
|
-
const
|
|
955
|
-
const B =
|
|
945
|
+
}, v = (h) => {
|
|
946
|
+
const w = typeof h == "string" ? h : h.id, x = t.get(w);
|
|
947
|
+
if (x)
|
|
948
|
+
return t.delete(w), x.bodies.forEach((L) => e.delete(L.id)), x;
|
|
949
|
+
console.warn(`Attempt to delete missing annotation: ${w}`);
|
|
950
|
+
}, b = (h, w = k.LOCAL) => {
|
|
951
|
+
const x = v(h);
|
|
952
|
+
x && s(w, { deleted: [x] });
|
|
953
|
+
}, C = (h, w = k.LOCAL) => {
|
|
954
|
+
const x = h.reduce((L, M) => {
|
|
955
|
+
const B = v(M);
|
|
956
956
|
return B ? [...L, B] : L;
|
|
957
957
|
}, []);
|
|
958
|
-
|
|
958
|
+
x.length > 0 && s(w, { deleted: x });
|
|
959
959
|
}, g = (h) => {
|
|
960
|
-
const
|
|
961
|
-
if (
|
|
962
|
-
const
|
|
963
|
-
if (
|
|
964
|
-
e.delete(
|
|
960
|
+
const w = t.get(h.annotation);
|
|
961
|
+
if (w) {
|
|
962
|
+
const x = w.bodies.find((L) => L.id === h.id);
|
|
963
|
+
if (x) {
|
|
964
|
+
e.delete(x.id);
|
|
965
965
|
const L = {
|
|
966
|
-
...
|
|
967
|
-
bodies:
|
|
966
|
+
...w,
|
|
967
|
+
bodies: w.bodies.filter((M) => M.id !== h.id)
|
|
968
968
|
};
|
|
969
|
-
return t.set(
|
|
970
|
-
oldValue:
|
|
969
|
+
return t.set(w.id, L), {
|
|
970
|
+
oldValue: w,
|
|
971
971
|
newValue: L,
|
|
972
|
-
bodiesDeleted: [
|
|
972
|
+
bodiesDeleted: [x]
|
|
973
973
|
};
|
|
974
974
|
} else
|
|
975
975
|
console.warn(`Attempt to delete missing body ${h.id} from annotation ${h.annotation}`);
|
|
976
976
|
} else
|
|
977
977
|
console.warn(`Attempt to delete body from missing annotation ${h.annotation}`);
|
|
978
|
-
}, u = (h,
|
|
979
|
-
const
|
|
980
|
-
|
|
981
|
-
}, y = (h,
|
|
982
|
-
const
|
|
983
|
-
|
|
978
|
+
}, u = (h, w = k.LOCAL) => {
|
|
979
|
+
const x = g(h);
|
|
980
|
+
x && s(w, { updated: [x] });
|
|
981
|
+
}, y = (h, w = k.LOCAL) => {
|
|
982
|
+
const x = h.map((L) => g(L)).filter(Boolean);
|
|
983
|
+
x.length > 0 && s(w, { updated: x });
|
|
984
984
|
}, S = (h) => {
|
|
985
|
-
const
|
|
986
|
-
return
|
|
985
|
+
const w = t.get(h);
|
|
986
|
+
return w ? { ...w } : void 0;
|
|
987
987
|
}, E = (h) => {
|
|
988
|
-
const
|
|
989
|
-
if (
|
|
990
|
-
const
|
|
991
|
-
if (
|
|
992
|
-
return
|
|
988
|
+
const w = e.get(h);
|
|
989
|
+
if (w) {
|
|
990
|
+
const x = S(w).bodies.find((L) => L.id === h);
|
|
991
|
+
if (x)
|
|
992
|
+
return x;
|
|
993
993
|
console.error(`Store integrity error: body ${h} in index, but not in annotation`);
|
|
994
994
|
} else
|
|
995
995
|
console.warn(`Attempt to retrieve missing body: ${h}`);
|
|
996
|
-
}, O = (h,
|
|
997
|
-
if (h.annotation !==
|
|
996
|
+
}, O = (h, w) => {
|
|
997
|
+
if (h.annotation !== w.annotation)
|
|
998
998
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
999
|
-
const
|
|
1000
|
-
if (
|
|
1001
|
-
const L =
|
|
1002
|
-
...
|
|
1003
|
-
bodies:
|
|
999
|
+
const x = t.get(h.annotation);
|
|
1000
|
+
if (x) {
|
|
1001
|
+
const L = x.bodies.find((B) => B.id === h.id), M = {
|
|
1002
|
+
...x,
|
|
1003
|
+
bodies: x.bodies.map((B) => B.id === L.id ? w : B)
|
|
1004
1004
|
};
|
|
1005
|
-
return t.set(
|
|
1006
|
-
oldValue:
|
|
1005
|
+
return t.set(x.id, M), L.id !== w.id && (e.delete(L.id), e.set(w.id, M.id)), {
|
|
1006
|
+
oldValue: x,
|
|
1007
1007
|
newValue: M,
|
|
1008
|
-
bodiesUpdated: [{ oldBody: L, newBody:
|
|
1008
|
+
bodiesUpdated: [{ oldBody: L, newBody: w }]
|
|
1009
1009
|
};
|
|
1010
1010
|
} else
|
|
1011
1011
|
console.warn(`Attempt to add body to missing annotation ${h.annotation}`);
|
|
1012
|
-
}, R = (h,
|
|
1013
|
-
const L = O(h,
|
|
1014
|
-
L && s(
|
|
1015
|
-
}, T = (h,
|
|
1016
|
-
const
|
|
1017
|
-
s(
|
|
1018
|
-
},
|
|
1019
|
-
const
|
|
1020
|
-
if (
|
|
1021
|
-
const
|
|
1022
|
-
...
|
|
1012
|
+
}, R = (h, w, x = k.LOCAL) => {
|
|
1013
|
+
const L = O(h, w);
|
|
1014
|
+
L && s(x, { updated: [L] });
|
|
1015
|
+
}, T = (h, w = k.LOCAL) => {
|
|
1016
|
+
const x = h.map((L) => O({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
|
|
1017
|
+
s(w, { updated: x });
|
|
1018
|
+
}, A = (h) => {
|
|
1019
|
+
const w = t.get(h.annotation);
|
|
1020
|
+
if (w) {
|
|
1021
|
+
const x = {
|
|
1022
|
+
...w,
|
|
1023
1023
|
target: {
|
|
1024
|
-
...
|
|
1024
|
+
...w.target,
|
|
1025
1025
|
...h
|
|
1026
1026
|
}
|
|
1027
1027
|
};
|
|
1028
|
-
return t.set(
|
|
1029
|
-
oldValue:
|
|
1030
|
-
newValue:
|
|
1028
|
+
return t.set(w.id, x), {
|
|
1029
|
+
oldValue: w,
|
|
1030
|
+
newValue: x,
|
|
1031
1031
|
targetUpdated: {
|
|
1032
|
-
oldTarget:
|
|
1032
|
+
oldTarget: w.target,
|
|
1033
1033
|
newTarget: h
|
|
1034
1034
|
}
|
|
1035
1035
|
};
|
|
@@ -1045,9 +1045,9 @@ const Bn = (t, e) => {
|
|
|
1045
1045
|
bulkDeleteBodies: y,
|
|
1046
1046
|
bulkUpdateAnnotation: c,
|
|
1047
1047
|
bulkUpdateBodies: T,
|
|
1048
|
-
bulkUpdateTargets: (h,
|
|
1049
|
-
const
|
|
1050
|
-
|
|
1048
|
+
bulkUpdateTargets: (h, w = k.LOCAL) => {
|
|
1049
|
+
const x = h.map((L) => A(L)).filter(Boolean);
|
|
1050
|
+
x.length > 0 && s(w, { updated: x });
|
|
1051
1051
|
},
|
|
1052
1052
|
clear: m,
|
|
1053
1053
|
deleteAnnotation: b,
|
|
@@ -1058,9 +1058,9 @@ const Bn = (t, e) => {
|
|
|
1058
1058
|
unobserve: i,
|
|
1059
1059
|
updateAnnotation: l,
|
|
1060
1060
|
updateBody: R,
|
|
1061
|
-
updateTarget: (h,
|
|
1062
|
-
const
|
|
1063
|
-
|
|
1061
|
+
updateTarget: (h, w = k.LOCAL) => {
|
|
1062
|
+
const x = A(h);
|
|
1063
|
+
x && s(w, { updated: [x] });
|
|
1064
1064
|
}
|
|
1065
1065
|
};
|
|
1066
1066
|
};
|
|
@@ -1083,36 +1083,36 @@ const Un = 250, Dn = (t) => {
|
|
|
1083
1083
|
let o = -1, i = !1, s = 0;
|
|
1084
1084
|
const r = (p) => {
|
|
1085
1085
|
if (!i) {
|
|
1086
|
-
const { changes:
|
|
1086
|
+
const { changes: v } = p, b = performance.now();
|
|
1087
1087
|
if (b - s > Un)
|
|
1088
|
-
n.splice(o + 1), n.push(
|
|
1088
|
+
n.splice(o + 1), n.push(v), o = n.length - 1;
|
|
1089
1089
|
else {
|
|
1090
1090
|
const C = n.length - 1;
|
|
1091
|
-
n[C] = kn(n[C],
|
|
1091
|
+
n[C] = kn(n[C], v);
|
|
1092
1092
|
}
|
|
1093
1093
|
s = b;
|
|
1094
1094
|
}
|
|
1095
1095
|
i = !1;
|
|
1096
1096
|
};
|
|
1097
1097
|
t.observe(r, { origin: k.LOCAL });
|
|
1098
|
-
const a = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), l = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), c = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue:
|
|
1098
|
+
const a = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), l = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), c = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue: v }) => v)), f = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: v }) => v)), d = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), m = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p);
|
|
1099
1099
|
return {
|
|
1100
1100
|
canRedo: () => n.length - 1 > o,
|
|
1101
1101
|
canUndo: () => o > -1,
|
|
1102
1102
|
destroy: () => t.unobserve(r),
|
|
1103
|
-
on: (p,
|
|
1103
|
+
on: (p, v) => e.on(p, v),
|
|
1104
1104
|
redo: () => {
|
|
1105
1105
|
if (n.length - 1 > o) {
|
|
1106
1106
|
i = !0;
|
|
1107
|
-
const { created: p, updated:
|
|
1108
|
-
l(p), f(
|
|
1107
|
+
const { created: p, updated: v, deleted: b } = n[o + 1];
|
|
1108
|
+
l(p), f(v), m(b), e.emit("redo", n[o + 1]), o += 1;
|
|
1109
1109
|
}
|
|
1110
1110
|
},
|
|
1111
1111
|
undo: () => {
|
|
1112
1112
|
if (o > -1) {
|
|
1113
1113
|
i = !0;
|
|
1114
|
-
const { created: p, updated:
|
|
1115
|
-
a(p), c(
|
|
1114
|
+
const { created: p, updated: v, deleted: b } = n[o];
|
|
1115
|
+
a(p), c(v), d(b), e.emit("undo", n[o]), o -= 1;
|
|
1116
1116
|
}
|
|
1117
1117
|
}
|
|
1118
1118
|
};
|
|
@@ -1185,11 +1185,11 @@ const Un = 250, Dn = (t) => {
|
|
|
1185
1185
|
g.length > 0 && (c = c.map((u) => g.find((S) => S.id === u.id) || u));
|
|
1186
1186
|
}
|
|
1187
1187
|
}, { origin: k.REMOTE });
|
|
1188
|
-
const
|
|
1188
|
+
const v = (b) => (C) => {
|
|
1189
1189
|
const { updated: g } = C;
|
|
1190
1190
|
b ? (g || []).forEach((u) => p("updateAnnotation", u.oldValue, u.newValue)) : (g || []).forEach((u) => p("updateAnnotation", u.newValue, u.oldValue));
|
|
1191
1191
|
};
|
|
1192
|
-
return e.on("undo",
|
|
1192
|
+
return e.on("undo", v(!0)), e.on("redo", v(!1)), { on: d, off: m, emit: p };
|
|
1193
1193
|
}, Yn = (t) => (e) => e.reduce((n, o) => {
|
|
1194
1194
|
const { parsed: i, error: s } = t.parse(o);
|
|
1195
1195
|
return s ? {
|
|
@@ -1231,7 +1231,7 @@ const Un = 250, Dn = (t) => {
|
|
|
1231
1231
|
E.length > 0 && console.warn(`Discarded ${E.length} invalid annotations`, E), o.bulkAddAnnotation(S, u, k.REMOTE);
|
|
1232
1232
|
} else
|
|
1233
1233
|
o.bulkAddAnnotation(g.map(Tt), u, k.REMOTE);
|
|
1234
|
-
},
|
|
1234
|
+
}, v = (g, u) => {
|
|
1235
1235
|
g ? i.setSelected(g, u) : i.clear();
|
|
1236
1236
|
}, b = (g) => {
|
|
1237
1237
|
i.clear(), i.setUserSelectAction(g);
|
|
@@ -1257,7 +1257,7 @@ const Un = 250, Dn = (t) => {
|
|
|
1257
1257
|
redo: e.redo,
|
|
1258
1258
|
removeAnnotation: m,
|
|
1259
1259
|
setAnnotations: p,
|
|
1260
|
-
setSelected:
|
|
1260
|
+
setSelected: v,
|
|
1261
1261
|
setUserSelectAction: b,
|
|
1262
1262
|
undo: e.undo,
|
|
1263
1263
|
updateAnnotation: C
|
|
@@ -1386,9 +1386,9 @@ const ko = (t, e) => ({
|
|
|
1386
1386
|
updated: c,
|
|
1387
1387
|
...f
|
|
1388
1388
|
} = i, d = r.map((m) => {
|
|
1389
|
-
const { id: p, quote:
|
|
1389
|
+
const { id: p, quote: v, start: b, end: C, range: g } = m, { prefix: u, suffix: y } = _e(g, n), S = [{
|
|
1390
1390
|
type: "TextQuoteSelector",
|
|
1391
|
-
exact:
|
|
1391
|
+
exact: v,
|
|
1392
1392
|
prefix: u,
|
|
1393
1393
|
suffix: y
|
|
1394
1394
|
}, {
|
|
@@ -1399,7 +1399,7 @@ const ko = (t, e) => ({
|
|
|
1399
1399
|
return {
|
|
1400
1400
|
...f,
|
|
1401
1401
|
id: p,
|
|
1402
|
-
// @ts-expect-error: `scope` is not part of the core `
|
|
1402
|
+
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
1403
1403
|
scope: "scope" in m ? m.scope : void 0,
|
|
1404
1404
|
source: e,
|
|
1405
1405
|
selector: S
|
|
@@ -1420,8 +1420,8 @@ const ko = (t, e) => ({
|
|
|
1420
1420
|
function we(t, e, n = 0, o = t.length - 1, i = eo) {
|
|
1421
1421
|
for (; o > n; ) {
|
|
1422
1422
|
if (o - n > 600) {
|
|
1423
|
-
const l = o - n + 1, c = e - n + 1, f = Math.log(l), d = 0.5 * Math.exp(2 * f / 3), m = 0.5 * Math.sqrt(f * d * (l - d) / l) * (c - l / 2 < 0 ? -1 : 1), p = Math.max(n, Math.floor(e - c * d / l + m)),
|
|
1424
|
-
we(t, e, p,
|
|
1423
|
+
const l = o - n + 1, c = e - n + 1, f = Math.log(l), d = 0.5 * Math.exp(2 * f / 3), m = 0.5 * Math.sqrt(f * d * (l - d) / l) * (c - l / 2 < 0 ? -1 : 1), p = Math.max(n, Math.floor(e - c * d / l + m)), v = Math.min(o, Math.floor(e + (l - c) * d / l + m));
|
|
1424
|
+
we(t, e, p, v, i);
|
|
1425
1425
|
}
|
|
1426
1426
|
const s = t[e];
|
|
1427
1427
|
let r = n, a = o;
|
|
@@ -1706,12 +1706,12 @@ const lo = (t, e) => {
|
|
|
1706
1706
|
return Array.from(T.getClientRects());
|
|
1707
1707
|
}), O = Ye(E).map((R) => je(R, S));
|
|
1708
1708
|
return O.map((R) => {
|
|
1709
|
-
const { x: T, y:
|
|
1709
|
+
const { x: T, y: A, width: h, height: w } = R;
|
|
1710
1710
|
return {
|
|
1711
1711
|
minX: T,
|
|
1712
|
-
minY:
|
|
1712
|
+
minY: A,
|
|
1713
1713
|
maxX: T + h,
|
|
1714
|
-
maxY:
|
|
1714
|
+
maxY: A + w,
|
|
1715
1715
|
annotation: {
|
|
1716
1716
|
id: y.annotation,
|
|
1717
1717
|
rects: O
|
|
@@ -1731,7 +1731,7 @@ const lo = (t, e) => {
|
|
|
1731
1731
|
}, d = (y, S = !0) => {
|
|
1732
1732
|
S && a();
|
|
1733
1733
|
const E = e.getBoundingClientRect(), O = y.map((T) => ({ target: T, rects: s(T, E) }));
|
|
1734
|
-
O.forEach(({ target: T, rects:
|
|
1734
|
+
O.forEach(({ target: T, rects: A }) => o.set(T.annotation, A));
|
|
1735
1735
|
const R = O.flatMap(({ rects: T }) => T);
|
|
1736
1736
|
n.load(R);
|
|
1737
1737
|
}, m = (y, S, E = !1) => {
|
|
@@ -1740,19 +1740,19 @@ const lo = (t, e) => {
|
|
|
1740
1740
|
minY: S,
|
|
1741
1741
|
maxX: y,
|
|
1742
1742
|
maxY: S
|
|
1743
|
-
}), R = (T) => T.annotation.rects.reduce((
|
|
1744
|
-
return O.length > 0 ? (O.sort((T,
|
|
1743
|
+
}), R = (T) => T.annotation.rects.reduce((A, h) => A + h.width * h.height, 0);
|
|
1744
|
+
return O.length > 0 ? (O.sort((T, A) => R(T) - R(A)), E ? O.map((T) => T.annotation.id) : [O[0].annotation.id]) : [];
|
|
1745
1745
|
}, p = (y) => {
|
|
1746
|
-
const S =
|
|
1746
|
+
const S = v(y);
|
|
1747
1747
|
if (S.length === 0)
|
|
1748
1748
|
return;
|
|
1749
1749
|
let E = S[0].left, O = S[0].top, R = S[0].right, T = S[0].bottom;
|
|
1750
|
-
for (let
|
|
1751
|
-
const h = S[
|
|
1750
|
+
for (let A = 1; A < S.length; A++) {
|
|
1751
|
+
const h = S[A];
|
|
1752
1752
|
E = Math.min(E, h.left), O = Math.min(O, h.top), R = Math.max(R, h.right), T = Math.max(T, h.bottom);
|
|
1753
1753
|
}
|
|
1754
1754
|
return new DOMRect(E, O, R - E, T - O);
|
|
1755
|
-
},
|
|
1755
|
+
}, v = (y) => {
|
|
1756
1756
|
const S = o.get(y);
|
|
1757
1757
|
return S[0] ? S[0].annotation.rects : [];
|
|
1758
1758
|
};
|
|
@@ -1761,13 +1761,13 @@ const lo = (t, e) => {
|
|
|
1761
1761
|
clear: a,
|
|
1762
1762
|
getAt: m,
|
|
1763
1763
|
getAnnotationBounds: p,
|
|
1764
|
-
getAnnotationRects:
|
|
1764
|
+
getAnnotationRects: v,
|
|
1765
1765
|
getIntersecting: (y, S, E, O) => {
|
|
1766
|
-
const R = n.search({ minX: y, minY: S, maxX: E, maxY: O }), T = new Set(R.map((
|
|
1767
|
-
return Array.from(T).map((
|
|
1768
|
-
annotation: t.getAnnotation(
|
|
1769
|
-
rects:
|
|
1770
|
-
})).filter((
|
|
1766
|
+
const R = n.search({ minX: y, minY: S, maxX: E, maxY: O }), T = new Set(R.map((A) => A.annotation.id));
|
|
1767
|
+
return Array.from(T).map((A) => ({
|
|
1768
|
+
annotation: t.getAnnotation(A),
|
|
1769
|
+
rects: v(A)
|
|
1770
|
+
})).filter((A) => !!A.annotation);
|
|
1771
1771
|
},
|
|
1772
1772
|
insert: l,
|
|
1773
1773
|
recalculate: () => {
|
|
@@ -1787,10 +1787,10 @@ const lo = (t, e) => {
|
|
|
1787
1787
|
return E && n.addAnnotation(S, y), E;
|
|
1788
1788
|
}, l = (u, y = !0, S = k.LOCAL) => {
|
|
1789
1789
|
const E = u.map((R) => vt(R, t)), O = E.filter((R) => !F(R.target.selector));
|
|
1790
|
-
return
|
|
1790
|
+
return n.bulkAddAnnotation(E, y, S), O;
|
|
1791
1791
|
}, c = (u, y = k.LOCAL) => {
|
|
1792
1792
|
const S = u.map((O) => vt(O, t)), E = S.filter((O) => !F(O.target.selector));
|
|
1793
|
-
return
|
|
1793
|
+
return S.forEach((O) => {
|
|
1794
1794
|
n.getAnnotation(O.id) ? n.updateAnnotation(O, y) : n.addAnnotation(O, y);
|
|
1795
1795
|
}), E;
|
|
1796
1796
|
}, f = (u, y = k.LOCAL) => {
|
|
@@ -1806,12 +1806,12 @@ const lo = (t, e) => {
|
|
|
1806
1806
|
const O = o.getAnnotationRects(u);
|
|
1807
1807
|
if (O.length !== 0) {
|
|
1808
1808
|
if (y && S) {
|
|
1809
|
-
const R = O.find(({ top: T, right:
|
|
1809
|
+
const R = O.find(({ top: T, right: A, bottom: h, left: w }) => y >= w - E && y <= A + E && S >= T - E && S <= h + E);
|
|
1810
1810
|
if (R) return R;
|
|
1811
1811
|
}
|
|
1812
1812
|
return o.getAnnotationBounds(u);
|
|
1813
1813
|
}
|
|
1814
|
-
},
|
|
1814
|
+
}, v = (u, y, S, E) => o.getIntersecting(u, y, S, E), b = (u) => o.getAnnotationRects(u), C = () => o.recalculate(), g = (u) => o.on("recalculate", u);
|
|
1815
1815
|
return n.observe(({ changes: u }) => {
|
|
1816
1816
|
const y = (u.deleted || []).filter((O) => F(O.target.selector)), S = (u.created || []).filter((O) => F(O.target.selector)), E = (u.updated || []).filter((O) => F(O.newValue.target.selector));
|
|
1817
1817
|
(y == null ? void 0 : y.length) > 0 && y.forEach((O) => o.remove(O.target)), S.length > 0 && o.set(S.map((O) => O.target), !1), (E == null ? void 0 : E.length) > 0 && E.forEach(({ newValue: O }) => o.update(O.target));
|
|
@@ -1824,7 +1824,7 @@ const lo = (t, e) => {
|
|
|
1824
1824
|
bulkUpsertAnnotations: c,
|
|
1825
1825
|
getAnnotationBounds: p,
|
|
1826
1826
|
getAnnotationRects: b,
|
|
1827
|
-
getIntersecting:
|
|
1827
|
+
getIntersecting: v,
|
|
1828
1828
|
getAt: m,
|
|
1829
1829
|
recalculatePositions: C,
|
|
1830
1830
|
onRecalculatePositions: g,
|
|
@@ -1857,8 +1857,8 @@ const lo = (t, e) => {
|
|
|
1857
1857
|
e.font && (o.font = e.font);
|
|
1858
1858
|
const p = i.get(f.annotation.id);
|
|
1859
1859
|
if (p) {
|
|
1860
|
-
const { height:
|
|
1861
|
-
o.fillStyle = p.appearance.color, o.fillRect(b - 2, C - 2.5, 2,
|
|
1860
|
+
const { height: v } = f.rects[0], b = f.rects[0].x + d.left, C = f.rects[0].y + d.top;
|
|
1861
|
+
o.fillStyle = p.appearance.color, o.fillRect(b - 2, C - 2.5, 2, v + 5);
|
|
1862
1862
|
const g = o.measureText(p.appearance.label), u = g.width + 6, y = g.actualBoundingBoxAscent + g.actualBoundingBoxDescent + 8, S = g.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1863
1863
|
return o.fillRect(b - 2, C - 2.5 - y, u, y), o.fillStyle = "#fff", o.fillText(p.appearance.label, b + 1, C - S), {
|
|
1864
1864
|
fill: p.appearance.color,
|
|
@@ -2155,15 +2155,15 @@ function P(t, e, n) {
|
|
|
2155
2155
|
const p = function() {
|
|
2156
2156
|
let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
|
|
2157
2157
|
return ie(b, r);
|
|
2158
|
-
},
|
|
2158
|
+
}, v = function() {
|
|
2159
2159
|
let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
|
|
2160
2160
|
ie(b, r), Eo(b);
|
|
2161
2161
|
};
|
|
2162
2162
|
z.set(r, {
|
|
2163
2163
|
keydownListener: p,
|
|
2164
|
-
keyupListenr:
|
|
2164
|
+
keyupListenr: v,
|
|
2165
2165
|
capture: d
|
|
2166
|
-
}), It(r, "keydown", p, d), It(r, "keyup",
|
|
2166
|
+
}), It(r, "keydown", p, d), It(r, "keyup", v, d);
|
|
2167
2167
|
}
|
|
2168
2168
|
if (!rt) {
|
|
2169
2169
|
const p = () => {
|
|
@@ -2248,20 +2248,20 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
|
|
|
2248
2248
|
], Oo = (t, e, n) => {
|
|
2249
2249
|
const { store: o, selection: i } = e;
|
|
2250
2250
|
let s;
|
|
2251
|
-
const r = (
|
|
2251
|
+
const r = (A) => s = A;
|
|
2252
2252
|
let a;
|
|
2253
|
-
const l = (
|
|
2253
|
+
const l = (A) => a = A;
|
|
2254
2254
|
let c, f, d, m = !0;
|
|
2255
|
-
const p = (
|
|
2256
|
-
m =
|
|
2257
|
-
},
|
|
2258
|
-
m && f !== !1 && (c = nt(
|
|
2255
|
+
const p = (A) => {
|
|
2256
|
+
m = A, b.clear(), A || (c = void 0, f = void 0, d = void 0);
|
|
2257
|
+
}, v = (A) => {
|
|
2258
|
+
m && f !== !1 && (c = nt(A.target) ? void 0 : {
|
|
2259
2259
|
annotation: ge(),
|
|
2260
2260
|
selector: [],
|
|
2261
2261
|
creator: s,
|
|
2262
2262
|
created: /* @__PURE__ */ new Date()
|
|
2263
2263
|
});
|
|
2264
|
-
}, b = Kt((
|
|
2264
|
+
}, b = Kt((A) => {
|
|
2265
2265
|
if (!m) return;
|
|
2266
2266
|
const h = document.getSelection();
|
|
2267
2267
|
if (!(h != null && h.anchorNode))
|
|
@@ -2270,13 +2270,13 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
|
|
|
2270
2270
|
c = void 0;
|
|
2271
2271
|
return;
|
|
2272
2272
|
}
|
|
2273
|
-
const
|
|
2274
|
-
if ((d == null ? void 0 : d.type) === "pointerdown" && (
|
|
2273
|
+
const w = A.timeStamp - ((d == null ? void 0 : d.timeStamp) || A.timeStamp);
|
|
2274
|
+
if ((d == null ? void 0 : d.type) === "pointerdown" && (w < 1e3 && !c || h.isCollapsed && w < se) && v(d || A), !c) return;
|
|
2275
2275
|
if (h.isCollapsed) {
|
|
2276
2276
|
o.getAnnotation(c.annotation) && (i.clear(), o.deleteAnnotation(c.annotation));
|
|
2277
2277
|
return;
|
|
2278
2278
|
}
|
|
2279
|
-
const
|
|
2279
|
+
const x = h.getRangeAt(0), L = $e(x, t);
|
|
2280
2280
|
if (De(L)) return;
|
|
2281
2281
|
const M = Ne(L.cloneRange());
|
|
2282
2282
|
(M.length !== c.selector.length || M.some((K, Y) => {
|
|
@@ -2287,64 +2287,72 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
|
|
|
2287
2287
|
selector: M.map((K) => Xe(K, t, n)),
|
|
2288
2288
|
updated: /* @__PURE__ */ new Date()
|
|
2289
2289
|
}, o.getAnnotation(c.annotation) ? o.updateTarget(c, k.LOCAL) : i.clear());
|
|
2290
|
-
}, 10), C = (
|
|
2291
|
-
nt(
|
|
2292
|
-
}, g = () => {
|
|
2293
|
-
|
|
2294
|
-
id: c.annotation,
|
|
2295
|
-
bodies: [],
|
|
2296
|
-
target: c
|
|
2297
|
-
});
|
|
2298
|
-
}, u = async (x) => {
|
|
2299
|
-
if (nt(x.target) || !f) return;
|
|
2290
|
+
}, 10), C = (A) => {
|
|
2291
|
+
nt(A.target) || (d = At(A), f = d.button === 0);
|
|
2292
|
+
}, g = async (A) => {
|
|
2293
|
+
if (nt(A.target) || !f) return;
|
|
2300
2294
|
const h = () => {
|
|
2301
|
-
const { x
|
|
2295
|
+
const { x, y: L } = t.getBoundingClientRect(), M = A.target instanceof Node && t.contains(A.target) && o.getAt(A.clientX - x, A.clientY - L, a);
|
|
2302
2296
|
if (M) {
|
|
2303
2297
|
const { selected: B } = i;
|
|
2304
|
-
(B.length !== 1 || B[0].id !== M.id) && i.userSelect(M.id,
|
|
2298
|
+
(B.length !== 1 || B[0].id !== M.id) && i.userSelect(M.id, A);
|
|
2305
2299
|
} else
|
|
2306
2300
|
i.clear();
|
|
2307
2301
|
};
|
|
2308
|
-
if (
|
|
2309
|
-
await
|
|
2310
|
-
const
|
|
2311
|
-
if (
|
|
2302
|
+
if (A.timeStamp - d.timeStamp < se) {
|
|
2303
|
+
await u();
|
|
2304
|
+
const x = document.getSelection();
|
|
2305
|
+
if (x != null && x.isCollapsed) {
|
|
2312
2306
|
c = void 0, h();
|
|
2313
2307
|
return;
|
|
2314
2308
|
}
|
|
2315
2309
|
}
|
|
2316
|
-
c && c.selector.length > 0 && (i.clear(),
|
|
2317
|
-
},
|
|
2318
|
-
const
|
|
2319
|
-
let h = !1,
|
|
2320
|
-
const
|
|
2321
|
-
return setTimeout(() => h = !0, 50), Co(() =>
|
|
2322
|
-
},
|
|
2310
|
+
c && c.selector.length > 0 && (i.clear(), R(), i.userSelect(c.annotation, At(A)));
|
|
2311
|
+
}, u = async () => {
|
|
2312
|
+
const A = document.getSelection();
|
|
2313
|
+
let h = !1, w = A == null ? void 0 : A.isCollapsed;
|
|
2314
|
+
const x = () => w || h, L = 1;
|
|
2315
|
+
return setTimeout(() => h = !0, 50), Co(() => w = A == null ? void 0 : A.isCollapsed, L, x);
|
|
2316
|
+
}, y = (A) => {
|
|
2323
2317
|
const h = document.getSelection();
|
|
2324
|
-
h != null && h.isCollapsed || ((!c || c.selector.length === 0) && b(
|
|
2325
|
-
},
|
|
2326
|
-
m &&
|
|
2327
|
-
},
|
|
2318
|
+
h != null && h.isCollapsed || ((!c || c.selector.length === 0) && b(A), R(), i.userSelect(c.annotation, At(A)));
|
|
2319
|
+
}, S = (A) => {
|
|
2320
|
+
m && A.key === "Shift" && c && (document.getSelection().isCollapsed || (i.clear(), R(), i.userSelect(c.annotation, ut(A))));
|
|
2321
|
+
}, E = (A) => {
|
|
2328
2322
|
const h = () => setTimeout(() => {
|
|
2329
2323
|
(c == null ? void 0 : c.selector.length) > 0 && (i.clear(), o.addAnnotation({
|
|
2330
2324
|
id: c.annotation,
|
|
2331
2325
|
bodies: [],
|
|
2332
2326
|
target: c
|
|
2333
|
-
}), i.userSelect(c.annotation, ut(
|
|
2327
|
+
}), i.userSelect(c.annotation, ut(A))), document.removeEventListener("selectionchange", h);
|
|
2334
2328
|
}, 100);
|
|
2335
|
-
document.addEventListener("selectionchange", h),
|
|
2329
|
+
document.addEventListener("selectionchange", h), v(A);
|
|
2336
2330
|
};
|
|
2337
|
-
P(Lo.join(","), { element: t, keydown: !0, keyup: !1 }, (
|
|
2338
|
-
|
|
2339
|
-
}), P(Le, { keydown: !0, keyup: !1 }, (
|
|
2340
|
-
d = ut(
|
|
2331
|
+
P(Lo.join(","), { element: t, keydown: !0, keyup: !1 }, (A) => {
|
|
2332
|
+
A.repeat || (d = ut(A));
|
|
2333
|
+
}), P(Le, { keydown: !0, keyup: !1 }, (A) => {
|
|
2334
|
+
d = ut(A), E(A);
|
|
2341
2335
|
});
|
|
2342
|
-
const
|
|
2343
|
-
|
|
2336
|
+
const O = (A) => {
|
|
2337
|
+
A.repeat || A.target !== t && A.target !== document.body || (c = void 0, i.clear());
|
|
2338
|
+
};
|
|
2339
|
+
P(Ce.join(","), { keydown: !0, keyup: !1 }, O);
|
|
2340
|
+
const R = () => {
|
|
2341
|
+
const A = o.getAnnotation(c.annotation);
|
|
2342
|
+
if (!A) {
|
|
2343
|
+
o.addAnnotation({
|
|
2344
|
+
id: c.annotation,
|
|
2345
|
+
bodies: [],
|
|
2346
|
+
target: c
|
|
2347
|
+
});
|
|
2348
|
+
return;
|
|
2349
|
+
}
|
|
2350
|
+
const { target: { updated: h } } = A, { updated: w } = c;
|
|
2351
|
+
(!A || !w || h < w) && o.updateTarget(c);
|
|
2344
2352
|
};
|
|
2345
|
-
return
|
|
2353
|
+
return document.addEventListener("pointerdown", C), document.addEventListener("pointerup", g), document.addEventListener("contextmenu", y), t.addEventListener("keyup", S), t.addEventListener("selectstart", v), document.addEventListener("selectionchange", b), {
|
|
2346
2354
|
destroy: () => {
|
|
2347
|
-
c = void 0, f = void 0, d = void 0, b.clear(), document.removeEventListener("pointerdown", C), document.removeEventListener("pointerup",
|
|
2355
|
+
c = void 0, f = void 0, d = void 0, b.clear(), document.removeEventListener("pointerdown", C), document.removeEventListener("pointerup", g), document.removeEventListener("contextmenu", y), t.removeEventListener("keyup", S), t.removeEventListener("selectstart", v), document.removeEventListener("selectionchange", b), P.unbind();
|
|
2348
2356
|
},
|
|
2349
2357
|
setFilter: l,
|
|
2350
2358
|
setUser: r,
|
|
@@ -2367,7 +2375,7 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
|
|
|
2367
2375
|
console.debug(`Using ${f} renderer`), n.style && d.setStyle(n.style);
|
|
2368
2376
|
const m = Oo(t, o, n.offsetReferenceSelector);
|
|
2369
2377
|
m.setUser(c), m.setAnnotatingEnabled(n.annotatingEnabled);
|
|
2370
|
-
const p = Xn(o, a, n.adapter),
|
|
2378
|
+
const p = Xn(o, a, n.adapter), v = () => c, b = (E) => {
|
|
2371
2379
|
m.setAnnotatingEnabled(
|
|
2372
2380
|
E === void 0 ? !0 : E
|
|
2373
2381
|
);
|
|
@@ -2386,7 +2394,7 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
|
|
|
2386
2394
|
d.destroy(), m.destroy(), a.destroy();
|
|
2387
2395
|
},
|
|
2388
2396
|
element: t,
|
|
2389
|
-
getUser:
|
|
2397
|
+
getUser: v,
|
|
2390
2398
|
setAnnotatingEnabled: b,
|
|
2391
2399
|
setFilter: C,
|
|
2392
2400
|
setStyle: d.setStyle.bind(d),
|