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