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