@soomo/text-annotator 3.4.0-staging.3 → 3.4.1-staging.0

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.
@@ -1,31 +1,31 @@
1
- import { UAParser as ut } from "ua-parser-js";
2
- import { OS as ft } from "ua-parser-js/enums";
1
+ import { UAParser as ft } from "ua-parser-js";
2
+ import { OS as ut } from "ua-parser-js/enums";
3
3
  import $ from "debounce";
4
- import { colord as ot } from "colord";
4
+ import { colord as Z } from "colord";
5
5
  import { dequal as gt } from "dequal/lite";
6
6
  import { v4 as st } from "uuid";
7
- import { serializeW3CBodies as mt, parseW3CBodies as pt, parseW3CUser as ht, createStore as yt, createSelectionState as bt, createHoverState as St, createViewportState as Ct, Origin as F, createAnonymousGuest as Et, createUndoStack as wt, createLifecycleObserver as At, createBaseAnnotator as vt } from "@annotorious/core";
7
+ import { serializeW3CBodies as mt, parseW3CBodies as pt, parseW3CUser as ht, createStore as bt, createSelectionState as yt, createHoverState as St, createViewportState as Ct, Origin as K, createAnonymousGuest as Et, createUndoStack as wt, createLifecycleObserver as At, createBaseAnnotator as vt } from "@annotorious/core";
8
8
  import { Origin as He, UserSelectAction as Pe, createBody as _e } from "@annotorious/core";
9
9
  import xt from "rbush";
10
- import { createNanoEvents as Rt } from "nanoevents";
11
- import X from "hotkeys-js";
12
- import { poll as Tt } from "poll";
13
- const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
10
+ import { createNanoEvents as Tt } from "nanoevents";
11
+ import Y from "hotkeys-js";
12
+ import { poll as Rt } from "poll";
13
+ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
14
14
  var r;
15
15
  return t.contains(e) ? !!(e instanceof HTMLElement ? e.closest(W) : (r = e.parentElement) == null ? void 0 : r.closest(W)) : !0;
