@soomo/text-annotator 3.1.0-staging.13 → 3.1.0-staging.14
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.
|
@@ -109,9 +109,9 @@ const ae = "not-annotatable", Z = `.${ae}`, nt = (t) => {
|
|
|
109
109
|
const { start: n, end: o } = t, i = t.offsetReference || e, s = document.createNodeIterator(
|
|
110
110
|
e,
|
|
111
111
|
NodeFilter.SHOW_TEXT,
|
|
112
|
-
(
|
|
112
|
+
(m) => {
|
|
113
113
|
var p;
|
|
114
|
-
return (p =
|
|
114
|
+
return (p = m.parentElement) != null && p.closest(Z) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
|
|
115
115
|
}
|
|
116
116
|
);
|
|
117
117
|
let r = 0;
|
|
@@ -121,22 +121,22 @@ const ae = "not-annotatable", Z = `.${ae}`, nt = (t) => {
|
|
|
121
121
|
let c = !i;
|
|
122
122
|
for (; l !== null; ) {
|
|
123
123
|
if (c || (c = i == null ? void 0 : i.contains(l)), c) {
|
|
124
|
-
const
|
|
125
|
-
if (r +
|
|
124
|
+
const m = ((f = l.textContent) == null ? void 0 : f.length) || 0;
|
|
125
|
+
if (r + m > n) {
|
|
126
126
|
a.setStart(l, n - r);
|
|
127
127
|
break;
|
|
128
128
|
}
|
|
129
|
-
r +=
|
|
129
|
+
r += m;
|
|
130
130
|
}
|
|
131
131
|
l = s.nextNode();
|
|
132
132
|
}
|
|
133
133
|
for (; l !== null; ) {
|
|
134
|
-
const
|
|
135
|
-
if (r +
|
|
134
|
+
const m = ((d = l.textContent) == null ? void 0 : d.length) || 0;
|
|
135
|
+
if (r + m >= o) {
|
|
136
136
|
a.setEnd(l, o - r);
|
|
137
137
|
break;
|
|
138
138
|
}
|
|
139
|
-
r +=
|
|
139
|
+
r += m, l = s.nextNode();
|
|
140
140
|
}
|
|
141
141
|
return {
|
|
142
142
|
...t,
|
|
@@ -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:
|
|
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, w = f.left - a.left, b = s.parentElement ? s.scrollTop : 0, C = s.parentElement ? s.scrollLeft : 0, g = p + b - (l - m) / 2, u = w + C - (c - d) / 2;
|
|
217
217
|
s.scroll({ top: g, left: u, behavior: "smooth" });
|
|
218
218
|
}, s = de(t);
|
|
219
219
|
if (s) {
|
|
@@ -250,17 +250,17 @@ function ue(t, e = 100, n = {}) {
|
|
|
250
250
|
const { immediate: o } = typeof n == "boolean" ? { immediate: n } : n;
|
|
251
251
|
let i, s, r, a, l;
|
|
252
252
|
function c() {
|
|
253
|
-
const
|
|
254
|
-
return i = void 0, s = void 0, l = t.apply(
|
|
253
|
+
const m = i, p = s;
|
|
254
|
+
return i = void 0, s = void 0, l = t.apply(m, p), l;
|
|
255
255
|
}
|
|
256
256
|
function f() {
|
|
257
|
-
const
|
|
258
|
-
|
|
257
|
+
const m = Date.now() - a;
|
|
258
|
+
m < e && m >= 0 ? r = setTimeout(f, e - m) : (r = void 0, o || (l = c()));
|
|
259
259
|
}
|
|
260
|
-
const d = function(...
|
|
260
|
+
const d = function(...m) {
|
|
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
|
-
i = this, s =
|
|
263
|
+
i = this, s = m, a = Date.now();
|
|
264
264
|
const p = o && !r;
|
|
265
265
|
return r || (r = setTimeout(f, e)), p && (l = c()), l;
|
|
266
266
|
};
|
|
@@ -288,41 +288,41 @@ 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
|
|
291
|
+
const { x, y: h } = t.getBoundingClientRect(), v = i.getAt(T.clientX - x, T.clientY - h, 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
|
-
const
|
|
295
|
+
const m = (T = !1) => {
|
|
296
296
|
c && c.clear();
|
|
297
|
-
const
|
|
297
|
+
const x = qe(t), { minX: h, minY: v, maxX: A, maxY: L } = x, M = l ? i.getIntersecting(h, v, A, L).filter(({ annotation: Y }) => l(Y)) : i.getIntersecting(h, v, A, 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, x, a, c, T), setTimeout(() => f(M.map(({ annotation: Y }) => Y)), 1);
|
|
302
302
|
}, p = (T) => {
|
|
303
|
-
c = T,
|
|
303
|
+
c = T, m();
|
|
304
304
|
}, w = (T) => {
|
|
305
|
-
a = T,
|
|
305
|
+
a = T, m();
|
|
306
306
|
}, b = (T) => {
|
|
307
|
-
l = T,
|
|
308
|
-
}, C = () =>
|
|
307
|
+
l = T, m(!1);
|
|
308
|
+
}, C = () => m();
|
|
309
309
|
i.observe(C);
|
|
310
|
-
const g = s.subscribe(() =>
|
|
310
|
+
const g = s.subscribe(() => m()), u = () => m(!0);
|
|
311
311
|
document.addEventListener("scroll", u, { capture: !0, passive: !0 });
|
|
312
|
-
const
|
|
313
|
-
i.recalculatePositions(), c == null || c.reset(),
|
|
312
|
+
const y = Kt(() => {
|
|
313
|
+
i.recalculatePositions(), c == null || c.reset(), m();
|
|
314
314
|
}, 10);
|
|
315
|
-
window.addEventListener("resize",
|
|
316
|
-
const S = new ResizeObserver(
|
|
315
|
+
window.addEventListener("resize", y);
|
|
316
|
+
const S = new ResizeObserver(y);
|
|
317
317
|
S.observe(t);
|
|
318
|
-
const
|
|
319
|
-
T.every((h) => h.target === t || t.contains(h.target)) ||
|
|
318
|
+
const E = { attributes: !0, childList: !0, subtree: !0 }, O = new MutationObserver((T) => {
|
|
319
|
+
T.every((h) => h.target === t || t.contains(h.target)) || m(!0);
|
|
320
320
|
});
|
|
321
|
-
return O.observe(document.body,
|
|
321
|
+
return O.observe(document.body, E), {
|
|
322
322
|
destroy: () => {
|
|
323
|
-
t.removeEventListener("pointermove", d), o.destroy(), i.unobserve(C), g(), document.removeEventListener("scroll", u),
|
|
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
|
-
redraw:
|
|
325
|
+
redraw: m,
|
|
326
326
|
setStyle: w,
|
|
327
327
|
setFilter: b,
|
|
328
328
|
setPainter: p,
|
|
@@ -338,27 +338,27 @@ const Kt = /* @__PURE__ */ Fe(We), qe = (t) => {
|
|
|
338
338
|
const e = Qe(), n = e.getContext("2d");
|
|
339
339
|
document.body.appendChild(e);
|
|
340
340
|
const o = (a, l, c, f) => requestAnimationFrame(() => {
|
|
341
|
-
const { width: d, height:
|
|
342
|
-
n.clearRect(-0.5, -0.5, d + 1,
|
|
341
|
+
const { width: d, height: m } = e;
|
|
342
|
+
n.clearRect(-0.5, -0.5, d + 1, m + 1), f && f.clear();
|
|
343
343
|
const { top: p, left: w } = l;
|
|
344
344
|
[...a].sort((C, g) => {
|
|
345
|
-
const { annotation: { target: { created: u } } } = C, { annotation: { target: { created:
|
|
346
|
-
return u.getTime() -
|
|
345
|
+
const { annotation: { target: { created: u } } } = C, { annotation: { target: { created: y } } } = g;
|
|
346
|
+
return u.getTime() - y.getTime();
|
|
347
347
|
}).forEach((C) => {
|
|
348
348
|
var S;
|
|
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,
|
|
350
|
-
x:
|
|
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 + w,
|
|
351
351
|
y: O + p,
|
|
352
352
|
width: R,
|
|
353
353
|
height: T
|
|
354
354
|
}));
|
|
355
|
-
if (n.fillStyle = u.fill, n.globalAlpha = u.fillOpacity || 1,
|
|
356
|
-
({ x, y: O, width: R, height: T }) => n.fillRect(
|
|
355
|
+
if (n.fillStyle = u.fill, n.globalAlpha = u.fillOpacity || 1, y.forEach(
|
|
356
|
+
({ x: E, y: O, width: R, height: T }) => n.fillRect(E, O, R, T)
|
|
357
357
|
), u.underlineColor) {
|
|
358
358
|
n.globalAlpha = 1, n.strokeStyle = u.underlineColor, n.lineWidth = u.underlineThickness ?? 1;
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
n.beginPath(), n.moveTo(O, R +
|
|
359
|
+
const E = u.underlineOffset ?? 0;
|
|
360
|
+
y.forEach(({ x: O, y: R, width: T, height: x }) => {
|
|
361
|
+
n.beginPath(), n.moveTo(O, R + x + E), n.lineTo(O + T, R + x + E), n.stroke();
|
|
362
362
|
});
|
|
363
363
|
}
|
|
364
364
|
});
|
|
@@ -526,12 +526,12 @@ const ln = (t) => [
|
|
|
526
526
|
Array.from(e).filter((d) => !c.has(d));
|
|
527
527
|
const f = s.map((d) => {
|
|
528
528
|
var w;
|
|
529
|
-
const
|
|
529
|
+
const m = a ? typeof a == "function" ? a(d.annotation, d.state) : a : (w = d.state) != null && w.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
|
|
534
|
+
const m = d.target.selector.map((w) => w.range), p = new Highlight(...m);
|
|
535
535
|
CSS.highlights.set(`_${d.id}`, p);
|
|
536
536
|
}), e = c;
|
|
537
537
|
}
|
|
@@ -571,15 +571,15 @@ const fn = (t, e) => {
|
|
|
571
571
|
e.remove();
|
|
572
572
|
},
|
|
573
573
|
redraw: (r, a, l, c, f) => {
|
|
574
|
-
const
|
|
575
|
-
if (!c && !
|
|
576
|
-
|
|
574
|
+
const m = !(Ut(n, r) && f);
|
|
575
|
+
if (!c && !m) return;
|
|
576
|
+
m && (e.innerHTML = ""), [...r].sort((w, b) => {
|
|
577
577
|
const { annotation: { target: { created: C } } } = w, { annotation: { target: { created: g } } } = b;
|
|
578
578
|
return C && g ? C.getTime() - g.getTime() : 0;
|
|
579
579
|
}).forEach((w) => {
|
|
580
580
|
w.rects.map((b) => {
|
|
581
581
|
const C = fn(b, r), g = ze(w, a, l, c, C);
|
|
582
|
-
if (
|
|
582
|
+
if (m) {
|
|
583
583
|
const u = document.createElement("span");
|
|
584
584
|
u.className = "r6o-annotation", u.dataset.annotation = w.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
|
}
|
|
@@ -719,18 +719,18 @@ const ht = { selected: [] }, xn = (t, e, n) => {
|
|
|
719
719
|
const C = Array.isArray(w) ? w : [w], g = C.map((u) => t.getAnnotation(u)).filter((u) => !!u);
|
|
720
720
|
i({
|
|
721
721
|
selected: g.map((u) => {
|
|
722
|
-
const
|
|
723
|
-
return { id: u.id, editable:
|
|
722
|
+
const y = b === void 0 ? te(u, s) === "EDIT" : b;
|
|
723
|
+
return { id: u.id, editable: y };
|
|
724
724
|
})
|
|
725
725
|
}), g.length !== C.length && console.warn("Invalid selection", w);
|
|
726
|
-
},
|
|
726
|
+
}, m = (w) => {
|
|
727
727
|
if (l())
|
|
728
728
|
return !1;
|
|
729
729
|
const { selected: b } = r;
|
|
730
730
|
b.some(({ id: C }) => w.includes(C)) && i({ selected: b.filter(({ id: C }) => !w.includes(C)) });
|
|
731
731
|
}, p = (w) => s = w;
|
|
732
732
|
return t.observe(
|
|
733
|
-
({ changes: w }) =>
|
|
733
|
+
({ changes: w }) => m((w.deleted || []).map((b) => b.id))
|
|
734
734
|
), {
|
|
735
735
|
get event() {
|
|
736
736
|
return r ? r.event : null;
|
|
@@ -834,17 +834,17 @@ const Bn = (t, e) => {
|
|
|
834
834
|
return !0;
|
|
835
835
|
}, kn = (t, e) => {
|
|
836
836
|
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 = [
|
|
837
|
-
...(t.created || []).filter((d) => !s.has(d.id)).map((d) => r.has(d.id) ? e.updated.find(({ oldValue:
|
|
837
|
+
...(t.created || []).filter((d) => !s.has(d.id)).map((d) => r.has(d.id) ? e.updated.find(({ oldValue: m }) => m.id === d.id).newValue : d),
|
|
838
838
|
...e.created || []
|
|
839
839
|
], c = [
|
|
840
840
|
...(t.deleted || []).filter((d) => !i.has(d.id)),
|
|
841
841
|
...(e.deleted || []).filter((d) => !n.has(d.id))
|
|
842
842
|
], f = [
|
|
843
843
|
...(t.updated || []).filter(({ newValue: d }) => !s.has(d.id)).map((d) => {
|
|
844
|
-
const { oldValue:
|
|
844
|
+
const { oldValue: m, newValue: p } = d;
|
|
845
845
|
if (r.has(p.id)) {
|
|
846
846
|
const w = e.updated.find((b) => b.oldValue.id === p.id).newValue;
|
|
847
|
-
return ye(
|
|
847
|
+
return ye(m, w);
|
|
848
848
|
} else
|
|
849
849
|
return d;
|
|
850
850
|
}),
|
|
@@ -921,7 +921,7 @@ const Bn = (t, e) => {
|
|
|
921
921
|
}] });
|
|
922
922
|
} else
|
|
923
923
|
console.warn(`Attempt to add body to missing annotation: ${h.annotation}`);
|
|
924
|
-
}, d = () => [...t.values()],
|
|
924
|
+
}, d = () => [...t.values()], m = (h = k.LOCAL) => {
|
|
925
925
|
const v = [...t.values()];
|
|
926
926
|
t.clear(), e.clear(), s(h, { deleted: v });
|
|
927
927
|
}, p = (h, v = !0, A = k.LOCAL) => {
|
|
@@ -978,13 +978,13 @@ const Bn = (t, e) => {
|
|
|
978
978
|
}, u = (h, v = k.LOCAL) => {
|
|
979
979
|
const A = g(h);
|
|
980
980
|
A && s(v, { updated: [A] });
|
|
981
|
-
},
|
|
981
|
+
}, y = (h, v = k.LOCAL) => {
|
|
982
982
|
const A = h.map((L) => g(L)).filter(Boolean);
|
|
983
983
|
A.length > 0 && s(v, { updated: A });
|
|
984
984
|
}, S = (h) => {
|
|
985
985
|
const v = t.get(h);
|
|
986
986
|
return v ? { ...v } : void 0;
|
|
987
|
-
},
|
|
987
|
+
}, E = (h) => {
|
|
988
988
|
const v = e.get(h);
|
|
989
989
|
if (v) {
|
|
990
990
|
const A = S(v).bodies.find((L) => L.id === h);
|
|
@@ -1015,7 +1015,7 @@ const Bn = (t, e) => {
|
|
|
1015
1015
|
}, T = (h, v = k.LOCAL) => {
|
|
1016
1016
|
const A = h.map((L) => O({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
|
|
1017
1017
|
s(v, { updated: A });
|
|
1018
|
-
},
|
|
1018
|
+
}, x = (h) => {
|
|
1019
1019
|
const v = t.get(h.annotation);
|
|
1020
1020
|
if (v) {
|
|
1021
1021
|
const A = {
|
|
@@ -1042,24 +1042,24 @@ const Bn = (t, e) => {
|
|
|
1042
1042
|
all: d,
|
|
1043
1043
|
bulkAddAnnotation: p,
|
|
1044
1044
|
bulkDeleteAnnotation: C,
|
|
1045
|
-
bulkDeleteBodies:
|
|
1045
|
+
bulkDeleteBodies: y,
|
|
1046
1046
|
bulkUpdateAnnotation: c,
|
|
1047
1047
|
bulkUpdateBodies: T,
|
|
1048
1048
|
bulkUpdateTargets: (h, v = k.LOCAL) => {
|
|
1049
|
-
const A = h.map((L) =>
|
|
1049
|
+
const A = h.map((L) => x(L)).filter(Boolean);
|
|
1050
1050
|
A.length > 0 && s(v, { updated: A });
|
|
1051
1051
|
},
|
|
1052
|
-
clear:
|
|
1052
|
+
clear: m,
|
|
1053
1053
|
deleteAnnotation: b,
|
|
1054
1054
|
deleteBody: u,
|
|
1055
1055
|
getAnnotation: S,
|
|
1056
|
-
getBody:
|
|
1056
|
+
getBody: E,
|
|
1057
1057
|
observe: o,
|
|
1058
1058
|
unobserve: i,
|
|
1059
1059
|
updateAnnotation: l,
|
|
1060
1060
|
updateBody: R,
|
|
1061
1061
|
updateTarget: (h, v = k.LOCAL) => {
|
|
1062
|
-
const A =
|
|
1062
|
+
const A = x(h);
|
|
1063
1063
|
A && s(v, { updated: [A] });
|
|
1064
1064
|
}
|
|
1065
1065
|
};
|
|
@@ -1095,7 +1095,7 @@ const Un = 250, Dn = (t) => {
|
|
|
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: w }) => w)), f = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: w }) => w)), d = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1),
|
|
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: w }) => w)), f = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: w }) => w)), 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,
|
|
@@ -1105,7 +1105,7 @@ const Un = 250, Dn = (t) => {
|
|
|
1105
1105
|
if (n.length - 1 > o) {
|
|
1106
1106
|
i = !0;
|
|
1107
1107
|
const { created: p, updated: w, deleted: b } = n[o + 1];
|
|
1108
|
-
l(p), f(w),
|
|
1108
|
+
l(p), f(w), m(b), e.emit("redo", n[o + 1]), o += 1;
|
|
1109
1109
|
}
|
|
1110
1110
|
},
|
|
1111
1111
|
undo: () => {
|
|
@@ -1127,7 +1127,7 @@ const Un = 250, Dn = (t) => {
|
|
|
1127
1127
|
let c = [], f;
|
|
1128
1128
|
const d = (b, C) => {
|
|
1129
1129
|
l.has(b) ? l.get(b).push(C) : l.set(b, [C]);
|
|
1130
|
-
},
|
|
1130
|
+
}, m = (b, C) => {
|
|
1131
1131
|
const g = l.get(b);
|
|
1132
1132
|
if (g) {
|
|
1133
1133
|
const u = g.indexOf(C);
|
|
@@ -1137,8 +1137,8 @@ const Un = 250, Dn = (t) => {
|
|
|
1137
1137
|
l.has(b) && setTimeout(() => {
|
|
1138
1138
|
l.get(b).forEach((u) => {
|
|
1139
1139
|
if (n) {
|
|
1140
|
-
const
|
|
1141
|
-
u(
|
|
1140
|
+
const y = Array.isArray(C) ? C.map((E) => n.serialize(E)) : n.serialize(C), S = g ? g instanceof PointerEvent ? g : n.serialize(g) : void 0;
|
|
1141
|
+
u(y, S);
|
|
1142
1142
|
} else
|
|
1143
1143
|
u(C, g);
|
|
1144
1144
|
});
|
|
@@ -1156,8 +1156,8 @@ const Un = 250, Dn = (t) => {
|
|
|
1156
1156
|
else {
|
|
1157
1157
|
const C = new Set(c.map((u) => u.id)), g = new Set(b.map(({ id: u }) => u));
|
|
1158
1158
|
c.filter((u) => !g.has(u.id)).forEach((u) => {
|
|
1159
|
-
const
|
|
1160
|
-
|
|
1159
|
+
const y = r.getAnnotation(u.id);
|
|
1160
|
+
y && !q(y, u) && p("updateAnnotation", y, u);
|
|
1161
1161
|
}), c = [
|
|
1162
1162
|
// Remove annotations that were deselected
|
|
1163
1163
|
...c.filter((u) => g.has(u.id)),
|
|
@@ -1175,9 +1175,9 @@ const Un = 250, Dn = (t) => {
|
|
|
1175
1175
|
...u.bodiesCreated || [],
|
|
1176
1176
|
...u.bodiesDeleted || [],
|
|
1177
1177
|
...u.bodiesUpdated || []
|
|
1178
|
-
].length > 0).forEach(({ oldValue: u, newValue:
|
|
1179
|
-
const S = c.find((
|
|
1180
|
-
c = c.map((
|
|
1178
|
+
].length > 0).forEach(({ oldValue: u, newValue: y }) => {
|
|
1179
|
+
const S = c.find((E) => E.id === u.id) || u;
|
|
1180
|
+
c = c.map((E) => E.id === u.id ? y : E), p("updateAnnotation", y, S);
|
|
1181
1181
|
});
|
|
1182
1182
|
}, { origin: k.LOCAL }), r.observe((b) => {
|
|
1183
1183
|
if (c) {
|
|
@@ -1189,7 +1189,7 @@ const Un = 250, Dn = (t) => {
|
|
|
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", w(!0)), e.on("redo", w(!1)), { on: d, off:
|
|
1192
|
+
return e.on("undo", w(!0)), e.on("redo", w(!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 ? {
|
|
@@ -1204,8 +1204,8 @@ const Un = 250, Dn = (t) => {
|
|
|
1204
1204
|
}, { parsed: [], failed: [] }), Xn = (t, e, n) => {
|
|
1205
1205
|
const { store: o, selection: i } = t, s = (g) => {
|
|
1206
1206
|
if (n) {
|
|
1207
|
-
const { parsed: u, error:
|
|
1208
|
-
u ? o.addAnnotation(u, k.REMOTE) : console.error(
|
|
1207
|
+
const { parsed: u, error: y } = n.parse(g);
|
|
1208
|
+
u ? o.addAnnotation(u, k.REMOTE) : console.error(y);
|
|
1209
1209
|
} else
|
|
1210
1210
|
o.addAnnotation(Tt(g), k.REMOTE);
|
|
1211
1211
|
}, r = () => i.clear(), a = () => o.clear(), l = (g) => {
|
|
@@ -1213,9 +1213,9 @@ const Un = 250, Dn = (t) => {
|
|
|
1213
1213
|
return n && u ? n.serialize(u) : u;
|
|
1214
1214
|
}, c = () => n ? o.all().map(n.serialize) : o.all(), f = () => {
|
|
1215
1215
|
var g;
|
|
1216
|
-
const u = (((g = i.selected) == null ? void 0 : g.map((
|
|
1216
|
+
const u = (((g = i.selected) == null ? void 0 : g.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
|
|
1217
1217
|
return n ? u.map(n.serialize) : u;
|
|
1218
|
-
}, d = (g, u = !0) => fetch(g).then((
|
|
1218
|
+
}, d = (g, u = !0) => fetch(g).then((y) => y.json()).then((y) => (p(y, u), y)), m = (g) => {
|
|
1219
1219
|
if (typeof g == "string") {
|
|
1220
1220
|
const u = o.getAnnotation(g);
|
|
1221
1221
|
if (o.deleteAnnotation(g), u)
|
|
@@ -1227,8 +1227,8 @@ const Un = 250, Dn = (t) => {
|
|
|
1227
1227
|
}
|
|
1228
1228
|
}, p = (g, u = !0) => {
|
|
1229
1229
|
if (n) {
|
|
1230
|
-
const
|
|
1231
|
-
|
|
1230
|
+
const y = n.parseAll || Yn(n), { parsed: S, failed: E } = y(g);
|
|
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
|
}, w = (g, u) => {
|
|
@@ -1237,8 +1237,8 @@ const Un = 250, Dn = (t) => {
|
|
|
1237
1237
|
i.clear(), i.setUserSelectAction(g);
|
|
1238
1238
|
}, C = (g) => {
|
|
1239
1239
|
if (n) {
|
|
1240
|
-
const u = n.parse(g).parsed,
|
|
1241
|
-
return o.updateAnnotation(u),
|
|
1240
|
+
const u = n.parse(g).parsed, y = n.serialize(o.getAnnotation(u.id));
|
|
1241
|
+
return o.updateAnnotation(u), y;
|
|
1242
1242
|
} else {
|
|
1243
1243
|
const u = o.getAnnotation(g.id);
|
|
1244
1244
|
return o.updateAnnotation(Tt(g)), u;
|
|
@@ -1255,7 +1255,7 @@ const Un = 250, Dn = (t) => {
|
|
|
1255
1255
|
getSelected: f,
|
|
1256
1256
|
loadAnnotations: d,
|
|
1257
1257
|
redo: e.redo,
|
|
1258
|
-
removeAnnotation:
|
|
1258
|
+
removeAnnotation: m,
|
|
1259
1259
|
setAnnotations: p,
|
|
1260
1260
|
setSelected: w,
|
|
1261
1261
|
setUserSelectAction: b,
|
|
@@ -1329,26 +1329,30 @@ const ko = (t, e) => ({
|
|
|
1329
1329
|
updated: i ? new Date(i) : void 0,
|
|
1330
1330
|
annotation: e,
|
|
1331
1331
|
selector: [],
|
|
1332
|
-
|
|
1332
|
+
// @ts-expect-error: `styleClass` is not part of the core `TextAnnotationTarget` type
|
|
1333
|
+
styleClass: "styleClass" in r[0] ? r[0].styleClass : void 0
|
|
1333
1334
|
};
|
|
1334
1335
|
for (const l of r) {
|
|
1335
|
-
const f = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((d,
|
|
1336
|
-
switch (
|
|
1336
|
+
const f = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((d, m) => {
|
|
1337
|
+
switch (m.type) {
|
|
1337
1338
|
case "TextQuoteSelector":
|
|
1338
|
-
d.quote =
|
|
1339
|
+
d.quote = m.exact;
|
|
1339
1340
|
break;
|
|
1340
1341
|
case "TextPositionSelector":
|
|
1341
|
-
d.start =
|
|
1342
|
+
d.start = m.start, d.end = m.end;
|
|
1342
1343
|
break;
|
|
1343
1344
|
}
|
|
1344
1345
|
return d;
|
|
1345
1346
|
}, {});
|
|
1346
1347
|
if (Qn(f))
|
|
1347
|
-
a.selector.push(
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1348
|
+
a.selector.push(
|
|
1349
|
+
{
|
|
1350
|
+
...f,
|
|
1351
|
+
id: l.id,
|
|
1352
|
+
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
1353
|
+
scope: l.scope
|
|
1354
|
+
}
|
|
1355
|
+
);
|
|
1352
1356
|
else {
|
|
1353
1357
|
const d = [
|
|
1354
1358
|
f.start ? void 0 : "TextPositionSelector",
|
|
@@ -1381,23 +1385,24 @@ const ko = (t, e) => ({
|
|
|
1381
1385
|
created: l,
|
|
1382
1386
|
updated: c,
|
|
1383
1387
|
...f
|
|
1384
|
-
} = i, d = r.map((
|
|
1385
|
-
const { id: p,
|
|
1388
|
+
} = i, d = r.map((m) => {
|
|
1389
|
+
const { id: p, quote: w, start: b, end: C, range: g } = m, { prefix: u, suffix: y } = _e(g, n), S = [{
|
|
1390
|
+
type: "TextQuoteSelector",
|
|
1391
|
+
exact: w,
|
|
1392
|
+
prefix: u,
|
|
1393
|
+
suffix: y
|
|
1394
|
+
}, {
|
|
1395
|
+
type: "TextPositionSelector",
|
|
1396
|
+
start: b,
|
|
1397
|
+
end: C
|
|
1398
|
+
}];
|
|
1386
1399
|
return {
|
|
1387
1400
|
...f,
|
|
1388
1401
|
id: p,
|
|
1389
|
-
|
|
1402
|
+
// @ts-expect-error: `scope` is not part of the core `TextAnnotationTarget` type
|
|
1403
|
+
scope: "scope" in m ? m.scope : void 0,
|
|
1390
1404
|
source: e,
|
|
1391
|
-
selector:
|
|
1392
|
-
type: "TextQuoteSelector",
|
|
1393
|
-
exact: b,
|
|
1394
|
-
prefix: m,
|
|
1395
|
-
suffix: S
|
|
1396
|
-
}, {
|
|
1397
|
-
type: "TextPositionSelector",
|
|
1398
|
-
start: C,
|
|
1399
|
-
end: g
|
|
1400
|
-
}]
|
|
1405
|
+
selector: S
|
|
1401
1406
|
};
|
|
1402
1407
|
});
|
|
1403
1408
|
return {
|
|
@@ -1415,7 +1420,7 @@ const ko = (t, e) => ({
|
|
|
1415
1420
|
function we(t, e, n = 0, o = t.length - 1, i = eo) {
|
|
1416
1421
|
for (; o > n; ) {
|
|
1417
1422
|
if (o - n > 600) {
|
|
1418
|
-
const l = o - n + 1, c = e - n + 1, f = Math.log(l), d = 0.5 * Math.exp(2 * f / 3),
|
|
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)), w = Math.min(o, Math.floor(e + (l - c) * d / l + m));
|
|
1419
1424
|
we(t, e, p, w, i);
|
|
1420
1425
|
}
|
|
1421
1426
|
const s = t[e];
|
|
@@ -1545,9 +1550,9 @@ class no {
|
|
|
1545
1550
|
for (let f = n; f <= o; f += c) {
|
|
1546
1551
|
const d = Math.min(f + c - 1, o);
|
|
1547
1552
|
ne(e, f, d, l, this.compareMinY);
|
|
1548
|
-
for (let
|
|
1549
|
-
const p = Math.min(
|
|
1550
|
-
a.children.push(this._build(e,
|
|
1553
|
+
for (let m = f; m <= d; m += l) {
|
|
1554
|
+
const p = Math.min(m + l - 1, d);
|
|
1555
|
+
a.children.push(this._build(e, m, p, i - 1));
|
|
1551
1556
|
}
|
|
1552
1557
|
}
|
|
1553
1558
|
return Q(a, this.toBBox), a;
|
|
@@ -1695,121 +1700,121 @@ let co = () => ({
|
|
|
1695
1700
|
}
|
|
1696
1701
|
});
|
|
1697
1702
|
const lo = (t, e) => {
|
|
1698
|
-
const n = new no(), o = /* @__PURE__ */ new Map(), i = co(), s = (
|
|
1699
|
-
const
|
|
1703
|
+
const n = new no(), o = /* @__PURE__ */ new Map(), i = co(), s = (y, S) => {
|
|
1704
|
+
const E = y.selector.flatMap((R) => {
|
|
1700
1705
|
const T = F([R]) ? R.range : ce(R, e).range;
|
|
1701
1706
|
return Array.from(T.getClientRects());
|
|
1702
|
-
}), O = Ye(
|
|
1707
|
+
}), O = Ye(E).map((R) => je(R, S));
|
|
1703
1708
|
return O.map((R) => {
|
|
1704
|
-
const { x: T, y:
|
|
1709
|
+
const { x: T, y: x, width: h, height: v } = R;
|
|
1705
1710
|
return {
|
|
1706
1711
|
minX: T,
|
|
1707
|
-
minY:
|
|
1712
|
+
minY: x,
|
|
1708
1713
|
maxX: T + h,
|
|
1709
|
-
maxY:
|
|
1714
|
+
maxY: x + v,
|
|
1710
1715
|
annotation: {
|
|
1711
|
-
id:
|
|
1716
|
+
id: y.annotation,
|
|
1712
1717
|
rects: O
|
|
1713
1718
|
}
|
|
1714
1719
|
};
|
|
1715
1720
|
});
|
|
1716
1721
|
}, r = () => [...o.values()], a = () => {
|
|
1717
1722
|
n.clear(), o.clear();
|
|
1718
|
-
}, l = (
|
|
1719
|
-
const S = s(
|
|
1720
|
-
S.forEach((
|
|
1721
|
-
}, c = (
|
|
1722
|
-
const S = o.get(
|
|
1723
|
-
S && (S.forEach((
|
|
1724
|
-
}, f = (
|
|
1725
|
-
c(
|
|
1726
|
-
}, d = (
|
|
1723
|
+
}, l = (y) => {
|
|
1724
|
+
const S = s(y, e.getBoundingClientRect());
|
|
1725
|
+
S.forEach((E) => n.insert(E)), o.set(y.annotation, S);
|
|
1726
|
+
}, c = (y) => {
|
|
1727
|
+
const S = o.get(y.annotation);
|
|
1728
|
+
S && (S.forEach((E) => n.remove(E)), o.delete(y.annotation));
|
|
1729
|
+
}, f = (y) => {
|
|
1730
|
+
c(y), l(y);
|
|
1731
|
+
}, d = (y, S = !0) => {
|
|
1727
1732
|
S && a();
|
|
1728
|
-
const
|
|
1729
|
-
O.forEach(({ target: T, rects:
|
|
1733
|
+
const E = e.getBoundingClientRect(), O = y.map((T) => ({ target: T, rects: s(T, E) }));
|
|
1734
|
+
O.forEach(({ target: T, rects: x }) => o.set(T.annotation, x));
|
|
1730
1735
|
const R = O.flatMap(({ rects: T }) => T);
|
|
1731
1736
|
n.load(R);
|
|
1732
|
-
},
|
|
1737
|
+
}, m = (y, S, E = !1) => {
|
|
1733
1738
|
const O = n.search({
|
|
1734
|
-
minX:
|
|
1739
|
+
minX: y,
|
|
1735
1740
|
minY: S,
|
|
1736
|
-
maxX:
|
|
1741
|
+
maxX: y,
|
|
1737
1742
|
maxY: S
|
|
1738
|
-
}), R = (T) => T.annotation.rects.reduce((
|
|
1739
|
-
return O.length > 0 ? (O.sort((T,
|
|
1740
|
-
}, p = (
|
|
1741
|
-
const S = w(
|
|
1743
|
+
}), R = (T) => T.annotation.rects.reduce((x, h) => x + h.width * h.height, 0);
|
|
1744
|
+
return O.length > 0 ? (O.sort((T, x) => R(T) - R(x)), E ? O.map((T) => T.annotation.id) : [O[0].annotation.id]) : [];
|
|
1745
|
+
}, p = (y) => {
|
|
1746
|
+
const S = w(y);
|
|
1742
1747
|
if (S.length === 0)
|
|
1743
1748
|
return;
|
|
1744
|
-
let
|
|
1745
|
-
for (let
|
|
1746
|
-
const h = S[
|
|
1747
|
-
|
|
1749
|
+
let E = S[0].left, O = S[0].top, R = S[0].right, T = S[0].bottom;
|
|
1750
|
+
for (let x = 1; x < S.length; x++) {
|
|
1751
|
+
const h = S[x];
|
|
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);
|
|
1748
1753
|
}
|
|
1749
|
-
return new DOMRect(
|
|
1750
|
-
}, w = (
|
|
1751
|
-
const S = o.get(
|
|
1754
|
+
return new DOMRect(E, O, R - E, T - O);
|
|
1755
|
+
}, w = (y) => {
|
|
1756
|
+
const S = o.get(y);
|
|
1752
1757
|
return S[0] ? S[0].annotation.rects : [];
|
|
1753
1758
|
};
|
|
1754
1759
|
return {
|
|
1755
1760
|
all: r,
|
|
1756
1761
|
clear: a,
|
|
1757
|
-
getAt:
|
|
1762
|
+
getAt: m,
|
|
1758
1763
|
getAnnotationBounds: p,
|
|
1759
1764
|
getAnnotationRects: w,
|
|
1760
|
-
getIntersecting: (
|
|
1761
|
-
const R = n.search({ minX:
|
|
1762
|
-
return Array.from(T).map((
|
|
1763
|
-
annotation: t.getAnnotation(
|
|
1764
|
-
rects: w(
|
|
1765
|
-
})).filter((
|
|
1765
|
+
getIntersecting: (y, S, E, O) => {
|
|
1766
|
+
const R = n.search({ minX: y, minY: S, maxX: E, maxY: O }), T = new Set(R.map((x) => x.annotation.id));
|
|
1767
|
+
return Array.from(T).map((x) => ({
|
|
1768
|
+
annotation: t.getAnnotation(x),
|
|
1769
|
+
rects: w(x)
|
|
1770
|
+
})).filter((x) => !!x.annotation);
|
|
1766
1771
|
},
|
|
1767
1772
|
insert: l,
|
|
1768
1773
|
recalculate: () => {
|
|
1769
|
-
d(t.all().map((
|
|
1774
|
+
d(t.all().map((y) => y.target), !0), i.emit("recalculate");
|
|
1770
1775
|
},
|
|
1771
1776
|
remove: c,
|
|
1772
1777
|
set: d,
|
|
1773
1778
|
size: () => n.all().length,
|
|
1774
1779
|
update: f,
|
|
1775
|
-
on: (
|
|
1780
|
+
on: (y, S) => i.on(y, S)
|
|
1776
1781
|
};
|
|
1777
1782
|
}, uo = (t, e) => {
|
|
1778
1783
|
const n = Nn(), o = lo(n, t), i = xn(n);
|
|
1779
1784
|
i.setUserSelectAction(e);
|
|
1780
|
-
const s = vn(n), r = Vn(), a = (u,
|
|
1781
|
-
const S = vt(u, t),
|
|
1782
|
-
return
|
|
1783
|
-
}, l = (u,
|
|
1784
|
-
const
|
|
1785
|
-
return O.length > 0 ? (console.warn("Could not revive all targets for these annotations:", O), n.bulkAddAnnotation(
|
|
1786
|
-
}, c = (u,
|
|
1787
|
-
const S = u.map((O) => vt(O, t)),
|
|
1788
|
-
return
|
|
1789
|
-
n.getAnnotation(O.id) ? n.updateAnnotation(O,
|
|
1790
|
-
}),
|
|
1791
|
-
}, f = (u,
|
|
1785
|
+
const s = vn(n), r = Vn(), a = (u, y = k.LOCAL) => {
|
|
1786
|
+
const S = vt(u, t), E = F(S.target.selector);
|
|
1787
|
+
return E && n.addAnnotation(S, y), E;
|
|
1788
|
+
}, l = (u, y = !0, S = k.LOCAL) => {
|
|
1789
|
+
const E = u.map((R) => vt(R, t)), O = E.filter((R) => !F(R.target.selector));
|
|
1790
|
+
return O.length > 0 ? (console.warn("Could not revive all targets for these annotations:", O), n.bulkAddAnnotation(E, y, S), O) : (n.bulkAddAnnotation(E, y, S), []);
|
|
1791
|
+
}, c = (u, y = k.LOCAL) => {
|
|
1792
|
+
const S = u.map((O) => vt(O, t)), E = S.filter((O) => !F(O.target.selector));
|
|
1793
|
+
return E.length > 0 && console.warn("Could not revive all targets for these annotations:", E), S.forEach((O) => {
|
|
1794
|
+
n.getAnnotation(O.id) ? n.updateAnnotation(O, y) : n.addAnnotation(O, y);
|
|
1795
|
+
}), E;
|
|
1796
|
+
}, f = (u, y = k.LOCAL) => {
|
|
1792
1797
|
const S = bt(u, t);
|
|
1793
|
-
n.updateTarget(S,
|
|
1794
|
-
}, d = (u,
|
|
1795
|
-
const S = u.map((
|
|
1796
|
-
n.bulkUpdateTargets(S,
|
|
1797
|
-
},
|
|
1798
|
-
const
|
|
1798
|
+
n.updateTarget(S, y);
|
|
1799
|
+
}, d = (u, y = k.LOCAL) => {
|
|
1800
|
+
const S = u.map((E) => bt(E, t));
|
|
1801
|
+
n.bulkUpdateTargets(S, y);
|
|
1802
|
+
}, m = (u, y, S) => {
|
|
1803
|
+
const E = o.getAt(u, y, !!S).map((R) => n.getAnnotation(R)), O = S ? E.filter(S) : E;
|
|
1799
1804
|
return O.length > 0 ? O[0] : void 0;
|
|
1800
|
-
}, p = (u,
|
|
1805
|
+
}, p = (u, y, S, E = 5) => {
|
|
1801
1806
|
const O = o.getAnnotationRects(u);
|
|
1802
1807
|
if (O.length !== 0) {
|
|
1803
|
-
if (
|
|
1804
|
-
const R = O.find(({ top: T, right:
|
|
1808
|
+
if (y && S) {
|
|
1809
|
+
const R = O.find(({ top: T, right: x, bottom: h, left: v }) => y >= v - E && y <= x + E && S >= T - E && S <= h + E);
|
|
1805
1810
|
if (R) return R;
|
|
1806
1811
|
}
|
|
1807
1812
|
return o.getAnnotationBounds(u);
|
|
1808
1813
|
}
|
|
1809
|
-
}, w = (u,
|
|
1814
|
+
}, w = (u, y, S, E) => o.getIntersecting(u, y, S, E), b = (u) => o.getAnnotationRects(u), C = () => o.recalculate(), g = (u) => o.on("recalculate", u);
|
|
1810
1815
|
return n.observe(({ changes: u }) => {
|
|
1811
|
-
const
|
|
1812
|
-
(
|
|
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
|
+
(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));
|
|
1813
1818
|
}), {
|
|
1814
1819
|
store: {
|
|
1815
1820
|
...n,
|
|
@@ -1820,7 +1825,7 @@ const lo = (t, e) => {
|
|
|
1820
1825
|
getAnnotationBounds: p,
|
|
1821
1826
|
getAnnotationRects: b,
|
|
1822
1827
|
getIntersecting: w,
|
|
1823
|
-
getAt:
|
|
1828
|
+
getAt: m,
|
|
1824
1829
|
recalculatePositions: C,
|
|
1825
1830
|
onRecalculatePositions: g,
|
|
1826
1831
|
updateTarget: f
|
|
@@ -1837,7 +1842,7 @@ const lo = (t, e) => {
|
|
|
1837
1842
|
}, ho = (t, e = {}) => {
|
|
1838
1843
|
const n = fo(), o = n.getContext("2d");
|
|
1839
1844
|
document.body.appendChild(n);
|
|
1840
|
-
const i = /* @__PURE__ */ new Map(), s = (f) => Array.from(i.entries()).filter(([d,
|
|
1845
|
+
const i = /* @__PURE__ */ new Map(), s = (f) => Array.from(i.entries()).filter(([d, m]) => m.presenceKey === f.presenceKey).map(([d, m]) => d);
|
|
1841
1846
|
return t.on("selectionChange", (f, d) => {
|
|
1842
1847
|
s(f).forEach((p) => i.delete(p)), d && d.forEach((p) => i.set(p, f));
|
|
1843
1848
|
}), {
|
|
@@ -1848,16 +1853,16 @@ const lo = (t, e) => {
|
|
|
1848
1853
|
destroy: () => {
|
|
1849
1854
|
n.remove();
|
|
1850
1855
|
},
|
|
1851
|
-
paint: (f, d,
|
|
1856
|
+
paint: (f, d, m) => {
|
|
1852
1857
|
e.font && (o.font = e.font);
|
|
1853
1858
|
const p = i.get(f.annotation.id);
|
|
1854
1859
|
if (p) {
|
|
1855
1860
|
const { height: w } = f.rects[0], b = f.rects[0].x + d.left, C = f.rects[0].y + d.top;
|
|
1856
1861
|
o.fillStyle = p.appearance.color, o.fillRect(b - 2, C - 2.5, 2, w + 5);
|
|
1857
|
-
const g = o.measureText(p.appearance.label), u = g.width + 6,
|
|
1858
|
-
return o.fillRect(b - 2, C - 2.5 -
|
|
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
|
+
return o.fillRect(b - 2, C - 2.5 - y, u, y), o.fillStyle = "#fff", o.fillText(p.appearance.label, b + 1, C - S), {
|
|
1859
1864
|
fill: p.appearance.color,
|
|
1860
|
-
fillOpacity:
|
|
1865
|
+
fillOpacity: m ? 0.45 : 0.18
|
|
1861
1866
|
};
|
|
1862
1867
|
}
|
|
1863
1868
|
},
|
|
@@ -2079,11 +2084,11 @@ const yt = (t) => {
|
|
|
2079
2084
|
const a = r.split(i), l = a.length, c = a[l - 1], f = c === "*" ? "*" : lt(c);
|
|
2080
2085
|
if (!N[f]) return;
|
|
2081
2086
|
n || (n = ct());
|
|
2082
|
-
const d = l > 1 ? ve(j, a) : [],
|
|
2087
|
+
const d = l > 1 ? ve(j, a) : [], m = [];
|
|
2083
2088
|
N[f] = N[f].filter((p) => {
|
|
2084
2089
|
const b = (o ? p.method === o : !0) && p.scope === n && po(p.mods, d);
|
|
2085
|
-
return b &&
|
|
2086
|
-
}),
|
|
2090
|
+
return b && m.push(p.element), !b;
|
|
2091
|
+
}), m.forEach((p) => Pt(p));
|
|
2087
2092
|
});
|
|
2088
2093
|
};
|
|
2089
2094
|
function oe(t, e, n, o) {
|
|
@@ -2124,16 +2129,16 @@ function ie(t, e) {
|
|
|
2124
2129
|
const l = s[a], {
|
|
2125
2130
|
splitKey: c
|
|
2126
2131
|
} = l, f = l.key.split(c), d = [];
|
|
2127
|
-
for (let
|
|
2128
|
-
d.push(lt(f[
|
|
2132
|
+
for (let m = 0; m < f.length; m++)
|
|
2133
|
+
d.push(lt(f[m]));
|
|
2129
2134
|
d.sort().join("") === I.sort().join("") && oe(t, l, i, e);
|
|
2130
2135
|
}
|
|
2131
2136
|
}
|
|
2132
2137
|
function P(t, e, n) {
|
|
2133
2138
|
I = [];
|
|
2134
2139
|
const o = Ae(t);
|
|
2135
|
-
let i = [], s = "all", r = document, a = 0, l = !1, c = !0, f = "+", d = !1,
|
|
2136
|
-
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 && (c = e.keydown), e.capture !== void 0 && (d = e.capture), typeof e.splitKey == "string" && (f = e.splitKey), e.single === !0 && (
|
|
2140
|
+
let i = [], s = "all", r = document, a = 0, l = !1, c = !0, f = "+", d = !1, m = !1;
|
|
2141
|
+
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 && (c = e.keydown), e.capture !== void 0 && (d = e.capture), typeof e.splitKey == "string" && (f = e.splitKey), e.single === !0 && (m = !0)), typeof e == "string" && (s = e), m && Se(t, s); a < o.length; a++)
|
|
2137
2142
|
t = o[a].split(f), i = [], t.length > 1 && (i = ve(j, t)), t = t[t.length - 1], t = t === "*" ? "*" : lt(t), t in N || (N[t] = []), N[t].push({
|
|
2138
2143
|
keyup: l,
|
|
2139
2144
|
keydown: c,
|
|
@@ -2243,21 +2248,21 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
|
|
|
2243
2248
|
], Oo = (t, e, n) => {
|
|
2244
2249
|
const { store: o, selection: i } = e;
|
|
2245
2250
|
let s;
|
|
2246
|
-
const r = (
|
|
2251
|
+
const r = (x) => s = x;
|
|
2247
2252
|
let a;
|
|
2248
|
-
const l = (
|
|
2249
|
-
let c, f, d,
|
|
2250
|
-
const p = (
|
|
2251
|
-
|
|
2252
|
-
}, w = (
|
|
2253
|
-
f !== !1 && (c = nt(
|
|
2253
|
+
const l = (x) => a = x;
|
|
2254
|
+
let c, f, d, m = !0;
|
|
2255
|
+
const p = (x) => {
|
|
2256
|
+
m = x, b.clear(), x || (c = void 0, d = void 0);
|
|
2257
|
+
}, w = (x) => {
|
|
2258
|
+
m && f !== !1 && (c = nt(x.target) ? void 0 : {
|
|
2254
2259
|
annotation: ge(),
|
|
2255
2260
|
selector: [],
|
|
2256
2261
|
creator: s,
|
|
2257
2262
|
created: /* @__PURE__ */ new Date()
|
|
2258
2263
|
});
|
|
2259
|
-
}, b = Kt((
|
|
2260
|
-
if (!
|
|
2264
|
+
}, b = Kt((x) => {
|
|
2265
|
+
if (!m) return;
|
|
2261
2266
|
const h = document.getSelection();
|
|
2262
2267
|
if (!(h != null && h.anchorNode))
|
|
2263
2268
|
return;
|
|
@@ -2265,8 +2270,8 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
|
|
|
2265
2270
|
c = void 0;
|
|
2266
2271
|
return;
|
|
2267
2272
|
}
|
|
2268
|
-
const v =
|
|
2269
|
-
if ((d == null ? void 0 : d.type) === "pointerdown" && (v < 1e3 && !c || h.isCollapsed && v < se) && w(d ||
|
|
2273
|
+
const v = x.timeStamp - ((d == null ? void 0 : d.timeStamp) || x.timeStamp);
|
|
2274
|
+
if ((d == null ? void 0 : d.type) === "pointerdown" && (v < 1e3 && !c || h.isCollapsed && v < se) && w(d || x), !c) return;
|
|
2270
2275
|
if (h.isCollapsed) {
|
|
2271
2276
|
o.getAnnotation(c.annotation) && (i.clear(), o.deleteAnnotation(c.annotation));
|
|
2272
2277
|
return;
|
|
@@ -2282,64 +2287,64 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
|
|
|
2282
2287
|
selector: M.map((K) => Xe(K, t, n)),
|
|
2283
2288
|
updated: /* @__PURE__ */ new Date()
|
|
2284
2289
|
}, o.getAnnotation(c.annotation) ? o.updateTarget(c, k.LOCAL) : i.clear());
|
|
2285
|
-
}, 10), C = (
|
|
2286
|
-
nt(
|
|
2290
|
+
}, 10), C = (x) => {
|
|
2291
|
+
nt(x.target) || (d = At(x), f = d.button === 0);
|
|
2287
2292
|
}, g = () => {
|
|
2288
2293
|
o.getAnnotation(c.annotation) ? o.updateTarget(c) : o.addAnnotation({
|
|
2289
2294
|
id: c.annotation,
|
|
2290
2295
|
bodies: [],
|
|
2291
2296
|
target: c
|
|
2292
2297
|
});
|
|
2293
|
-
}, u = async (
|
|
2294
|
-
if (nt(
|
|
2298
|
+
}, u = async (x) => {
|
|
2299
|
+
if (nt(x.target) || !f) return;
|
|
2295
2300
|
const h = () => {
|
|
2296
|
-
const { x: A, y: L } = t.getBoundingClientRect(), M =
|
|
2301
|
+
const { x: A, y: L } = t.getBoundingClientRect(), M = x.target instanceof Node && t.contains(x.target) && o.getAt(x.clientX - A, x.clientY - L, a);
|
|
2297
2302
|
if (M) {
|
|
2298
2303
|
const { selected: B } = i;
|
|
2299
|
-
(B.length !== 1 || B[0].id !== M.id) && i.userSelect(M.id,
|
|
2304
|
+
(B.length !== 1 || B[0].id !== M.id) && i.userSelect(M.id, x);
|
|
2300
2305
|
} else
|
|
2301
2306
|
i.clear();
|
|
2302
2307
|
};
|
|
2303
|
-
if (
|
|
2304
|
-
await
|
|
2308
|
+
if (x.timeStamp - d.timeStamp < se) {
|
|
2309
|
+
await y();
|
|
2305
2310
|
const A = document.getSelection();
|
|
2306
2311
|
if (A != null && A.isCollapsed) {
|
|
2307
2312
|
c = void 0, h();
|
|
2308
2313
|
return;
|
|
2309
2314
|
}
|
|
2310
2315
|
}
|
|
2311
|
-
c && c.selector.length > 0 && (i.clear(), g(), i.userSelect(c.annotation, At(
|
|
2312
|
-
},
|
|
2313
|
-
const
|
|
2314
|
-
let h = !1, v =
|
|
2316
|
+
c && c.selector.length > 0 && (i.clear(), g(), i.userSelect(c.annotation, At(x)));
|
|
2317
|
+
}, y = async () => {
|
|
2318
|
+
const x = document.getSelection();
|
|
2319
|
+
let h = !1, v = x == null ? void 0 : x.isCollapsed;
|
|
2315
2320
|
const A = () => v || h, L = 1;
|
|
2316
|
-
return setTimeout(() => h = !0, 50), Co(() => v =
|
|
2317
|
-
}, S = (
|
|
2321
|
+
return setTimeout(() => h = !0, 50), Co(() => v = x == null ? void 0 : x.isCollapsed, L, A);
|
|
2322
|
+
}, S = (x) => {
|
|
2318
2323
|
const h = document.getSelection();
|
|
2319
|
-
h != null && h.isCollapsed || ((!c || c.selector.length === 0) && b(
|
|
2320
|
-
},
|
|
2321
|
-
|
|
2322
|
-
}, O = (
|
|
2324
|
+
h != null && h.isCollapsed || ((!c || c.selector.length === 0) && b(x), g(), i.userSelect(c.annotation, At(x)));
|
|
2325
|
+
}, E = (x) => {
|
|
2326
|
+
m && x.key === "Shift" && c && (document.getSelection().isCollapsed || (i.clear(), g(), i.userSelect(c.annotation, ut(x))));
|
|
2327
|
+
}, O = (x) => {
|
|
2323
2328
|
const h = () => setTimeout(() => {
|
|
2324
2329
|
(c == null ? void 0 : c.selector.length) > 0 && (i.clear(), o.addAnnotation({
|
|
2325
2330
|
id: c.annotation,
|
|
2326
2331
|
bodies: [],
|
|
2327
2332
|
target: c
|
|
2328
|
-
}), i.userSelect(c.annotation, ut(
|
|
2333
|
+
}), i.userSelect(c.annotation, ut(x))), document.removeEventListener("selectionchange", h);
|
|
2329
2334
|
}, 100);
|
|
2330
|
-
document.addEventListener("selectionchange", h), w(
|
|
2335
|
+
document.addEventListener("selectionchange", h), w(x);
|
|
2331
2336
|
};
|
|
2332
|
-
P(Lo.join(","), { element: t, keydown: !0, keyup: !1 }, (
|
|
2333
|
-
|
|
2334
|
-
}), P(Le, { keydown: !0, keyup: !1 }, (
|
|
2335
|
-
d = ut(
|
|
2337
|
+
P(Lo.join(","), { element: t, keydown: !0, keyup: !1 }, (x) => {
|
|
2338
|
+
x.repeat || (d = ut(x));
|
|
2339
|
+
}), P(Le, { keydown: !0, keyup: !1 }, (x) => {
|
|
2340
|
+
d = ut(x), O(x);
|
|
2336
2341
|
});
|
|
2337
|
-
const R = (
|
|
2338
|
-
|
|
2342
|
+
const R = (x) => {
|
|
2343
|
+
x.repeat || x.target !== t && x.target !== document.body || (c = void 0, i.clear());
|
|
2339
2344
|
};
|
|
2340
|
-
return P(Ce.join(","), { keydown: !0, keyup: !1 }, R), document.addEventListener("pointerdown", C), document.addEventListener("pointerup", u), document.addEventListener("contextmenu", S), t.addEventListener("keyup",
|
|
2345
|
+
return P(Ce.join(","), { keydown: !0, keyup: !1 }, R), document.addEventListener("pointerdown", C), document.addEventListener("pointerup", u), document.addEventListener("contextmenu", S), t.addEventListener("keyup", E), t.addEventListener("selectstart", w), document.addEventListener("selectionchange", b), {
|
|
2341
2346
|
destroy: () => {
|
|
2342
|
-
c = void 0, f = void 0, d = void 0, b.clear(), document.removeEventListener("pointerdown", C), document.removeEventListener("pointerup", u), document.removeEventListener("contextmenu", S), t.removeEventListener("keyup",
|
|
2347
|
+
c = void 0, f = void 0, d = void 0, b.clear(), document.removeEventListener("pointerdown", C), document.removeEventListener("pointerup", u), document.removeEventListener("contextmenu", S), t.removeEventListener("keyup", E), t.removeEventListener("selectstart", w), document.removeEventListener("selectionchange", b), P.unbind();
|
|
2343
2348
|
},
|
|
2344
2349
|
setFilter: l,
|
|
2345
2350
|
setUser: r,
|
|
@@ -2360,25 +2365,25 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
|
|
|
2360
2365
|
if (!d)
|
|
2361
2366
|
throw `Unknown renderer implementation: ${f}`;
|
|
2362
2367
|
console.debug(`Using ${f} renderer`), n.style && d.setStyle(n.style);
|
|
2363
|
-
const
|
|
2364
|
-
|
|
2365
|
-
const p = Xn(o, a, n.adapter), w = () => c, b = (
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
+
const m = Oo(t, o, n.offsetReferenceSelector);
|
|
2369
|
+
m.setUser(c), m.setAnnotatingEnabled(n.annotatingEnabled);
|
|
2370
|
+
const p = Xn(o, a, n.adapter), w = () => c, b = (E) => {
|
|
2371
|
+
m.setAnnotatingEnabled(
|
|
2372
|
+
E === void 0 ? !0 : E
|
|
2368
2373
|
);
|
|
2369
|
-
}, C = (
|
|
2370
|
-
d.setFilter(
|
|
2371
|
-
}, g = (
|
|
2372
|
-
c =
|
|
2373
|
-
}, u = (
|
|
2374
|
-
|
|
2375
|
-
},
|
|
2376
|
-
|
|
2374
|
+
}, C = (E) => {
|
|
2375
|
+
d.setFilter(E), m.setFilter(E);
|
|
2376
|
+
}, g = (E) => {
|
|
2377
|
+
c = E, m.setUser(E);
|
|
2378
|
+
}, u = (E) => {
|
|
2379
|
+
E && (d.setPainter(ho(E, n.presence)), E.on("selectionChange", () => d.redraw()));
|
|
2380
|
+
}, y = (E) => {
|
|
2381
|
+
E ? i.setSelected(E) : i.clear();
|
|
2377
2382
|
};
|
|
2378
2383
|
return {
|
|
2379
2384
|
...p,
|
|
2380
2385
|
destroy: () => {
|
|
2381
|
-
d.destroy(),
|
|
2386
|
+
d.destroy(), m.destroy(), a.destroy();
|
|
2382
2387
|
},
|
|
2383
2388
|
element: t,
|
|
2384
2389
|
getUser: w,
|
|
@@ -2387,7 +2392,7 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
|
|
|
2387
2392
|
setStyle: d.setStyle.bind(d),
|
|
2388
2393
|
redraw: d.redraw.bind(d),
|
|
2389
2394
|
setUser: g,
|
|
2390
|
-
setSelected:
|
|
2395
|
+
setSelected: y,
|
|
2391
2396
|
setPresenceProvider: u,
|
|
2392
2397
|
setVisible: d.setVisible.bind(d),
|
|
2393
2398
|
on: l.on,
|