@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 H = {
1
+ const P = {
2
2
  fill: "rgb(0, 128, 255)",
3
3
  fillOpacity: 0.18
4
- }, et = {
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 ? et : H) : n : (s = t.state) != null && s.selected ? et : H;
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
- }, It = "not-annotatable", _ = `.${It}`, jt = (t) => {
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(_) : !((n = e.parentElement) != null && n.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(It) && !o.parentElement.closest(_) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
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
- }, ut = (t) => {
38
+ }, ft = (t) => {
39
39
  const e = t.cloneContents();
40
- return e.querySelectorAll(_).forEach((n) => n.remove()), e;
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(_) && !e.target.closest("a") && e.preventDefault();
44
+ !e.target.closest(X) && !e.target.closest("a") && e.preventDefault();
45
45
  });
46
- }, ft = (t, e = 10) => {
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(_).forEach((n) => n.remove()), e;
54
- }, mt = (t, e) => {
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
- }, bt = (t, e) => {
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((l) => {
76
- const m = l.cloneNode(!0);
77
- return l.nodeName === "CANVAS" ? l : m;
78
- }), s = mt(n, e), u = mt(i, e), f = () => {
79
- const l = e;
80
- l.replaceChildren(...a);
81
- const m = bt(s, l), p = bt(u, l);
82
- return t.setStart(m, o), t.setEnd(p, r), t;
83
- }, b = (l) => {
84
- const m = document.createElement("SPAN");
85
- return l.surroundContents(m), m;
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 l = document.createRange();
91
- l.selectNodeContents(n), l.setStart(n, o);
92
- const m = b(l), p = document.createRange();
93
- p.selectNode(i), p.setEnd(i, r);
94
- const x = b(p), h = Zt(t).reverse().map((d) => {
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 c = document.createElement("SPAN");
97
- return (y = d.parentNode) == null || y.insertBefore(c, d), c.appendChild(d), c;
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: [m, ...h, x] };
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 = ut(r).textContent, s = document.createRange();
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 = ut(s).textContent;
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
- }, Y = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), ee = (t, e) => {
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 = ut(o).textContent, a = t.toString(), s = r.length || 0, u = s + a.length;
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
- }, Mt = (t, e) => {
184
- var b, l;
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
- (m) => {
189
- var p;
190
- return (p = m.parentElement) != null && p.closest(_) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
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 m = ((b = u.textContent) == null ? void 0 : b.length) || 0;
201
- if (a + m > n) {
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 += m;
205
+ a += p;
206
206
  }
207
207
  u = r.nextNode();
208
208
  }
209
209
  for (; u !== null; ) {
210
- const m = ((l = u.textContent) == null ? void 0 : l.length) || 0;
211
- if (a + m >= o) {
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 += m, u = r.nextNode();
215
+ a += p, u = r.nextNode();
216
216
  }
217
217
  return {
218
218
  ...t,
219
219
  range: s
220
220
  };
221
- }, nt = (t, e) => Y(t.selector) ? t : {
221
+ }, it = (t, e) => $(t.selector) ? t : {
222
222
  ...t,
223
- selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : Mt(n, e))
224
- }, ot = (t, e) => Y(t.target.selector) ? t : { ...t, target: nt(t.target, e) }, re = (t) => {
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
- }, pt = (t, e, n, o) => {
247
+ }, mt = (t, e, n, o) => {
248
248
  const { store: i, selection: r, hover: a } = e;
249
249
  let s, u, f;
250
- const b = ae(n), l = (g) => {
251
- const { x: A, y: w } = t.getBoundingClientRect(), S = i.getAt(g.clientX - A, g.clientY - w);
252
- S && (!u || u(S)) ? a.current !== S.id && (t.classList.add("hovered"), a.set(S.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
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", l);
255
- const m = (g = !1) => {
254
+ t.addEventListener("pointermove", c);
255
+ const p = (R = !1) => {
256
256
  f && f.clear();
257
- const A = se(t), { minX: w, minY: S, maxX: R, maxY: B } = A, X = u ? i.getIntersecting(w, S, R, B).filter(({ annotation: D }) => u(D)) : i.getIntersecting(w, S, R, B), $t = r.selected.map(({ id: D }) => D), Pt = X.map(({ annotation: D, rects: zt }) => {
258
- const Ft = $t.includes(D.id), Wt = D.id === a.current;
259
- return { annotation: D, rects: zt, state: { selected: Ft, hover: Wt, custom: {} } };
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(Pt, A, s, f, g), setTimeout(() => b(X.map(({ annotation: D }) => D)), 1);
262
- }, p = (g) => {
263
- f = g, m();
264
- }, x = (g) => {
265
- s = g, m();
266
- }, v = (g) => {
267
- u = g, m(!1);
268
- }, h = () => m();
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(() => m()), c = () => m(!0);
271
- document.addEventListener("scroll", c, { capture: !0, passive: !0 });
272
- const y = ft(() => {
273
- i.recalculatePositions(), f && f.reset(), m();
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((g) => {
279
- g.every((w) => w.target === t || t.contains(w.target)) || m(!0);
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", l), o.destroy(), i.unobserve(h), d(), document.removeEventListener("scroll", c), window.removeEventListener("resize", y), T.disconnect(), E.disconnect();
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: m,
285
+ redraw: p,
286
286
  setStyle: x,
287
287
  setFilter: v,
288
- setPainter: p,
288
+ setPainter: g,
289
289
  setVisible: o.setVisible
290
290
  };
291
- }, le = () => {
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
- }, ce = (t, e) => {
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 = le(), n = e.getContext("2d");
298
+ const e = ce(), n = e.getContext("2d");
299
299
  t.insertBefore(e, t.firstChild);
300
- const o = (s, u, f, b) => requestAnimationFrame(() => {
301
- const { width: l, height: m } = e;
302
- n.clearRect(-0.5, -0.5, l + 1, m + 1), b && b.clear();
303
- const { top: p, left: x } = u;
304
- s.forEach((v) => {
305
- var T;
306
- const h = f ? typeof f == "function" ? f(v.annotation, v.state) : f : (T = v.state) != null && T.selected ? et : H, d = b && b.paint(v, u) || h, c = v.rects.map(({ x: C, y: E, width: N, height: g }) => ({
307
- x: C + x,
308
- y: E + p,
309
- width: N,
310
- height: g
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 = d.fill, n.globalAlpha = d.fillOpacity || 1;
313
- const y = 5;
314
- if (c.forEach(
315
- ({ x: C, y: E, width: N, height: g }) => n.fillRect(
316
- C,
317
- E - y / 2,
318
- N,
319
- g + y
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
- ), d.underlineColor) {
322
- n.globalAlpha = 1, n.strokeStyle = d.underlineColor, n.lineWidth = d.underlineThickness ?? 1;
323
- const C = y / 2 + (d.underlineOffset ?? 0);
324
- c.forEach(({ x: E, y: N, width: g, height: A }) => {
325
- n.beginPath(), n.moveTo(E, N + A + C), n.lineTo(E + g, N + A + C), n.stroke();
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 = ft(() => {
330
- ce(e);
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) => pt(t, e, n, de(t));
342
- var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, k = function(t) {
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
- }, O = function(t, e, n) {
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
- }, vt = function(t) {
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
- }, it = function(t) {
353
- return { r: O(t.r), g: O(t.g), b: O(t.b), a: O(t.a, 3) };
354
- }, fe = /^#([0-9a-f]{3,8})$/i, K = function(t) {
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
- }, Vt = function(t) {
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
- }, _t = function(t) {
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 _t((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 }));
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
- }, G = function(t) {
373
- return { h: (e = Vt(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 };
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
- }, pe = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ge = /^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, At = { string: [[function(t) {
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 ? O(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 ? O(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
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 : vt({ 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;
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 = pe.exec(t) || ge.exec(t);
385
+ var e = ge.exec(t) || pe.exec(t);
383
386
  if (!e)
384
387
  return null;
385
- var n, o, i = yt({ 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) });
386
- return xt(i);
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 k(e) && k(n) && k(o) ? vt({ r: Number(e), g: Number(n), b: Number(o), a: Number(r) }) : null;
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 (!k(e) || !k(n) || !k(o))
395
+ if (!Y(e) || !Y(n) || !Y(o))
393
396
  return null;
394
- var a = yt({ h: Number(e), s: Number(n), l: Number(o), a: Number(r) });
395
- return xt(a);
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 (!k(e) || !k(n) || !k(o))
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 _t(a);
404
- }, "hsv"]] }, Et = function(t, e) {
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" ? Et(t.trim(), At.string) : typeof t == "object" && t !== null ? Et(t, At.object) : [null, void 0];
413
- }, rt = function(t, e) {
414
- var n = G(t);
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
- }, st = function(t) {
419
+ }, ct = function(t) {
417
420
  return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
418
- }, St = function(t, e) {
419
- var n = G(t);
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
- }, Ct = function() {
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 O(st(this.rgba), 2);
431
+ return M(ct(this.rgba), 2);
429
432
  }, t.prototype.isDark = function() {
430
- return st(this.rgba) < 0.5;
433
+ return ct(this.rgba) < 0.5;
431
434
  }, t.prototype.isLight = function() {
432
- return st(this.rgba) >= 0.5;
435
+ return ct(this.rgba) >= 0.5;
433
436
  }, t.prototype.toHex = function() {
434
- return e = it(this.rgba), n = e.r, o = e.g, i = e.b, a = (r = e.a) < 1 ? K(O(255 * r)) : "", "#" + K(n) + K(o) + K(i) + a;
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 it(this.rgba);
440
+ return st(this.rgba);
438
441
  }, t.prototype.toRgbString = function() {
439
- return e = it(this.rgba), n = e.r, o = e.g, i = e.b, (r = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + r + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
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 wt(G(this.rgba));
445
+ return At(Q(this.rgba));
443
446
  }, t.prototype.toHslString = function() {
444
- return e = wt(G(this.rgba)), n = e.h, o = e.s, i = e.l, (r = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + r + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
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 = Vt(this.rgba), { h: O(e.h), s: O(e.s), v: O(e.v), a: O(e.a, 3) };
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 V({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
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), V(rt(this.rgba, e));
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), V(rt(this.rgba, -e));
458
+ return e === void 0 && (e = 0.1), D(at(this.rgba, -e));
456
459
  }, t.prototype.grayscale = function() {
457
- return V(rt(this.rgba, -1));
460
+ return D(at(this.rgba, -1));
458
461
  }, t.prototype.lighten = function(e) {
459
- return e === void 0 && (e = 0.1), V(St(this.rgba, e));
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), V(St(this.rgba, -e));
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" ? V({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : O(this.rgba.a, 3);
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 = G(this.rgba);
469
- return typeof e == "number" ? V({ h: e, s: n.s, l: n.l, a: n.a }) : O(n.h);
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() === V(e).toHex();
474
+ return this.toHex() === D(e).toHex();
472
475
  }, t;
473
- }(), V = function(t) {
474
- return t instanceof Ct ? t : new Ct(t);
476
+ }(), D = function(t) {
477
+ return t instanceof Nt ? t : new Nt(t);
475
478
  };
476
479
  const ye = (t) => [
477
- `background-color:${V((t == null ? void 0 : t.fill) || H.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? H.fillOpacity : t.fillOpacity).toHex()}`,
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((l) => l.annotation.id));
496
- Array.from(e).filter((l) => !f.has(l));
497
- const b = r.map((l) => {
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 m = s ? typeof s == "function" ? s(l.annotation, l.state) : s : (x = l.state) != null && x.selected ? et : H, p = u && u.paint(l, a) || m;
500
- return `::highlight(_${l.annotation.id}) { ${ye(p)} }`;
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 = b.join(`
503
- `), CSS.highlights.clear(), r.forEach(({ annotation: l }) => {
504
- const m = l.target.selector.map((x) => x.range), p = new Highlight(...m);
505
- CSS.highlights.set(`_${l.id}`, p);
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) => pt(t, e, n, we());
510
- var Tt = Object.prototype.hasOwnProperty;
511
- function ht(t, e) {
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-- && ht(t[o], e[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 (Tt.call(t, n) && ++o && !Tt.call(e, n) || !(n in e) || !ht(t[n], e[n]))
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, b) => {
549
- if (ht(n, a) && b)
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 m = a.reduce((p, { rects: x }) => [...p, ...x], []);
553
- a.forEach((p) => {
554
- const x = p.rects.map((v) => {
555
- const h = document.createElement("span");
556
- h.className = "r6o-annotation", h.dataset.annotation = p.annotation.id, h.style.left = `${v.x}px`, h.style.top = `${v.y}px`, h.style.width = `${v.width}px`, h.style.height = `${v.height}px`;
557
- const d = Ae(v, m), c = qt(p, s, u, f, d), y = V((c == null ? void 0 : c.fill) || H.fill).alpha((c == null ? void 0 : c.fillOpacity) === void 0 ? H.fillOpacity : c.fillOpacity).toHex();
558
- return h.style.backgroundColor = y, c.underlineStyle && (h.style.borderStyle = c.underlineStyle), c.underlineColor && (h.style.borderColor = c.underlineColor), c.underlineThickness && (h.style.borderBottomWidth = `${c.underlineThickness}px`), c.underlineOffset && (h.style.paddingBottom = `${c.underlineOffset}px`), e.appendChild(h), h;
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) => pt(t, e, n, Ee(t));
568
- let Q;
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 (!Q && (Q = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Q))
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 Q(Ce);
579
+ return Z(Ce);
574
580
  }
575
- const I = [];
581
+ const V = [];
576
582
  for (let t = 0; t < 256; ++t)
577
- I.push((t + 256).toString(16).slice(1));
583
+ V.push((t + 256).toString(16).slice(1));
578
584
  function Ne(t, e = 0) {
579
- return I[t[e + 0]] + I[t[e + 1]] + I[t[e + 2]] + I[t[e + 3]] + "-" + I[t[e + 4]] + I[t[e + 5]] + "-" + I[t[e + 6]] + I[t[e + 7]] + "-" + I[t[e + 8]] + I[t[e + 9]] + "-" + I[t[e + 10]] + I[t[e + 11]] + I[t[e + 12]] + I[t[e + 13]] + I[t[e + 14]] + I[t[e + 15]];
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), Nt = {
587
+ const Re = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Lt = {
582
588
  randomUUID: Re
583
589
  };
584
- function Xt(t, e, n) {
585
- if (Nt.randomUUID && !e && !t)
586
- return Nt.randomUUID();
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 Rt = Object.prototype.hasOwnProperty;
592
- function F(t, e) {
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-- && F(t[o], e[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 (Rt.call(t, n) && ++o && !Rt.call(e, n) || !(n in e) || !F(t[n], e[n]))
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 at() {
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 gt(t, e = at) {
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 = !$.length;
634
+ const u = !z.length;
629
635
  for (const f of o)
630
- f[1](), $.push(f, t);
636
+ f[1](), z.push(f, t);
631
637
  if (u) {
632
- for (let f = 0; f < $.length; f += 2)
633
- $[f][0]($[f + 1]);
634
- $.length = 0;
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 = at) {
647
+ function a(s, u = lt) {
642
648
  const f = [s, u];
643
- return o.add(f), o.size === 1 && (n = e(i, r) || at), s(t), () => {
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 } = gt();
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 lt = { selected: [] }, Ie = (t, e = "EDIT") => {
668
- const { subscribe: n, set: o } = gt(lt);
669
- let i = lt;
670
- n((l) => i = l);
671
- const r = () => o(lt), a = () => {
672
- var l;
673
- return ((l = i.selected) == null ? void 0 : l.length) === 0;
674
- }, s = (l) => {
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 m = typeof l == "string" ? l : l.id;
678
- return i.selected.some((p) => p.id === m);
679
- }, u = (l, m) => {
680
- const p = t.getAnnotation(l);
681
- if (p) {
682
- const x = Me(p, e);
683
- o(x === "EDIT" ? { selected: [{ id: l, editable: !0 }], pointerEvent: m } : x === "SELECT" ? { selected: [{ id: l }], pointerEvent: m } : { selected: [], pointerEvent: m });
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: " + l);
686
- }, f = (l, m = !0) => {
687
- const p = Array.isArray(l) ? l : [l], x = p.map((v) => t.getAnnotation(v)).filter(Boolean);
688
- o({ selected: x.map(({ id: v }) => ({ id: v, editable: m })) }), x.length !== p.length && console.warn("Invalid selection", l);
689
- }, b = (l) => {
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: m } = i;
693
- m.filter(({ id: p }) => l.includes(p)).length > 0 && o({ selected: m.filter(({ id: p }) => !l.includes(p)) });
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: l }) => b((l.deleted || []).map((m) => m.id))), {
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 J;
711
- const Ue = new Uint8Array(16);
712
- function Ve() {
713
- if (!J && (J = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !J))
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 J(Ue);
721
+ return tt(Ve);
716
722
  }
717
- const M = [];
723
+ const _ = [];
718
724
  for (let t = 0; t < 256; ++t)
719
- M.push((t + 256).toString(16).slice(1));
720
- function _e(t, e = 0) {
721
- return M[t[e + 0]] + M[t[e + 1]] + M[t[e + 2]] + M[t[e + 3]] + "-" + M[t[e + 4]] + M[t[e + 5]] + "-" + M[t[e + 6]] + M[t[e + 7]] + "-" + M[t[e + 8]] + M[t[e + 9]] + "-" + M[t[e + 10]] + M[t[e + 11]] + M[t[e + 12]] + M[t[e + 13]] + M[t[e + 14]] + M[t[e + 15]];
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 Xe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Lt = {
724
- randomUUID: Xe
729
+ const De = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Ot = {
730
+ randomUUID: De
725
731
  };
726
- function De(t, e, n) {
727
- if (Lt.randomUUID && !e && !t)
728
- return Lt.randomUUID();
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 || Ve)();
731
- return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, _e(o);
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: De(),
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 && !F(o, n) ? o : void 0 };
748
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), $e = (t, e) => !F(t.target, e.target), Dt = (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 L = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(L || {});
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((b) => s(b.bodiesCreated) || s(b.bodiesDeleted) || s(b.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((b) => b.targetUpdated);
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((l) => l.id)), o = new Set((t.updated || []).map(({ newValue: l }) => l.id)), i = new Set((e.created || []).map((l) => l.id)), r = new Set((e.deleted || []).map((l) => l.id)), a = new Set((e.updated || []).map(({ oldValue: l }) => l.id)), s = new Set((e.updated || []).filter(({ oldValue: l }) => n.has(l.id) || o.has(l.id)).map(({ oldValue: l }) => l.id)), u = [
784
- ...(t.created || []).filter((l) => !r.has(l.id)).map((l) => a.has(l.id) ? e.updated.find(({ oldValue: m }) => m.id === l.id).newValue : l),
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((l) => !i.has(l.id)),
788
- ...(e.deleted || []).filter((l) => !n.has(l.id))
789
- ], b = [
790
- ...(t.updated || []).filter(({ newValue: l }) => !r.has(l.id)).map((l) => {
791
- const { oldValue: m, newValue: p } = l;
792
- if (a.has(p.id)) {
793
- const x = e.updated.find((v) => v.oldValue.id === p.id).newValue;
794
- return Dt(m, x);
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 l;
802
+ return c;
797
803
  }),
798
- ...(e.updated || []).filter(({ oldValue: l }) => !s.has(l.id))
804
+ ...(e.updated || []).filter(({ oldValue: c }) => !s.has(c.id))
799
805
  ];
800
- return { created: u, deleted: f, updated: b };
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 = (g, A = {}) => n.push({ onChange: g, options: A }), i = (g) => {
803
- const A = n.findIndex((w) => w.onChange == g);
804
- A > -1 && n.splice(A, 1);
805
- }, r = (g, A) => {
806
- const w = {
807
- origin: g,
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: A.created || [],
810
- updated: A.updated || [],
811
- deleted: A.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, w) && S.onChange(w);
822
+ Pe(S, A) && S.onChange(A);
817
823
  });
818
- }, a = (g, A = L.LOCAL) => {
819
- if (t.get(g.id))
820
- throw Error(`Cannot add annotation ${g.id} - exists already`);
821
- t.set(g.id, g), g.bodies.forEach((w) => e.set(w.id, g.id)), r(A, { created: [g] });
822
- }, s = (g, A) => {
823
- const w = typeof g == "string" ? A : g, S = typeof g == "string" ? g : g.id, R = t.get(S);
824
- if (R) {
825
- const B = Dt(R, w);
826
- return S === w.id ? t.set(S, w) : (t.delete(S), t.set(w.id, w)), R.bodies.forEach((X) => e.delete(X.id)), w.bodies.forEach((X) => e.set(X.id, w.id)), B;
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 = (g, A = L.LOCAL, w = L.LOCAL) => {
830
- const S = Fe(A) ? w : A, R = s(g, A);
831
- R && r(S, { updated: [R] });
832
- }, f = (g, A = L.LOCAL) => {
833
- const w = g.reduce((S, R) => {
834
- const B = s(R);
835
- return B ? [...S, B] : S;
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
- w.length > 0 && r(A, { updated: w });
838
- }, b = (g, A = L.LOCAL) => {
839
- const w = t.get(g.annotation);
840
- if (w) {
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
- ...w,
843
- bodies: [...w.bodies, g]
848
+ ...A,
849
+ bodies: [...A.bodies, b]
844
850
  };
845
- t.set(w.id, S), e.set(g.id, S.id), r(A, { updated: [{
846
- oldValue: w,
851
+ t.set(A.id, S), e.set(b.id, S.id), r(w, { updated: [{
852
+ oldValue: A,
847
853
  newValue: S,
848
- bodiesCreated: [g]
854
+ bodiesCreated: [b]
849
855
  }] });
850
856
  } else
851
- console.warn(`Attempt to add body to missing annotation: ${g.annotation}`);
852
- }, l = () => [...t.values()], m = (g = L.LOCAL) => {
853
- const A = [...t.values()];
854
- t.clear(), e.clear(), r(g, { deleted: A });
855
- }, p = (g, A = !0, w = L.LOCAL) => {
856
- if (A) {
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(), g.forEach((R) => {
859
- t.set(R.id, R), R.bodies.forEach((B) => e.set(B.id, R.id));
860
- }), r(w, { created: g, deleted: S });
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 = g.reduce((R, B) => {
863
- const X = t.get(B.id);
864
- return X ? [...R, X] : R;
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((R) => R.id).join(", ")}`);
868
- g.forEach((R) => {
869
- t.set(R.id, R), R.bodies.forEach((B) => e.set(B.id, R.id));
870
- }), r(w, { created: g });
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 = (g) => {
873
- const A = typeof g == "string" ? g : g.id, w = t.get(A);
874
- if (w)
875
- return t.delete(A), w.bodies.forEach((S) => e.delete(S.id)), w;
876
- console.warn(`Attempt to delete missing annotation: ${A}`);
877
- }, v = (g, A = L.LOCAL) => {
878
- const w = x(g);
879
- w && r(A, { deleted: [w] });
880
- }, h = (g, A = L.LOCAL) => {
881
- const w = g.reduce((S, R) => {
882
- const B = x(R);
883
- return B ? [...S, B] : S;
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
- w.length > 0 && r(A, { deleted: w });
886
- }, d = (g, A = L.LOCAL) => {
887
- const w = t.get(g.annotation);
891
+ A.length > 0 && r(w, { deleted: A });
892
+ }, d = (b) => {
893
+ const w = t.get(b.annotation);
888
894
  if (w) {
889
- const S = w.bodies.find((R) => R.id === g.id);
890
- if (S) {
891
- e.delete(S.id);
892
- const R = {
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((B) => B.id !== g.id)
900
+ bodies: w.bodies.filter((L) => L.id !== b.id)
895
901
  };
896
- t.set(w.id, R), r(A, { updated: [{
902
+ return t.set(w.id, S), {
897
903
  oldValue: w,
898
- newValue: R,
899
- bodiesDeleted: [S]
900
- }] });
904
+ newValue: S,
905
+ bodiesDeleted: [A]
906
+ };
901
907
  } else
902
- console.warn(`Attempt to delete missing body ${g.id} from annotation ${g.annotation}`);
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 ${g.annotation}`);
905
- }, c = (g) => {
906
- const A = t.get(g);
907
- return A ? { ...A } : void 0;
908
- }, y = (g) => {
909
- const A = e.get(g);
910
- if (A) {
911
- const w = c(A).bodies.find((S) => S.id === g);
912
- if (w)
913
- return w;
914
- console.error(`Store integrity error: body ${g} in index, but not in annotation`);
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: ${g}`);
917
- }, T = (g, A) => {
918
- if (g.annotation !== A.annotation)
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 w = t.get(g.annotation);
921
- if (w) {
922
- const S = w.bodies.find((B) => B.id === g.id), R = {
923
- ...w,
924
- bodies: w.bodies.map((B) => B.id === S.id ? A : B)
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(w.id, R), S.id !== A.id && (e.delete(S.id), e.set(A.id, R.id)), {
927
- oldValue: w,
928
- newValue: R,
929
- bodiesUpdated: [{ oldBody: S, newBody: A }]
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 ${g.annotation}`);
933
- }, C = (g, A, w = L.LOCAL) => {
934
- const S = T(g, A);
935
- S && r(w, { updated: [S] });
936
- }, E = (g, A = L.LOCAL) => {
937
- const w = g.map((S) => T({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
938
- r(A, { updated: w });
939
- }, N = (g) => {
940
- const A = t.get(g.annotation);
941
- if (A) {
942
- const w = {
943
- ...A,
944
+ console.warn(`Attempt to add body to missing annotation ${b.annotation}`);
945
+ }, N = (b, w, A = B.LOCAL) => {
946
+ const S = E(b, w);
947
+ S && r(A, { updated: [S] });
948
+ }, R = (b, w = B.LOCAL) => {
949
+ const A = b.map((S) => E({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
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
- ...A.target,
946
- ...g
957
+ ...w.target,
958
+ ...b
947
959
  }
948
960
  };
949
- return t.set(A.id, w), {
950
- oldValue: A,
951
- newValue: w,
961
+ return t.set(w.id, A), {
962
+ oldValue: w,
963
+ newValue: A,
952
964
  targetUpdated: {
953
- oldTarget: A.target,
954
- newTarget: g
965
+ oldTarget: w.target,
966
+ newTarget: b
955
967
  }
956
968
  };
957
969
  } else
958
- console.warn(`Attempt to update target on missing annotation: ${g.annotation}`);
970
+ console.warn(`Attempt to update target on missing annotation: ${b.annotation}`);
959
971
  };
960
972
  return {
961
973
  addAnnotation: a,
962
- addBody: b,
963
- all: l,
964
- bulkAddAnnotation: p,
974
+ addBody: m,
975
+ all: c,
976
+ bulkAddAnnotation: g,
965
977
  bulkDeleteAnnotation: h,
978
+ bulkDeleteBodies: y,
966
979
  bulkUpdateAnnotation: f,
967
- bulkUpdateBodies: E,
968
- bulkUpdateTargets: (g, A = L.LOCAL) => {
969
- const w = g.map((S) => N(S)).filter(Boolean);
970
- w.length > 0 && r(A, { updated: w });
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: m,
985
+ clear: p,
973
986
  deleteAnnotation: v,
974
- deleteBody: d,
975
- getAnnotation: c,
976
- getBody: y,
987
+ deleteBody: l,
988
+ getAnnotation: T,
989
+ getBody: C,
977
990
  observe: o,
978
991
  unobserve: i,
979
992
  updateAnnotation: u,
980
- updateBody: C,
981
- updateTarget: (g, A = L.LOCAL) => {
982
- const w = N(g);
983
- w && r(A, { updated: [w] });
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 = (p) => {
1017
+ const a = (g) => {
1005
1018
  if (!i) {
1006
- const { changes: x } = p, v = performance.now();
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: L.LOCAL });
1018
- const s = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), u = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), f = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue: x }) => x)), b = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: x }) => x)), l = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), m = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p);
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: (p, x) => e.on(p, x),
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: p, updated: x, deleted: v } = n[o + 1];
1028
- u(p), b(x), m(v), e.emit("redo", n[o + 1]), o += 1;
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: p, updated: x, deleted: v } = n[o];
1035
- s(p), f(x), l(v), e.emit("undo", n[o]), o -= 1;
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 } = gt([]);
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 = [], b;
1048
- const l = (v, h) => {
1060
+ let f = [], m;
1061
+ const c = (v, h) => {
1049
1062
  u.has(v) ? u.get(v).push(h) : u.set(v, [h]);
1050
- }, m = (v, h) => {
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
- }, p = (v, h, d) => {
1066
+ }, g = (v, h, d) => {
1054
1067
  u.has(v) && setTimeout(() => {
1055
- u.get(v).forEach((c) => {
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
- c(y, T);
1071
+ l(y, T);
1059
1072
  } else
1060
- c(h, d);
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 && !F(d, h) && p("updateAnnotation", d, h);
1084
+ d && !q(d, h) && g("updateAnnotation", d, h);
1072
1085
  }), f = [];
1073
1086
  else {
1074
- const h = new Set(f.map((c) => c.id)), d = new Set(v.map(({ id: c }) => c));
1075
- f.filter((c) => !d.has(c.id)).forEach((c) => {
1076
- const y = i.getAnnotation(c.id);
1077
- y && !F(y, c) && p("updateAnnotation", y, c);
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((c) => d.has(c.id)),
1093
+ ...f.filter((l) => d.has(l.id)),
1081
1094
  // Add editable annotations that were selected
1082
- ...v.filter(({ id: c }) => !h.has(c)).map(({ id: c }) => i.getAnnotation(c))
1095
+ ...v.filter(({ id: l }) => !h.has(l)).map(({ id: l }) => i.getAnnotation(l))
1083
1096
  ];
1084
1097
  }
1085
- p("selectionChanged", f);
1098
+ g("selectionChanged", f);
1086
1099
  }
1087
1100
  }), a.subscribe((v) => {
1088
- !b && v ? p("mouseEnterAnnotation", i.getAnnotation(v)) : b && !v ? p("mouseLeaveAnnotation", i.getAnnotation(b)) : b && v && (p("mouseLeaveAnnotation", i.getAnnotation(b)), p("mouseEnterAnnotation", i.getAnnotation(v))), b = v;
1089
- }), s == null || s.subscribe((v) => p("viewportIntersect", v.map((h) => i.getAnnotation(h)))), i.observe((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((c) => p("createAnnotation", c)), (d || []).forEach((c) => p("deleteAnnotation", c)), (v.changes.updated || []).filter((c) => [
1092
- ...c.bodiesCreated || [],
1093
- ...c.bodiesDeleted || [],
1094
- ...c.bodiesUpdated || []
1095
- ].length > 0).forEach(({ oldValue: c, newValue: y }) => {
1096
- const T = f.find((C) => C.id === c.id) || c;
1097
- f = f.map((C) => C.id === c.id ? y : C), p("updateAnnotation", y, T);
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: L.LOCAL }), i.observe((v) => {
1112
+ }, { origin: B.LOCAL }), i.observe((v) => {
1100
1113
  if (f) {
1101
- const h = new Set(f.map((c) => c.id)), d = (v.changes.updated || []).filter(({ newValue: c }) => h.has(c.id)).map(({ newValue: c }) => c);
1102
- d.length > 0 && (f = f.map((c) => d.find((T) => T.id === c.id) || c));
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: L.REMOTE });
1117
+ }, { origin: B.REMOTE });
1105
1118
  const x = (v) => (h) => {
1106
1119
  const { updated: d } = h;
1107
- v ? (d || []).forEach((c) => p("updateAnnotation", c.oldValue, c.newValue)) : (d || []).forEach((c) => p("updateAnnotation", c.newValue, c.oldValue));
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: l, off: m, emit: p };
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: c } = n.parse(h);
1125
- d ? o.addAnnotation(d, L.REMOTE) : console.error(c);
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, L.REMOTE);
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(), b = () => {
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((c) => c.id)) || []).map((c) => o.getAnnotation(c)).filter(Boolean);
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
- }, l = (h, d = !0) => fetch(h).then((c) => c.json()).then((c) => (p(c, d), c)), m = (h) => {
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
- }, p = (h, d = !0) => {
1158
+ }, g = (h, d = !0) => {
1146
1159
  if (n) {
1147
- const { parsed: c, failed: y } = Je(n)(h);
1148
- y.length > 0 && console.warn(`Discarded ${y.length} invalid annotations`, y), o.bulkAddAnnotation(c, d, L.REMOTE);
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, L.REMOTE);
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, c = n.serialize(o.getAnnotation(d.id));
1156
- return o.updateAnnotation(d), c;
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: b,
1171
- loadAnnotations: l,
1183
+ getSelected: m,
1184
+ loadAnnotations: c,
1172
1185
  redo: e.redo,
1173
- removeAnnotation: m,
1174
- setAnnotations: p,
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
- }, kt = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, ln = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1206
- const { id: o, type: i, purpose: r, value: a, created: s, creator: u, ...f } = n;
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
- creator: kt(u),
1215
- ...f
1228
+ updated: u ? new Date(u) : void 0,
1229
+ ...m
1216
1230
  };
1217
- }), cn = (t) => t.map((e) => {
1218
- var n, o;
1219
- const i = { ...e };
1220
- return delete i.annotation, (n = i.id) != null && n.startsWith("temp-") && delete i.id, { ...i, created: (o = i.created) == null ? void 0 : o.toISOString() };
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: kt(n),
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 b = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((l, m) => {
1242
- switch (m.type) {
1259
+ const m = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((c, p) => {
1260
+ switch (p.type) {
1243
1261
  case "TextQuoteSelector":
1244
- l.quote = m.exact;
1262
+ c.quote = p.exact;
1245
1263
  break;
1246
1264
  case "TextPositionSelector":
1247
- l.start = m.start, l.end = m.end;
1265
+ c.start = p.start, c.end = p.end;
1248
1266
  break;
1249
1267
  }
1250
- return l;
1268
+ return c;
1251
1269
  }, {});
1252
- if (dn(b))
1253
- s.selector.push({ id: u.id, ...b });
1270
+ if (dn(m))
1271
+ s.selector.push({ id: u.id, ...m });
1254
1272
  else {
1255
- const l = [
1256
- b.start ? void 0 : "TextPositionSelector",
1257
- b.quote ? void 0 : "TextQuoteSelector"
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: ${l.join(" and ")} for annotation: ${t.id}`) };
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 || Xt(), {
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 = ln(r, e), u = un(t);
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
- ...b
1286
- } = i, l = a.map((m) => {
1287
- const { quote: p, start: x, end: v, range: h } = m, { prefix: d, suffix: c } = te(h, n), y = [{
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: p,
1307
+ exact: g,
1290
1308
  prefix: d,
1291
- suffix: c
1309
+ suffix: l
1292
1310
  }, {
1293
1311
  type: "TextPositionSelector",
1294
1312
  start: x,
1295
1313
  end: v
1296
1314
  }];
1297
1315
  return {
1298
- ...b,
1299
- id: m.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: cn(t.bodies),
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: l
1331
+ target: c
1314
1332
  };
1315
1333
  };
1316
- function pn(t, e, n, o, i) {
1317
- Yt(t, e, n || 0, o || t.length - 1, i || gn);
1334
+ function gn(t, e, n, o, i) {
1335
+ $t(t, e, n || 0, o || t.length - 1, i || pn);
1318
1336
  }
1319
- function Yt(t, e, n, o, i) {
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), b = Math.max(n, Math.floor(e - a * u / r + f)), l = Math.min(o, Math.floor(e + (r - a) * u / r + f));
1323
- Yt(t, e, b, l, i);
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 m = t[e], p = n, x = o;
1326
- for (W(t, n, e), i(t[o], m) > 0 && W(t, n, o); p < x; ) {
1327
- for (W(t, p, x), p++, x--; i(t[p], m) < 0; )
1328
- p++;
1329
- for (; i(t[x], m) > 0; )
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], m) === 0 ? W(t, n, x) : (x++, W(t, x, o)), x <= e && (n = x + 1), e <= x && (o = x - 1);
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 W(t, e, n) {
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 gn(t, e) {
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 (!tt(e, n))
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
- tt(e, u) && (n.leaf ? o.push(s) : dt(e, u) ? this._all(s, o) : r.push(s));
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 (!tt(e, n))
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 (tt(e, a)) {
1373
- if (n.leaf || dt(e, a))
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 = z([]), this;
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 b = bn(e, o.children, n);
1419
- if (b !== -1)
1420
- return o.children.splice(b, 1), r.push(o), this._condense(r), this;
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 && dt(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;
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 = z(e.slice(n, o + 1)), P(s, this.toBBox), s;
1452
- i || (i = Math.ceil(Math.log(r) / Math.log(a)), a = Math.ceil(r / Math.pow(a, i - 1))), s = z([]), s.leaf = !1, s.height = i;
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
- Bt(e, n, o, f, this.compareMinX);
1455
- for (let b = n; b <= o; b += f) {
1456
- const l = Math.min(b + f - 1, o);
1457
- Bt(e, b, l, u, this.compareMinY);
1458
- for (let m = b; m <= l; m += u) {
1459
- const p = Math.min(m + u - 1, l);
1460
- s.children.push(this._build(e, m, p, i - 1));
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 P(s, this.toBBox), s;
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], b = ct(f), l = wn(e, f) - b;
1470
- l < a ? (a = l, r = b < r ? b : r, s = f) : l === a && b < r && (r = b, s = f);
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), j(a, i); n >= 0 && r[n].children.length > this._maxEntries; )
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 = z(o.children.splice(a, o.children.length - a));
1487
- s.height = o.height, s.leaf = o.leaf, P(o, this.toBBox), P(s, this.toBBox), n ? e[n - 1].children.push(s) : this._splitRoot(o, s);
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 = z([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, P(this.data, this.toBBox);
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 = q(e, 0, s, this.toBBox), f = q(e, s, o, this.toBBox), b = xn(u, f), l = ct(u) + ct(f);
1496
- b < r ? (r = b, i = s, a = l < a ? l : a) : b === r && l < a && (a = l, i = s);
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 = q(e, 0, n, r), s = q(e, o - n, o, r);
1509
- let u = Z(a) + Z(s);
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 b = e.children[f];
1512
- j(a, e.leaf ? r(b) : b), u += Z(a);
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 b = e.children[f];
1516
- j(s, e.leaf ? r(b) : b), u += Z(s);
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
- j(n[i], e);
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() : P(e[n], this.toBBox);
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 P(t, e) {
1538
- q(t, 0, t.children.length, e, t);
1555
+ function F(t, e) {
1556
+ G(t, 0, t.children.length, e, t);
1539
1557
  }
1540
- function q(t, e, n, o, i) {
1541
- i || (i = z(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
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
- j(i, t.leaf ? o(a) : a);
1562
+ K(i, t.leaf ? o(a) : a);
1545
1563
  }
1546
1564
  return i;
1547
1565
  }
1548
- function j(t, e) {
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 ct(t) {
1575
+ function ut(t) {
1558
1576
  return (t.maxX - t.minX) * (t.maxY - t.minY);
1559
1577
  }
1560
- function Z(t) {
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 dt(t, e) {
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 tt(t, e) {
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 z(t) {
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 Bt(t, e, n, o, i) {
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
- pn(t, a, e, n, i), r.push(e, a, a, n);
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, c) => {
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 : Mt(C, e).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: g }) => new DOMRect(C - c.left, E - c.top, N - C, g - E));
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: g, height: A } = C;
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 + g,
1608
- maxY: N + A,
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 c = i(d, e.getBoundingClientRect());
1619
- c.forEach((y) => n.insert(y)), o.set(d.annotation, c);
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 c = o.get(d.annotation);
1622
- c && (c.forEach((y) => n.remove(y)), o.delete(d.annotation));
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
- }, b = (d, c = !0) => {
1626
- c && a();
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
- }, l = (d, c) => {
1649
+ }, c = (d, l) => {
1632
1650
  const y = n.search({
1633
1651
  minX: d,
1634
- minY: c,
1652
+ minY: l,
1635
1653
  maxX: d,
1636
- maxY: c
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
- }, m = (d) => {
1641
- const c = p(d);
1642
- if (c.length === 0)
1658
+ }, p = (d) => {
1659
+ const l = g(d);
1660
+ if (l.length === 0)
1643
1661
  return;
1644
- let y = c[0].left, T = c[0].top, C = c[0].right, E = c[0].bottom;
1645
- for (let N = 1; N < c.length; N++) {
1646
- const g = c[N];
1647
- y = Math.min(y, g.left), T = Math.min(T, g.top), C = Math.max(C, g.right), E = Math.max(E, g.bottom);
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
- }, p = (d) => {
1651
- const c = o.get(d);
1652
- return c ? c[0].annotation.rects : [];
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: l,
1658
- getAnnotationBounds: m,
1659
- getAnnotationRects: p,
1660
- getIntersecting: (d, c, y, T) => {
1661
- const C = n.search({ minX: d, minY: c, maxX: y, maxY: T }), E = new Set(C.reduce((N, g) => [...N, g.annotation.id], []));
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: p(N)
1682
+ rects: g(N)
1665
1683
  })).filter((N) => !!N.annotation);
1666
1684
  },
1667
1685
  insert: s,
1668
- recalculate: () => b(t.all().map((d) => d.target), !0),
1686
+ recalculate: () => m(t.all().map((d) => d.target), !0),
1669
1687
  remove: u,
1670
- set: b,
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 = L.LOCAL) => {
1676
- const d = ot(v, t), c = Y(d.target.selector);
1677
- return c && n.addAnnotation(d, h), c;
1678
- }, u = (v, h = !0, d = L.LOCAL) => {
1679
- const c = v.map((T) => ot(T, t)), y = c.filter((T) => !Y(T.target.selector));
1680
- return y.length > 0 ? (console.warn("Could not revive all targets for these annotations:", y), n.bulkAddAnnotation(c, h, d), y) : (n.bulkAddAnnotation(c, h, d), []);
1681
- }, f = (v, h = L.LOCAL) => {
1682
- const d = v.map((y) => ot(y, t)), c = d.filter((y) => !Y(y.target.selector));
1683
- return c.length > 0 && console.warn("Could not revive all targets for these annotations:", c), d.forEach((y) => {
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
- }), c;
1686
- }, b = (v, h = L.LOCAL) => {
1687
- const d = nt(v, t);
1703
+ }), l;
1704
+ }, m = (v, h = B.LOCAL) => {
1705
+ const d = it(v, t);
1688
1706
  n.updateTarget(d, h);
1689
- }, l = (v, h = L.LOCAL) => {
1690
- const d = v.map((c) => nt(c, t));
1707
+ }, c = (v, h = B.LOCAL) => {
1708
+ const d = v.map((l) => it(l, t));
1691
1709
  n.bulkUpdateTargets(d, h);
1692
- }, m = (v, h) => {
1710
+ }, p = (v, h) => {
1693
1711
  const d = o.getAt(v, h);
1694
1712
  return d ? n.getAnnotation(d) : void 0;
1695
- }, p = (v, h, d, c = 5) => {
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: g }) => h >= g - c && h <= E + c && d >= C - c && d <= N + c);
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) => Y(y.target.selector)), d = (v.deleted || []).filter((y) => Y(y.target.selector)), c = (v.updated || []).filter((y) => Y(y.newValue.target.selector));
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)), (c == null ? void 0 : c.length) > 0 && c.forEach(({ newValue: y }) => o.update(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: l,
1732
+ bulkUpdateTargets: c,
1715
1733
  bulkUpsertAnnotations: f,
1716
- getAnnotationBounds: p,
1717
- getAt: m,
1734
+ getAnnotationBounds: g,
1735
+ getAt: p,
1718
1736
  getIntersecting: o.getIntersecting,
1719
1737
  recalculatePositions: x,
1720
- updateTarget: b
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 = (l) => Array.from(r.entries()).filter(([m, p]) => p.presenceKey === l.presenceKey).map(([m, p]) => m);
1735
- return e.on("selectionChange", (l, m) => {
1736
- a(l).forEach((x) => r.delete(x)), m && m.forEach((x) => r.set(x, l));
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: l, height: m } = o;
1740
- i.clearRect(-0.5, -0.5, l + 1, m + 1);
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: (l, m, p) => {
1763
+ paint: (c, p, g) => {
1746
1764
  n.font && (i.font = n.font);
1747
- const x = r.get(l.annotation.id);
1765
+ const x = r.get(c.annotation.id);
1748
1766
  if (x) {
1749
- const { height: v } = l.rects[0], h = l.rects[0].x + m.left, d = l.rects[0].y + m.top;
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 c = i.measureText(x.appearance.label), y = c.width + 6, T = c.actualBoundingBoxAscent + c.actualBoundingBoxDescent + 8, C = c.fontBoundingBoxAscent ? 8 : 6.5;
1769
+ const l = i.measureText(x.appearance.label), y = l.width + 6, T = l.actualBoundingBoxAscent + l.actualBoundingBoxDescent + 8, C = l.fontBoundingBoxAscent ? 8 : 6.5;
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: p ? 0.45 : 0.18
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 l = o.getContext("2d");
1761
- l.scale(2, 2), l.translate(0.5, 0.5);
1778
+ const c = o.getContext("2d");
1779
+ c.scale(2, 2), c.translate(0.5, 0.5);
1762
1780
  }
1763
1781
  };
1764
- }, Ht = (t) => {
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 : Ht(t.parentElement);
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: b, height: l } = e.getAnnotationBounds(n.id), m = f.top - a.top, p = f.left - a.left, x = i.parentElement ? i.scrollTop : 0, v = i.parentElement ? i.scrollLeft : 0, h = m + x - (s - l) / 2, d = p + v - (u - b) / 2;
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 = Ht(t);
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 = nt(r.target, t), { range: u } = s.selector[0];
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, b;
1793
- const l = (h) => {
1794
- var c;
1810
+ let f = !1, m;
1811
+ const c = (h) => {
1812
+ var l;
1795
1813
  if (!f)
1796
1814
  return;
1797
- !((c = h.target.parentElement) != null && c.closest(_)) ? s = {
1798
- annotation: Xt(),
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", l);
1805
- const m = ft((h) => {
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 && N.closest(_))) {
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 - ((b == null ? void 0 : b.timeStamp) || h.timeStamp) < 1e3 && !s && l(b), d.isCollapsed || !f || !s)
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((g, A) => {
1833
+ (C.length !== s.selector.length || C.some((O, b) => {
1816
1834
  var w;
1817
- return g.toString() !== ((w = s.selector[A]) == null ? void 0 : w.quote);
1835
+ return O.toString() !== ((w = s.selector[b]) == null ? void 0 : w.quote);
1818
1836
  })) && (s = {
1819
1837
  ...s,
1820
- selector: C.map((g) => ie(g, t, o))
1821
- }, i.getAnnotation(s.annotation) ? i.updateTarget(s, L.LOCAL) : (i.addAnnotation({
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, b)));
1843
+ }), r.clickSelect(s.annotation, m)));
1826
1844
  });
1827
- n && document.addEventListener("selectionchange", m);
1828
- const p = (h) => {
1829
- const { target: d, timeStamp: c, offsetX: y, offsetY: T, type: C } = h;
1830
- b = { ...h, target: d, timeStamp: c, offsetX: y, offsetY: T, type: C }, f = h.button === 0;
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", p);
1850
+ t.addEventListener("pointerdown", g);
1833
1851
  const x = (h) => {
1834
1852
  var T;
1835
- if (!!((T = h.target.parentElement) != null && T.closest(_)) || !f)
1853
+ if (!!((T = h.target.parentElement) != null && T.closest(X)) || !f)
1836
1854
  return;
1837
- const c = () => {
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: g } = r;
1841
- (g.length !== 1 || g[0].id !== N.id) && r.clickSelect(N.id, h);
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 - b.timeStamp;
1845
- document.getSelection().isCollapsed && y < 300 ? (s = void 0, c()) : s && r.clickSelect(s.annotation, h);
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", l), document.removeEventListener("selectionchange", m), t.removeEventListener("pointerdown", p), document.removeEventListener("pointerup", x);
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
- }, Ot = "SPANS", Mn = (t, e = {}) => {
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 b = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : Ot : n.renderer || Ot, l = b === "SPANS" ? Se(t, o, r) : b === "CSS_HIGHLIGHTS" ? xe(t, o, r) : b === "CANVAS" ? ue(t, o, r) : void 0;
1860
- if (!l)
1861
- throw `Unknown renderer implementation: ${b}`;
1862
- console.debug(`Using ${b} renderer`), n.style && l.setStyle(n.style);
1863
- const m = Rn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
1864
- return m.setUser(f), {
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
- l.destroy(), m.destroy(), s.destroy();
1885
+ c.destroy(), p.destroy(), s.destroy();
1868
1886
  },
1869
1887
  element: t,
1870
1888
  getUser: () => f,
1871
- setFilter: (E) => l.setFilter(E),
1872
- setStyle: (E) => l.setStyle(E),
1889
+ setFilter: (E) => c.setFilter(E),
1890
+ setStyle: (E) => c.setStyle(E),
1873
1891
  setUser: (E) => {
1874
- f = E, m.setUser(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 && (l.setPainter(Cn(t, E, n.presence)), E.on("selectionChange", () => l.redraw()));
1898
+ E && (c.setPainter(Cn(t, E, n.presence)), E.on("selectionChange", () => c.redraw()));
1881
1899
  },
1882
- setVisible: (E) => l.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
- et as DEFAULT_SELECTED_STYLE,
1891
- H as DEFAULT_STYLE,
1892
- It as NOT_ANNOTATABLE_CLASS,
1893
- _ as NOT_ANNOTATABLE_SELECTOR,
1894
- L as Origin,
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
- ft as debounce,
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
- ut as getRangeAnnotatableContents,
1911
- Y as isRevived,
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
- ot as reviveAnnotation,
1917
- Mt as reviveSelector,
1918
- nt as reviveTarget,
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