@recogito/text-annotator 3.0.0-rc.50 → 3.0.0-rc.51

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.
@@ -145,7 +145,7 @@ const se = "not-annotatable", Z = `.${se}`, nt = (t) => {
145
145
  const s = _t(o).textContent, a = t.toString(), r = s.length || 0, l = r + a.length;
146
146
  return n ? { quote: a, start: r, end: l, range: t, offsetReference: i } : { quote: a, start: r, end: l, range: t };
147
147
  }, re = (t, e) => {
148
- var u, h;
148
+ var d, h;
149
149
  const { start: n, end: o } = t, i = t.offsetReference || e, s = document.createNodeIterator(
150
150
  e,
151
151
  NodeFilter.SHOW_TEXT,
@@ -161,7 +161,7 @@ const se = "not-annotatable", Z = `.${se}`, nt = (t) => {
161
161
  let f = !i;
162
162
  for (; l !== null; ) {
163
163
  if (f || (f = i == null ? void 0 : i.contains(l)), f) {
164
- const g = ((u = l.textContent) == null ? void 0 : u.length) || 0;
164
+ const g = ((d = l.textContent) == null ? void 0 : d.length) || 0;
165
165
  if (a + g > n) {
166
166
  r.setStart(l, n - a);
167
167
  break;
@@ -195,8 +195,8 @@ const se = "not-annotatable", Z = `.${se}`, nt = (t) => {
195
195
  return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ae(t.parentElement);
196
196
  }, De = (t, e) => (n) => {
197
197
  const o = typeof n == "string" ? n : n.id, i = (a) => {
198
- const r = s.getBoundingClientRect(), l = s.clientHeight, f = s.clientWidth, u = a.selector[0].range.getBoundingClientRect(), { width: h, height: g } = e.getAnnotationBounds(o), p = u.top - r.top, v = u.left - r.left, y = s.parentElement ? s.scrollTop : 0, m = s.parentElement ? s.scrollLeft : 0, d = p + y - (l - g) / 2, c = v + m - (f - h) / 2;
199
- s.scroll({ top: d, left: c, behavior: "smooth" });
198
+ const r = s.getBoundingClientRect(), l = s.clientHeight, f = s.clientWidth, d = a.selector[0].range.getBoundingClientRect(), { width: h, height: g } = e.getAnnotationBounds(o), p = d.top - r.top, A = d.left - r.left, y = s.parentElement ? s.scrollTop : 0, m = s.parentElement ? s.scrollLeft : 0, u = p + y - (l - g) / 2, c = A + m - (f - h) / 2;
199
+ s.scroll({ top: u, left: c, behavior: "smooth" });
200
200
  }, s = ae(t);
201
201
  if (s) {
202
202
  const a = e.getAnnotation(o), { range: r } = a.target.selector[0];
@@ -231,43 +231,43 @@ const se = "not-annotatable", Z = `.${se}`, nt = (t) => {
231
231
  }, Kt = (t, e, n, o) => {
232
232
  const { store: i, selection: s, hover: a } = e;
233
233
  let r, l, f;
234
- const u = $e(n), h = (E) => {
235
- const { x: R, y: w } = t.getBoundingClientRect(), A = i.getAt(E.clientX - R, E.clientY - w, l);
236
- A ? a.current !== A.id && (t.classList.add("hovered"), a.set(A.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
234
+ const d = $e(n), h = (O) => {
235
+ const { x: _, y: b } = t.getBoundingClientRect(), x = i.getAt(O.clientX - _, O.clientY - b, l);
236
+ x ? a.current !== x.id && (t.classList.add("hovered"), a.set(x.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
237
237
  };
238
238
  t.addEventListener("pointermove", h);
239
- const g = (E = !1) => {
239
+ const g = (O = !1) => {
240
240
  f && f.clear();
241
- const R = Pe(t), { minX: w, minY: A, maxX: x, maxY: C } = R, k = l ? i.getIntersecting(w, A, x, C).filter(({ annotation: Y }) => l(Y)) : i.getIntersecting(w, A, x, C), M = s.selected.map(({ id: Y }) => Y), D = k.map(({ annotation: Y, rects: Ee }) => {
242
- const Se = M.includes(Y.id), Ce = Y.id === a.current;
243
- return { annotation: Y, rects: Ee, state: { selected: Se, hover: Ce } };
241
+ const _ = Pe(t), { minX: b, minY: x, maxX: v, maxY: C } = _, B = l ? i.getIntersecting(b, x, v, C).filter(({ annotation: D }) => l(D)) : i.getIntersecting(b, x, v, C), M = s.selected.map(({ id: D }) => D), Y = B.map(({ annotation: D, rects: Ee }) => {
242
+ const Se = M.includes(D.id), Ce = D.id === a.current;
243
+ return { annotation: D, rects: Ee, state: { selected: Se, hover: Ce } };
244
244
  });
245
- o.redraw(D, R, r, f, E), setTimeout(() => u(k.map(({ annotation: Y }) => Y)), 1);
246
- }, p = (E) => {
247
- f = E, g();
248
- }, v = (E) => {
249
- r = E, g();
250
- }, y = (E) => {
251
- l = E, g(!1);
245
+ o.redraw(Y, _, r, f, O), setTimeout(() => d(B.map(({ annotation: D }) => D)), 1);
246
+ }, p = (O) => {
247
+ f = O, g();
248
+ }, A = (O) => {
249
+ r = O, g();
250
+ }, y = (O) => {
251
+ l = O, g(!1);
252
252
  }, m = () => g();
253
253
  i.observe(m);
254
- const d = s.subscribe(() => g()), c = () => g(!0);
254
+ const u = s.subscribe(() => g()), c = () => g(!0);
255
255
  document.addEventListener("scroll", c, { capture: !0, passive: !0 });
256
- const b = Vt(() => {
256
+ const w = Vt(() => {
257
257
  i.recalculatePositions(), f && f.reset(), g();
258
258
  });
259
- window.addEventListener("resize", b);
260
- const S = new ResizeObserver(b);
259
+ window.addEventListener("resize", w);
260
+ const S = new ResizeObserver(w);
261
261
  S.observe(t);
262
- const T = { attributes: !0, childList: !0, subtree: !0 }, L = new MutationObserver((E) => {
263
- E.every((w) => w.target === t || t.contains(w.target)) || g(!0);
262
+ const T = { attributes: !0, childList: !0, subtree: !0 }, L = new MutationObserver((O) => {
263
+ O.every((b) => b.target === t || t.contains(b.target)) || g(!0);
264
264
  });
265
265
  return L.observe(document.body, T), {
266
266
  destroy: () => {
267
- t.removeEventListener("pointermove", h), o.destroy(), i.unobserve(m), d(), document.removeEventListener("scroll", c), window.removeEventListener("resize", b), S.disconnect(), L.disconnect();
267
+ t.removeEventListener("pointermove", h), o.destroy(), i.unobserve(m), u(), document.removeEventListener("scroll", c), window.removeEventListener("resize", w), S.disconnect(), L.disconnect();
268
268
  },
269
269
  redraw: g,
270
- setStyle: v,
270
+ setStyle: A,
271
271
  setFilter: y,
272
272
  setPainter: p,
273
273
  setVisible: o.setVisible
@@ -281,28 +281,28 @@ const se = "not-annotatable", Z = `.${se}`, nt = (t) => {
281
281
  t.classList.add("r6o-annotatable");
282
282
  const e = He(), n = e.getContext("2d");
283
283
  document.body.appendChild(e);
284
- const o = (r, l, f, u) => requestAnimationFrame(() => {
284
+ const o = (r, l, f, d) => requestAnimationFrame(() => {
285
285
  const { width: h, height: g } = e;
286
- n.clearRect(-0.5, -0.5, h + 1, g + 1), u && u.clear();
287
- const { top: p, left: v } = l;
288
- [...r].sort((m, d) => {
289
- const { annotation: { target: { created: c } } } = m, { annotation: { target: { created: b } } } = d;
290
- return c.getTime() - b.getTime();
286
+ n.clearRect(-0.5, -0.5, h + 1, g + 1), d && d.clear();
287
+ const { top: p, left: A } = l;
288
+ [...r].sort((m, u) => {
289
+ const { annotation: { target: { created: c } } } = m, { annotation: { target: { created: w } } } = u;
290
+ return c.getTime() - w.getTime();
291
291
  }).forEach((m) => {
292
292
  var S;
293
- const d = f ? typeof f == "function" ? f(m.annotation, m.state) : f : (S = m.state) != null && S.selected ? bt : W, c = u && u.paint(m, l) || d, b = m.rects.map(({ x: T, y: L, width: O, height: E }) => ({
294
- x: T + v,
293
+ const u = f ? typeof f == "function" ? f(m.annotation, m.state) : f : (S = m.state) != null && S.selected ? bt : W, c = d && d.paint(m, l) || u, w = m.rects.map(({ x: T, y: L, width: E, height: O }) => ({
294
+ x: T + A,
295
295
  y: L + p,
296
- width: O,
297
- height: E
296
+ width: E,
297
+ height: O
298
298
  }));
299
- if (n.fillStyle = c.fill, n.globalAlpha = c.fillOpacity || 1, b.forEach(
300
- ({ x: T, y: L, width: O, height: E }) => n.fillRect(T, L, O, E)
299
+ if (n.fillStyle = c.fill, n.globalAlpha = c.fillOpacity || 1, w.forEach(
300
+ ({ x: T, y: L, width: E, height: O }) => n.fillRect(T, L, E, O)
301
301
  ), c.underlineColor) {
302
302
  n.globalAlpha = 1, n.strokeStyle = c.underlineColor, n.lineWidth = c.underlineThickness ?? 1;
303
303
  const T = c.underlineOffset ?? 0;
304
- b.forEach(({ x: L, y: O, width: E, height: R }) => {
305
- n.beginPath(), n.moveTo(L, O + R + T), n.lineTo(L + E, O + R + T), n.stroke();
304
+ w.forEach(({ x: L, y: E, width: O, height: _ }) => {
305
+ n.beginPath(), n.moveTo(L, E + _ + T), n.lineTo(L + O, E + _ + T), n.stroke();
306
306
  });
307
307
  }
308
308
  });
@@ -470,14 +470,14 @@ const en = (t) => [
470
470
  l && l.clear();
471
471
  const f = new Set(s.map((h) => h.annotation.id));
472
472
  Array.from(e).filter((h) => !f.has(h));
473
- const u = s.map((h) => {
474
- var v;
475
- const g = r ? typeof r == "function" ? r(h.annotation, h.state) : r : (v = h.state) != null && v.selected ? bt : W, p = l && l.paint(h, a) || g;
473
+ const d = s.map((h) => {
474
+ var A;
475
+ const g = r ? typeof r == "function" ? r(h.annotation, h.state) : r : (A = h.state) != null && A.selected ? bt : W, p = l && l.paint(h, a) || g;
476
476
  return `::highlight(_${h.annotation.id}) { ${en(p)} }`;
477
477
  });
478
- t.innerHTML = u.join(`
478
+ t.innerHTML = d.join(`
479
479
  `), CSS.highlights.clear(), s.forEach(({ annotation: h }) => {
480
- const g = h.target.selector.map((v) => v.range), p = new Highlight(...g);
480
+ const g = h.target.selector.map((A) => A.range), p = new Highlight(...g);
481
481
  CSS.highlights.set(`_${h.id}`, p);
482
482
  }), e = f;
483
483
  }
@@ -516,18 +516,18 @@ const sn = (t, e) => {
516
516
  destroy: () => {
517
517
  e.remove();
518
518
  },
519
- redraw: (a, r, l, f, u) => {
520
- const g = !(Nt(n, a) && u);
519
+ redraw: (a, r, l, f, d) => {
520
+ const g = !(Nt(n, a) && d);
521
521
  if (!f && !g) return;
522
- g && (e.innerHTML = ""), [...a].sort((v, y) => {
523
- const { annotation: { target: { created: m } } } = v, { annotation: { target: { created: d } } } = y;
524
- return m && d ? m.getTime() - d.getTime() : 0;
525
- }).forEach((v) => {
526
- v.rects.map((y) => {
527
- const m = sn(y, a), d = Xe(v, r, l, f, m);
522
+ g && (e.innerHTML = ""), [...a].sort((A, y) => {
523
+ const { annotation: { target: { created: m } } } = A, { annotation: { target: { created: u } } } = y;
524
+ return m && u ? m.getTime() - u.getTime() : 0;
525
+ }).forEach((A) => {
526
+ A.rects.map((y) => {
527
+ const m = sn(y, a), u = Xe(A, r, l, f, m);
528
528
  if (g) {
529
529
  const c = document.createElement("span");
530
- c.className = "r6o-annotation", c.dataset.annotation = v.annotation.id, c.style.left = `${y.x}px`, c.style.top = `${y.y}px`, c.style.width = `${y.width}px`, c.style.height = `${y.height}px`, c.style.backgroundColor = $((d == null ? void 0 : d.fill) || W.fill).alpha((d == null ? void 0 : d.fillOpacity) === void 0 ? W.fillOpacity : d.fillOpacity).toHex(), d.underlineStyle && (c.style.borderStyle = d.underlineStyle), d.underlineColor && (c.style.borderColor = d.underlineColor), d.underlineThickness && (c.style.borderBottomWidth = `${d.underlineThickness}px`), d.underlineOffset && (c.style.paddingBottom = `${d.underlineOffset}px`), e.appendChild(c);
530
+ c.className = "r6o-annotation", c.dataset.annotation = A.annotation.id, c.style.left = `${y.x}px`, c.style.top = `${y.y}px`, c.style.width = `${y.width}px`, c.style.height = `${y.height}px`, c.style.backgroundColor = $((u == null ? void 0 : u.fill) || W.fill).alpha((u == null ? void 0 : u.fillOpacity) === void 0 ? W.fillOpacity : u.fillOpacity).toHex(), u.underlineStyle && (c.style.borderStyle = u.underlineStyle), u.underlineColor && (c.style.borderColor = u.underlineColor), u.underlineThickness && (c.style.borderBottomWidth = `${u.underlineThickness}px`), u.underlineOffset && (c.style.paddingBottom = `${u.underlineOffset}px`), e.appendChild(c);
531
531
  }
532
532
  });
533
533
  }), n = a;
@@ -634,49 +634,49 @@ var pn = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE =
634
634
  const ft = { selected: [] }, gn = (t, e, n) => {
635
635
  const { subscribe: o, set: i } = Yt(ft);
636
636
  let s = e, a = ft;
637
- o((v) => a = v);
637
+ o((A) => a = A);
638
638
  const r = () => {
639
639
  q(a, ft) || i(ft);
640
640
  }, l = () => {
641
- var v;
642
- return ((v = a.selected) == null ? void 0 : v.length) === 0;
643
- }, f = (v) => {
641
+ var A;
642
+ return ((A = a.selected) == null ? void 0 : A.length) === 0;
643
+ }, f = (A) => {
644
644
  if (l())
645
645
  return !1;
646
- const y = typeof v == "string" ? v : v.id;
646
+ const y = typeof A == "string" ? A : A.id;
647
647
  return a.selected.some((m) => m.id === y);
648
- }, u = (v, y) => {
649
- const m = t.getAnnotation(v);
648
+ }, d = (A, y) => {
649
+ const m = t.getAnnotation(A);
650
650
  if (!m) {
651
- console.warn("Invalid selection: " + v);
651
+ console.warn("Invalid selection: " + A);
652
652
  return;
653
653
  }
654
654
  switch (Jt(m, s)) {
655
655
  case "EDIT":
656
- i({ selected: [{ id: v, editable: !0 }], event: y });
656
+ i({ selected: [{ id: A, editable: !0 }], event: y });
657
657
  break;
658
658
  case "SELECT":
659
- i({ selected: [{ id: v }], event: y });
659
+ i({ selected: [{ id: A }], event: y });
660
660
  break;
661
661
  default:
662
662
  i({ selected: [], event: y });
663
663
  }
664
- }, h = (v, y) => {
665
- const m = Array.isArray(v) ? v : [v], d = m.map((c) => t.getAnnotation(c)).filter((c) => !!c);
664
+ }, h = (A, y) => {
665
+ const m = Array.isArray(A) ? A : [A], u = m.map((c) => t.getAnnotation(c)).filter((c) => !!c);
666
666
  i({
667
- selected: d.map((c) => {
668
- const b = y === void 0 ? Jt(c, s) === "EDIT" : y;
669
- return { id: c.id, editable: b };
667
+ selected: u.map((c) => {
668
+ const w = y === void 0 ? Jt(c, s) === "EDIT" : y;
669
+ return { id: c.id, editable: w };
670
670
  })
671
- }), d.length !== m.length && console.warn("Invalid selection", v);
672
- }, g = (v) => {
671
+ }), u.length !== m.length && console.warn("Invalid selection", A);
672
+ }, g = (A) => {
673
673
  if (l())
674
674
  return !1;
675
675
  const { selected: y } = a;
676
- y.some(({ id: m }) => v.includes(m)) && i({ selected: y.filter(({ id: m }) => !v.includes(m)) });
677
- }, p = (v) => s = v;
676
+ y.some(({ id: m }) => A.includes(m)) && i({ selected: y.filter(({ id: m }) => !A.includes(m)) });
677
+ }, p = (A) => s = A;
678
678
  return t.observe(
679
- ({ changes: v }) => g((v.deleted || []).map((y) => y.id))
679
+ ({ changes: A }) => g((A.deleted || []).map((y) => y.id))
680
680
  ), {
681
681
  get event() {
682
682
  return a ? a.event : null;
@@ -693,7 +693,7 @@ const ft = { selected: [] }, gn = (t, e, n) => {
693
693
  setSelected: h,
694
694
  setUserSelectAction: p,
695
695
  subscribe: o,
696
- userSelect: u
696
+ userSelect: d
697
697
  };
698
698
  }, Jt = (t, e, n) => typeof e == "function" ? e(t) : e || "EDIT";
699
699
  var V = [];
@@ -755,7 +755,7 @@ const Tt = (t) => {
755
755
  targetUpdated: En(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
756
756
  };
757
757
  };
758
- var B = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t.SILENT = "SILENT", t))(B || {});
758
+ var R = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t.SILENT = "SILENT", t))(R || {});
759
759
  const Sn = (t, e) => {
760
760
  var n, o;
761
761
  const { changes: i, origin: s } = e;
@@ -764,7 +764,7 @@ const Sn = (t, e) => {
764
764
  if (t.options.ignore) {
765
765
  const { ignore: a } = t.options, r = (l) => l && l.length > 0;
766
766
  if (!(r(i.created) || r(i.deleted))) {
767
- const l = (n = i.updated) == null ? void 0 : n.some((u) => r(u.bodiesCreated) || r(u.bodiesDeleted) || r(u.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((u) => u.targetUpdated);
767
+ const l = (n = i.updated) == null ? void 0 : n.some((d) => r(d.bodiesCreated) || r(d.bodiesDeleted) || r(d.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((d) => d.targetUpdated);
768
768
  if (a === "BODY_ONLY" && l && !f || a === "TARGET_ONLY" && f && !l)
769
769
  return !1;
770
770
  }
@@ -785,18 +785,18 @@ const Sn = (t, e) => {
785
785
  ], f = [
786
786
  ...(t.deleted || []).filter((h) => !i.has(h.id)),
787
787
  ...(e.deleted || []).filter((h) => !n.has(h.id))
788
- ], u = [
788
+ ], d = [
789
789
  ...(t.updated || []).filter(({ newValue: h }) => !s.has(h.id)).map((h) => {
790
790
  const { oldValue: g, newValue: p } = h;
791
791
  if (a.has(p.id)) {
792
- const v = e.updated.find((y) => y.oldValue.id === p.id).newValue;
793
- return he(g, v);
792
+ const A = e.updated.find((y) => y.oldValue.id === p.id).newValue;
793
+ return he(g, A);
794
794
  } else
795
795
  return h;
796
796
  }),
797
797
  ...(e.updated || []).filter(({ oldValue: h }) => !r.has(h.id))
798
798
  ];
799
- return { created: l, deleted: f, updated: u };
799
+ return { created: l, deleted: f, updated: d };
800
800
  }, Ot = (t) => {
801
801
  const e = t.id === void 0 ? fe() : t.id;
802
802
  return {
@@ -812,188 +812,188 @@ const Sn = (t, e) => {
812
812
  }
813
813
  };
814
814
  }, Ln = (t) => t.id !== void 0, Tn = () => {
815
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (w, A = {}) => {
816
- n.push({ onChange: w, options: A });
817
- }, i = (w) => {
818
- const A = n.findIndex((x) => x.onChange == w);
819
- A > -1 && n.splice(A, 1);
820
- }, s = (w, A) => {
821
- const x = {
822
- origin: w,
815
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b, x = {}) => {
816
+ n.push({ onChange: b, options: x });
817
+ }, i = (b) => {
818
+ const x = n.findIndex((v) => v.onChange == b);
819
+ x > -1 && n.splice(x, 1);
820
+ }, s = (b, x) => {
821
+ const v = {
822
+ origin: b,
823
823
  changes: {
824
- created: A.created || [],
825
- updated: A.updated || [],
826
- deleted: A.deleted || []
824
+ created: x.created || [],
825
+ updated: x.updated || [],
826
+ deleted: x.deleted || []
827
827
  },
828
828
  state: [...t.values()]
829
829
  };
830
830
  n.forEach((C) => {
831
- Sn(C, x) && C.onChange(x);
831
+ Sn(C, v) && C.onChange(v);
832
832
  });
833
- }, a = (w, A = B.LOCAL) => {
834
- if (w.id && t.get(w.id))
835
- throw Error(`Cannot add annotation ${w.id} - exists already`);
833
+ }, a = (b, x = R.LOCAL) => {
834
+ if (b.id && t.get(b.id))
835
+ throw Error(`Cannot add annotation ${b.id} - exists already`);
836
836
  {
837
- const x = Ot(w);
838
- t.set(x.id, x), x.bodies.forEach((C) => e.set(C.id, x.id)), s(A, { created: [x] });
837
+ const v = Ot(b);
838
+ t.set(v.id, v), v.bodies.forEach((C) => e.set(C.id, v.id)), s(x, { created: [v] });
839
839
  }
840
- }, r = (w, A) => {
841
- const x = Ot(typeof w == "string" ? A : w), C = typeof w == "string" ? w : w.id, k = C && t.get(C);
842
- if (k) {
843
- const M = he(k, x);
844
- return C === x.id ? t.set(C, x) : (t.delete(C), t.set(x.id, x)), k.bodies.forEach((D) => e.delete(D.id)), x.bodies.forEach((D) => e.set(D.id, x.id)), M;
840
+ }, r = (b, x) => {
841
+ const v = Ot(typeof b == "string" ? x : b), C = typeof b == "string" ? b : b.id, B = C && t.get(C);
842
+ if (B) {
843
+ const M = he(B, v);
844
+ return C === v.id ? t.set(C, v) : (t.delete(C), t.set(v.id, v)), B.bodies.forEach((Y) => e.delete(Y.id)), v.bodies.forEach((Y) => e.set(Y.id, v.id)), M;
845
845
  } else
846
846
  console.warn(`Cannot update annotation ${C} - does not exist`);
847
- }, l = (w, A = B.LOCAL, x = B.LOCAL) => {
848
- const C = Ln(A) ? x : A, k = r(w, A);
849
- k && s(C, { updated: [k] });
850
- }, f = (w, A = B.LOCAL) => {
851
- const x = w.reduce((C, k) => {
852
- const M = r(k);
847
+ }, l = (b, x = R.LOCAL, v = R.LOCAL) => {
848
+ const C = Ln(x) ? v : x, B = r(b, x);
849
+ B && s(C, { updated: [B] });
850
+ }, f = (b, x = R.LOCAL) => {
851
+ const v = b.reduce((C, B) => {
852
+ const M = r(B);
853
853
  return M ? [...C, M] : C;
854
854
  }, []);
855
- x.length > 0 && s(A, { updated: x });
856
- }, u = (w, A = B.LOCAL) => {
857
- const x = t.get(w.annotation);
858
- if (x) {
855
+ v.length > 0 && s(x, { updated: v });
856
+ }, d = (b, x = R.LOCAL) => {
857
+ const v = t.get(b.annotation);
858
+ if (v) {
859
859
  const C = {
860
- ...x,
861
- bodies: [...x.bodies, w]
860
+ ...v,
861
+ bodies: [...v.bodies, b]
862
862
  };
863
- t.set(x.id, C), e.set(w.id, C.id), s(A, { updated: [{
864
- oldValue: x,
863
+ t.set(v.id, C), e.set(b.id, C.id), s(x, { updated: [{
864
+ oldValue: v,
865
865
  newValue: C,
866
- bodiesCreated: [w]
866
+ bodiesCreated: [b]
867
867
  }] });
868
868
  } else
869
- console.warn(`Attempt to add body to missing annotation: ${w.annotation}`);
870
- }, h = () => [...t.values()], g = (w = B.LOCAL) => {
871
- const A = [...t.values()];
872
- t.clear(), e.clear(), s(w, { deleted: A });
873
- }, p = (w, A = !0, x = B.LOCAL) => {
874
- const C = w.map(Ot);
875
- if (A) {
876
- const k = [...t.values()];
869
+ console.warn(`Attempt to add body to missing annotation: ${b.annotation}`);
870
+ }, h = () => [...t.values()], g = (b = R.LOCAL) => {
871
+ const x = [...t.values()];
872
+ t.clear(), e.clear(), s(b, { deleted: x });
873
+ }, p = (b, x = !0, v = R.LOCAL) => {
874
+ const C = b.map(Ot);
875
+ if (x) {
876
+ const B = [...t.values()];
877
877
  t.clear(), e.clear(), C.forEach((M) => {
878
- t.set(M.id, M), M.bodies.forEach((D) => e.set(D.id, M.id));
879
- }), s(x, { created: C, deleted: k });
878
+ t.set(M.id, M), M.bodies.forEach((Y) => e.set(Y.id, M.id));
879
+ }), s(v, { created: C, deleted: B });
880
880
  } else {
881
- const k = w.reduce((M, D) => {
882
- const Y = D.id && t.get(D.id);
883
- return Y ? [...M, Y] : M;
881
+ const B = b.reduce((M, Y) => {
882
+ const D = Y.id && t.get(Y.id);
883
+ return D ? [...M, D] : M;
884
884
  }, []);
885
- if (k.length > 0)
886
- throw Error(`Bulk insert would overwrite the following annotations: ${k.map((M) => M.id).join(", ")}`);
885
+ if (B.length > 0)
886
+ throw Error(`Bulk insert would overwrite the following annotations: ${B.map((M) => M.id).join(", ")}`);
887
887
  C.forEach((M) => {
888
- t.set(M.id, M), M.bodies.forEach((D) => e.set(D.id, M.id));
889
- }), s(x, { created: C });
888
+ t.set(M.id, M), M.bodies.forEach((Y) => e.set(Y.id, M.id));
889
+ }), s(v, { created: C });
890
890
  }
891
- }, v = (w) => {
892
- const A = typeof w == "string" ? w : w.id, x = t.get(A);
893
- if (x)
894
- return t.delete(A), x.bodies.forEach((C) => e.delete(C.id)), x;
895
- console.warn(`Attempt to delete missing annotation: ${A}`);
896
- }, y = (w, A = B.LOCAL) => {
897
- const x = v(w);
898
- x && s(A, { deleted: [x] });
899
- }, m = (w, A = B.LOCAL) => {
900
- const x = w.reduce((C, k) => {
901
- const M = v(k);
891
+ }, A = (b) => {
892
+ const x = typeof b == "string" ? b : b.id, v = t.get(x);
893
+ if (v)
894
+ return t.delete(x), v.bodies.forEach((C) => e.delete(C.id)), v;
895
+ console.warn(`Attempt to delete missing annotation: ${x}`);
896
+ }, y = (b, x = R.LOCAL) => {
897
+ const v = A(b);
898
+ v && s(x, { deleted: [v] });
899
+ }, m = (b, x = R.LOCAL) => {
900
+ const v = b.reduce((C, B) => {
901
+ const M = A(B);
902
902
  return M ? [...C, M] : C;
903
903
  }, []);
904
- x.length > 0 && s(A, { deleted: x });
905
- }, d = (w) => {
906
- const A = t.get(w.annotation);
907
- if (A) {
908
- const x = A.bodies.find((C) => C.id === w.id);
909
- if (x) {
910
- e.delete(x.id);
904
+ v.length > 0 && s(x, { deleted: v });
905
+ }, u = (b) => {
906
+ const x = t.get(b.annotation);
907
+ if (x) {
908
+ const v = x.bodies.find((C) => C.id === b.id);
909
+ if (v) {
910
+ e.delete(v.id);
911
911
  const C = {
912
- ...A,
913
- bodies: A.bodies.filter((k) => k.id !== w.id)
912
+ ...x,
913
+ bodies: x.bodies.filter((B) => B.id !== b.id)
914
914
  };
915
- return t.set(A.id, C), {
916
- oldValue: A,
915
+ return t.set(x.id, C), {
916
+ oldValue: x,
917
917
  newValue: C,
918
- bodiesDeleted: [x]
918
+ bodiesDeleted: [v]
919
919
  };
920
920
  } else
921
- console.warn(`Attempt to delete missing body ${w.id} from annotation ${w.annotation}`);
921
+ console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`);
922
922
  } else
923
- console.warn(`Attempt to delete body from missing annotation ${w.annotation}`);
924
- }, c = (w, A = B.LOCAL) => {
925
- const x = d(w);
926
- x && s(A, { updated: [x] });
927
- }, b = (w, A = B.LOCAL) => {
928
- const x = w.map((C) => d(C)).filter(Boolean);
929
- x.length > 0 && s(A, { updated: x });
930
- }, S = (w) => {
931
- const A = t.get(w);
932
- return A ? { ...A } : void 0;
933
- }, T = (w) => {
934
- const A = e.get(w);
935
- if (A) {
936
- const x = S(A).bodies.find((C) => C.id === w);
937
- if (x)
938
- return x;
939
- console.error(`Store integrity error: body ${w} in index, but not in annotation`);
923
+ console.warn(`Attempt to delete body from missing annotation ${b.annotation}`);
924
+ }, c = (b, x = R.LOCAL) => {
925
+ const v = u(b);
926
+ v && s(x, { updated: [v] });
927
+ }, w = (b, x = R.LOCAL) => {
928
+ const v = b.map((C) => u(C)).filter(Boolean);
929
+ v.length > 0 && s(x, { updated: v });
930
+ }, S = (b) => {
931
+ const x = t.get(b);
932
+ return x ? { ...x } : void 0;
933
+ }, T = (b) => {
934
+ const x = e.get(b);
935
+ if (x) {
936
+ const v = S(x).bodies.find((C) => C.id === b);
937
+ if (v)
938
+ return v;
939
+ console.error(`Store integrity error: body ${b} in index, but not in annotation`);
940
940
  } else
941
- console.warn(`Attempt to retrieve missing body: ${w}`);
942
- }, L = (w, A) => {
943
- if (w.annotation !== A.annotation)
941
+ console.warn(`Attempt to retrieve missing body: ${b}`);
942
+ }, L = (b, x) => {
943
+ if (b.annotation !== x.annotation)
944
944
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
945
- const x = t.get(w.annotation);
946
- if (x) {
947
- const C = x.bodies.find((M) => M.id === w.id), k = {
948
- ...x,
949
- bodies: x.bodies.map((M) => M.id === C.id ? A : M)
945
+ const v = t.get(b.annotation);
946
+ if (v) {
947
+ const C = v.bodies.find((M) => M.id === b.id), B = {
948
+ ...v,
949
+ bodies: v.bodies.map((M) => M.id === C.id ? x : M)
950
950
  };
951
- return t.set(x.id, k), C.id !== A.id && (e.delete(C.id), e.set(A.id, k.id)), {
952
- oldValue: x,
953
- newValue: k,
954
- bodiesUpdated: [{ oldBody: C, newBody: A }]
951
+ return t.set(v.id, B), C.id !== x.id && (e.delete(C.id), e.set(x.id, B.id)), {
952
+ oldValue: v,
953
+ newValue: B,
954
+ bodiesUpdated: [{ oldBody: C, newBody: x }]
955
955
  };
956
956
  } else
957
- console.warn(`Attempt to add body to missing annotation ${w.annotation}`);
958
- }, O = (w, A, x = B.LOCAL) => {
959
- const C = L(w, A);
960
- C && s(x, { updated: [C] });
961
- }, E = (w, A = B.LOCAL) => {
962
- const x = w.map((C) => L({ id: C.id, annotation: C.annotation }, C)).filter(Boolean);
963
- s(A, { updated: x });
964
- }, R = (w) => {
965
- const A = t.get(w.annotation);
966
- if (A) {
967
- const x = {
968
- ...A,
957
+ console.warn(`Attempt to add body to missing annotation ${b.annotation}`);
958
+ }, E = (b, x, v = R.LOCAL) => {
959
+ const C = L(b, x);
960
+ C && s(v, { updated: [C] });
961
+ }, O = (b, x = R.LOCAL) => {
962
+ const v = b.map((C) => L({ id: C.id, annotation: C.annotation }, C)).filter(Boolean);
963
+ s(x, { updated: v });
964
+ }, _ = (b) => {
965
+ const x = t.get(b.annotation);
966
+ if (x) {
967
+ const v = {
968
+ ...x,
969
969
  target: {
970
- ...A.target,
971
- ...w
970
+ ...x.target,
971
+ ...b
972
972
  }
973
973
  };
974
- return t.set(A.id, x), {
975
- oldValue: A,
976
- newValue: x,
974
+ return t.set(x.id, v), {
975
+ oldValue: x,
976
+ newValue: v,
977
977
  targetUpdated: {
978
- oldTarget: A.target,
979
- newTarget: w
978
+ oldTarget: x.target,
979
+ newTarget: b
980
980
  }
981
981
  };
982
982
  } else
983
- console.warn(`Attempt to update target on missing annotation: ${w.annotation}`);
983
+ console.warn(`Attempt to update target on missing annotation: ${b.annotation}`);
984
984
  };
985
985
  return {
986
986
  addAnnotation: a,
987
- addBody: u,
987
+ addBody: d,
988
988
  all: h,
989
989
  bulkAddAnnotation: p,
990
990
  bulkDeleteAnnotation: m,
991
- bulkDeleteBodies: b,
991
+ bulkDeleteBodies: w,
992
992
  bulkUpdateAnnotation: f,
993
- bulkUpdateBodies: E,
994
- bulkUpdateTargets: (w, A = B.LOCAL) => {
995
- const x = w.map((C) => R(C)).filter(Boolean);
996
- x.length > 0 && s(A, { updated: x });
993
+ bulkUpdateBodies: O,
994
+ bulkUpdateTargets: (b, x = R.LOCAL) => {
995
+ const v = b.map((C) => _(C)).filter(Boolean);
996
+ v.length > 0 && s(x, { updated: v });
997
997
  },
998
998
  clear: g,
999
999
  deleteAnnotation: y,
@@ -1003,10 +1003,10 @@ const Sn = (t, e) => {
1003
1003
  observe: o,
1004
1004
  unobserve: i,
1005
1005
  updateAnnotation: l,
1006
- updateBody: O,
1007
- updateTarget: (w, A = B.LOCAL) => {
1008
- const x = R(w);
1009
- x && s(A, { updated: [x] });
1006
+ updateBody: E,
1007
+ updateTarget: (b, x = R.LOCAL) => {
1008
+ const v = _(b);
1009
+ v && s(x, { updated: [v] });
1010
1010
  }
1011
1011
  };
1012
1012
  };
@@ -1029,36 +1029,36 @@ const Mn = 250, Rn = (t) => {
1029
1029
  let o = -1, i = !1, s = 0;
1030
1030
  const a = (p) => {
1031
1031
  if (!i) {
1032
- const { changes: v } = p, y = performance.now();
1032
+ const { changes: A } = p, y = performance.now();
1033
1033
  if (y - s > Mn)
1034
- n.splice(o + 1), n.push(v), o = n.length - 1;
1034
+ n.splice(o + 1), n.push(A), o = n.length - 1;
1035
1035
  else {
1036
1036
  const m = n.length - 1;
1037
- n[m] = Cn(n[m], v);
1037
+ n[m] = Cn(n[m], A);
1038
1038
  }
1039
1039
  s = y;
1040
1040
  }
1041
1041
  i = !1;
1042
1042
  };
1043
- t.observe(a, { origin: B.LOCAL });
1044
- const r = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), l = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), f = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue: v }) => v)), u = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: v }) => v)), h = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), g = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p);
1043
+ t.observe(a, { origin: R.LOCAL });
1044
+ const r = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), l = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), f = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue: A }) => A)), d = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: A }) => A)), h = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), g = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p);
1045
1045
  return {
1046
1046
  canRedo: () => n.length - 1 > o,
1047
1047
  canUndo: () => o > -1,
1048
1048
  destroy: () => t.unobserve(a),
1049
- on: (p, v) => e.on(p, v),
1049
+ on: (p, A) => e.on(p, A),
1050
1050
  redo: () => {
1051
1051
  if (n.length - 1 > o) {
1052
1052
  i = !0;
1053
- const { created: p, updated: v, deleted: y } = n[o + 1];
1054
- l(p), u(v), g(y), e.emit("redo", n[o + 1]), o += 1;
1053
+ const { created: p, updated: A, deleted: y } = n[o + 1];
1054
+ l(p), d(A), g(y), e.emit("redo", n[o + 1]), o += 1;
1055
1055
  }
1056
1056
  },
1057
1057
  undo: () => {
1058
1058
  if (o > -1) {
1059
1059
  i = !0;
1060
- const { created: p, updated: v, deleted: y } = n[o];
1061
- r(p), f(v), h(y), e.emit("undo", n[o]), o -= 1;
1060
+ const { created: p, updated: A, deleted: y } = n[o];
1061
+ r(p), f(A), h(y), e.emit("undo", n[o]), o -= 1;
1062
1062
  }
1063
1063
  }
1064
1064
  };
@@ -1070,23 +1070,23 @@ const Mn = 250, Rn = (t) => {
1070
1070
  };
1071
1071
  }, kn = (t, e, n, o) => {
1072
1072
  const { hover: i, selection: s, store: a, viewport: r } = t, l = /* @__PURE__ */ new Map();
1073
- let f = [], u;
1073
+ let f = [], d;
1074
1074
  const h = (y, m) => {
1075
1075
  l.has(y) ? l.get(y).push(m) : l.set(y, [m]);
1076
1076
  }, g = (y, m) => {
1077
- const d = l.get(y);
1078
- if (d) {
1079
- const c = d.indexOf(m);
1080
- c !== -1 && d.splice(c, 1);
1077
+ const u = l.get(y);
1078
+ if (u) {
1079
+ const c = u.indexOf(m);
1080
+ c !== -1 && u.splice(c, 1);
1081
1081
  }
1082
- }, p = (y, m, d) => {
1082
+ }, p = (y, m, u) => {
1083
1083
  l.has(y) && setTimeout(() => {
1084
1084
  l.get(y).forEach((c) => {
1085
1085
  if (n) {
1086
- const b = Array.isArray(m) ? m.map((T) => n.serialize(T)) : n.serialize(m), S = d ? d instanceof PointerEvent ? d : n.serialize(d) : void 0;
1087
- c(b, S);
1086
+ const w = Array.isArray(m) ? m.map((T) => n.serialize(T)) : n.serialize(m), S = u ? u instanceof PointerEvent ? u : n.serialize(u) : void 0;
1087
+ c(w, S);
1088
1088
  } else
1089
- c(m, d);
1089
+ c(m, u);
1090
1090
  });
1091
1091
  }, 1);
1092
1092
  };
@@ -1096,17 +1096,17 @@ const Mn = 250, Rn = (t) => {
1096
1096
  f = y.map(({ id: m }) => a.getAnnotation(m));
1097
1097
  else if (f.length > 0 && y.length === 0)
1098
1098
  f.forEach((m) => {
1099
- const d = a.getAnnotation(m.id);
1100
- d && !q(d, m) && p("updateAnnotation", d, m);
1099
+ const u = a.getAnnotation(m.id);
1100
+ u && !q(u, m) && p("updateAnnotation", u, m);
1101
1101
  }), f = [];
1102
1102
  else {
1103
- const m = new Set(f.map((c) => c.id)), d = new Set(y.map(({ id: c }) => c));
1104
- f.filter((c) => !d.has(c.id)).forEach((c) => {
1105
- const b = a.getAnnotation(c.id);
1106
- b && !q(b, c) && p("updateAnnotation", b, c);
1103
+ const m = new Set(f.map((c) => c.id)), u = new Set(y.map(({ id: c }) => c));
1104
+ f.filter((c) => !u.has(c.id)).forEach((c) => {
1105
+ const w = a.getAnnotation(c.id);
1106
+ w && !q(w, c) && p("updateAnnotation", w, c);
1107
1107
  }), f = [
1108
1108
  // Remove annotations that were deselected
1109
- ...f.filter((c) => d.has(c.id)),
1109
+ ...f.filter((c) => u.has(c.id)),
1110
1110
  // Add editable annotations that were selected
1111
1111
  ...y.filter(({ id: c }) => !m.has(c)).map(({ id: c }) => a.getAnnotation(c))
1112
1112
  ];
@@ -1114,28 +1114,28 @@ const Mn = 250, Rn = (t) => {
1114
1114
  p("selectionChanged", f);
1115
1115
  }
1116
1116
  }), i.subscribe((y) => {
1117
- !u && y ? p("mouseEnterAnnotation", a.getAnnotation(y)) : u && !y ? p("mouseLeaveAnnotation", a.getAnnotation(u)) : u && y && (p("mouseLeaveAnnotation", a.getAnnotation(u)), p("mouseEnterAnnotation", a.getAnnotation(y))), u = y;
1117
+ !d && y ? p("mouseEnterAnnotation", a.getAnnotation(y)) : d && !y ? p("mouseLeaveAnnotation", a.getAnnotation(d)) : d && y && (p("mouseLeaveAnnotation", a.getAnnotation(d)), p("mouseEnterAnnotation", a.getAnnotation(y))), d = y;
1118
1118
  }), r == null || r.subscribe((y) => p("viewportIntersect", y.map((m) => a.getAnnotation(m)))), a.observe((y) => {
1119
- const { created: m, deleted: d } = y.changes;
1120
- (m || []).forEach((c) => p("createAnnotation", c)), (d || []).forEach((c) => p("deleteAnnotation", c)), (y.changes.updated || []).filter((c) => [
1119
+ const { created: m, deleted: u } = y.changes;
1120
+ (m || []).forEach((c) => p("createAnnotation", c)), (u || []).forEach((c) => p("deleteAnnotation", c)), (y.changes.updated || []).filter((c) => [
1121
1121
  ...c.bodiesCreated || [],
1122
1122
  ...c.bodiesDeleted || [],
1123
1123
  ...c.bodiesUpdated || []
1124
- ].length > 0).forEach(({ oldValue: c, newValue: b }) => {
1124
+ ].length > 0).forEach(({ oldValue: c, newValue: w }) => {
1125
1125
  const S = f.find((T) => T.id === c.id) || c;
1126
- f = f.map((T) => T.id === c.id ? b : T), p("updateAnnotation", b, S);
1126
+ f = f.map((T) => T.id === c.id ? w : T), p("updateAnnotation", w, S);
1127
1127
  });
1128
- }, { origin: B.LOCAL }), a.observe((y) => {
1128
+ }, { origin: R.LOCAL }), a.observe((y) => {
1129
1129
  if (f) {
1130
- const m = new Set(f.map((c) => c.id)), d = (y.changes.updated || []).filter(({ newValue: c }) => m.has(c.id)).map(({ newValue: c }) => c);
1131
- d.length > 0 && (f = f.map((c) => d.find((S) => S.id === c.id) || c));
1130
+ const m = new Set(f.map((c) => c.id)), u = (y.changes.updated || []).filter(({ newValue: c }) => m.has(c.id)).map(({ newValue: c }) => c);
1131
+ u.length > 0 && (f = f.map((c) => u.find((S) => S.id === c.id) || c));
1132
1132
  }
1133
- }, { origin: B.REMOTE });
1134
- const v = (y) => (m) => {
1135
- const { updated: d } = m;
1136
- y ? (d || []).forEach((c) => p("updateAnnotation", c.oldValue, c.newValue)) : (d || []).forEach((c) => p("updateAnnotation", c.newValue, c.oldValue));
1133
+ }, { origin: R.REMOTE });
1134
+ const A = (y) => (m) => {
1135
+ const { updated: u } = m;
1136
+ y ? (u || []).forEach((c) => p("updateAnnotation", c.oldValue, c.newValue)) : (u || []).forEach((c) => p("updateAnnotation", c.newValue, c.oldValue));
1137
1137
  };
1138
- return e.on("undo", v(!0)), e.on("redo", v(!1)), { on: h, off: g, emit: p };
1138
+ return e.on("undo", A(!0)), e.on("redo", A(!1)), { on: h, off: g, emit: p };
1139
1139
  }, In = (t) => (e) => e.reduce((n, o) => {
1140
1140
  const { parsed: i, error: s } = t.parse(o);
1141
1141
  return s ? {
@@ -1148,46 +1148,46 @@ const Mn = 250, Rn = (t) => {
1148
1148
  ...n
1149
1149
  };
1150
1150
  }, { parsed: [], failed: [] }), _n = (t, e, n) => {
1151
- const { store: o, selection: i } = t, s = (d) => {
1151
+ const { store: o, selection: i } = t, s = (u) => {
1152
1152
  if (n) {
1153
- const { parsed: c, error: b } = n.parse(d);
1154
- c ? o.addAnnotation(c, B.REMOTE) : console.error(b);
1153
+ const { parsed: c, error: w } = n.parse(u);
1154
+ c ? o.addAnnotation(c, R.REMOTE) : console.error(w);
1155
1155
  } else
1156
- o.addAnnotation(Tt(d), B.REMOTE);
1157
- }, a = () => i.clear(), r = () => o.clear(), l = (d) => {
1158
- const c = o.getAnnotation(d);
1156
+ o.addAnnotation(Tt(u), R.REMOTE);
1157
+ }, a = () => i.clear(), r = () => o.clear(), l = (u) => {
1158
+ const c = o.getAnnotation(u);
1159
1159
  return n && c ? n.serialize(c) : c;
1160
- }, f = () => n ? o.all().map(n.serialize) : o.all(), u = () => {
1161
- var d;
1162
- const c = (((d = i.selected) == null ? void 0 : d.map((b) => b.id)) || []).map((b) => o.getAnnotation(b)).filter(Boolean);
1160
+ }, f = () => n ? o.all().map(n.serialize) : o.all(), d = () => {
1161
+ var u;
1162
+ const c = (((u = i.selected) == null ? void 0 : u.map((w) => w.id)) || []).map((w) => o.getAnnotation(w)).filter(Boolean);
1163
1163
  return n ? c.map(n.serialize) : c;
1164
- }, h = (d, c = !0) => fetch(d).then((b) => b.json()).then((b) => (p(b, c), b)), g = (d) => {
1165
- if (typeof d == "string") {
1166
- const c = o.getAnnotation(d);
1167
- if (o.deleteAnnotation(d), c)
1164
+ }, h = (u, c = !0) => fetch(u).then((w) => w.json()).then((w) => (p(w, c), w)), g = (u) => {
1165
+ if (typeof u == "string") {
1166
+ const c = o.getAnnotation(u);
1167
+ if (o.deleteAnnotation(u), c)
1168
1168
  return n ? n.serialize(c) : c;
1169
1169
  } else {
1170
- const c = n ? n.parse(d).parsed : d;
1170
+ const c = n ? n.parse(u).parsed : u;
1171
1171
  if (c)
1172
- return o.deleteAnnotation(c), d;
1172
+ return o.deleteAnnotation(c), u;
1173
1173
  }
1174
- }, p = (d, c = !0) => {
1174
+ }, p = (u, c = !0) => {
1175
1175
  if (n) {
1176
- const b = n.parseAll || In(n), { parsed: S, failed: T } = b(d);
1177
- T.length > 0 && console.warn(`Discarded ${T.length} invalid annotations`, T), o.bulkAddAnnotation(S, c, B.REMOTE);
1176
+ const w = n.parseAll || In(n), { parsed: S, failed: T } = w(u);
1177
+ T.length > 0 && console.warn(`Discarded ${T.length} invalid annotations`, T), o.bulkAddAnnotation(S, c, R.REMOTE);
1178
1178
  } else
1179
- o.bulkAddAnnotation(d.map(Tt), c, B.REMOTE);
1180
- }, v = (d, c) => {
1181
- d ? i.setSelected(d, c) : i.clear();
1182
- }, y = (d) => {
1183
- i.clear(), i.setUserSelectAction(d);
1184
- }, m = (d) => {
1179
+ o.bulkAddAnnotation(u.map(Tt), c, R.REMOTE);
1180
+ }, A = (u, c) => {
1181
+ u ? i.setSelected(u, c) : i.clear();
1182
+ }, y = (u) => {
1183
+ i.clear(), i.setUserSelectAction(u);
1184
+ }, m = (u) => {
1185
1185
  if (n) {
1186
- const c = n.parse(d).parsed, b = n.serialize(o.getAnnotation(c.id));
1187
- return o.updateAnnotation(c), b;
1186
+ const c = n.parse(u).parsed, w = n.serialize(o.getAnnotation(c.id));
1187
+ return o.updateAnnotation(c), w;
1188
1188
  } else {
1189
- const c = o.getAnnotation(d.id);
1190
- return o.updateAnnotation(Tt(d)), c;
1189
+ const c = o.getAnnotation(u.id);
1190
+ return o.updateAnnotation(Tt(u)), c;
1191
1191
  }
1192
1192
  };
1193
1193
  return {
@@ -1198,12 +1198,12 @@ const Mn = 250, Rn = (t) => {
1198
1198
  clearAnnotations: r,
1199
1199
  getAnnotationById: l,
1200
1200
  getAnnotations: f,
1201
- getSelected: u,
1201
+ getSelected: d,
1202
1202
  loadAnnotations: h,
1203
1203
  redo: e.redo,
1204
1204
  removeAnnotation: g,
1205
1205
  setAnnotations: p,
1206
- setSelected: v,
1206
+ setSelected: A,
1207
1207
  setUserSelectAction: y,
1208
1208
  undo: e.undo,
1209
1209
  updateAnnotation: m
@@ -1234,7 +1234,7 @@ const Dn = () => ({ isGuest: !0, id: Kn("1234567890abcdefghijklmnopqrstuvwxyzABC
1234
1234
  }
1235
1235
  return `${n}`;
1236
1236
  }, pe = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Pn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1237
- const { id: o, type: i, purpose: s, value: a, created: r, modified: l, creator: f, ...u } = n;
1237
+ const { id: o, type: i, purpose: s, value: a, created: r, modified: l, creator: f, ...d } = n;
1238
1238
  return {
1239
1239
  id: o || `temp-${Xn(n)}`,
1240
1240
  annotation: e,
@@ -1244,7 +1244,7 @@ const Dn = () => ({ isGuest: !0, id: Kn("1234567890abcdefghijklmnopqrstuvwxyzABC
1244
1244
  creator: pe(f),
1245
1245
  created: r ? new Date(r) : void 0,
1246
1246
  updated: l ? new Date(l) : void 0,
1247
- ...u
1247
+ ...d
1248
1248
  };
1249
1249
  }), $n = (t) => t.map((e) => {
1250
1250
  var n;
@@ -1266,15 +1266,20 @@ const Ao = (t, e) => ({
1266
1266
  created: o,
1267
1267
  modified: i,
1268
1268
  target: s
1269
- } = t, a = Array.isArray(s) ? s : [s], r = {
1269
+ } = t, a = Array.isArray(s) ? s : [s];
1270
+ if (a.length === 0)
1271
+ return { error: Error(`No targets found for annotation: ${t.id}`) };
1272
+ const r = {
1270
1273
  creator: pe(n),
1271
1274
  created: o ? new Date(o) : void 0,
1272
1275
  updated: i ? new Date(i) : void 0,
1273
1276
  annotation: e,
1274
- selector: []
1277
+ selector: [],
1278
+ // @ts-expect-error: `styleClass` is not part of the core `TextAnnotationTarget` type
1279
+ styleClass: "styleClass" in a[0] ? a[0].styleClass : void 0
1275
1280
  };
1276
1281
  for (const l of a) {
1277
- const u = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((h, g) => {
1282
+ const d = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((h, g) => {
1278
1283
  switch (g.type) {
1279
1284
  case "TextQuoteSelector":
1280
1285
  h.quote = g.exact;
@@ -1285,12 +1290,19 @@ const Ao = (t, e) => ({
1285
1290
  }
1286
1291
  return h;
1287
1292
  }, {});
1288
- if (Hn(u))
1289
- r.selector.push({ id: l.id, ...u });
1293
+ if (Hn(d))
1294
+ r.selector.push(
1295
+ {
1296
+ ...d,
1297
+ id: l.id,
1298
+ // @ts-expect-error: `scope` is not part of the core `TextSelector` type
1299
+ scope: l.scope
1300
+ }
1301
+ );
1290
1302
  else {
1291
1303
  const h = [
1292
- u.start ? void 0 : "TextPositionSelector",
1293
- u.quote ? void 0 : "TextQuoteSelector"
1304
+ d.start ? void 0 : "TextPositionSelector",
1305
+ d.quote ? void 0 : "TextQuoteSelector"
1294
1306
  ].filter(Boolean);
1295
1307
  return { error: Error(`Missing selector types: ${h.join(" and ")} for annotation: ${t.id}`) };
1296
1308
  }
@@ -1318,23 +1330,25 @@ const Ao = (t, e) => ({
1318
1330
  creator: r,
1319
1331
  created: l,
1320
1332
  updated: f,
1321
- ...u
1333
+ ...d
1322
1334
  } = i, h = a.map((g) => {
1323
- const { quote: p, start: v, end: y, range: m } = g, { prefix: d, suffix: c } = ke(m, n), b = [{
1335
+ const { id: p, quote: A, start: y, end: m, range: u } = g, { prefix: c, suffix: w } = ke(u, n), S = [{
1324
1336
  type: "TextQuoteSelector",
1325
- exact: p,
1326
- prefix: d,
1327
- suffix: c
1337
+ exact: A,
1338
+ prefix: c,
1339
+ suffix: w
1328
1340
  }, {
1329
1341
  type: "TextPositionSelector",
1330
- start: v,
1331
- end: y
1342
+ start: y,
1343
+ end: m
1332
1344
  }];
1333
1345
  return {
1334
- ...u,
1335
- id: g.id,
1346
+ ...d,
1347
+ id: p,
1348
+ // @ts-expect-error: `scope` is not part of the core `TextSelector` type
1349
+ scope: "scope" in g ? g.scope : void 0,
1336
1350
  source: e,
1337
- selector: b
1351
+ selector: S
1338
1352
  };
1339
1353
  });
1340
1354
  return {
@@ -1352,8 +1366,8 @@ const Ao = (t, e) => ({
1352
1366
  function ge(t, e, n = 0, o = t.length - 1, i = Wn) {
1353
1367
  for (; o > n; ) {
1354
1368
  if (o - n > 600) {
1355
- const l = o - n + 1, f = e - n + 1, u = Math.log(l), h = 0.5 * Math.exp(2 * u / 3), g = 0.5 * Math.sqrt(u * h * (l - h) / l) * (f - l / 2 < 0 ? -1 : 1), p = Math.max(n, Math.floor(e - f * h / l + g)), v = Math.min(o, Math.floor(e + (l - f) * h / l + g));
1356
- ge(t, e, p, v, i);
1369
+ const l = o - n + 1, f = e - n + 1, d = Math.log(l), h = 0.5 * Math.exp(2 * d / 3), g = 0.5 * Math.sqrt(d * h * (l - h) / l) * (f - l / 2 < 0 ? -1 : 1), p = Math.max(n, Math.floor(e - f * h / l + g)), A = Math.min(o, Math.floor(e + (l - f) * h / l + g));
1370
+ ge(t, e, p, A, i);
1357
1371
  }
1358
1372
  const s = t[e];
1359
1373
  let a = n, r = o;
@@ -1442,9 +1456,9 @@ class qn {
1442
1456
  let r, l, f;
1443
1457
  for (; o || s.length; ) {
1444
1458
  if (o || (o = s.pop(), l = s[s.length - 1], r = a.pop(), f = !0), o.leaf) {
1445
- const u = Gn(e, o.children, n);
1446
- if (u !== -1)
1447
- return o.children.splice(u, 1), s.push(o), this._condense(s), this;
1459
+ const d = Gn(e, o.children, n);
1460
+ if (d !== -1)
1461
+ return o.children.splice(d, 1), s.push(o), this._condense(s), this;
1448
1462
  }
1449
1463
  !f && !o.leaf && Rt(o, i) ? (s.push(o), a.push(r), r = 0, l = o, o = o.children[0]) : l ? (r++, o = l.children[r], f = !1) : o = null;
1450
1464
  }
@@ -1479,10 +1493,10 @@ class qn {
1479
1493
  i || (i = Math.ceil(Math.log(s) / Math.log(a)), a = Math.ceil(s / Math.pow(a, i - 1))), r = J([]), r.leaf = !1, r.height = i;
1480
1494
  const l = Math.ceil(s / a), f = l * Math.ceil(Math.sqrt(a));
1481
1495
  te(e, n, o, f, this.compareMinX);
1482
- for (let u = n; u <= o; u += f) {
1483
- const h = Math.min(u + f - 1, o);
1484
- te(e, u, h, l, this.compareMinY);
1485
- for (let g = u; g <= h; g += l) {
1496
+ for (let d = n; d <= o; d += f) {
1497
+ const h = Math.min(d + f - 1, o);
1498
+ te(e, d, h, l, this.compareMinY);
1499
+ for (let g = d; g <= h; g += l) {
1486
1500
  const p = Math.min(g + l - 1, h);
1487
1501
  r.children.push(this._build(e, g, p, i - 1));
1488
1502
  }
@@ -1493,8 +1507,8 @@ class qn {
1493
1507
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1494
1508
  let s = 1 / 0, a = 1 / 0, r;
1495
1509
  for (let l = 0; l < n.children.length; l++) {
1496
- const f = n.children[l], u = Mt(f), h = Zn(e, f) - u;
1497
- h < a ? (a = h, s = u < s ? u : s, r = f) : h === a && u < s && (s = u, r = f);
1510
+ const f = n.children[l], d = Mt(f), h = Zn(e, f) - d;
1511
+ h < a ? (a = h, s = d < s ? d : s, r = f) : h === a && d < s && (s = d, r = f);
1498
1512
  }
1499
1513
  n = r || n.children[0];
1500
1514
  }
@@ -1519,8 +1533,8 @@ class qn {
1519
1533
  _chooseSplitIndex(e, n, o) {
1520
1534
  let i, s = 1 / 0, a = 1 / 0;
1521
1535
  for (let r = n; r <= o - n; r++) {
1522
- const l = ot(e, 0, r, this.toBBox), f = ot(e, r, o, this.toBBox), u = to(l, f), h = Mt(l) + Mt(f);
1523
- u < s ? (s = u, i = r, a = h < a ? h : a) : u === s && h < a && (a = h, i = r);
1536
+ const l = ot(e, 0, r, this.toBBox), f = ot(e, r, o, this.toBBox), d = to(l, f), h = Mt(l) + Mt(f);
1537
+ d < s ? (s = d, i = r, a = h < a ? h : a) : d === s && h < a && (a = h, i = r);
1524
1538
  }
1525
1539
  return i || o - n;
1526
1540
  }
@@ -1535,12 +1549,12 @@ class qn {
1535
1549
  const s = this.toBBox, a = ot(e, 0, n, s), r = ot(e, o - n, o, s);
1536
1550
  let l = pt(a) + pt(r);
1537
1551
  for (let f = n; f < o - n; f++) {
1538
- const u = e.children[f];
1539
- it(a, e.leaf ? s(u) : u), l += pt(a);
1552
+ const d = e.children[f];
1553
+ it(a, e.leaf ? s(d) : d), l += pt(a);
1540
1554
  }
1541
1555
  for (let f = o - n - 1; f >= n; f--) {
1542
- const u = e.children[f];
1543
- it(r, e.leaf ? s(u) : u), l += pt(r);
1556
+ const d = e.children[f];
1557
+ it(r, e.leaf ? s(d) : d), l += pt(r);
1544
1558
  }
1545
1559
  return l;
1546
1560
  }
@@ -1618,60 +1632,60 @@ function te(t, e, n, o, i) {
1618
1632
  }
1619
1633
  }
1620
1634
  const eo = (t, e) => {
1621
- const n = new qn(), o = /* @__PURE__ */ new Map(), i = (d, c) => {
1622
- const b = d.selector.flatMap((T) => {
1635
+ const n = new qn(), o = /* @__PURE__ */ new Map(), i = (u, c) => {
1636
+ const w = u.selector.flatMap((T) => {
1623
1637
  const L = F([T]) ? T.range : re(T, e).range;
1624
1638
  return Array.from(L.getClientRects());
1625
- }), S = Ve(b).map(({ left: T, top: L, right: O, bottom: E }) => new DOMRect(T - c.left, L - c.top, O - T, E - L));
1639
+ }), S = Ve(w).map(({ left: T, top: L, right: E, bottom: O }) => new DOMRect(T - c.left, L - c.top, E - T, O - L));
1626
1640
  return S.map((T) => {
1627
- const { x: L, y: O, width: E, height: R } = T;
1641
+ const { x: L, y: E, width: O, height: _ } = T;
1628
1642
  return {
1629
1643
  minX: L,
1630
- minY: O,
1631
- maxX: L + E,
1632
- maxY: O + R,
1644
+ minY: E,
1645
+ maxX: L + O,
1646
+ maxY: E + _,
1633
1647
  annotation: {
1634
- id: d.annotation,
1648
+ id: u.annotation,
1635
1649
  rects: S
1636
1650
  }
1637
1651
  };
1638
1652
  });
1639
1653
  }, s = () => [...o.values()], a = () => {
1640
1654
  n.clear(), o.clear();
1641
- }, r = (d) => {
1642
- const c = i(d, e.getBoundingClientRect());
1643
- c.forEach((b) => n.insert(b)), o.set(d.annotation, c);
1644
- }, l = (d) => {
1645
- const c = o.get(d.annotation);
1646
- c && (c.forEach((b) => n.remove(b)), o.delete(d.annotation));
1647
- }, f = (d) => {
1648
- l(d), r(d);
1649
- }, u = (d, c = !0) => {
1655
+ }, r = (u) => {
1656
+ const c = i(u, e.getBoundingClientRect());
1657
+ c.forEach((w) => n.insert(w)), o.set(u.annotation, c);
1658
+ }, l = (u) => {
1659
+ const c = o.get(u.annotation);
1660
+ c && (c.forEach((w) => n.remove(w)), o.delete(u.annotation));
1661
+ }, f = (u) => {
1662
+ l(u), r(u);
1663
+ }, d = (u, c = !0) => {
1650
1664
  c && a();
1651
- const b = e.getBoundingClientRect(), S = d.map((L) => ({ target: L, rects: i(L, b) }));
1652
- S.forEach(({ target: L, rects: O }) => o.set(L.annotation, O));
1665
+ const w = e.getBoundingClientRect(), S = u.map((L) => ({ target: L, rects: i(L, w) }));
1666
+ S.forEach(({ target: L, rects: E }) => o.set(L.annotation, E));
1653
1667
  const T = S.flatMap(({ rects: L }) => L);
1654
1668
  n.load(T);
1655
- }, h = (d, c, b = !1) => {
1669
+ }, h = (u, c, w = !1) => {
1656
1670
  const S = n.search({
1657
- minX: d,
1671
+ minX: u,
1658
1672
  minY: c,
1659
- maxX: d,
1673
+ maxX: u,
1660
1674
  maxY: c
1661
- }), T = (L) => L.annotation.rects.reduce((O, E) => O + E.width * E.height, 0);
1662
- return S.length > 0 ? (S.sort((L, O) => T(L) - T(O)), b ? S.map((L) => L.annotation.id) : [S[0].annotation.id]) : [];
1663
- }, g = (d) => {
1664
- const c = p(d);
1675
+ }), T = (L) => L.annotation.rects.reduce((E, O) => E + O.width * O.height, 0);
1676
+ return S.length > 0 ? (S.sort((L, E) => T(L) - T(E)), w ? S.map((L) => L.annotation.id) : [S[0].annotation.id]) : [];
1677
+ }, g = (u) => {
1678
+ const c = p(u);
1665
1679
  if (c.length === 0)
1666
1680
  return;
1667
- let b = c[0].left, S = c[0].top, T = c[0].right, L = c[0].bottom;
1668
- for (let O = 1; O < c.length; O++) {
1669
- const E = c[O];
1670
- b = Math.min(b, E.left), S = Math.min(S, E.top), T = Math.max(T, E.right), L = Math.max(L, E.bottom);
1681
+ let w = c[0].left, S = c[0].top, T = c[0].right, L = c[0].bottom;
1682
+ for (let E = 1; E < c.length; E++) {
1683
+ const O = c[E];
1684
+ w = Math.min(w, O.left), S = Math.min(S, O.top), T = Math.max(T, O.right), L = Math.max(L, O.bottom);
1671
1685
  }
1672
- return new DOMRect(b, S, T - b, L - S);
1673
- }, p = (d) => {
1674
- const c = o.get(d);
1686
+ return new DOMRect(w, S, T - w, L - S);
1687
+ }, p = (u) => {
1688
+ const c = o.get(u);
1675
1689
  return c ? c[0].annotation.rects : [];
1676
1690
  };
1677
1691
  return {
@@ -1680,56 +1694,56 @@ const eo = (t, e) => {
1680
1694
  getAt: h,
1681
1695
  getAnnotationBounds: g,
1682
1696
  getAnnotationRects: p,
1683
- getIntersecting: (d, c, b, S) => {
1684
- const T = n.search({ minX: d, minY: c, maxX: b, maxY: S }), L = new Set(T.map((O) => O.annotation.id));
1685
- return Array.from(L).map((O) => ({
1686
- annotation: t.getAnnotation(O),
1687
- rects: p(O)
1688
- })).filter((O) => !!O.annotation);
1697
+ getIntersecting: (u, c, w, S) => {
1698
+ const T = n.search({ minX: u, minY: c, maxX: w, maxY: S }), L = new Set(T.map((E) => E.annotation.id));
1699
+ return Array.from(L).map((E) => ({
1700
+ annotation: t.getAnnotation(E),
1701
+ rects: p(E)
1702
+ })).filter((E) => !!E.annotation);
1689
1703
  },
1690
1704
  insert: r,
1691
- recalculate: () => u(t.all().map((d) => d.target), !0),
1705
+ recalculate: () => d(t.all().map((u) => u.target), !0),
1692
1706
  remove: l,
1693
- set: u,
1707
+ set: d,
1694
1708
  size: () => n.all().length,
1695
1709
  update: f
1696
1710
  };
1697
1711
  }, no = (t, e) => {
1698
1712
  const n = Tn(), o = eo(n, t), i = gn(n);
1699
1713
  i.setUserSelectAction(e);
1700
- const s = hn(n), a = Bn(), r = (m, d = B.LOCAL) => {
1701
- const c = vt(m, t), b = F(c.target.selector);
1702
- return b && n.addAnnotation(c, d), b;
1703
- }, l = (m, d = !0, c = B.LOCAL) => {
1704
- const b = m.map((T) => vt(T, t)), S = b.filter((T) => !F(T.target.selector));
1705
- return S.length > 0 ? (console.warn("Could not revive all targets for these annotations:", S), n.bulkAddAnnotation(b, d, c), S) : (n.bulkAddAnnotation(b, d, c), []);
1706
- }, f = (m, d = B.LOCAL) => {
1707
- const c = m.map((S) => vt(S, t)), b = c.filter((S) => !F(S.target.selector));
1708
- return b.length > 0 && console.warn("Could not revive all targets for these annotations:", b), c.forEach((S) => {
1709
- n.getAnnotation(S.id) ? n.updateAnnotation(S, d) : n.addAnnotation(S, d);
1710
- }), b;
1711
- }, u = (m, d = B.LOCAL) => {
1714
+ const s = hn(n), a = Bn(), r = (m, u = R.LOCAL) => {
1715
+ const c = vt(m, t), w = F(c.target.selector);
1716
+ return w && n.addAnnotation(c, u), w;
1717
+ }, l = (m, u = !0, c = R.LOCAL) => {
1718
+ const w = m.map((T) => vt(T, t)), S = w.filter((T) => !F(T.target.selector));
1719
+ return n.bulkAddAnnotation(w, u, c), S;
1720
+ }, f = (m, u = R.LOCAL) => {
1721
+ const c = m.map((S) => vt(S, t)), w = c.filter((S) => !F(S.target.selector));
1722
+ return c.forEach((S) => {
1723
+ n.getAnnotation(S.id) ? n.updateAnnotation(S, u) : n.addAnnotation(S, u);
1724
+ }), w;
1725
+ }, d = (m, u = R.LOCAL) => {
1712
1726
  const c = yt(m, t);
1713
- n.updateTarget(c, d);
1714
- }, h = (m, d = B.LOCAL) => {
1715
- const c = m.map((b) => yt(b, t));
1716
- n.bulkUpdateTargets(c, d);
1717
- }, g = (m, d, c) => {
1718
- const b = o.getAt(m, d, !!c).map((T) => n.getAnnotation(T)), S = c ? b.filter(c) : b;
1727
+ n.updateTarget(c, u);
1728
+ }, h = (m, u = R.LOCAL) => {
1729
+ const c = m.map((w) => yt(w, t));
1730
+ n.bulkUpdateTargets(c, u);
1731
+ }, g = (m, u, c) => {
1732
+ const w = o.getAt(m, u, !!c).map((T) => n.getAnnotation(T)), S = c ? w.filter(c) : w;
1719
1733
  return S.length > 0 ? S[0] : void 0;
1720
- }, p = (m, d, c, b = 5) => {
1734
+ }, p = (m, u, c, w = 5) => {
1721
1735
  const S = o.getAnnotationRects(m);
1722
1736
  if (S.length !== 0) {
1723
- if (d && c) {
1724
- const T = S.find(({ top: L, right: O, bottom: E, left: R }) => d >= R - b && d <= O + b && c >= L - b && c <= E + b);
1737
+ if (u && c) {
1738
+ const T = S.find(({ top: L, right: E, bottom: O, left: _ }) => u >= _ - w && u <= E + w && c >= L - w && c <= O + w);
1725
1739
  if (T) return T;
1726
1740
  }
1727
1741
  return o.getAnnotationBounds(m);
1728
1742
  }
1729
- }, v = (m) => o.getAnnotationRects(m), y = () => o.recalculate();
1743
+ }, A = (m) => o.getAnnotationRects(m), y = () => o.recalculate();
1730
1744
  return n.observe(({ changes: m }) => {
1731
- const d = (m.deleted || []).filter((S) => F(S.target.selector)), c = (m.created || []).filter((S) => F(S.target.selector)), b = (m.updated || []).filter((S) => F(S.newValue.target.selector));
1732
- (d == null ? void 0 : d.length) > 0 && d.forEach((S) => o.remove(S.target)), c.length > 0 && o.set(c.map((S) => S.target), !1), (b == null ? void 0 : b.length) > 0 && b.forEach(({ newValue: S }) => o.update(S.target));
1745
+ const u = (m.deleted || []).filter((S) => F(S.target.selector)), c = (m.created || []).filter((S) => F(S.target.selector)), w = (m.updated || []).filter((S) => F(S.newValue.target.selector));
1746
+ (u == null ? void 0 : u.length) > 0 && u.forEach((S) => o.remove(S.target)), c.length > 0 && o.set(c.map((S) => S.target), !1), (w == null ? void 0 : w.length) > 0 && w.forEach(({ newValue: S }) => o.update(S.target));
1733
1747
  }), {
1734
1748
  store: {
1735
1749
  ...n,
@@ -1738,11 +1752,11 @@ const eo = (t, e) => {
1738
1752
  bulkUpdateTargets: h,
1739
1753
  bulkUpsertAnnotations: f,
1740
1754
  getAnnotationBounds: p,
1741
- getAnnotationRects: v,
1755
+ getAnnotationRects: A,
1742
1756
  getAt: g,
1743
1757
  getIntersecting: o.getIntersecting,
1744
1758
  recalculatePositions: y,
1745
- updateTarget: u
1759
+ updateTarget: d
1746
1760
  },
1747
1761
  selection: i,
1748
1762
  hover: s,
@@ -1756,25 +1770,25 @@ const eo = (t, e) => {
1756
1770
  }, io = (t, e = {}) => {
1757
1771
  const n = oo(), o = n.getContext("2d");
1758
1772
  document.body.appendChild(n);
1759
- const i = /* @__PURE__ */ new Map(), s = (u) => Array.from(i.entries()).filter(([h, g]) => g.presenceKey === u.presenceKey).map(([h, g]) => h);
1760
- return t.on("selectionChange", (u, h) => {
1761
- s(u).forEach((p) => i.delete(p)), h && h.forEach((p) => i.set(p, u));
1773
+ const i = /* @__PURE__ */ new Map(), s = (d) => Array.from(i.entries()).filter(([h, g]) => g.presenceKey === d.presenceKey).map(([h, g]) => h);
1774
+ return t.on("selectionChange", (d, h) => {
1775
+ s(d).forEach((p) => i.delete(p)), h && h.forEach((p) => i.set(p, d));
1762
1776
  }), {
1763
1777
  clear: () => {
1764
- const { width: u, height: h } = n;
1765
- o.clearRect(-0.5, -0.5, u + 1, h + 1);
1778
+ const { width: d, height: h } = n;
1779
+ o.clearRect(-0.5, -0.5, d + 1, h + 1);
1766
1780
  },
1767
1781
  destroy: () => {
1768
1782
  n.remove();
1769
1783
  },
1770
- paint: (u, h, g) => {
1784
+ paint: (d, h, g) => {
1771
1785
  e.font && (o.font = e.font);
1772
- const p = i.get(u.annotation.id);
1786
+ const p = i.get(d.annotation.id);
1773
1787
  if (p) {
1774
- const { height: v } = u.rects[0], y = u.rects[0].x + h.left, m = u.rects[0].y + h.top;
1775
- o.fillStyle = p.appearance.color, o.fillRect(y - 2, m - 2.5, 2, v + 5);
1776
- const d = o.measureText(p.appearance.label), c = d.width + 6, b = d.actualBoundingBoxAscent + d.actualBoundingBoxDescent + 8, S = d.fontBoundingBoxAscent ? 8 : 6.5;
1777
- return o.fillRect(y - 2, m - 2.5 - b, c, b), o.fillStyle = "#fff", o.fillText(p.appearance.label, y + 1, m - S), {
1788
+ const { height: A } = d.rects[0], y = d.rects[0].x + h.left, m = d.rects[0].y + h.top;
1789
+ o.fillStyle = p.appearance.color, o.fillRect(y - 2, m - 2.5, 2, A + 5);
1790
+ const u = o.measureText(p.appearance.label), c = u.width + 6, w = u.actualBoundingBoxAscent + u.actualBoundingBoxDescent + 8, S = u.fontBoundingBoxAscent ? 8 : 6.5;
1791
+ return o.fillRect(y - 2, m - 2.5 - w, c, w), o.fillStyle = "#fff", o.fillText(p.appearance.label, y + 1, m - S), {
1778
1792
  fill: p.appearance.color,
1779
1793
  fillOpacity: g ? 0.45 : 0.18
1780
1794
  };
@@ -1782,8 +1796,8 @@ const eo = (t, e) => {
1782
1796
  },
1783
1797
  reset: () => {
1784
1798
  n.width = 2 * window.innerWidth, n.height = 2 * window.innerHeight;
1785
- const u = n.getContext("2d");
1786
- u.scale(2, 2), u.translate(0.5, 0.5);
1799
+ const d = n.getContext("2d");
1800
+ d.scale(2, 2), d.translate(0.5, 0.5);
1787
1801
  }
1788
1802
  };
1789
1803
  }, Bt = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
@@ -1895,10 +1909,10 @@ const at = {
1895
1909
  18: !1,
1896
1910
  17: !1,
1897
1911
  91: !1
1898
- }, _ = {};
1912
+ }, I = {};
1899
1913
  for (let t = 1; t < 20; t++)
1900
1914
  at["f".concat(t)] = 111 + t;
1901
- let I = [], rt = null, be = "all";
1915
+ let k = [], rt = null, be = "all";
1902
1916
  const z = /* @__PURE__ */ new Map(), lt = (t) => at[t.toLowerCase()] || H[t.toLowerCase()] || t.toUpperCase().charCodeAt(0), ro = (t) => Object.keys(at).find((e) => at[e] === t), ao = (t) => Object.keys(H).find((e) => H[e] === t);
1903
1917
  function we(t) {
1904
1918
  be = t || "all";
@@ -1907,15 +1921,15 @@ function ct() {
1907
1921
  return be || "all";
1908
1922
  }
1909
1923
  function co() {
1910
- return I.slice(0);
1924
+ return k.slice(0);
1911
1925
  }
1912
1926
  function lo() {
1913
- return I.map((t) => ro(t) || ao(t) || String.fromCharCode(t));
1927
+ return k.map((t) => ro(t) || ao(t) || String.fromCharCode(t));
1914
1928
  }
1915
1929
  function uo() {
1916
1930
  const t = [];
1917
- return Object.keys(_).forEach((e) => {
1918
- _[e].forEach((n) => {
1931
+ return Object.keys(I).forEach((e) => {
1932
+ I[e].forEach((n) => {
1919
1933
  let {
1920
1934
  key: o,
1921
1935
  scope: i,
@@ -1940,14 +1954,14 @@ function fo(t) {
1940
1954
  return (e.isContentEditable || (i || n === "TEXTAREA" || n === "SELECT") && !e.readOnly) && (o = !1), o;
1941
1955
  }
1942
1956
  function ho(t) {
1943
- return typeof t == "string" && (t = lt(t)), I.indexOf(t) !== -1;
1957
+ return typeof t == "string" && (t = lt(t)), k.indexOf(t) !== -1;
1944
1958
  }
1945
1959
  function po(t, e) {
1946
1960
  let n, o;
1947
1961
  t || (t = ct());
1948
- for (const i in _)
1949
- if (Object.prototype.hasOwnProperty.call(_, i))
1950
- for (n = _[i], o = 0; o < n.length; )
1962
+ for (const i in I)
1963
+ if (Object.prototype.hasOwnProperty.call(I, i))
1964
+ for (n = I[i], o = 0; o < n.length; )
1951
1965
  n[o].scope === t ? n.splice(o, 1).forEach((a) => {
1952
1966
  let {
1953
1967
  element: r
@@ -1958,16 +1972,16 @@ function po(t, e) {
1958
1972
  }
1959
1973
  function go(t) {
1960
1974
  let e = t.keyCode || t.which || t.charCode;
1961
- const n = I.indexOf(e);
1962
- if (n >= 0 && I.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && I.splice(0, I.length), (e === 93 || e === 224) && (e = 91), e in K) {
1975
+ const n = k.indexOf(e);
1976
+ if (n >= 0 && k.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && k.splice(0, k.length), (e === 93 || e === 224) && (e = 91), e in K) {
1963
1977
  K[e] = !1;
1964
1978
  for (const o in H) H[o] === e && (P[o] = !1);
1965
1979
  }
1966
1980
  }
1967
1981
  function ve(t) {
1968
1982
  if (typeof t > "u")
1969
- Object.keys(_).forEach((i) => {
1970
- Array.isArray(_[i]) && _[i].forEach((s) => mt(s)), delete _[i];
1983
+ Object.keys(I).forEach((i) => {
1984
+ Array.isArray(I[i]) && I[i].forEach((s) => mt(s)), delete I[i];
1971
1985
  }), Dt(null);
1972
1986
  else if (Array.isArray(t))
1973
1987
  t.forEach((i) => {
@@ -1995,11 +2009,11 @@ const mt = (t) => {
1995
2009
  splitKey: i = "+"
1996
2010
  } = t;
1997
2011
  ye(e).forEach((a) => {
1998
- const r = a.split(i), l = r.length, f = r[l - 1], u = f === "*" ? "*" : lt(f);
1999
- if (!_[u]) return;
2012
+ const r = a.split(i), l = r.length, f = r[l - 1], d = f === "*" ? "*" : lt(f);
2013
+ if (!I[d]) return;
2000
2014
  n || (n = ct());
2001
2015
  const h = l > 1 ? me(H, r) : [], g = [];
2002
- _[u] = _[u].filter((p) => {
2016
+ I[d] = I[d].filter((p) => {
2003
2017
  const y = (o ? p.method === o : !0) && p.scope === n && so(p.mods, h);
2004
2018
  return y && g.push(p.element), !y;
2005
2019
  }), g.forEach((p) => Dt(p));
@@ -2013,16 +2027,16 @@ function ee(t, e, n, o) {
2013
2027
  i = e.mods.length > 0;
2014
2028
  for (const s in K)
2015
2029
  Object.prototype.hasOwnProperty.call(K, s) && (!K[s] && e.mods.indexOf(+s) > -1 || K[s] && e.mods.indexOf(+s) === -1) && (i = !1);
2016
- (e.mods.length === 0 && !K[16] && !K[18] && !K[17] && !K[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(I), e.method(t, e) === !1 && (t.preventDefault ? t.preventDefault() : t.returnValue = !1, t.stopPropagation && t.stopPropagation(), t.cancelBubble && (t.cancelBubble = !0)));
2030
+ (e.mods.length === 0 && !K[16] && !K[18] && !K[17] && !K[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(k), e.method(t, e) === !1 && (t.preventDefault ? t.preventDefault() : t.returnValue = !1, t.stopPropagation && t.stopPropagation(), t.cancelBubble && (t.cancelBubble = !0)));
2017
2031
  }
2018
2032
  }
2019
2033
  function ne(t, e) {
2020
- const n = _["*"];
2034
+ const n = I["*"];
2021
2035
  let o = t.keyCode || t.which || t.charCode;
2022
2036
  if (!P.filter.call(this, t)) return;
2023
- if ((o === 93 || o === 224) && (o = 91), I.indexOf(o) === -1 && o !== 229 && I.push(o), ["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach((r) => {
2037
+ if ((o === 93 || o === 224) && (o = 91), k.indexOf(o) === -1 && o !== 229 && k.push(o), ["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach((r) => {
2024
2038
  const l = Ut[r];
2025
- t[r] && I.indexOf(l) === -1 ? I.push(l) : !t[r] && I.indexOf(l) > -1 ? I.splice(I.indexOf(l), 1) : r === "metaKey" && t[r] && I.length === 3 && (t.ctrlKey || t.shiftKey || t.altKey || (I = I.slice(I.indexOf(l))));
2039
+ t[r] && k.indexOf(l) === -1 ? k.push(l) : !t[r] && k.indexOf(l) > -1 ? k.splice(k.indexOf(l), 1) : r === "metaKey" && t[r] && k.length === 3 && (t.ctrlKey || t.shiftKey || t.altKey || (k = k.slice(k.indexOf(l))));
2026
2040
  }), o in K) {
2027
2041
  K[o] = !0;
2028
2042
  for (const r in H)
@@ -2031,29 +2045,29 @@ function ne(t, e) {
2031
2045
  }
2032
2046
  for (const r in K)
2033
2047
  Object.prototype.hasOwnProperty.call(K, r) && (K[r] = t[Ut[r]]);
2034
- t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (I.indexOf(17) === -1 && I.push(17), I.indexOf(18) === -1 && I.push(18), K[17] = !0, K[18] = !0);
2048
+ t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (k.indexOf(17) === -1 && k.push(17), k.indexOf(18) === -1 && k.push(18), K[17] = !0, K[18] = !0);
2035
2049
  const i = ct();
2036
2050
  if (n)
2037
2051
  for (let r = 0; r < n.length; r++)
2038
2052
  n[r].scope === i && (t.type === "keydown" && n[r].keydown || t.type === "keyup" && n[r].keyup) && ee(t, n[r], i, e);
2039
- if (!(o in _)) return;
2040
- const s = _[o], a = s.length;
2053
+ if (!(o in I)) return;
2054
+ const s = I[o], a = s.length;
2041
2055
  for (let r = 0; r < a; r++)
2042
2056
  if ((t.type === "keydown" && s[r].keydown || t.type === "keyup" && s[r].keyup) && s[r].key) {
2043
2057
  const l = s[r], {
2044
2058
  splitKey: f
2045
- } = l, u = l.key.split(f), h = [];
2046
- for (let g = 0; g < u.length; g++)
2047
- h.push(lt(u[g]));
2048
- h.sort().join("") === I.sort().join("") && ee(t, l, i, e);
2059
+ } = l, d = l.key.split(f), h = [];
2060
+ for (let g = 0; g < d.length; g++)
2061
+ h.push(lt(d[g]));
2062
+ h.sort().join("") === k.sort().join("") && ee(t, l, i, e);
2049
2063
  }
2050
2064
  }
2051
2065
  function P(t, e, n) {
2052
- I = [];
2066
+ k = [];
2053
2067
  const o = ye(t);
2054
- let i = [], s = "all", a = document, r = 0, l = !1, f = !0, u = "+", h = !1, g = !1;
2055
- for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (f = e.keydown), e.capture !== void 0 && (h = e.capture), typeof e.splitKey == "string" && (u = e.splitKey), e.single === !0 && (g = !0)), typeof e == "string" && (s = e), g && ve(t, s); r < o.length; r++)
2056
- t = o[r].split(u), i = [], t.length > 1 && (i = me(H, t)), t = t[t.length - 1], t = t === "*" ? "*" : lt(t), t in _ || (_[t] = []), _[t].push({
2068
+ let i = [], s = "all", a = document, r = 0, l = !1, f = !0, d = "+", h = !1, g = !1;
2069
+ for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (f = e.keydown), e.capture !== void 0 && (h = e.capture), typeof e.splitKey == "string" && (d = e.splitKey), e.single === !0 && (g = !0)), typeof e == "string" && (s = e), g && ve(t, s); r < o.length; r++)
2070
+ t = o[r].split(d), i = [], t.length > 1 && (i = me(H, t)), t = t[t.length - 1], t = t === "*" ? "*" : lt(t), t in I || (I[t] = []), I[t].push({
2057
2071
  keyup: l,
2058
2072
  keydown: f,
2059
2073
  scope: s,
@@ -2061,7 +2075,7 @@ function P(t, e, n) {
2061
2075
  shortcut: o[r],
2062
2076
  method: n,
2063
2077
  key: o[r],
2064
- splitKey: u,
2078
+ splitKey: d,
2065
2079
  element: a
2066
2080
  });
2067
2081
  if (typeof a < "u" && window) {
@@ -2069,19 +2083,19 @@ function P(t, e, n) {
2069
2083
  const p = function() {
2070
2084
  let y = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2071
2085
  return ne(y, a);
2072
- }, v = function() {
2086
+ }, A = function() {
2073
2087
  let y = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2074
2088
  ne(y, a), go(y);
2075
2089
  };
2076
2090
  z.set(a, {
2077
2091
  keydownListener: p,
2078
- keyupListenr: v,
2092
+ keyupListenr: A,
2079
2093
  capture: h
2080
- }), kt(a, "keydown", p, h), kt(a, "keyup", v, h);
2094
+ }), kt(a, "keydown", p, h), kt(a, "keyup", A, h);
2081
2095
  }
2082
2096
  if (!rt) {
2083
2097
  const p = () => {
2084
- I = [];
2098
+ k = [];
2085
2099
  };
2086
2100
  rt = {
2087
2101
  listener: p,
@@ -2092,14 +2106,14 @@ function P(t, e, n) {
2092
2106
  }
2093
2107
  function mo(t) {
2094
2108
  let e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "all";
2095
- Object.keys(_).forEach((n) => {
2096
- _[n].filter((i) => i.scope === e && i.shortcut === t).forEach((i) => {
2109
+ Object.keys(I).forEach((n) => {
2110
+ I[n].filter((i) => i.scope === e && i.shortcut === t).forEach((i) => {
2097
2111
  i && i.method && i.method();
2098
2112
  });
2099
2113
  });
2100
2114
  }
2101
2115
  function Dt(t) {
2102
- const e = Object.values(_).flat();
2116
+ const e = Object.values(I).flat();
2103
2117
  if (e.findIndex((o) => {
2104
2118
  let {
2105
2119
  element: i
@@ -2120,7 +2134,7 @@ function Dt(t) {
2120
2134
  capture: r
2121
2135
  } = z.get(i) || {};
2122
2136
  s && a && (et(i, "keyup", a, r), et(i, "keydown", s, r), z.delete(i));
2123
- }), z.clear(), Object.keys(_).forEach((i) => delete _[i]), rt)) {
2137
+ }), z.clear(), Object.keys(I).forEach((i) => delete I[i]), rt)) {
2124
2138
  const {
2125
2139
  listener: i,
2126
2140
  capture: s
@@ -2157,86 +2171,85 @@ const oe = 300, Ae = ["up", "down", "left", "right"], xe = Oe ? "⌘+a" : "ctrl+
2157
2171
  const s = (E) => i = E;
2158
2172
  let a;
2159
2173
  const r = (E) => a = E, { store: l, selection: f } = e;
2160
- let u, h, g, p = !1;
2161
- const v = (E) => {
2162
- p = !1, h !== !1 && (u = nt(E.target) ? void 0 : {
2174
+ let d, h, g;
2175
+ const p = (E) => {
2176
+ h !== !1 && (d = nt(E.target) ? void 0 : {
2163
2177
  annotation: ue(),
2164
2178
  selector: [],
2165
2179
  creator: i,
2166
2180
  created: /* @__PURE__ */ new Date()
2167
2181
  });
2168
- }, y = Vt((E) => {
2169
- const R = document.getSelection();
2170
- if (nt(R.anchorNode)) {
2171
- u = void 0;
2182
+ }, A = Vt((E) => {
2183
+ const O = document.getSelection();
2184
+ if (nt(O.anchorNode)) {
2185
+ d = void 0;
2172
2186
  return;
2173
2187
  }
2174
- const w = E.timeStamp - ((g == null ? void 0 : g.timeStamp) || E.timeStamp);
2175
- if ((g == null ? void 0 : g.type) === "pointerdown" && (w < 1e3 && !u || R.isCollapsed && w < oe) && v(g || E), !u) return;
2176
- if (R.isCollapsed) {
2177
- l.getAnnotation(u.annotation) && (f.clear(), l.deleteAnnotation(u.annotation));
2188
+ const _ = E.timeStamp - ((g == null ? void 0 : g.timeStamp) || E.timeStamp);
2189
+ if ((g == null ? void 0 : g.type) === "pointerdown" && (_ < 1e3 && !d || O.isCollapsed && _ < oe) && p(g || E), !d) return;
2190
+ if (O.isCollapsed) {
2191
+ l.getAnnotation(d.annotation) && (f.clear(), l.deleteAnnotation(d.annotation));
2178
2192
  return;
2179
2193
  }
2180
- const A = R.getRangeAt(0), x = Ye(A, t);
2194
+ const b = O.getRangeAt(0), x = Ye(b, t);
2181
2195
  if (_e(x)) return;
2182
- const C = Be(x.cloneRange());
2183
- (C.length !== u.selector.length || C.some((M, D) => {
2196
+ const v = Be(x.cloneRange());
2197
+ (v.length !== d.selector.length || v.some((B, M) => {
2184
2198
  var Y;
2185
- return M.toString() !== ((Y = u.selector[D]) == null ? void 0 : Y.quote);
2186
- })) && (u = {
2187
- ...u,
2188
- selector: C.map((M) => Ke(M, t, o)),
2199
+ return B.toString() !== ((Y = d.selector[M]) == null ? void 0 : Y.quote);
2200
+ })) && (d = {
2201
+ ...d,
2202
+ selector: v.map((B) => Ke(B, t, o)),
2189
2203
  updated: /* @__PURE__ */ new Date()
2190
- }, l.getAnnotation(u.annotation) ? l.updateTarget(u, B.LOCAL) : f.clear());
2191
- }), m = (E) => {
2192
- p || nt(E.target) || (g = wt(E), h = g.button === 0);
2193
- }, d = () => {
2194
- l.getAnnotation(u.annotation) ? l.updateTarget(u) : l.addAnnotation({
2195
- id: u.annotation,
2204
+ }, l.getAnnotation(d.annotation) ? l.updateTarget(d, R.LOCAL) : f.clear());
2205
+ }), y = (E) => {
2206
+ nt(E.target) || (g = wt(E), h = g.button === 0);
2207
+ }, m = () => {
2208
+ l.getAnnotation(d.annotation) ? l.updateTarget(d) : l.addAnnotation({
2209
+ id: d.annotation,
2196
2210
  bodies: [],
2197
- target: u
2211
+ target: d
2198
2212
  });
2199
- }, c = (E) => {
2200
- if (p || nt(E.target) || !h) return;
2201
- const R = () => {
2202
- const { x: A, y: x } = t.getBoundingClientRect(), C = E.target instanceof Node && t.contains(E.target) && l.getAt(E.clientX - A, E.clientY - x, a);
2203
- if (C) {
2204
- const { selected: k } = f;
2205
- (k.length !== 1 || k[0].id !== C.id) && f.userSelect(C.id, E);
2213
+ }, u = (E) => {
2214
+ if (nt(E.target) || !h) return;
2215
+ const O = () => {
2216
+ const { x: b, y: x } = t.getBoundingClientRect(), v = E.target instanceof Node && t.contains(E.target) && l.getAt(E.clientX - b, E.clientY - x, a);
2217
+ if (v) {
2218
+ const { selected: C } = f;
2219
+ (C.length !== 1 || C[0].id !== v.id) && f.userSelect(v.id, E);
2206
2220
  } else
2207
2221
  f.clear();
2208
- }, w = E.timeStamp - g.timeStamp;
2222
+ }, _ = E.timeStamp - g.timeStamp;
2209
2223
  setTimeout(() => {
2210
- const A = document.getSelection();
2211
- A != null && A.isCollapsed && w < oe ? (u = void 0, R()) : u && u.selector.length > 0 && (f.clear(), d(), f.userSelect(u.annotation, wt(E)));
2224
+ const b = document.getSelection();
2225
+ b != null && b.isCollapsed && _ < oe ? (d = void 0, O()) : d && d.selector.length > 0 && (f.clear(), m(), f.userSelect(d.annotation, wt(E)));
2212
2226
  });
2213
- }, b = (E) => {
2214
- p = !0;
2215
- const R = document.getSelection();
2216
- R != null && R.isCollapsed || ((!u || u.selector.length === 0) && y(E), d(), f.userSelect(u.annotation, wt(E)));
2227
+ }, c = (E) => {
2228
+ const O = document.getSelection();
2229
+ O != null && O.isCollapsed || ((!d || d.selector.length === 0) && A(E), m(), f.userSelect(d.annotation, wt(E)));
2230
+ }, w = (E) => {
2231
+ E.key === "Shift" && d && (document.getSelection().isCollapsed || (f.clear(), m(), f.userSelect(d.annotation, dt(E))));
2217
2232
  }, S = (E) => {
2218
- E.key === "Shift" && u && (document.getSelection().isCollapsed || (f.clear(), d(), f.userSelect(u.annotation, dt(E))));
2219
- }, T = (E) => {
2220
- const R = () => setTimeout(() => {
2221
- (u == null ? void 0 : u.selector.length) > 0 && (f.clear(), l.addAnnotation({
2222
- id: u.annotation,
2233
+ const O = () => setTimeout(() => {
2234
+ (d == null ? void 0 : d.selector.length) > 0 && (f.clear(), l.addAnnotation({
2235
+ id: d.annotation,
2223
2236
  bodies: [],
2224
- target: u
2225
- }), f.userSelect(u.annotation, dt(E))), document.removeEventListener("selectionchange", R);
2237
+ target: d
2238
+ }), f.userSelect(d.annotation, dt(E))), document.removeEventListener("selectionchange", O);
2226
2239
  }, 100);
2227
- document.addEventListener("selectionchange", R), v(E);
2240
+ document.addEventListener("selectionchange", O), p(E);
2228
2241
  };
2229
2242
  P(yo.join(","), { element: t, keydown: !0, keyup: !1 }, (E) => {
2230
2243
  E.repeat || (g = dt(E));
2231
2244
  }), P(xe, { keydown: !0, keyup: !1 }, (E) => {
2232
- g = dt(E), T(E);
2245
+ g = dt(E), S(E);
2233
2246
  });
2234
- const L = (E) => {
2235
- E.repeat || E.target !== t && E.target !== document.body || (u = void 0, f.clear());
2247
+ const T = (E) => {
2248
+ E.repeat || E.target !== t && E.target !== document.body || (d = void 0, f.clear());
2236
2249
  };
2237
- return P(Ae.join(","), { keydown: !0, keyup: !1 }, L), t.addEventListener("pointerdown", m), document.addEventListener("pointerup", c), document.addEventListener("contextmenu", b), n && (t.addEventListener("keyup", S), t.addEventListener("selectstart", v), document.addEventListener("selectionchange", y)), {
2250
+ return P(Ae.join(","), { keydown: !0, keyup: !1 }, T), t.addEventListener("pointerdown", y), document.addEventListener("pointerup", u), document.addEventListener("contextmenu", c), n && (t.addEventListener("keyup", w), t.addEventListener("selectstart", p), document.addEventListener("selectionchange", A)), {
2238
2251
  destroy: () => {
2239
- t.removeEventListener("pointerdown", m), document.removeEventListener("pointerup", c), document.removeEventListener("contextmenu", b), t.removeEventListener("keyup", S), t.removeEventListener("selectstart", v), document.removeEventListener("selectionchange", y), P.unbind();
2252
+ t.removeEventListener("pointerdown", y), document.removeEventListener("pointerup", u), document.removeEventListener("contextmenu", c), t.removeEventListener("keyup", w), t.removeEventListener("selectstart", p), document.removeEventListener("selectionchange", A), P.unbind();
2240
2253
  },
2241
2254
  setFilter: r,
2242
2255
  setUser: s
@@ -2252,10 +2265,10 @@ const oe = 300, Ae = ["up", "down", "left", "right"], xe = Oe ? "⌘+a" : "ctrl+
2252
2265
  user: Dn()
2253
2266
  }), o = no(t, n.userSelectAction), { selection: i, viewport: s } = o, a = o.store, r = Rn(a), l = kn(o, r, n.adapter);
2254
2267
  let f = n.user;
2255
- const u = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ie : n.renderer || ie, h = u === "SPANS" ? an(t, o, s) : u === "CSS_HIGHLIGHTS" ? on(t, o, s) : u === "CANVAS" ? Fe(t, o, s) : void 0;
2268
+ const d = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ie : n.renderer || ie, h = d === "SPANS" ? an(t, o, s) : d === "CSS_HIGHLIGHTS" ? on(t, o, s) : d === "CANVAS" ? Fe(t, o, s) : void 0;
2256
2269
  if (!h)
2257
- throw `Unknown renderer implementation: ${u}`;
2258
- console.debug(`Using ${u} renderer`), n.style && h.setStyle(n.style);
2270
+ throw `Unknown renderer implementation: ${d}`;
2271
+ console.debug(`Using ${d} renderer`), n.style && h.setStyle(n.style);
2259
2272
  const g = bo(t, o, n.annotatingEnabled, n.offsetReferenceSelector);
2260
2273
  return g.setUser(f), {
2261
2274
  ..._n(o, r, n.adapter),
@@ -2289,7 +2302,7 @@ export {
2289
2302
  W as DEFAULT_STYLE,
2290
2303
  se as NOT_ANNOTATABLE_CLASS,
2291
2304
  Z as NOT_ANNOTATABLE_SELECTOR,
2292
- B as Origin,
2305
+ R as Origin,
2293
2306
  bo as SelectionHandler,
2294
2307
  pn as UserSelectAction,
2295
2308
  Ao as W3CTextFormat,