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