16
16
  }, Lt = (t, e) => {
17
17
  const n = e.commonAncestorContainer;
18
- return !K(t, n);
18
+ return !z(t, n);
19
19
  }, Nt = (t) => t.addEventListener("click", (e) => {
20
20
  // Allow clicks within not-annotatable elements
21
21
  !e.target.closest(W) && !e.target.closest("a") && e.preventDefault();
22
- }), Ot = ut(), kt = Ot.os.is(ft.MACOS), Bt = (t) => {
22
+ }), Ot = ft(), kt = Ot.os.is(ut.MACOS), Bt = (t) => {
23
23
  !t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
24
- }, It = (t) => {
24
+ }, it = /^\s*$/, It = (t) => it.test(t.toString()), Mt = (t) => it.test(t.textContent || ""), Ht = (t) => {
25
25
  const e = [], n = document.createNodeIterator(t.commonAncestorContainer, NodeFilter.SHOW_TEXT);
26
26
  let r;
27
27
  for (; r = n.nextNode(); )
28
- t.intersectsNode(r) && e.push(r);
28
+ t.intersectsNode(r) && !Mt(r) && e.push(r);
29
29
  if (e.length < 2)
30
30
  return Array.from(t.getClientRects());
31
31
  {
@@ -33,9 +33,9 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
33
33
  i.selectNode(o), t.startContainer.nodeType === Node.TEXT_NODE ? i.setStart(o, t.startOffset) : i.setStartAfter(t.startContainer);
34
34
  const c = document.createRange();
35
35
  c.selectNode(s), t.endContainer.nodeType === Node.TEXT_NODE ? c.setEnd(s, t.endOffset) : c.setEndBefore(t.endContainer);
36
- const l = (f) => {
36
+ const l = (u) => {
37
37
  const p = document.createRange();
38
- return p.selectNode(f), Array.from(p.getClientRects());
38
+ return p.selectNode(u), Array.from(p.getClientRects());
39
39
  };
40
40
  return [
41
41
  ...Array.from(i.getClientRects()),
@@ -43,7 +43,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
43
43
  ...Array.from(c.getClientRects())
44
44
  ];
45
45
  }
46
- }, Mt = function* (t) {
46
+ }, Pt = function* (t) {
47
47
  const e = document.createNodeIterator(
48
48
  t.commonAncestorContainer,
49
49
  NodeFilter.SHOW_ELEMENT,
@@ -52,11 +52,11 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
52
52
  let n;
53
53
  for (; n = e.nextNode(); )
54
54
  n instanceof HTMLElement && (yield n);
55
- }, Ht = (t, e) => {
55
+ }, _t = (t, e) => {
56
56
  if (!Lt(t, e)) return [];
57
57
  const n = [];
58
58
  let r = null;
59
- for (const o of Mt(e)) {
59
+ for (const o of Pt(e)) {
60
60
  let s;
61
61
  r ? (s = document.createRange(), s.setStartAfter(r), s.setEndBefore(o)) : (s = e.cloneRange(), s.setEndBefore(o)), s.collapsed || n.push(s), r = o;
62
62
  }
@@ -65,20 +65,20 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
65
65
  o.setStartAfter(r), o.collapsed || n.push(o);
66
66
  }
67
67
  return n.length > 0 ? n : [e];
68
- }, Z = (t) => {
68
+ }, J = (t) => {
69
69
  const e = t.cloneContents();
70
70
  return e.querySelectorAll(W).forEach((n) => n.remove()), e;
71
- }, Pt = (t, e, n = 10, r) => {
71
+ }, Dt = (t, e, n = 10, r) => {
72
72
  const o = r ? t.startContainer.parentElement.closest(r) : e, s = document.createRange();
73
73
  s.setStart(o, 0), s.setEnd(t.startContainer, t.startOffset);
74
- const i = Z(s).textContent, c = document.createRange();
74
+ const i = J(s).textContent, c = document.createRange();
75
75
  c.setStart(t.endContainer, t.endOffset), o === document.body ? c.setEnd(o, o.childNodes.length) : c.setEndAfter(o);
76
- const l = Z(c).textContent;
76
+ const l = J(c).textContent;
77
77
  return {
78
78
  prefix: i.substring(i.length - n),
79
79
  suffix: l.substring(0, n)
80
80
  };
81
- }, P = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), _t = /^\s*$/, Dt = (t) => _t.test(t.toString()), Ut = (t, e, n, r) => {
81
+ }, P = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), Ut = (t, e, n, r) => {
82
82
  const o = (c) => Math.round(c * 10) / 10, s = {
83
83
  top: o(t.top),
84
84
  bottom: o(t.bottom),
@@ -112,16 +112,16 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
112
112
  for (const c of r) {
113
113
  const l = Ut(o, c, e, n);
114
114
  if (l === "inline-adjacent") {
115
- s = s.map((f) => f === c ? Ft(o, c) : f), i = !0;
115
+ s = s.map((u) => u === c ? Ft(o, c) : u), i = !0;
116
116
  break;
117
117
  } else if (l === "inline-contains") {
118
- s = s.map((f) => f === c ? o : f), i = !0;
118
+ s = s.map((u) => u === c ? o : u), i = !0;
119
119
  break;
120
120
  } else if (l === "inline-is-contained") {
121
121
  i = !0;
122
122
  break;
123
123
  } else if (l === "block-contains" || l === "block-is-contained") {
124
- o.width < c.width && (s = s.map((f) => f === c ? o : f)), o.width === c.width && o.height < c.width && (s = s.map((f) => f === c ? o : f)), i = !0;
124
+ o.width < c.width && (s = s.map((u) => u === c ? o : u)), o.width === c.width && o.height < c.width && (s = s.map((u) => u === c ? o : u)), i = !0;
125
125
  break;
126
126
  }
127
127
  }
@@ -136,10 +136,10 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
136
136
  }), $t = (t, e, n) => {
137
137
  const r = document.createRange(), o = n ? t.startContainer.parentElement.closest(n) : e;
138
138
  r.setStart(o, 0), r.setEnd(t.startContainer, t.startOffset);
139
- const s = Z(r).textContent, i = t.toString(), c = s.length || 0, l = c + i.length;
139
+ const s = J(r).textContent, i = t.toString(), c = s.length || 0, l = c + i.length;
140
140
  return n ? { quote: i, start: c, end: l, range: t, offsetReference: o } : { quote: i, start: c, end: l, range: t };
141
- }, it = (t, e) => {
142
- var p, u;
141
+ }, at = (t, e) => {
142
+ var p, f;
143
143
  const { start: n, end: r } = t, o = t.offsetReference || e, s = document.createNodeIterator(
144
144
  e,
145
145
  NodeFilter.SHOW_TEXT,
@@ -152,9 +152,9 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
152
152
  const c = document.createRange();
153
153
  let l = s.nextNode();
154
154
  l === null && console.error("Could not revive annotation target. Content missing.");
155
- let f = !o;
155
+ let u = !o;
156
156
  for (; l !== null; ) {
157
- if (f || (f = typeof (o == null ? void 0 : o.contains) == "function" ? o.contains(l) : !1), f) {
157
+ if (u || (u = typeof (o == null ? void 0 : o.contains) == "function" ? o.contains(l) : !1), u) {
158
158
  const g = ((p = l.textContent) == null ? void 0 : p.length) || 0;
159
159
  if (i + g > n) {
160
160
  c.setStart(l, n - i);
@@ -165,7 +165,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
165
165
  l = s.nextNode();
166
166
  }
167
167
  for (; l !== null; ) {
168
- const g = ((u = l.textContent) == null ? void 0 : u.length) || 0;
168
+ const g = ((f = l.textContent) == null ? void 0 : f.length) || 0;
169
169
  if (i + g >= r) {
170
170
  c.setEnd(l, r - i);
171
171
  break;
@@ -178,20 +178,10 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
178
178
  };
179
179
  }, q = (t, e) => P(t.selector) ? t : {
180
180
  ...t,
181
- selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : it(n, e))
182
- }, G = (t, e) => P(t.target.selector) ? t : { ...t, target: q(t.target, e) }, at = (t, e) => {
183
- if (t.isEqualNode(e))
184
- return !0;
185
- for (let n of t.childNodes)
186
- if (at(n, e))
187
- return !0;
188
- return !1;
189
- }, Wt = (t, e) => {
190
- const n = t.cloneContents();
191
- return at(n, e);
192
- }, Vt = (t, e) => {
193
- const n = t.cloneRange(), r = e.contains(n.startContainer), o = e.contains(n.endContainer);
194
- return !r && !o && !Wt(n, e) ? (n.collapse(), n) : (r || n.setStart(e, 0), o || n.setEnd(e, e.childNodes.length), n);
181
+ selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : at(n, e))
182
+ }, G = (t, e) => P(t.target.selector) ? t : { ...t, target: q(t.target, e) }, Wt = (t, e) => {
183
+ const n = t.cloneRange();
184
+ return e.contains(n.startContainer) || n.setStart(e, 0), e.contains(n.endContainer) || n.setEnd(e, e.childNodes.length), n;
195
185
  }, Q = (t) => ({
196
186
  ...t,
197
187
  type: t.type,
@@ -218,7 +208,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
218
208
  pointerId: t.pointerId,
219
209
  pointerType: t.pointerType,
220
210
  timeStamp: t.timeStamp
221
- }), z = (t) => ({
211
+ }), X = (t) => ({
222
212
  ...t,
223
213
  type: t.type,
224
214
  key: t.key,
@@ -234,7 +224,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
234
224
  defaultPrevented: t.defaultPrevented,
235
225
  detail: t.detail,
236
226
  timeStamp: t.timeStamp
237
- }), Yt = (t, e) => {
227
+ }), Vt = (t, e) => {
238
228
  const { left: n, top: r, right: o, bottom: s } = t;
239
229
  return new DOMRect(n - e.left, r - e.top, o - n, s - r);
240
230
  }, Oe = (t, e) => {
@@ -245,10 +235,10 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
245
235
  return document.scrollingElement;
246
236
  const { overflowY: e } = window.getComputedStyle(t);
247
237
  return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ct(t.parentElement);
248
- }, tt = (t, e, n) => {
249
- const r = n.getBoundingClientRect(), o = n.clientHeight, s = n.clientWidth, i = e.selector[0].range.getBoundingClientRect(), { width: c, height: l } = t.getAnnotationBounds(e.annotation), f = i.top - r.top, p = i.left - r.left, u = n.parentElement ? n.scrollTop : 0, g = n.parentElement ? n.scrollLeft : 0, d = f + u - (o - l) / 2, L = p + g - (s - c) / 2;
238
+ }, et = (t, e, n) => {
239
+ const r = n.getBoundingClientRect(), o = n.clientHeight, s = n.clientWidth, i = e.selector[0].range.getBoundingClientRect(), { width: c, height: l } = t.getAnnotationBounds(e.annotation), u = i.top - r.top, p = i.left - r.left, f = n.parentElement ? n.scrollTop : 0, g = n.parentElement ? n.scrollLeft : 0, d = u + f - (o - l) / 2, L = p + g - (s - c) / 2;
250
240
  n.scroll({ top: d, left: L, behavior: "smooth" });
251
- }, Xt = (t, e) => (n, r) => {
241
+ }, Yt = (t, e) => (n, r) => {
252
242
  const o = typeof n == "string" ? n : n.id, s = r ? typeof r == "string" ? document.getElementById(r) : r : ct(t);
253
243
  if (!s)
254
244
  return console.warn(`The scroll parent is missing for the annotation: ${o}`, { container: t }), !1;
@@ -257,59 +247,59 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
257
247
  return console.warn(`The annotation is missing in the store: ${o}`), !1;
258
248
  const { range: c } = i.target.selector[0];
259
249
  if (c && !c.collapsed)
260
- return tt(e, i.target, s), !0;
261
- const l = q(i.target, t), { range: f } = l.selector[0];
262
- return f && !f.collapsed ? (tt(e, l, s), !0) : !1;
250
+ return et(e, i.target, s), !0;
251
+ const l = q(i.target, t), { range: u } = l.selector[0];
252
+ return u && !u.collapsed ? (et(e, l, s), !0) : !1;
263
253
  }, _ = {
264
254
  fill: "rgb(0, 128, 255)",
265
255
  fillOpacity: 0.18
266
256
  }, j = {
267
257
  fill: "rgb(0, 128, 255)",
268
258
  fillOpacity: 0.45
269
- }, zt = (t, e, n, r, o) => {
259
+ }, Xt = (t, e, n, r, o) => {
270
260
  var i, c;
271
261
  const s = n ? typeof n == "function" ? n(t.annotation, t.state, o) || ((i = t.state) != null && i.selected ? j : _) : n : (c = t.state) != null && c.selected ? j : _;
272
262
  return r && r.paint(t, e) || s;
273
- }, qt = (t) => {
263
+ }, zt = (t) => {
274
264
  const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: r, innerHeight: o } = window, s = -n, i = -e, c = r - n, l = o - e;
275
265
  return { top: e, left: n, minX: s, minY: i, maxX: c, maxY: l };
276
- }, jt = (t) => {
266
+ }, qt = (t) => {
277
267
  let e = /* @__PURE__ */ new Set();
278
268
  return (r) => {
279
269
  const o = r.map((s) => s.id);
280
270
  (e.size !== o.length || o.some((s) => !e.has(s))) && t.set(o), e = new Set(o);
281
271
  };
282
- }, J = (t, e, n, r) => {
272
+ }, tt = (t, e, n, r) => {
283
273
  const { store: o, selection: s, hover: i } = e;
284
- let c, l, f;
285
- const p = jt(n), u = $((S) => {
286
- const { x, y: T } = t.getBoundingClientRect(), k = o.getAt(S.clientX - x, S.clientY - T, !1, l);
287
- k ? i.current !== k.id && (t.classList.add("hovered"), i.set(k.id)) : i.current && (t.classList.remove("hovered"), i.set(null));
274
+ let c, l, u;
275
+ const p = qt(n), f = $((S) => {
276
+ const { x: A, y: T } = t.getBoundingClientRect(), B = o.getAt(S.clientX - A, S.clientY - T, !1, l);
277
+ B ? i.current !== B.id && (t.classList.add("hovered"), i.set(B.id)) : i.current && (t.classList.remove("hovered"), i.set(null));
288
278
  }, 10);
289
- t.addEventListener("pointermove", u);
279
+ t.addEventListener("pointermove", f);
290
280
  const g = $((S = !1) => requestAnimationFrame(() => {
291
- f && f.clear();
292
- const x = qt(t), { minX: T, minY: k, maxX: y, maxY: v } = x, I = l ? o.getIntersecting(T, k, y, v).filter(({ annotation: O }) => l(O)) : o.getIntersecting(T, k, y, v), V = s.selected.map(({ id: O }) => O), M = I.map(({ annotation: O, rects: H }) => {
293
- const B = V.includes(O.id), D = O.id === i.current;
281
+ u && u.clear();
282
+ const A = zt(t), { minX: T, minY: B, maxX: y, maxY: v } = A, I = l ? o.getIntersecting(T, B, y, v).filter(({ annotation: O }) => l(O)) : o.getIntersecting(T, B, y, v), D = s.selected.map(({ id: O }) => O), M = I.map(({ annotation: O, rects: H }) => {
283
+ const k = D.includes(O.id), U = O.id === i.current;
294
284
  return {
295
285
  annotation: O,
296
286
  rects: H,
297
- state: { selected: B, hovered: D }
287
+ state: { selected: k, hovered: U }
298
288
  };
299
289
  });
300
- r.redraw(M, x, c, f, S), setTimeout(() => p(I.map(({ annotation: O }) => O)), 1);
290
+ r.redraw(M, A, c, u, S), setTimeout(() => p(I.map(({ annotation: O }) => O)), 1);
301
291
  }), 10), d = (S) => {
302
- f = S, g();
292
+ u = S, g();
303
293
  }, L = (S) => {
304
294
  c = S, g();
305
295
  }, w = (S) => {
306
296
  l = S, g(!1);
307
- }, R = () => g();
308
- o.observe(R);
309
- const A = s.subscribe(() => g()), C = i.subscribe(() => g()), N = () => g(!0);
297
+ }, x = () => g();
298
+ o.observe(x);
299
+ const R = s.subscribe(() => g()), C = i.subscribe(() => g()), N = () => g(!0);
310
300
  document.addEventListener("scroll", N, { capture: !0, passive: !0 });
311
301
  const E = $(() => {
312
- o.recalculatePositions(), f == null || f.reset(), g();
302
+ o.recalculatePositions(), u == null || u.reset(), g();
313
303
  }, 10);
314
304
  window.addEventListener("resize", E);
315
305
  const a = new ResizeObserver(E);
@@ -319,7 +309,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
319
309
  }, 150));
320
310
  return b.observe(document.body, m), {
321
311
  destroy: () => {
322
- t.removeEventListener("pointermove", u), r.destroy(), o.unobserve(R), A(), C(), document.removeEventListener("scroll", N), E.clear(), window.removeEventListener("resize", E), a.disconnect(), b.disconnect();
312
+ t.removeEventListener("pointermove", f), r.destroy(), o.unobserve(x), R(), C(), document.removeEventListener("scroll", N), E.clear(), window.removeEventListener("resize", E), a.disconnect(), b.disconnect();
323
313
  },
324
314
  redraw: g,
325
315
  setStyle: L,
@@ -327,25 +317,25 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
327
317
  setPainter: d,
328
318
  setVisible: r.setVisible
329
319
  };
330
- }, Gt = () => {
320
+ }, jt = () => {
331
321
  const t = document.createElement("canvas");
332
322
  return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-canvas-highlight-layer bg", t;
333
- }, Qt = (t, e) => {
323
+ }, Gt = (t, e) => {
334
324
  t.width = window.innerWidth, t.height = window.innerHeight;
335
- }, Zt = (t) => {
325
+ }, Qt = (t) => {
336
326
  t.classList.add("r6o-annotatable");
337
- const e = Gt(), n = e.getContext("2d");
327
+ const e = jt(), n = e.getContext("2d");
338
328
  document.body.appendChild(e);
339
- const r = (c, l, f, p) => requestAnimationFrame(() => {
340
- const { width: u, height: g } = e;
341
- n.clearRect(-0.5, -0.5, u + 1, g + 1), p && p.clear();
329
+ const r = (c, l, u, p) => requestAnimationFrame(() => {
330
+ const { width: f, height: g } = e;
331
+ n.clearRect(-0.5, -0.5, f + 1, g + 1), p && p.clear();
342
332
  const { top: d, left: L } = l;
343
- [...c].sort((R, A) => {
344
- const { annotation: { target: { created: C } } } = R, { annotation: { target: { created: N } } } = A;
333
+ [...c].sort((x, R) => {
334
+ const { annotation: { target: { created: C } } } = x, { annotation: { target: { created: N } } } = R;
345
335
  return C.getTime() - N.getTime();
346
- }).forEach((R) => {
336
+ }).forEach((x) => {
347
337
  var E;
348
- const A = f ? typeof f == "function" ? f(R.annotation, R.state) : f : (E = R.state) != null && E.selected ? j : _, C = p && p.paint(R, l) || A, N = R.rects.map(({ x: a, y: m, width: b, height: h }) => ({
338
+ const R = u ? typeof u == "function" ? u(x.annotation, x.state) : u : (E = x.state) != null && E.selected ? j : _, C = p && p.paint(x, l) || R, N = x.rects.map(({ x: a, y: m, width: b, height: h }) => ({
349
339
  x: a + L,
350
340
  y: m + d,
351
341
  width: b,
@@ -361,7 +351,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
361
351
  });
362
352
  }
363
353
  });
364
- }), o = $(() => Qt(e), 10);
354
+ }), o = $(() => Gt(e), 10);
365
355
  return window.addEventListener("resize", o), {
366
356
  destroy: () => {
367
357
  e.remove(), o.clear(), window.removeEventListener("resize", o);
@@ -371,13 +361,13 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
371
361
  },
372
362
  redraw: r
373
363
  };
374
- }, Jt = (t, e, n) => J(t, e, n, Zt(t)), te = (t) => [
375
- `background-color:${ot((t == null ? void 0 : t.fill) || _.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? _.fillOpacity : t.fillOpacity).toHex()}`,
364
+ }, Zt = (t, e, n) => tt(t, e, n, Qt(t)), Jt = (t) => [
365
+ `background-color:${Z((t == null ? void 0 : t.fill) || _.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? _.fillOpacity : t.fillOpacity).toHex()}`,
376
366
  t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
377
367
  t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
378
368
  t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
379
369
  t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
380
- ].filter(Boolean).join(";"), ee = () => {
370
+ ].filter(Boolean).join(";"), te = () => {
381
371
  const t = document.createElement("style");
382
372
  document.getElementsByTagName("head")[0].appendChild(t);
383
373
  let e = /* @__PURE__ */ new Set();
@@ -390,21 +380,21 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
390
380
  },
391
381
  redraw: (s, i, c, l) => {
392
382
  l && l.clear();
393
- const f = new Set(s.map((u) => u.annotation.id));
394
- Array.from(e).filter((u) => !f.has(u));
395
- const p = s.map((u) => {
383
+ const u = new Set(s.map((f) => f.annotation.id));
384
+ Array.from(e).filter((f) => !u.has(f));
385
+ const p = s.map((f) => {
396
386
  var L;
397
- const g = c ? typeof c == "function" ? c(u.annotation, u.state) : c : (L = u.state) != null && L.selected ? j : _, d = l && l.paint(u, i) || g;
398
- return `::highlight(_${u.annotation.id}) { ${te(d)} }`;
387
+ const g = c ? typeof c == "function" ? c(f.annotation, f.state) : c : (L = f.state) != null && L.selected ? j : _, d = l && l.paint(f, i) || g;
388
+ return `::highlight(_${f.annotation.id}) { ${Jt(d)} }`;
399
389
  });
400
390
  t.innerHTML = p.join(`
401
- `), CSS.highlights.clear(), s.forEach(({ annotation: u }) => {
402
- const g = u.target.selector.map((L) => L.range), d = new Highlight(...g);
403
- CSS.highlights.set(`_${u.id}`, d);
404
- }), e = f;
391
+ `), CSS.highlights.clear(), s.forEach(({ annotation: f }) => {
392
+ const g = f.target.selector.map((L) => L.range), d = new Highlight(...g);
393
+ CSS.highlights.set(`_${f.id}`, d);
394
+ }), e = u;
405
395
  }
406
396
  };
407
- }, ne = (t, e, n) => J(t, e, n, ee()), oe = (t, e) => {
397
+ }, ee = (t, e, n) => tt(t, e, n, te()), ne = (t) => (t == null ? void 0 : t.fillOpacity) !== void 0 ? Z((t == null ? void 0 : t.fill) || _.fill).alpha(t.fillOpacity).toHex() : t != null && t.fill ? t.fill : Z(_.fill).alpha(_.fillOpacity).toHex(), oe = (t, e) => {
408
398
  const n = (s, i) => s.x <= i.x + i.width && s.x + s.width >= i.x && s.y <= i.y + i.height && s.y + s.height >= i.y, r = (s) => s.rects.reduce((i, c) => i + c.width, 0), o = e.filter(({ rects: s }) => s.some((i) => n(t, i)));
409
399
  return o.sort((s, i) => r(i) - r(s)), o.findIndex((s) => s.rects.includes(t));
410
400
  }, se = (t) => {
@@ -416,18 +406,18 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
416
406
  destroy: () => {
417
407
  e.remove();
418
408
  },
419
- redraw: (i, c, l, f, p) => {
409
+ redraw: (i, c, l, u, p) => {
420
410
  const g = !(gt(n, i) && p);
421
- if (!f && !g) return;
411
+ if (!u && !g) return;
422
412
  g && (e.innerHTML = ""), [...i].sort((L, w) => {
423
- const { annotation: { target: { created: R } } } = L, { annotation: { target: { created: A } } } = w;
424
- return R && A ? R.getTime() - A.getTime() : 0;
413
+ const { annotation: { target: { created: x } } } = L, { annotation: { target: { created: R } } } = w;
414
+ return x && R ? x.getTime() - R.getTime() : 0;
425
415
  }).forEach((L) => {
426
416
  L.rects.map((w) => {
427
- const R = oe(w, i), A = zt(L, c, l, f, R);
417
+ const x = oe(w, i), R = Xt(L, c, l, u, x);
428
418
  if (g) {
429
419
  const C = document.createElement("span");
430
- C.className = "r6o-annotation", C.dataset.annotation = L.annotation.id, C.style.left = `${w.x}px`, C.style.top = `${w.y}px`, C.style.width = `${w.width}px`, C.style.height = `${w.height}px`, C.style.backgroundColor = ot((A == null ? void 0 : A.fill) || _.fill).alpha((A == null ? void 0 : A.fillOpacity) === void 0 ? _.fillOpacity : A.fillOpacity).toHex(), A.underlineStyle && (C.style.borderStyle = A.underlineStyle), A.underlineColor && (C.style.borderColor = A.underlineColor), A.underlineThickness && (C.style.borderBottomWidth = `${A.underlineThickness}px`), A.underlineOffset && (C.style.paddingBottom = `${A.underlineOffset}px`), e.appendChild(C);
420
+ C.className = "r6o-annotation", C.dataset.annotation = L.annotation.id, C.style.left = `${w.x}px`, C.style.top = `${w.y}px`, C.style.width = `${w.width}px`, C.style.height = `${w.height}px`, C.style.backgroundColor = ne(R), R.underlineStyle && (C.style.borderStyle = R.underlineStyle), R.underlineColor && (C.style.borderColor = R.underlineColor), R.underlineThickness && (C.style.borderBottomWidth = `${R.underlineThickness}px`), R.underlineOffset && (C.style.paddingBottom = `${R.underlineOffset}px`), e.appendChild(C);
431
421
  }
432
422
  });
433
423
  }), n = i;
@@ -436,7 +426,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
436
426
  i ? e.classList.remove("hidden") : e.classList.add("hidden");
437
427
  }
438
428
  };
439
- }, re = (t, e, n) => J(t, e, n, se(t)), ke = (t, e) => ({
429
+ }, re = (t, e, n) => tt(t, e, n, se(t)), ke = (t, e) => ({
440
430
  parse: (n) => ce(n),
441
431
  serialize: (n) => le(n, t, e)
442
432
  }), ie = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, ae = (t) => {
@@ -459,16 +449,16 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
459
449
  styleClass: "styleClass" in i[0] ? i[0].styleClass : void 0
460
450
  };
461
451
  for (const l of i) {
462
- const p = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((u, g) => {
452
+ const p = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((f, g) => {
463
453
  switch (g.type) {
464
454
  case "TextQuoteSelector":
465
- u.quote = g.exact;
455
+ f.quote = g.exact;
466
456
  break;
467
457
  case "TextPositionSelector":
468
- u.start = g.start, u.end = g.end;
458
+ f.start = g.start, f.end = g.end;
469
459
  break;
470
460
  }
471
- return u;
461
+ return f;
472
462
  }, {});
473
463
  if (c.outdated || (c.outdated = "outdated" in l ? l.outdated : void 0), ie(p))
474
464
  c.selector.push(
@@ -480,11 +470,11 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
480
470
  }
481
471
  );
482
472
  else {
483
- const u = [
473
+ const f = [
484
474
  p.start ? void 0 : "TextPositionSelector",
485
475
  p.quote ? void 0 : "TextQuoteSelector"
486
476
  ].filter(Boolean);
487
- return { error: Error(`Missing selector types: ${u.join(" and ")} for annotation: ${t.id}`) };
477
+ return { error: Error(`Missing selector types: ${f.join(" and ")} for annotation: ${t.id}`) };
488
478
  }
489
479
  }
490
480
  return { parsed: c };
@@ -509,21 +499,21 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
509
499
  selector: i,
510
500
  creator: c,
511
501
  created: l,
512
- updated: f,
502
+ updated: u,
513
503
  ...p
514
- } = o, u = i.map((g) => {
515
- const { id: d, quote: L, start: w, end: R, range: A } = g, C = {
504
+ } = o, f = i.map((g) => {
505
+ const { id: d, quote: L, start: w, end: x, range: R } = g, C = {
516
506
  type: "TextQuoteSelector",
517
507
  exact: L
518
508
  };
519
509
  if (n) {
520
- const { prefix: E, suffix: a } = Pt(A, n);
510
+ const { prefix: E, suffix: a } = Dt(R, n);
521
511
  C.prefix = E, C.suffix = a;
522
512
  }
523
513
  const N = {
524
514
  type: "TextPositionSelector",
525
515
  start: w,
526
- end: R
516
+ end: x
527
517
  };
528
518
  return {
529
519
  ...p,
@@ -542,21 +532,21 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
542
532
  body: mt(t.bodies),
543
533
  creator: c,
544
534
  created: l == null ? void 0 : l.toISOString(),
545
- modified: f == null ? void 0 : f.toISOString(),
546
- target: u
535
+ modified: u == null ? void 0 : u.toISOString(),
536
+ target: f
547
537
  };
548
538
  }, de = (t, e, n, r) => {
549
- const o = new xt(), s = /* @__PURE__ */ new Map(), i = Rt(), c = (a, m) => {
539
+ const o = new xt(), s = /* @__PURE__ */ new Map(), i = Tt(), c = (a, m) => {
550
540
  const b = a.selector.flatMap((S) => {
551
- const x = P([S]) ? S.range : it(S, e).range;
552
- return It(x);
553
- }), h = Kt(b, n, r).map((S) => Yt(S, m));
541
+ const A = P([S]) ? S.range : at(S, e).range;
542
+ return Ht(A);
543
+ }), h = Kt(b, n, r).map((S) => Vt(S, m));
554
544
  return h.map((S) => {
555
- const { x, y: T, width: k, height: y } = S;
545
+ const { x: A, y: T, width: B, height: y } = S;
556
546
  return {
557
- minX: x,
547
+ minX: A,
558
548
  minY: T,
559
- maxX: x + k,
549
+ maxX: A + B,
560
550
  maxY: T + y,
561
551
  annotation: {
562
552
  id: a.annotation,
@@ -564,23 +554,23 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
564
554
  }
565
555
  };
566
556
  });
567
- }, l = () => [...s.values()], f = () => {
557
+ }, l = () => [...s.values()], u = () => {
568
558
  o.clear(), s.clear();
569
559
  }, p = (a) => {
570
560
  const m = c(a, e.getBoundingClientRect());
571
561
  m.length !== 0 && (m.forEach((b) => o.insert(b)), s.set(a.annotation, m));
572
- }, u = (a) => {
562
+ }, f = (a) => {
573
563
  const m = s.get(a.annotation);
574
564
  m && (m.forEach((b) => o.remove(b)), s.delete(a.annotation));
575
565
  }, g = (a) => {
576
- u(a), p(a);
566
+ f(a), p(a);
577
567
  }, d = (a, m = !0) => {
578
- m && f();
579
- const b = e.getBoundingClientRect(), h = a.map((x) => ({ target: x, rects: c(x, b) }));
580
- h.forEach(({ target: x, rects: T }) => {
581
- T.length > 0 && s.set(x.annotation, T);
568
+ m && u();
569
+ const b = e.getBoundingClientRect(), h = a.map((A) => ({ target: A, rects: c(A, b) }));
570
+ h.forEach(({ target: A, rects: T }) => {
571
+ T.length > 0 && s.set(A.annotation, T);
582
572
  });
583
- const S = h.flatMap(({ rects: x }) => x);
573
+ const S = h.flatMap(({ rects: A }) => A);
584
574
  o.load(S);
585
575
  }, L = (a, m, b = !1) => {
586
576
  const h = o.search({
@@ -588,71 +578,71 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
588
578
  minY: m,
589
579
  maxX: a,
590
580
  maxY: m
591
- }), S = (x) => x.annotation.rects.reduce((T, k) => T + k.width * k.height, 0);
592
- return h.length > 0 ? (h.sort((x, T) => S(x) - S(T)), b ? h.map((x) => x.annotation.id) : [h[0].annotation.id]) : [];
581
+ }), S = (A) => A.annotation.rects.reduce((T, B) => T + B.width * B.height, 0);
582
+ return h.length > 0 ? (h.sort((A, T) => S(A) - S(T)), b ? h.map((A) => A.annotation.id) : [h[0].annotation.id]) : [];
593
583
  }, w = (a) => {
594
- const m = R(a);
584
+ const m = x(a);
595
585
  if (m.length === 0)
596
586
  return;
597
- let b = m[0].left, h = m[0].top, S = m[0].right, x = m[0].bottom;
587
+ let b = m[0].left, h = m[0].top, S = m[0].right, A = m[0].bottom;
598
588
  for (let T = 1; T < m.length; T++) {
599
- const k = m[T];
600
- b = Math.min(b, k.left), h = Math.min(h, k.top), S = Math.max(S, k.right), x = Math.max(x, k.bottom);
589
+ const B = m[T];
590
+ b = Math.min(b, B.left), h = Math.min(h, B.top), S = Math.max(S, B.right), A = Math.max(A, B.bottom);
601
591
  }
602
- return new DOMRect(b, h, S - b, x - h);
603
- }, R = (a) => {
592
+ return new DOMRect(b, h, S - b, A - h);
593
+ }, x = (a) => {
604
594
  const m = s.get(a);
605
595
  return m ? m[0].annotation.rects : [];
606
596
  };
607
597
  return {
608
598
  all: l,
609
- clear: f,
599
+ clear: u,
610
600
  getAt: L,
611
601
  getAnnotationBounds: w,
612
- getAnnotationRects: R,
602
+ getAnnotationRects: x,
613
603
  getIntersecting: (a, m, b, h) => {
614
- const S = o.search({ minX: a, minY: m, maxX: b, maxY: h }), x = new Set(S.map((T) => T.annotation.id));
615
- return Array.from(x).map((T) => ({
604
+ const S = o.search({ minX: a, minY: m, maxX: b, maxY: h }), A = new Set(S.map((T) => T.annotation.id));
605
+ return Array.from(A).map((T) => ({
616
606
  annotation: t.getAnnotation(T),
617
- rects: R(T)
607
+ rects: x(T)
618
608
  })).filter((T) => !!T.annotation);
619
609
  },
620
610
  insert: p,
621
611
  recalculate: () => {
622
612
  d(t.all().map((a) => a.target), !0), i.emit("recalculate");
623
613
  },
624
- remove: u,
614
+ remove: f,
625
615
  set: d,
626
616
  size: () => o.all().length,
627
617
  update: g,
628
618
  on: (a, m) => i.on(a, m)
629
619
  };
630
- }, ue = (t, e) => {
620
+ }, fe = (t, e) => {
631
621
  var C, N;
632
- const n = yt(), r = de(n, t, (C = e.mergeHighlights) == null ? void 0 : C.horizontalTolerance, (N = e.mergeHighlights) == null ? void 0 : N.verticalTolerance), o = bt(n, e.userSelectAction, e.adapter), s = St(n), i = Ct(), c = (E, a = F.LOCAL) => {
622
+ const n = bt(), r = de(n, t, (C = e.mergeHighlights) == null ? void 0 : C.horizontalTolerance, (N = e.mergeHighlights) == null ? void 0 : N.verticalTolerance), o = yt(n, e.userSelectAction, e.adapter), s = St(n), i = Ct(), c = (E, a = K.LOCAL) => {
633
623
  const m = G(E, t), b = P(m.target.selector);
634
624
  return b && n.addAnnotation(m, a), b;
635
- }, l = (E, a = !0, m = F.LOCAL) => {
625
+ }, l = (E, a = !0, m = K.LOCAL) => {
636
626
  const b = E.map((S) => G(S, t)), h = b.filter((S) => !P(S.target.selector));
637
627
  return n.bulkAddAnnotations(b, a, m), h;
638
- }, f = (E, a = F.LOCAL) => {
628
+ }, u = (E, a = K.LOCAL) => {
639
629
  const m = E.map((h) => G(h, t)), b = m.filter((h) => !P(h.target.selector));
640
630
  return m.forEach((h) => {
641
631
  n.getAnnotation(h.id) ? n.updateAnnotation(h, a) : n.addAnnotation(h, a);
642
632
  }), b;
643
- }, p = (E, a = F.LOCAL) => {
633
+ }, p = (E, a = K.LOCAL) => {
644
634
  const m = q(E, t);
645
635
  n.updateTarget(m, a);
646
- }, u = (E, a = F.LOCAL) => {
636
+ }, f = (E, a = K.LOCAL) => {
647
637
  const m = E.map((b) => q(b, t));
648
638
  n.bulkUpdateTargets(m, a);
649
639
  };
650
640
  function g(E, a, m, b) {
651
- const h = m || !!b, S = r.getAt(E, a, h).map((T) => n.getAnnotation(T)), x = b ? S.filter(b) : S;
652
- if (x.length !== 0)
653
- return m ? x : x[0];
641
+ const h = m || !!b, S = r.getAt(E, a, h).map((T) => n.getAnnotation(T)), A = b ? S.filter(b) : S;
642
+ if (A.length !== 0)
643
+ return m ? A : A[0];
654
644
  }
655
- const d = (E) => r.getAnnotationRects(E).length > 0 ? r.getAnnotationBounds(E) : void 0, L = (E, a, m, b) => r.getIntersecting(E, a, m, b), w = (E) => r.getAnnotationRects(E), R = () => r.recalculate(), A = (E) => r.on("recalculate", E);
645
+ const d = (E) => r.getAnnotationRects(E).length > 0 ? r.getAnnotationBounds(E) : void 0, L = (E, a, m, b) => r.getIntersecting(E, a, m, b), w = (E) => r.getAnnotationRects(E), x = () => r.recalculate(), R = (E) => r.on("recalculate", E);
656
646
  return n.observe(({ changes: E }) => {
657
647
  const a = (E.deleted || []).filter((h) => P(h.target.selector)), m = (E.created || []).filter((h) => P(h.target.selector)), b = (E.updated || []).filter((h) => P(h.newValue.target.selector));
658
648
  (a == null ? void 0 : a.length) > 0 && a.forEach((h) => r.remove(h.target)), m.length > 0 && r.set(m.map((h) => h.target), !1), (b == null ? void 0 : b.length) > 0 && b.forEach(({ newValue: h }) => r.update(h.target));
@@ -661,47 +651,47 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
661
651
  ...n,
662
652
  addAnnotation: c,
663
653
  bulkAddAnnotations: l,
664
- bulkUpdateTargets: u,
665
- bulkUpsertAnnotations: f,
654
+ bulkUpdateTargets: f,
655
+ bulkUpsertAnnotations: u,
666
656
  getAnnotationBounds: d,
667
657
  getAnnotationRects: w,
668
658
  getIntersecting: L,
669
659
  getAt: g,
670
- recalculatePositions: R,
671
- onRecalculatePositions: A,
660
+ recalculatePositions: x,
661
+ onRecalculatePositions: R,
672
662
  updateTarget: p
673
663
  },
674
664
  selection: o,
675
665
  hover: s,
676
666
  viewport: i
677
667
  };
678
- }, fe = () => {
668
+ }, ue = () => {
679
669
  const t = document.createElement("canvas");
680
670
  t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
681
671
  const e = t.getContext("2d");
682
672
  return e.scale(2, 2), e.translate(0.5, 0.5), t;
683
673
  }, ge = (t, e = {}) => {
684
- const n = fe(), r = n.getContext("2d");
674
+ const n = ue(), r = n.getContext("2d");
685
675
  document.body.appendChild(n);
686
- const o = /* @__PURE__ */ new Map(), s = (p) => Array.from(o.entries()).filter(([u, g]) => g.presenceKey === p.presenceKey).map(([u, g]) => u);
687
- return t.on("selectionChange", (p, u) => {
688
- s(p).forEach((d) => o.delete(d)), u && u.forEach((d) => o.set(d, p));
676
+ const o = /* @__PURE__ */ new Map(), s = (p) => Array.from(o.entries()).filter(([f, g]) => g.presenceKey === p.presenceKey).map(([f, g]) => f);
677
+ return t.on("selectionChange", (p, f) => {
678
+ s(p).forEach((d) => o.delete(d)), f && f.forEach((d) => o.set(d, p));
689
679
  }), {
690
680
  clear: () => {
691
- const { width: p, height: u } = n;
692
- r.clearRect(-0.5, -0.5, p + 1, u + 1);
681
+ const { width: p, height: f } = n;
682
+ r.clearRect(-0.5, -0.5, p + 1, f + 1);
693
683
  },
694
684
  destroy: () => {
695
685
  n.remove();
696
686
  },
697
- paint: (p, u, g) => {
687
+ paint: (p, f, g) => {
698
688
  e.font && (r.font = e.font);
699
689
  const d = o.get(p.annotation.id);
700
690
  if (d) {
701
- const { height: L } = p.rects[0], w = p.rects[0].x + u.left, R = p.rects[0].y + u.top;
702
- r.fillStyle = d.appearance.color, r.fillRect(w - 2, R - 2.5, 2, L + 5);
703
- const A = r.measureText(d.appearance.label), C = A.width + 6, N = A.actualBoundingBoxAscent + A.actualBoundingBoxDescent + 8, E = A.fontBoundingBoxAscent ? 8 : 6.5;
704
- return r.fillRect(w - 2, R - 2.5 - N, C, N), r.fillStyle = "#fff", r.fillText(d.appearance.label, w + 1, R - E), {
691
+ const { height: L } = p.rects[0], w = p.rects[0].x + f.left, x = p.rects[0].y + f.top;
692
+ r.fillStyle = d.appearance.color, r.fillRect(w - 2, x - 2.5, 2, L + 5);
693
+ const R = r.measureText(d.appearance.label), C = R.width + 6, N = R.actualBoundingBoxAscent + R.actualBoundingBoxDescent + 8, E = R.fontBoundingBoxAscent ? 8 : 6.5;
694
+ return r.fillRect(w - 2, x - 2.5 - N, C, N), r.fillStyle = "#fff", r.fillText(d.appearance.label, w + 1, x - E), {
705
695
  fill: d.appearance.color,
706
696
  fillOpacity: g ? 0.45 : 0.18
707
697
  };
@@ -713,7 +703,7 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
713
703
  p.scale(2, 2), p.translate(0.5, 0.5);
714
704
  }
715
705
  };
716
- }, et = 300, lt = ["up", "down", "left", "right"], dt = kt ? "⌘+a" : "ctrl+a", me = [
706
+ }, nt = 300, lt = ["up", "down", "left", "right"], dt = kt ? "⌘+a" : "ctrl+a", me = [
717
707
  ...lt.map((t) => `shift+${t}`),
718
708
  dt
719
709
  ], pe = (t, e, n) => {
@@ -723,71 +713,71 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
723
713
  annotatingEnabled: i,
724
714
  offsetReferenceSelector: c,
725
715
  selectionMode: l,
726
- dismissOnNotAnnotatable: f = "NEVER"
716
+ dismissOnNotAnnotatable: u = "NEVER"
727
717
  } = n, p = (y) => s = y;
728
- let u;
729
- const g = (y) => u = y;
730
- let d, L, w, R = i;
731
- const A = (y) => {
732
- R = y, N.clear(), y || (d = void 0, L = void 0, w = void 0);
733
- }, C = (y) => {
734
- R && L !== !1 && (d = K(t, y.target) ? void 0 : {
718
+ let f;
719
+ const g = (y) => f = y;
720
+ let d, L, w, x = i;
721
+ const R = (y) => {
722
+ x = y, N.clear(), y || (d = void 0, L = void 0, w = void 0);
723
+ }, C = () => {
724
+ x && L !== !1 && (d = {
735
725
  annotation: st(),
736
726
  selector: [],
737
727
  creator: s,
738
728
  created: /* @__PURE__ */ new Date()
739
729
  });
740
730
  }, N = $((y) => {
741
- if (!R) return;
731
+ if (!x) return;
742
732
  const v = document.getSelection();
743
733
  if (!(v != null && v.anchorNode))
744
734
  return;
745
- if (K(t, v.anchorNode)) {
735
+ const I = Array.from(Array(v.rangeCount).keys()).map((k) => v.getRangeAt(k));
736
+ if (!I.some((k) => k.intersectsNode(t))) {
746
737
  d = void 0;
747
738
  return;
748
739
  }
749
- const I = y.timeStamp - ((w == null ? void 0 : w.timeStamp) || y.timeStamp);
750
- if ((w == null ? void 0 : w.type) === "pointerdown" && (I < 1e3 && !d || v.isCollapsed && I < et) && C(w || y), !d) return;
751
- if (v.isCollapsed) {
740
+ const D = y.timeStamp - ((w == null ? void 0 : w.timeStamp) || y.timeStamp);
741
+ if ((w == null ? void 0 : w.type) === "pointerdown" && (D < 1e3 && !d || v.isCollapsed && D < nt) && C(), d || C(), v.isCollapsed) {
752
742
  r.getAnnotation(d.annotation) && (o.clear(), r.deleteAnnotation(d.annotation));
753
743
  return;
754
744
  }
755
- const M = Array.from(Array(v.rangeCount).keys()).map((B) => v.getRangeAt(B)).map((B) => Vt(B, t));
756
- if (M.every((B) => Dt(B))) return;
757
- const O = M.flatMap((B) => Ht(t, B.cloneRange()));
758
- (O.length !== d.selector.length || O.some((B, D) => {
759
- var U;
760
- return B.toString() !== ((U = d.selector[D]) == null ? void 0 : U.quote);
745
+ const M = I.map((k) => Wt(k, t));
746
+ if (M.every((k) => It(k))) return;
747
+ const O = M.flatMap((k) => _t(t, k.cloneRange()));
748
+ (O.length > 0 && !d || O.length !== d.selector.length || O.some((k, U) => {
749
+ var F;
750
+ return k.toString() !== ((F = d.selector[U]) == null ? void 0 : F.quote);
761
751
  })) && (d = {
762
752
  ...d,
763
- selector: O.map((B) => $t(B, t, c)),
753
+ selector: O.map((k) => $t(k, t, c)),
764
754
  updated: /* @__PURE__ */ new Date()
765
- }, r.getAnnotation(d.annotation) ? r.updateTarget(d, F.LOCAL) : o.clear());
755
+ }, r.getAnnotation(d.annotation) ? r.updateTarget(d, K.LOCAL) : o.clear());
766
756
  }, 10), E = (y) => {
767
757
  w = Q(y), L = w.button === 0;
768
758
  }, a = async (y) => {
769
759
  if (!L) return;
770
760
  const v = Q(y), I = () => {
771
761
  const { x: M, y: O } = t.getBoundingClientRect();
772
- if (K(t, v.target)) {
773
- (typeof f == "function" ? f(v, t) : f === "ALWAYS") && o.clear();
762
+ if (z(t, v.target)) {
763
+ (typeof u == "function" ? u(v, t) : u === "ALWAYS") && o.clear();
774
764
  return;
775
765
  }
776
766
  const H = v.target instanceof Node && t.contains(v.target) && r.getAt(
777
767
  v.clientX - M,
778
768
  v.clientY - O,
779
769
  l === "all",
780
- u
770
+ f
781
771
  );
782
772
  if (H) {
783
- const { selected: B } = o, D = new Set(B.map((Y) => Y.id)), U = Array.isArray(H) ? H.map((Y) => Y.id) : [H.id];
784
- (D.size !== U.length || !U.every((Y) => D.has(Y))) && o.userSelect(U, v);
773
+ const { selected: k } = o, U = new Set(k.map((V) => V.id)), F = Array.isArray(H) ? H.map((V) => V.id) : [H.id];
774
+ (U.size !== F.length || !F.every((V) => U.has(V))) && o.userSelect(F, v);
785
775
  } else
786
776
  o.clear();
787
777
  };
788
- if (v.timeStamp - w.timeStamp < et) {
778
+ if (v.timeStamp - w.timeStamp < nt) {
789
779
  await m();
790
- const M = document.getSelection(), O = K(t, w.target), H = K(t, v.target);
780
+ const M = document.getSelection(), O = z(t, w.target), H = z(t, v.target);
791
781
  if (M != null && M.isCollapsed || O && H) {
792
782
  d = void 0, I();
793
783
  return;
@@ -797,32 +787,32 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
797
787
  }, m = async () => {
798
788
  const y = document.getSelection();
799
789
  let v = !1, I = y == null ? void 0 : y.isCollapsed;
800
- const V = () => I || v, M = 1;
801
- return setTimeout(() => v = !0, 50), Tt(() => I = y == null ? void 0 : y.isCollapsed, M, V);
790
+ const D = () => I || v, M = 1;
791
+ return setTimeout(() => v = !0, 50), Rt(() => I = y == null ? void 0 : y.isCollapsed, M, D);
802
792
  }, b = (y) => {
803
793
  const v = document.getSelection();
804
794
  v != null && v.isCollapsed || ((!d || d.selector.length === 0) && N(y), d && (T(), o.userSelect(d.annotation, Q(y))));
805
795
  }, h = (y) => {
806
- R && y.key === "Shift" && d && (document.getSelection().isCollapsed || (T(), o.userSelect(d.annotation, z(y))));
796
+ x && y.key === "Shift" && d && (document.getSelection().isCollapsed || (T(), o.userSelect(d.annotation, X(y))));
807
797
  }, S = (y) => {
808
798
  const v = () => setTimeout(() => {
809
799
  (d == null ? void 0 : d.selector.length) > 0 && (o.clear(), r.addAnnotation({
810
800
  id: d.annotation,
811
801
  bodies: [],
812
802
  target: d
813
- }), o.userSelect(d.annotation, z(y))), document.removeEventListener("selectionchange", v);
803
+ }), o.userSelect(d.annotation, X(y))), document.removeEventListener("selectionchange", v);
814
804
  }, 100);
815
- document.addEventListener("selectionchange", v), C(y);
805
+ document.addEventListener("selectionchange", v), C();
816
806
  };
817
- X(me.join(","), { element: t, keydown: !0, keyup: !1 }, (y) => {
818
- y.repeat || (w = z(y));
819
- }), X(dt, { keydown: !0, keyup: !1 }, (y) => {
820
- w = z(y), S(y);
807
+ Y(me.join(","), { element: t, keydown: !0, keyup: !1 }, (y) => {
808
+ y.repeat || (w = X(y));
809
+ }), Y(dt, { keydown: !0, keyup: !1 }, (y) => {
810
+ w = X(y), S(y);
821
811
  });
822
- const x = (y) => {
812
+ const A = (y) => {
823
813
  y.repeat || y.target !== t && y.target !== document.body || (d = void 0, o.clear());
824
814
  };
825
- X(lt.join(","), { keydown: !0, keyup: !1 }, x);
815
+ Y(lt.join(","), { keydown: !0, keyup: !1 }, A);
826
816
  const T = () => {
827
817
  const y = r.getAnnotation(d.annotation);
828
818
  if (!y) {
@@ -838,60 +828,60 @@ const rt = "not-annotatable", W = `.${rt}`, K = (t, e) => {
838
828
  };
839
829
  return document.addEventListener("pointerdown", E), document.addEventListener("pointerup", a), document.addEventListener("contextmenu", b), t.addEventListener("keyup", h), t.addEventListener("selectstart", C), document.addEventListener("selectionchange", N), {
840
830
  destroy: () => {
841
- d = void 0, L = void 0, w = void 0, N.clear(), document.removeEventListener("pointerdown", E), document.removeEventListener("pointerup", a), document.removeEventListener("contextmenu", b), t.removeEventListener("keyup", h), t.removeEventListener("selectstart", C), document.removeEventListener("selectionchange", N), X.unbind();
831
+ d = void 0, L = void 0, w = void 0, N.clear(), document.removeEventListener("pointerdown", E), document.removeEventListener("pointerup", a), document.removeEventListener("contextmenu", b), t.removeEventListener("keyup", h), t.removeEventListener("selectstart", C), document.removeEventListener("selectionchange", N), Y.unbind();
842
832
  },
843
833
  setFilter: g,
844
834
  setUser: p,
845
- setAnnotatingEnabled: A
835
+ setAnnotatingEnabled: R
846
836
  };
847
837
  }, he = (t, e) => ({
848
838
  ...t,
849
839
  annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
850
840
  user: t.user || e.user
851
- }), nt = "SPANS", Be = (t, e = {}) => {
841
+ }), ot = "SPANS", Be = (t, e = {}) => {
852
842
  Nt(t), Bt(t);
853
843
  const n = he(e, {
854
844
  annotatingEnabled: !0,
855
845
  user: Et()
856
- }), r = ue(t, n), { selection: o, viewport: s } = r, i = r.store, c = wt(i), l = At(r, c, n.adapter);
857
- let f = n.user;
858
- const p = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : nt : n.renderer || nt, u = p === "SPANS" ? re(t, r, s) : p === "CSS_HIGHLIGHTS" ? ne(t, r, s) : p === "CANVAS" ? Jt(t, r, s) : void 0;
859
- if (!u)
846
+ }), r = fe(t, n), { selection: o, viewport: s } = r, i = r.store, c = wt(i), l = At(r, c, n.adapter);
847
+ let u = n.user;
848
+ const p = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ot : n.renderer || ot, f = p === "SPANS" ? re(t, r, s) : p === "CSS_HIGHLIGHTS" ? ee(t, r, s) : p === "CANVAS" ? Zt(t, r, s) : void 0;
849
+ if (!f)
860
850
  throw `Unknown renderer implementation: ${p}`;
861
- console.debug(`Using ${p} renderer`), n.style && u.setStyle(n.style);
851
+ console.debug(`Using ${p} renderer`), n.style && f.setStyle(n.style);
862
852
  const g = pe(t, r, n);
863
- g.setUser(f), g.setAnnotatingEnabled(n.annotatingEnabled);
864
- const d = vt(r, c, n.adapter), L = () => f, w = (a) => {
853
+ g.setUser(u), g.setAnnotatingEnabled(n.annotatingEnabled);
854
+ const d = vt(r, c, n.adapter), L = () => u, w = (a) => {
865
855
  g.setAnnotatingEnabled(
866
856
  a === void 0 ? !0 : a
867
857
  );
858
+ }, x = (a) => {
859
+ f.setFilter(a), g.setFilter(a);
868
860
  }, R = (a) => {
869
- u.setFilter(a), g.setFilter(a);
870
- }, A = (a) => {
871
- f = a, g.setUser(a);
861
+ u = a, g.setUser(a);
872
862
  }, C = (a) => {
873
- a && (u.setPainter(ge(a, n.presence)), a.on("selectionChange", () => u.redraw()));
863
+ a && (f.setPainter(ge(a, n.presence)), a.on("selectionChange", () => f.redraw()));
874
864
  }, N = (a) => {
875
865
  a ? o.setSelected(a) : o.clear();
876
866
  };
877
867
  return {
878
868
  ...d,
879
869
  destroy: () => {
880
- u.destroy(), g.destroy(), c.destroy();
870
+ f.destroy(), g.destroy(), c.destroy();
881
871
  },
882
872
  element: t,
883
873
  getUser: L,
884
874
  setAnnotatingEnabled: w,
885
- setFilter: R,
886
- setStyle: u.setStyle.bind(u),
887
- redraw: u.redraw.bind(u),
888
- setUser: A,
875
+ setFilter: x,
876
+ setStyle: f.setStyle.bind(f),
877
+ redraw: f.redraw.bind(f),
878
+ setUser: R,
889
879
  setSelected: N,
890
880
  setPresenceProvider: C,
891
- setVisible: u.setVisible.bind(u),
881
+ setVisible: f.setVisible.bind(f),
892
882
  on: l.on,
893
883
  off: l.off,
894
- scrollIntoView: Xt(t, i),
884
+ scrollIntoView: Yt(t, i),
895
885
  state: r
896
886
  };
897
887
  };
@@ -904,41 +894,42 @@ export {
904
894
  Pe as UserSelectAction,
905
895
  ke as W3CTextFormat,
906
896
  Nt as cancelSingleClickEvents,
907
- z as cloneKeyboardEvent,
897
+ X as cloneKeyboardEvent,
908
898
  Q as clonePointerEvent,
909
899
  _e as createBody,
910
- Jt as createCanvasRenderer,
911
- ne as createHighlightsRenderer,
900
+ Zt as createCanvasRenderer,
901
+ ee as createHighlightsRenderer,
912
902
  ge as createPresencePainter,
913
- ee as createRenderer,
903
+ te as createRenderer,
914
904
  pe as createSelectionHandler,
915
905
  re as createSpansRenderer,
916
906
  Be as createTextAnnotator,
917
- ue as createTextAnnotatorState,
907
+ fe as createTextAnnotatorState,
918
908
  he as fillDefaults,
919
- It as getHighlightClientRects,
920
- Pt as getQuoteContext,
921
- Z as getRangeAnnotatableContents,
909
+ Ht as getHighlightClientRects,
910
+ Dt as getQuoteContext,
911
+ J as getRangeAnnotatableContents,
922
912
  kt as isMac,
923
- K as isNotAnnotatable,
913
+ Mt as isNodeWhitespaceOrEmpty,
914
+ z as isNotAnnotatable,
924
915
  Lt as isRangeAnnotatable,
916
+ It as isRangeWhitespaceOrEmpty,
925
917
  P as isRevived,
926
- Dt as isWhitespaceOrEmpty,
927
918
  Kt as mergeClientRects,
928
- zt as paint,
919
+ Xt as paint,
929
920
  ce as parseW3CTextAnnotation,
930
921
  Bt as programmaticallyFocusable,
931
922
  $t as rangeToSelector,
932
923
  G as reviveAnnotation,
933
- it as reviveSelector,
924
+ at as reviveSelector,
934
925
  q as reviveTarget,
935
- Xt as scrollIntoView,
926
+ Yt as scrollIntoView,
936
927
  le as serializeW3CTextAnnotation,
937
- Ht as splitAnnotatableRanges,
928
+ _t as splitAnnotatableRanges,
938
929
  Ne as toDomRectList,
939
- Yt as toParentBounds,
930
+ Vt as toParentBounds,
940
931
  Oe as toViewportBounds,
941
- Vt as trimRangeToContainer,
942
- _t as whitespaceOrEmptyRegex
932
+ Wt as trimRangeToContainer,
933
+ it as whitespaceOrEmptyRegex
943
934
  };
944
935
  //# sourceMappingURL=text-annotator.es.js.map