@soomo/text-annotator 3.0.0-staging.54 → 3.0.0-staging.56
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.
|
@@ -265,22 +265,22 @@ const Ie = /* @__PURE__ */ Be(ke), Ut = (t, e = 10, n) => {
|
|
|
265
265
|
const { store: i, selection: r, hover: a } = e;
|
|
266
266
|
let s, l, f;
|
|
267
267
|
const h = Ce(n), c = (O) => {
|
|
268
|
-
const { x: R, y: m } = t.getBoundingClientRect(),
|
|
269
|
-
|
|
268
|
+
const { x: R, y: m } = t.getBoundingClientRect(), A = i.getAt(O.clientX - R, O.clientY - m, l);
|
|
269
|
+
A ? a.current !== A.id && (t.classList.add("hovered"), a.set(A.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
|
|
270
270
|
};
|
|
271
271
|
t.addEventListener("pointermove", c);
|
|
272
272
|
const g = (O = !1) => {
|
|
273
273
|
f && f.clear();
|
|
274
|
-
const R = Se(t), { minX: m, minY:
|
|
274
|
+
const R = Se(t), { minX: m, minY: A, maxX: v, maxY: L } = R, B = l ? i.getIntersecting(m, A, v, L).filter(({ annotation: Y }) => l(Y)) : i.getIntersecting(m, A, v, 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
278
|
o.redraw(K, R, s, f, O), setTimeout(() => h(B.map(({ annotation: Y }) => Y)), 1);
|
|
279
279
|
}, u = (O) => {
|
|
280
280
|
f = O, g();
|
|
281
|
-
},
|
|
281
|
+
}, x = (O) => {
|
|
282
282
|
s = O, g();
|
|
283
|
-
},
|
|
283
|
+
}, w = (O) => {
|
|
284
284
|
l = O, g(!1);
|
|
285
285
|
}, C = () => g();
|
|
286
286
|
i.observe(C);
|
|
@@ -292,16 +292,16 @@ const Ie = /* @__PURE__ */ Be(ke), Ut = (t, e = 10, n) => {
|
|
|
292
292
|
window.addEventListener("resize", y);
|
|
293
293
|
const S = new ResizeObserver(y);
|
|
294
294
|
S.observe(t);
|
|
295
|
-
const E = { attributes: !0, childList: !0, subtree: !0 },
|
|
295
|
+
const E = { attributes: !0, childList: !0, subtree: !0 }, b = new MutationObserver((O) => {
|
|
296
296
|
O.every((m) => m.target === t || t.contains(m.target)) || g(!0);
|
|
297
297
|
});
|
|
298
|
-
return
|
|
298
|
+
return b.observe(document.body, E), {
|
|
299
299
|
destroy: () => {
|
|
300
|
-
t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(C), p(), document.removeEventListener("scroll", d), y.clear(), window.removeEventListener("resize", y), S.disconnect(),
|
|
300
|
+
t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(C), p(), document.removeEventListener("scroll", d), y.clear(), window.removeEventListener("resize", y), S.disconnect(), b.disconnect();
|
|
301
301
|
},
|
|
302
302
|
redraw: g,
|
|
303
|
-
setStyle:
|
|
304
|
-
setFilter:
|
|
303
|
+
setStyle: x,
|
|
304
|
+
setFilter: w,
|
|
305
305
|
setPainter: u,
|
|
306
306
|
setVisible: o.setVisible
|
|
307
307
|
};
|
|
@@ -317,25 +317,25 @@ const Ie = /* @__PURE__ */ Be(ke), Ut = (t, e = 10, n) => {
|
|
|
317
317
|
const o = (s, l, f, h) => requestAnimationFrame(() => {
|
|
318
318
|
const { width: c, height: g } = e;
|
|
319
319
|
n.clearRect(-0.5, -0.5, c + 1, g + 1), h && h.clear();
|
|
320
|
-
const { top: u, left:
|
|
320
|
+
const { top: u, left: x } = l;
|
|
321
321
|
[...s].sort((C, p) => {
|
|
322
322
|
const { annotation: { target: { created: d } } } = C, { annotation: { target: { created: y } } } = p;
|
|
323
323
|
return d.getTime() - y.getTime();
|
|
324
324
|
}).forEach((C) => {
|
|
325
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:
|
|
327
|
-
x: E +
|
|
328
|
-
y:
|
|
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: b, width: T, height: O }) => ({
|
|
327
|
+
x: E + x,
|
|
328
|
+
y: b + u,
|
|
329
329
|
width: T,
|
|
330
330
|
height: O
|
|
331
331
|
}));
|
|
332
332
|
if (n.fillStyle = d.fill, n.globalAlpha = d.fillOpacity || 1, y.forEach(
|
|
333
|
-
({ x: E, y:
|
|
333
|
+
({ x: E, y: b, width: T, height: O }) => n.fillRect(E, b, T, O)
|
|
334
334
|
), d.underlineColor) {
|
|
335
335
|
n.globalAlpha = 1, n.strokeStyle = d.underlineColor, n.lineWidth = d.underlineThickness ?? 1;
|
|
336
336
|
const E = d.underlineOffset ?? 0;
|
|
337
|
-
y.forEach(({ x:
|
|
338
|
-
n.beginPath(), n.moveTo(
|
|
337
|
+
y.forEach(({ x: b, y: T, width: O, height: R }) => {
|
|
338
|
+
n.beginPath(), n.moveTo(b, T + R + E), n.lineTo(b + O, T + R + E), n.stroke();
|
|
339
339
|
});
|
|
340
340
|
}
|
|
341
341
|
});
|
|
@@ -502,13 +502,13 @@ const nn = (t) => [
|
|
|
502
502
|
const f = new Set(r.map((c) => c.annotation.id));
|
|
503
503
|
Array.from(e).filter((c) => !f.has(c));
|
|
504
504
|
const h = r.map((c) => {
|
|
505
|
-
var
|
|
506
|
-
const g = s ? typeof s == "function" ? s(c.annotation, c.state) : s : (
|
|
505
|
+
var x;
|
|
506
|
+
const g = s ? typeof s == "function" ? s(c.annotation, c.state) : s : (x = c.state) != null && x.selected ? yt : q, u = l && l.paint(c, a) || g;
|
|
507
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 g = c.target.selector.map((
|
|
511
|
+
const g = c.target.selector.map((x) => x.range), u = new Highlight(...g);
|
|
512
512
|
CSS.highlights.set(`_${c.id}`, u);
|
|
513
513
|
}), e = f;
|
|
514
514
|
}
|
|
@@ -550,15 +550,15 @@ const sn = (t, e) => {
|
|
|
550
550
|
redraw: (a, s, l, f, h) => {
|
|
551
551
|
const g = !(It(n, a) && h);
|
|
552
552
|
if (!f && !g) return;
|
|
553
|
-
g && (e.innerHTML = ""), [...a].sort((
|
|
554
|
-
const { annotation: { target: { created: C } } } =
|
|
555
|
-
return
|
|
556
|
-
}).forEach((
|
|
557
|
-
|
|
558
|
-
const C = sn(
|
|
553
|
+
g && (e.innerHTML = ""), [...a].sort((x, w) => {
|
|
554
|
+
const { annotation: { target: { created: C } } } = x, { annotation: { target: { created: p } } } = w;
|
|
555
|
+
return C && p ? C.getTime() - p.getTime() : 0;
|
|
556
|
+
}).forEach((x) => {
|
|
557
|
+
x.rects.map((w) => {
|
|
558
|
+
const C = sn(w, a), p = Ee(x, s, l, f, C);
|
|
559
559
|
if (g) {
|
|
560
560
|
const d = document.createElement("span");
|
|
561
|
-
d.className = "r6o-annotation", d.dataset.annotation =
|
|
561
|
+
d.className = "r6o-annotation", d.dataset.annotation = x.annotation.id, d.style.left = `${w.x}px`, d.style.top = `${w.y}px`, d.style.width = `${w.width}px`, d.style.height = `${w.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);
|
|
562
562
|
}
|
|
563
563
|
});
|
|
564
564
|
}), n = a;
|
|
@@ -674,40 +674,40 @@ const ft = { selected: [] }, mn = (t, e) => {
|
|
|
674
674
|
}, l = (u) => {
|
|
675
675
|
if (s())
|
|
676
676
|
return !1;
|
|
677
|
-
const
|
|
678
|
-
return r.selected.some((
|
|
679
|
-
}, f = (u,
|
|
680
|
-
const
|
|
681
|
-
if (!
|
|
677
|
+
const x = typeof u == "string" ? u : u.id;
|
|
678
|
+
return r.selected.some((w) => w.id === x);
|
|
679
|
+
}, f = (u, x) => {
|
|
680
|
+
const w = t.getAnnotation(u);
|
|
681
|
+
if (!w) {
|
|
682
682
|
console.warn("Invalid selection: " + u);
|
|
683
683
|
return;
|
|
684
684
|
}
|
|
685
|
-
switch (Qt(
|
|
685
|
+
switch (Qt(w, i)) {
|
|
686
686
|
case "EDIT":
|
|
687
|
-
o({ selected: [{ id: u, editable: !0 }], event:
|
|
687
|
+
o({ selected: [{ id: u, editable: !0 }], event: x });
|
|
688
688
|
break;
|
|
689
689
|
case "SELECT":
|
|
690
|
-
o({ selected: [{ id: u }], event:
|
|
690
|
+
o({ selected: [{ id: u }], event: x });
|
|
691
691
|
break;
|
|
692
692
|
default:
|
|
693
|
-
o({ selected: [], event:
|
|
693
|
+
o({ selected: [], event: x });
|
|
694
694
|
}
|
|
695
|
-
}, h = (u,
|
|
696
|
-
const
|
|
695
|
+
}, h = (u, x) => {
|
|
696
|
+
const w = Array.isArray(u) ? u : [u], C = w.map((p) => t.getAnnotation(p)).filter((p) => !!p);
|
|
697
697
|
o({
|
|
698
698
|
selected: C.map((p) => {
|
|
699
|
-
const d =
|
|
699
|
+
const d = x === void 0 ? Qt(p, i) === "EDIT" : x;
|
|
700
700
|
return { id: p.id, editable: d };
|
|
701
701
|
})
|
|
702
|
-
}), C.length !==
|
|
702
|
+
}), C.length !== w.length && console.warn("Invalid selection", u);
|
|
703
703
|
}, c = (u) => {
|
|
704
704
|
if (s())
|
|
705
705
|
return !1;
|
|
706
|
-
const { selected:
|
|
707
|
-
|
|
706
|
+
const { selected: x } = r;
|
|
707
|
+
x.some(({ id: w }) => u.includes(w)) && o({ selected: x.filter(({ id: w }) => !u.includes(w)) });
|
|
708
708
|
}, g = (u) => i = u;
|
|
709
709
|
return t.observe(
|
|
710
|
-
({ changes: u }) => c((u.deleted || []).map((
|
|
710
|
+
({ changes: u }) => c((u.deleted || []).map((x) => x.id))
|
|
711
711
|
), {
|
|
712
712
|
get event() {
|
|
713
713
|
return r ? r.event : null;
|
|
@@ -810,8 +810,8 @@ const Cn = (t, e) => {
|
|
|
810
810
|
...(t.updated || []).filter(({ newValue: c }) => !r.has(c.id)).map((c) => {
|
|
811
811
|
const { oldValue: g, newValue: u } = c;
|
|
812
812
|
if (a.has(u.id)) {
|
|
813
|
-
const
|
|
814
|
-
return fe(g,
|
|
813
|
+
const x = e.updated.find((w) => w.oldValue.id === u.id).newValue;
|
|
814
|
+
return fe(g, x);
|
|
815
815
|
} else
|
|
816
816
|
return c;
|
|
817
817
|
}),
|
|
@@ -833,71 +833,71 @@ const Cn = (t, e) => {
|
|
|
833
833
|
}
|
|
834
834
|
};
|
|
835
835
|
}, On = (t) => t.id !== void 0, Tn = () => {
|
|
836
|
-
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (m,
|
|
837
|
-
n.push({ onChange: m, options:
|
|
836
|
+
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (m, A = {}) => {
|
|
837
|
+
n.push({ onChange: m, options: A });
|
|
838
838
|
}, i = (m) => {
|
|
839
|
-
const
|
|
840
|
-
|
|
841
|
-
}, r = (m,
|
|
842
|
-
const
|
|
839
|
+
const A = n.findIndex((v) => v.onChange == m);
|
|
840
|
+
A > -1 && n.splice(A, 1);
|
|
841
|
+
}, r = (m, A) => {
|
|
842
|
+
const v = {
|
|
843
843
|
origin: m,
|
|
844
844
|
changes: {
|
|
845
|
-
created:
|
|
846
|
-
updated:
|
|
847
|
-
deleted:
|
|
845
|
+
created: A.created || [],
|
|
846
|
+
updated: A.updated || [],
|
|
847
|
+
deleted: A.deleted || []
|
|
848
848
|
},
|
|
849
849
|
state: [...t.values()]
|
|
850
850
|
};
|
|
851
851
|
n.forEach((L) => {
|
|
852
|
-
Cn(L,
|
|
852
|
+
Cn(L, v) && L.onChange(v);
|
|
853
853
|
});
|
|
854
|
-
}, a = (m,
|
|
854
|
+
}, a = (m, A = k.LOCAL) => {
|
|
855
855
|
if (m.id && t.get(m.id))
|
|
856
856
|
throw Error(`Cannot add annotation ${m.id} - exists already`);
|
|
857
857
|
{
|
|
858
|
-
const
|
|
859
|
-
t.set(
|
|
858
|
+
const v = Lt(m);
|
|
859
|
+
t.set(v.id, v), v.bodies.forEach((L) => e.set(L.id, v.id)), r(A, { created: [v] });
|
|
860
860
|
}
|
|
861
|
-
}, s = (m,
|
|
862
|
-
const
|
|
861
|
+
}, s = (m, A) => {
|
|
862
|
+
const v = Lt(typeof m == "string" ? A : m), L = typeof m == "string" ? m : m.id, B = L && t.get(L);
|
|
863
863
|
if (B) {
|
|
864
|
-
const M = fe(B,
|
|
865
|
-
return L ===
|
|
864
|
+
const M = fe(B, v);
|
|
865
|
+
return L === v.id ? t.set(L, v) : (t.delete(L), t.set(v.id, v)), B.bodies.forEach((K) => e.delete(K.id)), v.bodies.forEach((K) => e.set(K.id, v.id)), M;
|
|
866
866
|
} else
|
|
867
867
|
console.warn(`Cannot update annotation ${L} - does not exist`);
|
|
868
|
-
}, l = (m,
|
|
869
|
-
const L = On(
|
|
868
|
+
}, l = (m, A = k.LOCAL, v = k.LOCAL) => {
|
|
869
|
+
const L = On(A) ? v : A, B = s(m, A);
|
|
870
870
|
B && r(L, { updated: [B] });
|
|
871
|
-
}, f = (m,
|
|
872
|
-
const
|
|
871
|
+
}, f = (m, A = k.LOCAL) => {
|
|
872
|
+
const v = m.reduce((L, B) => {
|
|
873
873
|
const M = s(B);
|
|
874
874
|
return M ? [...L, M] : L;
|
|
875
875
|
}, []);
|
|
876
|
-
|
|
877
|
-
}, h = (m,
|
|
878
|
-
const
|
|
879
|
-
if (
|
|
876
|
+
v.length > 0 && r(A, { updated: v });
|
|
877
|
+
}, h = (m, A = k.LOCAL) => {
|
|
878
|
+
const v = t.get(m.annotation);
|
|
879
|
+
if (v) {
|
|
880
880
|
const L = {
|
|
881
|
-
...
|
|
882
|
-
bodies: [...
|
|
881
|
+
...v,
|
|
882
|
+
bodies: [...v.bodies, m]
|
|
883
883
|
};
|
|
884
|
-
t.set(
|
|
885
|
-
oldValue:
|
|
884
|
+
t.set(v.id, L), e.set(m.id, L.id), r(A, { updated: [{
|
|
885
|
+
oldValue: v,
|
|
886
886
|
newValue: L,
|
|
887
887
|
bodiesCreated: [m]
|
|
888
888
|
}] });
|
|
889
889
|
} else
|
|
890
890
|
console.warn(`Attempt to add body to missing annotation: ${m.annotation}`);
|
|
891
891
|
}, c = () => [...t.values()], g = (m = k.LOCAL) => {
|
|
892
|
-
const
|
|
893
|
-
t.clear(), e.clear(), r(m, { deleted:
|
|
894
|
-
}, u = (m,
|
|
892
|
+
const A = [...t.values()];
|
|
893
|
+
t.clear(), e.clear(), r(m, { deleted: A });
|
|
894
|
+
}, u = (m, A = !0, v = k.LOCAL) => {
|
|
895
895
|
const L = m.map(Lt);
|
|
896
|
-
if (
|
|
896
|
+
if (A) {
|
|
897
897
|
const B = [...t.values()];
|
|
898
898
|
t.clear(), e.clear(), L.forEach((M) => {
|
|
899
899
|
t.set(M.id, M), M.bodies.forEach((K) => e.set(K.id, M.id));
|
|
900
|
-
}), r(
|
|
900
|
+
}), r(v, { created: L, deleted: B });
|
|
901
901
|
} else {
|
|
902
902
|
const B = m.reduce((M, K) => {
|
|
903
903
|
const Y = K.id && t.get(K.id);
|
|
@@ -907,96 +907,96 @@ const Cn = (t, e) => {
|
|
|
907
907
|
throw Error(`Bulk insert would overwrite the following annotations: ${B.map((M) => M.id).join(", ")}`);
|
|
908
908
|
L.forEach((M) => {
|
|
909
909
|
t.set(M.id, M), M.bodies.forEach((K) => e.set(K.id, M.id));
|
|
910
|
-
}), r(
|
|
910
|
+
}), r(v, { created: L });
|
|
911
911
|
}
|
|
912
|
-
},
|
|
913
|
-
const
|
|
914
|
-
if (
|
|
915
|
-
return t.delete(
|
|
916
|
-
console.warn(`Attempt to delete missing annotation: ${
|
|
917
|
-
},
|
|
918
|
-
const
|
|
919
|
-
|
|
920
|
-
}, C = (m,
|
|
921
|
-
const
|
|
922
|
-
const M =
|
|
912
|
+
}, x = (m) => {
|
|
913
|
+
const A = typeof m == "string" ? m : m.id, v = t.get(A);
|
|
914
|
+
if (v)
|
|
915
|
+
return t.delete(A), v.bodies.forEach((L) => e.delete(L.id)), v;
|
|
916
|
+
console.warn(`Attempt to delete missing annotation: ${A}`);
|
|
917
|
+
}, w = (m, A = k.LOCAL) => {
|
|
918
|
+
const v = x(m);
|
|
919
|
+
v && r(A, { deleted: [v] });
|
|
920
|
+
}, C = (m, A = k.LOCAL) => {
|
|
921
|
+
const v = m.reduce((L, B) => {
|
|
922
|
+
const M = x(B);
|
|
923
923
|
return M ? [...L, M] : L;
|
|
924
924
|
}, []);
|
|
925
|
-
|
|
925
|
+
v.length > 0 && r(A, { deleted: v });
|
|
926
926
|
}, p = (m) => {
|
|
927
|
-
const
|
|
928
|
-
if (
|
|
929
|
-
const
|
|
930
|
-
if (
|
|
931
|
-
e.delete(
|
|
927
|
+
const A = t.get(m.annotation);
|
|
928
|
+
if (A) {
|
|
929
|
+
const v = A.bodies.find((L) => L.id === m.id);
|
|
930
|
+
if (v) {
|
|
931
|
+
e.delete(v.id);
|
|
932
932
|
const L = {
|
|
933
|
-
...
|
|
934
|
-
bodies:
|
|
933
|
+
...A,
|
|
934
|
+
bodies: A.bodies.filter((B) => B.id !== m.id)
|
|
935
935
|
};
|
|
936
|
-
return t.set(
|
|
937
|
-
oldValue:
|
|
936
|
+
return t.set(A.id, L), {
|
|
937
|
+
oldValue: A,
|
|
938
938
|
newValue: L,
|
|
939
|
-
bodiesDeleted: [
|
|
939
|
+
bodiesDeleted: [v]
|
|
940
940
|
};
|
|
941
941
|
} else
|
|
942
942
|
console.warn(`Attempt to delete missing body ${m.id} from annotation ${m.annotation}`);
|
|
943
943
|
} else
|
|
944
944
|
console.warn(`Attempt to delete body from missing annotation ${m.annotation}`);
|
|
945
|
-
}, d = (m,
|
|
946
|
-
const
|
|
947
|
-
|
|
948
|
-
}, y = (m,
|
|
949
|
-
const
|
|
950
|
-
|
|
945
|
+
}, d = (m, A = k.LOCAL) => {
|
|
946
|
+
const v = p(m);
|
|
947
|
+
v && r(A, { updated: [v] });
|
|
948
|
+
}, y = (m, A = k.LOCAL) => {
|
|
949
|
+
const v = m.map((L) => p(L)).filter(Boolean);
|
|
950
|
+
v.length > 0 && r(A, { updated: v });
|
|
951
951
|
}, S = (m) => {
|
|
952
|
-
const
|
|
953
|
-
return
|
|
952
|
+
const A = t.get(m);
|
|
953
|
+
return A ? { ...A } : void 0;
|
|
954
954
|
}, E = (m) => {
|
|
955
|
-
const
|
|
956
|
-
if (
|
|
957
|
-
const
|
|
958
|
-
if (
|
|
959
|
-
return
|
|
955
|
+
const A = e.get(m);
|
|
956
|
+
if (A) {
|
|
957
|
+
const v = S(A).bodies.find((L) => L.id === m);
|
|
958
|
+
if (v)
|
|
959
|
+
return v;
|
|
960
960
|
console.error(`Store integrity error: body ${m} in index, but not in annotation`);
|
|
961
961
|
} else
|
|
962
962
|
console.warn(`Attempt to retrieve missing body: ${m}`);
|
|
963
|
-
},
|
|
964
|
-
if (m.annotation !==
|
|
963
|
+
}, b = (m, A) => {
|
|
964
|
+
if (m.annotation !== A.annotation)
|
|
965
965
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
966
|
-
const
|
|
967
|
-
if (
|
|
968
|
-
const L =
|
|
969
|
-
...
|
|
970
|
-
bodies:
|
|
966
|
+
const v = t.get(m.annotation);
|
|
967
|
+
if (v) {
|
|
968
|
+
const L = v.bodies.find((M) => M.id === m.id), B = {
|
|
969
|
+
...v,
|
|
970
|
+
bodies: v.bodies.map((M) => M.id === L.id ? A : M)
|
|
971
971
|
};
|
|
972
|
-
return t.set(
|
|
973
|
-
oldValue:
|
|
972
|
+
return t.set(v.id, B), L.id !== A.id && (e.delete(L.id), e.set(A.id, B.id)), {
|
|
973
|
+
oldValue: v,
|
|
974
974
|
newValue: B,
|
|
975
|
-
bodiesUpdated: [{ oldBody: L, newBody:
|
|
975
|
+
bodiesUpdated: [{ oldBody: L, newBody: A }]
|
|
976
976
|
};
|
|
977
977
|
} else
|
|
978
978
|
console.warn(`Attempt to add body to missing annotation ${m.annotation}`);
|
|
979
|
-
}, T = (m,
|
|
980
|
-
const L =
|
|
981
|
-
L && r(
|
|
982
|
-
}, O = (m,
|
|
983
|
-
const
|
|
984
|
-
r(
|
|
979
|
+
}, T = (m, A, v = k.LOCAL) => {
|
|
980
|
+
const L = b(m, A);
|
|
981
|
+
L && r(v, { updated: [L] });
|
|
982
|
+
}, O = (m, A = k.LOCAL) => {
|
|
983
|
+
const v = m.map((L) => b({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
|
|
984
|
+
r(A, { updated: v });
|
|
985
985
|
}, R = (m) => {
|
|
986
|
-
const
|
|
987
|
-
if (
|
|
988
|
-
const
|
|
989
|
-
...
|
|
986
|
+
const A = t.get(m.annotation);
|
|
987
|
+
if (A) {
|
|
988
|
+
const v = {
|
|
989
|
+
...A,
|
|
990
990
|
target: {
|
|
991
|
-
...
|
|
991
|
+
...A.target,
|
|
992
992
|
...m
|
|
993
993
|
}
|
|
994
994
|
};
|
|
995
|
-
return t.set(
|
|
996
|
-
oldValue:
|
|
997
|
-
newValue:
|
|
995
|
+
return t.set(A.id, v), {
|
|
996
|
+
oldValue: A,
|
|
997
|
+
newValue: v,
|
|
998
998
|
targetUpdated: {
|
|
999
|
-
oldTarget:
|
|
999
|
+
oldTarget: A.target,
|
|
1000
1000
|
newTarget: m
|
|
1001
1001
|
}
|
|
1002
1002
|
};
|
|
@@ -1012,12 +1012,12 @@ const Cn = (t, e) => {
|
|
|
1012
1012
|
bulkDeleteBodies: y,
|
|
1013
1013
|
bulkUpdateAnnotation: f,
|
|
1014
1014
|
bulkUpdateBodies: O,
|
|
1015
|
-
bulkUpdateTargets: (m,
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1015
|
+
bulkUpdateTargets: (m, A = k.LOCAL) => {
|
|
1016
|
+
const v = m.map((L) => R(L)).filter(Boolean);
|
|
1017
|
+
v.length > 0 && r(A, { updated: v });
|
|
1018
1018
|
},
|
|
1019
1019
|
clear: g,
|
|
1020
|
-
deleteAnnotation:
|
|
1020
|
+
deleteAnnotation: w,
|
|
1021
1021
|
deleteBody: d,
|
|
1022
1022
|
getAnnotation: S,
|
|
1023
1023
|
getBody: E,
|
|
@@ -1025,9 +1025,9 @@ const Cn = (t, e) => {
|
|
|
1025
1025
|
unobserve: i,
|
|
1026
1026
|
updateAnnotation: l,
|
|
1027
1027
|
updateBody: T,
|
|
1028
|
-
updateTarget: (m,
|
|
1029
|
-
const
|
|
1030
|
-
|
|
1028
|
+
updateTarget: (m, A = k.LOCAL) => {
|
|
1029
|
+
const v = R(m);
|
|
1030
|
+
v && r(A, { updated: [v] });
|
|
1031
1031
|
}
|
|
1032
1032
|
};
|
|
1033
1033
|
};
|
|
@@ -1050,36 +1050,36 @@ const Mn = 250, Bn = (t) => {
|
|
|
1050
1050
|
let o = -1, i = !1, r = 0;
|
|
1051
1051
|
const a = (u) => {
|
|
1052
1052
|
if (!i) {
|
|
1053
|
-
const { changes:
|
|
1054
|
-
if (
|
|
1055
|
-
n.splice(o + 1), n.push(
|
|
1053
|
+
const { changes: x } = u, w = performance.now();
|
|
1054
|
+
if (w - r > Mn)
|
|
1055
|
+
n.splice(o + 1), n.push(x), o = n.length - 1;
|
|
1056
1056
|
else {
|
|
1057
1057
|
const C = n.length - 1;
|
|
1058
|
-
n[C] = Ln(n[C],
|
|
1058
|
+
n[C] = Ln(n[C], x);
|
|
1059
1059
|
}
|
|
1060
|
-
r =
|
|
1060
|
+
r = w;
|
|
1061
1061
|
}
|
|
1062
1062
|
i = !1;
|
|
1063
1063
|
};
|
|
1064
1064
|
t.observe(a, { origin: k.LOCAL });
|
|
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:
|
|
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: x }) => x)), h = (u) => u && u.length > 0 && t.bulkUpdateAnnotation(u.map(({ newValue: x }) => x)), c = (u) => u && u.length > 0 && t.bulkAddAnnotation(u, !1), g = (u) => u && u.length > 0 && t.bulkDeleteAnnotation(u);
|
|
1066
1066
|
return {
|
|
1067
1067
|
canRedo: () => n.length - 1 > o,
|
|
1068
1068
|
canUndo: () => o > -1,
|
|
1069
1069
|
destroy: () => t.unobserve(a),
|
|
1070
|
-
on: (u,
|
|
1070
|
+
on: (u, x) => e.on(u, x),
|
|
1071
1071
|
redo: () => {
|
|
1072
1072
|
if (n.length - 1 > o) {
|
|
1073
1073
|
i = !0;
|
|
1074
|
-
const { created: u, updated:
|
|
1075
|
-
l(u), h(
|
|
1074
|
+
const { created: u, updated: x, deleted: w } = n[o + 1];
|
|
1075
|
+
l(u), h(x), g(w), e.emit("redo", n[o + 1]), o += 1;
|
|
1076
1076
|
}
|
|
1077
1077
|
},
|
|
1078
1078
|
undo: () => {
|
|
1079
1079
|
if (o > -1) {
|
|
1080
1080
|
i = !0;
|
|
1081
|
-
const { created: u, updated:
|
|
1082
|
-
s(u), f(
|
|
1081
|
+
const { created: u, updated: x, deleted: w } = n[o];
|
|
1082
|
+
s(u), f(x), c(w), e.emit("undo", n[o]), o -= 1;
|
|
1083
1083
|
}
|
|
1084
1084
|
}
|
|
1085
1085
|
};
|
|
@@ -1092,17 +1092,17 @@ const Mn = 250, Bn = (t) => {
|
|
|
1092
1092
|
}, In = (t, e, n, o) => {
|
|
1093
1093
|
const { store: i, selection: r, hover: a, viewport: s } = t, l = /* @__PURE__ */ new Map();
|
|
1094
1094
|
let f = [], h;
|
|
1095
|
-
const c = (
|
|
1096
|
-
l.has(
|
|
1097
|
-
}, g = (
|
|
1098
|
-
const p = l.get(
|
|
1095
|
+
const c = (w, C) => {
|
|
1096
|
+
l.has(w) ? l.get(w).push(C) : l.set(w, [C]);
|
|
1097
|
+
}, g = (w, C) => {
|
|
1098
|
+
const p = l.get(w);
|
|
1099
1099
|
if (p) {
|
|
1100
1100
|
const d = p.indexOf(C);
|
|
1101
1101
|
d !== -1 && p.splice(d, 1);
|
|
1102
1102
|
}
|
|
1103
|
-
}, u = (
|
|
1104
|
-
l.has(
|
|
1105
|
-
l.get(
|
|
1103
|
+
}, u = (w, C, p) => {
|
|
1104
|
+
l.has(w) && setTimeout(() => {
|
|
1105
|
+
l.get(w).forEach((d) => {
|
|
1106
1106
|
if (n) {
|
|
1107
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
1108
|
d(y, S);
|
|
@@ -1111,17 +1111,17 @@ const Mn = 250, Bn = (t) => {
|
|
|
1111
1111
|
});
|
|
1112
1112
|
}, 1);
|
|
1113
1113
|
};
|
|
1114
|
-
r.subscribe(({ selected:
|
|
1115
|
-
if (!(f.length === 0 &&
|
|
1116
|
-
if (f.length === 0 &&
|
|
1117
|
-
f =
|
|
1118
|
-
else if (f.length > 0 &&
|
|
1114
|
+
r.subscribe(({ selected: w }) => {
|
|
1115
|
+
if (!(f.length === 0 && w.length === 0)) {
|
|
1116
|
+
if (f.length === 0 && w.length > 0)
|
|
1117
|
+
f = w.map(({ id: C }) => i.getAnnotation(C));
|
|
1118
|
+
else if (f.length > 0 && w.length === 0)
|
|
1119
1119
|
f.forEach((C) => {
|
|
1120
1120
|
const p = i.getAnnotation(C.id);
|
|
1121
1121
|
p && !G(p, C) && u("updateAnnotation", p, C);
|
|
1122
1122
|
}), f = [];
|
|
1123
1123
|
else {
|
|
1124
|
-
const C = new Set(f.map((d) => d.id)), p = new Set(
|
|
1124
|
+
const C = new Set(f.map((d) => d.id)), p = new Set(w.map(({ id: d }) => d));
|
|
1125
1125
|
f.filter((d) => !p.has(d.id)).forEach((d) => {
|
|
1126
1126
|
const y = i.getAnnotation(d.id);
|
|
1127
1127
|
y && !G(y, d) && u("updateAnnotation", y, d);
|
|
@@ -1129,16 +1129,16 @@ const Mn = 250, Bn = (t) => {
|
|
|
1129
1129
|
// Remove annotations that were deselected
|
|
1130
1130
|
...f.filter((d) => p.has(d.id)),
|
|
1131
1131
|
// Add editable annotations that were selected
|
|
1132
|
-
...
|
|
1132
|
+
...w.filter(({ id: d }) => !C.has(d)).map(({ id: d }) => i.getAnnotation(d))
|
|
1133
1133
|
];
|
|
1134
1134
|
}
|
|
1135
1135
|
u("selectionChanged", f);
|
|
1136
1136
|
}
|
|
1137
|
-
}), a.subscribe((
|
|
1138
|
-
!h &&
|
|
1139
|
-
}), s == null || s.subscribe((
|
|
1140
|
-
const { created: C, deleted: p } =
|
|
1141
|
-
(C || []).forEach((d) => u("createAnnotation", d)), (p || []).forEach((d) => u("deleteAnnotation", d)), (
|
|
1137
|
+
}), a.subscribe((w) => {
|
|
1138
|
+
!h && w ? u("mouseEnterAnnotation", i.getAnnotation(w)) : h && !w ? u("mouseLeaveAnnotation", i.getAnnotation(h)) : h && w && (u("mouseLeaveAnnotation", i.getAnnotation(h)), u("mouseEnterAnnotation", i.getAnnotation(w))), h = w;
|
|
1139
|
+
}), s == null || s.subscribe((w) => u("viewportIntersect", w.map((C) => i.getAnnotation(C)))), i.observe((w) => {
|
|
1140
|
+
const { created: C, deleted: p } = w.changes;
|
|
1141
|
+
(C || []).forEach((d) => u("createAnnotation", d)), (p || []).forEach((d) => u("deleteAnnotation", d)), (w.changes.updated || []).filter((d) => [
|
|
1142
1142
|
...d.bodiesCreated || [],
|
|
1143
1143
|
...d.bodiesDeleted || [],
|
|
1144
1144
|
...d.bodiesUpdated || []
|
|
@@ -1146,17 +1146,17 @@ const Mn = 250, Bn = (t) => {
|
|
|
1146
1146
|
const S = f.find((E) => E.id === d.id) || d;
|
|
1147
1147
|
f = f.map((E) => E.id === d.id ? y : E), u("updateAnnotation", y, S);
|
|
1148
1148
|
});
|
|
1149
|
-
}, { origin: k.LOCAL }), i.observe((
|
|
1149
|
+
}, { origin: k.LOCAL }), i.observe((w) => {
|
|
1150
1150
|
if (f) {
|
|
1151
|
-
const C = new Set(f.map((d) => d.id)), p = (
|
|
1151
|
+
const C = new Set(f.map((d) => d.id)), p = (w.changes.updated || []).filter(({ newValue: d }) => C.has(d.id)).map(({ newValue: d }) => d);
|
|
1152
1152
|
p.length > 0 && (f = f.map((d) => p.find((S) => S.id === d.id) || d));
|
|
1153
1153
|
}
|
|
1154
1154
|
}, { origin: k.REMOTE });
|
|
1155
|
-
const
|
|
1155
|
+
const x = (w) => (C) => {
|
|
1156
1156
|
const { updated: p } = C;
|
|
1157
|
-
|
|
1157
|
+
w ? (p || []).forEach((d) => u("updateAnnotation", d.oldValue, d.newValue)) : (p || []).forEach((d) => u("updateAnnotation", d.newValue, d.oldValue));
|
|
1158
1158
|
};
|
|
1159
|
-
return e.on("undo",
|
|
1159
|
+
return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: c, off: g, emit: u };
|
|
1160
1160
|
}, Nn = (t) => (e) => e.reduce((n, o) => {
|
|
1161
1161
|
const { parsed: i, error: r } = t.parse(o);
|
|
1162
1162
|
return r ? {
|
|
@@ -1198,9 +1198,9 @@ const Mn = 250, Bn = (t) => {
|
|
|
1198
1198
|
S.length > 0 && console.warn(`Discarded ${S.length} invalid annotations`, S), o.bulkAddAnnotation(y, d, k.REMOTE);
|
|
1199
1199
|
} else
|
|
1200
1200
|
o.bulkAddAnnotation(p, d, k.REMOTE);
|
|
1201
|
-
},
|
|
1201
|
+
}, x = (p, d) => {
|
|
1202
1202
|
p ? i.setSelected(p, d) : i.clear();
|
|
1203
|
-
},
|
|
1203
|
+
}, w = (p) => {
|
|
1204
1204
|
i.clear(), i.setUserSelectAction(p);
|
|
1205
1205
|
}, C = (p) => {
|
|
1206
1206
|
if (n) {
|
|
@@ -1224,8 +1224,8 @@ const Mn = 250, Bn = (t) => {
|
|
|
1224
1224
|
redo: e.redo,
|
|
1225
1225
|
removeAnnotation: g,
|
|
1226
1226
|
setAnnotations: u,
|
|
1227
|
-
setSelected:
|
|
1228
|
-
setUserSelectAction:
|
|
1227
|
+
setSelected: x,
|
|
1228
|
+
setUserSelectAction: w,
|
|
1229
1229
|
undo: e.undo,
|
|
1230
1230
|
updateAnnotation: C
|
|
1231
1231
|
};
|
|
@@ -1345,15 +1345,15 @@ const Lo = (t, e) => ({
|
|
|
1345
1345
|
updated: f,
|
|
1346
1346
|
...h
|
|
1347
1347
|
} = i, c = a.map((g) => {
|
|
1348
|
-
const { quote: u, start:
|
|
1348
|
+
const { quote: u, start: x, end: w, range: C } = g, { prefix: p, suffix: d } = Ne(C, n), y = [{
|
|
1349
1349
|
type: "TextQuoteSelector",
|
|
1350
1350
|
exact: u,
|
|
1351
1351
|
prefix: p,
|
|
1352
1352
|
suffix: d
|
|
1353
1353
|
}, {
|
|
1354
1354
|
type: "TextPositionSelector",
|
|
1355
|
-
start:
|
|
1356
|
-
end:
|
|
1355
|
+
start: x,
|
|
1356
|
+
end: w
|
|
1357
1357
|
}];
|
|
1358
1358
|
return {
|
|
1359
1359
|
...h,
|
|
@@ -1377,8 +1377,8 @@ const Lo = (t, e) => ({
|
|
|
1377
1377
|
function ge(t, e, n = 0, o = t.length - 1, i = qn) {
|
|
1378
1378
|
for (; o > n; ) {
|
|
1379
1379
|
if (o - n > 600) {
|
|
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)),
|
|
1381
|
-
ge(t, e, u,
|
|
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)), x = Math.min(o, Math.floor(e + (l - f) * c / l + g));
|
|
1381
|
+
ge(t, e, u, x, i);
|
|
1382
1382
|
}
|
|
1383
1383
|
const r = t[e];
|
|
1384
1384
|
let a = n, s = o;
|
|
@@ -1661,17 +1661,17 @@ const oo = (t, e) => {
|
|
|
1661
1661
|
const E = y.selector.flatMap((T) => {
|
|
1662
1662
|
const O = W([T]) ? T.range : se(T, e).range;
|
|
1663
1663
|
return Array.from(O.getClientRects());
|
|
1664
|
-
}),
|
|
1665
|
-
return
|
|
1666
|
-
const { x: O, y: R, width: m, height:
|
|
1664
|
+
}), b = Ke(E).map((T) => Pe(T, S));
|
|
1665
|
+
return b.map((T) => {
|
|
1666
|
+
const { x: O, y: R, width: m, height: A } = T;
|
|
1667
1667
|
return {
|
|
1668
1668
|
minX: O,
|
|
1669
1669
|
minY: R,
|
|
1670
1670
|
maxX: O + m,
|
|
1671
|
-
maxY: R +
|
|
1671
|
+
maxY: R + A,
|
|
1672
1672
|
annotation: {
|
|
1673
1673
|
id: y.annotation,
|
|
1674
|
-
rects:
|
|
1674
|
+
rects: b
|
|
1675
1675
|
}
|
|
1676
1676
|
};
|
|
1677
1677
|
});
|
|
@@ -1687,29 +1687,29 @@ const oo = (t, e) => {
|
|
|
1687
1687
|
f(y), l(y);
|
|
1688
1688
|
}, c = (y, S = !0) => {
|
|
1689
1689
|
S && s();
|
|
1690
|
-
const E = e.getBoundingClientRect(),
|
|
1691
|
-
|
|
1692
|
-
const T =
|
|
1690
|
+
const E = e.getBoundingClientRect(), b = y.map((O) => ({ target: O, rects: r(O, E) }));
|
|
1691
|
+
b.forEach(({ target: O, rects: R }) => o.set(O.annotation, R));
|
|
1692
|
+
const T = b.flatMap(({ rects: O }) => O);
|
|
1693
1693
|
n.load(T);
|
|
1694
1694
|
}, g = (y, S, E = !1) => {
|
|
1695
|
-
const
|
|
1695
|
+
const b = n.search({
|
|
1696
1696
|
minX: y,
|
|
1697
1697
|
minY: S,
|
|
1698
1698
|
maxX: y,
|
|
1699
1699
|
maxY: S
|
|
1700
1700
|
}), T = (O) => O.annotation.rects.reduce((R, m) => R + m.width * m.height, 0);
|
|
1701
|
-
return
|
|
1701
|
+
return b.length > 0 ? (b.sort((O, R) => T(O) - T(R)), E ? b.map((O) => O.annotation.id) : [b[0].annotation.id]) : [];
|
|
1702
1702
|
}, u = (y) => {
|
|
1703
|
-
const S =
|
|
1703
|
+
const S = x(y);
|
|
1704
1704
|
if (S.length === 0)
|
|
1705
1705
|
return;
|
|
1706
|
-
let E = S[0].left,
|
|
1706
|
+
let E = S[0].left, b = S[0].top, T = S[0].right, O = S[0].bottom;
|
|
1707
1707
|
for (let R = 1; R < S.length; R++) {
|
|
1708
1708
|
const m = S[R];
|
|
1709
|
-
E = Math.min(E, m.left),
|
|
1709
|
+
E = Math.min(E, m.left), b = Math.min(b, m.top), T = Math.max(T, m.right), O = Math.max(O, m.bottom);
|
|
1710
1710
|
}
|
|
1711
|
-
return new DOMRect(E,
|
|
1712
|
-
},
|
|
1711
|
+
return new DOMRect(E, b, T - E, O - b);
|
|
1712
|
+
}, x = (y) => {
|
|
1713
1713
|
const S = o.get(y);
|
|
1714
1714
|
return S ? S[0].annotation.rects : [];
|
|
1715
1715
|
};
|
|
@@ -1718,12 +1718,12 @@ const oo = (t, e) => {
|
|
|
1718
1718
|
clear: s,
|
|
1719
1719
|
getAt: g,
|
|
1720
1720
|
getAnnotationBounds: u,
|
|
1721
|
-
getAnnotationRects:
|
|
1722
|
-
getIntersecting: (y, S, E,
|
|
1723
|
-
const T = n.search({ minX: y, minY: S, maxX: E, maxY:
|
|
1721
|
+
getAnnotationRects: x,
|
|
1722
|
+
getIntersecting: (y, S, E, b) => {
|
|
1723
|
+
const T = n.search({ minX: y, minY: S, maxX: E, maxY: b }), O = new Set(T.map((R) => R.annotation.id));
|
|
1724
1724
|
return Array.from(O).map((R) => ({
|
|
1725
1725
|
annotation: t.getAnnotation(R),
|
|
1726
|
-
rects:
|
|
1726
|
+
rects: x(R)
|
|
1727
1727
|
})).filter((R) => !!R.annotation);
|
|
1728
1728
|
},
|
|
1729
1729
|
insert: l,
|
|
@@ -1743,12 +1743,12 @@ const oo = (t, e) => {
|
|
|
1743
1743
|
const S = wt(d, t), E = W(S.target.selector);
|
|
1744
1744
|
return E && n.addAnnotation(S, y), E;
|
|
1745
1745
|
}, l = (d, y = !0, S = k.LOCAL) => {
|
|
1746
|
-
const E = d.map((T) => wt(T, t)),
|
|
1747
|
-
return
|
|
1746
|
+
const E = d.map((T) => wt(T, t)), b = E.filter((T) => !W(T.target.selector));
|
|
1747
|
+
return b.length > 0 ? (console.warn("Could not revive all targets for these annotations:", b), n.bulkAddAnnotation(E, y, S), b) : (n.bulkAddAnnotation(E, y, S), []);
|
|
1748
1748
|
}, f = (d, y = k.LOCAL) => {
|
|
1749
|
-
const S = d.map((
|
|
1750
|
-
return E.length > 0 && console.warn("Could not revive all targets for these annotations:", E), S.forEach((
|
|
1751
|
-
n.getAnnotation(
|
|
1749
|
+
const S = d.map((b) => wt(b, t)), E = S.filter((b) => !W(b.target.selector));
|
|
1750
|
+
return E.length > 0 && console.warn("Could not revive all targets for these annotations:", E), S.forEach((b) => {
|
|
1751
|
+
n.getAnnotation(b.id) ? n.updateAnnotation(b, y) : n.addAnnotation(b, y);
|
|
1752
1752
|
}), E;
|
|
1753
1753
|
}, h = (d, y = k.LOCAL) => {
|
|
1754
1754
|
const S = bt(d, t);
|
|
@@ -1757,21 +1757,21 @@ const oo = (t, e) => {
|
|
|
1757
1757
|
const S = d.map((E) => bt(E, t));
|
|
1758
1758
|
n.bulkUpdateTargets(S, y);
|
|
1759
1759
|
}, g = (d, y, S) => {
|
|
1760
|
-
const E = o.getAt(d, y, !!S).map((T) => n.getAnnotation(T)),
|
|
1761
|
-
return
|
|
1760
|
+
const E = o.getAt(d, y, !!S).map((T) => n.getAnnotation(T)), b = S ? E.filter(S) : E;
|
|
1761
|
+
return b.length > 0 ? b[0] : void 0;
|
|
1762
1762
|
}, u = (d, y, S, E = 5) => {
|
|
1763
|
-
const
|
|
1764
|
-
if (
|
|
1763
|
+
const b = o.getAnnotationRects(d);
|
|
1764
|
+
if (b.length !== 0) {
|
|
1765
1765
|
if (y && S) {
|
|
1766
|
-
const T =
|
|
1766
|
+
const T = b.find(({ top: O, right: R, bottom: m, left: A }) => y >= A - E && y <= R + E && S >= O - E && S <= m + E);
|
|
1767
1767
|
if (T) return T;
|
|
1768
1768
|
}
|
|
1769
1769
|
return o.getAnnotationBounds(d);
|
|
1770
1770
|
}
|
|
1771
|
-
},
|
|
1771
|
+
}, x = (d, y, S, E) => o.getIntersecting(d, y, S, E), w = (d) => o.getAnnotationRects(d), C = () => o.recalculate(), p = (d) => o.on("recalculate", d);
|
|
1772
1772
|
return n.observe(({ changes: d }) => {
|
|
1773
|
-
const y = (d.deleted || []).filter((
|
|
1774
|
-
(y == null ? void 0 : y.length) > 0 && y.forEach((
|
|
1773
|
+
const y = (d.deleted || []).filter((b) => W(b.target.selector)), S = (d.created || []).filter((b) => W(b.target.selector)), E = (d.updated || []).filter((b) => W(b.newValue.target.selector));
|
|
1774
|
+
(y == null ? void 0 : y.length) > 0 && y.forEach((b) => o.remove(b.target)), S.length > 0 && o.set(S.map((b) => b.target), !1), (E == null ? void 0 : E.length) > 0 && E.forEach(({ newValue: b }) => o.update(b.target));
|
|
1775
1775
|
}), {
|
|
1776
1776
|
store: {
|
|
1777
1777
|
...n,
|
|
@@ -1780,8 +1780,8 @@ const oo = (t, e) => {
|
|
|
1780
1780
|
bulkUpdateTargets: c,
|
|
1781
1781
|
bulkUpsertAnnotations: f,
|
|
1782
1782
|
getAnnotationBounds: u,
|
|
1783
|
-
getAnnotationRects:
|
|
1784
|
-
getIntersecting:
|
|
1783
|
+
getAnnotationRects: w,
|
|
1784
|
+
getIntersecting: x,
|
|
1785
1785
|
getAt: g,
|
|
1786
1786
|
recalculatePositions: C,
|
|
1787
1787
|
onRecalculatePositions: p,
|
|
@@ -2005,8 +2005,8 @@ const mt = (t) => {
|
|
|
2005
2005
|
n || (n = at());
|
|
2006
2006
|
const c = l > 1 ? pe(H, s) : [], g = [];
|
|
2007
2007
|
N[h] = N[h].filter((u) => {
|
|
2008
|
-
const
|
|
2009
|
-
return
|
|
2008
|
+
const w = (o ? u.method === o : !0) && u.scope === n && ro(u.mods, c);
|
|
2009
|
+
return w && g.push(u.element), !w;
|
|
2010
2010
|
}), g.forEach((u) => Kt(u));
|
|
2011
2011
|
});
|
|
2012
2012
|
};
|
|
@@ -2072,17 +2072,17 @@ function $(t, e, n) {
|
|
|
2072
2072
|
if (typeof a < "u" && window) {
|
|
2073
2073
|
if (!F.has(a)) {
|
|
2074
2074
|
const u = function() {
|
|
2075
|
-
let
|
|
2076
|
-
return ee(
|
|
2077
|
-
},
|
|
2078
|
-
let
|
|
2079
|
-
ee(
|
|
2075
|
+
let w = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
|
|
2076
|
+
return ee(w, a);
|
|
2077
|
+
}, x = function() {
|
|
2078
|
+
let w = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
|
|
2079
|
+
ee(w, a), po(w);
|
|
2080
2080
|
};
|
|
2081
2081
|
F.set(a, {
|
|
2082
2082
|
keydownListener: u,
|
|
2083
|
-
keyupListenr:
|
|
2083
|
+
keyupListenr: x,
|
|
2084
2084
|
capture: c
|
|
2085
|
-
}), Mt(a, "keydown", u, c), Mt(a, "keyup",
|
|
2085
|
+
}), Mt(a, "keydown", u, c), Mt(a, "keyup", x, c);
|
|
2086
2086
|
}
|
|
2087
2087
|
if (!rt) {
|
|
2088
2088
|
const u = () => {
|
|
@@ -2156,24 +2156,24 @@ if (typeof window < "u") {
|
|
|
2156
2156
|
}
|
|
2157
2157
|
const ne = 300, yo = (t, e, n) => {
|
|
2158
2158
|
let o;
|
|
2159
|
-
const i = (
|
|
2159
|
+
const i = (b) => o = b;
|
|
2160
2160
|
let r;
|
|
2161
|
-
const a = (
|
|
2161
|
+
const a = (b) => r = b;
|
|
2162
2162
|
let s = !0;
|
|
2163
|
-
const l = (
|
|
2164
|
-
s =
|
|
2163
|
+
const l = (b) => {
|
|
2164
|
+
s = b, w.clear(), b || (c = void 0, g = void 0, u = void 0);
|
|
2165
2165
|
}, { store: f, selection: h } = e;
|
|
2166
2166
|
let c, g, u;
|
|
2167
|
-
const
|
|
2167
|
+
const x = (b) => {
|
|
2168
2168
|
var O;
|
|
2169
2169
|
if (!s || g === !1) return;
|
|
2170
|
-
c = !((O =
|
|
2170
|
+
c = !((O = b.target.parentElement) != null && O.closest(j)) ? {
|
|
2171
2171
|
annotation: de(),
|
|
2172
2172
|
selector: [],
|
|
2173
2173
|
creator: o,
|
|
2174
2174
|
created: /* @__PURE__ */ new Date()
|
|
2175
2175
|
} : void 0;
|
|
2176
|
-
},
|
|
2176
|
+
}, w = Ut((b) => {
|
|
2177
2177
|
var B, M;
|
|
2178
2178
|
if (!s) return;
|
|
2179
2179
|
const T = document.getSelection();
|
|
@@ -2181,62 +2181,61 @@ const ne = 300, yo = (t, e, n) => {
|
|
|
2181
2181
|
c = void 0;
|
|
2182
2182
|
return;
|
|
2183
2183
|
}
|
|
2184
|
-
const R =
|
|
2185
|
-
if ((u == null ? void 0 : u.type) === "pointerdown" && (R < 1e3 && !c || T.isCollapsed && R < ne) &&
|
|
2184
|
+
const R = b.timeStamp - ((u == null ? void 0 : u.timeStamp) || b.timeStamp);
|
|
2185
|
+
if ((u == null ? void 0 : u.type) === "pointerdown" && (R < 1e3 && !c || T.isCollapsed && R < ne) && x(u), !c) return;
|
|
2186
2186
|
if (T.isCollapsed) {
|
|
2187
2187
|
f.getAnnotation(c.annotation) && (h.clear(), f.deleteAnnotation(c.annotation));
|
|
2188
2188
|
return;
|
|
2189
2189
|
}
|
|
2190
|
-
const m = T.getRangeAt(0),
|
|
2191
|
-
if (Ue(
|
|
2192
|
-
const
|
|
2193
|
-
(
|
|
2190
|
+
const m = T.getRangeAt(0), A = Xe(m, t);
|
|
2191
|
+
if (Ue(A)) return;
|
|
2192
|
+
const v = Te(A.cloneRange());
|
|
2193
|
+
(v.length !== c.selector.length || v.some((K, Y) => {
|
|
2194
2194
|
var lt;
|
|
2195
2195
|
return K.toString() !== ((lt = c.selector[Y]) == null ? void 0 : lt.quote);
|
|
2196
2196
|
})) && (c = {
|
|
2197
2197
|
...c,
|
|
2198
|
-
selector:
|
|
2198
|
+
selector: v.map((K) => Ye(K, t, n)),
|
|
2199
2199
|
updated: /* @__PURE__ */ new Date()
|
|
2200
2200
|
}, f.getAnnotation(c.annotation) ? f.updateTarget(c, k.LOCAL) : (h.clear(), f.addAnnotation({
|
|
2201
2201
|
id: c.annotation,
|
|
2202
2202
|
bodies: [],
|
|
2203
2203
|
target: c
|
|
2204
2204
|
}, k.LOCAL), h.userSelect(c.annotation, u)));
|
|
2205
|
-
}), C = (
|
|
2206
|
-
u = $e(
|
|
2207
|
-
}, p = (
|
|
2208
|
-
var
|
|
2209
|
-
|
|
2205
|
+
}), C = (b) => {
|
|
2206
|
+
u = $e(b), g = u.button === 0;
|
|
2207
|
+
}, p = (b) => {
|
|
2208
|
+
var A;
|
|
2209
|
+
const T = b.target;
|
|
2210
|
+
if (!!((A = T.parentElement) != null && A.closest(j)) || !g)
|
|
2210
2211
|
return;
|
|
2211
|
-
const
|
|
2212
|
-
const { x: v, y:
|
|
2213
|
-
if (
|
|
2214
|
-
const { selected:
|
|
2215
|
-
(
|
|
2212
|
+
const R = () => {
|
|
2213
|
+
const { x: v, y: L } = t.getBoundingClientRect(), B = b.target instanceof Node && t.contains(b.target) && f.getAt(b.clientX - v, b.clientY - L, r);
|
|
2214
|
+
if (B) {
|
|
2215
|
+
const { selected: M } = h;
|
|
2216
|
+
(M.length !== 1 || M[0].id !== B.id) && h.userSelect(B.id, b);
|
|
2216
2217
|
} else h.isEmpty() || h.clear();
|
|
2217
|
-
};
|
|
2218
|
-
document.getSelection();
|
|
2219
|
-
const R = w.timeStamp - u.timeStamp;
|
|
2218
|
+
}, m = b.timeStamp - u.timeStamp;
|
|
2220
2219
|
setTimeout(() => {
|
|
2221
2220
|
const v = document.getSelection();
|
|
2222
|
-
v != null && v.isCollapsed &&
|
|
2221
|
+
v != null && v.isCollapsed && m < ne ? T !== document.documentElement && (c = void 0, R()) : c && f.getAnnotation(c.annotation) && h.userSelect(c.annotation, b);
|
|
2223
2222
|
});
|
|
2224
2223
|
};
|
|
2225
|
-
document.addEventListener("pointerdown", C), document.addEventListener("pointerup", p), t.addEventListener("selectstart",
|
|
2224
|
+
document.addEventListener("pointerdown", C), document.addEventListener("pointerup", p), t.addEventListener("selectstart", x), document.addEventListener("selectionchange", w);
|
|
2226
2225
|
const d = ["up", "down", "left", "right"], y = [
|
|
2227
|
-
...d.map((
|
|
2226
|
+
...d.map((b) => `shift+${b}`),
|
|
2228
2227
|
"ctrl+a",
|
|
2229
2228
|
"⌘+a"
|
|
2230
2229
|
];
|
|
2231
|
-
$(y.join(","), { element: t, keydown: !0, keyup: !1 }, (
|
|
2232
|
-
|
|
2230
|
+
$(y.join(","), { element: t, keydown: !0, keyup: !1 }, (b) => {
|
|
2231
|
+
b.repeat || (u = je(b));
|
|
2233
2232
|
});
|
|
2234
|
-
const S = (
|
|
2235
|
-
|
|
2233
|
+
const S = (b) => {
|
|
2234
|
+
b.repeat || b.target !== t && b.target !== document.body || (c = void 0, h.clear());
|
|
2236
2235
|
};
|
|
2237
2236
|
return $(d.join(","), { keydown: !0, keyup: !1 }, S), {
|
|
2238
2237
|
destroy: () => {
|
|
2239
|
-
c = void 0, g = void 0, u = void 0,
|
|
2238
|
+
c = void 0, g = void 0, u = void 0, w.clear(), document.removeEventListener("pointerdown", C), document.removeEventListener("pointerup", p), t.removeEventListener("selectstart", x), document.removeEventListener("selectionchange", w), $.unbind();
|
|
2240
2239
|
},
|
|
2241
2240
|
setFilter: a,
|
|
2242
2241
|
setUser: i,
|
|
@@ -2252,7 +2251,7 @@ const ne = 300, yo = (t, e, n) => {
|
|
|
2252
2251
|
document.body.appendChild(o);
|
|
2253
2252
|
const r = /* @__PURE__ */ new Map(), a = (c) => Array.from(r.entries()).filter(([g, u]) => u.presenceKey === c.presenceKey).map(([g, u]) => g);
|
|
2254
2253
|
return e.on("selectionChange", (c, g) => {
|
|
2255
|
-
a(c).forEach((
|
|
2254
|
+
a(c).forEach((x) => r.delete(x)), g && g.forEach((x) => r.set(x, c));
|
|
2256
2255
|
}), {
|
|
2257
2256
|
clear: () => {
|
|
2258
2257
|
const { width: c, height: g } = o;
|
|
@@ -2263,13 +2262,13 @@ const ne = 300, yo = (t, e, n) => {
|
|
|
2263
2262
|
},
|
|
2264
2263
|
paint: (c, g, u) => {
|
|
2265
2264
|
n.font && (i.font = n.font);
|
|
2266
|
-
const
|
|
2267
|
-
if (
|
|
2268
|
-
const { height:
|
|
2269
|
-
i.fillStyle =
|
|
2270
|
-
const d = i.measureText(
|
|
2271
|
-
return i.fillRect(C - 2, p - 2.5 - S, y, S), i.fillStyle = "#fff", i.fillText(
|
|
2272
|
-
fill:
|
|
2265
|
+
const x = r.get(c.annotation.id);
|
|
2266
|
+
if (x) {
|
|
2267
|
+
const { height: w } = c.rects[0], C = c.rects[0].x + g.left, p = c.rects[0].y + g.top;
|
|
2268
|
+
i.fillStyle = x.appearance.color, i.fillRect(C - 2, p - 2.5, 2, w + 5);
|
|
2269
|
+
const d = i.measureText(x.appearance.label), y = d.width + 6, S = d.actualBoundingBoxAscent + d.actualBoundingBoxDescent + 8, E = d.fontBoundingBoxAscent ? 8 : 6.5;
|
|
2270
|
+
return i.fillRect(C - 2, p - 2.5 - S, y, S), i.fillStyle = "#fff", i.fillText(x.appearance.label, C + 1, p - E), {
|
|
2271
|
+
fill: x.appearance.color,
|
|
2273
2272
|
fillOpacity: u ? 0.45 : 0.18
|
|
2274
2273
|
};
|
|
2275
2274
|
}
|
|
@@ -2287,7 +2286,7 @@ const ne = 300, yo = (t, e, n) => {
|
|
|
2287
2286
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ve(t.parentElement);
|
|
2288
2287
|
}, vo = (t, e) => (n) => {
|
|
2289
2288
|
const o = typeof n == "string" ? n : n.id, i = (a) => {
|
|
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,
|
|
2289
|
+
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, x = h.left - s.left, w = r.parentElement ? r.scrollTop : 0, C = r.parentElement ? r.scrollLeft : 0, p = u + w - (l - g) / 2, d = x + C - (f - c) / 2;
|
|
2291
2290
|
r.scroll({ top: p, left: d, behavior: "smooth" });
|
|
2292
2291
|
}, r = ve(t);
|
|
2293
2292
|
if (r) {
|
|
@@ -2318,7 +2317,7 @@ const ne = 300, yo = (t, e, n) => {
|
|
|
2318
2317
|
console.debug(`Using ${h} renderer`), n.style && c.setStyle(n.style);
|
|
2319
2318
|
const g = yo(t, o, n.offsetReferenceSelector);
|
|
2320
2319
|
g.setUser(f), g.setAnnotatingEnabled(n.annotatingEnabled);
|
|
2321
|
-
const u = _n(o, s, n.adapter),
|
|
2320
|
+
const u = _n(o, s, n.adapter), x = () => f, w = (E) => {
|
|
2322
2321
|
g.setAnnotatingEnabled(
|
|
2323
2322
|
E === void 0 ? !0 : E
|
|
2324
2323
|
);
|
|
@@ -2337,8 +2336,8 @@ const ne = 300, yo = (t, e, n) => {
|
|
|
2337
2336
|
c.destroy(), g.destroy(), s.destroy();
|
|
2338
2337
|
},
|
|
2339
2338
|
element: t,
|
|
2340
|
-
getUser:
|
|
2341
|
-
setAnnotatingEnabled:
|
|
2339
|
+
getUser: x,
|
|
2340
|
+
setAnnotatingEnabled: w,
|
|
2342
2341
|
setFilter: C,
|
|
2343
2342
|
setStyle: c.setStyle.bind(c),
|
|
2344
2343
|
redraw: c.redraw.bind(c),
|