@soomo/text-annotator 3.4.0-staging.3 → 3.4.2-staging.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.
- package/dist/src/highlight/span/color.d.ts +2 -0
- package/dist/src/utils/isWhitespaceOrEmpty.d.ts +2 -1
- package/dist/text-annotator.es.js +206 -202
- package/dist/text-annotator.es.js.map +1 -1
- package/dist/text-annotator.umd.js +2 -2
- package/dist/text-annotator.umd.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
import { UAParser as
|
|
2
|
-
import { OS as
|
|
1
|
+
import { UAParser as ft } from "ua-parser-js";
|
|
2
|
+
import { OS as ut } from "ua-parser-js/enums";
|
|
3
3
|
import $ from "debounce";
|
|
4
|
-
import { colord as
|
|
4
|
+
import { colord as Z } from "colord";
|
|
5
5
|
import { dequal as gt } from "dequal/lite";
|
|
6
6
|
import { v4 as st } from "uuid";
|
|
7
|
-
import { serializeW3CBodies as mt, parseW3CBodies as pt, parseW3CUser as ht, createStore as
|
|
7
|
+
import { serializeW3CBodies as mt, parseW3CBodies as pt, parseW3CUser as ht, createStore as bt, createSelectionState as yt, createHoverState as St, createViewportState as Ct, Origin as K, createAnonymousGuest as Et, createUndoStack as wt, createLifecycleObserver as At, createBaseAnnotator as vt } from "@annotorious/core";
|
|
8
8
|
import { Origin as He, UserSelectAction as Pe, createBody as _e } from "@annotorious/core";
|
|
9
9
|
import xt from "rbush";
|
|
10
|
-
import { createNanoEvents as
|
|
11
|
-
import
|
|
12
|
-
import { poll as
|
|
13
|
-
const rt = "not-annotatable", W = `.${rt}`,
|
|
10
|
+
import { createNanoEvents as Tt } from "nanoevents";
|
|
11
|
+
import Y from "hotkeys-js";
|
|
12
|
+
import { poll as Rt } from "poll";
|
|
13
|
+
const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
14
14
|
var r;
|
|
15
15
|
return t.contains(e) ? !!(e instanceof HTMLElement ? e.closest(W) : (r = e.parentElement) == null ? void 0 : r.closest(W)) : !0;
|
|
16
16
|
}, Lt = (t, e) => {
|
|
17
17
|
const n = e.commonAncestorContainer;
|
|
18
|
-
return !
|
|
18
|
+
return !z(t, n);
|
|
19
19
|
}, Nt = (t) => t.addEventListener("click", (e) => {
|
|
20
20
|
// Allow clicks within not-annotatable elements
|
|
21
21
|
!e.target.closest(W) && !e.target.closest("a") && e.preventDefault();
|
|
22
|
-
}), Ot =
|
|
22
|
+
}), Ot = ft(), kt = Ot.os.is(ut.MACOS), Bt = (t) => {
|
|
23
23
|
!t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
|
|
24
24
|
}, It = (t) => {
|
|
25
|
-
const e = [], n = document.createNodeIterator(
|
|
25
|
+
const e = [], n = document.createNodeIterator(
|
|
26
|
+
t.commonAncestorContainer,
|
|
27
|
+
NodeFilter.SHOW_TEXT
|
|
28
|
+
);
|
|
26
29
|
let r;
|
|
27
30
|
for (; r = n.nextNode(); )
|
|
28
31
|
t.intersectsNode(r) && e.push(r);
|
|
@@ -30,9 +33,19 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
30
33
|
return Array.from(t.getClientRects());
|
|
31
34
|
{
|
|
32
35
|
const o = e[0], s = e[e.length - 1], i = document.createRange();
|
|
33
|
-
i.selectNode(o), t.startContainer.nodeType === Node.TEXT_NODE
|
|
36
|
+
if (i.selectNode(o), t.startContainer.nodeType === Node.TEXT_NODE)
|
|
37
|
+
i.setStart(o, t.startOffset);
|
|
38
|
+
else {
|
|
39
|
+
const f = t.startContainer.childNodes[t.startOffset];
|
|
40
|
+
f ? i.setStartBefore(f) : i.setStartAfter(t.startContainer);
|
|
41
|
+
}
|
|
34
42
|
const c = document.createRange();
|
|
35
|
-
c.selectNode(s), t.endContainer.nodeType === Node.TEXT_NODE
|
|
43
|
+
if (c.selectNode(s), t.endContainer.nodeType === Node.TEXT_NODE)
|
|
44
|
+
c.setEnd(s, t.endOffset);
|
|
45
|
+
else {
|
|
46
|
+
const f = t.endContainer.childNodes[t.endOffset];
|
|
47
|
+
f ? c.setEndBefore(f) : c.setEndAfter(t.endContainer);
|
|
48
|
+
}
|
|
36
49
|
const l = (f) => {
|
|
37
50
|
const p = document.createRange();
|
|
38
51
|
return p.selectNode(f), Array.from(p.getClientRects());
|
|
@@ -65,20 +78,20 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
65
78
|
o.setStartAfter(r), o.collapsed || n.push(o);
|
|
66
79
|
}
|
|
67
80
|
return n.length > 0 ? n : [e];
|
|
68
|
-
},
|
|
81
|
+
}, J = (t) => {
|
|
69
82
|
const e = t.cloneContents();
|
|
70
83
|
return e.querySelectorAll(W).forEach((n) => n.remove()), e;
|
|
71
84
|
}, Pt = (t, e, n = 10, r) => {
|
|
72
85
|
const o = r ? t.startContainer.parentElement.closest(r) : e, s = document.createRange();
|
|
73
86
|
s.setStart(o, 0), s.setEnd(t.startContainer, t.startOffset);
|
|
74
|
-
const i =
|
|
87
|
+
const i = J(s).textContent, c = document.createRange();
|
|
75
88
|
c.setStart(t.endContainer, t.endOffset), o === document.body ? c.setEnd(o, o.childNodes.length) : c.setEndAfter(o);
|
|
76
|
-
const l =
|
|
89
|
+
const l = J(c).textContent;
|
|
77
90
|
return {
|
|
78
91
|
prefix: i.substring(i.length - n),
|
|
79
92
|
suffix: l.substring(0, n)
|
|
80
93
|
};
|
|
81
|
-
}, P = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed),
|
|
94
|
+
}, P = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), it = /^\s*$/, _t = (t) => it.test(t.toString()), Le = (t) => it.test(t.textContent || ""), Dt = (t, e, n, r) => {
|
|
82
95
|
const o = (c) => Math.round(c * 10) / 10, s = {
|
|
83
96
|
top: o(t.top),
|
|
84
97
|
bottom: o(t.bottom),
|
|
@@ -102,17 +115,17 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
102
115
|
return "block-contains";
|
|
103
116
|
} else if (s.top >= i.top && s.bottom <= i.bottom && s.left >= i.left && s.right <= i.right)
|
|
104
117
|
return "block-is-contained";
|
|
105
|
-
},
|
|
118
|
+
}, Ut = (t, e) => {
|
|
106
119
|
const n = Math.min(t.left, e.left), r = Math.max(t.right, e.right), o = Math.min(t.top, e.top), s = Math.max(t.bottom, e.bottom);
|
|
107
120
|
return new DOMRect(n, o, r - n, s - o);
|
|
108
|
-
},
|
|
121
|
+
}, Ft = (t, e = 0.5, n = 0.5) => t.reduce((r, o) => {
|
|
109
122
|
if (o.width === 0 || o.height === 0)
|
|
110
123
|
return r;
|
|
111
124
|
let s = [...r], i = !1;
|
|
112
125
|
for (const c of r) {
|
|
113
|
-
const l =
|
|
126
|
+
const l = Dt(o, c, e, n);
|
|
114
127
|
if (l === "inline-adjacent") {
|
|
115
|
-
s = s.map((f) => f === c ?
|
|
128
|
+
s = s.map((f) => f === c ? Ut(o, c) : f), i = !0;
|
|
116
129
|
break;
|
|
117
130
|
} else if (l === "inline-contains") {
|
|
118
131
|
s = s.map((f) => f === c ? o : f), i = !0;
|
|
@@ -133,12 +146,12 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
133
146
|
for (let e = 0; e < this.length; e++)
|
|
134
147
|
yield this.item(e);
|
|
135
148
|
}
|
|
136
|
-
}),
|
|
149
|
+
}), Kt = (t, e, n) => {
|
|
137
150
|
const r = document.createRange(), o = n ? t.startContainer.parentElement.closest(n) : e;
|
|
138
151
|
r.setStart(o, 0), r.setEnd(t.startContainer, t.startOffset);
|
|
139
|
-
const s =
|
|
152
|
+
const s = J(r).textContent, i = t.toString(), c = s.length || 0, l = c + i.length;
|
|
140
153
|
return n ? { quote: i, start: c, end: l, range: t, offsetReference: o } : { quote: i, start: c, end: l, range: t };
|
|
141
|
-
},
|
|
154
|
+
}, at = (t, e) => {
|
|
142
155
|
var p, u;
|
|
143
156
|
const { start: n, end: r } = t, o = t.offsetReference || e, s = document.createNodeIterator(
|
|
144
157
|
e,
|
|
@@ -178,20 +191,10 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
178
191
|
};
|
|
179
192
|
}, q = (t, e) => P(t.selector) ? t : {
|
|
180
193
|
...t,
|
|
181
|
-
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n :
|
|
182
|
-
}, G = (t, e) => P(t.target.selector) ? t : { ...t, target: q(t.target, e) },
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
for (let n of t.childNodes)
|
|
186
|
-
if (at(n, e))
|
|
187
|
-
return !0;
|
|
188
|
-
return !1;
|
|
189
|
-
}, Wt = (t, e) => {
|
|
190
|
-
const n = t.cloneContents();
|
|
191
|
-
return at(n, e);
|
|
192
|
-
}, Vt = (t, e) => {
|
|
193
|
-
const n = t.cloneRange(), r = e.contains(n.startContainer), o = e.contains(n.endContainer);
|
|
194
|
-
return !r && !o && !Wt(n, e) ? (n.collapse(), n) : (r || n.setStart(e, 0), o || n.setEnd(e, e.childNodes.length), n);
|
|
194
|
+
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : at(n, e))
|
|
195
|
+
}, G = (t, e) => P(t.target.selector) ? t : { ...t, target: q(t.target, e) }, $t = (t, e) => {
|
|
196
|
+
const n = t.cloneRange();
|
|
197
|
+
return e.contains(n.startContainer) || n.setStart(e, 0), e.contains(n.endContainer) || n.setEnd(e, e.childNodes.length), n;
|
|
195
198
|
}, Q = (t) => ({
|
|
196
199
|
...t,
|
|
197
200
|
type: t.type,
|
|
@@ -218,7 +221,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
218
221
|
pointerId: t.pointerId,
|
|
219
222
|
pointerType: t.pointerType,
|
|
220
223
|
timeStamp: t.timeStamp
|
|
221
|
-
}),
|
|
224
|
+
}), X = (t) => ({
|
|
222
225
|
...t,
|
|
223
226
|
type: t.type,
|
|
224
227
|
key: t.key,
|
|
@@ -234,7 +237,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
234
237
|
defaultPrevented: t.defaultPrevented,
|
|
235
238
|
detail: t.detail,
|
|
236
239
|
timeStamp: t.timeStamp
|
|
237
|
-
}),
|
|
240
|
+
}), Wt = (t, e) => {
|
|
238
241
|
const { left: n, top: r, right: o, bottom: s } = t;
|
|
239
242
|
return new DOMRect(n - e.left, r - e.top, o - n, s - r);
|
|
240
243
|
}, Oe = (t, e) => {
|
|
@@ -245,10 +248,10 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
245
248
|
return document.scrollingElement;
|
|
246
249
|
const { overflowY: e } = window.getComputedStyle(t);
|
|
247
250
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ct(t.parentElement);
|
|
248
|
-
},
|
|
251
|
+
}, et = (t, e, n) => {
|
|
249
252
|
const r = n.getBoundingClientRect(), o = n.clientHeight, s = n.clientWidth, i = e.selector[0].range.getBoundingClientRect(), { width: c, height: l } = t.getAnnotationBounds(e.annotation), f = i.top - r.top, p = i.left - r.left, u = n.parentElement ? n.scrollTop : 0, g = n.parentElement ? n.scrollLeft : 0, d = f + u - (o - l) / 2, L = p + g - (s - c) / 2;
|
|
250
253
|
n.scroll({ top: d, left: L, behavior: "smooth" });
|
|
251
|
-
},
|
|
254
|
+
}, Vt = (t, e) => (n, r) => {
|
|
252
255
|
const o = typeof n == "string" ? n : n.id, s = r ? typeof r == "string" ? document.getElementById(r) : r : ct(t);
|
|
253
256
|
if (!s)
|
|
254
257
|
return console.warn(`The scroll parent is missing for the annotation: ${o}`, { container: t }), !1;
|
|
@@ -257,56 +260,56 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
257
260
|
return console.warn(`The annotation is missing in the store: ${o}`), !1;
|
|
258
261
|
const { range: c } = i.target.selector[0];
|
|
259
262
|
if (c && !c.collapsed)
|
|
260
|
-
return
|
|
263
|
+
return et(e, i.target, s), !0;
|
|
261
264
|
const l = q(i.target, t), { range: f } = l.selector[0];
|
|
262
|
-
return f && !f.collapsed ? (
|
|
265
|
+
return f && !f.collapsed ? (et(e, l, s), !0) : !1;
|
|
263
266
|
}, _ = {
|
|
264
267
|
fill: "rgb(0, 128, 255)",
|
|
265
268
|
fillOpacity: 0.18
|
|
266
269
|
}, j = {
|
|
267
270
|
fill: "rgb(0, 128, 255)",
|
|
268
271
|
fillOpacity: 0.45
|
|
269
|
-
},
|
|
272
|
+
}, Yt = (t, e, n, r, o) => {
|
|
270
273
|
var i, c;
|
|
271
274
|
const s = n ? typeof n == "function" ? n(t.annotation, t.state, o) || ((i = t.state) != null && i.selected ? j : _) : n : (c = t.state) != null && c.selected ? j : _;
|
|
272
275
|
return r && r.paint(t, e) || s;
|
|
273
|
-
},
|
|
276
|
+
}, Xt = (t) => {
|
|
274
277
|
const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: r, innerHeight: o } = window, s = -n, i = -e, c = r - n, l = o - e;
|
|
275
278
|
return { top: e, left: n, minX: s, minY: i, maxX: c, maxY: l };
|
|
276
|
-
},
|
|
279
|
+
}, zt = (t) => {
|
|
277
280
|
let e = /* @__PURE__ */ new Set();
|
|
278
281
|
return (r) => {
|
|
279
282
|
const o = r.map((s) => s.id);
|
|
280
283
|
(e.size !== o.length || o.some((s) => !e.has(s))) && t.set(o), e = new Set(o);
|
|
281
284
|
};
|
|
282
|
-
},
|
|
285
|
+
}, tt = (t, e, n, r) => {
|
|
283
286
|
const { store: o, selection: s, hover: i } = e;
|
|
284
287
|
let c, l, f;
|
|
285
|
-
const p =
|
|
286
|
-
const { x, y: T } = t.getBoundingClientRect(),
|
|
287
|
-
|
|
288
|
+
const p = zt(n), u = $((S) => {
|
|
289
|
+
const { x: A, y: T } = t.getBoundingClientRect(), B = o.getAt(S.clientX - A, S.clientY - T, !1, l);
|
|
290
|
+
B ? i.current !== B.id && (t.classList.add("hovered"), i.set(B.id)) : i.current && (t.classList.remove("hovered"), i.set(null));
|
|
288
291
|
}, 10);
|
|
289
292
|
t.addEventListener("pointermove", u);
|
|
290
293
|
const g = $((S = !1) => requestAnimationFrame(() => {
|
|
291
294
|
f && f.clear();
|
|
292
|
-
const
|
|
293
|
-
const
|
|
295
|
+
const A = Xt(t), { minX: T, minY: B, maxX: y, maxY: v } = A, I = l ? o.getIntersecting(T, B, y, v).filter(({ annotation: O }) => l(O)) : o.getIntersecting(T, B, y, v), D = s.selected.map(({ id: O }) => O), M = I.map(({ annotation: O, rects: H }) => {
|
|
296
|
+
const k = D.includes(O.id), U = O.id === i.current;
|
|
294
297
|
return {
|
|
295
298
|
annotation: O,
|
|
296
299
|
rects: H,
|
|
297
|
-
state: { selected:
|
|
300
|
+
state: { selected: k, hovered: U }
|
|
298
301
|
};
|
|
299
302
|
});
|
|
300
|
-
r.redraw(M,
|
|
303
|
+
r.redraw(M, A, c, f, S), setTimeout(() => p(I.map(({ annotation: O }) => O)), 1);
|
|
301
304
|
}), 10), d = (S) => {
|
|
302
305
|
f = S, g();
|
|
303
306
|
}, L = (S) => {
|
|
304
307
|
c = S, g();
|
|
305
308
|
}, w = (S) => {
|
|
306
309
|
l = S, g(!1);
|
|
307
|
-
},
|
|
308
|
-
o.observe(
|
|
309
|
-
const
|
|
310
|
+
}, x = () => g();
|
|
311
|
+
o.observe(x);
|
|
312
|
+
const R = s.subscribe(() => g()), C = i.subscribe(() => g()), N = () => g(!0);
|
|
310
313
|
document.addEventListener("scroll", N, { capture: !0, passive: !0 });
|
|
311
314
|
const E = $(() => {
|
|
312
315
|
o.recalculatePositions(), f == null || f.reset(), g();
|
|
@@ -319,7 +322,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
319
322
|
}, 150));
|
|
320
323
|
return b.observe(document.body, m), {
|
|
321
324
|
destroy: () => {
|
|
322
|
-
t.removeEventListener("pointermove", u), r.destroy(), o.unobserve(
|
|
325
|
+
t.removeEventListener("pointermove", u), r.destroy(), o.unobserve(x), R(), C(), document.removeEventListener("scroll", N), E.clear(), window.removeEventListener("resize", E), a.disconnect(), b.disconnect();
|
|
323
326
|
},
|
|
324
327
|
redraw: g,
|
|
325
328
|
setStyle: L,
|
|
@@ -327,25 +330,25 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
327
330
|
setPainter: d,
|
|
328
331
|
setVisible: r.setVisible
|
|
329
332
|
};
|
|
330
|
-
},
|
|
333
|
+
}, qt = () => {
|
|
331
334
|
const t = document.createElement("canvas");
|
|
332
335
|
return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-canvas-highlight-layer bg", t;
|
|
333
|
-
},
|
|
336
|
+
}, jt = (t, e) => {
|
|
334
337
|
t.width = window.innerWidth, t.height = window.innerHeight;
|
|
335
|
-
},
|
|
338
|
+
}, Gt = (t) => {
|
|
336
339
|
t.classList.add("r6o-annotatable");
|
|
337
|
-
const e =
|
|
340
|
+
const e = qt(), n = e.getContext("2d");
|
|
338
341
|
document.body.appendChild(e);
|
|
339
342
|
const r = (c, l, f, p) => requestAnimationFrame(() => {
|
|
340
343
|
const { width: u, height: g } = e;
|
|
341
344
|
n.clearRect(-0.5, -0.5, u + 1, g + 1), p && p.clear();
|
|
342
345
|
const { top: d, left: L } = l;
|
|
343
|
-
[...c].sort((
|
|
344
|
-
const { annotation: { target: { created: C } } } =
|
|
346
|
+
[...c].sort((x, R) => {
|
|
347
|
+
const { annotation: { target: { created: C } } } = x, { annotation: { target: { created: N } } } = R;
|
|
345
348
|
return C.getTime() - N.getTime();
|
|
346
|
-
}).forEach((
|
|
349
|
+
}).forEach((x) => {
|
|
347
350
|
var E;
|
|
348
|
-
const
|
|
351
|
+
const R = f ? typeof f == "function" ? f(x.annotation, x.state) : f : (E = x.state) != null && E.selected ? j : _, C = p && p.paint(x, l) || R, N = x.rects.map(({ x: a, y: m, width: b, height: h }) => ({
|
|
349
352
|
x: a + L,
|
|
350
353
|
y: m + d,
|
|
351
354
|
width: b,
|
|
@@ -361,7 +364,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
361
364
|
});
|
|
362
365
|
}
|
|
363
366
|
});
|
|
364
|
-
}), o = $(() =>
|
|
367
|
+
}), o = $(() => jt(e), 10);
|
|
365
368
|
return window.addEventListener("resize", o), {
|
|
366
369
|
destroy: () => {
|
|
367
370
|
e.remove(), o.clear(), window.removeEventListener("resize", o);
|
|
@@ -371,13 +374,13 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
371
374
|
},
|
|
372
375
|
redraw: r
|
|
373
376
|
};
|
|
374
|
-
},
|
|
375
|
-
`background-color:${
|
|
377
|
+
}, Qt = (t, e, n) => tt(t, e, n, Gt(t)), Zt = (t) => [
|
|
378
|
+
`background-color:${Z((t == null ? void 0 : t.fill) || _.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? _.fillOpacity : t.fillOpacity).toHex()}`,
|
|
376
379
|
t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
|
|
377
380
|
t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
378
381
|
t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
379
382
|
t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
|
|
380
|
-
].filter(Boolean).join(";"),
|
|
383
|
+
].filter(Boolean).join(";"), Jt = () => {
|
|
381
384
|
const t = document.createElement("style");
|
|
382
385
|
document.getElementsByTagName("head")[0].appendChild(t);
|
|
383
386
|
let e = /* @__PURE__ */ new Set();
|
|
@@ -395,7 +398,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
395
398
|
const p = s.map((u) => {
|
|
396
399
|
var L;
|
|
397
400
|
const g = c ? typeof c == "function" ? c(u.annotation, u.state) : c : (L = u.state) != null && L.selected ? j : _, d = l && l.paint(u, i) || g;
|
|
398
|
-
return `::highlight(_${u.annotation.id}) { ${
|
|
401
|
+
return `::highlight(_${u.annotation.id}) { ${Zt(d)} }`;
|
|
399
402
|
});
|
|
400
403
|
t.innerHTML = p.join(`
|
|
401
404
|
`), CSS.highlights.clear(), s.forEach(({ annotation: u }) => {
|
|
@@ -404,10 +407,10 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
404
407
|
}), e = f;
|
|
405
408
|
}
|
|
406
409
|
};
|
|
407
|
-
},
|
|
410
|
+
}, te = (t, e, n) => tt(t, e, n, Jt()), ee = (t) => (t == null ? void 0 : t.fillOpacity) !== void 0 ? Z((t == null ? void 0 : t.fill) || _.fill).alpha(t.fillOpacity).toHex() : t != null && t.fill ? t.fill : Z(_.fill).alpha(_.fillOpacity).toHex(), ne = (t, e) => {
|
|
408
411
|
const n = (s, i) => s.x <= i.x + i.width && s.x + s.width >= i.x && s.y <= i.y + i.height && s.y + s.height >= i.y, r = (s) => s.rects.reduce((i, c) => i + c.width, 0), o = e.filter(({ rects: s }) => s.some((i) => n(t, i)));
|
|
409
412
|
return o.sort((s, i) => r(i) - r(s)), o.findIndex((s) => s.rects.includes(t));
|
|
410
|
-
},
|
|
413
|
+
}, oe = (t) => {
|
|
411
414
|
t.classList.add("r6o-annotatable");
|
|
412
415
|
const e = document.createElement("div");
|
|
413
416
|
e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
|
|
@@ -420,14 +423,14 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
420
423
|
const g = !(gt(n, i) && p);
|
|
421
424
|
if (!f && !g) return;
|
|
422
425
|
g && (e.innerHTML = ""), [...i].sort((L, w) => {
|
|
423
|
-
const { annotation: { target: { created:
|
|
424
|
-
return
|
|
426
|
+
const { annotation: { target: { created: x } } } = L, { annotation: { target: { created: R } } } = w;
|
|
427
|
+
return x && R ? x.getTime() - R.getTime() : 0;
|
|
425
428
|
}).forEach((L) => {
|
|
426
429
|
L.rects.map((w) => {
|
|
427
|
-
const
|
|
430
|
+
const x = ne(w, i), R = Yt(L, c, l, f, x);
|
|
428
431
|
if (g) {
|
|
429
432
|
const C = document.createElement("span");
|
|
430
|
-
C.className = "r6o-annotation", C.dataset.annotation = L.annotation.id, C.style.left = `${w.x}px`, C.style.top = `${w.y}px`, C.style.width = `${w.width}px`, C.style.height = `${w.height}px`, C.style.backgroundColor =
|
|
433
|
+
C.className = "r6o-annotation", C.dataset.annotation = L.annotation.id, C.style.left = `${w.x}px`, C.style.top = `${w.y}px`, C.style.width = `${w.width}px`, C.style.height = `${w.height}px`, C.style.backgroundColor = ee(R), R.underlineStyle && (C.style.borderStyle = R.underlineStyle), R.underlineColor && (C.style.borderColor = R.underlineColor), R.underlineThickness && (C.style.borderBottomWidth = `${R.underlineThickness}px`), R.underlineOffset && (C.style.paddingBottom = `${R.underlineOffset}px`), e.appendChild(C);
|
|
431
434
|
}
|
|
432
435
|
});
|
|
433
436
|
}), n = i;
|
|
@@ -436,10 +439,10 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
436
439
|
i ? e.classList.remove("hidden") : e.classList.add("hidden");
|
|
437
440
|
}
|
|
438
441
|
};
|
|
439
|
-
},
|
|
440
|
-
parse: (n) =>
|
|
441
|
-
serialize: (n) =>
|
|
442
|
-
}),
|
|
442
|
+
}, se = (t, e, n) => tt(t, e, n, oe(t)), ke = (t, e) => ({
|
|
443
|
+
parse: (n) => ae(n),
|
|
444
|
+
serialize: (n) => ce(n, t, e)
|
|
445
|
+
}), re = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, ie = (t) => {
|
|
443
446
|
const {
|
|
444
447
|
id: e,
|
|
445
448
|
creator: n,
|
|
@@ -470,7 +473,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
470
473
|
}
|
|
471
474
|
return u;
|
|
472
475
|
}, {});
|
|
473
|
-
if (c.outdated || (c.outdated = "outdated" in l ? l.outdated : void 0),
|
|
476
|
+
if (c.outdated || (c.outdated = "outdated" in l ? l.outdated : void 0), re(p))
|
|
474
477
|
c.selector.push(
|
|
475
478
|
{
|
|
476
479
|
...p,
|
|
@@ -488,14 +491,14 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
488
491
|
}
|
|
489
492
|
}
|
|
490
493
|
return { parsed: c };
|
|
491
|
-
},
|
|
494
|
+
}, ae = (t) => {
|
|
492
495
|
const e = t.id || st(), {
|
|
493
496
|
creator: n,
|
|
494
497
|
created: r,
|
|
495
498
|
modified: o,
|
|
496
499
|
body: s,
|
|
497
500
|
...i
|
|
498
|
-
} = t, c = pt(s, e), l =
|
|
501
|
+
} = t, c = pt(s, e), l = ie(t);
|
|
499
502
|
return "error" in l ? { error: l.error } : {
|
|
500
503
|
parsed: {
|
|
501
504
|
...i,
|
|
@@ -504,7 +507,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
504
507
|
target: l.parsed
|
|
505
508
|
}
|
|
506
509
|
};
|
|
507
|
-
},
|
|
510
|
+
}, ce = (t, e, n) => {
|
|
508
511
|
const { bodies: r, target: o, ...s } = t, {
|
|
509
512
|
selector: i,
|
|
510
513
|
creator: c,
|
|
@@ -512,18 +515,18 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
512
515
|
updated: f,
|
|
513
516
|
...p
|
|
514
517
|
} = o, u = i.map((g) => {
|
|
515
|
-
const { id: d, quote: L, start: w, end:
|
|
518
|
+
const { id: d, quote: L, start: w, end: x, range: R } = g, C = {
|
|
516
519
|
type: "TextQuoteSelector",
|
|
517
520
|
exact: L
|
|
518
521
|
};
|
|
519
522
|
if (n) {
|
|
520
|
-
const { prefix: E, suffix: a } = Pt(
|
|
523
|
+
const { prefix: E, suffix: a } = Pt(R, n);
|
|
521
524
|
C.prefix = E, C.suffix = a;
|
|
522
525
|
}
|
|
523
526
|
const N = {
|
|
524
527
|
type: "TextPositionSelector",
|
|
525
528
|
start: w,
|
|
526
|
-
end:
|
|
529
|
+
end: x
|
|
527
530
|
};
|
|
528
531
|
return {
|
|
529
532
|
...p,
|
|
@@ -545,18 +548,18 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
545
548
|
modified: f == null ? void 0 : f.toISOString(),
|
|
546
549
|
target: u
|
|
547
550
|
};
|
|
548
|
-
},
|
|
549
|
-
const o = new xt(), s = /* @__PURE__ */ new Map(), i =
|
|
551
|
+
}, le = (t, e, n, r) => {
|
|
552
|
+
const o = new xt(), s = /* @__PURE__ */ new Map(), i = Tt(), c = (a, m) => {
|
|
550
553
|
const b = a.selector.flatMap((S) => {
|
|
551
|
-
const
|
|
552
|
-
return It(
|
|
553
|
-
}), h =
|
|
554
|
+
const A = P([S]) ? S.range : at(S, e).range;
|
|
555
|
+
return It(A);
|
|
556
|
+
}), h = Ft(b, n, r).map((S) => Wt(S, m));
|
|
554
557
|
return h.map((S) => {
|
|
555
|
-
const { x, y: T, width:
|
|
558
|
+
const { x: A, y: T, width: B, height: y } = S;
|
|
556
559
|
return {
|
|
557
|
-
minX:
|
|
560
|
+
minX: A,
|
|
558
561
|
minY: T,
|
|
559
|
-
maxX:
|
|
562
|
+
maxX: A + B,
|
|
560
563
|
maxY: T + y,
|
|
561
564
|
annotation: {
|
|
562
565
|
id: a.annotation,
|
|
@@ -576,11 +579,11 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
576
579
|
u(a), p(a);
|
|
577
580
|
}, d = (a, m = !0) => {
|
|
578
581
|
m && f();
|
|
579
|
-
const b = e.getBoundingClientRect(), h = a.map((
|
|
580
|
-
h.forEach(({ target:
|
|
581
|
-
T.length > 0 && s.set(
|
|
582
|
+
const b = e.getBoundingClientRect(), h = a.map((A) => ({ target: A, rects: c(A, b) }));
|
|
583
|
+
h.forEach(({ target: A, rects: T }) => {
|
|
584
|
+
T.length > 0 && s.set(A.annotation, T);
|
|
582
585
|
});
|
|
583
|
-
const S = h.flatMap(({ rects:
|
|
586
|
+
const S = h.flatMap(({ rects: A }) => A);
|
|
584
587
|
o.load(S);
|
|
585
588
|
}, L = (a, m, b = !1) => {
|
|
586
589
|
const h = o.search({
|
|
@@ -588,19 +591,19 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
588
591
|
minY: m,
|
|
589
592
|
maxX: a,
|
|
590
593
|
maxY: m
|
|
591
|
-
}), S = (
|
|
592
|
-
return h.length > 0 ? (h.sort((
|
|
594
|
+
}), S = (A) => A.annotation.rects.reduce((T, B) => T + B.width * B.height, 0);
|
|
595
|
+
return h.length > 0 ? (h.sort((A, T) => S(A) - S(T)), b ? h.map((A) => A.annotation.id) : [h[0].annotation.id]) : [];
|
|
593
596
|
}, w = (a) => {
|
|
594
|
-
const m =
|
|
597
|
+
const m = x(a);
|
|
595
598
|
if (m.length === 0)
|
|
596
599
|
return;
|
|
597
|
-
let b = m[0].left, h = m[0].top, S = m[0].right,
|
|
600
|
+
let b = m[0].left, h = m[0].top, S = m[0].right, A = m[0].bottom;
|
|
598
601
|
for (let T = 1; T < m.length; T++) {
|
|
599
|
-
const
|
|
600
|
-
b = Math.min(b,
|
|
602
|
+
const B = m[T];
|
|
603
|
+
b = Math.min(b, B.left), h = Math.min(h, B.top), S = Math.max(S, B.right), A = Math.max(A, B.bottom);
|
|
601
604
|
}
|
|
602
|
-
return new DOMRect(b, h, S - b,
|
|
603
|
-
},
|
|
605
|
+
return new DOMRect(b, h, S - b, A - h);
|
|
606
|
+
}, x = (a) => {
|
|
604
607
|
const m = s.get(a);
|
|
605
608
|
return m ? m[0].annotation.rects : [];
|
|
606
609
|
};
|
|
@@ -609,12 +612,12 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
609
612
|
clear: f,
|
|
610
613
|
getAt: L,
|
|
611
614
|
getAnnotationBounds: w,
|
|
612
|
-
getAnnotationRects:
|
|
615
|
+
getAnnotationRects: x,
|
|
613
616
|
getIntersecting: (a, m, b, h) => {
|
|
614
|
-
const S = o.search({ minX: a, minY: m, maxX: b, maxY: h }),
|
|
615
|
-
return Array.from(
|
|
617
|
+
const S = o.search({ minX: a, minY: m, maxX: b, maxY: h }), A = new Set(S.map((T) => T.annotation.id));
|
|
618
|
+
return Array.from(A).map((T) => ({
|
|
616
619
|
annotation: t.getAnnotation(T),
|
|
617
|
-
rects:
|
|
620
|
+
rects: x(T)
|
|
618
621
|
})).filter((T) => !!T.annotation);
|
|
619
622
|
},
|
|
620
623
|
insert: p,
|
|
@@ -627,32 +630,32 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
627
630
|
update: g,
|
|
628
631
|
on: (a, m) => i.on(a, m)
|
|
629
632
|
};
|
|
630
|
-
},
|
|
633
|
+
}, de = (t, e) => {
|
|
631
634
|
var C, N;
|
|
632
|
-
const n =
|
|
635
|
+
const n = bt(), r = le(n, t, (C = e.mergeHighlights) == null ? void 0 : C.horizontalTolerance, (N = e.mergeHighlights) == null ? void 0 : N.verticalTolerance), o = yt(n, e.userSelectAction, e.adapter), s = St(n), i = Ct(), c = (E, a = K.LOCAL) => {
|
|
633
636
|
const m = G(E, t), b = P(m.target.selector);
|
|
634
637
|
return b && n.addAnnotation(m, a), b;
|
|
635
|
-
}, l = (E, a = !0, m =
|
|
638
|
+
}, l = (E, a = !0, m = K.LOCAL) => {
|
|
636
639
|
const b = E.map((S) => G(S, t)), h = b.filter((S) => !P(S.target.selector));
|
|
637
640
|
return n.bulkAddAnnotations(b, a, m), h;
|
|
638
|
-
}, f = (E, a =
|
|
641
|
+
}, f = (E, a = K.LOCAL) => {
|
|
639
642
|
const m = E.map((h) => G(h, t)), b = m.filter((h) => !P(h.target.selector));
|
|
640
643
|
return m.forEach((h) => {
|
|
641
644
|
n.getAnnotation(h.id) ? n.updateAnnotation(h, a) : n.addAnnotation(h, a);
|
|
642
645
|
}), b;
|
|
643
|
-
}, p = (E, a =
|
|
646
|
+
}, p = (E, a = K.LOCAL) => {
|
|
644
647
|
const m = q(E, t);
|
|
645
648
|
n.updateTarget(m, a);
|
|
646
|
-
}, u = (E, a =
|
|
649
|
+
}, u = (E, a = K.LOCAL) => {
|
|
647
650
|
const m = E.map((b) => q(b, t));
|
|
648
651
|
n.bulkUpdateTargets(m, a);
|
|
649
652
|
};
|
|
650
653
|
function g(E, a, m, b) {
|
|
651
|
-
const h = m || !!b, S = r.getAt(E, a, h).map((T) => n.getAnnotation(T)),
|
|
652
|
-
if (
|
|
653
|
-
return m ?
|
|
654
|
+
const h = m || !!b, S = r.getAt(E, a, h).map((T) => n.getAnnotation(T)), A = b ? S.filter(b) : S;
|
|
655
|
+
if (A.length !== 0)
|
|
656
|
+
return m ? A : A[0];
|
|
654
657
|
}
|
|
655
|
-
const d = (E) => r.getAnnotationRects(E).length > 0 ? r.getAnnotationBounds(E) : void 0, L = (E, a, m, b) => r.getIntersecting(E, a, m, b), w = (E) => r.getAnnotationRects(E),
|
|
658
|
+
const d = (E) => r.getAnnotationRects(E).length > 0 ? r.getAnnotationBounds(E) : void 0, L = (E, a, m, b) => r.getIntersecting(E, a, m, b), w = (E) => r.getAnnotationRects(E), x = () => r.recalculate(), R = (E) => r.on("recalculate", E);
|
|
656
659
|
return n.observe(({ changes: E }) => {
|
|
657
660
|
const a = (E.deleted || []).filter((h) => P(h.target.selector)), m = (E.created || []).filter((h) => P(h.target.selector)), b = (E.updated || []).filter((h) => P(h.newValue.target.selector));
|
|
658
661
|
(a == null ? void 0 : a.length) > 0 && a.forEach((h) => r.remove(h.target)), m.length > 0 && r.set(m.map((h) => h.target), !1), (b == null ? void 0 : b.length) > 0 && b.forEach(({ newValue: h }) => r.update(h.target));
|
|
@@ -667,8 +670,8 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
667
670
|
getAnnotationRects: w,
|
|
668
671
|
getIntersecting: L,
|
|
669
672
|
getAt: g,
|
|
670
|
-
recalculatePositions:
|
|
671
|
-
onRecalculatePositions:
|
|
673
|
+
recalculatePositions: x,
|
|
674
|
+
onRecalculatePositions: R,
|
|
672
675
|
updateTarget: p
|
|
673
676
|
},
|
|
674
677
|
selection: o,
|
|
@@ -680,7 +683,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
680
683
|
t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
|
|
681
684
|
const e = t.getContext("2d");
|
|
682
685
|
return e.scale(2, 2), e.translate(0.5, 0.5), t;
|
|
683
|
-
},
|
|
686
|
+
}, ue = (t, e = {}) => {
|
|
684
687
|
const n = fe(), r = n.getContext("2d");
|
|
685
688
|
document.body.appendChild(n);
|
|
686
689
|
const o = /* @__PURE__ */ new Map(), s = (p) => Array.from(o.entries()).filter(([u, g]) => g.presenceKey === p.presenceKey).map(([u, g]) => u);
|
|
@@ -698,10 +701,10 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
698
701
|
e.font && (r.font = e.font);
|
|
699
702
|
const d = o.get(p.annotation.id);
|
|
700
703
|
if (d) {
|
|
701
|
-
const { height: L } = p.rects[0], w = p.rects[0].x + u.left,
|
|
702
|
-
r.fillStyle = d.appearance.color, r.fillRect(w - 2,
|
|
703
|
-
const
|
|
704
|
-
return r.fillRect(w - 2,
|
|
704
|
+
const { height: L } = p.rects[0], w = p.rects[0].x + u.left, x = p.rects[0].y + u.top;
|
|
705
|
+
r.fillStyle = d.appearance.color, r.fillRect(w - 2, x - 2.5, 2, L + 5);
|
|
706
|
+
const R = r.measureText(d.appearance.label), C = R.width + 6, N = R.actualBoundingBoxAscent + R.actualBoundingBoxDescent + 8, E = R.fontBoundingBoxAscent ? 8 : 6.5;
|
|
707
|
+
return r.fillRect(w - 2, x - 2.5 - N, C, N), r.fillStyle = "#fff", r.fillText(d.appearance.label, w + 1, x - E), {
|
|
705
708
|
fill: d.appearance.color,
|
|
706
709
|
fillOpacity: g ? 0.45 : 0.18
|
|
707
710
|
};
|
|
@@ -713,10 +716,10 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
713
716
|
p.scale(2, 2), p.translate(0.5, 0.5);
|
|
714
717
|
}
|
|
715
718
|
};
|
|
716
|
-
},
|
|
719
|
+
}, nt = 300, lt = ["up", "down", "left", "right"], dt = kt ? "⌘+a" : "ctrl+a", ge = [
|
|
717
720
|
...lt.map((t) => `shift+${t}`),
|
|
718
721
|
dt
|
|
719
|
-
],
|
|
722
|
+
], me = (t, e, n) => {
|
|
720
723
|
const { store: r, selection: o } = e;
|
|
721
724
|
let s;
|
|
722
725
|
const {
|
|
@@ -727,49 +730,49 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
727
730
|
} = n, p = (y) => s = y;
|
|
728
731
|
let u;
|
|
729
732
|
const g = (y) => u = y;
|
|
730
|
-
let d, L, w,
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
}, C = (
|
|
734
|
-
|
|
733
|
+
let d, L, w, x = i;
|
|
734
|
+
const R = (y) => {
|
|
735
|
+
x = y, N.clear(), y || (d = void 0, L = void 0, w = void 0);
|
|
736
|
+
}, C = () => {
|
|
737
|
+
x && L !== !1 && (d = {
|
|
735
738
|
annotation: st(),
|
|
736
739
|
selector: [],
|
|
737
740
|
creator: s,
|
|
738
741
|
created: /* @__PURE__ */ new Date()
|
|
739
742
|
});
|
|
740
743
|
}, N = $((y) => {
|
|
741
|
-
if (!
|
|
744
|
+
if (!x) return;
|
|
742
745
|
const v = document.getSelection();
|
|
743
746
|
if (!(v != null && v.anchorNode))
|
|
744
747
|
return;
|
|
745
|
-
|
|
748
|
+
const I = Array.from(Array(v.rangeCount).keys()).map((k) => v.getRangeAt(k));
|
|
749
|
+
if (!I.some((k) => k.intersectsNode(t))) {
|
|
746
750
|
d = void 0;
|
|
747
751
|
return;
|
|
748
752
|
}
|
|
749
|
-
const
|
|
750
|
-
if ((w == null ? void 0 : w.type) === "pointerdown" && (
|
|
751
|
-
if (v.isCollapsed) {
|
|
753
|
+
const D = y.timeStamp - ((w == null ? void 0 : w.timeStamp) || y.timeStamp);
|
|
754
|
+
if ((w == null ? void 0 : w.type) === "pointerdown" && (D < 1e3 && !d || v.isCollapsed && D < nt) && C(), d || C(), v.isCollapsed) {
|
|
752
755
|
r.getAnnotation(d.annotation) && (o.clear(), r.deleteAnnotation(d.annotation));
|
|
753
756
|
return;
|
|
754
757
|
}
|
|
755
|
-
const M =
|
|
756
|
-
if (M.every((
|
|
757
|
-
const O = M.flatMap((
|
|
758
|
-
(O.length !== d.selector.length || O.some((
|
|
759
|
-
var
|
|
760
|
-
return
|
|
758
|
+
const M = I.map((k) => $t(k, t));
|
|
759
|
+
if (M.every((k) => _t(k))) return;
|
|
760
|
+
const O = M.flatMap((k) => Ht(t, k.cloneRange()));
|
|
761
|
+
(O.length > 0 && !d || O.length !== d.selector.length || O.some((k, U) => {
|
|
762
|
+
var F;
|
|
763
|
+
return k.toString() !== ((F = d.selector[U]) == null ? void 0 : F.quote);
|
|
761
764
|
})) && (d = {
|
|
762
765
|
...d,
|
|
763
|
-
selector: O.map((
|
|
766
|
+
selector: O.map((k) => Kt(k, t, c)),
|
|
764
767
|
updated: /* @__PURE__ */ new Date()
|
|
765
|
-
}, r.getAnnotation(d.annotation) ? r.updateTarget(d,
|
|
768
|
+
}, r.getAnnotation(d.annotation) ? r.updateTarget(d, K.LOCAL) : o.clear());
|
|
766
769
|
}, 10), E = (y) => {
|
|
767
770
|
w = Q(y), L = w.button === 0;
|
|
768
771
|
}, a = async (y) => {
|
|
769
772
|
if (!L) return;
|
|
770
773
|
const v = Q(y), I = () => {
|
|
771
774
|
const { x: M, y: O } = t.getBoundingClientRect();
|
|
772
|
-
if (
|
|
775
|
+
if (z(t, v.target)) {
|
|
773
776
|
(typeof f == "function" ? f(v, t) : f === "ALWAYS") && o.clear();
|
|
774
777
|
return;
|
|
775
778
|
}
|
|
@@ -780,14 +783,14 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
780
783
|
u
|
|
781
784
|
);
|
|
782
785
|
if (H) {
|
|
783
|
-
const { selected:
|
|
784
|
-
(
|
|
786
|
+
const { selected: k } = o, U = new Set(k.map((V) => V.id)), F = Array.isArray(H) ? H.map((V) => V.id) : [H.id];
|
|
787
|
+
(U.size !== F.length || !F.every((V) => U.has(V))) && o.userSelect(F, v);
|
|
785
788
|
} else
|
|
786
789
|
o.clear();
|
|
787
790
|
};
|
|
788
|
-
if (v.timeStamp - w.timeStamp <
|
|
791
|
+
if (v.timeStamp - w.timeStamp < nt) {
|
|
789
792
|
await m();
|
|
790
|
-
const M = document.getSelection(), O =
|
|
793
|
+
const M = document.getSelection(), O = z(t, w.target), H = z(t, v.target);
|
|
791
794
|
if (M != null && M.isCollapsed || O && H) {
|
|
792
795
|
d = void 0, I();
|
|
793
796
|
return;
|
|
@@ -797,32 +800,32 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
797
800
|
}, m = async () => {
|
|
798
801
|
const y = document.getSelection();
|
|
799
802
|
let v = !1, I = y == null ? void 0 : y.isCollapsed;
|
|
800
|
-
const
|
|
801
|
-
return setTimeout(() => v = !0, 50),
|
|
803
|
+
const D = () => I || v, M = 1;
|
|
804
|
+
return setTimeout(() => v = !0, 50), Rt(() => I = y == null ? void 0 : y.isCollapsed, M, D);
|
|
802
805
|
}, b = (y) => {
|
|
803
806
|
const v = document.getSelection();
|
|
804
807
|
v != null && v.isCollapsed || ((!d || d.selector.length === 0) && N(y), d && (T(), o.userSelect(d.annotation, Q(y))));
|
|
805
808
|
}, h = (y) => {
|
|
806
|
-
|
|
809
|
+
x && y.key === "Shift" && d && (document.getSelection().isCollapsed || (T(), o.userSelect(d.annotation, X(y))));
|
|
807
810
|
}, S = (y) => {
|
|
808
811
|
const v = () => setTimeout(() => {
|
|
809
812
|
(d == null ? void 0 : d.selector.length) > 0 && (o.clear(), r.addAnnotation({
|
|
810
813
|
id: d.annotation,
|
|
811
814
|
bodies: [],
|
|
812
815
|
target: d
|
|
813
|
-
}), o.userSelect(d.annotation,
|
|
816
|
+
}), o.userSelect(d.annotation, X(y))), document.removeEventListener("selectionchange", v);
|
|
814
817
|
}, 100);
|
|
815
|
-
document.addEventListener("selectionchange", v), C(
|
|
818
|
+
document.addEventListener("selectionchange", v), C();
|
|
816
819
|
};
|
|
817
|
-
|
|
818
|
-
y.repeat || (w =
|
|
819
|
-
}),
|
|
820
|
-
w =
|
|
820
|
+
Y(ge.join(","), { element: t, keydown: !0, keyup: !1 }, (y) => {
|
|
821
|
+
y.repeat || (w = X(y));
|
|
822
|
+
}), Y(dt, { keydown: !0, keyup: !1 }, (y) => {
|
|
823
|
+
w = X(y), S(y);
|
|
821
824
|
});
|
|
822
|
-
const
|
|
825
|
+
const A = (y) => {
|
|
823
826
|
y.repeat || y.target !== t && y.target !== document.body || (d = void 0, o.clear());
|
|
824
827
|
};
|
|
825
|
-
|
|
828
|
+
Y(lt.join(","), { keydown: !0, keyup: !1 }, A);
|
|
826
829
|
const T = () => {
|
|
827
830
|
const y = r.getAnnotation(d.annotation);
|
|
828
831
|
if (!y) {
|
|
@@ -838,39 +841,39 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
838
841
|
};
|
|
839
842
|
return document.addEventListener("pointerdown", E), document.addEventListener("pointerup", a), document.addEventListener("contextmenu", b), t.addEventListener("keyup", h), t.addEventListener("selectstart", C), document.addEventListener("selectionchange", N), {
|
|
840
843
|
destroy: () => {
|
|
841
|
-
d = void 0, L = void 0, w = void 0, N.clear(), document.removeEventListener("pointerdown", E), document.removeEventListener("pointerup", a), document.removeEventListener("contextmenu", b), t.removeEventListener("keyup", h), t.removeEventListener("selectstart", C), document.removeEventListener("selectionchange", N),
|
|
844
|
+
d = void 0, L = void 0, w = void 0, N.clear(), document.removeEventListener("pointerdown", E), document.removeEventListener("pointerup", a), document.removeEventListener("contextmenu", b), t.removeEventListener("keyup", h), t.removeEventListener("selectstart", C), document.removeEventListener("selectionchange", N), Y.unbind();
|
|
842
845
|
},
|
|
843
846
|
setFilter: g,
|
|
844
847
|
setUser: p,
|
|
845
|
-
setAnnotatingEnabled:
|
|
848
|
+
setAnnotatingEnabled: R
|
|
846
849
|
};
|
|
847
|
-
},
|
|
850
|
+
}, pe = (t, e) => ({
|
|
848
851
|
...t,
|
|
849
852
|
annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
|
|
850
853
|
user: t.user || e.user
|
|
851
|
-
}),
|
|
854
|
+
}), ot = "SPANS", Be = (t, e = {}) => {
|
|
852
855
|
Nt(t), Bt(t);
|
|
853
|
-
const n =
|
|
856
|
+
const n = pe(e, {
|
|
854
857
|
annotatingEnabled: !0,
|
|
855
858
|
user: Et()
|
|
856
|
-
}), r =
|
|
859
|
+
}), r = de(t, n), { selection: o, viewport: s } = r, i = r.store, c = wt(i), l = At(r, c, n.adapter);
|
|
857
860
|
let f = n.user;
|
|
858
|
-
const p = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" :
|
|
861
|
+
const p = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ot : n.renderer || ot, u = p === "SPANS" ? se(t, r, s) : p === "CSS_HIGHLIGHTS" ? te(t, r, s) : p === "CANVAS" ? Qt(t, r, s) : void 0;
|
|
859
862
|
if (!u)
|
|
860
863
|
throw `Unknown renderer implementation: ${p}`;
|
|
861
864
|
console.debug(`Using ${p} renderer`), n.style && u.setStyle(n.style);
|
|
862
|
-
const g =
|
|
865
|
+
const g = me(t, r, n);
|
|
863
866
|
g.setUser(f), g.setAnnotatingEnabled(n.annotatingEnabled);
|
|
864
867
|
const d = vt(r, c, n.adapter), L = () => f, w = (a) => {
|
|
865
868
|
g.setAnnotatingEnabled(
|
|
866
869
|
a === void 0 ? !0 : a
|
|
867
870
|
);
|
|
868
|
-
},
|
|
871
|
+
}, x = (a) => {
|
|
869
872
|
u.setFilter(a), g.setFilter(a);
|
|
870
|
-
},
|
|
873
|
+
}, R = (a) => {
|
|
871
874
|
f = a, g.setUser(a);
|
|
872
875
|
}, C = (a) => {
|
|
873
|
-
a && (u.setPainter(
|
|
876
|
+
a && (u.setPainter(ue(a, n.presence)), a.on("selectionChange", () => u.redraw()));
|
|
874
877
|
}, N = (a) => {
|
|
875
878
|
a ? o.setSelected(a) : o.clear();
|
|
876
879
|
};
|
|
@@ -882,16 +885,16 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
|
|
|
882
885
|
element: t,
|
|
883
886
|
getUser: L,
|
|
884
887
|
setAnnotatingEnabled: w,
|
|
885
|
-
setFilter:
|
|
888
|
+
setFilter: x,
|
|
886
889
|
setStyle: u.setStyle.bind(u),
|
|
887
890
|
redraw: u.redraw.bind(u),
|
|
888
|
-
setUser:
|
|
891
|
+
setUser: R,
|
|
889
892
|
setSelected: N,
|
|
890
893
|
setPresenceProvider: C,
|
|
891
894
|
setVisible: u.setVisible.bind(u),
|
|
892
895
|
on: l.on,
|
|
893
896
|
off: l.off,
|
|
894
|
-
scrollIntoView:
|
|
897
|
+
scrollIntoView: Vt(t, i),
|
|
895
898
|
state: r
|
|
896
899
|
};
|
|
897
900
|
};
|
|
@@ -904,41 +907,42 @@ export {
|
|
|
904
907
|
Pe as UserSelectAction,
|
|
905
908
|
ke as W3CTextFormat,
|
|
906
909
|
Nt as cancelSingleClickEvents,
|
|
907
|
-
|
|
910
|
+
X as cloneKeyboardEvent,
|
|
908
911
|
Q as clonePointerEvent,
|
|
909
912
|
_e as createBody,
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
913
|
+
Qt as createCanvasRenderer,
|
|
914
|
+
te as createHighlightsRenderer,
|
|
915
|
+
ue as createPresencePainter,
|
|
916
|
+
Jt as createRenderer,
|
|
917
|
+
me as createSelectionHandler,
|
|
918
|
+
se as createSpansRenderer,
|
|
916
919
|
Be as createTextAnnotator,
|
|
917
|
-
|
|
918
|
-
|
|
920
|
+
de as createTextAnnotatorState,
|
|
921
|
+
pe as fillDefaults,
|
|
919
922
|
It as getHighlightClientRects,
|
|
920
923
|
Pt as getQuoteContext,
|
|
921
|
-
|
|
924
|
+
J as getRangeAnnotatableContents,
|
|
922
925
|
kt as isMac,
|
|
923
|
-
|
|
926
|
+
Le as isNodeWhitespaceOrEmpty,
|
|
927
|
+
z as isNotAnnotatable,
|
|
924
928
|
Lt as isRangeAnnotatable,
|
|
929
|
+
_t as isRangeWhitespaceOrEmpty,
|
|
925
930
|
P as isRevived,
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
ce as parseW3CTextAnnotation,
|
|
931
|
+
Ft as mergeClientRects,
|
|
932
|
+
Yt as paint,
|
|
933
|
+
ae as parseW3CTextAnnotation,
|
|
930
934
|
Bt as programmaticallyFocusable,
|
|
931
|
-
|
|
935
|
+
Kt as rangeToSelector,
|
|
932
936
|
G as reviveAnnotation,
|
|
933
|
-
|
|
937
|
+
at as reviveSelector,
|
|
934
938
|
q as reviveTarget,
|
|
935
|
-
|
|
936
|
-
|
|
939
|
+
Vt as scrollIntoView,
|
|
940
|
+
ce as serializeW3CTextAnnotation,
|
|
937
941
|
Ht as splitAnnotatableRanges,
|
|
938
942
|
Ne as toDomRectList,
|
|
939
|
-
|
|
943
|
+
Wt as toParentBounds,
|
|
940
944
|
Oe as toViewportBounds,
|
|
941
|
-
|
|
942
|
-
|
|
945
|
+
$t as trimRangeToContainer,
|
|
946
|
+
it as whitespaceOrEmptyRegex
|
|
943
947
|
};
|
|
944
948
|
//# sourceMappingURL=text-annotator.es.js.map
|