@soomo/text-annotator 3.1.0-staging.14 → 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.
@@ -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: m } = 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 - m) / 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) {
@@ -288,20 +288,20 @@ 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, y: h } = t.getBoundingClientRect(), v = i.getAt(T.clientX - x, 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
295
  const m = (T = !1) => {
296
296
  c && c.clear();
297
- const x = qe(t), { minX: h, minY: v, maxX: A, maxY: L } = x, 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, x, 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
303
  c = T, m();
304
- }, w = (T) => {
304
+ }, v = (T) => {
305
305
  a = T, m();
306
306
  }, b = (T) => {
307
307
  l = T, m(!1);
@@ -323,7 +323,7 @@ const Kt = /* @__PURE__ */ Fe(We), qe = (t) => {
323
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
325
  redraw: m,
326
- setStyle: w,
326
+ setStyle: v,
327
327
  setFilter: b,
328
328
  setPainter: p,
329
329
  setVisible: o.setVisible
@@ -340,14 +340,14 @@ const Kt = /* @__PURE__ */ Fe(We), qe = (t) => {
340
340
  const o = (a, l, c, f) => requestAnimationFrame(() => {
341
341
  const { width: d, height: m } = e;
342
342
  n.clearRect(-0.5, -0.5, d + 1, m + 1), f && f.clear();
343
- const { top: p, left: w } = l;
343
+ const { top: p, left: v } = l;
344
344
  [...a].sort((C, g) => {
345
345
  const { annotation: { target: { created: u } } } = C, { annotation: { target: { created: y } } } = g;
346
346
  return u.getTime() - y.getTime();
347
347
  }).forEach((C) => {
348
348
  var S;
349
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 + w,
350
+ x: E + v,
351
351
  y: O + p,
352
352
  width: R,
353
353
  height: T
@@ -357,8 +357,8 @@ const Kt = /* @__PURE__ */ Fe(We), qe = (t) => {
357
357
  ), u.underlineColor) {
358
358
  n.globalAlpha = 1, n.strokeStyle = u.underlineColor, n.lineWidth = u.underlineThickness ?? 1;
359
359
  const E = u.underlineOffset ?? 0;
360
- y.forEach(({ x: O, y: R, width: T, height: x }) => {
361
- n.beginPath(), n.moveTo(O, R + x + E), n.lineTo(O + T, R + x + E), n.stroke();
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 m = a ? typeof a == "function" ? a(d.annotation, d.state) : a : (w = d.state) != null && w.selected ? wt : W, p = l && l.paint(d, r) || m;
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 m = d.target.selector.map((w) => w.range), p = new Highlight(...m);
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
  }
@@ -573,15 +573,15 @@ const fn = (t, e) => {
573
573
  redraw: (r, a, l, c, f) => {
574
574
  const m = !(Ut(n, r) && f);
575
575
  if (!c && !m) return;
576
- m && (e.innerHTML = ""), [...r].sort((w, b) => {
577
- const { annotation: { target: { created: C } } } = w, { annotation: { target: { created: g } } } = b;
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);
579
+ }).forEach((v) => {
580
+ v.rects.map((b) => {
581
+ const C = fn(b, r), g = ze(v, a, l, c, C);
582
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
722
  const y = b === void 0 ? te(u, s) === "EDIT" : b;
723
723
  return { id: u.id, editable: y };
724
724
  })
725
- }), g.length !== C.length && console.warn("Invalid selection", w);
726
- }, m = (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 }) => m((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;
@@ -843,8 +843,8 @@ const Bn = (t, e) => {
843
843
  ...(t.updated || []).filter(({ newValue: d }) => !s.has(d.id)).map((d) => {
844
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(m, 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
924
  }, d = () => [...t.values()], m = (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) => {
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
- }, y = (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;
985
+ const w = t.get(h);
986
+ return w ? { ...w } : void 0;
987
987
  }, E = (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;
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
- }, x = (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
  };
@@ -1045,9 +1045,9 @@ const Bn = (t, e) => {
1045
1045
  bulkDeleteBodies: y,
1046
1046
  bulkUpdateAnnotation: c,
1047
1047
  bulkUpdateBodies: T,
1048
- bulkUpdateTargets: (h, v = k.LOCAL) => {
1049
- const A = h.map((L) => x(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
1052
  clear: m,
1053
1053
  deleteAnnotation: b,
@@ -1058,9 +1058,9 @@ const Bn = (t, e) => {
1058
1058
  unobserve: i,
1059
1059
  updateAnnotation: l,
1060
1060
  updateBody: R,
1061
- updateTarget: (h, v = k.LOCAL) => {
1062
- const A = x(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), m = (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), m(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
  };
@@ -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: m, 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 ? {
@@ -1231,7 +1231,7 @@ const Un = 250, Dn = (t) => {
1231
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);
@@ -1257,7 +1257,7 @@ const Un = 250, Dn = (t) => {
1257
1257
  redo: e.redo,
1258
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
@@ -1386,9 +1386,9 @@ const ko = (t, e) => ({
1386
1386
  updated: c,
1387
1387
  ...f
1388
1388
  } = i, d = r.map((m) => {
1389
- const { id: p, quote: w, start: b, end: C, range: g } = m, { prefix: u, suffix: y } = _e(g, n), S = [{
1389
+ const { id: p, quote: v, start: b, end: C, range: g } = m, { prefix: u, suffix: y } = _e(g, n), S = [{
1390
1390
  type: "TextQuoteSelector",
1391
- exact: w,
1391
+ exact: v,
1392
1392
  prefix: u,
1393
1393
  suffix: y
1394
1394
  }, {
@@ -1399,7 +1399,7 @@ const ko = (t, e) => ({
1399
1399
  return {
1400
1400
  ...f,
1401
1401
  id: p,
1402
- // @ts-expect-error: `scope` is not part of the core `TextAnnotationTarget` type
1402
+ // @ts-expect-error: `scope` is not part of the core `TextSelector` type
1403
1403
  scope: "scope" in m ? m.scope : void 0,
1404
1404
  source: e,
1405
1405
  selector: S
@@ -1420,8 +1420,8 @@ const ko = (t, e) => ({
1420
1420
  function we(t, e, n = 0, o = t.length - 1, i = eo) {
1421
1421
  for (; o > n; ) {
1422
1422
  if (o - n > 600) {
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)), w = Math.min(o, Math.floor(e + (l - c) * d / l + m));
1424
- 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);
1425
1425
  }
1426
1426
  const s = t[e];
1427
1427
  let r = n, a = o;
@@ -1706,12 +1706,12 @@ const lo = (t, e) => {
1706
1706
  return Array.from(T.getClientRects());
1707
1707
  }), O = Ye(E).map((R) => je(R, S));
1708
1708
  return O.map((R) => {
1709
- const { x: T, y: x, width: h, height: v } = R;
1709
+ const { x: T, y: A, width: h, height: w } = R;
1710
1710
  return {
1711
1711
  minX: T,
1712
- minY: x,
1712
+ minY: A,
1713
1713
  maxX: T + h,
1714
- maxY: x + v,
1714
+ maxY: A + w,
1715
1715
  annotation: {
1716
1716
  id: y.annotation,
1717
1717
  rects: O
@@ -1731,7 +1731,7 @@ const lo = (t, e) => {
1731
1731
  }, d = (y, S = !0) => {
1732
1732
  S && a();
1733
1733
  const E = e.getBoundingClientRect(), O = y.map((T) => ({ target: T, rects: s(T, E) }));
1734
- O.forEach(({ target: T, rects: x }) => o.set(T.annotation, x));
1734
+ O.forEach(({ target: T, rects: A }) => o.set(T.annotation, A));
1735
1735
  const R = O.flatMap(({ rects: T }) => T);
1736
1736
  n.load(R);
1737
1737
  }, m = (y, S, E = !1) => {
@@ -1740,19 +1740,19 @@ const lo = (t, e) => {
1740
1740
  minY: S,
1741
1741
  maxX: y,
1742
1742
  maxY: S
1743
- }), R = (T) => T.annotation.rects.reduce((x, h) => x + h.width * h.height, 0);
1744
- return O.length > 0 ? (O.sort((T, x) => R(T) - R(x)), E ? O.map((T) => T.annotation.id) : [O[0].annotation.id]) : [];
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
1745
  }, p = (y) => {
1746
- const S = w(y);
1746
+ const S = v(y);
1747
1747
  if (S.length === 0)
1748
1748
  return;
1749
1749
  let E = S[0].left, O = S[0].top, R = S[0].right, T = S[0].bottom;
1750
- for (let x = 1; x < S.length; x++) {
1751
- const h = S[x];
1750
+ for (let A = 1; A < S.length; A++) {
1751
+ const h = S[A];
1752
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);
1753
1753
  }
1754
1754
  return new DOMRect(E, O, R - E, T - O);
1755
- }, w = (y) => {
1755
+ }, v = (y) => {
1756
1756
  const S = o.get(y);
1757
1757
  return S[0] ? S[0].annotation.rects : [];
1758
1758
  };
@@ -1761,13 +1761,13 @@ const lo = (t, e) => {
1761
1761
  clear: a,
1762
1762
  getAt: m,
1763
1763
  getAnnotationBounds: p,
1764
- getAnnotationRects: w,
1764
+ getAnnotationRects: v,
1765
1765
  getIntersecting: (y, S, E, O) => {
1766
- const R = n.search({ minX: y, minY: S, maxX: E, maxY: O }), T = new Set(R.map((x) => x.annotation.id));
1767
- return Array.from(T).map((x) => ({
1768
- annotation: t.getAnnotation(x),
1769
- rects: w(x)
1770
- })).filter((x) => !!x.annotation);
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);
1771
1771
  },
1772
1772
  insert: l,
1773
1773
  recalculate: () => {
@@ -1787,10 +1787,10 @@ const lo = (t, e) => {
1787
1787
  return E && n.addAnnotation(S, y), E;
1788
1788
  }, l = (u, y = !0, S = k.LOCAL) => {
1789
1789
  const E = u.map((R) => vt(R, t)), O = E.filter((R) => !F(R.target.selector));
1790
- return O.length > 0 ? (console.warn("Could not revive all targets for these annotations:", O), n.bulkAddAnnotation(E, y, S), O) : (n.bulkAddAnnotation(E, y, S), []);
1790
+ return n.bulkAddAnnotation(E, y, S), O;
1791
1791
  }, c = (u, y = k.LOCAL) => {
1792
1792
  const S = u.map((O) => vt(O, t)), E = S.filter((O) => !F(O.target.selector));
1793
- return E.length > 0 && console.warn("Could not revive all targets for these annotations:", E), S.forEach((O) => {
1793
+ return S.forEach((O) => {
1794
1794
  n.getAnnotation(O.id) ? n.updateAnnotation(O, y) : n.addAnnotation(O, y);
1795
1795
  }), E;
1796
1796
  }, f = (u, y = k.LOCAL) => {
@@ -1806,12 +1806,12 @@ const lo = (t, e) => {
1806
1806
  const O = o.getAnnotationRects(u);
1807
1807
  if (O.length !== 0) {
1808
1808
  if (y && S) {
1809
- const R = O.find(({ top: T, right: x, bottom: h, left: v }) => y >= v - E && y <= x + E && S >= T - E && S <= h + E);
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);
1810
1810
  if (R) return R;
1811
1811
  }
1812
1812
  return o.getAnnotationBounds(u);
1813
1813
  }
1814
- }, w = (u, y, S, E) => o.getIntersecting(u, y, S, E), 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);
1815
1815
  return n.observe(({ changes: u }) => {
1816
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
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));
@@ -1824,7 +1824,7 @@ const lo = (t, e) => {
1824
1824
  bulkUpsertAnnotations: c,
1825
1825
  getAnnotationBounds: p,
1826
1826
  getAnnotationRects: b,
1827
- getIntersecting: w,
1827
+ getIntersecting: v,
1828
1828
  getAt: m,
1829
1829
  recalculatePositions: C,
1830
1830
  onRecalculatePositions: g,
@@ -1857,8 +1857,8 @@ const lo = (t, e) => {
1857
1857
  e.font && (o.font = e.font);
1858
1858
  const p = i.get(f.annotation.id);
1859
1859
  if (p) {
1860
- const { height: w } = 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, w + 5);
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
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
1863
  return o.fillRect(b - 2, C - 2.5 - y, u, y), o.fillStyle = "#fff", o.fillText(p.appearance.label, b + 1, C - S), {
1864
1864
  fill: p.appearance.color,
@@ -2155,15 +2155,15 @@ function P(t, e, n) {
2155
2155
  const p = function() {
2156
2156
  let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2157
2157
  return ie(b, r);
2158
- }, w = function() {
2158
+ }, v = function() {
2159
2159
  let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2160
2160
  ie(b, r), Eo(b);
2161
2161
  };
2162
2162
  z.set(r, {
2163
2163
  keydownListener: p,
2164
- keyupListenr: w,
2164
+ keyupListenr: v,
2165
2165
  capture: d
2166
- }), It(r, "keydown", p, d), It(r, "keyup", w, d);
2166
+ }), It(r, "keydown", p, d), It(r, "keyup", v, d);
2167
2167
  }
2168
2168
  if (!rt) {
2169
2169
  const p = () => {
@@ -2248,20 +2248,20 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
2248
2248
  ], Oo = (t, e, n) => {
2249
2249
  const { store: o, selection: i } = e;
2250
2250
  let s;
2251
- const r = (x) => s = x;
2251
+ const r = (A) => s = A;
2252
2252
  let a;
2253
- const l = (x) => a = x;
2253
+ const l = (A) => a = A;
2254
2254
  let c, f, d, m = !0;
2255
- const p = (x) => {
2256
- m = x, b.clear(), x || (c = void 0, d = void 0);
2257
- }, w = (x) => {
2258
- m && f !== !1 && (c = nt(x.target) ? void 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 : {
2259
2259
  annotation: ge(),
2260
2260
  selector: [],
2261
2261
  creator: s,
2262
2262
  created: /* @__PURE__ */ new Date()
2263
2263
  });
2264
- }, b = Kt((x) => {
2264
+ }, b = Kt((A) => {
2265
2265
  if (!m) return;
2266
2266
  const h = document.getSelection();
2267
2267
  if (!(h != null && h.anchorNode))
@@ -2270,13 +2270,13 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
2270
2270
  c = void 0;
2271
2271
  return;
2272
2272
  }
2273
- const v = x.timeStamp - ((d == null ? void 0 : d.timeStamp) || x.timeStamp);
2274
- if ((d == null ? void 0 : d.type) === "pointerdown" && (v < 1e3 && !c || h.isCollapsed && v < se) && w(d || x), !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;
2275
2275
  if (h.isCollapsed) {
2276
2276
  o.getAnnotation(c.annotation) && (i.clear(), o.deleteAnnotation(c.annotation));
2277
2277
  return;
2278
2278
  }
2279
- const A = h.getRangeAt(0), L = $e(A, t);
2279
+ const x = h.getRangeAt(0), L = $e(x, t);
2280
2280
  if (De(L)) return;
2281
2281
  const M = Ne(L.cloneRange());
2282
2282
  (M.length !== c.selector.length || M.some((K, Y) => {
@@ -2287,64 +2287,72 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
2287
2287
  selector: M.map((K) => Xe(K, t, n)),
2288
2288
  updated: /* @__PURE__ */ new Date()
2289
2289
  }, o.getAnnotation(c.annotation) ? o.updateTarget(c, k.LOCAL) : i.clear());
2290
- }, 10), C = (x) => {
2291
- nt(x.target) || (d = At(x), f = d.button === 0);
2292
- }, g = () => {
2293
- o.getAnnotation(c.annotation) ? o.updateTarget(c) : o.addAnnotation({
2294
- id: c.annotation,
2295
- bodies: [],
2296
- target: c
2297
- });
2298
- }, u = async (x) => {
2299
- if (nt(x.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;
2300
2294
  const h = () => {
2301
- const { x: A, y: L } = t.getBoundingClientRect(), M = x.target instanceof Node && t.contains(x.target) && o.getAt(x.clientX - A, x.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);
2302
2296
  if (M) {
2303
2297
  const { selected: B } = i;
2304
- (B.length !== 1 || B[0].id !== M.id) && i.userSelect(M.id, x);
2298
+ (B.length !== 1 || B[0].id !== M.id) && i.userSelect(M.id, A);
2305
2299
  } else
2306
2300
  i.clear();
2307
2301
  };
2308
- if (x.timeStamp - d.timeStamp < se) {
2309
- await y();
2310
- const A = document.getSelection();
2311
- 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) {
2312
2306
  c = void 0, h();
2313
2307
  return;
2314
2308
  }
2315
2309
  }
2316
- c && c.selector.length > 0 && (i.clear(), g(), i.userSelect(c.annotation, At(x)));
2317
- }, y = async () => {
2318
- const x = document.getSelection();
2319
- let h = !1, v = x == null ? void 0 : x.isCollapsed;
2320
- const A = () => v || h, L = 1;
2321
- return setTimeout(() => h = !0, 50), Co(() => v = x == null ? void 0 : x.isCollapsed, L, A);
2322
- }, S = (x) => {
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) => {
2323
2317
  const h = document.getSelection();
2324
- h != null && h.isCollapsed || ((!c || c.selector.length === 0) && b(x), g(), i.userSelect(c.annotation, At(x)));
2325
- }, E = (x) => {
2326
- m && x.key === "Shift" && c && (document.getSelection().isCollapsed || (i.clear(), g(), i.userSelect(c.annotation, ut(x))));
2327
- }, O = (x) => {
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) => {
2328
2322
  const h = () => setTimeout(() => {
2329
2323
  (c == null ? void 0 : c.selector.length) > 0 && (i.clear(), o.addAnnotation({
2330
2324
  id: c.annotation,
2331
2325
  bodies: [],
2332
2326
  target: c
2333
- }), i.userSelect(c.annotation, ut(x))), document.removeEventListener("selectionchange", h);
2327
+ }), i.userSelect(c.annotation, ut(A))), document.removeEventListener("selectionchange", h);
2334
2328
  }, 100);
2335
- document.addEventListener("selectionchange", h), w(x);
2329
+ document.addEventListener("selectionchange", h), v(A);
2336
2330
  };
2337
- P(Lo.join(","), { element: t, keydown: !0, keyup: !1 }, (x) => {
2338
- x.repeat || (d = ut(x));
2339
- }), P(Le, { keydown: !0, keyup: !1 }, (x) => {
2340
- d = ut(x), O(x);
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);
2341
2335
  });
2342
- const R = (x) => {
2343
- x.repeat || x.target !== t && x.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);
2344
2352
  };
2345
- return P(Ce.join(","), { keydown: !0, keyup: !1 }, R), document.addEventListener("pointerdown", C), document.addEventListener("pointerup", u), document.addEventListener("contextmenu", S), t.addEventListener("keyup", E), 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), {
2346
2354
  destroy: () => {
2347
- 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", E), 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();
2348
2356
  },
2349
2357
  setFilter: l,
2350
2358
  setUser: r,
@@ -2367,7 +2375,7 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
2367
2375
  console.debug(`Using ${f} renderer`), n.style && d.setStyle(n.style);
2368
2376
  const m = Oo(t, o, n.offsetReferenceSelector);
2369
2377
  m.setUser(c), m.setAnnotatingEnabled(n.annotatingEnabled);
2370
- const p = Xn(o, a, n.adapter), w = () => c, b = (E) => {
2378
+ const p = Xn(o, a, n.adapter), v = () => c, b = (E) => {
2371
2379
  m.setAnnotatingEnabled(
2372
2380
  E === void 0 ? !0 : E
2373
2381
  );
@@ -2386,7 +2394,7 @@ const se = 300, Ce = ["up", "down", "left", "right"], Le = Be ? "⌘+a" : "ctrl+
2386
2394
  d.destroy(), m.destroy(), a.destroy();
2387
2395
  },
2388
2396
  element: t,
2389
- getUser: w,
2397
+ getUser: v,
2390
2398
  setAnnotatingEnabled: b,
2391
2399
  setFilter: C,
2392
2400
  setStyle: d.setStyle.bind(d),