@recogito/text-annotator 4.0.0-beta → 4.0.2-beta
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/index.d.ts +12 -409
- package/dist/model/core/text-annotation.d.ts +1 -1
- package/dist/model/w3c/w3c-text-annotation.d.ts +1 -1
- package/dist/model/w3c/w3c-text-format-adapter.d.ts +3 -3
- package/dist/rendering/base-renderer.d.ts +8 -8
- package/dist/rendering/highlight-style.d.ts +3 -3
- package/dist/rendering/highlight.d.ts +3 -3
- package/dist/rendering/index.d.ts +1 -0
- package/dist/rendering/renderer-css-highlight/css-highlight-renderer.d.ts +3 -2
- package/dist/rendering/renderer-spans/spans-renderer.d.ts +4 -2
- package/dist/rendering/viewport.d.ts +2 -2
- package/dist/selection-handler.d.ts +7 -7
- package/dist/state/spatial-tree.d.ts +5 -5
- package/dist/state/text-annotation-store.d.ts +5 -5
- package/dist/state/text-annotator-state.d.ts +6 -5
- package/dist/text-annotator-options.d.ts +5 -5
- package/dist/text-annotator.css +1 -1
- package/dist/text-annotator.d.ts +7 -6
- package/dist/text-annotator.es.js +558 -536
- 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/dist/utils/annotation/range-to-selector.d.ts +1 -1
- package/dist/utils/annotation/revive-annotation.d.ts +1 -1
- package/dist/utils/annotation/scroll-into-view.d.ts +2 -2
- package/dist/utils/highlight/compute-z-index.d.ts +2 -2
- package/package.json +10 -11
- package/dist/src/index.d.ts +0 -12
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { createNanoEvents as at } from "nanoevents";
|
|
2
|
-
import { UserSelectAction as Et, serializeW3CBodies as bt, parseW3CBodies as Ct, parseW3CUser as At, createStore as Tt, createSelectionState as Rt, createHoverState as vt, createViewportState as wt, Origin as F, createAnonymousGuest as xt, createUndoStack as Lt, createLifecycleObserver as Nt, createBaseAnnotator as Ot } from "@annotorious/core";
|
|
3
|
-
import { Origin as He, UserSelectAction as Pe, createBody as Ue } from "@annotorious/core";
|
|
4
|
-
import { UAParser as kt } from "ua-parser-js";
|
|
5
|
-
import { OSName as Mt } from "ua-parser-js/enums";
|
|
6
|
-
import { colord as et } from "colord";
|
|
7
1
|
import { v4 as lt } from "uuid";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
2
|
+
import { parseW3CBodies as Ct, serializeW3CBodies as At, parseW3CUser as Tt, UserSelectAction as Rt, createStore as vt, createSelectionState as wt, createHoverState as xt, createViewportState as Lt, Origin as F, createAnonymousGuest as Nt, createUndoStack as Ot, createLifecycleObserver as kt, createBaseAnnotator as Mt } from "@annotorious/core";
|
|
3
|
+
import { Origin as Be, UserSelectAction as Ie, createBody as _e } from "@annotorious/core";
|
|
4
|
+
import { createNanoEvents as dt } from "nanoevents";
|
|
5
|
+
import { colord as et } from "colord";
|
|
6
|
+
import { dequal as Bt } from "dequal/lite";
|
|
7
|
+
import It from "rbush";
|
|
8
|
+
import _t from "debounce";
|
|
10
9
|
import q from "hotkeys-js";
|
|
11
|
-
import { poll as
|
|
12
|
-
|
|
13
|
-
const Ht = kt(), dt = Ht.os.is(Mt.MACOS), ut = "not-annotatable", $ = `.${ut}`, G = (t, e) => t.contains(e) ? !!(e instanceof HTMLElement ? e.closest($) : e.parentElement?.closest($)) : !0, Pt = (t, e) => {
|
|
10
|
+
import { poll as Dt } from "poll";
|
|
11
|
+
const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft = "not-annotatable", Y = `.${ft}`, $ = (t, e) => t.contains(e) ? !!(e instanceof HTMLElement ? e.closest(Y) : e.parentElement?.closest(Y)) : !0, gt = (t, e) => {
|
|
14
12
|
const o = e.commonAncestorContainer;
|
|
15
|
-
return
|
|
16
|
-
},
|
|
13
|
+
return !$(t, o);
|
|
14
|
+
}, mt = /^\s*$/, Ht = (t) => mt.test(t.toString()), we = (t) => mt.test(t.textContent || ""), Pt = (t) => {
|
|
17
15
|
if (t.length === 0) return [];
|
|
18
16
|
if (t.length === 1) return [t[0]];
|
|
19
17
|
t.sort((s, n) => {
|
|
@@ -22,22 +20,22 @@ const Ht = kt(), dt = Ht.os.is(Mt.MACOS), ut = "not-annotatable", $ = `.${ut}`,
|
|
|
22
20
|
});
|
|
23
21
|
const [e, ...o] = t, i = o.reduce((s, n) => s.current.compareBoundaryPoints(Range.START_TO_END, n) >= 0 ? (s.current.compareBoundaryPoints(Range.END_TO_END, n) < 0 && s.current.setEnd(n.endContainer, n.endOffset), s) : (s.merged.push(s.current), s.current = n.cloneRange(), s), { merged: [], current: e.cloneRange() });
|
|
24
22
|
return [...i.merged, i.current];
|
|
25
|
-
},
|
|
26
|
-
!t.hasAttribute("tabindex")
|
|
27
|
-
},
|
|
23
|
+
}, Ut = (t) => {
|
|
24
|
+
(!t.hasAttribute("tabindex") || t.tabIndex < -1) && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
|
|
25
|
+
}, Kt = function* (t) {
|
|
28
26
|
const e = document.createNodeIterator(
|
|
29
27
|
t.commonAncestorContainer,
|
|
30
28
|
NodeFilter.SHOW_ELEMENT,
|
|
31
|
-
(i) => i instanceof HTMLElement && i.classList.contains(
|
|
29
|
+
(i) => i instanceof HTMLElement && i.classList.contains(ft) && !i.parentElement?.closest(Y) && t.intersectsNode(i) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
|
32
30
|
);
|
|
33
31
|
let o;
|
|
34
32
|
for (; o = e.nextNode(); )
|
|
35
33
|
o instanceof HTMLElement && (yield o);
|
|
36
|
-
},
|
|
37
|
-
if (!
|
|
34
|
+
}, Ft = (t, e) => {
|
|
35
|
+
if (!gt(t, e)) return [];
|
|
38
36
|
const o = [];
|
|
39
37
|
let i = null;
|
|
40
|
-
for (const s of
|
|
38
|
+
for (const s of Kt(e)) {
|
|
41
39
|
let n;
|
|
42
40
|
i ? (n = document.createRange(), n.setStartAfter(i), n.setEndBefore(s)) : (n = e.cloneRange(), n.setEndBefore(s)), n.collapsed || o.push(n), i = s;
|
|
43
41
|
}
|
|
@@ -48,208 +46,86 @@ const Ht = kt(), dt = Ht.os.is(Mt.MACOS), ut = "not-annotatable", $ = `.${ut}`,
|
|
|
48
46
|
return o.length > 0 ? o : [e];
|
|
49
47
|
}, nt = (t) => {
|
|
50
48
|
const e = t.cloneContents();
|
|
51
|
-
return e.querySelectorAll(
|
|
52
|
-
},
|
|
49
|
+
return e.querySelectorAll(Y).forEach((o) => o.remove()), e;
|
|
50
|
+
}, $t = (t, e) => {
|
|
53
51
|
const o = t.cloneRange();
|
|
54
52
|
return e.contains(o.startContainer) || o.setStart(e, 0), e.contains(o.endContainer) || o.setEnd(e, e.childNodes.length), o;
|
|
55
|
-
},
|
|
56
|
-
// Allow clicks within not-annotatable elements
|
|
57
|
-
!e.target.closest($) && !e.target.closest("a") && e.preventDefault();
|
|
58
|
-
}), Z = (t) => ({
|
|
59
|
-
...t,
|
|
60
|
-
type: t.type,
|
|
61
|
-
x: t.x,
|
|
62
|
-
y: t.y,
|
|
63
|
-
clientX: t.clientX,
|
|
64
|
-
clientY: t.clientY,
|
|
65
|
-
offsetX: t.offsetX,
|
|
66
|
-
offsetY: t.offsetY,
|
|
67
|
-
screenX: t.screenX,
|
|
68
|
-
screenY: t.screenY,
|
|
69
|
-
isPrimary: t.isPrimary,
|
|
70
|
-
altKey: t.altKey,
|
|
71
|
-
ctrlKey: t.ctrlKey,
|
|
72
|
-
metaKey: t.metaKey,
|
|
73
|
-
shiftKey: t.shiftKey,
|
|
74
|
-
button: t.button,
|
|
75
|
-
buttons: t.buttons,
|
|
76
|
-
currentTarget: t.currentTarget,
|
|
77
|
-
target: t.target,
|
|
78
|
-
defaultPrevented: t.defaultPrevented,
|
|
79
|
-
detail: t.detail,
|
|
80
|
-
eventPhase: t.eventPhase,
|
|
81
|
-
pointerId: t.pointerId,
|
|
82
|
-
pointerType: t.pointerType,
|
|
83
|
-
timeStamp: t.timeStamp
|
|
84
|
-
}), j = (t) => ({
|
|
85
|
-
...t,
|
|
86
|
-
type: t.type,
|
|
87
|
-
key: t.key,
|
|
88
|
-
code: t.code,
|
|
89
|
-
location: t.location,
|
|
90
|
-
repeat: t.repeat,
|
|
91
|
-
altKey: t.altKey,
|
|
92
|
-
ctrlKey: t.ctrlKey,
|
|
93
|
-
metaKey: t.metaKey,
|
|
94
|
-
shiftKey: t.shiftKey,
|
|
95
|
-
currentTarget: t.currentTarget,
|
|
96
|
-
target: t.target,
|
|
97
|
-
defaultPrevented: t.defaultPrevented,
|
|
98
|
-
detail: t.detail,
|
|
99
|
-
timeStamp: t.timeStamp
|
|
100
|
-
}), J = (t, e = 10) => {
|
|
101
|
-
let o;
|
|
102
|
-
return ((...i) => {
|
|
103
|
-
clearTimeout(o), o = setTimeout(() => t.apply(void 0, i), e);
|
|
104
|
-
});
|
|
105
|
-
}, gt = (t, e, o, i) => {
|
|
106
|
-
const { store: s, selection: n, hover: r } = o, c = at();
|
|
107
|
-
let d;
|
|
108
|
-
const f = /* @__PURE__ */ new Map();
|
|
109
|
-
let p;
|
|
110
|
-
const C = qt(i), h = (y) => {
|
|
111
|
-
const { x: b, y: O } = e.getBoundingClientRect(), B = s.getAt(y.clientX - b, y.clientY - O, !1, p);
|
|
112
|
-
B && o.selection.evalSelectAction(B) !== Et.NONE ? r.current !== B.id && (e.classList.add("hovered"), r.set(B.id)) : r.current && (e.classList.remove("hovered"), r.set(null));
|
|
113
|
-
};
|
|
114
|
-
e.addEventListener("pointermove", h);
|
|
115
|
-
const T = J((y = !1) => requestAnimationFrame(() => {
|
|
116
|
-
const b = zt(e), { minX: O, minY: B, maxX: X, maxY: V } = b, K = p ? s.getIntersecting(O, B, X, V).filter(({ annotation: S }) => p(S)) : s.getIntersecting(O, B, X, V), st = n.selected.map(({ id: S }) => S), g = K.map(({ annotation: S, rects: M }) => {
|
|
117
|
-
const U = st.includes(S.id), I = S.id === r.current;
|
|
118
|
-
return {
|
|
119
|
-
annotation: S,
|
|
120
|
-
rects: M,
|
|
121
|
-
state: { selected: U, hovered: I }
|
|
122
|
-
};
|
|
123
|
-
});
|
|
124
|
-
t.redraw(g, b, d, f, y), setTimeout(() => {
|
|
125
|
-
C(K.map(({ annotation: S }) => S)), c.emit("onRedraw");
|
|
126
|
-
}, 1);
|
|
127
|
-
}), 10), u = (y, b) => {
|
|
128
|
-
b ? y ? f.set(b, y) : f.delete(b) : d = y, T(!0);
|
|
129
|
-
}, L = (y) => {
|
|
130
|
-
p = y, T(!1);
|
|
131
|
-
}, x = (y, b) => c.on(y, b), v = () => {
|
|
132
|
-
T();
|
|
133
|
-
};
|
|
134
|
-
s.observe(v);
|
|
135
|
-
const m = n.subscribe(() => {
|
|
136
|
-
T();
|
|
137
|
-
}), E = r.subscribe(() => {
|
|
138
|
-
T();
|
|
139
|
-
}), w = () => {
|
|
140
|
-
T(!0);
|
|
141
|
-
};
|
|
142
|
-
document.addEventListener("scroll", w, { capture: !0, passive: !0 });
|
|
143
|
-
const a = J(() => {
|
|
144
|
-
s.recalculatePositions(), T();
|
|
145
|
-
}, 10);
|
|
146
|
-
window.addEventListener("resize", a);
|
|
147
|
-
const l = new ResizeObserver(a);
|
|
148
|
-
l.observe(e);
|
|
149
|
-
const A = { attributes: !0, childList: !0, subtree: !0 }, R = new MutationObserver(J((y) => {
|
|
150
|
-
y.every((O) => O.target === e || e.contains(O.target)) || T(!0);
|
|
151
|
-
}, 150));
|
|
152
|
-
return R.observe(document.body, A), {
|
|
153
|
-
destroy: () => {
|
|
154
|
-
e.removeEventListener("pointermove", h), t.destroy(), s.unobserve(v), m(), E(), document.removeEventListener("scroll", w), window.removeEventListener("resize", a), l.disconnect(), R.disconnect();
|
|
155
|
-
},
|
|
156
|
-
on: x,
|
|
157
|
-
redraw: T,
|
|
158
|
-
setStyle: u,
|
|
159
|
-
setFilter: L,
|
|
160
|
-
setVisible: t.setVisible.bind(t)
|
|
161
|
-
};
|
|
162
|
-
}, P = {
|
|
163
|
-
fill: "rgb(0, 128, 255)",
|
|
164
|
-
fillOpacity: 0.18
|
|
165
|
-
}, ot = {
|
|
166
|
-
fill: "rgb(0, 128, 255)",
|
|
167
|
-
fillOpacity: 0.45
|
|
168
|
-
}, Vt = (t) => t?.fillOpacity !== void 0 ? et(t?.fill || P.fill).alpha(t.fillOpacity).toHex() : t?.fill ? t.fill : et(P.fill).alpha(P.fillOpacity).toHex(), mt = (t, e, o) => e ? typeof e == "function" ? e(t.annotation, t.state, o) || (t.state?.selected ? ot : P) : e : t.state?.selected ? ot : P, zt = (t) => {
|
|
169
|
-
const { top: e, left: o } = t.getBoundingClientRect(), { innerWidth: i, innerHeight: s } = window, n = -o, r = -e, c = i - o, d = s - e;
|
|
170
|
-
return { top: e, left: o, minX: n, minY: r, maxX: c, maxY: d };
|
|
171
|
-
}, qt = (t) => {
|
|
172
|
-
let e = /* @__PURE__ */ new Set();
|
|
173
|
-
return (i) => {
|
|
174
|
-
const s = i.map((n) => n.id);
|
|
175
|
-
(e.size !== s.length || s.some((n) => !e.has(n))) && t.set(s), e = new Set(s);
|
|
176
|
-
};
|
|
177
|
-
}, jt = (t, e, o = 10, i) => {
|
|
53
|
+
}, rt = new Intl.Segmenter(void 0, { granularity: "grapheme" }), Yt = (t, e, o = 10, i) => {
|
|
178
54
|
const s = i ? t.startContainer.parentElement.closest(i) : e, n = document.createRange();
|
|
179
55
|
n.setStart(s, 0), n.setEnd(t.startContainer, t.startOffset);
|
|
180
|
-
const r = nt(n).textContent,
|
|
181
|
-
|
|
182
|
-
const
|
|
56
|
+
const r = nt(n).textContent, a = document.createRange();
|
|
57
|
+
a.setStart(t.endContainer, t.endOffset), s === document.body ? a.setEnd(s, s.childNodes.length) : a.setEndAfter(s);
|
|
58
|
+
const u = nt(a).textContent, g = [...rt.segment(r)], m = [...rt.segment(u)];
|
|
183
59
|
return {
|
|
184
|
-
prefix:
|
|
185
|
-
suffix:
|
|
60
|
+
prefix: g.slice(-o).map((b) => b.segment).join(""),
|
|
61
|
+
suffix: m.slice(0, o).map((b) => b.segment).join("")
|
|
186
62
|
};
|
|
187
|
-
},
|
|
63
|
+
}, Wt = (t, e, o) => {
|
|
188
64
|
const i = document.createRange(), s = o ? t.startContainer.parentElement.closest(o) : e;
|
|
189
65
|
i.setStart(s, 0), i.setEnd(t.startContainer, t.startOffset);
|
|
190
|
-
const n = nt(i).textContent, r = t.toString(),
|
|
191
|
-
return o ? { quote: r, start:
|
|
66
|
+
const n = nt(i).textContent, r = t.toString(), a = n.length || 0, u = a + r.length;
|
|
67
|
+
return o ? { quote: r, start: a, end: u, range: t, offsetReference: s } : { quote: r, start: a, end: u, range: t };
|
|
192
68
|
}, D = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), pt = (t, e) => {
|
|
193
69
|
const { start: o, end: i } = t, s = t.offsetReference || e, n = document.createNodeIterator(
|
|
194
70
|
e,
|
|
195
71
|
NodeFilter.SHOW_TEXT,
|
|
196
|
-
(
|
|
72
|
+
(m) => m.parentElement?.closest(Y) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT
|
|
197
73
|
);
|
|
198
74
|
let r = 0;
|
|
199
|
-
const
|
|
200
|
-
let
|
|
201
|
-
|
|
202
|
-
let
|
|
203
|
-
for (;
|
|
204
|
-
if (
|
|
205
|
-
const
|
|
206
|
-
if (r +
|
|
207
|
-
|
|
75
|
+
const a = document.createRange();
|
|
76
|
+
let u = n.nextNode();
|
|
77
|
+
u === null && console.error("Could not revive annotation target. Content missing.");
|
|
78
|
+
let g = !s;
|
|
79
|
+
for (; u !== null; ) {
|
|
80
|
+
if (g ||= typeof s?.contains == "function" ? s.contains(u) : !1, g) {
|
|
81
|
+
const m = u.textContent?.length || 0;
|
|
82
|
+
if (r + m > o) {
|
|
83
|
+
a.setStart(u, o - r);
|
|
208
84
|
break;
|
|
209
85
|
}
|
|
210
|
-
r +=
|
|
86
|
+
r += m;
|
|
211
87
|
}
|
|
212
|
-
|
|
88
|
+
u = n.nextNode();
|
|
213
89
|
}
|
|
214
|
-
for (;
|
|
215
|
-
const
|
|
216
|
-
if (r +
|
|
217
|
-
|
|
90
|
+
for (; u !== null; ) {
|
|
91
|
+
const m = u.textContent?.length || 0;
|
|
92
|
+
if (r + m >= i) {
|
|
93
|
+
a.setEnd(u, i - r);
|
|
218
94
|
break;
|
|
219
95
|
}
|
|
220
|
-
r +=
|
|
96
|
+
r += m, u = n.nextNode();
|
|
221
97
|
}
|
|
222
98
|
return {
|
|
223
99
|
...t,
|
|
224
|
-
range:
|
|
100
|
+
range: a
|
|
225
101
|
};
|
|
226
102
|
}, Q = (t, e) => D(t.selector) ? t : {
|
|
227
103
|
...t,
|
|
228
104
|
selector: t.selector.map((o) => o.range instanceof Range && !o.range.collapsed ? o : pt(o, e))
|
|
229
|
-
},
|
|
105
|
+
}, Z = (t, e) => D(t.target.selector) ? t : { ...t, target: Q(t.target, e) }, ht = (t) => {
|
|
230
106
|
if (!t)
|
|
231
107
|
return document.scrollingElement;
|
|
232
108
|
const { overflowY: e } = window.getComputedStyle(t);
|
|
233
109
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ht(t.parentElement);
|
|
234
|
-
},
|
|
235
|
-
const i = o.getBoundingClientRect(), s = o.clientHeight, n = o.clientWidth, r = e.selector[0].range.getBoundingClientRect(), { width:
|
|
236
|
-
o.scroll({ top: T, left:
|
|
237
|
-
},
|
|
110
|
+
}, it = (t, e, o) => {
|
|
111
|
+
const i = o.getBoundingClientRect(), s = o.clientHeight, n = o.clientWidth, r = e.selector[0].range.getBoundingClientRect(), { width: a, height: u } = t.getAnnotationBounds(e.annotation), g = r.top - i.top, m = r.left - i.left, b = o.parentElement ? o.scrollTop : 0, h = o.parentElement ? o.scrollLeft : 0, T = g + b - (s - u) / 2, l = m + h - (n - a) / 2;
|
|
112
|
+
o.scroll({ top: T, left: l, behavior: "smooth" });
|
|
113
|
+
}, Xt = (t, e) => (o, i) => {
|
|
238
114
|
const s = typeof o == "string" ? o : o.id, n = i ? typeof i == "string" ? document.getElementById(i) : i : ht(t);
|
|
239
115
|
if (!n)
|
|
240
116
|
return console.warn(`The scroll parent is missing for the annotation: ${s}`, { container: t }), !1;
|
|
241
117
|
const r = e.getAnnotation(s);
|
|
242
118
|
if (!r)
|
|
243
119
|
return console.warn(`The annotation is missing in the store: ${s}`), !1;
|
|
244
|
-
const { range:
|
|
245
|
-
if (
|
|
246
|
-
return
|
|
247
|
-
const
|
|
248
|
-
return
|
|
249
|
-
},
|
|
250
|
-
parse: (o) =>
|
|
251
|
-
serialize: (o) =>
|
|
252
|
-
}),
|
|
120
|
+
const { range: a } = r.target.selector[0];
|
|
121
|
+
if (a && !a.collapsed)
|
|
122
|
+
return it(e, r.target, n), !0;
|
|
123
|
+
const u = Q(r.target, t), { range: g } = u.selector[0];
|
|
124
|
+
return g && !g.collapsed ? (it(e, u, n), !0) : !1;
|
|
125
|
+
}, xe = (t, e) => ({
|
|
126
|
+
parse: (o) => jt(o),
|
|
127
|
+
serialize: (o) => qt(o, t, e)
|
|
128
|
+
}), Vt = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, zt = (t) => {
|
|
253
129
|
const {
|
|
254
130
|
id: e,
|
|
255
131
|
creator: o,
|
|
@@ -259,8 +135,8 @@ const Ht = kt(), dt = Ht.os.is(Mt.MACOS), ut = "not-annotatable", $ = `.${ut}`,
|
|
|
259
135
|
} = t, r = Array.isArray(n) ? n : [n];
|
|
260
136
|
if (r.length === 0)
|
|
261
137
|
return { error: Error(`No targets found for annotation: ${t.id}`) };
|
|
262
|
-
const
|
|
263
|
-
creator:
|
|
138
|
+
const a = {
|
|
139
|
+
creator: Tt(o),
|
|
264
140
|
created: i ? new Date(i) : void 0,
|
|
265
141
|
updated: s ? new Date(s) : void 0,
|
|
266
142
|
annotation: e,
|
|
@@ -268,67 +144,67 @@ const Ht = kt(), dt = Ht.os.is(Mt.MACOS), ut = "not-annotatable", $ = `.${ut}`,
|
|
|
268
144
|
// @ts-expect-error: `styleClass` is not part of the core `TextAnnotationTarget` type
|
|
269
145
|
styleClass: "styleClass" in r[0] ? r[0].styleClass : void 0
|
|
270
146
|
};
|
|
271
|
-
for (const
|
|
272
|
-
const
|
|
147
|
+
for (const u of r) {
|
|
148
|
+
const m = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((b, h) => {
|
|
273
149
|
switch (h.type) {
|
|
274
150
|
case "TextQuoteSelector":
|
|
275
|
-
|
|
151
|
+
b.quote = h.exact;
|
|
276
152
|
break;
|
|
277
153
|
case "TextPositionSelector":
|
|
278
|
-
|
|
154
|
+
b.start = h.start, b.end = h.end;
|
|
279
155
|
break;
|
|
280
156
|
}
|
|
281
|
-
return
|
|
157
|
+
return b;
|
|
282
158
|
}, {});
|
|
283
|
-
if (
|
|
284
|
-
|
|
159
|
+
if (Vt(m))
|
|
160
|
+
a.selector.push(
|
|
285
161
|
{
|
|
286
|
-
...
|
|
287
|
-
id:
|
|
162
|
+
...m,
|
|
163
|
+
id: u.id,
|
|
288
164
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
289
|
-
scope:
|
|
165
|
+
scope: u.scope
|
|
290
166
|
}
|
|
291
167
|
);
|
|
292
168
|
else {
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
169
|
+
const b = [
|
|
170
|
+
m.start ? void 0 : "TextPositionSelector",
|
|
171
|
+
m.quote ? void 0 : "TextQuoteSelector"
|
|
296
172
|
].filter(Boolean);
|
|
297
|
-
return { error: Error(`Missing selector types: ${
|
|
173
|
+
return { error: Error(`Missing selector types: ${b.join(" and ")} for annotation: ${t.id}`) };
|
|
298
174
|
}
|
|
299
175
|
}
|
|
300
|
-
return { parsed:
|
|
301
|
-
},
|
|
176
|
+
return { parsed: a };
|
|
177
|
+
}, jt = (t) => {
|
|
302
178
|
const e = t.id || lt(), {
|
|
303
179
|
creator: o,
|
|
304
180
|
created: i,
|
|
305
181
|
modified: s,
|
|
306
182
|
body: n,
|
|
307
183
|
...r
|
|
308
|
-
} = t,
|
|
309
|
-
return "error" in
|
|
184
|
+
} = t, a = Ct(n, e), u = zt(t);
|
|
185
|
+
return "error" in u ? { error: u.error } : {
|
|
310
186
|
parsed: {
|
|
311
187
|
...r,
|
|
312
188
|
id: e,
|
|
313
|
-
bodies:
|
|
314
|
-
target:
|
|
189
|
+
bodies: a,
|
|
190
|
+
target: u.parsed
|
|
315
191
|
}
|
|
316
192
|
};
|
|
317
|
-
},
|
|
193
|
+
}, qt = (t, e, o) => {
|
|
318
194
|
const { bodies: i, target: s, ...n } = t, {
|
|
319
195
|
selector: r,
|
|
320
|
-
creator:
|
|
321
|
-
created:
|
|
322
|
-
updated:
|
|
323
|
-
...
|
|
324
|
-
} = s,
|
|
325
|
-
const { id: T, quote:
|
|
196
|
+
creator: a,
|
|
197
|
+
created: u,
|
|
198
|
+
updated: g,
|
|
199
|
+
...m
|
|
200
|
+
} = s, b = r.map((h) => {
|
|
201
|
+
const { id: T, quote: l, start: L, end: x, range: v } = h, p = {
|
|
326
202
|
type: "TextQuoteSelector",
|
|
327
|
-
exact:
|
|
203
|
+
exact: l
|
|
328
204
|
};
|
|
329
205
|
if (o) {
|
|
330
|
-
const { prefix: w, suffix:
|
|
331
|
-
|
|
206
|
+
const { prefix: w, suffix: c } = Yt(v, o);
|
|
207
|
+
p.prefix = w, p.suffix = c;
|
|
332
208
|
}
|
|
333
209
|
const E = {
|
|
334
210
|
type: "TextPositionSelector",
|
|
@@ -336,12 +212,12 @@ const Ht = kt(), dt = Ht.os.is(Mt.MACOS), ut = "not-annotatable", $ = `.${ut}`,
|
|
|
336
212
|
end: x
|
|
337
213
|
};
|
|
338
214
|
return {
|
|
339
|
-
...
|
|
215
|
+
...m,
|
|
340
216
|
id: T,
|
|
341
217
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
342
218
|
scope: "scope" in h ? h.scope : void 0,
|
|
343
219
|
source: e,
|
|
344
|
-
selector: [
|
|
220
|
+
selector: [p, E]
|
|
345
221
|
};
|
|
346
222
|
});
|
|
347
223
|
return {
|
|
@@ -349,16 +225,129 @@ const Ht = kt(), dt = Ht.os.is(Mt.MACOS), ut = "not-annotatable", $ = `.${ut}`,
|
|
|
349
225
|
"@context": "http://www.w3.org/ns/anno.jsonld",
|
|
350
226
|
id: t.id,
|
|
351
227
|
type: "Annotation",
|
|
352
|
-
body:
|
|
353
|
-
creator:
|
|
354
|
-
created:
|
|
355
|
-
modified:
|
|
356
|
-
target:
|
|
228
|
+
body: At(t.bodies),
|
|
229
|
+
creator: a,
|
|
230
|
+
created: u?.toISOString(),
|
|
231
|
+
modified: g?.toISOString(),
|
|
232
|
+
target: b
|
|
357
233
|
};
|
|
358
|
-
},
|
|
359
|
-
|
|
234
|
+
}, Gt = (t) => t.addEventListener("click", (e) => {
|
|
235
|
+
// Allow clicks within not-annotatable elements
|
|
236
|
+
!e.target.closest(Y) && !e.target.closest("a") && e.preventDefault();
|
|
237
|
+
}), J = (t) => ({
|
|
238
|
+
...t,
|
|
239
|
+
type: t.type,
|
|
240
|
+
x: t.x,
|
|
241
|
+
y: t.y,
|
|
242
|
+
clientX: t.clientX,
|
|
243
|
+
clientY: t.clientY,
|
|
244
|
+
offsetX: t.offsetX,
|
|
245
|
+
offsetY: t.offsetY,
|
|
246
|
+
screenX: t.screenX,
|
|
247
|
+
screenY: t.screenY,
|
|
248
|
+
isPrimary: t.isPrimary,
|
|
249
|
+
altKey: t.altKey,
|
|
250
|
+
ctrlKey: t.ctrlKey,
|
|
251
|
+
metaKey: t.metaKey,
|
|
252
|
+
shiftKey: t.shiftKey,
|
|
253
|
+
button: t.button,
|
|
254
|
+
buttons: t.buttons,
|
|
255
|
+
currentTarget: t.currentTarget,
|
|
256
|
+
target: t.target,
|
|
257
|
+
defaultPrevented: t.defaultPrevented,
|
|
258
|
+
detail: t.detail,
|
|
259
|
+
eventPhase: t.eventPhase,
|
|
260
|
+
pointerId: t.pointerId,
|
|
261
|
+
pointerType: t.pointerType,
|
|
262
|
+
timeStamp: t.timeStamp
|
|
263
|
+
}), G = (t) => ({
|
|
264
|
+
...t,
|
|
265
|
+
type: t.type,
|
|
266
|
+
key: t.key,
|
|
267
|
+
code: t.code,
|
|
268
|
+
location: t.location,
|
|
269
|
+
repeat: t.repeat,
|
|
270
|
+
altKey: t.altKey,
|
|
271
|
+
ctrlKey: t.ctrlKey,
|
|
272
|
+
metaKey: t.metaKey,
|
|
273
|
+
shiftKey: t.shiftKey,
|
|
274
|
+
currentTarget: t.currentTarget,
|
|
275
|
+
target: t.target,
|
|
276
|
+
defaultPrevented: t.defaultPrevented,
|
|
277
|
+
detail: t.detail,
|
|
278
|
+
timeStamp: t.timeStamp
|
|
279
|
+
}), tt = (t, e = 10) => {
|
|
280
|
+
let o;
|
|
281
|
+
return ((...i) => {
|
|
282
|
+
clearTimeout(o), o = setTimeout(() => t.apply(void 0, i), e);
|
|
283
|
+
});
|
|
284
|
+
}, yt = (t, e, o, i) => {
|
|
285
|
+
const { store: s, selection: n, hover: r } = o, a = dt();
|
|
286
|
+
let u;
|
|
287
|
+
const g = /* @__PURE__ */ new Map();
|
|
288
|
+
let m;
|
|
289
|
+
const b = ae(i), h = (S) => {
|
|
290
|
+
const { x: C, y: O } = e.getBoundingClientRect(), B = s.getAt(S.clientX - C, S.clientY - O, !1, m);
|
|
291
|
+
B && o.selection.evalSelectAction(B) !== Rt.NONE ? r.current !== B.id && (e.classList.add("hovered"), r.set(B.id)) : r.current && (e.classList.remove("hovered"), r.set(null));
|
|
292
|
+
};
|
|
293
|
+
e.addEventListener("pointermove", h);
|
|
294
|
+
const T = tt((S = !1) => requestAnimationFrame(() => {
|
|
295
|
+
const C = ie(e), { minX: O, minY: B, maxX: V, maxY: z } = C, K = m ? s.getIntersecting(O, B, V, z).filter(({ annotation: y }) => m?.(y)) : s.getIntersecting(O, B, V, z), st = n.selected.map(({ id: y }) => y), f = K.map(({ annotation: y, rects: M }) => {
|
|
296
|
+
const U = st.includes(y.id), I = y.id === r.current;
|
|
297
|
+
return {
|
|
298
|
+
annotation: y,
|
|
299
|
+
rects: M,
|
|
300
|
+
state: { selected: U, hovered: I }
|
|
301
|
+
};
|
|
302
|
+
});
|
|
303
|
+
t.redraw(f, C, u, g, S), setTimeout(() => {
|
|
304
|
+
b(K.map(({ annotation: y }) => y)), a.emit("onRedraw");
|
|
305
|
+
}, 1);
|
|
306
|
+
}), 10), l = (S, C) => {
|
|
307
|
+
C ? S ? g.set(C, S) : g.delete(C) : u = S, T(!0);
|
|
308
|
+
}, L = (S) => {
|
|
309
|
+
m = S, T(!1);
|
|
310
|
+
}, x = (S, C) => a.on(S, C), v = () => {
|
|
311
|
+
T();
|
|
312
|
+
};
|
|
313
|
+
s.observe(v);
|
|
314
|
+
const p = n.subscribe(() => {
|
|
315
|
+
T();
|
|
316
|
+
}), E = r.subscribe(() => {
|
|
317
|
+
T();
|
|
318
|
+
}), w = () => {
|
|
319
|
+
T(!0);
|
|
320
|
+
};
|
|
321
|
+
document.addEventListener("scroll", w, { capture: !0, passive: !0 });
|
|
322
|
+
const c = tt(() => {
|
|
323
|
+
s.recalculatePositions(), T();
|
|
324
|
+
}, 10);
|
|
325
|
+
window.addEventListener("resize", c);
|
|
326
|
+
const d = new ResizeObserver(c);
|
|
327
|
+
d.observe(e);
|
|
328
|
+
const A = { attributes: !0, childList: !0, subtree: !0 }, R = new MutationObserver(tt((S) => {
|
|
329
|
+
S.every((O) => O.target === e || e.contains(O.target)) || T(!0);
|
|
330
|
+
}, 150));
|
|
331
|
+
return R.observe(document.body, A), {
|
|
332
|
+
destroy: () => {
|
|
333
|
+
e.removeEventListener("pointermove", h), t.destroy(), s.unobserve(v), p(), E(), document.removeEventListener("scroll", w), window.removeEventListener("resize", c), d.disconnect(), R.disconnect();
|
|
334
|
+
},
|
|
335
|
+
on: x,
|
|
336
|
+
redraw: T,
|
|
337
|
+
setStyle: l,
|
|
338
|
+
setFilter: L,
|
|
339
|
+
setVisible: t.setVisible.bind(t)
|
|
340
|
+
};
|
|
341
|
+
}, P = {
|
|
342
|
+
fill: "rgb(0, 128, 255)",
|
|
343
|
+
fillOpacity: 0.18
|
|
344
|
+
}, ot = {
|
|
345
|
+
fill: "rgb(0, 128, 255)",
|
|
346
|
+
fillOpacity: 0.45
|
|
347
|
+
}, Qt = (t) => t?.fillOpacity !== void 0 ? et(t?.fill || P.fill).alpha(t.fillOpacity).toHex() : t?.fill ? t.fill : et(P.fill).alpha(P.fillOpacity).toHex(), St = (t, e, o) => e ? typeof e == "function" ? e(t.annotation, t.state, o) || (t.state?.selected ? ot : P) : e : t.state?.selected ? ot : P, Zt = (t, e) => {
|
|
348
|
+
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)));
|
|
360
349
|
return s.sort((n, r) => i(r) - i(n)), s.findIndex((n) => n.rects.includes(t));
|
|
361
|
-
},
|
|
350
|
+
}, Jt = (t) => {
|
|
362
351
|
const e = [], o = document.createNodeIterator(
|
|
363
352
|
t.commonAncestorContainer,
|
|
364
353
|
NodeFilter.SHOW_TEXT
|
|
@@ -373,28 +362,28 @@ const Ht = kt(), dt = Ht.os.is(Mt.MACOS), ut = "not-annotatable", $ = `.${ut}`,
|
|
|
373
362
|
if (r.selectNode(s), t.startContainer.nodeType === Node.TEXT_NODE)
|
|
374
363
|
r.setStart(s, t.startOffset);
|
|
375
364
|
else {
|
|
376
|
-
const
|
|
377
|
-
|
|
365
|
+
const g = t.startContainer.childNodes[t.startOffset];
|
|
366
|
+
g ? r.setStartBefore(g) : r.setStartAfter(t.startContainer);
|
|
378
367
|
}
|
|
379
|
-
const
|
|
380
|
-
if (
|
|
381
|
-
|
|
368
|
+
const a = document.createRange();
|
|
369
|
+
if (a.selectNode(n), t.endContainer.nodeType === Node.TEXT_NODE)
|
|
370
|
+
a.setEnd(n, t.endOffset);
|
|
382
371
|
else {
|
|
383
|
-
const
|
|
384
|
-
|
|
372
|
+
const g = t.endContainer.childNodes[t.endOffset];
|
|
373
|
+
g ? a.setEndBefore(g) : a.setEndAfter(t.endContainer);
|
|
385
374
|
}
|
|
386
|
-
const
|
|
387
|
-
const
|
|
388
|
-
return
|
|
375
|
+
const u = (g) => {
|
|
376
|
+
const m = document.createRange();
|
|
377
|
+
return m.selectNode(g), Array.from(m.getClientRects());
|
|
389
378
|
};
|
|
390
379
|
return [
|
|
391
380
|
...Array.from(r.getClientRects()),
|
|
392
|
-
...e.slice(1, -1).flatMap(
|
|
393
|
-
...Array.from(
|
|
381
|
+
...e.slice(1, -1).flatMap(u),
|
|
382
|
+
...Array.from(a.getClientRects())
|
|
394
383
|
];
|
|
395
384
|
}
|
|
396
|
-
},
|
|
397
|
-
const s = (
|
|
385
|
+
}, te = (t, e, o, i) => {
|
|
386
|
+
const s = (a) => Math.round(a * 10) / 10, n = {
|
|
398
387
|
top: s(t.top),
|
|
399
388
|
bottom: s(t.bottom),
|
|
400
389
|
left: s(t.left),
|
|
@@ -417,202 +406,237 @@ const Ht = kt(), dt = Ht.os.is(Mt.MACOS), ut = "not-annotatable", $ = `.${ut}`,
|
|
|
417
406
|
return "block-contains";
|
|
418
407
|
} else if (n.top >= r.top && n.bottom <= r.bottom && n.left >= r.left && n.right <= r.right)
|
|
419
408
|
return "block-is-contained";
|
|
420
|
-
},
|
|
409
|
+
}, ee = (t, e) => {
|
|
421
410
|
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);
|
|
422
411
|
return new DOMRect(o, s, i - o, n - s);
|
|
423
|
-
},
|
|
412
|
+
}, ne = (t, e = 0.5, o = 0.5) => t.reduce((i, s) => {
|
|
424
413
|
if (s.width === 0 || s.height === 0)
|
|
425
414
|
return i;
|
|
426
415
|
let n = [...i], r = !1;
|
|
427
|
-
for (const
|
|
428
|
-
const
|
|
429
|
-
if (
|
|
430
|
-
n = n.map((
|
|
416
|
+
for (const a of i) {
|
|
417
|
+
const u = te(s, a, e, o);
|
|
418
|
+
if (u === "inline-adjacent") {
|
|
419
|
+
n = n.map((g) => g === a ? ee(s, a) : g), r = !0;
|
|
431
420
|
break;
|
|
432
|
-
} else if (
|
|
433
|
-
n = n.map((
|
|
421
|
+
} else if (u === "inline-contains") {
|
|
422
|
+
n = n.map((g) => g === a ? s : g), r = !0;
|
|
434
423
|
break;
|
|
435
|
-
} else if (
|
|
424
|
+
} else if (u === "inline-is-contained") {
|
|
436
425
|
r = !0;
|
|
437
426
|
break;
|
|
438
|
-
} else if (
|
|
439
|
-
s.width <
|
|
427
|
+
} else if (u === "block-contains" || u === "block-is-contained") {
|
|
428
|
+
s.width < a.width && (n = n.map((g) => g === a ? s : g)), s.width === a.width && s.height < a.width && (n = n.map((g) => g === a ? s : g)), r = !0;
|
|
440
429
|
break;
|
|
441
430
|
}
|
|
442
431
|
}
|
|
443
432
|
return r ? n : [...n, s];
|
|
444
|
-
}, []),
|
|
433
|
+
}, []), Le = (t) => ({
|
|
445
434
|
length: t.length,
|
|
446
435
|
item: (e) => t[e],
|
|
447
436
|
[Symbol.iterator]: function* () {
|
|
448
437
|
for (let e = 0; e < this.length; e++)
|
|
449
438
|
yield this.item(e);
|
|
450
439
|
}
|
|
451
|
-
}),
|
|
440
|
+
}), oe = (t, e) => {
|
|
452
441
|
const { left: o, top: i, right: s, bottom: n } = t;
|
|
453
442
|
return new DOMRect(o - e.left, i - e.top, s - o, n - i);
|
|
454
|
-
},
|
|
443
|
+
}, Ne = (t, e) => {
|
|
455
444
|
const { left: o, top: i, right: s, bottom: n } = t;
|
|
456
445
|
return new DOMRect(o + e.left, i + e.top, s - o, n - i);
|
|
457
|
-
},
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
446
|
+
}, se = (t) => {
|
|
447
|
+
t.classList.add("r6o-annotatable");
|
|
448
|
+
const e = document.createElement("div");
|
|
449
|
+
e.className = "r6o-span-highlight-layer", t.appendChild(e);
|
|
450
|
+
let o = [];
|
|
451
|
+
return {
|
|
452
|
+
destroy: () => {
|
|
453
|
+
e.remove();
|
|
454
|
+
},
|
|
455
|
+
redraw: (r, a, u, g, m) => {
|
|
456
|
+
if (!(!Bt(o, r) || m)) return;
|
|
457
|
+
e.innerHTML = "", [...r].sort((l, L) => {
|
|
458
|
+
const { annotation: { target: { created: x } } } = l, { annotation: { target: { created: v } } } = L;
|
|
459
|
+
return x && v ? x.getTime() - v.getTime() : 0;
|
|
460
|
+
}).forEach((l) => {
|
|
461
|
+
const L = g?.get(l.annotation.id) || u;
|
|
462
|
+
l.rects.map((x) => {
|
|
463
|
+
const v = Zt(x, r), p = St(l, L, v), E = document.createElement("span");
|
|
464
|
+
E.className = "r6o-annotation", E.dataset.annotation = l.annotation.id, E.style.left = `${x.x}px`, E.style.top = `${x.y}px`, E.style.width = `${x.width}px`, E.style.height = `${x.height}px`, E.style.backgroundColor = Qt(p), p.underlineStyle && (E.style.borderStyle = p.underlineStyle), p.underlineColor && (E.style.borderColor = p.underlineColor), p.underlineThickness && (E.style.borderBottomWidth = `${p.underlineThickness}px`), p.underlineOffset && (E.style.paddingBottom = `${p.underlineOffset}px`), e.appendChild(E);
|
|
465
|
+
});
|
|
466
|
+
}), o = r;
|
|
467
|
+
},
|
|
468
|
+
setVisible: (r) => {
|
|
469
|
+
r ? e.classList.remove("hidden") : e.classList.add("hidden");
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
}, re = (t, e, o) => yt(se(t), t, e, o), ie = (t) => {
|
|
473
|
+
const { top: e, left: o } = t.getBoundingClientRect(), { innerWidth: i, innerHeight: s } = window, n = -o, r = -e, a = i - o, u = s - e;
|
|
474
|
+
return { top: e, left: o, minX: n, minY: r, maxX: a, maxY: u };
|
|
475
|
+
}, ae = (t) => {
|
|
476
|
+
let e = /* @__PURE__ */ new Set();
|
|
477
|
+
return (i) => {
|
|
478
|
+
const s = i.map((n) => n.id);
|
|
479
|
+
(e.size !== s.length || s.some((n) => !e.has(n))) && t.set(s), e = new Set(s);
|
|
480
|
+
};
|
|
481
|
+
}, ce = (t, e, o, i) => {
|
|
482
|
+
const s = new It(), n = /* @__PURE__ */ new Map(), r = dt(), a = (c, d) => {
|
|
483
|
+
const A = c.selector.flatMap((N) => {
|
|
484
|
+
const S = D([N]) ? N.range : pt(N, e).range;
|
|
485
|
+
return Jt(S);
|
|
486
|
+
}), R = ne(A, o, i).map((N) => oe(N, d));
|
|
463
487
|
return R.map((N) => {
|
|
464
|
-
const { x:
|
|
488
|
+
const { x: S, y: C, width: O, height: B } = N;
|
|
465
489
|
return {
|
|
466
|
-
minX:
|
|
467
|
-
minY:
|
|
468
|
-
maxX:
|
|
469
|
-
maxY:
|
|
490
|
+
minX: S,
|
|
491
|
+
minY: C,
|
|
492
|
+
maxX: S + O,
|
|
493
|
+
maxY: C + B,
|
|
470
494
|
annotation: {
|
|
471
|
-
id:
|
|
495
|
+
id: c.annotation,
|
|
472
496
|
rects: R
|
|
473
497
|
}
|
|
474
498
|
};
|
|
475
499
|
});
|
|
476
|
-
},
|
|
500
|
+
}, u = () => [...n.values()], g = () => {
|
|
477
501
|
s.clear(), n.clear();
|
|
478
|
-
},
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
},
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
}, h = (
|
|
485
|
-
|
|
486
|
-
}, T = (
|
|
487
|
-
|
|
488
|
-
const A = e.getBoundingClientRect(), R =
|
|
489
|
-
R.forEach(({ target:
|
|
490
|
-
|
|
502
|
+
}, m = (c) => {
|
|
503
|
+
const d = a(c, e.getBoundingClientRect());
|
|
504
|
+
d.length !== 0 && (d.forEach((A) => s.insert(A)), n.set(c.annotation, d));
|
|
505
|
+
}, b = (c) => {
|
|
506
|
+
const d = n.get(c.annotation);
|
|
507
|
+
d && (d.forEach((A) => s.remove(A)), n.delete(c.annotation));
|
|
508
|
+
}, h = (c) => {
|
|
509
|
+
b(c), m(c);
|
|
510
|
+
}, T = (c, d = !0) => {
|
|
511
|
+
d && g();
|
|
512
|
+
const A = e.getBoundingClientRect(), R = c.map((S) => ({ target: S, rects: a(S, A) }));
|
|
513
|
+
R.forEach(({ target: S, rects: C }) => {
|
|
514
|
+
C.length > 0 && n.set(S.annotation, C);
|
|
491
515
|
});
|
|
492
|
-
const N = R.flatMap(({ rects:
|
|
516
|
+
const N = R.flatMap(({ rects: S }) => S);
|
|
493
517
|
s.load(N);
|
|
494
|
-
},
|
|
518
|
+
}, l = (c, d, A = !1) => {
|
|
495
519
|
const R = s.search({
|
|
496
|
-
minX:
|
|
497
|
-
minY:
|
|
498
|
-
maxX:
|
|
499
|
-
maxY:
|
|
500
|
-
}), N = (
|
|
501
|
-
return R.length > 0 ? (R.sort((
|
|
502
|
-
}, L = (
|
|
503
|
-
const
|
|
504
|
-
if (
|
|
520
|
+
minX: c,
|
|
521
|
+
minY: d,
|
|
522
|
+
maxX: c,
|
|
523
|
+
maxY: d
|
|
524
|
+
}), N = (S) => S.annotation.rects.reduce((C, O) => C + O.width * O.height, 0);
|
|
525
|
+
return R.length > 0 ? (R.sort((S, C) => N(S) - N(C)), A ? R.map((S) => S.annotation.id) : [R[0].annotation.id]) : [];
|
|
526
|
+
}, L = (c) => {
|
|
527
|
+
const d = x(c);
|
|
528
|
+
if (d.length === 0)
|
|
505
529
|
return;
|
|
506
|
-
let A =
|
|
507
|
-
for (let
|
|
508
|
-
const O =
|
|
509
|
-
A = Math.min(A, O.left), R = Math.min(R, O.top), N = Math.max(N, O.right),
|
|
530
|
+
let A = d[0].left, R = d[0].top, N = d[0].right, S = d[0].bottom;
|
|
531
|
+
for (let C = 1; C < d.length; C++) {
|
|
532
|
+
const O = d[C];
|
|
533
|
+
A = Math.min(A, O.left), R = Math.min(R, O.top), N = Math.max(N, O.right), S = Math.max(S, O.bottom);
|
|
510
534
|
}
|
|
511
|
-
return new DOMRect(A, R, N - A,
|
|
512
|
-
}, x = (
|
|
513
|
-
const
|
|
514
|
-
return
|
|
535
|
+
return new DOMRect(A, R, N - A, S - R);
|
|
536
|
+
}, x = (c) => {
|
|
537
|
+
const d = n.get(c);
|
|
538
|
+
return d ? d[0].annotation.rects : [];
|
|
515
539
|
};
|
|
516
540
|
return {
|
|
517
|
-
all:
|
|
518
|
-
clear:
|
|
519
|
-
getAt:
|
|
541
|
+
all: u,
|
|
542
|
+
clear: g,
|
|
543
|
+
getAt: l,
|
|
520
544
|
getAnnotationBounds: L,
|
|
521
545
|
getAnnotationRects: x,
|
|
522
|
-
getIntersecting: (
|
|
523
|
-
const N = s.search({ minX:
|
|
524
|
-
return Array.from(
|
|
525
|
-
annotation: t.getAnnotation(
|
|
526
|
-
rects: x(
|
|
527
|
-
})).filter((
|
|
546
|
+
getIntersecting: (c, d, A, R) => {
|
|
547
|
+
const N = s.search({ minX: c, minY: d, maxX: A, maxY: R }), S = new Set(N.map((C) => C.annotation.id));
|
|
548
|
+
return Array.from(S).map((C) => ({
|
|
549
|
+
annotation: t.getAnnotation(C),
|
|
550
|
+
rects: x(C)
|
|
551
|
+
})).filter((C) => !!C.annotation);
|
|
528
552
|
},
|
|
529
|
-
insert:
|
|
553
|
+
insert: m,
|
|
530
554
|
recalculate: () => {
|
|
531
|
-
T(t.all().map((
|
|
555
|
+
T(t.all().map((c) => c.target), !0), r.emit("recalculate");
|
|
532
556
|
},
|
|
533
|
-
remove:
|
|
557
|
+
remove: b,
|
|
534
558
|
set: T,
|
|
535
559
|
size: () => s.all().length,
|
|
536
560
|
update: h,
|
|
537
|
-
on: (
|
|
561
|
+
on: (c, d) => r.on(c, d)
|
|
538
562
|
};
|
|
539
563
|
}, le = (t, e) => {
|
|
540
|
-
const o =
|
|
541
|
-
const w =
|
|
542
|
-
return
|
|
543
|
-
},
|
|
544
|
-
const
|
|
545
|
-
return o.bulkAddAnnotations(
|
|
546
|
-
},
|
|
547
|
-
const w =
|
|
548
|
-
return w.forEach((
|
|
549
|
-
o.getAnnotation(
|
|
550
|
-
}),
|
|
551
|
-
},
|
|
552
|
-
const w = Q(
|
|
564
|
+
const o = vt(), i = ce(o, t, e.mergeHighlights?.horizontalTolerance, e.mergeHighlights?.verticalTolerance), s = wt(o, e.userSelectAction, e.adapter), n = xt(o), r = Lt(), a = (p, E = F.LOCAL) => {
|
|
565
|
+
const w = Z(p, t), c = D(w.target.selector);
|
|
566
|
+
return c && o.addAnnotation(w, E), c;
|
|
567
|
+
}, u = (p, E = !0, w = F.LOCAL) => {
|
|
568
|
+
const c = p.map((A) => Z(A, t)), d = c.filter((A) => !D(A.target.selector));
|
|
569
|
+
return o.bulkAddAnnotations(c, E, w), d;
|
|
570
|
+
}, g = (p, E = F.LOCAL) => {
|
|
571
|
+
const w = p.map((d) => Z(d, t)), c = w.filter((d) => !D(d.target.selector));
|
|
572
|
+
return w.forEach((d) => {
|
|
573
|
+
o.getAnnotation(d.id) ? o.updateAnnotation(d, E) : o.addAnnotation(d, E);
|
|
574
|
+
}), c;
|
|
575
|
+
}, m = (p, E = F.LOCAL) => {
|
|
576
|
+
const w = Q(p, t);
|
|
553
577
|
o.updateTarget(w, E);
|
|
554
|
-
},
|
|
555
|
-
const w =
|
|
578
|
+
}, b = (p, E = F.LOCAL) => {
|
|
579
|
+
const w = p.map((c) => Q(c, t));
|
|
556
580
|
o.bulkUpdateTargets(w, E);
|
|
557
581
|
};
|
|
558
|
-
function h(
|
|
559
|
-
const
|
|
582
|
+
function h(p, E, w, c) {
|
|
583
|
+
const d = w || !!c, A = i.getAt(p, E, d).map((N) => o.getAnnotation(N)).filter(Boolean), R = c ? A.filter(c) : A;
|
|
560
584
|
if (R.length !== 0)
|
|
561
585
|
return w ? R : R[0];
|
|
562
586
|
}
|
|
563
|
-
const T = (
|
|
564
|
-
return o.observe(({ changes:
|
|
565
|
-
const E = (
|
|
566
|
-
E?.length > 0 && E.forEach((
|
|
587
|
+
const T = (p) => i.getAnnotationRects(p).length > 0 ? i.getAnnotationBounds(p) : void 0, l = (p, E, w, c) => i.getIntersecting(p, E, w, c), L = (p) => i.getAnnotationRects(p), x = () => i.recalculate(), v = (p) => i.on("recalculate", p);
|
|
588
|
+
return o.observe(({ changes: p }) => {
|
|
589
|
+
const E = (p.deleted || []).filter((d) => D(d.target.selector)), w = (p.created || []).filter((d) => D(d.target.selector)), c = (p.updated || []).filter((d) => D(d.newValue.target.selector));
|
|
590
|
+
E?.length > 0 && E.forEach((d) => i.remove(d.target)), w.length > 0 && i.set(w.map((d) => d.target), !1), c?.length > 0 && c.forEach(({ newValue: d }) => i.update(d.target));
|
|
567
591
|
}), {
|
|
568
592
|
store: {
|
|
569
593
|
...o,
|
|
570
|
-
addAnnotation:
|
|
571
|
-
bulkAddAnnotations:
|
|
572
|
-
bulkUpdateTargets:
|
|
573
|
-
bulkUpsertAnnotations:
|
|
594
|
+
addAnnotation: a,
|
|
595
|
+
bulkAddAnnotations: u,
|
|
596
|
+
bulkUpdateTargets: b,
|
|
597
|
+
bulkUpsertAnnotations: g,
|
|
574
598
|
getAnnotationBounds: T,
|
|
575
599
|
getAnnotationRects: L,
|
|
576
|
-
getIntersecting:
|
|
600
|
+
getIntersecting: l,
|
|
577
601
|
getAt: h,
|
|
578
602
|
recalculatePositions: x,
|
|
579
603
|
onRecalculatePositions: v,
|
|
580
|
-
updateTarget:
|
|
604
|
+
updateTarget: m
|
|
581
605
|
},
|
|
582
606
|
selection: s,
|
|
583
607
|
hover: n,
|
|
584
608
|
viewport: r
|
|
585
609
|
};
|
|
586
|
-
},
|
|
587
|
-
...
|
|
588
|
-
|
|
610
|
+
}, at = 300, Et = ["up", "down", "left", "right"], bt = ut ? "⌘+a" : "ctrl+a", de = [
|
|
611
|
+
...Et.map((t) => `shift+${t}`),
|
|
612
|
+
bt
|
|
589
613
|
], ue = (t, e, o, i) => {
|
|
590
614
|
const { store: s, selection: n } = e;
|
|
591
615
|
let r;
|
|
592
616
|
const {
|
|
593
|
-
annotatingEnabled:
|
|
594
|
-
offsetReferenceSelector:
|
|
595
|
-
selectionMode:
|
|
596
|
-
dismissOnNotAnnotatable:
|
|
617
|
+
annotatingEnabled: a,
|
|
618
|
+
offsetReferenceSelector: u,
|
|
619
|
+
selectionMode: g,
|
|
620
|
+
dismissOnNotAnnotatable: m = "NEVER"
|
|
597
621
|
} = i;
|
|
598
|
-
let
|
|
599
|
-
const
|
|
600
|
-
h =
|
|
601
|
-
}, E = (
|
|
622
|
+
let b, h = a, T = "CREATE_NEW", l, L, x, v;
|
|
623
|
+
const p = (f) => {
|
|
624
|
+
h = f, R.clear(), f || (L = void 0, l = void 0, x = void 0, v = void 0);
|
|
625
|
+
}, E = (f) => T = f || "CREATE_NEW", w = (f) => b = f, c = (f) => r = f, d = (f) => {
|
|
602
626
|
if (T === "ADD_TO_CURRENT")
|
|
603
627
|
return !0;
|
|
604
628
|
if (i.allowModifierSelect) {
|
|
605
|
-
const
|
|
606
|
-
return
|
|
629
|
+
const y = f;
|
|
630
|
+
return ut ? y.metaKey : y.ctrlKey;
|
|
607
631
|
} else
|
|
608
632
|
return !1;
|
|
609
633
|
}, A = () => {
|
|
610
634
|
if (!h || x === !1) return;
|
|
611
|
-
const { selected:
|
|
612
|
-
if ((
|
|
613
|
-
const M = s.getAnnotation(
|
|
635
|
+
const { selected: f } = n;
|
|
636
|
+
if ((d(v) || T === "REPLACE_CURRENT") && f.length === 1 && f[0].editable) {
|
|
637
|
+
const M = s.getAnnotation(f[0].id);
|
|
614
638
|
if (M?.target) {
|
|
615
|
-
L = M.target,
|
|
639
|
+
L = M.target, l = {
|
|
616
640
|
annotation: M.id,
|
|
617
641
|
selector: [],
|
|
618
642
|
created: L.created,
|
|
@@ -623,153 +647,133 @@ const Ht = kt(), dt = Ht.os.is(Mt.MACOS), ut = "not-annotatable", $ = `.${ut}`,
|
|
|
623
647
|
return;
|
|
624
648
|
}
|
|
625
649
|
}
|
|
626
|
-
L = void 0,
|
|
650
|
+
L = void 0, l = {
|
|
627
651
|
annotation: lt(),
|
|
628
652
|
selector: [],
|
|
629
653
|
created: /* @__PURE__ */ new Date(),
|
|
630
654
|
creator: r
|
|
631
655
|
};
|
|
632
|
-
}, R =
|
|
656
|
+
}, R = _t((f) => {
|
|
633
657
|
if (!h) return;
|
|
634
|
-
const
|
|
635
|
-
if (!
|
|
636
|
-
const M = Array.from(Array(
|
|
637
|
-
if (
|
|
638
|
-
|
|
658
|
+
const y = document.getSelection();
|
|
659
|
+
if (!y?.anchorNode) return;
|
|
660
|
+
const M = Array.from(Array(y.rangeCount).keys()).map((k) => y.getRangeAt(k));
|
|
661
|
+
if (M.every((k) => !gt(t, k))) {
|
|
662
|
+
l = void 0;
|
|
639
663
|
return;
|
|
640
664
|
}
|
|
641
|
-
const U =
|
|
642
|
-
if (v?.type === "pointerdown" && (U < 1e3 && !
|
|
643
|
-
|
|
665
|
+
const U = f.timeStamp - (v?.timeStamp || f.timeStamp);
|
|
666
|
+
if (v?.type === "pointerdown" && (U < 1e3 && !l || y.isCollapsed && U < at) && A(), !l && (A(), !l))
|
|
667
|
+
return;
|
|
668
|
+
if (y.isCollapsed) {
|
|
669
|
+
s.getAnnotation(l.annotation) && !(d(v) || T === "REPLACE_CURRENT") && (n.clear(), s.deleteAnnotation(l.annotation));
|
|
644
670
|
return;
|
|
645
671
|
}
|
|
646
|
-
const I = M.map((k) =>
|
|
647
|
-
if (I.every((k) =>
|
|
648
|
-
const _ = I.flatMap((k) =>
|
|
649
|
-
if (!(_.length > 0 && !
|
|
650
|
-
const
|
|
672
|
+
const I = M.map((k) => $t(k, t));
|
|
673
|
+
if (I.every((k) => Ht(k))) return;
|
|
674
|
+
const _ = I.flatMap((k) => Ft(t, k.cloneRange()));
|
|
675
|
+
if (!(_.length > 0 && !l || _.length !== l.selector.length || _.some((k, W) => k.toString() !== l?.selector[W]?.quote))) return;
|
|
676
|
+
const j = d(v) && L ? Pt([
|
|
651
677
|
...L.selector.map((k) => k.range),
|
|
652
678
|
..._
|
|
653
679
|
]) : _;
|
|
654
|
-
|
|
655
|
-
...
|
|
656
|
-
selector:
|
|
680
|
+
l = {
|
|
681
|
+
...l,
|
|
682
|
+
selector: j.map((k) => Wt(k, t, u)),
|
|
657
683
|
updated: /* @__PURE__ */ new Date()
|
|
658
|
-
}, !(
|
|
659
|
-
}, 10), N = (
|
|
660
|
-
v =
|
|
661
|
-
},
|
|
684
|
+
}, !(d(v) || T === "REPLACE_CURRENT") && (s.getAnnotation(l.annotation) ? s.updateTarget(l, F.LOCAL) : n.clear());
|
|
685
|
+
}, 10), N = (f) => {
|
|
686
|
+
v = J(f), x = v.button === 0;
|
|
687
|
+
}, S = async (f) => {
|
|
662
688
|
if (!x) return;
|
|
663
|
-
const
|
|
689
|
+
const y = J(f), M = () => {
|
|
664
690
|
const { x: I, y: _ } = t.getBoundingClientRect();
|
|
665
|
-
if (
|
|
666
|
-
(typeof
|
|
691
|
+
if ($(t, y.target)) {
|
|
692
|
+
(typeof m == "function" ? m(y, t) : m === "ALWAYS") && n.clear();
|
|
667
693
|
return;
|
|
668
694
|
}
|
|
669
|
-
const H =
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
695
|
+
const H = y.target instanceof Node && t.contains(y.target) && s.getAt(
|
|
696
|
+
y.clientX - I,
|
|
697
|
+
y.clientY - _,
|
|
698
|
+
g === "all",
|
|
699
|
+
b
|
|
674
700
|
);
|
|
675
701
|
if (H) {
|
|
676
|
-
const { selected:
|
|
677
|
-
(k.size !==
|
|
702
|
+
const { selected: j } = n, k = new Set(j.map((X) => X.id)), W = Array.isArray(H) ? H.map((X) => X.id) : [H.id];
|
|
703
|
+
(k.size !== W.length || !W.every((X) => k.has(X))) && (o.emit("clickAnnotation", H), n.userSelect(W, y));
|
|
678
704
|
} else
|
|
679
705
|
n.clear();
|
|
680
706
|
};
|
|
681
|
-
if (
|
|
682
|
-
await
|
|
683
|
-
const I = document.getSelection(), _ =
|
|
707
|
+
if (y.timeStamp - (v?.timeStamp || 0) < at) {
|
|
708
|
+
await C();
|
|
709
|
+
const I = document.getSelection(), _ = $(t, v?.target), H = $(t, y.target);
|
|
684
710
|
if (I?.isCollapsed || _ && H) {
|
|
685
|
-
|
|
711
|
+
l = void 0, M();
|
|
686
712
|
return;
|
|
687
713
|
}
|
|
688
714
|
}
|
|
689
|
-
|
|
690
|
-
},
|
|
691
|
-
const
|
|
692
|
-
let
|
|
693
|
-
const U = () => M ||
|
|
694
|
-
return setTimeout(() =>
|
|
695
|
-
}, O = (
|
|
696
|
-
document.getSelection()?.isCollapsed || ((!
|
|
697
|
-
}, B = (
|
|
698
|
-
h &&
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
715
|
+
l && l.selector.length > 0 && (K(), n.userSelect(l.annotation, y));
|
|
716
|
+
}, C = async () => {
|
|
717
|
+
const f = document.getSelection();
|
|
718
|
+
let y = !1, M = f?.isCollapsed;
|
|
719
|
+
const U = () => M || y, I = 1;
|
|
720
|
+
return setTimeout(() => y = !0, 50), Dt(() => M = f?.isCollapsed, I, U);
|
|
721
|
+
}, O = (f) => {
|
|
722
|
+
document.getSelection()?.isCollapsed || ((!l || l.selector.length === 0) && R(f), l && (K(), n.userSelect(l.annotation, J(f))));
|
|
723
|
+
}, B = (f) => {
|
|
724
|
+
if (h && !(f.repeat || f.target instanceof Node && $(t, f.target) && f.target !== document.body) && f.key === "Shift" && l) {
|
|
725
|
+
const y = document.getSelection();
|
|
726
|
+
y && !y.isCollapsed && (K(), n.userSelect(l.annotation, G(f)));
|
|
727
|
+
}
|
|
728
|
+
}, V = (f) => {
|
|
729
|
+
const y = () => setTimeout(() => {
|
|
730
|
+
l && (l.selector.length > 0 && (n.clear(), s.addAnnotation({
|
|
731
|
+
id: l.annotation,
|
|
703
732
|
bodies: [],
|
|
704
|
-
target:
|
|
705
|
-
}), n.userSelect(
|
|
733
|
+
target: l
|
|
734
|
+
}), n.userSelect(l.annotation, G(f))), document.removeEventListener("selectionchange", y));
|
|
706
735
|
}, 100);
|
|
707
|
-
document.addEventListener("selectionchange",
|
|
736
|
+
document.addEventListener("selectionchange", y), A();
|
|
708
737
|
};
|
|
709
|
-
q(de.join(","), { element: t, keydown: !0, keyup: !1 }, (
|
|
710
|
-
|
|
711
|
-
}), q(
|
|
712
|
-
v =
|
|
738
|
+
q(de.join(","), { element: t, keydown: !0, keyup: !1 }, (f) => {
|
|
739
|
+
f.repeat || (v = G(f));
|
|
740
|
+
}), q(bt, { keydown: !0, keyup: !1 }, (f) => {
|
|
741
|
+
v = G(f), V(f);
|
|
713
742
|
});
|
|
714
|
-
const
|
|
715
|
-
|
|
743
|
+
const z = (f) => {
|
|
744
|
+
f.repeat || f.target instanceof Node && $(t, f.target) && f.target !== document.body || (l = void 0, n.clear());
|
|
716
745
|
};
|
|
717
|
-
q(
|
|
746
|
+
q(Et.join(","), { keydown: !0, keyup: !1 }, z);
|
|
718
747
|
const K = () => {
|
|
719
|
-
|
|
720
|
-
|
|
748
|
+
if (!l) return;
|
|
749
|
+
const f = s.getAnnotation(l.annotation);
|
|
750
|
+
if (!f)
|
|
721
751
|
s.addAnnotation({
|
|
722
|
-
id:
|
|
752
|
+
id: l.annotation,
|
|
723
753
|
bodies: [],
|
|
724
|
-
target:
|
|
754
|
+
target: l
|
|
725
755
|
});
|
|
726
756
|
else {
|
|
727
|
-
const { target: { updated:
|
|
728
|
-
(!
|
|
757
|
+
const { target: { updated: y } } = f, { updated: M } = l;
|
|
758
|
+
(!y || !M || y < M) && s.updateTarget(l);
|
|
729
759
|
}
|
|
730
760
|
};
|
|
731
|
-
return document.addEventListener("pointerdown", N), document.addEventListener("pointerup",
|
|
761
|
+
return document.addEventListener("pointerdown", N), document.addEventListener("pointerup", S), document.addEventListener("contextmenu", O), document.addEventListener("keyup", B), t.addEventListener("selectstart", A), document.addEventListener("selectionchange", R), {
|
|
732
762
|
destroy: () => {
|
|
733
|
-
|
|
763
|
+
l = void 0, L = void 0, x = void 0, v = void 0, R.clear(), document.removeEventListener("pointerdown", N), document.removeEventListener("pointerup", S), document.removeEventListener("contextmenu", O), document.removeEventListener("keyup", B), t.removeEventListener("selectstart", A), document.removeEventListener("selectionchange", R), q.unbind();
|
|
734
764
|
},
|
|
735
765
|
setFilter: w,
|
|
736
|
-
setUser:
|
|
737
|
-
setAnnotatingEnabled:
|
|
766
|
+
setUser: c,
|
|
767
|
+
setAnnotatingEnabled: p,
|
|
738
768
|
setAnnotatingMode: E
|
|
739
769
|
};
|
|
740
|
-
}, fe = (t) =>
|
|
741
|
-
t.classList.add("r6o-annotatable");
|
|
742
|
-
const e = document.createElement("div");
|
|
743
|
-
e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
|
|
744
|
-
let o = [];
|
|
745
|
-
return {
|
|
746
|
-
destroy: () => {
|
|
747
|
-
e.remove();
|
|
748
|
-
},
|
|
749
|
-
redraw: (r, c, d, f, p) => {
|
|
750
|
-
if (!(!Dt(o, r) || p)) return;
|
|
751
|
-
e.innerHTML = "", [...r].sort((u, L) => {
|
|
752
|
-
const { annotation: { target: { created: x } } } = u, { annotation: { target: { created: v } } } = L;
|
|
753
|
-
return x && v ? x.getTime() - v.getTime() : 0;
|
|
754
|
-
}).forEach((u) => {
|
|
755
|
-
const L = f.get(u.annotation.id) || d;
|
|
756
|
-
u.rects.map((x) => {
|
|
757
|
-
const v = ne(x, r), m = mt(u, L, v), E = document.createElement("span");
|
|
758
|
-
E.className = "r6o-annotation", E.dataset.annotation = u.annotation.id, E.style.left = `${x.x}px`, E.style.top = `${x.y}px`, E.style.width = `${x.width}px`, E.style.height = `${x.height}px`, E.style.backgroundColor = Vt(m), m.underlineStyle && (E.style.borderStyle = m.underlineStyle), m.underlineColor && (E.style.borderColor = m.underlineColor), m.underlineThickness && (E.style.borderBottomWidth = `${m.underlineThickness}px`), m.underlineOffset && (E.style.paddingBottom = `${m.underlineOffset}px`), e.appendChild(E);
|
|
759
|
-
});
|
|
760
|
-
}), o = r;
|
|
761
|
-
},
|
|
762
|
-
setVisible: (r) => {
|
|
763
|
-
r ? e.classList.remove("hidden") : e.classList.add("hidden");
|
|
764
|
-
}
|
|
765
|
-
};
|
|
766
|
-
}, ge = (t, e, o) => gt(fe(t), t, e, o), me = (t) => [
|
|
770
|
+
}, fe = (t) => [
|
|
767
771
|
`background-color:${et(t?.fill || P.fill).alpha(t?.fillOpacity === void 0 ? P.fillOpacity : t.fillOpacity).toHex()}`,
|
|
768
772
|
t?.underlineThickness ? "text-decoration:underline" : void 0,
|
|
769
773
|
t?.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
770
774
|
t?.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
771
775
|
t?.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
|
|
772
|
-
].filter(Boolean).join(";"),
|
|
776
|
+
].filter(Boolean).join(";"), ge = () => {
|
|
773
777
|
const t = document.createElement("style");
|
|
774
778
|
document.getElementsByTagName("head")[0].appendChild(t);
|
|
775
779
|
let e = /* @__PURE__ */ new Set();
|
|
@@ -780,119 +784,137 @@ const Ht = kt(), dt = Ht.os.is(Mt.MACOS), ut = "not-annotatable", $ = `.${ut}`,
|
|
|
780
784
|
setVisible: (n) => {
|
|
781
785
|
console.log("setVisible not implemented on CSS Custom Highlights renderer");
|
|
782
786
|
},
|
|
783
|
-
redraw: (n, r,
|
|
784
|
-
const
|
|
785
|
-
Array.from(e).filter((h) => !
|
|
786
|
-
const
|
|
787
|
-
|
|
788
|
-
const T =
|
|
789
|
-
return `::highlight(_${h.annotation.id}) { ${
|
|
787
|
+
redraw: (n, r, a, u, g) => {
|
|
788
|
+
const m = new Set(n.map((h) => h.annotation.id));
|
|
789
|
+
Array.from(e).filter((h) => !m.has(h));
|
|
790
|
+
const b = n.map((h) => {
|
|
791
|
+
a ? typeof a == "function" && a(h.annotation, h.state) : h.state?.selected;
|
|
792
|
+
const T = St(h, a);
|
|
793
|
+
return `::highlight(_${h.annotation.id}) { ${fe(T)} }`;
|
|
790
794
|
});
|
|
791
|
-
t.innerHTML =
|
|
795
|
+
t.innerHTML = b.join(`
|
|
792
796
|
`), CSS.highlights.clear(), n.forEach(({ annotation: h }) => {
|
|
793
|
-
const T = h.target.selector.map((L) => L.range),
|
|
794
|
-
CSS.highlights.set(`_${h.id}`,
|
|
795
|
-
}), e =
|
|
797
|
+
const T = h.target.selector.map((L) => L.range), l = new Highlight(...T);
|
|
798
|
+
CSS.highlights.set(`_${h.id}`, l);
|
|
799
|
+
}), e = m;
|
|
796
800
|
}
|
|
797
801
|
};
|
|
798
|
-
},
|
|
802
|
+
}, me = (t, e, o) => yt(ge(), t, e, o), pe = (t, e) => ({
|
|
799
803
|
...t,
|
|
800
804
|
annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
|
|
801
805
|
user: t.user || e.user
|
|
802
|
-
}), ct = "SPANS",
|
|
803
|
-
|
|
804
|
-
const o =
|
|
806
|
+
}), ct = "SPANS", Oe = (t, e = {}) => {
|
|
807
|
+
Gt(t), Ut(t);
|
|
808
|
+
const o = pe(e, {
|
|
805
809
|
annotatingEnabled: !0,
|
|
806
|
-
user:
|
|
807
|
-
}), i = le(t, o), { selection: s, viewport: n } = i, r = i.store,
|
|
808
|
-
let
|
|
809
|
-
const
|
|
810
|
-
|
|
810
|
+
user: Nt()
|
|
811
|
+
}), i = le(t, o), { selection: s, viewport: n } = i, r = i.store, a = Ot(r), u = kt(i, a, o.adapter);
|
|
812
|
+
let g = o.user;
|
|
813
|
+
const m = typeof o.renderer != "function" ? o.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ct : o.renderer || ct : null, b = m === null ? o.renderer(
|
|
814
|
+
t,
|
|
815
|
+
i,
|
|
816
|
+
n
|
|
817
|
+
) : m === "SPANS" ? re(
|
|
818
|
+
t,
|
|
819
|
+
i,
|
|
820
|
+
n
|
|
821
|
+
) : m === "CSS_HIGHLIGHTS" ? me(
|
|
822
|
+
t,
|
|
823
|
+
i,
|
|
824
|
+
n
|
|
825
|
+
) : void 0;
|
|
826
|
+
if (!b)
|
|
811
827
|
throw `Unknown renderer implementation: ${o.renderer}`;
|
|
812
|
-
console.debug(
|
|
813
|
-
const h = ue(
|
|
814
|
-
|
|
815
|
-
|
|
828
|
+
console.debug(m ? `Using ${m} renderer` : "Using custom renderer implementation"), o.style && b.setStyle(o.style);
|
|
829
|
+
const h = ue(
|
|
830
|
+
t,
|
|
831
|
+
i,
|
|
832
|
+
u,
|
|
833
|
+
o
|
|
834
|
+
);
|
|
835
|
+
h.setUser(g);
|
|
836
|
+
const T = Mt(i, a, o.adapter), l = () => g, L = (c) => {
|
|
816
837
|
h.setAnnotatingEnabled(
|
|
817
|
-
|
|
838
|
+
c === void 0 ? !0 : c
|
|
818
839
|
);
|
|
819
|
-
}, x = (
|
|
820
|
-
h.setAnnotatingMode(
|
|
821
|
-
}, v = (
|
|
822
|
-
|
|
823
|
-
},
|
|
824
|
-
|
|
825
|
-
}, E = (
|
|
826
|
-
|
|
840
|
+
}, x = (c) => {
|
|
841
|
+
h.setAnnotatingMode(c);
|
|
842
|
+
}, v = (c) => {
|
|
843
|
+
b.setFilter(c), h.setFilter(c);
|
|
844
|
+
}, p = (c) => {
|
|
845
|
+
g = c, h.setUser(c);
|
|
846
|
+
}, E = (c) => {
|
|
847
|
+
c ? s.setSelected(c) : s.clear();
|
|
827
848
|
};
|
|
828
849
|
return {
|
|
829
850
|
...T,
|
|
830
851
|
destroy: () => {
|
|
831
|
-
|
|
852
|
+
b.destroy(), h.destroy(), a.destroy();
|
|
832
853
|
},
|
|
833
854
|
element: t,
|
|
834
|
-
getUser:
|
|
835
|
-
renderer:
|
|
855
|
+
getUser: l,
|
|
856
|
+
renderer: b,
|
|
836
857
|
setAnnotatingEnabled: L,
|
|
837
858
|
setAnnotatingMode: x,
|
|
838
859
|
setFilter: v,
|
|
839
|
-
setStyle:
|
|
840
|
-
setUser:
|
|
860
|
+
setStyle: b.setStyle.bind(b),
|
|
861
|
+
setUser: p,
|
|
841
862
|
setSelected: E,
|
|
842
|
-
setVisible:
|
|
843
|
-
on:
|
|
844
|
-
off:
|
|
845
|
-
scrollIntoView:
|
|
863
|
+
setVisible: b.setVisible.bind(b),
|
|
864
|
+
on: u.on,
|
|
865
|
+
off: u.off,
|
|
866
|
+
scrollIntoView: Xt(t, r),
|
|
846
867
|
state: i
|
|
847
868
|
};
|
|
848
869
|
};
|
|
849
870
|
export {
|
|
850
871
|
ot as DEFAULT_SELECTED_STYLE,
|
|
851
872
|
P as DEFAULT_STYLE,
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
873
|
+
ft as NOT_ANNOTATABLE_CLASS,
|
|
874
|
+
Y as NOT_ANNOTATABLE_SELECTOR,
|
|
875
|
+
Be as Origin,
|
|
876
|
+
Ie as UserSelectAction,
|
|
877
|
+
xe as W3CTextFormat,
|
|
878
|
+
Gt as cancelSingleClickEvents,
|
|
879
|
+
G as cloneKeyboardEvent,
|
|
880
|
+
J as clonePointerEvent,
|
|
881
|
+
St as computeStyle,
|
|
882
|
+
Zt as computeZIndex,
|
|
883
|
+
_e as createBody,
|
|
884
|
+
yt as createRenderer,
|
|
864
885
|
ue as createSelectionHandler,
|
|
865
|
-
|
|
886
|
+
re as createSpansRenderer,
|
|
887
|
+
Oe as createTextAnnotator,
|
|
866
888
|
le as createTextAnnotatorState,
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
889
|
+
tt as debounce,
|
|
890
|
+
pe as fillDefaults,
|
|
891
|
+
Qt as getBackgroundColor,
|
|
892
|
+
Jt as getHighlightClientRects,
|
|
893
|
+
Yt as getQuoteContext,
|
|
872
894
|
nt as getRangeAnnotatableContents,
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
895
|
+
ie as getViewportBounds,
|
|
896
|
+
ut as isMac,
|
|
897
|
+
we as isNodeWhitespaceOrEmpty,
|
|
898
|
+
$ as isNotAnnotatable,
|
|
899
|
+
gt as isRangeAnnotatable,
|
|
900
|
+
Ht as isRangeWhitespaceOrEmpty,
|
|
879
901
|
D as isRevived,
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
902
|
+
ne as mergeClientRects,
|
|
903
|
+
Pt as mergeRanges,
|
|
904
|
+
jt as parseW3CTextAnnotation,
|
|
905
|
+
Ut as programmaticallyFocusable,
|
|
906
|
+
Wt as rangeToSelector,
|
|
907
|
+
Z as reviveAnnotation,
|
|
886
908
|
pt as reviveSelector,
|
|
887
909
|
Q as reviveTarget,
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
910
|
+
Xt as scrollIntoView,
|
|
911
|
+
qt as serializeW3CTextAnnotation,
|
|
912
|
+
Ft as splitAnnotatableRanges,
|
|
913
|
+
Le as toDomRectList,
|
|
914
|
+
oe as toParentBounds,
|
|
915
|
+
Ne as toViewportBounds,
|
|
916
|
+
ae as trackViewport,
|
|
917
|
+
$t as trimRangeToContainer,
|
|
918
|
+
mt as whitespaceOrEmptyRegex
|
|
897
919
|
};
|
|
898
920
|
//# sourceMappingURL=text-annotator.es.js.map
|