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