@recogito/text-annotator 4.0.1-beta → 4.0.3-beta

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.
@@ -26,7 +26,7 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
26
26
  const e = document.createNodeIterator(
27
27
  t.commonAncestorContainer,
28
28
  NodeFilter.SHOW_ELEMENT,
29
- (i) => i instanceof HTMLElement && i.classList.contains(ft) && !i.parentElement.closest(Y) && t.intersectsNode(i) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
29
+ (i) => i instanceof HTMLElement && i.classList.contains(ft) && !i.parentElement?.closest(Y) && t.intersectsNode(i) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
30
30
  );
31
31
  let o;
32
32
  for (; o = e.nextNode(); )
@@ -55,7 +55,7 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
55
55
  n.setStart(s, 0), n.setEnd(t.startContainer, t.startOffset);
56
56
  const r = nt(n).textContent, a = document.createRange();
57
57
  a.setStart(t.endContainer, t.endOffset), s === document.body ? a.setEnd(s, s.childNodes.length) : a.setEndAfter(s);
58
- const d = nt(a).textContent, g = [...rt.segment(r)], m = [...rt.segment(d)];
58
+ const u = nt(a).textContent, g = [...rt.segment(r)], m = [...rt.segment(u)];
59
59
  return {
60
60
  prefix: g.slice(-o).map((b) => b.segment).join(""),
61
61
  suffix: m.slice(0, o).map((b) => b.segment).join("")
@@ -63,8 +63,8 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
63
63
  }, Wt = (t, e, o) => {
64
64
  const i = document.createRange(), s = o ? t.startContainer.parentElement.closest(o) : e;
65
65
  i.setStart(s, 0), i.setEnd(t.startContainer, t.startOffset);
66
- const n = nt(i).textContent, r = t.toString(), a = n.length || 0, d = a + r.length;
67
- return o ? { quote: r, start: a, end: d, range: t, offsetReference: s } : { quote: r, start: a, end: d, range: t };
66
+ const n = nt(i).textContent, r = t.toString(), a = n.length || 0, u = a + r.length;
67
+ return o ? { quote: r, start: a, end: u, range: t, offsetReference: s } : { quote: r, start: a, end: u, range: t };
68
68
  }, D = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), pt = (t, e) => {
69
69
  const { start: o, end: i } = t, s = t.offsetReference || e, n = document.createNodeIterator(
70
70
  e,
@@ -73,27 +73,27 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
73
73
  );
74
74
  let r = 0;
75
75
  const a = document.createRange();
76
- let d = n.nextNode();
77
- d === null && console.error("Could not revive annotation target. Content missing.");
76
+ let u = n.nextNode();
77
+ u === null && console.error("Could not revive annotation target. Content missing.");
78
78
  let g = !s;
79
- for (; d !== null; ) {
80
- if (g ||= typeof s?.contains == "function" ? s.contains(d) : !1, g) {
81
- const m = d.textContent?.length || 0;
79
+ for (; u !== null; ) {
80
+ if (g ||= typeof s?.contains == "function" ? s.contains(u) : !1, g) {
81
+ const m = u.textContent?.length || 0;
82
82
  if (r + m > o) {
83
- a.setStart(d, o - r);
83
+ a.setStart(u, o - r);
84
84
  break;
85
85
  }
86
86
  r += m;
87
87
  }
88
- d = n.nextNode();
88
+ u = n.nextNode();
89
89
  }
90
- for (; d !== null; ) {
91
- const m = d.textContent?.length || 0;
90
+ for (; u !== null; ) {
91
+ const m = u.textContent?.length || 0;
92
92
  if (r + m >= i) {
93
- a.setEnd(d, i - r);
93
+ a.setEnd(u, i - r);
94
94
  break;
95
95
  }
96
- r += m, d = n.nextNode();
96
+ r += m, u = n.nextNode();
97
97
  }
98
98
  return {
99
99
  ...t,
@@ -108,8 +108,8 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
108
108
  const { overflowY: e } = window.getComputedStyle(t);
109
109
  return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ht(t.parentElement);
110
110
  }, it = (t, e, o) => {
111
- const i = o.getBoundingClientRect(), s = o.clientHeight, n = o.clientWidth, r = e.selector[0].range.getBoundingClientRect(), { width: a, height: d } = t.getAnnotationBounds(e.annotation), g = r.top - i.top, m = r.left - i.left, b = o.parentElement ? o.scrollTop : 0, h = o.parentElement ? o.scrollLeft : 0, T = g + b - (s - d) / 2, u = m + h - (n - a) / 2;
112
- o.scroll({ top: T, left: u, behavior: "smooth" });
111
+ const i = o.getBoundingClientRect(), s = o.clientHeight, n = o.clientWidth, r = e.selector[0].range.getBoundingClientRect(), { width: a, height: u } = t.getAnnotationBounds(e.annotation), g = r.top - i.top, m = r.left - i.left, b = o.parentElement ? o.scrollTop : 0, h = o.parentElement ? o.scrollLeft : 0, T = g + b - (s - u) / 2, l = m + h - (n - a) / 2;
112
+ o.scroll({ top: T, left: l, behavior: "smooth" });
113
113
  }, Xt = (t, e) => (o, i) => {
114
114
  const s = typeof o == "string" ? o : o.id, n = i ? typeof i == "string" ? document.getElementById(i) : i : ht(t);
115
115
  if (!n)
@@ -120,8 +120,8 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
120
120
  const { range: a } = r.target.selector[0];
121
121
  if (a && !a.collapsed)
122
122
  return it(e, r.target, n), !0;
123
- const d = Q(r.target, t), { range: g } = d.selector[0];
124
- return g && !g.collapsed ? (it(e, d, n), !0) : !1;
123
+ const u = Q(r.target, t), { range: g } = u.selector[0];
124
+ return g && !g.collapsed ? (it(e, u, n), !0) : !1;
125
125
  }, xe = (t, e) => ({
126
126
  parse: (o) => jt(o),
127
127
  serialize: (o) => qt(o, t, e)
@@ -144,8 +144,8 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
144
144
  // @ts-expect-error: `styleClass` is not part of the core `TextAnnotationTarget` type
145
145
  styleClass: "styleClass" in r[0] ? r[0].styleClass : void 0
146
146
  };
147
- for (const d of r) {
148
- const m = (Array.isArray(d.selector) ? d.selector : [d.selector]).reduce((b, h) => {
147
+ for (const u of r) {
148
+ const m = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((b, h) => {
149
149
  switch (h.type) {
150
150
  case "TextQuoteSelector":
151
151
  b.quote = h.exact;
@@ -160,9 +160,9 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
160
160
  a.selector.push(
161
161
  {
162
162
  ...m,
163
- id: d.id,
163
+ id: u.id,
164
164
  // @ts-expect-error: `scope` is not part of the core `TextSelector` type
165
- scope: d.scope
165
+ scope: u.scope
166
166
  }
167
167
  );
168
168
  else {
@@ -181,26 +181,26 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
181
181
  modified: s,
182
182
  body: n,
183
183
  ...r
184
- } = t, a = Ct(n, e), d = zt(t);
185
- return "error" in d ? { error: d.error } : {
184
+ } = t, a = Ct(n, e), u = zt(t);
185
+ return "error" in u ? { error: u.error } : {
186
186
  parsed: {
187
187
  ...r,
188
188
  id: e,
189
189
  bodies: a,
190
- target: d.parsed
190
+ target: u.parsed
191
191
  }
192
192
  };
193
193
  }, qt = (t, e, o) => {
194
194
  const { bodies: i, target: s, ...n } = t, {
195
195
  selector: r,
196
196
  creator: a,
197
- created: d,
197
+ created: u,
198
198
  updated: g,
199
199
  ...m
200
200
  } = s, b = r.map((h) => {
201
- const { id: T, quote: u, start: L, end: x, range: v } = h, p = {
201
+ const { id: T, quote: l, start: L, end: x, range: v } = h, p = {
202
202
  type: "TextQuoteSelector",
203
- exact: u
203
+ exact: l
204
204
  };
205
205
  if (o) {
206
206
  const { prefix: w, suffix: c } = Yt(v, o);
@@ -227,7 +227,7 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
227
227
  type: "Annotation",
228
228
  body: At(t.bodies),
229
229
  creator: a,
230
- created: d?.toISOString(),
230
+ created: u?.toISOString(),
231
231
  modified: g?.toISOString(),
232
232
  target: b
233
233
  };
@@ -283,31 +283,31 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
283
283
  });
284
284
  }, yt = (t, e, o, i) => {
285
285
  const { store: s, selection: n, hover: r } = o, a = dt();
286
- let d;
286
+ let u;
287
287
  const g = /* @__PURE__ */ new Map();
288
288
  let m;
289
- const b = ae(i), h = (y) => {
290
- const { x: C, y: O } = e.getBoundingClientRect(), B = s.getAt(y.clientX - C, y.clientY - O, !1, m);
289
+ const b = ae(i), h = (S) => {
290
+ const { x: C, y: O } = e.getBoundingClientRect(), B = s.getAt(S.clientX - C, S.clientY - O, !1, m);
291
291
  B && o.selection.evalSelectAction(B) !== Rt.NONE ? r.current !== B.id && (e.classList.add("hovered"), r.set(B.id)) : r.current && (e.classList.remove("hovered"), r.set(null));
292
292
  };
293
293
  e.addEventListener("pointermove", h);
294
- const T = tt((y = !1) => requestAnimationFrame(() => {
295
- const C = ie(e), { minX: O, minY: B, maxX: V, maxY: z } = C, K = m ? s.getIntersecting(O, B, V, z).filter(({ annotation: S }) => m(S)) : s.getIntersecting(O, B, V, z), st = n.selected.map(({ id: S }) => S), f = K.map(({ annotation: S, rects: M }) => {
296
- const U = st.includes(S.id), I = S.id === r.current;
294
+ const T = tt((S = !1) => requestAnimationFrame(() => {
295
+ const C = ie(e), { minX: O, minY: B, maxX: V, maxY: z } = C, K = m ? s.getIntersecting(O, B, V, z).filter(({ annotation: y }) => m?.(y)) : s.getIntersecting(O, B, V, z), st = n.selected.map(({ id: y }) => y), f = K.map(({ annotation: y, rects: M }) => {
296
+ const U = st.includes(y.id), I = y.id === r.current;
297
297
  return {
298
- annotation: S,
298
+ annotation: y,
299
299
  rects: M,
300
300
  state: { selected: U, hovered: I }
301
301
  };
302
302
  });
303
- t.redraw(f, C, d, g, y), setTimeout(() => {
304
- b(K.map(({ annotation: S }) => S)), a.emit("onRedraw");
303
+ t.redraw(f, C, u, g, S), setTimeout(() => {
304
+ b(K.map(({ annotation: y }) => y)), a.emit("onRedraw");
305
305
  }, 1);
306
- }), 10), u = (y, C) => {
307
- C ? y ? g.set(C, y) : g.delete(C) : d = y, T(!0);
308
- }, L = (y) => {
309
- m = y, T(!1);
310
- }, x = (y, C) => a.on(y, C), v = () => {
306
+ }), 10), l = (S, C) => {
307
+ C ? S ? g.set(C, S) : g.delete(C) : u = S, T(!0);
308
+ }, L = (S) => {
309
+ m = S, T(!1);
310
+ }, x = (S, C) => a.on(S, C), v = () => {
311
311
  T();
312
312
  };
313
313
  s.observe(v);
@@ -323,18 +323,18 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
323
323
  s.recalculatePositions(), T();
324
324
  }, 10);
325
325
  window.addEventListener("resize", c);
326
- const l = new ResizeObserver(c);
327
- l.observe(e);
328
- const A = { attributes: !0, childList: !0, subtree: !0 }, R = new MutationObserver(tt((y) => {
329
- y.every((O) => O.target === e || e.contains(O.target)) || T(!0);
326
+ const d = new ResizeObserver(c);
327
+ d.observe(e);
328
+ const A = { attributes: !0, childList: !0, subtree: !0 }, R = new MutationObserver(tt((S) => {
329
+ S.every((O) => O.target === e || e.contains(O.target)) || T(!0);
330
330
  }, 150));
331
331
  return R.observe(document.body, A), {
332
332
  destroy: () => {
333
- e.removeEventListener("pointermove", h), t.destroy(), s.unobserve(v), p(), E(), document.removeEventListener("scroll", w), window.removeEventListener("resize", c), l.disconnect(), R.disconnect();
333
+ e.removeEventListener("pointermove", h), t.destroy(), s.unobserve(v), p(), E(), document.removeEventListener("scroll", w), window.removeEventListener("resize", c), d.disconnect(), R.disconnect();
334
334
  },
335
335
  on: x,
336
336
  redraw: T,
337
- setStyle: u,
337
+ setStyle: l,
338
338
  setFilter: L,
339
339
  setVisible: t.setVisible.bind(t)
340
340
  };
@@ -372,13 +372,13 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
372
372
  const g = t.endContainer.childNodes[t.endOffset];
373
373
  g ? a.setEndBefore(g) : a.setEndAfter(t.endContainer);
374
374
  }
375
- const d = (g) => {
375
+ const u = (g) => {
376
376
  const m = document.createRange();
377
377
  return m.selectNode(g), Array.from(m.getClientRects());
378
378
  };
379
379
  return [
380
380
  ...Array.from(r.getClientRects()),
381
- ...e.slice(1, -1).flatMap(d),
381
+ ...e.slice(1, -1).flatMap(u),
382
382
  ...Array.from(a.getClientRects())
383
383
  ];
384
384
  }
@@ -414,17 +414,17 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
414
414
  return i;
415
415
  let n = [...i], r = !1;
416
416
  for (const a of i) {
417
- const d = te(s, a, e, o);
418
- if (d === "inline-adjacent") {
417
+ const u = te(s, a, e, o);
418
+ if (u === "inline-adjacent") {
419
419
  n = n.map((g) => g === a ? ee(s, a) : g), r = !0;
420
420
  break;
421
- } else if (d === "inline-contains") {
421
+ } else if (u === "inline-contains") {
422
422
  n = n.map((g) => g === a ? s : g), r = !0;
423
423
  break;
424
- } else if (d === "inline-is-contained") {
424
+ } else if (u === "inline-is-contained") {
425
425
  r = !0;
426
426
  break;
427
- } else if (d === "block-contains" || d === "block-is-contained") {
427
+ } else if (u === "block-contains" || u === "block-is-contained") {
428
428
  s.width < a.width && (n = n.map((g) => g === a ? s : g)), s.width === a.width && s.height < a.width && (n = n.map((g) => g === a ? s : g)), r = !0;
429
429
  break;
430
430
  }
@@ -452,16 +452,16 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
452
452
  destroy: () => {
453
453
  e.remove();
454
454
  },
455
- redraw: (r, a, d, g, m) => {
455
+ redraw: (r, a, u, g, m) => {
456
456
  if (!(!Bt(o, r) || m)) return;
457
- e.innerHTML = "", [...r].sort((u, L) => {
458
- const { annotation: { target: { created: x } } } = u, { annotation: { target: { created: v } } } = L;
457
+ e.innerHTML = "", [...r].sort((l, L) => {
458
+ const { annotation: { target: { created: x } } } = l, { annotation: { target: { created: v } } } = L;
459
459
  return x && v ? x.getTime() - v.getTime() : 0;
460
- }).forEach((u) => {
461
- const L = g.get(u.annotation.id) || d;
462
- u.rects.map((x) => {
463
- const v = Zt(x, r), p = St(u, L, v), E = document.createElement("span");
464
- E.className = "r6o-annotation", E.dataset.annotation = u.annotation.id, E.style.left = `${x.x}px`, E.style.top = `${x.y}px`, E.style.width = `${x.width}px`, E.style.height = `${x.height}px`, E.style.backgroundColor = Qt(p), p.underlineStyle && (E.style.borderStyle = p.underlineStyle), p.underlineColor && (E.style.borderColor = p.underlineColor), p.underlineThickness && (E.style.borderBottomWidth = `${p.underlineThickness}px`), p.underlineOffset && (E.style.paddingBottom = `${p.underlineOffset}px`), e.appendChild(E);
460
+ }).forEach((l) => {
461
+ const L = g?.get(l.annotation.id) || u;
462
+ l.rects.map((x) => {
463
+ const v = Zt(x, r), p = St(l, L, v), E = document.createElement("span");
464
+ E.className = "r6o-annotation", E.dataset.annotation = l.annotation.id, E.style.left = `${x.x}px`, E.style.top = `${x.y}px`, E.style.width = `${x.width}px`, E.style.height = `${x.height}px`, E.style.backgroundColor = Qt(p), p.underlineStyle && (E.style.borderStyle = p.underlineStyle), p.underlineColor && (E.style.borderColor = p.underlineColor), p.underlineThickness && (E.style.borderBottomWidth = `${p.underlineThickness}px`), p.underlineOffset && (E.style.paddingBottom = `${p.underlineOffset}px`), e.appendChild(E);
465
465
  });
466
466
  }), o = r;
467
467
  },
@@ -470,8 +470,8 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
470
470
  }
471
471
  };
472
472
  }, re = (t, e, o) => yt(se(t), t, e, o), ie = (t) => {
473
- const { top: e, left: o } = t.getBoundingClientRect(), { innerWidth: i, innerHeight: s } = window, n = -o, r = -e, a = i - o, d = s - e;
474
- return { top: e, left: o, minX: n, minY: r, maxX: a, maxY: d };
473
+ const { top: e, left: o } = t.getBoundingClientRect(), { innerWidth: i, innerHeight: s } = window, n = -o, r = -e, a = i - o, u = s - e;
474
+ return { top: e, left: o, minX: n, minY: r, maxX: a, maxY: u };
475
475
  }, ae = (t) => {
476
476
  let e = /* @__PURE__ */ new Set();
477
477
  return (i) => {
@@ -479,17 +479,17 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
479
479
  (e.size !== s.length || s.some((n) => !e.has(n))) && t.set(s), e = new Set(s);
480
480
  };
481
481
  }, ce = (t, e, o, i) => {
482
- const s = new It(), n = /* @__PURE__ */ new Map(), r = dt(), a = (c, l) => {
482
+ const s = new It(), n = /* @__PURE__ */ new Map(), r = dt(), a = (c, d) => {
483
483
  const A = c.selector.flatMap((N) => {
484
- const y = D([N]) ? N.range : pt(N, e).range;
485
- return Jt(y);
486
- }), R = ne(A, o, i).map((N) => oe(N, l));
484
+ const S = D([N]) ? N.range : pt(N, e).range;
485
+ return Jt(S);
486
+ }), R = ne(A, o, i).map((N) => oe(N, d));
487
487
  return R.map((N) => {
488
- const { x: y, y: C, width: O, height: B } = N;
488
+ const { x: S, y: C, width: O, height: B } = N;
489
489
  return {
490
- minX: y,
490
+ minX: S,
491
491
  minY: C,
492
- maxX: y + O,
492
+ maxX: S + O,
493
493
  maxY: C + B,
494
494
  annotation: {
495
495
  id: c.annotation,
@@ -497,55 +497,55 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
497
497
  }
498
498
  };
499
499
  });
500
- }, d = () => [...n.values()], g = () => {
500
+ }, u = () => [...n.values()], g = () => {
501
501
  s.clear(), n.clear();
502
502
  }, m = (c) => {
503
- const l = a(c, e.getBoundingClientRect());
504
- l.length !== 0 && (l.forEach((A) => s.insert(A)), n.set(c.annotation, l));
503
+ const d = a(c, e.getBoundingClientRect());
504
+ d.length !== 0 && (d.forEach((A) => s.insert(A)), n.set(c.annotation, d));
505
505
  }, b = (c) => {
506
- const l = n.get(c.annotation);
507
- l && (l.forEach((A) => s.remove(A)), n.delete(c.annotation));
506
+ const d = n.get(c.annotation);
507
+ d && (d.forEach((A) => s.remove(A)), n.delete(c.annotation));
508
508
  }, h = (c) => {
509
509
  b(c), m(c);
510
- }, T = (c, l = !0) => {
511
- l && g();
512
- const A = e.getBoundingClientRect(), R = c.map((y) => ({ target: y, rects: a(y, A) }));
513
- R.forEach(({ target: y, rects: C }) => {
514
- C.length > 0 && n.set(y.annotation, C);
510
+ }, T = (c, d = !0) => {
511
+ d && g();
512
+ const A = e.getBoundingClientRect(), R = c.map((S) => ({ target: S, rects: a(S, A) }));
513
+ R.forEach(({ target: S, rects: C }) => {
514
+ C.length > 0 && n.set(S.annotation, C);
515
515
  });
516
- const N = R.flatMap(({ rects: y }) => y);
516
+ const N = R.flatMap(({ rects: S }) => S);
517
517
  s.load(N);
518
- }, u = (c, l, A = !1) => {
518
+ }, l = (c, d, A = !1) => {
519
519
  const R = s.search({
520
520
  minX: c,
521
- minY: l,
521
+ minY: d,
522
522
  maxX: c,
523
- maxY: l
524
- }), N = (y) => y.annotation.rects.reduce((C, O) => C + O.width * O.height, 0);
525
- return R.length > 0 ? (R.sort((y, C) => N(y) - N(C)), A ? R.map((y) => y.annotation.id) : [R[0].annotation.id]) : [];
523
+ maxY: d
524
+ }), N = (S) => S.annotation.rects.reduce((C, O) => C + O.width * O.height, 0);
525
+ return R.length > 0 ? (R.sort((S, C) => N(S) - N(C)), A ? R.map((S) => S.annotation.id) : [R[0].annotation.id]) : [];
526
526
  }, L = (c) => {
527
- const l = x(c);
528
- if (l.length === 0)
527
+ const d = x(c);
528
+ if (d.length === 0)
529
529
  return;
530
- let A = l[0].left, R = l[0].top, N = l[0].right, y = l[0].bottom;
531
- for (let C = 1; C < l.length; C++) {
532
- const O = l[C];
533
- A = Math.min(A, O.left), R = Math.min(R, O.top), N = Math.max(N, O.right), y = Math.max(y, O.bottom);
530
+ let A = d[0].left, R = d[0].top, N = d[0].right, S = d[0].bottom;
531
+ for (let C = 1; C < d.length; C++) {
532
+ const O = d[C];
533
+ A = Math.min(A, O.left), R = Math.min(R, O.top), N = Math.max(N, O.right), S = Math.max(S, O.bottom);
534
534
  }
535
- return new DOMRect(A, R, N - A, y - R);
535
+ return new DOMRect(A, R, N - A, S - R);
536
536
  }, x = (c) => {
537
- const l = n.get(c);
538
- return l ? l[0].annotation.rects : [];
537
+ const d = n.get(c);
538
+ return d ? d[0].annotation.rects : [];
539
539
  };
540
540
  return {
541
- all: d,
541
+ all: u,
542
542
  clear: g,
543
- getAt: u,
543
+ getAt: l,
544
544
  getAnnotationBounds: L,
545
545
  getAnnotationRects: x,
546
- getIntersecting: (c, l, A, R) => {
547
- const N = s.search({ minX: c, minY: l, maxX: A, maxY: R }), y = new Set(N.map((C) => C.annotation.id));
548
- return Array.from(y).map((C) => ({
546
+ getIntersecting: (c, d, A, R) => {
547
+ const N = s.search({ minX: c, minY: d, maxX: A, maxY: R }), S = new Set(N.map((C) => C.annotation.id));
548
+ return Array.from(S).map((C) => ({
549
549
  annotation: t.getAnnotation(C),
550
550
  rects: x(C)
551
551
  })).filter((C) => !!C.annotation);
@@ -558,19 +558,19 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
558
558
  set: T,
559
559
  size: () => s.all().length,
560
560
  update: h,
561
- on: (c, l) => r.on(c, l)
561
+ on: (c, d) => r.on(c, d)
562
562
  };
563
563
  }, le = (t, e) => {
564
564
  const o = vt(), i = ce(o, t, e.mergeHighlights?.horizontalTolerance, e.mergeHighlights?.verticalTolerance), s = wt(o, e.userSelectAction, e.adapter), n = xt(o), r = Lt(), a = (p, E = F.LOCAL) => {
565
565
  const w = Z(p, t), c = D(w.target.selector);
566
566
  return c && o.addAnnotation(w, E), c;
567
- }, d = (p, E = !0, w = F.LOCAL) => {
568
- const c = p.map((A) => Z(A, t)), l = c.filter((A) => !D(A.target.selector));
569
- return o.bulkAddAnnotations(c, E, w), l;
567
+ }, u = (p, E = !0, w = F.LOCAL) => {
568
+ const c = p.map((A) => Z(A, t)), d = c.filter((A) => !D(A.target.selector));
569
+ return o.bulkAddAnnotations(c, E, w), d;
570
570
  }, g = (p, E = F.LOCAL) => {
571
- const w = p.map((l) => Z(l, t)), c = w.filter((l) => !D(l.target.selector));
572
- return w.forEach((l) => {
573
- o.getAnnotation(l.id) ? o.updateAnnotation(l, E) : o.addAnnotation(l, E);
571
+ const w = p.map((d) => Z(d, t)), c = w.filter((d) => !D(d.target.selector));
572
+ return w.forEach((d) => {
573
+ o.getAnnotation(d.id) ? o.updateAnnotation(d, E) : o.addAnnotation(d, E);
574
574
  }), c;
575
575
  }, m = (p, E = F.LOCAL) => {
576
576
  const w = Q(p, t);
@@ -580,24 +580,24 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
580
580
  o.bulkUpdateTargets(w, E);
581
581
  };
582
582
  function h(p, E, w, c) {
583
- const l = w || !!c, A = i.getAt(p, E, l).map((N) => o.getAnnotation(N)), R = c ? A.filter(c) : A;
583
+ const d = w || !!c, A = i.getAt(p, E, d).map((N) => o.getAnnotation(N)).filter(Boolean), R = c ? A.filter(c) : A;
584
584
  if (R.length !== 0)
585
585
  return w ? R : R[0];
586
586
  }
587
- const T = (p) => i.getAnnotationRects(p).length > 0 ? i.getAnnotationBounds(p) : void 0, u = (p, E, w, c) => i.getIntersecting(p, E, w, c), L = (p) => i.getAnnotationRects(p), x = () => i.recalculate(), v = (p) => i.on("recalculate", p);
587
+ const T = (p) => i.getAnnotationRects(p).length > 0 ? i.getAnnotationBounds(p) : void 0, l = (p, E, w, c) => i.getIntersecting(p, E, w, c), L = (p) => i.getAnnotationRects(p), x = () => i.recalculate(), v = (p) => i.on("recalculate", p);
588
588
  return o.observe(({ changes: p }) => {
589
- const E = (p.deleted || []).filter((l) => D(l.target.selector)), w = (p.created || []).filter((l) => D(l.target.selector)), c = (p.updated || []).filter((l) => D(l.newValue.target.selector));
590
- E?.length > 0 && E.forEach((l) => i.remove(l.target)), w.length > 0 && i.set(w.map((l) => l.target), !1), c?.length > 0 && c.forEach(({ newValue: l }) => i.update(l.target));
589
+ const E = (p.deleted || []).filter((d) => D(d.target.selector)), w = (p.created || []).filter((d) => D(d.target.selector)), c = (p.updated || []).filter((d) => D(d.newValue.target.selector));
590
+ E?.length > 0 && E.forEach((d) => i.remove(d.target)), w.length > 0 && i.set(w.map((d) => d.target), !1), c?.length > 0 && c.forEach(({ newValue: d }) => i.update(d.target));
591
591
  }), {
592
592
  store: {
593
593
  ...o,
594
594
  addAnnotation: a,
595
- bulkAddAnnotations: d,
595
+ bulkAddAnnotations: u,
596
596
  bulkUpdateTargets: b,
597
597
  bulkUpsertAnnotations: g,
598
598
  getAnnotationBounds: T,
599
599
  getAnnotationRects: L,
600
- getIntersecting: u,
600
+ getIntersecting: l,
601
601
  getAt: h,
602
602
  recalculatePositions: x,
603
603
  onRecalculatePositions: v,
@@ -615,28 +615,28 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
615
615
  let r;
616
616
  const {
617
617
  annotatingEnabled: a,
618
- offsetReferenceSelector: d,
618
+ offsetReferenceSelector: u,
619
619
  selectionMode: g,
620
620
  dismissOnNotAnnotatable: m = "NEVER"
621
621
  } = i;
622
- let b, h = a, T = "CREATE_NEW", u, L, x, v;
622
+ let b, h = a, T = "CREATE_NEW", l, L, x, v;
623
623
  const p = (f) => {
624
- h = f, R.clear(), f || (L = void 0, u = void 0, x = void 0, v = void 0);
625
- }, E = (f) => T = f || "CREATE_NEW", w = (f) => b = f, c = (f) => r = f, l = (f) => {
624
+ h = f, R.clear(), f || (L = void 0, l = void 0, x = void 0, v = void 0);
625
+ }, E = (f) => T = f || "CREATE_NEW", w = (f) => b = f, c = (f) => r = f, d = (f) => {
626
626
  if (T === "ADD_TO_CURRENT")
627
627
  return !0;
628
628
  if (i.allowModifierSelect) {
629
- const S = f;
630
- return ut ? S.metaKey : S.ctrlKey;
629
+ const y = f;
630
+ return ut ? y.metaKey : y.ctrlKey;
631
631
  } else
632
632
  return !1;
633
633
  }, A = () => {
634
634
  if (!h || x === !1) return;
635
635
  const { selected: f } = n;
636
- if ((l(v) || T === "REPLACE_CURRENT") && f.length === 1 && f[0].editable) {
636
+ if ((d(v) || T === "REPLACE_CURRENT") && f.length === 1 && f[0].editable) {
637
637
  const M = s.getAnnotation(f[0].id);
638
638
  if (M?.target) {
639
- L = M.target, u = {
639
+ L = M.target, l = {
640
640
  annotation: M.id,
641
641
  selector: [],
642
642
  created: L.created,
@@ -647,7 +647,7 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
647
647
  return;
648
648
  }
649
649
  }
650
- L = void 0, u = {
650
+ L = void 0, l = {
651
651
  annotation: lt(),
652
652
  selector: [],
653
653
  created: /* @__PURE__ */ new Date(),
@@ -655,82 +655,85 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
655
655
  };
656
656
  }, R = _t((f) => {
657
657
  if (!h) return;
658
- const S = document.getSelection();
659
- if (!S?.anchorNode) return;
660
- const M = Array.from(Array(S.rangeCount).keys()).map((k) => S.getRangeAt(k));
658
+ const y = document.getSelection();
659
+ if (!y?.anchorNode) return;
660
+ const M = Array.from(Array(y.rangeCount).keys()).map((k) => y.getRangeAt(k));
661
661
  if (M.every((k) => !gt(t, k))) {
662
- u = void 0;
662
+ l = void 0;
663
663
  return;
664
664
  }
665
665
  const U = f.timeStamp - (v?.timeStamp || f.timeStamp);
666
- if (v?.type === "pointerdown" && (U < 1e3 && !u || S.isCollapsed && U < at) && A(), !u && (A(), !u))
666
+ if (v?.type === "pointerdown" && (U < 1e3 && !l || y.isCollapsed && U < at) && A(), !l && (A(), !l))
667
667
  return;
668
- if (S.isCollapsed) {
669
- s.getAnnotation(u.annotation) && !(l(v) || T === "REPLACE_CURRENT") && (n.clear(), s.deleteAnnotation(u.annotation));
668
+ if (y.isCollapsed) {
669
+ s.getAnnotation(l.annotation) && !(d(v) || T === "REPLACE_CURRENT") && (n.clear(), s.deleteAnnotation(l.annotation));
670
670
  return;
671
671
  }
672
672
  const I = M.map((k) => $t(k, t));
673
673
  if (I.every((k) => Ht(k))) return;
674
674
  const _ = I.flatMap((k) => Ft(t, k.cloneRange()));
675
- if (!(_.length > 0 && !u || _.length !== u.selector.length || _.some((k, W) => k.toString() !== u.selector[W]?.quote))) return;
676
- const j = l(v) && L ? Pt([
675
+ if (!(_.length > 0 && !l || _.length !== l.selector.length || _.some((k, W) => k.toString() !== l?.selector[W]?.quote))) return;
676
+ const j = d(v) && L ? Pt([
677
677
  ...L.selector.map((k) => k.range),
678
678
  ..._
679
679
  ]) : _;
680
- u = {
681
- ...u,
682
- selector: j.map((k) => Wt(k, t, d)),
680
+ l = {
681
+ ...l,
682
+ selector: j.map((k) => Wt(k, t, u)),
683
683
  updated: /* @__PURE__ */ new Date()
684
- }, !(l(v) || T === "REPLACE_CURRENT") && (s.getAnnotation(u.annotation) ? s.updateTarget(u, F.LOCAL) : n.clear());
684
+ }, !(d(v) || T === "REPLACE_CURRENT") && (s.getAnnotation(l.annotation) ? s.updateTarget(l, F.LOCAL) : n.clear());
685
685
  }, 10), N = (f) => {
686
686
  v = J(f), x = v.button === 0;
687
- }, y = async (f) => {
687
+ }, S = async (f) => {
688
688
  if (!x) return;
689
- const S = J(f), M = () => {
689
+ const y = J(f), M = () => {
690
690
  const { x: I, y: _ } = t.getBoundingClientRect();
691
- if ($(t, S.target)) {
692
- (typeof m == "function" ? m(S, t) : m === "ALWAYS") && n.clear();
691
+ if ($(t, y.target)) {
692
+ (typeof m == "function" ? m(y, t) : m === "ALWAYS") && n.clear();
693
693
  return;
694
694
  }
695
- const H = S.target instanceof Node && t.contains(S.target) && s.getAt(
696
- S.clientX - I,
697
- S.clientY - _,
695
+ const H = y.target instanceof Node && t.contains(y.target) && s.getAt(
696
+ y.clientX - I,
697
+ y.clientY - _,
698
698
  g === "all",
699
699
  b
700
700
  );
701
701
  if (H) {
702
702
  const { selected: j } = n, k = new Set(j.map((X) => X.id)), W = Array.isArray(H) ? H.map((X) => X.id) : [H.id];
703
- (k.size !== W.length || !W.every((X) => k.has(X))) && (o.emit("clickAnnotation", H), n.userSelect(W, S));
703
+ (k.size !== W.length || !W.every((X) => k.has(X))) && (o.emit("clickAnnotation", H), n.userSelect(W, y));
704
704
  } else
705
705
  n.clear();
706
706
  };
707
- if (S.timeStamp - v.timeStamp < at) {
707
+ if (y.timeStamp - (v?.timeStamp || 0) < at) {
708
708
  await C();
709
- const I = document.getSelection(), _ = $(t, v.target), H = $(t, S.target);
709
+ const I = document.getSelection(), _ = $(t, v?.target), H = $(t, y.target);
710
710
  if (I?.isCollapsed || _ && H) {
711
- u = void 0, M();
711
+ l = void 0, M();
712
712
  return;
713
713
  }
714
714
  }
715
- u && u.selector.length > 0 && (K(), n.userSelect(u.annotation, S));
715
+ l && l.selector.length > 0 && (K(), n.userSelect(l.annotation, y));
716
716
  }, C = async () => {
717
717
  const f = document.getSelection();
718
- let S = !1, M = f?.isCollapsed;
719
- const U = () => M || S, I = 1;
720
- return setTimeout(() => S = !0, 50), Dt(() => M = f?.isCollapsed, I, U);
718
+ let y = !1, M = f?.isCollapsed;
719
+ const U = () => M || y, I = 1;
720
+ return setTimeout(() => y = !0, 50), Dt(() => M = f?.isCollapsed, I, U);
721
721
  }, O = (f) => {
722
- document.getSelection()?.isCollapsed || ((!u || u.selector.length === 0) && R(f), u && (K(), n.userSelect(u.annotation, J(f))));
722
+ document.getSelection()?.isCollapsed || ((!l || l.selector.length === 0) && R(f), l && (K(), n.userSelect(l.annotation, J(f))));
723
723
  }, B = (f) => {
724
- h && (f.repeat || f.target instanceof Node && $(t, f.target) && f.target !== document.body || f.key === "Shift" && u && (document.getSelection().isCollapsed || (K(), n.userSelect(u.annotation, G(f)))));
724
+ if (h && !(f.repeat || f.target instanceof Node && $(t, f.target) && f.target !== document.body) && f.key === "Shift" && l) {
725
+ const y = document.getSelection();
726
+ y && !y.isCollapsed && (K(), n.userSelect(l.annotation, G(f)));
727
+ }
725
728
  }, V = (f) => {
726
- const S = () => setTimeout(() => {
727
- u?.selector.length > 0 && (n.clear(), s.addAnnotation({
728
- id: u.annotation,
729
+ const y = () => setTimeout(() => {
730
+ l && (l.selector.length > 0 && (n.clear(), s.addAnnotation({
731
+ id: l.annotation,
729
732
  bodies: [],
730
- target: u
731
- }), n.userSelect(u.annotation, G(f))), document.removeEventListener("selectionchange", S);
733
+ target: l
734
+ }), n.userSelect(l.annotation, G(f))), document.removeEventListener("selectionchange", y));
732
735
  }, 100);
733
- document.addEventListener("selectionchange", S), A();
736
+ document.addEventListener("selectionchange", y), A();
734
737
  };
735
738
  q(de.join(","), { element: t, keydown: !0, keyup: !1 }, (f) => {
736
739
  f.repeat || (v = G(f));
@@ -738,25 +741,26 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
738
741
  v = G(f), V(f);
739
742
  });
740
743
  const z = (f) => {
741
- f.repeat || f.target instanceof Node && $(t, f.target) && f.target !== document.body || (u = void 0, n.clear());
744
+ f.repeat || f.target instanceof Node && $(t, f.target) && f.target !== document.body || (l = void 0, n.clear());
742
745
  };
743
746
  q(Et.join(","), { keydown: !0, keyup: !1 }, z);
744
747
  const K = () => {
745
- const f = s.getAnnotation(u.annotation);
748
+ if (!l) return;
749
+ const f = s.getAnnotation(l.annotation);
746
750
  if (!f)
747
751
  s.addAnnotation({
748
- id: u.annotation,
752
+ id: l.annotation,
749
753
  bodies: [],
750
- target: u
754
+ target: l
751
755
  });
752
756
  else {
753
- const { target: { updated: S } } = f, { updated: M } = u;
754
- (!S || !M || S < M) && s.updateTarget(u);
757
+ const { target: { updated: y } } = f, { updated: M } = l;
758
+ (!y || !M || y < M) && s.updateTarget(l);
755
759
  }
756
760
  };
757
- return document.addEventListener("pointerdown", N), document.addEventListener("pointerup", y), document.addEventListener("contextmenu", O), document.addEventListener("keyup", B), t.addEventListener("selectstart", A), document.addEventListener("selectionchange", R), {
761
+ return document.addEventListener("pointerdown", N), document.addEventListener("pointerup", S), document.addEventListener("contextmenu", O), document.addEventListener("keyup", B), t.addEventListener("selectstart", A), document.addEventListener("selectionchange", R), {
758
762
  destroy: () => {
759
- u = void 0, L = void 0, x = void 0, v = void 0, R.clear(), document.removeEventListener("pointerdown", N), document.removeEventListener("pointerup", y), document.removeEventListener("contextmenu", O), document.removeEventListener("keyup", B), t.removeEventListener("selectstart", A), document.removeEventListener("selectionchange", R), q.unbind();
763
+ l = void 0, L = void 0, x = void 0, v = void 0, R.clear(), document.removeEventListener("pointerdown", N), document.removeEventListener("pointerup", S), document.removeEventListener("contextmenu", O), document.removeEventListener("keyup", B), t.removeEventListener("selectstart", A), document.removeEventListener("selectionchange", R), q.unbind();
760
764
  },
761
765
  setFilter: w,
762
766
  setUser: c,
@@ -780,7 +784,7 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
780
784
  setVisible: (n) => {
781
785
  console.log("setVisible not implemented on CSS Custom Highlights renderer");
782
786
  },
783
- redraw: (n, r, a, d, g) => {
787
+ redraw: (n, r, a, u, g) => {
784
788
  const m = new Set(n.map((h) => h.annotation.id));
785
789
  Array.from(e).filter((h) => !m.has(h));
786
790
  const b = n.map((h) => {
@@ -790,8 +794,8 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
790
794
  });
791
795
  t.innerHTML = b.join(`
792
796
  `), CSS.highlights.clear(), n.forEach(({ annotation: h }) => {
793
- const T = h.target.selector.map((L) => L.range), u = new Highlight(...T);
794
- CSS.highlights.set(`_${h.id}`, u);
797
+ const T = h.target.selector.map((L) => L.range), l = new Highlight(...T);
798
+ CSS.highlights.set(`_${h.id}`, l);
795
799
  }), e = m;
796
800
  }
797
801
  };
@@ -804,15 +808,32 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
804
808
  const o = pe(e, {
805
809
  annotatingEnabled: !0,
806
810
  user: Nt()
807
- }), i = le(t, o), { selection: s, viewport: n } = i, r = i.store, a = Ot(r), d = kt(i, a, o.adapter);
811
+ }), i = le(t, o), { selection: s, viewport: n } = i, r = i.store, a = Ot(r), u = kt(i, a, o.adapter);
808
812
  let g = o.user;
809
- const m = typeof o.renderer != "function" ? o.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ct : o.renderer || ct : null, b = m === null ? o.renderer(t, i, n) : m === "SPANS" ? re(t, i, n) : m === "CSS_HIGHLIGHTS" ? me(t, i, n) : void 0;
813
+ const m = typeof o.renderer != "function" ? o.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ct : o.renderer || ct : null, b = m === null ? o.renderer(
814
+ t,
815
+ i,
816
+ n
817
+ ) : m === "SPANS" ? re(
818
+ t,
819
+ i,
820
+ n
821
+ ) : m === "CSS_HIGHLIGHTS" ? me(
822
+ t,
823
+ i,
824
+ n
825
+ ) : void 0;
810
826
  if (!b)
811
827
  throw `Unknown renderer implementation: ${o.renderer}`;
812
828
  console.debug(m ? `Using ${m} renderer` : "Using custom renderer implementation"), o.style && b.setStyle(o.style);
813
- const h = ue(t, i, d, o);
829
+ const h = ue(
830
+ t,
831
+ i,
832
+ u,
833
+ o
834
+ );
814
835
  h.setUser(g);
815
- const T = Mt(i, a, o.adapter), u = () => g, L = (c) => {
836
+ const T = Mt(i, a, o.adapter), l = () => g, L = (c) => {
816
837
  h.setAnnotatingEnabled(
817
838
  c === void 0 ? !0 : c
818
839
  );
@@ -831,7 +852,7 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
831
852
  b.destroy(), h.destroy(), a.destroy();
832
853
  },
833
854
  element: t,
834
- getUser: u,
855
+ getUser: l,
835
856
  renderer: b,
836
857
  setAnnotatingEnabled: L,
837
858
  setAnnotatingMode: x,
@@ -840,8 +861,8 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
840
861
  setUser: p,
841
862
  setSelected: E,
842
863
  setVisible: b.setVisible.bind(b),
843
- on: d.on,
844
- off: d.off,
864
+ on: u.on,
865
+ off: u.off,
845
866
  scrollIntoView: Xt(t, r),
846
867
  state: i
847
868
  };