@recogito/text-annotator 3.0.0-rc.8 → 3.0.0-rc.9
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,7 +1,7 @@
|
|
|
1
1
|
const ft = { fill: "rgb(0, 128, 255", fillOpacity: 0.18 }, gt = { fill: "rgb(0, 128, 255)", fillOpacity: 0.45 }, nt = {
|
|
2
2
|
paint: (e, t, n, o, i, s) => {
|
|
3
|
-
const
|
|
4
|
-
n.fillStyle =
|
|
3
|
+
const r = s ? typeof s == "function" ? s(e, i) : s : i ? gt : ft;
|
|
4
|
+
n.fillStyle = r.fill, n.globalAlpha = r.fillOpacity || 1, t.forEach(({ x: a, y: d, width: u, height: b }) => n.fillRect(a, d - 2.5, u, b + 5));
|
|
5
5
|
}
|
|
6
6
|
}, pt = (e) => {
|
|
7
7
|
let t = /* @__PURE__ */ new Set();
|
|
@@ -28,13 +28,13 @@ const ft = { fill: "rgb(0, 128, 255", fillOpacity: 0.18 }, gt = { fill: "rgb(0,
|
|
|
28
28
|
}
|
|
29
29
|
}, bt = (e, t, n) => {
|
|
30
30
|
const { store: o, selection: i, hover: s } = t;
|
|
31
|
-
let
|
|
31
|
+
let r, a, d = nt;
|
|
32
32
|
const u = pt(n);
|
|
33
33
|
e.classList.add("r6o-annotatable");
|
|
34
34
|
const b = j("r6o-highlight-layer bg"), h = j("r6o-highlight-layer fg", !0), v = b.getContext("2d"), m = h.getContext("2d");
|
|
35
35
|
e.insertBefore(b, e.firstChild), e.appendChild(h), e.addEventListener("pointermove", (E) => {
|
|
36
36
|
const { x: T, y: L } = e.getBoundingClientRect(), f = o.getAt(E.clientX - T, E.clientY - L);
|
|
37
|
-
f && (!
|
|
37
|
+
f && (!a || a(f)) ? s.current !== f.id && (e.classList.add("hovered"), s.set(f.id)) : s.current && (e.classList.remove("hovered"), s.set(null));
|
|
38
38
|
});
|
|
39
39
|
const x = () => {
|
|
40
40
|
const { top: E, left: T } = e.getBoundingClientRect(), { innerWidth: L, innerHeight: f } = window, A = -T, w = -E, B = L - T, S = f - E;
|
|
@@ -46,59 +46,59 @@ const ft = { fill: "rgb(0, 128, 255", fillOpacity: 0.18 }, gt = { fill: "rgb(0,
|
|
|
46
46
|
});
|
|
47
47
|
window.addEventListener("resize", y), new ResizeObserver(y).observe(e);
|
|
48
48
|
const c = () => requestAnimationFrame(() => {
|
|
49
|
-
const { top: E, left: T, minX: L, minY: f, maxX: A, maxY: w } = x(), B =
|
|
50
|
-
m.clearRect(-0.5, -0.5, S + 1, R + 1), v.clearRect(-0.5, -0.5, S + 1, R + 1), B.forEach(({ annotation: Y, rects:
|
|
51
|
-
const
|
|
49
|
+
const { top: E, left: T, minX: L, minY: f, maxX: A, maxY: w } = x(), B = a ? o.getIntersectingRects(L, f, A, w).filter(({ annotation: Y }) => a(Y)) : o.getIntersectingRects(L, f, A, w), { width: S, height: R } = h, X = new Set(i.selected.map(({ id: Y }) => Y));
|
|
50
|
+
m.clearRect(-0.5, -0.5, S + 1, R + 1), v.clearRect(-0.5, -0.5, S + 1, R + 1), B.forEach(({ annotation: Y, rects: rt }) => {
|
|
51
|
+
const at = rt.map(({ x: ct, y: dt, width: ut, height: ht }) => ({
|
|
52
52
|
x: ct + T,
|
|
53
53
|
y: dt + E,
|
|
54
54
|
width: ut,
|
|
55
55
|
height: ht
|
|
56
56
|
})), lt = X.has(Y.id);
|
|
57
|
-
d.paint(Y,
|
|
57
|
+
d.paint(Y, at, v, m, lt, r);
|
|
58
58
|
}), setTimeout(() => u(B.map(({ annotation: Y }) => Y)), 1);
|
|
59
59
|
});
|
|
60
60
|
return o.observe(() => c()), i.subscribe(() => c()), {
|
|
61
61
|
redraw: c,
|
|
62
62
|
setDrawingStyle: (E) => {
|
|
63
|
-
|
|
63
|
+
r = E, c();
|
|
64
64
|
},
|
|
65
65
|
setFilter: (E) => {
|
|
66
|
-
|
|
66
|
+
a = E, c();
|
|
67
67
|
},
|
|
68
68
|
setPainter: (E) => d = E
|
|
69
69
|
};
|
|
70
|
-
},
|
|
70
|
+
}, _ = (e, t) => {
|
|
71
71
|
const { start: n, end: o } = e.selector, i = e.selector.offsetReference ? e.selector.offsetReference : t;
|
|
72
72
|
if (!i)
|
|
73
73
|
return e;
|
|
74
74
|
const s = document.createNodeIterator(t, NodeFilter.SHOW_TEXT);
|
|
75
|
-
let
|
|
75
|
+
let r = 0, a = document.createRange(), d = s.nextNode();
|
|
76
76
|
d === null && console.error("Could not revive annotation target. Content missing.");
|
|
77
77
|
let u = !i;
|
|
78
78
|
for (; d !== null; ) {
|
|
79
79
|
const b = d.textContent.length;
|
|
80
80
|
if (!u && i && (u = i.contains(d)), u) {
|
|
81
|
-
if (
|
|
82
|
-
|
|
81
|
+
if (r + b > n) {
|
|
82
|
+
a.setStart(d, n - r);
|
|
83
83
|
break;
|
|
84
84
|
}
|
|
85
|
-
|
|
85
|
+
r += b;
|
|
86
86
|
}
|
|
87
87
|
d = s.nextNode();
|
|
88
88
|
}
|
|
89
89
|
for (; d !== null; ) {
|
|
90
90
|
const b = d.textContent.length;
|
|
91
|
-
if (
|
|
92
|
-
|
|
91
|
+
if (r + b > o) {
|
|
92
|
+
a.setEnd(d, o - r);
|
|
93
93
|
break;
|
|
94
94
|
}
|
|
95
|
-
|
|
95
|
+
r += b, d = s.nextNode();
|
|
96
96
|
}
|
|
97
97
|
return {
|
|
98
98
|
...e,
|
|
99
99
|
selector: {
|
|
100
100
|
...e.selector,
|
|
101
|
-
range:
|
|
101
|
+
range: a
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
104
|
};
|
|
@@ -137,8 +137,8 @@ const D = [];
|
|
|
137
137
|
function J(e, t = W) {
|
|
138
138
|
let n;
|
|
139
139
|
const o = /* @__PURE__ */ new Set();
|
|
140
|
-
function i(
|
|
141
|
-
if (wt(e,
|
|
140
|
+
function i(a) {
|
|
141
|
+
if (wt(e, a) && (e = a, n)) {
|
|
142
142
|
const d = !D.length;
|
|
143
143
|
for (const u of o)
|
|
144
144
|
u[1](), D.push(u, e);
|
|
@@ -149,24 +149,24 @@ function J(e, t = W) {
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
-
function s(
|
|
153
|
-
i(
|
|
152
|
+
function s(a) {
|
|
153
|
+
i(a(e));
|
|
154
154
|
}
|
|
155
|
-
function a
|
|
156
|
-
const u = [
|
|
157
|
-
return o.add(u), o.size === 1 && (n = t(i, s) || W),
|
|
155
|
+
function r(a, d = W) {
|
|
156
|
+
const u = [a, d];
|
|
157
|
+
return o.add(u), o.size === 1 && (n = t(i, s) || W), a(e), () => {
|
|
158
158
|
o.delete(u), o.size === 0 && n && (n(), n = null);
|
|
159
159
|
};
|
|
160
160
|
}
|
|
161
|
-
return { set: i, update: s, subscribe:
|
|
161
|
+
return { set: i, update: s, subscribe: r };
|
|
162
162
|
}
|
|
163
163
|
const At = (e) => {
|
|
164
164
|
const { subscribe: t, set: n } = J();
|
|
165
165
|
let o;
|
|
166
166
|
return t((i) => o = i), e.observe(({ changes: i }) => {
|
|
167
167
|
if (o) {
|
|
168
|
-
(i.deleted || []).some((
|
|
169
|
-
const s = (i.updated || []).find(({ oldValue:
|
|
168
|
+
(i.deleted || []).some((r) => r.id === o) && n(void 0);
|
|
169
|
+
const s = (i.updated || []).find(({ oldValue: r }) => r.id === o);
|
|
170
170
|
s && n(s.newValue.id);
|
|
171
171
|
}
|
|
172
172
|
}), {
|
|
@@ -180,10 +180,10 @@ const At = (e) => {
|
|
|
180
180
|
const { subscribe: n, set: o } = J(q);
|
|
181
181
|
let i = q;
|
|
182
182
|
n((h) => i = h);
|
|
183
|
-
const s = () => o(q),
|
|
183
|
+
const s = () => o(q), r = () => {
|
|
184
184
|
var h;
|
|
185
185
|
return ((h = i.selected) == null ? void 0 : h.length) === 0;
|
|
186
|
-
},
|
|
186
|
+
}, a = (h) => {
|
|
187
187
|
if (i.selected.length === 0)
|
|
188
188
|
return !1;
|
|
189
189
|
const v = typeof h == "string" ? h : h.id;
|
|
@@ -213,8 +213,8 @@ const At = (e) => {
|
|
|
213
213
|
get pointerEvent() {
|
|
214
214
|
return i ? i.pointerEvent : null;
|
|
215
215
|
},
|
|
216
|
-
isEmpty:
|
|
217
|
-
isSelected:
|
|
216
|
+
isEmpty: r,
|
|
217
|
+
isSelected: a,
|
|
218
218
|
setSelected: u,
|
|
219
219
|
subscribe: n
|
|
220
220
|
};
|
|
@@ -249,25 +249,25 @@ const Mt = (e, t) => {
|
|
|
249
249
|
if (!(!e.options.origin || e.options.origin === s))
|
|
250
250
|
return !1;
|
|
251
251
|
if (e.options.ignore) {
|
|
252
|
-
const { ignore:
|
|
253
|
-
if (!(
|
|
254
|
-
const d = (n = i.updated) == null ? void 0 : n.some((b) =>
|
|
255
|
-
if (
|
|
252
|
+
const { ignore: r } = e.options, a = (d) => d && d.length > 0;
|
|
253
|
+
if (!(a(i.created) || a(i.deleted))) {
|
|
254
|
+
const d = (n = i.updated) == null ? void 0 : n.some((b) => a(b.bodiesCreated) || a(b.bodiesDeleted) || a(b.bodiesUpdated)), u = (o = i.updated) == null ? void 0 : o.some((b) => b.targetUpdated);
|
|
255
|
+
if (r === "BODY_ONLY" && d && !u || r === "TARGET_ONLY" && u && !d)
|
|
256
256
|
return !1;
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
if (e.options.annotations) {
|
|
260
|
-
const
|
|
261
|
-
...(i.created || []).map((
|
|
262
|
-
...(i.deleted || []).map((
|
|
263
|
-
...(i.updated || []).map(({ oldValue:
|
|
260
|
+
const r = /* @__PURE__ */ new Set([
|
|
261
|
+
...(i.created || []).map((a) => a.id),
|
|
262
|
+
...(i.deleted || []).map((a) => a.id),
|
|
263
|
+
...(i.updated || []).map(({ oldValue: a }) => a.id)
|
|
264
264
|
]);
|
|
265
|
-
return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((
|
|
265
|
+
return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((a) => r.has(a));
|
|
266
266
|
} else
|
|
267
267
|
return !0;
|
|
268
268
|
}, Lt = (e, t) => {
|
|
269
|
-
const n = new Set((e.created || []).map((h) => h.id)), o = new Set((e.updated || []).map(({ newValue: h }) => h.id)), i = new Set((t.created || []).map((h) => h.id)), s = new Set((t.deleted || []).map((h) => h.id)),
|
|
270
|
-
...(e.created || []).filter((h) => !s.has(h.id)).map((h) =>
|
|
269
|
+
const n = new Set((e.created || []).map((h) => h.id)), o = new Set((e.updated || []).map(({ newValue: h }) => h.id)), i = new Set((t.created || []).map((h) => h.id)), s = new Set((t.deleted || []).map((h) => h.id)), r = new Set((t.updated || []).map(({ oldValue: h }) => h.id)), a = new Set((t.updated || []).filter(({ oldValue: h }) => n.has(h.id) || o.has(h.id)).map(({ oldValue: h }) => h.id)), d = [
|
|
270
|
+
...(e.created || []).filter((h) => !s.has(h.id)).map((h) => r.has(h.id) ? t.updated.find(({ oldValue: v }) => v.id === h.id).newValue : h),
|
|
271
271
|
...t.created || []
|
|
272
272
|
], u = [
|
|
273
273
|
...(e.deleted || []).filter((h) => !i.has(h.id)),
|
|
@@ -275,13 +275,13 @@ const Mt = (e, t) => {
|
|
|
275
275
|
], b = [
|
|
276
276
|
...(e.updated || []).filter(({ newValue: h }) => !s.has(h.id)).map((h) => {
|
|
277
277
|
const { oldValue: v, newValue: m } = h;
|
|
278
|
-
if (
|
|
278
|
+
if (r.has(m.id)) {
|
|
279
279
|
const x = t.updated.find((M) => M.oldValue.id === m.id).newValue;
|
|
280
280
|
return ot(v, x);
|
|
281
281
|
} else
|
|
282
282
|
return h;
|
|
283
283
|
}),
|
|
284
|
-
...(t.updated || []).filter(({ oldValue: h }) => !
|
|
284
|
+
...(t.updated || []).filter(({ oldValue: h }) => !a.has(h.id))
|
|
285
285
|
];
|
|
286
286
|
return { created: d, deleted: u, updated: b };
|
|
287
287
|
}, Ct = (e) => e.id !== void 0, Rt = () => {
|
|
@@ -301,11 +301,11 @@ const Mt = (e, t) => {
|
|
|
301
301
|
n.forEach((B) => {
|
|
302
302
|
Mt(B, w) && B.onChange(w);
|
|
303
303
|
});
|
|
304
|
-
},
|
|
304
|
+
}, r = (f, A = C.LOCAL) => {
|
|
305
305
|
if (e.get(f.id))
|
|
306
306
|
throw Error(`Cannot add annotation ${f.id} - exists already`);
|
|
307
307
|
e.set(f.id, f), f.bodies.forEach((w) => t.set(w.id, f.id)), s(A, { created: [f] });
|
|
308
|
-
},
|
|
308
|
+
}, a = (f, A) => {
|
|
309
309
|
const w = typeof f == "string" ? A : f, B = typeof f == "string" ? f : f.id, S = e.get(B);
|
|
310
310
|
if (S) {
|
|
311
311
|
const R = ot(S, w);
|
|
@@ -313,11 +313,11 @@ const Mt = (e, t) => {
|
|
|
313
313
|
} else
|
|
314
314
|
console.warn(`Cannot update annotation ${B} - does not exist`);
|
|
315
315
|
}, d = (f, A = C.LOCAL, w = C.LOCAL) => {
|
|
316
|
-
const B = Ct(A) ? w : A, S =
|
|
316
|
+
const B = Ct(A) ? w : A, S = a(f, A);
|
|
317
317
|
S && s(B, { updated: [S] });
|
|
318
318
|
}, u = (f, A = C.LOCAL) => {
|
|
319
319
|
const w = f.reduce((B, S) => {
|
|
320
|
-
const R =
|
|
320
|
+
const R = a(S);
|
|
321
321
|
return R ? [...B, R] : B;
|
|
322
322
|
}, []);
|
|
323
323
|
w.length > 0 && s(A, { updated: w });
|
|
@@ -444,7 +444,7 @@ const Mt = (e, t) => {
|
|
|
444
444
|
console.warn(`Attempt to update target on missing annotation: ${f.annotation}`);
|
|
445
445
|
};
|
|
446
446
|
return {
|
|
447
|
-
addAnnotation:
|
|
447
|
+
addAnnotation: r,
|
|
448
448
|
addBody: b,
|
|
449
449
|
all: h,
|
|
450
450
|
bulkAddAnnotation: m,
|
|
@@ -487,7 +487,7 @@ let Ot = () => ({
|
|
|
487
487
|
const Xt = 250, Yt = (e) => {
|
|
488
488
|
const t = Ot(), n = [];
|
|
489
489
|
let o = -1, i = !1, s = 0;
|
|
490
|
-
const
|
|
490
|
+
const r = (m) => {
|
|
491
491
|
if (!i) {
|
|
492
492
|
const { changes: x } = m, M = performance.now();
|
|
493
493
|
if (M - s > Xt)
|
|
@@ -500,12 +500,12 @@ const Xt = 250, Yt = (e) => {
|
|
|
500
500
|
}
|
|
501
501
|
i = !1;
|
|
502
502
|
};
|
|
503
|
-
e.observe(
|
|
504
|
-
const
|
|
503
|
+
e.observe(r, { origin: C.LOCAL });
|
|
504
|
+
const a = (m) => m && m.length > 0 && e.bulkDeleteAnnotation(m), d = (m) => m && m.length > 0 && e.bulkAddAnnotation(m, !1), u = (m) => m && m.length > 0 && e.bulkUpdateAnnotation(m.map(({ oldValue: x }) => x)), b = (m) => m && m.length > 0 && e.bulkUpdateAnnotation(m.map(({ newValue: x }) => x)), h = (m) => m && m.length > 0 && e.bulkAddAnnotation(m, !1), v = (m) => m && m.length > 0 && e.bulkDeleteAnnotation(m);
|
|
505
505
|
return {
|
|
506
506
|
canRedo: () => n.length - 1 > o,
|
|
507
507
|
canUndo: () => o > -1,
|
|
508
|
-
destroy: () => e.unobserve(
|
|
508
|
+
destroy: () => e.unobserve(r),
|
|
509
509
|
on: (m, x) => t.on(m, x),
|
|
510
510
|
redo: () => {
|
|
511
511
|
if (n.length - 1 > o) {
|
|
@@ -518,7 +518,7 @@ const Xt = 250, Yt = (e) => {
|
|
|
518
518
|
if (o > -1) {
|
|
519
519
|
i = !0;
|
|
520
520
|
const { created: m, updated: x, deleted: M } = n[o];
|
|
521
|
-
|
|
521
|
+
a(m), u(x), h(M), t.emit("undo", n[o]), o -= 1;
|
|
522
522
|
}
|
|
523
523
|
}
|
|
524
524
|
};
|
|
@@ -529,7 +529,7 @@ const Xt = 250, Yt = (e) => {
|
|
|
529
529
|
set: t
|
|
530
530
|
};
|
|
531
531
|
}, Dt = (e, t, n, o) => {
|
|
532
|
-
const { store: i, selection: s, hover:
|
|
532
|
+
const { store: i, selection: s, hover: r, viewport: a } = e, d = /* @__PURE__ */ new Map();
|
|
533
533
|
let u = [], b, h;
|
|
534
534
|
const v = (l, c) => {
|
|
535
535
|
d.has(l) ? d.get(l).push(c) : d.set(l, [c]);
|
|
@@ -576,9 +576,9 @@ const Xt = 250, Yt = (e) => {
|
|
|
576
576
|
}
|
|
577
577
|
x("selectionChanged", u);
|
|
578
578
|
}
|
|
579
|
-
}),
|
|
579
|
+
}), r.subscribe((l) => {
|
|
580
580
|
!b && l ? x("mouseEnterAnnotation", i.getAnnotation(l)) : b && !l ? x("mouseLeaveAnnotation", i.getAnnotation(b)) : b && l && (x("mouseLeaveAnnotation", i.getAnnotation(b)), x("mouseEnterAnnotation", i.getAnnotation(l))), b = l;
|
|
581
|
-
}),
|
|
581
|
+
}), a == null || a.subscribe((l) => x("viewportIntersect", l.map((c) => i.getAnnotation(c)))), i.observe((l) => {
|
|
582
582
|
o && (h && clearTimeout(h), h = setTimeout(M, 1e3));
|
|
583
583
|
const { created: c, deleted: g } = l.changes;
|
|
584
584
|
(c || []).forEach((p) => x("createAnnotation", p)), (g || []).forEach((p) => x("deleteAnnotation", p)), (l.changes.updated || []).filter((p) => [
|
|
@@ -618,7 +618,7 @@ const Xt = 250, Yt = (e) => {
|
|
|
618
618
|
l ? o.addAnnotation(l, C.REMOTE) : console.error(c);
|
|
619
619
|
} else
|
|
620
620
|
o.addAnnotation(y, C.REMOTE);
|
|
621
|
-
},
|
|
621
|
+
}, r = () => i.clear(), a = () => o.clear(), d = (y) => {
|
|
622
622
|
const l = o.getAnnotation(y);
|
|
623
623
|
return n && l ? n.serialize(l) : l;
|
|
624
624
|
}, u = () => n ? o.all().map(n.serialize) : o.all(), b = () => {
|
|
@@ -654,10 +654,10 @@ const Xt = 250, Yt = (e) => {
|
|
|
654
654
|
};
|
|
655
655
|
return {
|
|
656
656
|
addAnnotation: s,
|
|
657
|
-
cancelSelected:
|
|
657
|
+
cancelSelected: r,
|
|
658
658
|
canRedo: t.canRedo,
|
|
659
659
|
canUndo: t.canUndo,
|
|
660
|
-
clearAnnotations:
|
|
660
|
+
clearAnnotations: a,
|
|
661
661
|
getAnnotationById: d,
|
|
662
662
|
getAnnotations: u,
|
|
663
663
|
getSelected: b,
|
|
@@ -673,12 +673,12 @@ const Xt = 250, Yt = (e) => {
|
|
|
673
673
|
let _t = (e) => crypto.getRandomValues(new Uint8Array(e)), kt = (e, t, n) => {
|
|
674
674
|
let o = (2 << Math.log(e.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * t / e.length);
|
|
675
675
|
return (s = t) => {
|
|
676
|
-
let
|
|
676
|
+
let r = "";
|
|
677
677
|
for (; ; ) {
|
|
678
|
-
let
|
|
678
|
+
let a = n(i), d = i;
|
|
679
679
|
for (; d--; )
|
|
680
|
-
if (
|
|
681
|
-
return
|
|
680
|
+
if (r += e[a[d] & o] || "", r.length === s)
|
|
681
|
+
return r;
|
|
682
682
|
}
|
|
683
683
|
};
|
|
684
684
|
}, Nt = (e, t = 21) => kt(e, t, _t), Pt = (e = 21) => crypto.getRandomValues(new Uint8Array(e)).reduce((t, n) => (n &= 63, n < 36 ? t += n.toString(36) : n < 62 ? t += (n - 26).toString(36).toUpperCase() : n > 62 ? t += "-" : t += "_", t), "");
|
|
@@ -690,20 +690,20 @@ function Ht(e, t, n, o, i) {
|
|
|
690
690
|
function it(e, t, n, o, i) {
|
|
691
691
|
for (; o > n; ) {
|
|
692
692
|
if (o - n > 600) {
|
|
693
|
-
var s = o - n + 1,
|
|
693
|
+
var s = o - n + 1, r = t - n + 1, a = Math.log(s), d = 0.5 * Math.exp(2 * a / 3), u = 0.5 * Math.sqrt(a * d * (s - d) / s) * (r - s / 2 < 0 ? -1 : 1), b = Math.max(n, Math.floor(t - r * d / s + u)), h = Math.min(o, Math.floor(t + (s - r) * d / s + u));
|
|
694
694
|
it(e, t, b, h, i);
|
|
695
695
|
}
|
|
696
696
|
var v = e[t], m = n, x = o;
|
|
697
|
-
for (
|
|
698
|
-
for (
|
|
697
|
+
for (k(e, n, t), i(e[o], v) > 0 && k(e, n, o); m < x; ) {
|
|
698
|
+
for (k(e, m, x), m++, x--; i(e[m], v) < 0; )
|
|
699
699
|
m++;
|
|
700
700
|
for (; i(e[x], v) > 0; )
|
|
701
701
|
x--;
|
|
702
702
|
}
|
|
703
|
-
i(e[n], v) === 0 ?
|
|
703
|
+
i(e[n], v) === 0 ? k(e, n, x) : (x++, k(e, x, o)), x <= t && (n = x + 1), t <= x && (o = x - 1);
|
|
704
704
|
}
|
|
705
705
|
}
|
|
706
|
-
function
|
|
706
|
+
function k(e, t, n) {
|
|
707
707
|
var o = e[t];
|
|
708
708
|
e[t] = e[n], e[n] = o;
|
|
709
709
|
}
|
|
@@ -724,9 +724,9 @@ class $t {
|
|
|
724
724
|
return o;
|
|
725
725
|
const i = this.toBBox, s = [];
|
|
726
726
|
for (; n; ) {
|
|
727
|
-
for (let
|
|
728
|
-
const
|
|
729
|
-
H(t, d) && (n.leaf ? o.push(
|
|
727
|
+
for (let r = 0; r < n.children.length; r++) {
|
|
728
|
+
const a = n.children[r], d = n.leaf ? i(a) : a;
|
|
729
|
+
H(t, d) && (n.leaf ? o.push(a) : K(t, d) ? this._all(a, o) : s.push(a));
|
|
730
730
|
}
|
|
731
731
|
n = s.pop();
|
|
732
732
|
}
|
|
@@ -739,9 +739,9 @@ class $t {
|
|
|
739
739
|
const o = [];
|
|
740
740
|
for (; n; ) {
|
|
741
741
|
for (let i = 0; i < n.children.length; i++) {
|
|
742
|
-
const s = n.children[i],
|
|
743
|
-
if (H(t,
|
|
744
|
-
if (n.leaf || K(t,
|
|
742
|
+
const s = n.children[i], r = n.leaf ? this.toBBox(s) : s;
|
|
743
|
+
if (H(t, r)) {
|
|
744
|
+
if (n.leaf || K(t, r))
|
|
745
745
|
return !0;
|
|
746
746
|
o.push(s);
|
|
747
747
|
}
|
|
@@ -782,15 +782,15 @@ class $t {
|
|
|
782
782
|
if (!t)
|
|
783
783
|
return this;
|
|
784
784
|
let o = this.data;
|
|
785
|
-
const i = this.toBBox(t), s = [],
|
|
786
|
-
let
|
|
785
|
+
const i = this.toBBox(t), s = [], r = [];
|
|
786
|
+
let a, d, u;
|
|
787
787
|
for (; o || s.length; ) {
|
|
788
|
-
if (o || (o = s.pop(), d = s[s.length - 1],
|
|
788
|
+
if (o || (o = s.pop(), d = s[s.length - 1], a = r.pop(), u = !0), o.leaf) {
|
|
789
789
|
const b = Wt(t, o.children, n);
|
|
790
790
|
if (b !== -1)
|
|
791
791
|
return o.children.splice(b, 1), s.push(o), this._condense(s), this;
|
|
792
792
|
}
|
|
793
|
-
!u && !o.leaf && K(o, i) ? (s.push(o),
|
|
793
|
+
!u && !o.leaf && K(o, i) ? (s.push(o), r.push(a), a = 0, d = o, o = o.children[0]) : d ? (a++, o = d.children[a], u = !1) : o = null;
|
|
794
794
|
}
|
|
795
795
|
return this;
|
|
796
796
|
}
|
|
@@ -817,36 +817,36 @@ class $t {
|
|
|
817
817
|
}
|
|
818
818
|
_build(t, n, o, i) {
|
|
819
819
|
const s = o - n + 1;
|
|
820
|
-
let
|
|
821
|
-
if (s <=
|
|
822
|
-
return
|
|
823
|
-
i || (i = Math.ceil(Math.log(s) / Math.log(
|
|
824
|
-
const d = Math.ceil(s /
|
|
820
|
+
let r = this._maxEntries, a;
|
|
821
|
+
if (s <= r)
|
|
822
|
+
return a = V(t.slice(n, o + 1)), I(a, this.toBBox), a;
|
|
823
|
+
i || (i = Math.ceil(Math.log(s) / Math.log(r)), r = Math.ceil(s / Math.pow(r, i - 1))), a = V([]), a.leaf = !1, a.height = i;
|
|
824
|
+
const d = Math.ceil(s / r), u = d * Math.ceil(Math.sqrt(r));
|
|
825
825
|
tt(t, n, o, u, this.compareMinX);
|
|
826
826
|
for (let b = n; b <= o; b += u) {
|
|
827
827
|
const h = Math.min(b + u - 1, o);
|
|
828
828
|
tt(t, b, h, d, this.compareMinY);
|
|
829
829
|
for (let v = b; v <= h; v += d) {
|
|
830
830
|
const m = Math.min(v + d - 1, h);
|
|
831
|
-
|
|
831
|
+
a.children.push(this._build(t, v, m, i - 1));
|
|
832
832
|
}
|
|
833
833
|
}
|
|
834
|
-
return I(
|
|
834
|
+
return I(a, this.toBBox), a;
|
|
835
835
|
}
|
|
836
836
|
_chooseSubtree(t, n, o, i) {
|
|
837
837
|
for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
|
|
838
|
-
let s = 1 / 0,
|
|
838
|
+
let s = 1 / 0, r = 1 / 0, a;
|
|
839
839
|
for (let d = 0; d < n.children.length; d++) {
|
|
840
840
|
const u = n.children[d], b = G(u), h = Kt(t, u) - b;
|
|
841
|
-
h <
|
|
841
|
+
h < r ? (r = h, s = b < s ? b : s, a = u) : h === r && b < s && (s = b, a = u);
|
|
842
842
|
}
|
|
843
|
-
n =
|
|
843
|
+
n = a || n.children[0];
|
|
844
844
|
}
|
|
845
845
|
return n;
|
|
846
846
|
}
|
|
847
847
|
_insert(t, n, o) {
|
|
848
|
-
const i = o ? t : this.toBBox(t), s = [],
|
|
849
|
-
for (
|
|
848
|
+
const i = o ? t : this.toBBox(t), s = [], r = this._chooseSubtree(i, this.data, n, s);
|
|
849
|
+
for (r.children.push(t), P(r, i); n >= 0 && s[n].children.length > this._maxEntries; )
|
|
850
850
|
this._split(s, n), n--;
|
|
851
851
|
this._adjustParentBBoxes(i, s, n);
|
|
852
852
|
}
|
|
@@ -854,37 +854,37 @@ class $t {
|
|
|
854
854
|
_split(t, n) {
|
|
855
855
|
const o = t[n], i = o.children.length, s = this._minEntries;
|
|
856
856
|
this._chooseSplitAxis(o, s, i);
|
|
857
|
-
const
|
|
858
|
-
|
|
857
|
+
const r = this._chooseSplitIndex(o, s, i), a = V(o.children.splice(r, o.children.length - r));
|
|
858
|
+
a.height = o.height, a.leaf = o.leaf, I(o, this.toBBox), I(a, this.toBBox), n ? t[n - 1].children.push(a) : this._splitRoot(o, a);
|
|
859
859
|
}
|
|
860
860
|
_splitRoot(t, n) {
|
|
861
861
|
this.data = V([t, n]), this.data.height = t.height + 1, this.data.leaf = !1, I(this.data, this.toBBox);
|
|
862
862
|
}
|
|
863
863
|
_chooseSplitIndex(t, n, o) {
|
|
864
|
-
let i, s = 1 / 0,
|
|
865
|
-
for (let
|
|
866
|
-
const d = N(t, 0,
|
|
867
|
-
b < s ? (s = b, i =
|
|
864
|
+
let i, s = 1 / 0, r = 1 / 0;
|
|
865
|
+
for (let a = n; a <= o - n; a++) {
|
|
866
|
+
const d = N(t, 0, a, this.toBBox), u = N(t, a, o, this.toBBox), b = Jt(d, u), h = G(d) + G(u);
|
|
867
|
+
b < s ? (s = b, i = a, r = h < r ? h : r) : b === s && h < r && (r = h, i = a);
|
|
868
868
|
}
|
|
869
869
|
return i || o - n;
|
|
870
870
|
}
|
|
871
871
|
// sorts node children by the best axis for split
|
|
872
872
|
_chooseSplitAxis(t, n, o) {
|
|
873
|
-
const i = t.leaf ? this.compareMinX : qt, s = t.leaf ? this.compareMinY : Gt,
|
|
874
|
-
|
|
873
|
+
const i = t.leaf ? this.compareMinX : qt, s = t.leaf ? this.compareMinY : Gt, r = this._allDistMargin(t, n, o, i), a = this._allDistMargin(t, n, o, s);
|
|
874
|
+
r < a && t.children.sort(i);
|
|
875
875
|
}
|
|
876
876
|
// total margin of all possible split distributions where each node is at least m full
|
|
877
877
|
_allDistMargin(t, n, o, i) {
|
|
878
878
|
t.children.sort(i);
|
|
879
|
-
const s = this.toBBox,
|
|
880
|
-
let d = z(
|
|
879
|
+
const s = this.toBBox, r = N(t, 0, n, s), a = N(t, o - n, o, s);
|
|
880
|
+
let d = z(r) + z(a);
|
|
881
881
|
for (let u = n; u < o - n; u++) {
|
|
882
882
|
const b = t.children[u];
|
|
883
|
-
P(
|
|
883
|
+
P(r, t.leaf ? s(b) : b), d += z(r);
|
|
884
884
|
}
|
|
885
885
|
for (let u = o - n - 1; u >= n; u--) {
|
|
886
886
|
const b = t.children[u];
|
|
887
|
-
P(
|
|
887
|
+
P(a, t.leaf ? s(b) : b), d += z(a);
|
|
888
888
|
}
|
|
889
889
|
return d;
|
|
890
890
|
}
|
|
@@ -911,8 +911,8 @@ function I(e, t) {
|
|
|
911
911
|
function N(e, t, n, o, i) {
|
|
912
912
|
i || (i = V(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
|
|
913
913
|
for (let s = t; s < n; s++) {
|
|
914
|
-
const
|
|
915
|
-
P(i, e.leaf ? o(
|
|
914
|
+
const r = e.children[s];
|
|
915
|
+
P(i, e.leaf ? o(r) : r);
|
|
916
916
|
}
|
|
917
917
|
return i;
|
|
918
918
|
}
|
|
@@ -960,8 +960,8 @@ function tt(e, t, n, o, i) {
|
|
|
960
960
|
for (; s.length; ) {
|
|
961
961
|
if (n = s.pop(), t = s.pop(), n - t <= o)
|
|
962
962
|
continue;
|
|
963
|
-
const
|
|
964
|
-
Ht(e,
|
|
963
|
+
const r = t + Math.ceil((n - t) / o / 2) * o;
|
|
964
|
+
Ht(e, r, t, n, i), s.push(t, r, r, n);
|
|
965
965
|
}
|
|
966
966
|
}
|
|
967
967
|
const jt = (e, t) => {
|
|
@@ -996,18 +996,18 @@ const jt = (e, t) => {
|
|
|
996
996
|
return t;
|
|
997
997
|
let o = [...t], i = !1;
|
|
998
998
|
for (const s of t) {
|
|
999
|
-
const
|
|
1000
|
-
if (
|
|
1001
|
-
o = o.map((
|
|
999
|
+
const r = jt(n, s);
|
|
1000
|
+
if (r === "inline-adjacent") {
|
|
1001
|
+
o = o.map((a) => a === s ? Zt(n, s) : a), i = !0;
|
|
1002
1002
|
break;
|
|
1003
|
-
} else if (
|
|
1004
|
-
o = o.map((
|
|
1003
|
+
} else if (r === "inline-contains") {
|
|
1004
|
+
o = o.map((a) => a === s ? n : a), i = !0;
|
|
1005
1005
|
break;
|
|
1006
|
-
} else if (
|
|
1006
|
+
} else if (r === "inline-is-contained") {
|
|
1007
1007
|
i = !0;
|
|
1008
1008
|
break;
|
|
1009
|
-
} else if (
|
|
1010
|
-
n.width < s.width && (o = o.map((
|
|
1009
|
+
} else if (r === "block-contains" || r === "block-is-contained") {
|
|
1010
|
+
n.width < s.width && (o = o.map((a) => a === s ? n : a)), i = !0;
|
|
1011
1011
|
break;
|
|
1012
1012
|
}
|
|
1013
1013
|
}
|
|
@@ -1017,17 +1017,17 @@ const jt = (e, t) => {
|
|
|
1017
1017
|
if (t.nodeType === Node.TEXT_NODE && n.nodeType === Node.TEXT_NODE)
|
|
1018
1018
|
return e;
|
|
1019
1019
|
if (t.nodeType !== Node.TEXT_NODE) {
|
|
1020
|
-
const i = t.nextSibling || t.parentNode, s = i.nodeType === Node.TEXT_NODE ? i : Array.from(i.childNodes).filter((
|
|
1020
|
+
const i = t.nextSibling || t.parentNode, s = i.nodeType === Node.TEXT_NODE ? i : Array.from(i.childNodes).filter((r) => r.nodeType === Node.TEXT_NODE).shift();
|
|
1021
1021
|
e.setEnd(s, 0);
|
|
1022
1022
|
}
|
|
1023
1023
|
if (n.nodeType !== Node.TEXT_NODE) {
|
|
1024
|
-
const i = n.previousSibling || n.parentNode, s = i.nodeType === Node.TEXT_NODE ? i : Array.from(i.childNodes).filter((
|
|
1024
|
+
const i = n.previousSibling || n.parentNode, s = i.nodeType === Node.TEXT_NODE ? i : Array.from(i.childNodes).filter((r) => r.nodeType === Node.TEXT_NODE).pop();
|
|
1025
1025
|
e.setEnd(s, s.textContent.length);
|
|
1026
1026
|
}
|
|
1027
1027
|
return e;
|
|
1028
1028
|
}, ee = (e, t) => {
|
|
1029
1029
|
const n = new $t(), o = /* @__PURE__ */ new Map(), i = (l) => {
|
|
1030
|
-
const c = t.getBoundingClientRect(), p = l.selector.range instanceof Range && !l.selector.range.collapsed && l.selector.range.startContainer.nodeType === Node.TEXT_NODE && l.selector.range.endContainer.nodeType === Node.TEXT_NODE ? l :
|
|
1030
|
+
const c = t.getBoundingClientRect(), p = l.selector.range instanceof Range && !l.selector.range.collapsed && l.selector.range.startContainer.nodeType === Node.TEXT_NODE && l.selector.range.endContainer.nodeType === Node.TEXT_NODE ? l : _(l, t), E = Array.from(p.selector.range.getClientRects()), T = Qt(E);
|
|
1031
1031
|
return T.map((L) => {
|
|
1032
1032
|
const { x: f, y: A, width: w, height: B } = L;
|
|
1033
1033
|
return {
|
|
@@ -1041,17 +1041,17 @@ const jt = (e, t) => {
|
|
|
1041
1041
|
}
|
|
1042
1042
|
};
|
|
1043
1043
|
});
|
|
1044
|
-
}, s = () => [...o.values()],
|
|
1044
|
+
}, s = () => [...o.values()], r = () => {
|
|
1045
1045
|
n.clear(), o.clear();
|
|
1046
|
-
},
|
|
1046
|
+
}, a = (l) => {
|
|
1047
1047
|
const c = i(l);
|
|
1048
1048
|
c.forEach((g) => n.insert(g)), o.set(l.annotation, c);
|
|
1049
1049
|
}, d = (l) => {
|
|
1050
1050
|
o.get(l.annotation).forEach((g) => n.remove(g)), o.delete(l.annotation);
|
|
1051
1051
|
}, u = (l) => {
|
|
1052
|
-
d(l),
|
|
1052
|
+
d(l), a(l);
|
|
1053
1053
|
}, b = (l, c = !0) => {
|
|
1054
|
-
c &&
|
|
1054
|
+
c && r();
|
|
1055
1055
|
const g = l.map((E) => ({ target: E, rects: i(E) }));
|
|
1056
1056
|
g.forEach(({ target: E, rects: T }) => o.set(E.annotation, T));
|
|
1057
1057
|
const p = g.reduce((E, { rects: T }) => [...E, ...T], []);
|
|
@@ -1081,12 +1081,12 @@ const jt = (e, t) => {
|
|
|
1081
1081
|
};
|
|
1082
1082
|
return {
|
|
1083
1083
|
all: s,
|
|
1084
|
-
clear:
|
|
1084
|
+
clear: r,
|
|
1085
1085
|
getAt: h,
|
|
1086
1086
|
getBoundsForAnnotation: v,
|
|
1087
1087
|
getDOMRectsForAnnotation: m,
|
|
1088
1088
|
getIntersectingRects: (l, c, g, p) => n.search({ minX: l, minY: c, maxX: g, maxY: p }),
|
|
1089
|
-
insert:
|
|
1089
|
+
insert: a,
|
|
1090
1090
|
recalculate: () => b(e.all().map((l) => l.target), !0),
|
|
1091
1091
|
remove: d,
|
|
1092
1092
|
set: b,
|
|
@@ -1097,21 +1097,21 @@ const jt = (e, t) => {
|
|
|
1097
1097
|
const { range: t } = e.target.selector;
|
|
1098
1098
|
return t instanceof Range && !t.collapsed;
|
|
1099
1099
|
}, ne = (e, t) => {
|
|
1100
|
-
const n = Rt(), o = ee(n, e), i = xt(n, t), s = At(n),
|
|
1101
|
-
const c = y.target.selector.range instanceof Range ? y : { ...y, target:
|
|
1100
|
+
const n = Rt(), o = ee(n, e), i = xt(n, t), s = At(n), r = Ut(), a = (y, l = C.LOCAL) => {
|
|
1101
|
+
const c = y.target.selector.range instanceof Range ? y : { ...y, target: _(y.target, e) }, { range: g } = c.target.selector, p = g && !g.collapsed;
|
|
1102
1102
|
return p && n.addAnnotation(c, l), p;
|
|
1103
1103
|
}, d = (y, l = !0, c = C.LOCAL) => {
|
|
1104
|
-
const g = y.map((E) => F(E) ? E : { ...E, target:
|
|
1104
|
+
const g = y.map((E) => F(E) ? E : { ...E, target: _(E.target, e) });
|
|
1105
1105
|
if (g.some((E) => E.target.selector.range.collapsed)) {
|
|
1106
1106
|
const E = g.filter((T) => T.target.selector.range.collapsed);
|
|
1107
1107
|
return console.warn("Could not revive all targets"), console.warn(E), n.bulkAddAnnotation(g, l, c), E;
|
|
1108
1108
|
} else
|
|
1109
1109
|
return n.bulkAddAnnotation(g, l, c), [];
|
|
1110
1110
|
}, u = (y, l = C.LOCAL) => {
|
|
1111
|
-
const c = y.selector.range instanceof Range ? y :
|
|
1111
|
+
const c = y.selector.range instanceof Range ? y : _(y, e);
|
|
1112
1112
|
n.updateTarget(c, l);
|
|
1113
1113
|
}, b = (y, l = C.LOCAL) => {
|
|
1114
|
-
const c = y.map((g) => g.selector.range instanceof Range ? g :
|
|
1114
|
+
const c = y.map((g) => g.selector.range instanceof Range ? g : _(g, e));
|
|
1115
1115
|
n.bulkUpdateTargets(c, l);
|
|
1116
1116
|
}, h = (y, l) => {
|
|
1117
1117
|
const c = o.getAt(y, l);
|
|
@@ -1142,7 +1142,7 @@ const jt = (e, t) => {
|
|
|
1142
1142
|
}), {
|
|
1143
1143
|
store: {
|
|
1144
1144
|
...n,
|
|
1145
|
-
addAnnotation:
|
|
1145
|
+
addAnnotation: a,
|
|
1146
1146
|
bulkAddAnnotation: d,
|
|
1147
1147
|
bulkUpdateTargets: b,
|
|
1148
1148
|
getAnnotationBounds: m,
|
|
@@ -1154,22 +1154,22 @@ const jt = (e, t) => {
|
|
|
1154
1154
|
},
|
|
1155
1155
|
selection: i,
|
|
1156
1156
|
hover: s,
|
|
1157
|
-
viewport:
|
|
1157
|
+
viewport: r
|
|
1158
1158
|
};
|
|
1159
1159
|
}, oe = (e, t = {}) => {
|
|
1160
|
-
const n = /* @__PURE__ */ new Map(), o = (s) => Array.from(n.entries()).filter(([
|
|
1161
|
-
return e.on("selectionChange", (s,
|
|
1162
|
-
o(s).forEach((d) => n.delete(d)),
|
|
1163
|
-
}), { paint: (s,
|
|
1160
|
+
const n = /* @__PURE__ */ new Map(), o = (s) => Array.from(n.entries()).filter(([r, a]) => a.presenceKey === s.presenceKey).map(([r, a]) => r);
|
|
1161
|
+
return e.on("selectionChange", (s, r) => {
|
|
1162
|
+
o(s).forEach((d) => n.delete(d)), r && r.forEach((d) => n.set(d, s));
|
|
1163
|
+
}), { paint: (s, r, a, d, u, b) => {
|
|
1164
1164
|
t.font && (d.font = t.font);
|
|
1165
1165
|
const h = n.get(s.id);
|
|
1166
1166
|
if (h) {
|
|
1167
|
-
const { x: v, y: m, height: x } =
|
|
1167
|
+
const { x: v, y: m, height: x } = r[0];
|
|
1168
1168
|
d.fillStyle = h.appearance.color, d.fillRect(v - 2, m - 2.5, 2, x + 5);
|
|
1169
1169
|
const M = d.measureText(h.appearance.label), y = M.width + 6, l = M.actualBoundingBoxAscent + M.actualBoundingBoxDescent + 8, c = M.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1170
|
-
d.fillRect(v - 2, m - 2.5 - l, y, l), d.fillStyle = "#fff", d.fillText(h.appearance.label, v + 1, m - c),
|
|
1170
|
+
d.fillRect(v - 2, m - 2.5 - l, y, l), d.fillStyle = "#fff", d.fillText(h.appearance.label, v + 1, m - c), a.fillStyle = h.appearance.color, a.globalAlpha = u ? 0.45 : 0.18, r.forEach(({ x: g, y: p, width: E, height: T }) => a.fillRect(g, p - 2.5, E, T + 5));
|
|
1171
1171
|
} else
|
|
1172
|
-
nt.paint(s,
|
|
1172
|
+
nt.paint(s, r, a, d, u, b);
|
|
1173
1173
|
} };
|
|
1174
1174
|
}, st = (e) => {
|
|
1175
1175
|
if (e === null)
|
|
@@ -1177,18 +1177,25 @@ const jt = (e, t) => {
|
|
|
1177
1177
|
const { overflowY: t } = window.getComputedStyle(e);
|
|
1178
1178
|
return t !== "visible" && t !== "hidden" && e.scrollHeight > e.clientHeight ? e : st(e.parentElement);
|
|
1179
1179
|
}, ie = (e, t) => (n) => {
|
|
1180
|
-
const o =
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
const
|
|
1186
|
-
|
|
1180
|
+
const o = (s) => {
|
|
1181
|
+
const r = i.getBoundingClientRect(), a = i.clientHeight, d = i.clientWidth, u = s.selector.range.getBoundingClientRect(), { width: b, height: h } = t.getAnnotationBounds(n.id), v = u.top - r.top, m = u.left - r.left, x = i.parentElement ? i.scrollTop : 0, M = i.parentElement ? i.scrollLeft : 0, y = v + x - (a - h) / 2, l = m + M - (d - b) / 2;
|
|
1182
|
+
i.scroll({ top: y, left: l, behavior: "smooth" });
|
|
1183
|
+
}, i = st(e);
|
|
1184
|
+
if (i) {
|
|
1185
|
+
const s = t.getAnnotation(n.id), { range: r } = s.target.selector;
|
|
1186
|
+
if (r && !r.collapsed)
|
|
1187
|
+
return o(s.target), !0;
|
|
1188
|
+
{
|
|
1189
|
+
const a = _(s.target, e);
|
|
1190
|
+
if (a.selector.range && !a.selector.range.collapsed)
|
|
1191
|
+
return console.log("scrolling revived"), o(a), !0;
|
|
1192
|
+
}
|
|
1187
1193
|
}
|
|
1194
|
+
return !1;
|
|
1188
1195
|
};
|
|
1189
1196
|
let $;
|
|
1190
1197
|
const se = new Uint8Array(16);
|
|
1191
|
-
function
|
|
1198
|
+
function re() {
|
|
1192
1199
|
if (!$ && ($ = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !$))
|
|
1193
1200
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
1194
1201
|
return $(se);
|
|
@@ -1196,7 +1203,7 @@ function ae() {
|
|
|
1196
1203
|
const O = [];
|
|
1197
1204
|
for (let e = 0; e < 256; ++e)
|
|
1198
1205
|
O.push((e + 256).toString(16).slice(1));
|
|
1199
|
-
function
|
|
1206
|
+
function ae(e, t = 0) {
|
|
1200
1207
|
return O[e[t + 0]] + O[e[t + 1]] + O[e[t + 2]] + O[e[t + 3]] + "-" + O[e[t + 4]] + O[e[t + 5]] + "-" + O[e[t + 6]] + O[e[t + 7]] + "-" + O[e[t + 8]] + O[e[t + 9]] + "-" + O[e[t + 10]] + O[e[t + 11]] + O[e[t + 12]] + O[e[t + 13]] + O[e[t + 14]] + O[e[t + 15]];
|
|
1201
1208
|
}
|
|
1202
1209
|
const le = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), et = {
|
|
@@ -1206,34 +1213,34 @@ function ce(e, t, n) {
|
|
|
1206
1213
|
if (et.randomUUID && !t && !e)
|
|
1207
1214
|
return et.randomUUID();
|
|
1208
1215
|
e = e || {};
|
|
1209
|
-
const o = e.random || (e.rng ||
|
|
1216
|
+
const o = e.random || (e.rng || re)();
|
|
1210
1217
|
if (o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, t) {
|
|
1211
1218
|
n = n || 0;
|
|
1212
1219
|
for (let i = 0; i < 16; ++i)
|
|
1213
1220
|
t[n + i] = o[i];
|
|
1214
1221
|
return t;
|
|
1215
1222
|
}
|
|
1216
|
-
return
|
|
1223
|
+
return ae(o);
|
|
1217
1224
|
}
|
|
1218
1225
|
const de = (e, t, n) => {
|
|
1219
1226
|
const o = document.createRange(), i = n ? e.startContainer.parentElement.closest(n) : t;
|
|
1220
1227
|
o.setStart(i, 0), o.setEnd(e.startContainer, e.startOffset);
|
|
1221
|
-
const s = e.toString(),
|
|
1222
|
-
return n ? { quote: s, start:
|
|
1228
|
+
const s = e.toString(), r = o.toString().length, a = r + s.length;
|
|
1229
|
+
return n ? { quote: s, start: r, end: a, range: e, offsetReference: i } : { quote: s, start: r, end: a, range: e };
|
|
1223
1230
|
}, ue = (e, t, n) => {
|
|
1224
1231
|
const { store: o, selection: i } = t;
|
|
1225
|
-
let s,
|
|
1226
|
-
const
|
|
1232
|
+
let s, r = null;
|
|
1233
|
+
const a = (v) => s = v;
|
|
1227
1234
|
let d = !1, u;
|
|
1228
1235
|
e.addEventListener("selectstart", (v) => {
|
|
1229
1236
|
if (!d)
|
|
1230
1237
|
return;
|
|
1231
|
-
!v.target.parentElement.closest(".not-annotatable") ?
|
|
1238
|
+
!v.target.parentElement.closest(".not-annotatable") ? r = {
|
|
1232
1239
|
annotation: ce(),
|
|
1233
1240
|
selector: void 0,
|
|
1234
1241
|
creator: s,
|
|
1235
1242
|
created: /* @__PURE__ */ new Date()
|
|
1236
|
-
} : (
|
|
1243
|
+
} : (r = null, u = void 0);
|
|
1237
1244
|
});
|
|
1238
1245
|
let b;
|
|
1239
1246
|
document.addEventListener("selectionchange", (v) => {
|
|
@@ -1242,16 +1249,16 @@ const de = (e, t, n) => {
|
|
|
1242
1249
|
const h = () => {
|
|
1243
1250
|
var m, x;
|
|
1244
1251
|
const v = document.getSelection();
|
|
1245
|
-
if (!v.isCollapsed && d &&
|
|
1252
|
+
if (!v.isCollapsed && d && r) {
|
|
1246
1253
|
const M = Array.from(Array(v.rangeCount).keys()).map((c) => v.getRangeAt(c));
|
|
1247
|
-
te(M[0]).toString() !== ((x = (m =
|
|
1248
|
-
...
|
|
1254
|
+
te(M[0]).toString() !== ((x = (m = r.selector) == null ? void 0 : m.range) == null ? void 0 : x.toString()) && (r = {
|
|
1255
|
+
...r,
|
|
1249
1256
|
selector: de(M[0], e, n)
|
|
1250
|
-
}, o.getAnnotation(
|
|
1251
|
-
id:
|
|
1257
|
+
}, o.getAnnotation(r.annotation) ? o.updateTarget(r, C.LOCAL) : (o.addAnnotation({
|
|
1258
|
+
id: r.annotation,
|
|
1252
1259
|
bodies: [],
|
|
1253
|
-
target:
|
|
1254
|
-
}), i.clickSelect(
|
|
1260
|
+
target: r
|
|
1261
|
+
}), i.clickSelect(r.annotation, u)));
|
|
1255
1262
|
}
|
|
1256
1263
|
};
|
|
1257
1264
|
return e.addEventListener("pointerdown", (v) => {
|
|
@@ -1259,8 +1266,8 @@ const de = (e, t, n) => {
|
|
|
1259
1266
|
}), document.addEventListener("pointerup", (v) => {
|
|
1260
1267
|
var x;
|
|
1261
1268
|
u = v, !((x = v.target.parentElement) != null && x.closest(".not-annotatable") || !d) && setTimeout(() => {
|
|
1262
|
-
if (
|
|
1263
|
-
o.updateTarget(
|
|
1269
|
+
if (r != null && r.selector)
|
|
1270
|
+
o.updateTarget(r, C.LOCAL), i.clickSelect(r.annotation, v), r = null, u = void 0;
|
|
1264
1271
|
else {
|
|
1265
1272
|
const { x: M, y } = e.getBoundingClientRect(), l = o.getAt(v.clientX - M, v.clientY - y);
|
|
1266
1273
|
if (l) {
|
|
@@ -1271,12 +1278,12 @@ const de = (e, t, n) => {
|
|
|
1271
1278
|
}
|
|
1272
1279
|
}, 50);
|
|
1273
1280
|
}), {
|
|
1274
|
-
setUser:
|
|
1281
|
+
setUser: a
|
|
1275
1282
|
};
|
|
1276
1283
|
}, he = (e, t = {}) => {
|
|
1277
|
-
const n = ne(e, t.pointerAction), { selection: o, viewport: i } = n, s = n.store,
|
|
1284
|
+
const n = ne(e, t.pointerAction), { selection: o, viewport: i } = n, s = n.store, r = Yt(s), a = Dt(
|
|
1278
1285
|
n,
|
|
1279
|
-
|
|
1286
|
+
r,
|
|
1280
1287
|
t.adapter
|
|
1281
1288
|
);
|
|
1282
1289
|
let d = zt();
|
|
@@ -1284,7 +1291,7 @@ const de = (e, t, n) => {
|
|
|
1284
1291
|
t.style && u.setDrawingStyle(t.style);
|
|
1285
1292
|
const b = ue(e, n, t.offsetReferenceSelector);
|
|
1286
1293
|
return b.setUser(d), {
|
|
1287
|
-
...Vt(n,
|
|
1294
|
+
...Vt(n, r, t.adapter),
|
|
1288
1295
|
destroy: () => {
|
|
1289
1296
|
throw "Not implemented yet";
|
|
1290
1297
|
},
|
|
@@ -1301,8 +1308,8 @@ const de = (e, t, n) => {
|
|
|
1301
1308
|
setPresenceProvider: (g) => {
|
|
1302
1309
|
g && (u.setPainter(oe(g, t.presence)), g.on("selectionChange", () => u.redraw()));
|
|
1303
1310
|
},
|
|
1304
|
-
on:
|
|
1305
|
-
off:
|
|
1311
|
+
on: a.on,
|
|
1312
|
+
off: a.off,
|
|
1306
1313
|
scrollIntoView: ie(e, s),
|
|
1307
1314
|
state: n
|
|
1308
1315
|
};
|
|
@@ -1313,6 +1320,6 @@ export {
|
|
|
1313
1320
|
he as createTextAnnotator,
|
|
1314
1321
|
ne as createTextAnnotatorState,
|
|
1315
1322
|
nt as defaultPainter,
|
|
1316
|
-
|
|
1323
|
+
_ as reviveTarget
|
|
1317
1324
|
};
|
|
1318
1325
|
//# sourceMappingURL=text-annotator.es.js.map
|