@recogito/text-annotator 3.2.0 → 3.3.0
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.
|
@@ -4,19 +4,19 @@ import { colord as et } from "colord";
|
|
|
4
4
|
import { dequal as dt } from "dequal/lite";
|
|
5
5
|
import { v4 as nt } from "uuid";
|
|
6
6
|
import { serializeW3CBodies as ft, parseW3CBodies as ut, parseW3CUser as gt, createStore as mt, createSelectionState as pt, createHoverState as ht, createViewportState as yt, Origin as F, createAnonymousGuest as bt, createUndoStack as St, createLifecycleObserver as Ct, createBaseAnnotator as Et } from "@annotorious/core";
|
|
7
|
-
import { Origin as
|
|
7
|
+
import { Origin as Te, UserSelectAction as xe, createBody as Re } from "@annotorious/core";
|
|
8
8
|
import wt from "rbush";
|
|
9
9
|
import V from "hotkeys-js";
|
|
10
10
|
import { poll as At } from "poll";
|
|
11
|
-
const ot = "not-annotatable",
|
|
11
|
+
const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
12
12
|
var r;
|
|
13
|
-
return t.contains(e) ? !!(e instanceof HTMLElement ? e.closest(
|
|
14
|
-
},
|
|
13
|
+
return t.contains(e) ? !!(e instanceof HTMLElement ? e.closest(K) : (r = e.parentElement) == null ? void 0 : r.closest(K)) : !0;
|
|
14
|
+
}, vt = (t, e) => {
|
|
15
15
|
const n = e.commonAncestorContainer;
|
|
16
16
|
return !Y(t, n);
|
|
17
|
-
},
|
|
17
|
+
}, Tt = (t) => t.addEventListener("click", (e) => {
|
|
18
18
|
// Allow clicks within not-annotatable elements
|
|
19
|
-
!e.target.closest(
|
|
19
|
+
!e.target.closest(K) && !e.target.closest("a") && e.preventDefault();
|
|
20
20
|
}), q = (t) => ({
|
|
21
21
|
...t,
|
|
22
22
|
type: t.type,
|
|
@@ -61,7 +61,7 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
61
61
|
timeStamp: t.timeStamp
|
|
62
62
|
}), xt = ct(), Rt = xt.os.is(lt.MACOS), Lt = (t) => {
|
|
63
63
|
!t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
|
|
64
|
-
},
|
|
64
|
+
}, D = (t, e = 10) => {
|
|
65
65
|
let n;
|
|
66
66
|
return ((...r) => {
|
|
67
67
|
clearTimeout(n), n = setTimeout(() => t.apply(void 0, r), e);
|
|
@@ -92,13 +92,13 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
92
92
|
const e = document.createNodeIterator(
|
|
93
93
|
t.commonAncestorContainer,
|
|
94
94
|
NodeFilter.SHOW_ELEMENT,
|
|
95
|
-
(r) => r instanceof HTMLElement && r.classList.contains(ot) && !r.parentElement.closest(
|
|
95
|
+
(r) => r instanceof HTMLElement && r.classList.contains(ot) && !r.parentElement.closest(K) && t.intersectsNode(r) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
|
96
96
|
);
|
|
97
97
|
let n;
|
|
98
98
|
for (; n = e.nextNode(); )
|
|
99
99
|
n instanceof HTMLElement && (yield n);
|
|
100
100
|
}, kt = (t, e) => {
|
|
101
|
-
if (!
|
|
101
|
+
if (!vt(t, e)) return [];
|
|
102
102
|
const n = [];
|
|
103
103
|
let r = null;
|
|
104
104
|
for (const s of Ot(e)) {
|
|
@@ -112,7 +112,7 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
112
112
|
return n.length > 0 ? n : [e];
|
|
113
113
|
}, G = (t) => {
|
|
114
114
|
const e = t.cloneContents();
|
|
115
|
-
return e.querySelectorAll(
|
|
115
|
+
return e.querySelectorAll(K).forEach((n) => n.remove()), e;
|
|
116
116
|
}, It = (t, e, n = 10, r) => {
|
|
117
117
|
const s = r ? t.startContainer.parentElement.closest(r) : e, o = document.createRange();
|
|
118
118
|
o.setStart(s, 0), o.setEnd(t.startContainer, t.startOffset);
|
|
@@ -123,7 +123,7 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
123
123
|
prefix: i.substring(i.length - n),
|
|
124
124
|
suffix: d.substring(0, n)
|
|
125
125
|
};
|
|
126
|
-
},
|
|
126
|
+
}, M = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), Bt = /^\s*$/, Mt = (t) => Bt.test(t.toString()), Pt = (t, e, n, r) => {
|
|
127
127
|
const s = (a) => Math.round(a * 10) / 10, o = {
|
|
128
128
|
top: s(t.top),
|
|
129
129
|
bottom: s(t.bottom),
|
|
@@ -190,7 +190,7 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
190
190
|
NodeFilter.SHOW_TEXT,
|
|
191
191
|
(c) => {
|
|
192
192
|
var g;
|
|
193
|
-
return (g = c.parentElement) != null && g.closest(
|
|
193
|
+
return (g = c.parentElement) != null && g.closest(K) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
|
|
194
194
|
}
|
|
195
195
|
);
|
|
196
196
|
let i = 0;
|
|
@@ -221,10 +221,10 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
221
221
|
...t,
|
|
222
222
|
range: a
|
|
223
223
|
};
|
|
224
|
-
}, X = (t, e) =>
|
|
224
|
+
}, X = (t, e) => M(t.selector) ? t : {
|
|
225
225
|
...t,
|
|
226
226
|
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : st(n, e))
|
|
227
|
-
}, j = (t, e) =>
|
|
227
|
+
}, j = (t, e) => M(t.target.selector) ? t : { ...t, target: X(t.target, e) }, Ft = (t, e) => {
|
|
228
228
|
const n = t.cloneRange();
|
|
229
229
|
return e.contains(n.startContainer) || n.setStart(e, 0), e.contains(n.endContainer) || n.setEnd(e, e.childNodes.length), n;
|
|
230
230
|
}, rt = (t) => {
|
|
@@ -232,9 +232,9 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
232
232
|
return document.scrollingElement;
|
|
233
233
|
const { overflowY: e } = window.getComputedStyle(t);
|
|
234
234
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : rt(t.parentElement);
|
|
235
|
-
},
|
|
235
|
+
}, Dt = (t, e) => (n) => {
|
|
236
236
|
const r = typeof n == "string" ? n : n.id, s = (b) => {
|
|
237
|
-
const f = o.getBoundingClientRect(), c = o.clientHeight, g = o.clientWidth, R = b.selector[0].range.getBoundingClientRect(), { width:
|
|
237
|
+
const f = o.getBoundingClientRect(), c = o.clientHeight, g = o.clientWidth, R = b.selector[0].range.getBoundingClientRect(), { width: T, height: x } = e.getAnnotationBounds(r), E = R.top - f.top, A = R.left - f.left, u = o.parentElement ? o.scrollTop : 0, m = o.parentElement ? o.scrollLeft : 0, y = E + u - (c - x) / 2, l = A + m - (g - T) / 2;
|
|
238
238
|
o.scroll({ top: y, left: l, behavior: "smooth" });
|
|
239
239
|
}, o = rt(t);
|
|
240
240
|
if (!o)
|
|
@@ -247,17 +247,17 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
247
247
|
return s(i.target), !0;
|
|
248
248
|
const d = X(i.target, t), { range: p } = d.selector[0];
|
|
249
249
|
return p && !p.collapsed ? (s(d), !0) : !1;
|
|
250
|
-
},
|
|
250
|
+
}, U = {
|
|
251
251
|
fill: "rgb(0, 128, 255)",
|
|
252
252
|
fillOpacity: 0.18
|
|
253
253
|
}, z = {
|
|
254
254
|
fill: "rgb(0, 128, 255)",
|
|
255
255
|
fillOpacity: 0.45
|
|
256
|
-
},
|
|
256
|
+
}, Kt = (t, e, n, r, s) => {
|
|
257
257
|
var i, a;
|
|
258
|
-
const o = n ? typeof n == "function" ? n(t.annotation, t.state, s) || ((i = t.state) != null && i.selected ? z :
|
|
258
|
+
const o = n ? typeof n == "function" ? n(t.annotation, t.state, s) || ((i = t.state) != null && i.selected ? z : U) : n : (a = t.state) != null && a.selected ? z : U;
|
|
259
259
|
return r && r.paint(t, e) || o;
|
|
260
|
-
},
|
|
260
|
+
}, $t = (t) => {
|
|
261
261
|
const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: r, innerHeight: s } = window, o = -n, i = -e, a = r - n, d = s - e;
|
|
262
262
|
return { top: e, left: n, minX: o, minY: i, maxX: a, maxY: d };
|
|
263
263
|
}, Vt = (t) => {
|
|
@@ -269,48 +269,48 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
269
269
|
}, Q = (t, e, n, r) => {
|
|
270
270
|
const { store: s, selection: o, hover: i } = e;
|
|
271
271
|
let a, d, p;
|
|
272
|
-
const b = Vt(n), f =
|
|
272
|
+
const b = Vt(n), f = D((C) => {
|
|
273
273
|
const { x: N, y: S } = t.getBoundingClientRect(), v = s.getAt(C.clientX - N, C.clientY - S, !1, d);
|
|
274
274
|
v ? i.current !== v.id && (t.classList.add("hovered"), i.set(v.id)) : i.current && (t.classList.remove("hovered"), i.set(null));
|
|
275
275
|
}, 10);
|
|
276
276
|
t.addEventListener("pointermove", f);
|
|
277
|
-
const c =
|
|
277
|
+
const c = D((C = !1) => requestAnimationFrame(() => {
|
|
278
278
|
p && p.clear();
|
|
279
|
-
const N =
|
|
280
|
-
const
|
|
279
|
+
const N = $t(t), { minX: S, minY: v, maxX: O, maxY: P } = N, k = d ? s.getIntersecting(S, v, O, P).filter(({ annotation: L }) => d(L)) : s.getIntersecting(S, v, O, P), I = o.selected.map(({ id: L }) => L), B = k.map(({ annotation: L, rects: _ }) => {
|
|
280
|
+
const H = I.includes(L.id), Z = L.id === i.current;
|
|
281
281
|
return {
|
|
282
282
|
annotation: L,
|
|
283
283
|
rects: _,
|
|
284
|
-
state: { selected:
|
|
284
|
+
state: { selected: H, hovered: Z }
|
|
285
285
|
};
|
|
286
286
|
});
|
|
287
|
-
r.redraw(
|
|
287
|
+
r.redraw(B, N, a, p, C), setTimeout(() => b(k.map(({ annotation: L }) => L)), 1);
|
|
288
288
|
}), 10), g = (C) => {
|
|
289
289
|
p = C, c();
|
|
290
290
|
}, R = (C) => {
|
|
291
291
|
a = C, c();
|
|
292
|
-
},
|
|
292
|
+
}, T = (C) => {
|
|
293
293
|
d = C, c(!1);
|
|
294
294
|
}, x = () => c();
|
|
295
295
|
s.observe(x);
|
|
296
|
-
const E = o.subscribe(() => c()),
|
|
296
|
+
const E = o.subscribe(() => c()), A = i.subscribe(() => c()), u = () => c(!0);
|
|
297
297
|
document.addEventListener("scroll", u, { capture: !0, passive: !0 });
|
|
298
|
-
const m =
|
|
298
|
+
const m = D(() => {
|
|
299
299
|
s.recalculatePositions(), p && p.reset(), c();
|
|
300
300
|
});
|
|
301
301
|
window.addEventListener("resize", m);
|
|
302
302
|
const y = new ResizeObserver(m);
|
|
303
303
|
y.observe(t);
|
|
304
|
-
const l = { attributes: !0, childList: !0, subtree: !0 }, h = new MutationObserver(
|
|
304
|
+
const l = { attributes: !0, childList: !0, subtree: !0 }, h = new MutationObserver(D((C) => {
|
|
305
305
|
C.every((S) => S.target === t || t.contains(S.target)) || c(!0);
|
|
306
306
|
}, 150));
|
|
307
307
|
return h.observe(document.body, l), {
|
|
308
308
|
destroy: () => {
|
|
309
|
-
t.removeEventListener("pointermove", f), r.destroy(), s.unobserve(x), E(),
|
|
309
|
+
t.removeEventListener("pointermove", f), r.destroy(), s.unobserve(x), E(), A(), document.removeEventListener("scroll", u), window.removeEventListener("resize", m), y.disconnect(), h.disconnect();
|
|
310
310
|
},
|
|
311
311
|
redraw: c,
|
|
312
312
|
setStyle: R,
|
|
313
|
-
setFilter:
|
|
313
|
+
setFilter: T,
|
|
314
314
|
setPainter: g,
|
|
315
315
|
setVisible: r.setVisible
|
|
316
316
|
};
|
|
@@ -328,27 +328,27 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
328
328
|
n.clearRect(-0.5, -0.5, f + 1, c + 1), b && b.clear();
|
|
329
329
|
const { top: g, left: R } = d;
|
|
330
330
|
[...a].sort((x, E) => {
|
|
331
|
-
const { annotation: { target: { created:
|
|
332
|
-
return
|
|
331
|
+
const { annotation: { target: { created: A } } } = x, { annotation: { target: { created: u } } } = E;
|
|
332
|
+
return A.getTime() - u.getTime();
|
|
333
333
|
}).forEach((x) => {
|
|
334
334
|
var m;
|
|
335
|
-
const E = p ? typeof p == "function" ? p(x.annotation, x.state) : p : (m = x.state) != null && m.selected ? z :
|
|
335
|
+
const E = p ? typeof p == "function" ? p(x.annotation, x.state) : p : (m = x.state) != null && m.selected ? z : U, A = b && b.paint(x, d) || E, u = x.rects.map(({ x: y, y: l, width: h, height: w }) => ({
|
|
336
336
|
x: y + R,
|
|
337
337
|
y: l + g,
|
|
338
338
|
width: h,
|
|
339
339
|
height: w
|
|
340
340
|
}));
|
|
341
|
-
if (n.fillStyle =
|
|
341
|
+
if (n.fillStyle = A.fill, n.globalAlpha = A.fillOpacity || 1, u.forEach(
|
|
342
342
|
({ x: y, y: l, width: h, height: w }) => n.fillRect(y, l, h, w)
|
|
343
|
-
),
|
|
344
|
-
n.globalAlpha = 1, n.strokeStyle =
|
|
345
|
-
const y =
|
|
343
|
+
), A.underlineColor) {
|
|
344
|
+
n.globalAlpha = 1, n.strokeStyle = A.underlineColor, n.lineWidth = A.underlineThickness ?? 1;
|
|
345
|
+
const y = A.underlineOffset ?? 0;
|
|
346
346
|
u.forEach(({ x: l, y: h, width: w, height: C }) => {
|
|
347
347
|
n.beginPath(), n.moveTo(l, h + C + y), n.lineTo(l + w, h + C + y), n.stroke();
|
|
348
348
|
});
|
|
349
349
|
}
|
|
350
350
|
});
|
|
351
|
-
}), s =
|
|
351
|
+
}), s = D(() => {
|
|
352
352
|
Yt(e);
|
|
353
353
|
});
|
|
354
354
|
return window.addEventListener("resize", s), {
|
|
@@ -361,7 +361,7 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
361
361
|
redraw: r
|
|
362
362
|
};
|
|
363
363
|
}, zt = (t, e, n) => Q(t, e, n, Xt(t)), qt = (t) => [
|
|
364
|
-
`background-color:${et((t == null ? void 0 : t.fill) ||
|
|
364
|
+
`background-color:${et((t == null ? void 0 : t.fill) || U.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? U.fillOpacity : t.fillOpacity).toHex()}`,
|
|
365
365
|
t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
|
|
366
366
|
t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
367
367
|
t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
@@ -383,7 +383,7 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
383
383
|
Array.from(e).filter((f) => !p.has(f));
|
|
384
384
|
const b = o.map((f) => {
|
|
385
385
|
var R;
|
|
386
|
-
const c = a ? typeof a == "function" ? a(f.annotation, f.state) : a : (R = f.state) != null && R.selected ? z :
|
|
386
|
+
const c = a ? typeof a == "function" ? a(f.annotation, f.state) : a : (R = f.state) != null && R.selected ? z : U, g = d && d.paint(f, i) || c;
|
|
387
387
|
return `::highlight(_${f.annotation.id}) { ${qt(g)} }`;
|
|
388
388
|
});
|
|
389
389
|
t.innerHTML = b.join(`
|
|
@@ -408,15 +408,15 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
408
408
|
redraw: (i, a, d, p, b) => {
|
|
409
409
|
const c = !(dt(n, i) && b);
|
|
410
410
|
if (!p && !c) return;
|
|
411
|
-
c && (e.innerHTML = ""), [...i].sort((R,
|
|
412
|
-
const { annotation: { target: { created: x } } } = R, { annotation: { target: { created: E } } } =
|
|
411
|
+
c && (e.innerHTML = ""), [...i].sort((R, T) => {
|
|
412
|
+
const { annotation: { target: { created: x } } } = R, { annotation: { target: { created: E } } } = T;
|
|
413
413
|
return x && E ? x.getTime() - E.getTime() : 0;
|
|
414
414
|
}).forEach((R) => {
|
|
415
|
-
R.rects.map((
|
|
416
|
-
const x = Qt(
|
|
415
|
+
R.rects.map((T) => {
|
|
416
|
+
const x = Qt(T, i), E = Kt(R, a, d, p, x);
|
|
417
417
|
if (c) {
|
|
418
|
-
const
|
|
419
|
-
|
|
418
|
+
const A = document.createElement("span");
|
|
419
|
+
A.className = "r6o-annotation", A.dataset.annotation = R.annotation.id, A.style.left = `${T.x}px`, A.style.top = `${T.y}px`, A.style.width = `${T.width}px`, A.style.height = `${T.height}px`, A.style.backgroundColor = et((E == null ? void 0 : E.fill) || U.fill).alpha((E == null ? void 0 : E.fillOpacity) === void 0 ? U.fillOpacity : E.fillOpacity).toHex(), E.underlineStyle && (A.style.borderStyle = E.underlineStyle), E.underlineColor && (A.style.borderColor = E.underlineColor), E.underlineThickness && (A.style.borderBottomWidth = `${E.underlineThickness}px`), E.underlineOffset && (A.style.paddingBottom = `${E.underlineOffset}px`), e.appendChild(A);
|
|
420
420
|
}
|
|
421
421
|
});
|
|
422
422
|
}), n = i;
|
|
@@ -501,17 +501,17 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
501
501
|
updated: p,
|
|
502
502
|
...b
|
|
503
503
|
} = s, f = i.map((c) => {
|
|
504
|
-
const { id: g, quote: R, start:
|
|
504
|
+
const { id: g, quote: R, start: T, end: x, range: E } = c, A = {
|
|
505
505
|
type: "TextQuoteSelector",
|
|
506
506
|
exact: R
|
|
507
507
|
};
|
|
508
508
|
if (n) {
|
|
509
509
|
const { prefix: m, suffix: y } = It(E, n);
|
|
510
|
-
|
|
510
|
+
A.prefix = m, A.suffix = y;
|
|
511
511
|
}
|
|
512
512
|
const u = {
|
|
513
513
|
type: "TextPositionSelector",
|
|
514
|
-
start:
|
|
514
|
+
start: T,
|
|
515
515
|
end: x
|
|
516
516
|
};
|
|
517
517
|
return {
|
|
@@ -520,7 +520,7 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
520
520
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
521
521
|
scope: "scope" in c ? c.scope : void 0,
|
|
522
522
|
source: e,
|
|
523
|
-
selector: [
|
|
523
|
+
selector: [A, u]
|
|
524
524
|
};
|
|
525
525
|
});
|
|
526
526
|
return {
|
|
@@ -537,7 +537,7 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
537
537
|
}, se = (t, e, n, r) => {
|
|
538
538
|
const s = new wt(), o = /* @__PURE__ */ new Map(), i = (u, m) => {
|
|
539
539
|
const y = u.selector.flatMap((h) => {
|
|
540
|
-
const w =
|
|
540
|
+
const w = M([h]) ? h.range : st(h, e).range;
|
|
541
541
|
return Nt(w);
|
|
542
542
|
}), l = Ut(y, n, r).map(({ left: h, top: w, right: C, bottom: N }) => new DOMRect(h - m.left, w - m.top, C - h, N - w));
|
|
543
543
|
return l.map((h) => {
|
|
@@ -580,7 +580,7 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
580
580
|
}), h = (w) => w.annotation.rects.reduce((C, N) => C + N.width * N.height, 0);
|
|
581
581
|
return l.length > 0 ? (l.sort((w, C) => h(w) - h(C)), y ? l.map((w) => w.annotation.id) : [l[0].annotation.id]) : [];
|
|
582
582
|
}, R = (u) => {
|
|
583
|
-
const m =
|
|
583
|
+
const m = T(u);
|
|
584
584
|
if (m.length === 0)
|
|
585
585
|
return;
|
|
586
586
|
let y = m[0].left, l = m[0].top, h = m[0].right, w = m[0].bottom;
|
|
@@ -589,7 +589,7 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
589
589
|
y = Math.min(y, N.left), l = Math.min(l, N.top), h = Math.max(h, N.right), w = Math.max(w, N.bottom);
|
|
590
590
|
}
|
|
591
591
|
return new DOMRect(y, l, h - y, w - l);
|
|
592
|
-
},
|
|
592
|
+
}, T = (u) => {
|
|
593
593
|
const m = o.get(u);
|
|
594
594
|
return m ? m[0].annotation.rects : [];
|
|
595
595
|
};
|
|
@@ -598,12 +598,12 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
598
598
|
clear: d,
|
|
599
599
|
getAt: g,
|
|
600
600
|
getAnnotationBounds: R,
|
|
601
|
-
getAnnotationRects:
|
|
601
|
+
getAnnotationRects: T,
|
|
602
602
|
getIntersecting: (u, m, y, l) => {
|
|
603
603
|
const h = s.search({ minX: u, minY: m, maxX: y, maxY: l }), w = new Set(h.map((C) => C.annotation.id));
|
|
604
604
|
return Array.from(w).map((C) => ({
|
|
605
605
|
annotation: t.getAnnotation(C),
|
|
606
|
-
rects:
|
|
606
|
+
rects: T(C)
|
|
607
607
|
})).filter((C) => !!C.annotation);
|
|
608
608
|
},
|
|
609
609
|
insert: p,
|
|
@@ -614,15 +614,15 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
614
614
|
update: f
|
|
615
615
|
};
|
|
616
616
|
}, re = (t, e) => {
|
|
617
|
-
var E,
|
|
618
|
-
const n = mt(), r = se(n, t, (E = e.mergeHighlights) == null ? void 0 : E.horizontalTolerance, (
|
|
619
|
-
const y = j(u, t), l =
|
|
617
|
+
var E, A;
|
|
618
|
+
const n = mt(), r = se(n, t, (E = e.mergeHighlights) == null ? void 0 : E.horizontalTolerance, (A = e.mergeHighlights) == null ? void 0 : A.verticalTolerance), s = pt(n, e.userSelectAction, e.adapter), o = ht(n), i = yt(), a = (u, m = F.LOCAL) => {
|
|
619
|
+
const y = j(u, t), l = M(y.target.selector);
|
|
620
620
|
return l && n.addAnnotation(y, m), l;
|
|
621
621
|
}, d = (u, m = !0, y = F.LOCAL) => {
|
|
622
|
-
const l = u.map((w) => j(w, t)), h = l.filter((w) => !
|
|
622
|
+
const l = u.map((w) => j(w, t)), h = l.filter((w) => !M(w.target.selector));
|
|
623
623
|
return n.bulkAddAnnotations(l, m, y), h;
|
|
624
624
|
}, p = (u, m = F.LOCAL) => {
|
|
625
|
-
const y = u.map((h) => j(h, t)), l = y.filter((h) => !
|
|
625
|
+
const y = u.map((h) => j(h, t)), l = y.filter((h) => !M(h.target.selector));
|
|
626
626
|
return y.forEach((h) => {
|
|
627
627
|
n.getAnnotation(h.id) ? n.updateAnnotation(h, m) : n.addAnnotation(h, m);
|
|
628
628
|
}), l;
|
|
@@ -641,9 +641,9 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
641
641
|
const g = (u) => {
|
|
642
642
|
if (r.getAnnotationRects(u).length !== 0)
|
|
643
643
|
return r.getAnnotationBounds(u);
|
|
644
|
-
}, R = (u, m, y, l) => r.getIntersecting(u, m, y, l),
|
|
644
|
+
}, R = (u, m, y, l) => r.getIntersecting(u, m, y, l), T = (u) => r.getAnnotationRects(u), x = () => r.recalculate();
|
|
645
645
|
return n.observe(({ changes: u }) => {
|
|
646
|
-
const m = (u.deleted || []).filter((h) =>
|
|
646
|
+
const m = (u.deleted || []).filter((h) => M(h.target.selector)), y = (u.created || []).filter((h) => M(h.target.selector)), l = (u.updated || []).filter((h) => M(h.newValue.target.selector));
|
|
647
647
|
(m == null ? void 0 : m.length) > 0 && m.forEach((h) => r.remove(h.target)), y.length > 0 && r.set(y.map((h) => h.target), !1), (l == null ? void 0 : l.length) > 0 && l.forEach(({ newValue: h }) => r.update(h.target));
|
|
648
648
|
}), {
|
|
649
649
|
store: {
|
|
@@ -653,7 +653,7 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
653
653
|
bulkUpdateTargets: f,
|
|
654
654
|
bulkUpsertAnnotations: p,
|
|
655
655
|
getAnnotationBounds: g,
|
|
656
|
-
getAnnotationRects:
|
|
656
|
+
getAnnotationRects: T,
|
|
657
657
|
getIntersecting: R,
|
|
658
658
|
getAt: c,
|
|
659
659
|
recalculatePositions: x,
|
|
@@ -686,10 +686,10 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
686
686
|
e.font && (r.font = e.font);
|
|
687
687
|
const g = s.get(b.annotation.id);
|
|
688
688
|
if (g) {
|
|
689
|
-
const { height: R } = b.rects[0],
|
|
690
|
-
r.fillStyle = g.appearance.color, r.fillRect(
|
|
691
|
-
const E = r.measureText(g.appearance.label),
|
|
692
|
-
return r.fillRect(
|
|
689
|
+
const { height: R } = b.rects[0], T = b.rects[0].x + f.left, x = b.rects[0].y + f.top;
|
|
690
|
+
r.fillStyle = g.appearance.color, r.fillRect(T - 2, x - 2.5, 2, R + 5);
|
|
691
|
+
const E = r.measureText(g.appearance.label), A = E.width + 6, u = E.actualBoundingBoxAscent + E.actualBoundingBoxDescent + 8, m = E.fontBoundingBoxAscent ? 8 : 6.5;
|
|
692
|
+
return r.fillRect(T - 2, x - 2.5 - u, A, u), r.fillStyle = "#fff", r.fillText(g.appearance.label, T + 1, x - m), {
|
|
693
693
|
fill: g.appearance.color,
|
|
694
694
|
fillOpacity: c ? 0.45 : 0.18
|
|
695
695
|
};
|
|
@@ -714,65 +714,66 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
714
714
|
} = n, d = (S) => r = S;
|
|
715
715
|
let p;
|
|
716
716
|
const b = (S) => p = S, { store: f, selection: c } = e;
|
|
717
|
-
let g, R,
|
|
718
|
-
const x = (
|
|
719
|
-
R !== !1 && (g =
|
|
717
|
+
let g, R, T;
|
|
718
|
+
const x = () => {
|
|
719
|
+
R !== !1 && (g = {
|
|
720
720
|
annotation: nt(),
|
|
721
721
|
selector: [],
|
|
722
722
|
creator: r,
|
|
723
723
|
created: /* @__PURE__ */ new Date()
|
|
724
724
|
});
|
|
725
|
-
}, E =
|
|
725
|
+
}, E = D((S) => {
|
|
726
726
|
const v = document.getSelection();
|
|
727
727
|
if (!(v != null && v.anchorNode))
|
|
728
728
|
return;
|
|
729
|
-
|
|
729
|
+
const O = Array.from(Array(v.rangeCount).keys()).map((L) => v.getRangeAt(L));
|
|
730
|
+
if (!O.some((L) => L.intersectsNode(t))) {
|
|
730
731
|
g = void 0;
|
|
731
732
|
return;
|
|
732
733
|
}
|
|
733
|
-
const
|
|
734
|
-
if ((
|
|
734
|
+
const P = S.timeStamp - ((T == null ? void 0 : T.timeStamp) || S.timeStamp);
|
|
735
|
+
if ((T == null ? void 0 : T.type) === "pointerdown" && (P < 1e3 && !g || v.isCollapsed && P < J) && x(), !g) return;
|
|
735
736
|
if (v.isCollapsed) {
|
|
736
737
|
f.getAnnotation(g.annotation) && (c.clear(), f.deleteAnnotation(g.annotation));
|
|
737
738
|
return;
|
|
738
739
|
}
|
|
739
|
-
const k =
|
|
740
|
+
const k = O.map((L) => Ft(L, t));
|
|
740
741
|
if (k.every((L) => Mt(L))) return;
|
|
741
|
-
const
|
|
742
|
-
(
|
|
743
|
-
var
|
|
744
|
-
return L.toString() !== ((
|
|
742
|
+
const I = k.flatMap((L) => kt(t, L.cloneRange()));
|
|
743
|
+
(I.length !== g.selector.length || I.some((L, _) => {
|
|
744
|
+
var H;
|
|
745
|
+
return L.toString() !== ((H = g.selector[_]) == null ? void 0 : H.quote);
|
|
745
746
|
})) && (g = {
|
|
746
747
|
...g,
|
|
747
|
-
selector:
|
|
748
|
+
selector: I.map((L) => _t(L, t, o)),
|
|
748
749
|
updated: /* @__PURE__ */ new Date()
|
|
749
750
|
}, f.getAnnotation(g.annotation) ? f.updateTarget(g, F.LOCAL) : c.clear());
|
|
750
|
-
}),
|
|
751
|
-
|
|
751
|
+
}), A = (S) => {
|
|
752
|
+
T = q(S), R = T.button === 0;
|
|
752
753
|
}, u = async (S) => {
|
|
753
754
|
if (!R) return;
|
|
754
755
|
const v = q(S), O = () => {
|
|
755
|
-
const { x: k, y:
|
|
756
|
+
const { x: k, y: I } = t.getBoundingClientRect();
|
|
756
757
|
if (Y(t, v.target)) {
|
|
757
758
|
(typeof a == "function" ? a(v, t) : a === "ALWAYS") && c.clear();
|
|
758
759
|
return;
|
|
759
760
|
}
|
|
760
|
-
const
|
|
761
|
+
const B = v.target instanceof Node && t.contains(v.target) && f.getAt(
|
|
761
762
|
v.clientX - k,
|
|
762
|
-
v.clientY -
|
|
763
|
+
v.clientY - I,
|
|
763
764
|
i === "all",
|
|
764
765
|
p
|
|
765
766
|
);
|
|
766
|
-
if (
|
|
767
|
-
const { selected: L } = c, _ = new Set(L.map((
|
|
768
|
-
(_.size !==
|
|
767
|
+
if (B) {
|
|
768
|
+
const { selected: L } = c, _ = new Set(L.map(($) => $.id)), H = Array.isArray(B) ? B.map(($) => $.id) : [B.id];
|
|
769
|
+
(_.size !== H.length || !H.every(($) => _.has($))) && c.userSelect(H, v);
|
|
769
770
|
} else
|
|
770
771
|
c.clear();
|
|
771
772
|
};
|
|
772
|
-
if (v.timeStamp -
|
|
773
|
+
if (v.timeStamp - T.timeStamp < J) {
|
|
773
774
|
await m();
|
|
774
|
-
const k = document.getSelection();
|
|
775
|
-
if (k != null && k.isCollapsed) {
|
|
775
|
+
const k = document.getSelection(), I = Y(t, T.target), B = Y(t, v.target);
|
|
776
|
+
if (k != null && k.isCollapsed || I && B) {
|
|
776
777
|
g = void 0, O();
|
|
777
778
|
return;
|
|
778
779
|
}
|
|
@@ -781,8 +782,8 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
781
782
|
}, m = async () => {
|
|
782
783
|
const S = document.getSelection();
|
|
783
784
|
let v = !1, O = S == null ? void 0 : S.isCollapsed;
|
|
784
|
-
const
|
|
785
|
-
return setTimeout(() => v = !0, 50), At(() => O = S == null ? void 0 : S.isCollapsed, k,
|
|
785
|
+
const P = () => O || v, k = 1;
|
|
786
|
+
return setTimeout(() => v = !0, 50), At(() => O = S == null ? void 0 : S.isCollapsed, k, P);
|
|
786
787
|
}, y = (S) => {
|
|
787
788
|
const v = document.getSelection();
|
|
788
789
|
v != null && v.isCollapsed || ((!g || g.selector.length === 0) && E(S), g && (C(), c.userSelect(g.annotation, q(S))));
|
|
@@ -796,12 +797,12 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
796
797
|
target: g
|
|
797
798
|
}), c.userSelect(g.annotation, W(S))), document.removeEventListener("selectionchange", v);
|
|
798
799
|
}, 100);
|
|
799
|
-
document.addEventListener("selectionchange", v), x(
|
|
800
|
+
document.addEventListener("selectionchange", v), x();
|
|
800
801
|
};
|
|
801
802
|
V(ce.join(","), { element: t, keydown: !0, keyup: !1 }, (S) => {
|
|
802
|
-
S.repeat || (
|
|
803
|
+
S.repeat || (T = W(S));
|
|
803
804
|
}), V(at, { keydown: !0, keyup: !1 }, (S) => {
|
|
804
|
-
|
|
805
|
+
T = W(S), h(S);
|
|
805
806
|
});
|
|
806
807
|
const w = (S) => {
|
|
807
808
|
S.repeat || S.target !== t && S.target !== document.body || (g = void 0, c.clear());
|
|
@@ -820,9 +821,9 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
820
821
|
const { target: { updated: v } } = S, { updated: O } = g;
|
|
821
822
|
(!v || !O || v < O) && f.updateTarget(g);
|
|
822
823
|
};
|
|
823
|
-
return document.addEventListener("pointerdown",
|
|
824
|
+
return document.addEventListener("pointerdown", A), document.addEventListener("pointerup", u), document.addEventListener("contextmenu", y), s && (t.addEventListener("keyup", l), t.addEventListener("selectstart", x), document.addEventListener("selectionchange", E)), {
|
|
824
825
|
destroy: () => {
|
|
825
|
-
document.removeEventListener("pointerdown",
|
|
826
|
+
document.removeEventListener("pointerdown", A), document.removeEventListener("pointerup", u), document.removeEventListener("contextmenu", y), t.removeEventListener("keyup", l), t.removeEventListener("selectstart", x), document.removeEventListener("selectionchange", E), V.unbind();
|
|
826
827
|
},
|
|
827
828
|
setFilter: b,
|
|
828
829
|
setUser: d
|
|
@@ -832,7 +833,7 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
832
833
|
annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
|
|
833
834
|
user: t.user || e.user
|
|
834
835
|
}), tt = "SPANS", we = (t, e = {}) => {
|
|
835
|
-
|
|
836
|
+
Tt(t), Lt(t);
|
|
836
837
|
const n = de(e, {
|
|
837
838
|
annotatingEnabled: !0,
|
|
838
839
|
user: bt()
|
|
@@ -866,20 +867,20 @@ const ot = "not-annotatable", $ = `.${ot}`, Y = (t, e) => {
|
|
|
866
867
|
setVisible: (l) => f.setVisible(l),
|
|
867
868
|
on: d.on,
|
|
868
869
|
off: d.off,
|
|
869
|
-
scrollIntoView:
|
|
870
|
+
scrollIntoView: Dt(t, i),
|
|
870
871
|
state: r
|
|
871
872
|
};
|
|
872
873
|
};
|
|
873
874
|
export {
|
|
874
875
|
z as DEFAULT_SELECTED_STYLE,
|
|
875
|
-
|
|
876
|
+
U as DEFAULT_STYLE,
|
|
876
877
|
ot as NOT_ANNOTATABLE_CLASS,
|
|
877
|
-
|
|
878
|
-
|
|
878
|
+
K as NOT_ANNOTATABLE_SELECTOR,
|
|
879
|
+
Te as Origin,
|
|
879
880
|
le as SelectionHandler,
|
|
880
881
|
xe as UserSelectAction,
|
|
881
882
|
Ee as W3CTextFormat,
|
|
882
|
-
|
|
883
|
+
Tt as cancelSingleClickEvents,
|
|
883
884
|
W as cloneKeyboardEvent,
|
|
884
885
|
q as clonePointerEvent,
|
|
885
886
|
Re as createBody,
|
|
@@ -890,25 +891,25 @@ export {
|
|
|
890
891
|
Jt as createSpansRenderer,
|
|
891
892
|
we as createTextAnnotator,
|
|
892
893
|
re as createTextAnnotatorState,
|
|
893
|
-
|
|
894
|
+
D as debounce,
|
|
894
895
|
de as fillDefaults,
|
|
895
896
|
Nt as getHighlightClientRects,
|
|
896
897
|
It as getQuoteContext,
|
|
897
898
|
G as getRangeAnnotatableContents,
|
|
898
899
|
Rt as isMac,
|
|
899
900
|
Y as isNotAnnotatable,
|
|
900
|
-
|
|
901
|
-
|
|
901
|
+
vt as isRangeAnnotatable,
|
|
902
|
+
M as isRevived,
|
|
902
903
|
Mt as isWhitespaceOrEmpty,
|
|
903
904
|
Ut as mergeClientRects,
|
|
904
|
-
|
|
905
|
+
Kt as paint,
|
|
905
906
|
ne as parseW3CTextAnnotation,
|
|
906
907
|
Lt as programmaticallyFocusable,
|
|
907
908
|
_t as rangeToSelector,
|
|
908
909
|
j as reviveAnnotation,
|
|
909
910
|
st as reviveSelector,
|
|
910
911
|
X as reviveTarget,
|
|
911
|
-
|
|
912
|
+
Dt as scrollIntoView,
|
|
912
913
|
oe as serializeW3CTextAnnotation,
|
|
913
914
|
kt as splitAnnotatableRanges,
|
|
914
915
|
Ce as toDomRectList,
|