@soomo/text-annotator 3.4.2-staging.0 → 3.4.2-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.
- package/dist/SelectionHandler.d.ts +10 -0
- package/dist/TextAnnotator.d.ts +15 -0
- package/dist/TextAnnotatorOptions.d.ts +34 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/scrollIntoView.d.ts +3 -0
- package/dist/highlight/Highlight.d.ts +5 -0
- package/dist/highlight/HighlightPainter.d.ts +11 -0
- package/dist/highlight/HighlightStyle.d.ts +11 -0
- package/dist/highlight/baseRenderer.d.ts +20 -0
- package/dist/highlight/canvas/canvasRenderer.d.ts +5 -0
- package/dist/highlight/canvas/index.d.ts +1 -0
- package/dist/highlight/highlights/highlightsRenderer.d.ts +6 -0
- package/dist/highlight/highlights/index.d.ts +1 -0
- package/dist/highlight/index.d.ts +6 -0
- package/dist/highlight/span/color.d.ts +2 -0
- package/dist/highlight/span/index.d.ts +1 -0
- package/dist/highlight/span/spansRenderer.d.ts +5 -0
- package/dist/highlight/viewport.d.ts +12 -0
- package/dist/index.d.ts +11 -0
- package/dist/model/core/TextAnnotation.d.ts +15 -0
- package/dist/model/core/index.d.ts +1 -0
- package/dist/model/index.d.ts +2 -0
- package/dist/model/w3c/W3CTextAnnotation.d.ts +35 -0
- package/dist/model/w3c/W3CTextFormatAdapter.d.ts +12 -0
- package/dist/model/w3c/index.d.ts +2 -0
- package/dist/presence/PresencePainter.d.ts +5 -0
- package/dist/presence/PresencePainterOptions.d.ts +3 -0
- package/dist/presence/index.d.ts +2 -0
- package/dist/state/TextAnnotationStore.d.ts +28 -0
- package/dist/state/TextAnnotatorState.d.ts +12 -0
- package/dist/state/index.d.ts +2 -0
- package/dist/state/spatialTree.d.ts +33 -0
- package/dist/text-annotator.es.js +151 -151
- package/dist/text-annotator.es.js.map +1 -1
- package/dist/text-annotator.umd.js +2 -2
- package/dist/text-annotator.umd.js.map +1 -1
- package/dist/utils/cancelSingleClickEvents.d.ts +6 -0
- package/dist/utils/cloneEvents.d.ts +11 -0
- package/dist/utils/device.d.ts +1 -0
- package/dist/utils/getHighlightClientRects.d.ts +1 -0
- package/dist/utils/getQuoteContext.d.ts +4 -0
- package/dist/utils/index.d.ts +17 -0
- package/dist/utils/isNotAnnotatable.d.ts +4 -0
- package/dist/utils/isRevived.d.ts +2 -0
- package/dist/utils/isWhitespaceOrEmpty.d.ts +3 -0
- package/dist/utils/mergeClientRects.d.ts +2 -0
- package/dist/utils/programmaticallyFocusable.d.ts +6 -0
- package/dist/utils/rangeToSelector.d.ts +2 -0
- package/dist/utils/rectsToBounds.d.ts +8 -0
- package/dist/utils/reviveAnnotation.d.ts +2 -0
- package/dist/utils/reviveSelector.d.ts +11 -0
- package/dist/utils/reviveTarget.d.ts +2 -0
- package/dist/utils/splitAnnotatableRanges.d.ts +5 -0
- package/dist/utils/trimRangeToContainer.d.ts +1 -0
- package/package.json +7 -8
|
@@ -19,6 +19,48 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
19
19
|
}, Nt = (t) => t.addEventListener("click", (e) => {
|
|
20
20
|
// Allow clicks within not-annotatable elements
|
|
21
21
|
!e.target.closest(W) && !e.target.closest("a") && e.preventDefault();
|
|
22
|
+
}), G = (t) => ({
|
|
23
|
+
...t,
|
|
24
|
+
type: t.type,
|
|
25
|
+
x: t.x,
|
|
26
|
+
y: t.y,
|
|
27
|
+
clientX: t.clientX,
|
|
28
|
+
clientY: t.clientY,
|
|
29
|
+
offsetX: t.offsetX,
|
|
30
|
+
offsetY: t.offsetY,
|
|
31
|
+
screenX: t.screenX,
|
|
32
|
+
screenY: t.screenY,
|
|
33
|
+
isPrimary: t.isPrimary,
|
|
34
|
+
altKey: t.altKey,
|
|
35
|
+
ctrlKey: t.ctrlKey,
|
|
36
|
+
metaKey: t.metaKey,
|
|
37
|
+
shiftKey: t.shiftKey,
|
|
38
|
+
button: t.button,
|
|
39
|
+
buttons: t.buttons,
|
|
40
|
+
currentTarget: t.currentTarget,
|
|
41
|
+
target: t.target,
|
|
42
|
+
defaultPrevented: t.defaultPrevented,
|
|
43
|
+
detail: t.detail,
|
|
44
|
+
eventPhase: t.eventPhase,
|
|
45
|
+
pointerId: t.pointerId,
|
|
46
|
+
pointerType: t.pointerType,
|
|
47
|
+
timeStamp: t.timeStamp
|
|
48
|
+
}), X = (t) => ({
|
|
49
|
+
...t,
|
|
50
|
+
type: t.type,
|
|
51
|
+
key: t.key,
|
|
52
|
+
code: t.code,
|
|
53
|
+
location: t.location,
|
|
54
|
+
repeat: t.repeat,
|
|
55
|
+
altKey: t.altKey,
|
|
56
|
+
ctrlKey: t.ctrlKey,
|
|
57
|
+
metaKey: t.metaKey,
|
|
58
|
+
shiftKey: t.shiftKey,
|
|
59
|
+
currentTarget: t.currentTarget,
|
|
60
|
+
target: t.target,
|
|
61
|
+
defaultPrevented: t.defaultPrevented,
|
|
62
|
+
detail: t.detail,
|
|
63
|
+
timeStamp: t.timeStamp
|
|
22
64
|
}), Ot = ft(), kt = Ot.os.is(ut.MACOS), Bt = (t) => {
|
|
23
65
|
!t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
|
|
24
66
|
}, It = (t) => {
|
|
@@ -151,14 +193,20 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
151
193
|
r.setStart(o, 0), r.setEnd(t.startContainer, t.startOffset);
|
|
152
194
|
const s = J(r).textContent, i = t.toString(), c = s.length || 0, l = c + i.length;
|
|
153
195
|
return n ? { quote: i, start: c, end: l, range: t, offsetReference: o } : { quote: i, start: c, end: l, range: t };
|
|
196
|
+
}, $t = (t, e) => {
|
|
197
|
+
const { left: n, top: r, right: o, bottom: s } = t;
|
|
198
|
+
return new DOMRect(n - e.left, r - e.top, o - n, s - r);
|
|
199
|
+
}, Oe = (t, e) => {
|
|
200
|
+
const { left: n, top: r, right: o, bottom: s } = t;
|
|
201
|
+
return new DOMRect(n + e.left, r + e.top, o - n, s - r);
|
|
154
202
|
}, at = (t, e) => {
|
|
155
203
|
var p, u;
|
|
156
204
|
const { start: n, end: r } = t, o = t.offsetReference || e, s = document.createNodeIterator(
|
|
157
205
|
e,
|
|
158
206
|
NodeFilter.SHOW_TEXT,
|
|
159
|
-
(
|
|
207
|
+
(m) => {
|
|
160
208
|
var d;
|
|
161
|
-
return (d =
|
|
209
|
+
return (d = m.parentElement) != null && d.closest(W) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
|
|
162
210
|
}
|
|
163
211
|
);
|
|
164
212
|
let i = 0;
|
|
@@ -168,22 +216,22 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
168
216
|
let f = !o;
|
|
169
217
|
for (; l !== null; ) {
|
|
170
218
|
if (f || (f = typeof (o == null ? void 0 : o.contains) == "function" ? o.contains(l) : !1), f) {
|
|
171
|
-
const
|
|
172
|
-
if (i +
|
|
219
|
+
const m = ((p = l.textContent) == null ? void 0 : p.length) || 0;
|
|
220
|
+
if (i + m > n) {
|
|
173
221
|
c.setStart(l, n - i);
|
|
174
222
|
break;
|
|
175
223
|
}
|
|
176
|
-
i +=
|
|
224
|
+
i += m;
|
|
177
225
|
}
|
|
178
226
|
l = s.nextNode();
|
|
179
227
|
}
|
|
180
228
|
for (; l !== null; ) {
|
|
181
|
-
const
|
|
182
|
-
if (i +
|
|
229
|
+
const m = ((u = l.textContent) == null ? void 0 : u.length) || 0;
|
|
230
|
+
if (i + m >= r) {
|
|
183
231
|
c.setEnd(l, r - i);
|
|
184
232
|
break;
|
|
185
233
|
}
|
|
186
|
-
i +=
|
|
234
|
+
i += m, l = s.nextNode();
|
|
187
235
|
}
|
|
188
236
|
return {
|
|
189
237
|
...t,
|
|
@@ -192,64 +240,16 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
192
240
|
}, q = (t, e) => P(t.selector) ? t : {
|
|
193
241
|
...t,
|
|
194
242
|
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : at(n, e))
|
|
195
|
-
},
|
|
243
|
+
}, Q = (t, e) => P(t.target.selector) ? t : { ...t, target: q(t.target, e) }, Wt = (t, e) => {
|
|
196
244
|
const n = t.cloneRange();
|
|
197
245
|
return e.contains(n.startContainer) || n.setStart(e, 0), e.contains(n.endContainer) || n.setEnd(e, e.childNodes.length), n;
|
|
198
|
-
}, Q = (t) => ({
|
|
199
|
-
...t,
|
|
200
|
-
type: t.type,
|
|
201
|
-
x: t.x,
|
|
202
|
-
y: t.y,
|
|
203
|
-
clientX: t.clientX,
|
|
204
|
-
clientY: t.clientY,
|
|
205
|
-
offsetX: t.offsetX,
|
|
206
|
-
offsetY: t.offsetY,
|
|
207
|
-
screenX: t.screenX,
|
|
208
|
-
screenY: t.screenY,
|
|
209
|
-
isPrimary: t.isPrimary,
|
|
210
|
-
altKey: t.altKey,
|
|
211
|
-
ctrlKey: t.ctrlKey,
|
|
212
|
-
metaKey: t.metaKey,
|
|
213
|
-
shiftKey: t.shiftKey,
|
|
214
|
-
button: t.button,
|
|
215
|
-
buttons: t.buttons,
|
|
216
|
-
currentTarget: t.currentTarget,
|
|
217
|
-
target: t.target,
|
|
218
|
-
defaultPrevented: t.defaultPrevented,
|
|
219
|
-
detail: t.detail,
|
|
220
|
-
eventPhase: t.eventPhase,
|
|
221
|
-
pointerId: t.pointerId,
|
|
222
|
-
pointerType: t.pointerType,
|
|
223
|
-
timeStamp: t.timeStamp
|
|
224
|
-
}), X = (t) => ({
|
|
225
|
-
...t,
|
|
226
|
-
type: t.type,
|
|
227
|
-
key: t.key,
|
|
228
|
-
code: t.code,
|
|
229
|
-
location: t.location,
|
|
230
|
-
repeat: t.repeat,
|
|
231
|
-
altKey: t.altKey,
|
|
232
|
-
ctrlKey: t.ctrlKey,
|
|
233
|
-
metaKey: t.metaKey,
|
|
234
|
-
shiftKey: t.shiftKey,
|
|
235
|
-
currentTarget: t.currentTarget,
|
|
236
|
-
target: t.target,
|
|
237
|
-
defaultPrevented: t.defaultPrevented,
|
|
238
|
-
detail: t.detail,
|
|
239
|
-
timeStamp: t.timeStamp
|
|
240
|
-
}), Wt = (t, e) => {
|
|
241
|
-
const { left: n, top: r, right: o, bottom: s } = t;
|
|
242
|
-
return new DOMRect(n - e.left, r - e.top, o - n, s - r);
|
|
243
|
-
}, Oe = (t, e) => {
|
|
244
|
-
const { left: n, top: r, right: o, bottom: s } = t;
|
|
245
|
-
return new DOMRect(n + e.left, r + e.top, o - n, s - r);
|
|
246
246
|
}, ct = (t) => {
|
|
247
247
|
if (!t)
|
|
248
248
|
return document.scrollingElement;
|
|
249
249
|
const { overflowY: e } = window.getComputedStyle(t);
|
|
250
250
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ct(t.parentElement);
|
|
251
251
|
}, et = (t, e, n) => {
|
|
252
|
-
const r = n.getBoundingClientRect(), o = n.clientHeight, s = n.clientWidth, i = e.selector[0].range.getBoundingClientRect(), { width: c, height: l } = t.getAnnotationBounds(e.annotation), f = i.top - r.top, p = i.left - r.left, u = n.parentElement ? n.scrollTop : 0,
|
|
252
|
+
const r = n.getBoundingClientRect(), o = n.clientHeight, s = n.clientWidth, i = e.selector[0].range.getBoundingClientRect(), { width: c, height: l } = t.getAnnotationBounds(e.annotation), f = i.top - r.top, p = i.left - r.left, u = n.parentElement ? n.scrollTop : 0, m = n.parentElement ? n.scrollLeft : 0, d = f + u - (o - l) / 2, L = p + m - (s - c) / 2;
|
|
253
253
|
n.scroll({ top: d, left: L, behavior: "smooth" });
|
|
254
254
|
}, Vt = (t, e) => (n, r) => {
|
|
255
255
|
const o = typeof n == "string" ? n : n.id, s = r ? typeof r == "string" ? document.getElementById(r) : r : ct(t);
|
|
@@ -290,7 +290,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
290
290
|
B ? i.current !== B.id && (t.classList.add("hovered"), i.set(B.id)) : i.current && (t.classList.remove("hovered"), i.set(null));
|
|
291
291
|
}, 10);
|
|
292
292
|
t.addEventListener("pointermove", u);
|
|
293
|
-
const
|
|
293
|
+
const m = $((S = !1) => requestAnimationFrame(() => {
|
|
294
294
|
f && f.clear();
|
|
295
295
|
const A = Xt(t), { minX: T, minY: B, maxX: y, maxY: v } = A, I = l ? o.getIntersecting(T, B, y, v).filter(({ annotation: O }) => l(O)) : o.getIntersecting(T, B, y, v), D = s.selected.map(({ id: O }) => O), M = I.map(({ annotation: O, rects: H }) => {
|
|
296
296
|
const k = D.includes(O.id), U = O.id === i.current;
|
|
@@ -302,29 +302,29 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
302
302
|
});
|
|
303
303
|
r.redraw(M, A, c, f, S), setTimeout(() => p(I.map(({ annotation: O }) => O)), 1);
|
|
304
304
|
}), 10), d = (S) => {
|
|
305
|
-
f = S,
|
|
305
|
+
f = S, m();
|
|
306
306
|
}, L = (S) => {
|
|
307
|
-
c = S,
|
|
307
|
+
c = S, m();
|
|
308
308
|
}, w = (S) => {
|
|
309
|
-
l = S,
|
|
310
|
-
}, x = () =>
|
|
309
|
+
l = S, m(!1);
|
|
310
|
+
}, x = () => m();
|
|
311
311
|
o.observe(x);
|
|
312
|
-
const R = s.subscribe(() =>
|
|
312
|
+
const R = s.subscribe(() => m()), C = i.subscribe(() => m()), N = () => m(!0);
|
|
313
313
|
document.addEventListener("scroll", N, { capture: !0, passive: !0 });
|
|
314
314
|
const E = $(() => {
|
|
315
|
-
o.recalculatePositions(), f == null || f.reset(),
|
|
315
|
+
o.recalculatePositions(), f == null || f.reset(), m();
|
|
316
316
|
}, 10);
|
|
317
317
|
window.addEventListener("resize", E);
|
|
318
318
|
const a = new ResizeObserver(E);
|
|
319
319
|
a.observe(t);
|
|
320
|
-
const
|
|
321
|
-
S.every((T) => T.target === t || t.contains(T.target)) ||
|
|
320
|
+
const g = { attributes: !0, childList: !0, subtree: !0 }, b = new MutationObserver($((S) => {
|
|
321
|
+
S.every((T) => T.target === t || t.contains(T.target)) || m(!0);
|
|
322
322
|
}, 150));
|
|
323
|
-
return b.observe(document.body,
|
|
323
|
+
return b.observe(document.body, g), {
|
|
324
324
|
destroy: () => {
|
|
325
325
|
t.removeEventListener("pointermove", u), r.destroy(), o.unobserve(x), R(), C(), document.removeEventListener("scroll", N), E.clear(), window.removeEventListener("resize", E), a.disconnect(), b.disconnect();
|
|
326
326
|
},
|
|
327
|
-
redraw:
|
|
327
|
+
redraw: m,
|
|
328
328
|
setStyle: L,
|
|
329
329
|
setFilter: w,
|
|
330
330
|
setPainter: d,
|
|
@@ -340,27 +340,27 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
340
340
|
const e = qt(), n = e.getContext("2d");
|
|
341
341
|
document.body.appendChild(e);
|
|
342
342
|
const r = (c, l, f, p) => requestAnimationFrame(() => {
|
|
343
|
-
const { width: u, height:
|
|
344
|
-
n.clearRect(-0.5, -0.5, u + 1,
|
|
343
|
+
const { width: u, height: m } = e;
|
|
344
|
+
n.clearRect(-0.5, -0.5, u + 1, m + 1), p && p.clear();
|
|
345
345
|
const { top: d, left: L } = l;
|
|
346
346
|
[...c].sort((x, R) => {
|
|
347
347
|
const { annotation: { target: { created: C } } } = x, { annotation: { target: { created: N } } } = R;
|
|
348
348
|
return C.getTime() - N.getTime();
|
|
349
349
|
}).forEach((x) => {
|
|
350
350
|
var E;
|
|
351
|
-
const R = f ? typeof f == "function" ? f(x.annotation, x.state) : f : (E = x.state) != null && E.selected ? j : _, C = p && p.paint(x, l) || R, N = x.rects.map(({ x: a, y:
|
|
351
|
+
const R = f ? typeof f == "function" ? f(x.annotation, x.state) : f : (E = x.state) != null && E.selected ? j : _, C = p && p.paint(x, l) || R, N = x.rects.map(({ x: a, y: g, width: b, height: h }) => ({
|
|
352
352
|
x: a + L,
|
|
353
|
-
y:
|
|
353
|
+
y: g + d,
|
|
354
354
|
width: b,
|
|
355
355
|
height: h
|
|
356
356
|
}));
|
|
357
357
|
if (n.fillStyle = C.fill, n.globalAlpha = C.fillOpacity || 1, N.forEach(
|
|
358
|
-
({ x: a, y:
|
|
358
|
+
({ x: a, y: g, width: b, height: h }) => n.fillRect(a, g, b, h)
|
|
359
359
|
), C.underlineColor) {
|
|
360
360
|
n.globalAlpha = 1, n.strokeStyle = C.underlineColor, n.lineWidth = C.underlineThickness ?? 1;
|
|
361
361
|
const a = C.underlineOffset ?? 0;
|
|
362
|
-
N.forEach(({ x:
|
|
363
|
-
n.beginPath(), n.moveTo(
|
|
362
|
+
N.forEach(({ x: g, y: b, width: h, height: S }) => {
|
|
363
|
+
n.beginPath(), n.moveTo(g, b + S + a), n.lineTo(g + h, b + S + a), n.stroke();
|
|
364
364
|
});
|
|
365
365
|
}
|
|
366
366
|
});
|
|
@@ -397,12 +397,12 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
397
397
|
Array.from(e).filter((u) => !f.has(u));
|
|
398
398
|
const p = s.map((u) => {
|
|
399
399
|
var L;
|
|
400
|
-
const
|
|
400
|
+
const m = c ? typeof c == "function" ? c(u.annotation, u.state) : c : (L = u.state) != null && L.selected ? j : _, d = l && l.paint(u, i) || m;
|
|
401
401
|
return `::highlight(_${u.annotation.id}) { ${Zt(d)} }`;
|
|
402
402
|
});
|
|
403
403
|
t.innerHTML = p.join(`
|
|
404
404
|
`), CSS.highlights.clear(), s.forEach(({ annotation: u }) => {
|
|
405
|
-
const
|
|
405
|
+
const m = u.target.selector.map((L) => L.range), d = new Highlight(...m);
|
|
406
406
|
CSS.highlights.set(`_${u.id}`, d);
|
|
407
407
|
}), e = f;
|
|
408
408
|
}
|
|
@@ -420,15 +420,15 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
420
420
|
e.remove();
|
|
421
421
|
},
|
|
422
422
|
redraw: (i, c, l, f, p) => {
|
|
423
|
-
const
|
|
424
|
-
if (!f && !
|
|
425
|
-
|
|
423
|
+
const m = !(gt(n, i) && p);
|
|
424
|
+
if (!f && !m) return;
|
|
425
|
+
m && (e.innerHTML = ""), [...i].sort((L, w) => {
|
|
426
426
|
const { annotation: { target: { created: x } } } = L, { annotation: { target: { created: R } } } = w;
|
|
427
427
|
return x && R ? x.getTime() - R.getTime() : 0;
|
|
428
428
|
}).forEach((L) => {
|
|
429
429
|
L.rects.map((w) => {
|
|
430
430
|
const x = ne(w, i), R = Yt(L, c, l, f, x);
|
|
431
|
-
if (
|
|
431
|
+
if (m) {
|
|
432
432
|
const C = document.createElement("span");
|
|
433
433
|
C.className = "r6o-annotation", C.dataset.annotation = L.annotation.id, C.style.left = `${w.x}px`, C.style.top = `${w.y}px`, C.style.width = `${w.width}px`, C.style.height = `${w.height}px`, C.style.backgroundColor = ee(R), R.underlineStyle && (C.style.borderStyle = R.underlineStyle), R.underlineColor && (C.style.borderColor = R.underlineColor), R.underlineThickness && (C.style.borderBottomWidth = `${R.underlineThickness}px`), R.underlineOffset && (C.style.paddingBottom = `${R.underlineOffset}px`), e.appendChild(C);
|
|
434
434
|
}
|
|
@@ -462,13 +462,13 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
462
462
|
styleClass: "styleClass" in i[0] ? i[0].styleClass : void 0
|
|
463
463
|
};
|
|
464
464
|
for (const l of i) {
|
|
465
|
-
const p = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((u,
|
|
466
|
-
switch (
|
|
465
|
+
const p = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((u, m) => {
|
|
466
|
+
switch (m.type) {
|
|
467
467
|
case "TextQuoteSelector":
|
|
468
|
-
u.quote =
|
|
468
|
+
u.quote = m.exact;
|
|
469
469
|
break;
|
|
470
470
|
case "TextPositionSelector":
|
|
471
|
-
u.start =
|
|
471
|
+
u.start = m.start, u.end = m.end;
|
|
472
472
|
break;
|
|
473
473
|
}
|
|
474
474
|
return u;
|
|
@@ -514,8 +514,8 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
514
514
|
created: l,
|
|
515
515
|
updated: f,
|
|
516
516
|
...p
|
|
517
|
-
} = o, u = i.map((
|
|
518
|
-
const { id: d, quote: L, start: w, end: x, range: R } =
|
|
517
|
+
} = o, u = i.map((m) => {
|
|
518
|
+
const { id: d, quote: L, start: w, end: x, range: R } = m, C = {
|
|
519
519
|
type: "TextQuoteSelector",
|
|
520
520
|
exact: L
|
|
521
521
|
};
|
|
@@ -532,7 +532,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
532
532
|
...p,
|
|
533
533
|
id: d,
|
|
534
534
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
535
|
-
scope: "scope" in
|
|
535
|
+
scope: "scope" in m ? m.scope : void 0,
|
|
536
536
|
source: e,
|
|
537
537
|
selector: [C, N]
|
|
538
538
|
};
|
|
@@ -549,11 +549,11 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
549
549
|
target: u
|
|
550
550
|
};
|
|
551
551
|
}, le = (t, e, n, r) => {
|
|
552
|
-
const o = new xt(), s = /* @__PURE__ */ new Map(), i = Tt(), c = (a,
|
|
552
|
+
const o = new xt(), s = /* @__PURE__ */ new Map(), i = Tt(), c = (a, g) => {
|
|
553
553
|
const b = a.selector.flatMap((S) => {
|
|
554
554
|
const A = P([S]) ? S.range : at(S, e).range;
|
|
555
555
|
return It(A);
|
|
556
|
-
}), h = Ft(b, n, r).map((S) =>
|
|
556
|
+
}), h = Ft(b, n, r).map((S) => $t(S, g));
|
|
557
557
|
return h.map((S) => {
|
|
558
558
|
const { x: A, y: T, width: B, height: y } = S;
|
|
559
559
|
return {
|
|
@@ -570,42 +570,42 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
570
570
|
}, l = () => [...s.values()], f = () => {
|
|
571
571
|
o.clear(), s.clear();
|
|
572
572
|
}, p = (a) => {
|
|
573
|
-
const
|
|
574
|
-
|
|
573
|
+
const g = c(a, e.getBoundingClientRect());
|
|
574
|
+
g.length !== 0 && (g.forEach((b) => o.insert(b)), s.set(a.annotation, g));
|
|
575
575
|
}, u = (a) => {
|
|
576
|
-
const
|
|
577
|
-
|
|
578
|
-
},
|
|
576
|
+
const g = s.get(a.annotation);
|
|
577
|
+
g && (g.forEach((b) => o.remove(b)), s.delete(a.annotation));
|
|
578
|
+
}, m = (a) => {
|
|
579
579
|
u(a), p(a);
|
|
580
|
-
}, d = (a,
|
|
581
|
-
|
|
580
|
+
}, d = (a, g = !0) => {
|
|
581
|
+
g && f();
|
|
582
582
|
const b = e.getBoundingClientRect(), h = a.map((A) => ({ target: A, rects: c(A, b) }));
|
|
583
583
|
h.forEach(({ target: A, rects: T }) => {
|
|
584
584
|
T.length > 0 && s.set(A.annotation, T);
|
|
585
585
|
});
|
|
586
586
|
const S = h.flatMap(({ rects: A }) => A);
|
|
587
587
|
o.load(S);
|
|
588
|
-
}, L = (a,
|
|
588
|
+
}, L = (a, g, b = !1) => {
|
|
589
589
|
const h = o.search({
|
|
590
590
|
minX: a,
|
|
591
|
-
minY:
|
|
591
|
+
minY: g,
|
|
592
592
|
maxX: a,
|
|
593
|
-
maxY:
|
|
593
|
+
maxY: g
|
|
594
594
|
}), S = (A) => A.annotation.rects.reduce((T, B) => T + B.width * B.height, 0);
|
|
595
595
|
return h.length > 0 ? (h.sort((A, T) => S(A) - S(T)), b ? h.map((A) => A.annotation.id) : [h[0].annotation.id]) : [];
|
|
596
596
|
}, w = (a) => {
|
|
597
|
-
const
|
|
598
|
-
if (
|
|
597
|
+
const g = x(a);
|
|
598
|
+
if (g.length === 0)
|
|
599
599
|
return;
|
|
600
|
-
let b =
|
|
601
|
-
for (let T = 1; T <
|
|
602
|
-
const B =
|
|
600
|
+
let b = g[0].left, h = g[0].top, S = g[0].right, A = g[0].bottom;
|
|
601
|
+
for (let T = 1; T < g.length; T++) {
|
|
602
|
+
const B = g[T];
|
|
603
603
|
b = Math.min(b, B.left), h = Math.min(h, B.top), S = Math.max(S, B.right), A = Math.max(A, B.bottom);
|
|
604
604
|
}
|
|
605
605
|
return new DOMRect(b, h, S - b, A - h);
|
|
606
606
|
}, x = (a) => {
|
|
607
|
-
const
|
|
608
|
-
return
|
|
607
|
+
const g = s.get(a);
|
|
608
|
+
return g ? g[0].annotation.rects : [];
|
|
609
609
|
};
|
|
610
610
|
return {
|
|
611
611
|
all: l,
|
|
@@ -613,8 +613,8 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
613
613
|
getAt: L,
|
|
614
614
|
getAnnotationBounds: w,
|
|
615
615
|
getAnnotationRects: x,
|
|
616
|
-
getIntersecting: (a,
|
|
617
|
-
const S = o.search({ minX: a, minY:
|
|
616
|
+
getIntersecting: (a, g, b, h) => {
|
|
617
|
+
const S = o.search({ minX: a, minY: g, maxX: b, maxY: h }), A = new Set(S.map((T) => T.annotation.id));
|
|
618
618
|
return Array.from(A).map((T) => ({
|
|
619
619
|
annotation: t.getAnnotation(T),
|
|
620
620
|
rects: x(T)
|
|
@@ -627,38 +627,38 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
627
627
|
remove: u,
|
|
628
628
|
set: d,
|
|
629
629
|
size: () => o.all().length,
|
|
630
|
-
update:
|
|
631
|
-
on: (a,
|
|
630
|
+
update: m,
|
|
631
|
+
on: (a, g) => i.on(a, g)
|
|
632
632
|
};
|
|
633
633
|
}, de = (t, e) => {
|
|
634
634
|
var C, N;
|
|
635
635
|
const n = bt(), r = le(n, t, (C = e.mergeHighlights) == null ? void 0 : C.horizontalTolerance, (N = e.mergeHighlights) == null ? void 0 : N.verticalTolerance), o = yt(n, e.userSelectAction, e.adapter), s = St(n), i = Ct(), c = (E, a = K.LOCAL) => {
|
|
636
|
-
const
|
|
637
|
-
return b && n.addAnnotation(
|
|
638
|
-
}, l = (E, a = !0,
|
|
639
|
-
const b = E.map((S) =>
|
|
640
|
-
return n.bulkAddAnnotations(b, a,
|
|
636
|
+
const g = Q(E, t), b = P(g.target.selector);
|
|
637
|
+
return b && n.addAnnotation(g, a), b;
|
|
638
|
+
}, l = (E, a = !0, g = K.LOCAL) => {
|
|
639
|
+
const b = E.map((S) => Q(S, t)), h = b.filter((S) => !P(S.target.selector));
|
|
640
|
+
return n.bulkAddAnnotations(b, a, g), h;
|
|
641
641
|
}, f = (E, a = K.LOCAL) => {
|
|
642
|
-
const
|
|
643
|
-
return
|
|
642
|
+
const g = E.map((h) => Q(h, t)), b = g.filter((h) => !P(h.target.selector));
|
|
643
|
+
return g.forEach((h) => {
|
|
644
644
|
n.getAnnotation(h.id) ? n.updateAnnotation(h, a) : n.addAnnotation(h, a);
|
|
645
645
|
}), b;
|
|
646
646
|
}, p = (E, a = K.LOCAL) => {
|
|
647
|
-
const
|
|
648
|
-
n.updateTarget(
|
|
647
|
+
const g = q(E, t);
|
|
648
|
+
n.updateTarget(g, a);
|
|
649
649
|
}, u = (E, a = K.LOCAL) => {
|
|
650
|
-
const
|
|
651
|
-
n.bulkUpdateTargets(
|
|
650
|
+
const g = E.map((b) => q(b, t));
|
|
651
|
+
n.bulkUpdateTargets(g, a);
|
|
652
652
|
};
|
|
653
|
-
function
|
|
654
|
-
const h =
|
|
653
|
+
function m(E, a, g, b) {
|
|
654
|
+
const h = g || !!b, S = r.getAt(E, a, h).map((T) => n.getAnnotation(T)), A = b ? S.filter(b) : S;
|
|
655
655
|
if (A.length !== 0)
|
|
656
|
-
return
|
|
656
|
+
return g ? A : A[0];
|
|
657
657
|
}
|
|
658
|
-
const d = (E) => r.getAnnotationRects(E).length > 0 ? r.getAnnotationBounds(E) : void 0, L = (E, a,
|
|
658
|
+
const d = (E) => r.getAnnotationRects(E).length > 0 ? r.getAnnotationBounds(E) : void 0, L = (E, a, g, b) => r.getIntersecting(E, a, g, b), w = (E) => r.getAnnotationRects(E), x = () => r.recalculate(), R = (E) => r.on("recalculate", E);
|
|
659
659
|
return n.observe(({ changes: E }) => {
|
|
660
|
-
const a = (E.deleted || []).filter((h) => P(h.target.selector)),
|
|
661
|
-
(a == null ? void 0 : a.length) > 0 && a.forEach((h) => r.remove(h.target)),
|
|
660
|
+
const a = (E.deleted || []).filter((h) => P(h.target.selector)), g = (E.created || []).filter((h) => P(h.target.selector)), b = (E.updated || []).filter((h) => P(h.newValue.target.selector));
|
|
661
|
+
(a == null ? void 0 : a.length) > 0 && a.forEach((h) => r.remove(h.target)), g.length > 0 && r.set(g.map((h) => h.target), !1), (b == null ? void 0 : b.length) > 0 && b.forEach(({ newValue: h }) => r.update(h.target));
|
|
662
662
|
}), {
|
|
663
663
|
store: {
|
|
664
664
|
...n,
|
|
@@ -669,7 +669,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
669
669
|
getAnnotationBounds: d,
|
|
670
670
|
getAnnotationRects: w,
|
|
671
671
|
getIntersecting: L,
|
|
672
|
-
getAt:
|
|
672
|
+
getAt: m,
|
|
673
673
|
recalculatePositions: x,
|
|
674
674
|
onRecalculatePositions: R,
|
|
675
675
|
updateTarget: p
|
|
@@ -686,7 +686,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
686
686
|
}, ue = (t, e = {}) => {
|
|
687
687
|
const n = fe(), r = n.getContext("2d");
|
|
688
688
|
document.body.appendChild(n);
|
|
689
|
-
const o = /* @__PURE__ */ new Map(), s = (p) => Array.from(o.entries()).filter(([u,
|
|
689
|
+
const o = /* @__PURE__ */ new Map(), s = (p) => Array.from(o.entries()).filter(([u, m]) => m.presenceKey === p.presenceKey).map(([u, m]) => u);
|
|
690
690
|
return t.on("selectionChange", (p, u) => {
|
|
691
691
|
s(p).forEach((d) => o.delete(d)), u && u.forEach((d) => o.set(d, p));
|
|
692
692
|
}), {
|
|
@@ -697,7 +697,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
697
697
|
destroy: () => {
|
|
698
698
|
n.remove();
|
|
699
699
|
},
|
|
700
|
-
paint: (p, u,
|
|
700
|
+
paint: (p, u, m) => {
|
|
701
701
|
e.font && (r.font = e.font);
|
|
702
702
|
const d = o.get(p.annotation.id);
|
|
703
703
|
if (d) {
|
|
@@ -706,7 +706,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
706
706
|
const R = r.measureText(d.appearance.label), C = R.width + 6, N = R.actualBoundingBoxAscent + R.actualBoundingBoxDescent + 8, E = R.fontBoundingBoxAscent ? 8 : 6.5;
|
|
707
707
|
return r.fillRect(w - 2, x - 2.5 - N, C, N), r.fillStyle = "#fff", r.fillText(d.appearance.label, w + 1, x - E), {
|
|
708
708
|
fill: d.appearance.color,
|
|
709
|
-
fillOpacity:
|
|
709
|
+
fillOpacity: m ? 0.45 : 0.18
|
|
710
710
|
};
|
|
711
711
|
}
|
|
712
712
|
},
|
|
@@ -729,7 +729,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
729
729
|
dismissOnNotAnnotatable: f = "NEVER"
|
|
730
730
|
} = n, p = (y) => s = y;
|
|
731
731
|
let u;
|
|
732
|
-
const
|
|
732
|
+
const m = (y) => u = y;
|
|
733
733
|
let d, L, w, x = i;
|
|
734
734
|
const R = (y) => {
|
|
735
735
|
x = y, N.clear(), y || (d = void 0, L = void 0, w = void 0);
|
|
@@ -755,7 +755,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
755
755
|
r.getAnnotation(d.annotation) && (o.clear(), r.deleteAnnotation(d.annotation));
|
|
756
756
|
return;
|
|
757
757
|
}
|
|
758
|
-
const M = I.map((k) =>
|
|
758
|
+
const M = I.map((k) => Wt(k, t));
|
|
759
759
|
if (M.every((k) => _t(k))) return;
|
|
760
760
|
const O = M.flatMap((k) => Ht(t, k.cloneRange()));
|
|
761
761
|
(O.length > 0 && !d || O.length !== d.selector.length || O.some((k, U) => {
|
|
@@ -767,10 +767,10 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
767
767
|
updated: /* @__PURE__ */ new Date()
|
|
768
768
|
}, r.getAnnotation(d.annotation) ? r.updateTarget(d, K.LOCAL) : o.clear());
|
|
769
769
|
}, 10), E = (y) => {
|
|
770
|
-
w =
|
|
770
|
+
w = G(y), L = w.button === 0;
|
|
771
771
|
}, a = async (y) => {
|
|
772
772
|
if (!L) return;
|
|
773
|
-
const v =
|
|
773
|
+
const v = G(y), I = () => {
|
|
774
774
|
const { x: M, y: O } = t.getBoundingClientRect();
|
|
775
775
|
if (z(t, v.target)) {
|
|
776
776
|
(typeof f == "function" ? f(v, t) : f === "ALWAYS") && o.clear();
|
|
@@ -789,7 +789,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
789
789
|
o.clear();
|
|
790
790
|
};
|
|
791
791
|
if (v.timeStamp - w.timeStamp < nt) {
|
|
792
|
-
await
|
|
792
|
+
await g();
|
|
793
793
|
const M = document.getSelection(), O = z(t, w.target), H = z(t, v.target);
|
|
794
794
|
if (M != null && M.isCollapsed || O && H) {
|
|
795
795
|
d = void 0, I();
|
|
@@ -797,14 +797,14 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
797
797
|
}
|
|
798
798
|
}
|
|
799
799
|
d && d.selector.length > 0 && (T(), o.userSelect(d.annotation, v));
|
|
800
|
-
},
|
|
800
|
+
}, g = async () => {
|
|
801
801
|
const y = document.getSelection();
|
|
802
802
|
let v = !1, I = y == null ? void 0 : y.isCollapsed;
|
|
803
803
|
const D = () => I || v, M = 1;
|
|
804
804
|
return setTimeout(() => v = !0, 50), Rt(() => I = y == null ? void 0 : y.isCollapsed, M, D);
|
|
805
805
|
}, b = (y) => {
|
|
806
806
|
const v = document.getSelection();
|
|
807
|
-
v != null && v.isCollapsed || ((!d || d.selector.length === 0) && N(y), d && (T(), o.userSelect(d.annotation,
|
|
807
|
+
v != null && v.isCollapsed || ((!d || d.selector.length === 0) && N(y), d && (T(), o.userSelect(d.annotation, G(y))));
|
|
808
808
|
}, h = (y) => {
|
|
809
809
|
x && y.key === "Shift" && d && (document.getSelection().isCollapsed || (T(), o.userSelect(d.annotation, X(y))));
|
|
810
810
|
}, S = (y) => {
|
|
@@ -843,7 +843,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
843
843
|
destroy: () => {
|
|
844
844
|
d = void 0, L = void 0, w = void 0, N.clear(), document.removeEventListener("pointerdown", E), document.removeEventListener("pointerup", a), document.removeEventListener("contextmenu", b), t.removeEventListener("keyup", h), t.removeEventListener("selectstart", C), document.removeEventListener("selectionchange", N), Y.unbind();
|
|
845
845
|
},
|
|
846
|
-
setFilter:
|
|
846
|
+
setFilter: m,
|
|
847
847
|
setUser: p,
|
|
848
848
|
setAnnotatingEnabled: R
|
|
849
849
|
};
|
|
@@ -862,16 +862,16 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
862
862
|
if (!u)
|
|
863
863
|
throw `Unknown renderer implementation: ${p}`;
|
|
864
864
|
console.debug(`Using ${p} renderer`), n.style && u.setStyle(n.style);
|
|
865
|
-
const
|
|
866
|
-
|
|
865
|
+
const m = me(t, r, n);
|
|
866
|
+
m.setUser(f);
|
|
867
867
|
const d = vt(r, c, n.adapter), L = () => f, w = (a) => {
|
|
868
|
-
|
|
868
|
+
m.setAnnotatingEnabled(
|
|
869
869
|
a === void 0 ? !0 : a
|
|
870
870
|
);
|
|
871
871
|
}, x = (a) => {
|
|
872
|
-
u.setFilter(a),
|
|
872
|
+
u.setFilter(a), m.setFilter(a);
|
|
873
873
|
}, R = (a) => {
|
|
874
|
-
f = a,
|
|
874
|
+
f = a, m.setUser(a);
|
|
875
875
|
}, C = (a) => {
|
|
876
876
|
a && (u.setPainter(ue(a, n.presence)), a.on("selectionChange", () => u.redraw()));
|
|
877
877
|
}, N = (a) => {
|
|
@@ -880,7 +880,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
|
880
880
|
return {
|
|
881
881
|
...d,
|
|
882
882
|
destroy: () => {
|
|
883
|
-
u.destroy(),
|
|
883
|
+
u.destroy(), m.destroy(), c.destroy();
|
|
884
884
|
},
|
|
885
885
|
element: t,
|
|
886
886
|
getUser: L,
|
|
@@ -908,7 +908,7 @@ export {
|
|
|
908
908
|
ke as W3CTextFormat,
|
|
909
909
|
Nt as cancelSingleClickEvents,
|
|
910
910
|
X as cloneKeyboardEvent,
|
|
911
|
-
|
|
911
|
+
G as clonePointerEvent,
|
|
912
912
|
_e as createBody,
|
|
913
913
|
Qt as createCanvasRenderer,
|
|
914
914
|
te as createHighlightsRenderer,
|
|
@@ -933,16 +933,16 @@ export {
|
|
|
933
933
|
ae as parseW3CTextAnnotation,
|
|
934
934
|
Bt as programmaticallyFocusable,
|
|
935
935
|
Kt as rangeToSelector,
|
|
936
|
-
|
|
936
|
+
Q as reviveAnnotation,
|
|
937
937
|
at as reviveSelector,
|
|
938
938
|
q as reviveTarget,
|
|
939
939
|
Vt as scrollIntoView,
|
|
940
940
|
ce as serializeW3CTextAnnotation,
|
|
941
941
|
Ht as splitAnnotatableRanges,
|
|
942
942
|
Ne as toDomRectList,
|
|
943
|
-
|
|
943
|
+
$t as toParentBounds,
|
|
944
944
|
Oe as toViewportBounds,
|
|
945
|
-
|
|
945
|
+
Wt as trimRangeToContainer,
|
|
946
946
|
it as whitespaceOrEmptyRegex
|
|
947
947
|
};
|
|
948
948
|
//# sourceMappingURL=text-annotator.es.js.map
|