@recogito/text-annotator 4.2.1 → 4.2.2
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.
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { v4 as dt } from "uuid";
|
|
2
|
-
import { parseW3CBodies as
|
|
2
|
+
import { parseW3CBodies as Tt, serializeW3CBodies as At, parseW3CUser as vt, UserSelectAction as Rt, createStore as wt, createSelectionState as xt, createHoverState as Lt, createViewportState as Nt, Origin as K, createAnonymousGuest as Ot, createUndoStack as kt, createLifecycleObserver as _t, createBaseAnnotator as Mt } from "@annotorious/core";
|
|
3
3
|
import { Origin as De, UserSelectAction as He, createBody as Pe } from "@annotorious/core";
|
|
4
4
|
import { createNanoEvents as ut } from "nanoevents";
|
|
5
5
|
import { colord as ot } from "colord";
|
|
6
|
-
import { dequal as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
6
|
+
import { dequal as Bt } from "dequal/lite";
|
|
7
|
+
import It from "rbush";
|
|
8
|
+
import Dt from "debounce";
|
|
9
9
|
import G from "hotkeys-js";
|
|
10
|
-
import { poll as
|
|
11
|
-
const
|
|
10
|
+
import { poll as Ht } from "poll";
|
|
11
|
+
const xe = (t) => t.target.selector.every(I), Le = (t) => t.selector.every(I);
|
|
12
12
|
function I(t) {
|
|
13
13
|
return Array.isArray(t) ? t.every((e) => "range" in e && e.range instanceof Range && !e.range.collapsed) : "range" in t && t.range instanceof Range && !t.range.collapsed;
|
|
14
14
|
}
|
|
15
|
-
const
|
|
15
|
+
const ft = typeof navigator < "u" && navigator.platform.startsWith("Mac"), gt = "not-annotatable", W = `.${gt}`, Z = (t, e) => t.contains(e) ? !!(e instanceof HTMLElement ? e.closest(W) : e.parentElement?.closest(W)) : !0, mt = (t, e) => {
|
|
16
16
|
const o = e.commonAncestorContainer;
|
|
17
17
|
return !Z(t, o);
|
|
18
|
-
},
|
|
18
|
+
}, pt = /^\s*$/, Pt = (t) => pt.test(t.toString()), Ne = (t) => pt.test(t.textContent || ""), Ut = (t) => {
|
|
19
19
|
if (t.length === 0) return [];
|
|
20
20
|
if (t.length === 1) return [t[0]];
|
|
21
21
|
t.sort((s, n) => {
|
|
@@ -26,20 +26,20 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
26
26
|
return [...i.merged, i.current];
|
|
27
27
|
}, Ft = (t) => {
|
|
28
28
|
(!t.hasAttribute("tabindex") || t.tabIndex < -1) && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
|
|
29
|
-
},
|
|
29
|
+
}, Kt = function* (t) {
|
|
30
30
|
const e = document.createTreeWalker(
|
|
31
31
|
t.commonAncestorContainer,
|
|
32
32
|
NodeFilter.SHOW_ELEMENT,
|
|
33
|
-
(i) => i instanceof HTMLElement && i.classList.contains(
|
|
33
|
+
(i) => i instanceof HTMLElement && i.classList.contains(gt) && !i.parentElement?.closest(W) && t.intersectsNode(i) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
|
34
34
|
);
|
|
35
35
|
let o;
|
|
36
36
|
for (; o = e.nextNode(); )
|
|
37
37
|
o instanceof HTMLElement && (yield o);
|
|
38
|
-
},
|
|
39
|
-
if (!
|
|
38
|
+
}, Wt = (t, e) => {
|
|
39
|
+
if (!mt(t, e)) return [];
|
|
40
40
|
const o = [];
|
|
41
41
|
let i = null;
|
|
42
|
-
for (const s of
|
|
42
|
+
for (const s of Kt(e)) {
|
|
43
43
|
let n;
|
|
44
44
|
i ? (n = document.createRange(), n.setStartAfter(i), n.setEndBefore(s)) : (n = e.cloneRange(), n.setEndBefore(s)), n.collapsed || o.push(n), i = s;
|
|
45
45
|
}
|
|
@@ -51,10 +51,10 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
51
51
|
}, st = (t) => {
|
|
52
52
|
const e = t.cloneContents();
|
|
53
53
|
return e.querySelectorAll(W).forEach((o) => o.remove()), e;
|
|
54
|
-
},
|
|
54
|
+
}, $t = (t, e) => {
|
|
55
55
|
const o = t.cloneRange();
|
|
56
56
|
return e.contains(o.startContainer) || o.setStart(e, 0), e.contains(o.endContainer) || o.setEnd(e, e.childNodes.length), o;
|
|
57
|
-
}, it = new Intl.Segmenter(void 0, { granularity: "grapheme" }),
|
|
57
|
+
}, it = new Intl.Segmenter(void 0, { granularity: "grapheme" }), Yt = (t, e, o = 10, i) => {
|
|
58
58
|
const s = i ? t.startContainer.parentElement.closest(i) : e, n = document.createRange();
|
|
59
59
|
n.setStart(s, 0), n.setEnd(t.startContainer, t.startOffset);
|
|
60
60
|
const r = st(n).textContent, a = document.createRange();
|
|
@@ -64,12 +64,13 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
64
64
|
prefix: m.slice(-o).map((y) => y.segment).join(""),
|
|
65
65
|
suffix: f.slice(0, o).map((y) => y.segment).join("")
|
|
66
66
|
};
|
|
67
|
-
},
|
|
67
|
+
}, Xt = (t, e, o) => {
|
|
68
68
|
const i = document.createRange(), s = o ? t.startContainer.parentElement.closest(o) : e;
|
|
69
69
|
i.setStart(s, 0), i.setEnd(t.startContainer, t.startOffset);
|
|
70
70
|
const n = st(i).textContent, r = t.toString(), a = n.length || 0, c = a + r.length;
|
|
71
71
|
return o ? { quote: r, start: a, end: c, range: t, offsetReference: s } : { quote: r, start: a, end: c, range: t };
|
|
72
|
-
},
|
|
72
|
+
}, ht = (t, e) => {
|
|
73
|
+
if (I(t)) return t;
|
|
73
74
|
const { start: o, end: i } = t, s = t.offsetReference || e, n = document.createTreeWalker(
|
|
74
75
|
e,
|
|
75
76
|
NodeFilter.SHOW_TEXT,
|
|
@@ -103,19 +104,22 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
103
104
|
...t,
|
|
104
105
|
range: a
|
|
105
106
|
};
|
|
106
|
-
}, J = (t, e, o = (i, s) =>
|
|
107
|
+
}, J = (t, e, o = (i, s) => ht(i, s)) => ({
|
|
108
|
+
...t,
|
|
109
|
+
selector: t.selector.map((i) => o(i, e))
|
|
110
|
+
}), tt = (t, e, o) => ({
|
|
107
111
|
...t,
|
|
108
|
-
|
|
109
|
-
}
|
|
112
|
+
target: J(t.target, e, o)
|
|
113
|
+
}), yt = (t) => {
|
|
110
114
|
if (!t)
|
|
111
115
|
return document.scrollingElement;
|
|
112
116
|
const { overflowY: e } = window.getComputedStyle(t);
|
|
113
|
-
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t :
|
|
117
|
+
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : yt(t.parentElement);
|
|
114
118
|
}, at = (t, e, o) => {
|
|
115
119
|
const i = o.getBoundingClientRect(), s = o.clientHeight, n = o.clientWidth, r = e.selector[0].range.getBoundingClientRect(), { width: a, height: c } = t.getAnnotationBounds(e.annotation), m = r.top - i.top, f = r.left - i.left, y = o.parentElement ? o.scrollTop : 0, g = o.parentElement ? o.scrollLeft : 0, R = m + y - (s - c) / 2, l = f + g - (n - a) / 2;
|
|
116
120
|
o.scroll({ top: R, left: l, behavior: "smooth" });
|
|
117
|
-
},
|
|
118
|
-
const s = typeof o == "string" ? o : o.id, n = i ? typeof i == "string" ? document.getElementById(i) : i :
|
|
121
|
+
}, Vt = (t, e) => (o, i) => {
|
|
122
|
+
const s = typeof o == "string" ? o : o.id, n = i ? typeof i == "string" ? document.getElementById(i) : i : yt(t);
|
|
119
123
|
if (!n)
|
|
120
124
|
return console.warn(`The scroll parent is missing for the annotation: ${s}`, { container: t }), !1;
|
|
121
125
|
const r = e.getAnnotation(s);
|
|
@@ -127,9 +131,9 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
127
131
|
const c = J(r.target, t), { range: m } = c.selector[0];
|
|
128
132
|
return m && !m.collapsed ? (at(e, c, n), !0) : !1;
|
|
129
133
|
}, Oe = (t, e) => ({
|
|
130
|
-
parse: (o) =>
|
|
131
|
-
serialize: (o) =>
|
|
132
|
-
}),
|
|
134
|
+
parse: (o) => jt(o),
|
|
135
|
+
serialize: (o) => Gt(o, t, e)
|
|
136
|
+
}), zt = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, qt = (t) => {
|
|
133
137
|
const {
|
|
134
138
|
id: e,
|
|
135
139
|
creator: o,
|
|
@@ -140,7 +144,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
140
144
|
if (r.length === 0)
|
|
141
145
|
return { error: Error(`No targets found for annotation: ${t.id}`) };
|
|
142
146
|
const a = {
|
|
143
|
-
creator:
|
|
147
|
+
creator: vt(o),
|
|
144
148
|
created: i ? new Date(i) : void 0,
|
|
145
149
|
updated: s ? new Date(s) : void 0,
|
|
146
150
|
annotation: e,
|
|
@@ -160,7 +164,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
160
164
|
}
|
|
161
165
|
return y;
|
|
162
166
|
}, {});
|
|
163
|
-
if (
|
|
167
|
+
if (zt(f))
|
|
164
168
|
a.selector.push(
|
|
165
169
|
{
|
|
166
170
|
...f,
|
|
@@ -178,14 +182,14 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
178
182
|
}
|
|
179
183
|
}
|
|
180
184
|
return { parsed: a };
|
|
181
|
-
},
|
|
185
|
+
}, jt = (t) => {
|
|
182
186
|
const e = t.id || dt(), {
|
|
183
187
|
creator: o,
|
|
184
188
|
created: i,
|
|
185
189
|
modified: s,
|
|
186
190
|
body: n,
|
|
187
191
|
...r
|
|
188
|
-
} = t, a =
|
|
192
|
+
} = t, a = Tt(n, e), c = qt(t);
|
|
189
193
|
return "error" in c ? { error: c.error } : {
|
|
190
194
|
parsed: {
|
|
191
195
|
...r,
|
|
@@ -194,7 +198,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
194
198
|
target: c.parsed
|
|
195
199
|
}
|
|
196
200
|
};
|
|
197
|
-
},
|
|
201
|
+
}, Gt = (t, e, o) => {
|
|
198
202
|
const { bodies: i, target: s, ...n } = t, {
|
|
199
203
|
selector: r,
|
|
200
204
|
creator: a,
|
|
@@ -207,7 +211,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
207
211
|
exact: l
|
|
208
212
|
};
|
|
209
213
|
if (o && "range" in g) {
|
|
210
|
-
const { prefix: S, suffix: x } =
|
|
214
|
+
const { prefix: S, suffix: x } = Yt(g.range, o);
|
|
211
215
|
L.prefix = S, L.suffix = x;
|
|
212
216
|
}
|
|
213
217
|
if (!("start" in g))
|
|
@@ -231,13 +235,13 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
231
235
|
"@context": "http://www.w3.org/ns/anno.jsonld",
|
|
232
236
|
id: t.id,
|
|
233
237
|
type: "Annotation",
|
|
234
|
-
body:
|
|
238
|
+
body: At(t.bodies),
|
|
235
239
|
creator: a,
|
|
236
240
|
created: c?.toISOString(),
|
|
237
241
|
modified: m?.toISOString(),
|
|
238
242
|
target: y
|
|
239
243
|
};
|
|
240
|
-
},
|
|
244
|
+
}, Qt = (t) => t.addEventListener("click", (e) => {
|
|
241
245
|
// Allow clicks within not-annotatable elements
|
|
242
246
|
!e.target.closest(W) && !e.target.closest("a") && e.preventDefault();
|
|
243
247
|
}), et = (t) => ({
|
|
@@ -287,18 +291,18 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
287
291
|
return ((...i) => {
|
|
288
292
|
clearTimeout(o), o = setTimeout(() => t.apply(void 0, i), e);
|
|
289
293
|
});
|
|
290
|
-
},
|
|
294
|
+
}, St = (t, e, o, i) => {
|
|
291
295
|
const { store: s, selection: n, hover: r } = o, a = ut();
|
|
292
296
|
let c;
|
|
293
297
|
const m = /* @__PURE__ */ new Map();
|
|
294
298
|
let f;
|
|
295
|
-
const y =
|
|
299
|
+
const y = ce(i), g = (T) => {
|
|
296
300
|
const { x: b, y: v } = e.getBoundingClientRect(), k = s.getAt(T.clientX - b, T.clientY - v, !1, f);
|
|
297
|
-
k && o.selection.evalSelectAction(k) !==
|
|
301
|
+
k && o.selection.evalSelectAction(k) !== Rt.NONE ? r.current !== k.id && (e.classList.add("hovered"), r.set(k.id)) : r.current && (e.classList.remove("hovered"), r.set(null));
|
|
298
302
|
};
|
|
299
303
|
e.addEventListener("pointermove", g);
|
|
300
304
|
const R = nt((T = !1) => requestAnimationFrame(() => {
|
|
301
|
-
const b =
|
|
305
|
+
const b = ae(e), { minX: v, minY: k, maxX: F, maxY: z } = b, q = f ? s.getIntersecting(v, k, F, z).filter(({ annotation: u }) => f?.(u)) : s.getIntersecting(v, k, F, z), $ = n.selected.map(({ id: u }) => u), Y = q.map(({ annotation: u, rects: C }) => {
|
|
302
306
|
const M = $.includes(u.id), D = u.id === r.current;
|
|
303
307
|
return {
|
|
304
308
|
annotation: u,
|
|
@@ -350,10 +354,10 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
350
354
|
}, rt = {
|
|
351
355
|
fill: "rgb(0, 128, 255)",
|
|
352
356
|
fillOpacity: 0.45
|
|
353
|
-
},
|
|
357
|
+
}, Zt = (t) => t?.fillOpacity !== void 0 ? ot(t?.fill || U.fill).alpha(t.fillOpacity).toHex() : t?.fill ? t.fill : ot(U.fill).alpha(U.fillOpacity).toHex(), Et = (t, e, o) => e ? typeof e == "function" ? e(t.annotation, t.state, o) || (t.state?.selected ? rt : U) : e : t.state?.selected ? rt : U, Jt = (t, e) => {
|
|
354
358
|
const o = (n, r) => n.x <= r.x + r.width && n.x + n.width >= r.x && n.y <= r.y + r.height && n.y + n.height >= r.y, i = (n) => n.rects.reduce((r, a) => r + a.width, 0), s = e.filter(({ rects: n }) => n.some((r) => o(t, r)));
|
|
355
359
|
return s.sort((n, r) => i(r) - i(n)), s.findIndex((n) => n.rects.includes(t));
|
|
356
|
-
},
|
|
360
|
+
}, te = (t) => {
|
|
357
361
|
const e = [], o = document.createTreeWalker(
|
|
358
362
|
t.commonAncestorContainer,
|
|
359
363
|
NodeFilter.SHOW_TEXT
|
|
@@ -392,7 +396,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
392
396
|
...Array.from(c.getClientRects())
|
|
393
397
|
];
|
|
394
398
|
}
|
|
395
|
-
},
|
|
399
|
+
}, ee = (t, e, o, i) => {
|
|
396
400
|
const s = (a) => Math.round(a * 10) / 10, n = {
|
|
397
401
|
top: s(t.top),
|
|
398
402
|
bottom: s(t.bottom),
|
|
@@ -416,17 +420,17 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
416
420
|
return "block-contains";
|
|
417
421
|
} else if (n.top >= r.top && n.bottom <= r.bottom && n.left >= r.left && n.right <= r.right)
|
|
418
422
|
return "block-is-contained";
|
|
419
|
-
},
|
|
423
|
+
}, ne = (t, e) => {
|
|
420
424
|
const o = Math.min(t.left, e.left), i = Math.max(t.right, e.right), s = Math.min(t.top, e.top), n = Math.max(t.bottom, e.bottom);
|
|
421
425
|
return new DOMRect(o, s, i - o, n - s);
|
|
422
|
-
},
|
|
426
|
+
}, oe = (t, e = 0.5, o = 0.5) => t.reduce((i, s) => {
|
|
423
427
|
if (s.width === 0 || s.height === 0)
|
|
424
428
|
return i;
|
|
425
429
|
let n = [...i], r = !1;
|
|
426
430
|
for (const a of i) {
|
|
427
|
-
const c =
|
|
431
|
+
const c = ee(s, a, e, o);
|
|
428
432
|
if (c === "inline-adjacent") {
|
|
429
|
-
n = n.map((m) => m === a ?
|
|
433
|
+
n = n.map((m) => m === a ? ne(s, a) : m), r = !0;
|
|
430
434
|
break;
|
|
431
435
|
} else if (c === "inline-contains") {
|
|
432
436
|
n = n.map((m) => m === a ? s : m), r = !0;
|
|
@@ -447,13 +451,13 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
447
451
|
for (let e = 0; e < this.length; e++)
|
|
448
452
|
yield this.item(e);
|
|
449
453
|
}
|
|
450
|
-
}),
|
|
454
|
+
}), se = (t, e) => {
|
|
451
455
|
const { left: o, top: i, right: s, bottom: n } = t;
|
|
452
456
|
return new DOMRect(o - e.left, i - e.top, s - o, n - i);
|
|
453
457
|
}, _e = (t, e) => {
|
|
454
458
|
const { left: o, top: i, right: s, bottom: n } = t;
|
|
455
459
|
return new DOMRect(o + e.left, i + e.top, s - o, n - i);
|
|
456
|
-
},
|
|
460
|
+
}, re = (t) => {
|
|
457
461
|
t.classList.add("r6o-annotatable");
|
|
458
462
|
const e = document.createElement("div");
|
|
459
463
|
e.className = "r6o-span-highlight-layer", t.appendChild(e);
|
|
@@ -463,15 +467,15 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
463
467
|
e.remove();
|
|
464
468
|
},
|
|
465
469
|
redraw: (r, a, c, m, f) => {
|
|
466
|
-
if (!(!
|
|
470
|
+
if (!(!Bt(o, r) || f)) return;
|
|
467
471
|
e.innerHTML = "", [...r].sort((l, L) => {
|
|
468
472
|
const { annotation: { target: { created: N } } } = l, { annotation: { target: { created: A } } } = L;
|
|
469
473
|
return N && A ? N.getTime() - A.getTime() : 0;
|
|
470
474
|
}).forEach((l) => {
|
|
471
475
|
const L = m?.get(l.annotation.id) || c;
|
|
472
476
|
l.rects.map((N) => {
|
|
473
|
-
const A =
|
|
474
|
-
S.className = "r6o-annotation", S.dataset.annotation = l.annotation.id, S.style.left = `${N.x}px`, S.style.top = `${N.y}px`, S.style.width = `${N.width}px`, S.style.height = `${N.height}px`, S.style.backgroundColor =
|
|
477
|
+
const A = Jt(N, r), h = Et(l, L, A), S = document.createElement("span");
|
|
478
|
+
S.className = "r6o-annotation", S.dataset.annotation = l.annotation.id, S.style.left = `${N.x}px`, S.style.top = `${N.y}px`, S.style.width = `${N.width}px`, S.style.height = `${N.height}px`, S.style.backgroundColor = Zt(h), h.underlineStyle && (S.style.borderStyle = h.underlineStyle), h.underlineColor && (S.style.borderColor = h.underlineColor), h.underlineThickness && (S.style.borderBottomWidth = `${h.underlineThickness}px`), h.underlineOffset && (S.style.paddingBottom = `${h.underlineOffset}px`), e.appendChild(S);
|
|
475
479
|
});
|
|
476
480
|
}), o = r;
|
|
477
481
|
},
|
|
@@ -479,28 +483,28 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
479
483
|
r ? e.classList.remove("hidden") : e.classList.add("hidden");
|
|
480
484
|
}
|
|
481
485
|
};
|
|
482
|
-
},
|
|
486
|
+
}, ie = (t, e, o) => St(re(t), t, e, o), ae = (t) => {
|
|
483
487
|
const { top: e, left: o } = t.getBoundingClientRect(), { innerWidth: i, innerHeight: s } = window, n = -o, r = -e, a = i - o, c = s - e;
|
|
484
488
|
return { top: e, left: o, minX: n, minY: r, maxX: a, maxY: c };
|
|
485
|
-
},
|
|
489
|
+
}, ce = (t) => {
|
|
486
490
|
let e = /* @__PURE__ */ new Set();
|
|
487
491
|
return (i) => {
|
|
488
492
|
const s = i.map((n) => n.id);
|
|
489
493
|
(e.size !== s.length || s.some((n) => !e.has(n))) && t.set(s), e = new Set(s);
|
|
490
494
|
};
|
|
491
|
-
},
|
|
492
|
-
const n = new
|
|
495
|
+
}, le = (t, e, o, i, s) => {
|
|
496
|
+
const n = new It(), r = /* @__PURE__ */ new Map(), a = ut(), c = (d, p) => {
|
|
493
497
|
const w = d.selector.flatMap((T) => {
|
|
494
|
-
const b = (s ? s(T, e) :
|
|
495
|
-
return
|
|
496
|
-
}), O =
|
|
498
|
+
const b = (s ? s(T, e) : ht(T, e))?.range;
|
|
499
|
+
return te(b);
|
|
500
|
+
}), O = oe(w, o, i).map((T) => se(T, p));
|
|
497
501
|
return O.map((T) => {
|
|
498
|
-
const { x: b, y: v, width: k, height:
|
|
502
|
+
const { x: b, y: v, width: k, height: F } = T;
|
|
499
503
|
return {
|
|
500
504
|
minX: b,
|
|
501
505
|
minY: v,
|
|
502
506
|
maxX: b + k,
|
|
503
|
-
maxY: v +
|
|
507
|
+
maxY: v + F,
|
|
504
508
|
annotation: {
|
|
505
509
|
id: d.annotation,
|
|
506
510
|
rects: O
|
|
@@ -570,28 +574,28 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
570
574
|
update: R,
|
|
571
575
|
on: (d, p) => a.on(d, p)
|
|
572
576
|
};
|
|
573
|
-
},
|
|
574
|
-
const o =
|
|
577
|
+
}, de = (t, e) => {
|
|
578
|
+
const o = wt(), i = le(
|
|
575
579
|
o,
|
|
576
580
|
t,
|
|
577
581
|
e.mergeHighlights?.horizontalTolerance,
|
|
578
582
|
e.mergeHighlights?.verticalTolerance,
|
|
579
583
|
e.selectorReviveFn
|
|
580
|
-
), s =
|
|
584
|
+
), s = xt(o, e.userSelectAction, e.adapter), n = Lt(o), r = Nt(), a = (h, S = K.LOCAL) => {
|
|
581
585
|
const x = tt(h, t, e.selectorReviveFn), E = I(x.target.selector);
|
|
582
586
|
return E && o.addAnnotation(x, S), E;
|
|
583
|
-
}, c = (h, S = !0, x =
|
|
584
|
-
const E = h.map((p) => tt(p, t)), d = E.filter((p) => !I(p.target.selector));
|
|
587
|
+
}, c = (h, S = !0, x = K.LOCAL) => {
|
|
588
|
+
const E = h.map((p) => tt(p, t, e.selectorReviveFn)), d = E.filter((p) => !I(p.target.selector));
|
|
585
589
|
return o.bulkAddAnnotations(E, S, x), d;
|
|
586
|
-
}, m = (h, S =
|
|
587
|
-
const x = h.map((d) => tt(d, t)), E = x.filter((d) => !I(d.target.selector));
|
|
590
|
+
}, m = (h, S = K.LOCAL) => {
|
|
591
|
+
const x = h.map((d) => tt(d, t, e.selectorReviveFn)), E = x.filter((d) => !I(d.target.selector));
|
|
588
592
|
return x.forEach((d) => {
|
|
589
593
|
o.getAnnotation(d.id) ? o.updateAnnotation(d, S) : o.addAnnotation(d, S);
|
|
590
594
|
}), E;
|
|
591
|
-
}, f = (h, S =
|
|
595
|
+
}, f = (h, S = K.LOCAL) => {
|
|
592
596
|
const x = J(h, t);
|
|
593
597
|
o.updateTarget(x, S);
|
|
594
|
-
}, y = (h, S =
|
|
598
|
+
}, y = (h, S = K.LOCAL) => {
|
|
595
599
|
const x = h.map((E) => J(E, t));
|
|
596
600
|
o.bulkUpdateTargets(x, S);
|
|
597
601
|
};
|
|
@@ -623,10 +627,10 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
623
627
|
hover: n,
|
|
624
628
|
viewport: r
|
|
625
629
|
};
|
|
626
|
-
}, ct = 300,
|
|
627
|
-
...
|
|
628
|
-
|
|
629
|
-
],
|
|
630
|
+
}, ct = 300, bt = ["up", "down", "left", "right"], Ct = ft ? "⌘+a" : "ctrl+a", ue = [
|
|
631
|
+
...bt.map((t) => `shift+${t}`),
|
|
632
|
+
Ct
|
|
633
|
+
], fe = (t, e, o, i) => {
|
|
630
634
|
const { store: s, selection: n } = e;
|
|
631
635
|
let r;
|
|
632
636
|
const {
|
|
@@ -643,7 +647,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
643
647
|
return !0;
|
|
644
648
|
if (i.allowModifierSelect) {
|
|
645
649
|
const C = u;
|
|
646
|
-
return
|
|
650
|
+
return ft ? C.metaKey : C.ctrlKey;
|
|
647
651
|
} else
|
|
648
652
|
return !1;
|
|
649
653
|
}, p = () => {
|
|
@@ -669,12 +673,12 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
669
673
|
created: /* @__PURE__ */ new Date(),
|
|
670
674
|
creator: r
|
|
671
675
|
};
|
|
672
|
-
}, w =
|
|
676
|
+
}, w = Dt((u) => {
|
|
673
677
|
if (!g) return;
|
|
674
678
|
const C = document.getSelection();
|
|
675
679
|
if (!C?.anchorNode) return;
|
|
676
|
-
const D = $().map((_) =>
|
|
677
|
-
if (D.every((_) => !
|
|
680
|
+
const D = $().map((_) => $t(_, t));
|
|
681
|
+
if (D.every((_) => !mt(t, _))) {
|
|
678
682
|
l = void 0;
|
|
679
683
|
return;
|
|
680
684
|
}
|
|
@@ -685,18 +689,18 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
685
689
|
s.getAnnotation(l.annotation) && !(d(A) || R === "REPLACE_CURRENT") && (n.clear(), s.deleteAnnotation(l.annotation));
|
|
686
690
|
return;
|
|
687
691
|
}
|
|
688
|
-
if (D.every((_) =>
|
|
689
|
-
const B = D.flatMap((_) =>
|
|
692
|
+
if (D.every((_) => Pt(_))) return;
|
|
693
|
+
const B = D.flatMap((_) => Wt(t, _.cloneRange()));
|
|
690
694
|
if (!(B.length > 0 && !l || B.length !== l.selector.length || B.some((_, X) => _.toString() !== l?.selector[X]?.quote))) return;
|
|
691
|
-
const j = d(A) && L ?
|
|
695
|
+
const j = d(A) && L ? Ut([
|
|
692
696
|
...L.selector.map((_) => _.range),
|
|
693
697
|
...B
|
|
694
698
|
]) : B;
|
|
695
699
|
l = {
|
|
696
700
|
...l,
|
|
697
|
-
selector: j.map((_) =>
|
|
701
|
+
selector: j.map((_) => Xt(_, t, c)),
|
|
698
702
|
updated: /* @__PURE__ */ new Date()
|
|
699
|
-
}, !(d(A) || R === "REPLACE_CURRENT") && (s.getAnnotation(l.annotation) ? s.updateTarget(l,
|
|
703
|
+
}, !(d(A) || R === "REPLACE_CURRENT") && (s.getAnnotation(l.annotation) ? s.updateTarget(l, K.LOCAL) : n.clear());
|
|
700
704
|
}, 10), O = (u) => {
|
|
701
705
|
A = et(u), N = A.button === 0;
|
|
702
706
|
}, T = async (u) => {
|
|
@@ -732,7 +736,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
732
736
|
const u = document.getSelection();
|
|
733
737
|
let C = !1, M = u?.isCollapsed;
|
|
734
738
|
const D = () => M || C, H = 1;
|
|
735
|
-
return setTimeout(() => C = !0, 50),
|
|
739
|
+
return setTimeout(() => C = !0, 50), Ht(() => M = u?.isCollapsed, H, D);
|
|
736
740
|
}, v = (u) => {
|
|
737
741
|
document.getSelection()?.isCollapsed || ((!l || l.selector.length === 0) && w(u), l && (Y(), n.userSelect(l.annotation, et(u))));
|
|
738
742
|
}, k = (u) => {
|
|
@@ -740,7 +744,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
740
744
|
const C = document.getSelection();
|
|
741
745
|
C && !C.isCollapsed && (Y(), n.userSelect(l.annotation, Q(u)));
|
|
742
746
|
}
|
|
743
|
-
},
|
|
747
|
+
}, F = (u) => {
|
|
744
748
|
const C = () => setTimeout(() => {
|
|
745
749
|
l && (l.selector.length > 0 && (n.clear(), s.addAnnotation({
|
|
746
750
|
id: l.annotation,
|
|
@@ -750,15 +754,15 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
750
754
|
}, 100);
|
|
751
755
|
document.addEventListener("selectionchange", C), p();
|
|
752
756
|
};
|
|
753
|
-
G(
|
|
757
|
+
G(ue.join(","), { element: t, keydown: !0, keyup: !1 }, (u) => {
|
|
754
758
|
u.repeat || (A = Q(u));
|
|
755
|
-
}), G(
|
|
756
|
-
A = Q(u),
|
|
759
|
+
}), G(Ct, { keydown: !0, keyup: !1 }, (u) => {
|
|
760
|
+
A = Q(u), F(u);
|
|
757
761
|
});
|
|
758
762
|
const z = (u) => {
|
|
759
763
|
u.repeat || $().length !== 0 && (l = void 0, n.clear());
|
|
760
764
|
};
|
|
761
|
-
G(
|
|
765
|
+
G(bt.join(","), { keydown: !0, keyup: !1 }, z), document.addEventListener("pointerdown", O), document.addEventListener("pointerup", T), document.addEventListener("contextmenu", v), document.addEventListener("keyup", k), t.addEventListener("selectstart", p), document.addEventListener("selectionchange", w);
|
|
762
766
|
const q = () => {
|
|
763
767
|
l = void 0, L = void 0, N = void 0, A = void 0, w.clear(), document.removeEventListener("pointerdown", O), document.removeEventListener("pointerup", T), document.removeEventListener("contextmenu", v), document.removeEventListener("keyup", k), t.removeEventListener("selectstart", p), document.removeEventListener("selectionchange", w), G.unbind();
|
|
764
768
|
}, $ = () => {
|
|
@@ -785,13 +789,13 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
785
789
|
setAnnotatingEnabled: h,
|
|
786
790
|
setAnnotatingMode: S
|
|
787
791
|
};
|
|
788
|
-
},
|
|
792
|
+
}, ge = (t) => [
|
|
789
793
|
`background-color:${ot(t?.fill || U.fill).alpha(t?.fillOpacity === void 0 ? U.fillOpacity : t.fillOpacity).toHex()}`,
|
|
790
794
|
t?.underlineThickness ? "text-decoration:underline" : void 0,
|
|
791
795
|
t?.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
792
796
|
t?.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
793
797
|
t?.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
|
|
794
|
-
].filter(Boolean).join(";"),
|
|
798
|
+
].filter(Boolean).join(";"), me = () => {
|
|
795
799
|
const t = document.createElement("style");
|
|
796
800
|
document.getElementsByTagName("head")[0].appendChild(t);
|
|
797
801
|
let e = /* @__PURE__ */ new Set();
|
|
@@ -807,8 +811,8 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
807
811
|
Array.from(e).filter((g) => !f.has(g));
|
|
808
812
|
const y = n.map((g) => {
|
|
809
813
|
a ? typeof a == "function" && a(g.annotation, g.state) : g.state?.selected;
|
|
810
|
-
const R =
|
|
811
|
-
return `::highlight(_${g.annotation.id}) { ${
|
|
814
|
+
const R = Et(g, a);
|
|
815
|
+
return `::highlight(_${g.annotation.id}) { ${ge(R)} }`;
|
|
812
816
|
});
|
|
813
817
|
t.innerHTML = y.join(`
|
|
814
818
|
`), CSS.highlights.clear(), n.forEach(({ annotation: g }) => {
|
|
@@ -817,26 +821,26 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
817
821
|
}), e = f;
|
|
818
822
|
}
|
|
819
823
|
};
|
|
820
|
-
},
|
|
824
|
+
}, pe = (t, e, o) => St(me(), t, e, o), he = (t, e) => ({
|
|
821
825
|
...t,
|
|
822
826
|
annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
|
|
823
827
|
user: t.user || e.user
|
|
824
828
|
}), lt = "SPANS", Me = (t, e = {}) => {
|
|
825
|
-
|
|
826
|
-
const o =
|
|
829
|
+
Qt(t), Ft(t);
|
|
830
|
+
const o = he(e, {
|
|
827
831
|
annotatingEnabled: !0,
|
|
828
|
-
user:
|
|
829
|
-
}), i =
|
|
832
|
+
user: Ot()
|
|
833
|
+
}), i = de(t, o), { selection: s, viewport: n } = i, r = i.store, a = kt(r), c = _t(i, a, o.adapter);
|
|
830
834
|
let m = o.user;
|
|
831
835
|
const f = typeof o.renderer != "function" ? o.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : lt : o.renderer || lt : null, y = f === null ? o.renderer(
|
|
832
836
|
t,
|
|
833
837
|
i,
|
|
834
838
|
n
|
|
835
|
-
) : f === "SPANS" ?
|
|
839
|
+
) : f === "SPANS" ? ie(
|
|
836
840
|
t,
|
|
837
841
|
i,
|
|
838
842
|
n
|
|
839
|
-
) : f === "CSS_HIGHLIGHTS" ?
|
|
843
|
+
) : f === "CSS_HIGHLIGHTS" ? pe(
|
|
840
844
|
t,
|
|
841
845
|
i,
|
|
842
846
|
n
|
|
@@ -844,14 +848,14 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
844
848
|
if (!y)
|
|
845
849
|
throw `Unknown renderer implementation: ${o.renderer}`;
|
|
846
850
|
console.debug(f ? `Using ${f} renderer` : "Using custom renderer implementation"), o.style && y.setStyle(o.style);
|
|
847
|
-
const g =
|
|
851
|
+
const g = fe(
|
|
848
852
|
t,
|
|
849
853
|
i,
|
|
850
854
|
c,
|
|
851
855
|
o
|
|
852
856
|
);
|
|
853
857
|
g.setUser(m);
|
|
854
|
-
const R =
|
|
858
|
+
const R = Mt(i, a, o.adapter), l = () => m, L = (E) => {
|
|
855
859
|
g.setAnnotatingEnabled(
|
|
856
860
|
E === void 0 ? !0 : E
|
|
857
861
|
);
|
|
@@ -881,60 +885,60 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
|
|
|
881
885
|
setVisible: y.setVisible.bind(y),
|
|
882
886
|
on: c.on,
|
|
883
887
|
off: c.off,
|
|
884
|
-
scrollIntoView:
|
|
888
|
+
scrollIntoView: Vt(t, r),
|
|
885
889
|
state: i
|
|
886
890
|
};
|
|
887
891
|
};
|
|
888
892
|
export {
|
|
889
893
|
rt as DEFAULT_SELECTED_STYLE,
|
|
890
894
|
U as DEFAULT_STYLE,
|
|
891
|
-
|
|
895
|
+
gt as NOT_ANNOTATABLE_CLASS,
|
|
892
896
|
W as NOT_ANNOTATABLE_SELECTOR,
|
|
893
897
|
De as Origin,
|
|
894
898
|
He as UserSelectAction,
|
|
895
899
|
Oe as W3CTextFormat,
|
|
896
|
-
|
|
900
|
+
Qt as cancelSingleClickEvents,
|
|
897
901
|
Q as cloneKeyboardEvent,
|
|
898
902
|
et as clonePointerEvent,
|
|
899
|
-
|
|
900
|
-
|
|
903
|
+
Et as computeStyle,
|
|
904
|
+
Jt as computeZIndex,
|
|
901
905
|
Pe as createBody,
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
906
|
+
St as createRenderer,
|
|
907
|
+
fe as createSelectionHandler,
|
|
908
|
+
ie as createSpansRenderer,
|
|
905
909
|
Me as createTextAnnotator,
|
|
906
|
-
|
|
910
|
+
de as createTextAnnotatorState,
|
|
907
911
|
nt as debounce,
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
+
he as fillDefaults,
|
|
913
|
+
Zt as getBackgroundColor,
|
|
914
|
+
te as getHighlightClientRects,
|
|
915
|
+
Yt as getQuoteContext,
|
|
912
916
|
st as getRangeAnnotatableContents,
|
|
913
|
-
|
|
914
|
-
|
|
917
|
+
ae as getViewportBounds,
|
|
918
|
+
ft as isMac,
|
|
915
919
|
Ne as isNodeWhitespaceOrEmpty,
|
|
916
920
|
Z as isNotAnnotatable,
|
|
917
|
-
|
|
918
|
-
|
|
921
|
+
mt as isRangeAnnotatable,
|
|
922
|
+
Pt as isRangeWhitespaceOrEmpty,
|
|
919
923
|
I as isRevived,
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
924
|
+
xe as isRevivedAnnotation,
|
|
925
|
+
Le as isRevivedTarget,
|
|
926
|
+
oe as mergeClientRects,
|
|
927
|
+
Ut as mergeRanges,
|
|
928
|
+
jt as parseW3CTextAnnotation,
|
|
925
929
|
Ft as programmaticallyFocusable,
|
|
926
|
-
|
|
930
|
+
Xt as rangeToSelector,
|
|
927
931
|
tt as reviveAnnotation,
|
|
928
932
|
J as reviveTarget,
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
+
ht as reviveTextSelector,
|
|
934
|
+
Vt as scrollIntoView,
|
|
935
|
+
Gt as serializeW3CTextAnnotation,
|
|
936
|
+
Wt as splitAnnotatableRanges,
|
|
933
937
|
ke as toDomRectList,
|
|
934
|
-
|
|
938
|
+
se as toParentBounds,
|
|
935
939
|
_e as toViewportBounds,
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
940
|
+
ce as trackViewport,
|
|
941
|
+
$t as trimRangeToContainer,
|
|
942
|
+
pt as whitespaceOrEmptyRegex
|
|
939
943
|
};
|
|
940
944
|
//# sourceMappingURL=text-annotator.es.js.map
|