@soomo/text-annotator 3.1.0-staging.13 → 3.1.0-staging.15

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.
@@ -109,9 +109,9 @@ const ae = "not-annotatable", Z = `.${ae}`, nt = (t) => {
109
109
  const { start: n, end: o } = t, i = t.offsetReference || e, s = document.createNodeIterator(
110
110
  e,
111
111
  NodeFilter.SHOW_TEXT,
112
- (y) => {
112
+ (m) => {
113
113
  var p;
114
- return (p = y.parentElement) != null && p.closest(Z) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
114
+ return (p = m.parentElement) != null && p.closest(Z) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
115
115
  }
116
116
  );
117
117
  let r = 0;
@@ -121,22 +121,22 @@ const ae = "not-annotatable", Z = `.${ae}`, nt = (t) => {
121
121
  let c = !i;
122
122
  for (; l !== null; ) {
123
123
  if (c || (c = i == null ? void 0 : i.contains(l)), c) {
124
- const y = ((f = l.textContent) == null ? void 0 : f.length) || 0;
125
- if (r + y > n) {
124
+ const m = ((f = l.textContent) == null ? void 0 : f.length) || 0;
125
+ if (r + m > n) {
126
126
  a.setStart(l, n - r);
127
127
  break;
128
128
  }
129
- r += y;
129
+ r += m;
130
130
  }
131
131
  l = s.nextNode();
132
132
  }
133
133
  for (; l !== null; ) {
134
- const y = ((d = l.textContent) == null ? void 0 : d.length) || 0;
135
- if (r + y >= o) {
134
+ const m = ((d = l.textContent) == null ? void 0 : d.length) || 0;
135
+ if (r + m >= o) {
136
136
  a.setEnd(l, o - r);
137
137
  break;
138
138
  }
139
- r += y, l = s.nextNode();
139
+ r += m, l = s.nextNode();
140
140
  }
141
141
  return {
142
142
  ...t,
@@ -213,7 +213,7 @@ const ae = "not-annotatable", Z = `.${ae}`, nt = (t) => {
213
213
  return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : de(t.parentElement);
214
214
  }, He = (t, e) => (n) => {
215
215
  const o = typeof n == "string" ? n : n.id, i = (r) => {
216
- const a = s.getBoundingClientRect(), l = s.clientHeight, c = s.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: d, height: y } = e.getAnnotationBounds(o), p = f.top - a.top, w = f.left - a.left, b = s.parentElement ? s.scrollTop : 0, C = s.parentElement ? s.scrollLeft : 0, g = p + b - (l - y) / 2, u = w + C - (c - d) / 2;
216
+ const a = s.getBoundingClientRect(), l = s.clientHeight, c = s.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: d, height: m } = e.getAnnotationBounds(o), p = f.top - a.top, v = f.left - a.left, b = s.parentElement ? s.scrollTop : 0, C = s.parentElement ? s.scrollLeft : 0, g = p + b - (l - m) / 2, u = v + C - (c - d) / 2;
217
217
  s.scroll({ top: g, left: u, behavior: "smooth" });
218
218
  }, s = de(t);
219
219
  if (s) {
@@ -250,17 +250,17 @@ function ue(t, e = 100, n = {}) {
250
250
  const { immediate: o } = typeof n == "boolean" ? { immediate: n } : n;
251
251
  let i, s, r, a, l;
252
252
  function c() {
253
- const y = i, p = s;
254
- return i = void 0, s = void 0, l = t.apply(y, p), l;
253
+ const m = i, p = s;
254
+ return i = void 0, s = void 0, l = t.apply(m, p), l;
255
255
  }
256
256
  function f() {
257
- const y = Date.now() - a;
258
- y < e && y >= 0 ? r = setTimeout(f, e - y) : (r = void 0, o || (l = c()));
257
+ const m = Date.now() - a;
258
+ m < e && m >= 0 ? r = setTimeout(f, e - m) : (r = void 0, o || (l = c()));
259
259
  }
260
- const d = function(...y) {
260
+ const d = function(...m) {
261
261
  if (i && this !== i && Object.getPrototypeOf(this) === Object.getPrototypeOf(i))
262
262
  throw new Error("Debounced method called with different contexts of the same prototype.");
263
- i = this, s = y, a = Date.now();
263
+ i = this, s = m, a = Date.now();
264
264
  const p = o && !r;
265
265
  return r || (r = setTimeout(f, e)), p && (l = c()), l;
266
266
  };
@@ -288,42 +288,42 @@ const Kt = /* @__PURE__ */ Fe(We), qe = (t) => {
288
288
  const { store: i, selection: s, hover: r } = e;
289
289
  let a, l, c;
290
290
  const f = Ge(n), d = (T) => {
291
- const { x: E, y: h } = t.getBoundingClientRect(), v = i.getAt(T.clientX - E, T.clientY - h, l);
292
- v ? r.current !== v.id && (t.classList.add("hovered"), r.set(v.id)) : r.current && (t.classList.remove("hovered"), r.set(null));
291
+ const { x: A, y: h } = t.getBoundingClientRect(), w = i.getAt(T.clientX - A, T.clientY - h, l);
292
+ w ? r.current !== w.id && (t.classList.add("hovered"), r.set(w.id)) : r.current && (t.classList.remove("hovered"), r.set(null));
293
293
  };
294
294
  t.addEventListener("pointermove", d);
295
- const y = (T = !1) => {
295
+ const m = (T = !1) => {
296
296
  c && c.clear();
297
- const E = qe(t), { minX: h, minY: v, maxX: A, maxY: L } = E, M = l ? i.getIntersecting(h, v, A, L).filter(({ annotation: Y }) => l(Y)) : i.getIntersecting(h, v, A, L), B = s.selected.map(({ id: Y }) => Y), K = M.map(({ annotation: Y, rects: dt }) => {
297
+ const A = qe(t), { minX: h, minY: w, maxX: x, maxY: L } = A, M = l ? i.getIntersecting(h, w, x, L).filter(({ annotation: Y }) => l(Y)) : i.getIntersecting(h, w, x, L), B = s.selected.map(({ id: Y }) => Y), K = M.map(({ annotation: Y, rects: dt }) => {
298
298
  const Oe = B.includes(Y.id), Te = Y.id === r.current;
299
299
  return { annotation: Y, rects: dt, state: { selected: Oe, hover: Te } };
300
300
  });
301
- o.redraw(K, E, a, c, T), setTimeout(() => f(M.map(({ annotation: Y }) => Y)), 1);
301
+ o.redraw(K, A, a, c, T), setTimeout(() => f(M.map(({ annotation: Y }) => Y)), 1);
302
302
  }, p = (T) => {
303
- c = T, y();
304
- }, w = (T) => {
305
- a = T, y();
303
+ c = T, m();
304
+ }, v = (T) => {
305
+ a = T, m();
306
306
  }, b = (T) => {
307
- l = T, y(!1);
308
- }, C = () => y();
307
+ l = T, m(!1);
308
+ }, C = () => m();
309
309
  i.observe(C);
310
- const g = s.subscribe(() => y()), u = () => y(!0);
310
+ const g = s.subscribe(() => m()), u = () => m(!0);
311
311
  document.addEventListener("scroll", u, { capture: !0, passive: !0 });
312
- const m = Kt(() => {
313
- i.recalculatePositions(), c == null || c.reset(), y();
312
+ const y = Kt(() => {
313
+ i.recalculatePositions(), c == null || c.reset(), m();
314
314
  }, 10);
315
- window.addEventListener("resize", m);
316
- const S = new ResizeObserver(m);
315
+ window.addEventListener("resize", y);
316
+ const S = new ResizeObserver(y);
317
317
  S.observe(t);
318
- const x = { attributes: !0, childList: !0, subtree: !0 }, O = new MutationObserver((T) => {
319
- T.every((h) => h.target === t || t.contains(h.target)) || y(!0);
318
+ const E = { attributes: !0, childList: !0, subtree: !0 }, O = new MutationObserver((T) => {
319
+ T.every((h) => h.target === t || t.contains(h.target)) || m(!0);
320
320
  });
321
- return O.observe(document.body, x), {
321
+ return O.observe(document.body, E), {
322
322
  destroy: () => {
323
- t.removeEventListener("pointermove", d), o.destroy(), i.unobserve(C), g(), document.removeEventListener("scroll", u), m.clear(), window.removeEventListener("resize", m), S.disconnect(), O.disconnect();
323
+ t.removeEventListener("pointermove", d), o.destroy(), i.unobserve(C), g(), document.removeEventListener("scroll", u), y.clear(), window.removeEventListener("resize", y), S.disconnect(), O.disconnect();
324
324
  },
325
- redraw: y,
326
- setStyle: w,
325
+ redraw: m,
326
+ setStyle: v,
327
327
  setFilter: b,
328
328
  setPainter: p,
329
329
  setVisible: o.setVisible
@@ -338,27 +338,27 @@ const Kt = /* @__PURE__ */ Fe(We), qe = (t) => {
338
338
  const e = Qe(), n = e.getContext("2d");
339
339
  document.body.appendChild(e);
340
340
  const o = (a, l, c, f) => requestAnimationFrame(() => {
341
- const { width: d, height: y } = e;
342
- n.clearRect(-0.5, -0.5, d + 1, y + 1), f && f.clear();
343
- const { top: p, left: w } = l;
341
+ const { width: d, height: m } = e;
342
+ n.clearRect(-0.5, -0.5, d + 1, m + 1), f && f.clear();
343
+ const { top: p, left: v } = l;
344
344
  [...a].sort((C, g) => {
345
- const { annotation: { target: { created: u } } } = C, { annotation: { target: { created: m } } } = g;
346
- return u.getTime() - m.getTime();
345
+ const { annotation: { target: { created: u } } } = C, { annotation: { target: { created: y } } } = g;
346
+ return u.getTime() - y.getTime();
347
347
  }).forEach((C) => {
348
348
  var S;
349
- const g = c ? typeof c == "function" ? c(C.annotation, C.state) : c : (S = C.state) != null && S.selected ? wt : W, u = f && f.paint(C, l) || g, m = C.rects.map(({ x, y: O, width: R, height: T }) => ({
350
- x: x + w,
349
+ const g = c ? typeof c == "function" ? c(C.annotation, C.state) : c : (S = C.state) != null && S.selected ? wt : W, u = f && f.paint(C, l) || g, y = C.rects.map(({ x: E, y: O, width: R, height: T }) => ({
350
+ x: E + v,
351
351
  y: O + p,
352
352
  width: R,
353
353
  height: T
354
354
  }));
355
- if (n.fillStyle = u.fill, n.globalAlpha = u.fillOpacity || 1, m.forEach(
356
- ({ x, y: O, width: R, height: T }) => n.fillRect(x, O, R, T)
355
+ if (n.fillStyle = u.fill, n.globalAlpha = u.fillOpacity || 1, y.forEach(
356
+ ({ x: E, y: O, width: R, height: T }) => n.fillRect(E, O, R, T)
357
357
  ), u.underlineColor) {
358
358
  n.globalAlpha = 1, n.strokeStyle = u.underlineColor, n.lineWidth = u.underlineThickness ?? 1;
359
- const x = u.underlineOffset ?? 0;
360
- m.forEach(({ x: O, y: R, width: T, height: E }) => {
361
- n.beginPath(), n.moveTo(O, R + E + x), n.lineTo(O + T, R + E + x), n.stroke();
359
+ const E = u.underlineOffset ?? 0;
360
+ y.forEach(({ x: O, y: R, width: T, height: A }) => {
361
+ n.beginPath(), n.moveTo(O, R + A + E), n.lineTo(O + T, R + A + E), n.stroke();
362
362
  });
363
363
  }
364
364
  });
@@ -525,13 +525,13 @@ const ln = (t) => [
525
525
  const c = new Set(s.map((d) => d.annotation.id));
526
526
  Array.from(e).filter((d) => !c.has(d));
527
527
  const f = s.map((d) => {
528
- var w;
529
- const y = a ? typeof a == "function" ? a(d.annotation, d.state) : a : (w = d.state) != null && w.selected ? wt : W, p = l && l.paint(d, r) || y;
528
+ var v;
529
+ const m = a ? typeof a == "function" ? a(d.annotation, d.state) : a : (v = d.state) != null && v.selected ? wt : W, p = l && l.paint(d, r) || m;
530
530
  return `::highlight(_${d.annotation.id}) { ${ln(p)} }`;
531
531
  });
532
532
  t.innerHTML = f.join(`
533
533
  `), CSS.highlights.clear(), s.forEach(({ annotation: d }) => {
534
- const y = d.target.selector.map((w) => w.range), p = new Highlight(...y);
534
+ const m = d.target.selector.map((v) => v.range), p = new Highlight(...m);
535
535
  CSS.highlights.set(`_${d.id}`, p);
536
536
  }), e = c;
537
537
  }
@@ -571,17 +571,17 @@ const fn = (t, e) => {
571
571
  e.remove();
572
572
  },
573
573
  redraw: (r, a, l, c, f) => {
574
- const y = !(Ut(n, r) && f);
575
- if (!c && !y) return;
576
- y && (e.innerHTML = ""), [...r].sort((w, b) => {
577
- const { annotation: { target: { created: C } } } = w, { annotation: { target: { created: g } } } = b;
574
+ const m = !(Ut(n, r) && f);
575
+ if (!c && !m) return;
576
+ m && (e.innerHTML = ""), [...r].sort((v, b) => {
577
+ const { annotation: { target: { created: C } } } = v, { annotation: { target: { created: g } } } = b;
578
578
  return C && g ? C.getTime() - g.getTime() : 0;
579
- }).forEach((w) => {
580
- w.rects.map((b) => {
581
- const C = fn(b, r), g = ze(w, a, l, c, C);
582
- if (y) {
579
+ }).forEach((v) => {
580
+ v.rects.map((b) => {
581
+ const C = fn(b, r), g = ze(v, a, l, c, C);
582
+ if (m) {
583
583
  const u = document.createElement("span");
584
- u.className = "r6o-annotation", u.dataset.annotation = w.annotation.id, u.style.left = `${b.x}px`, u.style.top = `${b.y}px`, u.style.width = `${b.width}px`, u.style.height = `${b.height}px`, u.style.backgroundColor = $((g == null ? void 0 : g.fill) || W.fill).alpha((g == null ? void 0 : g.fillOpacity) === void 0 ? W.fillOpacity : g.fillOpacity).toHex(), g.underlineStyle && (u.style.borderStyle = g.underlineStyle), g.underlineColor && (u.style.borderColor = g.underlineColor), g.underlineThickness && (u.style.borderBottomWidth = `${g.underlineThickness}px`), g.underlineOffset && (u.style.paddingBottom = `${g.underlineOffset}px`), e.appendChild(u);
584
+ u.className = "r6o-annotation", u.dataset.annotation = v.annotation.id, u.style.left = `${b.x}px`, u.style.top = `${b.y}px`, u.style.width = `${b.width}px`, u.style.height = `${b.height}px`, u.style.backgroundColor = $((g == null ? void 0 : g.fill) || W.fill).alpha((g == null ? void 0 : g.fillOpacity) === void 0 ? W.fillOpacity : g.fillOpacity).toHex(), g.underlineStyle && (u.style.borderStyle = g.underlineStyle), g.underlineColor && (u.style.borderColor = g.underlineColor), g.underlineThickness && (u.style.borderBottomWidth = `${g.underlineThickness}px`), g.underlineOffset && (u.style.paddingBottom = `${g.underlineOffset}px`), e.appendChild(u);
585
585
  }
586
586
  });
587
587
  }), n = r;
@@ -688,49 +688,49 @@ var An = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE =
688
688
  const ht = { selected: [] }, xn = (t, e, n) => {
689
689
  const { subscribe: o, set: i } = Xt(ht);
690
690
  let s = e, r = ht;
691
- o((w) => r = w);
691
+ o((v) => r = v);
692
692
  const a = () => {
693
693
  q(r, ht) || i(ht);
694
694
  }, l = () => {
695
- var w;
696
- return ((w = r.selected) == null ? void 0 : w.length) === 0;
697
- }, c = (w) => {
695
+ var v;
696
+ return ((v = r.selected) == null ? void 0 : v.length) === 0;
697
+ }, c = (v) => {
698
698
  if (l())
699
699
  return !1;
700
- const b = typeof w == "string" ? w : w.id;
700
+ const b = typeof v == "string" ? v : v.id;
701
701
  return r.selected.some((C) => C.id === b);
702
- }, f = (w, b) => {
703
- const C = t.getAnnotation(w);
702
+ }, f = (v, b) => {
703
+ const C = t.getAnnotation(v);
704
704
  if (!C) {
705
- console.warn("Invalid selection: " + w);
705
+ console.warn("Invalid selection: " + v);
706
706
  return;
707
707
  }
708
708
  switch (te(C, s)) {
709
709
  case "EDIT":
710
- i({ selected: [{ id: w, editable: !0 }], event: b });
710
+ i({ selected: [{ id: v, editable: !0 }], event: b });
711
711
  break;
712
712
  case "SELECT":
713
- i({ selected: [{ id: w }], event: b });
713
+ i({ selected: [{ id: v }], event: b });
714
714
  break;
715
715
  default:
716
716
  i({ selected: [], event: b });
717
717
  }
718
- }, d = (w, b) => {
719
- const C = Array.isArray(w) ? w : [w], g = C.map((u) => t.getAnnotation(u)).filter((u) => !!u);
718
+ }, d = (v, b) => {
719
+ const C = Array.isArray(v) ? v : [v], g = C.map((u) => t.getAnnotation(u)).filter((u) => !!u);
720
720
  i({
721
721
  selected: g.map((u) => {
722
- const m = b === void 0 ? te(u, s) === "EDIT" : b;
723
- return { id: u.id, editable: m };
722
+ const y = b === void 0 ? te(u, s) === "EDIT" : b;
723
+ return { id: u.id, editable: y };
724
724
  })
725
- }), g.length !== C.length && console.warn("Invalid selection", w);
726
- }, y = (w) => {
725
+ }), g.length !== C.length && console.warn("Invalid selection", v);
726
+ }, m = (v) => {
727
727
  if (l())
728
728
  return !1;
729
729
  const { selected: b } = r;
730
- b.some(({ id: C }) => w.includes(C)) && i({ selected: b.filter(({ id: C }) => !w.includes(C)) });
731
- }, p = (w) => s = w;
730
+ b.some(({ id: C }) => v.includes(C)) && i({ selected: b.filter(({ id: C }) => !v.includes(C)) });
731
+ }, p = (v) => s = v;
732
732
  return t.observe(
733
- ({ changes: w }) => y((w.deleted || []).map((b) => b.id))
733
+ ({ changes: v }) => m((v.deleted || []).map((b) => b.id))
734
734
  ), {
735
735
  get event() {
736
736
  return r ? r.event : null;
@@ -834,17 +834,17 @@ const Bn = (t, e) => {
834
834
  return !0;
835
835
  }, kn = (t, e) => {
836
836
  const n = new Set((t.created || []).map((d) => d.id)), o = new Set((t.updated || []).map(({ newValue: d }) => d.id)), i = new Set((e.created || []).map((d) => d.id)), s = new Set((e.deleted || []).map((d) => d.id)), r = new Set((e.updated || []).map(({ oldValue: d }) => d.id)), a = new Set((e.updated || []).filter(({ oldValue: d }) => n.has(d.id) || o.has(d.id)).map(({ oldValue: d }) => d.id)), l = [
837
- ...(t.created || []).filter((d) => !s.has(d.id)).map((d) => r.has(d.id) ? e.updated.find(({ oldValue: y }) => y.id === d.id).newValue : d),
837
+ ...(t.created || []).filter((d) => !s.has(d.id)).map((d) => r.has(d.id) ? e.updated.find(({ oldValue: m }) => m.id === d.id).newValue : d),
838
838
  ...e.created || []
839
839
  ], c = [
840
840
  ...(t.deleted || []).filter((d) => !i.has(d.id)),
841
841
  ...(e.deleted || []).filter((d) => !n.has(d.id))
842
842
  ], f = [
843
843
  ...(t.updated || []).filter(({ newValue: d }) => !s.has(d.id)).map((d) => {
844
- const { oldValue: y, newValue: p } = d;
844
+ const { oldValue: m, newValue: p } = d;
845
845
  if (r.has(p.id)) {
846
- const w = e.updated.find((b) => b.oldValue.id === p.id).newValue;
847
- return ye(y, w);
846
+ const v = e.updated.find((b) => b.oldValue.id === p.id).newValue;
847
+ return ye(m, v);
848
848
  } else
849
849
  return d;
850
850
  }),
@@ -866,71 +866,71 @@ const Bn = (t, e) => {
866
866
  }
867
867
  };
868
868
  }, In = (t) => t.id !== void 0, Nn = () => {
869
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (h, v = {}) => {
870
- n.push({ onChange: h, options: v });
869
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (h, w = {}) => {
870
+ n.push({ onChange: h, options: w });
871
871
  }, i = (h) => {
872
- const v = n.findIndex((A) => A.onChange == h);
873
- v > -1 && n.splice(v, 1);
874
- }, s = (h, v) => {
875
- const A = {
872
+ const w = n.findIndex((x) => x.onChange == h);
873
+ w > -1 && n.splice(w, 1);
874
+ }, s = (h, w) => {
875
+ const x = {
876
876
  origin: h,
877
877
  changes: {
878
- created: v.created || [],
879
- updated: v.updated || [],
880
- deleted: v.deleted || []
878
+ created: w.created || [],
879
+ updated: w.updated || [],
880
+ deleted: w.deleted || []
881
881
  },
882
882
  state: [...t.values()]
883
883
  };
884
884
  n.forEach((L) => {
885
- Bn(L, A) && L.onChange(A);
885
+ Bn(L, x) && L.onChange(x);
886
886
  });
887
- }, r = (h, v = k.LOCAL) => {
887
+ }, r = (h, w = k.LOCAL) => {
888
888
  if (h.id && t.get(h.id))
889
889
  throw Error(`Cannot add annotation ${h.id} - exists already`);
890
890
  {
891
- const A = Rt(h);
892
- t.set(A.id, A), A.bodies.forEach((L) => e.set(L.id, A.id)), s(v, { created: [A] });
891
+ const x = Rt(h);
892
+ t.set(x.id, x), x.bodies.forEach((L) => e.set(L.id, x.id)), s(w, { created: [x] });
893
893
  }
894
- }, a = (h, v) => {
895
- const A = Rt(typeof h == "string" ? v : h), L = typeof h == "string" ? h : h.id, M = L && t.get(L);
894
+ }, a = (h, w) => {
895
+ const x = Rt(typeof h == "string" ? w : h), L = typeof h == "string" ? h : h.id, M = L && t.get(L);
896
896
  if (M) {
897
- const B = ye(M, A);
898
- return L === A.id ? t.set(L, A) : (t.delete(L), t.set(A.id, A)), M.bodies.forEach((K) => e.delete(K.id)), A.bodies.forEach((K) => e.set(K.id, A.id)), B;
897
+ const B = ye(M, x);
898
+ return L === x.id ? t.set(L, x) : (t.delete(L), t.set(x.id, x)), M.bodies.forEach((K) => e.delete(K.id)), x.bodies.forEach((K) => e.set(K.id, x.id)), B;
899
899
  } else
900
900
  console.warn(`Cannot update annotation ${L} - does not exist`);
901
- }, l = (h, v = k.LOCAL, A = k.LOCAL) => {
902
- const L = In(v) ? A : v, M = a(h, v);
901
+ }, l = (h, w = k.LOCAL, x = k.LOCAL) => {
902
+ const L = In(w) ? x : w, M = a(h, w);
903
903
  M && s(L, { updated: [M] });
904
- }, c = (h, v = k.LOCAL) => {
905
- const A = h.reduce((L, M) => {
904
+ }, c = (h, w = k.LOCAL) => {
905
+ const x = h.reduce((L, M) => {
906
906
  const B = a(M);
907
907
  return B ? [...L, B] : L;
908
908
  }, []);
909
- A.length > 0 && s(v, { updated: A });
910
- }, f = (h, v = k.LOCAL) => {
911
- const A = t.get(h.annotation);
912
- if (A) {
909
+ x.length > 0 && s(w, { updated: x });
910
+ }, f = (h, w = k.LOCAL) => {
911
+ const x = t.get(h.annotation);
912
+ if (x) {
913
913
  const L = {
914
- ...A,
915
- bodies: [...A.bodies, h]
914
+ ...x,
915
+ bodies: [...x.bodies, h]
916
916
  };
917
- t.set(A.id, L), e.set(h.id, L.id), s(v, { updated: [{
918
- oldValue: A,
917
+ t.set(x.id, L), e.set(h.id, L.id), s(w, { updated: [{
918
+ oldValue: x,
919
919
  newValue: L,
920
920
  bodiesCreated: [h]
921
921
  }] });
922
922
  } else
923
923
  console.warn(`Attempt to add body to missing annotation: ${h.annotation}`);
924
- }, d = () => [...t.values()], y = (h = k.LOCAL) => {
925
- const v = [...t.values()];
926
- t.clear(), e.clear(), s(h, { deleted: v });
927
- }, p = (h, v = !0, A = k.LOCAL) => {
924
+ }, d = () => [...t.values()], m = (h = k.LOCAL) => {
925
+ const w = [...t.values()];
926
+ t.clear(), e.clear(), s(h, { deleted: w });
927
+ }, p = (h, w = !0, x = k.LOCAL) => {
928
928
  const L = h.map(Rt);
929
- if (v) {
929
+ if (w) {
930
930
  const M = [...t.values()];
931
931
  t.clear(), e.clear(), L.forEach((B) => {
932
932
  t.set(B.id, B), B.bodies.forEach((K) => e.set(K.id, B.id));
933
- }), s(A, { created: L, deleted: M });
933
+ }), s(x, { created: L, deleted: M });
934
934
  } else {
935
935
  const M = h.reduce((B, K) => {
936
936
  const Y = K.id && t.get(K.id);
@@ -940,96 +940,96 @@ const Bn = (t, e) => {
940
940
  throw Error(`Bulk insert would overwrite the following annotations: ${M.map((B) => B.id).join(", ")}`);
941
941
  L.forEach((B) => {
942
942
  t.set(B.id, B), B.bodies.forEach((K) => e.set(K.id, B.id));
943
- }), s(A, { created: L });
943
+ }), s(x, { created: L });
944
944
  }
945
- }, w = (h) => {
946
- const v = typeof h == "string" ? h : h.id, A = t.get(v);
947
- if (A)
948
- return t.delete(v), A.bodies.forEach((L) => e.delete(L.id)), A;
949
- console.warn(`Attempt to delete missing annotation: ${v}`);
950
- }, b = (h, v = k.LOCAL) => {
951
- const A = w(h);
952
- A && s(v, { deleted: [A] });
953
- }, C = (h, v = k.LOCAL) => {
954
- const A = h.reduce((L, M) => {
955
- const B = w(M);
945
+ }, v = (h) => {
946
+ const w = typeof h == "string" ? h : h.id, x = t.get(w);
947
+ if (x)
948
+ return t.delete(w), x.bodies.forEach((L) => e.delete(L.id)), x;
949
+ console.warn(`Attempt to delete missing annotation: ${w}`);
950
+ }, b = (h, w = k.LOCAL) => {
951
+ const x = v(h);
952
+ x && s(w, { deleted: [x] });
953
+ }, C = (h, w = k.LOCAL) => {
954
+ const x = h.reduce((L, M) => {
955
+ const B = v(M);
956
956
  return B ? [...L, B] : L;
957
957
  }, []);
958
- A.length > 0 && s(v, { deleted: A });
958
+ x.length > 0 && s(w, { deleted: x });
959
959
  }, g = (h) => {
960
- const v = t.get(h.annotation);
961
- if (v) {
962
- const A = v.bodies.find((L) => L.id === h.id);
963
- if (A) {
964
- e.delete(A.id);
960
+ const w = t.get(h.annotation);
961
+ if (w) {
962
+ const x = w.bodies.find((L) => L.id === h.id);
963
+ if (x) {
964
+ e.delete(x.id);
965
965
  const L = {
966
- ...v,
967
- bodies: v.bodies.filter((M) => M.id !== h.id)
966
+ ...w,
967
+ bodies: w.bodies.filter((M) => M.id !== h.id)
968
968
  };
969
- return t.set(v.id, L), {
970
- oldValue: v,
969
+ return t.set(w.id, L), {
970
+ oldValue: w,
971
971
  newValue: L,
972
- bodiesDeleted: [A]
972
+ bodiesDeleted: [x]
973
973
  };
974
974
  } else
975
975
  console.warn(`Attempt to delete missing body ${h.id} from annotation ${h.annotation}`);
976
976
  } else
977
977
  console.warn(`Attempt to delete body from missing annotation ${h.annotation}`);
978
- }, u = (h, v = k.LOCAL) => {
979
- const A = g(h);
980
- A && s(v, { updated: [A] });
981
- }, m = (h, v = k.LOCAL) => {
982
- const A = h.map((L) => g(L)).filter(Boolean);
983
- A.length > 0 && s(v, { updated: A });
978
+ }, u = (h, w = k.LOCAL) => {
979
+ const x = g(h);
980
+ x && s(w, { updated: [x] });
981
+ }, y = (h, w = k.LOCAL) => {
982
+ const x = h.map((L) => g(L)).filter(Boolean);
983
+ x.length > 0 && s(w, { updated: x });
984
984
  }, S = (h) => {
985
- const v = t.get(h);
986
- return v ? { ...v } : void 0;
987
- }, x = (h) => {
988
- const v = e.get(h);
989
- if (v) {
990
- const A = S(v).bodies.find((L) => L.id === h);
991
- if (A)
992
- return A;
985
+ const w = t.get(h);
986
+ return w ? { ...w } : void 0;
987
+ }, E = (h) => {
988
+ const w = e.get(h);
989
+ if (w) {
990
+ const x = S(w).bodies.find((L) => L.id === h);
991
+ if (x)
992
+ return x;
993
993
  console.error(`Store integrity error: body ${h} in index, but not in annotation`);
994
994
  } else
995
995
  console.warn(`Attempt to retrieve missing body: ${h}`);
996
- }, O = (h, v) => {
997
- if (h.annotation !== v.annotation)
996
+ }, O = (h, w) => {
997
+ if (h.annotation !== w.annotation)
998
998
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
999
- const A = t.get(h.annotation);
1000
- if (A) {
1001
- const L = A.bodies.find((B) => B.id === h.id), M = {
1002
- ...A,
1003
- bodies: A.bodies.map((B) => B.id === L.id ? v : B)
999
+ const x = t.get(h.annotation);
1000
+ if (x) {
1001
+ const L = x.bodies.find((B) => B.id === h.id), M = {
1002
+ ...x,
1003
+ bodies: x.bodies.map((B) => B.id === L.id ? w : B)
1004
1004
  };
1005
- return t.set(A.id, M), L.id !== v.id && (e.delete(L.id), e.set(v.id, M.id)), {
1006
- oldValue: A,
1005
+ return t.set(x.id, M), L.id !== w.id && (e.delete(L.id), e.set(w.id, M.id)), {
1006
+ oldValue: x,
1007
1007
  newValue: M,
1008
- bodiesUpdated: [{ oldBody: L, newBody: v }]
1008
+ bodiesUpdated: [{ oldBody: L, newBody: w }]
1009
1009
  };
1010
1010
  } else
1011
1011
  console.warn(`Attempt to add body to missing annotation ${h.annotation}`);
1012
- }, R = (h, v, A = k.LOCAL) => {
1013
- const L = O(h, v);
1014
- L && s(A, { updated: [L] });
1015
- }, T = (h, v = k.LOCAL) => {
1016
- const A = h.map((L) => O({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
1017
- s(v, { updated: A });
1018
- }, E = (h) => {
1019
- const v = t.get(h.annotation);
1020
- if (v) {
1021
- const A = {
1022
- ...v,
1012
+ }, R = (h, w, x = k.LOCAL) => {
1013
+ const L = O(h, w);
1014
+ L && s(x, { updated: [L] });
1015
+ }, T = (h, w = k.LOCAL) => {
1016
+ const x = h.map((L) => O({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
1017
+ s(w, { updated: x });
1018
+ }, A = (h) => {
1019
+ const w = t.get(h.annotation);
1020
+ if (w) {
1021
+ const x = {
1022
+ ...w,
1023
1023
  target: {
1024
- ...v.target,
1024
+ ...w.target,
1025
1025
  ...h
1026
1026
  }
1027
1027
  };
1028
- return t.set(v.id, A), {
1029
- oldValue: v,
1030
- newValue: A,
1028
+ return t.set(w.id, x), {
1029
+ oldValue: w,
1030
+ newValue: x,
1031
1031
  targetUpdated: {
1032
- oldTarget: v.target,
1032
+ oldTarget: w.target,
1033
1033
  newTarget: h
1034
1034
  }
1035
1035
  };
@@ -1042,25 +1042,25 @@ const Bn = (t, e) => {
1042
1042
  all: d,
1043
1043
  bulkAddAnnotation: p,
1044
1044
  bulkDeleteAnnotation: C,
1045
- bulkDeleteBodies: m,
1045
+ bulkDeleteBodies: y,
1046
1046
  bulkUpdateAnnotation: c,
1047
1047
  bulkUpdateBodies: T,
1048
- bulkUpdateTargets: (h, v = k.LOCAL) => {
1049
- const A = h.map((L) => E(L)).filter(Boolean);
1050
- A.length > 0 && s(v, { updated: A });
1048
+ bulkUpdateTargets: (h, w = k.LOCAL) => {
1049
+ const x = h.map((L) => A(L)).filter(Boolean);
1050
+ x.length > 0 && s(w, { updated: x });
1051
1051
  },
1052
- clear: y,
1052
+ clear: m,
1053
1053
  deleteAnnotation: b,
1054
1054
  deleteBody: u,
1055
1055
  getAnnotation: S,
1056
- getBody: x,
1056
+ getBody: E,
1057
1057
  observe: o,
1058
1058
  unobserve: i,
1059
1059
  updateAnnotation: l,
1060
1060
  updateBody: R,
1061
- updateTarget: (h, v = k.LOCAL) => {
1062
- const A = E(h);
1063
- A && s(v, { updated: [A] });
1061
+ updateTarget: (h, w = k.LOCAL) => {
1062
+ const x = A(h);
1063
+ x && s(w, { updated: [x] });
1064
1064
  }
1065
1065
  };
1066
1066
  };
@@ -1083,36 +1083,36 @@ const Un = 250, Dn = (t) => {
1083
1083
  let o = -1, i = !1, s = 0;
1084
1084
  const r = (p) => {
1085
1085
  if (!i) {
1086
- const { changes: w } = p, b = performance.now();
1086
+ const { changes: v } = p, b = performance.now();
1087
1087
  if (b - s > Un)
1088
- n.splice(o + 1), n.push(w), o = n.length - 1;
1088
+ n.splice(o + 1), n.push(v), o = n.length - 1;
1089
1089
  else {
1090
1090
  const C = n.length - 1;
1091
- n[C] = kn(n[C], w);
1091
+ n[C] = kn(n[C], v);
1092
1092
  }
1093
1093
  s = b;
1094
1094
  }
1095
1095
  i = !1;
1096
1096
  };
1097
1097
  t.observe(r, { origin: k.LOCAL });
1098
- const a = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), l = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), c = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue: w }) => w)), f = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: w }) => w)), d = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), y = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p);
1098
+ const a = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), l = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), c = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue: v }) => v)), f = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: v }) => v)), d = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), m = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p);
1099
1099
  return {
1100
1100
  canRedo: () => n.length - 1 > o,
1101
1101
  canUndo: () => o > -1,
1102
1102
  destroy: () => t.unobserve(r),
1103
- on: (p, w) => e.on(p, w),
1103
+ on: (p, v) => e.on(p, v),
1104
1104
  redo: () => {
1105
1105
  if (n.length - 1 > o) {
1106
1106
  i = !0;
1107
- const { created: p, updated: w, deleted: b } = n[o + 1];
1108
- l(p), f(w), y(b), e.emit("redo", n[o + 1]), o += 1;
1107
+ const { created: p, updated: v, deleted: b } = n[o + 1];
1108
+ l(p), f(v), m(b), e.emit("redo", n[o + 1]), o += 1;
1109
1109
  }
1110
1110
  },
1111
1111
  undo: () => {
1112
1112
  if (o > -1) {
1113
1113
  i = !0;
1114
- const { created: p, updated: w, deleted: b } = n[o];
1115
- a(p), c(w), d(b), e.emit("undo", n[o]), o -= 1;
1114
+ const { created: p, updated: v, deleted: b } = n[o];
1115
+ a(p), c(v), d(b), e.emit("undo", n[o]), o -= 1;
1116
1116
  }
1117
1117
  }
1118
1118
  };
@@ -1127,7 +1127,7 @@ const Un = 250, Dn = (t) => {
1127
1127
  let c = [], f;
1128
1128
  const d = (b, C) => {
1129
1129
  l.has(b) ? l.get(b).push(C) : l.set(b, [C]);
1130
- }, y = (b, C) => {
1130
+ }, m = (b, C) => {
1131
1131
  const g = l.get(b);
1132
1132
  if (g) {
1133
1133
  const u = g.indexOf(C);
@@ -1137,8 +1137,8 @@ const Un = 250, Dn = (t) => {
1137
1137
  l.has(b) && setTimeout(() => {
1138
1138
  l.get(b).forEach((u) => {
1139
1139
  if (n) {
1140
- const m = Array.isArray(C) ? C.map((x) => n.serialize(x)) : n.serialize(C), S = g ? g instanceof PointerEvent ? g : n.serialize(g) : void 0;
1141
- u(m, S);
1140
+ const y = Array.isArray(C) ? C.map((E) => n.serialize(E)) : n.serialize(C), S = g ? g instanceof PointerEvent ? g : n.serialize(g) : void 0;
1141
+ u(y, S);
1142
1142
  } else
1143
1143
  u(C, g);
1144
1144
  });
@@ -1156,8 +1156,8 @@ const Un = 250, Dn = (t) => {
1156
1156
  else {
1157
1157
  const C = new Set(c.map((u) => u.id)), g = new Set(b.map(({ id: u }) => u));
1158
1158
  c.filter((u) => !g.has(u.id)).forEach((u) => {
1159
- const m = r.getAnnotation(u.id);
1160
- m && !q(m, u) && p("updateAnnotation", m, u);
1159
+ const y = r.getAnnotation(u.id);
1160
+ y && !q(y, u) && p("updateAnnotation", y, u);
1161
1161
  }), c = [
1162
1162
  // Remove annotations that were deselected
1163
1163
  ...c.filter((u) => g.has(u.id)),
@@ -1175,9 +1175,9 @@ const Un = 250, Dn = (t) => {
1175
1175
  ...u.bodiesCreated || [],
1176
1176
  ...u.bodiesDeleted || [],
1177
1177
  ...u.bodiesUpdated || []
1178
- ].length > 0).forEach(({ oldValue: u, newValue: m }) => {
1179
- const S = c.find((x) => x.id === u.id) || u;
1180
- c = c.map((x) => x.id === u.id ? m : x), p("updateAnnotation", m, S);
1178
+ ].length > 0).forEach(({ oldValue: u, newValue: y }) => {
1179
+ const S = c.find((E) => E.id === u.id) || u;
1180
+ c = c.map((E) => E.id === u.id ? y : E), p("updateAnnotation", y, S);
1181
1181
  });
1182
1182
  }, { origin: k.LOCAL }), r.observe((b) => {
1183
1183
  if (c) {
@@ -1185,11 +1185,11 @@ const Un = 250, Dn = (t) => {
1185
1185
  g.length > 0 && (c = c.map((u) => g.find((S) => S.id === u.id) || u));
1186
1186
  }
1187
1187
  }, { origin: k.REMOTE });
1188
- const w = (b) => (C) => {
1188
+ const v = (b) => (C) => {
1189
1189
  const { updated: g } = C;
1190
1190
  b ? (g || []).forEach((u) => p("updateAnnotation", u.oldValue, u.newValue)) : (g || []).forEach((u) => p("updateAnnotation", u.newValue, u.oldValue));
1191
1191
  };
1192
- return e.on("undo", w(!0)), e.on("redo", w(!1)), { on: d, off: y, emit: p };
1192
+ return e.on("undo", v(!0)), e.on("redo", v(!1)), { on: d, off: m, emit: p };
1193
1193
  }, Yn = (t) => (e) => e.reduce((n, o) => {
1194
1194
  const { parsed: i, error: s } = t.parse(o);
1195
1195
  return s ? {
@@ -1204,8 +1204,8 @@ const Un = 250, Dn = (t) => {
1204
1204
  }, { parsed: [], failed: [] }), Xn = (t, e, n) => {
1205
1205
  const { store: o, selection: i } = t, s = (g) => {
1206
1206
  if (n) {
1207
- const { parsed: u, error: m } = n.parse(g);
1208
- u ? o.addAnnotation(u, k.REMOTE) : console.error(m);
1207
+ const { parsed: u, error: y } = n.parse(g);
1208
+ u ? o.addAnnotation(u, k.REMOTE) : console.error(y);
1209
1209
  } else
1210
1210
  o.addAnnotation(Tt(g), k.REMOTE);
1211
1211
  }, r = () => i.clear(), a = () => o.clear(), l = (g) => {
@@ -1213,9 +1213,9 @@ const Un = 250, Dn = (t) => {
1213
1213
  return n && u ? n.serialize(u) : u;
1214
1214
  }, c = () => n ? o.all().map(n.serialize) : o.all(), f = () => {
1215
1215
  var g;
1216
- const u = (((g = i.selected) == null ? void 0 : g.map((m) => m.id)) || []).map((m) => o.getAnnotation(m)).filter(Boolean);
1216
+ const u = (((g = i.selected) == null ? void 0 : g.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
1217
1217
  return n ? u.map(n.serialize) : u;
1218
- }, d = (g, u = !0) => fetch(g).then((m) => m.json()).then((m) => (p(m, u), m)), y = (g) => {
1218
+ }, d = (g, u = !0) => fetch(g).then((y) => y.json()).then((y) => (p(y, u), y)), m = (g) => {
1219
1219
  if (typeof g == "string") {
1220
1220
  const u = o.getAnnotation(g);
1221
1221
  if (o.deleteAnnotation(g), u)
@@ -1227,18 +1227,18 @@ const Un = 250, Dn = (t) => {
1227
1227
  }
1228
1228
  }, p = (g, u = !0) => {
1229
1229
  if (n) {
1230
- const m = n.parseAll || Yn(n), { parsed: S, failed: x } = m(g);
1231
- x.length > 0 && console.warn(`Discarded ${x.length} invalid annotations`, x), o.bulkAddAnnotation(S, u, k.REMOTE);
1230
+ const y = n.parseAll || Yn(n), { parsed: S, failed: E } = y(g);
1231
+ E.length > 0 && console.warn(`Discarded ${E.length} invalid annotations`, E), o.bulkAddAnnotation(S, u, k.REMOTE);
1232
1232
  } else
1233
1233
  o.bulkAddAnnotation(g.map(Tt), u, k.REMOTE);
1234
- }, w = (g, u) => {
1234
+ }, v = (g, u) => {
1235
1235
  g ? i.setSelected(g, u) : i.clear();
1236
1236
  }, b = (g) => {
1237
1237
  i.clear(), i.setUserSelectAction(g);
1238
1238
  }, C = (g) => {
1239
1239
  if (n) {
1240
- const u = n.parse(g).parsed, m = n.serialize(o.getAnnotation(u.id));
1241
- return o.updateAnnotation(u), m;
1240
+ const u = n.parse(g).parsed, y = n.serialize(o.getAnnotation(u.id));
1241
+ return o.updateAnnotation(u), y;
1242
1242
  } else {
1243
1243
  const u = o.getAnnotation(g.id);
1244
1244
  return o.updateAnnotation(Tt(g)), u;
@@ -1255,9 +1255,9 @@ const Un = 250, Dn = (t) => {
1255
1255
  getSelected: f,
1256
1256
  loadAnnotations: d,
1257
1257
  redo: e.redo,
1258
- removeAnnotation: y,
1258
+ removeAnnotation: m,
1259
1259
  setAnnotations: p,
1260
- setSelected: w,
1260
+ setSelected: v,
1261
1261
  setUserSelectAction: b,
1262
1262
  undo: e.undo,
1263
1263
  updateAnnotation: C
@@ -1329,26 +1329,30 @@ const ko = (t, e) => ({
1329
1329
  updated: i ? new Date(i) : void 0,
1330
1330
  annotation: e,
1331
1331
  selector: [],
1332
- styleClass: r[0].styleClass
1332
+ // @ts-expect-error: `styleClass` is not part of the core `TextAnnotationTarget` type
1333
+ styleClass: "styleClass" in r[0] ? r[0].styleClass : void 0
1333
1334
  };
1334
1335
  for (const l of r) {
1335
- const f = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((d, y) => {
1336
- switch (y.type) {
1336
+ const f = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((d, m) => {
1337
+ switch (m.type) {
1337
1338
  case "TextQuoteSelector":
1338
- d.quote = y.exact;
1339
+ d.quote = m.exact;
1339
1340
  break;
1340
1341
  case "TextPositionSelector":
1341
- d.start = y.start, d.end = y.end;
1342
+ d.start = m.start, d.end = m.end;
1342
1343
  break;
1343
1344
  }
1344
1345
  return d;
1345
1346
  }, {});
1346
1347
  if (Qn(f))
1347
- a.selector.push({
1348
- ...f,
1349
- id: l.id,
1350
- scope: l.scope
1351
- });
1348
+ a.selector.push(
1349
+ {
1350
+ ...f,
1351
+ id: l.id,
1352
+ // @ts-expect-error: `scope` is not part of the core `TextSelector` type
1353
+ scope: l.scope
1354
+ }
1355
+ );
1352
1356
  else {
1353
1357
  const d = [
1354
1358
  f.start ? void 0 : "TextPositionSelector",
@@ -1381,23 +1385,24 @@ const ko = (t, e) => ({
1381
1385
  created: l,
1382
1386
  updated: c,
1383
1387
  ...f
1384
- } = i, d = r.map((y) => {
1385
- const { id: p, scope: w, quote: b, start: C, end: g, range: u } = y, { prefix: m, suffix: S } = _e(u, n);
1388
+ } = i, d = r.map((m) => {
1389
+ const { id: p, quote: v, start: b, end: C, range: g } = m, { prefix: u, suffix: y } = _e(g, n), S = [{
1390
+ type: "TextQuoteSelector",
1391
+ exact: v,
1392
+ prefix: u,
1393
+ suffix: y
1394
+ }, {
1395
+ type: "TextPositionSelector",
1396
+ start: b,
1397
+ end: C
1398
+ }];
1386
1399
  return {
1387
1400
  ...f,
1388
1401
  id: p,
1389
- scope: w,
1402
+ // @ts-expect-error: `scope` is not part of the core `TextSelector` type
1403
+ scope: "scope" in m ? m.scope : void 0,
1390
1404
  source: e,
1391
- selector: [{
1392
- type: "TextQuoteSelector",
1393
- exact: b,
1394
- prefix: m,
1395
- suffix: S
1396
- }, {
1397
- type: "TextPositionSelector",
1398
- start: C,
1399
- end: g
1400
- }]
1405
+ selector: S
1401
1406
  };
1402
1407
  });
1403
1408
  return {
@@ -1415,8 +1420,8 @@ const ko = (t, e) => ({
1415
1420
  function we(t, e, n = 0, o = t.length - 1, i = eo) {
1416
1421
  for (; o > n; ) {
1417
1422
  if (o - n > 600) {
1418
- const l = o - n + 1, c = e - n + 1, f = Math.log(l), d = 0.5 * Math.exp(2 * f / 3), y = 0.5 * Math.sqrt(f * d * (l - d) / l) * (c - l / 2 < 0 ? -1 : 1), p = Math.max(n, Math.floor(e - c * d / l + y)), w = Math.min(o, Math.floor(e + (l - c) * d / l + y));
1419
- we(t, e, p, w, i);
1423
+ const l = o - n + 1, c = e - n + 1, f = Math.log(l), d = 0.5 * Math.exp(2 * f / 3), m = 0.5 * Math.sqrt(f * d * (l - d) / l) * (c - l / 2 < 0 ? -1 : 1), p = Math.max(n, Math.floor(e - c * d / l + m)), v = Math.min(o, Math.floor(e + (l - c) * d / l + m));
1424
+ we(t, e, p, v, i);
1420
1425
  }
1421
1426
  const s = t[e];
1422
1427
  let r = n, a = o;
@@ -1545,9 +1550,9 @@ class no {
1545
1550
  for (let f = n; f <= o; f += c) {
1546
1551
  const d = Math.min(f + c - 1, o);
1547
1552
  ne(e, f, d, l, this.compareMinY);
1548
- for (let y = f; y <= d; y += l) {
1549
- const p = Math.min(y + l - 1, d);
1550
- a.children.push(this._build(e, y, p, i - 1));
1553
+ for (let m = f; m <= d; m += l) {
1554
+ const p = Math.min(m + l - 1, d);
1555
+ a.children.push(this._build(e, m, p, i - 1));
1551
1556
  }
1552
1557
  }
1553
1558
  return Q(a, this.toBBox), a;
@@ -1695,121 +1700,121 @@ let co = () => ({
1695
1700
  }
1696
1701
  });
1697
1702
  const lo = (t, e) => {
1698
- const n = new no(), o = /* @__PURE__ */ new Map(), i = co(), s = (m, S) => {
1699
- const x = m.selector.flatMap((R) => {
1703
+ const n = new no(), o = /* @__PURE__ */ new Map(), i = co(), s = (y, S) => {
1704
+ const E = y.selector.flatMap((R) => {
1700
1705
  const T = F([R]) ? R.range : ce(R, e).range;
1701
1706
  return Array.from(T.getClientRects());
1702
- }), O = Ye(x).map((R) => je(R, S));
1707
+ }), O = Ye(E).map((R) => je(R, S));
1703
1708
  return O.map((R) => {
1704
- const { x: T, y: E, width: h, height: v } = R;
1709
+ const { x: T, y: A, width: h, height: w } = R;
1705
1710
  return {
1706
1711
  minX: T,
1707
- minY: E,
1712
+ minY: A,
1708
1713
  maxX: T + h,
1709
- maxY: E + v,
1714
+ maxY: A + w,
1710
1715
  annotation: {
1711
- id: m.annotation,
1716
+ id: y.annotation,
1712
1717
  rects: O
1713
1718
  }
1714
1719
  };
1715
1720
  });
1716
1721
  }, r = () => [...o.values()], a = () => {
1717
1722
  n.clear(), o.clear();
1718
- }, l = (m) => {
1719
- const S = s(m, e.getBoundingClientRect());
1720
- S.forEach((x) => n.insert(x)), o.set(m.annotation, S);
1721
- }, c = (m) => {
1722
- const S = o.get(m.annotation);
1723
- S && (S.forEach((x) => n.remove(x)), o.delete(m.annotation));
1724
- }, f = (m) => {
1725
- c(m), l(m);
1726
- }, d = (m, S = !0) => {
1723
+ }, l = (y) => {
1724
+ const S = s(y, e.getBoundingClientRect());
1725
+ S.forEach((E) => n.insert(E)), o.set(y.annotation, S);
1726
+ }, c = (y) => {
1727
+ const S = o.get(y.annotation);
1728
+ S && (S.forEach((E) => n.remove(E)), o.delete(y.annotation));
1729
+ }, f = (y) => {
1730
+ c(y), l(y);
1731
+ }, d = (y, S = !0) => {
1727
1732
  S && a();
1728
- const x = e.getBoundingClientRect(), O = m.map((T) => ({ target: T, rects: s(T, x) }));
1729
- O.forEach(({ target: T, rects: E }) => o.set(T.annotation, E));
1733
+ const E = e.getBoundingClientRect(), O = y.map((T) => ({ target: T, rects: s(T, E) }));
1734
+ O.forEach(({ target: T, rects: A }) => o.set(T.annotation, A));
1730
1735
  const R = O.flatMap(({ rects: T }) => T);
1731
1736
  n.load(R);
1732
- }, y = (m, S, x = !1) => {
1737
+ }, m = (y, S, E = !1) => {
1733
1738
  const O = n.search({
1734
- minX: m,
1739
+ minX: y,
1735
1740
  minY: S,
1736
- maxX: m,
1741
+ maxX: y,
1737
1742
  maxY: S
1738
- }), R = (T) => T.annotation.rects.reduce((E, h) => E + h.width * h.height, 0);
1739
- return O.length > 0 ? (O.sort((T, E) => R(T) - R(E)), x ? O.map((T) => T.annotation.id) : [O[0].annotation.id]) : [];
1740
- }, p = (m) => {
1741
- const S = w(m);
1743
+ }), R = (T) => T.annotation.rects.reduce((A, h) => A + h.width * h.height, 0);
1744
+ return O.length > 0 ? (O.sort((T, A) => R(T) - R(A)), E ? O.map((T) => T.annotation.id) : [O[0].annotation.id]) : [];
1745
+ }, p = (y) => {
1746
+ const S = v(y);
1742
1747
  if (S.length === 0)
1743
1748
  return;
1744
- let x = S[0].left, O = S[0].top, R = S[0].right, T = S[0].bottom;
1745
- for (let E = 1; E < S.length; E++) {
1746
- const h = S[E];
1747
- x = Math.min(x, h.left), O = Math.min(O, h.top), R = Math.max(R, h.right), T = Math.max(T, h.bottom);
1749
+ let E = S[0].left, O = S[0].top, R = S[0].right, T = S[0].bottom;
1750
+ for (let A = 1; A < S.length; A++) {
1751
+ const h = S[A];
1752
+ E = Math.min(E, h.left), O = Math.min(O, h.top), R = Math.max(R, h.right), T = Math.max(T, h.bottom);
1748
1753
  }
1749
- return new DOMRect(x, O, R - x, T - O);
1750
- }, w = (m) => {
1751
- const S = o.get(m);
1754
+ return new DOMRect(E, O, R - E, T - O);
1755
+ }, v = (y) => {
1756
+ const S = o.get(y);
1752
1757
  return S[0] ? S[0].annotation.rects : [];
1753
1758
  };
1754
1759
  return {
1755
1760
  all: r,
1756
1761
  clear: a,
1757
- getAt: y,
1762
+ getAt: m,
1758
1763
  getAnnotationBounds: p,
1759
- getAnnotationRects: w,
1760
- getIntersecting: (m, S, x, O) => {
1761
- const R = n.search({ minX: m, minY: S, maxX: x, maxY: O }), T = new Set(R.map((E) => E.annotation.id));
1762
- return Array.from(T).map((E) => ({
1763
- annotation: t.getAnnotation(E),
1764
- rects: w(E)
1765
- })).filter((E) => !!E.annotation);
1764
+ getAnnotationRects: v,
1765
+ getIntersecting: (y, S, E, O) => {
1766
+ const R = n.search({ minX: y, minY: S, maxX: E, maxY: O }), T = new Set(R.map((A) => A.annotation.id));
1767
+ return Array.from(T).map((A) => ({
1768
+ annotation: t.getAnnotation(A),
1769
+ rects: v(A)
1770
+ })).filter((A) => !!A.annotation);
1766
1771
  },
1767
1772
  insert: l,
1768
1773
  recalculate: () => {
1769
- d(t.all().map((m) => m.target), !0), i.emit("recalculate");
1774
+ d(t.all().map((y) => y.target), !0), i.emit("recalculate");
1770
1775
  },
1771
1776
  remove: c,
1772
1777
  set: d,
1773
1778
  size: () => n.all().length,
1774
1779
  update: f,
1775
- on: (m, S) => i.on(m, S)
1780
+ on: (y, S) => i.on(y, S)
1776
1781
  };
1777
1782
  }, uo = (t, e) => {
1778
1783
  const n = Nn(), o = lo(n, t), i = xn(n);
1779
1784
  i.setUserSelectAction(e);
1780
- const s = vn(n), r = Vn(), a = (u, m = k.LOCAL) => {
1781
- const S = vt(u, t), x = F(S.target.selector);
1782
- return x && n.addAnnotation(S, m), x;
1783
- }, l = (u, m = !0, S = k.LOCAL) => {
1784
- const x = u.map((R) => vt(R, t)), O = x.filter((R) => !F(R.target.selector));
1785
- return O.length > 0 ? (console.warn("Could not revive all targets for these annotations:", O), n.bulkAddAnnotation(x, m, S), O) : (n.bulkAddAnnotation(x, m, S), []);
1786
- }, c = (u, m = k.LOCAL) => {
1787
- const S = u.map((O) => vt(O, t)), x = S.filter((O) => !F(O.target.selector));
1788
- return x.length > 0 && console.warn("Could not revive all targets for these annotations:", x), S.forEach((O) => {
1789
- n.getAnnotation(O.id) ? n.updateAnnotation(O, m) : n.addAnnotation(O, m);
1790
- }), x;
1791
- }, f = (u, m = k.LOCAL) => {
1785
+ const s = vn(n), r = Vn(), a = (u, y = k.LOCAL) => {
1786
+ const S = vt(u, t), E = F(S.target.selector);
1787
+ return E && n.addAnnotation(S, y), E;
1788
+ }, l = (u, y = !0, S = k.LOCAL) => {
1789
+ const E = u.map((R) => vt(R, t)), O = E.filter((R) => !F(R.target.selector));
1790
+ return n.bulkAddAnnotation(E, y, S), O;
1791
+ }, c = (u, y = k.LOCAL) => {
1792
+ const S = u.map((O) => vt(O, t)), E = S.filter((O) => !F(O.target.selector));
1793
+ return S.forEach((O) => {
1794
+ n.getAnnotation(O.id) ? n.updateAnnotation(O, y) : n.addAnnotation(O, y);
1795
+ }), E;
1796
+ }, f = (u, y = k.LOCAL) => {
1792
1797
  const S = bt(u, t);
1793
- n.updateTarget(S, m);
1794
- }, d = (u, m = k.LOCAL) => {
1795
- const S = u.map((x) => bt(x, t));
1796
- n.bulkUpdateTargets(S, m);
1797
- }, y = (u, m, S) => {
1798
- const x = o.getAt(u, m, !!S).map((R) => n.getAnnotation(R)), O = S ? x.filter(S) : x;
1798
+ n.updateTarget(S, y);
1799
+ }, d = (u, y = k.LOCAL) => {
1800
+ const S = u.map((E) => bt(E, t));
1801
+ n.bulkUpdateTargets(S, y);
1802
+ }, m = (u, y, S) => {
1803
+ const E = o.getAt(u, y, !!S).map((R) => n.getAnnotation(R)), O = S ? E.filter(S) : E;
1799
1804
  return O.length > 0 ? O[0] : void 0;
1800
- }, p = (u, m, S, x = 5) => {
1805
+ }, p = (u, y, S, E = 5) => {
1801
1806
  const O = o.getAnnotationRects(u);
1802
1807
  if (O.length !== 0) {
1803
- if (m && S) {
1804
- const R = O.find(({ top: T, right: E, bottom: h, left: v }) => m >= v - x && m <= E + x && S >= T - x && S <= h + x);
1808
+ if (y && S) {
1809
+ const R = O.find(({ top: T, right: A, bottom: h, left: w }) => y >= w - E && y <= A + E && S >= T - E && S <= h + E);
1805
1810
  if (R) return R;
1806
1811
  }
1807
1812
  return o.getAnnotationBounds(u);
1808
1813
  }
1809
- }, w = (u, m, S, x) => o.getIntersecting(u, m, S, x), b = (u) => o.getAnnotationRects(u), C = () => o.recalculate(), g = (u) => o.on("recalculate", u);
1814
+ }, v = (u, y, S, E) => o.getIntersecting(u, y, S, E), b = (u) => o.getAnnotationRects(u), C = () => o.recalculate(), g = (u) => o.on("recalculate", u);
1810
1815
  return n.observe(({ changes: u }) => {
1811
- const m = (u.deleted || []).filter((O) => F(O.target.selector)), S = (u.created || []).filter((O) => F(O.target.selector)), x = (u.updated || []).filter((O) => F(O.newValue.target.selector));
1812
- (m == null ? void 0 : m.length) > 0 && m.forEach((O) => o.remove(O.target)), S.length > 0 && o.set(S.map((O) => O.target), !1), (x == null ? void 0 : x.length) > 0 && x.forEach(({ newValue: O }) => o.update(O.target));
1816
+ const y = (u.deleted || []).filter((O) => F(O.target.selector)), S = (u.created || []).filter((O) => F(O.target.selector)), E = (u.updated || []).filter((O) => F(O.newValue.target.selector));
1817
+ (y == null ? void 0 : y.length) > 0 && y.forEach((O) => o.remove(O.target)), S.length > 0 && o.set(S.map((O) => O.target), !1), (E == null ? void 0 : E.length) > 0 && E.forEach(({ newValue: O }) => o.update(O.target));
1813
1818
  }), {
1814
1819
  store: {
1815
1820
  ...n,
@@ -1819,8 +1824,8 @@ const lo = (t, e) => {
1819
1824
  bulkUpsertAnnotations: c,
1820
1825
  getAnnotationBounds: p,
1821
1826
  getAnnotationRects: b,
1822
- getIntersecting: w,
1823
- getAt: y,
1827
+ getIntersecting: v,
1828
+ getAt: m,
1824
1829
  recalculatePositions: C,
1825
1830
  onRecalculatePositions: g,
1826
1831
  updateTarget: f
@@ -1837,7 +1842,7 @@ const lo = (t, e) => {
1837
1842
  }, ho = (t, e = {}) => {
1838
1843
  const n = fo(), o = n.getContext("2d");
1839
1844
  document.body.appendChild(n);
1840
- const i = /* @__PURE__ */ new Map(), s = (f) => Array.from(i.entries()).filter(([d, y]) => y.presenceKey === f.presenceKey).map(([d, y]) => d);
1845
+ const i = /* @__PURE__ */ new Map(), s = (f) => Array.from(i.entries()).filter(([d, m]) => m.presenceKey === f.presenceKey).map(([d, m]) => d);
1841
1846
  return t.on("selectionChange", (f, d) => {
1842
1847
  s(f).forEach((p) => i.delete(p)), d && d.forEach((p) => i.set(p, f));
1843
1848
  }), {
@@ -1848,16 +1853,16 @@ const lo = (t, e) => {
1848
1853
  destroy: () => {
1849
1854
  n.remove();
1850
1855
  },
1851
- paint: (f, d, y) => {
1856
+ paint: (f, d, m) => {
1852
1857
  e.font && (o.font = e.font);
1853
1858
  const p = i.get(f.annotation.id);
1854
1859
  if (p) {
1855
- const { height: w } = f.rects[0], b = f.rects[0].x + d.left, C = f.rects[0].y + d.top;
1856
- o.fillStyle = p.appearance.color, o.fillRect(b - 2, C - 2.5, 2, w + 5);
1857
- const g = o.measureText(p.appearance.label), u = g.width + 6, m = g.actualBoundingBoxAscent + g.actualBoundingBoxDescent + 8, S = g.fontBoundingBoxAscent ? 8 : 6.5;
1858
- return o.fillRect(b - 2, C - 2.5 - m, u, m), o.fillStyle = "#fff", o.fillText(p.appearance.label, b + 1, C - S), {
1860
+ const { height: v } = f.rects[0], b = f.rects[0].x + d.left, C = f.rects[0].y + d.top;
1861
+ o.fillStyle = p.appearance.color, o.fillRect(b - 2, C - 2.5, 2, v + 5);
1862
+ const g = o.measureText(p.appearance.label), u = g.width + 6, y = g.actualBoundingBoxAscent + g.actualBoundingBoxDescent + 8, S = g.fontBoundingBoxAscent ? 8 : 6.5;
1863
+ return o.fillRect(b - 2, C - 2.5 - y, u, y), o.fillStyle = "#fff", o.fillText(p.appearance.label, b + 1, C - S), {
1859
1864
  fill: p.appearance.color,
1860
- fillOpacity: y ? 0.45 : 0.18
1865
+ fillOpacity: m ? 0.45 : 0.18
1861
1866
  };
1862
1867
  }
1863
1868
  },
@@ -2079,11 +2084,11 @@ const yt = (t) => {
2079
2084
  const a = r.split(i), l = a.length, c = a[l - 1], f = c === "*" ? "*" : lt(c);
2080
2085
  if (!N[f]) return;
2081
2086
  n || (n = ct());
2082
- const d = l > 1 ? ve(j, a) : [], y = [];
2087
+ const d = l > 1 ? ve(j, a) : [], m = [];
2083
2088
  N[f] = N[f].filter((p) => {
2084
2089
  const b = (o ? p.method === o : !0) && p.scope === n && po(p.mods, d);
2085
- return b && y.push(p.element), !b;
2086
- }), y.forEach((p) => Pt(p));
2090
+ return b && m.push(p.element), !b;
2091
+ }), m.forEach((p) => Pt(p));
2087
2092
  });
2088
2093
  };
2089
2094
  function oe(t, e, n, o) {
@@ -2124,16 +2129,16 @@ function ie(t, e) {
2124
2129
  const l = s[a], {
2125
2130
  splitKey: c
2126
2131
  } = l, f = l.key.split(c), d = [];
2127
- for (let y = 0; y < f.length; y++)
2128
- d.push(lt(f[y]));
2132
+ for (let m = 0; m < f.length; m++)
2133
+ d.push(lt(f[m]));
2129
2134
  d.sort().join("") === I.sort().join("") && oe(t, l, i, e);
2130
2135
  }
2131
2136
  }
2132
2137
  function P(t, e, n) {
2133
2138
  I = [];
2134
2139
  const o = Ae(t);
2135
- let i = [], s = "all", r = document, a = 0, l = !1, c = !0, f = "+", d = !1, y = !1;
2136
- for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (r = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (c = e.keydown), e.capture !== void 0 && (d = e.capture), typeof e.splitKey == "string" && (f = e.splitKey), e.single === !0 && (y = !0)), typeof e == "string" && (s = e), y && Se(t, s); a < o.length; a++)
2140
+ let i = [], s = "all", r = document, a = 0, l = !1, c = !0, f = "+", d = !1, m = !1;
2141
+ for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (r = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (c = e.keydown), e.capture !== void 0 && (d = e.capture), typeof e.splitKey == "string" && (f = e.splitKey), e.single === !0 && (m = !0)), typeof e == "string" && (s = e), m && Se(t, s); a < o.length; a++)
2137
2142
  t = o[a].split(f), i = [], t.length > 1 && (i = ve(j, t)), t = t[t.length - 1], t = t === "*" ? "*" : lt(t), t in N || (N[t] = []), N[t].push({
2138
2143
  keyup: l,
2139
2144
  keydown: c,
@@ -2150,15 +2155,15 @@ function P(t, e, n) {
2150
2155
  const p = function() {
2151
2156
  let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2152
2157
  return ie(b, r);
2153
- }, w = function() {
2158
+ }, v = function() {
2154
2159
  let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2155
2160
  ie(b, r), Eo(b);
2156
2161
  };
2157
2162
  z.set(r, {
2158
2163
  keydownListener: p,
2159
- keyupListenr: w,
2164
+ keyupListenr: v,
2160
2165
  capture: d
2161
- }), It(r, "keydown", p, d), It(r, "keyup", w, d);
2166
+ }), It(r, "keydown", p, d), It(r, "keyup", v, d);
2162
2167
  }
2163
2168
  if (!rt) {
2164
2169
  const p = () => {
@@ -2243,21 +2248,21 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
2243
2248
  ], Oo = (t, e, n) => {
2244
2249
  const { store: o, selection: i } = e;
2245
2250
  let s;
2246
- const r = (E) => s = E;
2251
+ const r = (A) => s = A;
2247
2252
  let a;
2248
- const l = (E) => a = E;
2249
- let c, f, d, y = !0;
2250
- const p = (E) => {
2251
- y = E, b.clear(), E || (c = void 0, d = void 0);
2252
- }, w = (E) => {
2253
- f !== !1 && (c = nt(E.target) ? void 0 : {
2253
+ const l = (A) => a = A;
2254
+ let c, f, d, m = !0;
2255
+ const p = (A) => {
2256
+ m = A, b.clear(), A || (c = void 0, f = void 0, d = void 0);
2257
+ }, v = (A) => {
2258
+ m && f !== !1 && (c = nt(A.target) ? void 0 : {
2254
2259
  annotation: ge(),
2255
2260
  selector: [],
2256
2261
  creator: s,
2257
2262
  created: /* @__PURE__ */ new Date()
2258
2263
  });
2259
- }, b = Kt((E) => {
2260
- if (!y) return;
2264
+ }, b = Kt((A) => {
2265
+ if (!m) return;
2261
2266
  const h = document.getSelection();
2262
2267
  if (!(h != null && h.anchorNode))
2263
2268
  return;
@@ -2265,13 +2270,13 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
2265
2270
  c = void 0;
2266
2271
  return;
2267
2272
  }
2268
- const v = E.timeStamp - ((d == null ? void 0 : d.timeStamp) || E.timeStamp);
2269
- if ((d == null ? void 0 : d.type) === "pointerdown" && (v < 1e3 && !c || h.isCollapsed && v < se) && w(d || E), !c) return;
2273
+ const w = A.timeStamp - ((d == null ? void 0 : d.timeStamp) || A.timeStamp);
2274
+ if ((d == null ? void 0 : d.type) === "pointerdown" && (w < 1e3 && !c || h.isCollapsed && w < se) && v(d || A), !c) return;
2270
2275
  if (h.isCollapsed) {
2271
2276
  o.getAnnotation(c.annotation) && (i.clear(), o.deleteAnnotation(c.annotation));
2272
2277
  return;
2273
2278
  }
2274
- const A = h.getRangeAt(0), L = $e(A, t);
2279
+ const x = h.getRangeAt(0), L = $e(x, t);
2275
2280
  if (De(L)) return;
2276
2281
  const M = Ne(L.cloneRange());
2277
2282
  (M.length !== c.selector.length || M.some((K, Y) => {
@@ -2282,64 +2287,72 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
2282
2287
  selector: M.map((K) => Xe(K, t, n)),
2283
2288
  updated: /* @__PURE__ */ new Date()
2284
2289
  }, o.getAnnotation(c.annotation) ? o.updateTarget(c, k.LOCAL) : i.clear());
2285
- }, 10), C = (E) => {
2286
- nt(E.target) || (d = At(E), f = d.button === 0);
2287
- }, g = () => {
2288
- o.getAnnotation(c.annotation) ? o.updateTarget(c) : o.addAnnotation({
2289
- id: c.annotation,
2290
- bodies: [],
2291
- target: c
2292
- });
2293
- }, u = async (E) => {
2294
- if (nt(E.target) || !f) return;
2290
+ }, 10), C = (A) => {
2291
+ nt(A.target) || (d = At(A), f = d.button === 0);
2292
+ }, g = async (A) => {
2293
+ if (nt(A.target) || !f) return;
2295
2294
  const h = () => {
2296
- const { x: A, y: L } = t.getBoundingClientRect(), M = E.target instanceof Node && t.contains(E.target) && o.getAt(E.clientX - A, E.clientY - L, a);
2295
+ const { x, y: L } = t.getBoundingClientRect(), M = A.target instanceof Node && t.contains(A.target) && o.getAt(A.clientX - x, A.clientY - L, a);
2297
2296
  if (M) {
2298
2297
  const { selected: B } = i;
2299
- (B.length !== 1 || B[0].id !== M.id) && i.userSelect(M.id, E);
2298
+ (B.length !== 1 || B[0].id !== M.id) && i.userSelect(M.id, A);
2300
2299
  } else
2301
2300
  i.clear();
2302
2301
  };
2303
- if (E.timeStamp - d.timeStamp < se) {
2304
- await m();
2305
- const A = document.getSelection();
2306
- if (A != null && A.isCollapsed) {
2302
+ if (A.timeStamp - d.timeStamp < se) {
2303
+ await u();
2304
+ const x = document.getSelection();
2305
+ if (x != null && x.isCollapsed) {
2307
2306
  c = void 0, h();
2308
2307
  return;
2309
2308
  }
2310
2309
  }
2311
- c && c.selector.length > 0 && (i.clear(), g(), i.userSelect(c.annotation, At(E)));
2312
- }, m = async () => {
2313
- const E = document.getSelection();
2314
- let h = !1, v = E == null ? void 0 : E.isCollapsed;
2315
- const A = () => v || h, L = 1;
2316
- return setTimeout(() => h = !0, 50), Co(() => v = E == null ? void 0 : E.isCollapsed, L, A);
2317
- }, S = (E) => {
2310
+ c && c.selector.length > 0 && (i.clear(), R(), i.userSelect(c.annotation, At(A)));
2311
+ }, u = async () => {
2312
+ const A = document.getSelection();
2313
+ let h = !1, w = A == null ? void 0 : A.isCollapsed;
2314
+ const x = () => w || h, L = 1;
2315
+ return setTimeout(() => h = !0, 50), Co(() => w = A == null ? void 0 : A.isCollapsed, L, x);
2316
+ }, y = (A) => {
2318
2317
  const h = document.getSelection();
2319
- h != null && h.isCollapsed || ((!c || c.selector.length === 0) && b(E), g(), i.userSelect(c.annotation, At(E)));
2320
- }, x = (E) => {
2321
- y && E.key === "Shift" && c && (document.getSelection().isCollapsed || (i.clear(), g(), i.userSelect(c.annotation, ut(E))));
2322
- }, O = (E) => {
2318
+ h != null && h.isCollapsed || ((!c || c.selector.length === 0) && b(A), R(), i.userSelect(c.annotation, At(A)));
2319
+ }, S = (A) => {
2320
+ m && A.key === "Shift" && c && (document.getSelection().isCollapsed || (i.clear(), R(), i.userSelect(c.annotation, ut(A))));
2321
+ }, E = (A) => {
2323
2322
  const h = () => setTimeout(() => {
2324
2323
  (c == null ? void 0 : c.selector.length) > 0 && (i.clear(), o.addAnnotation({
2325
2324
  id: c.annotation,
2326
2325
  bodies: [],
2327
2326
  target: c
2328
- }), i.userSelect(c.annotation, ut(E))), document.removeEventListener("selectionchange", h);
2327
+ }), i.userSelect(c.annotation, ut(A))), document.removeEventListener("selectionchange", h);
2329
2328
  }, 100);
2330
- document.addEventListener("selectionchange", h), w(E);
2329
+ document.addEventListener("selectionchange", h), v(A);
2331
2330
  };
2332
- P(Lo.join(","), { element: t, keydown: !0, keyup: !1 }, (E) => {
2333
- E.repeat || (d = ut(E));
2334
- }), P(Le, { keydown: !0, keyup: !1 }, (E) => {
2335
- d = ut(E), O(E);
2331
+ P(Lo.join(","), { element: t, keydown: !0, keyup: !1 }, (A) => {
2332
+ A.repeat || (d = ut(A));
2333
+ }), P(Le, { keydown: !0, keyup: !1 }, (A) => {
2334
+ d = ut(A), E(A);
2336
2335
  });
2337
- const R = (E) => {
2338
- E.repeat || E.target !== t && E.target !== document.body || (c = void 0, i.clear());
2336
+ const O = (A) => {
2337
+ A.repeat || A.target !== t && A.target !== document.body || (c = void 0, i.clear());
2338
+ };
2339
+ P(Ce.join(","), { keydown: !0, keyup: !1 }, O);
2340
+ const R = () => {
2341
+ const A = o.getAnnotation(c.annotation);
2342
+ if (!A) {
2343
+ o.addAnnotation({
2344
+ id: c.annotation,
2345
+ bodies: [],
2346
+ target: c
2347
+ });
2348
+ return;
2349
+ }
2350
+ const { target: { updated: h } } = A, { updated: w } = c;
2351
+ (!A || !w || h < w) && o.updateTarget(c);
2339
2352
  };
2340
- return P(Ce.join(","), { keydown: !0, keyup: !1 }, R), document.addEventListener("pointerdown", C), document.addEventListener("pointerup", u), document.addEventListener("contextmenu", S), t.addEventListener("keyup", x), t.addEventListener("selectstart", w), document.addEventListener("selectionchange", b), {
2353
+ return document.addEventListener("pointerdown", C), document.addEventListener("pointerup", g), document.addEventListener("contextmenu", y), t.addEventListener("keyup", S), t.addEventListener("selectstart", v), document.addEventListener("selectionchange", b), {
2341
2354
  destroy: () => {
2342
- c = void 0, f = void 0, d = void 0, b.clear(), document.removeEventListener("pointerdown", C), document.removeEventListener("pointerup", u), document.removeEventListener("contextmenu", S), t.removeEventListener("keyup", x), t.removeEventListener("selectstart", w), document.removeEventListener("selectionchange", b), P.unbind();
2355
+ c = void 0, f = void 0, d = void 0, b.clear(), document.removeEventListener("pointerdown", C), document.removeEventListener("pointerup", g), document.removeEventListener("contextmenu", y), t.removeEventListener("keyup", S), t.removeEventListener("selectstart", v), document.removeEventListener("selectionchange", b), P.unbind();
2343
2356
  },
2344
2357
  setFilter: l,
2345
2358
  setUser: r,
@@ -2360,34 +2373,34 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
2360
2373
  if (!d)
2361
2374
  throw `Unknown renderer implementation: ${f}`;
2362
2375
  console.debug(`Using ${f} renderer`), n.style && d.setStyle(n.style);
2363
- const y = Oo(t, o, n.offsetReferenceSelector);
2364
- y.setUser(c), y.setAnnotatingEnabled(n.annotatingEnabled);
2365
- const p = Xn(o, a, n.adapter), w = () => c, b = (x) => {
2366
- y.setAnnotatingEnabled(
2367
- x === void 0 ? !0 : x
2376
+ const m = Oo(t, o, n.offsetReferenceSelector);
2377
+ m.setUser(c), m.setAnnotatingEnabled(n.annotatingEnabled);
2378
+ const p = Xn(o, a, n.adapter), v = () => c, b = (E) => {
2379
+ m.setAnnotatingEnabled(
2380
+ E === void 0 ? !0 : E
2368
2381
  );
2369
- }, C = (x) => {
2370
- d.setFilter(x), y.setFilter(x);
2371
- }, g = (x) => {
2372
- c = x, y.setUser(x);
2373
- }, u = (x) => {
2374
- x && (d.setPainter(ho(x, n.presence)), x.on("selectionChange", () => d.redraw()));
2375
- }, m = (x) => {
2376
- x ? i.setSelected(x) : i.clear();
2382
+ }, C = (E) => {
2383
+ d.setFilter(E), m.setFilter(E);
2384
+ }, g = (E) => {
2385
+ c = E, m.setUser(E);
2386
+ }, u = (E) => {
2387
+ E && (d.setPainter(ho(E, n.presence)), E.on("selectionChange", () => d.redraw()));
2388
+ }, y = (E) => {
2389
+ E ? i.setSelected(E) : i.clear();
2377
2390
  };
2378
2391
  return {
2379
2392
  ...p,
2380
2393
  destroy: () => {
2381
- d.destroy(), y.destroy(), a.destroy();
2394
+ d.destroy(), m.destroy(), a.destroy();
2382
2395
  },
2383
2396
  element: t,
2384
- getUser: w,
2397
+ getUser: v,
2385
2398
  setAnnotatingEnabled: b,
2386
2399
  setFilter: C,
2387
2400
  setStyle: d.setStyle.bind(d),
2388
2401
  redraw: d.redraw.bind(d),
2389
2402
  setUser: g,
2390
- setSelected: m,
2403
+ setSelected: y,
2391
2404
  setPresenceProvider: u,
2392
2405
  setVisible: d.setVisible.bind(d),
2393
2406
  on: l.on,