@recogito/text-annotator 3.3.2 → 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.
|
@@ -9,8 +9,8 @@ import At from "rbush";
|
|
|
9
9
|
import W from "hotkeys-js";
|
|
10
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) : (
|
|
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
14
|
}, xt = (t, e) => {
|
|
15
15
|
const n = e.commonAncestorContainer;
|
|
16
16
|
return !Y(t, n);
|
|
@@ -63,114 +63,127 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
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
|
|
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
|
-
},
|
|
113
|
+
}, Bt = (t, e) => {
|
|
101
114
|
if (!xt(t, e)) return [];
|
|
102
115
|
const n = [];
|
|
103
|
-
let
|
|
104
|
-
for (const
|
|
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 (
|
|
109
|
-
const
|
|
110
|
-
|
|
121
|
+
if (i) {
|
|
122
|
+
const s = e.cloneRange();
|
|
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
|
-
},
|
|
117
|
-
const
|
|
118
|
-
o.setStart(
|
|
119
|
-
const
|
|
120
|
-
a.setStart(t.endContainer, t.endOffset),
|
|
129
|
+
}, It = (t, e, n = 10, i) => {
|
|
130
|
+
const s = i ? t.startContainer.parentElement.closest(i) : e, o = document.createRange();
|
|
131
|
+
o.setStart(s, 0), o.setEnd(t.startContainer, t.startOffset);
|
|
132
|
+
const r = Q(o).textContent, a = document.createRange();
|
|
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),
|
|
127
|
-
const
|
|
128
|
-
top:
|
|
129
|
-
bottom:
|
|
130
|
-
left:
|
|
131
|
-
right:
|
|
132
|
-
},
|
|
133
|
-
top:
|
|
134
|
-
bottom:
|
|
135
|
-
left:
|
|
136
|
-
right:
|
|
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) => {
|
|
140
|
+
const s = (a) => Math.round(a * 10) / 10, o = {
|
|
141
|
+
top: s(t.top),
|
|
142
|
+
bottom: s(t.bottom),
|
|
143
|
+
left: s(t.left),
|
|
144
|
+
right: s(t.right)
|
|
145
|
+
}, r = {
|
|
146
|
+
top: s(e.top),
|
|
147
|
+
bottom: s(e.bottom),
|
|
148
|
+
left: s(e.left),
|
|
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
|
-
},
|
|
151
|
-
const n = Math.min(t.left, e.left),
|
|
152
|
-
return new DOMRect(n,
|
|
153
|
-
},
|
|
154
|
-
if (
|
|
155
|
-
return
|
|
156
|
-
let o = [...
|
|
157
|
-
for (const a of
|
|
158
|
-
const d =
|
|
163
|
+
}, Pt = (t, e) => {
|
|
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) => {
|
|
167
|
+
if (s.width === 0 || s.height === 0)
|
|
168
|
+
return i;
|
|
169
|
+
let o = [...i], r = !1;
|
|
170
|
+
for (const a of i) {
|
|
171
|
+
const d = Mt(s, a, e, n);
|
|
159
172
|
if (d === "inline-adjacent") {
|
|
160
|
-
o = o.map((p) => p === a ?
|
|
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 ?
|
|
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
|
-
|
|
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
|
|
186
|
+
return r ? o : [...o, s];
|
|
174
187
|
}, []), we = (t) => ({
|
|
175
188
|
length: t.length,
|
|
176
189
|
item: (e) => t[e],
|
|
@@ -178,14 +191,14 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
178
191
|
for (let e = 0; e < this.length; e++)
|
|
179
192
|
yield this.item(e);
|
|
180
193
|
}
|
|
181
|
-
}),
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
const o = Q(
|
|
185
|
-
return n ? { quote:
|
|
194
|
+
}), _t = (t, e, n) => {
|
|
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 };
|
|
186
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) => {
|
|
@@ -193,29 +206,29 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
193
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.");
|
|
200
|
-
let p = !
|
|
213
|
+
let p = !s;
|
|
201
214
|
for (; d !== null; ) {
|
|
202
|
-
if (p || (p = typeof (
|
|
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,
|
|
@@ -224,7 +237,7 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
224
237
|
}, X = (t, e) => H(t.selector) ? t : {
|
|
225
238
|
...t,
|
|
226
239
|
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : rt(n, e))
|
|
227
|
-
}, j = (t, e) => H(t.target.selector) ? t : { ...t, target: X(t.target, e) },
|
|
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) => {
|
|
@@ -232,59 +245,59 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
232
245
|
return document.scrollingElement;
|
|
233
246
|
const { overflowY: e } = window.getComputedStyle(t);
|
|
234
247
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : it(t.parentElement);
|
|
235
|
-
},
|
|
236
|
-
const
|
|
237
|
-
const f = o.getBoundingClientRect(), c = o.clientHeight, u = o.clientWidth, R = b.selector[0].range.getBoundingClientRect(), { width: v, height: T } = e.getAnnotationBounds(
|
|
248
|
+
}, Dt = (t, e) => (n) => {
|
|
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
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 r
|
|
248
|
-
const d = X(
|
|
249
|
-
return p && !p.collapsed ? (
|
|
260
|
+
return s(r.target), !0;
|
|
261
|
+
const d = X(r.target, t), { range: p } = d.selector[0];
|
|
262
|
+
return p && !p.collapsed ? (s(d), !0) : !1;
|
|
250
263
|
}, M = {
|
|
251
264
|
fill: "rgb(0, 128, 255)",
|
|
252
265
|
fillOpacity: 0.18
|
|
253
266
|
}, z = {
|
|
254
267
|
fill: "rgb(0, 128, 255)",
|
|
255
268
|
fillOpacity: 0.45
|
|
256
|
-
},
|
|
257
|
-
var
|
|
258
|
-
const o = n ? typeof n == "function" ? n(t.annotation, t.state,
|
|
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;
|
|
273
|
+
}, $t = (t) => {
|
|
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 };
|
|
260
276
|
}, Wt = (t) => {
|
|
261
|
-
const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: s, innerHeight: r } = window, o = -n, i = -e, a = s - n, d = r - e;
|
|
262
|
-
return { top: e, left: n, minX: o, minY: i, maxX: a, maxY: d };
|
|
263
|
-
}, Vt = (t) => {
|
|
264
277
|
let e = /* @__PURE__ */ new Set();
|
|
265
|
-
return (
|
|
266
|
-
const
|
|
267
|
-
(e.size !==
|
|
278
|
+
return (i) => {
|
|
279
|
+
const s = i.map((o) => o.id);
|
|
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:
|
|
282
|
+
}, Z = (t, e, n, i) => {
|
|
283
|
+
const { store: s, selection: o, hover: r } = e;
|
|
271
284
|
let a, d, p;
|
|
272
|
-
const b =
|
|
273
|
-
const { x: N, y: S } = t.getBoundingClientRect(), A =
|
|
274
|
-
A ?
|
|
285
|
+
const b = Wt(n), f = D((C) => {
|
|
286
|
+
const { x: N, y: S } = t.getBoundingClientRect(), A = s.getAt(C.clientX - N, C.clientY - S, !1, d);
|
|
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 =
|
|
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
|
-
|
|
300
|
+
i.redraw(I, N, a, p, C), setTimeout(() => b(k.map(({ annotation: L }) => L)), 1);
|
|
288
301
|
}), 10), u = (C) => {
|
|
289
302
|
p = C, c();
|
|
290
303
|
}, R = (C) => {
|
|
@@ -292,11 +305,11 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
292
305
|
}, v = (C) => {
|
|
293
306
|
d = C, c(!1);
|
|
294
307
|
}, T = () => c();
|
|
295
|
-
|
|
296
|
-
const x = o.subscribe(() => c()), w =
|
|
308
|
+
s.observe(T);
|
|
309
|
+
const x = o.subscribe(() => c()), w = r.subscribe(() => c()), g = () => c(!0);
|
|
297
310
|
document.addEventListener("scroll", g, { capture: !0, passive: !0 });
|
|
298
311
|
const m = D(() => {
|
|
299
|
-
|
|
312
|
+
s.recalculatePositions(), p && p.reset(), c();
|
|
300
313
|
});
|
|
301
314
|
window.addEventListener("resize", m);
|
|
302
315
|
const y = new ResizeObserver(m);
|
|
@@ -306,24 +319,24 @@ 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
327
|
setPainter: u,
|
|
315
|
-
setVisible:
|
|
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
342
|
const { top: u, left: R } = d;
|
|
@@ -348,25 +361,25 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
348
361
|
});
|
|
349
362
|
}
|
|
350
363
|
});
|
|
351
|
-
}),
|
|
352
|
-
|
|
364
|
+
}), s = D(() => {
|
|
365
|
+
Yt(e);
|
|
353
366
|
});
|
|
354
|
-
return window.addEventListener("resize",
|
|
367
|
+
return window.addEventListener("resize", s), {
|
|
355
368
|
destroy: () => {
|
|
356
|
-
e.remove(), window.removeEventListener("resize",
|
|
369
|
+
e.remove(), window.removeEventListener("resize", s);
|
|
357
370
|
},
|
|
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()}`,
|
|
365
378
|
t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
|
|
366
379
|
t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
367
380
|
t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
368
381
|
t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
|
|
369
|
-
].filter(Boolean).join(";"),
|
|
382
|
+
].filter(Boolean).join(";"), jt = () => {
|
|
370
383
|
const t = document.createElement("style");
|
|
371
384
|
document.getElementsByTagName("head")[0].appendChild(t);
|
|
372
385
|
let e = /* @__PURE__ */ new Set();
|
|
@@ -377,14 +390,14 @@ 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, u = d && d.paint(f,
|
|
387
|
-
return `::highlight(_${f.annotation.id}) { ${
|
|
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 }) => {
|
|
@@ -393,10 +406,10 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
393
406
|
}), e = p;
|
|
394
407
|
}
|
|
395
408
|
};
|
|
396
|
-
},
|
|
397
|
-
const n = (o,
|
|
398
|
-
return
|
|
399
|
-
},
|
|
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) => {
|
|
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));
|
|
412
|
+
}, Jt = (t) => {
|
|
400
413
|
t.classList.add("r6o-annotatable");
|
|
401
414
|
const e = document.createElement("div");
|
|
402
415
|
e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
|
|
@@ -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 = !(ft(n,
|
|
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 =
|
|
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
|
-
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 =
|
|
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
|
-
},
|
|
429
|
-
parse: (n) =>
|
|
430
|
-
serialize: (n) =>
|
|
431
|
-
}),
|
|
441
|
+
}, te = (t, e, n) => Z(t, e, n, Jt(t)), Ae = (t, e) => ({
|
|
442
|
+
parse: (n) => oe(n),
|
|
443
|
+
serialize: (n) => se(n, t, e)
|
|
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:
|
|
436
|
-
modified:
|
|
448
|
+
created: i,
|
|
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
455
|
creator: mt(n),
|
|
443
|
-
created:
|
|
444
|
-
updated:
|
|
456
|
+
created: i ? new Date(i) : void 0,
|
|
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":
|
|
@@ -459,7 +472,7 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
459
472
|
}
|
|
460
473
|
return f;
|
|
461
474
|
}, {});
|
|
462
|
-
if (
|
|
475
|
+
if (ee(b))
|
|
463
476
|
a.selector.push(
|
|
464
477
|
{
|
|
465
478
|
...b,
|
|
@@ -477,36 +490,36 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
477
490
|
}
|
|
478
491
|
}
|
|
479
492
|
return { parsed: a };
|
|
480
|
-
},
|
|
493
|
+
}, oe = (t) => {
|
|
481
494
|
const e = t.id || nt(), {
|
|
482
495
|
creator: n,
|
|
483
|
-
created:
|
|
484
|
-
modified:
|
|
496
|
+
created: i,
|
|
497
|
+
modified: s,
|
|
485
498
|
body: o,
|
|
486
|
-
...
|
|
487
|
-
} = t, a = gt(o, e), d =
|
|
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
|
-
},
|
|
497
|
-
const { bodies:
|
|
498
|
-
selector:
|
|
509
|
+
}, se = (t, e, n) => {
|
|
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
|
-
} =
|
|
516
|
+
} = s, f = r.map((c) => {
|
|
504
517
|
const { id: u, quote: R, start: v, end: T, range: x } = c, w = {
|
|
505
518
|
type: "TextQuoteSelector",
|
|
506
519
|
exact: R
|
|
507
520
|
};
|
|
508
521
|
if (n) {
|
|
509
|
-
const { prefix: m, suffix: y } =
|
|
522
|
+
const { prefix: m, suffix: y } = It(x, n);
|
|
510
523
|
w.prefix = m, w.suffix = y;
|
|
511
524
|
}
|
|
512
525
|
const g = {
|
|
@@ -534,12 +547,12 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
534
547
|
modified: p == null ? void 0 : p.toISOString(),
|
|
535
548
|
target: f
|
|
536
549
|
};
|
|
537
|
-
},
|
|
538
|
-
const
|
|
550
|
+
}, re = (t, e, n, i) => {
|
|
551
|
+
const s = new At(), o = /* @__PURE__ */ new Map(), r = (g, m) => {
|
|
539
552
|
const y = g.selector.flatMap((h) => {
|
|
540
553
|
const E = H([h]) ? h.range : rt(h, e).range;
|
|
541
|
-
return
|
|
542
|
-
}), l =
|
|
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 {
|
|
@@ -554,25 +567,25 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
554
567
|
};
|
|
555
568
|
});
|
|
556
569
|
}, a = () => [...o.values()], d = () => {
|
|
557
|
-
|
|
570
|
+
s.clear(), o.clear();
|
|
558
571
|
}, p = (g) => {
|
|
559
|
-
const m =
|
|
560
|
-
m.length !== 0 && (m.forEach((y) =>
|
|
572
|
+
const m = r(g, e.getBoundingClientRect());
|
|
573
|
+
m.length !== 0 && (m.forEach((y) => s.insert(y)), o.set(g.annotation, m));
|
|
561
574
|
}, b = (g) => {
|
|
562
575
|
const m = o.get(g.annotation);
|
|
563
|
-
m && (m.forEach((y) =>
|
|
576
|
+
m && (m.forEach((y) => s.remove(y)), o.delete(g.annotation));
|
|
564
577
|
}, f = (g) => {
|
|
565
578
|
b(g), p(g);
|
|
566
579
|
}, c = (g, m = !0) => {
|
|
567
580
|
m && d();
|
|
568
|
-
const y = e.getBoundingClientRect(), l = g.map((E) => ({ target: E, rects:
|
|
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
|
-
const l =
|
|
588
|
+
const l = s.search({
|
|
576
589
|
minX: g,
|
|
577
590
|
minY: m,
|
|
578
591
|
maxX: g,
|
|
@@ -600,7 +613,7 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
600
613
|
getAnnotationBounds: R,
|
|
601
614
|
getAnnotationRects: v,
|
|
602
615
|
getIntersecting: (g, m, y, l) => {
|
|
603
|
-
const h =
|
|
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)
|
|
@@ -610,12 +623,12 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
610
623
|
recalculate: () => c(t.all().map((g) => g.target), !0),
|
|
611
624
|
remove: b,
|
|
612
625
|
set: c,
|
|
613
|
-
size: () =>
|
|
626
|
+
size: () => s.all().length,
|
|
614
627
|
update: f
|
|
615
628
|
};
|
|
616
|
-
},
|
|
629
|
+
}, ie = (t, e) => {
|
|
617
630
|
var x, w;
|
|
618
|
-
const n = pt(),
|
|
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) => {
|
|
619
632
|
const y = j(g, t), l = H(y.target.selector);
|
|
620
633
|
return l && n.addAnnotation(y, m), l;
|
|
621
634
|
}, d = (g, m = !0, y = F.LOCAL) => {
|
|
@@ -634,17 +647,17 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
634
647
|
n.bulkUpdateTargets(y, m);
|
|
635
648
|
};
|
|
636
649
|
function c(g, m, y, l) {
|
|
637
|
-
const h = y || !!l, E =
|
|
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
654
|
const u = (g) => {
|
|
642
|
-
if (
|
|
643
|
-
return
|
|
644
|
-
}, R = (g, m, y, l) =>
|
|
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();
|
|
645
658
|
return n.observe(({ changes: g }) => {
|
|
646
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));
|
|
647
|
-
(m == null ? void 0 : m.length) > 0 && m.forEach((h) =>
|
|
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,
|
|
@@ -659,37 +672,37 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
659
672
|
recalculatePositions: T,
|
|
660
673
|
updateTarget: b
|
|
661
674
|
},
|
|
662
|
-
selection:
|
|
675
|
+
selection: s,
|
|
663
676
|
hover: o,
|
|
664
|
-
viewport:
|
|
677
|
+
viewport: r
|
|
665
678
|
};
|
|
666
|
-
},
|
|
679
|
+
}, ae = () => {
|
|
667
680
|
const t = document.createElement("canvas");
|
|
668
681
|
t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
|
|
669
682
|
const e = t.getContext("2d");
|
|
670
683
|
return e.scale(2, 2), e.translate(0.5, 0.5), t;
|
|
671
|
-
},
|
|
672
|
-
const n =
|
|
684
|
+
}, ce = (t, e = {}) => {
|
|
685
|
+
const n = ae(), i = n.getContext("2d");
|
|
673
686
|
document.body.appendChild(n);
|
|
674
|
-
const
|
|
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((u) =>
|
|
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 u =
|
|
699
|
+
e.font && (i.font = e.font);
|
|
700
|
+
const u = s.get(b.annotation.id);
|
|
688
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
|
|
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), {
|
|
693
706
|
fill: u.appearance.color,
|
|
694
707
|
fillOpacity: c ? 0.45 : 0.18
|
|
695
708
|
};
|
|
@@ -701,17 +714,17 @@ 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, at = ["up", "down", "left", "right"], ct = Lt ? "⌘+a" : "ctrl+a",
|
|
717
|
+
}, tt = 300, at = ["up", "down", "left", "right"], ct = Lt ? "⌘+a" : "ctrl+a", le = [
|
|
705
718
|
...at.map((t) => `shift+${t}`),
|
|
706
719
|
ct
|
|
707
|
-
],
|
|
708
|
-
let
|
|
720
|
+
], de = (t, e, n) => {
|
|
721
|
+
let i;
|
|
709
722
|
const {
|
|
710
|
-
annotatingEnabled:
|
|
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
730
|
let u, R, v;
|
|
@@ -719,7 +732,7 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
719
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) => {
|
|
@@ -736,15 +749,15 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
736
749
|
f.getAnnotation(u.annotation) && (c.clear(), f.deleteAnnotation(u.annotation));
|
|
737
750
|
return;
|
|
738
751
|
}
|
|
739
|
-
const k = O.map((L) =>
|
|
740
|
-
if (k.every((L) =>
|
|
741
|
-
const
|
|
742
|
-
(
|
|
752
|
+
const k = O.map((L) => Ft(L, t));
|
|
753
|
+
if (k.every((L) => Ht(L))) return;
|
|
754
|
+
const B = k.flatMap((L) => Bt(t, L.cloneRange()));
|
|
755
|
+
(B.length > 0 && !u || B.length !== u.selector.length || B.some((L, _) => {
|
|
743
756
|
var U;
|
|
744
757
|
return L.toString() !== ((U = u.selector[_]) == null ? void 0 : U.quote);
|
|
745
758
|
})) && (u = {
|
|
746
759
|
...u,
|
|
747
|
-
selector:
|
|
760
|
+
selector: B.map((L) => _t(L, t, o)),
|
|
748
761
|
updated: /* @__PURE__ */ new Date()
|
|
749
762
|
}, f.getAnnotation(u.annotation) ? f.updateTarget(u, F.LOCAL) : c.clear());
|
|
750
763
|
}), w = (S) => {
|
|
@@ -752,27 +765,27 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
752
765
|
}, g = async (S) => {
|
|
753
766
|
if (!R) return;
|
|
754
767
|
const A = q(S), O = () => {
|
|
755
|
-
const { x: k, y:
|
|
768
|
+
const { x: k, y: B } = t.getBoundingClientRect();
|
|
756
769
|
if (Y(t, A.target)) {
|
|
757
770
|
(typeof a == "function" ? a(A, t) : a === "ALWAYS") && c.clear();
|
|
758
771
|
return;
|
|
759
772
|
}
|
|
760
|
-
const
|
|
773
|
+
const I = A.target instanceof Node && t.contains(A.target) && f.getAt(
|
|
761
774
|
A.clientX - k,
|
|
762
|
-
A.clientY -
|
|
763
|
-
|
|
775
|
+
A.clientY - B,
|
|
776
|
+
r === "all",
|
|
764
777
|
p
|
|
765
778
|
);
|
|
766
|
-
if (
|
|
767
|
-
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];
|
|
768
781
|
(_.size !== U.length || !U.every(($) => _.has($))) && c.userSelect(U, A);
|
|
769
782
|
} else
|
|
770
783
|
c.clear();
|
|
771
784
|
};
|
|
772
785
|
if (A.timeStamp - v.timeStamp < tt) {
|
|
773
786
|
await m();
|
|
774
|
-
const k = document.getSelection(),
|
|
775
|
-
if (k != null && k.isCollapsed ||
|
|
787
|
+
const k = document.getSelection(), B = Y(t, v.target), I = Y(t, A.target);
|
|
788
|
+
if (k != null && k.isCollapsed || B && I) {
|
|
776
789
|
u = void 0, O();
|
|
777
790
|
return;
|
|
778
791
|
}
|
|
@@ -798,7 +811,7 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
798
811
|
}, 100);
|
|
799
812
|
document.addEventListener("selectionchange", A), T();
|
|
800
813
|
};
|
|
801
|
-
W(
|
|
814
|
+
W(le.join(","), { element: t, keydown: !0, keyup: !1 }, (S) => {
|
|
802
815
|
S.repeat || (v = V(S));
|
|
803
816
|
}), W(ct, { keydown: !0, keyup: !1 }, (S) => {
|
|
804
817
|
v = V(S), h(S);
|
|
@@ -820,31 +833,31 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
820
833
|
const { target: { updated: A } } = S, { updated: O } = u;
|
|
821
834
|
(!A || !O || A < O) && f.updateTarget(u);
|
|
822
835
|
};
|
|
823
|
-
return document.addEventListener("pointerdown", w), document.addEventListener("pointerup", g), document.addEventListener("contextmenu", y),
|
|
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)), {
|
|
824
837
|
destroy: () => {
|
|
825
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();
|
|
826
839
|
},
|
|
827
840
|
setFilter: b,
|
|
828
841
|
setUser: d
|
|
829
842
|
};
|
|
830
|
-
},
|
|
843
|
+
}, fe = (t, e) => ({
|
|
831
844
|
...t,
|
|
832
845
|
annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
|
|
833
846
|
user: t.user || e.user
|
|
834
847
|
}), et = "SPANS", ve = (t, e = {}) => {
|
|
835
848
|
Tt(t), Nt(t);
|
|
836
|
-
const n =
|
|
849
|
+
const n = fe(e, {
|
|
837
850
|
annotatingEnabled: !0,
|
|
838
851
|
user: St()
|
|
839
|
-
}),
|
|
852
|
+
}), i = ie(t, n), { selection: s, viewport: o } = i, r = i.store, a = Ct(r), d = Et(i, a, n.adapter);
|
|
840
853
|
let p = n.user;
|
|
841
|
-
const b = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : et : n.renderer || et, f = b === "SPANS" ?
|
|
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;
|
|
842
855
|
if (!f)
|
|
843
856
|
throw `Unknown renderer implementation: ${b}`;
|
|
844
857
|
console.debug(`Using ${b} renderer`), n.style && f.setStyle(n.style);
|
|
845
|
-
const c =
|
|
858
|
+
const c = de(t, i, n);
|
|
846
859
|
return c.setUser(p), {
|
|
847
|
-
...wt(
|
|
860
|
+
...wt(i, a, n.adapter),
|
|
848
861
|
destroy: () => {
|
|
849
862
|
f.destroy(), c.destroy(), a.destroy();
|
|
850
863
|
},
|
|
@@ -858,16 +871,16 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
858
871
|
p = l, c.setUser(l);
|
|
859
872
|
},
|
|
860
873
|
setSelected: (l) => {
|
|
861
|
-
l ?
|
|
874
|
+
l ? s.setSelected(l) : s.clear();
|
|
862
875
|
},
|
|
863
876
|
setPresenceProvider: (l) => {
|
|
864
|
-
l && (f.setPainter(
|
|
877
|
+
l && (f.setPainter(ce(l, n.presence)), l.on("selectionChange", () => f.redraw()));
|
|
865
878
|
},
|
|
866
879
|
setVisible: (l) => f.setVisible(l),
|
|
867
880
|
on: d.on,
|
|
868
881
|
off: d.off,
|
|
869
|
-
scrollIntoView:
|
|
870
|
-
state:
|
|
882
|
+
scrollIntoView: Dt(t, r),
|
|
883
|
+
state: i
|
|
871
884
|
};
|
|
872
885
|
};
|
|
873
886
|
export {
|
|
@@ -876,44 +889,44 @@ export {
|
|
|
876
889
|
ot as NOT_ANNOTATABLE_CLASS,
|
|
877
890
|
K as NOT_ANNOTATABLE_SELECTOR,
|
|
878
891
|
Re as Origin,
|
|
879
|
-
|
|
892
|
+
de as SelectionHandler,
|
|
880
893
|
Le as UserSelectAction,
|
|
881
894
|
Ae as W3CTextFormat,
|
|
882
895
|
Tt as cancelSingleClickEvents,
|
|
883
896
|
V as cloneKeyboardEvent,
|
|
884
897
|
q as clonePointerEvent,
|
|
885
898
|
Ne as createBody,
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
899
|
+
zt as createCanvasRenderer,
|
|
900
|
+
Gt as createHighlightsRenderer,
|
|
901
|
+
ce as createPresencePainter,
|
|
902
|
+
jt as createRenderer,
|
|
903
|
+
te as createSpansRenderer,
|
|
891
904
|
ve as createTextAnnotator,
|
|
892
|
-
|
|
905
|
+
ie as createTextAnnotatorState,
|
|
893
906
|
D as debounce,
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
907
|
+
fe as fillDefaults,
|
|
908
|
+
Ot as getHighlightClientRects,
|
|
909
|
+
It as getQuoteContext,
|
|
897
910
|
Q as getRangeAnnotatableContents,
|
|
898
911
|
Lt as isMac,
|
|
899
|
-
|
|
912
|
+
Ee as isNodeWhitespaceOrEmpty,
|
|
900
913
|
Y as isNotAnnotatable,
|
|
901
914
|
xt as isRangeAnnotatable,
|
|
902
|
-
|
|
915
|
+
Ht as isRangeWhitespaceOrEmpty,
|
|
903
916
|
H as isRevived,
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
917
|
+
Ut as mergeClientRects,
|
|
918
|
+
Kt as paint,
|
|
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
|
-
|
|
913
|
-
|
|
914
|
-
|
|
925
|
+
Dt as scrollIntoView,
|
|
926
|
+
se as serializeW3CTextAnnotation,
|
|
927
|
+
Bt as splitAnnotatableRanges,
|
|
915
928
|
we as toDomRectList,
|
|
916
|
-
|
|
929
|
+
Ft as trimRangeToContainer,
|
|
917
930
|
st as whitespaceOrEmptyRegex
|
|
918
931
|
};
|
|
919
932
|
//# sourceMappingURL=text-annotator.es.js.map
|