@recogito/text-annotator 3.0.0-rc.28 → 3.0.0-rc.29
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.
|
@@ -43,7 +43,7 @@ const P = {
|
|
|
43
43
|
// Allow clicks within not-annotatable elements
|
|
44
44
|
!e.target.closest(X) && !e.target.closest("a") && e.preventDefault();
|
|
45
45
|
});
|
|
46
|
-
},
|
|
46
|
+
}, pt = (t, e = 10) => {
|
|
47
47
|
let n;
|
|
48
48
|
return (...o) => {
|
|
49
49
|
clearTimeout(n), n = setTimeout(() => t.apply(void 0, o), e);
|
|
@@ -73,30 +73,30 @@ const P = {
|
|
|
73
73
|
endContainer: i,
|
|
74
74
|
endOffset: r
|
|
75
75
|
} = t, a = Array.from(e.childNodes).map((c) => {
|
|
76
|
-
const
|
|
77
|
-
return c.nodeName === "CANVAS" ? c :
|
|
78
|
-
}), s = vt(n, e), u = vt(i, e),
|
|
76
|
+
const p = c.cloneNode(!0);
|
|
77
|
+
return c.nodeName === "CANVAS" ? c : p;
|
|
78
|
+
}), s = vt(n, e), u = vt(i, e), f = () => {
|
|
79
79
|
const c = e;
|
|
80
80
|
c.replaceChildren(...a);
|
|
81
|
-
const
|
|
82
|
-
return t.setStart(
|
|
81
|
+
const p = yt(s, c), g = yt(u, c);
|
|
82
|
+
return t.setStart(p, o), t.setEnd(g, r), t;
|
|
83
83
|
}, m = (c) => {
|
|
84
|
-
const
|
|
85
|
-
return c.surroundContents(
|
|
84
|
+
const p = document.createElement("SPAN");
|
|
85
|
+
return c.surroundContents(p), p;
|
|
86
86
|
};
|
|
87
87
|
if (n === i)
|
|
88
88
|
throw "Not implemented";
|
|
89
89
|
{
|
|
90
90
|
const c = document.createRange();
|
|
91
91
|
c.selectNodeContents(n), c.setStart(n, o);
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
const x = m(
|
|
92
|
+
const p = m(c), g = document.createRange();
|
|
93
|
+
g.selectNode(i), g.setEnd(i, r);
|
|
94
|
+
const x = m(g), h = Zt(t).reverse().map((d) => {
|
|
95
95
|
var y;
|
|
96
|
-
const
|
|
97
|
-
return (y =
|
|
96
|
+
const l = document.createElement("SPAN");
|
|
97
|
+
return (y = d.parentNode) == null || y.insertBefore(l, d), l.appendChild(d), l;
|
|
98
98
|
});
|
|
99
|
-
return { unwrap:
|
|
99
|
+
return { unwrap: f, nodes: [p, ...h, x] };
|
|
100
100
|
}
|
|
101
101
|
}, Zt = (t) => {
|
|
102
102
|
const {
|
|
@@ -185,34 +185,34 @@ const P = {
|
|
|
185
185
|
const { start: n, end: o } = t, i = t.offsetReference || e, r = document.createNodeIterator(
|
|
186
186
|
e,
|
|
187
187
|
NodeFilter.SHOW_TEXT,
|
|
188
|
-
(
|
|
189
|
-
var
|
|
190
|
-
return (
|
|
188
|
+
(p) => {
|
|
189
|
+
var g;
|
|
190
|
+
return (g = p.parentElement) != null && g.closest(X) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
|
|
191
191
|
}
|
|
192
192
|
);
|
|
193
193
|
let a = 0;
|
|
194
194
|
const s = document.createRange();
|
|
195
195
|
let u = r.nextNode();
|
|
196
196
|
u === null && console.error("Could not revive annotation target. Content missing.");
|
|
197
|
-
let
|
|
197
|
+
let f = !i;
|
|
198
198
|
for (; u !== null; ) {
|
|
199
|
-
if (
|
|
200
|
-
const
|
|
201
|
-
if (a +
|
|
199
|
+
if (f || (f = i == null ? void 0 : i.contains(u)), f) {
|
|
200
|
+
const p = ((m = u.textContent) == null ? void 0 : m.length) || 0;
|
|
201
|
+
if (a + p > n) {
|
|
202
202
|
s.setStart(u, n - a);
|
|
203
203
|
break;
|
|
204
204
|
}
|
|
205
|
-
a +=
|
|
205
|
+
a += p;
|
|
206
206
|
}
|
|
207
207
|
u = r.nextNode();
|
|
208
208
|
}
|
|
209
209
|
for (; u !== null; ) {
|
|
210
|
-
const
|
|
211
|
-
if (a +
|
|
210
|
+
const p = ((c = u.textContent) == null ? void 0 : c.length) || 0;
|
|
211
|
+
if (a + p >= o) {
|
|
212
212
|
s.setEnd(u, o - a);
|
|
213
213
|
break;
|
|
214
214
|
}
|
|
215
|
-
a +=
|
|
215
|
+
a += p, u = r.nextNode();
|
|
216
216
|
}
|
|
217
217
|
return {
|
|
218
218
|
...t,
|
|
@@ -246,46 +246,46 @@ const P = {
|
|
|
246
246
|
};
|
|
247
247
|
}, mt = (t, e, n, o) => {
|
|
248
248
|
const { store: i, selection: r, hover: a } = e;
|
|
249
|
-
let s, u,
|
|
249
|
+
let s, u, f;
|
|
250
250
|
const m = ae(n), c = (R) => {
|
|
251
|
-
const { x:
|
|
251
|
+
const { x: O, y: b } = t.getBoundingClientRect(), w = i.getAt(R.clientX - O, R.clientY - b);
|
|
252
252
|
w && (!u || u(w)) ? a.current !== w.id && (t.classList.add("hovered"), a.set(w.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
|
|
253
253
|
};
|
|
254
254
|
t.addEventListener("pointermove", c);
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
const Ft =
|
|
255
|
+
const p = (R = !1) => {
|
|
256
|
+
f && f.clear();
|
|
257
|
+
const O = se(t), { minX: b, minY: w, maxX: A, maxY: S } = O, L = u ? i.getIntersecting(b, w, A, S).filter(({ annotation: k }) => u(k)) : i.getIntersecting(b, w, A, S), I = r.selected.map(({ id: k }) => k), H = L.map(({ annotation: k, rects: zt }) => {
|
|
258
|
+
const Ft = I.includes(k.id), Wt = k.id === a.current;
|
|
259
259
|
return { annotation: k, rects: zt, state: { selected: Ft, hover: Wt } };
|
|
260
260
|
});
|
|
261
|
-
o.redraw(H,
|
|
262
|
-
},
|
|
263
|
-
|
|
261
|
+
o.redraw(H, O, s, f, R), setTimeout(() => m(L.map(({ annotation: k }) => k)), 1);
|
|
262
|
+
}, g = (R) => {
|
|
263
|
+
f = R, p();
|
|
264
264
|
}, x = (R) => {
|
|
265
|
-
s = R,
|
|
266
|
-
},
|
|
267
|
-
u = R,
|
|
268
|
-
},
|
|
269
|
-
i.observe(
|
|
270
|
-
const
|
|
271
|
-
document.addEventListener("scroll",
|
|
272
|
-
const y =
|
|
273
|
-
i.recalculatePositions(),
|
|
265
|
+
s = R, p();
|
|
266
|
+
}, v = (R) => {
|
|
267
|
+
u = R, p(!1);
|
|
268
|
+
}, h = () => p();
|
|
269
|
+
i.observe(h);
|
|
270
|
+
const d = r.subscribe(() => p()), l = () => p(!0);
|
|
271
|
+
document.addEventListener("scroll", l, { capture: !0, passive: !0 });
|
|
272
|
+
const y = pt(() => {
|
|
273
|
+
i.recalculatePositions(), f && f.reset(), p();
|
|
274
274
|
});
|
|
275
275
|
window.addEventListener("resize", y);
|
|
276
276
|
const T = new ResizeObserver(y);
|
|
277
277
|
T.observe(t);
|
|
278
|
-
const
|
|
279
|
-
R.every((
|
|
278
|
+
const C = { attributes: !0, childList: !0, subtree: !0 }, E = new MutationObserver((R) => {
|
|
279
|
+
R.every((b) => b.target === t || t.contains(b.target)) || p(!0);
|
|
280
280
|
});
|
|
281
|
-
return E.observe(document.body,
|
|
281
|
+
return E.observe(document.body, C), {
|
|
282
282
|
destroy: () => {
|
|
283
|
-
t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(
|
|
283
|
+
t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(h), d(), document.removeEventListener("scroll", l), window.removeEventListener("resize", y), T.disconnect(), E.disconnect();
|
|
284
284
|
},
|
|
285
|
-
redraw:
|
|
285
|
+
redraw: p,
|
|
286
286
|
setStyle: x,
|
|
287
|
-
setFilter:
|
|
288
|
-
setPainter:
|
|
287
|
+
setFilter: v,
|
|
288
|
+
setPainter: g,
|
|
289
289
|
setVisible: o.setVisible
|
|
290
290
|
};
|
|
291
291
|
}, ce = () => {
|
|
@@ -297,36 +297,39 @@ const P = {
|
|
|
297
297
|
t.classList.add("r6o-annotatable");
|
|
298
298
|
const e = ce(), n = e.getContext("2d");
|
|
299
299
|
t.insertBefore(e, t.firstChild);
|
|
300
|
-
const o = (s, u,
|
|
301
|
-
const { width: c, height:
|
|
302
|
-
n.clearRect(-0.5, -0.5, c + 1,
|
|
303
|
-
const { top:
|
|
304
|
-
s.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
300
|
+
const o = (s, u, f, m) => requestAnimationFrame(() => {
|
|
301
|
+
const { width: c, height: p } = e;
|
|
302
|
+
n.clearRect(-0.5, -0.5, c + 1, p + 1), m && m.clear();
|
|
303
|
+
const { top: g, left: x } = u;
|
|
304
|
+
[...s].sort((h, d) => {
|
|
305
|
+
const { annotation: { target: { created: l } } } = h, { annotation: { target: { created: y } } } = d;
|
|
306
|
+
return l.getTime() - y.getTime();
|
|
307
|
+
}).forEach((h) => {
|
|
308
|
+
var C;
|
|
309
|
+
const d = f ? typeof f == "function" ? f(h.annotation, h.state) : f : (C = h.state) != null && C.selected ? ot : P, l = m && m.paint(h, u) || d, y = h.rects.map(({ x: E, y: N, width: R, height: O }) => ({
|
|
310
|
+
x: E + x,
|
|
311
|
+
y: N + g,
|
|
312
|
+
width: R,
|
|
313
|
+
height: O
|
|
311
314
|
}));
|
|
312
315
|
n.fillStyle = l.fill, n.globalAlpha = l.fillOpacity || 1;
|
|
313
|
-
const
|
|
314
|
-
if (
|
|
315
|
-
({ x:
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
316
|
+
const T = 5;
|
|
317
|
+
if (y.forEach(
|
|
318
|
+
({ x: E, y: N, width: R, height: O }) => n.fillRect(
|
|
319
|
+
E,
|
|
320
|
+
N - T / 2,
|
|
321
|
+
R,
|
|
322
|
+
O + T
|
|
320
323
|
)
|
|
321
324
|
), l.underlineColor) {
|
|
322
325
|
n.globalAlpha = 1, n.strokeStyle = l.underlineColor, n.lineWidth = l.underlineThickness ?? 1;
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
n.beginPath(), n.moveTo(
|
|
326
|
+
const E = T / 2 + (l.underlineOffset ?? 0);
|
|
327
|
+
y.forEach(({ x: N, y: R, width: O, height: b }) => {
|
|
328
|
+
n.beginPath(), n.moveTo(N, R + b + E), n.lineTo(N + O, R + b + E), n.stroke();
|
|
326
329
|
});
|
|
327
330
|
}
|
|
328
331
|
});
|
|
329
|
-
}), i =
|
|
332
|
+
}), i = pt(() => {
|
|
330
333
|
le(e);
|
|
331
334
|
});
|
|
332
335
|
return window.addEventListener("resize", i), {
|
|
@@ -341,7 +344,7 @@ const P = {
|
|
|
341
344
|
}, ue = (t, e, n) => mt(t, e, n, de(t));
|
|
342
345
|
var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, Y = function(t) {
|
|
343
346
|
return typeof t == "string" ? t.length > 0 : typeof t == "number";
|
|
344
|
-
},
|
|
347
|
+
}, M = function(t, e, n) {
|
|
345
348
|
return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
|
|
346
349
|
}, U = function(t, e, n) {
|
|
347
350
|
return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
|
|
@@ -350,7 +353,7 @@ var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, Y = function(t) {
|
|
|
350
353
|
}, wt = function(t) {
|
|
351
354
|
return { r: U(t.r, 0, 255), g: U(t.g, 0, 255), b: U(t.b, 0, 255), a: U(t.a) };
|
|
352
355
|
}, st = function(t) {
|
|
353
|
-
return { r:
|
|
356
|
+
return { r: M(t.r), g: M(t.g), b: M(t.b), a: M(t.a, 3) };
|
|
354
357
|
}, fe = /^#([0-9a-f]{3,8})$/i, J = function(t) {
|
|
355
358
|
var e = t.toString(16);
|
|
356
359
|
return e.length < 2 ? "0" + e : e;
|
|
@@ -360,26 +363,26 @@ var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, Y = function(t) {
|
|
|
360
363
|
}, Xt = function(t) {
|
|
361
364
|
var e = t.h, n = t.s, o = t.v, i = t.a;
|
|
362
365
|
e = e / 360 * 6, n /= 100, o /= 100;
|
|
363
|
-
var r = Math.floor(e), a = o * (1 - n), s = o * (1 - (e - r) * n), u = o * (1 - (1 - e + r) * n),
|
|
364
|
-
return { r: 255 * [o, s, a, a, u, o][
|
|
366
|
+
var r = Math.floor(e), a = o * (1 - n), s = o * (1 - (e - r) * n), u = o * (1 - (1 - e + r) * n), f = r % 6;
|
|
367
|
+
return { r: 255 * [o, s, a, a, u, o][f], g: 255 * [u, o, o, s, a, a][f], b: 255 * [a, a, u, o, o, s][f], a: i };
|
|
365
368
|
}, xt = function(t) {
|
|
366
369
|
return { h: Ut(t.h), s: U(t.s, 0, 100), l: U(t.l, 0, 100), a: U(t.a) };
|
|
367
370
|
}, At = function(t) {
|
|
368
|
-
return { h:
|
|
371
|
+
return { h: M(t.h), s: M(t.s), l: M(t.l), a: M(t.a, 3) };
|
|
369
372
|
}, Et = function(t) {
|
|
370
373
|
return Xt((n = (e = t).s, { h: e.h, s: (n *= ((o = e.l) < 50 ? o : 100 - o) / 100) > 0 ? 2 * n / (o + n) * 100 : 0, v: o + n, a: e.a }));
|
|
371
374
|
var e, n, o;
|
|
372
375
|
}, Q = function(t) {
|
|
373
376
|
return { h: (e = Dt(t)).h, s: (i = (200 - (n = e.s)) * (o = e.v) / 100) > 0 && i < 200 ? n * o / 100 / (i <= 100 ? i : 200 - i) * 100 : 0, l: i / 2, a: e.a };
|
|
374
377
|
var e, n, o, i;
|
|
375
|
-
},
|
|
378
|
+
}, ge = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, pe = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, me = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, be = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, St = { string: [[function(t) {
|
|
376
379
|
var e = fe.exec(t);
|
|
377
|
-
return e ? (t = e[1]).length <= 4 ? { r: parseInt(t[0] + t[0], 16), g: parseInt(t[1] + t[1], 16), b: parseInt(t[2] + t[2], 16), a: t.length === 4 ?
|
|
380
|
+
return e ? (t = e[1]).length <= 4 ? { r: parseInt(t[0] + t[0], 16), g: parseInt(t[1] + t[1], 16), b: parseInt(t[2] + t[2], 16), a: t.length === 4 ? M(parseInt(t[3] + t[3], 16) / 255, 2) : 1 } : t.length === 6 || t.length === 8 ? { r: parseInt(t.substr(0, 2), 16), g: parseInt(t.substr(2, 2), 16), b: parseInt(t.substr(4, 2), 16), a: t.length === 8 ? M(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
|
|
378
381
|
}, "hex"], [function(t) {
|
|
379
382
|
var e = me.exec(t) || be.exec(t);
|
|
380
383
|
return e ? e[2] !== e[4] || e[4] !== e[6] ? null : wt({ r: Number(e[1]) / (e[2] ? 100 / 255 : 1), g: Number(e[3]) / (e[4] ? 100 / 255 : 1), b: Number(e[5]) / (e[6] ? 100 / 255 : 1), a: e[7] === void 0 ? 1 : Number(e[7]) / (e[8] ? 100 : 1) }) : null;
|
|
381
384
|
}, "rgb"], [function(t) {
|
|
382
|
-
var e =
|
|
385
|
+
var e = ge.exec(t) || pe.exec(t);
|
|
383
386
|
if (!e)
|
|
384
387
|
return null;
|
|
385
388
|
var n, o, i = xt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (he[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
|
|
@@ -425,13 +428,13 @@ var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, Y = function(t) {
|
|
|
425
428
|
return t.prototype.isValid = function() {
|
|
426
429
|
return this.parsed !== null;
|
|
427
430
|
}, t.prototype.brightness = function() {
|
|
428
|
-
return
|
|
431
|
+
return M(ct(this.rgba), 2);
|
|
429
432
|
}, t.prototype.isDark = function() {
|
|
430
433
|
return ct(this.rgba) < 0.5;
|
|
431
434
|
}, t.prototype.isLight = function() {
|
|
432
435
|
return ct(this.rgba) >= 0.5;
|
|
433
436
|
}, t.prototype.toHex = function() {
|
|
434
|
-
return e = st(this.rgba), n = e.r, o = e.g, i = e.b, a = (r = e.a) < 1 ? J(
|
|
437
|
+
return e = st(this.rgba), n = e.r, o = e.g, i = e.b, a = (r = e.a) < 1 ? J(M(255 * r)) : "", "#" + J(n) + J(o) + J(i) + a;
|
|
435
438
|
var e, n, o, i, r, a;
|
|
436
439
|
}, t.prototype.toRgb = function() {
|
|
437
440
|
return st(this.rgba);
|
|
@@ -444,7 +447,7 @@ var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, Y = function(t) {
|
|
|
444
447
|
return e = At(Q(this.rgba)), n = e.h, o = e.s, i = e.l, (r = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + r + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
|
|
445
448
|
var e, n, o, i, r;
|
|
446
449
|
}, t.prototype.toHsv = function() {
|
|
447
|
-
return e = Dt(this.rgba), { h:
|
|
450
|
+
return e = Dt(this.rgba), { h: M(e.h), s: M(e.s), v: M(e.v), a: M(e.a, 3) };
|
|
448
451
|
var e;
|
|
449
452
|
}, t.prototype.invert = function() {
|
|
450
453
|
return D({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
|
|
@@ -462,11 +465,11 @@ var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, Y = function(t) {
|
|
|
462
465
|
}, t.prototype.rotate = function(e) {
|
|
463
466
|
return e === void 0 && (e = 15), this.hue(this.hue() + e);
|
|
464
467
|
}, t.prototype.alpha = function(e) {
|
|
465
|
-
return typeof e == "number" ? D({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) :
|
|
468
|
+
return typeof e == "number" ? D({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : M(this.rgba.a, 3);
|
|
466
469
|
var n;
|
|
467
470
|
}, t.prototype.hue = function(e) {
|
|
468
471
|
var n = Q(this.rgba);
|
|
469
|
-
return typeof e == "number" ? D({ h: e, s: n.s, l: n.l, a: n.a }) :
|
|
472
|
+
return typeof e == "number" ? D({ h: e, s: n.s, l: n.l, a: n.a }) : M(n.h);
|
|
470
473
|
}, t.prototype.isEqual = function(e) {
|
|
471
474
|
return this.toHex() === D(e).toHex();
|
|
472
475
|
}, t;
|
|
@@ -492,23 +495,23 @@ const ye = (t) => [
|
|
|
492
495
|
},
|
|
493
496
|
redraw: (r, a, s, u) => {
|
|
494
497
|
u && u.clear();
|
|
495
|
-
const
|
|
496
|
-
Array.from(e).filter((c) => !
|
|
498
|
+
const f = new Set(r.map((c) => c.annotation.id));
|
|
499
|
+
Array.from(e).filter((c) => !f.has(c));
|
|
497
500
|
const m = r.map((c) => {
|
|
498
501
|
var x;
|
|
499
|
-
const
|
|
500
|
-
return `::highlight(_${c.annotation.id}) { ${ye(
|
|
502
|
+
const p = s ? typeof s == "function" ? s(c.annotation, c.state) : s : (x = c.state) != null && x.selected ? ot : P, g = u && u.paint(c, a) || p;
|
|
503
|
+
return `::highlight(_${c.annotation.id}) { ${ye(g)} }`;
|
|
501
504
|
});
|
|
502
505
|
t.innerHTML = m.join(`
|
|
503
506
|
`), CSS.highlights.clear(), r.forEach(({ annotation: c }) => {
|
|
504
|
-
const
|
|
505
|
-
CSS.highlights.set(`_${c.id}`,
|
|
506
|
-
}), e =
|
|
507
|
+
const p = c.target.selector.map((x) => x.range), g = new Highlight(...p);
|
|
508
|
+
CSS.highlights.set(`_${c.id}`, g);
|
|
509
|
+
}), e = f;
|
|
507
510
|
}
|
|
508
511
|
};
|
|
509
512
|
}, xe = (t, e, n) => mt(t, e, n, we());
|
|
510
513
|
var Rt = Object.prototype.hasOwnProperty;
|
|
511
|
-
function
|
|
514
|
+
function gt(t, e) {
|
|
512
515
|
var n, o;
|
|
513
516
|
if (t === e)
|
|
514
517
|
return !0;
|
|
@@ -519,14 +522,14 @@ function pt(t, e) {
|
|
|
519
522
|
return t.toString() === e.toString();
|
|
520
523
|
if (n === Array) {
|
|
521
524
|
if ((o = t.length) === e.length)
|
|
522
|
-
for (; o-- &&
|
|
525
|
+
for (; o-- && gt(t[o], e[o]); )
|
|
523
526
|
;
|
|
524
527
|
return o === -1;
|
|
525
528
|
}
|
|
526
529
|
if (!n || typeof t == "object") {
|
|
527
530
|
o = 0;
|
|
528
531
|
for (n in t)
|
|
529
|
-
if (Rt.call(t, n) && ++o && !Rt.call(e, n) || !(n in e) || !
|
|
532
|
+
if (Rt.call(t, n) && ++o && !Rt.call(e, n) || !(n in e) || !gt(t[n], e[n]))
|
|
530
533
|
return !1;
|
|
531
534
|
return Object.keys(e).length === o;
|
|
532
535
|
}
|
|
@@ -545,20 +548,20 @@ const Ae = (t, e) => {
|
|
|
545
548
|
destroy: () => {
|
|
546
549
|
e.remove();
|
|
547
550
|
},
|
|
548
|
-
redraw: (a, s, u,
|
|
549
|
-
const
|
|
550
|
-
if (!
|
|
551
|
+
redraw: (a, s, u, f, m) => {
|
|
552
|
+
const p = !(gt(n, a) && m);
|
|
553
|
+
if (!f && !p)
|
|
551
554
|
return;
|
|
552
|
-
|
|
553
|
-
const
|
|
555
|
+
p && (e.innerHTML = "");
|
|
556
|
+
const g = a.reduce((x, { rects: v }) => [...x, ...v], []);
|
|
554
557
|
a.forEach((x) => {
|
|
555
|
-
x.rects.map((
|
|
556
|
-
const
|
|
557
|
-
if (
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
const y = D((
|
|
561
|
-
|
|
558
|
+
x.rects.map((v) => {
|
|
559
|
+
const h = Ae(v, g), d = qt(x, s, u, f, h);
|
|
560
|
+
if (p) {
|
|
561
|
+
const l = document.createElement("span");
|
|
562
|
+
l.className = "r6o-annotation", l.dataset.annotation = x.annotation.id, l.style.left = `${v.x}px`, l.style.top = `${v.y}px`, l.style.width = `${v.width}px`, l.style.height = `${v.height}px`;
|
|
563
|
+
const y = D((d == null ? void 0 : d.fill) || P.fill).alpha((d == null ? void 0 : d.fillOpacity) === void 0 ? P.fillOpacity : d.fillOpacity).toHex();
|
|
564
|
+
l.style.backgroundColor = y, d.underlineStyle && (l.style.borderStyle = d.underlineStyle), d.underlineColor && (l.style.borderColor = d.underlineColor), d.underlineThickness && (l.style.borderBottomWidth = `${d.underlineThickness}px`), d.underlineOffset && (l.style.paddingBottom = `${d.underlineOffset}px`), e.appendChild(l);
|
|
562
565
|
}
|
|
563
566
|
});
|
|
564
567
|
}), n = a;
|
|
@@ -629,11 +632,11 @@ function bt(t, e = lt) {
|
|
|
629
632
|
function i(s) {
|
|
630
633
|
if (Le(t, s) && (t = s, n)) {
|
|
631
634
|
const u = !z.length;
|
|
632
|
-
for (const
|
|
633
|
-
|
|
635
|
+
for (const f of o)
|
|
636
|
+
f[1](), z.push(f, t);
|
|
634
637
|
if (u) {
|
|
635
|
-
for (let
|
|
636
|
-
z[
|
|
638
|
+
for (let f = 0; f < z.length; f += 2)
|
|
639
|
+
z[f][0](z[f + 1]);
|
|
637
640
|
z.length = 0;
|
|
638
641
|
}
|
|
639
642
|
}
|
|
@@ -642,9 +645,9 @@ function bt(t, e = lt) {
|
|
|
642
645
|
i(s(t));
|
|
643
646
|
}
|
|
644
647
|
function a(s, u = lt) {
|
|
645
|
-
const
|
|
646
|
-
return o.add(
|
|
647
|
-
o.delete(
|
|
648
|
+
const f = [s, u];
|
|
649
|
+
return o.add(f), o.size === 1 && (n = e(i, r) || lt), s(t), () => {
|
|
650
|
+
o.delete(f), o.size === 0 && n && (n(), n = null);
|
|
648
651
|
};
|
|
649
652
|
}
|
|
650
653
|
return { set: i, update: r, subscribe: a };
|
|
@@ -677,25 +680,25 @@ const dt = { selected: [] }, Ie = (t, e = "EDIT") => {
|
|
|
677
680
|
}, s = (c) => {
|
|
678
681
|
if (i.selected.length === 0)
|
|
679
682
|
return !1;
|
|
680
|
-
const
|
|
681
|
-
return i.selected.some((
|
|
682
|
-
}, u = (c,
|
|
683
|
-
const
|
|
684
|
-
if (
|
|
685
|
-
const x = Me(
|
|
686
|
-
o(x === "EDIT" ? { selected: [{ id: c, editable: !0 }], pointerEvent:
|
|
683
|
+
const p = typeof c == "string" ? c : c.id;
|
|
684
|
+
return i.selected.some((g) => g.id === p);
|
|
685
|
+
}, u = (c, p) => {
|
|
686
|
+
const g = t.getAnnotation(c);
|
|
687
|
+
if (g) {
|
|
688
|
+
const x = Me(g, e);
|
|
689
|
+
o(x === "EDIT" ? { selected: [{ id: c, editable: !0 }], pointerEvent: p } : x === "SELECT" ? { selected: [{ id: c }], pointerEvent: p } : { selected: [], pointerEvent: p });
|
|
687
690
|
} else
|
|
688
691
|
console.warn("Invalid selection: " + c);
|
|
689
|
-
},
|
|
690
|
-
const
|
|
691
|
-
o({ selected: x.map(({ id:
|
|
692
|
+
}, f = (c, p = !0) => {
|
|
693
|
+
const g = Array.isArray(c) ? c : [c], x = g.map((v) => t.getAnnotation(v)).filter(Boolean);
|
|
694
|
+
o({ selected: x.map(({ id: v }) => ({ id: v, editable: p })) }), x.length !== g.length && console.warn("Invalid selection", c);
|
|
692
695
|
}, m = (c) => {
|
|
693
696
|
if (i.selected.length === 0)
|
|
694
697
|
return !1;
|
|
695
|
-
const { selected:
|
|
696
|
-
|
|
698
|
+
const { selected: p } = i;
|
|
699
|
+
p.filter(({ id: g }) => c.includes(g)).length > 0 && o({ selected: p.filter(({ id: g }) => !c.includes(g)) });
|
|
697
700
|
};
|
|
698
|
-
return t.observe(({ changes: c }) => m((c.deleted || []).map((
|
|
701
|
+
return t.observe(({ changes: c }) => m((c.deleted || []).map((p) => p.id))), {
|
|
699
702
|
clear: r,
|
|
700
703
|
clickSelect: u,
|
|
701
704
|
get selected() {
|
|
@@ -706,7 +709,7 @@ const dt = { selected: [] }, Ie = (t, e = "EDIT") => {
|
|
|
706
709
|
},
|
|
707
710
|
isEmpty: a,
|
|
708
711
|
isSelected: s,
|
|
709
|
-
setSelected:
|
|
712
|
+
setSelected: f,
|
|
710
713
|
subscribe: n
|
|
711
714
|
};
|
|
712
715
|
}, Me = (t, e) => typeof e == "function" ? e(t) || "EDIT" : e || "EDIT";
|
|
@@ -768,8 +771,8 @@ const Pe = (t, e) => {
|
|
|
768
771
|
if (t.options.ignore) {
|
|
769
772
|
const { ignore: a } = t.options, s = (u) => u && u.length > 0;
|
|
770
773
|
if (!(s(i.created) || s(i.deleted))) {
|
|
771
|
-
const u = (n = i.updated) == null ? void 0 : n.some((m) => s(m.bodiesCreated) || s(m.bodiesDeleted) || s(m.bodiesUpdated)),
|
|
772
|
-
if (a === "BODY_ONLY" && u && !
|
|
774
|
+
const u = (n = i.updated) == null ? void 0 : n.some((m) => s(m.bodiesCreated) || s(m.bodiesDeleted) || s(m.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((m) => m.targetUpdated);
|
|
775
|
+
if (a === "BODY_ONLY" && u && !f || a === "TARGET_ONLY" && f && !u)
|
|
773
776
|
return !1;
|
|
774
777
|
}
|
|
775
778
|
}
|
|
@@ -784,30 +787,30 @@ const Pe = (t, e) => {
|
|
|
784
787
|
return !0;
|
|
785
788
|
}, ze = (t, e) => {
|
|
786
789
|
const n = new Set((t.created || []).map((c) => c.id)), o = new Set((t.updated || []).map(({ newValue: c }) => c.id)), i = new Set((e.created || []).map((c) => c.id)), r = new Set((e.deleted || []).map((c) => c.id)), a = new Set((e.updated || []).map(({ oldValue: c }) => c.id)), s = new Set((e.updated || []).filter(({ oldValue: c }) => n.has(c.id) || o.has(c.id)).map(({ oldValue: c }) => c.id)), u = [
|
|
787
|
-
...(t.created || []).filter((c) => !r.has(c.id)).map((c) => a.has(c.id) ? e.updated.find(({ oldValue:
|
|
790
|
+
...(t.created || []).filter((c) => !r.has(c.id)).map((c) => a.has(c.id) ? e.updated.find(({ oldValue: p }) => p.id === c.id).newValue : c),
|
|
788
791
|
...e.created || []
|
|
789
|
-
],
|
|
792
|
+
], f = [
|
|
790
793
|
...(t.deleted || []).filter((c) => !i.has(c.id)),
|
|
791
794
|
...(e.deleted || []).filter((c) => !n.has(c.id))
|
|
792
795
|
], m = [
|
|
793
796
|
...(t.updated || []).filter(({ newValue: c }) => !r.has(c.id)).map((c) => {
|
|
794
|
-
const { oldValue:
|
|
795
|
-
if (a.has(
|
|
796
|
-
const x = e.updated.find((
|
|
797
|
-
return Yt(
|
|
797
|
+
const { oldValue: p, newValue: g } = c;
|
|
798
|
+
if (a.has(g.id)) {
|
|
799
|
+
const x = e.updated.find((v) => v.oldValue.id === g.id).newValue;
|
|
800
|
+
return Yt(p, x);
|
|
798
801
|
} else
|
|
799
802
|
return c;
|
|
800
803
|
}),
|
|
801
804
|
...(e.updated || []).filter(({ oldValue: c }) => !s.has(c.id))
|
|
802
805
|
];
|
|
803
|
-
return { created: u, deleted:
|
|
806
|
+
return { created: u, deleted: f, updated: m };
|
|
804
807
|
}, Fe = (t) => t.id !== void 0, We = () => {
|
|
805
|
-
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (
|
|
806
|
-
const w = n.findIndex((A) => A.onChange ==
|
|
808
|
+
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b, w = {}) => n.push({ onChange: b, options: w }), i = (b) => {
|
|
809
|
+
const w = n.findIndex((A) => A.onChange == b);
|
|
807
810
|
w > -1 && n.splice(w, 1);
|
|
808
|
-
}, r = (
|
|
811
|
+
}, r = (b, w) => {
|
|
809
812
|
const A = {
|
|
810
|
-
origin:
|
|
813
|
+
origin: b,
|
|
811
814
|
changes: {
|
|
812
815
|
created: w.created || [],
|
|
813
816
|
updated: w.updated || [],
|
|
@@ -815,144 +818,144 @@ const Pe = (t, e) => {
|
|
|
815
818
|
},
|
|
816
819
|
state: [...t.values()]
|
|
817
820
|
};
|
|
818
|
-
n.forEach((
|
|
819
|
-
Pe(
|
|
821
|
+
n.forEach((S) => {
|
|
822
|
+
Pe(S, A) && S.onChange(A);
|
|
820
823
|
});
|
|
821
|
-
}, a = (
|
|
822
|
-
if (t.get(
|
|
823
|
-
throw Error(`Cannot add annotation ${
|
|
824
|
-
t.set(
|
|
825
|
-
}, s = (
|
|
826
|
-
const A = typeof
|
|
824
|
+
}, a = (b, w = B.LOCAL) => {
|
|
825
|
+
if (t.get(b.id))
|
|
826
|
+
throw Error(`Cannot add annotation ${b.id} - exists already`);
|
|
827
|
+
t.set(b.id, b), b.bodies.forEach((A) => e.set(A.id, b.id)), r(w, { created: [b] });
|
|
828
|
+
}, s = (b, w) => {
|
|
829
|
+
const A = typeof b == "string" ? w : b, S = typeof b == "string" ? b : b.id, L = t.get(S);
|
|
827
830
|
if (L) {
|
|
828
|
-
const
|
|
829
|
-
return
|
|
831
|
+
const I = Yt(L, A);
|
|
832
|
+
return S === A.id ? t.set(S, A) : (t.delete(S), t.set(A.id, A)), L.bodies.forEach((H) => e.delete(H.id)), A.bodies.forEach((H) => e.set(H.id, A.id)), I;
|
|
830
833
|
} else
|
|
831
|
-
console.warn(`Cannot update annotation ${
|
|
832
|
-
}, u = (
|
|
833
|
-
const
|
|
834
|
-
L && r(
|
|
835
|
-
},
|
|
836
|
-
const A =
|
|
837
|
-
const
|
|
838
|
-
return
|
|
834
|
+
console.warn(`Cannot update annotation ${S} - does not exist`);
|
|
835
|
+
}, u = (b, w = B.LOCAL, A = B.LOCAL) => {
|
|
836
|
+
const S = Fe(w) ? A : w, L = s(b, w);
|
|
837
|
+
L && r(S, { updated: [L] });
|
|
838
|
+
}, f = (b, w = B.LOCAL) => {
|
|
839
|
+
const A = b.reduce((S, L) => {
|
|
840
|
+
const I = s(L);
|
|
841
|
+
return I ? [...S, I] : S;
|
|
839
842
|
}, []);
|
|
840
843
|
A.length > 0 && r(w, { updated: A });
|
|
841
|
-
}, m = (
|
|
842
|
-
const A = t.get(
|
|
844
|
+
}, m = (b, w = B.LOCAL) => {
|
|
845
|
+
const A = t.get(b.annotation);
|
|
843
846
|
if (A) {
|
|
844
|
-
const
|
|
847
|
+
const S = {
|
|
845
848
|
...A,
|
|
846
|
-
bodies: [...A.bodies,
|
|
849
|
+
bodies: [...A.bodies, b]
|
|
847
850
|
};
|
|
848
|
-
t.set(A.id,
|
|
851
|
+
t.set(A.id, S), e.set(b.id, S.id), r(w, { updated: [{
|
|
849
852
|
oldValue: A,
|
|
850
|
-
newValue:
|
|
851
|
-
bodiesCreated: [
|
|
853
|
+
newValue: S,
|
|
854
|
+
bodiesCreated: [b]
|
|
852
855
|
}] });
|
|
853
856
|
} else
|
|
854
|
-
console.warn(`Attempt to add body to missing annotation: ${
|
|
855
|
-
}, c = () => [...t.values()],
|
|
857
|
+
console.warn(`Attempt to add body to missing annotation: ${b.annotation}`);
|
|
858
|
+
}, c = () => [...t.values()], p = (b = B.LOCAL) => {
|
|
856
859
|
const w = [...t.values()];
|
|
857
|
-
t.clear(), e.clear(), r(
|
|
858
|
-
},
|
|
860
|
+
t.clear(), e.clear(), r(b, { deleted: w });
|
|
861
|
+
}, g = (b, w = !0, A = B.LOCAL) => {
|
|
859
862
|
if (w) {
|
|
860
|
-
const
|
|
861
|
-
t.clear(), e.clear(),
|
|
862
|
-
t.set(L.id, L), L.bodies.forEach((
|
|
863
|
-
}), r(A, { created:
|
|
863
|
+
const S = [...t.values()];
|
|
864
|
+
t.clear(), e.clear(), b.forEach((L) => {
|
|
865
|
+
t.set(L.id, L), L.bodies.forEach((I) => e.set(I.id, L.id));
|
|
866
|
+
}), r(A, { created: b, deleted: S });
|
|
864
867
|
} else {
|
|
865
|
-
const
|
|
866
|
-
const H = t.get(
|
|
868
|
+
const S = b.reduce((L, I) => {
|
|
869
|
+
const H = t.get(I.id);
|
|
867
870
|
return H ? [...L, H] : L;
|
|
868
871
|
}, []);
|
|
869
|
-
if (
|
|
870
|
-
throw Error(`Bulk insert would overwrite the following annotations: ${
|
|
871
|
-
|
|
872
|
-
t.set(L.id, L), L.bodies.forEach((
|
|
873
|
-
}), r(A, { created:
|
|
872
|
+
if (S.length > 0)
|
|
873
|
+
throw Error(`Bulk insert would overwrite the following annotations: ${S.map((L) => L.id).join(", ")}`);
|
|
874
|
+
b.forEach((L) => {
|
|
875
|
+
t.set(L.id, L), L.bodies.forEach((I) => e.set(I.id, L.id));
|
|
876
|
+
}), r(A, { created: b });
|
|
874
877
|
}
|
|
875
|
-
}, x = (
|
|
876
|
-
const w = typeof
|
|
878
|
+
}, x = (b) => {
|
|
879
|
+
const w = typeof b == "string" ? b : b.id, A = t.get(w);
|
|
877
880
|
if (A)
|
|
878
|
-
return t.delete(w), A.bodies.forEach((
|
|
881
|
+
return t.delete(w), A.bodies.forEach((S) => e.delete(S.id)), A;
|
|
879
882
|
console.warn(`Attempt to delete missing annotation: ${w}`);
|
|
880
|
-
},
|
|
881
|
-
const A = x(
|
|
883
|
+
}, v = (b, w = B.LOCAL) => {
|
|
884
|
+
const A = x(b);
|
|
882
885
|
A && r(w, { deleted: [A] });
|
|
883
|
-
},
|
|
884
|
-
const A =
|
|
885
|
-
const
|
|
886
|
-
return
|
|
886
|
+
}, h = (b, w = B.LOCAL) => {
|
|
887
|
+
const A = b.reduce((S, L) => {
|
|
888
|
+
const I = x(L);
|
|
889
|
+
return I ? [...S, I] : S;
|
|
887
890
|
}, []);
|
|
888
891
|
A.length > 0 && r(w, { deleted: A });
|
|
889
|
-
},
|
|
890
|
-
const w = t.get(
|
|
892
|
+
}, d = (b) => {
|
|
893
|
+
const w = t.get(b.annotation);
|
|
891
894
|
if (w) {
|
|
892
|
-
const A = w.bodies.find((
|
|
895
|
+
const A = w.bodies.find((S) => S.id === b.id);
|
|
893
896
|
if (A) {
|
|
894
897
|
e.delete(A.id);
|
|
895
|
-
const
|
|
898
|
+
const S = {
|
|
896
899
|
...w,
|
|
897
|
-
bodies: w.bodies.filter((L) => L.id !==
|
|
900
|
+
bodies: w.bodies.filter((L) => L.id !== b.id)
|
|
898
901
|
};
|
|
899
|
-
return t.set(w.id,
|
|
902
|
+
return t.set(w.id, S), {
|
|
900
903
|
oldValue: w,
|
|
901
|
-
newValue:
|
|
904
|
+
newValue: S,
|
|
902
905
|
bodiesDeleted: [A]
|
|
903
906
|
};
|
|
904
907
|
} else
|
|
905
|
-
console.warn(`Attempt to delete missing body ${
|
|
908
|
+
console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`);
|
|
906
909
|
} else
|
|
907
|
-
console.warn(`Attempt to delete body from missing annotation ${
|
|
908
|
-
},
|
|
909
|
-
const A =
|
|
910
|
+
console.warn(`Attempt to delete body from missing annotation ${b.annotation}`);
|
|
911
|
+
}, l = (b, w = B.LOCAL) => {
|
|
912
|
+
const A = d(b);
|
|
910
913
|
A && r(w, { updated: [A] });
|
|
911
|
-
}, y = (
|
|
912
|
-
const A =
|
|
914
|
+
}, y = (b, w = B.LOCAL) => {
|
|
915
|
+
const A = b.map((S) => d(S)).filter(Boolean);
|
|
913
916
|
A.length > 0 && r(w, { updated: A });
|
|
914
|
-
}, T = (
|
|
915
|
-
const w = t.get(
|
|
917
|
+
}, T = (b) => {
|
|
918
|
+
const w = t.get(b);
|
|
916
919
|
return w ? { ...w } : void 0;
|
|
917
|
-
},
|
|
918
|
-
const w = e.get(
|
|
920
|
+
}, C = (b) => {
|
|
921
|
+
const w = e.get(b);
|
|
919
922
|
if (w) {
|
|
920
|
-
const A = T(w).bodies.find((
|
|
923
|
+
const A = T(w).bodies.find((S) => S.id === b);
|
|
921
924
|
if (A)
|
|
922
925
|
return A;
|
|
923
|
-
console.error(`Store integrity error: body ${
|
|
926
|
+
console.error(`Store integrity error: body ${b} in index, but not in annotation`);
|
|
924
927
|
} else
|
|
925
|
-
console.warn(`Attempt to retrieve missing body: ${
|
|
926
|
-
}, E = (
|
|
927
|
-
if (
|
|
928
|
+
console.warn(`Attempt to retrieve missing body: ${b}`);
|
|
929
|
+
}, E = (b, w) => {
|
|
930
|
+
if (b.annotation !== w.annotation)
|
|
928
931
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
929
|
-
const A = t.get(
|
|
932
|
+
const A = t.get(b.annotation);
|
|
930
933
|
if (A) {
|
|
931
|
-
const
|
|
934
|
+
const S = A.bodies.find((I) => I.id === b.id), L = {
|
|
932
935
|
...A,
|
|
933
|
-
bodies: A.bodies.map((
|
|
936
|
+
bodies: A.bodies.map((I) => I.id === S.id ? w : I)
|
|
934
937
|
};
|
|
935
|
-
return t.set(A.id, L),
|
|
938
|
+
return t.set(A.id, L), S.id !== w.id && (e.delete(S.id), e.set(w.id, L.id)), {
|
|
936
939
|
oldValue: A,
|
|
937
940
|
newValue: L,
|
|
938
|
-
bodiesUpdated: [{ oldBody:
|
|
941
|
+
bodiesUpdated: [{ oldBody: S, newBody: w }]
|
|
939
942
|
};
|
|
940
943
|
} else
|
|
941
|
-
console.warn(`Attempt to add body to missing annotation ${
|
|
942
|
-
}, N = (
|
|
943
|
-
const
|
|
944
|
-
|
|
945
|
-
}, R = (
|
|
946
|
-
const A =
|
|
944
|
+
console.warn(`Attempt to add body to missing annotation ${b.annotation}`);
|
|
945
|
+
}, N = (b, w, A = B.LOCAL) => {
|
|
946
|
+
const S = E(b, w);
|
|
947
|
+
S && r(A, { updated: [S] });
|
|
948
|
+
}, R = (b, w = B.LOCAL) => {
|
|
949
|
+
const A = b.map((S) => E({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
|
|
947
950
|
r(w, { updated: A });
|
|
948
|
-
},
|
|
949
|
-
const w = t.get(
|
|
951
|
+
}, O = (b) => {
|
|
952
|
+
const w = t.get(b.annotation);
|
|
950
953
|
if (w) {
|
|
951
954
|
const A = {
|
|
952
955
|
...w,
|
|
953
956
|
target: {
|
|
954
957
|
...w.target,
|
|
955
|
-
...
|
|
958
|
+
...b
|
|
956
959
|
}
|
|
957
960
|
};
|
|
958
961
|
return t.set(w.id, A), {
|
|
@@ -960,36 +963,36 @@ const Pe = (t, e) => {
|
|
|
960
963
|
newValue: A,
|
|
961
964
|
targetUpdated: {
|
|
962
965
|
oldTarget: w.target,
|
|
963
|
-
newTarget:
|
|
966
|
+
newTarget: b
|
|
964
967
|
}
|
|
965
968
|
};
|
|
966
969
|
} else
|
|
967
|
-
console.warn(`Attempt to update target on missing annotation: ${
|
|
970
|
+
console.warn(`Attempt to update target on missing annotation: ${b.annotation}`);
|
|
968
971
|
};
|
|
969
972
|
return {
|
|
970
973
|
addAnnotation: a,
|
|
971
974
|
addBody: m,
|
|
972
975
|
all: c,
|
|
973
|
-
bulkAddAnnotation:
|
|
974
|
-
bulkDeleteAnnotation:
|
|
976
|
+
bulkAddAnnotation: g,
|
|
977
|
+
bulkDeleteAnnotation: h,
|
|
975
978
|
bulkDeleteBodies: y,
|
|
976
|
-
bulkUpdateAnnotation:
|
|
979
|
+
bulkUpdateAnnotation: f,
|
|
977
980
|
bulkUpdateBodies: R,
|
|
978
|
-
bulkUpdateTargets: (
|
|
979
|
-
const A =
|
|
981
|
+
bulkUpdateTargets: (b, w = B.LOCAL) => {
|
|
982
|
+
const A = b.map((S) => O(S)).filter(Boolean);
|
|
980
983
|
A.length > 0 && r(w, { updated: A });
|
|
981
984
|
},
|
|
982
|
-
clear:
|
|
983
|
-
deleteAnnotation:
|
|
984
|
-
deleteBody:
|
|
985
|
+
clear: p,
|
|
986
|
+
deleteAnnotation: v,
|
|
987
|
+
deleteBody: l,
|
|
985
988
|
getAnnotation: T,
|
|
986
|
-
getBody:
|
|
989
|
+
getBody: C,
|
|
987
990
|
observe: o,
|
|
988
991
|
unobserve: i,
|
|
989
992
|
updateAnnotation: u,
|
|
990
993
|
updateBody: N,
|
|
991
|
-
updateTarget: (
|
|
992
|
-
const A =
|
|
994
|
+
updateTarget: (b, w = B.LOCAL) => {
|
|
995
|
+
const A = O(b);
|
|
993
996
|
A && r(w, { updated: [A] });
|
|
994
997
|
}
|
|
995
998
|
};
|
|
@@ -1011,38 +1014,38 @@ let qe = () => ({
|
|
|
1011
1014
|
const je = 250, Ge = (t) => {
|
|
1012
1015
|
const e = qe(), n = [];
|
|
1013
1016
|
let o = -1, i = !1, r = 0;
|
|
1014
|
-
const a = (
|
|
1017
|
+
const a = (g) => {
|
|
1015
1018
|
if (!i) {
|
|
1016
|
-
const { changes: x } =
|
|
1017
|
-
if (
|
|
1019
|
+
const { changes: x } = g, v = performance.now();
|
|
1020
|
+
if (v - r > je)
|
|
1018
1021
|
n.splice(o + 1), n.push(x), o = n.length - 1;
|
|
1019
1022
|
else {
|
|
1020
|
-
const
|
|
1021
|
-
n[
|
|
1023
|
+
const h = n.length - 1;
|
|
1024
|
+
n[h] = ze(n[h], x);
|
|
1022
1025
|
}
|
|
1023
|
-
r =
|
|
1026
|
+
r = v;
|
|
1024
1027
|
}
|
|
1025
1028
|
i = !1;
|
|
1026
1029
|
};
|
|
1027
1030
|
t.observe(a, { origin: B.LOCAL });
|
|
1028
|
-
const s = (
|
|
1031
|
+
const s = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g), u = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), f = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ oldValue: x }) => x)), m = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ newValue: x }) => x)), c = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), p = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g);
|
|
1029
1032
|
return {
|
|
1030
1033
|
canRedo: () => n.length - 1 > o,
|
|
1031
1034
|
canUndo: () => o > -1,
|
|
1032
1035
|
destroy: () => t.unobserve(a),
|
|
1033
|
-
on: (
|
|
1036
|
+
on: (g, x) => e.on(g, x),
|
|
1034
1037
|
redo: () => {
|
|
1035
1038
|
if (n.length - 1 > o) {
|
|
1036
1039
|
i = !0;
|
|
1037
|
-
const { created:
|
|
1038
|
-
u(
|
|
1040
|
+
const { created: g, updated: x, deleted: v } = n[o + 1];
|
|
1041
|
+
u(g), m(x), p(v), e.emit("redo", n[o + 1]), o += 1;
|
|
1039
1042
|
}
|
|
1040
1043
|
},
|
|
1041
1044
|
undo: () => {
|
|
1042
1045
|
if (o > -1) {
|
|
1043
1046
|
i = !0;
|
|
1044
|
-
const { created:
|
|
1045
|
-
s(
|
|
1047
|
+
const { created: g, updated: x, deleted: v } = n[o];
|
|
1048
|
+
s(g), f(x), c(v), e.emit("undo", n[o]), o -= 1;
|
|
1046
1049
|
}
|
|
1047
1050
|
}
|
|
1048
1051
|
};
|
|
@@ -1054,69 +1057,69 @@ const je = 250, Ge = (t) => {
|
|
|
1054
1057
|
};
|
|
1055
1058
|
}, Qe = (t, e, n, o) => {
|
|
1056
1059
|
const { store: i, selection: r, hover: a, viewport: s } = t, u = /* @__PURE__ */ new Map();
|
|
1057
|
-
let
|
|
1058
|
-
const c = (
|
|
1059
|
-
u.has(
|
|
1060
|
-
},
|
|
1061
|
-
const
|
|
1062
|
-
|
|
1063
|
-
},
|
|
1064
|
-
u.has(
|
|
1065
|
-
u.get(
|
|
1060
|
+
let f = [], m;
|
|
1061
|
+
const c = (v, h) => {
|
|
1062
|
+
u.has(v) ? u.get(v).push(h) : u.set(v, [h]);
|
|
1063
|
+
}, p = (v, h) => {
|
|
1064
|
+
const d = u.get(v);
|
|
1065
|
+
d && d.indexOf(h) > 0 && d.splice(d.indexOf(h), 1);
|
|
1066
|
+
}, g = (v, h, d) => {
|
|
1067
|
+
u.has(v) && setTimeout(() => {
|
|
1068
|
+
u.get(v).forEach((l) => {
|
|
1066
1069
|
if (n) {
|
|
1067
|
-
const y = Array.isArray(
|
|
1068
|
-
|
|
1070
|
+
const y = Array.isArray(h) ? h.map((C) => n.serialize(C)) : n.serialize(h), T = d ? d instanceof PointerEvent ? d : n.serialize(d) : void 0;
|
|
1071
|
+
l(y, T);
|
|
1069
1072
|
} else
|
|
1070
|
-
|
|
1073
|
+
l(h, d);
|
|
1071
1074
|
});
|
|
1072
1075
|
}, 1);
|
|
1073
1076
|
};
|
|
1074
|
-
r.subscribe(({ selected:
|
|
1075
|
-
if (!(
|
|
1076
|
-
if (
|
|
1077
|
-
|
|
1078
|
-
else if (
|
|
1079
|
-
|
|
1080
|
-
const
|
|
1081
|
-
|
|
1082
|
-
}),
|
|
1077
|
+
r.subscribe(({ selected: v }) => {
|
|
1078
|
+
if (!(f.length === 0 && v.length === 0)) {
|
|
1079
|
+
if (f.length === 0 && v.length > 0)
|
|
1080
|
+
f = v.map(({ id: h }) => i.getAnnotation(h));
|
|
1081
|
+
else if (f.length > 0 && v.length === 0)
|
|
1082
|
+
f.forEach((h) => {
|
|
1083
|
+
const d = i.getAnnotation(h.id);
|
|
1084
|
+
d && !q(d, h) && g("updateAnnotation", d, h);
|
|
1085
|
+
}), f = [];
|
|
1083
1086
|
else {
|
|
1084
|
-
const
|
|
1085
|
-
|
|
1086
|
-
const y = i.getAnnotation(
|
|
1087
|
-
y && !q(y,
|
|
1088
|
-
}),
|
|
1087
|
+
const h = new Set(f.map((l) => l.id)), d = new Set(v.map(({ id: l }) => l));
|
|
1088
|
+
f.filter((l) => !d.has(l.id)).forEach((l) => {
|
|
1089
|
+
const y = i.getAnnotation(l.id);
|
|
1090
|
+
y && !q(y, l) && g("updateAnnotation", y, l);
|
|
1091
|
+
}), f = [
|
|
1089
1092
|
// Remove annotations that were deselected
|
|
1090
|
-
...
|
|
1093
|
+
...f.filter((l) => d.has(l.id)),
|
|
1091
1094
|
// Add editable annotations that were selected
|
|
1092
|
-
...
|
|
1095
|
+
...v.filter(({ id: l }) => !h.has(l)).map(({ id: l }) => i.getAnnotation(l))
|
|
1093
1096
|
];
|
|
1094
1097
|
}
|
|
1095
|
-
|
|
1098
|
+
g("selectionChanged", f);
|
|
1096
1099
|
}
|
|
1097
|
-
}), a.subscribe((
|
|
1098
|
-
!m &&
|
|
1099
|
-
}), s == null || s.subscribe((
|
|
1100
|
-
const { created:
|
|
1101
|
-
(
|
|
1102
|
-
...
|
|
1103
|
-
...
|
|
1104
|
-
...
|
|
1105
|
-
].length > 0).forEach(({ oldValue:
|
|
1106
|
-
const T =
|
|
1107
|
-
|
|
1100
|
+
}), a.subscribe((v) => {
|
|
1101
|
+
!m && v ? g("mouseEnterAnnotation", i.getAnnotation(v)) : m && !v ? g("mouseLeaveAnnotation", i.getAnnotation(m)) : m && v && (g("mouseLeaveAnnotation", i.getAnnotation(m)), g("mouseEnterAnnotation", i.getAnnotation(v))), m = v;
|
|
1102
|
+
}), s == null || s.subscribe((v) => g("viewportIntersect", v.map((h) => i.getAnnotation(h)))), i.observe((v) => {
|
|
1103
|
+
const { created: h, deleted: d } = v.changes;
|
|
1104
|
+
(h || []).forEach((l) => g("createAnnotation", l)), (d || []).forEach((l) => g("deleteAnnotation", l)), (v.changes.updated || []).filter((l) => [
|
|
1105
|
+
...l.bodiesCreated || [],
|
|
1106
|
+
...l.bodiesDeleted || [],
|
|
1107
|
+
...l.bodiesUpdated || []
|
|
1108
|
+
].length > 0).forEach(({ oldValue: l, newValue: y }) => {
|
|
1109
|
+
const T = f.find((C) => C.id === l.id) || l;
|
|
1110
|
+
f = f.map((C) => C.id === l.id ? y : C), g("updateAnnotation", y, T);
|
|
1108
1111
|
});
|
|
1109
|
-
}, { origin: B.LOCAL }), i.observe((
|
|
1110
|
-
if (
|
|
1111
|
-
const
|
|
1112
|
-
|
|
1112
|
+
}, { origin: B.LOCAL }), i.observe((v) => {
|
|
1113
|
+
if (f) {
|
|
1114
|
+
const h = new Set(f.map((l) => l.id)), d = (v.changes.updated || []).filter(({ newValue: l }) => h.has(l.id)).map(({ newValue: l }) => l);
|
|
1115
|
+
d.length > 0 && (f = f.map((l) => d.find((T) => T.id === l.id) || l));
|
|
1113
1116
|
}
|
|
1114
1117
|
}, { origin: B.REMOTE });
|
|
1115
|
-
const x = (
|
|
1116
|
-
const { updated:
|
|
1117
|
-
|
|
1118
|
+
const x = (v) => (h) => {
|
|
1119
|
+
const { updated: d } = h;
|
|
1120
|
+
v ? (d || []).forEach((l) => g("updateAnnotation", l.oldValue, l.newValue)) : (d || []).forEach((l) => g("updateAnnotation", l.newValue, l.oldValue));
|
|
1118
1121
|
};
|
|
1119
|
-
return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: c, off:
|
|
1122
|
+
return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: c, off: p, emit: g };
|
|
1120
1123
|
}, Je = (t) => (e) => e.reduce((n, o) => {
|
|
1121
1124
|
const { parsed: i, error: r } = t.parse(o);
|
|
1122
1125
|
return r ? {
|
|
@@ -1129,44 +1132,44 @@ const je = 250, Ge = (t) => {
|
|
|
1129
1132
|
...n
|
|
1130
1133
|
};
|
|
1131
1134
|
}, { parsed: [], failed: [] }), Ze = (t, e, n) => {
|
|
1132
|
-
const { store: o, selection: i } = t, r = (
|
|
1135
|
+
const { store: o, selection: i } = t, r = (h) => {
|
|
1133
1136
|
if (n) {
|
|
1134
|
-
const { parsed:
|
|
1135
|
-
|
|
1137
|
+
const { parsed: d, error: l } = n.parse(h);
|
|
1138
|
+
d ? o.addAnnotation(d, B.REMOTE) : console.error(l);
|
|
1136
1139
|
} else
|
|
1137
|
-
o.addAnnotation(
|
|
1138
|
-
}, a = () => i.clear(), s = () => o.clear(), u = (
|
|
1139
|
-
const
|
|
1140
|
-
return n &&
|
|
1141
|
-
},
|
|
1142
|
-
var
|
|
1143
|
-
const
|
|
1144
|
-
return n ?
|
|
1145
|
-
}, c = (
|
|
1146
|
-
if (typeof
|
|
1147
|
-
const
|
|
1148
|
-
if (o.deleteAnnotation(
|
|
1149
|
-
return n ? n.serialize(
|
|
1140
|
+
o.addAnnotation(h, B.REMOTE);
|
|
1141
|
+
}, a = () => i.clear(), s = () => o.clear(), u = (h) => {
|
|
1142
|
+
const d = o.getAnnotation(h);
|
|
1143
|
+
return n && d ? n.serialize(d) : d;
|
|
1144
|
+
}, f = () => n ? o.all().map(n.serialize) : o.all(), m = () => {
|
|
1145
|
+
var h;
|
|
1146
|
+
const d = (((h = i.selected) == null ? void 0 : h.map((l) => l.id)) || []).map((l) => o.getAnnotation(l)).filter(Boolean);
|
|
1147
|
+
return n ? d.map(n.serialize) : d;
|
|
1148
|
+
}, c = (h, d = !0) => fetch(h).then((l) => l.json()).then((l) => (g(l, d), l)), p = (h) => {
|
|
1149
|
+
if (typeof h == "string") {
|
|
1150
|
+
const d = o.getAnnotation(h);
|
|
1151
|
+
if (o.deleteAnnotation(h), d)
|
|
1152
|
+
return n ? n.serialize(d) : d;
|
|
1150
1153
|
} else {
|
|
1151
|
-
const
|
|
1152
|
-
if (
|
|
1153
|
-
return o.deleteAnnotation(
|
|
1154
|
+
const d = n ? n.parse(h).parsed : h;
|
|
1155
|
+
if (d)
|
|
1156
|
+
return o.deleteAnnotation(d), h;
|
|
1154
1157
|
}
|
|
1155
|
-
},
|
|
1158
|
+
}, g = (h, d = !0) => {
|
|
1156
1159
|
if (n) {
|
|
1157
|
-
const { parsed:
|
|
1158
|
-
y.length > 0 && console.warn(`Discarded ${y.length} invalid annotations`, y), o.bulkAddAnnotation(
|
|
1160
|
+
const { parsed: l, failed: y } = Je(n)(h);
|
|
1161
|
+
y.length > 0 && console.warn(`Discarded ${y.length} invalid annotations`, y), o.bulkAddAnnotation(l, d, B.REMOTE);
|
|
1159
1162
|
} else
|
|
1160
|
-
o.bulkAddAnnotation(
|
|
1161
|
-
}, x = (
|
|
1162
|
-
|
|
1163
|
-
},
|
|
1163
|
+
o.bulkAddAnnotation(h, d, B.REMOTE);
|
|
1164
|
+
}, x = (h) => {
|
|
1165
|
+
h ? i.setSelected(h) : i.clear();
|
|
1166
|
+
}, v = (h) => {
|
|
1164
1167
|
if (n) {
|
|
1165
|
-
const
|
|
1166
|
-
return o.updateAnnotation(
|
|
1168
|
+
const d = n.parse(h).parsed, l = n.serialize(o.getAnnotation(d.id));
|
|
1169
|
+
return o.updateAnnotation(d), l;
|
|
1167
1170
|
} else {
|
|
1168
|
-
const
|
|
1169
|
-
return o.updateAnnotation(
|
|
1171
|
+
const d = o.getAnnotation(h.id);
|
|
1172
|
+
return o.updateAnnotation(h), d;
|
|
1170
1173
|
}
|
|
1171
1174
|
};
|
|
1172
1175
|
return {
|
|
@@ -1176,15 +1179,15 @@ const je = 250, Ge = (t) => {
|
|
|
1176
1179
|
canUndo: e.canUndo,
|
|
1177
1180
|
clearAnnotations: s,
|
|
1178
1181
|
getAnnotationById: u,
|
|
1179
|
-
getAnnotations:
|
|
1182
|
+
getAnnotations: f,
|
|
1180
1183
|
getSelected: m,
|
|
1181
1184
|
loadAnnotations: c,
|
|
1182
1185
|
redo: e.redo,
|
|
1183
|
-
removeAnnotation:
|
|
1184
|
-
setAnnotations:
|
|
1186
|
+
removeAnnotation: p,
|
|
1187
|
+
setAnnotations: g,
|
|
1185
1188
|
setSelected: x,
|
|
1186
1189
|
undo: e.undo,
|
|
1187
|
-
updateAnnotation:
|
|
1190
|
+
updateAnnotation: v
|
|
1188
1191
|
};
|
|
1189
1192
|
}, tn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
1190
1193
|
let en = (t) => crypto.getRandomValues(new Uint8Array(t)), nn = (t, e, n) => {
|
|
@@ -1213,14 +1216,14 @@ const sn = () => ({ isGuest: !0, id: on("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
1213
1216
|
}
|
|
1214
1217
|
return `${n}`;
|
|
1215
1218
|
}, Ht = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, cn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
|
|
1216
|
-
const { id: o, type: i, purpose: r, value: a, created: s, modified: u, creator:
|
|
1219
|
+
const { id: o, type: i, purpose: r, value: a, created: s, modified: u, creator: f, ...m } = n;
|
|
1217
1220
|
return {
|
|
1218
1221
|
id: o || `temp-${an(n)}`,
|
|
1219
1222
|
annotation: e,
|
|
1220
1223
|
type: i,
|
|
1221
1224
|
purpose: r,
|
|
1222
1225
|
value: a,
|
|
1223
|
-
creator: Ht(
|
|
1226
|
+
creator: Ht(f),
|
|
1224
1227
|
created: s ? new Date(s) : void 0,
|
|
1225
1228
|
updated: u ? new Date(u) : void 0,
|
|
1226
1229
|
...m
|
|
@@ -1253,13 +1256,13 @@ const In = (t, e) => ({
|
|
|
1253
1256
|
selector: []
|
|
1254
1257
|
};
|
|
1255
1258
|
for (const u of a) {
|
|
1256
|
-
const m = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((c,
|
|
1257
|
-
switch (
|
|
1259
|
+
const m = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((c, p) => {
|
|
1260
|
+
switch (p.type) {
|
|
1258
1261
|
case "TextQuoteSelector":
|
|
1259
|
-
c.quote =
|
|
1262
|
+
c.quote = p.exact;
|
|
1260
1263
|
break;
|
|
1261
1264
|
case "TextPositionSelector":
|
|
1262
|
-
c.start =
|
|
1265
|
+
c.start = p.start, c.end = p.end;
|
|
1263
1266
|
break;
|
|
1264
1267
|
}
|
|
1265
1268
|
return c;
|
|
@@ -1296,22 +1299,22 @@ const In = (t, e) => ({
|
|
|
1296
1299
|
selector: a,
|
|
1297
1300
|
creator: s,
|
|
1298
1301
|
created: u,
|
|
1299
|
-
updated:
|
|
1302
|
+
updated: f,
|
|
1300
1303
|
...m
|
|
1301
|
-
} = i, c = a.map((
|
|
1302
|
-
const { quote:
|
|
1304
|
+
} = i, c = a.map((p) => {
|
|
1305
|
+
const { quote: g, start: x, end: v, range: h } = p, { prefix: d, suffix: l } = te(h, n), y = [{
|
|
1303
1306
|
type: "TextQuoteSelector",
|
|
1304
|
-
exact:
|
|
1305
|
-
prefix:
|
|
1306
|
-
suffix:
|
|
1307
|
+
exact: g,
|
|
1308
|
+
prefix: d,
|
|
1309
|
+
suffix: l
|
|
1307
1310
|
}, {
|
|
1308
1311
|
type: "TextPositionSelector",
|
|
1309
1312
|
start: x,
|
|
1310
|
-
end:
|
|
1313
|
+
end: v
|
|
1311
1314
|
}];
|
|
1312
1315
|
return {
|
|
1313
1316
|
...m,
|
|
1314
|
-
id:
|
|
1317
|
+
id: p.id,
|
|
1315
1318
|
source: e,
|
|
1316
1319
|
selector: y
|
|
1317
1320
|
};
|
|
@@ -1324,34 +1327,34 @@ const In = (t, e) => ({
|
|
|
1324
1327
|
body: ln(t.bodies),
|
|
1325
1328
|
creator: s,
|
|
1326
1329
|
created: u == null ? void 0 : u.toISOString(),
|
|
1327
|
-
modified:
|
|
1330
|
+
modified: f == null ? void 0 : f.toISOString(),
|
|
1328
1331
|
target: c
|
|
1329
1332
|
};
|
|
1330
1333
|
};
|
|
1331
|
-
function
|
|
1332
|
-
$t(t, e, n || 0, o || t.length - 1, i ||
|
|
1334
|
+
function gn(t, e, n, o, i) {
|
|
1335
|
+
$t(t, e, n || 0, o || t.length - 1, i || pn);
|
|
1333
1336
|
}
|
|
1334
1337
|
function $t(t, e, n, o, i) {
|
|
1335
1338
|
for (; o > n; ) {
|
|
1336
1339
|
if (o - n > 600) {
|
|
1337
|
-
var r = o - n + 1, a = e - n + 1, s = Math.log(r), u = 0.5 * Math.exp(2 * s / 3),
|
|
1340
|
+
var r = o - n + 1, a = e - n + 1, s = Math.log(r), u = 0.5 * Math.exp(2 * s / 3), f = 0.5 * Math.sqrt(s * u * (r - u) / r) * (a - r / 2 < 0 ? -1 : 1), m = Math.max(n, Math.floor(e - a * u / r + f)), c = Math.min(o, Math.floor(e + (r - a) * u / r + f));
|
|
1338
1341
|
$t(t, e, m, c, i);
|
|
1339
1342
|
}
|
|
1340
|
-
var
|
|
1341
|
-
for (j(t, n, e), i(t[o],
|
|
1342
|
-
for (j(t,
|
|
1343
|
-
|
|
1344
|
-
for (; i(t[x],
|
|
1343
|
+
var p = t[e], g = n, x = o;
|
|
1344
|
+
for (j(t, n, e), i(t[o], p) > 0 && j(t, n, o); g < x; ) {
|
|
1345
|
+
for (j(t, g, x), g++, x--; i(t[g], p) < 0; )
|
|
1346
|
+
g++;
|
|
1347
|
+
for (; i(t[x], p) > 0; )
|
|
1345
1348
|
x--;
|
|
1346
1349
|
}
|
|
1347
|
-
i(t[n],
|
|
1350
|
+
i(t[n], p) === 0 ? j(t, n, x) : (x++, j(t, x, o)), x <= e && (n = x + 1), e <= x && (o = x - 1);
|
|
1348
1351
|
}
|
|
1349
1352
|
}
|
|
1350
1353
|
function j(t, e, n) {
|
|
1351
1354
|
var o = t[e];
|
|
1352
1355
|
t[e] = t[n], t[n] = o;
|
|
1353
1356
|
}
|
|
1354
|
-
function
|
|
1357
|
+
function pn(t, e) {
|
|
1355
1358
|
return t < e ? -1 : t > e ? 1 : 0;
|
|
1356
1359
|
}
|
|
1357
1360
|
class mn {
|
|
@@ -1427,14 +1430,14 @@ class mn {
|
|
|
1427
1430
|
return this;
|
|
1428
1431
|
let o = this.data;
|
|
1429
1432
|
const i = this.toBBox(e), r = [], a = [];
|
|
1430
|
-
let s, u,
|
|
1433
|
+
let s, u, f;
|
|
1431
1434
|
for (; o || r.length; ) {
|
|
1432
|
-
if (o || (o = r.pop(), u = r[r.length - 1], s = a.pop(),
|
|
1435
|
+
if (o || (o = r.pop(), u = r[r.length - 1], s = a.pop(), f = !0), o.leaf) {
|
|
1433
1436
|
const m = bn(e, o.children, n);
|
|
1434
1437
|
if (m !== -1)
|
|
1435
1438
|
return o.children.splice(m, 1), r.push(o), this._condense(r), this;
|
|
1436
1439
|
}
|
|
1437
|
-
!
|
|
1440
|
+
!f && !o.leaf && ht(o, i) ? (r.push(o), a.push(s), s = 0, u = o, o = o.children[0]) : u ? (s++, o = u.children[s], f = !1) : o = null;
|
|
1438
1441
|
}
|
|
1439
1442
|
return this;
|
|
1440
1443
|
}
|
|
@@ -1465,14 +1468,14 @@ class mn {
|
|
|
1465
1468
|
if (r <= a)
|
|
1466
1469
|
return s = W(e.slice(n, o + 1)), F(s, this.toBBox), s;
|
|
1467
1470
|
i || (i = Math.ceil(Math.log(r) / Math.log(a)), a = Math.ceil(r / Math.pow(a, i - 1))), s = W([]), s.leaf = !1, s.height = i;
|
|
1468
|
-
const u = Math.ceil(r / a),
|
|
1469
|
-
It(e, n, o,
|
|
1470
|
-
for (let m = n; m <= o; m +=
|
|
1471
|
-
const c = Math.min(m +
|
|
1471
|
+
const u = Math.ceil(r / a), f = u * Math.ceil(Math.sqrt(a));
|
|
1472
|
+
It(e, n, o, f, this.compareMinX);
|
|
1473
|
+
for (let m = n; m <= o; m += f) {
|
|
1474
|
+
const c = Math.min(m + f - 1, o);
|
|
1472
1475
|
It(e, m, c, u, this.compareMinY);
|
|
1473
|
-
for (let
|
|
1474
|
-
const
|
|
1475
|
-
s.children.push(this._build(e,
|
|
1476
|
+
for (let p = m; p <= c; p += u) {
|
|
1477
|
+
const g = Math.min(p + u - 1, c);
|
|
1478
|
+
s.children.push(this._build(e, p, g, i - 1));
|
|
1476
1479
|
}
|
|
1477
1480
|
}
|
|
1478
1481
|
return F(s, this.toBBox), s;
|
|
@@ -1481,8 +1484,8 @@ class mn {
|
|
|
1481
1484
|
for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
|
|
1482
1485
|
let r = 1 / 0, a = 1 / 0, s;
|
|
1483
1486
|
for (let u = 0; u < n.children.length; u++) {
|
|
1484
|
-
const
|
|
1485
|
-
c < a ? (a = c, r = m < r ? m : r, s =
|
|
1487
|
+
const f = n.children[u], m = ut(f), c = wn(e, f) - m;
|
|
1488
|
+
c < a ? (a = c, r = m < r ? m : r, s = f) : c === a && m < r && (r = m, s = f);
|
|
1486
1489
|
}
|
|
1487
1490
|
n = s || n.children[0];
|
|
1488
1491
|
}
|
|
@@ -1507,7 +1510,7 @@ class mn {
|
|
|
1507
1510
|
_chooseSplitIndex(e, n, o) {
|
|
1508
1511
|
let i, r = 1 / 0, a = 1 / 0;
|
|
1509
1512
|
for (let s = n; s <= o - n; s++) {
|
|
1510
|
-
const u = G(e, 0, s, this.toBBox),
|
|
1513
|
+
const u = G(e, 0, s, this.toBBox), f = G(e, s, o, this.toBBox), m = xn(u, f), c = ut(u) + ut(f);
|
|
1511
1514
|
m < r ? (r = m, i = s, a = c < a ? c : a) : m === r && c < a && (a = c, i = s);
|
|
1512
1515
|
}
|
|
1513
1516
|
return i || o - n;
|
|
@@ -1522,12 +1525,12 @@ class mn {
|
|
|
1522
1525
|
e.children.sort(i);
|
|
1523
1526
|
const r = this.toBBox, a = G(e, 0, n, r), s = G(e, o - n, o, r);
|
|
1524
1527
|
let u = et(a) + et(s);
|
|
1525
|
-
for (let
|
|
1526
|
-
const m = e.children[
|
|
1528
|
+
for (let f = n; f < o - n; f++) {
|
|
1529
|
+
const m = e.children[f];
|
|
1527
1530
|
K(a, e.leaf ? r(m) : m), u += et(a);
|
|
1528
1531
|
}
|
|
1529
|
-
for (let
|
|
1530
|
-
const m = e.children[
|
|
1532
|
+
for (let f = o - n - 1; f >= n; f--) {
|
|
1533
|
+
const m = e.children[f];
|
|
1531
1534
|
K(s, e.leaf ? r(m) : m), u += et(s);
|
|
1532
1535
|
}
|
|
1533
1536
|
return u;
|
|
@@ -1605,131 +1608,131 @@ function It(t, e, n, o, i) {
|
|
|
1605
1608
|
if (n = r.pop(), e = r.pop(), n - e <= o)
|
|
1606
1609
|
continue;
|
|
1607
1610
|
const a = e + Math.ceil((n - e) / o / 2) * o;
|
|
1608
|
-
|
|
1611
|
+
gn(t, a, e, n, i), r.push(e, a, a, n);
|
|
1609
1612
|
}
|
|
1610
1613
|
}
|
|
1611
1614
|
const An = (t, e) => {
|
|
1612
|
-
const n = new mn(), o = /* @__PURE__ */ new Map(), i = (
|
|
1613
|
-
const y =
|
|
1614
|
-
const N =
|
|
1615
|
+
const n = new mn(), o = /* @__PURE__ */ new Map(), i = (d, l) => {
|
|
1616
|
+
const y = d.selector.flatMap((C) => {
|
|
1617
|
+
const N = C.range instanceof Range && !C.range.collapsed && C.range.startContainer.nodeType === Node.TEXT_NODE && C.range.endContainer.nodeType === Node.TEXT_NODE ? C.range : _t(C, e).range;
|
|
1615
1618
|
return Array.from(N.getClientRects());
|
|
1616
|
-
}), T = oe(y).map(({ left:
|
|
1617
|
-
return T.map((
|
|
1618
|
-
const { x: E, y: N, width: R, height:
|
|
1619
|
+
}), T = oe(y).map(({ left: C, top: E, right: N, bottom: R }) => new DOMRect(C - l.left, E - l.top, N - C, R - E));
|
|
1620
|
+
return T.map((C) => {
|
|
1621
|
+
const { x: E, y: N, width: R, height: O } = C;
|
|
1619
1622
|
return {
|
|
1620
1623
|
minX: E,
|
|
1621
1624
|
minY: N,
|
|
1622
1625
|
maxX: E + R,
|
|
1623
|
-
maxY: N +
|
|
1626
|
+
maxY: N + O,
|
|
1624
1627
|
annotation: {
|
|
1625
|
-
id:
|
|
1628
|
+
id: d.annotation,
|
|
1626
1629
|
rects: T
|
|
1627
1630
|
}
|
|
1628
1631
|
};
|
|
1629
1632
|
});
|
|
1630
1633
|
}, r = () => [...o.values()], a = () => {
|
|
1631
1634
|
n.clear(), o.clear();
|
|
1632
|
-
}, s = (
|
|
1633
|
-
const
|
|
1634
|
-
|
|
1635
|
-
}, u = (
|
|
1636
|
-
const
|
|
1637
|
-
|
|
1638
|
-
},
|
|
1639
|
-
u(
|
|
1640
|
-
}, m = (
|
|
1641
|
-
|
|
1642
|
-
const y = e.getBoundingClientRect(), T =
|
|
1635
|
+
}, s = (d) => {
|
|
1636
|
+
const l = i(d, e.getBoundingClientRect());
|
|
1637
|
+
l.forEach((y) => n.insert(y)), o.set(d.annotation, l);
|
|
1638
|
+
}, u = (d) => {
|
|
1639
|
+
const l = o.get(d.annotation);
|
|
1640
|
+
l && (l.forEach((y) => n.remove(y)), o.delete(d.annotation));
|
|
1641
|
+
}, f = (d) => {
|
|
1642
|
+
u(d), s(d);
|
|
1643
|
+
}, m = (d, l = !0) => {
|
|
1644
|
+
l && a();
|
|
1645
|
+
const y = e.getBoundingClientRect(), T = d.map((E) => ({ target: E, rects: i(E, y) }));
|
|
1643
1646
|
T.forEach(({ target: E, rects: N }) => o.set(E.annotation, N));
|
|
1644
|
-
const
|
|
1645
|
-
n.load(
|
|
1646
|
-
}, c = (
|
|
1647
|
+
const C = T.reduce((E, { rects: N }) => [...E, ...N], []);
|
|
1648
|
+
n.load(C);
|
|
1649
|
+
}, c = (d, l) => {
|
|
1647
1650
|
const y = n.search({
|
|
1648
|
-
minX:
|
|
1649
|
-
minY:
|
|
1650
|
-
maxX:
|
|
1651
|
-
maxY:
|
|
1652
|
-
}), T = (
|
|
1651
|
+
minX: d,
|
|
1652
|
+
minY: l,
|
|
1653
|
+
maxX: d,
|
|
1654
|
+
maxY: l
|
|
1655
|
+
}), T = (C) => C.annotation.rects.reduce((E, N) => E + N.width * N.height, 0);
|
|
1653
1656
|
if (y.length > 0)
|
|
1654
|
-
return y.sort((
|
|
1655
|
-
},
|
|
1656
|
-
const
|
|
1657
|
-
if (
|
|
1657
|
+
return y.sort((C, E) => T(C) - T(E)), y[0].annotation.id;
|
|
1658
|
+
}, p = (d) => {
|
|
1659
|
+
const l = g(d);
|
|
1660
|
+
if (l.length === 0)
|
|
1658
1661
|
return;
|
|
1659
|
-
let y =
|
|
1660
|
-
for (let N = 1; N <
|
|
1661
|
-
const R =
|
|
1662
|
-
y = Math.min(y, R.left), T = Math.min(T, R.top),
|
|
1662
|
+
let y = l[0].left, T = l[0].top, C = l[0].right, E = l[0].bottom;
|
|
1663
|
+
for (let N = 1; N < l.length; N++) {
|
|
1664
|
+
const R = l[N];
|
|
1665
|
+
y = Math.min(y, R.left), T = Math.min(T, R.top), C = Math.max(C, R.right), E = Math.max(E, R.bottom);
|
|
1663
1666
|
}
|
|
1664
|
-
return new DOMRect(y, T,
|
|
1665
|
-
},
|
|
1666
|
-
const
|
|
1667
|
-
return
|
|
1667
|
+
return new DOMRect(y, T, C - y, E - T);
|
|
1668
|
+
}, g = (d) => {
|
|
1669
|
+
const l = o.get(d);
|
|
1670
|
+
return l ? l[0].annotation.rects : [];
|
|
1668
1671
|
};
|
|
1669
1672
|
return {
|
|
1670
1673
|
all: r,
|
|
1671
1674
|
clear: a,
|
|
1672
1675
|
getAt: c,
|
|
1673
|
-
getAnnotationBounds:
|
|
1674
|
-
getAnnotationRects:
|
|
1675
|
-
getIntersecting: (
|
|
1676
|
-
const
|
|
1676
|
+
getAnnotationBounds: p,
|
|
1677
|
+
getAnnotationRects: g,
|
|
1678
|
+
getIntersecting: (d, l, y, T) => {
|
|
1679
|
+
const C = n.search({ minX: d, minY: l, maxX: y, maxY: T }), E = new Set(C.reduce((N, R) => [...N, R.annotation.id], []));
|
|
1677
1680
|
return Array.from(E).map((N) => ({
|
|
1678
1681
|
annotation: t.getAnnotation(N),
|
|
1679
|
-
rects:
|
|
1682
|
+
rects: g(N)
|
|
1680
1683
|
})).filter((N) => !!N.annotation);
|
|
1681
1684
|
},
|
|
1682
1685
|
insert: s,
|
|
1683
|
-
recalculate: () => m(t.all().map((
|
|
1686
|
+
recalculate: () => m(t.all().map((d) => d.target), !0),
|
|
1684
1687
|
remove: u,
|
|
1685
1688
|
set: m,
|
|
1686
1689
|
size: () => n.all().length,
|
|
1687
|
-
update:
|
|
1690
|
+
update: f
|
|
1688
1691
|
};
|
|
1689
1692
|
}, En = (t, e) => {
|
|
1690
|
-
const n = We(), o = An(n, t), i = Ie(n, e), r = Be(n), a = Ke(), s = (
|
|
1691
|
-
const
|
|
1692
|
-
return
|
|
1693
|
-
}, u = (
|
|
1694
|
-
const
|
|
1695
|
-
return y.length > 0 ? (console.warn("Could not revive all targets for these annotations:", y), n.bulkAddAnnotation(
|
|
1696
|
-
},
|
|
1697
|
-
const
|
|
1698
|
-
return
|
|
1699
|
-
n.getAnnotation(y.id) ? n.updateAnnotation(y,
|
|
1700
|
-
}),
|
|
1701
|
-
}, m = (
|
|
1702
|
-
const
|
|
1703
|
-
n.updateTarget(
|
|
1704
|
-
}, c = (
|
|
1705
|
-
const
|
|
1706
|
-
n.bulkUpdateTargets(
|
|
1707
|
-
},
|
|
1708
|
-
const
|
|
1709
|
-
return
|
|
1710
|
-
},
|
|
1711
|
-
const y = o.getAnnotationRects(
|
|
1693
|
+
const n = We(), o = An(n, t), i = Ie(n, e), r = Be(n), a = Ke(), s = (v, h = B.LOCAL) => {
|
|
1694
|
+
const d = rt(v, t), l = $(d.target.selector);
|
|
1695
|
+
return l && n.addAnnotation(d, h), l;
|
|
1696
|
+
}, u = (v, h = !0, d = B.LOCAL) => {
|
|
1697
|
+
const l = v.map((T) => rt(T, t)), y = l.filter((T) => !$(T.target.selector));
|
|
1698
|
+
return y.length > 0 ? (console.warn("Could not revive all targets for these annotations:", y), n.bulkAddAnnotation(l, h, d), y) : (n.bulkAddAnnotation(l, h, d), []);
|
|
1699
|
+
}, f = (v, h = B.LOCAL) => {
|
|
1700
|
+
const d = v.map((y) => rt(y, t)), l = d.filter((y) => !$(y.target.selector));
|
|
1701
|
+
return l.length > 0 && console.warn("Could not revive all targets for these annotations:", l), d.forEach((y) => {
|
|
1702
|
+
n.getAnnotation(y.id) ? n.updateAnnotation(y, h) : n.addAnnotation(y, h);
|
|
1703
|
+
}), l;
|
|
1704
|
+
}, m = (v, h = B.LOCAL) => {
|
|
1705
|
+
const d = it(v, t);
|
|
1706
|
+
n.updateTarget(d, h);
|
|
1707
|
+
}, c = (v, h = B.LOCAL) => {
|
|
1708
|
+
const d = v.map((l) => it(l, t));
|
|
1709
|
+
n.bulkUpdateTargets(d, h);
|
|
1710
|
+
}, p = (v, h) => {
|
|
1711
|
+
const d = o.getAt(v, h);
|
|
1712
|
+
return d ? n.getAnnotation(d) : void 0;
|
|
1713
|
+
}, g = (v, h, d, l = 5) => {
|
|
1714
|
+
const y = o.getAnnotationRects(v);
|
|
1712
1715
|
if (y.length !== 0) {
|
|
1713
|
-
if (
|
|
1714
|
-
const T = y.find(({ top:
|
|
1716
|
+
if (h && d) {
|
|
1717
|
+
const T = y.find(({ top: C, right: E, bottom: N, left: R }) => h >= R - l && h <= E + l && d >= C - l && d <= N + l);
|
|
1715
1718
|
if (T)
|
|
1716
1719
|
return T;
|
|
1717
1720
|
}
|
|
1718
|
-
return o.getAnnotationBounds(
|
|
1721
|
+
return o.getAnnotationBounds(v);
|
|
1719
1722
|
}
|
|
1720
1723
|
}, x = () => o.recalculate();
|
|
1721
|
-
return n.observe(({ changes:
|
|
1722
|
-
const
|
|
1723
|
-
|
|
1724
|
+
return n.observe(({ changes: v }) => {
|
|
1725
|
+
const h = (v.created || []).filter((y) => $(y.target.selector)), d = (v.deleted || []).filter((y) => $(y.target.selector)), l = (v.updated || []).filter((y) => $(y.newValue.target.selector));
|
|
1726
|
+
h.length > 0 && o.set(h.map((y) => y.target), !1), (d == null ? void 0 : d.length) > 0 && d.forEach((y) => o.remove(y.target)), (l == null ? void 0 : l.length) > 0 && l.forEach(({ newValue: y }) => o.update(y.target));
|
|
1724
1727
|
}), {
|
|
1725
1728
|
store: {
|
|
1726
1729
|
...n,
|
|
1727
1730
|
addAnnotation: s,
|
|
1728
1731
|
bulkAddAnnotation: u,
|
|
1729
1732
|
bulkUpdateTargets: c,
|
|
1730
|
-
bulkUpsertAnnotations:
|
|
1731
|
-
getAnnotationBounds:
|
|
1732
|
-
getAt:
|
|
1733
|
+
bulkUpsertAnnotations: f,
|
|
1734
|
+
getAnnotationBounds: g,
|
|
1735
|
+
getAt: p,
|
|
1733
1736
|
getIntersecting: o.getIntersecting,
|
|
1734
1737
|
recalculatePositions: x,
|
|
1735
1738
|
updateTarget: m
|
|
@@ -1746,27 +1749,27 @@ const An = (t, e) => {
|
|
|
1746
1749
|
}, Cn = (t, e, n = {}) => {
|
|
1747
1750
|
const o = Sn(), i = o.getContext("2d");
|
|
1748
1751
|
t.appendChild(o);
|
|
1749
|
-
const r = /* @__PURE__ */ new Map(), a = (c) => Array.from(r.entries()).filter(([
|
|
1750
|
-
return e.on("selectionChange", (c,
|
|
1751
|
-
a(c).forEach((x) => r.delete(x)),
|
|
1752
|
+
const r = /* @__PURE__ */ new Map(), a = (c) => Array.from(r.entries()).filter(([p, g]) => g.presenceKey === c.presenceKey).map(([p, g]) => p);
|
|
1753
|
+
return e.on("selectionChange", (c, p) => {
|
|
1754
|
+
a(c).forEach((x) => r.delete(x)), p && p.forEach((x) => r.set(x, c));
|
|
1752
1755
|
}), {
|
|
1753
1756
|
clear: () => {
|
|
1754
|
-
const { width: c, height:
|
|
1755
|
-
i.clearRect(-0.5, -0.5, c + 1,
|
|
1757
|
+
const { width: c, height: p } = o;
|
|
1758
|
+
i.clearRect(-0.5, -0.5, c + 1, p + 1);
|
|
1756
1759
|
},
|
|
1757
1760
|
destroy: () => {
|
|
1758
1761
|
o.remove();
|
|
1759
1762
|
},
|
|
1760
|
-
paint: (c,
|
|
1763
|
+
paint: (c, p, g) => {
|
|
1761
1764
|
n.font && (i.font = n.font);
|
|
1762
1765
|
const x = r.get(c.annotation.id);
|
|
1763
1766
|
if (x) {
|
|
1764
|
-
const { height:
|
|
1765
|
-
i.fillStyle = x.appearance.color, i.fillRect(
|
|
1766
|
-
const
|
|
1767
|
-
return i.fillRect(
|
|
1767
|
+
const { height: v } = c.rects[0], h = c.rects[0].x + p.left, d = c.rects[0].y + p.top;
|
|
1768
|
+
i.fillStyle = x.appearance.color, i.fillRect(h - 2, d - 2.5, 2, v + 5);
|
|
1769
|
+
const l = i.measureText(x.appearance.label), y = l.width + 6, T = l.actualBoundingBoxAscent + l.actualBoundingBoxDescent + 8, C = l.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1770
|
+
return i.fillRect(h - 2, d - 2.5 - T, y, T), i.fillStyle = "#fff", i.fillText(x.appearance.label, h + 1, d - C), {
|
|
1768
1771
|
fill: x.appearance.color,
|
|
1769
|
-
fillOpacity:
|
|
1772
|
+
fillOpacity: g ? 0.45 : 0.18
|
|
1770
1773
|
};
|
|
1771
1774
|
}
|
|
1772
1775
|
},
|
|
@@ -1783,8 +1786,8 @@ const An = (t, e) => {
|
|
|
1783
1786
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : Pt(t.parentElement);
|
|
1784
1787
|
}, Tn = (t, e) => (n) => {
|
|
1785
1788
|
const o = (r) => {
|
|
1786
|
-
const a = i.getBoundingClientRect(), s = i.clientHeight, u = i.clientWidth,
|
|
1787
|
-
i.scroll({ top:
|
|
1789
|
+
const a = i.getBoundingClientRect(), s = i.clientHeight, u = i.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: m, height: c } = e.getAnnotationBounds(n.id), p = f.top - a.top, g = f.left - a.left, x = i.parentElement ? i.scrollTop : 0, v = i.parentElement ? i.scrollLeft : 0, h = p + x - (s - c) / 2, d = g + v - (u - m) / 2;
|
|
1790
|
+
i.scroll({ top: h, left: d, behavior: "smooth" });
|
|
1788
1791
|
}, i = Pt(t);
|
|
1789
1792
|
if (i) {
|
|
1790
1793
|
const r = e.getAnnotation(n.id), { range: a } = r.target.selector[0];
|
|
@@ -1803,13 +1806,13 @@ const An = (t, e) => {
|
|
|
1803
1806
|
}), Rn = (t, e, n, o) => {
|
|
1804
1807
|
const { store: i, selection: r } = e;
|
|
1805
1808
|
let a, s;
|
|
1806
|
-
const u = (
|
|
1807
|
-
let
|
|
1808
|
-
const c = (
|
|
1809
|
-
var
|
|
1810
|
-
if (!
|
|
1809
|
+
const u = (h) => a = h;
|
|
1810
|
+
let f = !1, m;
|
|
1811
|
+
const c = (h) => {
|
|
1812
|
+
var l;
|
|
1813
|
+
if (!f)
|
|
1811
1814
|
return;
|
|
1812
|
-
!((
|
|
1815
|
+
!((l = h.target.parentElement) != null && l.closest(X)) ? s = {
|
|
1813
1816
|
annotation: kt(),
|
|
1814
1817
|
selector: [],
|
|
1815
1818
|
creator: a,
|
|
@@ -1817,51 +1820,51 @@ const An = (t, e) => {
|
|
|
1817
1820
|
} : s = void 0;
|
|
1818
1821
|
};
|
|
1819
1822
|
n && t.addEventListener("selectstart", c);
|
|
1820
|
-
const
|
|
1823
|
+
const p = pt((h) => {
|
|
1821
1824
|
var N, R;
|
|
1822
|
-
const
|
|
1823
|
-
if (!!((R = (N =
|
|
1825
|
+
const d = document.getSelection();
|
|
1826
|
+
if (!!((R = (N = d.anchorNode) == null ? void 0 : N.parentElement) != null && R.closest(X))) {
|
|
1824
1827
|
s = void 0;
|
|
1825
1828
|
return;
|
|
1826
1829
|
}
|
|
1827
|
-
if (
|
|
1830
|
+
if (h.timeStamp - ((m == null ? void 0 : m.timeStamp) || h.timeStamp) < 1e3 && !s && c(m), d.isCollapsed || !f || !s)
|
|
1828
1831
|
return;
|
|
1829
|
-
const y =
|
|
1830
|
-
(
|
|
1832
|
+
const y = d.getRangeAt(0), T = re(y.cloneRange()), C = Kt(T);
|
|
1833
|
+
(C.length !== s.selector.length || C.some((O, b) => {
|
|
1831
1834
|
var w;
|
|
1832
|
-
return
|
|
1835
|
+
return O.toString() !== ((w = s.selector[b]) == null ? void 0 : w.quote);
|
|
1833
1836
|
})) && (s = {
|
|
1834
1837
|
...s,
|
|
1835
|
-
selector:
|
|
1838
|
+
selector: C.map((O) => ie(O, t, o))
|
|
1836
1839
|
}, i.getAnnotation(s.annotation) ? i.updateTarget(s, B.LOCAL) : (i.addAnnotation({
|
|
1837
1840
|
id: s.annotation,
|
|
1838
1841
|
bodies: [],
|
|
1839
1842
|
target: s
|
|
1840
1843
|
}), r.clickSelect(s.annotation, m)));
|
|
1841
1844
|
});
|
|
1842
|
-
n && document.addEventListener("selectionchange",
|
|
1843
|
-
const
|
|
1844
|
-
const { target:
|
|
1845
|
-
m = { ...
|
|
1845
|
+
n && document.addEventListener("selectionchange", p);
|
|
1846
|
+
const g = (h) => {
|
|
1847
|
+
const { target: d, timeStamp: l, offsetX: y, offsetY: T, type: C } = h;
|
|
1848
|
+
m = { ...h, target: d, timeStamp: l, offsetX: y, offsetY: T, type: C }, f = h.button === 0;
|
|
1846
1849
|
};
|
|
1847
|
-
t.addEventListener("pointerdown",
|
|
1848
|
-
const x = (
|
|
1850
|
+
t.addEventListener("pointerdown", g);
|
|
1851
|
+
const x = (h) => {
|
|
1849
1852
|
var T;
|
|
1850
|
-
if (!!((T =
|
|
1853
|
+
if (!!((T = h.target.parentElement) != null && T.closest(X)) || !f)
|
|
1851
1854
|
return;
|
|
1852
|
-
const
|
|
1853
|
-
const { x:
|
|
1855
|
+
const l = () => {
|
|
1856
|
+
const { x: C, y: E } = t.getBoundingClientRect(), N = i.getAt(h.clientX - C, h.clientY - E);
|
|
1854
1857
|
if (N) {
|
|
1855
1858
|
const { selected: R } = r;
|
|
1856
|
-
(R.length !== 1 || R[0].id !== N.id) && r.clickSelect(N.id,
|
|
1859
|
+
(R.length !== 1 || R[0].id !== N.id) && r.clickSelect(N.id, h);
|
|
1857
1860
|
} else
|
|
1858
1861
|
r.isEmpty() || r.clear();
|
|
1859
|
-
}, y =
|
|
1860
|
-
document.getSelection().isCollapsed && y < 300 ? (s = void 0,
|
|
1862
|
+
}, y = h.timeStamp - m.timeStamp;
|
|
1863
|
+
document.getSelection().isCollapsed && y < 300 ? (s = void 0, l()) : s && r.clickSelect(s.annotation, h);
|
|
1861
1864
|
};
|
|
1862
1865
|
return document.addEventListener("pointerup", x), {
|
|
1863
1866
|
destroy: () => {
|
|
1864
|
-
t.removeEventListener("selectstart", c), document.removeEventListener("selectionchange",
|
|
1867
|
+
t.removeEventListener("selectstart", c), document.removeEventListener("selectionchange", p), t.removeEventListener("pointerdown", g), document.removeEventListener("pointerup", x);
|
|
1865
1868
|
},
|
|
1866
1869
|
setUser: u
|
|
1867
1870
|
};
|
|
@@ -1870,23 +1873,23 @@ const An = (t, e) => {
|
|
|
1870
1873
|
const n = Nn(e, {
|
|
1871
1874
|
annotationEnabled: !0
|
|
1872
1875
|
}), o = En(t, n.pointerAction), { selection: i, viewport: r } = o, a = o.store, s = Ge(a), u = Qe(o, s, n.adapter);
|
|
1873
|
-
let
|
|
1876
|
+
let f = sn();
|
|
1874
1877
|
const m = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : Mt : n.renderer || Mt, c = m === "SPANS" ? Se(t, o, r) : m === "CSS_HIGHLIGHTS" ? xe(t, o, r) : m === "CANVAS" ? ue(t, o, r) : void 0;
|
|
1875
1878
|
if (!c)
|
|
1876
1879
|
throw `Unknown renderer implementation: ${m}`;
|
|
1877
1880
|
console.debug(`Using ${m} renderer`), n.style && c.setStyle(n.style);
|
|
1878
|
-
const
|
|
1879
|
-
return
|
|
1881
|
+
const p = Rn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
|
|
1882
|
+
return p.setUser(f), {
|
|
1880
1883
|
...Ze(o, s, n.adapter),
|
|
1881
1884
|
destroy: () => {
|
|
1882
|
-
c.destroy(),
|
|
1885
|
+
c.destroy(), p.destroy(), s.destroy();
|
|
1883
1886
|
},
|
|
1884
1887
|
element: t,
|
|
1885
|
-
getUser: () =>
|
|
1888
|
+
getUser: () => f,
|
|
1886
1889
|
setFilter: (E) => c.setFilter(E),
|
|
1887
1890
|
setStyle: (E) => c.setStyle(E),
|
|
1888
1891
|
setUser: (E) => {
|
|
1889
|
-
|
|
1892
|
+
f = E, p.setUser(E);
|
|
1890
1893
|
},
|
|
1891
1894
|
setSelected: (E) => {
|
|
1892
1895
|
E ? i.setSelected(E) : i.clear();
|
|
@@ -1917,7 +1920,7 @@ export {
|
|
|
1917
1920
|
Se as createSpansRenderer,
|
|
1918
1921
|
Mn as createTextAnnotator,
|
|
1919
1922
|
En as createTextAnnotatorState,
|
|
1920
|
-
|
|
1923
|
+
pt as debounce,
|
|
1921
1924
|
Nn as fillDefaults,
|
|
1922
1925
|
Ln as getAnnotatableFragment,
|
|
1923
1926
|
Bn as getClientRectsPonyfill,
|