@soomo/text-annotator 3.4.0-staging.0 → 3.4.0-staging.2
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,19 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import z from "debounce";
|
|
2
2
|
import { colord as ot } from "colord";
|
|
3
3
|
import { dequal as ut } from "dequal/lite";
|
|
4
4
|
import { v4 as st } from "uuid";
|
|
5
|
-
import { serializeW3CBodies as ft, parseW3CBodies as gt, parseW3CUser as mt, createStore as pt, createSelectionState as ht, createHoverState as yt, createViewportState as bt, Origin as
|
|
6
|
-
import { Origin as
|
|
7
|
-
import
|
|
8
|
-
import { createNanoEvents as
|
|
9
|
-
import
|
|
5
|
+
import { serializeW3CBodies as ft, parseW3CBodies as gt, parseW3CUser as mt, createStore as pt, createSelectionState as ht, createHoverState as yt, createViewportState as bt, Origin as U, createAnonymousGuest as St, createUndoStack as Ct, createLifecycleObserver as Et, createBaseAnnotator as wt } from "@annotorious/core";
|
|
6
|
+
import { Origin as ke, UserSelectAction as Ne, createBody as Be } from "@annotorious/core";
|
|
7
|
+
import vt from "rbush";
|
|
8
|
+
import { createNanoEvents as At } from "nanoevents";
|
|
9
|
+
import V from "hotkeys-js";
|
|
10
10
|
import { poll as xt } from "poll";
|
|
11
|
-
const rt = "not-annotatable", _ = `.${rt}`,
|
|
11
|
+
const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
|
|
12
12
|
var o;
|
|
13
13
|
return t.contains(n) ? !!(n instanceof HTMLElement ? n.closest(_) : (o = n.parentElement) == null ? void 0 : o.closest(_)) : !0;
|
|
14
14
|
}, Rt = (t, n) => {
|
|
15
15
|
const e = n.commonAncestorContainer;
|
|
16
|
-
return !
|
|
16
|
+
return !X(t, e);
|
|
17
17
|
}, Tt = (t) => t.addEventListener("click", (n) => {
|
|
18
18
|
// Allow clicks within not-annotatable elements
|
|
19
19
|
!n.target.closest(_) && !n.target.closest("a") && n.preventDefault();
|
|
@@ -98,12 +98,12 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
98
98
|
s = !0;
|
|
99
99
|
break;
|
|
100
100
|
} else if (i === "block-contains" || i === "block-is-contained") {
|
|
101
|
-
e.width < r.width && (o = o.map((a) => a === r ? e : a)), s = !0;
|
|
101
|
+
e.width < r.width && (o = o.map((a) => a === r ? e : a)), e.width === r.width && e.height < r.width && (o = o.map((a) => a === r ? e : a)), s = !0;
|
|
102
102
|
break;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
return s ? o : [...o, e];
|
|
106
|
-
}, []),
|
|
106
|
+
}, []), ve = (t) => ({
|
|
107
107
|
length: t.length,
|
|
108
108
|
item: (n) => t[n],
|
|
109
109
|
[Symbol.iterator]: function* () {
|
|
@@ -116,7 +116,7 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
116
116
|
const r = Z(o).textContent, i = t.toString(), a = r.length || 0, u = a + i.length;
|
|
117
117
|
return e ? { quote: i, start: a, end: u, range: t, offsetReference: s } : { quote: i, start: a, end: u, range: t };
|
|
118
118
|
}, it = (t, n) => {
|
|
119
|
-
var
|
|
119
|
+
var y, f;
|
|
120
120
|
const { start: e, end: o } = t, s = t.offsetReference || n, r = document.createNodeIterator(
|
|
121
121
|
n,
|
|
122
122
|
NodeFilter.SHOW_TEXT,
|
|
@@ -132,7 +132,7 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
132
132
|
let S = !s;
|
|
133
133
|
for (; u !== null; ) {
|
|
134
134
|
if (S || (S = typeof (s == null ? void 0 : s.contains) == "function" ? s.contains(u) : !1), S) {
|
|
135
|
-
const p = ((
|
|
135
|
+
const p = ((y = u.textContent) == null ? void 0 : y.length) || 0;
|
|
136
136
|
if (i + p > e) {
|
|
137
137
|
a.setStart(u, e - i);
|
|
138
138
|
break;
|
|
@@ -153,10 +153,10 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
153
153
|
...t,
|
|
154
154
|
range: a
|
|
155
155
|
};
|
|
156
|
-
},
|
|
156
|
+
}, q = (t, n) => M(t.selector) ? t : {
|
|
157
157
|
...t,
|
|
158
158
|
selector: t.selector.map((e) => e.range instanceof Range && !e.range.collapsed ? e : it(e, n))
|
|
159
|
-
}, G = (t, n) => M(t.target.selector) ? t : { ...t, target:
|
|
159
|
+
}, G = (t, n) => M(t.target.selector) ? t : { ...t, target: q(t.target, n) }, at = (t, n) => {
|
|
160
160
|
if (t.isEqualNode(n))
|
|
161
161
|
return !0;
|
|
162
162
|
for (let e of t.childNodes)
|
|
@@ -166,7 +166,7 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
166
166
|
}, $t = (t, n) => {
|
|
167
167
|
const e = t.cloneContents();
|
|
168
168
|
return at(e, n);
|
|
169
|
-
},
|
|
169
|
+
}, Ut = (t, n) => {
|
|
170
170
|
const e = t.cloneRange(), o = n.contains(e.startContainer), s = n.contains(e.endContainer);
|
|
171
171
|
return !o && !s && !$t(e, n) ? (e.collapse(), e) : (o || e.setStart(n, 0), s || e.setEnd(n, n.childNodes.length), e);
|
|
172
172
|
}, Q = (t) => ({
|
|
@@ -195,7 +195,7 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
195
195
|
pointerId: t.pointerId,
|
|
196
196
|
pointerType: t.pointerType,
|
|
197
197
|
timeStamp: t.timeStamp
|
|
198
|
-
}),
|
|
198
|
+
}), Y = (t) => ({
|
|
199
199
|
...t,
|
|
200
200
|
type: t.type,
|
|
201
201
|
key: t.key,
|
|
@@ -211,7 +211,7 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
211
211
|
defaultPrevented: t.defaultPrevented,
|
|
212
212
|
detail: t.detail,
|
|
213
213
|
timeStamp: t.timeStamp
|
|
214
|
-
}),
|
|
214
|
+
}), _t = (t, n) => {
|
|
215
215
|
const { left: e, top: o, right: s, bottom: r } = t;
|
|
216
216
|
return new DOMRect(e - n.left, o - n.top, s - e, r - o);
|
|
217
217
|
}, Ae = (t, n) => {
|
|
@@ -223,9 +223,9 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
223
223
|
const { overflowY: n } = window.getComputedStyle(t);
|
|
224
224
|
return n !== "visible" && n !== "hidden" && t.scrollHeight > t.clientHeight ? t : ct(t.parentElement);
|
|
225
225
|
}, tt = (t, n, e) => {
|
|
226
|
-
const o = e.getBoundingClientRect(), s = e.clientHeight, r = e.clientWidth, i = n.selector[0].range.getBoundingClientRect(), { width: a, height: u } = t.getAnnotationBounds(n.annotation), S = i.top - o.top,
|
|
227
|
-
e.scroll({ top: c, left:
|
|
228
|
-
},
|
|
226
|
+
const o = e.getBoundingClientRect(), s = e.clientHeight, r = e.clientWidth, i = n.selector[0].range.getBoundingClientRect(), { width: a, height: u } = t.getAnnotationBounds(n.annotation), S = i.top - o.top, y = i.left - o.left, f = e.parentElement ? e.scrollTop : 0, p = e.parentElement ? e.scrollLeft : 0, c = S + f - (s - u) / 2, R = y + p - (r - a) / 2;
|
|
227
|
+
e.scroll({ top: c, left: R, behavior: "smooth" });
|
|
228
|
+
}, Ft = (t, n) => (e, o) => {
|
|
229
229
|
const s = typeof e == "string" ? e : e.id, r = o ? typeof o == "string" ? document.getElementById(o) : o : ct(t);
|
|
230
230
|
if (!r)
|
|
231
231
|
return console.warn(`The scroll parent is missing for the annotation: ${s}`, { container: t }), !1;
|
|
@@ -235,17 +235,17 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
235
235
|
const { range: a } = i.target.selector[0];
|
|
236
236
|
if (a && !a.collapsed)
|
|
237
237
|
return tt(n, i.target, r), !0;
|
|
238
|
-
const u =
|
|
238
|
+
const u = q(i.target, t), { range: S } = u.selector[0];
|
|
239
239
|
return S && !S.collapsed ? (tt(n, u, r), !0) : !1;
|
|
240
|
-
},
|
|
240
|
+
}, H = {
|
|
241
241
|
fill: "rgb(0, 128, 255)",
|
|
242
242
|
fillOpacity: 0.18
|
|
243
|
-
},
|
|
243
|
+
}, j = {
|
|
244
244
|
fill: "rgb(0, 128, 255)",
|
|
245
245
|
fillOpacity: 0.45
|
|
246
246
|
}, Wt = (t, n, e, o, s) => {
|
|
247
247
|
var i, a;
|
|
248
|
-
const r = e ? typeof e == "function" ? e(t.annotation, t.state, s) || ((i = t.state) != null && i.selected ?
|
|
248
|
+
const r = e ? typeof e == "function" ? e(t.annotation, t.state, s) || ((i = t.state) != null && i.selected ? j : H) : e : (a = t.state) != null && a.selected ? j : H;
|
|
249
249
|
return o && o.paint(t, n) || r;
|
|
250
250
|
}, Vt = (t) => {
|
|
251
251
|
const { top: n, left: e } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: s } = window, r = -e, i = -n, a = o - e, u = s - n;
|
|
@@ -259,48 +259,48 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
259
259
|
}, J = (t, n, e, o) => {
|
|
260
260
|
const { store: s, selection: r, hover: i } = n;
|
|
261
261
|
let a, u, S;
|
|
262
|
-
const
|
|
263
|
-
const { x:
|
|
264
|
-
|
|
262
|
+
const y = Yt(e), f = (C) => {
|
|
263
|
+
const { x: L, y: B } = t.getBoundingClientRect(), P = s.getAt(C.clientX - L, C.clientY - B, !1, u);
|
|
264
|
+
P ? i.current !== P.id && (t.classList.add("hovered"), i.set(P.id)) : i.current && (t.classList.remove("hovered"), i.set(null));
|
|
265
265
|
};
|
|
266
266
|
t.addEventListener("pointermove", f);
|
|
267
267
|
const p = (C = !1) => {
|
|
268
268
|
S && S.clear();
|
|
269
|
-
const
|
|
270
|
-
const N =
|
|
269
|
+
const L = Vt(t), { minX: B, minY: P, maxX: b, maxY: x } = L, O = u ? s.getIntersecting(B, P, b, x).filter(({ annotation: k }) => u(k)) : s.getIntersecting(B, P, b, x), F = r.selected.map(({ id: k }) => k), I = O.map(({ annotation: k, rects: D }) => {
|
|
270
|
+
const N = F.includes(k.id), K = k.id === i.current;
|
|
271
271
|
return {
|
|
272
|
-
annotation:
|
|
273
|
-
rects:
|
|
272
|
+
annotation: k,
|
|
273
|
+
rects: D,
|
|
274
274
|
state: { selected: N, hovered: K }
|
|
275
275
|
};
|
|
276
276
|
});
|
|
277
|
-
o.redraw(
|
|
277
|
+
o.redraw(I, L, a, S, C), setTimeout(() => y(O.map(({ annotation: k }) => k)), 1);
|
|
278
278
|
}, c = (C) => {
|
|
279
279
|
S = C, p();
|
|
280
|
-
},
|
|
280
|
+
}, R = (C) => {
|
|
281
281
|
a = C, p();
|
|
282
|
-
},
|
|
282
|
+
}, v = (C) => {
|
|
283
283
|
u = C, p(!1);
|
|
284
|
-
},
|
|
285
|
-
s.observe(
|
|
284
|
+
}, T = () => p();
|
|
285
|
+
s.observe(T);
|
|
286
286
|
const E = r.subscribe(() => p()), m = i.subscribe(() => p()), l = () => p(!0);
|
|
287
287
|
document.addEventListener("scroll", l, { capture: !0, passive: !0 });
|
|
288
|
-
const g =
|
|
288
|
+
const g = z(() => {
|
|
289
289
|
s.recalculatePositions(), S == null || S.reset(), p();
|
|
290
290
|
}, 10);
|
|
291
291
|
window.addEventListener("resize", g);
|
|
292
292
|
const d = new ResizeObserver(g);
|
|
293
293
|
d.observe(t);
|
|
294
|
-
const
|
|
294
|
+
const h = { attributes: !0, childList: !0, subtree: !0 }, w = new MutationObserver(z((C) => {
|
|
295
295
|
C.every((B) => B.target === t || t.contains(B.target)) || p(!0);
|
|
296
296
|
}, 150));
|
|
297
|
-
return w.observe(document.body,
|
|
297
|
+
return w.observe(document.body, h), {
|
|
298
298
|
destroy: () => {
|
|
299
|
-
t.removeEventListener("pointermove", f), o.destroy(), s.unobserve(
|
|
299
|
+
t.removeEventListener("pointermove", f), o.destroy(), s.unobserve(T), E(), m(), document.removeEventListener("scroll", l), g.clear(), window.removeEventListener("resize", g), d.disconnect(), w.disconnect();
|
|
300
300
|
},
|
|
301
301
|
redraw: p,
|
|
302
|
-
setStyle:
|
|
303
|
-
setFilter:
|
|
302
|
+
setStyle: R,
|
|
303
|
+
setFilter: v,
|
|
304
304
|
setPainter: c,
|
|
305
305
|
setVisible: o.setVisible
|
|
306
306
|
};
|
|
@@ -313,32 +313,32 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
313
313
|
t.classList.add("r6o-annotatable");
|
|
314
314
|
const n = Xt(), e = n.getContext("2d");
|
|
315
315
|
document.body.appendChild(n);
|
|
316
|
-
const o = (a, u, S,
|
|
316
|
+
const o = (a, u, S, y) => requestAnimationFrame(() => {
|
|
317
317
|
const { width: f, height: p } = n;
|
|
318
|
-
e.clearRect(-0.5, -0.5, f + 1, p + 1),
|
|
319
|
-
const { top: c, left:
|
|
320
|
-
[...a].sort((
|
|
321
|
-
const { annotation: { target: { created: m } } } =
|
|
318
|
+
e.clearRect(-0.5, -0.5, f + 1, p + 1), y && y.clear();
|
|
319
|
+
const { top: c, left: R } = u;
|
|
320
|
+
[...a].sort((T, E) => {
|
|
321
|
+
const { annotation: { target: { created: m } } } = T, { annotation: { target: { created: l } } } = E;
|
|
322
322
|
return m.getTime() - l.getTime();
|
|
323
|
-
}).forEach((
|
|
323
|
+
}).forEach((T) => {
|
|
324
324
|
var g;
|
|
325
|
-
const E = S ? typeof S == "function" ? S(
|
|
326
|
-
x: d +
|
|
327
|
-
y:
|
|
325
|
+
const E = S ? typeof S == "function" ? S(T.annotation, T.state) : S : (g = T.state) != null && g.selected ? j : H, m = y && y.paint(T, u) || E, l = T.rects.map(({ x: d, y: h, width: w, height: A }) => ({
|
|
326
|
+
x: d + R,
|
|
327
|
+
y: h + c,
|
|
328
328
|
width: w,
|
|
329
|
-
height:
|
|
329
|
+
height: A
|
|
330
330
|
}));
|
|
331
331
|
if (e.fillStyle = m.fill, e.globalAlpha = m.fillOpacity || 1, l.forEach(
|
|
332
|
-
({ x: d, y, width: w, height:
|
|
332
|
+
({ x: d, y: h, width: w, height: A }) => e.fillRect(d, h, w, A)
|
|
333
333
|
), m.underlineColor) {
|
|
334
334
|
e.globalAlpha = 1, e.strokeStyle = m.underlineColor, e.lineWidth = m.underlineThickness ?? 1;
|
|
335
335
|
const d = m.underlineOffset ?? 0;
|
|
336
|
-
l.forEach(({ x:
|
|
337
|
-
e.beginPath(), e.moveTo(
|
|
336
|
+
l.forEach(({ x: h, y: w, width: A, height: C }) => {
|
|
337
|
+
e.beginPath(), e.moveTo(h, w + C + d), e.lineTo(h + A, w + C + d), e.stroke();
|
|
338
338
|
});
|
|
339
339
|
}
|
|
340
340
|
});
|
|
341
|
-
}), s =
|
|
341
|
+
}), s = z(() => zt(n), 10);
|
|
342
342
|
return window.addEventListener("resize", s), {
|
|
343
343
|
destroy: () => {
|
|
344
344
|
n.remove(), s.clear(), window.removeEventListener("resize", s);
|
|
@@ -349,7 +349,7 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
349
349
|
redraw: o
|
|
350
350
|
};
|
|
351
351
|
}, jt = (t, n, e) => J(t, n, e, qt(t)), Gt = (t) => [
|
|
352
|
-
`background-color:${ot((t == null ? void 0 : t.fill) ||
|
|
352
|
+
`background-color:${ot((t == null ? void 0 : t.fill) || H.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? H.fillOpacity : t.fillOpacity).toHex()}`,
|
|
353
353
|
t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
|
|
354
354
|
t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
355
355
|
t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
@@ -369,14 +369,14 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
369
369
|
u && u.clear();
|
|
370
370
|
const S = new Set(r.map((f) => f.annotation.id));
|
|
371
371
|
Array.from(n).filter((f) => !S.has(f));
|
|
372
|
-
const
|
|
373
|
-
var
|
|
374
|
-
const p = a ? typeof a == "function" ? a(f.annotation, f.state) : a : (
|
|
372
|
+
const y = r.map((f) => {
|
|
373
|
+
var R;
|
|
374
|
+
const p = a ? typeof a == "function" ? a(f.annotation, f.state) : a : (R = f.state) != null && R.selected ? j : H, c = u && u.paint(f, i) || p;
|
|
375
375
|
return `::highlight(_${f.annotation.id}) { ${Gt(c)} }`;
|
|
376
376
|
});
|
|
377
|
-
t.innerHTML =
|
|
377
|
+
t.innerHTML = y.join(`
|
|
378
378
|
`), CSS.highlights.clear(), r.forEach(({ annotation: f }) => {
|
|
379
|
-
const p = f.target.selector.map((
|
|
379
|
+
const p = f.target.selector.map((R) => R.range), c = new Highlight(...p);
|
|
380
380
|
CSS.highlights.set(`_${f.id}`, c);
|
|
381
381
|
}), n = S;
|
|
382
382
|
}
|
|
@@ -393,18 +393,18 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
393
393
|
destroy: () => {
|
|
394
394
|
n.remove();
|
|
395
395
|
},
|
|
396
|
-
redraw: (i, a, u, S,
|
|
397
|
-
const p = !(ut(e, i) &&
|
|
396
|
+
redraw: (i, a, u, S, y) => {
|
|
397
|
+
const p = !(ut(e, i) && y);
|
|
398
398
|
if (!S && !p) return;
|
|
399
|
-
p && (n.innerHTML = ""), [...i].sort((
|
|
400
|
-
const { annotation: { target: { created:
|
|
401
|
-
return
|
|
402
|
-
}).forEach((
|
|
403
|
-
|
|
404
|
-
const
|
|
399
|
+
p && (n.innerHTML = ""), [...i].sort((R, v) => {
|
|
400
|
+
const { annotation: { target: { created: T } } } = R, { annotation: { target: { created: E } } } = v;
|
|
401
|
+
return T && E ? T.getTime() - E.getTime() : 0;
|
|
402
|
+
}).forEach((R) => {
|
|
403
|
+
R.rects.map((v) => {
|
|
404
|
+
const T = Jt(v, i), E = Wt(R, a, u, S, T);
|
|
405
405
|
if (p) {
|
|
406
406
|
const m = document.createElement("span");
|
|
407
|
-
m.className = "r6o-annotation", m.dataset.annotation =
|
|
407
|
+
m.className = "r6o-annotation", m.dataset.annotation = R.annotation.id, m.style.left = `${v.x}px`, m.style.top = `${v.y}px`, m.style.width = `${v.width}px`, m.style.height = `${v.height}px`, m.style.backgroundColor = ot((E == null ? void 0 : E.fill) || H.fill).alpha((E == null ? void 0 : E.fillOpacity) === void 0 ? H.fillOpacity : E.fillOpacity).toHex(), E.underlineStyle && (m.style.borderStyle = E.underlineStyle), E.underlineColor && (m.style.borderColor = E.underlineColor), E.underlineThickness && (m.style.borderBottomWidth = `${E.underlineThickness}px`), E.underlineOffset && (m.style.paddingBottom = `${E.underlineOffset}px`), n.appendChild(m);
|
|
408
408
|
}
|
|
409
409
|
});
|
|
410
410
|
}), e = i;
|
|
@@ -413,7 +413,7 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
413
413
|
i ? n.classList.remove("hidden") : n.classList.add("hidden");
|
|
414
414
|
}
|
|
415
415
|
};
|
|
416
|
-
}, ee = (t, n, e) => J(t, n, e, te(t)),
|
|
416
|
+
}, ee = (t, n, e) => J(t, n, e, te(t)), xe = (t, n) => ({
|
|
417
417
|
parse: (e) => se(e),
|
|
418
418
|
serialize: (e) => re(e, t, n)
|
|
419
419
|
}), ne = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, oe = (t) => {
|
|
@@ -436,7 +436,7 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
436
436
|
styleClass: "styleClass" in i[0] ? i[0].styleClass : void 0
|
|
437
437
|
};
|
|
438
438
|
for (const u of i) {
|
|
439
|
-
const
|
|
439
|
+
const y = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((f, p) => {
|
|
440
440
|
switch (p.type) {
|
|
441
441
|
case "TextQuoteSelector":
|
|
442
442
|
f.quote = p.exact;
|
|
@@ -447,10 +447,10 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
447
447
|
}
|
|
448
448
|
return f;
|
|
449
449
|
}, {});
|
|
450
|
-
if (a.outdated || (a.outdated = "outdated" in u ? u.outdated : void 0), ne(
|
|
450
|
+
if (a.outdated || (a.outdated = "outdated" in u ? u.outdated : void 0), ne(y))
|
|
451
451
|
a.selector.push(
|
|
452
452
|
{
|
|
453
|
-
...
|
|
453
|
+
...y,
|
|
454
454
|
id: u.id,
|
|
455
455
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
456
456
|
scope: u.scope
|
|
@@ -458,8 +458,8 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
458
458
|
);
|
|
459
459
|
else {
|
|
460
460
|
const f = [
|
|
461
|
-
|
|
462
|
-
|
|
461
|
+
y.start ? void 0 : "TextPositionSelector",
|
|
462
|
+
y.quote ? void 0 : "TextQuoteSelector"
|
|
463
463
|
].filter(Boolean);
|
|
464
464
|
return { error: Error(`Missing selector types: ${f.join(" and ")} for annotation: ${t.id}`) };
|
|
465
465
|
}
|
|
@@ -487,11 +487,11 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
487
487
|
creator: a,
|
|
488
488
|
created: u,
|
|
489
489
|
updated: S,
|
|
490
|
-
...
|
|
490
|
+
...y
|
|
491
491
|
} = s, f = i.map((p) => {
|
|
492
|
-
const { id: c, quote:
|
|
492
|
+
const { id: c, quote: R, start: v, end: T, range: E } = p, m = {
|
|
493
493
|
type: "TextQuoteSelector",
|
|
494
|
-
exact:
|
|
494
|
+
exact: R
|
|
495
495
|
};
|
|
496
496
|
if (e) {
|
|
497
497
|
const { prefix: g, suffix: d } = Ot(E, e);
|
|
@@ -499,11 +499,11 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
499
499
|
}
|
|
500
500
|
const l = {
|
|
501
501
|
type: "TextPositionSelector",
|
|
502
|
-
start:
|
|
503
|
-
end:
|
|
502
|
+
start: v,
|
|
503
|
+
end: T
|
|
504
504
|
};
|
|
505
505
|
return {
|
|
506
|
-
...
|
|
506
|
+
...y,
|
|
507
507
|
id: c,
|
|
508
508
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
509
509
|
scope: "scope" in p ? p.scope : void 0,
|
|
@@ -523,21 +523,21 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
523
523
|
target: f
|
|
524
524
|
};
|
|
525
525
|
}, ie = (t, n) => {
|
|
526
|
-
const e = new
|
|
526
|
+
const e = new vt(), o = /* @__PURE__ */ new Map(), s = At(), r = (l, g) => {
|
|
527
527
|
const d = l.selector.flatMap((w) => {
|
|
528
|
-
const
|
|
529
|
-
return Array.from(
|
|
530
|
-
}),
|
|
531
|
-
return
|
|
532
|
-
const { x:
|
|
528
|
+
const A = M([w]) ? w.range : it(w, n).range;
|
|
529
|
+
return Array.from(A.getClientRects());
|
|
530
|
+
}), h = Dt(d).map((w) => _t(w, g));
|
|
531
|
+
return h.map((w) => {
|
|
532
|
+
const { x: A, y: C, width: L, height: B } = w;
|
|
533
533
|
return {
|
|
534
|
-
minX:
|
|
534
|
+
minX: A,
|
|
535
535
|
minY: C,
|
|
536
|
-
maxX:
|
|
536
|
+
maxX: A + L,
|
|
537
537
|
maxY: C + B,
|
|
538
538
|
annotation: {
|
|
539
539
|
id: l.annotation,
|
|
540
|
-
rects:
|
|
540
|
+
rects: h
|
|
541
541
|
}
|
|
542
542
|
};
|
|
543
543
|
});
|
|
@@ -549,35 +549,35 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
549
549
|
}, S = (l) => {
|
|
550
550
|
const g = o.get(l.annotation);
|
|
551
551
|
g && (g.forEach((d) => e.remove(d)), o.delete(l.annotation));
|
|
552
|
-
},
|
|
552
|
+
}, y = (l) => {
|
|
553
553
|
S(l), u(l);
|
|
554
554
|
}, f = (l, g = !0) => {
|
|
555
555
|
g && a();
|
|
556
|
-
const d = n.getBoundingClientRect(),
|
|
557
|
-
|
|
558
|
-
C.length > 0 && o.set(
|
|
556
|
+
const d = n.getBoundingClientRect(), h = l.map((A) => ({ target: A, rects: r(A, d) }));
|
|
557
|
+
h.forEach(({ target: A, rects: C }) => {
|
|
558
|
+
C.length > 0 && o.set(A.annotation, C);
|
|
559
559
|
});
|
|
560
|
-
const w =
|
|
560
|
+
const w = h.flatMap(({ rects: A }) => A);
|
|
561
561
|
e.load(w);
|
|
562
562
|
}, p = (l, g, d = !1) => {
|
|
563
|
-
const
|
|
563
|
+
const h = e.search({
|
|
564
564
|
minX: l,
|
|
565
565
|
minY: g,
|
|
566
566
|
maxX: l,
|
|
567
567
|
maxY: g
|
|
568
|
-
}), w = (
|
|
569
|
-
return
|
|
568
|
+
}), w = (A) => A.annotation.rects.reduce((C, L) => C + L.width * L.height, 0);
|
|
569
|
+
return h.length > 0 ? (h.sort((A, C) => w(A) - w(C)), d ? h.map((A) => A.annotation.id) : [h[0].annotation.id]) : [];
|
|
570
570
|
}, c = (l) => {
|
|
571
|
-
const g =
|
|
571
|
+
const g = R(l);
|
|
572
572
|
if (g.length === 0)
|
|
573
573
|
return;
|
|
574
|
-
let d = g[0].left,
|
|
574
|
+
let d = g[0].left, h = g[0].top, w = g[0].right, A = g[0].bottom;
|
|
575
575
|
for (let C = 1; C < g.length; C++) {
|
|
576
|
-
const
|
|
577
|
-
d = Math.min(d,
|
|
576
|
+
const L = g[C];
|
|
577
|
+
d = Math.min(d, L.left), h = Math.min(h, L.top), w = Math.max(w, L.right), A = Math.max(A, L.bottom);
|
|
578
578
|
}
|
|
579
|
-
return new DOMRect(d,
|
|
580
|
-
},
|
|
579
|
+
return new DOMRect(d, h, w - d, A - h);
|
|
580
|
+
}, R = (l) => {
|
|
581
581
|
const g = o.get(l);
|
|
582
582
|
return g ? g[0].annotation.rects : [];
|
|
583
583
|
};
|
|
@@ -586,12 +586,12 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
586
586
|
clear: a,
|
|
587
587
|
getAt: p,
|
|
588
588
|
getAnnotationBounds: c,
|
|
589
|
-
getAnnotationRects:
|
|
590
|
-
getIntersecting: (l, g, d,
|
|
591
|
-
const w = e.search({ minX: l, minY: g, maxX: d, maxY:
|
|
592
|
-
return Array.from(
|
|
589
|
+
getAnnotationRects: R,
|
|
590
|
+
getIntersecting: (l, g, d, h) => {
|
|
591
|
+
const w = e.search({ minX: l, minY: g, maxX: d, maxY: h }), A = new Set(w.map((C) => C.annotation.id));
|
|
592
|
+
return Array.from(A).map((C) => ({
|
|
593
593
|
annotation: t.getAnnotation(C),
|
|
594
|
-
rects:
|
|
594
|
+
rects: R(C)
|
|
595
595
|
})).filter((C) => !!C.annotation);
|
|
596
596
|
},
|
|
597
597
|
insert: u,
|
|
@@ -601,37 +601,37 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
601
601
|
remove: S,
|
|
602
602
|
set: f,
|
|
603
603
|
size: () => e.all().length,
|
|
604
|
-
update:
|
|
604
|
+
update: y,
|
|
605
605
|
on: (l, g) => s.on(l, g)
|
|
606
606
|
};
|
|
607
607
|
}, ae = (t, n) => {
|
|
608
|
-
const e = pt(), o = ie(e, t), s = ht(e, n.userSelectAction, n.adapter), r = yt(e), i = bt(), a = (m, l =
|
|
608
|
+
const e = pt(), o = ie(e, t), s = ht(e, n.userSelectAction, n.adapter), r = yt(e), i = bt(), a = (m, l = U.LOCAL) => {
|
|
609
609
|
const g = G(m, t), d = M(g.target.selector);
|
|
610
610
|
return d && e.addAnnotation(g, l), d;
|
|
611
|
-
}, u = (m, l = !0, g =
|
|
612
|
-
const d = m.map((w) => G(w, t)),
|
|
613
|
-
return e.bulkAddAnnotations(d, l, g),
|
|
614
|
-
}, S = (m, l =
|
|
615
|
-
const g = m.map((
|
|
616
|
-
return g.forEach((
|
|
617
|
-
e.getAnnotation(
|
|
611
|
+
}, u = (m, l = !0, g = U.LOCAL) => {
|
|
612
|
+
const d = m.map((w) => G(w, t)), h = d.filter((w) => !M(w.target.selector));
|
|
613
|
+
return e.bulkAddAnnotations(d, l, g), h;
|
|
614
|
+
}, S = (m, l = U.LOCAL) => {
|
|
615
|
+
const g = m.map((h) => G(h, t)), d = g.filter((h) => !M(h.target.selector));
|
|
616
|
+
return g.forEach((h) => {
|
|
617
|
+
e.getAnnotation(h.id) ? e.updateAnnotation(h, l) : e.addAnnotation(h, l);
|
|
618
618
|
}), d;
|
|
619
|
-
},
|
|
620
|
-
const g =
|
|
619
|
+
}, y = (m, l = U.LOCAL) => {
|
|
620
|
+
const g = q(m, t);
|
|
621
621
|
e.updateTarget(g, l);
|
|
622
|
-
}, f = (m, l =
|
|
623
|
-
const g = m.map((d) =>
|
|
622
|
+
}, f = (m, l = U.LOCAL) => {
|
|
623
|
+
const g = m.map((d) => q(d, t));
|
|
624
624
|
e.bulkUpdateTargets(g, l);
|
|
625
625
|
};
|
|
626
626
|
function p(m, l, g, d) {
|
|
627
|
-
const
|
|
628
|
-
if (
|
|
629
|
-
return g ?
|
|
627
|
+
const h = g || !!d, w = o.getAt(m, l, h).map((C) => e.getAnnotation(C)), A = d ? w.filter(d) : w;
|
|
628
|
+
if (A.length !== 0)
|
|
629
|
+
return g ? A : A[0];
|
|
630
630
|
}
|
|
631
|
-
const c = (m) => o.getAnnotationRects(m).length > 0 ? o.getAnnotationBounds(m) : void 0,
|
|
631
|
+
const c = (m) => o.getAnnotationRects(m).length > 0 ? o.getAnnotationBounds(m) : void 0, R = (m, l, g, d) => o.getIntersecting(m, l, g, d), v = (m) => o.getAnnotationRects(m), T = () => o.recalculate(), E = (m) => o.on("recalculate", m);
|
|
632
632
|
return e.observe(({ changes: m }) => {
|
|
633
|
-
const l = (m.deleted || []).filter((
|
|
634
|
-
(l == null ? void 0 : l.length) > 0 && l.forEach((
|
|
633
|
+
const l = (m.deleted || []).filter((h) => M(h.target.selector)), g = (m.created || []).filter((h) => M(h.target.selector)), d = (m.updated || []).filter((h) => M(h.newValue.target.selector));
|
|
634
|
+
(l == null ? void 0 : l.length) > 0 && l.forEach((h) => o.remove(h.target)), g.length > 0 && o.set(g.map((h) => h.target), !1), (d == null ? void 0 : d.length) > 0 && d.forEach(({ newValue: h }) => o.update(h.target));
|
|
635
635
|
}), {
|
|
636
636
|
store: {
|
|
637
637
|
...e,
|
|
@@ -640,12 +640,12 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
640
640
|
bulkUpdateTargets: f,
|
|
641
641
|
bulkUpsertAnnotations: S,
|
|
642
642
|
getAnnotationBounds: c,
|
|
643
|
-
getAnnotationRects:
|
|
644
|
-
getIntersecting:
|
|
643
|
+
getAnnotationRects: v,
|
|
644
|
+
getIntersecting: R,
|
|
645
645
|
getAt: p,
|
|
646
|
-
recalculatePositions:
|
|
646
|
+
recalculatePositions: T,
|
|
647
647
|
onRecalculatePositions: E,
|
|
648
|
-
updateTarget:
|
|
648
|
+
updateTarget: y
|
|
649
649
|
},
|
|
650
650
|
selection: s,
|
|
651
651
|
hover: r,
|
|
@@ -659,25 +659,25 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
659
659
|
}, le = (t, n = {}) => {
|
|
660
660
|
const e = ce(), o = e.getContext("2d");
|
|
661
661
|
document.body.appendChild(e);
|
|
662
|
-
const s = /* @__PURE__ */ new Map(), r = (
|
|
663
|
-
return t.on("selectionChange", (
|
|
664
|
-
r(
|
|
662
|
+
const s = /* @__PURE__ */ new Map(), r = (y) => Array.from(s.entries()).filter(([f, p]) => p.presenceKey === y.presenceKey).map(([f, p]) => f);
|
|
663
|
+
return t.on("selectionChange", (y, f) => {
|
|
664
|
+
r(y).forEach((c) => s.delete(c)), f && f.forEach((c) => s.set(c, y));
|
|
665
665
|
}), {
|
|
666
666
|
clear: () => {
|
|
667
|
-
const { width:
|
|
668
|
-
o.clearRect(-0.5, -0.5,
|
|
667
|
+
const { width: y, height: f } = e;
|
|
668
|
+
o.clearRect(-0.5, -0.5, y + 1, f + 1);
|
|
669
669
|
},
|
|
670
670
|
destroy: () => {
|
|
671
671
|
e.remove();
|
|
672
672
|
},
|
|
673
|
-
paint: (
|
|
673
|
+
paint: (y, f, p) => {
|
|
674
674
|
n.font && (o.font = n.font);
|
|
675
|
-
const c = s.get(
|
|
675
|
+
const c = s.get(y.annotation.id);
|
|
676
676
|
if (c) {
|
|
677
|
-
const { height:
|
|
678
|
-
o.fillStyle = c.appearance.color, o.fillRect(
|
|
677
|
+
const { height: R } = y.rects[0], v = y.rects[0].x + f.left, T = y.rects[0].y + f.top;
|
|
678
|
+
o.fillStyle = c.appearance.color, o.fillRect(v - 2, T - 2.5, 2, R + 5);
|
|
679
679
|
const E = o.measureText(c.appearance.label), m = E.width + 6, l = E.actualBoundingBoxAscent + E.actualBoundingBoxDescent + 8, g = E.fontBoundingBoxAscent ? 8 : 6.5;
|
|
680
|
-
return o.fillRect(
|
|
680
|
+
return o.fillRect(v - 2, T - 2.5 - l, m, l), o.fillStyle = "#fff", o.fillText(c.appearance.label, v + 1, T - g), {
|
|
681
681
|
fill: c.appearance.color,
|
|
682
682
|
fillOpacity: p ? 0.45 : 0.18
|
|
683
683
|
};
|
|
@@ -685,8 +685,8 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
685
685
|
},
|
|
686
686
|
reset: () => {
|
|
687
687
|
e.width = 2 * window.innerWidth, e.height = 2 * window.innerHeight;
|
|
688
|
-
const
|
|
689
|
-
|
|
688
|
+
const y = e.getContext("2d");
|
|
689
|
+
y.scale(2, 2), y.translate(0.5, 0.5);
|
|
690
690
|
}
|
|
691
691
|
};
|
|
692
692
|
}, et = 300, lt = ["up", "down", "left", "right"], dt = Lt ? "⌘+a" : "ctrl+a", de = [
|
|
@@ -700,103 +700,108 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
700
700
|
offsetReferenceSelector: a,
|
|
701
701
|
selectionMode: u,
|
|
702
702
|
dismissOnNotAnnotatable: S = "NEVER"
|
|
703
|
-
} = e,
|
|
703
|
+
} = e, y = (b) => r = b;
|
|
704
704
|
let f;
|
|
705
|
-
const p = (
|
|
706
|
-
let c,
|
|
707
|
-
const E = (
|
|
708
|
-
|
|
709
|
-
}, m = (
|
|
710
|
-
|
|
705
|
+
const p = (b) => f = b;
|
|
706
|
+
let c, R, v, T = i;
|
|
707
|
+
const E = (b) => {
|
|
708
|
+
T = b, l.clear(), b || (c = void 0, R = void 0, v = void 0);
|
|
709
|
+
}, m = (b) => {
|
|
710
|
+
T && R !== !1 && (c = X(t, b.target) ? void 0 : {
|
|
711
711
|
annotation: st(),
|
|
712
712
|
selector: [],
|
|
713
713
|
creator: r,
|
|
714
714
|
created: /* @__PURE__ */ new Date()
|
|
715
715
|
});
|
|
716
|
-
}, l =
|
|
717
|
-
if (!
|
|
718
|
-
const
|
|
719
|
-
if (!(
|
|
716
|
+
}, l = z((b) => {
|
|
717
|
+
if (!T) return;
|
|
718
|
+
const x = document.getSelection();
|
|
719
|
+
if (!(x != null && x.anchorNode))
|
|
720
720
|
return;
|
|
721
|
-
if (
|
|
721
|
+
if (X(t, x.anchorNode)) {
|
|
722
722
|
c = void 0;
|
|
723
723
|
return;
|
|
724
724
|
}
|
|
725
|
-
const O =
|
|
726
|
-
if ((
|
|
727
|
-
if (
|
|
725
|
+
const O = b.timeStamp - ((v == null ? void 0 : v.timeStamp) || b.timeStamp);
|
|
726
|
+
if ((v == null ? void 0 : v.type) === "pointerdown" && (O < 1e3 && !c || x.isCollapsed && O < et) && m(v || b), !c) return;
|
|
727
|
+
if (x.isCollapsed) {
|
|
728
728
|
o.getAnnotation(c.annotation) && (s.clear(), o.deleteAnnotation(c.annotation));
|
|
729
729
|
return;
|
|
730
730
|
}
|
|
731
|
-
const
|
|
732
|
-
if (
|
|
733
|
-
const
|
|
734
|
-
(
|
|
735
|
-
var
|
|
736
|
-
return N.toString() !== ((
|
|
731
|
+
const I = Array.from(Array(x.rangeCount).keys()).map((N) => x.getRangeAt(N)).map((N) => Ut(N, t));
|
|
732
|
+
if (I.every((N) => Mt(N))) return;
|
|
733
|
+
const k = I.flatMap((N) => Bt(t, N.cloneRange()));
|
|
734
|
+
(k.length !== c.selector.length || k.some((N, K) => {
|
|
735
|
+
var $;
|
|
736
|
+
return N.toString() !== (($ = c.selector[K]) == null ? void 0 : $.quote);
|
|
737
737
|
})) && (c = {
|
|
738
738
|
...c,
|
|
739
|
-
selector:
|
|
739
|
+
selector: k.map((N) => Kt(N, t, a)),
|
|
740
740
|
updated: /* @__PURE__ */ new Date()
|
|
741
|
-
}, o.getAnnotation(c.annotation) ? o.updateTarget(c,
|
|
742
|
-
}, 10), g = (
|
|
743
|
-
|
|
744
|
-
}, d = async (
|
|
745
|
-
if (!
|
|
746
|
-
const
|
|
747
|
-
const { x: I, y:
|
|
748
|
-
if (
|
|
749
|
-
(typeof S == "function" ? S(
|
|
741
|
+
}, o.getAnnotation(c.annotation) ? o.updateTarget(c, U.LOCAL) : s.clear());
|
|
742
|
+
}, 10), g = (b) => {
|
|
743
|
+
v = Q(b), R = v.button === 0;
|
|
744
|
+
}, d = async (b) => {
|
|
745
|
+
if (!R) return;
|
|
746
|
+
const x = Q(b), O = () => {
|
|
747
|
+
const { x: I, y: k } = t.getBoundingClientRect();
|
|
748
|
+
if (X(t, x.target)) {
|
|
749
|
+
(typeof S == "function" ? S(x, t) : S === "ALWAYS") && s.clear();
|
|
750
750
|
return;
|
|
751
751
|
}
|
|
752
|
-
const
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
752
|
+
const D = x.target instanceof Node && t.contains(x.target) && o.getAt(
|
|
753
|
+
x.clientX - I,
|
|
754
|
+
x.clientY - k,
|
|
755
|
+
u === "all",
|
|
756
|
+
f
|
|
757
|
+
);
|
|
758
|
+
if (D) {
|
|
759
|
+
const { selected: N } = s, K = new Set(N.map((W) => W.id)), $ = Array.isArray(D) ? D.map((W) => W.id) : [D.id];
|
|
760
|
+
(K.size !== $.length || !$.every((W) => K.has(W))) && s.userSelect($, x);
|
|
756
761
|
} else
|
|
757
762
|
s.clear();
|
|
758
763
|
};
|
|
759
|
-
if (
|
|
760
|
-
await
|
|
764
|
+
if (x.timeStamp - v.timeStamp < et) {
|
|
765
|
+
await h();
|
|
761
766
|
const I = document.getSelection();
|
|
762
767
|
if (I != null && I.isCollapsed) {
|
|
763
|
-
c = void 0,
|
|
768
|
+
c = void 0, O();
|
|
764
769
|
return;
|
|
765
770
|
}
|
|
766
771
|
}
|
|
767
|
-
c && c.selector.length > 0 && (B(), s.userSelect(c.annotation,
|
|
768
|
-
},
|
|
769
|
-
const
|
|
770
|
-
let
|
|
771
|
-
const
|
|
772
|
-
return setTimeout(() =>
|
|
773
|
-
}, w = (
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
},
|
|
777
|
-
|
|
778
|
-
}, C = (
|
|
779
|
-
const
|
|
772
|
+
c && c.selector.length > 0 && (B(), s.userSelect(c.annotation, x));
|
|
773
|
+
}, h = async () => {
|
|
774
|
+
const b = document.getSelection();
|
|
775
|
+
let x = !1, O = b == null ? void 0 : b.isCollapsed;
|
|
776
|
+
const F = () => O || x, I = 1;
|
|
777
|
+
return setTimeout(() => x = !0, 50), xt(() => O = b == null ? void 0 : b.isCollapsed, I, F);
|
|
778
|
+
}, w = (b) => {
|
|
779
|
+
const x = document.getSelection();
|
|
780
|
+
x != null && x.isCollapsed || ((!c || c.selector.length === 0) && l(b), c && (B(), s.userSelect(c.annotation, Q(b))));
|
|
781
|
+
}, A = (b) => {
|
|
782
|
+
T && b.key === "Shift" && c && (document.getSelection().isCollapsed || (B(), s.userSelect(c.annotation, Y(b))));
|
|
783
|
+
}, C = (b) => {
|
|
784
|
+
const x = () => setTimeout(() => {
|
|
780
785
|
(c == null ? void 0 : c.selector.length) > 0 && (s.clear(), o.addAnnotation({
|
|
781
786
|
id: c.annotation,
|
|
782
787
|
bodies: [],
|
|
783
788
|
target: c
|
|
784
|
-
}), s.userSelect(c.annotation,
|
|
789
|
+
}), s.userSelect(c.annotation, Y(b))), document.removeEventListener("selectionchange", x);
|
|
785
790
|
}, 100);
|
|
786
|
-
document.addEventListener("selectionchange",
|
|
791
|
+
document.addEventListener("selectionchange", x), m(b);
|
|
787
792
|
};
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
}),
|
|
791
|
-
|
|
793
|
+
V(de.join(","), { element: t, keydown: !0, keyup: !1 }, (b) => {
|
|
794
|
+
b.repeat || (v = Y(b));
|
|
795
|
+
}), V(dt, { keydown: !0, keyup: !1 }, (b) => {
|
|
796
|
+
v = Y(b), C(b);
|
|
792
797
|
});
|
|
793
|
-
const
|
|
794
|
-
|
|
798
|
+
const L = (b) => {
|
|
799
|
+
b.repeat || b.target !== t && b.target !== document.body || (c = void 0, s.clear());
|
|
795
800
|
};
|
|
796
|
-
|
|
801
|
+
V(lt.join(","), { keydown: !0, keyup: !1 }, L);
|
|
797
802
|
const B = () => {
|
|
798
|
-
const
|
|
799
|
-
if (!
|
|
803
|
+
const b = o.getAnnotation(c.annotation);
|
|
804
|
+
if (!b) {
|
|
800
805
|
o.addAnnotation({
|
|
801
806
|
id: c.annotation,
|
|
802
807
|
bodies: [],
|
|
@@ -804,39 +809,39 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
804
809
|
});
|
|
805
810
|
return;
|
|
806
811
|
}
|
|
807
|
-
const { target: { updated:
|
|
808
|
-
(!
|
|
812
|
+
const { target: { updated: x } } = b, { updated: O } = c;
|
|
813
|
+
(!x || !O || x < O) && o.updateTarget(c);
|
|
809
814
|
};
|
|
810
|
-
return document.addEventListener("pointerdown", g), document.addEventListener("pointerup", d), document.addEventListener("contextmenu", w), t.addEventListener("keyup",
|
|
815
|
+
return document.addEventListener("pointerdown", g), document.addEventListener("pointerup", d), document.addEventListener("contextmenu", w), t.addEventListener("keyup", A), t.addEventListener("selectstart", m), document.addEventListener("selectionchange", l), {
|
|
811
816
|
destroy: () => {
|
|
812
|
-
c = void 0,
|
|
817
|
+
c = void 0, R = void 0, v = void 0, l.clear(), document.removeEventListener("pointerdown", g), document.removeEventListener("pointerup", d), document.removeEventListener("contextmenu", w), t.removeEventListener("keyup", A), t.removeEventListener("selectstart", m), document.removeEventListener("selectionchange", l), V.unbind();
|
|
813
818
|
},
|
|
814
819
|
setFilter: p,
|
|
815
|
-
setUser:
|
|
820
|
+
setUser: y,
|
|
816
821
|
setAnnotatingEnabled: E
|
|
817
822
|
};
|
|
818
823
|
}, fe = (t, n) => ({
|
|
819
824
|
...t,
|
|
820
825
|
annotatingEnabled: t.annotatingEnabled ?? n.annotatingEnabled,
|
|
821
826
|
user: t.user || n.user
|
|
822
|
-
}), nt = "SPANS",
|
|
827
|
+
}), nt = "SPANS", Re = (t, n = {}) => {
|
|
823
828
|
Tt(t), kt(t);
|
|
824
829
|
const e = fe(n, {
|
|
825
830
|
annotatingEnabled: !0,
|
|
826
831
|
user: St()
|
|
827
832
|
}), o = ae(t, e), { selection: s, viewport: r } = o, i = o.store, a = Ct(i), u = Et(o, a, e.adapter);
|
|
828
833
|
let S = e.user;
|
|
829
|
-
const
|
|
834
|
+
const y = e.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : nt : e.renderer || nt, f = y === "SPANS" ? ee(t, o, r) : y === "CSS_HIGHLIGHTS" ? Zt(t, o, r) : y === "CANVAS" ? jt(t, o, r) : void 0;
|
|
830
835
|
if (!f)
|
|
831
|
-
throw `Unknown renderer implementation: ${
|
|
832
|
-
console.debug(`Using ${
|
|
836
|
+
throw `Unknown renderer implementation: ${y}`;
|
|
837
|
+
console.debug(`Using ${y} renderer`), e.style && f.setStyle(e.style);
|
|
833
838
|
const p = ue(t, o, e);
|
|
834
839
|
p.setUser(S), p.setAnnotatingEnabled(e.annotatingEnabled);
|
|
835
|
-
const c = wt(o, a, e.adapter),
|
|
840
|
+
const c = wt(o, a, e.adapter), R = () => S, v = (d) => {
|
|
836
841
|
p.setAnnotatingEnabled(
|
|
837
842
|
d === void 0 ? !0 : d
|
|
838
843
|
);
|
|
839
|
-
},
|
|
844
|
+
}, T = (d) => {
|
|
840
845
|
f.setFilter(d), p.setFilter(d);
|
|
841
846
|
}, E = (d) => {
|
|
842
847
|
S = d, p.setUser(d);
|
|
@@ -851,9 +856,9 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
851
856
|
f.destroy(), p.destroy(), a.destroy();
|
|
852
857
|
},
|
|
853
858
|
element: t,
|
|
854
|
-
getUser:
|
|
855
|
-
setAnnotatingEnabled:
|
|
856
|
-
setFilter:
|
|
859
|
+
getUser: R,
|
|
860
|
+
setAnnotatingEnabled: v,
|
|
861
|
+
setFilter: T,
|
|
857
862
|
setStyle: f.setStyle.bind(f),
|
|
858
863
|
redraw: f.redraw.bind(f),
|
|
859
864
|
setUser: E,
|
|
@@ -862,35 +867,35 @@ const rt = "not-annotatable", _ = `.${rt}`, Y = (t, n) => {
|
|
|
862
867
|
setVisible: f.setVisible.bind(f),
|
|
863
868
|
on: u.on,
|
|
864
869
|
off: u.off,
|
|
865
|
-
scrollIntoView:
|
|
870
|
+
scrollIntoView: Ft(t, i),
|
|
866
871
|
state: o
|
|
867
872
|
};
|
|
868
873
|
};
|
|
869
874
|
export {
|
|
870
|
-
|
|
871
|
-
|
|
875
|
+
j as DEFAULT_SELECTED_STYLE,
|
|
876
|
+
H as DEFAULT_STYLE,
|
|
872
877
|
rt as NOT_ANNOTATABLE_CLASS,
|
|
873
878
|
_ as NOT_ANNOTATABLE_SELECTOR,
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
879
|
+
ke as Origin,
|
|
880
|
+
Ne as UserSelectAction,
|
|
881
|
+
xe as W3CTextFormat,
|
|
877
882
|
Tt as cancelSingleClickEvents,
|
|
878
|
-
|
|
883
|
+
Y as cloneKeyboardEvent,
|
|
879
884
|
Q as clonePointerEvent,
|
|
880
|
-
|
|
885
|
+
Be as createBody,
|
|
881
886
|
jt as createCanvasRenderer,
|
|
882
887
|
Zt as createHighlightsRenderer,
|
|
883
888
|
le as createPresencePainter,
|
|
884
889
|
Qt as createRenderer,
|
|
885
890
|
ue as createSelectionHandler,
|
|
886
891
|
ee as createSpansRenderer,
|
|
887
|
-
|
|
892
|
+
Re as createTextAnnotator,
|
|
888
893
|
ae as createTextAnnotatorState,
|
|
889
894
|
fe as fillDefaults,
|
|
890
895
|
Ot as getQuoteContext,
|
|
891
896
|
Z as getRangeAnnotatableContents,
|
|
892
897
|
Lt as isMac,
|
|
893
|
-
|
|
898
|
+
X as isNotAnnotatable,
|
|
894
899
|
Rt as isRangeAnnotatable,
|
|
895
900
|
M as isRevived,
|
|
896
901
|
Mt as isWhitespaceOrEmpty,
|
|
@@ -902,14 +907,14 @@ export {
|
|
|
902
907
|
Kt as rangeToSelector,
|
|
903
908
|
G as reviveAnnotation,
|
|
904
909
|
it as reviveSelector,
|
|
905
|
-
|
|
906
|
-
|
|
910
|
+
q as reviveTarget,
|
|
911
|
+
Ft as scrollIntoView,
|
|
907
912
|
re as serializeW3CTextAnnotation,
|
|
908
913
|
Bt as splitAnnotatableRanges,
|
|
909
|
-
|
|
910
|
-
|
|
914
|
+
ve as toDomRectList,
|
|
915
|
+
_t as toParentBounds,
|
|
911
916
|
Ae as toViewportBounds,
|
|
912
|
-
|
|
917
|
+
Ut as trimRangeToContainer,
|
|
913
918
|
It as whitespaceOrEmptyRegex
|
|
914
919
|
};
|
|
915
920
|
//# sourceMappingURL=text-annotator.es.js.map
|