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