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