@recogito/text-annotator 4.0.3-beta → 4.1.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.
- package/dist/model/core/text-annotation.d.ts +12 -0
- package/dist/rendering/base-renderer.d.ts +3 -3
- package/dist/rendering/highlight-style.d.ts +2 -2
- package/dist/rendering/highlight.d.ts +2 -2
- package/dist/rendering/renderer-spans/spans-renderer.d.ts +2 -2
- package/dist/rendering/viewport.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 +391 -386
- 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 $, 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", W = `.${ft}`, F = (t, e) => t.contains(e) ? !!(e instanceof HTMLElement ? e.closest(W) : e.parentElement?.closest(W)) : !0, gt = (t, e) => {
|
|
12
12
|
const o = e.commonAncestorContainer;
|
|
13
|
-
return
|
|
13
|
+
return !F(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,15 +23,15 @@ 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(W) && t.intersectsNode(i) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
|
30
30
|
);
|
|
31
31
|
let o;
|
|
32
32
|
for (; o = e.nextNode(); )
|
|
33
33
|
o instanceof HTMLElement && (yield o);
|
|
34
|
-
},
|
|
34
|
+
}, $t = (t, e) => {
|
|
35
35
|
if (!gt(t, e)) return [];
|
|
36
36
|
const o = [];
|
|
37
37
|
let i = null;
|
|
@@ -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(W).forEach((o) => o.remove()), e;
|
|
50
|
+
}, Ft = (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" }), Wt = (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((y) => y.segment).join(""),
|
|
61
|
+
suffix: g.slice(0, o).map((y) => y.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(W) ? 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, y = o.parentElement ? o.scrollTop : 0, p = o.parentElement ? o.scrollLeft : 0, v = m + y - (s - l) / 2, u = g + p - (n - a) / 2;
|
|
112
|
+
o.scroll({ top: v, left: u, 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
|
|
149
|
-
switch (
|
|
147
|
+
for (const l of r) {
|
|
148
|
+
const g = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((y, p) => {
|
|
149
|
+
switch (p.type) {
|
|
150
150
|
case "TextQuoteSelector":
|
|
151
|
-
|
|
151
|
+
y.quote = p.exact;
|
|
152
152
|
break;
|
|
153
153
|
case "TextPositionSelector":
|
|
154
|
-
|
|
154
|
+
y.start = p.start, y.end = p.end;
|
|
155
155
|
break;
|
|
156
156
|
}
|
|
157
|
-
return
|
|
157
|
+
return y;
|
|
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 y = [
|
|
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: ${y.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, y = r.map((p) => {
|
|
201
|
+
const { id: v, quote: u, start: x, end: N, range: A } = p, b = {
|
|
202
202
|
type: "TextQuoteSelector",
|
|
203
|
-
exact:
|
|
203
|
+
exact: u
|
|
204
204
|
};
|
|
205
205
|
if (o) {
|
|
206
|
-
const { prefix:
|
|
207
|
-
|
|
206
|
+
const { prefix: S, suffix: c } = Wt(A, o);
|
|
207
|
+
b.prefix = S, b.suffix = c;
|
|
208
208
|
}
|
|
209
|
-
const
|
|
209
|
+
const C = {
|
|
210
210
|
type: "TextPositionSelector",
|
|
211
|
-
start:
|
|
212
|
-
end:
|
|
211
|
+
start: x,
|
|
212
|
+
end: N
|
|
213
213
|
};
|
|
214
214
|
return {
|
|
215
|
-
...
|
|
216
|
-
id:
|
|
215
|
+
...g,
|
|
216
|
+
id: v,
|
|
217
217
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
218
|
-
scope: "scope" in
|
|
218
|
+
scope: "scope" in p ? p.scope : void 0,
|
|
219
219
|
source: e,
|
|
220
|
-
selector: [
|
|
220
|
+
selector: [b, C]
|
|
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: y
|
|
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(W) && !e.target.closest("a") && e.preventDefault();
|
|
237
237
|
}), J = (t) => ({
|
|
238
238
|
...t,
|
|
239
239
|
type: t.type,
|
|
@@ -283,103 +283,107 @@ 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:
|
|
286
|
+
let l;
|
|
287
|
+
const m = /* @__PURE__ */ new Map();
|
|
288
|
+
let g;
|
|
289
|
+
const y = ae(i), p = (E) => {
|
|
290
|
+
const { x: T, y: O } = e.getBoundingClientRect(), B = s.getAt(E.clientX - T, E.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
|
-
e.addEventListener("pointermove",
|
|
294
|
-
const
|
|
295
|
-
const
|
|
296
|
-
const
|
|
293
|
+
e.addEventListener("pointermove", p);
|
|
294
|
+
const v = tt((E = !1) => requestAnimationFrame(() => {
|
|
295
|
+
const T = ie(e), { minX: O, minY: B, maxX: V, maxY: z } = T, K = g ? s.getIntersecting(O, B, V, z).filter(({ annotation: h }) => g?.(h)) : s.getIntersecting(O, B, V, z), st = n.selected.map(({ id: h }) => h), f = K.map(({ annotation: h, rects: M }) => {
|
|
296
|
+
const H = st.includes(h.id), _ = h.id === r.current;
|
|
297
297
|
return {
|
|
298
|
-
annotation:
|
|
298
|
+
annotation: h,
|
|
299
299
|
rects: M,
|
|
300
|
-
state: { selected:
|
|
300
|
+
state: { selected: H, hovered: _ }
|
|
301
301
|
};
|
|
302
302
|
});
|
|
303
|
-
t.redraw(f,
|
|
304
|
-
|
|
303
|
+
t.redraw(f, T, l, m, E), setTimeout(() => {
|
|
304
|
+
y(K.map(({ annotation: h }) => h)), a.emit("onRedraw");
|
|
305
305
|
}, 1);
|
|
306
|
-
}), 10),
|
|
307
|
-
|
|
308
|
-
},
|
|
309
|
-
|
|
310
|
-
},
|
|
311
|
-
|
|
306
|
+
}), 10), u = (E, T) => {
|
|
307
|
+
T ? E ? m.set(T, E) : m.delete(T) : l = E, v(!0);
|
|
308
|
+
}, x = (E) => {
|
|
309
|
+
g = E, v(!1);
|
|
310
|
+
}, N = (E, T) => a.on(E, T), A = () => {
|
|
311
|
+
v();
|
|
312
312
|
};
|
|
313
|
-
s.observe(
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
}),
|
|
317
|
-
|
|
318
|
-
}),
|
|
319
|
-
|
|
313
|
+
s.observe(A);
|
|
314
|
+
const b = n.subscribe(() => {
|
|
315
|
+
v();
|
|
316
|
+
}), C = r.subscribe(() => {
|
|
317
|
+
v();
|
|
318
|
+
}), S = () => {
|
|
319
|
+
v(!0);
|
|
320
320
|
};
|
|
321
|
-
document.addEventListener("scroll",
|
|
321
|
+
document.addEventListener("scroll", S, { capture: !0, passive: !0 });
|
|
322
322
|
const c = tt(() => {
|
|
323
|
-
s.recalculatePositions(),
|
|
323
|
+
s.recalculatePositions(), v();
|
|
324
324
|
}, 10);
|
|
325
325
|
window.addEventListener("resize", c);
|
|
326
326
|
const d = new ResizeObserver(c);
|
|
327
327
|
d.observe(e);
|
|
328
|
-
const
|
|
329
|
-
|
|
328
|
+
const R = { attributes: !0, childList: !0, subtree: !0 }, w = new MutationObserver(tt((E) => {
|
|
329
|
+
E.every((O) => O.target === e || e.contains(O.target)) || v(!0);
|
|
330
330
|
}, 150));
|
|
331
|
-
return
|
|
331
|
+
return w.observe(document.body, R), {
|
|
332
332
|
destroy: () => {
|
|
333
|
-
e.removeEventListener("pointermove",
|
|
333
|
+
e.removeEventListener("pointermove", p), t.destroy(), s.unobserve(A), b(), C(), document.removeEventListener("scroll", S), window.removeEventListener("resize", c), d.disconnect(), w.disconnect();
|
|
334
334
|
},
|
|
335
|
-
on:
|
|
336
|
-
redraw:
|
|
337
|
-
setStyle:
|
|
338
|
-
setFilter:
|
|
335
|
+
on: N,
|
|
336
|
+
redraw: v,
|
|
337
|
+
setStyle: u,
|
|
338
|
+
setFilter: x,
|
|
339
339
|
setVisible: t.setVisible.bind(t)
|
|
340
340
|
};
|
|
341
|
-
},
|
|
341
|
+
}, U = {
|
|
342
342
|
fill: "rgb(0, 128, 255)",
|
|
343
343
|
fillOpacity: 0.18
|
|
344
344
|
}, ot = {
|
|
345
345
|
fill: "rgb(0, 128, 255)",
|
|
346
346
|
fillOpacity: 0.45
|
|
347
|
-
}, Qt = (t) => t?.fillOpacity !== void 0 ? et(t?.fill ||
|
|
347
|
+
}, Qt = (t) => t?.fillOpacity !== void 0 ? et(t?.fill || U.fill).alpha(t.fillOpacity).toHex() : t?.fill ? t.fill : et(U.fill).alpha(U.fillOpacity).toHex(), St = (t, e, o) => e ? typeof e == "function" ? e(t.annotation, t.state, o) || (t.state?.selected ? ot : U) : e : t.state?.selected ? ot : U, Zt = (t, e) => {
|
|
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 y = document.createRange();
|
|
381
|
+
return y.selectNode(g), Array.from(y.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,26 +456,27 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
452
456
|
destroy: () => {
|
|
453
457
|
e.remove();
|
|
454
458
|
},
|
|
455
|
-
redraw: (r, a,
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
459
|
+
redraw: (r, a, l, m, g) => {
|
|
460
|
+
const y = performance.now();
|
|
461
|
+
if (!(!Bt(o, r) || g)) return;
|
|
462
|
+
e.innerHTML = "", [...r].sort((x, N) => {
|
|
463
|
+
const { annotation: { target: { created: A } } } = x, { annotation: { target: { created: b } } } = N;
|
|
464
|
+
return A && b ? A.getTime() - b.getTime() : 0;
|
|
465
|
+
}).forEach((x) => {
|
|
466
|
+
const N = m?.get(x.annotation.id) || l;
|
|
467
|
+
x.rects.map((A) => {
|
|
468
|
+
const b = Zt(A, r), C = St(x, N, b), S = document.createElement("span");
|
|
469
|
+
S.className = "r6o-annotation", S.dataset.annotation = x.annotation.id, S.style.left = `${A.x}px`, S.style.top = `${A.y}px`, S.style.width = `${A.width}px`, S.style.height = `${A.height}px`, S.style.backgroundColor = Qt(C), C.underlineStyle && (S.style.borderStyle = C.underlineStyle), C.underlineColor && (S.style.borderColor = C.underlineColor), C.underlineThickness && (S.style.borderBottomWidth = `${C.underlineThickness}px`), C.underlineOffset && (S.style.paddingBottom = `${C.underlineOffset}px`), e.appendChild(S);
|
|
465
470
|
});
|
|
466
|
-
}), o = r;
|
|
471
|
+
}), o = r, console.log(`Took ${performance.now() - y} ms`);
|
|
467
472
|
},
|
|
468
473
|
setVisible: (r) => {
|
|
469
474
|
r ? e.classList.remove("hidden") : e.classList.add("hidden");
|
|
470
475
|
}
|
|
471
476
|
};
|
|
472
477
|
}, 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:
|
|
478
|
+
const { top: e, left: o } = t.getBoundingClientRect(), { innerWidth: i, innerHeight: s } = window, n = -o, r = -e, a = i - o, l = s - e;
|
|
479
|
+
return { top: e, left: o, minX: n, minY: r, maxX: a, maxY: l };
|
|
475
480
|
}, ae = (t) => {
|
|
476
481
|
let e = /* @__PURE__ */ new Set();
|
|
477
482
|
return (i) => {
|
|
@@ -479,129 +484,129 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
479
484
|
(e.size !== s.length || s.some((n) => !e.has(n))) && t.set(s), e = new Set(s);
|
|
480
485
|
};
|
|
481
486
|
}, ce = (t, e, o, i) => {
|
|
482
|
-
const s = new
|
|
483
|
-
const
|
|
484
|
-
const
|
|
485
|
-
return Jt(
|
|
486
|
-
}),
|
|
487
|
-
return
|
|
488
|
-
const { x:
|
|
487
|
+
const s = new _t(), n = /* @__PURE__ */ new Map(), r = dt(), a = (c, d) => {
|
|
488
|
+
const R = c.selector.flatMap((L) => {
|
|
489
|
+
const E = D([L]) ? L.range : pt(L, e).range;
|
|
490
|
+
return Jt(E);
|
|
491
|
+
}), w = ne(R, o, i).map((L) => oe(L, d));
|
|
492
|
+
return w.map((L) => {
|
|
493
|
+
const { x: E, y: T, width: O, height: B } = L;
|
|
489
494
|
return {
|
|
490
|
-
minX:
|
|
491
|
-
minY:
|
|
492
|
-
maxX:
|
|
493
|
-
maxY:
|
|
495
|
+
minX: E,
|
|
496
|
+
minY: T,
|
|
497
|
+
maxX: E + O,
|
|
498
|
+
maxY: T + B,
|
|
494
499
|
annotation: {
|
|
495
500
|
id: c.annotation,
|
|
496
|
-
rects:
|
|
501
|
+
rects: w
|
|
497
502
|
}
|
|
498
503
|
};
|
|
499
504
|
});
|
|
500
|
-
},
|
|
505
|
+
}, l = () => [...n.values()], m = () => {
|
|
501
506
|
s.clear(), n.clear();
|
|
502
|
-
},
|
|
507
|
+
}, g = (c) => {
|
|
503
508
|
const d = a(c, e.getBoundingClientRect());
|
|
504
|
-
d.length !== 0 && (d.forEach((
|
|
505
|
-
},
|
|
509
|
+
d.length !== 0 && (d.forEach((R) => s.insert(R)), n.set(c.annotation, d));
|
|
510
|
+
}, y = (c) => {
|
|
506
511
|
const d = n.get(c.annotation);
|
|
507
|
-
d && (d.forEach((
|
|
508
|
-
},
|
|
509
|
-
|
|
510
|
-
},
|
|
511
|
-
d &&
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
|
|
512
|
+
d && (d.forEach((R) => s.remove(R)), n.delete(c.annotation));
|
|
513
|
+
}, p = (c) => {
|
|
514
|
+
y(c), g(c);
|
|
515
|
+
}, v = (c, d = !0) => {
|
|
516
|
+
d && m();
|
|
517
|
+
const R = e.getBoundingClientRect(), w = c.map((E) => ({ target: E, rects: a(E, R) }));
|
|
518
|
+
w.forEach(({ target: E, rects: T }) => {
|
|
519
|
+
T.length > 0 && n.set(E.annotation, T);
|
|
515
520
|
});
|
|
516
|
-
const
|
|
517
|
-
s.load(
|
|
518
|
-
},
|
|
519
|
-
const
|
|
521
|
+
const L = w.flatMap(({ rects: E }) => E);
|
|
522
|
+
s.load(L);
|
|
523
|
+
}, u = (c, d, R = !1) => {
|
|
524
|
+
const w = s.search({
|
|
520
525
|
minX: c,
|
|
521
526
|
minY: d,
|
|
522
527
|
maxX: c,
|
|
523
528
|
maxY: d
|
|
524
|
-
}),
|
|
525
|
-
return
|
|
526
|
-
},
|
|
527
|
-
const d =
|
|
529
|
+
}), L = (E) => E.annotation.rects.reduce((T, O) => T + O.width * O.height, 0);
|
|
530
|
+
return w.length > 0 ? (w.sort((E, T) => L(E) - L(T)), R ? w.map((E) => E.annotation.id) : [w[0].annotation.id]) : [];
|
|
531
|
+
}, x = (c) => {
|
|
532
|
+
const d = N(c);
|
|
528
533
|
if (d.length === 0)
|
|
529
534
|
return;
|
|
530
|
-
let
|
|
531
|
-
for (let
|
|
532
|
-
const O = d[
|
|
533
|
-
|
|
535
|
+
let R = d[0].left, w = d[0].top, L = d[0].right, E = d[0].bottom;
|
|
536
|
+
for (let T = 1; T < d.length; T++) {
|
|
537
|
+
const O = d[T];
|
|
538
|
+
R = Math.min(R, O.left), w = Math.min(w, O.top), L = Math.max(L, O.right), E = Math.max(E, O.bottom);
|
|
534
539
|
}
|
|
535
|
-
return new DOMRect(
|
|
536
|
-
},
|
|
540
|
+
return new DOMRect(R, w, L - R, E - w);
|
|
541
|
+
}, N = (c) => {
|
|
537
542
|
const d = n.get(c);
|
|
538
543
|
return d ? d[0].annotation.rects : [];
|
|
539
544
|
};
|
|
540
545
|
return {
|
|
541
|
-
all:
|
|
542
|
-
clear:
|
|
543
|
-
getAt:
|
|
544
|
-
getAnnotationBounds:
|
|
545
|
-
getAnnotationRects:
|
|
546
|
-
getIntersecting: (c, d,
|
|
547
|
-
const
|
|
548
|
-
return Array.from(
|
|
549
|
-
annotation: t.getAnnotation(
|
|
550
|
-
rects:
|
|
551
|
-
})).filter((
|
|
546
|
+
all: l,
|
|
547
|
+
clear: m,
|
|
548
|
+
getAt: u,
|
|
549
|
+
getAnnotationBounds: x,
|
|
550
|
+
getAnnotationRects: N,
|
|
551
|
+
getIntersecting: (c, d, R, w) => {
|
|
552
|
+
const L = s.search({ minX: c, minY: d, maxX: R, maxY: w }), E = new Set(L.map((T) => T.annotation.id));
|
|
553
|
+
return Array.from(E).map((T) => ({
|
|
554
|
+
annotation: t.getAnnotation(T),
|
|
555
|
+
rects: N(T)
|
|
556
|
+
})).filter((T) => !!T.annotation);
|
|
552
557
|
},
|
|
553
|
-
insert:
|
|
558
|
+
insert: g,
|
|
554
559
|
recalculate: () => {
|
|
555
|
-
|
|
560
|
+
v(t.all().map((c) => c.target), !0), r.emit("recalculate");
|
|
556
561
|
},
|
|
557
|
-
remove:
|
|
558
|
-
set:
|
|
562
|
+
remove: y,
|
|
563
|
+
set: v,
|
|
559
564
|
size: () => s.all().length,
|
|
560
|
-
update:
|
|
565
|
+
update: p,
|
|
561
566
|
on: (c, d) => r.on(c, d)
|
|
562
567
|
};
|
|
563
568
|
}, 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 = (
|
|
565
|
-
const
|
|
566
|
-
return c && o.addAnnotation(
|
|
567
|
-
},
|
|
568
|
-
const c =
|
|
569
|
-
return o.bulkAddAnnotations(c,
|
|
570
|
-
},
|
|
571
|
-
const
|
|
572
|
-
return
|
|
573
|
-
o.getAnnotation(d.id) ? o.updateAnnotation(d,
|
|
569
|
+
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 = (b, C = $.LOCAL) => {
|
|
570
|
+
const S = Z(b, t), c = D(S.target.selector);
|
|
571
|
+
return c && o.addAnnotation(S, C), c;
|
|
572
|
+
}, l = (b, C = !0, S = $.LOCAL) => {
|
|
573
|
+
const c = b.map((R) => Z(R, t)), d = c.filter((R) => !D(R.target.selector));
|
|
574
|
+
return o.bulkAddAnnotations(c, C, S), d;
|
|
575
|
+
}, m = (b, C = $.LOCAL) => {
|
|
576
|
+
const S = b.map((d) => Z(d, t)), c = S.filter((d) => !D(d.target.selector));
|
|
577
|
+
return S.forEach((d) => {
|
|
578
|
+
o.getAnnotation(d.id) ? o.updateAnnotation(d, C) : o.addAnnotation(d, C);
|
|
574
579
|
}), c;
|
|
575
|
-
},
|
|
576
|
-
const
|
|
577
|
-
o.updateTarget(
|
|
578
|
-
},
|
|
579
|
-
const
|
|
580
|
-
o.bulkUpdateTargets(
|
|
580
|
+
}, g = (b, C = $.LOCAL) => {
|
|
581
|
+
const S = Q(b, t);
|
|
582
|
+
o.updateTarget(S, C);
|
|
583
|
+
}, y = (b, C = $.LOCAL) => {
|
|
584
|
+
const S = b.map((c) => Q(c, t));
|
|
585
|
+
o.bulkUpdateTargets(S, C);
|
|
581
586
|
};
|
|
582
|
-
function
|
|
583
|
-
const d =
|
|
584
|
-
if (
|
|
585
|
-
return
|
|
587
|
+
function p(b, C, S, c) {
|
|
588
|
+
const d = S || !!c, R = i.getAt(b, C, d).map((L) => o.getAnnotation(L)).filter(Boolean), w = c ? R.filter(c) : R;
|
|
589
|
+
if (w.length !== 0)
|
|
590
|
+
return S ? w : w[0];
|
|
586
591
|
}
|
|
587
|
-
const
|
|
588
|
-
return o.observe(({ changes:
|
|
589
|
-
const
|
|
590
|
-
|
|
592
|
+
const v = (b) => i.getAnnotationRects(b).length > 0 ? i.getAnnotationBounds(b) : void 0, u = (b, C, S, c) => i.getIntersecting(b, C, S, c), x = (b) => i.getAnnotationRects(b), N = () => i.recalculate(), A = (b) => i.on("recalculate", b);
|
|
593
|
+
return o.observe(({ changes: b }) => {
|
|
594
|
+
const C = (b.deleted || []).filter((d) => D(d.target.selector)), S = (b.created || []).filter((d) => D(d.target.selector)), c = (b.updated || []).filter((d) => D(d.newValue.target.selector));
|
|
595
|
+
C?.length > 0 && C.forEach((d) => i.remove(d.target)), S.length > 0 && i.set(S.map((d) => d.target), !1), c?.length > 0 && c.forEach(({ newValue: d }) => i.update(d.target));
|
|
591
596
|
}), {
|
|
592
597
|
store: {
|
|
593
598
|
...o,
|
|
594
599
|
addAnnotation: a,
|
|
595
|
-
bulkAddAnnotations:
|
|
596
|
-
bulkUpdateTargets:
|
|
597
|
-
bulkUpsertAnnotations:
|
|
598
|
-
getAnnotationBounds:
|
|
599
|
-
getAnnotationRects:
|
|
600
|
-
getIntersecting:
|
|
601
|
-
getAt:
|
|
602
|
-
recalculatePositions:
|
|
603
|
-
onRecalculatePositions:
|
|
604
|
-
updateTarget:
|
|
600
|
+
bulkAddAnnotations: l,
|
|
601
|
+
bulkUpdateTargets: y,
|
|
602
|
+
bulkUpsertAnnotations: m,
|
|
603
|
+
getAnnotationBounds: v,
|
|
604
|
+
getAnnotationRects: x,
|
|
605
|
+
getIntersecting: u,
|
|
606
|
+
getAt: p,
|
|
607
|
+
recalculatePositions: N,
|
|
608
|
+
onRecalculatePositions: A,
|
|
609
|
+
updateTarget: g
|
|
605
610
|
},
|
|
606
611
|
selection: s,
|
|
607
612
|
hover: n,
|
|
@@ -615,160 +620,159 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
615
620
|
let r;
|
|
616
621
|
const {
|
|
617
622
|
annotatingEnabled: a,
|
|
618
|
-
offsetReferenceSelector:
|
|
619
|
-
selectionMode:
|
|
620
|
-
dismissOnNotAnnotatable:
|
|
623
|
+
offsetReferenceSelector: l,
|
|
624
|
+
selectionMode: m,
|
|
625
|
+
dismissOnNotAnnotatable: g = "NEVER"
|
|
621
626
|
} = i;
|
|
622
|
-
let
|
|
623
|
-
const
|
|
624
|
-
|
|
625
|
-
},
|
|
626
|
-
if (
|
|
627
|
+
let y, p = a, v = "CREATE_NEW", u, x, N, A;
|
|
628
|
+
const b = (f) => {
|
|
629
|
+
p = f, w.clear(), f || (x = void 0, u = void 0, N = void 0, A = void 0);
|
|
630
|
+
}, C = (f) => v = f || "CREATE_NEW", S = (f) => y = f, c = (f) => r = f, d = (f) => {
|
|
631
|
+
if (v === "ADD_TO_CURRENT")
|
|
627
632
|
return !0;
|
|
628
633
|
if (i.allowModifierSelect) {
|
|
629
|
-
const
|
|
630
|
-
return ut ?
|
|
634
|
+
const h = f;
|
|
635
|
+
return ut ? h.metaKey : h.ctrlKey;
|
|
631
636
|
} else
|
|
632
637
|
return !1;
|
|
633
|
-
},
|
|
634
|
-
if (!
|
|
638
|
+
}, R = () => {
|
|
639
|
+
if (!p || N === !1) return;
|
|
635
640
|
const { selected: f } = n;
|
|
636
|
-
if ((d(
|
|
641
|
+
if ((d(A) || v === "REPLACE_CURRENT") && f.length === 1 && f[0].editable) {
|
|
637
642
|
const M = s.getAnnotation(f[0].id);
|
|
638
643
|
if (M?.target) {
|
|
639
|
-
|
|
644
|
+
x = M.target, u = {
|
|
640
645
|
annotation: M.id,
|
|
641
646
|
selector: [],
|
|
642
|
-
created:
|
|
643
|
-
creator:
|
|
647
|
+
created: x.created,
|
|
648
|
+
creator: x.creator,
|
|
644
649
|
updated: /* @__PURE__ */ new Date(),
|
|
645
650
|
updatedBy: r
|
|
646
651
|
};
|
|
647
652
|
return;
|
|
648
653
|
}
|
|
649
654
|
}
|
|
650
|
-
|
|
655
|
+
x = void 0, u = {
|
|
651
656
|
annotation: lt(),
|
|
652
657
|
selector: [],
|
|
653
658
|
created: /* @__PURE__ */ new Date(),
|
|
654
659
|
creator: r
|
|
655
660
|
};
|
|
656
|
-
},
|
|
657
|
-
if (!
|
|
658
|
-
const
|
|
659
|
-
if (!
|
|
660
|
-
const
|
|
661
|
-
if (
|
|
662
|
-
|
|
661
|
+
}, w = It((f) => {
|
|
662
|
+
if (!p) return;
|
|
663
|
+
const h = document.getSelection();
|
|
664
|
+
if (!h?.anchorNode) return;
|
|
665
|
+
const H = Array.from(Array(h.rangeCount).keys()).map((k) => h.getRangeAt(k)).map((k) => Ft(k, t));
|
|
666
|
+
if (H.every((k) => !gt(t, k))) {
|
|
667
|
+
u = void 0;
|
|
663
668
|
return;
|
|
664
669
|
}
|
|
665
|
-
const
|
|
666
|
-
if (
|
|
670
|
+
const _ = f.timeStamp - (A?.timeStamp || f.timeStamp);
|
|
671
|
+
if (A?.type === "pointerdown" && (_ < 1e3 && !u || h.isCollapsed && _ < at) && R(), !u && (R(), !u))
|
|
667
672
|
return;
|
|
668
|
-
if (
|
|
669
|
-
s.getAnnotation(
|
|
673
|
+
if (h.isCollapsed) {
|
|
674
|
+
s.getAnnotation(u.annotation) && !(d(A) || v === "REPLACE_CURRENT") && (n.clear(), s.deleteAnnotation(u.annotation));
|
|
670
675
|
return;
|
|
671
676
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
...
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
selector: j.map((k) => Wt(k, t, u)),
|
|
677
|
+
if (H.every((k) => Ht(k))) return;
|
|
678
|
+
const I = H.flatMap((k) => $t(t, k.cloneRange()));
|
|
679
|
+
if (!(I.length > 0 && !u || I.length !== u.selector.length || I.some((k, Y) => k.toString() !== u?.selector[Y]?.quote))) return;
|
|
680
|
+
const j = d(A) && x ? Pt([
|
|
681
|
+
...x.selector.map((k) => k.range),
|
|
682
|
+
...I
|
|
683
|
+
]) : I;
|
|
684
|
+
u = {
|
|
685
|
+
...u,
|
|
686
|
+
selector: j.map((k) => Yt(k, t, l)),
|
|
683
687
|
updated: /* @__PURE__ */ new Date()
|
|
684
|
-
}, !(d(
|
|
685
|
-
}, 10),
|
|
686
|
-
|
|
687
|
-
},
|
|
688
|
-
if (!
|
|
689
|
-
const
|
|
690
|
-
const { x:
|
|
691
|
-
if (
|
|
692
|
-
(typeof
|
|
688
|
+
}, !(d(A) || v === "REPLACE_CURRENT") && (s.getAnnotation(u.annotation) ? s.updateTarget(u, $.LOCAL) : n.clear());
|
|
689
|
+
}, 10), L = (f) => {
|
|
690
|
+
A = J(f), N = A.button === 0;
|
|
691
|
+
}, E = async (f) => {
|
|
692
|
+
if (!N) return;
|
|
693
|
+
const h = J(f), M = () => {
|
|
694
|
+
const { x: _, y: I } = t.getBoundingClientRect();
|
|
695
|
+
if (F(t, h.target)) {
|
|
696
|
+
(typeof g == "function" ? g(h, t) : g === "ALWAYS") && n.clear();
|
|
693
697
|
return;
|
|
694
698
|
}
|
|
695
|
-
const
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
699
|
+
const P = h.target instanceof Node && t.contains(h.target) && s.getAt(
|
|
700
|
+
h.clientX - _,
|
|
701
|
+
h.clientY - I,
|
|
702
|
+
m === "all",
|
|
703
|
+
y
|
|
700
704
|
);
|
|
701
|
-
if (
|
|
702
|
-
const { selected: j } = n, k = new Set(j.map((X) => X.id)),
|
|
703
|
-
(k.size !==
|
|
705
|
+
if (P) {
|
|
706
|
+
const { selected: j } = n, k = new Set(j.map((X) => X.id)), Y = Array.isArray(P) ? P.map((X) => X.id) : [P.id];
|
|
707
|
+
(k.size !== Y.length || !Y.every((X) => k.has(X))) && (o.emit("clickAnnotation", P), n.userSelect(Y, h));
|
|
704
708
|
} else
|
|
705
709
|
n.clear();
|
|
706
710
|
};
|
|
707
|
-
if (
|
|
708
|
-
await
|
|
709
|
-
const
|
|
710
|
-
if (
|
|
711
|
-
|
|
711
|
+
if (h.timeStamp - (A?.timeStamp || 0) < at) {
|
|
712
|
+
await T();
|
|
713
|
+
const _ = document.getSelection(), I = F(t, A?.target), P = F(t, h.target);
|
|
714
|
+
if (_?.isCollapsed || I && P) {
|
|
715
|
+
u = void 0, M();
|
|
712
716
|
return;
|
|
713
717
|
}
|
|
714
718
|
}
|
|
715
|
-
|
|
716
|
-
},
|
|
719
|
+
u && u.selector.length > 0 && (K(), n.userSelect(u.annotation, h));
|
|
720
|
+
}, T = async () => {
|
|
717
721
|
const f = document.getSelection();
|
|
718
|
-
let
|
|
719
|
-
const
|
|
720
|
-
return setTimeout(() =>
|
|
722
|
+
let h = !1, M = f?.isCollapsed;
|
|
723
|
+
const H = () => M || h, _ = 1;
|
|
724
|
+
return setTimeout(() => h = !0, 50), Dt(() => M = f?.isCollapsed, _, H);
|
|
721
725
|
}, O = (f) => {
|
|
722
|
-
document.getSelection()?.isCollapsed || ((!
|
|
726
|
+
document.getSelection()?.isCollapsed || ((!u || u.selector.length === 0) && w(f), u && (K(), n.userSelect(u.annotation, J(f))));
|
|
723
727
|
}, B = (f) => {
|
|
724
|
-
if (
|
|
725
|
-
const
|
|
726
|
-
|
|
728
|
+
if (p && !(f.repeat || f.target instanceof Node && F(t, f.target) && f.target !== document.body) && f.key === "Shift" && u) {
|
|
729
|
+
const h = document.getSelection();
|
|
730
|
+
h && !h.isCollapsed && (K(), n.userSelect(u.annotation, G(f)));
|
|
727
731
|
}
|
|
728
732
|
}, V = (f) => {
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
id:
|
|
733
|
+
const h = () => setTimeout(() => {
|
|
734
|
+
u && (u.selector.length > 0 && (n.clear(), s.addAnnotation({
|
|
735
|
+
id: u.annotation,
|
|
732
736
|
bodies: [],
|
|
733
|
-
target:
|
|
734
|
-
}), n.userSelect(
|
|
737
|
+
target: u
|
|
738
|
+
}), n.userSelect(u.annotation, G(f))), document.removeEventListener("selectionchange", h));
|
|
735
739
|
}, 100);
|
|
736
|
-
document.addEventListener("selectionchange",
|
|
740
|
+
document.addEventListener("selectionchange", h), R();
|
|
737
741
|
};
|
|
738
742
|
q(de.join(","), { element: t, keydown: !0, keyup: !1 }, (f) => {
|
|
739
|
-
f.repeat || (
|
|
743
|
+
f.repeat || (A = G(f));
|
|
740
744
|
}), q(bt, { keydown: !0, keyup: !1 }, (f) => {
|
|
741
|
-
|
|
745
|
+
A = 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 && F(t, f.target) && f.target !== document.body || (u = 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 (!u) return;
|
|
753
|
+
const f = s.getAnnotation(u.annotation);
|
|
750
754
|
if (!f)
|
|
751
755
|
s.addAnnotation({
|
|
752
|
-
id:
|
|
756
|
+
id: u.annotation,
|
|
753
757
|
bodies: [],
|
|
754
|
-
target:
|
|
758
|
+
target: u
|
|
755
759
|
});
|
|
756
760
|
else {
|
|
757
|
-
const { target: { updated:
|
|
758
|
-
(!
|
|
761
|
+
const { target: { updated: h } } = f, { updated: M } = u;
|
|
762
|
+
(!h || !M || h < M) && s.updateTarget(u);
|
|
759
763
|
}
|
|
760
764
|
};
|
|
761
|
-
return document.addEventListener("pointerdown",
|
|
765
|
+
return document.addEventListener("pointerdown", L), document.addEventListener("pointerup", E), document.addEventListener("contextmenu", O), document.addEventListener("keyup", B), t.addEventListener("selectstart", R), document.addEventListener("selectionchange", w), {
|
|
762
766
|
destroy: () => {
|
|
763
|
-
|
|
767
|
+
u = void 0, x = void 0, N = void 0, A = void 0, w.clear(), document.removeEventListener("pointerdown", L), document.removeEventListener("pointerup", E), document.removeEventListener("contextmenu", O), document.removeEventListener("keyup", B), t.removeEventListener("selectstart", R), document.removeEventListener("selectionchange", w), q.unbind();
|
|
764
768
|
},
|
|
765
|
-
setFilter:
|
|
769
|
+
setFilter: S,
|
|
766
770
|
setUser: c,
|
|
767
|
-
setAnnotatingEnabled:
|
|
768
|
-
setAnnotatingMode:
|
|
771
|
+
setAnnotatingEnabled: b,
|
|
772
|
+
setAnnotatingMode: C
|
|
769
773
|
};
|
|
770
774
|
}, fe = (t) => [
|
|
771
|
-
`background-color:${et(t?.fill ||
|
|
775
|
+
`background-color:${et(t?.fill || U.fill).alpha(t?.fillOpacity === void 0 ? U.fillOpacity : t.fillOpacity).toHex()}`,
|
|
772
776
|
t?.underlineThickness ? "text-decoration:underline" : void 0,
|
|
773
777
|
t?.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
774
778
|
t?.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
@@ -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((
|
|
790
|
-
const
|
|
791
|
-
a ? typeof a == "function" && a(
|
|
792
|
-
const
|
|
793
|
-
return `::highlight(_${
|
|
791
|
+
redraw: (n, r, a, l, m) => {
|
|
792
|
+
const g = new Set(n.map((p) => p.annotation.id));
|
|
793
|
+
Array.from(e).filter((p) => !g.has(p));
|
|
794
|
+
const y = n.map((p) => {
|
|
795
|
+
a ? typeof a == "function" && a(p.annotation, p.state) : p.state?.selected;
|
|
796
|
+
const v = St(p, a);
|
|
797
|
+
return `::highlight(_${p.annotation.id}) { ${fe(v)} }`;
|
|
794
798
|
});
|
|
795
|
-
t.innerHTML =
|
|
796
|
-
`), CSS.highlights.clear(), n.forEach(({ annotation:
|
|
797
|
-
const
|
|
798
|
-
CSS.highlights.set(`_${
|
|
799
|
-
}), e =
|
|
799
|
+
t.innerHTML = y.join(`
|
|
800
|
+
`), CSS.highlights.clear(), n.forEach(({ annotation: p }) => {
|
|
801
|
+
const v = p.target.selector.map((x) => x.range), u = new Highlight(...v);
|
|
802
|
+
CSS.highlights.set(`_${p.id}`, u);
|
|
803
|
+
}), e = g;
|
|
800
804
|
}
|
|
801
805
|
};
|
|
802
806
|
}, me = (t, e, o) => yt(ge(), t, e, o), pe = (t, e) => ({
|
|
@@ -808,79 +812,80 @@ 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, y = 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 (!y)
|
|
827
831
|
throw `Unknown renderer implementation: ${o.renderer}`;
|
|
828
|
-
console.debug(
|
|
829
|
-
const
|
|
832
|
+
console.debug(g ? `Using ${g} renderer` : "Using custom renderer implementation"), o.style && y.setStyle(o.style);
|
|
833
|
+
const p = ue(
|
|
830
834
|
t,
|
|
831
835
|
i,
|
|
832
|
-
|
|
836
|
+
l,
|
|
833
837
|
o
|
|
834
838
|
);
|
|
835
|
-
|
|
836
|
-
const
|
|
837
|
-
|
|
839
|
+
p.setUser(m);
|
|
840
|
+
const v = Mt(i, a, o.adapter), u = () => m, x = (c) => {
|
|
841
|
+
p.setAnnotatingEnabled(
|
|
838
842
|
c === void 0 ? !0 : c
|
|
839
843
|
);
|
|
840
|
-
},
|
|
841
|
-
|
|
842
|
-
},
|
|
843
|
-
|
|
844
|
-
},
|
|
845
|
-
|
|
846
|
-
},
|
|
844
|
+
}, N = (c) => {
|
|
845
|
+
p.setAnnotatingMode(c);
|
|
846
|
+
}, A = (c) => {
|
|
847
|
+
y.setFilter(c), p.setFilter(c);
|
|
848
|
+
}, b = (c) => {
|
|
849
|
+
m = c, p.setUser(c);
|
|
850
|
+
}, C = (c) => {
|
|
847
851
|
c ? s.setSelected(c) : s.clear();
|
|
848
852
|
};
|
|
849
853
|
return {
|
|
850
|
-
...
|
|
854
|
+
...v,
|
|
851
855
|
destroy: () => {
|
|
852
|
-
|
|
856
|
+
y.destroy(), p.destroy(), a.destroy();
|
|
853
857
|
},
|
|
854
858
|
element: t,
|
|
855
|
-
getUser:
|
|
856
|
-
renderer:
|
|
857
|
-
setAnnotatingEnabled:
|
|
858
|
-
setAnnotatingMode:
|
|
859
|
-
setFilter:
|
|
860
|
-
setStyle:
|
|
861
|
-
setUser:
|
|
862
|
-
setSelected:
|
|
863
|
-
setVisible:
|
|
864
|
-
on:
|
|
865
|
-
off:
|
|
859
|
+
getUser: u,
|
|
860
|
+
renderer: y,
|
|
861
|
+
setAnnotatingEnabled: x,
|
|
862
|
+
setAnnotatingMode: N,
|
|
863
|
+
setFilter: A,
|
|
864
|
+
setStyle: y.setStyle.bind(y),
|
|
865
|
+
setUser: b,
|
|
866
|
+
setSelected: C,
|
|
867
|
+
setVisible: y.setVisible.bind(y),
|
|
868
|
+
on: l.on,
|
|
869
|
+
off: l.off,
|
|
870
|
+
// @ts-ignore - temporary
|
|
866
871
|
scrollIntoView: Xt(t, r),
|
|
867
872
|
state: i
|
|
868
873
|
};
|
|
869
874
|
};
|
|
870
875
|
export {
|
|
871
876
|
ot as DEFAULT_SELECTED_STYLE,
|
|
872
|
-
|
|
877
|
+
U as DEFAULT_STYLE,
|
|
873
878
|
ft as NOT_ANNOTATABLE_CLASS,
|
|
874
|
-
|
|
879
|
+
W 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
|
+
Wt as getQuoteContext,
|
|
894
899
|
nt as getRangeAnnotatableContents,
|
|
895
900
|
ie as getViewportBounds,
|
|
896
901
|
ut as isMac,
|
|
897
902
|
we as isNodeWhitespaceOrEmpty,
|
|
898
|
-
|
|
903
|
+
F as isNotAnnotatable,
|
|
899
904
|
gt as isRangeAnnotatable,
|
|
900
905
|
Ht as isRangeWhitespaceOrEmpty,
|
|
901
906
|
D as isRevived,
|
|
@@ -903,18 +908,18 @@ 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,
|
|
910
915
|
Xt as scrollIntoView,
|
|
911
916
|
qt as serializeW3CTextAnnotation,
|
|
912
|
-
|
|
917
|
+
$t as splitAnnotatableRanges,
|
|
913
918
|
Le as toDomRectList,
|
|
914
919
|
oe as toParentBounds,
|
|
915
920
|
Ne as toViewportBounds,
|
|
916
921
|
ae as trackViewport,
|
|
917
|
-
|
|
922
|
+
Ft as trimRangeToContainer,
|
|
918
923
|
mt as whitespaceOrEmptyRegex
|
|
919
924
|
};
|
|
920
925
|
//# sourceMappingURL=text-annotator.es.js.map
|