@recogito/text-annotator 3.0.0-rc.15 → 3.0.0-rc.17
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.
|
@@ -7,7 +7,7 @@ const Ot = (t) => {
|
|
|
7
7
|
const i = o.map((s) => s.id);
|
|
8
8
|
(e.size !== i.length || i.some((s) => !e.has(s))) && t.set(i), e = new Set(i);
|
|
9
9
|
};
|
|
10
|
-
},
|
|
10
|
+
}, gt = (t, e = 10) => {
|
|
11
11
|
let n;
|
|
12
12
|
return (...o) => {
|
|
13
13
|
clearTimeout(n), n = setTimeout(() => t.apply(void 0, o), e);
|
|
@@ -39,13 +39,13 @@ const Ot = (t) => {
|
|
|
39
39
|
o.setStartAfter(n), o.collapsed || e.push(o);
|
|
40
40
|
}
|
|
41
41
|
return e.length > 0 ? e : [t];
|
|
42
|
-
},
|
|
42
|
+
}, ft = (t) => {
|
|
43
43
|
const e = t.cloneContents();
|
|
44
44
|
return e.querySelectorAll(q).forEach((n) => n.remove()), e;
|
|
45
45
|
}, mn = (t) => {
|
|
46
46
|
const e = t.cloneContents();
|
|
47
47
|
return e.querySelectorAll(q).forEach((n) => n.remove()), e;
|
|
48
|
-
},
|
|
48
|
+
}, yt = (t, e) => {
|
|
49
49
|
const n = document.createNodeIterator(e);
|
|
50
50
|
let o = 0, i = n.nextNode();
|
|
51
51
|
for (; i !== null; ) {
|
|
@@ -53,7 +53,7 @@ const Ot = (t) => {
|
|
|
53
53
|
return o;
|
|
54
54
|
o += 1, i = n.nextNode();
|
|
55
55
|
}
|
|
56
|
-
},
|
|
56
|
+
}, wt = (t, e) => {
|
|
57
57
|
const n = document.createNodeIterator(e);
|
|
58
58
|
let o = null;
|
|
59
59
|
for (let i = 0; i < t + 1; i++)
|
|
@@ -69,11 +69,11 @@ const Ot = (t) => {
|
|
|
69
69
|
} = t, r = Array.from(e.childNodes).map((c) => {
|
|
70
70
|
const b = c.cloneNode(!0);
|
|
71
71
|
return c.nodeName === "CANVAS" ? c : b;
|
|
72
|
-
}), a =
|
|
72
|
+
}), a = yt(n, e), d = yt(i, e), u = () => {
|
|
73
73
|
const c = e;
|
|
74
74
|
c.replaceChildren(...r);
|
|
75
|
-
const b =
|
|
76
|
-
return t.setStart(b, o), t.setEnd(
|
|
75
|
+
const b = wt(a, c), p = wt(d, c);
|
|
76
|
+
return t.setStart(b, o), t.setEnd(p, s), t;
|
|
77
77
|
}, y = (c) => {
|
|
78
78
|
const b = document.createElement("SPAN");
|
|
79
79
|
return c.surroundContents(b), b;
|
|
@@ -83,14 +83,14 @@ const Ot = (t) => {
|
|
|
83
83
|
{
|
|
84
84
|
const c = document.createRange();
|
|
85
85
|
c.selectNodeContents(n), c.setStart(n, o);
|
|
86
|
-
const b = y(c),
|
|
87
|
-
|
|
88
|
-
const v = y(
|
|
86
|
+
const b = y(c), p = document.createRange();
|
|
87
|
+
p.selectNode(i), p.setEnd(i, s);
|
|
88
|
+
const v = y(p), E = Zt(t).reverse().map((l) => {
|
|
89
89
|
var m;
|
|
90
90
|
const h = document.createElement("SPAN");
|
|
91
91
|
return (m = l.parentNode) == null || m.insertBefore(h, l), h.appendChild(l), h;
|
|
92
92
|
});
|
|
93
|
-
return { unwrap: u, nodes: [b, ...
|
|
93
|
+
return { unwrap: u, nodes: [b, ...E, v] };
|
|
94
94
|
}
|
|
95
95
|
}, Zt = (t) => {
|
|
96
96
|
const {
|
|
@@ -114,14 +114,14 @@ const Ot = (t) => {
|
|
|
114
114
|
}, te = (t, e, n = 10, o) => {
|
|
115
115
|
const i = o ? t.startContainer.parentElement.closest(o) : e, s = document.createRange();
|
|
116
116
|
s.setStart(i, 0), s.setEnd(t.startContainer, t.startOffset);
|
|
117
|
-
const r =
|
|
117
|
+
const r = ft(s).textContent, a = document.createRange();
|
|
118
118
|
a.setStart(t.endContainer, t.endOffset), i === document.body ? a.setEnd(i, i.childNodes.length) : a.setEndAfter(i);
|
|
119
|
-
const d =
|
|
119
|
+
const d = ft(a).textContent;
|
|
120
120
|
return {
|
|
121
121
|
prefix: r.substring(r.length - n),
|
|
122
122
|
suffix: d.substring(0, n)
|
|
123
123
|
};
|
|
124
|
-
},
|
|
124
|
+
}, D = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), ee = (t, e) => {
|
|
125
125
|
const n = (s) => Math.round(s * 10) / 10, o = {
|
|
126
126
|
top: n(t.top),
|
|
127
127
|
bottom: n(t.bottom),
|
|
@@ -172,7 +172,7 @@ const Ot = (t) => {
|
|
|
172
172
|
}, []), ie = (t, e, n) => {
|
|
173
173
|
const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
|
|
174
174
|
o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
|
|
175
|
-
const s =
|
|
175
|
+
const s = ft(o).textContent, r = t.toString(), a = s.length || 0, d = a + r.length;
|
|
176
176
|
return n ? { quote: r, start: a, end: d, range: t, offsetReference: i } : { quote: r, start: a, end: d, range: t };
|
|
177
177
|
}, _t = (t, e) => {
|
|
178
178
|
var y, c;
|
|
@@ -180,8 +180,8 @@ const Ot = (t) => {
|
|
|
180
180
|
e,
|
|
181
181
|
NodeFilter.SHOW_TEXT,
|
|
182
182
|
(b) => {
|
|
183
|
-
var
|
|
184
|
-
return (
|
|
183
|
+
var p;
|
|
184
|
+
return (p = b.parentElement) != null && p.closest(q) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
|
|
185
185
|
}
|
|
186
186
|
);
|
|
187
187
|
let r = 0;
|
|
@@ -212,10 +212,10 @@ const Ot = (t) => {
|
|
|
212
212
|
...t,
|
|
213
213
|
range: a
|
|
214
214
|
};
|
|
215
|
-
}, J = (t, e) =>
|
|
215
|
+
}, J = (t, e) => D(t.selector) ? t : {
|
|
216
216
|
...t,
|
|
217
217
|
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : _t(n, e))
|
|
218
|
-
},
|
|
218
|
+
}, st = (t, e) => D(t.target.selector) ? t : { ...t, target: J(t.target, e) }, se = (t) => {
|
|
219
219
|
var i;
|
|
220
220
|
const { startContainer: e, endContainer: n } = t;
|
|
221
221
|
if (e.nodeType === Node.TEXT_NODE && n.nodeType === Node.TEXT_NODE)
|
|
@@ -250,63 +250,63 @@ const Ot = (t) => {
|
|
|
250
250
|
t.classList.add("r6o-annotatable");
|
|
251
251
|
const y = re(), c = y.getContext("2d");
|
|
252
252
|
t.insertBefore(y, t.firstChild);
|
|
253
|
-
const b = (
|
|
254
|
-
const { x: A, y: x } = t.getBoundingClientRect(), S = o.getAt(
|
|
253
|
+
const b = (g) => {
|
|
254
|
+
const { x: A, y: x } = t.getBoundingClientRect(), S = o.getAt(g.clientX - A, g.clientY - x);
|
|
255
255
|
S && (!a || a(S)) ? s.current !== S.id && (t.classList.add("hovered"), s.set(S.id)) : s.current && (t.classList.remove("hovered"), s.set(null));
|
|
256
256
|
};
|
|
257
257
|
t.addEventListener("pointermove", b);
|
|
258
|
-
const
|
|
259
|
-
const
|
|
260
|
-
c.clearRect(-0.5, -0.5, zt + 1, Wt + 1), d && d.clear(),
|
|
261
|
-
const tt = qt.has(_.annotation.id),
|
|
258
|
+
const p = () => requestAnimationFrame(() => {
|
|
259
|
+
const g = Ot(t), { top: A, left: x, minX: S, minY: B, maxX: N, maxY: I } = g, mt = a ? o.getIntersectingRects(S, B, N, I).filter(({ annotation: _ }) => a(_)) : o.getIntersectingRects(S, B, N, I), { width: zt, height: Wt } = y, qt = new Set(i.selected.map(({ id: _ }) => _));
|
|
260
|
+
c.clearRect(-0.5, -0.5, zt + 1, Wt + 1), d && d.clear(), mt.forEach((_) => {
|
|
261
|
+
const tt = qt.has(_.annotation.id), bt = r ? typeof r == "function" ? r(_.annotation, tt) : r : tt ? Yt : Z, vt = d && d.paint(_, g, tt) || bt, jt = _.rects.map(({ x: et, y: nt, width: ot, height: it }) => ({
|
|
262
262
|
x: et + x,
|
|
263
263
|
y: nt + A,
|
|
264
264
|
width: ot,
|
|
265
265
|
height: it
|
|
266
266
|
}));
|
|
267
|
-
c.fillStyle =
|
|
268
|
-
}), setTimeout(() => u(
|
|
269
|
-
}), v = (
|
|
270
|
-
r =
|
|
271
|
-
}, C = (
|
|
272
|
-
a =
|
|
273
|
-
},
|
|
274
|
-
o.observe(
|
|
275
|
-
const l = i.subscribe(() =>
|
|
267
|
+
c.fillStyle = vt.fill, c.globalAlpha = vt.fillOpacity || 1, jt.forEach(({ x: et, y: nt, width: ot, height: it }) => c.fillRect(et, nt - 2.5, ot, it + 5));
|
|
268
|
+
}), setTimeout(() => u(mt.map(({ annotation: _ }) => _)), 1);
|
|
269
|
+
}), v = (g) => {
|
|
270
|
+
r = g, p();
|
|
271
|
+
}, C = (g) => {
|
|
272
|
+
a = g, p();
|
|
273
|
+
}, E = () => p();
|
|
274
|
+
o.observe(E);
|
|
275
|
+
const l = i.subscribe(() => p()), h = () => p();
|
|
276
276
|
document.addEventListener("scroll", h, { capture: !0, passive: !0 });
|
|
277
|
-
const m =
|
|
278
|
-
ae(y), o.recalculatePositions(), d && d.reset(),
|
|
277
|
+
const m = gt(() => {
|
|
278
|
+
ae(y), o.recalculatePositions(), d && d.reset(), p();
|
|
279
279
|
});
|
|
280
280
|
window.addEventListener("resize", m);
|
|
281
281
|
const f = new ResizeObserver(m);
|
|
282
282
|
f.observe(t);
|
|
283
|
-
const
|
|
284
|
-
return T.observe(document.body,
|
|
283
|
+
const w = { attributes: !0, childList: !0, subtree: !0 }, T = new MutationObserver(p);
|
|
284
|
+
return T.observe(document.body, w), {
|
|
285
285
|
destroy: () => {
|
|
286
|
-
t.removeEventListener("pointermove", b), t.removeChild(y), o.unobserve(
|
|
286
|
+
t.removeEventListener("pointermove", b), t.removeChild(y), o.unobserve(E), l(), document.removeEventListener("scroll", h), window.removeEventListener("resize", m), f.disconnect(), T.disconnect();
|
|
287
287
|
},
|
|
288
|
-
refresh:
|
|
288
|
+
refresh: p,
|
|
289
289
|
setDrawingStyle: v,
|
|
290
290
|
setFilter: C,
|
|
291
|
-
setPainter: (
|
|
291
|
+
setPainter: (g) => d = g
|
|
292
292
|
};
|
|
293
293
|
};
|
|
294
|
-
var le = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) },
|
|
294
|
+
var le = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, U = function(t) {
|
|
295
295
|
return typeof t == "string" ? t.length > 0 : typeof t == "number";
|
|
296
296
|
}, M = function(t, e, n) {
|
|
297
297
|
return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
|
|
298
298
|
}, X = function(t, e, n) {
|
|
299
299
|
return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
|
|
300
|
-
},
|
|
300
|
+
}, Ut = function(t) {
|
|
301
301
|
return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
|
|
302
302
|
}, xt = function(t) {
|
|
303
303
|
return { r: X(t.r, 0, 255), g: X(t.g, 0, 255), b: X(t.b, 0, 255), a: X(t.a) };
|
|
304
|
-
},
|
|
304
|
+
}, rt = function(t) {
|
|
305
305
|
return { r: M(t.r), g: M(t.g), b: M(t.b), a: M(t.a, 3) };
|
|
306
306
|
}, de = /^#([0-9a-f]{3,8})$/i, j = function(t) {
|
|
307
307
|
var e = t.toString(16);
|
|
308
308
|
return e.length < 2 ? "0" + e : e;
|
|
309
|
-
},
|
|
309
|
+
}, Dt = function(t) {
|
|
310
310
|
var e = t.r, n = t.g, o = t.b, i = t.a, s = Math.max(e, n, o), r = s - Math.min(e, n, o), a = r ? s === e ? (n - o) / r : s === n ? 2 + (o - e) / r : 4 + (e - n) / r : 0;
|
|
311
311
|
return { h: 60 * (a < 0 ? a + 6 : a), s: s ? r / s * 100 : 0, v: s / 255 * 100, a: i };
|
|
312
312
|
}, Vt = function(t) {
|
|
@@ -315,14 +315,14 @@ var le = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, D = function(t) {
|
|
|
315
315
|
var s = Math.floor(e), r = o * (1 - n), a = o * (1 - (e - s) * n), d = o * (1 - (1 - e + s) * n), u = s % 6;
|
|
316
316
|
return { r: 255 * [o, a, r, r, d, o][u], g: 255 * [d, o, o, a, r, r][u], b: 255 * [r, r, d, o, o, a][u], a: i };
|
|
317
317
|
}, At = function(t) {
|
|
318
|
-
return { h:
|
|
318
|
+
return { h: Ut(t.h), s: X(t.s, 0, 100), l: X(t.l, 0, 100), a: X(t.a) };
|
|
319
319
|
}, Et = function(t) {
|
|
320
320
|
return { h: M(t.h), s: M(t.s), l: M(t.l), a: M(t.a, 3) };
|
|
321
321
|
}, St = function(t) {
|
|
322
322
|
return Vt((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 }));
|
|
323
323
|
var e, n, o;
|
|
324
324
|
}, W = function(t) {
|
|
325
|
-
return { h: (e =
|
|
325
|
+
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 };
|
|
326
326
|
var e, n, o, i;
|
|
327
327
|
}, ue = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, he = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, fe = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ge = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ct = { string: [[function(t) {
|
|
328
328
|
var e = de.exec(t);
|
|
@@ -338,19 +338,19 @@ var le = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, D = function(t) {
|
|
|
338
338
|
return St(i);
|
|
339
339
|
}, "hsl"]], object: [[function(t) {
|
|
340
340
|
var e = t.r, n = t.g, o = t.b, i = t.a, s = i === void 0 ? 1 : i;
|
|
341
|
-
return
|
|
341
|
+
return U(e) && U(n) && U(o) ? xt({ r: Number(e), g: Number(n), b: Number(o), a: Number(s) }) : null;
|
|
342
342
|
}, "rgb"], [function(t) {
|
|
343
343
|
var e = t.h, n = t.s, o = t.l, i = t.a, s = i === void 0 ? 1 : i;
|
|
344
|
-
if (!
|
|
344
|
+
if (!U(e) || !U(n) || !U(o))
|
|
345
345
|
return null;
|
|
346
346
|
var r = At({ h: Number(e), s: Number(n), l: Number(o), a: Number(s) });
|
|
347
347
|
return St(r);
|
|
348
348
|
}, "hsl"], [function(t) {
|
|
349
349
|
var e = t.h, n = t.s, o = t.v, i = t.a, s = i === void 0 ? 1 : i;
|
|
350
|
-
if (!
|
|
350
|
+
if (!U(e) || !U(n) || !U(o))
|
|
351
351
|
return null;
|
|
352
352
|
var r = function(a) {
|
|
353
|
-
return { h:
|
|
353
|
+
return { h: Ut(a.h), s: X(a.s, 0, 100), v: X(a.v, 0, 100), a: X(a.a) };
|
|
354
354
|
}({ h: Number(e), s: Number(n), v: Number(o), a: Number(s) });
|
|
355
355
|
return Vt(r);
|
|
356
356
|
}, "hsv"]] }, Tt = function(t, e) {
|
|
@@ -362,10 +362,10 @@ var le = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, D = function(t) {
|
|
|
362
362
|
return [null, void 0];
|
|
363
363
|
}, pe = function(t) {
|
|
364
364
|
return typeof t == "string" ? Tt(t.trim(), Ct.string) : typeof t == "object" && t !== null ? Tt(t, Ct.object) : [null, void 0];
|
|
365
|
-
},
|
|
365
|
+
}, at = function(t, e) {
|
|
366
366
|
var n = W(t);
|
|
367
367
|
return { h: n.h, s: X(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
|
|
368
|
-
},
|
|
368
|
+
}, ct = function(t) {
|
|
369
369
|
return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
|
|
370
370
|
}, Rt = function(t, e) {
|
|
371
371
|
var n = W(t);
|
|
@@ -377,18 +377,18 @@ var le = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, D = function(t) {
|
|
|
377
377
|
return t.prototype.isValid = function() {
|
|
378
378
|
return this.parsed !== null;
|
|
379
379
|
}, t.prototype.brightness = function() {
|
|
380
|
-
return M(
|
|
380
|
+
return M(ct(this.rgba), 2);
|
|
381
381
|
}, t.prototype.isDark = function() {
|
|
382
|
-
return
|
|
382
|
+
return ct(this.rgba) < 0.5;
|
|
383
383
|
}, t.prototype.isLight = function() {
|
|
384
|
-
return
|
|
384
|
+
return ct(this.rgba) >= 0.5;
|
|
385
385
|
}, t.prototype.toHex = function() {
|
|
386
|
-
return e =
|
|
386
|
+
return e = rt(this.rgba), n = e.r, o = e.g, i = e.b, r = (s = e.a) < 1 ? j(M(255 * s)) : "", "#" + j(n) + j(o) + j(i) + r;
|
|
387
387
|
var e, n, o, i, s, r;
|
|
388
388
|
}, t.prototype.toRgb = function() {
|
|
389
|
-
return
|
|
389
|
+
return rt(this.rgba);
|
|
390
390
|
}, t.prototype.toRgbString = function() {
|
|
391
|
-
return e =
|
|
391
|
+
return e = rt(this.rgba), n = e.r, o = e.g, i = e.b, (s = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + s + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
|
|
392
392
|
var e, n, o, i, s;
|
|
393
393
|
}, t.prototype.toHsl = function() {
|
|
394
394
|
return Et(W(this.rgba));
|
|
@@ -396,17 +396,17 @@ var le = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, D = function(t) {
|
|
|
396
396
|
return e = Et(W(this.rgba)), n = e.h, o = e.s, i = e.l, (s = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + s + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
|
|
397
397
|
var e, n, o, i, s;
|
|
398
398
|
}, t.prototype.toHsv = function() {
|
|
399
|
-
return e =
|
|
399
|
+
return e = Dt(this.rgba), { h: M(e.h), s: M(e.s), v: M(e.v), a: M(e.a, 3) };
|
|
400
400
|
var e;
|
|
401
401
|
}, t.prototype.invert = function() {
|
|
402
402
|
return Y({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
|
|
403
403
|
var e;
|
|
404
404
|
}, t.prototype.saturate = function(e) {
|
|
405
|
-
return e === void 0 && (e = 0.1), Y(
|
|
405
|
+
return e === void 0 && (e = 0.1), Y(at(this.rgba, e));
|
|
406
406
|
}, t.prototype.desaturate = function(e) {
|
|
407
|
-
return e === void 0 && (e = 0.1), Y(
|
|
407
|
+
return e === void 0 && (e = 0.1), Y(at(this.rgba, -e));
|
|
408
408
|
}, t.prototype.grayscale = function() {
|
|
409
|
-
return Y(
|
|
409
|
+
return Y(at(this.rgba, -1));
|
|
410
410
|
}, t.prototype.lighten = function(e) {
|
|
411
411
|
return e === void 0 && (e = 0.1), Y(Rt(this.rgba, e));
|
|
412
412
|
}, t.prototype.darken = function(e) {
|
|
@@ -435,14 +435,14 @@ const me = (t) => `background-color: ${Y(t.fill || Z.fill).alpha(t.fillOpacity |
|
|
|
435
435
|
},
|
|
436
436
|
refresh: (r, a, d, u) => {
|
|
437
437
|
e && e.clear();
|
|
438
|
-
const y = new Set(r.map((v) => v.annotation.id)), c = new Set(d), b = Array.from(n).filter((v) => !y.has(v)),
|
|
439
|
-
const C = c.has(v.annotation.id),
|
|
438
|
+
const y = new Set(r.map((v) => v.annotation.id)), c = new Set(d), b = Array.from(n).filter((v) => !y.has(v)), p = r.map((v) => {
|
|
439
|
+
const C = c.has(v.annotation.id), E = u ? typeof u == "function" ? u(v.annotation, C) : u : C ? Yt : Z, l = e && e.paint(v, a, C) || E;
|
|
440
440
|
return `::highlight(_${v.annotation.id}) { ${me(l)} }`;
|
|
441
441
|
});
|
|
442
|
-
t.innerHTML =
|
|
442
|
+
t.innerHTML = p.join(`
|
|
443
443
|
`), b.forEach((v) => CSS.highlights.delete(`_${v}`)), r.forEach(({ annotation: v }) => {
|
|
444
|
-
const C = v.target.selector.map((l) => l.range),
|
|
445
|
-
CSS.highlights.set(`_${v.id}`,
|
|
444
|
+
const C = v.target.selector.map((l) => l.range), E = new Highlight(...C);
|
|
445
|
+
CSS.highlights.set(`_${v.id}`, E);
|
|
446
446
|
}), n = y;
|
|
447
447
|
},
|
|
448
448
|
setPainter: (r) => e = r
|
|
@@ -451,38 +451,38 @@ const me = (t) => `background-color: ${Y(t.fill || Z.fill).alpha(t.fillOpacity |
|
|
|
451
451
|
const { store: o, selection: i, hover: s } = e;
|
|
452
452
|
let r, a, d;
|
|
453
453
|
const u = be(), y = It(n), c = (R) => {
|
|
454
|
-
const { x:
|
|
454
|
+
const { x: g, y: A } = t.getBoundingClientRect(), x = o.getAt(R.clientX - g, R.clientY - A);
|
|
455
455
|
x && (!d || d(x)) ? s.current !== x.id && (t.classList.add("hovered"), s.set(x.id)) : s.current && (t.classList.remove("hovered"), s.set(null));
|
|
456
456
|
};
|
|
457
457
|
t.addEventListener("pointermove", c);
|
|
458
458
|
const b = () => {
|
|
459
|
-
const R = Ot(t), { minX:
|
|
459
|
+
const R = Ot(t), { minX: g, minY: A, maxX: x, maxY: S } = R, B = d ? o.getIntersectingRects(g, A, x, S).filter(({ annotation: I }) => d(I)) : o.getIntersectingRects(g, A, x, S), N = i.selected.map(({ id: I }) => I);
|
|
460
460
|
u.refresh(B, R, N, a), setTimeout(() => y(B.map(({ annotation: I }) => I)), 1);
|
|
461
|
-
},
|
|
461
|
+
}, p = (R) => {
|
|
462
462
|
r = R, u.setPainter(R);
|
|
463
463
|
}, v = (R) => {
|
|
464
464
|
a = R, b();
|
|
465
465
|
}, C = (R) => {
|
|
466
466
|
d = R, b();
|
|
467
|
-
},
|
|
468
|
-
o.observe(
|
|
467
|
+
}, E = () => b();
|
|
468
|
+
o.observe(E);
|
|
469
469
|
const l = i.subscribe(() => b());
|
|
470
470
|
document.addEventListener("scroll", b, { capture: !0, passive: !0 });
|
|
471
|
-
const h =
|
|
471
|
+
const h = gt(() => {
|
|
472
472
|
o.recalculatePositions(), r && r.reset(), b();
|
|
473
473
|
});
|
|
474
474
|
window.addEventListener("resize", h);
|
|
475
475
|
const m = new ResizeObserver(h);
|
|
476
476
|
m.observe(t);
|
|
477
|
-
const f = { attributes: !0, childList: !0, subtree: !0 },
|
|
478
|
-
return
|
|
477
|
+
const f = { attributes: !0, childList: !0, subtree: !0 }, w = new MutationObserver(b);
|
|
478
|
+
return w.observe(document.body, f), {
|
|
479
479
|
destroy: () => {
|
|
480
|
-
t.removeEventListener("pointermove", c), u.destroy(), o.unobserve(
|
|
480
|
+
t.removeEventListener("pointermove", c), u.destroy(), o.unobserve(E), l(), document.removeEventListener("scroll", b), window.removeEventListener("resize", h), m.disconnect(), w.disconnect();
|
|
481
481
|
},
|
|
482
482
|
refresh: b,
|
|
483
483
|
setDrawingStyle: v,
|
|
484
484
|
setFilter: C,
|
|
485
|
-
setPainter:
|
|
485
|
+
setPainter: p
|
|
486
486
|
};
|
|
487
487
|
};
|
|
488
488
|
let K;
|
|
@@ -540,13 +540,13 @@ function V(t, e) {
|
|
|
540
540
|
}
|
|
541
541
|
return t !== t && e !== e;
|
|
542
542
|
}
|
|
543
|
-
function
|
|
543
|
+
function lt() {
|
|
544
544
|
}
|
|
545
545
|
function Ee(t, e) {
|
|
546
546
|
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
|
|
547
547
|
}
|
|
548
548
|
const k = [];
|
|
549
|
-
function
|
|
549
|
+
function pt(t, e = lt) {
|
|
550
550
|
let n;
|
|
551
551
|
const o = /* @__PURE__ */ new Set();
|
|
552
552
|
function i(a) {
|
|
@@ -564,16 +564,16 @@ function gt(t, e = ct) {
|
|
|
564
564
|
function s(a) {
|
|
565
565
|
i(a(t));
|
|
566
566
|
}
|
|
567
|
-
function r(a, d =
|
|
567
|
+
function r(a, d = lt) {
|
|
568
568
|
const u = [a, d];
|
|
569
|
-
return o.add(u), o.size === 1 && (n = e(i, s) ||
|
|
569
|
+
return o.add(u), o.size === 1 && (n = e(i, s) || lt), a(t), () => {
|
|
570
570
|
o.delete(u), o.size === 0 && n && (n(), n = null);
|
|
571
571
|
};
|
|
572
572
|
}
|
|
573
573
|
return { set: i, update: s, subscribe: r };
|
|
574
574
|
}
|
|
575
575
|
const Se = (t) => {
|
|
576
|
-
const { subscribe: e, set: n } =
|
|
576
|
+
const { subscribe: e, set: n } = pt();
|
|
577
577
|
let o;
|
|
578
578
|
return e((i) => o = i), t.observe(({ changes: i }) => {
|
|
579
579
|
if (o) {
|
|
@@ -588,33 +588,33 @@ const Se = (t) => {
|
|
|
588
588
|
subscribe: e,
|
|
589
589
|
set: n
|
|
590
590
|
};
|
|
591
|
-
},
|
|
592
|
-
const { subscribe: n, set: o } =
|
|
593
|
-
let i =
|
|
591
|
+
}, dt = { selected: [] }, Ce = (t, e = "EDIT") => {
|
|
592
|
+
const { subscribe: n, set: o } = pt(dt);
|
|
593
|
+
let i = dt;
|
|
594
594
|
n((c) => i = c);
|
|
595
|
-
const s = () => o(
|
|
595
|
+
const s = () => o(dt), r = () => {
|
|
596
596
|
var c;
|
|
597
597
|
return ((c = i.selected) == null ? void 0 : c.length) === 0;
|
|
598
598
|
}, a = (c) => {
|
|
599
599
|
if (i.selected.length === 0)
|
|
600
600
|
return !1;
|
|
601
601
|
const b = typeof c == "string" ? c : c.id;
|
|
602
|
-
return i.selected.some((
|
|
602
|
+
return i.selected.some((p) => p.id === b);
|
|
603
603
|
}, d = (c, b) => {
|
|
604
|
-
const
|
|
605
|
-
if (
|
|
606
|
-
const v = Te(
|
|
604
|
+
const p = t.getAnnotation(c);
|
|
605
|
+
if (p) {
|
|
606
|
+
const v = Te(p, e);
|
|
607
607
|
o(v === "EDIT" ? { selected: [{ id: c, editable: !0 }], pointerEvent: b } : v === "SELECT" ? { selected: [{ id: c }], pointerEvent: b } : { selected: [], pointerEvent: b });
|
|
608
608
|
} else
|
|
609
609
|
console.warn("Invalid selection: " + c);
|
|
610
610
|
}, u = (c, b = !0) => {
|
|
611
|
-
const
|
|
612
|
-
o({ selected: v.map(({ id: C }) => ({ id: C, editable: b })) }), v.length !==
|
|
611
|
+
const p = Array.isArray(c) ? c : [c], v = p.map((C) => t.getAnnotation(C)).filter(Boolean);
|
|
612
|
+
o({ selected: v.map(({ id: C }) => ({ id: C, editable: b })) }), v.length !== p.length && console.warn("Invalid selection", c);
|
|
613
613
|
}, y = (c) => {
|
|
614
614
|
if (i.selected.length === 0)
|
|
615
615
|
return !1;
|
|
616
616
|
const { selected: b } = i;
|
|
617
|
-
b.filter(({ id:
|
|
617
|
+
b.filter(({ id: p }) => c.includes(p)).length > 0 && o({ selected: b.filter(({ id: p }) => !c.includes(p)) });
|
|
618
618
|
};
|
|
619
619
|
return t.observe(({ changes: c }) => y((c.deleted || []).map((b) => b.id))), {
|
|
620
620
|
clear: s,
|
|
@@ -686,9 +686,9 @@ const Oe = (t, e) => {
|
|
|
686
686
|
...(e.deleted || []).filter((c) => !n.has(c.id))
|
|
687
687
|
], y = [
|
|
688
688
|
...(t.updated || []).filter(({ newValue: c }) => !s.has(c.id)).map((c) => {
|
|
689
|
-
const { oldValue: b, newValue:
|
|
690
|
-
if (r.has(
|
|
691
|
-
const v = e.updated.find((C) => C.oldValue.id ===
|
|
689
|
+
const { oldValue: b, newValue: p } = c;
|
|
690
|
+
if (r.has(p.id)) {
|
|
691
|
+
const v = e.updated.find((C) => C.oldValue.id === p.id).newValue;
|
|
692
692
|
return Pt(b, v);
|
|
693
693
|
} else
|
|
694
694
|
return c;
|
|
@@ -697,12 +697,12 @@ const Oe = (t, e) => {
|
|
|
697
697
|
];
|
|
698
698
|
return { created: d, deleted: u, updated: y };
|
|
699
699
|
}, Xe = (t) => t.id !== void 0, _e = () => {
|
|
700
|
-
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (
|
|
701
|
-
const A = n.findIndex((x) => x.onChange ==
|
|
700
|
+
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (g, A = {}) => n.push({ onChange: g, options: A }), i = (g) => {
|
|
701
|
+
const A = n.findIndex((x) => x.onChange == g);
|
|
702
702
|
A > -1 && n.splice(A, 1);
|
|
703
|
-
}, s = (
|
|
703
|
+
}, s = (g, A) => {
|
|
704
704
|
const x = {
|
|
705
|
-
origin:
|
|
705
|
+
origin: g,
|
|
706
706
|
changes: {
|
|
707
707
|
created: A.created || [],
|
|
708
708
|
updated: A.updated || [],
|
|
@@ -713,83 +713,83 @@ const Oe = (t, e) => {
|
|
|
713
713
|
n.forEach((S) => {
|
|
714
714
|
Oe(S, x) && S.onChange(x);
|
|
715
715
|
});
|
|
716
|
-
}, r = (
|
|
717
|
-
if (t.get(
|
|
718
|
-
throw Error(`Cannot add annotation ${
|
|
719
|
-
t.set(
|
|
720
|
-
}, a = (
|
|
721
|
-
const x = typeof
|
|
716
|
+
}, r = (g, A = L.LOCAL) => {
|
|
717
|
+
if (t.get(g.id))
|
|
718
|
+
throw Error(`Cannot add annotation ${g.id} - exists already`);
|
|
719
|
+
t.set(g.id, g), g.bodies.forEach((x) => e.set(x.id, g.id)), s(A, { created: [g] });
|
|
720
|
+
}, a = (g, A) => {
|
|
721
|
+
const x = typeof g == "string" ? A : g, S = typeof g == "string" ? g : g.id, B = t.get(S);
|
|
722
722
|
if (B) {
|
|
723
723
|
const N = Pt(B, x);
|
|
724
724
|
return S === x.id ? t.set(S, x) : (t.delete(S), t.set(x.id, x)), B.bodies.forEach((I) => e.delete(I.id)), x.bodies.forEach((I) => e.set(I.id, x.id)), N;
|
|
725
725
|
} else
|
|
726
726
|
console.warn(`Cannot update annotation ${S} - does not exist`);
|
|
727
|
-
}, d = (
|
|
728
|
-
const S = Xe(A) ? x : A, B = a(
|
|
727
|
+
}, d = (g, A = L.LOCAL, x = L.LOCAL) => {
|
|
728
|
+
const S = Xe(A) ? x : A, B = a(g, A);
|
|
729
729
|
B && s(S, { updated: [B] });
|
|
730
|
-
}, u = (
|
|
731
|
-
const x =
|
|
730
|
+
}, u = (g, A = L.LOCAL) => {
|
|
731
|
+
const x = g.reduce((S, B) => {
|
|
732
732
|
const N = a(B);
|
|
733
733
|
return N ? [...S, N] : S;
|
|
734
734
|
}, []);
|
|
735
735
|
x.length > 0 && s(A, { updated: x });
|
|
736
|
-
}, y = (
|
|
737
|
-
const x = t.get(
|
|
736
|
+
}, y = (g, A = L.LOCAL) => {
|
|
737
|
+
const x = t.get(g.annotation);
|
|
738
738
|
if (x) {
|
|
739
739
|
const S = {
|
|
740
740
|
...x,
|
|
741
|
-
bodies: [...x.bodies,
|
|
741
|
+
bodies: [...x.bodies, g]
|
|
742
742
|
};
|
|
743
|
-
t.set(x.id, S), e.set(
|
|
743
|
+
t.set(x.id, S), e.set(g.id, S.id), s(A, { updated: [{
|
|
744
744
|
oldValue: x,
|
|
745
745
|
newValue: S,
|
|
746
|
-
bodiesCreated: [
|
|
746
|
+
bodiesCreated: [g]
|
|
747
747
|
}] });
|
|
748
748
|
} else
|
|
749
|
-
console.warn(`Attempt to add body to missing annotation: ${
|
|
750
|
-
}, c = () => [...t.values()], b = (
|
|
749
|
+
console.warn(`Attempt to add body to missing annotation: ${g.annotation}`);
|
|
750
|
+
}, c = () => [...t.values()], b = (g = L.LOCAL) => {
|
|
751
751
|
const A = [...t.values()];
|
|
752
|
-
t.clear(), e.clear(), s(
|
|
753
|
-
},
|
|
752
|
+
t.clear(), e.clear(), s(g, { deleted: A });
|
|
753
|
+
}, p = (g, A = !0, x = L.LOCAL) => {
|
|
754
754
|
if (A) {
|
|
755
755
|
const S = [...t.values()];
|
|
756
|
-
t.clear(), e.clear(),
|
|
756
|
+
t.clear(), e.clear(), g.forEach((B) => {
|
|
757
757
|
t.set(B.id, B), B.bodies.forEach((N) => e.set(N.id, B.id));
|
|
758
|
-
}), s(x, { created:
|
|
758
|
+
}), s(x, { created: g, deleted: S });
|
|
759
759
|
} else {
|
|
760
|
-
const S =
|
|
760
|
+
const S = g.reduce((B, N) => {
|
|
761
761
|
const I = t.get(N.id);
|
|
762
762
|
return I ? [...B, I] : B;
|
|
763
763
|
}, []);
|
|
764
764
|
if (S.length > 0)
|
|
765
765
|
throw Error(`Bulk insert would overwrite the following annotations: ${S.map((B) => B.id).join(", ")}`);
|
|
766
|
-
|
|
766
|
+
g.forEach((B) => {
|
|
767
767
|
t.set(B.id, B), B.bodies.forEach((N) => e.set(N.id, B.id));
|
|
768
|
-
}), s(x, { created:
|
|
768
|
+
}), s(x, { created: g });
|
|
769
769
|
}
|
|
770
|
-
}, v = (
|
|
771
|
-
const A = typeof
|
|
770
|
+
}, v = (g) => {
|
|
771
|
+
const A = typeof g == "string" ? g : g.id, x = t.get(A);
|
|
772
772
|
if (x)
|
|
773
773
|
return t.delete(A), x.bodies.forEach((S) => e.delete(S.id)), x;
|
|
774
774
|
console.warn(`Attempt to delete missing annotation: ${A}`);
|
|
775
|
-
}, C = (
|
|
776
|
-
const x = v(
|
|
775
|
+
}, C = (g, A = L.LOCAL) => {
|
|
776
|
+
const x = v(g);
|
|
777
777
|
x && s(A, { deleted: [x] });
|
|
778
|
-
},
|
|
779
|
-
const x =
|
|
778
|
+
}, E = (g, A = L.LOCAL) => {
|
|
779
|
+
const x = g.reduce((S, B) => {
|
|
780
780
|
const N = v(B);
|
|
781
781
|
return N ? [...S, N] : S;
|
|
782
782
|
}, []);
|
|
783
783
|
x.length > 0 && s(A, { deleted: x });
|
|
784
|
-
}, l = (
|
|
785
|
-
const x = t.get(
|
|
784
|
+
}, l = (g, A = L.LOCAL) => {
|
|
785
|
+
const x = t.get(g.annotation);
|
|
786
786
|
if (x) {
|
|
787
|
-
const S = x.bodies.find((B) => B.id ===
|
|
787
|
+
const S = x.bodies.find((B) => B.id === g.id);
|
|
788
788
|
if (S) {
|
|
789
789
|
e.delete(S.id);
|
|
790
790
|
const B = {
|
|
791
791
|
...x,
|
|
792
|
-
bodies: x.bodies.filter((N) => N.id !==
|
|
792
|
+
bodies: x.bodies.filter((N) => N.id !== g.id)
|
|
793
793
|
};
|
|
794
794
|
t.set(x.id, B), s(A, { updated: [{
|
|
795
795
|
oldValue: x,
|
|
@@ -797,27 +797,27 @@ const Oe = (t, e) => {
|
|
|
797
797
|
bodiesDeleted: [S]
|
|
798
798
|
}] });
|
|
799
799
|
} else
|
|
800
|
-
console.warn(`Attempt to delete missing body ${
|
|
800
|
+
console.warn(`Attempt to delete missing body ${g.id} from annotation ${g.annotation}`);
|
|
801
801
|
} else
|
|
802
|
-
console.warn(`Attempt to delete body from missing annotation ${
|
|
803
|
-
}, h = (
|
|
804
|
-
const A = t.get(
|
|
802
|
+
console.warn(`Attempt to delete body from missing annotation ${g.annotation}`);
|
|
803
|
+
}, h = (g) => {
|
|
804
|
+
const A = t.get(g);
|
|
805
805
|
return A ? { ...A } : void 0;
|
|
806
|
-
}, m = (
|
|
807
|
-
const A = e.get(
|
|
806
|
+
}, m = (g) => {
|
|
807
|
+
const A = e.get(g);
|
|
808
808
|
if (A) {
|
|
809
|
-
const x = h(A).bodies.find((S) => S.id ===
|
|
809
|
+
const x = h(A).bodies.find((S) => S.id === g);
|
|
810
810
|
if (x)
|
|
811
811
|
return x;
|
|
812
|
-
console.error(`Store integrity error: body ${
|
|
812
|
+
console.error(`Store integrity error: body ${g} in index, but not in annotation`);
|
|
813
813
|
} else
|
|
814
|
-
console.warn(`Attempt to retrieve missing body: ${
|
|
815
|
-
}, f = (
|
|
816
|
-
if (
|
|
814
|
+
console.warn(`Attempt to retrieve missing body: ${g}`);
|
|
815
|
+
}, f = (g, A) => {
|
|
816
|
+
if (g.annotation !== A.annotation)
|
|
817
817
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
818
|
-
const x = t.get(
|
|
818
|
+
const x = t.get(g.annotation);
|
|
819
819
|
if (x) {
|
|
820
|
-
const S = x.bodies.find((N) => N.id ===
|
|
820
|
+
const S = x.bodies.find((N) => N.id === g.id), B = {
|
|
821
821
|
...x,
|
|
822
822
|
bodies: x.bodies.map((N) => N.id === S.id ? A : N)
|
|
823
823
|
};
|
|
@@ -827,21 +827,21 @@ const Oe = (t, e) => {
|
|
|
827
827
|
bodiesUpdated: [{ oldBody: S, newBody: A }]
|
|
828
828
|
};
|
|
829
829
|
} else
|
|
830
|
-
console.warn(`Attempt to add body to missing annotation ${
|
|
831
|
-
},
|
|
832
|
-
const S = f(
|
|
830
|
+
console.warn(`Attempt to add body to missing annotation ${g.annotation}`);
|
|
831
|
+
}, w = (g, A, x = L.LOCAL) => {
|
|
832
|
+
const S = f(g, A);
|
|
833
833
|
S && s(x, { updated: [S] });
|
|
834
|
-
}, T = (
|
|
835
|
-
const x =
|
|
834
|
+
}, T = (g, A = L.LOCAL) => {
|
|
835
|
+
const x = g.map((S) => f({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
|
|
836
836
|
s(A, { updated: x });
|
|
837
|
-
}, R = (
|
|
838
|
-
const A = t.get(
|
|
837
|
+
}, R = (g) => {
|
|
838
|
+
const A = t.get(g.annotation);
|
|
839
839
|
if (A) {
|
|
840
840
|
const x = {
|
|
841
841
|
...A,
|
|
842
842
|
target: {
|
|
843
843
|
...A.target,
|
|
844
|
-
...
|
|
844
|
+
...g
|
|
845
845
|
}
|
|
846
846
|
};
|
|
847
847
|
return t.set(A.id, x), {
|
|
@@ -849,22 +849,22 @@ const Oe = (t, e) => {
|
|
|
849
849
|
newValue: x,
|
|
850
850
|
targetUpdated: {
|
|
851
851
|
oldTarget: A.target,
|
|
852
|
-
newTarget:
|
|
852
|
+
newTarget: g
|
|
853
853
|
}
|
|
854
854
|
};
|
|
855
855
|
} else
|
|
856
|
-
console.warn(`Attempt to update target on missing annotation: ${
|
|
856
|
+
console.warn(`Attempt to update target on missing annotation: ${g.annotation}`);
|
|
857
857
|
};
|
|
858
858
|
return {
|
|
859
859
|
addAnnotation: r,
|
|
860
860
|
addBody: y,
|
|
861
861
|
all: c,
|
|
862
|
-
bulkAddAnnotation:
|
|
863
|
-
bulkDeleteAnnotation:
|
|
862
|
+
bulkAddAnnotation: p,
|
|
863
|
+
bulkDeleteAnnotation: E,
|
|
864
864
|
bulkUpdateAnnotation: u,
|
|
865
865
|
bulkUpdateBodies: T,
|
|
866
|
-
bulkUpdateTargets: (
|
|
867
|
-
const x =
|
|
866
|
+
bulkUpdateTargets: (g, A = L.LOCAL) => {
|
|
867
|
+
const x = g.map((S) => R(S)).filter(Boolean);
|
|
868
868
|
x.length > 0 && s(A, { updated: x });
|
|
869
869
|
},
|
|
870
870
|
clear: b,
|
|
@@ -875,9 +875,9 @@ const Oe = (t, e) => {
|
|
|
875
875
|
observe: o,
|
|
876
876
|
unobserve: i,
|
|
877
877
|
updateAnnotation: d,
|
|
878
|
-
updateBody:
|
|
879
|
-
updateTarget: (
|
|
880
|
-
const x = R(
|
|
878
|
+
updateBody: w,
|
|
879
|
+
updateTarget: (g, A = L.LOCAL) => {
|
|
880
|
+
const x = R(g);
|
|
881
881
|
x && s(A, { updated: [x] });
|
|
882
882
|
}
|
|
883
883
|
};
|
|
@@ -896,46 +896,46 @@ let Ye = () => ({
|
|
|
896
896
|
};
|
|
897
897
|
}
|
|
898
898
|
});
|
|
899
|
-
const
|
|
899
|
+
const Ue = 250, De = (t) => {
|
|
900
900
|
const e = Ye(), n = [];
|
|
901
901
|
let o = -1, i = !1, s = 0;
|
|
902
|
-
const r = (
|
|
902
|
+
const r = (p) => {
|
|
903
903
|
if (!i) {
|
|
904
|
-
const { changes: v } =
|
|
905
|
-
if (C - s >
|
|
904
|
+
const { changes: v } = p, C = performance.now();
|
|
905
|
+
if (C - s > Ue)
|
|
906
906
|
n.splice(o + 1), n.push(v), o = n.length - 1;
|
|
907
907
|
else {
|
|
908
|
-
const
|
|
909
|
-
n[
|
|
908
|
+
const E = n.length - 1;
|
|
909
|
+
n[E] = Ie(n[E], v);
|
|
910
910
|
}
|
|
911
911
|
s = C;
|
|
912
912
|
}
|
|
913
913
|
i = !1;
|
|
914
914
|
};
|
|
915
915
|
t.observe(r, { origin: L.LOCAL });
|
|
916
|
-
const a = (
|
|
916
|
+
const a = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), d = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), u = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue: v }) => v)), y = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: v }) => v)), c = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), b = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p);
|
|
917
917
|
return {
|
|
918
918
|
canRedo: () => n.length - 1 > o,
|
|
919
919
|
canUndo: () => o > -1,
|
|
920
920
|
destroy: () => t.unobserve(r),
|
|
921
|
-
on: (
|
|
921
|
+
on: (p, v) => e.on(p, v),
|
|
922
922
|
redo: () => {
|
|
923
923
|
if (n.length - 1 > o) {
|
|
924
924
|
i = !0;
|
|
925
|
-
const { created:
|
|
926
|
-
d(
|
|
925
|
+
const { created: p, updated: v, deleted: C } = n[o + 1];
|
|
926
|
+
d(p), y(v), b(C), e.emit("redo", n[o + 1]), o += 1;
|
|
927
927
|
}
|
|
928
928
|
},
|
|
929
929
|
undo: () => {
|
|
930
930
|
if (o > -1) {
|
|
931
931
|
i = !0;
|
|
932
|
-
const { created:
|
|
933
|
-
a(
|
|
932
|
+
const { created: p, updated: v, deleted: C } = n[o];
|
|
933
|
+
a(p), u(v), c(C), e.emit("undo", n[o]), o -= 1;
|
|
934
934
|
}
|
|
935
935
|
}
|
|
936
936
|
};
|
|
937
937
|
}, Ve = () => {
|
|
938
|
-
const { subscribe: t, set: e } =
|
|
938
|
+
const { subscribe: t, set: e } = pt([]);
|
|
939
939
|
return {
|
|
940
940
|
subscribe: t,
|
|
941
941
|
set: e
|
|
@@ -945,15 +945,15 @@ const De = 250, Ue = (t) => {
|
|
|
945
945
|
let u = [], y, c;
|
|
946
946
|
const b = (l, h) => {
|
|
947
947
|
d.has(l) ? d.get(l).push(h) : d.set(l, [h]);
|
|
948
|
-
},
|
|
948
|
+
}, p = (l, h) => {
|
|
949
949
|
const m = d.get(l);
|
|
950
950
|
m && m.indexOf(h) > 0 && m.splice(m.indexOf(h), 1);
|
|
951
951
|
}, v = (l, h, m) => {
|
|
952
952
|
d.has(l) && setTimeout(() => {
|
|
953
953
|
d.get(l).forEach((f) => {
|
|
954
954
|
if (n) {
|
|
955
|
-
const
|
|
956
|
-
f(
|
|
955
|
+
const w = Array.isArray(h) ? h.map((R) => n.serialize(R)) : n.serialize(h), T = m ? m instanceof PointerEvent ? m : n.serialize(m) : void 0;
|
|
956
|
+
f(w, T);
|
|
957
957
|
} else
|
|
958
958
|
f(h, m);
|
|
959
959
|
});
|
|
@@ -961,9 +961,9 @@ const De = 250, Ue = (t) => {
|
|
|
961
961
|
}, C = () => {
|
|
962
962
|
const { selected: l } = s, h = (l || []).map(({ id: m }) => i.getAnnotation(m));
|
|
963
963
|
h.forEach((m) => {
|
|
964
|
-
const f = u.find((
|
|
964
|
+
const f = u.find((w) => w.id === m.id);
|
|
965
965
|
(!f || !V(f, m)) && v("updateAnnotation", m, f);
|
|
966
|
-
}), u = u.map((m) => h.find(({ id:
|
|
966
|
+
}), u = u.map((m) => h.find(({ id: w }) => w === m.id) || m);
|
|
967
967
|
};
|
|
968
968
|
s.subscribe(({ selected: l }) => {
|
|
969
969
|
if (!(u.length === 0 && l.length === 0)) {
|
|
@@ -977,8 +977,8 @@ const De = 250, Ue = (t) => {
|
|
|
977
977
|
else {
|
|
978
978
|
const h = new Set(u.map((f) => f.id)), m = new Set(l.map(({ id: f }) => f));
|
|
979
979
|
u.filter((f) => !m.has(f.id)).forEach((f) => {
|
|
980
|
-
const
|
|
981
|
-
|
|
980
|
+
const w = i.getAnnotation(f.id);
|
|
981
|
+
w && !V(w, f) && v("updateAnnotation", w, f);
|
|
982
982
|
}), u = [
|
|
983
983
|
// Remove annotations that were deselected
|
|
984
984
|
...u.filter((f) => m.has(f.id)),
|
|
@@ -997,9 +997,9 @@ const De = 250, Ue = (t) => {
|
|
|
997
997
|
...f.bodiesCreated || [],
|
|
998
998
|
...f.bodiesDeleted || [],
|
|
999
999
|
...f.bodiesUpdated || []
|
|
1000
|
-
].length > 0).forEach(({ oldValue: f, newValue:
|
|
1000
|
+
].length > 0).forEach(({ oldValue: f, newValue: w }) => {
|
|
1001
1001
|
const T = u.find((R) => R.id === f.id) || f;
|
|
1002
|
-
u = u.map((R) => R.id === f.id ?
|
|
1002
|
+
u = u.map((R) => R.id === f.id ? w : R), v("updateAnnotation", w, T);
|
|
1003
1003
|
});
|
|
1004
1004
|
}, { origin: L.LOCAL }), i.observe((l) => {
|
|
1005
1005
|
if (u) {
|
|
@@ -1007,11 +1007,11 @@ const De = 250, Ue = (t) => {
|
|
|
1007
1007
|
m.length > 0 && (u = u.map((f) => m.find((T) => T.id === f.id) || f));
|
|
1008
1008
|
}
|
|
1009
1009
|
}, { origin: L.REMOTE });
|
|
1010
|
-
const
|
|
1011
|
-
const { created: m, deleted: f, updated:
|
|
1012
|
-
(m || []).forEach((T) => v("createAnnotation", T)), (f || []).forEach((T) => v("deleteAnnotation", T)), l ? (
|
|
1010
|
+
const E = (l) => (h) => {
|
|
1011
|
+
const { created: m, deleted: f, updated: w } = h;
|
|
1012
|
+
(m || []).forEach((T) => v("createAnnotation", T)), (f || []).forEach((T) => v("deleteAnnotation", T)), l ? (w || []).forEach((T) => v("updateAnnotation", T.oldValue, T.newValue)) : (w || []).forEach((T) => v("updateAnnotation", T.newValue, T.oldValue));
|
|
1013
1013
|
};
|
|
1014
|
-
return e.on("undo",
|
|
1014
|
+
return e.on("undo", E(!0)), e.on("redo", E(!1)), { on: b, off: p, emit: v };
|
|
1015
1015
|
}, Pe = (t) => (e) => e.reduce((n, o) => {
|
|
1016
1016
|
const { parsed: i, error: s } = t.parse(o);
|
|
1017
1017
|
return s ? {
|
|
@@ -1024,44 +1024,44 @@ const De = 250, Ue = (t) => {
|
|
|
1024
1024
|
...n
|
|
1025
1025
|
};
|
|
1026
1026
|
}, { parsed: [], failed: [] }), He = (t, e, n) => {
|
|
1027
|
-
const { store: o, selection: i } = t, s = (
|
|
1027
|
+
const { store: o, selection: i } = t, s = (E) => {
|
|
1028
1028
|
if (n) {
|
|
1029
|
-
const { parsed: l, error: h } = n.parse(
|
|
1029
|
+
const { parsed: l, error: h } = n.parse(E);
|
|
1030
1030
|
l ? o.addAnnotation(l, L.REMOTE) : console.error(h);
|
|
1031
1031
|
} else
|
|
1032
|
-
o.addAnnotation(
|
|
1033
|
-
}, r = () => i.clear(), a = () => o.clear(), d = (
|
|
1034
|
-
const l = o.getAnnotation(
|
|
1032
|
+
o.addAnnotation(E, L.REMOTE);
|
|
1033
|
+
}, r = () => i.clear(), a = () => o.clear(), d = (E) => {
|
|
1034
|
+
const l = o.getAnnotation(E);
|
|
1035
1035
|
return n && l ? n.serialize(l) : l;
|
|
1036
1036
|
}, u = () => n ? o.all().map(n.serialize) : o.all(), y = () => {
|
|
1037
|
-
var
|
|
1038
|
-
const l = (((
|
|
1037
|
+
var E;
|
|
1038
|
+
const l = (((E = i.selected) == null ? void 0 : E.map((h) => h.id)) || []).map((h) => o.getAnnotation(h)).filter(Boolean);
|
|
1039
1039
|
return n ? l.map(n.serialize) : l;
|
|
1040
|
-
}, c = (
|
|
1041
|
-
if (typeof
|
|
1042
|
-
const l = o.getAnnotation(
|
|
1043
|
-
if (o.deleteAnnotation(
|
|
1040
|
+
}, c = (E) => fetch(E).then((l) => l.json()).then((l) => (p(l), l)), b = (E) => {
|
|
1041
|
+
if (typeof E == "string") {
|
|
1042
|
+
const l = o.getAnnotation(E);
|
|
1043
|
+
if (o.deleteAnnotation(E), l)
|
|
1044
1044
|
return n ? n.serialize(l) : l;
|
|
1045
1045
|
} else {
|
|
1046
|
-
const l = n ? n.parse(
|
|
1046
|
+
const l = n ? n.parse(E).parsed : E;
|
|
1047
1047
|
if (l)
|
|
1048
|
-
return o.deleteAnnotation(l),
|
|
1048
|
+
return o.deleteAnnotation(l), E;
|
|
1049
1049
|
}
|
|
1050
|
-
},
|
|
1050
|
+
}, p = (E) => {
|
|
1051
1051
|
if (n) {
|
|
1052
|
-
const { parsed: l, failed: h } = Pe(n)(
|
|
1052
|
+
const { parsed: l, failed: h } = Pe(n)(E);
|
|
1053
1053
|
h.length > 0 && console.warn(`Discarded ${h.length} invalid annotations`, h), o.bulkAddAnnotation(l, !0, L.REMOTE);
|
|
1054
1054
|
} else
|
|
1055
|
-
o.bulkAddAnnotation(
|
|
1056
|
-
}, v = (
|
|
1057
|
-
|
|
1058
|
-
}, C = (
|
|
1055
|
+
o.bulkAddAnnotation(E, !0, L.REMOTE);
|
|
1056
|
+
}, v = (E) => {
|
|
1057
|
+
E ? i.setSelected(E) : i.clear();
|
|
1058
|
+
}, C = (E) => {
|
|
1059
1059
|
if (n) {
|
|
1060
|
-
const l = n.parse(
|
|
1060
|
+
const l = n.parse(E).parsed, h = n.serialize(o.getAnnotation(l.id));
|
|
1061
1061
|
return o.updateAnnotation(l), h;
|
|
1062
1062
|
} else {
|
|
1063
|
-
const l = o.getAnnotation(
|
|
1064
|
-
return o.updateAnnotation(
|
|
1063
|
+
const l = o.getAnnotation(E.id);
|
|
1064
|
+
return o.updateAnnotation(E), l;
|
|
1065
1065
|
}
|
|
1066
1066
|
};
|
|
1067
1067
|
return {
|
|
@@ -1076,7 +1076,7 @@ const De = 250, Ue = (t) => {
|
|
|
1076
1076
|
loadAnnotations: c,
|
|
1077
1077
|
redo: e.redo,
|
|
1078
1078
|
removeAnnotation: b,
|
|
1079
|
-
setAnnotations:
|
|
1079
|
+
setAnnotations: p,
|
|
1080
1080
|
setSelected: v,
|
|
1081
1081
|
undo: e.undo,
|
|
1082
1082
|
updateAnnotation: C
|
|
@@ -1138,13 +1138,13 @@ const vn = (t, e) => ({
|
|
|
1138
1138
|
selector: []
|
|
1139
1139
|
};
|
|
1140
1140
|
for (const u of a) {
|
|
1141
|
-
const c = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((b,
|
|
1142
|
-
switch (
|
|
1141
|
+
const c = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((b, p) => {
|
|
1142
|
+
switch (p.type) {
|
|
1143
1143
|
case "TextQuoteSelector":
|
|
1144
|
-
b.quote =
|
|
1144
|
+
b.quote = p.exact;
|
|
1145
1145
|
break;
|
|
1146
1146
|
case "TextPositionSelector":
|
|
1147
|
-
b.start =
|
|
1147
|
+
b.start = p.start, b.end = p.end;
|
|
1148
1148
|
break;
|
|
1149
1149
|
}
|
|
1150
1150
|
return b;
|
|
@@ -1184,13 +1184,13 @@ const vn = (t, e) => ({
|
|
|
1184
1184
|
updated: u,
|
|
1185
1185
|
...y
|
|
1186
1186
|
} = i, c = r.map((b) => {
|
|
1187
|
-
const { quote:
|
|
1187
|
+
const { quote: p, start: v, end: C, range: E } = b, { prefix: l, suffix: h } = te(E, n);
|
|
1188
1188
|
return {
|
|
1189
1189
|
...y,
|
|
1190
1190
|
source: e,
|
|
1191
1191
|
selector: [{
|
|
1192
1192
|
type: "TextQuoteSelector",
|
|
1193
|
-
exact:
|
|
1193
|
+
exact: p,
|
|
1194
1194
|
prefix: l,
|
|
1195
1195
|
suffix: h
|
|
1196
1196
|
}, {
|
|
@@ -1221,10 +1221,10 @@ function $t(t, e, n, o, i) {
|
|
|
1221
1221
|
var s = o - n + 1, r = e - 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), y = Math.max(n, Math.floor(e - r * d / s + u)), c = Math.min(o, Math.floor(e + (s - r) * d / s + u));
|
|
1222
1222
|
$t(t, e, y, c, i);
|
|
1223
1223
|
}
|
|
1224
|
-
var b = t[e],
|
|
1225
|
-
for ($(t, n, e), i(t[o], b) > 0 && $(t, n, o);
|
|
1226
|
-
for ($(t,
|
|
1227
|
-
|
|
1224
|
+
var b = t[e], p = n, v = o;
|
|
1225
|
+
for ($(t, n, e), i(t[o], b) > 0 && $(t, n, o); p < v; ) {
|
|
1226
|
+
for ($(t, p, v), p++, v--; i(t[p], b) < 0; )
|
|
1227
|
+
p++;
|
|
1228
1228
|
for (; i(t[v], b) > 0; )
|
|
1229
1229
|
v--;
|
|
1230
1230
|
}
|
|
@@ -1254,7 +1254,7 @@ class on {
|
|
|
1254
1254
|
for (; n; ) {
|
|
1255
1255
|
for (let r = 0; r < n.children.length; r++) {
|
|
1256
1256
|
const a = n.children[r], d = n.leaf ? i(a) : a;
|
|
1257
|
-
G(e, d) && (n.leaf ? o.push(a) :
|
|
1257
|
+
G(e, d) && (n.leaf ? o.push(a) : ht(e, d) ? this._all(a, o) : s.push(a));
|
|
1258
1258
|
}
|
|
1259
1259
|
n = s.pop();
|
|
1260
1260
|
}
|
|
@@ -1269,7 +1269,7 @@ class on {
|
|
|
1269
1269
|
for (let i = 0; i < n.children.length; i++) {
|
|
1270
1270
|
const s = n.children[i], r = n.leaf ? this.toBBox(s) : s;
|
|
1271
1271
|
if (G(e, r)) {
|
|
1272
|
-
if (n.leaf ||
|
|
1272
|
+
if (n.leaf || ht(e, r))
|
|
1273
1273
|
return !0;
|
|
1274
1274
|
o.push(s);
|
|
1275
1275
|
}
|
|
@@ -1318,7 +1318,7 @@ class on {
|
|
|
1318
1318
|
if (y !== -1)
|
|
1319
1319
|
return o.children.splice(y, 1), s.push(o), this._condense(s), this;
|
|
1320
1320
|
}
|
|
1321
|
-
!u && !o.leaf &&
|
|
1321
|
+
!u && !o.leaf && ht(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;
|
|
1322
1322
|
}
|
|
1323
1323
|
return this;
|
|
1324
1324
|
}
|
|
@@ -1355,8 +1355,8 @@ class on {
|
|
|
1355
1355
|
const c = Math.min(y + u - 1, o);
|
|
1356
1356
|
Mt(e, y, c, d, this.compareMinY);
|
|
1357
1357
|
for (let b = y; b <= c; b += d) {
|
|
1358
|
-
const
|
|
1359
|
-
a.children.push(this._build(e, b,
|
|
1358
|
+
const p = Math.min(b + d - 1, c);
|
|
1359
|
+
a.children.push(this._build(e, b, p, i - 1));
|
|
1360
1360
|
}
|
|
1361
1361
|
}
|
|
1362
1362
|
return P(a, this.toBBox), a;
|
|
@@ -1365,7 +1365,7 @@ class on {
|
|
|
1365
1365
|
for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
|
|
1366
1366
|
let s = 1 / 0, r = 1 / 0, a;
|
|
1367
1367
|
for (let d = 0; d < n.children.length; d++) {
|
|
1368
|
-
const u = n.children[d], y =
|
|
1368
|
+
const u = n.children[d], y = ut(u), c = cn(e, u) - y;
|
|
1369
1369
|
c < r ? (r = c, s = y < s ? y : s, a = u) : c === r && y < s && (s = y, a = u);
|
|
1370
1370
|
}
|
|
1371
1371
|
n = a || n.children[0];
|
|
@@ -1391,7 +1391,7 @@ class on {
|
|
|
1391
1391
|
_chooseSplitIndex(e, n, o) {
|
|
1392
1392
|
let i, s = 1 / 0, r = 1 / 0;
|
|
1393
1393
|
for (let a = n; a <= o - n; a++) {
|
|
1394
|
-
const d = F(e, 0, a, this.toBBox), u = F(e, a, o, this.toBBox), y = ln(d, u), c =
|
|
1394
|
+
const d = F(e, 0, a, this.toBBox), u = F(e, a, o, this.toBBox), y = ln(d, u), c = ut(d) + ut(u);
|
|
1395
1395
|
y < s ? (s = y, i = a, r = c < r ? c : r) : y === s && c < r && (r = c, i = a);
|
|
1396
1396
|
}
|
|
1397
1397
|
return i || o - n;
|
|
@@ -1453,7 +1453,7 @@ function rn(t, e) {
|
|
|
1453
1453
|
function an(t, e) {
|
|
1454
1454
|
return t.minY - e.minY;
|
|
1455
1455
|
}
|
|
1456
|
-
function
|
|
1456
|
+
function ut(t) {
|
|
1457
1457
|
return (t.maxX - t.minX) * (t.maxY - t.minY);
|
|
1458
1458
|
}
|
|
1459
1459
|
function Q(t) {
|
|
@@ -1466,7 +1466,7 @@ function ln(t, e) {
|
|
|
1466
1466
|
const n = Math.max(t.minX, e.minX), o = Math.max(t.minY, e.minY), i = Math.min(t.maxX, e.maxX), s = Math.min(t.maxY, e.maxY);
|
|
1467
1467
|
return Math.max(0, i - n) * Math.max(0, s - o);
|
|
1468
1468
|
}
|
|
1469
|
-
function
|
|
1469
|
+
function ht(t, e) {
|
|
1470
1470
|
return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
|
|
1471
1471
|
}
|
|
1472
1472
|
function G(t, e) {
|
|
@@ -1494,16 +1494,16 @@ function Mt(t, e, n, o, i) {
|
|
|
1494
1494
|
}
|
|
1495
1495
|
const dn = (t, e) => {
|
|
1496
1496
|
const n = new on(), o = /* @__PURE__ */ new Map(), i = (l) => {
|
|
1497
|
-
const h = e.getBoundingClientRect(), m = l.selector.flatMap((
|
|
1498
|
-
const R =
|
|
1497
|
+
const h = e.getBoundingClientRect(), m = l.selector.flatMap((w) => {
|
|
1498
|
+
const R = w.range instanceof Range && !w.range.collapsed && w.range.startContainer.nodeType === Node.TEXT_NODE && w.range.endContainer.nodeType === Node.TEXT_NODE ? w.range : _t(w, e).range;
|
|
1499
1499
|
return Array.from(R.getClientRects());
|
|
1500
1500
|
}), f = oe(m);
|
|
1501
|
-
return f.map((
|
|
1502
|
-
const { x: T, y: R, width:
|
|
1501
|
+
return f.map((w) => {
|
|
1502
|
+
const { x: T, y: R, width: g, height: A } = w;
|
|
1503
1503
|
return {
|
|
1504
1504
|
minX: T - h.x,
|
|
1505
1505
|
minY: R - h.y,
|
|
1506
|
-
maxX: T - h.x +
|
|
1506
|
+
maxX: T - h.x + g,
|
|
1507
1507
|
maxY: R - h.y + A,
|
|
1508
1508
|
annotation: {
|
|
1509
1509
|
id: l.annotation,
|
|
@@ -1517,14 +1517,15 @@ const dn = (t, e) => {
|
|
|
1517
1517
|
const h = i(l);
|
|
1518
1518
|
h.forEach((m) => n.insert(m)), o.set(l.annotation, h);
|
|
1519
1519
|
}, d = (l) => {
|
|
1520
|
-
|
|
1520
|
+
const h = o.get(l.annotation);
|
|
1521
|
+
h && (h.forEach((m) => n.remove(m)), o.delete(l.annotation));
|
|
1521
1522
|
}, u = (l) => {
|
|
1522
1523
|
d(l), a(l);
|
|
1523
1524
|
}, y = (l, h = !0) => {
|
|
1524
1525
|
h && r();
|
|
1525
|
-
const m = l.map((
|
|
1526
|
-
m.forEach(({ target:
|
|
1527
|
-
const f = m.reduce((
|
|
1526
|
+
const m = l.map((w) => ({ target: w, rects: i(w) }));
|
|
1527
|
+
m.forEach(({ target: w, rects: T }) => o.set(w.annotation, T));
|
|
1528
|
+
const f = m.reduce((w, { rects: T }) => [...w, ...T], []);
|
|
1528
1529
|
n.load(f);
|
|
1529
1530
|
}, c = (l, h) => {
|
|
1530
1531
|
const m = n.search({
|
|
@@ -1532,20 +1533,20 @@ const dn = (t, e) => {
|
|
|
1532
1533
|
minY: h,
|
|
1533
1534
|
maxX: l,
|
|
1534
1535
|
maxY: h
|
|
1535
|
-
}), f = (
|
|
1536
|
+
}), f = (w) => w.annotation.rects.reduce((T, R) => T + R.width * R.height, 0);
|
|
1536
1537
|
if (m.length > 0)
|
|
1537
|
-
return m.sort((
|
|
1538
|
+
return m.sort((w, T) => f(w) - f(T)), m[0].annotation.id;
|
|
1538
1539
|
}, b = (l) => {
|
|
1539
|
-
const h =
|
|
1540
|
+
const h = p(l);
|
|
1540
1541
|
if (h.length === 0)
|
|
1541
1542
|
return;
|
|
1542
|
-
let m = h[0].left, f = h[0].top,
|
|
1543
|
+
let m = h[0].left, f = h[0].top, w = h[0].right, T = h[0].bottom;
|
|
1543
1544
|
for (let R = 1; R < h.length; R++) {
|
|
1544
|
-
const
|
|
1545
|
-
m = Math.min(m,
|
|
1545
|
+
const g = h[R];
|
|
1546
|
+
m = Math.min(m, g.left), f = Math.min(f, g.top), w = Math.max(w, g.right), T = Math.max(T, g.bottom);
|
|
1546
1547
|
}
|
|
1547
|
-
return new DOMRect(m, f,
|
|
1548
|
-
},
|
|
1548
|
+
return new DOMRect(m, f, w - m, T - f);
|
|
1549
|
+
}, p = (l) => {
|
|
1549
1550
|
const h = o.get(l);
|
|
1550
1551
|
return h ? h[0].annotation.rects : [];
|
|
1551
1552
|
};
|
|
@@ -1554,7 +1555,7 @@ const dn = (t, e) => {
|
|
|
1554
1555
|
clear: r,
|
|
1555
1556
|
getAt: c,
|
|
1556
1557
|
getBoundsForAnnotation: b,
|
|
1557
|
-
getDOMRectsForAnnotation:
|
|
1558
|
+
getDOMRectsForAnnotation: p,
|
|
1558
1559
|
getIntersectingRects: (l, h, m, f) => n.search({ minX: l, minY: h, maxX: m, maxY: f }),
|
|
1559
1560
|
insert: a,
|
|
1560
1561
|
recalculate: () => y(t.all().map((l) => l.target), !0),
|
|
@@ -1564,56 +1565,62 @@ const dn = (t, e) => {
|
|
|
1564
1565
|
update: u
|
|
1565
1566
|
};
|
|
1566
1567
|
}, un = (t, e) => {
|
|
1567
|
-
const n = _e(), o = dn(n, t), i = Ce(n, e), s = Se(n), r = Ve(), a = (
|
|
1568
|
-
const
|
|
1569
|
-
return
|
|
1570
|
-
}, d = (
|
|
1571
|
-
const
|
|
1572
|
-
return
|
|
1573
|
-
}, u = (
|
|
1574
|
-
const
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1568
|
+
const n = _e(), o = dn(n, t), i = Ce(n, e), s = Se(n), r = Ve(), a = (l, h = L.LOCAL) => {
|
|
1569
|
+
const m = st(l, t), f = D(m.target.selector);
|
|
1570
|
+
return f && n.addAnnotation(m, h), f;
|
|
1571
|
+
}, d = (l, h = !0, m = L.LOCAL) => {
|
|
1572
|
+
const f = l.map((T) => st(T, t)), w = f.filter((T) => !D(T.target.selector));
|
|
1573
|
+
return w.length > 0 ? (console.warn("Could not revive all targets for these annotations:", w), n.bulkAddAnnotation(f, h, m), w) : (n.bulkAddAnnotation(f, h, m), []);
|
|
1574
|
+
}, u = (l, h = L.LOCAL) => {
|
|
1575
|
+
const m = l.map((w) => st(w, t)), f = m.filter((w) => !D(w.target.selector));
|
|
1576
|
+
return f.length > 0 && console.warn("Could not revive all targets for these annotations:", f), m.forEach((w) => {
|
|
1577
|
+
n.getAnnotation(w.id) ? n.updateAnnotation(w, h) : n.addAnnotation(w, h);
|
|
1578
|
+
}), f;
|
|
1579
|
+
}, y = (l, h = L.LOCAL) => {
|
|
1580
|
+
const m = J(l, t);
|
|
1581
|
+
n.updateTarget(m, h);
|
|
1582
|
+
}, c = (l, h = L.LOCAL) => {
|
|
1583
|
+
const m = l.map((f) => J(f, t));
|
|
1584
|
+
n.bulkUpdateTargets(m, h);
|
|
1585
|
+
}, b = (l, h) => {
|
|
1586
|
+
const m = o.getAt(l, h);
|
|
1587
|
+
return m ? n.getAnnotation(m) : void 0;
|
|
1588
|
+
}, p = (l, h, m, f) => {
|
|
1589
|
+
const w = o.getIntersectingRects(l, h, m, f);
|
|
1590
|
+
return Array.from(new Set(w.map((R) => R.annotation.id))).map((R) => n.getAnnotation(R)).filter(Boolean);
|
|
1591
|
+
}, v = (l, h, m, f = 5) => {
|
|
1592
|
+
const w = o.getDOMRectsForAnnotation(l);
|
|
1593
|
+
if (w.length !== 0) {
|
|
1594
|
+
if (h && m) {
|
|
1595
|
+
const T = w.find(({ top: R, right: g, bottom: A, left: x }) => h >= x - f && h <= g + f && m >= R - f && m <= A + f);
|
|
1596
|
+
if (T)
|
|
1597
|
+
return T;
|
|
1592
1598
|
}
|
|
1593
|
-
return o.getBoundsForAnnotation(
|
|
1599
|
+
return o.getBoundsForAnnotation(l);
|
|
1594
1600
|
}
|
|
1595
|
-
},
|
|
1596
|
-
const
|
|
1597
|
-
return Object.entries(
|
|
1598
|
-
annotation: n.getAnnotation(
|
|
1599
|
-
rects:
|
|
1601
|
+
}, C = (l, h, m, f) => {
|
|
1602
|
+
const T = o.getIntersectingRects(l, h, m, f).reduce((R, g) => ((R[g.annotation.id] = R[g.annotation.id] || []).push(g), R), {});
|
|
1603
|
+
return Object.entries(T).map(([R, g]) => ({
|
|
1604
|
+
annotation: n.getAnnotation(R),
|
|
1605
|
+
rects: g.map(({ minX: A, minY: x, maxX: S, maxY: B }) => ({ x: A, y: x, width: S - A, height: B - x }))
|
|
1600
1606
|
}));
|
|
1601
|
-
},
|
|
1602
|
-
return n.observe(({ changes:
|
|
1603
|
-
const
|
|
1604
|
-
|
|
1607
|
+
}, E = () => o.recalculate();
|
|
1608
|
+
return n.observe(({ changes: l }) => {
|
|
1609
|
+
const h = (l.created || []).filter((w) => D(w.target.selector)), m = (l.deleted || []).filter((w) => D(w.target.selector)), f = (l.updated || []).filter((w) => D(w.newValue.target.selector));
|
|
1610
|
+
h.length > 0 && o.set(h.map((w) => w.target), !1), (m == null ? void 0 : m.length) > 0 && m.forEach((w) => o.remove(w.target)), (f == null ? void 0 : f.length) > 0 && f.forEach(({ newValue: w }) => o.update(w.target));
|
|
1605
1611
|
}), {
|
|
1606
1612
|
store: {
|
|
1607
1613
|
...n,
|
|
1608
1614
|
addAnnotation: a,
|
|
1609
1615
|
bulkAddAnnotation: d,
|
|
1610
|
-
bulkUpdateTargets:
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1616
|
+
bulkUpdateTargets: c,
|
|
1617
|
+
bulkUpsertAnnotations: u,
|
|
1618
|
+
getAnnotationBounds: v,
|
|
1619
|
+
getAt: b,
|
|
1620
|
+
getIntersecting: p,
|
|
1621
|
+
getIntersectingRects: C,
|
|
1622
|
+
recalculatePositions: E,
|
|
1623
|
+
updateTarget: y
|
|
1617
1624
|
},
|
|
1618
1625
|
selection: i,
|
|
1619
1626
|
hover: s,
|
|
@@ -1627,7 +1634,7 @@ const dn = (t, e) => {
|
|
|
1627
1634
|
}, fn = (t, e, n = {}) => {
|
|
1628
1635
|
const o = hn(), i = o.getContext("2d");
|
|
1629
1636
|
t.appendChild(o);
|
|
1630
|
-
const s = /* @__PURE__ */ new Map(), r = (c) => Array.from(s.entries()).filter(([b,
|
|
1637
|
+
const s = /* @__PURE__ */ new Map(), r = (c) => Array.from(s.entries()).filter(([b, p]) => p.presenceKey === c.presenceKey).map(([b, p]) => b);
|
|
1631
1638
|
return e.on("selectionChange", (c, b) => {
|
|
1632
1639
|
r(c).forEach((v) => s.delete(v)), b && b.forEach((v) => s.set(v, c));
|
|
1633
1640
|
}), {
|
|
@@ -1638,16 +1645,16 @@ const dn = (t, e) => {
|
|
|
1638
1645
|
destroy: () => {
|
|
1639
1646
|
o.remove();
|
|
1640
1647
|
},
|
|
1641
|
-
paint: (c, b,
|
|
1648
|
+
paint: (c, b, p) => {
|
|
1642
1649
|
n.font && (i.font = n.font);
|
|
1643
1650
|
const v = s.get(c.annotation.id);
|
|
1644
1651
|
if (v) {
|
|
1645
|
-
const { height: C } = c.rects[0],
|
|
1646
|
-
i.fillStyle = v.appearance.color, i.fillRect(
|
|
1647
|
-
const h = i.measureText(v.appearance.label), m = h.width + 6, f = h.actualBoundingBoxAscent + h.actualBoundingBoxDescent + 8,
|
|
1648
|
-
return i.fillRect(
|
|
1652
|
+
const { height: C } = c.rects[0], E = c.rects[0].x + b.left, l = c.rects[0].y + b.top;
|
|
1653
|
+
i.fillStyle = v.appearance.color, i.fillRect(E - 2, l - 2.5, 2, C + 5);
|
|
1654
|
+
const h = i.measureText(v.appearance.label), m = h.width + 6, f = h.actualBoundingBoxAscent + h.actualBoundingBoxDescent + 8, w = h.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1655
|
+
return i.fillRect(E - 2, l - 2.5 - f, m, f), i.fillStyle = "#fff", i.fillText(v.appearance.label, E + 1, l - w), {
|
|
1649
1656
|
fill: v.appearance.color,
|
|
1650
|
-
fillOpacity:
|
|
1657
|
+
fillOpacity: p ? 0.45 : 0.18
|
|
1651
1658
|
};
|
|
1652
1659
|
}
|
|
1653
1660
|
},
|
|
@@ -1664,8 +1671,8 @@ const dn = (t, e) => {
|
|
|
1664
1671
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : Ft(t.parentElement);
|
|
1665
1672
|
}, gn = (t, e) => (n) => {
|
|
1666
1673
|
const o = (s) => {
|
|
1667
|
-
const r = i.getBoundingClientRect(), a = i.clientHeight, d = i.clientWidth, u = s.selector[0].range.getBoundingClientRect(), { width: y, height: c } = e.getAnnotationBounds(n.id), b = u.top - r.top,
|
|
1668
|
-
i.scroll({ top:
|
|
1674
|
+
const r = i.getBoundingClientRect(), a = i.clientHeight, d = i.clientWidth, u = s.selector[0].range.getBoundingClientRect(), { width: y, height: c } = e.getAnnotationBounds(n.id), b = u.top - r.top, p = u.left - r.left, v = i.parentElement ? i.scrollTop : 0, C = i.parentElement ? i.scrollLeft : 0, E = b + v - (a - c) / 2, l = p + C - (d - y) / 2;
|
|
1675
|
+
i.scroll({ top: E, left: l, behavior: "smooth" });
|
|
1669
1676
|
}, i = Ft(t);
|
|
1670
1677
|
if (i) {
|
|
1671
1678
|
const s = e.getAnnotation(n.id), { range: r } = s.target.selector[0];
|
|
@@ -1695,17 +1702,17 @@ const dn = (t, e) => {
|
|
|
1695
1702
|
} : r = void 0;
|
|
1696
1703
|
};
|
|
1697
1704
|
t.addEventListener("selectstart", y);
|
|
1698
|
-
const c =
|
|
1699
|
-
const
|
|
1700
|
-
if (C.timeStamp - ((u == null ? void 0 : u.timeStamp) || C.timeStamp) < 1e3 && !r && y(u),
|
|
1705
|
+
const c = gt((C) => {
|
|
1706
|
+
const E = document.getSelection();
|
|
1707
|
+
if (C.timeStamp - ((u == null ? void 0 : u.timeStamp) || C.timeStamp) < 1e3 && !r && y(u), E.isCollapsed || !d || !r)
|
|
1701
1708
|
return;
|
|
1702
|
-
const l =
|
|
1703
|
-
(m.length !== r.selector.length || m.some((
|
|
1709
|
+
const l = E.getRangeAt(0), h = se(l.cloneRange()), m = Gt(h);
|
|
1710
|
+
(m.length !== r.selector.length || m.some((w, T) => {
|
|
1704
1711
|
var R;
|
|
1705
|
-
return
|
|
1712
|
+
return w.toString() !== ((R = r.selector[T]) == null ? void 0 : R.quote);
|
|
1706
1713
|
})) && (r = {
|
|
1707
1714
|
...r,
|
|
1708
|
-
selector: m.map((
|
|
1715
|
+
selector: m.map((w) => ie(w, t, n))
|
|
1709
1716
|
}, o.getAnnotation(r.annotation) ? o.updateTarget(r, L.LOCAL) : (o.addAnnotation({
|
|
1710
1717
|
id: r.annotation,
|
|
1711
1718
|
bodies: [],
|
|
@@ -1714,16 +1721,16 @@ const dn = (t, e) => {
|
|
|
1714
1721
|
});
|
|
1715
1722
|
document.addEventListener("selectionchange", c);
|
|
1716
1723
|
const b = (C) => {
|
|
1717
|
-
const { target:
|
|
1718
|
-
u = { ...C, target:
|
|
1724
|
+
const { target: E, timeStamp: l, offsetX: h, offsetY: m, type: f } = C;
|
|
1725
|
+
u = { ...C, target: E, timeStamp: l, offsetX: h, offsetY: m, type: f }, d = C.button === 0;
|
|
1719
1726
|
};
|
|
1720
1727
|
t.addEventListener("pointerdown", b);
|
|
1721
|
-
const
|
|
1728
|
+
const p = (C) => {
|
|
1722
1729
|
var m;
|
|
1723
1730
|
if (!!((m = C.target.parentElement) != null && m.closest(".not-annotatable")) || !d)
|
|
1724
1731
|
return;
|
|
1725
1732
|
const l = () => {
|
|
1726
|
-
const { x: f, y:
|
|
1733
|
+
const { x: f, y: w } = t.getBoundingClientRect(), T = o.getAt(C.clientX - f, C.clientY - w);
|
|
1727
1734
|
if (T) {
|
|
1728
1735
|
const { selected: R } = i;
|
|
1729
1736
|
(R.length !== 1 || R[0].id !== T.id) && i.clickSelect(T.id, C);
|
|
@@ -1732,15 +1739,15 @@ const dn = (t, e) => {
|
|
|
1732
1739
|
}, h = C.timeStamp - u.timeStamp;
|
|
1733
1740
|
document.getSelection().isCollapsed && h < 300 ? (r = void 0, l()) : r && i.clickSelect(r.annotation, C);
|
|
1734
1741
|
};
|
|
1735
|
-
return document.addEventListener("pointerup",
|
|
1742
|
+
return document.addEventListener("pointerup", p), {
|
|
1736
1743
|
destroy: () => {
|
|
1737
|
-
t.removeEventListener("selectstart", y), document.removeEventListener("selectionchange", c), t.removeEventListener("pointerdown", b), document.removeEventListener("pointerup",
|
|
1744
|
+
t.removeEventListener("selectstart", y), document.removeEventListener("selectionchange", c), t.removeEventListener("pointerdown", b), document.removeEventListener("pointerup", p);
|
|
1738
1745
|
},
|
|
1739
1746
|
setUser: a
|
|
1740
1747
|
};
|
|
1741
1748
|
}, yn = (t, e = {}) => {
|
|
1742
1749
|
t.addEventListener("click", (f) => !f.target.closest("a") && f.preventDefault());
|
|
1743
|
-
const n = un(t, e.pointerAction), { selection: o, viewport: i } = n, s = n.store, r =
|
|
1750
|
+
const n = un(t, e.pointerAction), { selection: o, viewport: i } = n, s = n.store, r = De(s), a = ke(
|
|
1744
1751
|
n,
|
|
1745
1752
|
r,
|
|
1746
1753
|
e.adapter
|
|
@@ -1783,16 +1790,16 @@ export {
|
|
|
1783
1790
|
ce as createCanvasHighlightRenderer,
|
|
1784
1791
|
yn as createTextAnnotator,
|
|
1785
1792
|
un as createTextAnnotatorState,
|
|
1786
|
-
|
|
1793
|
+
gt as debounce,
|
|
1787
1794
|
mn as getAnnotatableFragment,
|
|
1788
1795
|
bn as getClientRectsPonyfill,
|
|
1789
1796
|
te as getQuoteContext,
|
|
1790
|
-
|
|
1791
|
-
|
|
1797
|
+
ft as getRangeAnnotatableContents,
|
|
1798
|
+
D as isRevived,
|
|
1792
1799
|
oe as mergeClientRects,
|
|
1793
1800
|
Ze as parseW3CTextAnnotation,
|
|
1794
1801
|
ie as rangeToSelector,
|
|
1795
|
-
|
|
1802
|
+
st as reviveAnnotation,
|
|
1796
1803
|
_t as reviveSelector,
|
|
1797
1804
|
J as reviveTarget,
|
|
1798
1805
|
tn as serializeW3CTextAnnotation,
|