@soomo/text-annotator 3.3.0-staging.0 → 3.4.0-staging.1
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
|
|
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 vt } from "@annotorious/core";
|
|
6
|
+
import { Origin as ke, UserSelectAction as Ne, createBody as Be } from "@annotorious/core";
|
|
7
|
+
import wt from "rbush";
|
|
8
|
+
import { createNanoEvents as At } from "nanoevents";
|
|
9
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();
|
|
@@ -116,7 +116,7 @@ const rt = "not-annotatable", _ = `.${rt}`, U = (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}`, U = (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}`, U = (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}`, U = (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) => ({
|
|
@@ -211,7 +211,7 @@ const rt = "not-annotatable", _ = `.${rt}`, U = (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}`, U = (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}`, U = (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}`, U = (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
|
+
}, w = (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 }, v = new MutationObserver(z((C) => {
|
|
295
295
|
C.every((B) => B.target === t || t.contains(B.target)) || p(!0);
|
|
296
296
|
}, 150));
|
|
297
|
-
return
|
|
297
|
+
return v.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(), v.disconnect();
|
|
300
300
|
},
|
|
301
301
|
redraw: p,
|
|
302
|
-
setStyle:
|
|
303
|
-
setFilter:
|
|
302
|
+
setStyle: R,
|
|
303
|
+
setFilter: w,
|
|
304
304
|
setPainter: c,
|
|
305
305
|
setVisible: o.setVisible
|
|
306
306
|
};
|
|
@@ -313,32 +313,32 @@ const rt = "not-annotatable", _ = `.${rt}`, U = (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:
|
|
328
|
-
width:
|
|
329
|
-
height:
|
|
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: v, height: A }) => ({
|
|
326
|
+
x: d + R,
|
|
327
|
+
y: h + c,
|
|
328
|
+
width: v,
|
|
329
|
+
height: A
|
|
330
330
|
}));
|
|
331
331
|
if (e.fillStyle = m.fill, e.globalAlpha = m.fillOpacity || 1, l.forEach(
|
|
332
|
-
({ x: d, y, width:
|
|
332
|
+
({ x: d, y: h, width: v, height: A }) => e.fillRect(d, h, v, 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: v, width: A, height: C }) => {
|
|
337
|
+
e.beginPath(), e.moveTo(h, v + C + d), e.lineTo(h + A, v + 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}`, U = (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}`, U = (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}`, U = (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, w) => {
|
|
400
|
+
const { annotation: { target: { created: T } } } = R, { annotation: { target: { created: E } } } = w;
|
|
401
|
+
return T && E ? T.getTime() - E.getTime() : 0;
|
|
402
|
+
}).forEach((R) => {
|
|
403
|
+
R.rects.map((w) => {
|
|
404
|
+
const T = Jt(w, 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 = `${w.x}px`, m.style.top = `${w.y}px`, m.style.width = `${w.width}px`, m.style.height = `${w.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}`, U = (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}`, U = (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}`, U = (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}`, U = (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}`, U = (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: w, 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}`, U = (t, n) => {
|
|
|
499
499
|
}
|
|
500
500
|
const l = {
|
|
501
501
|
type: "TextPositionSelector",
|
|
502
|
-
start:
|
|
503
|
-
end:
|
|
502
|
+
start: w,
|
|
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}`, U = (t, n) => {
|
|
|
523
523
|
target: f
|
|
524
524
|
};
|
|
525
525
|
}, ie = (t, n) => {
|
|
526
|
-
const e = new
|
|
527
|
-
const d = l.selector.flatMap((
|
|
528
|
-
const
|
|
529
|
-
return Array.from(
|
|
530
|
-
}),
|
|
531
|
-
return
|
|
532
|
-
const { x:
|
|
526
|
+
const e = new wt(), o = /* @__PURE__ */ new Map(), s = At(), r = (l, g) => {
|
|
527
|
+
const d = l.selector.flatMap((v) => {
|
|
528
|
+
const A = M([v]) ? v.range : it(v, n).range;
|
|
529
|
+
return Array.from(A.getClientRects());
|
|
530
|
+
}), h = Dt(d).map((v) => _t(v, g));
|
|
531
|
+
return h.map((v) => {
|
|
532
|
+
const { x: A, y: C, width: L, height: B } = v;
|
|
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}`, U = (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
|
|
561
|
-
e.load(
|
|
560
|
+
const v = h.flatMap(({ rects: A }) => A);
|
|
561
|
+
e.load(v);
|
|
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
|
-
}),
|
|
569
|
-
return
|
|
568
|
+
}), v = (A) => A.annotation.rects.reduce((C, L) => C + L.width * L.height, 0);
|
|
569
|
+
return h.length > 0 ? (h.sort((A, C) => v(A) - v(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, v = 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), v = Math.max(v, L.right), A = Math.max(A, L.bottom);
|
|
578
578
|
}
|
|
579
|
-
return new DOMRect(d,
|
|
580
|
-
},
|
|
579
|
+
return new DOMRect(d, h, v - 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}`, U = (t, n) => {
|
|
|
586
586
|
clear: a,
|
|
587
587
|
getAt: p,
|
|
588
588
|
getAnnotationBounds: c,
|
|
589
|
-
getAnnotationRects:
|
|
590
|
-
getIntersecting: (l, g, d,
|
|
591
|
-
const
|
|
592
|
-
return Array.from(
|
|
589
|
+
getAnnotationRects: R,
|
|
590
|
+
getIntersecting: (l, g, d, h) => {
|
|
591
|
+
const v = e.search({ minX: l, minY: g, maxX: d, maxY: h }), A = new Set(v.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}`, U = (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((
|
|
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((v) => G(v, t)), h = d.filter((v) => !M(v.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, v = o.getAt(m, l, h).map((C) => e.getAnnotation(C)), A = d ? v.filter(d) : v;
|
|
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), w = (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}`, U = (t, n) => {
|
|
|
640
640
|
bulkUpdateTargets: f,
|
|
641
641
|
bulkUpsertAnnotations: S,
|
|
642
642
|
getAnnotationBounds: c,
|
|
643
|
-
getAnnotationRects:
|
|
644
|
-
getIntersecting:
|
|
643
|
+
getAnnotationRects: w,
|
|
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}`, U = (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], w = y.rects[0].x + f.left, T = y.rects[0].y + f.top;
|
|
678
|
+
o.fillStyle = c.appearance.color, o.fillRect(w - 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(w - 2, T - 2.5 - l, m, l), o.fillStyle = "#fff", o.fillText(c.appearance.label, w + 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}`, U = (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,102 +700,108 @@ const rt = "not-annotatable", _ = `.${rt}`, U = (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, w, T = i;
|
|
707
|
+
const E = (b) => {
|
|
708
|
+
T = b, l.clear(), b || (c = void 0, R = void 0, w = 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 - ((w == null ? void 0 : w.timeStamp) || b.timeStamp);
|
|
726
|
+
if ((w == null ? void 0 : w.type) === "pointerdown" && (O < 1e3 && !c || x.isCollapsed && O < et) && m(w || 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
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
741
|
+
}, o.getAnnotation(c.annotation) ? o.updateTarget(c, U.LOCAL) : s.clear());
|
|
742
|
+
}, 10), g = (b) => {
|
|
743
|
+
w = Q(b), R = w.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
|
+
return;
|
|
751
|
+
}
|
|
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);
|
|
755
761
|
} else
|
|
756
762
|
s.clear();
|
|
757
763
|
};
|
|
758
|
-
if (
|
|
759
|
-
await
|
|
764
|
+
if (x.timeStamp - w.timeStamp < et) {
|
|
765
|
+
await h();
|
|
760
766
|
const I = document.getSelection();
|
|
761
767
|
if (I != null && I.isCollapsed) {
|
|
762
|
-
c = void 0,
|
|
768
|
+
c = void 0, O();
|
|
763
769
|
return;
|
|
764
770
|
}
|
|
765
771
|
}
|
|
766
|
-
c && c.selector.length > 0 && (B(), s.userSelect(c.annotation,
|
|
767
|
-
},
|
|
768
|
-
const
|
|
769
|
-
let
|
|
770
|
-
const
|
|
771
|
-
return setTimeout(() =>
|
|
772
|
-
},
|
|
773
|
-
const
|
|
774
|
-
|
|
775
|
-
},
|
|
776
|
-
|
|
777
|
-
}, C = (
|
|
778
|
-
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
|
+
}, v = (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(() => {
|
|
779
785
|
(c == null ? void 0 : c.selector.length) > 0 && (s.clear(), o.addAnnotation({
|
|
780
786
|
id: c.annotation,
|
|
781
787
|
bodies: [],
|
|
782
788
|
target: c
|
|
783
|
-
}), s.userSelect(c.annotation, Y(
|
|
789
|
+
}), s.userSelect(c.annotation, Y(b))), document.removeEventListener("selectionchange", x);
|
|
784
790
|
}, 100);
|
|
785
|
-
document.addEventListener("selectionchange",
|
|
791
|
+
document.addEventListener("selectionchange", x), m(b);
|
|
786
792
|
};
|
|
787
|
-
V(de.join(","), { element: t, keydown: !0, keyup: !1 }, (
|
|
788
|
-
|
|
789
|
-
}), V(dt, { keydown: !0, keyup: !1 }, (
|
|
790
|
-
|
|
793
|
+
V(de.join(","), { element: t, keydown: !0, keyup: !1 }, (b) => {
|
|
794
|
+
b.repeat || (w = Y(b));
|
|
795
|
+
}), V(dt, { keydown: !0, keyup: !1 }, (b) => {
|
|
796
|
+
w = Y(b), C(b);
|
|
791
797
|
});
|
|
792
|
-
const
|
|
793
|
-
|
|
798
|
+
const L = (b) => {
|
|
799
|
+
b.repeat || b.target !== t && b.target !== document.body || (c = void 0, s.clear());
|
|
794
800
|
};
|
|
795
|
-
V(lt.join(","), { keydown: !0, keyup: !1 },
|
|
801
|
+
V(lt.join(","), { keydown: !0, keyup: !1 }, L);
|
|
796
802
|
const B = () => {
|
|
797
|
-
const
|
|
798
|
-
if (!
|
|
803
|
+
const b = o.getAnnotation(c.annotation);
|
|
804
|
+
if (!b) {
|
|
799
805
|
o.addAnnotation({
|
|
800
806
|
id: c.annotation,
|
|
801
807
|
bodies: [],
|
|
@@ -803,39 +809,39 @@ const rt = "not-annotatable", _ = `.${rt}`, U = (t, n) => {
|
|
|
803
809
|
});
|
|
804
810
|
return;
|
|
805
811
|
}
|
|
806
|
-
const { target: { updated:
|
|
807
|
-
(!
|
|
812
|
+
const { target: { updated: x } } = b, { updated: O } = c;
|
|
813
|
+
(!x || !O || x < O) && o.updateTarget(c);
|
|
808
814
|
};
|
|
809
|
-
return
|
|
815
|
+
return document.addEventListener("pointerdown", g), document.addEventListener("pointerup", d), document.addEventListener("contextmenu", v), t.addEventListener("keyup", A), t.addEventListener("selectstart", m), document.addEventListener("selectionchange", l), {
|
|
810
816
|
destroy: () => {
|
|
811
|
-
c = void 0,
|
|
817
|
+
c = void 0, R = void 0, w = void 0, l.clear(), document.removeEventListener("pointerdown", g), document.removeEventListener("pointerup", d), document.removeEventListener("contextmenu", v), t.removeEventListener("keyup", A), t.removeEventListener("selectstart", m), document.removeEventListener("selectionchange", l), V.unbind();
|
|
812
818
|
},
|
|
813
819
|
setFilter: p,
|
|
814
|
-
setUser:
|
|
820
|
+
setUser: y,
|
|
815
821
|
setAnnotatingEnabled: E
|
|
816
822
|
};
|
|
817
823
|
}, fe = (t, n) => ({
|
|
818
824
|
...t,
|
|
819
825
|
annotatingEnabled: t.annotatingEnabled ?? n.annotatingEnabled,
|
|
820
826
|
user: t.user || n.user
|
|
821
|
-
}), nt = "SPANS",
|
|
827
|
+
}), nt = "SPANS", Re = (t, n = {}) => {
|
|
822
828
|
Tt(t), kt(t);
|
|
823
829
|
const e = fe(n, {
|
|
824
830
|
annotatingEnabled: !0,
|
|
825
831
|
user: St()
|
|
826
832
|
}), o = ae(t, e), { selection: s, viewport: r } = o, i = o.store, a = Ct(i), u = Et(o, a, e.adapter);
|
|
827
833
|
let S = e.user;
|
|
828
|
-
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;
|
|
829
835
|
if (!f)
|
|
830
|
-
throw `Unknown renderer implementation: ${
|
|
831
|
-
console.debug(`Using ${
|
|
836
|
+
throw `Unknown renderer implementation: ${y}`;
|
|
837
|
+
console.debug(`Using ${y} renderer`), e.style && f.setStyle(e.style);
|
|
832
838
|
const p = ue(t, o, e);
|
|
833
839
|
p.setUser(S), p.setAnnotatingEnabled(e.annotatingEnabled);
|
|
834
|
-
const c =
|
|
840
|
+
const c = vt(o, a, e.adapter), R = () => S, w = (d) => {
|
|
835
841
|
p.setAnnotatingEnabled(
|
|
836
842
|
d === void 0 ? !0 : d
|
|
837
843
|
);
|
|
838
|
-
},
|
|
844
|
+
}, T = (d) => {
|
|
839
845
|
f.setFilter(d), p.setFilter(d);
|
|
840
846
|
}, E = (d) => {
|
|
841
847
|
S = d, p.setUser(d);
|
|
@@ -850,9 +856,9 @@ const rt = "not-annotatable", _ = `.${rt}`, U = (t, n) => {
|
|
|
850
856
|
f.destroy(), p.destroy(), a.destroy();
|
|
851
857
|
},
|
|
852
858
|
element: t,
|
|
853
|
-
getUser:
|
|
854
|
-
setAnnotatingEnabled:
|
|
855
|
-
setFilter:
|
|
859
|
+
getUser: R,
|
|
860
|
+
setAnnotatingEnabled: w,
|
|
861
|
+
setFilter: T,
|
|
856
862
|
setStyle: f.setStyle.bind(f),
|
|
857
863
|
redraw: f.redraw.bind(f),
|
|
858
864
|
setUser: E,
|
|
@@ -861,35 +867,35 @@ const rt = "not-annotatable", _ = `.${rt}`, U = (t, n) => {
|
|
|
861
867
|
setVisible: f.setVisible.bind(f),
|
|
862
868
|
on: u.on,
|
|
863
869
|
off: u.off,
|
|
864
|
-
scrollIntoView:
|
|
870
|
+
scrollIntoView: Ft(t, i),
|
|
865
871
|
state: o
|
|
866
872
|
};
|
|
867
873
|
};
|
|
868
874
|
export {
|
|
869
|
-
|
|
870
|
-
|
|
875
|
+
j as DEFAULT_SELECTED_STYLE,
|
|
876
|
+
H as DEFAULT_STYLE,
|
|
871
877
|
rt as NOT_ANNOTATABLE_CLASS,
|
|
872
878
|
_ as NOT_ANNOTATABLE_SELECTOR,
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
879
|
+
ke as Origin,
|
|
880
|
+
Ne as UserSelectAction,
|
|
881
|
+
xe as W3CTextFormat,
|
|
876
882
|
Tt as cancelSingleClickEvents,
|
|
877
883
|
Y as cloneKeyboardEvent,
|
|
878
884
|
Q as clonePointerEvent,
|
|
879
|
-
|
|
885
|
+
Be as createBody,
|
|
880
886
|
jt as createCanvasRenderer,
|
|
881
887
|
Zt as createHighlightsRenderer,
|
|
882
888
|
le as createPresencePainter,
|
|
883
889
|
Qt as createRenderer,
|
|
884
890
|
ue as createSelectionHandler,
|
|
885
891
|
ee as createSpansRenderer,
|
|
886
|
-
|
|
892
|
+
Re as createTextAnnotator,
|
|
887
893
|
ae as createTextAnnotatorState,
|
|
888
894
|
fe as fillDefaults,
|
|
889
895
|
Ot as getQuoteContext,
|
|
890
896
|
Z as getRangeAnnotatableContents,
|
|
891
897
|
Lt as isMac,
|
|
892
|
-
|
|
898
|
+
X as isNotAnnotatable,
|
|
893
899
|
Rt as isRangeAnnotatable,
|
|
894
900
|
M as isRevived,
|
|
895
901
|
Mt as isWhitespaceOrEmpty,
|
|
@@ -901,14 +907,14 @@ export {
|
|
|
901
907
|
Kt as rangeToSelector,
|
|
902
908
|
G as reviveAnnotation,
|
|
903
909
|
it as reviveSelector,
|
|
904
|
-
|
|
905
|
-
|
|
910
|
+
q as reviveTarget,
|
|
911
|
+
Ft as scrollIntoView,
|
|
906
912
|
re as serializeW3CTextAnnotation,
|
|
907
913
|
Bt as splitAnnotatableRanges,
|
|
908
914
|
we as toDomRectList,
|
|
909
|
-
|
|
915
|
+
_t as toParentBounds,
|
|
910
916
|
Ae as toViewportBounds,
|
|
911
|
-
|
|
917
|
+
Ut as trimRangeToContainer,
|
|
912
918
|
It as whitespaceOrEmptyRegex
|
|
913
919
|
};
|
|
914
920
|
//# sourceMappingURL=text-annotator.es.js.map
|