@soomo/text-annotator 3.0.0-staging.54 → 3.0.0-staging.56

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.
@@ -265,22 +265,22 @@ const Ie = /* @__PURE__ */ Be(ke), Ut = (t, e = 10, n) => {
265
265
  const { store: i, selection: r, hover: a } = e;
266
266
  let s, l, f;
267
267
  const h = Ce(n), c = (O) => {
268
- const { x: R, y: m } = t.getBoundingClientRect(), v = i.getAt(O.clientX - R, O.clientY - m, l);
269
- v ? a.current !== v.id && (t.classList.add("hovered"), a.set(v.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
268
+ const { x: R, y: m } = t.getBoundingClientRect(), A = i.getAt(O.clientX - R, O.clientY - m, l);
269
+ A ? a.current !== A.id && (t.classList.add("hovered"), a.set(A.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
270
270
  };
271
271
  t.addEventListener("pointermove", c);
272
272
  const g = (O = !1) => {
273
273
  f && f.clear();
274
- const R = Se(t), { minX: m, minY: v, maxX: x, maxY: L } = R, B = l ? i.getIntersecting(m, v, x, L).filter(({ annotation: Y }) => l(Y)) : i.getIntersecting(m, v, x, L), M = r.selected.map(({ id: Y }) => Y), K = B.map(({ annotation: Y, rects: lt }) => {
274
+ const R = Se(t), { minX: m, minY: A, maxX: v, maxY: L } = R, B = l ? i.getIntersecting(m, A, v, L).filter(({ annotation: Y }) => l(Y)) : i.getIntersecting(m, A, v, L), M = r.selected.map(({ id: Y }) => Y), K = B.map(({ annotation: Y, rects: lt }) => {
275
275
  const Ae = M.includes(Y.id), xe = Y.id === a.current;
276
276
  return { annotation: Y, rects: lt, state: { selected: Ae, hover: xe } };
277
277
  });
278
278
  o.redraw(K, R, s, f, O), setTimeout(() => h(B.map(({ annotation: Y }) => Y)), 1);
279
279
  }, u = (O) => {
280
280
  f = O, g();
281
- }, A = (O) => {
281
+ }, x = (O) => {
282
282
  s = O, g();
283
- }, b = (O) => {
283
+ }, w = (O) => {
284
284
  l = O, g(!1);
285
285
  }, C = () => g();
286
286
  i.observe(C);
@@ -292,16 +292,16 @@ const Ie = /* @__PURE__ */ Be(ke), Ut = (t, e = 10, n) => {
292
292
  window.addEventListener("resize", y);
293
293
  const S = new ResizeObserver(y);
294
294
  S.observe(t);
295
- const E = { attributes: !0, childList: !0, subtree: !0 }, w = new MutationObserver((O) => {
295
+ const E = { attributes: !0, childList: !0, subtree: !0 }, b = new MutationObserver((O) => {
296
296
  O.every((m) => m.target === t || t.contains(m.target)) || g(!0);
297
297
  });
298
- return w.observe(document.body, E), {
298
+ return b.observe(document.body, E), {
299
299
  destroy: () => {
300
- t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(C), p(), document.removeEventListener("scroll", d), y.clear(), window.removeEventListener("resize", y), S.disconnect(), w.disconnect();
300
+ t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(C), p(), document.removeEventListener("scroll", d), y.clear(), window.removeEventListener("resize", y), S.disconnect(), b.disconnect();
301
301
  },
302
302
  redraw: g,
303
- setStyle: A,
304
- setFilter: b,
303
+ setStyle: x,
304
+ setFilter: w,
305
305
  setPainter: u,
306
306
  setVisible: o.setVisible
307
307
  };
@@ -317,25 +317,25 @@ const Ie = /* @__PURE__ */ Be(ke), Ut = (t, e = 10, n) => {
317
317
  const o = (s, l, f, h) => requestAnimationFrame(() => {
318
318
  const { width: c, height: g } = e;
319
319
  n.clearRect(-0.5, -0.5, c + 1, g + 1), h && h.clear();
320
- const { top: u, left: A } = l;
320
+ const { top: u, left: x } = l;
321
321
  [...s].sort((C, p) => {
322
322
  const { annotation: { target: { created: d } } } = C, { annotation: { target: { created: y } } } = p;
323
323
  return d.getTime() - y.getTime();
324
324
  }).forEach((C) => {
325
325
  var S;
326
- const p = f ? typeof f == "function" ? f(C.annotation, C.state) : f : (S = C.state) != null && S.selected ? yt : q, d = h && h.paint(C, l) || p, y = C.rects.map(({ x: E, y: w, width: T, height: O }) => ({
327
- x: E + A,
328
- y: w + u,
326
+ const p = f ? typeof f == "function" ? f(C.annotation, C.state) : f : (S = C.state) != null && S.selected ? yt : q, d = h && h.paint(C, l) || p, y = C.rects.map(({ x: E, y: b, width: T, height: O }) => ({
327
+ x: E + x,
328
+ y: b + u,
329
329
  width: T,
330
330
  height: O
331
331
  }));
332
332
  if (n.fillStyle = d.fill, n.globalAlpha = d.fillOpacity || 1, y.forEach(
333
- ({ x: E, y: w, width: T, height: O }) => n.fillRect(E, w, T, O)
333
+ ({ x: E, y: b, width: T, height: O }) => n.fillRect(E, b, T, O)
334
334
  ), d.underlineColor) {
335
335
  n.globalAlpha = 1, n.strokeStyle = d.underlineColor, n.lineWidth = d.underlineThickness ?? 1;
336
336
  const E = d.underlineOffset ?? 0;
337
- y.forEach(({ x: w, y: T, width: O, height: R }) => {
338
- n.beginPath(), n.moveTo(w, T + R + E), n.lineTo(w + O, T + R + E), n.stroke();
337
+ y.forEach(({ x: b, y: T, width: O, height: R }) => {
338
+ n.beginPath(), n.moveTo(b, T + R + E), n.lineTo(b + O, T + R + E), n.stroke();
339
339
  });
340
340
  }
341
341
  });
@@ -502,13 +502,13 @@ const nn = (t) => [
502
502
  const f = new Set(r.map((c) => c.annotation.id));
503
503
  Array.from(e).filter((c) => !f.has(c));
504
504
  const h = r.map((c) => {
505
- var A;
506
- const g = s ? typeof s == "function" ? s(c.annotation, c.state) : s : (A = c.state) != null && A.selected ? yt : q, u = l && l.paint(c, a) || g;
505
+ var x;
506
+ const g = s ? typeof s == "function" ? s(c.annotation, c.state) : s : (x = c.state) != null && x.selected ? yt : q, u = l && l.paint(c, a) || g;
507
507
  return `::highlight(_${c.annotation.id}) { ${nn(u)} }`;
508
508
  });
509
509
  t.innerHTML = h.join(`
510
510
  `), CSS.highlights.clear(), r.forEach(({ annotation: c }) => {
511
- const g = c.target.selector.map((A) => A.range), u = new Highlight(...g);
511
+ const g = c.target.selector.map((x) => x.range), u = new Highlight(...g);
512
512
  CSS.highlights.set(`_${c.id}`, u);
513
513
  }), e = f;
514
514
  }
@@ -550,15 +550,15 @@ const sn = (t, e) => {
550
550
  redraw: (a, s, l, f, h) => {
551
551
  const g = !(It(n, a) && h);
552
552
  if (!f && !g) return;
553
- g && (e.innerHTML = ""), [...a].sort((A, b) => {
554
- const { annotation: { target: { created: C } } } = A, { annotation: { target: { created: p } } } = b;
555
- return console.log(A.annotation), console.log(b.annotation), C && p ? C.getTime() - p.getTime() : 0;
556
- }).forEach((A) => {
557
- A.rects.map((b) => {
558
- const C = sn(b, a), p = Ee(A, s, l, f, C);
553
+ g && (e.innerHTML = ""), [...a].sort((x, w) => {
554
+ const { annotation: { target: { created: C } } } = x, { annotation: { target: { created: p } } } = w;
555
+ return C && p ? C.getTime() - p.getTime() : 0;
556
+ }).forEach((x) => {
557
+ x.rects.map((w) => {
558
+ const C = sn(w, a), p = Ee(x, s, l, f, C);
559
559
  if (g) {
560
560
  const d = document.createElement("span");
561
- d.className = "r6o-annotation", d.dataset.annotation = A.annotation.id, d.style.left = `${b.x}px`, d.style.top = `${b.y}px`, d.style.width = `${b.width}px`, d.style.height = `${b.height}px`, d.style.backgroundColor = P((p == null ? void 0 : p.fill) || q.fill).alpha((p == null ? void 0 : p.fillOpacity) === void 0 ? q.fillOpacity : p.fillOpacity).toHex(), p.underlineStyle && (d.style.borderStyle = p.underlineStyle), p.underlineColor && (d.style.borderColor = p.underlineColor), p.underlineThickness && (d.style.borderBottomWidth = `${p.underlineThickness}px`), p.underlineOffset && (d.style.paddingBottom = `${p.underlineOffset}px`), e.appendChild(d);
561
+ d.className = "r6o-annotation", d.dataset.annotation = x.annotation.id, d.style.left = `${w.x}px`, d.style.top = `${w.y}px`, d.style.width = `${w.width}px`, d.style.height = `${w.height}px`, d.style.backgroundColor = P((p == null ? void 0 : p.fill) || q.fill).alpha((p == null ? void 0 : p.fillOpacity) === void 0 ? q.fillOpacity : p.fillOpacity).toHex(), p.underlineStyle && (d.style.borderStyle = p.underlineStyle), p.underlineColor && (d.style.borderColor = p.underlineColor), p.underlineThickness && (d.style.borderBottomWidth = `${p.underlineThickness}px`), p.underlineOffset && (d.style.paddingBottom = `${p.underlineOffset}px`), e.appendChild(d);
562
562
  }
563
563
  });
564
564
  }), n = a;
@@ -674,40 +674,40 @@ const ft = { selected: [] }, mn = (t, e) => {
674
674
  }, l = (u) => {
675
675
  if (s())
676
676
  return !1;
677
- const A = typeof u == "string" ? u : u.id;
678
- return r.selected.some((b) => b.id === A);
679
- }, f = (u, A) => {
680
- const b = t.getAnnotation(u);
681
- if (!b) {
677
+ const x = typeof u == "string" ? u : u.id;
678
+ return r.selected.some((w) => w.id === x);
679
+ }, f = (u, x) => {
680
+ const w = t.getAnnotation(u);
681
+ if (!w) {
682
682
  console.warn("Invalid selection: " + u);
683
683
  return;
684
684
  }
685
- switch (Qt(b, i)) {
685
+ switch (Qt(w, i)) {
686
686
  case "EDIT":
687
- o({ selected: [{ id: u, editable: !0 }], event: A });
687
+ o({ selected: [{ id: u, editable: !0 }], event: x });
688
688
  break;
689
689
  case "SELECT":
690
- o({ selected: [{ id: u }], event: A });
690
+ o({ selected: [{ id: u }], event: x });
691
691
  break;
692
692
  default:
693
- o({ selected: [], event: A });
693
+ o({ selected: [], event: x });
694
694
  }
695
- }, h = (u, A) => {
696
- const b = Array.isArray(u) ? u : [u], C = b.map((p) => t.getAnnotation(p)).filter((p) => !!p);
695
+ }, h = (u, x) => {
696
+ const w = Array.isArray(u) ? u : [u], C = w.map((p) => t.getAnnotation(p)).filter((p) => !!p);
697
697
  o({
698
698
  selected: C.map((p) => {
699
- const d = A === void 0 ? Qt(p, i) === "EDIT" : A;
699
+ const d = x === void 0 ? Qt(p, i) === "EDIT" : x;
700
700
  return { id: p.id, editable: d };
701
701
  })
702
- }), C.length !== b.length && console.warn("Invalid selection", u);
702
+ }), C.length !== w.length && console.warn("Invalid selection", u);
703
703
  }, c = (u) => {
704
704
  if (s())
705
705
  return !1;
706
- const { selected: A } = r;
707
- A.some(({ id: b }) => u.includes(b)) && o({ selected: A.filter(({ id: b }) => !u.includes(b)) });
706
+ const { selected: x } = r;
707
+ x.some(({ id: w }) => u.includes(w)) && o({ selected: x.filter(({ id: w }) => !u.includes(w)) });
708
708
  }, g = (u) => i = u;
709
709
  return t.observe(
710
- ({ changes: u }) => c((u.deleted || []).map((A) => A.id))
710
+ ({ changes: u }) => c((u.deleted || []).map((x) => x.id))
711
711
  ), {
712
712
  get event() {
713
713
  return r ? r.event : null;
@@ -810,8 +810,8 @@ const Cn = (t, e) => {
810
810
  ...(t.updated || []).filter(({ newValue: c }) => !r.has(c.id)).map((c) => {
811
811
  const { oldValue: g, newValue: u } = c;
812
812
  if (a.has(u.id)) {
813
- const A = e.updated.find((b) => b.oldValue.id === u.id).newValue;
814
- return fe(g, A);
813
+ const x = e.updated.find((w) => w.oldValue.id === u.id).newValue;
814
+ return fe(g, x);
815
815
  } else
816
816
  return c;
817
817
  }),
@@ -833,71 +833,71 @@ const Cn = (t, e) => {
833
833
  }
834
834
  };
835
835
  }, On = (t) => t.id !== void 0, Tn = () => {
836
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (m, v = {}) => {
837
- n.push({ onChange: m, options: v });
836
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (m, A = {}) => {
837
+ n.push({ onChange: m, options: A });
838
838
  }, i = (m) => {
839
- const v = n.findIndex((x) => x.onChange == m);
840
- v > -1 && n.splice(v, 1);
841
- }, r = (m, v) => {
842
- const x = {
839
+ const A = n.findIndex((v) => v.onChange == m);
840
+ A > -1 && n.splice(A, 1);
841
+ }, r = (m, A) => {
842
+ const v = {
843
843
  origin: m,
844
844
  changes: {
845
- created: v.created || [],
846
- updated: v.updated || [],
847
- deleted: v.deleted || []
845
+ created: A.created || [],
846
+ updated: A.updated || [],
847
+ deleted: A.deleted || []
848
848
  },
849
849
  state: [...t.values()]
850
850
  };
851
851
  n.forEach((L) => {
852
- Cn(L, x) && L.onChange(x);
852
+ Cn(L, v) && L.onChange(v);
853
853
  });
854
- }, a = (m, v = k.LOCAL) => {
854
+ }, a = (m, A = k.LOCAL) => {
855
855
  if (m.id && t.get(m.id))
856
856
  throw Error(`Cannot add annotation ${m.id} - exists already`);
857
857
  {
858
- const x = Lt(m);
859
- t.set(x.id, x), x.bodies.forEach((L) => e.set(L.id, x.id)), r(v, { created: [x] });
858
+ const v = Lt(m);
859
+ t.set(v.id, v), v.bodies.forEach((L) => e.set(L.id, v.id)), r(A, { created: [v] });
860
860
  }
861
- }, s = (m, v) => {
862
- const x = Lt(typeof m == "string" ? v : m), L = typeof m == "string" ? m : m.id, B = L && t.get(L);
861
+ }, s = (m, A) => {
862
+ const v = Lt(typeof m == "string" ? A : m), L = typeof m == "string" ? m : m.id, B = L && t.get(L);
863
863
  if (B) {
864
- const M = fe(B, x);
865
- return L === x.id ? t.set(L, x) : (t.delete(L), t.set(x.id, x)), B.bodies.forEach((K) => e.delete(K.id)), x.bodies.forEach((K) => e.set(K.id, x.id)), M;
864
+ const M = fe(B, v);
865
+ return L === v.id ? t.set(L, v) : (t.delete(L), t.set(v.id, v)), B.bodies.forEach((K) => e.delete(K.id)), v.bodies.forEach((K) => e.set(K.id, v.id)), M;
866
866
  } else
867
867
  console.warn(`Cannot update annotation ${L} - does not exist`);
868
- }, l = (m, v = k.LOCAL, x = k.LOCAL) => {
869
- const L = On(v) ? x : v, B = s(m, v);
868
+ }, l = (m, A = k.LOCAL, v = k.LOCAL) => {
869
+ const L = On(A) ? v : A, B = s(m, A);
870
870
  B && r(L, { updated: [B] });
871
- }, f = (m, v = k.LOCAL) => {
872
- const x = m.reduce((L, B) => {
871
+ }, f = (m, A = k.LOCAL) => {
872
+ const v = m.reduce((L, B) => {
873
873
  const M = s(B);
874
874
  return M ? [...L, M] : L;
875
875
  }, []);
876
- x.length > 0 && r(v, { updated: x });
877
- }, h = (m, v = k.LOCAL) => {
878
- const x = t.get(m.annotation);
879
- if (x) {
876
+ v.length > 0 && r(A, { updated: v });
877
+ }, h = (m, A = k.LOCAL) => {
878
+ const v = t.get(m.annotation);
879
+ if (v) {
880
880
  const L = {
881
- ...x,
882
- bodies: [...x.bodies, m]
881
+ ...v,
882
+ bodies: [...v.bodies, m]
883
883
  };
884
- t.set(x.id, L), e.set(m.id, L.id), r(v, { updated: [{
885
- oldValue: x,
884
+ t.set(v.id, L), e.set(m.id, L.id), r(A, { updated: [{
885
+ oldValue: v,
886
886
  newValue: L,
887
887
  bodiesCreated: [m]
888
888
  }] });
889
889
  } else
890
890
  console.warn(`Attempt to add body to missing annotation: ${m.annotation}`);
891
891
  }, c = () => [...t.values()], g = (m = k.LOCAL) => {
892
- const v = [...t.values()];
893
- t.clear(), e.clear(), r(m, { deleted: v });
894
- }, u = (m, v = !0, x = k.LOCAL) => {
892
+ const A = [...t.values()];
893
+ t.clear(), e.clear(), r(m, { deleted: A });
894
+ }, u = (m, A = !0, v = k.LOCAL) => {
895
895
  const L = m.map(Lt);
896
- if (v) {
896
+ if (A) {
897
897
  const B = [...t.values()];
898
898
  t.clear(), e.clear(), L.forEach((M) => {
899
899
  t.set(M.id, M), M.bodies.forEach((K) => e.set(K.id, M.id));
900
- }), r(x, { created: L, deleted: B });
900
+ }), r(v, { created: L, deleted: B });
901
901
  } else {
902
902
  const B = m.reduce((M, K) => {
903
903
  const Y = K.id && t.get(K.id);
@@ -907,96 +907,96 @@ const Cn = (t, e) => {
907
907
  throw Error(`Bulk insert would overwrite the following annotations: ${B.map((M) => M.id).join(", ")}`);
908
908
  L.forEach((M) => {
909
909
  t.set(M.id, M), M.bodies.forEach((K) => e.set(K.id, M.id));
910
- }), r(x, { created: L });
910
+ }), r(v, { created: L });
911
911
  }
912
- }, A = (m) => {
913
- const v = typeof m == "string" ? m : m.id, x = t.get(v);
914
- if (x)
915
- return t.delete(v), x.bodies.forEach((L) => e.delete(L.id)), x;
916
- console.warn(`Attempt to delete missing annotation: ${v}`);
917
- }, b = (m, v = k.LOCAL) => {
918
- const x = A(m);
919
- x && r(v, { deleted: [x] });
920
- }, C = (m, v = k.LOCAL) => {
921
- const x = m.reduce((L, B) => {
922
- const M = A(B);
912
+ }, x = (m) => {
913
+ const A = typeof m == "string" ? m : m.id, v = t.get(A);
914
+ if (v)
915
+ return t.delete(A), v.bodies.forEach((L) => e.delete(L.id)), v;
916
+ console.warn(`Attempt to delete missing annotation: ${A}`);
917
+ }, w = (m, A = k.LOCAL) => {
918
+ const v = x(m);
919
+ v && r(A, { deleted: [v] });
920
+ }, C = (m, A = k.LOCAL) => {
921
+ const v = m.reduce((L, B) => {
922
+ const M = x(B);
923
923
  return M ? [...L, M] : L;
924
924
  }, []);
925
- x.length > 0 && r(v, { deleted: x });
925
+ v.length > 0 && r(A, { deleted: v });
926
926
  }, p = (m) => {
927
- const v = t.get(m.annotation);
928
- if (v) {
929
- const x = v.bodies.find((L) => L.id === m.id);
930
- if (x) {
931
- e.delete(x.id);
927
+ const A = t.get(m.annotation);
928
+ if (A) {
929
+ const v = A.bodies.find((L) => L.id === m.id);
930
+ if (v) {
931
+ e.delete(v.id);
932
932
  const L = {
933
- ...v,
934
- bodies: v.bodies.filter((B) => B.id !== m.id)
933
+ ...A,
934
+ bodies: A.bodies.filter((B) => B.id !== m.id)
935
935
  };
936
- return t.set(v.id, L), {
937
- oldValue: v,
936
+ return t.set(A.id, L), {
937
+ oldValue: A,
938
938
  newValue: L,
939
- bodiesDeleted: [x]
939
+ bodiesDeleted: [v]
940
940
  };
941
941
  } else
942
942
  console.warn(`Attempt to delete missing body ${m.id} from annotation ${m.annotation}`);
943
943
  } else
944
944
  console.warn(`Attempt to delete body from missing annotation ${m.annotation}`);
945
- }, d = (m, v = k.LOCAL) => {
946
- const x = p(m);
947
- x && r(v, { updated: [x] });
948
- }, y = (m, v = k.LOCAL) => {
949
- const x = m.map((L) => p(L)).filter(Boolean);
950
- x.length > 0 && r(v, { updated: x });
945
+ }, d = (m, A = k.LOCAL) => {
946
+ const v = p(m);
947
+ v && r(A, { updated: [v] });
948
+ }, y = (m, A = k.LOCAL) => {
949
+ const v = m.map((L) => p(L)).filter(Boolean);
950
+ v.length > 0 && r(A, { updated: v });
951
951
  }, S = (m) => {
952
- const v = t.get(m);
953
- return v ? { ...v } : void 0;
952
+ const A = t.get(m);
953
+ return A ? { ...A } : void 0;
954
954
  }, E = (m) => {
955
- const v = e.get(m);
956
- if (v) {
957
- const x = S(v).bodies.find((L) => L.id === m);
958
- if (x)
959
- return x;
955
+ const A = e.get(m);
956
+ if (A) {
957
+ const v = S(A).bodies.find((L) => L.id === m);
958
+ if (v)
959
+ return v;
960
960
  console.error(`Store integrity error: body ${m} in index, but not in annotation`);
961
961
  } else
962
962
  console.warn(`Attempt to retrieve missing body: ${m}`);
963
- }, w = (m, v) => {
964
- if (m.annotation !== v.annotation)
963
+ }, b = (m, A) => {
964
+ if (m.annotation !== A.annotation)
965
965
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
966
- const x = t.get(m.annotation);
967
- if (x) {
968
- const L = x.bodies.find((M) => M.id === m.id), B = {
969
- ...x,
970
- bodies: x.bodies.map((M) => M.id === L.id ? v : M)
966
+ const v = t.get(m.annotation);
967
+ if (v) {
968
+ const L = v.bodies.find((M) => M.id === m.id), B = {
969
+ ...v,
970
+ bodies: v.bodies.map((M) => M.id === L.id ? A : M)
971
971
  };
972
- return t.set(x.id, B), L.id !== v.id && (e.delete(L.id), e.set(v.id, B.id)), {
973
- oldValue: x,
972
+ return t.set(v.id, B), L.id !== A.id && (e.delete(L.id), e.set(A.id, B.id)), {
973
+ oldValue: v,
974
974
  newValue: B,
975
- bodiesUpdated: [{ oldBody: L, newBody: v }]
975
+ bodiesUpdated: [{ oldBody: L, newBody: A }]
976
976
  };
977
977
  } else
978
978
  console.warn(`Attempt to add body to missing annotation ${m.annotation}`);
979
- }, T = (m, v, x = k.LOCAL) => {
980
- const L = w(m, v);
981
- L && r(x, { updated: [L] });
982
- }, O = (m, v = k.LOCAL) => {
983
- const x = m.map((L) => w({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
984
- r(v, { updated: x });
979
+ }, T = (m, A, v = k.LOCAL) => {
980
+ const L = b(m, A);
981
+ L && r(v, { updated: [L] });
982
+ }, O = (m, A = k.LOCAL) => {
983
+ const v = m.map((L) => b({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
984
+ r(A, { updated: v });
985
985
  }, R = (m) => {
986
- const v = t.get(m.annotation);
987
- if (v) {
988
- const x = {
989
- ...v,
986
+ const A = t.get(m.annotation);
987
+ if (A) {
988
+ const v = {
989
+ ...A,
990
990
  target: {
991
- ...v.target,
991
+ ...A.target,
992
992
  ...m
993
993
  }
994
994
  };
995
- return t.set(v.id, x), {
996
- oldValue: v,
997
- newValue: x,
995
+ return t.set(A.id, v), {
996
+ oldValue: A,
997
+ newValue: v,
998
998
  targetUpdated: {
999
- oldTarget: v.target,
999
+ oldTarget: A.target,
1000
1000
  newTarget: m
1001
1001
  }
1002
1002
  };
@@ -1012,12 +1012,12 @@ const Cn = (t, e) => {
1012
1012
  bulkDeleteBodies: y,
1013
1013
  bulkUpdateAnnotation: f,
1014
1014
  bulkUpdateBodies: O,
1015
- bulkUpdateTargets: (m, v = k.LOCAL) => {
1016
- const x = m.map((L) => R(L)).filter(Boolean);
1017
- x.length > 0 && r(v, { updated: x });
1015
+ bulkUpdateTargets: (m, A = k.LOCAL) => {
1016
+ const v = m.map((L) => R(L)).filter(Boolean);
1017
+ v.length > 0 && r(A, { updated: v });
1018
1018
  },
1019
1019
  clear: g,
1020
- deleteAnnotation: b,
1020
+ deleteAnnotation: w,
1021
1021
  deleteBody: d,
1022
1022
  getAnnotation: S,
1023
1023
  getBody: E,
@@ -1025,9 +1025,9 @@ const Cn = (t, e) => {
1025
1025
  unobserve: i,
1026
1026
  updateAnnotation: l,
1027
1027
  updateBody: T,
1028
- updateTarget: (m, v = k.LOCAL) => {
1029
- const x = R(m);
1030
- x && r(v, { updated: [x] });
1028
+ updateTarget: (m, A = k.LOCAL) => {
1029
+ const v = R(m);
1030
+ v && r(A, { updated: [v] });
1031
1031
  }
1032
1032
  };
1033
1033
  };
@@ -1050,36 +1050,36 @@ const Mn = 250, Bn = (t) => {
1050
1050
  let o = -1, i = !1, r = 0;
1051
1051
  const a = (u) => {
1052
1052
  if (!i) {
1053
- const { changes: A } = u, b = performance.now();
1054
- if (b - r > Mn)
1055
- n.splice(o + 1), n.push(A), o = n.length - 1;
1053
+ const { changes: x } = u, w = performance.now();
1054
+ if (w - r > Mn)
1055
+ n.splice(o + 1), n.push(x), o = n.length - 1;
1056
1056
  else {
1057
1057
  const C = n.length - 1;
1058
- n[C] = Ln(n[C], A);
1058
+ n[C] = Ln(n[C], x);
1059
1059
  }
1060
- r = b;
1060
+ r = w;
1061
1061
  }
1062
1062
  i = !1;
1063
1063
  };
1064
1064
  t.observe(a, { origin: k.LOCAL });
1065
- const s = (u) => u && u.length > 0 && t.bulkDeleteAnnotation(u), l = (u) => u && u.length > 0 && t.bulkAddAnnotation(u, !1), f = (u) => u && u.length > 0 && t.bulkUpdateAnnotation(u.map(({ oldValue: A }) => A)), h = (u) => u && u.length > 0 && t.bulkUpdateAnnotation(u.map(({ newValue: A }) => A)), c = (u) => u && u.length > 0 && t.bulkAddAnnotation(u, !1), g = (u) => u && u.length > 0 && t.bulkDeleteAnnotation(u);
1065
+ const s = (u) => u && u.length > 0 && t.bulkDeleteAnnotation(u), l = (u) => u && u.length > 0 && t.bulkAddAnnotation(u, !1), f = (u) => u && u.length > 0 && t.bulkUpdateAnnotation(u.map(({ oldValue: x }) => x)), h = (u) => u && u.length > 0 && t.bulkUpdateAnnotation(u.map(({ newValue: x }) => x)), c = (u) => u && u.length > 0 && t.bulkAddAnnotation(u, !1), g = (u) => u && u.length > 0 && t.bulkDeleteAnnotation(u);
1066
1066
  return {
1067
1067
  canRedo: () => n.length - 1 > o,
1068
1068
  canUndo: () => o > -1,
1069
1069
  destroy: () => t.unobserve(a),
1070
- on: (u, A) => e.on(u, A),
1070
+ on: (u, x) => e.on(u, x),
1071
1071
  redo: () => {
1072
1072
  if (n.length - 1 > o) {
1073
1073
  i = !0;
1074
- const { created: u, updated: A, deleted: b } = n[o + 1];
1075
- l(u), h(A), g(b), e.emit("redo", n[o + 1]), o += 1;
1074
+ const { created: u, updated: x, deleted: w } = n[o + 1];
1075
+ l(u), h(x), g(w), e.emit("redo", n[o + 1]), o += 1;
1076
1076
  }
1077
1077
  },
1078
1078
  undo: () => {
1079
1079
  if (o > -1) {
1080
1080
  i = !0;
1081
- const { created: u, updated: A, deleted: b } = n[o];
1082
- s(u), f(A), c(b), e.emit("undo", n[o]), o -= 1;
1081
+ const { created: u, updated: x, deleted: w } = n[o];
1082
+ s(u), f(x), c(w), e.emit("undo", n[o]), o -= 1;
1083
1083
  }
1084
1084
  }
1085
1085
  };
@@ -1092,17 +1092,17 @@ const Mn = 250, Bn = (t) => {
1092
1092
  }, In = (t, e, n, o) => {
1093
1093
  const { store: i, selection: r, hover: a, viewport: s } = t, l = /* @__PURE__ */ new Map();
1094
1094
  let f = [], h;
1095
- const c = (b, C) => {
1096
- l.has(b) ? l.get(b).push(C) : l.set(b, [C]);
1097
- }, g = (b, C) => {
1098
- const p = l.get(b);
1095
+ const c = (w, C) => {
1096
+ l.has(w) ? l.get(w).push(C) : l.set(w, [C]);
1097
+ }, g = (w, C) => {
1098
+ const p = l.get(w);
1099
1099
  if (p) {
1100
1100
  const d = p.indexOf(C);
1101
1101
  d !== -1 && p.splice(d, 1);
1102
1102
  }
1103
- }, u = (b, C, p) => {
1104
- l.has(b) && setTimeout(() => {
1105
- l.get(b).forEach((d) => {
1103
+ }, u = (w, C, p) => {
1104
+ l.has(w) && setTimeout(() => {
1105
+ l.get(w).forEach((d) => {
1106
1106
  if (n) {
1107
1107
  const y = Array.isArray(C) ? C.map((E) => n.serialize(E)) : n.serialize(C), S = p ? p instanceof PointerEvent ? p : n.serialize(p) : void 0;
1108
1108
  d(y, S);
@@ -1111,17 +1111,17 @@ const Mn = 250, Bn = (t) => {
1111
1111
  });
1112
1112
  }, 1);
1113
1113
  };
1114
- r.subscribe(({ selected: b }) => {
1115
- if (!(f.length === 0 && b.length === 0)) {
1116
- if (f.length === 0 && b.length > 0)
1117
- f = b.map(({ id: C }) => i.getAnnotation(C));
1118
- else if (f.length > 0 && b.length === 0)
1114
+ r.subscribe(({ selected: w }) => {
1115
+ if (!(f.length === 0 && w.length === 0)) {
1116
+ if (f.length === 0 && w.length > 0)
1117
+ f = w.map(({ id: C }) => i.getAnnotation(C));
1118
+ else if (f.length > 0 && w.length === 0)
1119
1119
  f.forEach((C) => {
1120
1120
  const p = i.getAnnotation(C.id);
1121
1121
  p && !G(p, C) && u("updateAnnotation", p, C);
1122
1122
  }), f = [];
1123
1123
  else {
1124
- const C = new Set(f.map((d) => d.id)), p = new Set(b.map(({ id: d }) => d));
1124
+ const C = new Set(f.map((d) => d.id)), p = new Set(w.map(({ id: d }) => d));
1125
1125
  f.filter((d) => !p.has(d.id)).forEach((d) => {
1126
1126
  const y = i.getAnnotation(d.id);
1127
1127
  y && !G(y, d) && u("updateAnnotation", y, d);
@@ -1129,16 +1129,16 @@ const Mn = 250, Bn = (t) => {
1129
1129
  // Remove annotations that were deselected
1130
1130
  ...f.filter((d) => p.has(d.id)),
1131
1131
  // Add editable annotations that were selected
1132
- ...b.filter(({ id: d }) => !C.has(d)).map(({ id: d }) => i.getAnnotation(d))
1132
+ ...w.filter(({ id: d }) => !C.has(d)).map(({ id: d }) => i.getAnnotation(d))
1133
1133
  ];
1134
1134
  }
1135
1135
  u("selectionChanged", f);
1136
1136
  }
1137
- }), a.subscribe((b) => {
1138
- !h && b ? u("mouseEnterAnnotation", i.getAnnotation(b)) : h && !b ? u("mouseLeaveAnnotation", i.getAnnotation(h)) : h && b && (u("mouseLeaveAnnotation", i.getAnnotation(h)), u("mouseEnterAnnotation", i.getAnnotation(b))), h = b;
1139
- }), s == null || s.subscribe((b) => u("viewportIntersect", b.map((C) => i.getAnnotation(C)))), i.observe((b) => {
1140
- const { created: C, deleted: p } = b.changes;
1141
- (C || []).forEach((d) => u("createAnnotation", d)), (p || []).forEach((d) => u("deleteAnnotation", d)), (b.changes.updated || []).filter((d) => [
1137
+ }), a.subscribe((w) => {
1138
+ !h && w ? u("mouseEnterAnnotation", i.getAnnotation(w)) : h && !w ? u("mouseLeaveAnnotation", i.getAnnotation(h)) : h && w && (u("mouseLeaveAnnotation", i.getAnnotation(h)), u("mouseEnterAnnotation", i.getAnnotation(w))), h = w;
1139
+ }), s == null || s.subscribe((w) => u("viewportIntersect", w.map((C) => i.getAnnotation(C)))), i.observe((w) => {
1140
+ const { created: C, deleted: p } = w.changes;
1141
+ (C || []).forEach((d) => u("createAnnotation", d)), (p || []).forEach((d) => u("deleteAnnotation", d)), (w.changes.updated || []).filter((d) => [
1142
1142
  ...d.bodiesCreated || [],
1143
1143
  ...d.bodiesDeleted || [],
1144
1144
  ...d.bodiesUpdated || []
@@ -1146,17 +1146,17 @@ const Mn = 250, Bn = (t) => {
1146
1146
  const S = f.find((E) => E.id === d.id) || d;
1147
1147
  f = f.map((E) => E.id === d.id ? y : E), u("updateAnnotation", y, S);
1148
1148
  });
1149
- }, { origin: k.LOCAL }), i.observe((b) => {
1149
+ }, { origin: k.LOCAL }), i.observe((w) => {
1150
1150
  if (f) {
1151
- const C = new Set(f.map((d) => d.id)), p = (b.changes.updated || []).filter(({ newValue: d }) => C.has(d.id)).map(({ newValue: d }) => d);
1151
+ const C = new Set(f.map((d) => d.id)), p = (w.changes.updated || []).filter(({ newValue: d }) => C.has(d.id)).map(({ newValue: d }) => d);
1152
1152
  p.length > 0 && (f = f.map((d) => p.find((S) => S.id === d.id) || d));
1153
1153
  }
1154
1154
  }, { origin: k.REMOTE });
1155
- const A = (b) => (C) => {
1155
+ const x = (w) => (C) => {
1156
1156
  const { updated: p } = C;
1157
- b ? (p || []).forEach((d) => u("updateAnnotation", d.oldValue, d.newValue)) : (p || []).forEach((d) => u("updateAnnotation", d.newValue, d.oldValue));
1157
+ w ? (p || []).forEach((d) => u("updateAnnotation", d.oldValue, d.newValue)) : (p || []).forEach((d) => u("updateAnnotation", d.newValue, d.oldValue));
1158
1158
  };
1159
- return e.on("undo", A(!0)), e.on("redo", A(!1)), { on: c, off: g, emit: u };
1159
+ return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: c, off: g, emit: u };
1160
1160
  }, Nn = (t) => (e) => e.reduce((n, o) => {
1161
1161
  const { parsed: i, error: r } = t.parse(o);
1162
1162
  return r ? {
@@ -1198,9 +1198,9 @@ const Mn = 250, Bn = (t) => {
1198
1198
  S.length > 0 && console.warn(`Discarded ${S.length} invalid annotations`, S), o.bulkAddAnnotation(y, d, k.REMOTE);
1199
1199
  } else
1200
1200
  o.bulkAddAnnotation(p, d, k.REMOTE);
1201
- }, A = (p, d) => {
1201
+ }, x = (p, d) => {
1202
1202
  p ? i.setSelected(p, d) : i.clear();
1203
- }, b = (p) => {
1203
+ }, w = (p) => {
1204
1204
  i.clear(), i.setUserSelectAction(p);
1205
1205
  }, C = (p) => {
1206
1206
  if (n) {
@@ -1224,8 +1224,8 @@ const Mn = 250, Bn = (t) => {
1224
1224
  redo: e.redo,
1225
1225
  removeAnnotation: g,
1226
1226
  setAnnotations: u,
1227
- setSelected: A,
1228
- setUserSelectAction: b,
1227
+ setSelected: x,
1228
+ setUserSelectAction: w,
1229
1229
  undo: e.undo,
1230
1230
  updateAnnotation: C
1231
1231
  };
@@ -1345,15 +1345,15 @@ const Lo = (t, e) => ({
1345
1345
  updated: f,
1346
1346
  ...h
1347
1347
  } = i, c = a.map((g) => {
1348
- const { quote: u, start: A, end: b, range: C } = g, { prefix: p, suffix: d } = Ne(C, n), y = [{
1348
+ const { quote: u, start: x, end: w, range: C } = g, { prefix: p, suffix: d } = Ne(C, n), y = [{
1349
1349
  type: "TextQuoteSelector",
1350
1350
  exact: u,
1351
1351
  prefix: p,
1352
1352
  suffix: d
1353
1353
  }, {
1354
1354
  type: "TextPositionSelector",
1355
- start: A,
1356
- end: b
1355
+ start: x,
1356
+ end: w
1357
1357
  }];
1358
1358
  return {
1359
1359
  ...h,
@@ -1377,8 +1377,8 @@ const Lo = (t, e) => ({
1377
1377
  function ge(t, e, n = 0, o = t.length - 1, i = qn) {
1378
1378
  for (; o > n; ) {
1379
1379
  if (o - n > 600) {
1380
- const l = o - n + 1, f = e - n + 1, h = Math.log(l), c = 0.5 * Math.exp(2 * h / 3), g = 0.5 * Math.sqrt(h * c * (l - c) / l) * (f - l / 2 < 0 ? -1 : 1), u = Math.max(n, Math.floor(e - f * c / l + g)), A = Math.min(o, Math.floor(e + (l - f) * c / l + g));
1381
- ge(t, e, u, A, i);
1380
+ const l = o - n + 1, f = e - n + 1, h = Math.log(l), c = 0.5 * Math.exp(2 * h / 3), g = 0.5 * Math.sqrt(h * c * (l - c) / l) * (f - l / 2 < 0 ? -1 : 1), u = Math.max(n, Math.floor(e - f * c / l + g)), x = Math.min(o, Math.floor(e + (l - f) * c / l + g));
1381
+ ge(t, e, u, x, i);
1382
1382
  }
1383
1383
  const r = t[e];
1384
1384
  let a = n, s = o;
@@ -1661,17 +1661,17 @@ const oo = (t, e) => {
1661
1661
  const E = y.selector.flatMap((T) => {
1662
1662
  const O = W([T]) ? T.range : se(T, e).range;
1663
1663
  return Array.from(O.getClientRects());
1664
- }), w = Ke(E).map((T) => Pe(T, S));
1665
- return w.map((T) => {
1666
- const { x: O, y: R, width: m, height: v } = T;
1664
+ }), b = Ke(E).map((T) => Pe(T, S));
1665
+ return b.map((T) => {
1666
+ const { x: O, y: R, width: m, height: A } = T;
1667
1667
  return {
1668
1668
  minX: O,
1669
1669
  minY: R,
1670
1670
  maxX: O + m,
1671
- maxY: R + v,
1671
+ maxY: R + A,
1672
1672
  annotation: {
1673
1673
  id: y.annotation,
1674
- rects: w
1674
+ rects: b
1675
1675
  }
1676
1676
  };
1677
1677
  });
@@ -1687,29 +1687,29 @@ const oo = (t, e) => {
1687
1687
  f(y), l(y);
1688
1688
  }, c = (y, S = !0) => {
1689
1689
  S && s();
1690
- const E = e.getBoundingClientRect(), w = y.map((O) => ({ target: O, rects: r(O, E) }));
1691
- w.forEach(({ target: O, rects: R }) => o.set(O.annotation, R));
1692
- const T = w.flatMap(({ rects: O }) => O);
1690
+ const E = e.getBoundingClientRect(), b = y.map((O) => ({ target: O, rects: r(O, E) }));
1691
+ b.forEach(({ target: O, rects: R }) => o.set(O.annotation, R));
1692
+ const T = b.flatMap(({ rects: O }) => O);
1693
1693
  n.load(T);
1694
1694
  }, g = (y, S, E = !1) => {
1695
- const w = n.search({
1695
+ const b = n.search({
1696
1696
  minX: y,
1697
1697
  minY: S,
1698
1698
  maxX: y,
1699
1699
  maxY: S
1700
1700
  }), T = (O) => O.annotation.rects.reduce((R, m) => R + m.width * m.height, 0);
1701
- return w.length > 0 ? (w.sort((O, R) => T(O) - T(R)), E ? w.map((O) => O.annotation.id) : [w[0].annotation.id]) : [];
1701
+ return b.length > 0 ? (b.sort((O, R) => T(O) - T(R)), E ? b.map((O) => O.annotation.id) : [b[0].annotation.id]) : [];
1702
1702
  }, u = (y) => {
1703
- const S = A(y);
1703
+ const S = x(y);
1704
1704
  if (S.length === 0)
1705
1705
  return;
1706
- let E = S[0].left, w = S[0].top, T = S[0].right, O = S[0].bottom;
1706
+ let E = S[0].left, b = S[0].top, T = S[0].right, O = S[0].bottom;
1707
1707
  for (let R = 1; R < S.length; R++) {
1708
1708
  const m = S[R];
1709
- E = Math.min(E, m.left), w = Math.min(w, m.top), T = Math.max(T, m.right), O = Math.max(O, m.bottom);
1709
+ E = Math.min(E, m.left), b = Math.min(b, m.top), T = Math.max(T, m.right), O = Math.max(O, m.bottom);
1710
1710
  }
1711
- return new DOMRect(E, w, T - E, O - w);
1712
- }, A = (y) => {
1711
+ return new DOMRect(E, b, T - E, O - b);
1712
+ }, x = (y) => {
1713
1713
  const S = o.get(y);
1714
1714
  return S ? S[0].annotation.rects : [];
1715
1715
  };
@@ -1718,12 +1718,12 @@ const oo = (t, e) => {
1718
1718
  clear: s,
1719
1719
  getAt: g,
1720
1720
  getAnnotationBounds: u,
1721
- getAnnotationRects: A,
1722
- getIntersecting: (y, S, E, w) => {
1723
- const T = n.search({ minX: y, minY: S, maxX: E, maxY: w }), O = new Set(T.map((R) => R.annotation.id));
1721
+ getAnnotationRects: x,
1722
+ getIntersecting: (y, S, E, b) => {
1723
+ const T = n.search({ minX: y, minY: S, maxX: E, maxY: b }), O = new Set(T.map((R) => R.annotation.id));
1724
1724
  return Array.from(O).map((R) => ({
1725
1725
  annotation: t.getAnnotation(R),
1726
- rects: A(R)
1726
+ rects: x(R)
1727
1727
  })).filter((R) => !!R.annotation);
1728
1728
  },
1729
1729
  insert: l,
@@ -1743,12 +1743,12 @@ const oo = (t, e) => {
1743
1743
  const S = wt(d, t), E = W(S.target.selector);
1744
1744
  return E && n.addAnnotation(S, y), E;
1745
1745
  }, l = (d, y = !0, S = k.LOCAL) => {
1746
- const E = d.map((T) => wt(T, t)), w = E.filter((T) => !W(T.target.selector));
1747
- return w.length > 0 ? (console.warn("Could not revive all targets for these annotations:", w), n.bulkAddAnnotation(E, y, S), w) : (n.bulkAddAnnotation(E, y, S), []);
1746
+ const E = d.map((T) => wt(T, t)), b = E.filter((T) => !W(T.target.selector));
1747
+ return b.length > 0 ? (console.warn("Could not revive all targets for these annotations:", b), n.bulkAddAnnotation(E, y, S), b) : (n.bulkAddAnnotation(E, y, S), []);
1748
1748
  }, f = (d, y = k.LOCAL) => {
1749
- const S = d.map((w) => wt(w, t)), E = S.filter((w) => !W(w.target.selector));
1750
- return E.length > 0 && console.warn("Could not revive all targets for these annotations:", E), S.forEach((w) => {
1751
- n.getAnnotation(w.id) ? n.updateAnnotation(w, y) : n.addAnnotation(w, y);
1749
+ const S = d.map((b) => wt(b, t)), E = S.filter((b) => !W(b.target.selector));
1750
+ return E.length > 0 && console.warn("Could not revive all targets for these annotations:", E), S.forEach((b) => {
1751
+ n.getAnnotation(b.id) ? n.updateAnnotation(b, y) : n.addAnnotation(b, y);
1752
1752
  }), E;
1753
1753
  }, h = (d, y = k.LOCAL) => {
1754
1754
  const S = bt(d, t);
@@ -1757,21 +1757,21 @@ const oo = (t, e) => {
1757
1757
  const S = d.map((E) => bt(E, t));
1758
1758
  n.bulkUpdateTargets(S, y);
1759
1759
  }, g = (d, y, S) => {
1760
- const E = o.getAt(d, y, !!S).map((T) => n.getAnnotation(T)), w = S ? E.filter(S) : E;
1761
- return w.length > 0 ? w[0] : void 0;
1760
+ const E = o.getAt(d, y, !!S).map((T) => n.getAnnotation(T)), b = S ? E.filter(S) : E;
1761
+ return b.length > 0 ? b[0] : void 0;
1762
1762
  }, u = (d, y, S, E = 5) => {
1763
- const w = o.getAnnotationRects(d);
1764
- if (w.length !== 0) {
1763
+ const b = o.getAnnotationRects(d);
1764
+ if (b.length !== 0) {
1765
1765
  if (y && S) {
1766
- const T = w.find(({ top: O, right: R, bottom: m, left: v }) => y >= v - E && y <= R + E && S >= O - E && S <= m + E);
1766
+ const T = b.find(({ top: O, right: R, bottom: m, left: A }) => y >= A - E && y <= R + E && S >= O - E && S <= m + E);
1767
1767
  if (T) return T;
1768
1768
  }
1769
1769
  return o.getAnnotationBounds(d);
1770
1770
  }
1771
- }, A = (d, y, S, E) => o.getIntersecting(d, y, S, E), b = (d) => o.getAnnotationRects(d), C = () => o.recalculate(), p = (d) => o.on("recalculate", d);
1771
+ }, x = (d, y, S, E) => o.getIntersecting(d, y, S, E), w = (d) => o.getAnnotationRects(d), C = () => o.recalculate(), p = (d) => o.on("recalculate", d);
1772
1772
  return n.observe(({ changes: d }) => {
1773
- const y = (d.deleted || []).filter((w) => W(w.target.selector)), S = (d.created || []).filter((w) => W(w.target.selector)), E = (d.updated || []).filter((w) => W(w.newValue.target.selector));
1774
- (y == null ? void 0 : y.length) > 0 && y.forEach((w) => o.remove(w.target)), S.length > 0 && o.set(S.map((w) => w.target), !1), (E == null ? void 0 : E.length) > 0 && E.forEach(({ newValue: w }) => o.update(w.target));
1773
+ const y = (d.deleted || []).filter((b) => W(b.target.selector)), S = (d.created || []).filter((b) => W(b.target.selector)), E = (d.updated || []).filter((b) => W(b.newValue.target.selector));
1774
+ (y == null ? void 0 : y.length) > 0 && y.forEach((b) => o.remove(b.target)), S.length > 0 && o.set(S.map((b) => b.target), !1), (E == null ? void 0 : E.length) > 0 && E.forEach(({ newValue: b }) => o.update(b.target));
1775
1775
  }), {
1776
1776
  store: {
1777
1777
  ...n,
@@ -1780,8 +1780,8 @@ const oo = (t, e) => {
1780
1780
  bulkUpdateTargets: c,
1781
1781
  bulkUpsertAnnotations: f,
1782
1782
  getAnnotationBounds: u,
1783
- getAnnotationRects: b,
1784
- getIntersecting: A,
1783
+ getAnnotationRects: w,
1784
+ getIntersecting: x,
1785
1785
  getAt: g,
1786
1786
  recalculatePositions: C,
1787
1787
  onRecalculatePositions: p,
@@ -2005,8 +2005,8 @@ const mt = (t) => {
2005
2005
  n || (n = at());
2006
2006
  const c = l > 1 ? pe(H, s) : [], g = [];
2007
2007
  N[h] = N[h].filter((u) => {
2008
- const b = (o ? u.method === o : !0) && u.scope === n && ro(u.mods, c);
2009
- return b && g.push(u.element), !b;
2008
+ const w = (o ? u.method === o : !0) && u.scope === n && ro(u.mods, c);
2009
+ return w && g.push(u.element), !w;
2010
2010
  }), g.forEach((u) => Kt(u));
2011
2011
  });
2012
2012
  };
@@ -2072,17 +2072,17 @@ function $(t, e, n) {
2072
2072
  if (typeof a < "u" && window) {
2073
2073
  if (!F.has(a)) {
2074
2074
  const u = function() {
2075
- let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2076
- return ee(b, a);
2077
- }, A = function() {
2078
- let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2079
- ee(b, a), po(b);
2075
+ let w = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2076
+ return ee(w, a);
2077
+ }, x = function() {
2078
+ let w = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2079
+ ee(w, a), po(w);
2080
2080
  };
2081
2081
  F.set(a, {
2082
2082
  keydownListener: u,
2083
- keyupListenr: A,
2083
+ keyupListenr: x,
2084
2084
  capture: c
2085
- }), Mt(a, "keydown", u, c), Mt(a, "keyup", A, c);
2085
+ }), Mt(a, "keydown", u, c), Mt(a, "keyup", x, c);
2086
2086
  }
2087
2087
  if (!rt) {
2088
2088
  const u = () => {
@@ -2156,24 +2156,24 @@ if (typeof window < "u") {
2156
2156
  }
2157
2157
  const ne = 300, yo = (t, e, n) => {
2158
2158
  let o;
2159
- const i = (w) => o = w;
2159
+ const i = (b) => o = b;
2160
2160
  let r;
2161
- const a = (w) => r = w;
2161
+ const a = (b) => r = b;
2162
2162
  let s = !0;
2163
- const l = (w) => {
2164
- s = w, b.clear(), w || (c = void 0, g = void 0, u = void 0);
2163
+ const l = (b) => {
2164
+ s = b, w.clear(), b || (c = void 0, g = void 0, u = void 0);
2165
2165
  }, { store: f, selection: h } = e;
2166
2166
  let c, g, u;
2167
- const A = (w) => {
2167
+ const x = (b) => {
2168
2168
  var O;
2169
2169
  if (!s || g === !1) return;
2170
- c = !((O = w.target.parentElement) != null && O.closest(j)) ? {
2170
+ c = !((O = b.target.parentElement) != null && O.closest(j)) ? {
2171
2171
  annotation: de(),
2172
2172
  selector: [],
2173
2173
  creator: o,
2174
2174
  created: /* @__PURE__ */ new Date()
2175
2175
  } : void 0;
2176
- }, b = Ut((w) => {
2176
+ }, w = Ut((b) => {
2177
2177
  var B, M;
2178
2178
  if (!s) return;
2179
2179
  const T = document.getSelection();
@@ -2181,62 +2181,61 @@ const ne = 300, yo = (t, e, n) => {
2181
2181
  c = void 0;
2182
2182
  return;
2183
2183
  }
2184
- const R = w.timeStamp - ((u == null ? void 0 : u.timeStamp) || w.timeStamp);
2185
- if ((u == null ? void 0 : u.type) === "pointerdown" && (R < 1e3 && !c || T.isCollapsed && R < ne) && A(u), !c) return;
2184
+ const R = b.timeStamp - ((u == null ? void 0 : u.timeStamp) || b.timeStamp);
2185
+ if ((u == null ? void 0 : u.type) === "pointerdown" && (R < 1e3 && !c || T.isCollapsed && R < ne) && x(u), !c) return;
2186
2186
  if (T.isCollapsed) {
2187
2187
  f.getAnnotation(c.annotation) && (h.clear(), f.deleteAnnotation(c.annotation));
2188
2188
  return;
2189
2189
  }
2190
- const m = T.getRangeAt(0), v = Xe(m, t);
2191
- if (Ue(v)) return;
2192
- const x = Te(v.cloneRange());
2193
- (x.length !== c.selector.length || x.some((K, Y) => {
2190
+ const m = T.getRangeAt(0), A = Xe(m, t);
2191
+ if (Ue(A)) return;
2192
+ const v = Te(A.cloneRange());
2193
+ (v.length !== c.selector.length || v.some((K, Y) => {
2194
2194
  var lt;
2195
2195
  return K.toString() !== ((lt = c.selector[Y]) == null ? void 0 : lt.quote);
2196
2196
  })) && (c = {
2197
2197
  ...c,
2198
- selector: x.map((K) => Ye(K, t, n)),
2198
+ selector: v.map((K) => Ye(K, t, n)),
2199
2199
  updated: /* @__PURE__ */ new Date()
2200
2200
  }, f.getAnnotation(c.annotation) ? f.updateTarget(c, k.LOCAL) : (h.clear(), f.addAnnotation({
2201
2201
  id: c.annotation,
2202
2202
  bodies: [],
2203
2203
  target: c
2204
2204
  }, k.LOCAL), h.userSelect(c.annotation, u)));
2205
- }), C = (w) => {
2206
- u = $e(w), g = u.button === 0;
2207
- }, p = (w) => {
2208
- var m;
2209
- if (!!((m = w.target.parentElement) != null && m.closest(j)) || !g)
2205
+ }), C = (b) => {
2206
+ u = $e(b), g = u.button === 0;
2207
+ }, p = (b) => {
2208
+ var A;
2209
+ const T = b.target;
2210
+ if (!!((A = T.parentElement) != null && A.closest(j)) || !g)
2210
2211
  return;
2211
- const O = () => {
2212
- const { x: v, y: x } = t.getBoundingClientRect(), L = w.target instanceof Node && t.contains(w.target) && f.getAt(w.clientX - v, w.clientY - x, r);
2213
- if (L) {
2214
- const { selected: B } = h;
2215
- (B.length !== 1 || B[0].id !== L.id) && h.userSelect(L.id, w);
2212
+ const R = () => {
2213
+ const { x: v, y: L } = t.getBoundingClientRect(), B = b.target instanceof Node && t.contains(b.target) && f.getAt(b.clientX - v, b.clientY - L, r);
2214
+ if (B) {
2215
+ const { selected: M } = h;
2216
+ (M.length !== 1 || M[0].id !== B.id) && h.userSelect(B.id, b);
2216
2217
  } else h.isEmpty() || h.clear();
2217
- };
2218
- document.getSelection();
2219
- const R = w.timeStamp - u.timeStamp;
2218
+ }, m = b.timeStamp - u.timeStamp;
2220
2219
  setTimeout(() => {
2221
2220
  const v = document.getSelection();
2222
- v != null && v.isCollapsed && R < ne ? (c = void 0, O()) : c && f.getAnnotation(c.annotation) && h.userSelect(c.annotation, w);
2221
+ v != null && v.isCollapsed && m < ne ? T !== document.documentElement && (c = void 0, R()) : c && f.getAnnotation(c.annotation) && h.userSelect(c.annotation, b);
2223
2222
  });
2224
2223
  };
2225
- document.addEventListener("pointerdown", C), document.addEventListener("pointerup", p), t.addEventListener("selectstart", A), document.addEventListener("selectionchange", b);
2224
+ document.addEventListener("pointerdown", C), document.addEventListener("pointerup", p), t.addEventListener("selectstart", x), document.addEventListener("selectionchange", w);
2226
2225
  const d = ["up", "down", "left", "right"], y = [
2227
- ...d.map((w) => `shift+${w}`),
2226
+ ...d.map((b) => `shift+${b}`),
2228
2227
  "ctrl+a",
2229
2228
  "⌘+a"
2230
2229
  ];
2231
- $(y.join(","), { element: t, keydown: !0, keyup: !1 }, (w) => {
2232
- w.repeat || (u = je(w));
2230
+ $(y.join(","), { element: t, keydown: !0, keyup: !1 }, (b) => {
2231
+ b.repeat || (u = je(b));
2233
2232
  });
2234
- const S = (w) => {
2235
- w.repeat || w.target !== t && w.target !== document.body || (c = void 0, h.clear());
2233
+ const S = (b) => {
2234
+ b.repeat || b.target !== t && b.target !== document.body || (c = void 0, h.clear());
2236
2235
  };
2237
2236
  return $(d.join(","), { keydown: !0, keyup: !1 }, S), {
2238
2237
  destroy: () => {
2239
- c = void 0, g = void 0, u = void 0, b.clear(), document.removeEventListener("pointerdown", C), document.removeEventListener("pointerup", p), t.removeEventListener("selectstart", A), document.removeEventListener("selectionchange", b), $.unbind();
2238
+ c = void 0, g = void 0, u = void 0, w.clear(), document.removeEventListener("pointerdown", C), document.removeEventListener("pointerup", p), t.removeEventListener("selectstart", x), document.removeEventListener("selectionchange", w), $.unbind();
2240
2239
  },
2241
2240
  setFilter: a,
2242
2241
  setUser: i,
@@ -2252,7 +2251,7 @@ const ne = 300, yo = (t, e, n) => {
2252
2251
  document.body.appendChild(o);
2253
2252
  const r = /* @__PURE__ */ new Map(), a = (c) => Array.from(r.entries()).filter(([g, u]) => u.presenceKey === c.presenceKey).map(([g, u]) => g);
2254
2253
  return e.on("selectionChange", (c, g) => {
2255
- a(c).forEach((A) => r.delete(A)), g && g.forEach((A) => r.set(A, c));
2254
+ a(c).forEach((x) => r.delete(x)), g && g.forEach((x) => r.set(x, c));
2256
2255
  }), {
2257
2256
  clear: () => {
2258
2257
  const { width: c, height: g } = o;
@@ -2263,13 +2262,13 @@ const ne = 300, yo = (t, e, n) => {
2263
2262
  },
2264
2263
  paint: (c, g, u) => {
2265
2264
  n.font && (i.font = n.font);
2266
- const A = r.get(c.annotation.id);
2267
- if (A) {
2268
- const { height: b } = c.rects[0], C = c.rects[0].x + g.left, p = c.rects[0].y + g.top;
2269
- i.fillStyle = A.appearance.color, i.fillRect(C - 2, p - 2.5, 2, b + 5);
2270
- const d = i.measureText(A.appearance.label), y = d.width + 6, S = d.actualBoundingBoxAscent + d.actualBoundingBoxDescent + 8, E = d.fontBoundingBoxAscent ? 8 : 6.5;
2271
- return i.fillRect(C - 2, p - 2.5 - S, y, S), i.fillStyle = "#fff", i.fillText(A.appearance.label, C + 1, p - E), {
2272
- fill: A.appearance.color,
2265
+ const x = r.get(c.annotation.id);
2266
+ if (x) {
2267
+ const { height: w } = c.rects[0], C = c.rects[0].x + g.left, p = c.rects[0].y + g.top;
2268
+ i.fillStyle = x.appearance.color, i.fillRect(C - 2, p - 2.5, 2, w + 5);
2269
+ const d = i.measureText(x.appearance.label), y = d.width + 6, S = d.actualBoundingBoxAscent + d.actualBoundingBoxDescent + 8, E = d.fontBoundingBoxAscent ? 8 : 6.5;
2270
+ return i.fillRect(C - 2, p - 2.5 - S, y, S), i.fillStyle = "#fff", i.fillText(x.appearance.label, C + 1, p - E), {
2271
+ fill: x.appearance.color,
2273
2272
  fillOpacity: u ? 0.45 : 0.18
2274
2273
  };
2275
2274
  }
@@ -2287,7 +2286,7 @@ const ne = 300, yo = (t, e, n) => {
2287
2286
  return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ve(t.parentElement);
2288
2287
  }, vo = (t, e) => (n) => {
2289
2288
  const o = typeof n == "string" ? n : n.id, i = (a) => {
2290
- const s = r.getBoundingClientRect(), l = r.clientHeight, f = r.clientWidth, h = a.selector[0].range.getBoundingClientRect(), { width: c, height: g } = e.getAnnotationBounds(o), u = h.top - s.top, A = h.left - s.left, b = r.parentElement ? r.scrollTop : 0, C = r.parentElement ? r.scrollLeft : 0, p = u + b - (l - g) / 2, d = A + C - (f - c) / 2;
2289
+ const s = r.getBoundingClientRect(), l = r.clientHeight, f = r.clientWidth, h = a.selector[0].range.getBoundingClientRect(), { width: c, height: g } = e.getAnnotationBounds(o), u = h.top - s.top, x = h.left - s.left, w = r.parentElement ? r.scrollTop : 0, C = r.parentElement ? r.scrollLeft : 0, p = u + w - (l - g) / 2, d = x + C - (f - c) / 2;
2291
2290
  r.scroll({ top: p, left: d, behavior: "smooth" });
2292
2291
  }, r = ve(t);
2293
2292
  if (r) {
@@ -2318,7 +2317,7 @@ const ne = 300, yo = (t, e, n) => {
2318
2317
  console.debug(`Using ${h} renderer`), n.style && c.setStyle(n.style);
2319
2318
  const g = yo(t, o, n.offsetReferenceSelector);
2320
2319
  g.setUser(f), g.setAnnotatingEnabled(n.annotatingEnabled);
2321
- const u = _n(o, s, n.adapter), A = () => f, b = (E) => {
2320
+ const u = _n(o, s, n.adapter), x = () => f, w = (E) => {
2322
2321
  g.setAnnotatingEnabled(
2323
2322
  E === void 0 ? !0 : E
2324
2323
  );
@@ -2337,8 +2336,8 @@ const ne = 300, yo = (t, e, n) => {
2337
2336
  c.destroy(), g.destroy(), s.destroy();
2338
2337
  },
2339
2338
  element: t,
2340
- getUser: A,
2341
- setAnnotatingEnabled: b,
2339
+ getUser: x,
2340
+ setAnnotatingEnabled: w,
2342
2341
  setFilter: C,
2343
2342
  setStyle: c.setStyle.bind(c),
2344
2343
  redraw: c.redraw.bind(c),