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