@soomo/text-annotator 3.0.0-staging.53 → 3.0.0-staging.55

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.
@@ -63,27 +63,27 @@ function re(t, e = 100, n = {}) {
63
63
  throw new RangeError("`wait` must not be negative.");
64
64
  const { immediate: o } = typeof n == "boolean" ? { immediate: n } : n;
65
65
  let i, r, a, s, l;
66
- function u() {
67
- const p = i, d = r;
68
- return i = void 0, r = void 0, l = t.apply(p, d), l;
66
+ function f() {
67
+ const g = i, u = r;
68
+ return i = void 0, r = void 0, l = t.apply(g, u), l;
69
69
  }
70
70
  function h() {
71
- const p = Date.now() - s;
72
- p < e && p >= 0 ? a = setTimeout(h, e - p) : (a = void 0, o || (l = u()));
71
+ const g = Date.now() - s;
72
+ g < e && g >= 0 ? a = setTimeout(h, e - g) : (a = void 0, o || (l = f()));
73
73
  }
74
- const c = function(...p) {
74
+ const c = function(...g) {
75
75
  if (i && this !== i)
76
76
  throw new Error("Debounced method called with different contexts.");
77
- i = this, r = p, s = Date.now();
78
- const d = o && !a;
79
- return a || (a = setTimeout(h, e)), d && (l = u()), l;
77
+ i = this, r = g, s = Date.now();
78
+ const u = o && !a;
79
+ return a || (a = setTimeout(h, e)), u && (l = f()), l;
80
80
  };
81
81
  return c.clear = () => {
82
82
  a && (clearTimeout(a), a = void 0);
83
83
  }, c.flush = () => {
84
84
  a && c.trigger();
85
85
  }, c.trigger = () => {
86
- l = u(), c.clear();
86
+ l = f(), c.clear();
87
87
  }, c;
88
88
  }
89
89
  _t.exports.debounce = re;
@@ -174,34 +174,34 @@ const Ie = /* @__PURE__ */ Be(ke), Ut = (t, e = 10, n) => {
174
174
  const { start: n, end: o } = t, i = t.offsetReference || e, r = document.createNodeIterator(
175
175
  e,
176
176
  NodeFilter.SHOW_TEXT,
177
- (p) => {
178
- var d;
179
- return (d = p.parentElement) != null && d.closest(j) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
177
+ (g) => {
178
+ var u;
179
+ return (u = g.parentElement) != null && u.closest(j) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
180
180
  }
181
181
  );
182
182
  let a = 0;
183
183
  const s = document.createRange();
184
184
  let l = r.nextNode();
185
185
  l === null && console.error("Could not revive annotation target. Content missing.");
186
- let u = !i;
186
+ let f = !i;
187
187
  for (; l !== null; ) {
188
- if (u || (u = i == null ? void 0 : i.contains(l)), u) {
189
- const p = ((h = l.textContent) == null ? void 0 : h.length) || 0;
190
- if (a + p > n) {
188
+ if (f || (f = i == null ? void 0 : i.contains(l)), f) {
189
+ const g = ((h = l.textContent) == null ? void 0 : h.length) || 0;
190
+ if (a + g > n) {
191
191
  s.setStart(l, n - a);
192
192
  break;
193
193
  }
194
- a += p;
194
+ a += g;
195
195
  }
196
196
  l = r.nextNode();
197
197
  }
198
198
  for (; l !== null; ) {
199
- const p = ((c = l.textContent) == null ? void 0 : c.length) || 0;
200
- if (a + p >= o) {
199
+ const g = ((c = l.textContent) == null ? void 0 : c.length) || 0;
200
+ if (a + g >= o) {
201
201
  s.setEnd(l, o - a);
202
202
  break;
203
203
  }
204
- a += p, l = r.nextNode();
204
+ a += g, l = r.nextNode();
205
205
  }
206
206
  return {
207
207
  ...t,
@@ -263,46 +263,46 @@ const Ie = /* @__PURE__ */ Be(ke), Ut = (t, e = 10, n) => {
263
263
  timeStamp: t.timeStamp
264
264
  }), Vt = (t, e, n, o) => {
265
265
  const { store: i, selection: r, hover: a } = e;
266
- let s, l, u;
266
+ let s, l, f;
267
267
  const h = Ce(n), c = (O) => {
268
- const { x: R, y: g } = t.getBoundingClientRect(), w = i.getAt(O.clientX - R, O.clientY - g, l);
269
- w ? a.current !== w.id && (t.classList.add("hovered"), a.set(w.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
268
+ const { x: R, y: m } = t.getBoundingClientRect(), A = i.getAt(O.clientX - R, O.clientY - m, l);
269
+ A ? a.current !== A.id && (t.classList.add("hovered"), a.set(A.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
270
270
  };
271
271
  t.addEventListener("pointermove", c);
272
- const p = (O = !1) => {
273
- u && u.clear();
274
- const R = Se(t), { minX: g, minY: w, maxX: x, maxY: L } = R, B = l ? i.getIntersecting(g, w, x, L).filter(({ annotation: Y }) => l(Y)) : i.getIntersecting(g, w, x, L), M = r.selected.map(({ id: Y }) => Y), K = B.map(({ annotation: Y, rects: lt }) => {
272
+ const g = (O = !1) => {
273
+ f && f.clear();
274
+ const R = Se(t), { minX: m, minY: A, maxX: v, maxY: L } = R, B = l ? i.getIntersecting(m, A, v, L).filter(({ annotation: Y }) => l(Y)) : i.getIntersecting(m, A, v, L), M = r.selected.map(({ id: Y }) => Y), K = B.map(({ annotation: Y, rects: lt }) => {
275
275
  const Ae = M.includes(Y.id), xe = Y.id === a.current;
276
276
  return { annotation: Y, rects: lt, state: { selected: Ae, hover: xe } };
277
277
  });
278
- o.redraw(K, R, s, u, O), setTimeout(() => h(B.map(({ annotation: Y }) => Y)), 1);
279
- }, d = (O) => {
280
- u = O, p();
281
- }, A = (O) => {
282
- s = O, p();
283
- }, v = (O) => {
284
- l = O, p(!1);
285
- }, S = () => p();
286
- i.observe(S);
287
- const m = r.subscribe(() => p()), f = () => p(!0);
288
- document.addEventListener("scroll", f, { capture: !0, passive: !0 });
278
+ o.redraw(K, R, s, f, O), setTimeout(() => h(B.map(({ annotation: Y }) => Y)), 1);
279
+ }, u = (O) => {
280
+ f = O, g();
281
+ }, x = (O) => {
282
+ s = O, g();
283
+ }, b = (O) => {
284
+ l = O, g(!1);
285
+ }, C = () => g();
286
+ i.observe(C);
287
+ const p = r.subscribe(() => g()), d = () => g(!0);
288
+ document.addEventListener("scroll", d, { capture: !0, passive: !0 });
289
289
  const y = Ut(() => {
290
- i.recalculatePositions(), u == null || u.reset(), p();
290
+ i.recalculatePositions(), f == null || f.reset(), g();
291
291
  });
292
292
  window.addEventListener("resize", y);
293
- const C = new ResizeObserver(y);
294
- C.observe(t);
295
- const E = { attributes: !0, childList: !0, subtree: !0 }, b = new MutationObserver((O) => {
296
- O.every((g) => g.target === t || t.contains(g.target)) || p(!0);
293
+ const S = new ResizeObserver(y);
294
+ S.observe(t);
295
+ const E = { attributes: !0, childList: !0, subtree: !0 }, w = new MutationObserver((O) => {
296
+ O.every((m) => m.target === t || t.contains(m.target)) || g(!0);
297
297
  });
298
- return b.observe(document.body, E), {
298
+ return w.observe(document.body, E), {
299
299
  destroy: () => {
300
- t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(S), m(), document.removeEventListener("scroll", f), y.clear(), window.removeEventListener("resize", y), C.disconnect(), b.disconnect();
300
+ t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(C), p(), document.removeEventListener("scroll", d), y.clear(), window.removeEventListener("resize", y), S.disconnect(), w.disconnect();
301
301
  },
302
- redraw: p,
303
- setStyle: A,
304
- setFilter: v,
305
- setPainter: d,
302
+ redraw: g,
303
+ setStyle: x,
304
+ setFilter: b,
305
+ setPainter: u,
306
306
  setVisible: o.setVisible
307
307
  };
308
308
  }, He = () => {
@@ -314,28 +314,28 @@ const Ie = /* @__PURE__ */ Be(ke), Ut = (t, e = 10, n) => {
314
314
  t.classList.add("r6o-annotatable");
315
315
  const e = He(), n = e.getContext("2d");
316
316
  document.body.appendChild(e);
317
- const o = (s, l, u, h) => requestAnimationFrame(() => {
318
- const { width: c, height: p } = e;
319
- n.clearRect(-0.5, -0.5, c + 1, p + 1), h && h.clear();
320
- const { top: d, left: A } = l;
321
- [...s].sort((S, m) => {
322
- const { annotation: { target: { created: f } } } = S, { annotation: { target: { created: y } } } = m;
323
- return f.getTime() - y.getTime();
324
- }).forEach((S) => {
325
- var C;
326
- const m = u ? typeof u == "function" ? u(S.annotation, S.state) : u : (C = S.state) != null && C.selected ? yt : q, f = h && h.paint(S, l) || m, y = S.rects.map(({ x: E, y: b, width: T, height: O }) => ({
327
- x: E + A,
328
- y: b + d,
317
+ const o = (s, l, f, h) => requestAnimationFrame(() => {
318
+ const { width: c, height: g } = e;
319
+ n.clearRect(-0.5, -0.5, c + 1, g + 1), h && h.clear();
320
+ const { top: u, left: x } = l;
321
+ [...s].sort((C, p) => {
322
+ const { annotation: { target: { created: d } } } = C, { annotation: { target: { created: y } } } = p;
323
+ return d.getTime() - y.getTime();
324
+ }).forEach((C) => {
325
+ var S;
326
+ const p = f ? typeof f == "function" ? f(C.annotation, C.state) : f : (S = C.state) != null && S.selected ? yt : q, d = h && h.paint(C, l) || p, y = C.rects.map(({ x: E, y: w, width: T, height: O }) => ({
327
+ x: E + x,
328
+ y: w + u,
329
329
  width: T,
330
330
  height: O
331
331
  }));
332
- if (n.fillStyle = f.fill, n.globalAlpha = f.fillOpacity || 1, y.forEach(
333
- ({ x: E, y: b, width: T, height: O }) => n.fillRect(E, b, T, O)
334
- ), f.underlineColor) {
335
- n.globalAlpha = 1, n.strokeStyle = f.underlineColor, n.lineWidth = f.underlineThickness ?? 1;
336
- const E = f.underlineOffset ?? 0;
337
- y.forEach(({ x: b, y: T, width: O, height: R }) => {
338
- n.beginPath(), n.moveTo(b, T + R + E), n.lineTo(b + O, T + R + E), n.stroke();
332
+ if (n.fillStyle = d.fill, n.globalAlpha = d.fillOpacity || 1, y.forEach(
333
+ ({ x: E, y: w, width: T, height: O }) => n.fillRect(E, w, T, O)
334
+ ), d.underlineColor) {
335
+ n.globalAlpha = 1, n.strokeStyle = d.underlineColor, n.lineWidth = d.underlineThickness ?? 1;
336
+ const E = d.underlineOffset ?? 0;
337
+ y.forEach(({ x: w, y: T, width: O, height: R }) => {
338
+ n.beginPath(), n.moveTo(w, T + R + E), n.lineTo(w + O, T + R + E), n.stroke();
339
339
  });
340
340
  }
341
341
  });
@@ -371,8 +371,8 @@ var qe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
371
371
  }, le = function(t) {
372
372
  var e = t.h, n = t.s, o = t.v, i = t.a;
373
373
  e = e / 360 * 6, n /= 100, o /= 100;
374
- var r = Math.floor(e), a = o * (1 - n), s = o * (1 - (e - r) * n), l = o * (1 - (1 - e + r) * n), u = r % 6;
375
- return { r: 255 * [o, s, a, a, l, o][u], g: 255 * [l, o, o, s, a, a][u], b: 255 * [a, a, l, o, o, s][u], a: i };
374
+ var r = Math.floor(e), a = o * (1 - n), s = o * (1 - (e - r) * n), l = o * (1 - (1 - e + r) * n), f = r % 6;
375
+ return { r: 255 * [o, s, a, a, l, o][f], g: 255 * [l, o, o, s, a, a][f], b: 255 * [a, a, l, o, o, s][f], a: i };
376
376
  }, Xt = function(t) {
377
377
  return { h: ae(t.h), s: X(t.s, 0, 100), l: X(t.l, 0, 100), a: X(t.a) };
378
378
  }, Pt = function(t) {
@@ -499,18 +499,18 @@ const nn = (t) => [
499
499
  },
500
500
  redraw: (r, a, s, l) => {
501
501
  l && l.clear();
502
- const u = new Set(r.map((c) => c.annotation.id));
503
- Array.from(e).filter((c) => !u.has(c));
502
+ const f = new Set(r.map((c) => c.annotation.id));
503
+ Array.from(e).filter((c) => !f.has(c));
504
504
  const h = r.map((c) => {
505
- var A;
506
- const p = s ? typeof s == "function" ? s(c.annotation, c.state) : s : (A = c.state) != null && A.selected ? yt : q, d = l && l.paint(c, a) || p;
507
- return `::highlight(_${c.annotation.id}) { ${nn(d)} }`;
505
+ var x;
506
+ const g = s ? typeof s == "function" ? s(c.annotation, c.state) : s : (x = c.state) != null && x.selected ? yt : q, u = l && l.paint(c, a) || g;
507
+ return `::highlight(_${c.annotation.id}) { ${nn(u)} }`;
508
508
  });
509
509
  t.innerHTML = h.join(`
510
510
  `), CSS.highlights.clear(), r.forEach(({ annotation: c }) => {
511
- const p = c.target.selector.map((A) => A.range), d = new Highlight(...p);
512
- CSS.highlights.set(`_${c.id}`, d);
513
- }), e = u;
511
+ const g = c.target.selector.map((x) => x.range), u = new Highlight(...g);
512
+ CSS.highlights.set(`_${c.id}`, u);
513
+ }), e = f;
514
514
  }
515
515
  };
516
516
  }, rn = (t, e, n) => Vt(t, e, n, on());
@@ -547,17 +547,21 @@ const sn = (t, e) => {
547
547
  destroy: () => {
548
548
  e.remove();
549
549
  },
550
- redraw: (a, s, l, u, h) => {
551
- const p = !(It(n, a) && h);
552
- !u && !p || (p && (e.innerHTML = ""), [...a].forEach((d) => {
553
- d.rects.map((A) => {
554
- const v = sn(A, a), S = Ee(d, s, l, u, v);
555
- if (p) {
556
- const m = document.createElement("span");
557
- m.className = "r6o-annotation", m.dataset.annotation = d.annotation.id, m.style.left = `${A.x}px`, m.style.top = `${A.y}px`, m.style.width = `${A.width}px`, m.style.height = `${A.height}px`, m.style.backgroundColor = P((S == null ? void 0 : S.fill) || q.fill).alpha((S == null ? void 0 : S.fillOpacity) === void 0 ? q.fillOpacity : S.fillOpacity).toHex(), S.underlineStyle && (m.style.borderStyle = S.underlineStyle), S.underlineColor && (m.style.borderColor = S.underlineColor), S.underlineThickness && (m.style.borderBottomWidth = `${S.underlineThickness}px`), S.underlineOffset && (m.style.paddingBottom = `${S.underlineOffset}px`), e.appendChild(m);
550
+ redraw: (a, s, l, f, h) => {
551
+ const g = !(It(n, a) && h);
552
+ if (!f && !g) return;
553
+ g && (e.innerHTML = ""), [...a].sort((x, b) => {
554
+ const { annotation: { target: { created: C } } } = x, { annotation: { target: { created: p } } } = b;
555
+ return console.log(x.annotation), console.log(b.annotation), C && p ? C.getTime() - p.getTime() : 0;
556
+ }).forEach((x) => {
557
+ x.rects.map((b) => {
558
+ const C = sn(b, a), p = Ee(x, s, l, f, C);
559
+ if (g) {
560
+ const d = document.createElement("span");
561
+ d.className = "r6o-annotation", d.dataset.annotation = x.annotation.id, d.style.left = `${b.x}px`, d.style.top = `${b.y}px`, d.style.width = `${b.width}px`, d.style.height = `${b.height}px`, d.style.backgroundColor = P((p == null ? void 0 : p.fill) || q.fill).alpha((p == null ? void 0 : p.fillOpacity) === void 0 ? q.fillOpacity : p.fillOpacity).toHex(), p.underlineStyle && (d.style.borderStyle = p.underlineStyle), p.underlineColor && (d.style.borderColor = p.underlineColor), p.underlineThickness && (d.style.borderBottomWidth = `${p.underlineThickness}px`), p.underlineOffset && (d.style.paddingBottom = `${p.underlineOffset}px`), e.appendChild(d);
558
562
  }
559
563
  });
560
- }), n = a);
564
+ }), n = a;
561
565
  },
562
566
  setVisible: (a) => {
563
567
  a ? e.classList.remove("hidden") : e.classList.add("hidden");
@@ -620,11 +624,11 @@ function Dt(t, e = St) {
620
624
  function i(s) {
621
625
  if (hn(t, s) && (t = s, n)) {
622
626
  const l = !Q.length;
623
- for (const u of o)
624
- u[1](), Q.push(u, t);
627
+ for (const f of o)
628
+ f[1](), Q.push(f, t);
625
629
  if (l) {
626
- for (let u = 0; u < Q.length; u += 2)
627
- Q[u][0](Q[u + 1]);
630
+ for (let f = 0; f < Q.length; f += 2)
631
+ Q[f][0](Q[f + 1]);
628
632
  Q.length = 0;
629
633
  }
630
634
  }
@@ -633,14 +637,14 @@ function Dt(t, e = St) {
633
637
  i(s(t));
634
638
  }
635
639
  function a(s, l = St) {
636
- const u = [s, l];
637
- return o.add(u), o.size === 1 && (n = e(i, r) || St), s(t), () => {
638
- o.delete(u), o.size === 0 && n && (n(), n = null);
640
+ const f = [s, l];
641
+ return o.add(f), o.size === 1 && (n = e(i, r) || St), s(t), () => {
642
+ o.delete(f), o.size === 0 && n && (n(), n = null);
639
643
  };
640
644
  }
641
645
  return { set: i, update: r, subscribe: a };
642
646
  }
643
- const pn = (t) => {
647
+ const gn = (t) => {
644
648
  const { subscribe: e, set: n } = Dt();
645
649
  let o;
646
650
  return e((i) => o = i), t.observe(({ changes: i }) => {
@@ -657,53 +661,53 @@ const pn = (t) => {
657
661
  set: n
658
662
  };
659
663
  };
660
- var gn = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(gn || {});
664
+ var pn = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(pn || {});
661
665
  const ft = { selected: [] }, mn = (t, e) => {
662
666
  const { subscribe: n, set: o } = Dt(ft);
663
667
  let i = e, r = ft;
664
- n((d) => r = d);
668
+ n((u) => r = u);
665
669
  const a = () => {
666
670
  G(r, ft) || o(ft);
667
671
  }, s = () => {
668
- var d;
669
- return ((d = r.selected) == null ? void 0 : d.length) === 0;
670
- }, l = (d) => {
672
+ var u;
673
+ return ((u = r.selected) == null ? void 0 : u.length) === 0;
674
+ }, l = (u) => {
671
675
  if (s())
672
676
  return !1;
673
- const A = typeof d == "string" ? d : d.id;
674
- return r.selected.some((v) => v.id === A);
675
- }, u = (d, A) => {
676
- const v = t.getAnnotation(d);
677
- if (!v) {
678
- console.warn("Invalid selection: " + d);
677
+ const x = typeof u == "string" ? u : u.id;
678
+ return r.selected.some((b) => b.id === x);
679
+ }, f = (u, x) => {
680
+ const b = t.getAnnotation(u);
681
+ if (!b) {
682
+ console.warn("Invalid selection: " + u);
679
683
  return;
680
684
  }
681
- switch (Qt(v, i)) {
685
+ switch (Qt(b, i)) {
682
686
  case "EDIT":
683
- o({ selected: [{ id: d, editable: !0 }], event: A });
687
+ o({ selected: [{ id: u, editable: !0 }], event: x });
684
688
  break;
685
689
  case "SELECT":
686
- o({ selected: [{ id: d }], event: A });
690
+ o({ selected: [{ id: u }], event: x });
687
691
  break;
688
692
  default:
689
- o({ selected: [], event: A });
693
+ o({ selected: [], event: x });
690
694
  }
691
- }, h = (d, A) => {
692
- const v = Array.isArray(d) ? d : [d], S = v.map((m) => t.getAnnotation(m)).filter((m) => !!m);
695
+ }, h = (u, x) => {
696
+ const b = Array.isArray(u) ? u : [u], C = b.map((p) => t.getAnnotation(p)).filter((p) => !!p);
693
697
  o({
694
- selected: S.map((m) => {
695
- const f = A === void 0 ? Qt(m, i) === "EDIT" : A;
696
- return { id: m.id, editable: f };
698
+ selected: C.map((p) => {
699
+ const d = x === void 0 ? Qt(p, i) === "EDIT" : x;
700
+ return { id: p.id, editable: d };
697
701
  })
698
- }), S.length !== v.length && console.warn("Invalid selection", d);
699
- }, c = (d) => {
702
+ }), C.length !== b.length && console.warn("Invalid selection", u);
703
+ }, c = (u) => {
700
704
  if (s())
701
705
  return !1;
702
- const { selected: A } = r;
703
- A.some(({ id: v }) => d.includes(v)) && o({ selected: A.filter(({ id: v }) => !d.includes(v)) });
704
- }, p = (d) => i = d;
706
+ const { selected: x } = r;
707
+ x.some(({ id: b }) => u.includes(b)) && o({ selected: x.filter(({ id: b }) => !u.includes(b)) });
708
+ }, g = (u) => i = u;
705
709
  return t.observe(
706
- ({ changes: d }) => c((d.deleted || []).map((A) => A.id))
710
+ ({ changes: u }) => c((u.deleted || []).map((x) => x.id))
707
711
  ), {
708
712
  get event() {
709
713
  return r ? r.event : null;
@@ -718,9 +722,9 @@ const ft = { selected: [] }, mn = (t, e) => {
718
722
  isEmpty: s,
719
723
  isSelected: l,
720
724
  setSelected: h,
721
- setUserSelectAction: p,
725
+ setUserSelectAction: g,
722
726
  subscribe: n,
723
- userSelect: u
727
+ userSelect: f
724
728
  };
725
729
  }, Qt = (t, e) => typeof e == "function" ? e(t) : e || "EDIT";
726
730
  var V = [];
@@ -781,8 +785,8 @@ const Cn = (t, e) => {
781
785
  if (t.options.ignore) {
782
786
  const { ignore: a } = t.options, s = (l) => l && l.length > 0;
783
787
  if (!(s(i.created) || s(i.deleted))) {
784
- const l = (n = i.updated) == null ? void 0 : n.some((h) => s(h.bodiesCreated) || s(h.bodiesDeleted) || s(h.bodiesUpdated)), u = (o = i.updated) == null ? void 0 : o.some((h) => h.targetUpdated);
785
- if (a === "BODY_ONLY" && l && !u || a === "TARGET_ONLY" && u && !l)
788
+ const l = (n = i.updated) == null ? void 0 : n.some((h) => s(h.bodiesCreated) || s(h.bodiesDeleted) || s(h.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((h) => h.targetUpdated);
789
+ if (a === "BODY_ONLY" && l && !f || a === "TARGET_ONLY" && f && !l)
786
790
  return !1;
787
791
  }
788
792
  }
@@ -797,23 +801,23 @@ const Cn = (t, e) => {
797
801
  return !0;
798
802
  }, Ln = (t, e) => {
799
803
  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)), l = [
800
- ...(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),
804
+ ...(t.created || []).filter((c) => !r.has(c.id)).map((c) => a.has(c.id) ? e.updated.find(({ oldValue: g }) => g.id === c.id).newValue : c),
801
805
  ...e.created || []
802
- ], u = [
806
+ ], f = [
803
807
  ...(t.deleted || []).filter((c) => !i.has(c.id)),
804
808
  ...(e.deleted || []).filter((c) => !n.has(c.id))
805
809
  ], h = [
806
810
  ...(t.updated || []).filter(({ newValue: c }) => !r.has(c.id)).map((c) => {
807
- const { oldValue: p, newValue: d } = c;
808
- if (a.has(d.id)) {
809
- const A = e.updated.find((v) => v.oldValue.id === d.id).newValue;
810
- return fe(p, A);
811
+ const { oldValue: g, newValue: u } = c;
812
+ if (a.has(u.id)) {
813
+ const x = e.updated.find((b) => b.oldValue.id === u.id).newValue;
814
+ return fe(g, x);
811
815
  } else
812
816
  return c;
813
817
  }),
814
818
  ...(e.updated || []).filter(({ oldValue: c }) => !s.has(c.id))
815
819
  ];
816
- return { created: l, deleted: u, updated: h };
820
+ return { created: l, deleted: f, updated: h };
817
821
  }, Lt = (t) => {
818
822
  const e = t.id === void 0 ? ue() : t.id;
819
823
  return {
@@ -829,73 +833,73 @@ const Cn = (t, e) => {
829
833
  }
830
834
  };
831
835
  }, On = (t) => t.id !== void 0, Tn = () => {
832
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (g, w = {}) => {
833
- n.push({ onChange: g, options: w });
834
- }, i = (g) => {
835
- const w = n.findIndex((x) => x.onChange == g);
836
- w > -1 && n.splice(w, 1);
837
- }, r = (g, w) => {
838
- const x = {
839
- origin: g,
836
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (m, A = {}) => {
837
+ n.push({ onChange: m, options: A });
838
+ }, i = (m) => {
839
+ const A = n.findIndex((v) => v.onChange == m);
840
+ A > -1 && n.splice(A, 1);
841
+ }, r = (m, A) => {
842
+ const v = {
843
+ origin: m,
840
844
  changes: {
841
- created: w.created || [],
842
- updated: w.updated || [],
843
- deleted: w.deleted || []
845
+ created: A.created || [],
846
+ updated: A.updated || [],
847
+ deleted: A.deleted || []
844
848
  },
845
849
  state: [...t.values()]
846
850
  };
847
851
  n.forEach((L) => {
848
- Cn(L, x) && L.onChange(x);
852
+ Cn(L, v) && L.onChange(v);
849
853
  });
850
- }, a = (g, w = k.LOCAL) => {
851
- if (g.id && t.get(g.id))
852
- throw Error(`Cannot add annotation ${g.id} - exists already`);
854
+ }, a = (m, A = k.LOCAL) => {
855
+ if (m.id && t.get(m.id))
856
+ throw Error(`Cannot add annotation ${m.id} - exists already`);
853
857
  {
854
- const x = Lt(g);
855
- t.set(x.id, x), x.bodies.forEach((L) => e.set(L.id, x.id)), r(w, { created: [x] });
858
+ const v = Lt(m);
859
+ t.set(v.id, v), v.bodies.forEach((L) => e.set(L.id, v.id)), r(A, { created: [v] });
856
860
  }
857
- }, s = (g, w) => {
858
- const x = Lt(typeof g == "string" ? w : g), L = typeof g == "string" ? g : g.id, B = L && t.get(L);
861
+ }, s = (m, A) => {
862
+ const v = Lt(typeof m == "string" ? A : m), L = typeof m == "string" ? m : m.id, B = L && t.get(L);
859
863
  if (B) {
860
- const M = fe(B, x);
861
- return L === x.id ? t.set(L, x) : (t.delete(L), t.set(x.id, x)), B.bodies.forEach((K) => e.delete(K.id)), x.bodies.forEach((K) => e.set(K.id, x.id)), M;
864
+ const M = fe(B, v);
865
+ return L === v.id ? t.set(L, v) : (t.delete(L), t.set(v.id, v)), B.bodies.forEach((K) => e.delete(K.id)), v.bodies.forEach((K) => e.set(K.id, v.id)), M;
862
866
  } else
863
867
  console.warn(`Cannot update annotation ${L} - does not exist`);
864
- }, l = (g, w = k.LOCAL, x = k.LOCAL) => {
865
- const L = On(w) ? x : w, B = s(g, w);
868
+ }, l = (m, A = k.LOCAL, v = k.LOCAL) => {
869
+ const L = On(A) ? v : A, B = s(m, A);
866
870
  B && r(L, { updated: [B] });
867
- }, u = (g, w = k.LOCAL) => {
868
- const x = g.reduce((L, B) => {
871
+ }, f = (m, A = k.LOCAL) => {
872
+ const v = m.reduce((L, B) => {
869
873
  const M = s(B);
870
874
  return M ? [...L, M] : L;
871
875
  }, []);
872
- x.length > 0 && r(w, { updated: x });
873
- }, h = (g, w = k.LOCAL) => {
874
- const x = t.get(g.annotation);
875
- if (x) {
876
+ v.length > 0 && r(A, { updated: v });
877
+ }, h = (m, A = k.LOCAL) => {
878
+ const v = t.get(m.annotation);
879
+ if (v) {
876
880
  const L = {
877
- ...x,
878
- bodies: [...x.bodies, g]
881
+ ...v,
882
+ bodies: [...v.bodies, m]
879
883
  };
880
- t.set(x.id, L), e.set(g.id, L.id), r(w, { updated: [{
881
- oldValue: x,
884
+ t.set(v.id, L), e.set(m.id, L.id), r(A, { updated: [{
885
+ oldValue: v,
882
886
  newValue: L,
883
- bodiesCreated: [g]
887
+ bodiesCreated: [m]
884
888
  }] });
885
889
  } else
886
- console.warn(`Attempt to add body to missing annotation: ${g.annotation}`);
887
- }, c = () => [...t.values()], p = (g = k.LOCAL) => {
888
- const w = [...t.values()];
889
- t.clear(), e.clear(), r(g, { deleted: w });
890
- }, d = (g, w = !0, x = k.LOCAL) => {
891
- const L = g.map(Lt);
892
- if (w) {
890
+ console.warn(`Attempt to add body to missing annotation: ${m.annotation}`);
891
+ }, c = () => [...t.values()], g = (m = k.LOCAL) => {
892
+ const A = [...t.values()];
893
+ t.clear(), e.clear(), r(m, { deleted: A });
894
+ }, u = (m, A = !0, v = k.LOCAL) => {
895
+ const L = m.map(Lt);
896
+ if (A) {
893
897
  const B = [...t.values()];
894
898
  t.clear(), e.clear(), L.forEach((M) => {
895
899
  t.set(M.id, M), M.bodies.forEach((K) => e.set(K.id, M.id));
896
- }), r(x, { created: L, deleted: B });
900
+ }), r(v, { created: L, deleted: B });
897
901
  } else {
898
- const B = g.reduce((M, K) => {
902
+ const B = m.reduce((M, K) => {
899
903
  const Y = K.id && t.get(K.id);
900
904
  return Y ? [...M, Y] : M;
901
905
  }, []);
@@ -903,127 +907,127 @@ const Cn = (t, e) => {
903
907
  throw Error(`Bulk insert would overwrite the following annotations: ${B.map((M) => M.id).join(", ")}`);
904
908
  L.forEach((M) => {
905
909
  t.set(M.id, M), M.bodies.forEach((K) => e.set(K.id, M.id));
906
- }), r(x, { created: L });
910
+ }), r(v, { created: L });
907
911
  }
908
- }, A = (g) => {
909
- const w = typeof g == "string" ? g : g.id, x = t.get(w);
910
- if (x)
911
- return t.delete(w), x.bodies.forEach((L) => e.delete(L.id)), x;
912
- console.warn(`Attempt to delete missing annotation: ${w}`);
913
- }, v = (g, w = k.LOCAL) => {
914
- const x = A(g);
915
- x && r(w, { deleted: [x] });
916
- }, S = (g, w = k.LOCAL) => {
917
- const x = g.reduce((L, B) => {
918
- const M = A(B);
912
+ }, x = (m) => {
913
+ const A = typeof m == "string" ? m : m.id, v = t.get(A);
914
+ if (v)
915
+ return t.delete(A), v.bodies.forEach((L) => e.delete(L.id)), v;
916
+ console.warn(`Attempt to delete missing annotation: ${A}`);
917
+ }, b = (m, A = k.LOCAL) => {
918
+ const v = x(m);
919
+ v && r(A, { deleted: [v] });
920
+ }, C = (m, A = k.LOCAL) => {
921
+ const v = m.reduce((L, B) => {
922
+ const M = x(B);
919
923
  return M ? [...L, M] : L;
920
924
  }, []);
921
- x.length > 0 && r(w, { deleted: x });
922
- }, m = (g) => {
923
- const w = t.get(g.annotation);
924
- if (w) {
925
- const x = w.bodies.find((L) => L.id === g.id);
926
- if (x) {
927
- e.delete(x.id);
925
+ v.length > 0 && r(A, { deleted: v });
926
+ }, p = (m) => {
927
+ const A = t.get(m.annotation);
928
+ if (A) {
929
+ const v = A.bodies.find((L) => L.id === m.id);
930
+ if (v) {
931
+ e.delete(v.id);
928
932
  const L = {
929
- ...w,
930
- bodies: w.bodies.filter((B) => B.id !== g.id)
933
+ ...A,
934
+ bodies: A.bodies.filter((B) => B.id !== m.id)
931
935
  };
932
- return t.set(w.id, L), {
933
- oldValue: w,
936
+ return t.set(A.id, L), {
937
+ oldValue: A,
934
938
  newValue: L,
935
- bodiesDeleted: [x]
939
+ bodiesDeleted: [v]
936
940
  };
937
941
  } else
938
- console.warn(`Attempt to delete missing body ${g.id} from annotation ${g.annotation}`);
942
+ console.warn(`Attempt to delete missing body ${m.id} from annotation ${m.annotation}`);
939
943
  } else
940
- console.warn(`Attempt to delete body from missing annotation ${g.annotation}`);
941
- }, f = (g, w = k.LOCAL) => {
942
- const x = m(g);
943
- x && r(w, { updated: [x] });
944
- }, y = (g, w = k.LOCAL) => {
945
- const x = g.map((L) => m(L)).filter(Boolean);
946
- x.length > 0 && r(w, { updated: x });
947
- }, C = (g) => {
948
- const w = t.get(g);
949
- return w ? { ...w } : void 0;
950
- }, E = (g) => {
951
- const w = e.get(g);
952
- if (w) {
953
- const x = C(w).bodies.find((L) => L.id === g);
954
- if (x)
955
- return x;
956
- console.error(`Store integrity error: body ${g} in index, but not in annotation`);
944
+ console.warn(`Attempt to delete body from missing annotation ${m.annotation}`);
945
+ }, d = (m, A = k.LOCAL) => {
946
+ const v = p(m);
947
+ v && r(A, { updated: [v] });
948
+ }, y = (m, A = k.LOCAL) => {
949
+ const v = m.map((L) => p(L)).filter(Boolean);
950
+ v.length > 0 && r(A, { updated: v });
951
+ }, S = (m) => {
952
+ const A = t.get(m);
953
+ return A ? { ...A } : void 0;
954
+ }, E = (m) => {
955
+ const A = e.get(m);
956
+ if (A) {
957
+ const v = S(A).bodies.find((L) => L.id === m);
958
+ if (v)
959
+ return v;
960
+ console.error(`Store integrity error: body ${m} in index, but not in annotation`);
957
961
  } else
958
- console.warn(`Attempt to retrieve missing body: ${g}`);
959
- }, b = (g, w) => {
960
- if (g.annotation !== w.annotation)
962
+ console.warn(`Attempt to retrieve missing body: ${m}`);
963
+ }, w = (m, A) => {
964
+ if (m.annotation !== A.annotation)
961
965
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
962
- const x = t.get(g.annotation);
963
- if (x) {
964
- const L = x.bodies.find((M) => M.id === g.id), B = {
965
- ...x,
966
- bodies: x.bodies.map((M) => M.id === L.id ? w : M)
966
+ const v = t.get(m.annotation);
967
+ if (v) {
968
+ const L = v.bodies.find((M) => M.id === m.id), B = {
969
+ ...v,
970
+ bodies: v.bodies.map((M) => M.id === L.id ? A : M)
967
971
  };
968
- return t.set(x.id, B), L.id !== w.id && (e.delete(L.id), e.set(w.id, B.id)), {
969
- oldValue: x,
972
+ return t.set(v.id, B), L.id !== A.id && (e.delete(L.id), e.set(A.id, B.id)), {
973
+ oldValue: v,
970
974
  newValue: B,
971
- bodiesUpdated: [{ oldBody: L, newBody: w }]
975
+ bodiesUpdated: [{ oldBody: L, newBody: A }]
972
976
  };
973
977
  } else
974
- console.warn(`Attempt to add body to missing annotation ${g.annotation}`);
975
- }, T = (g, w, x = k.LOCAL) => {
976
- const L = b(g, w);
977
- L && r(x, { updated: [L] });
978
- }, O = (g, w = k.LOCAL) => {
979
- const x = g.map((L) => b({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
980
- r(w, { updated: x });
981
- }, R = (g) => {
982
- const w = t.get(g.annotation);
983
- if (w) {
984
- const x = {
985
- ...w,
978
+ console.warn(`Attempt to add body to missing annotation ${m.annotation}`);
979
+ }, T = (m, A, v = k.LOCAL) => {
980
+ const L = w(m, A);
981
+ L && r(v, { updated: [L] });
982
+ }, O = (m, A = k.LOCAL) => {
983
+ const v = m.map((L) => w({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
984
+ r(A, { updated: v });
985
+ }, R = (m) => {
986
+ const A = t.get(m.annotation);
987
+ if (A) {
988
+ const v = {
989
+ ...A,
986
990
  target: {
987
- ...w.target,
988
- ...g
991
+ ...A.target,
992
+ ...m
989
993
  }
990
994
  };
991
- return t.set(w.id, x), {
992
- oldValue: w,
993
- newValue: x,
995
+ return t.set(A.id, v), {
996
+ oldValue: A,
997
+ newValue: v,
994
998
  targetUpdated: {
995
- oldTarget: w.target,
996
- newTarget: g
999
+ oldTarget: A.target,
1000
+ newTarget: m
997
1001
  }
998
1002
  };
999
1003
  } else
1000
- console.warn(`Attempt to update target on missing annotation: ${g.annotation}`);
1004
+ console.warn(`Attempt to update target on missing annotation: ${m.annotation}`);
1001
1005
  };
1002
1006
  return {
1003
1007
  addAnnotation: a,
1004
1008
  addBody: h,
1005
1009
  all: c,
1006
- bulkAddAnnotation: d,
1007
- bulkDeleteAnnotation: S,
1010
+ bulkAddAnnotation: u,
1011
+ bulkDeleteAnnotation: C,
1008
1012
  bulkDeleteBodies: y,
1009
- bulkUpdateAnnotation: u,
1013
+ bulkUpdateAnnotation: f,
1010
1014
  bulkUpdateBodies: O,
1011
- bulkUpdateTargets: (g, w = k.LOCAL) => {
1012
- const x = g.map((L) => R(L)).filter(Boolean);
1013
- x.length > 0 && r(w, { updated: x });
1015
+ bulkUpdateTargets: (m, A = k.LOCAL) => {
1016
+ const v = m.map((L) => R(L)).filter(Boolean);
1017
+ v.length > 0 && r(A, { updated: v });
1014
1018
  },
1015
- clear: p,
1016
- deleteAnnotation: v,
1017
- deleteBody: f,
1018
- getAnnotation: C,
1019
+ clear: g,
1020
+ deleteAnnotation: b,
1021
+ deleteBody: d,
1022
+ getAnnotation: S,
1019
1023
  getBody: E,
1020
1024
  observe: o,
1021
1025
  unobserve: i,
1022
1026
  updateAnnotation: l,
1023
1027
  updateBody: T,
1024
- updateTarget: (g, w = k.LOCAL) => {
1025
- const x = R(g);
1026
- x && r(w, { updated: [x] });
1028
+ updateTarget: (m, A = k.LOCAL) => {
1029
+ const v = R(m);
1030
+ v && r(A, { updated: [v] });
1027
1031
  }
1028
1032
  };
1029
1033
  };
@@ -1044,38 +1048,38 @@ let Rn = () => ({
1044
1048
  const Mn = 250, Bn = (t) => {
1045
1049
  const e = Rn(), n = [];
1046
1050
  let o = -1, i = !1, r = 0;
1047
- const a = (d) => {
1051
+ const a = (u) => {
1048
1052
  if (!i) {
1049
- const { changes: A } = d, v = performance.now();
1050
- if (v - r > Mn)
1051
- n.splice(o + 1), n.push(A), o = n.length - 1;
1053
+ const { changes: x } = u, b = performance.now();
1054
+ if (b - r > Mn)
1055
+ n.splice(o + 1), n.push(x), o = n.length - 1;
1052
1056
  else {
1053
- const S = n.length - 1;
1054
- n[S] = Ln(n[S], A);
1057
+ const C = n.length - 1;
1058
+ n[C] = Ln(n[C], x);
1055
1059
  }
1056
- r = v;
1060
+ r = b;
1057
1061
  }
1058
1062
  i = !1;
1059
1063
  };
1060
1064
  t.observe(a, { origin: k.LOCAL });
1061
- const s = (d) => d && d.length > 0 && t.bulkDeleteAnnotation(d), l = (d) => d && d.length > 0 && t.bulkAddAnnotation(d, !1), u = (d) => d && d.length > 0 && t.bulkUpdateAnnotation(d.map(({ oldValue: A }) => A)), h = (d) => d && d.length > 0 && t.bulkUpdateAnnotation(d.map(({ newValue: A }) => A)), c = (d) => d && d.length > 0 && t.bulkAddAnnotation(d, !1), p = (d) => d && d.length > 0 && t.bulkDeleteAnnotation(d);
1065
+ const s = (u) => u && u.length > 0 && t.bulkDeleteAnnotation(u), l = (u) => u && u.length > 0 && t.bulkAddAnnotation(u, !1), f = (u) => u && u.length > 0 && t.bulkUpdateAnnotation(u.map(({ oldValue: x }) => x)), h = (u) => u && u.length > 0 && t.bulkUpdateAnnotation(u.map(({ newValue: x }) => x)), c = (u) => u && u.length > 0 && t.bulkAddAnnotation(u, !1), g = (u) => u && u.length > 0 && t.bulkDeleteAnnotation(u);
1062
1066
  return {
1063
1067
  canRedo: () => n.length - 1 > o,
1064
1068
  canUndo: () => o > -1,
1065
1069
  destroy: () => t.unobserve(a),
1066
- on: (d, A) => e.on(d, A),
1070
+ on: (u, x) => e.on(u, x),
1067
1071
  redo: () => {
1068
1072
  if (n.length - 1 > o) {
1069
1073
  i = !0;
1070
- const { created: d, updated: A, deleted: v } = n[o + 1];
1071
- l(d), h(A), p(v), e.emit("redo", n[o + 1]), o += 1;
1074
+ const { created: u, updated: x, deleted: b } = n[o + 1];
1075
+ l(u), h(x), g(b), e.emit("redo", n[o + 1]), o += 1;
1072
1076
  }
1073
1077
  },
1074
1078
  undo: () => {
1075
1079
  if (o > -1) {
1076
1080
  i = !0;
1077
- const { created: d, updated: A, deleted: v } = n[o];
1078
- s(d), u(A), c(v), e.emit("undo", n[o]), o -= 1;
1081
+ const { created: u, updated: x, deleted: b } = n[o];
1082
+ s(u), f(x), c(b), e.emit("undo", n[o]), o -= 1;
1079
1083
  }
1080
1084
  }
1081
1085
  };
@@ -1087,72 +1091,72 @@ const Mn = 250, Bn = (t) => {
1087
1091
  };
1088
1092
  }, In = (t, e, n, o) => {
1089
1093
  const { store: i, selection: r, hover: a, viewport: s } = t, l = /* @__PURE__ */ new Map();
1090
- let u = [], h;
1091
- const c = (v, S) => {
1092
- l.has(v) ? l.get(v).push(S) : l.set(v, [S]);
1093
- }, p = (v, S) => {
1094
- const m = l.get(v);
1095
- if (m) {
1096
- const f = m.indexOf(S);
1097
- f !== -1 && m.splice(f, 1);
1094
+ let f = [], h;
1095
+ const c = (b, C) => {
1096
+ l.has(b) ? l.get(b).push(C) : l.set(b, [C]);
1097
+ }, g = (b, C) => {
1098
+ const p = l.get(b);
1099
+ if (p) {
1100
+ const d = p.indexOf(C);
1101
+ d !== -1 && p.splice(d, 1);
1098
1102
  }
1099
- }, d = (v, S, m) => {
1100
- l.has(v) && setTimeout(() => {
1101
- l.get(v).forEach((f) => {
1103
+ }, u = (b, C, p) => {
1104
+ l.has(b) && setTimeout(() => {
1105
+ l.get(b).forEach((d) => {
1102
1106
  if (n) {
1103
- const y = Array.isArray(S) ? S.map((E) => n.serialize(E)) : n.serialize(S), C = m ? m instanceof PointerEvent ? m : n.serialize(m) : void 0;
1104
- f(y, C);
1107
+ const y = Array.isArray(C) ? C.map((E) => n.serialize(E)) : n.serialize(C), S = p ? p instanceof PointerEvent ? p : n.serialize(p) : void 0;
1108
+ d(y, S);
1105
1109
  } else
1106
- f(S, m);
1110
+ d(C, p);
1107
1111
  });
1108
1112
  }, 1);
1109
1113
  };
1110
- r.subscribe(({ selected: v }) => {
1111
- if (!(u.length === 0 && v.length === 0)) {
1112
- if (u.length === 0 && v.length > 0)
1113
- u = v.map(({ id: S }) => i.getAnnotation(S));
1114
- else if (u.length > 0 && v.length === 0)
1115
- u.forEach((S) => {
1116
- const m = i.getAnnotation(S.id);
1117
- m && !G(m, S) && d("updateAnnotation", m, S);
1118
- }), u = [];
1114
+ r.subscribe(({ selected: b }) => {
1115
+ if (!(f.length === 0 && b.length === 0)) {
1116
+ if (f.length === 0 && b.length > 0)
1117
+ f = b.map(({ id: C }) => i.getAnnotation(C));
1118
+ else if (f.length > 0 && b.length === 0)
1119
+ f.forEach((C) => {
1120
+ const p = i.getAnnotation(C.id);
1121
+ p && !G(p, C) && u("updateAnnotation", p, C);
1122
+ }), f = [];
1119
1123
  else {
1120
- const S = new Set(u.map((f) => f.id)), m = new Set(v.map(({ id: f }) => f));
1121
- u.filter((f) => !m.has(f.id)).forEach((f) => {
1122
- const y = i.getAnnotation(f.id);
1123
- y && !G(y, f) && d("updateAnnotation", y, f);
1124
- }), u = [
1124
+ const C = new Set(f.map((d) => d.id)), p = new Set(b.map(({ id: d }) => d));
1125
+ f.filter((d) => !p.has(d.id)).forEach((d) => {
1126
+ const y = i.getAnnotation(d.id);
1127
+ y && !G(y, d) && u("updateAnnotation", y, d);
1128
+ }), f = [
1125
1129
  // Remove annotations that were deselected
1126
- ...u.filter((f) => m.has(f.id)),
1130
+ ...f.filter((d) => p.has(d.id)),
1127
1131
  // Add editable annotations that were selected
1128
- ...v.filter(({ id: f }) => !S.has(f)).map(({ id: f }) => i.getAnnotation(f))
1132
+ ...b.filter(({ id: d }) => !C.has(d)).map(({ id: d }) => i.getAnnotation(d))
1129
1133
  ];
1130
1134
  }
1131
- d("selectionChanged", u);
1135
+ u("selectionChanged", f);
1132
1136
  }
1133
- }), a.subscribe((v) => {
1134
- !h && v ? d("mouseEnterAnnotation", i.getAnnotation(v)) : h && !v ? d("mouseLeaveAnnotation", i.getAnnotation(h)) : h && v && (d("mouseLeaveAnnotation", i.getAnnotation(h)), d("mouseEnterAnnotation", i.getAnnotation(v))), h = v;
1135
- }), s == null || s.subscribe((v) => d("viewportIntersect", v.map((S) => i.getAnnotation(S)))), i.observe((v) => {
1136
- const { created: S, deleted: m } = v.changes;
1137
- (S || []).forEach((f) => d("createAnnotation", f)), (m || []).forEach((f) => d("deleteAnnotation", f)), (v.changes.updated || []).filter((f) => [
1138
- ...f.bodiesCreated || [],
1139
- ...f.bodiesDeleted || [],
1140
- ...f.bodiesUpdated || []
1141
- ].length > 0).forEach(({ oldValue: f, newValue: y }) => {
1142
- const C = u.find((E) => E.id === f.id) || f;
1143
- u = u.map((E) => E.id === f.id ? y : E), d("updateAnnotation", y, C);
1137
+ }), a.subscribe((b) => {
1138
+ !h && b ? u("mouseEnterAnnotation", i.getAnnotation(b)) : h && !b ? u("mouseLeaveAnnotation", i.getAnnotation(h)) : h && b && (u("mouseLeaveAnnotation", i.getAnnotation(h)), u("mouseEnterAnnotation", i.getAnnotation(b))), h = b;
1139
+ }), s == null || s.subscribe((b) => u("viewportIntersect", b.map((C) => i.getAnnotation(C)))), i.observe((b) => {
1140
+ const { created: C, deleted: p } = b.changes;
1141
+ (C || []).forEach((d) => u("createAnnotation", d)), (p || []).forEach((d) => u("deleteAnnotation", d)), (b.changes.updated || []).filter((d) => [
1142
+ ...d.bodiesCreated || [],
1143
+ ...d.bodiesDeleted || [],
1144
+ ...d.bodiesUpdated || []
1145
+ ].length > 0).forEach(({ oldValue: d, newValue: y }) => {
1146
+ const S = f.find((E) => E.id === d.id) || d;
1147
+ f = f.map((E) => E.id === d.id ? y : E), u("updateAnnotation", y, S);
1144
1148
  });
1145
- }, { origin: k.LOCAL }), i.observe((v) => {
1146
- if (u) {
1147
- const S = new Set(u.map((f) => f.id)), m = (v.changes.updated || []).filter(({ newValue: f }) => S.has(f.id)).map(({ newValue: f }) => f);
1148
- m.length > 0 && (u = u.map((f) => m.find((C) => C.id === f.id) || f));
1149
+ }, { origin: k.LOCAL }), i.observe((b) => {
1150
+ if (f) {
1151
+ const C = new Set(f.map((d) => d.id)), p = (b.changes.updated || []).filter(({ newValue: d }) => C.has(d.id)).map(({ newValue: d }) => d);
1152
+ p.length > 0 && (f = f.map((d) => p.find((S) => S.id === d.id) || d));
1149
1153
  }
1150
1154
  }, { origin: k.REMOTE });
1151
- const A = (v) => (S) => {
1152
- const { updated: m } = S;
1153
- v ? (m || []).forEach((f) => d("updateAnnotation", f.oldValue, f.newValue)) : (m || []).forEach((f) => d("updateAnnotation", f.newValue, f.oldValue));
1155
+ const x = (b) => (C) => {
1156
+ const { updated: p } = C;
1157
+ b ? (p || []).forEach((d) => u("updateAnnotation", d.oldValue, d.newValue)) : (p || []).forEach((d) => u("updateAnnotation", d.newValue, d.oldValue));
1154
1158
  };
1155
- return e.on("undo", A(!0)), e.on("redo", A(!1)), { on: c, off: p, emit: d };
1159
+ return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: c, off: g, emit: u };
1156
1160
  }, Nn = (t) => (e) => e.reduce((n, o) => {
1157
1161
  const { parsed: i, error: r } = t.parse(o);
1158
1162
  return r ? {
@@ -1165,46 +1169,46 @@ const Mn = 250, Bn = (t) => {
1165
1169
  ...n
1166
1170
  };
1167
1171
  }, { parsed: [], failed: [] }), _n = (t, e, n) => {
1168
- const { store: o, selection: i } = t, r = (m) => {
1172
+ const { store: o, selection: i } = t, r = (p) => {
1169
1173
  if (n) {
1170
- const { parsed: f, error: y } = n.parse(m);
1171
- f ? o.addAnnotation(f, k.REMOTE) : console.error(y);
1174
+ const { parsed: d, error: y } = n.parse(p);
1175
+ d ? o.addAnnotation(d, k.REMOTE) : console.error(y);
1172
1176
  } else
1173
- o.addAnnotation(m, k.REMOTE);
1174
- }, a = () => i.clear(), s = () => o.clear(), l = (m) => {
1175
- const f = o.getAnnotation(m);
1176
- return n && f ? n.serialize(f) : f;
1177
- }, u = () => n ? o.all().map(n.serialize) : o.all(), h = () => {
1178
- var m;
1179
- const f = (((m = i.selected) == null ? void 0 : m.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
1180
- return n ? f.map(n.serialize) : f;
1181
- }, c = (m, f = !0) => fetch(m).then((y) => y.json()).then((y) => (d(y, f), y)), p = (m) => {
1182
- if (typeof m == "string") {
1183
- const f = o.getAnnotation(m);
1184
- if (o.deleteAnnotation(m), f)
1185
- return n ? n.serialize(f) : f;
1177
+ o.addAnnotation(p, k.REMOTE);
1178
+ }, a = () => i.clear(), s = () => o.clear(), l = (p) => {
1179
+ const d = o.getAnnotation(p);
1180
+ return n && d ? n.serialize(d) : d;
1181
+ }, f = () => n ? o.all().map(n.serialize) : o.all(), h = () => {
1182
+ var p;
1183
+ const d = (((p = i.selected) == null ? void 0 : p.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
1184
+ return n ? d.map(n.serialize) : d;
1185
+ }, c = (p, d = !0) => fetch(p).then((y) => y.json()).then((y) => (u(y, d), y)), g = (p) => {
1186
+ if (typeof p == "string") {
1187
+ const d = o.getAnnotation(p);
1188
+ if (o.deleteAnnotation(p), d)
1189
+ return n ? n.serialize(d) : d;
1186
1190
  } else {
1187
- const f = n ? n.parse(m).parsed : m;
1188
- if (f)
1189
- return o.deleteAnnotation(f), m;
1191
+ const d = n ? n.parse(p).parsed : p;
1192
+ if (d)
1193
+ return o.deleteAnnotation(d), p;
1190
1194
  }
1191
- }, d = (m, f = !0) => {
1195
+ }, u = (p, d = !0) => {
1192
1196
  if (n) {
1193
- const { parsed: y, failed: C } = Nn(n)(m);
1194
- C.length > 0 && console.warn(`Discarded ${C.length} invalid annotations`, C), o.bulkAddAnnotation(y, f, k.REMOTE);
1197
+ const { parsed: y, failed: S } = Nn(n)(p);
1198
+ S.length > 0 && console.warn(`Discarded ${S.length} invalid annotations`, S), o.bulkAddAnnotation(y, d, k.REMOTE);
1195
1199
  } else
1196
- o.bulkAddAnnotation(m, f, k.REMOTE);
1197
- }, A = (m, f) => {
1198
- m ? i.setSelected(m, f) : i.clear();
1199
- }, v = (m) => {
1200
- i.clear(), i.setUserSelectAction(m);
1201
- }, S = (m) => {
1200
+ o.bulkAddAnnotation(p, d, k.REMOTE);
1201
+ }, x = (p, d) => {
1202
+ p ? i.setSelected(p, d) : i.clear();
1203
+ }, b = (p) => {
1204
+ i.clear(), i.setUserSelectAction(p);
1205
+ }, C = (p) => {
1202
1206
  if (n) {
1203
- const f = n.parse(m).parsed, y = n.serialize(o.getAnnotation(f.id));
1204
- return o.updateAnnotation(f), y;
1207
+ const d = n.parse(p).parsed, y = n.serialize(o.getAnnotation(d.id));
1208
+ return o.updateAnnotation(d), y;
1205
1209
  } else {
1206
- const f = o.getAnnotation(m.id);
1207
- return o.updateAnnotation(m), f;
1210
+ const d = o.getAnnotation(p.id);
1211
+ return o.updateAnnotation(p), d;
1208
1212
  }
1209
1213
  };
1210
1214
  return {
@@ -1214,16 +1218,16 @@ const Mn = 250, Bn = (t) => {
1214
1218
  canUndo: e.canUndo,
1215
1219
  clearAnnotations: s,
1216
1220
  getAnnotationById: l,
1217
- getAnnotations: u,
1221
+ getAnnotations: f,
1218
1222
  getSelected: h,
1219
1223
  loadAnnotations: c,
1220
1224
  redo: e.redo,
1221
- removeAnnotation: p,
1222
- setAnnotations: d,
1223
- setSelected: A,
1224
- setUserSelectAction: v,
1225
+ removeAnnotation: g,
1226
+ setAnnotations: u,
1227
+ setSelected: x,
1228
+ setUserSelectAction: b,
1225
1229
  undo: e.undo,
1226
- updateAnnotation: S
1230
+ updateAnnotation: C
1227
1231
  };
1228
1232
  }, Un = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1229
1233
  let Vn = (t) => crypto.getRandomValues(new Uint8Array(t)), Dn = (t, e, n) => {
@@ -1251,14 +1255,14 @@ const Xn = () => ({ isGuest: !0, id: Kn("1234567890abcdefghijklmnopqrstuvwxyzABC
1251
1255
  }
1252
1256
  return `${n}`;
1253
1257
  }, he = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, $n = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1254
- const { id: o, type: i, purpose: r, value: a, created: s, modified: l, creator: u, ...h } = n;
1258
+ const { id: o, type: i, purpose: r, value: a, created: s, modified: l, creator: f, ...h } = n;
1255
1259
  return {
1256
1260
  id: o || `temp-${Pn(n)}`,
1257
1261
  annotation: e,
1258
1262
  type: i,
1259
1263
  purpose: r,
1260
1264
  value: a,
1261
- creator: he(u),
1265
+ creator: he(f),
1262
1266
  created: s ? new Date(s) : void 0,
1263
1267
  updated: l ? new Date(l) : void 0,
1264
1268
  ...h
@@ -1295,13 +1299,13 @@ const Lo = (t, e) => ({
1295
1299
  styleClass: a[0].styleClass
1296
1300
  };
1297
1301
  for (const l of a) {
1298
- const h = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((c, p) => {
1299
- switch (p.type) {
1302
+ const h = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((c, g) => {
1303
+ switch (g.type) {
1300
1304
  case "TextQuoteSelector":
1301
- c.quote = p.exact;
1305
+ c.quote = g.exact;
1302
1306
  break;
1303
1307
  case "TextPositionSelector":
1304
- c.start = p.start, c.end = p.end;
1308
+ c.start = g.start, c.end = g.end;
1305
1309
  break;
1306
1310
  }
1307
1311
  return c;
@@ -1338,22 +1342,22 @@ const Lo = (t, e) => ({
1338
1342
  selector: a,
1339
1343
  creator: s,
1340
1344
  created: l,
1341
- updated: u,
1345
+ updated: f,
1342
1346
  ...h
1343
- } = i, c = a.map((p) => {
1344
- const { quote: d, start: A, end: v, range: S } = p, { prefix: m, suffix: f } = Ne(S, n), y = [{
1347
+ } = i, c = a.map((g) => {
1348
+ const { quote: u, start: x, end: b, range: C } = g, { prefix: p, suffix: d } = Ne(C, n), y = [{
1345
1349
  type: "TextQuoteSelector",
1346
- exact: d,
1347
- prefix: m,
1348
- suffix: f
1350
+ exact: u,
1351
+ prefix: p,
1352
+ suffix: d
1349
1353
  }, {
1350
1354
  type: "TextPositionSelector",
1351
- start: A,
1352
- end: v
1355
+ start: x,
1356
+ end: b
1353
1357
  }];
1354
1358
  return {
1355
1359
  ...h,
1356
- id: p.id,
1360
+ id: g.id,
1357
1361
  source: e,
1358
1362
  selector: y
1359
1363
  };
@@ -1366,15 +1370,15 @@ const Lo = (t, e) => ({
1366
1370
  body: jn(t.bodies),
1367
1371
  creator: s,
1368
1372
  created: l == null ? void 0 : l.toISOString(),
1369
- modified: u == null ? void 0 : u.toISOString(),
1373
+ modified: f == null ? void 0 : f.toISOString(),
1370
1374
  target: c
1371
1375
  };
1372
1376
  };
1373
- function pe(t, e, n = 0, o = t.length - 1, i = qn) {
1377
+ function ge(t, e, n = 0, o = t.length - 1, i = qn) {
1374
1378
  for (; o > n; ) {
1375
1379
  if (o - n > 600) {
1376
- const l = o - n + 1, u = e - n + 1, h = Math.log(l), c = 0.5 * Math.exp(2 * h / 3), p = 0.5 * Math.sqrt(h * c * (l - c) / l) * (u - l / 2 < 0 ? -1 : 1), d = Math.max(n, Math.floor(e - u * c / l + p)), A = Math.min(o, Math.floor(e + (l - u) * c / l + p));
1377
- pe(t, e, d, A, i);
1380
+ const l = o - n + 1, f = e - n + 1, h = Math.log(l), c = 0.5 * Math.exp(2 * h / 3), g = 0.5 * Math.sqrt(h * c * (l - c) / l) * (f - l / 2 < 0 ? -1 : 1), u = Math.max(n, Math.floor(e - f * c / l + g)), x = Math.min(o, Math.floor(e + (l - f) * c / l + g));
1381
+ ge(t, e, u, x, i);
1378
1382
  }
1379
1383
  const r = t[e];
1380
1384
  let a = n, s = o;
@@ -1402,12 +1406,12 @@ class Gn {
1402
1406
  search(e) {
1403
1407
  let n = this.data;
1404
1408
  const o = [];
1405
- if (!gt(e, n)) return o;
1409
+ if (!pt(e, n)) return o;
1406
1410
  const i = this.toBBox, r = [];
1407
1411
  for (; n; ) {
1408
1412
  for (let a = 0; a < n.children.length; a++) {
1409
1413
  const s = n.children[a], l = n.leaf ? i(s) : s;
1410
- gt(e, l) && (n.leaf ? o.push(s) : Tt(e, l) ? this._all(s, o) : r.push(s));
1414
+ pt(e, l) && (n.leaf ? o.push(s) : Tt(e, l) ? this._all(s, o) : r.push(s));
1411
1415
  }
1412
1416
  n = r.pop();
1413
1417
  }
@@ -1415,12 +1419,12 @@ class Gn {
1415
1419
  }
1416
1420
  collides(e) {
1417
1421
  let n = this.data;
1418
- if (!gt(e, n)) return !1;
1422
+ if (!pt(e, n)) return !1;
1419
1423
  const o = [];
1420
1424
  for (; n; ) {
1421
1425
  for (let i = 0; i < n.children.length; i++) {
1422
1426
  const r = n.children[i], a = n.leaf ? this.toBBox(r) : r;
1423
- if (gt(e, a)) {
1427
+ if (pt(e, a)) {
1424
1428
  if (n.leaf || Tt(e, a)) return !0;
1425
1429
  o.push(r);
1426
1430
  }
@@ -1460,14 +1464,14 @@ class Gn {
1460
1464
  if (!e) return this;
1461
1465
  let o = this.data;
1462
1466
  const i = this.toBBox(e), r = [], a = [];
1463
- let s, l, u;
1467
+ let s, l, f;
1464
1468
  for (; o || r.length; ) {
1465
- if (o || (o = r.pop(), l = r[r.length - 1], s = a.pop(), u = !0), o.leaf) {
1469
+ if (o || (o = r.pop(), l = r[r.length - 1], s = a.pop(), f = !0), o.leaf) {
1466
1470
  const h = Qn(e, o.children, n);
1467
1471
  if (h !== -1)
1468
1472
  return o.children.splice(h, 1), r.push(o), this._condense(r), this;
1469
1473
  }
1470
- !u && !o.leaf && Tt(o, i) ? (r.push(o), a.push(s), s = 0, l = o, o = o.children[0]) : l ? (s++, o = l.children[s], u = !1) : o = null;
1474
+ !f && !o.leaf && Tt(o, i) ? (r.push(o), a.push(s), s = 0, l = o, o = o.children[0]) : l ? (s++, o = l.children[s], f = !1) : o = null;
1471
1475
  }
1472
1476
  return this;
1473
1477
  }
@@ -1498,14 +1502,14 @@ class Gn {
1498
1502
  if (r <= a)
1499
1503
  return s = Z(e.slice(n, o + 1)), J(s, this.toBBox), s;
1500
1504
  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;
1501
- const l = Math.ceil(r / a), u = l * Math.ceil(Math.sqrt(a));
1502
- Zt(e, n, o, u, this.compareMinX);
1503
- for (let h = n; h <= o; h += u) {
1504
- const c = Math.min(h + u - 1, o);
1505
+ const l = Math.ceil(r / a), f = l * Math.ceil(Math.sqrt(a));
1506
+ Zt(e, n, o, f, this.compareMinX);
1507
+ for (let h = n; h <= o; h += f) {
1508
+ const c = Math.min(h + f - 1, o);
1505
1509
  Zt(e, h, c, l, this.compareMinY);
1506
- for (let p = h; p <= c; p += l) {
1507
- const d = Math.min(p + l - 1, c);
1508
- s.children.push(this._build(e, p, d, i - 1));
1510
+ for (let g = h; g <= c; g += l) {
1511
+ const u = Math.min(g + l - 1, c);
1512
+ s.children.push(this._build(e, g, u, i - 1));
1509
1513
  }
1510
1514
  }
1511
1515
  return J(s, this.toBBox), s;
@@ -1514,8 +1518,8 @@ class Gn {
1514
1518
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1515
1519
  let r = 1 / 0, a = 1 / 0, s;
1516
1520
  for (let l = 0; l < n.children.length; l++) {
1517
- const u = n.children[l], h = Ot(u), c = to(e, u) - h;
1518
- c < a ? (a = c, r = h < r ? h : r, s = u) : c === a && h < r && (r = h, s = u);
1521
+ const f = n.children[l], h = Ot(f), c = to(e, f) - h;
1522
+ c < a ? (a = c, r = h < r ? h : r, s = f) : c === a && h < r && (r = h, s = f);
1519
1523
  }
1520
1524
  n = s || n.children[0];
1521
1525
  }
@@ -1540,7 +1544,7 @@ class Gn {
1540
1544
  _chooseSplitIndex(e, n, o) {
1541
1545
  let i, r = 1 / 0, a = 1 / 0;
1542
1546
  for (let s = n; s <= o - n; s++) {
1543
- const l = nt(e, 0, s, this.toBBox), u = nt(e, s, o, this.toBBox), h = eo(l, u), c = Ot(l) + Ot(u);
1547
+ const l = nt(e, 0, s, this.toBBox), f = nt(e, s, o, this.toBBox), h = eo(l, f), c = Ot(l) + Ot(f);
1544
1548
  h < r ? (r = h, i = s, a = c < a ? c : a) : h === r && c < a && (a = c, i = s);
1545
1549
  }
1546
1550
  return i || o - n;
@@ -1554,14 +1558,14 @@ class Gn {
1554
1558
  _allDistMargin(e, n, o, i) {
1555
1559
  e.children.sort(i);
1556
1560
  const r = this.toBBox, a = nt(e, 0, n, r), s = nt(e, o - n, o, r);
1557
- let l = pt(a) + pt(s);
1558
- for (let u = n; u < o - n; u++) {
1559
- const h = e.children[u];
1560
- ot(a, e.leaf ? r(h) : h), l += pt(a);
1561
+ let l = gt(a) + gt(s);
1562
+ for (let f = n; f < o - n; f++) {
1563
+ const h = e.children[f];
1564
+ ot(a, e.leaf ? r(h) : h), l += gt(a);
1561
1565
  }
1562
- for (let u = o - n - 1; u >= n; u--) {
1563
- const h = e.children[u];
1564
- ot(s, e.leaf ? r(h) : h), l += pt(s);
1566
+ for (let f = o - n - 1; f >= n; f--) {
1567
+ const h = e.children[f];
1568
+ ot(s, e.leaf ? r(h) : h), l += gt(s);
1565
1569
  }
1566
1570
  return l;
1567
1571
  }
@@ -1603,7 +1607,7 @@ function Zn(t, e) {
1603
1607
  function Ot(t) {
1604
1608
  return (t.maxX - t.minX) * (t.maxY - t.minY);
1605
1609
  }
1606
- function pt(t) {
1610
+ function gt(t) {
1607
1611
  return t.maxX - t.minX + (t.maxY - t.minY);
1608
1612
  }
1609
1613
  function to(t, e) {
@@ -1616,7 +1620,7 @@ function eo(t, e) {
1616
1620
  function Tt(t, e) {
1617
1621
  return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
1618
1622
  }
1619
- function gt(t, e) {
1623
+ function pt(t, e) {
1620
1624
  return e.minX <= t.maxX && e.minY <= t.maxY && e.maxX >= t.minX && e.maxY >= t.minY;
1621
1625
  }
1622
1626
  function Z(t) {
@@ -1635,7 +1639,7 @@ function Zt(t, e, n, o, i) {
1635
1639
  for (; r.length; ) {
1636
1640
  if (n = r.pop(), e = r.pop(), n - e <= o) continue;
1637
1641
  const a = e + Math.ceil((n - e) / o / 2) * o;
1638
- pe(t, a, e, n, i), r.push(e, a, a, n);
1642
+ ge(t, a, e, n, i), r.push(e, a, a, n);
1639
1643
  }
1640
1644
  }
1641
1645
  let no = () => ({
@@ -1653,134 +1657,134 @@ let no = () => ({
1653
1657
  }
1654
1658
  });
1655
1659
  const oo = (t, e) => {
1656
- const n = new Gn(), o = /* @__PURE__ */ new Map(), i = no(), r = (y, C) => {
1660
+ const n = new Gn(), o = /* @__PURE__ */ new Map(), i = no(), r = (y, S) => {
1657
1661
  const E = y.selector.flatMap((T) => {
1658
1662
  const O = W([T]) ? T.range : se(T, e).range;
1659
1663
  return Array.from(O.getClientRects());
1660
- }), b = Ke(E).map((T) => Pe(T, C));
1661
- return b.map((T) => {
1662
- const { x: O, y: R, width: g, height: w } = T;
1664
+ }), w = Ke(E).map((T) => Pe(T, S));
1665
+ return w.map((T) => {
1666
+ const { x: O, y: R, width: m, height: A } = T;
1663
1667
  return {
1664
1668
  minX: O,
1665
1669
  minY: R,
1666
- maxX: O + g,
1667
- maxY: R + w,
1670
+ maxX: O + m,
1671
+ maxY: R + A,
1668
1672
  annotation: {
1669
1673
  id: y.annotation,
1670
- rects: b
1674
+ rects: w
1671
1675
  }
1672
1676
  };
1673
1677
  });
1674
1678
  }, a = () => [...o.values()], s = () => {
1675
1679
  n.clear(), o.clear();
1676
1680
  }, l = (y) => {
1677
- const C = r(y, e.getBoundingClientRect());
1678
- C.forEach((E) => n.insert(E)), o.set(y.annotation, C);
1679
- }, u = (y) => {
1680
- const C = o.get(y.annotation);
1681
- C && (C.forEach((E) => n.remove(E)), o.delete(y.annotation));
1681
+ const S = r(y, e.getBoundingClientRect());
1682
+ S.forEach((E) => n.insert(E)), o.set(y.annotation, S);
1683
+ }, f = (y) => {
1684
+ const S = o.get(y.annotation);
1685
+ S && (S.forEach((E) => n.remove(E)), o.delete(y.annotation));
1682
1686
  }, h = (y) => {
1683
- u(y), l(y);
1684
- }, c = (y, C = !0) => {
1685
- C && s();
1686
- const E = e.getBoundingClientRect(), b = y.map((O) => ({ target: O, rects: r(O, E) }));
1687
- b.forEach(({ target: O, rects: R }) => o.set(O.annotation, R));
1688
- const T = b.flatMap(({ rects: O }) => O);
1687
+ f(y), l(y);
1688
+ }, c = (y, S = !0) => {
1689
+ S && s();
1690
+ const E = e.getBoundingClientRect(), w = y.map((O) => ({ target: O, rects: r(O, E) }));
1691
+ w.forEach(({ target: O, rects: R }) => o.set(O.annotation, R));
1692
+ const T = w.flatMap(({ rects: O }) => O);
1689
1693
  n.load(T);
1690
- }, p = (y, C, E = !1) => {
1691
- const b = n.search({
1694
+ }, g = (y, S, E = !1) => {
1695
+ const w = n.search({
1692
1696
  minX: y,
1693
- minY: C,
1697
+ minY: S,
1694
1698
  maxX: y,
1695
- maxY: C
1696
- }), T = (O) => O.annotation.rects.reduce((R, g) => R + g.width * g.height, 0);
1697
- return b.length > 0 ? (b.sort((O, R) => T(O) - T(R)), E ? b.map((O) => O.annotation.id) : [b[0].annotation.id]) : [];
1698
- }, d = (y) => {
1699
- const C = A(y);
1700
- if (C.length === 0)
1699
+ maxY: S
1700
+ }), T = (O) => O.annotation.rects.reduce((R, m) => R + m.width * m.height, 0);
1701
+ return w.length > 0 ? (w.sort((O, R) => T(O) - T(R)), E ? w.map((O) => O.annotation.id) : [w[0].annotation.id]) : [];
1702
+ }, u = (y) => {
1703
+ const S = x(y);
1704
+ if (S.length === 0)
1701
1705
  return;
1702
- let E = C[0].left, b = C[0].top, T = C[0].right, O = C[0].bottom;
1703
- for (let R = 1; R < C.length; R++) {
1704
- const g = C[R];
1705
- E = Math.min(E, g.left), b = Math.min(b, g.top), T = Math.max(T, g.right), O = Math.max(O, g.bottom);
1706
+ let E = S[0].left, w = S[0].top, T = S[0].right, O = S[0].bottom;
1707
+ for (let R = 1; R < S.length; R++) {
1708
+ const m = S[R];
1709
+ E = Math.min(E, m.left), w = Math.min(w, m.top), T = Math.max(T, m.right), O = Math.max(O, m.bottom);
1706
1710
  }
1707
- return new DOMRect(E, b, T - E, O - b);
1708
- }, A = (y) => {
1709
- const C = o.get(y);
1710
- return C ? C[0].annotation.rects : [];
1711
+ return new DOMRect(E, w, T - E, O - w);
1712
+ }, x = (y) => {
1713
+ const S = o.get(y);
1714
+ return S ? S[0].annotation.rects : [];
1711
1715
  };
1712
1716
  return {
1713
1717
  all: a,
1714
1718
  clear: s,
1715
- getAt: p,
1716
- getAnnotationBounds: d,
1717
- getAnnotationRects: A,
1718
- getIntersecting: (y, C, E, b) => {
1719
- const T = n.search({ minX: y, minY: C, maxX: E, maxY: b }), O = new Set(T.map((R) => R.annotation.id));
1719
+ getAt: g,
1720
+ getAnnotationBounds: u,
1721
+ getAnnotationRects: x,
1722
+ getIntersecting: (y, S, E, w) => {
1723
+ const T = n.search({ minX: y, minY: S, maxX: E, maxY: w }), O = new Set(T.map((R) => R.annotation.id));
1720
1724
  return Array.from(O).map((R) => ({
1721
1725
  annotation: t.getAnnotation(R),
1722
- rects: A(R)
1726
+ rects: x(R)
1723
1727
  })).filter((R) => !!R.annotation);
1724
1728
  },
1725
1729
  insert: l,
1726
1730
  recalculate: () => {
1727
1731
  c(t.all().map((y) => y.target), !0), i.emit("recalculate");
1728
1732
  },
1729
- remove: u,
1733
+ remove: f,
1730
1734
  set: c,
1731
1735
  size: () => n.all().length,
1732
1736
  update: h,
1733
- on: (y, C) => i.on(y, C)
1737
+ on: (y, S) => i.on(y, S)
1734
1738
  };
1735
1739
  }, io = (t, e) => {
1736
1740
  const n = Tn(), o = oo(n, t), i = mn(n);
1737
1741
  i.setUserSelectAction(e);
1738
- const r = pn(n), a = kn(), s = (f, y = k.LOCAL) => {
1739
- const C = wt(f, t), E = W(C.target.selector);
1740
- return E && n.addAnnotation(C, y), E;
1741
- }, l = (f, y = !0, C = k.LOCAL) => {
1742
- const E = f.map((T) => wt(T, t)), b = E.filter((T) => !W(T.target.selector));
1743
- return b.length > 0 ? (console.warn("Could not revive all targets for these annotations:", b), n.bulkAddAnnotation(E, y, C), b) : (n.bulkAddAnnotation(E, y, C), []);
1744
- }, u = (f, y = k.LOCAL) => {
1745
- const C = f.map((b) => wt(b, t)), E = C.filter((b) => !W(b.target.selector));
1746
- return E.length > 0 && console.warn("Could not revive all targets for these annotations:", E), C.forEach((b) => {
1747
- n.getAnnotation(b.id) ? n.updateAnnotation(b, y) : n.addAnnotation(b, y);
1742
+ const r = gn(n), a = kn(), s = (d, y = k.LOCAL) => {
1743
+ const S = wt(d, t), E = W(S.target.selector);
1744
+ return E && n.addAnnotation(S, y), E;
1745
+ }, l = (d, y = !0, S = k.LOCAL) => {
1746
+ const E = d.map((T) => wt(T, t)), w = E.filter((T) => !W(T.target.selector));
1747
+ return w.length > 0 ? (console.warn("Could not revive all targets for these annotations:", w), n.bulkAddAnnotation(E, y, S), w) : (n.bulkAddAnnotation(E, y, S), []);
1748
+ }, f = (d, y = k.LOCAL) => {
1749
+ const S = d.map((w) => wt(w, t)), E = S.filter((w) => !W(w.target.selector));
1750
+ return E.length > 0 && console.warn("Could not revive all targets for these annotations:", E), S.forEach((w) => {
1751
+ n.getAnnotation(w.id) ? n.updateAnnotation(w, y) : n.addAnnotation(w, y);
1748
1752
  }), E;
1749
- }, h = (f, y = k.LOCAL) => {
1750
- const C = bt(f, t);
1751
- n.updateTarget(C, y);
1752
- }, c = (f, y = k.LOCAL) => {
1753
- const C = f.map((E) => bt(E, t));
1754
- n.bulkUpdateTargets(C, y);
1755
- }, p = (f, y, C) => {
1756
- const E = o.getAt(f, y, !!C).map((T) => n.getAnnotation(T)), b = C ? E.filter(C) : E;
1757
- return b.length > 0 ? b[0] : void 0;
1758
- }, d = (f, y, C, E = 5) => {
1759
- const b = o.getAnnotationRects(f);
1760
- if (b.length !== 0) {
1761
- if (y && C) {
1762
- const T = b.find(({ top: O, right: R, bottom: g, left: w }) => y >= w - E && y <= R + E && C >= O - E && C <= g + E);
1753
+ }, h = (d, y = k.LOCAL) => {
1754
+ const S = bt(d, t);
1755
+ n.updateTarget(S, y);
1756
+ }, c = (d, y = k.LOCAL) => {
1757
+ const S = d.map((E) => bt(E, t));
1758
+ n.bulkUpdateTargets(S, y);
1759
+ }, g = (d, y, S) => {
1760
+ const E = o.getAt(d, y, !!S).map((T) => n.getAnnotation(T)), w = S ? E.filter(S) : E;
1761
+ return w.length > 0 ? w[0] : void 0;
1762
+ }, u = (d, y, S, E = 5) => {
1763
+ const w = o.getAnnotationRects(d);
1764
+ if (w.length !== 0) {
1765
+ if (y && S) {
1766
+ const T = w.find(({ top: O, right: R, bottom: m, left: A }) => y >= A - E && y <= R + E && S >= O - E && S <= m + E);
1763
1767
  if (T) return T;
1764
1768
  }
1765
- return o.getAnnotationBounds(f);
1769
+ return o.getAnnotationBounds(d);
1766
1770
  }
1767
- }, A = (f, y, C, E) => o.getIntersecting(f, y, C, E), v = (f) => o.getAnnotationRects(f), S = () => o.recalculate(), m = (f) => o.on("recalculate", f);
1768
- return n.observe(({ changes: f }) => {
1769
- const y = (f.deleted || []).filter((b) => W(b.target.selector)), C = (f.created || []).filter((b) => W(b.target.selector)), E = (f.updated || []).filter((b) => W(b.newValue.target.selector));
1770
- (y == null ? void 0 : y.length) > 0 && y.forEach((b) => o.remove(b.target)), C.length > 0 && o.set(C.map((b) => b.target), !1), (E == null ? void 0 : E.length) > 0 && E.forEach(({ newValue: b }) => o.update(b.target));
1771
+ }, x = (d, y, S, E) => o.getIntersecting(d, y, S, E), b = (d) => o.getAnnotationRects(d), C = () => o.recalculate(), p = (d) => o.on("recalculate", d);
1772
+ return n.observe(({ changes: d }) => {
1773
+ const y = (d.deleted || []).filter((w) => W(w.target.selector)), S = (d.created || []).filter((w) => W(w.target.selector)), E = (d.updated || []).filter((w) => W(w.newValue.target.selector));
1774
+ (y == null ? void 0 : y.length) > 0 && y.forEach((w) => o.remove(w.target)), S.length > 0 && o.set(S.map((w) => w.target), !1), (E == null ? void 0 : E.length) > 0 && E.forEach(({ newValue: w }) => o.update(w.target));
1771
1775
  }), {
1772
1776
  store: {
1773
1777
  ...n,
1774
1778
  addAnnotation: s,
1775
1779
  bulkAddAnnotation: l,
1776
1780
  bulkUpdateTargets: c,
1777
- bulkUpsertAnnotations: u,
1778
- getAnnotationBounds: d,
1779
- getAnnotationRects: v,
1780
- getIntersecting: A,
1781
- getAt: p,
1782
- recalculatePositions: S,
1783
- onRecalculatePositions: m,
1781
+ bulkUpsertAnnotations: f,
1782
+ getAnnotationBounds: u,
1783
+ getAnnotationRects: b,
1784
+ getIntersecting: x,
1785
+ getAt: g,
1786
+ recalculatePositions: C,
1787
+ onRecalculatePositions: p,
1784
1788
  updateTarget: h
1785
1789
  },
1786
1790
  selection: i,
@@ -1794,7 +1798,7 @@ function Mt(t, e, n, o) {
1794
1798
  function et(t, e, n, o) {
1795
1799
  t.removeEventListener ? t.removeEventListener(e, n, o) : t.detachEvent && t.detachEvent("on".concat(e), n);
1796
1800
  }
1797
- function ge(t, e) {
1801
+ function pe(t, e) {
1798
1802
  const n = e.slice(0, e.length - 1);
1799
1803
  for (let o = 0; o < n.length; o++) n[o] = t[n[o].toLowerCase()];
1800
1804
  return n;
@@ -1943,7 +1947,7 @@ function fo(t) {
1943
1947
  function ho(t) {
1944
1948
  return typeof t == "string" && (t = ct(t)), I.indexOf(t) !== -1;
1945
1949
  }
1946
- function po(t, e) {
1950
+ function go(t, e) {
1947
1951
  let n, o;
1948
1952
  t || (t = at());
1949
1953
  for (const i in N)
@@ -1957,7 +1961,7 @@ function po(t, e) {
1957
1961
  }) : o++;
1958
1962
  at() === t && be(e || "all");
1959
1963
  }
1960
- function go(t) {
1964
+ function po(t) {
1961
1965
  let e = t.keyCode || t.which || t.charCode;
1962
1966
  const n = I.indexOf(e);
1963
1967
  if (n >= 0 && I.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && I.splice(0, I.length), (e === 93 || e === 224) && (e = 91), e in D) {
@@ -1996,14 +2000,14 @@ const mt = (t) => {
1996
2000
  splitKey: i = "+"
1997
2001
  } = t;
1998
2002
  me(e).forEach((a) => {
1999
- const s = a.split(i), l = s.length, u = s[l - 1], h = u === "*" ? "*" : ct(u);
2003
+ const s = a.split(i), l = s.length, f = s[l - 1], h = f === "*" ? "*" : ct(f);
2000
2004
  if (!N[h]) return;
2001
2005
  n || (n = at());
2002
- const c = l > 1 ? ge(H, s) : [], p = [];
2003
- N[h] = N[h].filter((d) => {
2004
- const v = (o ? d.method === o : !0) && d.scope === n && ro(d.mods, c);
2005
- return v && p.push(d.element), !v;
2006
- }), p.forEach((d) => Kt(d));
2006
+ const c = l > 1 ? pe(H, s) : [], g = [];
2007
+ N[h] = N[h].filter((u) => {
2008
+ const b = (o ? u.method === o : !0) && u.scope === n && ro(u.mods, c);
2009
+ return b && g.push(u.element), !b;
2010
+ }), g.forEach((u) => Kt(u));
2007
2011
  });
2008
2012
  };
2009
2013
  function te(t, e, n, o) {
@@ -2042,21 +2046,21 @@ function ee(t, e) {
2042
2046
  for (let s = 0; s < a; s++)
2043
2047
  if ((t.type === "keydown" && r[s].keydown || t.type === "keyup" && r[s].keyup) && r[s].key) {
2044
2048
  const l = r[s], {
2045
- splitKey: u
2046
- } = l, h = l.key.split(u), c = [];
2047
- for (let p = 0; p < h.length; p++)
2048
- c.push(ct(h[p]));
2049
+ splitKey: f
2050
+ } = l, h = l.key.split(f), c = [];
2051
+ for (let g = 0; g < h.length; g++)
2052
+ c.push(ct(h[g]));
2049
2053
  c.sort().join("") === I.sort().join("") && te(t, l, i, e);
2050
2054
  }
2051
2055
  }
2052
2056
  function $(t, e, n) {
2053
2057
  I = [];
2054
2058
  const o = me(t);
2055
- let i = [], r = "all", a = document, s = 0, l = !1, u = !0, h = "+", c = !1, p = !1;
2056
- for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (r = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (u = e.keydown), e.capture !== void 0 && (c = e.capture), typeof e.splitKey == "string" && (h = e.splitKey), e.single === !0 && (p = !0)), typeof e == "string" && (r = e), p && we(t, r); s < o.length; s++)
2057
- t = o[s].split(h), i = [], t.length > 1 && (i = ge(H, t)), t = t[t.length - 1], t = t === "*" ? "*" : ct(t), t in N || (N[t] = []), N[t].push({
2059
+ let i = [], r = "all", a = document, s = 0, l = !1, f = !0, h = "+", c = !1, g = !1;
2060
+ for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (r = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (f = e.keydown), e.capture !== void 0 && (c = e.capture), typeof e.splitKey == "string" && (h = e.splitKey), e.single === !0 && (g = !0)), typeof e == "string" && (r = e), g && we(t, r); s < o.length; s++)
2061
+ t = o[s].split(h), i = [], t.length > 1 && (i = pe(H, t)), t = t[t.length - 1], t = t === "*" ? "*" : ct(t), t in N || (N[t] = []), N[t].push({
2058
2062
  keyup: l,
2059
- keydown: u,
2063
+ keydown: f,
2060
2064
  scope: r,
2061
2065
  mods: i,
2062
2066
  shortcut: o[s],
@@ -2067,27 +2071,27 @@ function $(t, e, n) {
2067
2071
  });
2068
2072
  if (typeof a < "u" && window) {
2069
2073
  if (!F.has(a)) {
2070
- const d = function() {
2071
- let v = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2072
- return ee(v, a);
2073
- }, A = function() {
2074
- let v = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2075
- ee(v, a), go(v);
2074
+ const u = function() {
2075
+ let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2076
+ return ee(b, a);
2077
+ }, x = function() {
2078
+ let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2079
+ ee(b, a), po(b);
2076
2080
  };
2077
2081
  F.set(a, {
2078
- keydownListener: d,
2079
- keyupListenr: A,
2082
+ keydownListener: u,
2083
+ keyupListenr: x,
2080
2084
  capture: c
2081
- }), Mt(a, "keydown", d, c), Mt(a, "keyup", A, c);
2085
+ }), Mt(a, "keydown", u, c), Mt(a, "keyup", x, c);
2082
2086
  }
2083
2087
  if (!rt) {
2084
- const d = () => {
2088
+ const u = () => {
2085
2089
  I = [];
2086
2090
  };
2087
2091
  rt = {
2088
- listener: d,
2092
+ listener: u,
2089
2093
  capture: c
2090
- }, Mt(window, "focus", d, c);
2094
+ }, Mt(window, "focus", u, c);
2091
2095
  }
2092
2096
  }
2093
2097
  }
@@ -2133,7 +2137,7 @@ const Bt = {
2133
2137
  getPressedKeyString: lo,
2134
2138
  setScope: be,
2135
2139
  getScope: at,
2136
- deleteScope: po,
2140
+ deleteScope: go,
2137
2141
  getPressedKeyCodes: co,
2138
2142
  getAllKeyCodes: uo,
2139
2143
  isPressed: ho,
@@ -2152,24 +2156,24 @@ if (typeof window < "u") {
2152
2156
  }
2153
2157
  const ne = 300, yo = (t, e, n) => {
2154
2158
  let o;
2155
- const i = (b) => o = b;
2159
+ const i = (w) => o = w;
2156
2160
  let r;
2157
- const a = (b) => r = b;
2161
+ const a = (w) => r = w;
2158
2162
  let s = !0;
2159
- const l = (b) => {
2160
- s = b, v.clear(), b || (c = void 0, p = void 0, d = void 0);
2161
- }, { store: u, selection: h } = e;
2162
- let c, p, d;
2163
- const A = (b) => {
2163
+ const l = (w) => {
2164
+ s = w, b.clear(), w || (c = void 0, g = void 0, u = void 0);
2165
+ }, { store: f, selection: h } = e;
2166
+ let c, g, u;
2167
+ const x = (w) => {
2164
2168
  var O;
2165
- if (!s || p === !1) return;
2166
- c = !((O = b.target.parentElement) != null && O.closest(j)) ? {
2169
+ if (!s || g === !1) return;
2170
+ c = !((O = w.target.parentElement) != null && O.closest(j)) ? {
2167
2171
  annotation: de(),
2168
2172
  selector: [],
2169
2173
  creator: o,
2170
2174
  created: /* @__PURE__ */ new Date()
2171
2175
  } : void 0;
2172
- }, v = Ut((b) => {
2176
+ }, b = Ut((w) => {
2173
2177
  var B, M;
2174
2178
  if (!s) return;
2175
2179
  const T = document.getSelection();
@@ -2177,62 +2181,61 @@ const ne = 300, yo = (t, e, n) => {
2177
2181
  c = void 0;
2178
2182
  return;
2179
2183
  }
2180
- const R = b.timeStamp - ((d == null ? void 0 : d.timeStamp) || b.timeStamp);
2181
- if ((d == null ? void 0 : d.type) === "pointerdown" && (R < 1e3 && !c || T.isCollapsed && R < ne) && A(d), !c) return;
2184
+ const R = w.timeStamp - ((u == null ? void 0 : u.timeStamp) || w.timeStamp);
2185
+ if ((u == null ? void 0 : u.type) === "pointerdown" && (R < 1e3 && !c || T.isCollapsed && R < ne) && x(u), !c) return;
2182
2186
  if (T.isCollapsed) {
2183
- u.getAnnotation(c.annotation) && (h.clear(), u.deleteAnnotation(c.annotation));
2187
+ f.getAnnotation(c.annotation) && (h.clear(), f.deleteAnnotation(c.annotation));
2184
2188
  return;
2185
2189
  }
2186
- const g = T.getRangeAt(0), w = Xe(g, t);
2187
- if (Ue(w)) return;
2188
- const x = Te(w.cloneRange());
2189
- (x.length !== c.selector.length || x.some((K, Y) => {
2190
+ const m = T.getRangeAt(0), A = Xe(m, t);
2191
+ if (Ue(A)) return;
2192
+ const v = Te(A.cloneRange());
2193
+ (v.length !== c.selector.length || v.some((K, Y) => {
2190
2194
  var lt;
2191
2195
  return K.toString() !== ((lt = c.selector[Y]) == null ? void 0 : lt.quote);
2192
2196
  })) && (c = {
2193
2197
  ...c,
2194
- selector: x.map((K) => Ye(K, t, n)),
2198
+ selector: v.map((K) => Ye(K, t, n)),
2195
2199
  updated: /* @__PURE__ */ new Date()
2196
- }, u.getAnnotation(c.annotation) ? u.updateTarget(c, k.LOCAL) : (h.clear(), u.addAnnotation({
2200
+ }, f.getAnnotation(c.annotation) ? f.updateTarget(c, k.LOCAL) : (h.clear(), f.addAnnotation({
2197
2201
  id: c.annotation,
2198
2202
  bodies: [],
2199
2203
  target: c
2200
- }, k.LOCAL), h.userSelect(c.annotation, d)));
2201
- }), S = (b) => {
2202
- d = $e(b), p = d.button === 0;
2203
- }, m = (b) => {
2204
- var g;
2205
- if (!!((g = b.target.parentElement) != null && g.closest(j)) || !p)
2204
+ }, k.LOCAL), h.userSelect(c.annotation, u)));
2205
+ }), C = (w) => {
2206
+ u = $e(w), g = u.button === 0;
2207
+ }, p = (w) => {
2208
+ var A;
2209
+ const T = w.target;
2210
+ if (!!((A = T.parentElement) != null && A.closest(j)) || !g)
2206
2211
  return;
2207
- const O = () => {
2208
- const { x: w, y: x } = t.getBoundingClientRect(), L = b.target instanceof Node && t.contains(b.target) && u.getAt(b.clientX - w, b.clientY - x, r);
2209
- if (L) {
2210
- const { selected: B } = h;
2211
- (B.length !== 1 || B[0].id !== L.id) && h.userSelect(L.id, b);
2212
+ const R = () => {
2213
+ const { x: v, y: L } = t.getBoundingClientRect(), B = w.target instanceof Node && t.contains(w.target) && f.getAt(w.clientX - v, w.clientY - L, r);
2214
+ if (B) {
2215
+ const { selected: M } = h;
2216
+ (M.length !== 1 || M[0].id !== B.id) && h.userSelect(B.id, w);
2212
2217
  } else h.isEmpty() || h.clear();
2213
- };
2214
- document.getSelection();
2215
- const R = b.timeStamp - d.timeStamp;
2218
+ }, m = w.timeStamp - u.timeStamp;
2216
2219
  setTimeout(() => {
2217
- const w = document.getSelection();
2218
- w != null && w.isCollapsed && R < ne ? (c = void 0, O()) : c && u.getAnnotation(c.annotation) && h.userSelect(c.annotation, b);
2220
+ const v = document.getSelection();
2221
+ v != null && v.isCollapsed && m < ne ? T !== document.documentElement && (c = void 0, R()) : c && f.getAnnotation(c.annotation) && h.userSelect(c.annotation, w);
2219
2222
  });
2220
2223
  };
2221
- document.addEventListener("pointerdown", S), document.addEventListener("pointerup", m), t.addEventListener("selectstart", A), document.addEventListener("selectionchange", v);
2222
- const f = ["up", "down", "left", "right"], y = [
2223
- ...f.map((b) => `shift+${b}`),
2224
+ document.addEventListener("pointerdown", C), document.addEventListener("pointerup", p), t.addEventListener("selectstart", x), document.addEventListener("selectionchange", b);
2225
+ const d = ["up", "down", "left", "right"], y = [
2226
+ ...d.map((w) => `shift+${w}`),
2224
2227
  "ctrl+a",
2225
2228
  "⌘+a"
2226
2229
  ];
2227
- $(y.join(","), { element: t, keydown: !0, keyup: !1 }, (b) => {
2228
- b.repeat || (d = je(b));
2230
+ $(y.join(","), { element: t, keydown: !0, keyup: !1 }, (w) => {
2231
+ w.repeat || (u = je(w));
2229
2232
  });
2230
- const C = (b) => {
2231
- b.repeat || b.target !== t && b.target !== document.body || (c = void 0, h.clear());
2233
+ const S = (w) => {
2234
+ w.repeat || w.target !== t && w.target !== document.body || (c = void 0, h.clear());
2232
2235
  };
2233
- return $(f.join(","), { keydown: !0, keyup: !1 }, C), {
2236
+ return $(d.join(","), { keydown: !0, keyup: !1 }, S), {
2234
2237
  destroy: () => {
2235
- c = void 0, p = void 0, d = void 0, v.clear(), document.removeEventListener("pointerdown", S), document.removeEventListener("pointerup", m), t.removeEventListener("selectstart", A), document.removeEventListener("selectionchange", v), $.unbind();
2238
+ c = void 0, g = void 0, u = void 0, b.clear(), document.removeEventListener("pointerdown", C), document.removeEventListener("pointerup", p), t.removeEventListener("selectstart", x), document.removeEventListener("selectionchange", b), $.unbind();
2236
2239
  },
2237
2240
  setFilter: a,
2238
2241
  setUser: i,
@@ -2246,27 +2249,27 @@ const ne = 300, yo = (t, e, n) => {
2246
2249
  }, wo = (t, e, n = {}) => {
2247
2250
  const o = bo(), i = o.getContext("2d");
2248
2251
  document.body.appendChild(o);
2249
- const r = /* @__PURE__ */ new Map(), a = (c) => Array.from(r.entries()).filter(([p, d]) => d.presenceKey === c.presenceKey).map(([p, d]) => p);
2250
- return e.on("selectionChange", (c, p) => {
2251
- a(c).forEach((A) => r.delete(A)), p && p.forEach((A) => r.set(A, c));
2252
+ const r = /* @__PURE__ */ new Map(), a = (c) => Array.from(r.entries()).filter(([g, u]) => u.presenceKey === c.presenceKey).map(([g, u]) => g);
2253
+ return e.on("selectionChange", (c, g) => {
2254
+ a(c).forEach((x) => r.delete(x)), g && g.forEach((x) => r.set(x, c));
2252
2255
  }), {
2253
2256
  clear: () => {
2254
- const { width: c, height: p } = o;
2255
- i.clearRect(-0.5, -0.5, c + 1, p + 1);
2257
+ const { width: c, height: g } = o;
2258
+ i.clearRect(-0.5, -0.5, c + 1, g + 1);
2256
2259
  },
2257
2260
  destroy: () => {
2258
2261
  o.remove();
2259
2262
  },
2260
- paint: (c, p, d) => {
2263
+ paint: (c, g, u) => {
2261
2264
  n.font && (i.font = n.font);
2262
- const A = r.get(c.annotation.id);
2263
- if (A) {
2264
- const { height: v } = c.rects[0], S = c.rects[0].x + p.left, m = c.rects[0].y + p.top;
2265
- i.fillStyle = A.appearance.color, i.fillRect(S - 2, m - 2.5, 2, v + 5);
2266
- const f = i.measureText(A.appearance.label), y = f.width + 6, C = f.actualBoundingBoxAscent + f.actualBoundingBoxDescent + 8, E = f.fontBoundingBoxAscent ? 8 : 6.5;
2267
- return i.fillRect(S - 2, m - 2.5 - C, y, C), i.fillStyle = "#fff", i.fillText(A.appearance.label, S + 1, m - E), {
2268
- fill: A.appearance.color,
2269
- fillOpacity: d ? 0.45 : 0.18
2265
+ const x = r.get(c.annotation.id);
2266
+ if (x) {
2267
+ const { height: b } = c.rects[0], C = c.rects[0].x + g.left, p = c.rects[0].y + g.top;
2268
+ i.fillStyle = x.appearance.color, i.fillRect(C - 2, p - 2.5, 2, b + 5);
2269
+ const d = i.measureText(x.appearance.label), y = d.width + 6, S = d.actualBoundingBoxAscent + d.actualBoundingBoxDescent + 8, E = d.fontBoundingBoxAscent ? 8 : 6.5;
2270
+ return i.fillRect(C - 2, p - 2.5 - S, y, S), i.fillStyle = "#fff", i.fillText(x.appearance.label, C + 1, p - E), {
2271
+ fill: x.appearance.color,
2272
+ fillOpacity: u ? 0.45 : 0.18
2270
2273
  };
2271
2274
  }
2272
2275
  },
@@ -2283,16 +2286,16 @@ const ne = 300, yo = (t, e, n) => {
2283
2286
  return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ve(t.parentElement);
2284
2287
  }, vo = (t, e) => (n) => {
2285
2288
  const o = typeof n == "string" ? n : n.id, i = (a) => {
2286
- const s = r.getBoundingClientRect(), l = r.clientHeight, u = r.clientWidth, h = a.selector[0].range.getBoundingClientRect(), { width: c, height: p } = e.getAnnotationBounds(o), d = h.top - s.top, A = h.left - s.left, v = r.parentElement ? r.scrollTop : 0, S = r.parentElement ? r.scrollLeft : 0, m = d + v - (l - p) / 2, f = A + S - (u - c) / 2;
2287
- r.scroll({ top: m, left: f, behavior: "smooth" });
2289
+ const s = r.getBoundingClientRect(), l = r.clientHeight, f = r.clientWidth, h = a.selector[0].range.getBoundingClientRect(), { width: c, height: g } = e.getAnnotationBounds(o), u = h.top - s.top, x = h.left - s.left, b = r.parentElement ? r.scrollTop : 0, C = r.parentElement ? r.scrollLeft : 0, p = u + b - (l - g) / 2, d = x + C - (f - c) / 2;
2290
+ r.scroll({ top: p, left: d, behavior: "smooth" });
2288
2291
  }, r = ve(t);
2289
2292
  if (r) {
2290
2293
  const a = e.getAnnotation(o), { range: s } = a.target.selector[0];
2291
2294
  if (s && !s.collapsed)
2292
2295
  return i(a.target), !0;
2293
2296
  {
2294
- const l = bt(a.target, t), { range: u } = l.selector[0];
2295
- if (u && !u.collapsed)
2297
+ const l = bt(a.target, t), { range: f } = l.selector[0];
2298
+ if (f && !f.collapsed)
2296
2299
  return i(l), !0;
2297
2300
  }
2298
2301
  }
@@ -2307,40 +2310,40 @@ const ne = 300, yo = (t, e, n) => {
2307
2310
  annotatingEnabled: !0,
2308
2311
  user: Xn()
2309
2312
  }), o = io(t, n.userSelectAction), { selection: i, viewport: r } = o, a = o.store, s = Bn(a), l = In(o, s, n.adapter);
2310
- let u = n.user;
2313
+ let f = n.user;
2311
2314
  const h = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : oe : n.renderer || oe, c = h === "SPANS" ? cn(t, o, r) : h === "CSS_HIGHLIGHTS" ? rn(t, o, r) : h === "CANVAS" ? We(t, o, r) : void 0;
2312
2315
  if (!c)
2313
2316
  throw `Unknown renderer implementation: ${h}`;
2314
2317
  console.debug(`Using ${h} renderer`), n.style && c.setStyle(n.style);
2315
- const p = yo(t, o, n.offsetReferenceSelector);
2316
- p.setUser(u), p.setAnnotatingEnabled(n.annotatingEnabled);
2317
- const d = _n(o, s, n.adapter), A = () => u, v = (E) => {
2318
- p.setAnnotatingEnabled(
2318
+ const g = yo(t, o, n.offsetReferenceSelector);
2319
+ g.setUser(f), g.setAnnotatingEnabled(n.annotatingEnabled);
2320
+ const u = _n(o, s, n.adapter), x = () => f, b = (E) => {
2321
+ g.setAnnotatingEnabled(
2319
2322
  E === void 0 ? !0 : E
2320
2323
  );
2321
- }, S = (E) => {
2322
- c.setFilter(E), p.setFilter(E);
2323
- }, m = (E) => {
2324
- u = E, p.setUser(E);
2325
- }, f = (E) => {
2324
+ }, C = (E) => {
2325
+ c.setFilter(E), g.setFilter(E);
2326
+ }, p = (E) => {
2327
+ f = E, g.setUser(E);
2328
+ }, d = (E) => {
2326
2329
  E && (c.setPainter(wo(t, E, n.presence)), E.on("selectionChange", () => c.redraw()));
2327
2330
  }, y = (E) => {
2328
2331
  E ? i.setSelected(E) : i.clear();
2329
2332
  };
2330
2333
  return {
2331
- ...d,
2334
+ ...u,
2332
2335
  destroy: () => {
2333
- c.destroy(), p.destroy(), s.destroy();
2336
+ c.destroy(), g.destroy(), s.destroy();
2334
2337
  },
2335
2338
  element: t,
2336
- getUser: A,
2337
- setAnnotatingEnabled: v,
2338
- setFilter: S,
2339
+ getUser: x,
2340
+ setAnnotatingEnabled: b,
2341
+ setFilter: C,
2339
2342
  setStyle: c.setStyle.bind(c),
2340
2343
  redraw: c.redraw.bind(c),
2341
- setUser: m,
2344
+ setUser: p,
2342
2345
  setSelected: y,
2343
- setPresenceProvider: f,
2346
+ setPresenceProvider: d,
2344
2347
  setVisible: c.setVisible.bind(c),
2345
2348
  on: l.on,
2346
2349
  off: l.off,
@@ -2354,7 +2357,7 @@ export {
2354
2357
  ie as NOT_ANNOTATABLE_CLASS,
2355
2358
  j as NOT_ANNOTATABLE_SELECTOR,
2356
2359
  k as Origin,
2357
- gn as UserSelectAction,
2360
+ pn as UserSelectAction,
2358
2361
  Lo as W3CTextFormat,
2359
2362
  Re as cancelSingleClickEvents,
2360
2363
  je as cloneKeyboardEvent,