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