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