@recogito/text-annotator 4.0.3-beta → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/core/text-annotation.d.ts +12 -0
- package/dist/rendering/base-renderer.d.ts +2 -2
- package/dist/state/spatial-tree.d.ts +2 -2
- package/dist/state/text-annotation-store.d.ts +3 -3
- package/dist/state/text-annotator-state.d.ts +2 -2
- package/dist/text-annotator-options.d.ts +3 -3
- package/dist/text-annotator.d.ts +3 -3
- package/dist/text-annotator.es.js +300 -295
- 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/annotation/revive-annotation.d.ts +2 -2
- package/package.json +5 -5
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { v4 as lt } from "uuid";
|
|
2
|
-
import { parseW3CBodies as Ct, serializeW3CBodies as
|
|
3
|
-
import { Origin as Be, UserSelectAction as
|
|
2
|
+
import { parseW3CBodies as Ct, serializeW3CBodies as Tt, parseW3CUser as At, UserSelectAction as Rt, createStore as vt, createSelectionState as wt, createHoverState as xt, createViewportState as Lt, Origin as F, createAnonymousGuest as Nt, createUndoStack as Ot, createLifecycleObserver as kt, createBaseAnnotator as Mt } from "@annotorious/core";
|
|
3
|
+
import { Origin as Be, UserSelectAction as _e, createBody as Ie } from "@annotorious/core";
|
|
4
4
|
import { createNanoEvents as dt } from "nanoevents";
|
|
5
5
|
import { colord as et } from "colord";
|
|
6
6
|
import { dequal as Bt } from "dequal/lite";
|
|
7
|
-
import
|
|
8
|
-
import
|
|
7
|
+
import _t from "rbush";
|
|
8
|
+
import It from "debounce";
|
|
9
9
|
import q from "hotkeys-js";
|
|
10
10
|
import { poll as Dt } from "poll";
|
|
11
|
-
const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft = "not-annotatable",
|
|
11
|
+
const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft = "not-annotatable", $ = `.${ft}`, W = (t, e) => t.contains(e) ? !!(e instanceof HTMLElement ? e.closest($) : e.parentElement?.closest($)) : !0, gt = (t, e) => {
|
|
12
12
|
const o = e.commonAncestorContainer;
|
|
13
|
-
return
|
|
13
|
+
return !W(t, o);
|
|
14
14
|
}, mt = /^\s*$/, Ht = (t) => mt.test(t.toString()), we = (t) => mt.test(t.textContent || ""), Pt = (t) => {
|
|
15
15
|
if (t.length === 0) return [];
|
|
16
16
|
if (t.length === 1) return [t[0]];
|
|
@@ -23,10 +23,10 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
23
23
|
}, Ut = (t) => {
|
|
24
24
|
(!t.hasAttribute("tabindex") || t.tabIndex < -1) && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
|
|
25
25
|
}, Kt = function* (t) {
|
|
26
|
-
const e = document.
|
|
26
|
+
const e = document.createTreeWalker(
|
|
27
27
|
t.commonAncestorContainer,
|
|
28
28
|
NodeFilter.SHOW_ELEMENT,
|
|
29
|
-
(i) => i instanceof HTMLElement && i.classList.contains(ft) && !i.parentElement?.closest(
|
|
29
|
+
(i) => i instanceof HTMLElement && i.classList.contains(ft) && !i.parentElement?.closest($) && t.intersectsNode(i) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
|
30
30
|
);
|
|
31
31
|
let o;
|
|
32
32
|
for (; o = e.nextNode(); )
|
|
@@ -46,54 +46,54 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
46
46
|
return o.length > 0 ? o : [e];
|
|
47
47
|
}, nt = (t) => {
|
|
48
48
|
const e = t.cloneContents();
|
|
49
|
-
return e.querySelectorAll(
|
|
50
|
-
},
|
|
49
|
+
return e.querySelectorAll($).forEach((o) => o.remove()), e;
|
|
50
|
+
}, Wt = (t, e) => {
|
|
51
51
|
const o = t.cloneRange();
|
|
52
52
|
return e.contains(o.startContainer) || o.setStart(e, 0), e.contains(o.endContainer) || o.setEnd(e, e.childNodes.length), o;
|
|
53
|
-
}, rt = new Intl.Segmenter(void 0, { granularity: "grapheme" }),
|
|
53
|
+
}, rt = new Intl.Segmenter(void 0, { granularity: "grapheme" }), $t = (t, e, o = 10, i) => {
|
|
54
54
|
const s = i ? t.startContainer.parentElement.closest(i) : e, n = document.createRange();
|
|
55
55
|
n.setStart(s, 0), n.setEnd(t.startContainer, t.startOffset);
|
|
56
56
|
const r = nt(n).textContent, a = document.createRange();
|
|
57
57
|
a.setStart(t.endContainer, t.endOffset), s === document.body ? a.setEnd(s, s.childNodes.length) : a.setEndAfter(s);
|
|
58
|
-
const
|
|
58
|
+
const l = nt(a).textContent, m = [...rt.segment(r)], g = [...rt.segment(l)];
|
|
59
59
|
return {
|
|
60
|
-
prefix:
|
|
61
|
-
suffix:
|
|
60
|
+
prefix: m.slice(-o).map((E) => E.segment).join(""),
|
|
61
|
+
suffix: g.slice(0, o).map((E) => E.segment).join("")
|
|
62
62
|
};
|
|
63
|
-
},
|
|
63
|
+
}, Yt = (t, e, o) => {
|
|
64
64
|
const i = document.createRange(), s = o ? t.startContainer.parentElement.closest(o) : e;
|
|
65
65
|
i.setStart(s, 0), i.setEnd(t.startContainer, t.startOffset);
|
|
66
|
-
const n = nt(i).textContent, r = t.toString(), a = n.length || 0,
|
|
67
|
-
return o ? { quote: r, start: a, end:
|
|
66
|
+
const n = nt(i).textContent, r = t.toString(), a = n.length || 0, l = a + r.length;
|
|
67
|
+
return o ? { quote: r, start: a, end: l, range: t, offsetReference: s } : { quote: r, start: a, end: l, range: t };
|
|
68
68
|
}, D = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), pt = (t, e) => {
|
|
69
|
-
const { start: o, end: i } = t, s = t.offsetReference || e, n = document.
|
|
69
|
+
const { start: o, end: i } = t, s = t.offsetReference || e, n = document.createTreeWalker(
|
|
70
70
|
e,
|
|
71
71
|
NodeFilter.SHOW_TEXT,
|
|
72
|
-
(
|
|
72
|
+
(g) => g.parentElement?.closest($) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT
|
|
73
73
|
);
|
|
74
74
|
let r = 0;
|
|
75
75
|
const a = document.createRange();
|
|
76
|
-
let
|
|
77
|
-
|
|
78
|
-
let
|
|
79
|
-
for (;
|
|
80
|
-
if (
|
|
81
|
-
const
|
|
82
|
-
if (r +
|
|
83
|
-
a.setStart(
|
|
76
|
+
let l = n.nextNode();
|
|
77
|
+
l === null && console.error("Could not revive annotation target. Content missing.");
|
|
78
|
+
let m = !s;
|
|
79
|
+
for (; l !== null; ) {
|
|
80
|
+
if (m ||= typeof s?.contains == "function" ? s.contains(l) : !1, m) {
|
|
81
|
+
const g = l.textContent?.length || 0;
|
|
82
|
+
if (r + g > o) {
|
|
83
|
+
a.setStart(l, o - r);
|
|
84
84
|
break;
|
|
85
85
|
}
|
|
86
|
-
r +=
|
|
86
|
+
r += g;
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
l = n.nextNode();
|
|
89
89
|
}
|
|
90
|
-
for (;
|
|
91
|
-
const
|
|
92
|
-
if (r +
|
|
93
|
-
a.setEnd(
|
|
90
|
+
for (; l !== null; ) {
|
|
91
|
+
const g = l.textContent?.length || 0;
|
|
92
|
+
if (r + g >= i) {
|
|
93
|
+
a.setEnd(l, i - r);
|
|
94
94
|
break;
|
|
95
95
|
}
|
|
96
|
-
r +=
|
|
96
|
+
r += g, l = n.nextNode();
|
|
97
97
|
}
|
|
98
98
|
return {
|
|
99
99
|
...t,
|
|
@@ -108,8 +108,8 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
108
108
|
const { overflowY: e } = window.getComputedStyle(t);
|
|
109
109
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ht(t.parentElement);
|
|
110
110
|
}, it = (t, e, o) => {
|
|
111
|
-
const i = o.getBoundingClientRect(), s = o.clientHeight, n = o.clientWidth, r = e.selector[0].range.getBoundingClientRect(), { width: a, height:
|
|
112
|
-
o.scroll({ top:
|
|
111
|
+
const i = o.getBoundingClientRect(), s = o.clientHeight, n = o.clientWidth, r = e.selector[0].range.getBoundingClientRect(), { width: a, height: l } = t.getAnnotationBounds(e.annotation), m = r.top - i.top, g = r.left - i.left, E = o.parentElement ? o.scrollTop : 0, h = o.parentElement ? o.scrollLeft : 0, A = m + E - (s - l) / 2, d = g + h - (n - a) / 2;
|
|
112
|
+
o.scroll({ top: A, left: d, behavior: "smooth" });
|
|
113
113
|
}, Xt = (t, e) => (o, i) => {
|
|
114
114
|
const s = typeof o == "string" ? o : o.id, n = i ? typeof i == "string" ? document.getElementById(i) : i : ht(t);
|
|
115
115
|
if (!n)
|
|
@@ -120,8 +120,8 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
120
120
|
const { range: a } = r.target.selector[0];
|
|
121
121
|
if (a && !a.collapsed)
|
|
122
122
|
return it(e, r.target, n), !0;
|
|
123
|
-
const
|
|
124
|
-
return
|
|
123
|
+
const l = Q(r.target, t), { range: m } = l.selector[0];
|
|
124
|
+
return m && !m.collapsed ? (it(e, l, n), !0) : !1;
|
|
125
125
|
}, xe = (t, e) => ({
|
|
126
126
|
parse: (o) => jt(o),
|
|
127
127
|
serialize: (o) => qt(o, t, e)
|
|
@@ -136,7 +136,7 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
136
136
|
if (r.length === 0)
|
|
137
137
|
return { error: Error(`No targets found for annotation: ${t.id}`) };
|
|
138
138
|
const a = {
|
|
139
|
-
creator:
|
|
139
|
+
creator: At(o),
|
|
140
140
|
created: i ? new Date(i) : void 0,
|
|
141
141
|
updated: s ? new Date(s) : void 0,
|
|
142
142
|
annotation: e,
|
|
@@ -144,33 +144,33 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
144
144
|
// @ts-expect-error: `styleClass` is not part of the core `TextAnnotationTarget` type
|
|
145
145
|
styleClass: "styleClass" in r[0] ? r[0].styleClass : void 0
|
|
146
146
|
};
|
|
147
|
-
for (const
|
|
148
|
-
const
|
|
147
|
+
for (const l of r) {
|
|
148
|
+
const g = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((E, h) => {
|
|
149
149
|
switch (h.type) {
|
|
150
150
|
case "TextQuoteSelector":
|
|
151
|
-
|
|
151
|
+
E.quote = h.exact;
|
|
152
152
|
break;
|
|
153
153
|
case "TextPositionSelector":
|
|
154
|
-
|
|
154
|
+
E.start = h.start, E.end = h.end;
|
|
155
155
|
break;
|
|
156
156
|
}
|
|
157
|
-
return
|
|
157
|
+
return E;
|
|
158
158
|
}, {});
|
|
159
|
-
if (Vt(
|
|
159
|
+
if (Vt(g))
|
|
160
160
|
a.selector.push(
|
|
161
161
|
{
|
|
162
|
-
...
|
|
163
|
-
id:
|
|
162
|
+
...g,
|
|
163
|
+
id: l.id,
|
|
164
164
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
165
|
-
scope:
|
|
165
|
+
scope: l.scope
|
|
166
166
|
}
|
|
167
167
|
);
|
|
168
168
|
else {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
const E = [
|
|
170
|
+
g.start ? void 0 : "TextPositionSelector",
|
|
171
|
+
g.quote ? void 0 : "TextQuoteSelector"
|
|
172
172
|
].filter(Boolean);
|
|
173
|
-
return { error: Error(`Missing selector types: ${
|
|
173
|
+
return { error: Error(`Missing selector types: ${E.join(" and ")} for annotation: ${t.id}`) };
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
return { parsed: a };
|
|
@@ -181,43 +181,43 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
181
181
|
modified: s,
|
|
182
182
|
body: n,
|
|
183
183
|
...r
|
|
184
|
-
} = t, a = Ct(n, e),
|
|
185
|
-
return "error" in
|
|
184
|
+
} = t, a = Ct(n, e), l = zt(t);
|
|
185
|
+
return "error" in l ? { error: l.error } : {
|
|
186
186
|
parsed: {
|
|
187
187
|
...r,
|
|
188
188
|
id: e,
|
|
189
189
|
bodies: a,
|
|
190
|
-
target:
|
|
190
|
+
target: l.parsed
|
|
191
191
|
}
|
|
192
192
|
};
|
|
193
193
|
}, qt = (t, e, o) => {
|
|
194
194
|
const { bodies: i, target: s, ...n } = t, {
|
|
195
195
|
selector: r,
|
|
196
196
|
creator: a,
|
|
197
|
-
created:
|
|
198
|
-
updated:
|
|
199
|
-
...
|
|
200
|
-
} = s,
|
|
201
|
-
const { id:
|
|
197
|
+
created: l,
|
|
198
|
+
updated: m,
|
|
199
|
+
...g
|
|
200
|
+
} = s, E = r.map((h) => {
|
|
201
|
+
const { id: A, quote: d, start: L, end: x, range: v } = h, p = {
|
|
202
202
|
type: "TextQuoteSelector",
|
|
203
|
-
exact:
|
|
203
|
+
exact: d
|
|
204
204
|
};
|
|
205
205
|
if (o) {
|
|
206
|
-
const { prefix: w, suffix: c } =
|
|
206
|
+
const { prefix: w, suffix: c } = $t(v, o);
|
|
207
207
|
p.prefix = w, p.suffix = c;
|
|
208
208
|
}
|
|
209
|
-
const
|
|
209
|
+
const b = {
|
|
210
210
|
type: "TextPositionSelector",
|
|
211
211
|
start: L,
|
|
212
212
|
end: x
|
|
213
213
|
};
|
|
214
214
|
return {
|
|
215
|
-
...
|
|
216
|
-
id:
|
|
215
|
+
...g,
|
|
216
|
+
id: A,
|
|
217
217
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
218
218
|
scope: "scope" in h ? h.scope : void 0,
|
|
219
219
|
source: e,
|
|
220
|
-
selector: [p,
|
|
220
|
+
selector: [p, b]
|
|
221
221
|
};
|
|
222
222
|
});
|
|
223
223
|
return {
|
|
@@ -225,15 +225,15 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
225
225
|
"@context": "http://www.w3.org/ns/anno.jsonld",
|
|
226
226
|
id: t.id,
|
|
227
227
|
type: "Annotation",
|
|
228
|
-
body:
|
|
228
|
+
body: Tt(t.bodies),
|
|
229
229
|
creator: a,
|
|
230
|
-
created:
|
|
231
|
-
modified:
|
|
232
|
-
target:
|
|
230
|
+
created: l?.toISOString(),
|
|
231
|
+
modified: m?.toISOString(),
|
|
232
|
+
target: E
|
|
233
233
|
};
|
|
234
234
|
}, Gt = (t) => t.addEventListener("click", (e) => {
|
|
235
235
|
// Allow clicks within not-annotatable elements
|
|
236
|
-
!e.target.closest(
|
|
236
|
+
!e.target.closest($) && !e.target.closest("a") && e.preventDefault();
|
|
237
237
|
}), J = (t) => ({
|
|
238
238
|
...t,
|
|
239
239
|
type: t.type,
|
|
@@ -283,58 +283,58 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
283
283
|
});
|
|
284
284
|
}, yt = (t, e, o, i) => {
|
|
285
285
|
const { store: s, selection: n, hover: r } = o, a = dt();
|
|
286
|
-
let
|
|
287
|
-
const
|
|
288
|
-
let
|
|
289
|
-
const
|
|
290
|
-
const { x: C, y: O } = e.getBoundingClientRect(), B = s.getAt(S.clientX - C, S.clientY - O, !1,
|
|
286
|
+
let l;
|
|
287
|
+
const m = /* @__PURE__ */ new Map();
|
|
288
|
+
let g;
|
|
289
|
+
const E = ae(i), h = (S) => {
|
|
290
|
+
const { x: C, y: O } = e.getBoundingClientRect(), B = s.getAt(S.clientX - C, S.clientY - O, !1, g);
|
|
291
291
|
B && o.selection.evalSelectAction(B) !== Rt.NONE ? r.current !== B.id && (e.classList.add("hovered"), r.set(B.id)) : r.current && (e.classList.remove("hovered"), r.set(null));
|
|
292
292
|
};
|
|
293
293
|
e.addEventListener("pointermove", h);
|
|
294
|
-
const
|
|
295
|
-
const C = ie(e), { minX: O, minY: B, maxX: V, maxY: z } = C, K =
|
|
296
|
-
const U = st.includes(y.id),
|
|
294
|
+
const A = tt((S = !1) => requestAnimationFrame(() => {
|
|
295
|
+
const C = ie(e), { minX: O, minY: B, maxX: V, maxY: z } = C, K = g ? s.getIntersecting(O, B, V, z).filter(({ annotation: y }) => g?.(y)) : s.getIntersecting(O, B, V, z), st = n.selected.map(({ id: y }) => y), f = K.map(({ annotation: y, rects: M }) => {
|
|
296
|
+
const U = st.includes(y.id), _ = y.id === r.current;
|
|
297
297
|
return {
|
|
298
298
|
annotation: y,
|
|
299
299
|
rects: M,
|
|
300
|
-
state: { selected: U, hovered:
|
|
300
|
+
state: { selected: U, hovered: _ }
|
|
301
301
|
};
|
|
302
302
|
});
|
|
303
|
-
t.redraw(f, C,
|
|
304
|
-
|
|
303
|
+
t.redraw(f, C, l, m, S), setTimeout(() => {
|
|
304
|
+
E(K.map(({ annotation: y }) => y)), a.emit("onRedraw");
|
|
305
305
|
}, 1);
|
|
306
|
-
}), 10),
|
|
307
|
-
C ? S ?
|
|
306
|
+
}), 10), d = (S, C) => {
|
|
307
|
+
C ? S ? m.set(C, S) : m.delete(C) : l = S, A(!0);
|
|
308
308
|
}, L = (S) => {
|
|
309
|
-
|
|
309
|
+
g = S, A(!1);
|
|
310
310
|
}, x = (S, C) => a.on(S, C), v = () => {
|
|
311
|
-
|
|
311
|
+
A();
|
|
312
312
|
};
|
|
313
313
|
s.observe(v);
|
|
314
314
|
const p = n.subscribe(() => {
|
|
315
|
-
|
|
316
|
-
}),
|
|
317
|
-
|
|
315
|
+
A();
|
|
316
|
+
}), b = r.subscribe(() => {
|
|
317
|
+
A();
|
|
318
318
|
}), w = () => {
|
|
319
|
-
|
|
319
|
+
A(!0);
|
|
320
320
|
};
|
|
321
321
|
document.addEventListener("scroll", w, { capture: !0, passive: !0 });
|
|
322
322
|
const c = tt(() => {
|
|
323
|
-
s.recalculatePositions(),
|
|
323
|
+
s.recalculatePositions(), A();
|
|
324
324
|
}, 10);
|
|
325
325
|
window.addEventListener("resize", c);
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
const
|
|
329
|
-
S.every((O) => O.target === e || e.contains(O.target)) ||
|
|
326
|
+
const u = new ResizeObserver(c);
|
|
327
|
+
u.observe(e);
|
|
328
|
+
const T = { attributes: !0, childList: !0, subtree: !0 }, R = new MutationObserver(tt((S) => {
|
|
329
|
+
S.every((O) => O.target === e || e.contains(O.target)) || A(!0);
|
|
330
330
|
}, 150));
|
|
331
|
-
return R.observe(document.body,
|
|
331
|
+
return R.observe(document.body, T), {
|
|
332
332
|
destroy: () => {
|
|
333
|
-
e.removeEventListener("pointermove", h), t.destroy(), s.unobserve(v), p(),
|
|
333
|
+
e.removeEventListener("pointermove", h), t.destroy(), s.unobserve(v), p(), b(), document.removeEventListener("scroll", w), window.removeEventListener("resize", c), u.disconnect(), R.disconnect();
|
|
334
334
|
},
|
|
335
335
|
on: x,
|
|
336
|
-
redraw:
|
|
337
|
-
setStyle:
|
|
336
|
+
redraw: A,
|
|
337
|
+
setStyle: d,
|
|
338
338
|
setFilter: L,
|
|
339
339
|
setVisible: t.setVisible.bind(t)
|
|
340
340
|
};
|
|
@@ -348,38 +348,42 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
348
348
|
const o = (n, r) => n.x <= r.x + r.width && n.x + n.width >= r.x && n.y <= r.y + r.height && n.y + n.height >= r.y, i = (n) => n.rects.reduce((r, a) => r + a.width, 0), s = e.filter(({ rects: n }) => n.some((r) => o(t, r)));
|
|
349
349
|
return s.sort((n, r) => i(r) - i(n)), s.findIndex((n) => n.rects.includes(t));
|
|
350
350
|
}, Jt = (t) => {
|
|
351
|
-
const e = [], o = document.
|
|
351
|
+
const e = [], o = document.createTreeWalker(
|
|
352
352
|
t.commonAncestorContainer,
|
|
353
353
|
NodeFilter.SHOW_TEXT
|
|
354
354
|
);
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
355
|
+
t.startContainer.nodeType === Node.TEXT_NODE && (o.currentNode = t.startContainer, t.intersectsNode(t.startContainer) && e.push(t.startContainer));
|
|
356
|
+
let i = e.length > 0, s;
|
|
357
|
+
for (; s = o.nextNode(); )
|
|
358
|
+
if (t.intersectsNode(s))
|
|
359
|
+
i = !0, e.push(s);
|
|
360
|
+
else if (i)
|
|
361
|
+
break;
|
|
358
362
|
if (e.length < 2)
|
|
359
363
|
return Array.from(t.getClientRects());
|
|
360
364
|
{
|
|
361
|
-
const
|
|
362
|
-
if (
|
|
363
|
-
|
|
365
|
+
const n = e[0], r = e[e.length - 1], a = document.createRange();
|
|
366
|
+
if (a.selectNode(n), t.startContainer.nodeType === Node.TEXT_NODE)
|
|
367
|
+
a.setStart(n, t.startOffset);
|
|
364
368
|
else {
|
|
365
369
|
const g = t.startContainer.childNodes[t.startOffset];
|
|
366
|
-
g ?
|
|
370
|
+
g ? a.setStartBefore(g) : a.setStartAfter(t.startContainer);
|
|
367
371
|
}
|
|
368
|
-
const
|
|
369
|
-
if (
|
|
370
|
-
|
|
372
|
+
const l = document.createRange();
|
|
373
|
+
if (l.selectNode(r), t.endContainer.nodeType === Node.TEXT_NODE)
|
|
374
|
+
l.setEnd(r, t.endOffset);
|
|
371
375
|
else {
|
|
372
376
|
const g = t.endContainer.childNodes[t.endOffset];
|
|
373
|
-
g ?
|
|
377
|
+
g ? l.setEndBefore(g) : l.setEndAfter(t.endContainer);
|
|
374
378
|
}
|
|
375
|
-
const
|
|
376
|
-
const
|
|
377
|
-
return
|
|
379
|
+
const m = (g) => {
|
|
380
|
+
const E = document.createRange();
|
|
381
|
+
return E.selectNode(g), Array.from(E.getClientRects());
|
|
378
382
|
};
|
|
379
383
|
return [
|
|
380
|
-
...Array.from(
|
|
381
|
-
...e.slice(1, -1).flatMap(
|
|
382
|
-
...Array.from(
|
|
384
|
+
...Array.from(a.getClientRects()),
|
|
385
|
+
...e.slice(1, -1).flatMap(m),
|
|
386
|
+
...Array.from(l.getClientRects())
|
|
383
387
|
];
|
|
384
388
|
}
|
|
385
389
|
}, te = (t, e, o, i) => {
|
|
@@ -414,18 +418,18 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
414
418
|
return i;
|
|
415
419
|
let n = [...i], r = !1;
|
|
416
420
|
for (const a of i) {
|
|
417
|
-
const
|
|
418
|
-
if (
|
|
419
|
-
n = n.map((
|
|
421
|
+
const l = te(s, a, e, o);
|
|
422
|
+
if (l === "inline-adjacent") {
|
|
423
|
+
n = n.map((m) => m === a ? ee(s, a) : m), r = !0;
|
|
420
424
|
break;
|
|
421
|
-
} else if (
|
|
422
|
-
n = n.map((
|
|
425
|
+
} else if (l === "inline-contains") {
|
|
426
|
+
n = n.map((m) => m === a ? s : m), r = !0;
|
|
423
427
|
break;
|
|
424
|
-
} else if (
|
|
428
|
+
} else if (l === "inline-is-contained") {
|
|
425
429
|
r = !0;
|
|
426
430
|
break;
|
|
427
|
-
} else if (
|
|
428
|
-
s.width < a.width && (n = n.map((
|
|
431
|
+
} else if (l === "block-contains" || l === "block-is-contained") {
|
|
432
|
+
s.width < a.width && (n = n.map((m) => m === a ? s : m)), s.width === a.width && s.height < a.width && (n = n.map((m) => m === a ? s : m)), r = !0;
|
|
429
433
|
break;
|
|
430
434
|
}
|
|
431
435
|
}
|
|
@@ -452,16 +456,16 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
452
456
|
destroy: () => {
|
|
453
457
|
e.remove();
|
|
454
458
|
},
|
|
455
|
-
redraw: (r, a,
|
|
456
|
-
if (!(!Bt(o, r) ||
|
|
457
|
-
e.innerHTML = "", [...r].sort((
|
|
458
|
-
const { annotation: { target: { created: x } } } =
|
|
459
|
+
redraw: (r, a, l, m, g) => {
|
|
460
|
+
if (!(!Bt(o, r) || g)) return;
|
|
461
|
+
e.innerHTML = "", [...r].sort((d, L) => {
|
|
462
|
+
const { annotation: { target: { created: x } } } = d, { annotation: { target: { created: v } } } = L;
|
|
459
463
|
return x && v ? x.getTime() - v.getTime() : 0;
|
|
460
|
-
}).forEach((
|
|
461
|
-
const L =
|
|
462
|
-
|
|
463
|
-
const v = Zt(x, r), p = St(
|
|
464
|
-
|
|
464
|
+
}).forEach((d) => {
|
|
465
|
+
const L = m?.get(d.annotation.id) || l;
|
|
466
|
+
d.rects.map((x) => {
|
|
467
|
+
const v = Zt(x, r), p = St(d, L, v), b = document.createElement("span");
|
|
468
|
+
b.className = "r6o-annotation", b.dataset.annotation = d.annotation.id, b.style.left = `${x.x}px`, b.style.top = `${x.y}px`, b.style.width = `${x.width}px`, b.style.height = `${x.height}px`, b.style.backgroundColor = Qt(p), p.underlineStyle && (b.style.borderStyle = p.underlineStyle), p.underlineColor && (b.style.borderColor = p.underlineColor), p.underlineThickness && (b.style.borderBottomWidth = `${p.underlineThickness}px`), p.underlineOffset && (b.style.paddingBottom = `${p.underlineOffset}px`), e.appendChild(b);
|
|
465
469
|
});
|
|
466
470
|
}), o = r;
|
|
467
471
|
},
|
|
@@ -470,8 +474,8 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
470
474
|
}
|
|
471
475
|
};
|
|
472
476
|
}, re = (t, e, o) => yt(se(t), t, e, o), ie = (t) => {
|
|
473
|
-
const { top: e, left: o } = t.getBoundingClientRect(), { innerWidth: i, innerHeight: s } = window, n = -o, r = -e, a = i - o,
|
|
474
|
-
return { top: e, left: o, minX: n, minY: r, maxX: a, maxY:
|
|
477
|
+
const { top: e, left: o } = t.getBoundingClientRect(), { innerWidth: i, innerHeight: s } = window, n = -o, r = -e, a = i - o, l = s - e;
|
|
478
|
+
return { top: e, left: o, minX: n, minY: r, maxX: a, maxY: l };
|
|
475
479
|
}, ae = (t) => {
|
|
476
480
|
let e = /* @__PURE__ */ new Set();
|
|
477
481
|
return (i) => {
|
|
@@ -479,11 +483,11 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
479
483
|
(e.size !== s.length || s.some((n) => !e.has(n))) && t.set(s), e = new Set(s);
|
|
480
484
|
};
|
|
481
485
|
}, ce = (t, e, o, i) => {
|
|
482
|
-
const s = new
|
|
483
|
-
const
|
|
486
|
+
const s = new _t(), n = /* @__PURE__ */ new Map(), r = dt(), a = (c, u) => {
|
|
487
|
+
const T = c.selector.flatMap((N) => {
|
|
484
488
|
const S = D([N]) ? N.range : pt(N, e).range;
|
|
485
489
|
return Jt(S);
|
|
486
|
-
}), R = ne(
|
|
490
|
+
}), R = ne(T, o, i).map((N) => oe(N, u));
|
|
487
491
|
return R.map((N) => {
|
|
488
492
|
const { x: S, y: C, width: O, height: B } = N;
|
|
489
493
|
return {
|
|
@@ -497,111 +501,111 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
497
501
|
}
|
|
498
502
|
};
|
|
499
503
|
});
|
|
500
|
-
},
|
|
504
|
+
}, l = () => [...n.values()], m = () => {
|
|
501
505
|
s.clear(), n.clear();
|
|
502
|
-
},
|
|
503
|
-
const
|
|
504
|
-
|
|
505
|
-
},
|
|
506
|
-
const
|
|
507
|
-
|
|
506
|
+
}, g = (c) => {
|
|
507
|
+
const u = a(c, e.getBoundingClientRect());
|
|
508
|
+
u.length !== 0 && (u.forEach((T) => s.insert(T)), n.set(c.annotation, u));
|
|
509
|
+
}, E = (c) => {
|
|
510
|
+
const u = n.get(c.annotation);
|
|
511
|
+
u && (u.forEach((T) => s.remove(T)), n.delete(c.annotation));
|
|
508
512
|
}, h = (c) => {
|
|
509
|
-
|
|
510
|
-
},
|
|
511
|
-
|
|
512
|
-
const
|
|
513
|
+
E(c), g(c);
|
|
514
|
+
}, A = (c, u = !0) => {
|
|
515
|
+
u && m();
|
|
516
|
+
const T = e.getBoundingClientRect(), R = c.map((S) => ({ target: S, rects: a(S, T) }));
|
|
513
517
|
R.forEach(({ target: S, rects: C }) => {
|
|
514
518
|
C.length > 0 && n.set(S.annotation, C);
|
|
515
519
|
});
|
|
516
520
|
const N = R.flatMap(({ rects: S }) => S);
|
|
517
521
|
s.load(N);
|
|
518
|
-
},
|
|
522
|
+
}, d = (c, u, T = !1) => {
|
|
519
523
|
const R = s.search({
|
|
520
524
|
minX: c,
|
|
521
|
-
minY:
|
|
525
|
+
minY: u,
|
|
522
526
|
maxX: c,
|
|
523
|
-
maxY:
|
|
527
|
+
maxY: u
|
|
524
528
|
}), N = (S) => S.annotation.rects.reduce((C, O) => C + O.width * O.height, 0);
|
|
525
|
-
return R.length > 0 ? (R.sort((S, C) => N(S) - N(C)),
|
|
529
|
+
return R.length > 0 ? (R.sort((S, C) => N(S) - N(C)), T ? R.map((S) => S.annotation.id) : [R[0].annotation.id]) : [];
|
|
526
530
|
}, L = (c) => {
|
|
527
|
-
const
|
|
528
|
-
if (
|
|
531
|
+
const u = x(c);
|
|
532
|
+
if (u.length === 0)
|
|
529
533
|
return;
|
|
530
|
-
let
|
|
531
|
-
for (let C = 1; C <
|
|
532
|
-
const O =
|
|
533
|
-
|
|
534
|
+
let T = u[0].left, R = u[0].top, N = u[0].right, S = u[0].bottom;
|
|
535
|
+
for (let C = 1; C < u.length; C++) {
|
|
536
|
+
const O = u[C];
|
|
537
|
+
T = Math.min(T, O.left), R = Math.min(R, O.top), N = Math.max(N, O.right), S = Math.max(S, O.bottom);
|
|
534
538
|
}
|
|
535
|
-
return new DOMRect(
|
|
539
|
+
return new DOMRect(T, R, N - T, S - R);
|
|
536
540
|
}, x = (c) => {
|
|
537
|
-
const
|
|
538
|
-
return
|
|
541
|
+
const u = n.get(c);
|
|
542
|
+
return u ? u[0].annotation.rects : [];
|
|
539
543
|
};
|
|
540
544
|
return {
|
|
541
|
-
all:
|
|
542
|
-
clear:
|
|
543
|
-
getAt:
|
|
545
|
+
all: l,
|
|
546
|
+
clear: m,
|
|
547
|
+
getAt: d,
|
|
544
548
|
getAnnotationBounds: L,
|
|
545
549
|
getAnnotationRects: x,
|
|
546
|
-
getIntersecting: (c,
|
|
547
|
-
const N = s.search({ minX: c, minY:
|
|
550
|
+
getIntersecting: (c, u, T, R) => {
|
|
551
|
+
const N = s.search({ minX: c, minY: u, maxX: T, maxY: R }), S = new Set(N.map((C) => C.annotation.id));
|
|
548
552
|
return Array.from(S).map((C) => ({
|
|
549
553
|
annotation: t.getAnnotation(C),
|
|
550
554
|
rects: x(C)
|
|
551
555
|
})).filter((C) => !!C.annotation);
|
|
552
556
|
},
|
|
553
|
-
insert:
|
|
557
|
+
insert: g,
|
|
554
558
|
recalculate: () => {
|
|
555
|
-
|
|
559
|
+
A(t.all().map((c) => c.target), !0), r.emit("recalculate");
|
|
556
560
|
},
|
|
557
|
-
remove:
|
|
558
|
-
set:
|
|
561
|
+
remove: E,
|
|
562
|
+
set: A,
|
|
559
563
|
size: () => s.all().length,
|
|
560
564
|
update: h,
|
|
561
|
-
on: (c,
|
|
565
|
+
on: (c, u) => r.on(c, u)
|
|
562
566
|
};
|
|
563
567
|
}, le = (t, e) => {
|
|
564
|
-
const o = vt(), i = ce(o, t, e.mergeHighlights?.horizontalTolerance, e.mergeHighlights?.verticalTolerance), s = wt(o, e.userSelectAction, e.adapter), n = xt(o), r = Lt(), a = (p,
|
|
568
|
+
const o = vt(), i = ce(o, t, e.mergeHighlights?.horizontalTolerance, e.mergeHighlights?.verticalTolerance), s = wt(o, e.userSelectAction, e.adapter), n = xt(o), r = Lt(), a = (p, b = F.LOCAL) => {
|
|
565
569
|
const w = Z(p, t), c = D(w.target.selector);
|
|
566
|
-
return c && o.addAnnotation(w,
|
|
567
|
-
},
|
|
568
|
-
const c = p.map((
|
|
569
|
-
return o.bulkAddAnnotations(c,
|
|
570
|
-
},
|
|
571
|
-
const w = p.map((
|
|
572
|
-
return w.forEach((
|
|
573
|
-
o.getAnnotation(
|
|
570
|
+
return c && o.addAnnotation(w, b), c;
|
|
571
|
+
}, l = (p, b = !0, w = F.LOCAL) => {
|
|
572
|
+
const c = p.map((T) => Z(T, t)), u = c.filter((T) => !D(T.target.selector));
|
|
573
|
+
return o.bulkAddAnnotations(c, b, w), u;
|
|
574
|
+
}, m = (p, b = F.LOCAL) => {
|
|
575
|
+
const w = p.map((u) => Z(u, t)), c = w.filter((u) => !D(u.target.selector));
|
|
576
|
+
return w.forEach((u) => {
|
|
577
|
+
o.getAnnotation(u.id) ? o.updateAnnotation(u, b) : o.addAnnotation(u, b);
|
|
574
578
|
}), c;
|
|
575
|
-
},
|
|
579
|
+
}, g = (p, b = F.LOCAL) => {
|
|
576
580
|
const w = Q(p, t);
|
|
577
|
-
o.updateTarget(w,
|
|
578
|
-
},
|
|
581
|
+
o.updateTarget(w, b);
|
|
582
|
+
}, E = (p, b = F.LOCAL) => {
|
|
579
583
|
const w = p.map((c) => Q(c, t));
|
|
580
|
-
o.bulkUpdateTargets(w,
|
|
584
|
+
o.bulkUpdateTargets(w, b);
|
|
581
585
|
};
|
|
582
|
-
function h(p,
|
|
583
|
-
const
|
|
586
|
+
function h(p, b, w, c) {
|
|
587
|
+
const u = w || !!c, T = i.getAt(p, b, u).map((N) => o.getAnnotation(N)).filter(Boolean), R = c ? T.filter(c) : T;
|
|
584
588
|
if (R.length !== 0)
|
|
585
589
|
return w ? R : R[0];
|
|
586
590
|
}
|
|
587
|
-
const
|
|
591
|
+
const A = (p) => i.getAnnotationRects(p).length > 0 ? i.getAnnotationBounds(p) : void 0, d = (p, b, w, c) => i.getIntersecting(p, b, w, c), L = (p) => i.getAnnotationRects(p), x = () => i.recalculate(), v = (p) => i.on("recalculate", p);
|
|
588
592
|
return o.observe(({ changes: p }) => {
|
|
589
|
-
const
|
|
590
|
-
|
|
593
|
+
const b = (p.deleted || []).filter((u) => D(u.target.selector)), w = (p.created || []).filter((u) => D(u.target.selector)), c = (p.updated || []).filter((u) => D(u.newValue.target.selector));
|
|
594
|
+
b?.length > 0 && b.forEach((u) => i.remove(u.target)), w.length > 0 && i.set(w.map((u) => u.target), !1), c?.length > 0 && c.forEach(({ newValue: u }) => i.update(u.target));
|
|
591
595
|
}), {
|
|
592
596
|
store: {
|
|
593
597
|
...o,
|
|
594
598
|
addAnnotation: a,
|
|
595
|
-
bulkAddAnnotations:
|
|
596
|
-
bulkUpdateTargets:
|
|
597
|
-
bulkUpsertAnnotations:
|
|
598
|
-
getAnnotationBounds:
|
|
599
|
+
bulkAddAnnotations: l,
|
|
600
|
+
bulkUpdateTargets: E,
|
|
601
|
+
bulkUpsertAnnotations: m,
|
|
602
|
+
getAnnotationBounds: A,
|
|
599
603
|
getAnnotationRects: L,
|
|
600
|
-
getIntersecting:
|
|
604
|
+
getIntersecting: d,
|
|
601
605
|
getAt: h,
|
|
602
606
|
recalculatePositions: x,
|
|
603
607
|
onRecalculatePositions: v,
|
|
604
|
-
updateTarget:
|
|
608
|
+
updateTarget: g
|
|
605
609
|
},
|
|
606
610
|
selection: s,
|
|
607
611
|
hover: n,
|
|
@@ -615,28 +619,28 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
615
619
|
let r;
|
|
616
620
|
const {
|
|
617
621
|
annotatingEnabled: a,
|
|
618
|
-
offsetReferenceSelector:
|
|
619
|
-
selectionMode:
|
|
620
|
-
dismissOnNotAnnotatable:
|
|
622
|
+
offsetReferenceSelector: l,
|
|
623
|
+
selectionMode: m,
|
|
624
|
+
dismissOnNotAnnotatable: g = "NEVER"
|
|
621
625
|
} = i;
|
|
622
|
-
let
|
|
626
|
+
let E, h = a, A = "CREATE_NEW", d, L, x, v;
|
|
623
627
|
const p = (f) => {
|
|
624
|
-
h = f, R.clear(), f || (L = void 0,
|
|
625
|
-
},
|
|
626
|
-
if (
|
|
628
|
+
h = f, R.clear(), f || (L = void 0, d = void 0, x = void 0, v = void 0);
|
|
629
|
+
}, b = (f) => A = f || "CREATE_NEW", w = (f) => E = f, c = (f) => r = f, u = (f) => {
|
|
630
|
+
if (A === "ADD_TO_CURRENT")
|
|
627
631
|
return !0;
|
|
628
632
|
if (i.allowModifierSelect) {
|
|
629
633
|
const y = f;
|
|
630
634
|
return ut ? y.metaKey : y.ctrlKey;
|
|
631
635
|
} else
|
|
632
636
|
return !1;
|
|
633
|
-
},
|
|
637
|
+
}, T = () => {
|
|
634
638
|
if (!h || x === !1) return;
|
|
635
639
|
const { selected: f } = n;
|
|
636
|
-
if ((
|
|
640
|
+
if ((u(v) || A === "REPLACE_CURRENT") && f.length === 1 && f[0].editable) {
|
|
637
641
|
const M = s.getAnnotation(f[0].id);
|
|
638
642
|
if (M?.target) {
|
|
639
|
-
L = M.target,
|
|
643
|
+
L = M.target, d = {
|
|
640
644
|
annotation: M.id,
|
|
641
645
|
selector: [],
|
|
642
646
|
created: L.created,
|
|
@@ -647,93 +651,93 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
647
651
|
return;
|
|
648
652
|
}
|
|
649
653
|
}
|
|
650
|
-
L = void 0,
|
|
654
|
+
L = void 0, d = {
|
|
651
655
|
annotation: lt(),
|
|
652
656
|
selector: [],
|
|
653
657
|
created: /* @__PURE__ */ new Date(),
|
|
654
658
|
creator: r
|
|
655
659
|
};
|
|
656
|
-
}, R =
|
|
660
|
+
}, R = It((f) => {
|
|
657
661
|
if (!h) return;
|
|
658
662
|
const y = document.getSelection();
|
|
659
663
|
if (!y?.anchorNode) return;
|
|
660
664
|
const M = Array.from(Array(y.rangeCount).keys()).map((k) => y.getRangeAt(k));
|
|
661
665
|
if (M.every((k) => !gt(t, k))) {
|
|
662
|
-
|
|
666
|
+
d = void 0;
|
|
663
667
|
return;
|
|
664
668
|
}
|
|
665
669
|
const U = f.timeStamp - (v?.timeStamp || f.timeStamp);
|
|
666
|
-
if (v?.type === "pointerdown" && (U < 1e3 && !
|
|
670
|
+
if (v?.type === "pointerdown" && (U < 1e3 && !d || y.isCollapsed && U < at) && T(), !d && (T(), !d))
|
|
667
671
|
return;
|
|
668
672
|
if (y.isCollapsed) {
|
|
669
|
-
s.getAnnotation(
|
|
673
|
+
s.getAnnotation(d.annotation) && !(u(v) || A === "REPLACE_CURRENT") && (n.clear(), s.deleteAnnotation(d.annotation));
|
|
670
674
|
return;
|
|
671
675
|
}
|
|
672
|
-
const
|
|
673
|
-
if (
|
|
674
|
-
const
|
|
675
|
-
if (!(
|
|
676
|
-
const j =
|
|
676
|
+
const _ = M.map((k) => Wt(k, t));
|
|
677
|
+
if (_.every((k) => Ht(k))) return;
|
|
678
|
+
const I = _.flatMap((k) => Ft(t, k.cloneRange()));
|
|
679
|
+
if (!(I.length > 0 && !d || I.length !== d.selector.length || I.some((k, Y) => k.toString() !== d?.selector[Y]?.quote))) return;
|
|
680
|
+
const j = u(v) && L ? Pt([
|
|
677
681
|
...L.selector.map((k) => k.range),
|
|
678
|
-
...
|
|
679
|
-
]) :
|
|
680
|
-
|
|
681
|
-
...
|
|
682
|
-
selector: j.map((k) =>
|
|
682
|
+
...I
|
|
683
|
+
]) : I;
|
|
684
|
+
d = {
|
|
685
|
+
...d,
|
|
686
|
+
selector: j.map((k) => Yt(k, t, l)),
|
|
683
687
|
updated: /* @__PURE__ */ new Date()
|
|
684
|
-
}, !(
|
|
688
|
+
}, !(u(v) || A === "REPLACE_CURRENT") && (s.getAnnotation(d.annotation) ? s.updateTarget(d, F.LOCAL) : n.clear());
|
|
685
689
|
}, 10), N = (f) => {
|
|
686
690
|
v = J(f), x = v.button === 0;
|
|
687
691
|
}, S = async (f) => {
|
|
688
692
|
if (!x) return;
|
|
689
693
|
const y = J(f), M = () => {
|
|
690
|
-
const { x:
|
|
691
|
-
if (
|
|
692
|
-
(typeof
|
|
694
|
+
const { x: _, y: I } = t.getBoundingClientRect();
|
|
695
|
+
if (W(t, y.target)) {
|
|
696
|
+
(typeof g == "function" ? g(y, t) : g === "ALWAYS") && n.clear();
|
|
693
697
|
return;
|
|
694
698
|
}
|
|
695
699
|
const H = y.target instanceof Node && t.contains(y.target) && s.getAt(
|
|
696
|
-
y.clientX -
|
|
697
|
-
y.clientY -
|
|
698
|
-
|
|
699
|
-
|
|
700
|
+
y.clientX - _,
|
|
701
|
+
y.clientY - I,
|
|
702
|
+
m === "all",
|
|
703
|
+
E
|
|
700
704
|
);
|
|
701
705
|
if (H) {
|
|
702
|
-
const { selected: j } = n, k = new Set(j.map((X) => X.id)),
|
|
703
|
-
(k.size !==
|
|
706
|
+
const { selected: j } = n, k = new Set(j.map((X) => X.id)), Y = Array.isArray(H) ? H.map((X) => X.id) : [H.id];
|
|
707
|
+
(k.size !== Y.length || !Y.every((X) => k.has(X))) && (o.emit("clickAnnotation", H), n.userSelect(Y, y));
|
|
704
708
|
} else
|
|
705
709
|
n.clear();
|
|
706
710
|
};
|
|
707
711
|
if (y.timeStamp - (v?.timeStamp || 0) < at) {
|
|
708
712
|
await C();
|
|
709
|
-
const
|
|
710
|
-
if (
|
|
711
|
-
|
|
713
|
+
const _ = document.getSelection(), I = W(t, v?.target), H = W(t, y.target);
|
|
714
|
+
if (_?.isCollapsed || I && H) {
|
|
715
|
+
d = void 0, M();
|
|
712
716
|
return;
|
|
713
717
|
}
|
|
714
718
|
}
|
|
715
|
-
|
|
719
|
+
d && d.selector.length > 0 && (K(), n.userSelect(d.annotation, y));
|
|
716
720
|
}, C = async () => {
|
|
717
721
|
const f = document.getSelection();
|
|
718
722
|
let y = !1, M = f?.isCollapsed;
|
|
719
|
-
const U = () => M || y,
|
|
720
|
-
return setTimeout(() => y = !0, 50), Dt(() => M = f?.isCollapsed,
|
|
723
|
+
const U = () => M || y, _ = 1;
|
|
724
|
+
return setTimeout(() => y = !0, 50), Dt(() => M = f?.isCollapsed, _, U);
|
|
721
725
|
}, O = (f) => {
|
|
722
|
-
document.getSelection()?.isCollapsed || ((!
|
|
726
|
+
document.getSelection()?.isCollapsed || ((!d || d.selector.length === 0) && R(f), d && (K(), n.userSelect(d.annotation, J(f))));
|
|
723
727
|
}, B = (f) => {
|
|
724
|
-
if (h && !(f.repeat || f.target instanceof Node &&
|
|
728
|
+
if (h && !(f.repeat || f.target instanceof Node && W(t, f.target) && f.target !== document.body) && f.key === "Shift" && d) {
|
|
725
729
|
const y = document.getSelection();
|
|
726
|
-
y && !y.isCollapsed && (K(), n.userSelect(
|
|
730
|
+
y && !y.isCollapsed && (K(), n.userSelect(d.annotation, G(f)));
|
|
727
731
|
}
|
|
728
732
|
}, V = (f) => {
|
|
729
733
|
const y = () => setTimeout(() => {
|
|
730
|
-
|
|
731
|
-
id:
|
|
734
|
+
d && (d.selector.length > 0 && (n.clear(), s.addAnnotation({
|
|
735
|
+
id: d.annotation,
|
|
732
736
|
bodies: [],
|
|
733
|
-
target:
|
|
734
|
-
}), n.userSelect(
|
|
737
|
+
target: d
|
|
738
|
+
}), n.userSelect(d.annotation, G(f))), document.removeEventListener("selectionchange", y));
|
|
735
739
|
}, 100);
|
|
736
|
-
document.addEventListener("selectionchange", y),
|
|
740
|
+
document.addEventListener("selectionchange", y), T();
|
|
737
741
|
};
|
|
738
742
|
q(de.join(","), { element: t, keydown: !0, keyup: !1 }, (f) => {
|
|
739
743
|
f.repeat || (v = G(f));
|
|
@@ -741,31 +745,31 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
741
745
|
v = G(f), V(f);
|
|
742
746
|
});
|
|
743
747
|
const z = (f) => {
|
|
744
|
-
f.repeat || f.target instanceof Node &&
|
|
748
|
+
f.repeat || f.target instanceof Node && W(t, f.target) && f.target !== document.body || (d = void 0, n.clear());
|
|
745
749
|
};
|
|
746
750
|
q(Et.join(","), { keydown: !0, keyup: !1 }, z);
|
|
747
751
|
const K = () => {
|
|
748
|
-
if (!
|
|
749
|
-
const f = s.getAnnotation(
|
|
752
|
+
if (!d) return;
|
|
753
|
+
const f = s.getAnnotation(d.annotation);
|
|
750
754
|
if (!f)
|
|
751
755
|
s.addAnnotation({
|
|
752
|
-
id:
|
|
756
|
+
id: d.annotation,
|
|
753
757
|
bodies: [],
|
|
754
|
-
target:
|
|
758
|
+
target: d
|
|
755
759
|
});
|
|
756
760
|
else {
|
|
757
|
-
const { target: { updated: y } } = f, { updated: M } =
|
|
758
|
-
(!y || !M || y < M) && s.updateTarget(
|
|
761
|
+
const { target: { updated: y } } = f, { updated: M } = d;
|
|
762
|
+
(!y || !M || y < M) && s.updateTarget(d);
|
|
759
763
|
}
|
|
760
764
|
};
|
|
761
|
-
return document.addEventListener("pointerdown", N), document.addEventListener("pointerup", S), document.addEventListener("contextmenu", O), document.addEventListener("keyup", B), t.addEventListener("selectstart",
|
|
765
|
+
return document.addEventListener("pointerdown", N), document.addEventListener("pointerup", S), document.addEventListener("contextmenu", O), document.addEventListener("keyup", B), t.addEventListener("selectstart", T), document.addEventListener("selectionchange", R), {
|
|
762
766
|
destroy: () => {
|
|
763
|
-
|
|
767
|
+
d = void 0, L = void 0, x = void 0, v = void 0, R.clear(), document.removeEventListener("pointerdown", N), document.removeEventListener("pointerup", S), document.removeEventListener("contextmenu", O), document.removeEventListener("keyup", B), t.removeEventListener("selectstart", T), document.removeEventListener("selectionchange", R), q.unbind();
|
|
764
768
|
},
|
|
765
769
|
setFilter: w,
|
|
766
770
|
setUser: c,
|
|
767
771
|
setAnnotatingEnabled: p,
|
|
768
|
-
setAnnotatingMode:
|
|
772
|
+
setAnnotatingMode: b
|
|
769
773
|
};
|
|
770
774
|
}, fe = (t) => [
|
|
771
775
|
`background-color:${et(t?.fill || P.fill).alpha(t?.fillOpacity === void 0 ? P.fillOpacity : t.fillOpacity).toHex()}`,
|
|
@@ -784,19 +788,19 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
784
788
|
setVisible: (n) => {
|
|
785
789
|
console.log("setVisible not implemented on CSS Custom Highlights renderer");
|
|
786
790
|
},
|
|
787
|
-
redraw: (n, r, a,
|
|
788
|
-
const
|
|
789
|
-
Array.from(e).filter((h) => !
|
|
790
|
-
const
|
|
791
|
+
redraw: (n, r, a, l, m) => {
|
|
792
|
+
const g = new Set(n.map((h) => h.annotation.id));
|
|
793
|
+
Array.from(e).filter((h) => !g.has(h));
|
|
794
|
+
const E = n.map((h) => {
|
|
791
795
|
a ? typeof a == "function" && a(h.annotation, h.state) : h.state?.selected;
|
|
792
|
-
const
|
|
793
|
-
return `::highlight(_${h.annotation.id}) { ${fe(
|
|
796
|
+
const A = St(h, a);
|
|
797
|
+
return `::highlight(_${h.annotation.id}) { ${fe(A)} }`;
|
|
794
798
|
});
|
|
795
|
-
t.innerHTML =
|
|
799
|
+
t.innerHTML = E.join(`
|
|
796
800
|
`), CSS.highlights.clear(), n.forEach(({ annotation: h }) => {
|
|
797
|
-
const
|
|
798
|
-
CSS.highlights.set(`_${h.id}`,
|
|
799
|
-
}), e =
|
|
801
|
+
const A = h.target.selector.map((L) => L.range), d = new Highlight(...A);
|
|
802
|
+
CSS.highlights.set(`_${h.id}`, d);
|
|
803
|
+
}), e = g;
|
|
800
804
|
}
|
|
801
805
|
};
|
|
802
806
|
}, me = (t, e, o) => yt(ge(), t, e, o), pe = (t, e) => ({
|
|
@@ -808,61 +812,62 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
808
812
|
const o = pe(e, {
|
|
809
813
|
annotatingEnabled: !0,
|
|
810
814
|
user: Nt()
|
|
811
|
-
}), i = le(t, o), { selection: s, viewport: n } = i, r = i.store, a = Ot(r),
|
|
812
|
-
let
|
|
813
|
-
const
|
|
815
|
+
}), i = le(t, o), { selection: s, viewport: n } = i, r = i.store, a = Ot(r), l = kt(i, a, o.adapter);
|
|
816
|
+
let m = o.user;
|
|
817
|
+
const g = typeof o.renderer != "function" ? o.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ct : o.renderer || ct : null, E = g === null ? o.renderer(
|
|
814
818
|
t,
|
|
815
819
|
i,
|
|
816
820
|
n
|
|
817
|
-
) :
|
|
821
|
+
) : g === "SPANS" ? re(
|
|
818
822
|
t,
|
|
819
823
|
i,
|
|
820
824
|
n
|
|
821
|
-
) :
|
|
825
|
+
) : g === "CSS_HIGHLIGHTS" ? me(
|
|
822
826
|
t,
|
|
823
827
|
i,
|
|
824
828
|
n
|
|
825
829
|
) : void 0;
|
|
826
|
-
if (!
|
|
830
|
+
if (!E)
|
|
827
831
|
throw `Unknown renderer implementation: ${o.renderer}`;
|
|
828
|
-
console.debug(
|
|
832
|
+
console.debug(g ? `Using ${g} renderer` : "Using custom renderer implementation"), o.style && E.setStyle(o.style);
|
|
829
833
|
const h = ue(
|
|
830
834
|
t,
|
|
831
835
|
i,
|
|
832
|
-
|
|
836
|
+
l,
|
|
833
837
|
o
|
|
834
838
|
);
|
|
835
|
-
h.setUser(
|
|
836
|
-
const
|
|
839
|
+
h.setUser(m);
|
|
840
|
+
const A = Mt(i, a, o.adapter), d = () => m, L = (c) => {
|
|
837
841
|
h.setAnnotatingEnabled(
|
|
838
842
|
c === void 0 ? !0 : c
|
|
839
843
|
);
|
|
840
844
|
}, x = (c) => {
|
|
841
845
|
h.setAnnotatingMode(c);
|
|
842
846
|
}, v = (c) => {
|
|
843
|
-
|
|
847
|
+
E.setFilter(c), h.setFilter(c);
|
|
844
848
|
}, p = (c) => {
|
|
845
|
-
|
|
846
|
-
},
|
|
849
|
+
m = c, h.setUser(c);
|
|
850
|
+
}, b = (c) => {
|
|
847
851
|
c ? s.setSelected(c) : s.clear();
|
|
848
852
|
};
|
|
849
853
|
return {
|
|
850
|
-
...
|
|
854
|
+
...A,
|
|
851
855
|
destroy: () => {
|
|
852
|
-
|
|
856
|
+
E.destroy(), h.destroy(), a.destroy();
|
|
853
857
|
},
|
|
854
858
|
element: t,
|
|
855
|
-
getUser:
|
|
856
|
-
renderer:
|
|
859
|
+
getUser: d,
|
|
860
|
+
renderer: E,
|
|
857
861
|
setAnnotatingEnabled: L,
|
|
858
862
|
setAnnotatingMode: x,
|
|
859
863
|
setFilter: v,
|
|
860
|
-
setStyle:
|
|
864
|
+
setStyle: E.setStyle.bind(E),
|
|
861
865
|
setUser: p,
|
|
862
|
-
setSelected:
|
|
863
|
-
setVisible:
|
|
864
|
-
on:
|
|
865
|
-
off:
|
|
866
|
+
setSelected: b,
|
|
867
|
+
setVisible: E.setVisible.bind(E),
|
|
868
|
+
on: l.on,
|
|
869
|
+
off: l.off,
|
|
870
|
+
// @ts-ignore - temporary
|
|
866
871
|
scrollIntoView: Xt(t, r),
|
|
867
872
|
state: i
|
|
868
873
|
};
|
|
@@ -871,16 +876,16 @@ export {
|
|
|
871
876
|
ot as DEFAULT_SELECTED_STYLE,
|
|
872
877
|
P as DEFAULT_STYLE,
|
|
873
878
|
ft as NOT_ANNOTATABLE_CLASS,
|
|
874
|
-
|
|
879
|
+
$ as NOT_ANNOTATABLE_SELECTOR,
|
|
875
880
|
Be as Origin,
|
|
876
|
-
|
|
881
|
+
_e as UserSelectAction,
|
|
877
882
|
xe as W3CTextFormat,
|
|
878
883
|
Gt as cancelSingleClickEvents,
|
|
879
884
|
G as cloneKeyboardEvent,
|
|
880
885
|
J as clonePointerEvent,
|
|
881
886
|
St as computeStyle,
|
|
882
887
|
Zt as computeZIndex,
|
|
883
|
-
|
|
888
|
+
Ie as createBody,
|
|
884
889
|
yt as createRenderer,
|
|
885
890
|
ue as createSelectionHandler,
|
|
886
891
|
re as createSpansRenderer,
|
|
@@ -890,12 +895,12 @@ export {
|
|
|
890
895
|
pe as fillDefaults,
|
|
891
896
|
Qt as getBackgroundColor,
|
|
892
897
|
Jt as getHighlightClientRects,
|
|
893
|
-
|
|
898
|
+
$t as getQuoteContext,
|
|
894
899
|
nt as getRangeAnnotatableContents,
|
|
895
900
|
ie as getViewportBounds,
|
|
896
901
|
ut as isMac,
|
|
897
902
|
we as isNodeWhitespaceOrEmpty,
|
|
898
|
-
|
|
903
|
+
W as isNotAnnotatable,
|
|
899
904
|
gt as isRangeAnnotatable,
|
|
900
905
|
Ht as isRangeWhitespaceOrEmpty,
|
|
901
906
|
D as isRevived,
|
|
@@ -903,7 +908,7 @@ export {
|
|
|
903
908
|
Pt as mergeRanges,
|
|
904
909
|
jt as parseW3CTextAnnotation,
|
|
905
910
|
Ut as programmaticallyFocusable,
|
|
906
|
-
|
|
911
|
+
Yt as rangeToSelector,
|
|
907
912
|
Z as reviveAnnotation,
|
|
908
913
|
pt as reviveSelector,
|
|
909
914
|
Q as reviveTarget,
|
|
@@ -914,7 +919,7 @@ export {
|
|
|
914
919
|
oe as toParentBounds,
|
|
915
920
|
Ne as toViewportBounds,
|
|
916
921
|
ae as trackViewport,
|
|
917
|
-
|
|
922
|
+
Wt as trimRangeToContainer,
|
|
918
923
|
mt as whitespaceOrEmptyRegex
|
|
919
924
|
};
|
|
920
925
|
//# sourceMappingURL=text-annotator.es.js.map
|