@recogito/text-annotator 3.0.0-rc.27 → 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.
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
const
|
|
1
|
+
const P = {
|
|
2
2
|
fill: "rgb(0, 128, 255)",
|
|
3
3
|
fillOpacity: 0.18
|
|
4
|
-
},
|
|
4
|
+
}, ot = {
|
|
5
5
|
fill: "rgb(0, 128, 255)",
|
|
6
6
|
fillOpacity: 0.45
|
|
7
7
|
}, qt = (t, e, n, o, i) => {
|
|
8
8
|
var a, s;
|
|
9
|
-
const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ?
|
|
9
|
+
const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? ot : P) : n : (s = t.state) != null && s.selected ? ot : P;
|
|
10
10
|
return o && o.paint(t, e) || r;
|
|
11
|
-
},
|
|
11
|
+
}, Vt = "not-annotatable", X = `.${Vt}`, jt = (t) => {
|
|
12
12
|
var n;
|
|
13
13
|
const e = t.commonAncestorContainer;
|
|
14
|
-
return e instanceof HTMLElement ? !e.closest(
|
|
14
|
+
return e instanceof HTMLElement ? !e.closest(X) : !((n = e.parentElement) != null && n.closest(X));
|
|
15
15
|
}, Gt = function* (t) {
|
|
16
16
|
const e = document.createNodeIterator(
|
|
17
17
|
t.commonAncestorContainer,
|
|
18
18
|
NodeFilter.SHOW_ELEMENT,
|
|
19
|
-
(o) => o instanceof HTMLElement && o.classList.contains(
|
|
19
|
+
(o) => o instanceof HTMLElement && o.classList.contains(Vt) && !o.parentElement.closest(X) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
|
20
20
|
);
|
|
21
21
|
let n;
|
|
22
22
|
for (; n = e.nextNode(); )
|
|
@@ -35,23 +35,23 @@ const H = {
|
|
|
35
35
|
o.setStartAfter(n), o.collapsed || e.push(o);
|
|
36
36
|
}
|
|
37
37
|
return e.length > 0 ? e : [t];
|
|
38
|
-
},
|
|
38
|
+
}, ft = (t) => {
|
|
39
39
|
const e = t.cloneContents();
|
|
40
|
-
return e.querySelectorAll(
|
|
40
|
+
return e.querySelectorAll(X).forEach((n) => n.remove()), e;
|
|
41
41
|
}, Qt = (t) => {
|
|
42
42
|
t.addEventListener("click", (e) => {
|
|
43
43
|
// Allow clicks within not-annotatable elements
|
|
44
|
-
!e.target.closest(
|
|
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);
|
|
50
50
|
};
|
|
51
51
|
}, Ln = (t) => {
|
|
52
52
|
const e = t.cloneContents();
|
|
53
|
-
return e.querySelectorAll(
|
|
54
|
-
},
|
|
53
|
+
return e.querySelectorAll(X).forEach((n) => n.remove()), e;
|
|
54
|
+
}, vt = (t, e) => {
|
|
55
55
|
const n = document.createNodeIterator(e);
|
|
56
56
|
let o = 0, i = n.nextNode();
|
|
57
57
|
for (; i !== null; ) {
|
|
@@ -59,7 +59,7 @@ const H = {
|
|
|
59
59
|
return o;
|
|
60
60
|
o += 1, i = n.nextNode();
|
|
61
61
|
}
|
|
62
|
-
},
|
|
62
|
+
}, yt = (t, e) => {
|
|
63
63
|
const n = document.createNodeIterator(e);
|
|
64
64
|
let o = null;
|
|
65
65
|
for (let i = 0; i < t + 1; i++)
|
|
@@ -72,31 +72,31 @@ const H = {
|
|
|
72
72
|
startOffset: o,
|
|
73
73
|
endContainer: i,
|
|
74
74
|
endOffset: r
|
|
75
|
-
} = t, a = Array.from(e.childNodes).map((
|
|
76
|
-
const
|
|
77
|
-
return
|
|
78
|
-
}), s =
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
return t.setStart(
|
|
83
|
-
},
|
|
84
|
-
const
|
|
85
|
-
return
|
|
75
|
+
} = t, a = Array.from(e.childNodes).map((c) => {
|
|
76
|
+
const p = c.cloneNode(!0);
|
|
77
|
+
return c.nodeName === "CANVAS" ? c : p;
|
|
78
|
+
}), s = vt(n, e), u = vt(i, e), f = () => {
|
|
79
|
+
const c = e;
|
|
80
|
+
c.replaceChildren(...a);
|
|
81
|
+
const p = yt(s, c), g = yt(u, c);
|
|
82
|
+
return t.setStart(p, o), t.setEnd(g, r), t;
|
|
83
|
+
}, m = (c) => {
|
|
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
|
-
const
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
const x =
|
|
90
|
+
const c = document.createRange();
|
|
91
|
+
c.selectNodeContents(n), c.setStart(n, o);
|
|
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 = d.parentNode) == null || y.insertBefore(
|
|
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: f, nodes: [
|
|
99
|
+
return { unwrap: f, nodes: [p, ...h, x] };
|
|
100
100
|
}
|
|
101
101
|
}, Zt = (t) => {
|
|
102
102
|
const {
|
|
@@ -120,14 +120,14 @@ const H = {
|
|
|
120
120
|
}, te = (t, e, n = 10, o) => {
|
|
121
121
|
const i = o ? t.startContainer.parentElement.closest(o) : e, r = document.createRange();
|
|
122
122
|
r.setStart(i, 0), r.setEnd(t.startContainer, t.startOffset);
|
|
123
|
-
const a =
|
|
123
|
+
const a = ft(r).textContent, s = document.createRange();
|
|
124
124
|
s.setStart(t.endContainer, t.endOffset), i === document.body ? s.setEnd(i, i.childNodes.length) : s.setEndAfter(i);
|
|
125
|
-
const u =
|
|
125
|
+
const u = ft(s).textContent;
|
|
126
126
|
return {
|
|
127
127
|
prefix: a.substring(a.length - n),
|
|
128
128
|
suffix: u.substring(0, n)
|
|
129
129
|
};
|
|
130
|
-
},
|
|
130
|
+
}, $ = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), ee = (t, e) => {
|
|
131
131
|
const n = (r) => Math.round(r * 10) / 10, o = {
|
|
132
132
|
top: n(t.top),
|
|
133
133
|
bottom: n(t.bottom),
|
|
@@ -178,16 +178,16 @@ const H = {
|
|
|
178
178
|
}, []), ie = (t, e, n) => {
|
|
179
179
|
const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
|
|
180
180
|
o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
|
|
181
|
-
const r =
|
|
181
|
+
const r = ft(o).textContent, a = t.toString(), s = r.length || 0, u = s + a.length;
|
|
182
182
|
return n ? { quote: a, start: s, end: u, range: t, offsetReference: i } : { quote: a, start: s, end: u, range: t };
|
|
183
|
-
},
|
|
184
|
-
var
|
|
183
|
+
}, _t = (t, e) => {
|
|
184
|
+
var m, c;
|
|
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;
|
|
@@ -197,31 +197,31 @@ const H = {
|
|
|
197
197
|
let f = !i;
|
|
198
198
|
for (; u !== null; ) {
|
|
199
199
|
if (f || (f = i == null ? void 0 : i.contains(u)), f) {
|
|
200
|
-
const
|
|
201
|
-
if (a +
|
|
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,
|
|
219
219
|
range: s
|
|
220
220
|
};
|
|
221
|
-
},
|
|
221
|
+
}, it = (t, e) => $(t.selector) ? t : {
|
|
222
222
|
...t,
|
|
223
|
-
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n :
|
|
224
|
-
},
|
|
223
|
+
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : _t(n, e))
|
|
224
|
+
}, rt = (t, e) => $(t.target.selector) ? t : { ...t, target: it(t.target, e) }, re = (t) => {
|
|
225
225
|
var i;
|
|
226
226
|
const { startContainer: e, endContainer: n } = t;
|
|
227
227
|
if (e.nodeType === Node.TEXT_NODE && n.nodeType === Node.TEXT_NODE)
|
|
@@ -244,90 +244,93 @@ const H = {
|
|
|
244
244
|
const i = o.map((r) => r.id);
|
|
245
245
|
(e.size !== i.length || i.some((r) => !e.has(r))) && t.set(i), e = new Set(i);
|
|
246
246
|
};
|
|
247
|
-
},
|
|
247
|
+
}, mt = (t, e, n, o) => {
|
|
248
248
|
const { store: i, selection: r, hover: a } = e;
|
|
249
249
|
let s, u, f;
|
|
250
|
-
const
|
|
251
|
-
const { x:
|
|
252
|
-
|
|
250
|
+
const m = ae(n), c = (R) => {
|
|
251
|
+
const { x: O, y: b } = t.getBoundingClientRect(), w = i.getAt(R.clientX - O, R.clientY - b);
|
|
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
|
-
t.addEventListener("pointermove",
|
|
255
|
-
const
|
|
254
|
+
t.addEventListener("pointermove", c);
|
|
255
|
+
const p = (R = !1) => {
|
|
256
256
|
f && f.clear();
|
|
257
|
-
const
|
|
258
|
-
const Ft =
|
|
259
|
-
return { annotation:
|
|
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
|
+
return { annotation: k, rects: zt, state: { selected: Ft, hover: Wt } };
|
|
260
260
|
});
|
|
261
|
-
o.redraw(
|
|
262
|
-
},
|
|
263
|
-
f =
|
|
264
|
-
}, x = (
|
|
265
|
-
s =
|
|
266
|
-
}, v = (
|
|
267
|
-
u =
|
|
268
|
-
}, h = () =>
|
|
261
|
+
o.redraw(H, O, s, f, R), setTimeout(() => m(L.map(({ annotation: k }) => k)), 1);
|
|
262
|
+
}, g = (R) => {
|
|
263
|
+
f = R, p();
|
|
264
|
+
}, x = (R) => {
|
|
265
|
+
s = R, p();
|
|
266
|
+
}, v = (R) => {
|
|
267
|
+
u = R, p(!1);
|
|
268
|
+
}, h = () => p();
|
|
269
269
|
i.observe(h);
|
|
270
|
-
const d = r.subscribe(() =>
|
|
271
|
-
document.addEventListener("scroll",
|
|
272
|
-
const y =
|
|
273
|
-
i.recalculatePositions(), f && f.reset(),
|
|
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 C = { attributes: !0, childList: !0, subtree: !0 }, E = new MutationObserver((
|
|
279
|
-
|
|
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
281
|
return E.observe(document.body, C), {
|
|
282
282
|
destroy: () => {
|
|
283
|
-
t.removeEventListener("pointermove",
|
|
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
287
|
setFilter: v,
|
|
288
|
-
setPainter:
|
|
288
|
+
setPainter: g,
|
|
289
289
|
setVisible: o.setVisible
|
|
290
290
|
};
|
|
291
|
-
},
|
|
291
|
+
}, ce = () => {
|
|
292
292
|
const t = document.createElement("canvas");
|
|
293
293
|
return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-highlight-layer bg", t;
|
|
294
|
-
},
|
|
294
|
+
}, le = (t, e) => {
|
|
295
295
|
t.width = window.innerWidth, t.height = window.innerHeight;
|
|
296
296
|
}, de = (t) => {
|
|
297
297
|
t.classList.add("r6o-annotatable");
|
|
298
|
-
const e =
|
|
298
|
+
const e = ce(), n = e.getContext("2d");
|
|
299
299
|
t.insertBefore(e, t.firstChild);
|
|
300
|
-
const o = (s, u, f,
|
|
301
|
-
const { width:
|
|
302
|
-
n.clearRect(-0.5, -0.5,
|
|
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
|
-
n.fillStyle =
|
|
313
|
-
const
|
|
314
|
-
if (
|
|
315
|
-
({ x:
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
315
|
+
n.fillStyle = l.fill, n.globalAlpha = l.fillOpacity || 1;
|
|
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
|
-
),
|
|
322
|
-
n.globalAlpha = 1, n.strokeStyle =
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
n.beginPath(), n.moveTo(
|
|
324
|
+
), l.underlineColor) {
|
|
325
|
+
n.globalAlpha = 1, n.strokeStyle = l.underlineColor, n.lineWidth = l.underlineThickness ?? 1;
|
|
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 =
|
|
330
|
-
|
|
332
|
+
}), i = pt(() => {
|
|
333
|
+
le(e);
|
|
331
334
|
});
|
|
332
335
|
return window.addEventListener("resize", i), {
|
|
333
336
|
destroy: () => {
|
|
@@ -338,70 +341,70 @@ const H = {
|
|
|
338
341
|
},
|
|
339
342
|
redraw: o
|
|
340
343
|
};
|
|
341
|
-
}, ue = (t, e, n) =>
|
|
342
|
-
var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) },
|
|
344
|
+
}, ue = (t, e, n) => mt(t, e, n, de(t));
|
|
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;
|
|
348
351
|
}, Ut = function(t) {
|
|
349
352
|
return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
|
|
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
|
-
},
|
|
353
|
-
return { r:
|
|
354
|
-
}, fe = /^#([0-9a-f]{3,8})$/i,
|
|
355
|
+
}, st = function(t) {
|
|
356
|
+
return { r: M(t.r), g: M(t.g), b: M(t.b), a: M(t.a, 3) };
|
|
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;
|
|
357
|
-
},
|
|
360
|
+
}, Dt = function(t) {
|
|
358
361
|
var e = t.r, n = t.g, o = t.b, i = t.a, r = Math.max(e, n, o), a = r - Math.min(e, n, o), s = a ? r === e ? (n - o) / a : r === n ? 2 + (o - e) / a : 4 + (e - n) / a : 0;
|
|
359
362
|
return { h: 60 * (s < 0 ? s + 6 : s), s: r ? a / r * 100 : 0, v: r / 255 * 100, a: i };
|
|
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
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;
|
|
364
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
|
-
}, yt = function(t) {
|
|
366
|
-
return { h: Ut(t.h), s: U(t.s, 0, 100), l: U(t.l, 0, 100), a: U(t.a) };
|
|
367
|
-
}, wt = function(t) {
|
|
368
|
-
return { h: O(t.h), s: O(t.s), l: O(t.l), a: O(t.a, 3) };
|
|
369
368
|
}, xt = function(t) {
|
|
370
|
-
return
|
|
369
|
+
return { h: Ut(t.h), s: U(t.s, 0, 100), l: U(t.l, 0, 100), a: U(t.a) };
|
|
370
|
+
}, At = function(t) {
|
|
371
|
+
return { h: M(t.h), s: M(t.s), l: M(t.l), a: M(t.a, 3) };
|
|
372
|
+
}, Et = function(t) {
|
|
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
|
-
},
|
|
373
|
-
return { h: (e =
|
|
375
|
+
}, Q = function(t) {
|
|
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
|
-
return e ? e[2] !== e[4] || e[4] !== e[6] ? null :
|
|
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
|
-
var n, o, i =
|
|
386
|
-
return
|
|
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) });
|
|
389
|
+
return Et(i);
|
|
387
390
|
}, "hsl"]], object: [[function(t) {
|
|
388
391
|
var e = t.r, n = t.g, o = t.b, i = t.a, r = i === void 0 ? 1 : i;
|
|
389
|
-
return
|
|
392
|
+
return Y(e) && Y(n) && Y(o) ? wt({ r: Number(e), g: Number(n), b: Number(o), a: Number(r) }) : null;
|
|
390
393
|
}, "rgb"], [function(t) {
|
|
391
394
|
var e = t.h, n = t.s, o = t.l, i = t.a, r = i === void 0 ? 1 : i;
|
|
392
|
-
if (!
|
|
395
|
+
if (!Y(e) || !Y(n) || !Y(o))
|
|
393
396
|
return null;
|
|
394
|
-
var a =
|
|
395
|
-
return
|
|
397
|
+
var a = xt({ h: Number(e), s: Number(n), l: Number(o), a: Number(r) });
|
|
398
|
+
return Et(a);
|
|
396
399
|
}, "hsl"], [function(t) {
|
|
397
400
|
var e = t.h, n = t.s, o = t.v, i = t.a, r = i === void 0 ? 1 : i;
|
|
398
|
-
if (!
|
|
401
|
+
if (!Y(e) || !Y(n) || !Y(o))
|
|
399
402
|
return null;
|
|
400
403
|
var a = function(s) {
|
|
401
404
|
return { h: Ut(s.h), s: U(s.s, 0, 100), v: U(s.v, 0, 100), a: U(s.a) };
|
|
402
405
|
}({ h: Number(e), s: Number(n), v: Number(o), a: Number(r) });
|
|
403
|
-
return
|
|
404
|
-
}, "hsv"]] },
|
|
406
|
+
return Xt(a);
|
|
407
|
+
}, "hsv"]] }, Ct = function(t, e) {
|
|
405
408
|
for (var n = 0; n < e.length; n++) {
|
|
406
409
|
var o = e[n][0](t);
|
|
407
410
|
if (o)
|
|
@@ -409,72 +412,72 @@ var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, k = function(t) {
|
|
|
409
412
|
}
|
|
410
413
|
return [null, void 0];
|
|
411
414
|
}, ve = function(t) {
|
|
412
|
-
return typeof t == "string" ?
|
|
413
|
-
},
|
|
414
|
-
var n =
|
|
415
|
+
return typeof t == "string" ? Ct(t.trim(), St.string) : typeof t == "object" && t !== null ? Ct(t, St.object) : [null, void 0];
|
|
416
|
+
}, at = function(t, e) {
|
|
417
|
+
var n = Q(t);
|
|
415
418
|
return { h: n.h, s: U(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
|
|
416
|
-
},
|
|
419
|
+
}, ct = function(t) {
|
|
417
420
|
return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
|
|
418
|
-
},
|
|
419
|
-
var n =
|
|
421
|
+
}, Tt = function(t, e) {
|
|
422
|
+
var n = Q(t);
|
|
420
423
|
return { h: n.h, s: n.s, l: U(n.l + 100 * e, 0, 100), a: n.a };
|
|
421
|
-
},
|
|
424
|
+
}, Nt = function() {
|
|
422
425
|
function t(e) {
|
|
423
426
|
this.parsed = ve(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
|
|
424
427
|
}
|
|
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
|
-
return
|
|
433
|
+
return ct(this.rgba) < 0.5;
|
|
431
434
|
}, t.prototype.isLight = function() {
|
|
432
|
-
return
|
|
435
|
+
return ct(this.rgba) >= 0.5;
|
|
433
436
|
}, t.prototype.toHex = function() {
|
|
434
|
-
return e =
|
|
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
|
-
return
|
|
440
|
+
return st(this.rgba);
|
|
438
441
|
}, t.prototype.toRgbString = function() {
|
|
439
|
-
return e =
|
|
442
|
+
return e = st(this.rgba), n = e.r, o = e.g, i = e.b, (r = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + r + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
|
|
440
443
|
var e, n, o, i, r;
|
|
441
444
|
}, t.prototype.toHsl = function() {
|
|
442
|
-
return
|
|
445
|
+
return At(Q(this.rgba));
|
|
443
446
|
}, t.prototype.toHslString = function() {
|
|
444
|
-
return e =
|
|
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 =
|
|
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
|
-
return
|
|
453
|
+
return D({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
|
|
451
454
|
var e;
|
|
452
455
|
}, t.prototype.saturate = function(e) {
|
|
453
|
-
return e === void 0 && (e = 0.1),
|
|
456
|
+
return e === void 0 && (e = 0.1), D(at(this.rgba, e));
|
|
454
457
|
}, t.prototype.desaturate = function(e) {
|
|
455
|
-
return e === void 0 && (e = 0.1),
|
|
458
|
+
return e === void 0 && (e = 0.1), D(at(this.rgba, -e));
|
|
456
459
|
}, t.prototype.grayscale = function() {
|
|
457
|
-
return
|
|
460
|
+
return D(at(this.rgba, -1));
|
|
458
461
|
}, t.prototype.lighten = function(e) {
|
|
459
|
-
return e === void 0 && (e = 0.1),
|
|
462
|
+
return e === void 0 && (e = 0.1), D(Tt(this.rgba, e));
|
|
460
463
|
}, t.prototype.darken = function(e) {
|
|
461
|
-
return e === void 0 && (e = 0.1),
|
|
464
|
+
return e === void 0 && (e = 0.1), D(Tt(this.rgba, -e));
|
|
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" ?
|
|
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
|
-
var n =
|
|
469
|
-
return typeof e == "number" ?
|
|
471
|
+
var n = Q(this.rgba);
|
|
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
|
-
return this.toHex() ===
|
|
474
|
+
return this.toHex() === D(e).toHex();
|
|
472
475
|
}, t;
|
|
473
|
-
}(),
|
|
474
|
-
return t instanceof
|
|
476
|
+
}(), D = function(t) {
|
|
477
|
+
return t instanceof Nt ? t : new Nt(t);
|
|
475
478
|
};
|
|
476
479
|
const ye = (t) => [
|
|
477
|
-
`background-color:${
|
|
480
|
+
`background-color:${D((t == null ? void 0 : t.fill) || P.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? P.fillOpacity : t.fillOpacity).toHex()}`,
|
|
478
481
|
t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
|
|
479
482
|
t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
480
483
|
t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
@@ -492,23 +495,23 @@ const ye = (t) => [
|
|
|
492
495
|
},
|
|
493
496
|
redraw: (r, a, s, u) => {
|
|
494
497
|
u && u.clear();
|
|
495
|
-
const f = new Set(r.map((
|
|
496
|
-
Array.from(e).filter((
|
|
497
|
-
const
|
|
498
|
+
const f = new Set(r.map((c) => c.annotation.id));
|
|
499
|
+
Array.from(e).filter((c) => !f.has(c));
|
|
500
|
+
const m = r.map((c) => {
|
|
498
501
|
var x;
|
|
499
|
-
const
|
|
500
|
-
return `::highlight(_${
|
|
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
|
-
t.innerHTML =
|
|
503
|
-
`), CSS.highlights.clear(), r.forEach(({ annotation:
|
|
504
|
-
const
|
|
505
|
-
CSS.highlights.set(`_${
|
|
505
|
+
t.innerHTML = m.join(`
|
|
506
|
+
`), CSS.highlights.clear(), r.forEach(({ annotation: c }) => {
|
|
507
|
+
const p = c.target.selector.map((x) => x.range), g = new Highlight(...p);
|
|
508
|
+
CSS.highlights.set(`_${c.id}`, g);
|
|
506
509
|
}), e = f;
|
|
507
510
|
}
|
|
508
511
|
};
|
|
509
|
-
}, xe = (t, e, n) =>
|
|
510
|
-
var
|
|
511
|
-
function
|
|
512
|
+
}, xe = (t, e, n) => mt(t, e, n, we());
|
|
513
|
+
var Rt = Object.prototype.hasOwnProperty;
|
|
514
|
+
function gt(t, e) {
|
|
512
515
|
var n, o;
|
|
513
516
|
if (t === e)
|
|
514
517
|
return !0;
|
|
@@ -519,14 +522,14 @@ function ht(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 (
|
|
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,51 +548,54 @@ const Ae = (t, e) => {
|
|
|
545
548
|
destroy: () => {
|
|
546
549
|
e.remove();
|
|
547
550
|
},
|
|
548
|
-
redraw: (a, s, u, f,
|
|
549
|
-
|
|
551
|
+
redraw: (a, s, u, f, m) => {
|
|
552
|
+
const p = !(gt(n, a) && m);
|
|
553
|
+
if (!f && !p)
|
|
550
554
|
return;
|
|
551
|
-
e.innerHTML = "";
|
|
552
|
-
const
|
|
553
|
-
a.forEach((
|
|
554
|
-
|
|
555
|
-
const h =
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
555
|
+
p && (e.innerHTML = "");
|
|
556
|
+
const g = a.reduce((x, { rects: v }) => [...x, ...v], []);
|
|
557
|
+
a.forEach((x) => {
|
|
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);
|
|
565
|
+
}
|
|
559
566
|
});
|
|
560
|
-
return { id: p.annotation.id, spans: x };
|
|
561
567
|
}), n = a;
|
|
562
568
|
},
|
|
563
569
|
setVisible: (a) => {
|
|
564
570
|
a ? e.classList.remove("hidden") : e.classList.add("hidden");
|
|
565
571
|
}
|
|
566
572
|
};
|
|
567
|
-
}, Se = (t, e, n) =>
|
|
568
|
-
let
|
|
573
|
+
}, Se = (t, e, n) => mt(t, e, n, Ee(t));
|
|
574
|
+
let Z;
|
|
569
575
|
const Ce = new Uint8Array(16);
|
|
570
576
|
function Te() {
|
|
571
|
-
if (!
|
|
577
|
+
if (!Z && (Z = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Z))
|
|
572
578
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
573
|
-
return
|
|
579
|
+
return Z(Ce);
|
|
574
580
|
}
|
|
575
|
-
const
|
|
581
|
+
const V = [];
|
|
576
582
|
for (let t = 0; t < 256; ++t)
|
|
577
|
-
|
|
583
|
+
V.push((t + 256).toString(16).slice(1));
|
|
578
584
|
function Ne(t, e = 0) {
|
|
579
|
-
return
|
|
585
|
+
return V[t[e + 0]] + V[t[e + 1]] + V[t[e + 2]] + V[t[e + 3]] + "-" + V[t[e + 4]] + V[t[e + 5]] + "-" + V[t[e + 6]] + V[t[e + 7]] + "-" + V[t[e + 8]] + V[t[e + 9]] + "-" + V[t[e + 10]] + V[t[e + 11]] + V[t[e + 12]] + V[t[e + 13]] + V[t[e + 14]] + V[t[e + 15]];
|
|
580
586
|
}
|
|
581
|
-
const Re = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto),
|
|
587
|
+
const Re = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Lt = {
|
|
582
588
|
randomUUID: Re
|
|
583
589
|
};
|
|
584
|
-
function
|
|
585
|
-
if (
|
|
586
|
-
return
|
|
590
|
+
function kt(t, e, n) {
|
|
591
|
+
if (Lt.randomUUID && !e && !t)
|
|
592
|
+
return Lt.randomUUID();
|
|
587
593
|
t = t || {};
|
|
588
594
|
const o = t.random || (t.rng || Te)();
|
|
589
595
|
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Ne(o);
|
|
590
596
|
}
|
|
591
|
-
var
|
|
592
|
-
function
|
|
597
|
+
var Bt = Object.prototype.hasOwnProperty;
|
|
598
|
+
function q(t, e) {
|
|
593
599
|
var n, o;
|
|
594
600
|
if (t === e)
|
|
595
601
|
return !0;
|
|
@@ -600,54 +606,54 @@ function F(t, e) {
|
|
|
600
606
|
return t.toString() === e.toString();
|
|
601
607
|
if (n === Array) {
|
|
602
608
|
if ((o = t.length) === e.length)
|
|
603
|
-
for (; o-- &&
|
|
609
|
+
for (; o-- && q(t[o], e[o]); )
|
|
604
610
|
;
|
|
605
611
|
return o === -1;
|
|
606
612
|
}
|
|
607
613
|
if (!n || typeof t == "object") {
|
|
608
614
|
o = 0;
|
|
609
615
|
for (n in t)
|
|
610
|
-
if (
|
|
616
|
+
if (Bt.call(t, n) && ++o && !Bt.call(e, n) || !(n in e) || !q(t[n], e[n]))
|
|
611
617
|
return !1;
|
|
612
618
|
return Object.keys(e).length === o;
|
|
613
619
|
}
|
|
614
620
|
}
|
|
615
621
|
return t !== t && e !== e;
|
|
616
622
|
}
|
|
617
|
-
function
|
|
623
|
+
function lt() {
|
|
618
624
|
}
|
|
619
625
|
function Le(t, e) {
|
|
620
626
|
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
|
|
621
627
|
}
|
|
622
|
-
const
|
|
623
|
-
function
|
|
628
|
+
const z = [];
|
|
629
|
+
function bt(t, e = lt) {
|
|
624
630
|
let n;
|
|
625
631
|
const o = /* @__PURE__ */ new Set();
|
|
626
632
|
function i(s) {
|
|
627
633
|
if (Le(t, s) && (t = s, n)) {
|
|
628
|
-
const u =
|
|
634
|
+
const u = !z.length;
|
|
629
635
|
for (const f of o)
|
|
630
|
-
f[1](),
|
|
636
|
+
f[1](), z.push(f, t);
|
|
631
637
|
if (u) {
|
|
632
|
-
for (let f = 0; f <
|
|
633
|
-
|
|
634
|
-
|
|
638
|
+
for (let f = 0; f < z.length; f += 2)
|
|
639
|
+
z[f][0](z[f + 1]);
|
|
640
|
+
z.length = 0;
|
|
635
641
|
}
|
|
636
642
|
}
|
|
637
643
|
}
|
|
638
644
|
function r(s) {
|
|
639
645
|
i(s(t));
|
|
640
646
|
}
|
|
641
|
-
function a(s, u =
|
|
647
|
+
function a(s, u = lt) {
|
|
642
648
|
const f = [s, u];
|
|
643
|
-
return o.add(f), o.size === 1 && (n = e(i, r) ||
|
|
649
|
+
return o.add(f), o.size === 1 && (n = e(i, r) || lt), s(t), () => {
|
|
644
650
|
o.delete(f), o.size === 0 && n && (n(), n = null);
|
|
645
651
|
};
|
|
646
652
|
}
|
|
647
653
|
return { set: i, update: r, subscribe: a };
|
|
648
654
|
}
|
|
649
655
|
const Be = (t) => {
|
|
650
|
-
const { subscribe: e, set: n } =
|
|
656
|
+
const { subscribe: e, set: n } = bt();
|
|
651
657
|
let o;
|
|
652
658
|
return e((i) => o = i), t.observe(({ changes: i }) => {
|
|
653
659
|
if (o) {
|
|
@@ -664,35 +670,35 @@ const Be = (t) => {
|
|
|
664
670
|
};
|
|
665
671
|
};
|
|
666
672
|
var Oe = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(Oe || {});
|
|
667
|
-
const
|
|
668
|
-
const { subscribe: n, set: o } =
|
|
669
|
-
let i =
|
|
670
|
-
n((
|
|
671
|
-
const r = () => o(
|
|
672
|
-
var
|
|
673
|
-
return ((
|
|
674
|
-
}, s = (
|
|
673
|
+
const dt = { selected: [] }, Ie = (t, e = "EDIT") => {
|
|
674
|
+
const { subscribe: n, set: o } = bt(dt);
|
|
675
|
+
let i = dt;
|
|
676
|
+
n((c) => i = c);
|
|
677
|
+
const r = () => o(dt), a = () => {
|
|
678
|
+
var c;
|
|
679
|
+
return ((c = i.selected) == null ? void 0 : c.length) === 0;
|
|
680
|
+
}, s = (c) => {
|
|
675
681
|
if (i.selected.length === 0)
|
|
676
682
|
return !1;
|
|
677
|
-
const
|
|
678
|
-
return i.selected.some((
|
|
679
|
-
}, u = (
|
|
680
|
-
const
|
|
681
|
-
if (
|
|
682
|
-
const x = Me(
|
|
683
|
-
o(x === "EDIT" ? { selected: [{ id:
|
|
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 });
|
|
684
690
|
} else
|
|
685
|
-
console.warn("Invalid selection: " +
|
|
686
|
-
}, f = (
|
|
687
|
-
const
|
|
688
|
-
o({ selected: x.map(({ id: v }) => ({ id: v, editable:
|
|
689
|
-
},
|
|
691
|
+
console.warn("Invalid selection: " + c);
|
|
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);
|
|
695
|
+
}, m = (c) => {
|
|
690
696
|
if (i.selected.length === 0)
|
|
691
697
|
return !1;
|
|
692
|
-
const { selected:
|
|
693
|
-
|
|
698
|
+
const { selected: p } = i;
|
|
699
|
+
p.filter(({ id: g }) => c.includes(g)).length > 0 && o({ selected: p.filter(({ id: g }) => !c.includes(g)) });
|
|
694
700
|
};
|
|
695
|
-
return t.observe(({ changes:
|
|
701
|
+
return t.observe(({ changes: c }) => m((c.deleted || []).map((p) => p.id))), {
|
|
696
702
|
clear: r,
|
|
697
703
|
clickSelect: u,
|
|
698
704
|
get selected() {
|
|
@@ -707,31 +713,31 @@ const lt = { selected: [] }, Ie = (t, e = "EDIT") => {
|
|
|
707
713
|
subscribe: n
|
|
708
714
|
};
|
|
709
715
|
}, Me = (t, e) => typeof e == "function" ? e(t) || "EDIT" : e || "EDIT";
|
|
710
|
-
let
|
|
711
|
-
const
|
|
712
|
-
function
|
|
713
|
-
if (!
|
|
716
|
+
let tt;
|
|
717
|
+
const Ve = new Uint8Array(16);
|
|
718
|
+
function _e() {
|
|
719
|
+
if (!tt && (tt = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !tt))
|
|
714
720
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
715
|
-
return
|
|
721
|
+
return tt(Ve);
|
|
716
722
|
}
|
|
717
|
-
const
|
|
723
|
+
const _ = [];
|
|
718
724
|
for (let t = 0; t < 256; ++t)
|
|
719
|
-
|
|
720
|
-
function
|
|
721
|
-
return
|
|
725
|
+
_.push((t + 256).toString(16).slice(1));
|
|
726
|
+
function Ue(t, e = 0) {
|
|
727
|
+
return _[t[e + 0]] + _[t[e + 1]] + _[t[e + 2]] + _[t[e + 3]] + "-" + _[t[e + 4]] + _[t[e + 5]] + "-" + _[t[e + 6]] + _[t[e + 7]] + "-" + _[t[e + 8]] + _[t[e + 9]] + "-" + _[t[e + 10]] + _[t[e + 11]] + _[t[e + 12]] + _[t[e + 13]] + _[t[e + 14]] + _[t[e + 15]];
|
|
722
728
|
}
|
|
723
|
-
const
|
|
724
|
-
randomUUID:
|
|
729
|
+
const De = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Ot = {
|
|
730
|
+
randomUUID: De
|
|
725
731
|
};
|
|
726
|
-
function
|
|
727
|
-
if (
|
|
728
|
-
return
|
|
732
|
+
function Xe(t, e, n) {
|
|
733
|
+
if (Ot.randomUUID && !e && !t)
|
|
734
|
+
return Ot.randomUUID();
|
|
729
735
|
t = t || {};
|
|
730
|
-
const o = t.random || (t.rng ||
|
|
731
|
-
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128,
|
|
736
|
+
const o = t.random || (t.rng || _e)();
|
|
737
|
+
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Ue(o);
|
|
732
738
|
}
|
|
733
739
|
const On = (t, e, n, o) => ({
|
|
734
|
-
id:
|
|
740
|
+
id: Xe(),
|
|
735
741
|
annotation: t.id,
|
|
736
742
|
created: n || /* @__PURE__ */ new Date(),
|
|
737
743
|
creator: o,
|
|
@@ -744,8 +750,8 @@ const On = (t, e, n, o) => ({
|
|
|
744
750
|
return t.bodies.filter((o) => !n.has(o.id));
|
|
745
751
|
}, He = (t, e) => e.bodies.map((n) => {
|
|
746
752
|
const o = t.bodies.find((i) => i.id === n.id);
|
|
747
|
-
return { newBody: n, oldBody: o && !
|
|
748
|
-
}).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), $e = (t, e) => !
|
|
753
|
+
return { newBody: n, oldBody: o && !q(o, n) ? o : void 0 };
|
|
754
|
+
}).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), $e = (t, e) => !q(t.target, e.target), Yt = (t, e) => {
|
|
749
755
|
const n = ke(t, e), o = Ye(t, e), i = He(t, e);
|
|
750
756
|
return {
|
|
751
757
|
oldValue: t,
|
|
@@ -756,7 +762,7 @@ const On = (t, e, n, o) => ({
|
|
|
756
762
|
targetUpdated: $e(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
|
|
757
763
|
};
|
|
758
764
|
};
|
|
759
|
-
var
|
|
765
|
+
var B = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(B || {});
|
|
760
766
|
const Pe = (t, e) => {
|
|
761
767
|
var n, o;
|
|
762
768
|
const { changes: i, origin: r } = e;
|
|
@@ -765,7 +771,7 @@ const Pe = (t, e) => {
|
|
|
765
771
|
if (t.options.ignore) {
|
|
766
772
|
const { ignore: a } = t.options, s = (u) => u && u.length > 0;
|
|
767
773
|
if (!(s(i.created) || s(i.deleted))) {
|
|
768
|
-
const u = (n = i.updated) == null ? void 0 : n.some((
|
|
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);
|
|
769
775
|
if (a === "BODY_ONLY" && u && !f || a === "TARGET_ONLY" && f && !u)
|
|
770
776
|
return !1;
|
|
771
777
|
}
|
|
@@ -780,207 +786,214 @@ const Pe = (t, e) => {
|
|
|
780
786
|
} else
|
|
781
787
|
return !0;
|
|
782
788
|
}, ze = (t, e) => {
|
|
783
|
-
const n = new Set((t.created || []).map((
|
|
784
|
-
...(t.created || []).filter((
|
|
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 = [
|
|
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),
|
|
785
791
|
...e.created || []
|
|
786
792
|
], f = [
|
|
787
|
-
...(t.deleted || []).filter((
|
|
788
|
-
...(e.deleted || []).filter((
|
|
789
|
-
],
|
|
790
|
-
...(t.updated || []).filter(({ newValue:
|
|
791
|
-
const { oldValue:
|
|
792
|
-
if (a.has(
|
|
793
|
-
const x = e.updated.find((v) => v.oldValue.id ===
|
|
794
|
-
return
|
|
793
|
+
...(t.deleted || []).filter((c) => !i.has(c.id)),
|
|
794
|
+
...(e.deleted || []).filter((c) => !n.has(c.id))
|
|
795
|
+
], m = [
|
|
796
|
+
...(t.updated || []).filter(({ newValue: c }) => !r.has(c.id)).map((c) => {
|
|
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);
|
|
795
801
|
} else
|
|
796
|
-
return
|
|
802
|
+
return c;
|
|
797
803
|
}),
|
|
798
|
-
...(e.updated || []).filter(({ oldValue:
|
|
804
|
+
...(e.updated || []).filter(({ oldValue: c }) => !s.has(c.id))
|
|
799
805
|
];
|
|
800
|
-
return { created: u, deleted: f, updated:
|
|
806
|
+
return { created: u, deleted: f, updated: m };
|
|
801
807
|
}, Fe = (t) => t.id !== void 0, We = () => {
|
|
802
|
-
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (
|
|
803
|
-
const
|
|
804
|
-
|
|
805
|
-
}, r = (
|
|
806
|
-
const
|
|
807
|
-
origin:
|
|
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);
|
|
810
|
+
w > -1 && n.splice(w, 1);
|
|
811
|
+
}, r = (b, w) => {
|
|
812
|
+
const A = {
|
|
813
|
+
origin: b,
|
|
808
814
|
changes: {
|
|
809
|
-
created:
|
|
810
|
-
updated:
|
|
811
|
-
deleted:
|
|
815
|
+
created: w.created || [],
|
|
816
|
+
updated: w.updated || [],
|
|
817
|
+
deleted: w.deleted || []
|
|
812
818
|
},
|
|
813
819
|
state: [...t.values()]
|
|
814
820
|
};
|
|
815
821
|
n.forEach((S) => {
|
|
816
|
-
Pe(S,
|
|
822
|
+
Pe(S, A) && S.onChange(A);
|
|
817
823
|
});
|
|
818
|
-
}, a = (
|
|
819
|
-
if (t.get(
|
|
820
|
-
throw Error(`Cannot add annotation ${
|
|
821
|
-
t.set(
|
|
822
|
-
}, s = (
|
|
823
|
-
const
|
|
824
|
-
if (
|
|
825
|
-
const
|
|
826
|
-
return S ===
|
|
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);
|
|
830
|
+
if (L) {
|
|
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;
|
|
827
833
|
} else
|
|
828
834
|
console.warn(`Cannot update annotation ${S} - does not exist`);
|
|
829
|
-
}, u = (
|
|
830
|
-
const S = Fe(
|
|
831
|
-
|
|
832
|
-
}, f = (
|
|
833
|
-
const
|
|
834
|
-
const
|
|
835
|
-
return
|
|
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;
|
|
836
842
|
}, []);
|
|
837
|
-
|
|
838
|
-
},
|
|
839
|
-
const
|
|
840
|
-
if (
|
|
843
|
+
A.length > 0 && r(w, { updated: A });
|
|
844
|
+
}, m = (b, w = B.LOCAL) => {
|
|
845
|
+
const A = t.get(b.annotation);
|
|
846
|
+
if (A) {
|
|
841
847
|
const S = {
|
|
842
|
-
...
|
|
843
|
-
bodies: [...
|
|
848
|
+
...A,
|
|
849
|
+
bodies: [...A.bodies, b]
|
|
844
850
|
};
|
|
845
|
-
t.set(
|
|
846
|
-
oldValue:
|
|
851
|
+
t.set(A.id, S), e.set(b.id, S.id), r(w, { updated: [{
|
|
852
|
+
oldValue: A,
|
|
847
853
|
newValue: S,
|
|
848
|
-
bodiesCreated: [
|
|
854
|
+
bodiesCreated: [b]
|
|
849
855
|
}] });
|
|
850
856
|
} else
|
|
851
|
-
console.warn(`Attempt to add body to missing annotation: ${
|
|
852
|
-
},
|
|
853
|
-
const
|
|
854
|
-
t.clear(), e.clear(), r(
|
|
855
|
-
},
|
|
856
|
-
if (
|
|
857
|
+
console.warn(`Attempt to add body to missing annotation: ${b.annotation}`);
|
|
858
|
+
}, c = () => [...t.values()], p = (b = B.LOCAL) => {
|
|
859
|
+
const w = [...t.values()];
|
|
860
|
+
t.clear(), e.clear(), r(b, { deleted: w });
|
|
861
|
+
}, g = (b, w = !0, A = B.LOCAL) => {
|
|
862
|
+
if (w) {
|
|
857
863
|
const S = [...t.values()];
|
|
858
|
-
t.clear(), e.clear(),
|
|
859
|
-
t.set(
|
|
860
|
-
}), r(
|
|
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 });
|
|
861
867
|
} else {
|
|
862
|
-
const S =
|
|
863
|
-
const
|
|
864
|
-
return
|
|
868
|
+
const S = b.reduce((L, I) => {
|
|
869
|
+
const H = t.get(I.id);
|
|
870
|
+
return H ? [...L, H] : L;
|
|
865
871
|
}, []);
|
|
866
872
|
if (S.length > 0)
|
|
867
|
-
throw Error(`Bulk insert would overwrite the following annotations: ${S.map((
|
|
868
|
-
|
|
869
|
-
t.set(
|
|
870
|
-
}), r(
|
|
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 });
|
|
871
877
|
}
|
|
872
|
-
}, x = (
|
|
873
|
-
const
|
|
874
|
-
if (
|
|
875
|
-
return t.delete(
|
|
876
|
-
console.warn(`Attempt to delete missing annotation: ${
|
|
877
|
-
}, v = (
|
|
878
|
-
const
|
|
879
|
-
|
|
880
|
-
}, h = (
|
|
881
|
-
const
|
|
882
|
-
const
|
|
883
|
-
return
|
|
878
|
+
}, x = (b) => {
|
|
879
|
+
const w = typeof b == "string" ? b : b.id, A = t.get(w);
|
|
880
|
+
if (A)
|
|
881
|
+
return t.delete(w), A.bodies.forEach((S) => e.delete(S.id)), A;
|
|
882
|
+
console.warn(`Attempt to delete missing annotation: ${w}`);
|
|
883
|
+
}, v = (b, w = B.LOCAL) => {
|
|
884
|
+
const A = x(b);
|
|
885
|
+
A && r(w, { deleted: [A] });
|
|
886
|
+
}, h = (b, w = B.LOCAL) => {
|
|
887
|
+
const A = b.reduce((S, L) => {
|
|
888
|
+
const I = x(L);
|
|
889
|
+
return I ? [...S, I] : S;
|
|
884
890
|
}, []);
|
|
885
|
-
|
|
886
|
-
}, d = (
|
|
887
|
-
const w = t.get(
|
|
891
|
+
A.length > 0 && r(w, { deleted: A });
|
|
892
|
+
}, d = (b) => {
|
|
893
|
+
const w = t.get(b.annotation);
|
|
888
894
|
if (w) {
|
|
889
|
-
const
|
|
890
|
-
if (
|
|
891
|
-
e.delete(
|
|
892
|
-
const
|
|
895
|
+
const A = w.bodies.find((S) => S.id === b.id);
|
|
896
|
+
if (A) {
|
|
897
|
+
e.delete(A.id);
|
|
898
|
+
const S = {
|
|
893
899
|
...w,
|
|
894
|
-
bodies: w.bodies.filter((
|
|
900
|
+
bodies: w.bodies.filter((L) => L.id !== b.id)
|
|
895
901
|
};
|
|
896
|
-
t.set(w.id,
|
|
902
|
+
return t.set(w.id, S), {
|
|
897
903
|
oldValue: w,
|
|
898
|
-
newValue:
|
|
899
|
-
bodiesDeleted: [
|
|
900
|
-
}
|
|
904
|
+
newValue: S,
|
|
905
|
+
bodiesDeleted: [A]
|
|
906
|
+
};
|
|
901
907
|
} else
|
|
902
|
-
console.warn(`Attempt to delete missing body ${
|
|
908
|
+
console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`);
|
|
903
909
|
} else
|
|
904
|
-
console.warn(`Attempt to delete body from missing annotation ${
|
|
905
|
-
},
|
|
906
|
-
const A =
|
|
907
|
-
|
|
908
|
-
}, y = (
|
|
909
|
-
const A =
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
910
|
+
console.warn(`Attempt to delete body from missing annotation ${b.annotation}`);
|
|
911
|
+
}, l = (b, w = B.LOCAL) => {
|
|
912
|
+
const A = d(b);
|
|
913
|
+
A && r(w, { updated: [A] });
|
|
914
|
+
}, y = (b, w = B.LOCAL) => {
|
|
915
|
+
const A = b.map((S) => d(S)).filter(Boolean);
|
|
916
|
+
A.length > 0 && r(w, { updated: A });
|
|
917
|
+
}, T = (b) => {
|
|
918
|
+
const w = t.get(b);
|
|
919
|
+
return w ? { ...w } : void 0;
|
|
920
|
+
}, C = (b) => {
|
|
921
|
+
const w = e.get(b);
|
|
922
|
+
if (w) {
|
|
923
|
+
const A = T(w).bodies.find((S) => S.id === b);
|
|
924
|
+
if (A)
|
|
925
|
+
return A;
|
|
926
|
+
console.error(`Store integrity error: body ${b} in index, but not in annotation`);
|
|
915
927
|
} else
|
|
916
|
-
console.warn(`Attempt to retrieve missing body: ${
|
|
917
|
-
},
|
|
918
|
-
if (
|
|
928
|
+
console.warn(`Attempt to retrieve missing body: ${b}`);
|
|
929
|
+
}, E = (b, w) => {
|
|
930
|
+
if (b.annotation !== w.annotation)
|
|
919
931
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
920
|
-
const
|
|
921
|
-
if (
|
|
922
|
-
const S =
|
|
923
|
-
...
|
|
924
|
-
bodies:
|
|
932
|
+
const A = t.get(b.annotation);
|
|
933
|
+
if (A) {
|
|
934
|
+
const S = A.bodies.find((I) => I.id === b.id), L = {
|
|
935
|
+
...A,
|
|
936
|
+
bodies: A.bodies.map((I) => I.id === S.id ? w : I)
|
|
925
937
|
};
|
|
926
|
-
return t.set(
|
|
927
|
-
oldValue:
|
|
928
|
-
newValue:
|
|
929
|
-
bodiesUpdated: [{ oldBody: S, newBody:
|
|
938
|
+
return t.set(A.id, L), S.id !== w.id && (e.delete(S.id), e.set(w.id, L.id)), {
|
|
939
|
+
oldValue: A,
|
|
940
|
+
newValue: L,
|
|
941
|
+
bodiesUpdated: [{ oldBody: S, newBody: w }]
|
|
930
942
|
};
|
|
931
943
|
} else
|
|
932
|
-
console.warn(`Attempt to add body to missing annotation ${
|
|
933
|
-
},
|
|
934
|
-
const S =
|
|
935
|
-
S && r(
|
|
936
|
-
},
|
|
937
|
-
const
|
|
938
|
-
r(
|
|
939
|
-
},
|
|
940
|
-
const
|
|
941
|
-
if (
|
|
942
|
-
const
|
|
943
|
-
...
|
|
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);
|
|
950
|
+
r(w, { updated: A });
|
|
951
|
+
}, O = (b) => {
|
|
952
|
+
const w = t.get(b.annotation);
|
|
953
|
+
if (w) {
|
|
954
|
+
const A = {
|
|
955
|
+
...w,
|
|
944
956
|
target: {
|
|
945
|
-
...
|
|
946
|
-
...
|
|
957
|
+
...w.target,
|
|
958
|
+
...b
|
|
947
959
|
}
|
|
948
960
|
};
|
|
949
|
-
return t.set(
|
|
950
|
-
oldValue:
|
|
951
|
-
newValue:
|
|
961
|
+
return t.set(w.id, A), {
|
|
962
|
+
oldValue: w,
|
|
963
|
+
newValue: A,
|
|
952
964
|
targetUpdated: {
|
|
953
|
-
oldTarget:
|
|
954
|
-
newTarget:
|
|
965
|
+
oldTarget: w.target,
|
|
966
|
+
newTarget: b
|
|
955
967
|
}
|
|
956
968
|
};
|
|
957
969
|
} else
|
|
958
|
-
console.warn(`Attempt to update target on missing annotation: ${
|
|
970
|
+
console.warn(`Attempt to update target on missing annotation: ${b.annotation}`);
|
|
959
971
|
};
|
|
960
972
|
return {
|
|
961
973
|
addAnnotation: a,
|
|
962
|
-
addBody:
|
|
963
|
-
all:
|
|
964
|
-
bulkAddAnnotation:
|
|
974
|
+
addBody: m,
|
|
975
|
+
all: c,
|
|
976
|
+
bulkAddAnnotation: g,
|
|
965
977
|
bulkDeleteAnnotation: h,
|
|
978
|
+
bulkDeleteBodies: y,
|
|
966
979
|
bulkUpdateAnnotation: f,
|
|
967
|
-
bulkUpdateBodies:
|
|
968
|
-
bulkUpdateTargets: (
|
|
969
|
-
const
|
|
970
|
-
|
|
980
|
+
bulkUpdateBodies: R,
|
|
981
|
+
bulkUpdateTargets: (b, w = B.LOCAL) => {
|
|
982
|
+
const A = b.map((S) => O(S)).filter(Boolean);
|
|
983
|
+
A.length > 0 && r(w, { updated: A });
|
|
971
984
|
},
|
|
972
|
-
clear:
|
|
985
|
+
clear: p,
|
|
973
986
|
deleteAnnotation: v,
|
|
974
|
-
deleteBody:
|
|
975
|
-
getAnnotation:
|
|
976
|
-
getBody:
|
|
987
|
+
deleteBody: l,
|
|
988
|
+
getAnnotation: T,
|
|
989
|
+
getBody: C,
|
|
977
990
|
observe: o,
|
|
978
991
|
unobserve: i,
|
|
979
992
|
updateAnnotation: u,
|
|
980
|
-
updateBody:
|
|
981
|
-
updateTarget: (
|
|
982
|
-
const
|
|
983
|
-
|
|
993
|
+
updateBody: N,
|
|
994
|
+
updateTarget: (b, w = B.LOCAL) => {
|
|
995
|
+
const A = O(b);
|
|
996
|
+
A && r(w, { updated: [A] });
|
|
984
997
|
}
|
|
985
998
|
};
|
|
986
999
|
};
|
|
@@ -1001,9 +1014,9 @@ let qe = () => ({
|
|
|
1001
1014
|
const je = 250, Ge = (t) => {
|
|
1002
1015
|
const e = qe(), n = [];
|
|
1003
1016
|
let o = -1, i = !1, r = 0;
|
|
1004
|
-
const a = (
|
|
1017
|
+
const a = (g) => {
|
|
1005
1018
|
if (!i) {
|
|
1006
|
-
const { changes: x } =
|
|
1019
|
+
const { changes: x } = g, v = performance.now();
|
|
1007
1020
|
if (v - r > je)
|
|
1008
1021
|
n.splice(o + 1), n.push(x), o = n.length - 1;
|
|
1009
1022
|
else {
|
|
@@ -1014,50 +1027,50 @@ const je = 250, Ge = (t) => {
|
|
|
1014
1027
|
}
|
|
1015
1028
|
i = !1;
|
|
1016
1029
|
};
|
|
1017
|
-
t.observe(a, { origin:
|
|
1018
|
-
const s = (
|
|
1030
|
+
t.observe(a, { origin: B.LOCAL });
|
|
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);
|
|
1019
1032
|
return {
|
|
1020
1033
|
canRedo: () => n.length - 1 > o,
|
|
1021
1034
|
canUndo: () => o > -1,
|
|
1022
1035
|
destroy: () => t.unobserve(a),
|
|
1023
|
-
on: (
|
|
1036
|
+
on: (g, x) => e.on(g, x),
|
|
1024
1037
|
redo: () => {
|
|
1025
1038
|
if (n.length - 1 > o) {
|
|
1026
1039
|
i = !0;
|
|
1027
|
-
const { created:
|
|
1028
|
-
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;
|
|
1029
1042
|
}
|
|
1030
1043
|
},
|
|
1031
1044
|
undo: () => {
|
|
1032
1045
|
if (o > -1) {
|
|
1033
1046
|
i = !0;
|
|
1034
|
-
const { created:
|
|
1035
|
-
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;
|
|
1036
1049
|
}
|
|
1037
1050
|
}
|
|
1038
1051
|
};
|
|
1039
1052
|
}, Ke = () => {
|
|
1040
|
-
const { subscribe: t, set: e } =
|
|
1053
|
+
const { subscribe: t, set: e } = bt([]);
|
|
1041
1054
|
return {
|
|
1042
1055
|
subscribe: t,
|
|
1043
1056
|
set: e
|
|
1044
1057
|
};
|
|
1045
1058
|
}, Qe = (t, e, n, o) => {
|
|
1046
1059
|
const { store: i, selection: r, hover: a, viewport: s } = t, u = /* @__PURE__ */ new Map();
|
|
1047
|
-
let f = [],
|
|
1048
|
-
const
|
|
1060
|
+
let f = [], m;
|
|
1061
|
+
const c = (v, h) => {
|
|
1049
1062
|
u.has(v) ? u.get(v).push(h) : u.set(v, [h]);
|
|
1050
|
-
},
|
|
1063
|
+
}, p = (v, h) => {
|
|
1051
1064
|
const d = u.get(v);
|
|
1052
1065
|
d && d.indexOf(h) > 0 && d.splice(d.indexOf(h), 1);
|
|
1053
|
-
},
|
|
1066
|
+
}, g = (v, h, d) => {
|
|
1054
1067
|
u.has(v) && setTimeout(() => {
|
|
1055
|
-
u.get(v).forEach((
|
|
1068
|
+
u.get(v).forEach((l) => {
|
|
1056
1069
|
if (n) {
|
|
1057
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;
|
|
1058
|
-
|
|
1071
|
+
l(y, T);
|
|
1059
1072
|
} else
|
|
1060
|
-
|
|
1073
|
+
l(h, d);
|
|
1061
1074
|
});
|
|
1062
1075
|
}, 1);
|
|
1063
1076
|
};
|
|
@@ -1068,45 +1081,45 @@ const je = 250, Ge = (t) => {
|
|
|
1068
1081
|
else if (f.length > 0 && v.length === 0)
|
|
1069
1082
|
f.forEach((h) => {
|
|
1070
1083
|
const d = i.getAnnotation(h.id);
|
|
1071
|
-
d && !
|
|
1084
|
+
d && !q(d, h) && g("updateAnnotation", d, h);
|
|
1072
1085
|
}), f = [];
|
|
1073
1086
|
else {
|
|
1074
|
-
const h = new Set(f.map((
|
|
1075
|
-
f.filter((
|
|
1076
|
-
const y = i.getAnnotation(
|
|
1077
|
-
y && !
|
|
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);
|
|
1078
1091
|
}), f = [
|
|
1079
1092
|
// Remove annotations that were deselected
|
|
1080
|
-
...f.filter((
|
|
1093
|
+
...f.filter((l) => d.has(l.id)),
|
|
1081
1094
|
// Add editable annotations that were selected
|
|
1082
|
-
...v.filter(({ id:
|
|
1095
|
+
...v.filter(({ id: l }) => !h.has(l)).map(({ id: l }) => i.getAnnotation(l))
|
|
1083
1096
|
];
|
|
1084
1097
|
}
|
|
1085
|
-
|
|
1098
|
+
g("selectionChanged", f);
|
|
1086
1099
|
}
|
|
1087
1100
|
}), a.subscribe((v) => {
|
|
1088
|
-
!
|
|
1089
|
-
}), s == null || s.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) => {
|
|
1090
1103
|
const { created: h, deleted: d } = v.changes;
|
|
1091
|
-
(h || []).forEach((
|
|
1092
|
-
...
|
|
1093
|
-
...
|
|
1094
|
-
...
|
|
1095
|
-
].length > 0).forEach(({ oldValue:
|
|
1096
|
-
const T = f.find((C) => C.id ===
|
|
1097
|
-
f = f.map((C) => C.id ===
|
|
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);
|
|
1098
1111
|
});
|
|
1099
|
-
}, { origin:
|
|
1112
|
+
}, { origin: B.LOCAL }), i.observe((v) => {
|
|
1100
1113
|
if (f) {
|
|
1101
|
-
const h = new Set(f.map((
|
|
1102
|
-
d.length > 0 && (f = f.map((
|
|
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));
|
|
1103
1116
|
}
|
|
1104
|
-
}, { origin:
|
|
1117
|
+
}, { origin: B.REMOTE });
|
|
1105
1118
|
const x = (v) => (h) => {
|
|
1106
1119
|
const { updated: d } = h;
|
|
1107
|
-
v ? (d || []).forEach((
|
|
1120
|
+
v ? (d || []).forEach((l) => g("updateAnnotation", l.oldValue, l.newValue)) : (d || []).forEach((l) => g("updateAnnotation", l.newValue, l.oldValue));
|
|
1108
1121
|
};
|
|
1109
|
-
return e.on("undo", x(!0)), e.on("redo", x(!1)), { on:
|
|
1122
|
+
return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: c, off: p, emit: g };
|
|
1110
1123
|
}, Je = (t) => (e) => e.reduce((n, o) => {
|
|
1111
1124
|
const { parsed: i, error: r } = t.parse(o);
|
|
1112
1125
|
return r ? {
|
|
@@ -1121,18 +1134,18 @@ const je = 250, Ge = (t) => {
|
|
|
1121
1134
|
}, { parsed: [], failed: [] }), Ze = (t, e, n) => {
|
|
1122
1135
|
const { store: o, selection: i } = t, r = (h) => {
|
|
1123
1136
|
if (n) {
|
|
1124
|
-
const { parsed: d, error:
|
|
1125
|
-
d ? o.addAnnotation(d,
|
|
1137
|
+
const { parsed: d, error: l } = n.parse(h);
|
|
1138
|
+
d ? o.addAnnotation(d, B.REMOTE) : console.error(l);
|
|
1126
1139
|
} else
|
|
1127
|
-
o.addAnnotation(h,
|
|
1140
|
+
o.addAnnotation(h, B.REMOTE);
|
|
1128
1141
|
}, a = () => i.clear(), s = () => o.clear(), u = (h) => {
|
|
1129
1142
|
const d = o.getAnnotation(h);
|
|
1130
1143
|
return n && d ? n.serialize(d) : d;
|
|
1131
|
-
}, f = () => n ? o.all().map(n.serialize) : o.all(),
|
|
1144
|
+
}, f = () => n ? o.all().map(n.serialize) : o.all(), m = () => {
|
|
1132
1145
|
var h;
|
|
1133
|
-
const d = (((h = i.selected) == null ? void 0 : h.map((
|
|
1146
|
+
const d = (((h = i.selected) == null ? void 0 : h.map((l) => l.id)) || []).map((l) => o.getAnnotation(l)).filter(Boolean);
|
|
1134
1147
|
return n ? d.map(n.serialize) : d;
|
|
1135
|
-
},
|
|
1148
|
+
}, c = (h, d = !0) => fetch(h).then((l) => l.json()).then((l) => (g(l, d), l)), p = (h) => {
|
|
1136
1149
|
if (typeof h == "string") {
|
|
1137
1150
|
const d = o.getAnnotation(h);
|
|
1138
1151
|
if (o.deleteAnnotation(h), d)
|
|
@@ -1142,18 +1155,18 @@ const je = 250, Ge = (t) => {
|
|
|
1142
1155
|
if (d)
|
|
1143
1156
|
return o.deleteAnnotation(d), h;
|
|
1144
1157
|
}
|
|
1145
|
-
},
|
|
1158
|
+
}, g = (h, d = !0) => {
|
|
1146
1159
|
if (n) {
|
|
1147
|
-
const { parsed:
|
|
1148
|
-
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);
|
|
1149
1162
|
} else
|
|
1150
|
-
o.bulkAddAnnotation(h, d,
|
|
1163
|
+
o.bulkAddAnnotation(h, d, B.REMOTE);
|
|
1151
1164
|
}, x = (h) => {
|
|
1152
1165
|
h ? i.setSelected(h) : i.clear();
|
|
1153
1166
|
}, v = (h) => {
|
|
1154
1167
|
if (n) {
|
|
1155
|
-
const d = n.parse(h).parsed,
|
|
1156
|
-
return o.updateAnnotation(d),
|
|
1168
|
+
const d = n.parse(h).parsed, l = n.serialize(o.getAnnotation(d.id));
|
|
1169
|
+
return o.updateAnnotation(d), l;
|
|
1157
1170
|
} else {
|
|
1158
1171
|
const d = o.getAnnotation(h.id);
|
|
1159
1172
|
return o.updateAnnotation(h), d;
|
|
@@ -1167,11 +1180,11 @@ const je = 250, Ge = (t) => {
|
|
|
1167
1180
|
clearAnnotations: s,
|
|
1168
1181
|
getAnnotationById: u,
|
|
1169
1182
|
getAnnotations: f,
|
|
1170
|
-
getSelected:
|
|
1171
|
-
loadAnnotations:
|
|
1183
|
+
getSelected: m,
|
|
1184
|
+
loadAnnotations: c,
|
|
1172
1185
|
redo: e.redo,
|
|
1173
|
-
removeAnnotation:
|
|
1174
|
-
setAnnotations:
|
|
1186
|
+
removeAnnotation: p,
|
|
1187
|
+
setAnnotations: g,
|
|
1175
1188
|
setSelected: x,
|
|
1176
1189
|
undo: e.undo,
|
|
1177
1190
|
updateAnnotation: v
|
|
@@ -1202,22 +1215,27 @@ const sn = () => ({ isGuest: !0, id: on("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
1202
1215
|
n = (n << 5) - n + r, n |= 0;
|
|
1203
1216
|
}
|
|
1204
1217
|
return `${n}`;
|
|
1205
|
-
},
|
|
1206
|
-
const { id: o, type: i, purpose: r, value: a, created: s,
|
|
1218
|
+
}, Ht = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, cn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
|
|
1219
|
+
const { id: o, type: i, purpose: r, value: a, created: s, modified: u, creator: f, ...m } = n;
|
|
1207
1220
|
return {
|
|
1208
1221
|
id: o || `temp-${an(n)}`,
|
|
1209
1222
|
annotation: e,
|
|
1210
1223
|
type: i,
|
|
1211
1224
|
purpose: r,
|
|
1212
1225
|
value: a,
|
|
1226
|
+
creator: Ht(f),
|
|
1213
1227
|
created: s ? new Date(s) : void 0,
|
|
1214
|
-
|
|
1215
|
-
...
|
|
1228
|
+
updated: u ? new Date(u) : void 0,
|
|
1229
|
+
...m
|
|
1216
1230
|
};
|
|
1217
|
-
}),
|
|
1218
|
-
var n
|
|
1219
|
-
const i
|
|
1220
|
-
|
|
1231
|
+
}), ln = (t) => t.map((e) => {
|
|
1232
|
+
var n;
|
|
1233
|
+
const { annotation: o, created: i, updated: r, ...a } = e, s = {
|
|
1234
|
+
...a,
|
|
1235
|
+
created: i == null ? void 0 : i.toISOString(),
|
|
1236
|
+
modified: r == null ? void 0 : r.toISOString()
|
|
1237
|
+
};
|
|
1238
|
+
return (n = s.id) != null && n.startsWith("temp-") && delete s.id, s;
|
|
1221
1239
|
});
|
|
1222
1240
|
rn();
|
|
1223
1241
|
const In = (t, e) => ({
|
|
@@ -1231,43 +1249,43 @@ const In = (t, e) => ({
|
|
|
1231
1249
|
modified: i,
|
|
1232
1250
|
target: r
|
|
1233
1251
|
} = t, a = Array.isArray(r) ? r : [r], s = {
|
|
1234
|
-
creator:
|
|
1252
|
+
creator: Ht(n),
|
|
1235
1253
|
created: o ? new Date(o) : void 0,
|
|
1236
1254
|
updated: i ? new Date(i) : void 0,
|
|
1237
1255
|
annotation: e,
|
|
1238
1256
|
selector: []
|
|
1239
1257
|
};
|
|
1240
1258
|
for (const u of a) {
|
|
1241
|
-
const
|
|
1242
|
-
switch (
|
|
1259
|
+
const m = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((c, p) => {
|
|
1260
|
+
switch (p.type) {
|
|
1243
1261
|
case "TextQuoteSelector":
|
|
1244
|
-
|
|
1262
|
+
c.quote = p.exact;
|
|
1245
1263
|
break;
|
|
1246
1264
|
case "TextPositionSelector":
|
|
1247
|
-
|
|
1265
|
+
c.start = p.start, c.end = p.end;
|
|
1248
1266
|
break;
|
|
1249
1267
|
}
|
|
1250
|
-
return
|
|
1268
|
+
return c;
|
|
1251
1269
|
}, {});
|
|
1252
|
-
if (dn(
|
|
1253
|
-
s.selector.push({ id: u.id, ...
|
|
1270
|
+
if (dn(m))
|
|
1271
|
+
s.selector.push({ id: u.id, ...m });
|
|
1254
1272
|
else {
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1257
|
-
|
|
1273
|
+
const c = [
|
|
1274
|
+
m.start ? void 0 : "TextPositionSelector",
|
|
1275
|
+
m.quote ? void 0 : "TextQuoteSelector"
|
|
1258
1276
|
].filter(Boolean);
|
|
1259
|
-
return { error: Error(`Missing selector types: ${
|
|
1277
|
+
return { error: Error(`Missing selector types: ${c.join(" and ")} for annotation: ${t.id}`) };
|
|
1260
1278
|
}
|
|
1261
1279
|
}
|
|
1262
1280
|
return { parsed: s };
|
|
1263
1281
|
}, hn = (t) => {
|
|
1264
|
-
const e = t.id ||
|
|
1282
|
+
const e = t.id || kt(), {
|
|
1265
1283
|
creator: n,
|
|
1266
1284
|
created: o,
|
|
1267
1285
|
modified: i,
|
|
1268
1286
|
body: r,
|
|
1269
1287
|
...a
|
|
1270
|
-
} = t, s =
|
|
1288
|
+
} = t, s = cn(r, e), u = un(t);
|
|
1271
1289
|
return "error" in u ? { error: u.error } : {
|
|
1272
1290
|
parsed: {
|
|
1273
1291
|
...a,
|
|
@@ -1282,21 +1300,21 @@ const In = (t, e) => ({
|
|
|
1282
1300
|
creator: s,
|
|
1283
1301
|
created: u,
|
|
1284
1302
|
updated: f,
|
|
1285
|
-
...
|
|
1286
|
-
} = i,
|
|
1287
|
-
const { quote:
|
|
1303
|
+
...m
|
|
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 = [{
|
|
1288
1306
|
type: "TextQuoteSelector",
|
|
1289
|
-
exact:
|
|
1307
|
+
exact: g,
|
|
1290
1308
|
prefix: d,
|
|
1291
|
-
suffix:
|
|
1309
|
+
suffix: l
|
|
1292
1310
|
}, {
|
|
1293
1311
|
type: "TextPositionSelector",
|
|
1294
1312
|
start: x,
|
|
1295
1313
|
end: v
|
|
1296
1314
|
}];
|
|
1297
1315
|
return {
|
|
1298
|
-
...
|
|
1299
|
-
id:
|
|
1316
|
+
...m,
|
|
1317
|
+
id: p.id,
|
|
1300
1318
|
source: e,
|
|
1301
1319
|
selector: y
|
|
1302
1320
|
};
|
|
@@ -1306,37 +1324,37 @@ const In = (t, e) => ({
|
|
|
1306
1324
|
"@context": "http://www.w3.org/ns/anno.jsonld",
|
|
1307
1325
|
id: t.id,
|
|
1308
1326
|
type: "Annotation",
|
|
1309
|
-
body:
|
|
1327
|
+
body: ln(t.bodies),
|
|
1310
1328
|
creator: s,
|
|
1311
1329
|
created: u == null ? void 0 : u.toISOString(),
|
|
1312
1330
|
modified: f == null ? void 0 : f.toISOString(),
|
|
1313
|
-
target:
|
|
1331
|
+
target: c
|
|
1314
1332
|
};
|
|
1315
1333
|
};
|
|
1316
|
-
function
|
|
1317
|
-
|
|
1334
|
+
function gn(t, e, n, o, i) {
|
|
1335
|
+
$t(t, e, n || 0, o || t.length - 1, i || pn);
|
|
1318
1336
|
}
|
|
1319
|
-
function
|
|
1337
|
+
function $t(t, e, n, o, i) {
|
|
1320
1338
|
for (; o > n; ) {
|
|
1321
1339
|
if (o - n > 600) {
|
|
1322
|
-
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),
|
|
1323
|
-
|
|
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));
|
|
1341
|
+
$t(t, e, m, c, i);
|
|
1324
1342
|
}
|
|
1325
|
-
var
|
|
1326
|
-
for (
|
|
1327
|
-
for (
|
|
1328
|
-
|
|
1329
|
-
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; )
|
|
1330
1348
|
x--;
|
|
1331
1349
|
}
|
|
1332
|
-
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);
|
|
1333
1351
|
}
|
|
1334
1352
|
}
|
|
1335
|
-
function
|
|
1353
|
+
function j(t, e, n) {
|
|
1336
1354
|
var o = t[e];
|
|
1337
1355
|
t[e] = t[n], t[n] = o;
|
|
1338
1356
|
}
|
|
1339
|
-
function
|
|
1357
|
+
function pn(t, e) {
|
|
1340
1358
|
return t < e ? -1 : t > e ? 1 : 0;
|
|
1341
1359
|
}
|
|
1342
1360
|
class mn {
|
|
@@ -1349,13 +1367,13 @@ class mn {
|
|
|
1349
1367
|
search(e) {
|
|
1350
1368
|
let n = this.data;
|
|
1351
1369
|
const o = [];
|
|
1352
|
-
if (!
|
|
1370
|
+
if (!nt(e, n))
|
|
1353
1371
|
return o;
|
|
1354
1372
|
const i = this.toBBox, r = [];
|
|
1355
1373
|
for (; n; ) {
|
|
1356
1374
|
for (let a = 0; a < n.children.length; a++) {
|
|
1357
1375
|
const s = n.children[a], u = n.leaf ? i(s) : s;
|
|
1358
|
-
|
|
1376
|
+
nt(e, u) && (n.leaf ? o.push(s) : ht(e, u) ? this._all(s, o) : r.push(s));
|
|
1359
1377
|
}
|
|
1360
1378
|
n = r.pop();
|
|
1361
1379
|
}
|
|
@@ -1363,14 +1381,14 @@ class mn {
|
|
|
1363
1381
|
}
|
|
1364
1382
|
collides(e) {
|
|
1365
1383
|
let n = this.data;
|
|
1366
|
-
if (!
|
|
1384
|
+
if (!nt(e, n))
|
|
1367
1385
|
return !1;
|
|
1368
1386
|
const o = [];
|
|
1369
1387
|
for (; n; ) {
|
|
1370
1388
|
for (let i = 0; i < n.children.length; i++) {
|
|
1371
1389
|
const r = n.children[i], a = n.leaf ? this.toBBox(r) : r;
|
|
1372
|
-
if (
|
|
1373
|
-
if (n.leaf ||
|
|
1390
|
+
if (nt(e, a)) {
|
|
1391
|
+
if (n.leaf || ht(e, a))
|
|
1374
1392
|
return !0;
|
|
1375
1393
|
o.push(r);
|
|
1376
1394
|
}
|
|
@@ -1405,7 +1423,7 @@ class mn {
|
|
|
1405
1423
|
return e && this._insert(e, this.data.height - 1), this;
|
|
1406
1424
|
}
|
|
1407
1425
|
clear() {
|
|
1408
|
-
return this.data =
|
|
1426
|
+
return this.data = W([]), this;
|
|
1409
1427
|
}
|
|
1410
1428
|
remove(e, n) {
|
|
1411
1429
|
if (!e)
|
|
@@ -1415,11 +1433,11 @@ class mn {
|
|
|
1415
1433
|
let s, u, f;
|
|
1416
1434
|
for (; o || r.length; ) {
|
|
1417
1435
|
if (o || (o = r.pop(), u = r[r.length - 1], s = a.pop(), f = !0), o.leaf) {
|
|
1418
|
-
const
|
|
1419
|
-
if (
|
|
1420
|
-
return o.children.splice(
|
|
1436
|
+
const m = bn(e, o.children, n);
|
|
1437
|
+
if (m !== -1)
|
|
1438
|
+
return o.children.splice(m, 1), r.push(o), this._condense(r), this;
|
|
1421
1439
|
}
|
|
1422
|
-
!f && !o.leaf &&
|
|
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;
|
|
1423
1441
|
}
|
|
1424
1442
|
return this;
|
|
1425
1443
|
}
|
|
@@ -1448,26 +1466,26 @@ class mn {
|
|
|
1448
1466
|
const r = o - n + 1;
|
|
1449
1467
|
let a = this._maxEntries, s;
|
|
1450
1468
|
if (r <= a)
|
|
1451
|
-
return s =
|
|
1452
|
-
i || (i = Math.ceil(Math.log(r) / Math.log(a)), a = Math.ceil(r / Math.pow(a, i - 1))), s =
|
|
1469
|
+
return s = W(e.slice(n, o + 1)), F(s, this.toBBox), s;
|
|
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;
|
|
1453
1471
|
const u = Math.ceil(r / a), f = u * Math.ceil(Math.sqrt(a));
|
|
1454
|
-
|
|
1455
|
-
for (let
|
|
1456
|
-
const
|
|
1457
|
-
|
|
1458
|
-
for (let
|
|
1459
|
-
const
|
|
1460
|
-
s.children.push(this._build(e,
|
|
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);
|
|
1475
|
+
It(e, m, c, u, this.compareMinY);
|
|
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));
|
|
1461
1479
|
}
|
|
1462
1480
|
}
|
|
1463
|
-
return
|
|
1481
|
+
return F(s, this.toBBox), s;
|
|
1464
1482
|
}
|
|
1465
1483
|
_chooseSubtree(e, n, o, i) {
|
|
1466
1484
|
for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
|
|
1467
1485
|
let r = 1 / 0, a = 1 / 0, s;
|
|
1468
1486
|
for (let u = 0; u < n.children.length; u++) {
|
|
1469
|
-
const f = n.children[u],
|
|
1470
|
-
|
|
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);
|
|
1471
1489
|
}
|
|
1472
1490
|
n = s || n.children[0];
|
|
1473
1491
|
}
|
|
@@ -1475,7 +1493,7 @@ class mn {
|
|
|
1475
1493
|
}
|
|
1476
1494
|
_insert(e, n, o) {
|
|
1477
1495
|
const i = o ? e : this.toBBox(e), r = [], a = this._chooseSubtree(i, this.data, n, r);
|
|
1478
|
-
for (a.children.push(e),
|
|
1496
|
+
for (a.children.push(e), K(a, i); n >= 0 && r[n].children.length > this._maxEntries; )
|
|
1479
1497
|
this._split(r, n), n--;
|
|
1480
1498
|
this._adjustParentBBoxes(i, r, n);
|
|
1481
1499
|
}
|
|
@@ -1483,17 +1501,17 @@ class mn {
|
|
|
1483
1501
|
_split(e, n) {
|
|
1484
1502
|
const o = e[n], i = o.children.length, r = this._minEntries;
|
|
1485
1503
|
this._chooseSplitAxis(o, r, i);
|
|
1486
|
-
const a = this._chooseSplitIndex(o, r, i), s =
|
|
1487
|
-
s.height = o.height, s.leaf = o.leaf,
|
|
1504
|
+
const a = this._chooseSplitIndex(o, r, i), s = W(o.children.splice(a, o.children.length - a));
|
|
1505
|
+
s.height = o.height, s.leaf = o.leaf, F(o, this.toBBox), F(s, this.toBBox), n ? e[n - 1].children.push(s) : this._splitRoot(o, s);
|
|
1488
1506
|
}
|
|
1489
1507
|
_splitRoot(e, n) {
|
|
1490
|
-
this.data =
|
|
1508
|
+
this.data = W([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, F(this.data, this.toBBox);
|
|
1491
1509
|
}
|
|
1492
1510
|
_chooseSplitIndex(e, n, o) {
|
|
1493
1511
|
let i, r = 1 / 0, a = 1 / 0;
|
|
1494
1512
|
for (let s = n; s <= o - n; s++) {
|
|
1495
|
-
const u =
|
|
1496
|
-
|
|
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);
|
|
1514
|
+
m < r ? (r = m, i = s, a = c < a ? c : a) : m === r && c < a && (a = c, i = s);
|
|
1497
1515
|
}
|
|
1498
1516
|
return i || o - n;
|
|
1499
1517
|
}
|
|
@@ -1505,25 +1523,25 @@ class mn {
|
|
|
1505
1523
|
// total margin of all possible split distributions where each node is at least m full
|
|
1506
1524
|
_allDistMargin(e, n, o, i) {
|
|
1507
1525
|
e.children.sort(i);
|
|
1508
|
-
const r = this.toBBox, a =
|
|
1509
|
-
let u =
|
|
1526
|
+
const r = this.toBBox, a = G(e, 0, n, r), s = G(e, o - n, o, r);
|
|
1527
|
+
let u = et(a) + et(s);
|
|
1510
1528
|
for (let f = n; f < o - n; f++) {
|
|
1511
|
-
const
|
|
1512
|
-
|
|
1529
|
+
const m = e.children[f];
|
|
1530
|
+
K(a, e.leaf ? r(m) : m), u += et(a);
|
|
1513
1531
|
}
|
|
1514
1532
|
for (let f = o - n - 1; f >= n; f--) {
|
|
1515
|
-
const
|
|
1516
|
-
|
|
1533
|
+
const m = e.children[f];
|
|
1534
|
+
K(s, e.leaf ? r(m) : m), u += et(s);
|
|
1517
1535
|
}
|
|
1518
1536
|
return u;
|
|
1519
1537
|
}
|
|
1520
1538
|
_adjustParentBBoxes(e, n, o) {
|
|
1521
1539
|
for (let i = o; i >= 0; i--)
|
|
1522
|
-
|
|
1540
|
+
K(n[i], e);
|
|
1523
1541
|
}
|
|
1524
1542
|
_condense(e) {
|
|
1525
1543
|
for (let n = e.length - 1, o; n >= 0; n--)
|
|
1526
|
-
e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() :
|
|
1544
|
+
e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : F(e[n], this.toBBox);
|
|
1527
1545
|
}
|
|
1528
1546
|
}
|
|
1529
1547
|
function bn(t, e, n) {
|
|
@@ -1534,18 +1552,18 @@ function bn(t, e, n) {
|
|
|
1534
1552
|
return o;
|
|
1535
1553
|
return -1;
|
|
1536
1554
|
}
|
|
1537
|
-
function
|
|
1538
|
-
|
|
1555
|
+
function F(t, e) {
|
|
1556
|
+
G(t, 0, t.children.length, e, t);
|
|
1539
1557
|
}
|
|
1540
|
-
function
|
|
1541
|
-
i || (i =
|
|
1558
|
+
function G(t, e, n, o, i) {
|
|
1559
|
+
i || (i = W(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
|
|
1542
1560
|
for (let r = e; r < n; r++) {
|
|
1543
1561
|
const a = t.children[r];
|
|
1544
|
-
|
|
1562
|
+
K(i, t.leaf ? o(a) : a);
|
|
1545
1563
|
}
|
|
1546
1564
|
return i;
|
|
1547
1565
|
}
|
|
1548
|
-
function
|
|
1566
|
+
function K(t, e) {
|
|
1549
1567
|
return t.minX = Math.min(t.minX, e.minX), t.minY = Math.min(t.minY, e.minY), t.maxX = Math.max(t.maxX, e.maxX), t.maxY = Math.max(t.maxY, e.maxY), t;
|
|
1550
1568
|
}
|
|
1551
1569
|
function vn(t, e) {
|
|
@@ -1554,10 +1572,10 @@ function vn(t, e) {
|
|
|
1554
1572
|
function yn(t, e) {
|
|
1555
1573
|
return t.minY - e.minY;
|
|
1556
1574
|
}
|
|
1557
|
-
function
|
|
1575
|
+
function ut(t) {
|
|
1558
1576
|
return (t.maxX - t.minX) * (t.maxY - t.minY);
|
|
1559
1577
|
}
|
|
1560
|
-
function
|
|
1578
|
+
function et(t) {
|
|
1561
1579
|
return t.maxX - t.minX + (t.maxY - t.minY);
|
|
1562
1580
|
}
|
|
1563
1581
|
function wn(t, e) {
|
|
@@ -1567,13 +1585,13 @@ function xn(t, e) {
|
|
|
1567
1585
|
const n = Math.max(t.minX, e.minX), o = Math.max(t.minY, e.minY), i = Math.min(t.maxX, e.maxX), r = Math.min(t.maxY, e.maxY);
|
|
1568
1586
|
return Math.max(0, i - n) * Math.max(0, r - o);
|
|
1569
1587
|
}
|
|
1570
|
-
function
|
|
1588
|
+
function ht(t, e) {
|
|
1571
1589
|
return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
|
|
1572
1590
|
}
|
|
1573
|
-
function
|
|
1591
|
+
function nt(t, e) {
|
|
1574
1592
|
return e.minX <= t.maxX && e.minY <= t.maxY && e.maxX >= t.minX && e.maxY >= t.minY;
|
|
1575
1593
|
}
|
|
1576
|
-
function
|
|
1594
|
+
function W(t) {
|
|
1577
1595
|
return {
|
|
1578
1596
|
children: t,
|
|
1579
1597
|
height: 1,
|
|
@@ -1584,28 +1602,28 @@ function z(t) {
|
|
|
1584
1602
|
maxY: -1 / 0
|
|
1585
1603
|
};
|
|
1586
1604
|
}
|
|
1587
|
-
function
|
|
1605
|
+
function It(t, e, n, o, i) {
|
|
1588
1606
|
const r = [e, n];
|
|
1589
1607
|
for (; r.length; ) {
|
|
1590
1608
|
if (n = r.pop(), e = r.pop(), n - e <= o)
|
|
1591
1609
|
continue;
|
|
1592
1610
|
const a = e + Math.ceil((n - e) / o / 2) * o;
|
|
1593
|
-
|
|
1611
|
+
gn(t, a, e, n, i), r.push(e, a, a, n);
|
|
1594
1612
|
}
|
|
1595
1613
|
}
|
|
1596
1614
|
const An = (t, e) => {
|
|
1597
|
-
const n = new mn(), o = /* @__PURE__ */ new Map(), i = (d,
|
|
1615
|
+
const n = new mn(), o = /* @__PURE__ */ new Map(), i = (d, l) => {
|
|
1598
1616
|
const y = d.selector.flatMap((C) => {
|
|
1599
|
-
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 :
|
|
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;
|
|
1600
1618
|
return Array.from(N.getClientRects());
|
|
1601
|
-
}), T = oe(y).map(({ left: C, top: E, right: N, bottom:
|
|
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));
|
|
1602
1620
|
return T.map((C) => {
|
|
1603
|
-
const { x: E, y: N, width:
|
|
1621
|
+
const { x: E, y: N, width: R, height: O } = C;
|
|
1604
1622
|
return {
|
|
1605
1623
|
minX: E,
|
|
1606
1624
|
minY: N,
|
|
1607
|
-
maxX: E +
|
|
1608
|
-
maxY: N +
|
|
1625
|
+
maxX: E + R,
|
|
1626
|
+
maxY: N + O,
|
|
1609
1627
|
annotation: {
|
|
1610
1628
|
id: d.annotation,
|
|
1611
1629
|
rects: T
|
|
@@ -1615,88 +1633,88 @@ const An = (t, e) => {
|
|
|
1615
1633
|
}, r = () => [...o.values()], a = () => {
|
|
1616
1634
|
n.clear(), o.clear();
|
|
1617
1635
|
}, s = (d) => {
|
|
1618
|
-
const
|
|
1619
|
-
|
|
1636
|
+
const l = i(d, e.getBoundingClientRect());
|
|
1637
|
+
l.forEach((y) => n.insert(y)), o.set(d.annotation, l);
|
|
1620
1638
|
}, u = (d) => {
|
|
1621
|
-
const
|
|
1622
|
-
|
|
1639
|
+
const l = o.get(d.annotation);
|
|
1640
|
+
l && (l.forEach((y) => n.remove(y)), o.delete(d.annotation));
|
|
1623
1641
|
}, f = (d) => {
|
|
1624
1642
|
u(d), s(d);
|
|
1625
|
-
},
|
|
1626
|
-
|
|
1643
|
+
}, m = (d, l = !0) => {
|
|
1644
|
+
l && a();
|
|
1627
1645
|
const y = e.getBoundingClientRect(), T = d.map((E) => ({ target: E, rects: i(E, y) }));
|
|
1628
1646
|
T.forEach(({ target: E, rects: N }) => o.set(E.annotation, N));
|
|
1629
1647
|
const C = T.reduce((E, { rects: N }) => [...E, ...N], []);
|
|
1630
1648
|
n.load(C);
|
|
1631
|
-
},
|
|
1649
|
+
}, c = (d, l) => {
|
|
1632
1650
|
const y = n.search({
|
|
1633
1651
|
minX: d,
|
|
1634
|
-
minY:
|
|
1652
|
+
minY: l,
|
|
1635
1653
|
maxX: d,
|
|
1636
|
-
maxY:
|
|
1654
|
+
maxY: l
|
|
1637
1655
|
}), T = (C) => C.annotation.rects.reduce((E, N) => E + N.width * N.height, 0);
|
|
1638
1656
|
if (y.length > 0)
|
|
1639
1657
|
return y.sort((C, E) => T(C) - T(E)), y[0].annotation.id;
|
|
1640
|
-
},
|
|
1641
|
-
const
|
|
1642
|
-
if (
|
|
1658
|
+
}, p = (d) => {
|
|
1659
|
+
const l = g(d);
|
|
1660
|
+
if (l.length === 0)
|
|
1643
1661
|
return;
|
|
1644
|
-
let y =
|
|
1645
|
-
for (let N = 1; N <
|
|
1646
|
-
const
|
|
1647
|
-
y = Math.min(y,
|
|
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);
|
|
1648
1666
|
}
|
|
1649
1667
|
return new DOMRect(y, T, C - y, E - T);
|
|
1650
|
-
},
|
|
1651
|
-
const
|
|
1652
|
-
return
|
|
1668
|
+
}, g = (d) => {
|
|
1669
|
+
const l = o.get(d);
|
|
1670
|
+
return l ? l[0].annotation.rects : [];
|
|
1653
1671
|
};
|
|
1654
1672
|
return {
|
|
1655
1673
|
all: r,
|
|
1656
1674
|
clear: a,
|
|
1657
|
-
getAt:
|
|
1658
|
-
getAnnotationBounds:
|
|
1659
|
-
getAnnotationRects:
|
|
1660
|
-
getIntersecting: (d,
|
|
1661
|
-
const C = n.search({ minX: d, minY:
|
|
1675
|
+
getAt: c,
|
|
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], []));
|
|
1662
1680
|
return Array.from(E).map((N) => ({
|
|
1663
1681
|
annotation: t.getAnnotation(N),
|
|
1664
|
-
rects:
|
|
1682
|
+
rects: g(N)
|
|
1665
1683
|
})).filter((N) => !!N.annotation);
|
|
1666
1684
|
},
|
|
1667
1685
|
insert: s,
|
|
1668
|
-
recalculate: () =>
|
|
1686
|
+
recalculate: () => m(t.all().map((d) => d.target), !0),
|
|
1669
1687
|
remove: u,
|
|
1670
|
-
set:
|
|
1688
|
+
set: m,
|
|
1671
1689
|
size: () => n.all().length,
|
|
1672
1690
|
update: f
|
|
1673
1691
|
};
|
|
1674
1692
|
}, En = (t, e) => {
|
|
1675
|
-
const n = We(), o = An(n, t), i = Ie(n, e), r = Be(n), a = Ke(), s = (v, h =
|
|
1676
|
-
const d =
|
|
1677
|
-
return
|
|
1678
|
-
}, u = (v, h = !0, d =
|
|
1679
|
-
const
|
|
1680
|
-
return y.length > 0 ? (console.warn("Could not revive all targets for these annotations:", y), n.bulkAddAnnotation(
|
|
1681
|
-
}, f = (v, h =
|
|
1682
|
-
const d = v.map((y) =>
|
|
1683
|
-
return
|
|
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) => {
|
|
1684
1702
|
n.getAnnotation(y.id) ? n.updateAnnotation(y, h) : n.addAnnotation(y, h);
|
|
1685
|
-
}),
|
|
1686
|
-
},
|
|
1687
|
-
const d =
|
|
1703
|
+
}), l;
|
|
1704
|
+
}, m = (v, h = B.LOCAL) => {
|
|
1705
|
+
const d = it(v, t);
|
|
1688
1706
|
n.updateTarget(d, h);
|
|
1689
|
-
},
|
|
1690
|
-
const d = v.map((
|
|
1707
|
+
}, c = (v, h = B.LOCAL) => {
|
|
1708
|
+
const d = v.map((l) => it(l, t));
|
|
1691
1709
|
n.bulkUpdateTargets(d, h);
|
|
1692
|
-
},
|
|
1710
|
+
}, p = (v, h) => {
|
|
1693
1711
|
const d = o.getAt(v, h);
|
|
1694
1712
|
return d ? n.getAnnotation(d) : void 0;
|
|
1695
|
-
},
|
|
1713
|
+
}, g = (v, h, d, l = 5) => {
|
|
1696
1714
|
const y = o.getAnnotationRects(v);
|
|
1697
1715
|
if (y.length !== 0) {
|
|
1698
1716
|
if (h && d) {
|
|
1699
|
-
const T = y.find(({ top: C, right: E, bottom: N, left:
|
|
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);
|
|
1700
1718
|
if (T)
|
|
1701
1719
|
return T;
|
|
1702
1720
|
}
|
|
@@ -1704,20 +1722,20 @@ const An = (t, e) => {
|
|
|
1704
1722
|
}
|
|
1705
1723
|
}, x = () => o.recalculate();
|
|
1706
1724
|
return n.observe(({ changes: v }) => {
|
|
1707
|
-
const h = (v.created || []).filter((y) =>
|
|
1708
|
-
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)), (
|
|
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));
|
|
1709
1727
|
}), {
|
|
1710
1728
|
store: {
|
|
1711
1729
|
...n,
|
|
1712
1730
|
addAnnotation: s,
|
|
1713
1731
|
bulkAddAnnotation: u,
|
|
1714
|
-
bulkUpdateTargets:
|
|
1732
|
+
bulkUpdateTargets: c,
|
|
1715
1733
|
bulkUpsertAnnotations: f,
|
|
1716
|
-
getAnnotationBounds:
|
|
1717
|
-
getAt:
|
|
1734
|
+
getAnnotationBounds: g,
|
|
1735
|
+
getAt: p,
|
|
1718
1736
|
getIntersecting: o.getIntersecting,
|
|
1719
1737
|
recalculatePositions: x,
|
|
1720
|
-
updateTarget:
|
|
1738
|
+
updateTarget: m
|
|
1721
1739
|
},
|
|
1722
1740
|
selection: i,
|
|
1723
1741
|
hover: r,
|
|
@@ -1731,52 +1749,52 @@ const An = (t, e) => {
|
|
|
1731
1749
|
}, Cn = (t, e, n = {}) => {
|
|
1732
1750
|
const o = Sn(), i = o.getContext("2d");
|
|
1733
1751
|
t.appendChild(o);
|
|
1734
|
-
const r = /* @__PURE__ */ new Map(), a = (
|
|
1735
|
-
return e.on("selectionChange", (
|
|
1736
|
-
a(
|
|
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));
|
|
1737
1755
|
}), {
|
|
1738
1756
|
clear: () => {
|
|
1739
|
-
const { width:
|
|
1740
|
-
i.clearRect(-0.5, -0.5,
|
|
1757
|
+
const { width: c, height: p } = o;
|
|
1758
|
+
i.clearRect(-0.5, -0.5, c + 1, p + 1);
|
|
1741
1759
|
},
|
|
1742
1760
|
destroy: () => {
|
|
1743
1761
|
o.remove();
|
|
1744
1762
|
},
|
|
1745
|
-
paint: (
|
|
1763
|
+
paint: (c, p, g) => {
|
|
1746
1764
|
n.font && (i.font = n.font);
|
|
1747
|
-
const x = r.get(
|
|
1765
|
+
const x = r.get(c.annotation.id);
|
|
1748
1766
|
if (x) {
|
|
1749
|
-
const { height: v } =
|
|
1767
|
+
const { height: v } = c.rects[0], h = c.rects[0].x + p.left, d = c.rects[0].y + p.top;
|
|
1750
1768
|
i.fillStyle = x.appearance.color, i.fillRect(h - 2, d - 2.5, 2, v + 5);
|
|
1751
|
-
const
|
|
1769
|
+
const l = i.measureText(x.appearance.label), y = l.width + 6, T = l.actualBoundingBoxAscent + l.actualBoundingBoxDescent + 8, C = l.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1752
1770
|
return i.fillRect(h - 2, d - 2.5 - T, y, T), i.fillStyle = "#fff", i.fillText(x.appearance.label, h + 1, d - C), {
|
|
1753
1771
|
fill: x.appearance.color,
|
|
1754
|
-
fillOpacity:
|
|
1772
|
+
fillOpacity: g ? 0.45 : 0.18
|
|
1755
1773
|
};
|
|
1756
1774
|
}
|
|
1757
1775
|
},
|
|
1758
1776
|
reset: () => {
|
|
1759
1777
|
o.width = 2 * window.innerWidth, o.height = 2 * window.innerHeight;
|
|
1760
|
-
const
|
|
1761
|
-
|
|
1778
|
+
const c = o.getContext("2d");
|
|
1779
|
+
c.scale(2, 2), c.translate(0.5, 0.5);
|
|
1762
1780
|
}
|
|
1763
1781
|
};
|
|
1764
|
-
},
|
|
1782
|
+
}, Pt = (t) => {
|
|
1765
1783
|
if (t === null)
|
|
1766
1784
|
return document.scrollingElement;
|
|
1767
1785
|
const { overflowY: e } = window.getComputedStyle(t);
|
|
1768
|
-
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t :
|
|
1786
|
+
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : Pt(t.parentElement);
|
|
1769
1787
|
}, Tn = (t, e) => (n) => {
|
|
1770
1788
|
const o = (r) => {
|
|
1771
|
-
const a = i.getBoundingClientRect(), s = i.clientHeight, u = i.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width:
|
|
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;
|
|
1772
1790
|
i.scroll({ top: h, left: d, behavior: "smooth" });
|
|
1773
|
-
}, i =
|
|
1791
|
+
}, i = Pt(t);
|
|
1774
1792
|
if (i) {
|
|
1775
1793
|
const r = e.getAnnotation(n.id), { range: a } = r.target.selector[0];
|
|
1776
1794
|
if (a && !a.collapsed)
|
|
1777
1795
|
return o(r.target), !0;
|
|
1778
1796
|
{
|
|
1779
|
-
const s =
|
|
1797
|
+
const s = it(r.target, t), { range: u } = s.selector[0];
|
|
1780
1798
|
if (u && !u.collapsed)
|
|
1781
1799
|
return o(s), !0;
|
|
1782
1800
|
}
|
|
@@ -1789,97 +1807,97 @@ const An = (t, e) => {
|
|
|
1789
1807
|
const { store: i, selection: r } = e;
|
|
1790
1808
|
let a, s;
|
|
1791
1809
|
const u = (h) => a = h;
|
|
1792
|
-
let f = !1,
|
|
1793
|
-
const
|
|
1794
|
-
var
|
|
1810
|
+
let f = !1, m;
|
|
1811
|
+
const c = (h) => {
|
|
1812
|
+
var l;
|
|
1795
1813
|
if (!f)
|
|
1796
1814
|
return;
|
|
1797
|
-
!((
|
|
1798
|
-
annotation:
|
|
1815
|
+
!((l = h.target.parentElement) != null && l.closest(X)) ? s = {
|
|
1816
|
+
annotation: kt(),
|
|
1799
1817
|
selector: [],
|
|
1800
1818
|
creator: a,
|
|
1801
1819
|
created: /* @__PURE__ */ new Date()
|
|
1802
1820
|
} : s = void 0;
|
|
1803
1821
|
};
|
|
1804
|
-
n && t.addEventListener("selectstart",
|
|
1805
|
-
const
|
|
1806
|
-
var N;
|
|
1822
|
+
n && t.addEventListener("selectstart", c);
|
|
1823
|
+
const p = pt((h) => {
|
|
1824
|
+
var N, R;
|
|
1807
1825
|
const d = document.getSelection();
|
|
1808
|
-
if (!!((N = d.anchorNode.parentElement) != null &&
|
|
1826
|
+
if (!!((R = (N = d.anchorNode) == null ? void 0 : N.parentElement) != null && R.closest(X))) {
|
|
1809
1827
|
s = void 0;
|
|
1810
1828
|
return;
|
|
1811
1829
|
}
|
|
1812
|
-
if (h.timeStamp - ((
|
|
1830
|
+
if (h.timeStamp - ((m == null ? void 0 : m.timeStamp) || h.timeStamp) < 1e3 && !s && c(m), d.isCollapsed || !f || !s)
|
|
1813
1831
|
return;
|
|
1814
1832
|
const y = d.getRangeAt(0), T = re(y.cloneRange()), C = Kt(T);
|
|
1815
|
-
(C.length !== s.selector.length || C.some((
|
|
1833
|
+
(C.length !== s.selector.length || C.some((O, b) => {
|
|
1816
1834
|
var w;
|
|
1817
|
-
return
|
|
1835
|
+
return O.toString() !== ((w = s.selector[b]) == null ? void 0 : w.quote);
|
|
1818
1836
|
})) && (s = {
|
|
1819
1837
|
...s,
|
|
1820
|
-
selector: C.map((
|
|
1821
|
-
}, i.getAnnotation(s.annotation) ? i.updateTarget(s,
|
|
1838
|
+
selector: C.map((O) => ie(O, t, o))
|
|
1839
|
+
}, i.getAnnotation(s.annotation) ? i.updateTarget(s, B.LOCAL) : (i.addAnnotation({
|
|
1822
1840
|
id: s.annotation,
|
|
1823
1841
|
bodies: [],
|
|
1824
1842
|
target: s
|
|
1825
|
-
}), r.clickSelect(s.annotation,
|
|
1843
|
+
}), r.clickSelect(s.annotation, m)));
|
|
1826
1844
|
});
|
|
1827
|
-
n && document.addEventListener("selectionchange",
|
|
1828
|
-
const
|
|
1829
|
-
const { target: d, timeStamp:
|
|
1830
|
-
|
|
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;
|
|
1831
1849
|
};
|
|
1832
|
-
t.addEventListener("pointerdown",
|
|
1850
|
+
t.addEventListener("pointerdown", g);
|
|
1833
1851
|
const x = (h) => {
|
|
1834
1852
|
var T;
|
|
1835
|
-
if (!!((T = h.target.parentElement) != null && T.closest(
|
|
1853
|
+
if (!!((T = h.target.parentElement) != null && T.closest(X)) || !f)
|
|
1836
1854
|
return;
|
|
1837
|
-
const
|
|
1855
|
+
const l = () => {
|
|
1838
1856
|
const { x: C, y: E } = t.getBoundingClientRect(), N = i.getAt(h.clientX - C, h.clientY - E);
|
|
1839
1857
|
if (N) {
|
|
1840
|
-
const { selected:
|
|
1841
|
-
(
|
|
1858
|
+
const { selected: R } = r;
|
|
1859
|
+
(R.length !== 1 || R[0].id !== N.id) && r.clickSelect(N.id, h);
|
|
1842
1860
|
} else
|
|
1843
1861
|
r.isEmpty() || r.clear();
|
|
1844
|
-
}, y = h.timeStamp -
|
|
1845
|
-
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);
|
|
1846
1864
|
};
|
|
1847
1865
|
return document.addEventListener("pointerup", x), {
|
|
1848
1866
|
destroy: () => {
|
|
1849
|
-
t.removeEventListener("selectstart",
|
|
1867
|
+
t.removeEventListener("selectstart", c), document.removeEventListener("selectionchange", p), t.removeEventListener("pointerdown", g), document.removeEventListener("pointerup", x);
|
|
1850
1868
|
},
|
|
1851
1869
|
setUser: u
|
|
1852
1870
|
};
|
|
1853
|
-
},
|
|
1871
|
+
}, Mt = "SPANS", Mn = (t, e = {}) => {
|
|
1854
1872
|
Qt(t);
|
|
1855
1873
|
const n = Nn(e, {
|
|
1856
1874
|
annotationEnabled: !0
|
|
1857
1875
|
}), o = En(t, n.pointerAction), { selection: i, viewport: r } = o, a = o.store, s = Ge(a), u = Qe(o, s, n.adapter);
|
|
1858
1876
|
let f = sn();
|
|
1859
|
-
const
|
|
1860
|
-
if (!
|
|
1861
|
-
throw `Unknown renderer implementation: ${
|
|
1862
|
-
console.debug(`Using ${
|
|
1863
|
-
const
|
|
1864
|
-
return
|
|
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;
|
|
1878
|
+
if (!c)
|
|
1879
|
+
throw `Unknown renderer implementation: ${m}`;
|
|
1880
|
+
console.debug(`Using ${m} renderer`), n.style && c.setStyle(n.style);
|
|
1881
|
+
const p = Rn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
|
|
1882
|
+
return p.setUser(f), {
|
|
1865
1883
|
...Ze(o, s, n.adapter),
|
|
1866
1884
|
destroy: () => {
|
|
1867
|
-
|
|
1885
|
+
c.destroy(), p.destroy(), s.destroy();
|
|
1868
1886
|
},
|
|
1869
1887
|
element: t,
|
|
1870
1888
|
getUser: () => f,
|
|
1871
|
-
setFilter: (E) =>
|
|
1872
|
-
setStyle: (E) =>
|
|
1889
|
+
setFilter: (E) => c.setFilter(E),
|
|
1890
|
+
setStyle: (E) => c.setStyle(E),
|
|
1873
1891
|
setUser: (E) => {
|
|
1874
|
-
f = E,
|
|
1892
|
+
f = E, p.setUser(E);
|
|
1875
1893
|
},
|
|
1876
1894
|
setSelected: (E) => {
|
|
1877
1895
|
E ? i.setSelected(E) : i.clear();
|
|
1878
1896
|
},
|
|
1879
1897
|
setPresenceProvider: (E) => {
|
|
1880
|
-
E && (
|
|
1898
|
+
E && (c.setPainter(Cn(t, E, n.presence)), E.on("selectionChange", () => c.redraw()));
|
|
1881
1899
|
},
|
|
1882
|
-
setVisible: (E) =>
|
|
1900
|
+
setVisible: (E) => c.setVisible(E),
|
|
1883
1901
|
on: u.on,
|
|
1884
1902
|
off: u.off,
|
|
1885
1903
|
scrollIntoView: Tn(t, a),
|
|
@@ -1887,11 +1905,11 @@ const An = (t, e) => {
|
|
|
1887
1905
|
};
|
|
1888
1906
|
};
|
|
1889
1907
|
export {
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1908
|
+
ot as DEFAULT_SELECTED_STYLE,
|
|
1909
|
+
P as DEFAULT_STYLE,
|
|
1910
|
+
Vt as NOT_ANNOTATABLE_CLASS,
|
|
1911
|
+
X as NOT_ANNOTATABLE_SELECTOR,
|
|
1912
|
+
B as Origin,
|
|
1895
1913
|
Oe as PointerSelectAction,
|
|
1896
1914
|
In as W3CTextFormat,
|
|
1897
1915
|
Qt as cancelSingleClickEvents,
|
|
@@ -1902,20 +1920,20 @@ export {
|
|
|
1902
1920
|
Se as createSpansRenderer,
|
|
1903
1921
|
Mn as createTextAnnotator,
|
|
1904
1922
|
En as createTextAnnotatorState,
|
|
1905
|
-
|
|
1923
|
+
pt as debounce,
|
|
1906
1924
|
Nn as fillDefaults,
|
|
1907
1925
|
Ln as getAnnotatableFragment,
|
|
1908
1926
|
Bn as getClientRectsPonyfill,
|
|
1909
1927
|
te as getQuoteContext,
|
|
1910
|
-
|
|
1911
|
-
|
|
1928
|
+
ft as getRangeAnnotatableContents,
|
|
1929
|
+
$ as isRevived,
|
|
1912
1930
|
oe as mergeClientRects,
|
|
1913
1931
|
qt as paint,
|
|
1914
1932
|
hn as parseW3CTextAnnotation,
|
|
1915
1933
|
ie as rangeToSelector,
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1934
|
+
rt as reviveAnnotation,
|
|
1935
|
+
_t as reviveSelector,
|
|
1936
|
+
it as reviveTarget,
|
|
1919
1937
|
fn as serializeW3CTextAnnotation,
|
|
1920
1938
|
Kt as splitAnnotatableRanges,
|
|
1921
1939
|
re as trimRange
|