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